mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix bug of nx_json parse, to 0.9.104
This commit is contained in:
parent
d6355efe22
commit
3064e5ec61
4 changed files with 60 additions and 41 deletions
|
@ -213,13 +213,34 @@ int SrsApiConfigsLogs::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if (req->is_http_put()) {
|
||||
// HTTP GET
|
||||
if (req->is_http_get()) {
|
||||
std::stringstream ss;
|
||||
ss << JOBJECT_START
|
||||
<< JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
|
||||
<< JFIELD_ORG("data", JOBJECT_START)
|
||||
<< JFIELD_STR("tank", (_srs_config->get_log_tank_file()? "file":"console")) << JFIELD_CONT
|
||||
<< JFIELD_STR("level", _srs_config->get_log_level()) << JFIELD_CONT
|
||||
<< JFIELD_STR("cwd", _srs_config->cwd()) << JFIELD_CONT
|
||||
<< JFIELD_STR("file", _srs_config->get_log_file())
|
||||
<< JOBJECT_END
|
||||
<< JOBJECT_END;
|
||||
|
||||
return res_json(skt, req, ss.str());
|
||||
}
|
||||
|
||||
// HTTP PUT
|
||||
srs_trace("http api PUT logs, req is: %s", req->body().c_str());
|
||||
|
||||
SrsJsonAny* json = SrsJsonAny::loads(req->body_raw());
|
||||
SrsAutoFree(SrsJsonAny, json);
|
||||
|
||||
if (json->is_object()) {
|
||||
if (!json) {
|
||||
return response_error(skt, req, ERROR_HTTP_API_LOGS, "invalid PUT json");
|
||||
} else if (!json->is_object()) {
|
||||
return response_error(skt, req, ERROR_HTTP_API_LOGS, "invalid PUT json logs params");
|
||||
}
|
||||
|
||||
SrsJsonObject* o = json->to_object();
|
||||
SrsJsonAny* prop = NULL;
|
||||
if ((prop = o->ensure_property_string("file")) != NULL && _srs_config->set_log_file(prop->to_str())) {
|
||||
|
@ -240,21 +261,8 @@ int SrsApiConfigsLogs::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
|
|||
}
|
||||
srs_warn("http api reload log level to %s", prop->to_str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << JOBJECT_START
|
||||
<< JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
|
||||
<< JFIELD_ORG("data", JOBJECT_START)
|
||||
<< JFIELD_STR("tank", (_srs_config->get_log_tank_file()? "file":"console")) << JFIELD_CONT
|
||||
<< JFIELD_STR("level", _srs_config->get_log_level()) << JFIELD_CONT
|
||||
<< JFIELD_STR("cwd", _srs_config->cwd()) << JFIELD_CONT
|
||||
<< JFIELD_STR("file", _srs_config->get_log_file())
|
||||
<< JOBJECT_END
|
||||
<< JOBJECT_END;
|
||||
|
||||
return res_json(skt, req, ss.str());
|
||||
return response_error(skt, req, ret, "PUT logs success.");
|
||||
}
|
||||
|
||||
SrsApiVersion::SrsApiVersion()
|
||||
|
|
|
@ -306,6 +306,10 @@ SrsJsonArray* SrsJsonAny::array()
|
|||
#ifdef SRS_JSON_USE_NXJSON
|
||||
SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node)
|
||||
{
|
||||
if (!node) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (node->type) {
|
||||
case NX_JSON_NULL:
|
||||
return SrsJsonAny::null();
|
||||
|
@ -338,6 +342,7 @@ SrsJsonAny* srs_json_parse_tree_nx_json(const nx_json* node)
|
|||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -352,8 +357,13 @@ SrsJsonAny* SrsJsonAny::loads(char* str)
|
|||
}
|
||||
|
||||
const nx_json* o = nx_json_parse(str, 0);
|
||||
|
||||
SrsJsonAny* json = srs_json_parse_tree_nx_json(o);
|
||||
|
||||
if (o) {
|
||||
nx_json_free(o);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
#endif
|
||||
|
@ -529,7 +539,7 @@ extern "C" {
|
|||
|
||||
// redefine NX_JSON_REPORT_ERROR to use custom error reporting
|
||||
#ifndef NX_JSON_REPORT_ERROR
|
||||
#define NX_JSON_REPORT_ERROR(msg, p) srs_error("NXJSON PARSE ERROR (%d): " msg " at %s\n", __LINE__, p)
|
||||
#define NX_JSON_REPORT_ERROR(msg, p) srs_warn("NXJSON PARSE ERROR (%d): " msg " at %s", __LINE__, p)
|
||||
#endif
|
||||
|
||||
#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.
|
|||
// current release version
|
||||
#define VERSION_MAJOR "0"
|
||||
#define VERSION_MINOR "9"
|
||||
#define VERSION_REVISION "103"
|
||||
#define VERSION_REVISION "104"
|
||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "srs"
|
||||
|
|
|
@ -183,6 +183,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_HTTP_HANDLER_INVALID 804
|
||||
#define ERROR_HTTP_OPEN_FILE 805
|
||||
#define ERROR_HTTP_READ_FILE 806
|
||||
#define ERROR_HTTP_API_LOGS 807
|
||||
|
||||
// system control message,
|
||||
// not an error, but special control logic.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue