2020-03-19 16:01:48 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2020-03-31 14:30:57 +00:00
|
|
|
* Copyright (c) 2013-2020 Lixin
|
2020-03-19 16:01:48 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRS_PROTOCOL_SIP_HPP
|
|
|
|
#define SRS_PROTOCOL_SIP_HPP
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#if !defined(SRS_EXPORT_LIBRTMP)
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <srs_kernel_consts.hpp>
|
|
|
|
#include <srs_rtsp_stack.hpp>
|
|
|
|
|
|
|
|
class SrsBuffer;
|
|
|
|
class SrsSimpleStream;
|
|
|
|
class SrsAudioFrame;
|
|
|
|
|
|
|
|
// SIP methods
|
|
|
|
#define SRS_SIP_METHOD_REGISTER "REGISTER"
|
|
|
|
#define SRS_SIP_METHOD_MESSAGE "MESSAGE"
|
|
|
|
#define SRS_SIP_METHOD_INVITE "INVITE"
|
|
|
|
#define SRS_SIP_METHOD_ACK "ACK"
|
|
|
|
#define SRS_SIP_METHOD_BYE "BYE"
|
|
|
|
|
|
|
|
// SIP-Version
|
|
|
|
#define SRS_SIP_VERSION "SIP/2.0"
|
|
|
|
#define SRS_SIP_USER_AGENT RTMP_SIG_SRS_SERVER
|
|
|
|
|
|
|
|
|
|
|
|
enum SrsSipCmdType{
|
|
|
|
SrsSipCmdRequest=0,
|
|
|
|
SrsSipCmdRespone=1
|
|
|
|
};
|
|
|
|
|
2020-04-05 05:51:19 +00:00
|
|
|
std::string srs_sip_get_utc_date();
|
|
|
|
|
2020-03-19 16:01:48 +00:00
|
|
|
class SrsSipRequest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//sip header member
|
|
|
|
std::string method;
|
|
|
|
std::string uri;
|
|
|
|
std::string version;
|
|
|
|
std::string status;
|
|
|
|
|
|
|
|
std::string via;
|
|
|
|
std::string from;
|
|
|
|
std::string to;
|
|
|
|
std::string from_tag;
|
|
|
|
std::string to_tag;
|
|
|
|
std::string branch;
|
|
|
|
|
|
|
|
std::string call_id;
|
|
|
|
long seq;
|
|
|
|
|
|
|
|
std::string contact;
|
|
|
|
std::string user_agent;
|
|
|
|
|
|
|
|
std::string content_type;
|
|
|
|
long content_length;
|
|
|
|
|
|
|
|
long expires;
|
|
|
|
int max_forwards;
|
|
|
|
|
2020-03-30 16:39:10 +00:00
|
|
|
std::string www_authenticate;
|
|
|
|
std::string authorization;
|
|
|
|
|
2020-03-19 16:01:48 +00:00
|
|
|
public:
|
|
|
|
std::string serial;
|
|
|
|
std::string realm;
|
|
|
|
std::string sip_auth_id;
|
|
|
|
std::string sip_auth_pwd;
|
|
|
|
std::string sip_username;
|
|
|
|
std::string peer_ip;
|
|
|
|
int peer_port;
|
|
|
|
std::string host;
|
|
|
|
int host_port;
|
|
|
|
SrsSipCmdType cmdtype;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SrsRtspSdp* sdp;
|
|
|
|
SrsRtspTransport* transport;
|
|
|
|
public:
|
|
|
|
SrsSipRequest();
|
|
|
|
virtual ~SrsSipRequest();
|
|
|
|
public:
|
|
|
|
virtual bool is_register();
|
|
|
|
virtual bool is_invite();
|
|
|
|
virtual bool is_message();
|
|
|
|
virtual bool is_ack();
|
|
|
|
virtual bool is_bye();
|
|
|
|
|
|
|
|
virtual void copy(SrsSipRequest* src);
|
|
|
|
public:
|
|
|
|
virtual std::string get_cmdtype_str();
|
|
|
|
};
|
|
|
|
|
|
|
|
// The gb28181 sip protocol stack.
|
|
|
|
class SrsSipStack
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// The cached bytes buffer.
|
|
|
|
SrsSimpleStream* buf;
|
|
|
|
public:
|
|
|
|
SrsSipStack();
|
|
|
|
virtual ~SrsSipStack();
|
|
|
|
public:
|
|
|
|
virtual srs_error_t parse_request(SrsSipRequest** preq, const char *recv_msg, int nb_buf);
|
|
|
|
protected:
|
|
|
|
virtual srs_error_t do_parse_request(SrsSipRequest* req, const char *recv_msg);
|
|
|
|
|
2020-04-02 08:56:03 +00:00
|
|
|
private:
|
|
|
|
//response from
|
|
|
|
virtual std::string get_sip_from(SrsSipRequest const *req);
|
|
|
|
//response to
|
|
|
|
virtual std::string get_sip_to(SrsSipRequest const *req);
|
|
|
|
//response via
|
|
|
|
virtual std::string get_sip_via(SrsSipRequest const *req);
|
|
|
|
|
2020-03-19 16:01:48 +00:00
|
|
|
public:
|
2020-04-02 08:56:03 +00:00
|
|
|
//response: request sent by the sip-agent, wait for sip-server response
|
2020-03-30 16:39:10 +00:00
|
|
|
virtual void resp_status(std::stringstream& ss, SrsSipRequest *req);
|
|
|
|
virtual void resp_keepalive(std::stringstream& ss, SrsSipRequest *req);
|
2020-04-02 08:56:03 +00:00
|
|
|
|
|
|
|
//request: request sent by the sip-server, wait for sip-agent response
|
2020-03-30 16:39:10 +00:00
|
|
|
virtual void req_invite(std::stringstream& ss, SrsSipRequest *req, std::string ip, int port, uint32_t ssrc);
|
2020-04-02 08:56:03 +00:00
|
|
|
virtual void req_ack(std::stringstream& ss, SrsSipRequest *req);
|
2020-03-30 16:39:10 +00:00
|
|
|
virtual void req_bye(std::stringstream& ss, SrsSipRequest *req);
|
|
|
|
virtual void req_401_unauthorized(std::stringstream& ss, SrsSipRequest *req);
|
2020-03-19 16:01:48 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|