正在显示
5 个修改的文件
包含
71 行增加
和
1 行删除
| @@ -357,7 +357,57 @@ vector<string> srs_string_split(string str, string flag) | @@ -357,7 +357,57 @@ vector<string> srs_string_split(string str, string flag) | ||
| 357 | 357 | ||
| 358 | while ((pos = s.find(flag)) != string::npos) { | 358 | while ((pos = s.find(flag)) != string::npos) { |
| 359 | arr.push_back(s.substr(0, pos)); | 359 | arr.push_back(s.substr(0, pos)); |
| 360 | - s = s.substr(pos + 1); | 360 | + s = s.substr(pos + flag.length()); |
| 361 | + } | ||
| 362 | + | ||
| 363 | + if (!s.empty()) { | ||
| 364 | + arr.push_back(s); | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + return arr; | ||
| 368 | +} | ||
| 369 | + | ||
| 370 | +string srs_string_min_match(string str, vector<string> flags) | ||
| 371 | +{ | ||
| 372 | + string match; | ||
| 373 | + | ||
| 374 | + size_t min_pos = string::npos; | ||
| 375 | + for (vector<string>::iterator it = flags.begin(); it != flags.end(); ++it) { | ||
| 376 | + string flag = *it; | ||
| 377 | + | ||
| 378 | + size_t pos = str.find(flag); | ||
| 379 | + if (pos == string::npos) { | ||
| 380 | + continue; | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + if (min_pos == string::npos || pos < min_pos) { | ||
| 384 | + min_pos = pos; | ||
| 385 | + match = flag; | ||
| 386 | + } | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + return match; | ||
| 390 | +} | ||
| 391 | + | ||
| 392 | +vector<string> srs_string_split(string str, vector<string> flags) | ||
| 393 | +{ | ||
| 394 | + vector<string> arr; | ||
| 395 | + | ||
| 396 | + size_t pos = string::npos; | ||
| 397 | + string s = str; | ||
| 398 | + | ||
| 399 | + while (true) { | ||
| 400 | + string flag = srs_string_min_match(s, flags); | ||
| 401 | + if (flag.empty()) { | ||
| 402 | + break; | ||
| 403 | + } | ||
| 404 | + | ||
| 405 | + if ((pos = s.find(flag)) == string::npos) { | ||
| 406 | + break; | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + arr.push_back(s.substr(0, pos)); | ||
| 410 | + s = s.substr(pos + flag.length()); | ||
| 361 | } | 411 | } |
| 362 | 412 | ||
| 363 | if (!s.empty()) { | 413 | if (!s.empty()) { |
| @@ -90,6 +90,7 @@ extern bool srs_string_starts_with(std::string str, std::string flag0, std::stri | @@ -90,6 +90,7 @@ extern bool srs_string_starts_with(std::string str, std::string flag0, std::stri | ||
| 90 | extern bool srs_string_contains(std::string str, std::string flag); | 90 | extern bool srs_string_contains(std::string str, std::string flag); |
| 91 | // split the string by flag to array. | 91 | // split the string by flag to array. |
| 92 | extern std::vector<std::string> srs_string_split(std::string str, std::string flag); | 92 | extern std::vector<std::string> srs_string_split(std::string str, std::string flag); |
| 93 | +extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags); | ||
| 93 | 94 | ||
| 94 | // create dir recursively | 95 | // create dir recursively |
| 95 | extern int srs_create_dir_recursively(std::string dir); | 96 | extern int srs_create_dir_recursively(std::string dir); |
trunk/src/protocol/srs_http_stack.cpp
100755 → 100644
| @@ -2989,6 +2989,9 @@ int SrsHttpUri::initialize(string _url) | @@ -2989,6 +2989,9 @@ int SrsHttpUri::initialize(string _url) | ||
| 2989 | { | 2989 | { |
| 2990 | int ret = ERROR_SUCCESS; | 2990 | int ret = ERROR_SUCCESS; |
| 2991 | 2991 | ||
| 2992 | + port = 0; | ||
| 2993 | + schema = host = path = query = ""; | ||
| 2994 | + | ||
| 2992 | url = _url; | 2995 | url = _url; |
| 2993 | const char* purl = url.c_str(); | 2996 | const char* purl = url.c_str(); |
| 2994 | 2997 |
| @@ -630,6 +630,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_integer(string name) | @@ -630,6 +630,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_integer(string name) | ||
| 630 | return prop; | 630 | return prop; |
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | +SrsJsonAny* SrsJsonObject::ensure_property_number(string name) | ||
| 634 | +{ | ||
| 635 | + SrsJsonAny* prop = get_property(name); | ||
| 636 | + | ||
| 637 | + if (!prop) { | ||
| 638 | + return NULL; | ||
| 639 | + } | ||
| 640 | + | ||
| 641 | + if (!prop->is_number()) { | ||
| 642 | + return NULL; | ||
| 643 | + } | ||
| 644 | + | ||
| 645 | + return prop; | ||
| 646 | +} | ||
| 647 | + | ||
| 633 | SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name) | 648 | SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name) |
| 634 | { | 649 | { |
| 635 | SrsJsonAny* prop = get_property(name); | 650 | SrsJsonAny* prop = get_property(name); |
| @@ -157,6 +157,7 @@ public: | @@ -157,6 +157,7 @@ public: | ||
| 157 | virtual SrsJsonAny* get_property(std::string name); | 157 | virtual SrsJsonAny* get_property(std::string name); |
| 158 | virtual SrsJsonAny* ensure_property_string(std::string name); | 158 | virtual SrsJsonAny* ensure_property_string(std::string name); |
| 159 | virtual SrsJsonAny* ensure_property_integer(std::string name); | 159 | virtual SrsJsonAny* ensure_property_integer(std::string name); |
| 160 | + virtual SrsJsonAny* ensure_property_number(std::string name); | ||
| 160 | virtual SrsJsonAny* ensure_property_boolean(std::string name); | 161 | virtual SrsJsonAny* ensure_property_boolean(std::string name); |
| 161 | virtual SrsJsonAny* ensure_property_object(std::string name); | 162 | virtual SrsJsonAny* ensure_property_object(std::string name); |
| 162 | virtual SrsJsonAny* ensure_property_array(std::string name); | 163 | virtual SrsJsonAny* ensure_property_array(std::string name); |
-
请 注册 或 登录 后发表评论