winlin

fix #448, fix the bug of response of http hooks. 2.0.195

@@ -335,6 +335,7 @@ Remark: @@ -335,6 +335,7 @@ Remark:
335 335
336 ## History 336 ## History
337 337
  338 +* v2.0, 2015-10-04, for [#448][bug #448] fix the bug of response of http hooks. 2.0.195
338 * v2.0, 2015-10-01, for [#497][bug #497] response error when client not found to kickoff. 2.0.194 339 * v2.0, 2015-10-01, for [#497][bug #497] response error when client not found to kickoff. 2.0.194
339 * v2.0, 2015-10-01, for [#495][bug #495] decrease the srs-librtmp size. 2.0.193 340 * v2.0, 2015-10-01, for [#495][bug #495] decrease the srs-librtmp size. 2.0.193
340 * v2.0, 2015-09-23, for [#485][bug #485] error when arm glibc 2.15+ or not i386/x86_64/amd64. 2.0.192 341 * v2.0, 2015-09-23, for [#485][bug #485] error when arm glibc 2.15+ or not i386/x86_64/amd64. 2.0.192
@@ -1031,6 +1032,7 @@ Winlin @@ -1031,6 +1032,7 @@ Winlin
1031 [bug #485]: https://github.com/simple-rtmp-server/srs/issues/485 1032 [bug #485]: https://github.com/simple-rtmp-server/srs/issues/485
1032 [bug #495]: https://github.com/simple-rtmp-server/srs/issues/495 1033 [bug #495]: https://github.com/simple-rtmp-server/srs/issues/495
1033 [bug #497]: https://github.com/simple-rtmp-server/srs/issues/497 1034 [bug #497]: https://github.com/simple-rtmp-server/srs/issues/497
  1035 +[bug #448]: https://github.com/simple-rtmp-server/srs/issues/448
1034 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475 1036 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475
1035 [bug #458]: https://github.com/simple-rtmp-server/srs/issues/458 1037 [bug #458]: https://github.com/simple-rtmp-server/srs/issues/458
1036 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454 1038 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454
@@ -431,37 +431,49 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r @@ -431,37 +431,49 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r
431 // ensure the http status is ok. 431 // ensure the http status is ok.
432 // https://github.com/simple-rtmp-server/srs/issues/158 432 // https://github.com/simple-rtmp-server/srs/issues/158
433 if (code != SRS_CONSTS_HTTP_OK) { 433 if (code != SRS_CONSTS_HTTP_OK) {
434 - return ERROR_HTTP_STATUS_INVLIAD; 434 + ret = ERROR_HTTP_STATUS_INVLIAD;
  435 + srs_error("invalid response status=%d. ret=%d", code, ret);
  436 + return ret;
435 } 437 }
436 438
  439 + // should never be empty.
437 if (res.empty()) { 440 if (res.empty()) {
438 - return ERROR_HTTP_DATA_INVLIAD; 441 + ret = ERROR_HTTP_DATA_INVLIAD;
  442 + srs_error("invalid empty response. ret=%d", ret);
  443 + return ret;
439 } 444 }
440 445
441 // parse string res to json. 446 // parse string res to json.
442 SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str()); 447 SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str());
  448 + if (!info) {
  449 + ret = ERROR_HTTP_DATA_INVLIAD;
  450 + srs_error("invalid response %s. ret=%d", res.c_str(), ret);
  451 + return ret;
  452 + }
443 SrsAutoFree(SrsJsonAny, info); 453 SrsAutoFree(SrsJsonAny, info);
444 454
445 - // if res is number of error code 455 + // response error code in string.
446 if (!info->is_object()) { 456 if (!info->is_object()) {
447 if (res != SRS_HTTP_RESPONSE_OK) { 457 if (res != SRS_HTTP_RESPONSE_OK) {
448 - return ERROR_HTTP_DATA_INVLIAD; 458 + ret = ERROR_HTTP_DATA_INVLIAD;
  459 + srs_error("invalid response number %s. ret=%d", res.c_str(), ret);
  460 + return ret;
449 } 461 }
450 return ret; 462 return ret;
451 } 463 }
452 464
453 - // if res is json obj, like: {"code": 0, "data": ""} 465 + // response standard object, format in json: {"code": 0, "data": ""}
454 SrsJsonObject* res_info = info->to_object(); 466 SrsJsonObject* res_info = info->to_object();
455 SrsJsonAny* res_code = NULL; 467 SrsJsonAny* res_code = NULL;
456 if ((res_code = res_info->ensure_property_integer("code")) == NULL) { 468 if ((res_code = res_info->ensure_property_integer("code")) == NULL) {
457 ret = ERROR_RESPONSE_CODE; 469 ret = ERROR_RESPONSE_CODE;
458 - srs_error("res code error, ret=%d", ret); 470 + srs_error("invalid response without code, ret=%d", ret);
459 return ret; 471 return ret;
460 } 472 }
461 473
462 if ((res_code->to_integer()) != ERROR_SUCCESS) { 474 if ((res_code->to_integer()) != ERROR_SUCCESS) {
463 ret = ERROR_RESPONSE_CODE; 475 ret = ERROR_RESPONSE_CODE;
464 - srs_error("res code error, ret=%d, code=%d", ret, code); 476 + srs_error("error response code=%d. ret=%d", res_code->to_integer(), ret);
465 return ret; 477 return ret;
466 } 478 }
467 479
@@ -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 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 194 34 +#define VERSION_REVISION 195
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"