winlin

refie http consts.

@@ -41,6 +41,13 @@ using namespace std; @@ -41,6 +41,13 @@ using namespace std;
41 41
42 #define SRS_HTTP_HEADER_BUFFER 1024 42 #define SRS_HTTP_HEADER_BUFFER 1024
43 43
  44 +// for http parser macros
  45 +#define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS
  46 +#define SRS_CONSTS_HTTP_GET HTTP_GET
  47 +#define SRS_CONSTS_HTTP_POST HTTP_POST
  48 +#define SRS_CONSTS_HTTP_PUT HTTP_PUT
  49 +#define SRS_CONSTS_HTTP_DELETE HTTP_DELETE
  50 +
44 bool srs_path_equals(const char* expect, const char* path, int nb_path) 51 bool srs_path_equals(const char* expect, const char* path, int nb_path)
45 { 52 {
46 int size = strlen(expect); 53 int size = strlen(expect);
@@ -92,7 +99,7 @@ bool SrsHttpHandler::can_handle(const char* /*path*/, int /*length*/, const char @@ -92,7 +99,7 @@ bool SrsHttpHandler::can_handle(const char* /*path*/, int /*length*/, const char
92 99
93 int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req) 100 int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
94 { 101 {
95 - if (req->method() == HTTP_OPTIONS) { 102 + if (req->method() == SRS_CONSTS_HTTP_OPTIONS) {
96 req->set_requires_crossdomain(true); 103 req->set_requires_crossdomain(true);
97 return res_options(skt); 104 return res_options(skt);
98 } 105 }
@@ -120,8 +127,8 @@ int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req) @@ -120,8 +127,8 @@ int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
120 bool SrsHttpHandler::is_handler_valid(SrsHttpMessage* req, int& status_code, string& reason_phrase) 127 bool SrsHttpHandler::is_handler_valid(SrsHttpMessage* req, int& status_code, string& reason_phrase)
121 { 128 {
122 if (!req->match()->unmatched_url.empty()) { 129 if (!req->match()->unmatched_url.empty()) {
123 - status_code = HTTP_NotFound;  
124 - reason_phrase = HTTP_NotFound_str; 130 + status_code = SRS_CONSTS_HTTP_NotFound;
  131 + reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
125 132
126 return false; 133 return false;
127 } 134 }
@@ -534,7 +541,7 @@ SrsHttpMessage::SrsHttpMessage() @@ -534,7 +541,7 @@ SrsHttpMessage::SrsHttpMessage()
534 _uri = new SrsHttpUri(); 541 _uri = new SrsHttpUri();
535 _match = NULL; 542 _match = NULL;
536 _requires_crossdomain = false; 543 _requires_crossdomain = false;
537 - _http_ts_send_buffer = new char[HTTP_TS_SEND_BUFFER_SIZE]; 544 + _http_ts_send_buffer = new char[SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE];
538 } 545 }
539 546
540 SrsHttpMessage::~SrsHttpMessage() 547 SrsHttpMessage::~SrsHttpMessage()
@@ -608,27 +615,27 @@ string SrsHttpMessage::method_str() @@ -608,27 +615,27 @@ string SrsHttpMessage::method_str()
608 615
609 bool SrsHttpMessage::is_http_get() 616 bool SrsHttpMessage::is_http_get()
610 { 617 {
611 - return _header.method == HTTP_GET; 618 + return _header.method == SRS_CONSTS_HTTP_GET;
612 } 619 }
613 620
614 bool SrsHttpMessage::is_http_put() 621 bool SrsHttpMessage::is_http_put()
615 { 622 {
616 - return _header.method == HTTP_PUT; 623 + return _header.method == SRS_CONSTS_HTTP_PUT;
617 } 624 }
618 625
619 bool SrsHttpMessage::is_http_post() 626 bool SrsHttpMessage::is_http_post()
620 { 627 {
621 - return _header.method == HTTP_POST; 628 + return _header.method == SRS_CONSTS_HTTP_POST;
622 } 629 }
623 630
624 bool SrsHttpMessage::is_http_delete() 631 bool SrsHttpMessage::is_http_delete()
625 { 632 {
626 - return _header.method == HTTP_DELETE; 633 + return _header.method == SRS_CONSTS_HTTP_DELETE;
627 } 634 }
628 635
629 bool SrsHttpMessage::is_http_options() 636 bool SrsHttpMessage::is_http_options()
630 { 637 {
631 - return _header.method == HTTP_OPTIONS; 638 + return _header.method == SRS_CONSTS_HTTP_OPTIONS;
632 } 639 }
633 640
634 string SrsHttpMessage::uri() 641 string SrsHttpMessage::uri()
@@ -63,90 +63,90 @@ class SrsHttpHandler; @@ -63,90 +63,90 @@ class SrsHttpHandler;
63 #define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A 63 #define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
64 64
65 // 6.1.1 Status Code and Reason Phrase 65 // 6.1.1 Status Code and Reason Phrase
66 -#define HTTP_Continue 100  
67 -#define HTTP_SwitchingProtocols 101  
68 -#define HTTP_OK 200  
69 -#define HTTP_Created 201  
70 -#define HTTP_Accepted 202  
71 -#define HTTP_NonAuthoritativeInformation 203  
72 -#define HTTP_NoContent 204  
73 -#define HTTP_ResetContent 205  
74 -#define HTTP_PartialContent 206  
75 -#define HTTP_MultipleChoices 300  
76 -#define HTTP_MovedPermanently 301  
77 -#define HTTP_Found 302  
78 -#define HTTP_SeeOther 303  
79 -#define HTTP_NotModified 304  
80 -#define HTTP_UseProxy 305  
81 -#define HTTP_TemporaryRedirect 307  
82 -#define HTTP_BadRequest 400  
83 -#define HTTP_Unauthorized 401  
84 -#define HTTP_PaymentRequired 402  
85 -#define HTTP_Forbidden 403  
86 -#define HTTP_NotFound 404  
87 -#define HTTP_MethodNotAllowed 405  
88 -#define HTTP_NotAcceptable 406  
89 -#define HTTP_ProxyAuthenticationRequired 407  
90 -#define HTTP_RequestTimeout 408  
91 -#define HTTP_Conflict 409  
92 -#define HTTP_Gone 410  
93 -#define HTTP_LengthRequired 411  
94 -#define HTTP_PreconditionFailed 412  
95 -#define HTTP_RequestEntityTooLarge 413  
96 -#define HTTP_RequestURITooLarge 414  
97 -#define HTTP_UnsupportedMediaType 415  
98 -#define HTTP_RequestedRangeNotSatisfiable 416  
99 -#define HTTP_ExpectationFailed 417  
100 -#define HTTP_InternalServerError 500  
101 -#define HTTP_NotImplemented 501  
102 -#define HTTP_BadGateway 502  
103 -#define HTTP_ServiceUnavailable 503  
104 -#define HTTP_GatewayTimeout 504  
105 -#define HTTP_HTTPVersionNotSupported 505 66 +#define SRS_CONSTS_HTTP_Continue 100
  67 +#define SRS_CONSTS_HTTP_SwitchingProtocols 101
  68 +#define SRS_CONSTS_HTTP_OK 200
  69 +#define SRS_CONSTS_HTTP_Created 201
  70 +#define SRS_CONSTS_HTTP_Accepted 202
  71 +#define SRS_CONSTS_HTTP_NonAuthoritativeInformation 203
  72 +#define SRS_CONSTS_HTTP_NoContent 204
  73 +#define SRS_CONSTS_HTTP_ResetContent 205
  74 +#define SRS_CONSTS_HTTP_PartialContent 206
  75 +#define SRS_CONSTS_HTTP_MultipleChoices 300
  76 +#define SRS_CONSTS_HTTP_MovedPermanently 301
  77 +#define SRS_CONSTS_HTTP_Found 302
  78 +#define SRS_CONSTS_HTTP_SeeOther 303
  79 +#define SRS_CONSTS_HTTP_NotModified 304
  80 +#define SRS_CONSTS_HTTP_UseProxy 305
  81 +#define SRS_CONSTS_HTTP_TemporaryRedirect 307
  82 +#define SRS_CONSTS_HTTP_BadRequest 400
  83 +#define SRS_CONSTS_HTTP_Unauthorized 401
  84 +#define SRS_CONSTS_HTTP_PaymentRequired 402
  85 +#define SRS_CONSTS_HTTP_Forbidden 403
  86 +#define SRS_CONSTS_HTTP_NotFound 404
  87 +#define SRS_CONSTS_HTTP_MethodNotAllowed 405
  88 +#define SRS_CONSTS_HTTP_NotAcceptable 406
  89 +#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired 407
  90 +#define SRS_CONSTS_HTTP_RequestTimeout 408
  91 +#define SRS_CONSTS_HTTP_Conflict 409
  92 +#define SRS_CONSTS_HTTP_Gone 410
  93 +#define SRS_CONSTS_HTTP_LengthRequired 411
  94 +#define SRS_CONSTS_HTTP_PreconditionFailed 412
  95 +#define SRS_CONSTS_HTTP_RequestEntityTooLarge 413
  96 +#define SRS_CONSTS_HTTP_RequestURITooLarge 414
  97 +#define SRS_CONSTS_HTTP_UnsupportedMediaType 415
  98 +#define SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable 416
  99 +#define SRS_CONSTS_HTTP_ExpectationFailed 417
  100 +#define SRS_CONSTS_HTTP_InternalServerError 500
  101 +#define SRS_CONSTS_HTTP_NotImplemented 501
  102 +#define SRS_CONSTS_HTTP_BadGateway 502
  103 +#define SRS_CONSTS_HTTP_ServiceUnavailable 503
  104 +#define SRS_CONSTS_HTTP_GatewayTimeout 504
  105 +#define SRS_CONSTS_HTTP_HTTPVersionNotSupported 505
106 106
107 -#define HTTP_Continue_str "Continue"  
108 -#define HTTP_SwitchingProtocols_str "Switching Protocols"  
109 -#define HTTP_OK_str "OK"  
110 -#define HTTP_Created_str "Created "  
111 -#define HTTP_Accepted_str "Accepted"  
112 -#define HTTP_NonAuthoritativeInformation_str "Non Authoritative Information "  
113 -#define HTTP_NoContent_str "No Content "  
114 -#define HTTP_ResetContent_str "Reset Content"  
115 -#define HTTP_PartialContent_str "Partial Content"  
116 -#define HTTP_MultipleChoices_str "Multiple Choices "  
117 -#define HTTP_MovedPermanently_str "Moved Permanently"  
118 -#define HTTP_Found_str "Found"  
119 -#define HTTP_SeeOther_str "See Other"  
120 -#define HTTP_NotModified_str "Not Modified "  
121 -#define HTTP_UseProxy_str "Use Proxy"  
122 -#define HTTP_TemporaryRedirect_str "Temporary Redirect "  
123 -#define HTTP_BadRequest_str "Bad Request"  
124 -#define HTTP_Unauthorized_str "Unauthorized"  
125 -#define HTTP_PaymentRequired_str "Payment Required "  
126 -#define HTTP_Forbidden_str "Forbidden "  
127 -#define HTTP_NotFound_str "Not Found"  
128 -#define HTTP_MethodNotAllowed_str "Method Not Allowed"  
129 -#define HTTP_NotAcceptable_str "Not Acceptable "  
130 -#define HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required "  
131 -#define HTTP_RequestTimeout_str "Request Timeout"  
132 -#define HTTP_Conflict_str "Conflict"  
133 -#define HTTP_Gone_str "Gone"  
134 -#define HTTP_LengthRequired_str "Length Required"  
135 -#define HTTP_PreconditionFailed_str "Precondition Failed"  
136 -#define HTTP_RequestEntityTooLarge_str "Request Entity Too Large "  
137 -#define HTTP_RequestURITooLarge_str "Request URI Too Large"  
138 -#define HTTP_UnsupportedMediaType_str "Unsupported Media Type"  
139 -#define HTTP_RequestedRangeNotSatisfiable_str "Requested Range Not Satisfiable"  
140 -#define HTTP_ExpectationFailed_str "Expectation Failed "  
141 -#define HTTP_InternalServerError_str "Internal Server Error "  
142 -#define HTTP_NotImplemented_str "Not Implemented"  
143 -#define HTTP_BadGateway_str "Bad Gateway"  
144 -#define HTTP_ServiceUnavailable_str "Service Unavailable"  
145 -#define HTTP_GatewayTimeout_str "Gateway Timeout"  
146 -#define HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported" 107 +#define SRS_CONSTS_HTTP_Continue_str "Continue"
  108 +#define SRS_CONSTS_HTTP_SwitchingProtocols_str "Switching Protocols"
  109 +#define SRS_CONSTS_HTTP_OK_str "OK"
  110 +#define SRS_CONSTS_HTTP_Created_str "Created "
  111 +#define SRS_CONSTS_HTTP_Accepted_str "Accepted"
  112 +#define SRS_CONSTS_HTTP_NonAuthoritativeInformation_str "Non Authoritative Information "
  113 +#define SRS_CONSTS_HTTP_NoContent_str "No Content "
  114 +#define SRS_CONSTS_HTTP_ResetContent_str "Reset Content"
  115 +#define SRS_CONSTS_HTTP_PartialContent_str "Partial Content"
  116 +#define SRS_CONSTS_HTTP_MultipleChoices_str "Multiple Choices "
  117 +#define SRS_CONSTS_HTTP_MovedPermanently_str "Moved Permanently"
  118 +#define SRS_CONSTS_HTTP_Found_str "Found"
  119 +#define SRS_CONSTS_HTTP_SeeOther_str "See Other"
  120 +#define SRS_CONSTS_HTTP_NotModified_str "Not Modified "
  121 +#define SRS_CONSTS_HTTP_UseProxy_str "Use Proxy"
  122 +#define SRS_CONSTS_HTTP_TemporaryRedirect_str "Temporary Redirect "
  123 +#define SRS_CONSTS_HTTP_BadRequest_str "Bad Request"
  124 +#define SRS_CONSTS_HTTP_Unauthorized_str "Unauthorized"
  125 +#define SRS_CONSTS_HTTP_PaymentRequired_str "Payment Required "
  126 +#define SRS_CONSTS_HTTP_Forbidden_str "Forbidden "
  127 +#define SRS_CONSTS_HTTP_NotFound_str "Not Found"
  128 +#define SRS_CONSTS_HTTP_MethodNotAllowed_str "Method Not Allowed"
  129 +#define SRS_CONSTS_HTTP_NotAcceptable_str "Not Acceptable "
  130 +#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required "
  131 +#define SRS_CONSTS_HTTP_RequestTimeout_str "Request Timeout"
  132 +#define SRS_CONSTS_HTTP_Conflict_str "Conflict"
  133 +#define SRS_CONSTS_HTTP_Gone_str "Gone"
  134 +#define SRS_CONSTS_HTTP_LengthRequired_str "Length Required"
  135 +#define SRS_CONSTS_HTTP_PreconditionFailed_str "Precondition Failed"
  136 +#define SRS_CONSTS_HTTP_RequestEntityTooLarge_str "Request Entity Too Large "
  137 +#define SRS_CONSTS_HTTP_RequestURITooLarge_str "Request URI Too Large"
  138 +#define SRS_CONSTS_HTTP_UnsupportedMediaType_str "Unsupported Media Type"
  139 +#define SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str "Requested Range Not Satisfiable"
  140 +#define SRS_CONSTS_HTTP_ExpectationFailed_str "Expectation Failed "
  141 +#define SRS_CONSTS_HTTP_InternalServerError_str "Internal Server Error "
  142 +#define SRS_CONSTS_HTTP_NotImplemented_str "Not Implemented"
  143 +#define SRS_CONSTS_HTTP_BadGateway_str "Bad Gateway"
  144 +#define SRS_CONSTS_HTTP_ServiceUnavailable_str "Service Unavailable"
  145 +#define SRS_CONSTS_HTTP_GatewayTimeout_str "Gateway Timeout"
  146 +#define SRS_CONSTS_HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported"
147 147
148 // @see SrsHttpMessage._http_ts_send_buffer 148 // @see SrsHttpMessage._http_ts_send_buffer
149 -#define HTTP_TS_SEND_BUFFER_SIZE 4096 149 +#define SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE 4096
150 150
151 // linux path seprator 151 // linux path seprator
152 #define __PATH_SEP '/' 152 #define __PATH_SEP '/'
@@ -54,8 +54,8 @@ bool SrsApiRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::st @@ -54,8 +54,8 @@ bool SrsApiRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::st
54 } 54 }
55 55
56 if (req->match()->matched_url.length() != 1) { 56 if (req->match()->matched_url.length() != 1) {
57 - status_code = HTTP_NotFound;  
58 - reason_phrase = HTTP_NotFound_str; 57 + status_code = SRS_CONSTS_HTTP_NotFound;
  58 + reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
59 return false; 59 return false;
60 } 60 }
61 61
@@ -118,8 +118,8 @@ int SrsHttpRoot::best_match(const char* path, int length, SrsHttpHandlerMatch** @@ -118,8 +118,8 @@ int SrsHttpRoot::best_match(const char* path, int length, SrsHttpHandlerMatch**
118 118
119 bool SrsHttpRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase) 119 bool SrsHttpRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
120 { 120 {
121 - status_code = HTTP_InternalServerError;  
122 - reason_phrase = HTTP_InternalServerError_str; 121 + status_code = SRS_CONSTS_HTTP_InternalServerError;
  122 + reason_phrase = SRS_CONSTS_HTTP_InternalServerError_str;
123 123
124 return false; 124 return false;
125 } 125 }
@@ -153,8 +153,8 @@ bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std:: @@ -153,8 +153,8 @@ bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std::
153 if (::access(fullpath.c_str(), F_OK | R_OK) < 0) { 153 if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
154 srs_warn("check file %s does not exists", fullpath.c_str()); 154 srs_warn("check file %s does not exists", fullpath.c_str());
155 155
156 - status_code = HTTP_NotFound;  
157 - reason_phrase = HTTP_NotFound_str; 156 + status_code = SRS_CONSTS_HTTP_NotFound;
  157 + reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
158 return false; 158 return false;
159 } 159 }
160 160
@@ -272,7 +272,7 @@ int SrsHttpVhost::response_flv_file(SrsSocket* skt, SrsHttpMessage* req, string @@ -272,7 +272,7 @@ int SrsHttpVhost::response_flv_file(SrsSocket* skt, SrsHttpMessage* req, string
272 272
273 while (left > 0) { 273 while (left > 0) {
274 ssize_t nread = -1; 274 ssize_t nread = -1;
275 - if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) { 275 + if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
276 srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret); 276 srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
277 break; 277 break;
278 } 278 }
@@ -377,7 +377,7 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string @@ -377,7 +377,7 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string
377 // send data 377 // send data
378 while (left > 0) { 378 while (left > 0) {
379 ssize_t nread = -1; 379 ssize_t nread = -1;
380 - if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) { 380 + if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
381 return ret; 381 return ret;
382 } 382 }
383 383
@@ -427,7 +427,7 @@ int SrsHttpVhost::response_ts_file(SrsSocket* skt, SrsHttpMessage* req, string f @@ -427,7 +427,7 @@ int SrsHttpVhost::response_ts_file(SrsSocket* skt, SrsHttpMessage* req, string f
427 427
428 while (left > 0) { 428 while (left > 0) {
429 ssize_t nread = -1; 429 ssize_t nread = -1;
430 - if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) { 430 + if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
431 srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret); 431 srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
432 break; 432 break;
433 } 433 }