winlin

merge from bravo, parse the http reponse in json of bravo system.

... ... @@ -433,10 +433,36 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r
return ERROR_HTTP_STATUS_INVLIAD;
}
// TODO: FIXME: parse json.
if (res.empty() || res != SRS_HTTP_RESPONSE_OK) {
if (res.empty()) {
return ERROR_HTTP_DATA_INVLIAD;
}
// parse string res to json.
SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str());
SrsAutoFree(SrsJsonAny, info);
// if res is number of error code
if (!info->is_object()) {
if (res != SRS_HTTP_RESPONSE_OK) {
return ERROR_HTTP_DATA_INVLIAD;
}
return ret;
}
// if res is json obj, like: {"code": 0, "data": ""}
SrsJsonObject* res_info = info->to_object();
SrsJsonAny* res_code = NULL;
if ((res_code = res_info->ensure_property_integer("code")) == NULL) {
ret = ERROR_RESPONSE_CODE;
srs_error("res code error, ret=%d", ret);
return ret;
}
if ((res_code->to_integer()) != ERROR_SUCCESS) {
ret = ERROR_RESPONSE_CODE;
srs_error("res code error, ret=%d, code=%d", ret, code);
return ret;
}
return ret;
}
... ...
... ... @@ -223,6 +223,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060
#define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061
#define ERROR_HLS_NO_STREAM 3062
#define ERROR_JSON_LOADS 3063
#define ERROR_RESPONSE_CODE 3064
///////////////////////////////////////////////////////
// HTTP/StreamCaster protocol error.
... ... @@ -262,6 +264,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// user-define error.
///////////////////////////////////////////////////////
#define ERROR_USER_START 9000
#define ERROR_USER_DISCONNECT 9001
#define ERROR_SOURCE_NOT_FOUND 9002
#define ERROR_USER_END 9999
/**
... ...