mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix sip message parse error
This commit is contained in:
parent
7826c743e4
commit
95b869245b
3 changed files with 43 additions and 13 deletions
|
@ -441,6 +441,10 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
||||||
|
|
||||||
if (req->is_register()) {
|
if (req->is_register()) {
|
||||||
std::vector<std::string> serial = srs_string_split(srs_string_replace(req->uri,"sip:", ""), "@");
|
std::vector<std::string> serial = srs_string_split(srs_string_replace(req->uri,"sip:", ""), "@");
|
||||||
|
if (serial.empty()){
|
||||||
|
return srs_error_new(ERROR_GB28181_SIP_PRASE_FAILED, "register string split");
|
||||||
|
}
|
||||||
|
|
||||||
if (serial.at(0) != config->sip_serial){
|
if (serial.at(0) != config->sip_serial){
|
||||||
srs_warn("gb28181: client:%s request serial and server serial inconformity(%s:%s)",
|
srs_warn("gb28181: client:%s request serial and server serial inconformity(%s:%s)",
|
||||||
req->sip_auth_id.c_str(), serial.at(0).c_str(), config->sip_serial.c_str());
|
req->sip_auth_id.c_str(), serial.at(0).c_str(), config->sip_serial.c_str());
|
||||||
|
|
|
@ -366,6 +366,7 @@
|
||||||
#define ERROR_GB28181_SIP_CH_OFFLINE 6012
|
#define ERROR_GB28181_SIP_CH_OFFLINE 6012
|
||||||
#define ERROR_GB28181_SIP_CH_NOTEXIST 6013
|
#define ERROR_GB28181_SIP_CH_NOTEXIST 6013
|
||||||
#define ERROR_GB28181_SIP_RAW_DATA_FAILED 6014
|
#define ERROR_GB28181_SIP_RAW_DATA_FAILED 6014
|
||||||
|
#define ERROR_GB28181_SIP_PRASE_FAILED 6015
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// HTTP API error.
|
// HTTP API error.
|
||||||
|
|
|
@ -328,6 +328,10 @@ srs_error_t SrsSipStack::parse_xml(std::string xml_msg, std::map<std::string, st
|
||||||
|
|
||||||
//<DeviceList Num="2"> get DeviceList
|
//<DeviceList Num="2"> get DeviceList
|
||||||
std::vector<string> vec = srs_string_split(key, " ");
|
std::vector<string> vec = srs_string_split(key, " ");
|
||||||
|
if (vec.empty()){
|
||||||
|
return srs_error_new(ERROR_GB28181_SIP_PRASE_FAILED, "prase xml");
|
||||||
|
}
|
||||||
|
|
||||||
key = vec.at(0);
|
key = vec.at(0);
|
||||||
|
|
||||||
/*xml element to map
|
/*xml element to map
|
||||||
|
@ -378,6 +382,10 @@ srs_error_t SrsSipStack::parse_xml(std::string xml_msg, std::map<std::string, st
|
||||||
}else {
|
}else {
|
||||||
//<DeviceList Num="2"> get DeviceList
|
//<DeviceList Num="2"> get DeviceList
|
||||||
std::vector<string> vec = srs_string_split(key, " ");
|
std::vector<string> vec = srs_string_split(key, " ");
|
||||||
|
if (vec.empty()){
|
||||||
|
return srs_error_new(ERROR_GB28181_SIP_PRASE_FAILED, "prase xml");
|
||||||
|
}
|
||||||
|
|
||||||
key = vec.at(0);
|
key = vec.at(0);
|
||||||
|
|
||||||
//key to map by xml_layer
|
//key to map by xml_layer
|
||||||
|
@ -411,7 +419,13 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
std::vector<std::string> header_body = srs_string_split(recv_msg, SRS_RTSP_CRLFCRLF);
|
std::vector<std::string> header_body = srs_string_split(recv_msg, SRS_RTSP_CRLFCRLF);
|
||||||
|
if (header_body.empty()){
|
||||||
|
return srs_error_new(ERROR_GB28181_SIP_PRASE_FAILED, "parse reques message");
|
||||||
|
}
|
||||||
|
|
||||||
std::string header = header_body.at(0);
|
std::string header = header_body.at(0);
|
||||||
|
//Must be added SRS_RTSP_CRLFCRLF in order to handle the last line header
|
||||||
|
header += SRS_RTSP_CRLFCRLF;
|
||||||
std::string body = "";
|
std::string body = "";
|
||||||
|
|
||||||
if (header_body.size() > 1){
|
if (header_body.size() > 1){
|
||||||
|
@ -435,7 +449,7 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
newline_start = p;
|
newline_start = p;
|
||||||
|
|
||||||
if (firstline == ""){
|
if (firstline == ""){
|
||||||
firstline = oneline;
|
firstline = srs_string_replace(oneline, "\r\n", "");
|
||||||
srs_info("sip: first line=%s", firstline.c_str());
|
srs_info("sip: first line=%s", firstline.c_str());
|
||||||
}else{
|
}else{
|
||||||
size_t pos = oneline.find(":");
|
size_t pos = oneline.find(":");
|
||||||
|
@ -450,7 +464,7 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
|
|
||||||
if (!strcasecmp(phead, "call-id:")) {
|
if (!strcasecmp(phead, "call-id:")) {
|
||||||
std::vector<std::string> vec_callid = srs_string_split(content, " ");
|
std::vector<std::string> vec_callid = srs_string_split(content, " ");
|
||||||
req->call_id = vec_callid.at(0);
|
req->call_id = vec_callid.empty() ? "" : vec_callid.at(0);
|
||||||
}
|
}
|
||||||
else if (!strcasecmp(phead, "contact:")) {
|
else if (!strcasecmp(phead, "contact:")) {
|
||||||
req->contact = content;
|
req->contact = content;
|
||||||
|
@ -466,8 +480,9 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
}
|
}
|
||||||
else if (!strcasecmp(phead, "cseq:")) {
|
else if (!strcasecmp(phead, "cseq:")) {
|
||||||
std::vector<std::string> vec_seq = srs_string_split(content, " ");
|
std::vector<std::string> vec_seq = srs_string_split(content, " ");
|
||||||
req->seq = strtoul(vec_seq.at(0).c_str(), NULL, 10);
|
std::string seq = vec_seq.empty() ? "" : vec_seq.at(0);
|
||||||
req->method = vec_seq.at(1);
|
req->seq = strtoul(seq.c_str(), NULL, 10);
|
||||||
|
req->method = vec_seq.size() > 0 ? vec_seq.at(1) : "";
|
||||||
}
|
}
|
||||||
else if (!strcasecmp(phead, "from:")) {
|
else if (!strcasecmp(phead, "from:")) {
|
||||||
content = srs_string_replace(content, "sip:", "");
|
content = srs_string_replace(content, "sip:", "");
|
||||||
|
@ -484,7 +499,6 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcasecmp(phead, "via:")) {
|
else if (!strcasecmp(phead, "via:")) {
|
||||||
//std::vector<std::string> vec_via = srs_string_split(content, ";");
|
|
||||||
req->via = content;
|
req->via = content;
|
||||||
req->branch = srs_sip_get_param(content.c_str(), "branch");
|
req->branch = srs_sip_get_param(content.c_str(), "branch");
|
||||||
}
|
}
|
||||||
|
@ -516,25 +530,32 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> method_uri_ver = srs_string_split(firstline, " ");
|
std::vector<std::string> method_uri_ver = srs_string_split(firstline, " ");
|
||||||
|
|
||||||
|
if (method_uri_ver.empty()) {
|
||||||
|
return srs_error_new(ERROR_GB28181_SIP_PRASE_FAILED, "parse request firstline is empty");
|
||||||
|
}
|
||||||
|
|
||||||
//respone first line text:SIP/2.0 200 OK
|
//respone first line text:SIP/2.0 200 OK
|
||||||
if (!strcasecmp(method_uri_ver.at(0).c_str(), "sip/2.0")) {
|
if (!strcasecmp(method_uri_ver.at(0).c_str(), "sip/2.0")) {
|
||||||
req->cmdtype = SrsSipCmdRespone;
|
req->cmdtype = SrsSipCmdRespone;
|
||||||
//req->method= vec_seq.at(1);
|
//req->method= vec_seq.at(1);
|
||||||
req->status = method_uri_ver.at(1);
|
req->status = method_uri_ver.size() > 0 ? method_uri_ver.at(1) : "";
|
||||||
req->version = method_uri_ver.at(0);
|
req->version = method_uri_ver.at(0);
|
||||||
req->uri = req->from;
|
req->uri = req->from;
|
||||||
|
|
||||||
vector<string> str = srs_string_split(req->to, "@");
|
vector<string> str = srs_string_split(req->to, "@");
|
||||||
req->sip_auth_id = srs_string_replace(str.at(0), "sip:", "");
|
std::string ss = str.empty() ? "" : str.at(0);
|
||||||
|
req->sip_auth_id = srs_string_replace(ss, "sip:", "");
|
||||||
|
|
||||||
}else {//request first line text :MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
|
}else {//request first line text :MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
|
||||||
req->cmdtype = SrsSipCmdRequest;
|
req->cmdtype = SrsSipCmdRequest;
|
||||||
req->method= method_uri_ver.at(0);
|
req->method= method_uri_ver.at(0);
|
||||||
req->uri = method_uri_ver.at(1);
|
req->uri = method_uri_ver.size() > 0 ? method_uri_ver.at(1) : "";
|
||||||
req->version = method_uri_ver.at(2);
|
req->version = method_uri_ver.size() > 1 ? method_uri_ver.at(2) : "";
|
||||||
|
|
||||||
vector<string> str = srs_string_split(req->from, "@");
|
vector<string> str = srs_string_split(req->from, "@");
|
||||||
req->sip_auth_id = srs_string_replace(str.at(0), "sip:", "");
|
std::string ss = str.empty() ? "" : str.at(0);
|
||||||
|
req->sip_auth_id = srs_string_replace(ss, "sip:", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
req->sip_username = req->sip_auth_id;
|
req->sip_username = req->sip_auth_id;
|
||||||
|
@ -625,9 +646,13 @@ std::string SrsSipStack::get_sip_via(SrsSipRequest const *req)
|
||||||
{
|
{
|
||||||
std::string via = srs_string_replace(req->via, SRS_SIP_VERSION"/UDP ", "");
|
std::string via = srs_string_replace(req->via, SRS_SIP_VERSION"/UDP ", "");
|
||||||
std::vector<std::string> vec_via = srs_string_split(via, ";");
|
std::vector<std::string> vec_via = srs_string_split(via, ";");
|
||||||
std::string ip_port = vec_via.at(0);
|
|
||||||
|
std::string ip_port = vec_via.empty() ? "" : vec_via.at(0);
|
||||||
std::vector<std::string> vec_ip_port = srs_string_split(ip_port, ":");
|
std::vector<std::string> vec_ip_port = srs_string_split(ip_port, ":");
|
||||||
|
|
||||||
|
std::string ip = vec_ip_port.empty() ? "" : vec_ip_port.at(0);
|
||||||
|
std::string port = vec_ip_port.size() > 0 ? vec_ip_port.at(1) : "";
|
||||||
|
|
||||||
std::string branch, rport, received;
|
std::string branch, rport, received;
|
||||||
if (req->branch.empty()){
|
if (req->branch.empty()){
|
||||||
branch = "";
|
branch = "";
|
||||||
|
@ -635,8 +660,8 @@ std::string SrsSipStack::get_sip_via(SrsSipRequest const *req)
|
||||||
branch = ";branch=" + req->branch;
|
branch = ";branch=" + req->branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
received = ";received=" + vec_ip_port.at(0);
|
received = ";received=" + ip;
|
||||||
rport = ";rport=" + vec_ip_port.at(1);
|
rport = ";rport=" + port;
|
||||||
|
|
||||||
return SRS_SIP_VERSION"/UDP " + ip_port + rport + received + branch;
|
return SRS_SIP_VERSION"/UDP " + ip_port + rport + received + branch;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue