winlin

implements api/v1/version, change to 0.9.43

@@ -61,7 +61,7 @@ int SrsApiRoot::do_process_request(SrsSocket* skt, SrsHttpMessage* req) @@ -61,7 +61,7 @@ int SrsApiRoot::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
61 ss << JOBJECT_START 61 ss << JOBJECT_START
62 << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT 62 << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
63 << JFIELD_ORG("urls", JOBJECT_START) 63 << JFIELD_ORG("urls", JOBJECT_START)
64 - << JFIELD_STR("v1", "the api version 1.0") 64 + << JFIELD_STR("api", "the api root")
65 << JOBJECT_END 65 << JOBJECT_END
66 << JOBJECT_END; 66 << JOBJECT_END;
67 67
@@ -70,6 +70,7 @@ int SrsApiRoot::do_process_request(SrsSocket* skt, SrsHttpMessage* req) @@ -70,6 +70,7 @@ int SrsApiRoot::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
70 70
71 SrsApiApi::SrsApiApi() 71 SrsApiApi::SrsApiApi()
72 { 72 {
  73 + handlers.push_back(new SrsApiV1());
73 } 74 }
74 75
75 SrsApiApi::~SrsApiApi() 76 SrsApiApi::~SrsApiApi()
@@ -83,8 +84,75 @@ bool SrsApiApi::can_handle(const char* path, int length, const char** /*pchild*/ @@ -83,8 +84,75 @@ bool SrsApiApi::can_handle(const char* path, int length, const char** /*pchild*/
83 84
84 int SrsApiApi::do_process_request(SrsSocket* skt, SrsHttpMessage* req) 85 int SrsApiApi::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
85 { 86 {
86 - std::string body = "hello, api";  
87 - return res_text(skt, body); 87 + std::stringstream ss;
  88 +
  89 + ss << JOBJECT_START
  90 + << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
  91 + << JFIELD_ORG("urls", JOBJECT_START)
  92 + << JFIELD_STR("v1", "the api version 1.0")
  93 + << JOBJECT_END
  94 + << JOBJECT_END;
  95 +
  96 + return res_json(skt, ss.str());
  97 +}
  98 +
  99 +SrsApiV1::SrsApiV1()
  100 +{
  101 + handlers.push_back(new SrsApiVersion());
  102 +}
  103 +
  104 +SrsApiV1::~SrsApiV1()
  105 +{
  106 +}
  107 +
  108 +bool SrsApiV1::can_handle(const char* path, int length, const char** /*pchild*/)
  109 +{
  110 + return srs_path_equals("/v1", path, length);
  111 +}
  112 +
  113 +int SrsApiV1::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
  114 +{
  115 + std::stringstream ss;
  116 +
  117 + ss << JOBJECT_START
  118 + << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
  119 + << JFIELD_ORG("urls", JOBJECT_START)
  120 + << JFIELD_STR("version", "the version of SRS")
  121 + << JOBJECT_END
  122 + << JOBJECT_END;
  123 +
  124 + return res_json(skt, ss.str());
  125 +}
  126 +
  127 +SrsApiVersion::SrsApiVersion()
  128 +{
  129 +}
  130 +
  131 +SrsApiVersion::~SrsApiVersion()
  132 +{
  133 +}
  134 +
  135 +bool SrsApiVersion::can_handle(const char* path, int length, const char** /*pchild*/)
  136 +{
  137 + return srs_path_equals("/version", path, length);
  138 +}
  139 +
  140 +int SrsApiVersion::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
  141 +{
  142 + std::stringstream ss;
  143 +
  144 + ss << JOBJECT_START
  145 + << JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
  146 + << JFIELD_ORG("data", JOBJECT_START)
  147 + << JFIELD_ORG("major", VERSION_MAJOR) << JFIELD_CONT
  148 + << JFIELD_ORG("minor", VERSION_MINOR) << JFIELD_CONT
  149 + << JFIELD_ORG("revision", VERSION_REVISION) << JFIELD_CONT
  150 + << JFIELD_STR("version", RTMP_SIG_SRS_VERSION) << JFIELD_CONT
  151 + << JFIELD_STR("primary_authors", RTMP_SIG_SRS_PRIMARY_AUTHROS)
  152 + << JOBJECT_END
  153 + << JOBJECT_END;
  154 +
  155 + return res_json(skt, ss.str());
88 } 156 }
89 157
90 SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler) 158 SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler)
@@ -62,6 +62,26 @@ public: @@ -62,6 +62,26 @@ public:
62 virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req); 62 virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
63 }; 63 };
64 64
  65 +class SrsApiV1 : public SrsHttpHandler
  66 +{
  67 +public:
  68 + SrsApiV1();
  69 + virtual ~SrsApiV1();
  70 +public:
  71 + virtual bool can_handle(const char* path, int length, const char** pchild);
  72 + virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
  73 +};
  74 +
  75 +class SrsApiVersion : public SrsHttpHandler
  76 +{
  77 +public:
  78 + SrsApiVersion();
  79 + virtual ~SrsApiVersion();
  80 +public:
  81 + virtual bool can_handle(const char* path, int length, const char** pchild);
  82 + virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
  83 +};
  84 +
65 class SrsHttpApi : public SrsConnection 85 class SrsHttpApi : public SrsConnection
66 { 86 {
67 private: 87 private:
@@ -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 "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "42" 34 +#define VERSION_REVISION "43"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"