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 @@ -433,10 +433,36 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r
433 return ERROR_HTTP_STATUS_INVLIAD; 433 return ERROR_HTTP_STATUS_INVLIAD;
434 } 434 }
435 435
436 - // TODO: FIXME: parse json.  
437 - if (res.empty() || res != SRS_HTTP_RESPONSE_OK) { 436 + if (res.empty()) {
438 return ERROR_HTTP_DATA_INVLIAD; 437 return ERROR_HTTP_DATA_INVLIAD;
439 } 438 }
  439 +
  440 + // parse string res to json.
  441 + SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str());
  442 + SrsAutoFree(SrsJsonAny, info);
  443 +
  444 + // if res is number of error code
  445 + if (!info->is_object()) {
  446 + if (res != SRS_HTTP_RESPONSE_OK) {
  447 + return ERROR_HTTP_DATA_INVLIAD;
  448 + }
  449 + return ret;
  450 + }
  451 +
  452 + // if res is json obj, like: {"code": 0, "data": ""}
  453 + SrsJsonObject* res_info = info->to_object();
  454 + SrsJsonAny* res_code = NULL;
  455 + if ((res_code = res_info->ensure_property_integer("code")) == NULL) {
  456 + ret = ERROR_RESPONSE_CODE;
  457 + srs_error("res code error, ret=%d", ret);
  458 + return ret;
  459 + }
  460 +
  461 + if ((res_code->to_integer()) != ERROR_SUCCESS) {
  462 + ret = ERROR_RESPONSE_CODE;
  463 + srs_error("res code error, ret=%d, code=%d", ret, code);
  464 + return ret;
  465 + }
440 466
441 return ret; 467 return ret;
442 } 468 }
@@ -223,6 +223,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -223,6 +223,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
223 #define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060 223 #define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060
224 #define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061 224 #define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061
225 #define ERROR_HLS_NO_STREAM 3062 225 #define ERROR_HLS_NO_STREAM 3062
  226 +#define ERROR_JSON_LOADS 3063
  227 +#define ERROR_RESPONSE_CODE 3064
226 228
227 /////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////
228 // HTTP/StreamCaster protocol error. 230 // HTTP/StreamCaster protocol error.
@@ -262,6 +264,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -262,6 +264,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
262 // user-define error. 264 // user-define error.
263 /////////////////////////////////////////////////////// 265 ///////////////////////////////////////////////////////
264 #define ERROR_USER_START 9000 266 #define ERROR_USER_START 9000
  267 +#define ERROR_USER_DISCONNECT 9001
  268 +#define ERROR_SOURCE_NOT_FOUND 9002
265 #define ERROR_USER_END 9999 269 #define ERROR_USER_END 9999
266 270
267 /** 271 /**