From 0c8209cccd7b40962670dbd6256c65b39e214e1e Mon Sep 17 00:00:00 2001
From: winlin <winlin@vip.126.com>
Date: Sun, 4 Oct 2015 08:09:39 +0800
Subject: [PATCH] fix #448, fix the bug of response of http hooks. 2.0.195

---
 README.md                            |  2 ++
 trunk/src/app/srs_app_http_hooks.cpp | 26 +++++++++++++++++++-------
 trunk/src/core/srs_core.hpp          |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 09819903a..28c9b8eed 100755
--- a/README.md
+++ b/README.md
@@ -335,6 +335,7 @@ Remark:
 
 ## History
 
+* v2.0, 2015-10-04, for [#448][bug #448] fix the bug of response of http hooks. 2.0.195
 * v2.0, 2015-10-01, for [#497][bug #497] response error when client not found to kickoff. 2.0.194
 * v2.0, 2015-10-01, for [#495][bug #495] decrease the srs-librtmp size. 2.0.193
 * 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
 [bug #485]: https://github.com/simple-rtmp-server/srs/issues/485
 [bug #495]: https://github.com/simple-rtmp-server/srs/issues/495
 [bug #497]: https://github.com/simple-rtmp-server/srs/issues/497
+[bug #448]: https://github.com/simple-rtmp-server/srs/issues/448
 [bug #475]: https://github.com/simple-rtmp-server/srs/issues/475
 [bug #458]: https://github.com/simple-rtmp-server/srs/issues/458
 [bug #454]: https://github.com/simple-rtmp-server/srs/issues/454
diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp
index 261ffb1b2..292d03a8d 100644
--- a/trunk/src/app/srs_app_http_hooks.cpp
+++ b/trunk/src/app/srs_app_http_hooks.cpp
@@ -431,37 +431,49 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r
     // ensure the http status is ok.
     // https://github.com/simple-rtmp-server/srs/issues/158
     if (code != SRS_CONSTS_HTTP_OK) {
-        return ERROR_HTTP_STATUS_INVLIAD;
+        ret = ERROR_HTTP_STATUS_INVLIAD;
+        srs_error("invalid response status=%d. ret=%d", code, ret);
+        return ret;
     }
     
+    // should never be empty.
     if (res.empty()) {
-        return ERROR_HTTP_DATA_INVLIAD;
+        ret = ERROR_HTTP_DATA_INVLIAD;
+        srs_error("invalid empty response. ret=%d", ret);
+        return ret;
     }
     
     // parse string res to json.
     SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str());
+    if (!info) {
+        ret = ERROR_HTTP_DATA_INVLIAD;
+        srs_error("invalid response %s. ret=%d", res.c_str(), ret);
+        return ret;
+    }
     SrsAutoFree(SrsJsonAny, info);
     
-    // if res is number of error code
+    // response error code in string.
     if (!info->is_object()) {
         if (res != SRS_HTTP_RESPONSE_OK) {
-            return ERROR_HTTP_DATA_INVLIAD;
+            ret = ERROR_HTTP_DATA_INVLIAD;
+            srs_error("invalid response number %s. ret=%d", res.c_str(), ret);
+            return ret;
         }
         return ret;
     }
     
-    // if res is json obj, like: {"code": 0, "data": ""}
+    // response standard object, format in json: {"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);
+        srs_error("invalid response without code, 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);
+        srs_error("error response code=%d. ret=%d", res_code->to_integer(), ret);
         return ret;
     }
 
diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp
index a9d367b65..d4d96eb3e 100644
--- a/trunk/src/core/srs_core.hpp
+++ b/trunk/src/core/srs_core.hpp
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // current release version
 #define VERSION_MAJOR       2
 #define VERSION_MINOR       0
-#define VERSION_REVISION    194
+#define VERSION_REVISION    195
 
 // server info.
 #define RTMP_SIG_SRS_KEY "SRS"