正在显示
4 个修改的文件
包含
60 行增加
和
41 行删除
| @@ -213,48 +213,56 @@ int SrsApiConfigsLogs::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | @@ -213,48 +213,56 @@ int SrsApiConfigsLogs::do_process_request(SrsSocket* skt, SrsHttpMessage* req) | ||
| 213 | { | 213 | { |
| 214 | int ret = ERROR_SUCCESS; | 214 | int ret = ERROR_SUCCESS; |
| 215 | 215 | ||
| 216 | - if (req->is_http_put()) { | ||
| 217 | - srs_trace("http api PUT logs, req is: %s", req->body().c_str()); | ||
| 218 | - | ||
| 219 | - SrsJsonAny* json = SrsJsonAny::loads(req->body_raw()); | ||
| 220 | - SrsAutoFree(SrsJsonAny, json); | 216 | + // HTTP GET |
| 217 | + if (req->is_http_get()) { | ||
| 218 | + std::stringstream ss; | ||
| 219 | + ss << JOBJECT_START | ||
| 220 | + << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT | ||
| 221 | + << JFIELD_ORG("data", JOBJECT_START) | ||
| 222 | + << JFIELD_STR("tank", (_srs_config->get_log_tank_file()? "file":"console")) << JFIELD_CONT | ||
| 223 | + << JFIELD_STR("level", _srs_config->get_log_level()) << JFIELD_CONT | ||
| 224 | + << JFIELD_STR("cwd", _srs_config->cwd()) << JFIELD_CONT | ||
| 225 | + << JFIELD_STR("file", _srs_config->get_log_file()) | ||
| 226 | + << JOBJECT_END | ||
| 227 | + << JOBJECT_END; | ||
| 221 | 228 | ||
| 222 | - if (json->is_object()) { | ||
| 223 | - SrsJsonObject* o = json->to_object(); | ||
| 224 | - SrsJsonAny* prop = NULL; | ||
| 225 | - if ((prop = o->ensure_property_string("file")) != NULL && _srs_config->set_log_file(prop->to_str())) { | ||
| 226 | - if ((ret = _srs_config->force_reload_log_file()) != ERROR_SUCCESS) { | ||
| 227 | - return response_error(skt, req, ret, "reload log file failed"); | ||
| 228 | - } | ||
| 229 | - srs_warn("http api reload log file to %s", prop->to_str().c_str()); | ||
| 230 | - } | ||
| 231 | - if ((prop = o->ensure_property_string("tank")) != NULL && _srs_config->set_log_tank(prop->to_str())) { | ||
| 232 | - if ((ret = _srs_config->force_reload_log_tank()) != ERROR_SUCCESS) { | ||
| 233 | - return response_error(skt, req, ret, "reload log tank failed"); | ||
| 234 | - } | ||
| 235 | - srs_warn("http api reload log tank to %s", prop->to_str().c_str()); | ||
| 236 | - } | ||
| 237 | - if ((prop = o->ensure_property_string("level")) != NULL && _srs_config->set_log_level(prop->to_str())) { | ||
| 238 | - if ((ret = _srs_config->force_reload_log_level()) != ERROR_SUCCESS) { | ||
| 239 | - return response_error(skt, req, ret, "reload log level failed"); | ||
| 240 | - } | ||
| 241 | - srs_warn("http api reload log level to %s", prop->to_str().c_str()); | ||
| 242 | - } | ||
| 243 | - } | 229 | + return res_json(skt, req, ss.str()); |
| 244 | } | 230 | } |
| 245 | 231 | ||
| 246 | - std::stringstream ss; | ||
| 247 | - ss << JOBJECT_START | ||
| 248 | - << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT | ||
| 249 | - << JFIELD_ORG("data", JOBJECT_START) | ||
| 250 | - << JFIELD_STR("tank", (_srs_config->get_log_tank_file()? "file":"console")) << JFIELD_CONT | ||
| 251 | - << JFIELD_STR("level", _srs_config->get_log_level()) << JFIELD_CONT | ||
| 252 | - << JFIELD_STR("cwd", _srs_config->cwd()) << JFIELD_CONT | ||
| 253 | - << JFIELD_STR("file", _srs_config->get_log_file()) | ||
| 254 | - << JOBJECT_END | ||
| 255 | - << JOBJECT_END; | 232 | + // HTTP PUT |
| 233 | + srs_trace("http api PUT logs, req is: %s", req->body().c_str()); | ||
| 256 | 234 | ||
| 257 | - return res_json(skt, req, ss.str()); | 235 | + SrsJsonAny* json = SrsJsonAny::loads(req->body_raw()); |
| 236 | + SrsAutoFree(SrsJsonAny, json); | ||
| 237 | + | ||
| 238 | + if (!json) { | ||
| 239 | + return response_error(skt, req, ERROR_HTTP_API_LOGS, "invalid PUT json"); | ||
| 240 | + } else if (!json->is_object()) { | ||
| 241 | + return response_error(skt, req, ERROR_HTTP_API_LOGS, "invalid PUT json logs params"); | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + SrsJsonObject* o = json->to_object(); | ||
| 245 | + SrsJsonAny* prop = NULL; | ||
| 246 | + if ((prop = o->ensure_property_string("file")) != NULL && _srs_config->set_log_file(prop->to_str())) { | ||
| 247 | + if ((ret = _srs_config->force_reload_log_file()) != ERROR_SUCCESS) { | ||
| 248 | + return response_error(skt, req, ret, "reload log file failed"); | ||
| 249 | + } | ||
| 250 | + srs_warn("http api reload log file to %s", prop->to_str().c_str()); | ||
| 251 | + } | ||
| 252 | + if ((prop = o->ensure_property_string("tank")) != NULL && _srs_config->set_log_tank(prop->to_str())) { | ||
| 253 | + if ((ret = _srs_config->force_reload_log_tank()) != ERROR_SUCCESS) { | ||
| 254 | + return response_error(skt, req, ret, "reload log tank failed"); | ||
| 255 | + } | ||
| 256 | + srs_warn("http api reload log tank to %s", prop->to_str().c_str()); | ||
| 257 | + } | ||
| 258 | + if ((prop = o->ensure_property_string("level")) != NULL && _srs_config->set_log_level(prop->to_str())) { | ||
| 259 | + if ((ret = _srs_config->force_reload_log_level()) != ERROR_SUCCESS) { | ||
| 260 | + return response_error(skt, req, ret, "reload log level failed"); | ||
| 261 | + } | ||
| 262 | + srs_warn("http api reload log level to %s", prop->to_str().c_str()); | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + return response_error(skt, req, ret, "PUT logs success."); | ||
| 258 | } | 266 | } |
| 259 | 267 | ||
| 260 | SrsApiVersion::SrsApiVersion() | 268 | SrsApiVersion::SrsApiVersion() |
| @@ -306,6 +306,10 @@ SrsJsonArray* SrsJsonAny::array() | @@ -306,6 +306,10 @@ SrsJsonArray* SrsJsonAny::array() | ||
| 306 | #ifdef SRS_JSON_USE_NXJSON | 306 | #ifdef SRS_JSON_USE_NXJSON |
| 307 | SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node) | 307 | SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node) |
| 308 | { | 308 | { |
| 309 | + if (!node) { | ||
| 310 | + return NULL; | ||
| 311 | + } | ||
| 312 | + | ||
| 309 | switch (node->type) { | 313 | switch (node->type) { |
| 310 | case NX_JSON_NULL: | 314 | case NX_JSON_NULL: |
| 311 | return SrsJsonAny::null(); | 315 | return SrsJsonAny::null(); |
| @@ -338,6 +342,7 @@ SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node) | @@ -338,6 +342,7 @@ SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node) | ||
| 338 | return arr; | 342 | return arr; |
| 339 | } | 343 | } |
| 340 | } | 344 | } |
| 345 | + | ||
| 341 | return NULL; | 346 | return NULL; |
| 342 | } | 347 | } |
| 343 | 348 | ||
| @@ -352,8 +357,13 @@ SrsJsonAny* SrsJsonAny::loads(char* str) | @@ -352,8 +357,13 @@ SrsJsonAny* SrsJsonAny::loads(char* str) | ||
| 352 | } | 357 | } |
| 353 | 358 | ||
| 354 | const nx_json* o = nx_json_parse(str, 0); | 359 | const nx_json* o = nx_json_parse(str, 0); |
| 360 | + | ||
| 355 | SrsJsonAny* json = srs_json_parse_tree_nx_json(o); | 361 | SrsJsonAny* json = srs_json_parse_tree_nx_json(o); |
| 356 | - nx_json_free(o); | 362 | + |
| 363 | + if (o) { | ||
| 364 | + nx_json_free(o); | ||
| 365 | + } | ||
| 366 | + | ||
| 357 | return json; | 367 | return json; |
| 358 | } | 368 | } |
| 359 | #endif | 369 | #endif |
| @@ -529,7 +539,7 @@ extern "C" { | @@ -529,7 +539,7 @@ extern "C" { | ||
| 529 | 539 | ||
| 530 | // redefine NX_JSON_REPORT_ERROR to use custom error reporting | 540 | // redefine NX_JSON_REPORT_ERROR to use custom error reporting |
| 531 | #ifndef NX_JSON_REPORT_ERROR | 541 | #ifndef NX_JSON_REPORT_ERROR |
| 532 | -#define NX_JSON_REPORT_ERROR(msg, p) srs_error("NXJSON PARSE ERROR (%d): " msg " at %s\n", __LINE__, p) | 542 | +#define NX_JSON_REPORT_ERROR(msg, p) srs_warn("NXJSON PARSE ERROR (%d): " msg " at %s", __LINE__, p) |
| 533 | #endif | 543 | #endif |
| 534 | 544 | ||
| 535 | #define IS_WHITESPACE(c) ((unsigned char)(c)<=(unsigned char)' ') | 545 | #define IS_WHITESPACE(c) ((unsigned char)(c)<=(unsigned char)' ') |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "103" | 34 | +#define VERSION_REVISION "104" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
| @@ -183,6 +183,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -183,6 +183,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 183 | #define ERROR_HTTP_HANDLER_INVALID 804 | 183 | #define ERROR_HTTP_HANDLER_INVALID 804 |
| 184 | #define ERROR_HTTP_OPEN_FILE 805 | 184 | #define ERROR_HTTP_OPEN_FILE 805 |
| 185 | #define ERROR_HTTP_READ_FILE 806 | 185 | #define ERROR_HTTP_READ_FILE 806 |
| 186 | +#define ERROR_HTTP_API_LOGS 807 | ||
| 186 | 187 | ||
| 187 | // system control message, | 188 | // system control message, |
| 188 | // not an error, but special control logic. | 189 | // not an error, but special control logic. |
-
请 注册 或 登录 后发表评论