├── librtmp ├── lib │ ├── librtmp.so │ ├── librtmp.a │ ├── librtmp.so.1 │ └── pkgconfig │ │ └── librtmp.pc └── include │ └── librtmp │ ├── http.h │ ├── log.h │ └── amf.h ├── prtsp_conn.cpp ├── prtsp_client.cpp ├── README.md ├── prtsp_server.h ├── ptask_timer.h ├── pmedia_client.h ├── pstring.h ├── Makefile ├── pmedia_client.cpp ├── psip_conn.h ├── prtmp_client.h ├── pencoder.h ├── pdecoder.h ├── plog.h ├── pmedia.cpp ├── pmanager.h ├── prtsp_conn.h ├── ptask.h ├── pstring.cpp ├── psip_server.h ├── prtsp_client.h ├── ptask_timer.cpp ├── prtsp_server.cpp ├── psip_client.h ├── osip2 └── include │ └── osipparser2 │ ├── osip_md5.h │ ├── headers │ ├── osip_allow.h │ ├── osip_mime_version.h │ ├── osip_content_encoding.h │ ├── osip_content_length.h │ ├── osip_alert_info.h │ ├── osip_error_info.h │ ├── osip_accept.h │ ├── osip_content_disposition.h │ ├── osip_call_info.h │ ├── osip_cseq.h │ ├── osip_content_type.h │ ├── osip_call_id.h │ ├── osip_accept_language.h │ ├── osip_header.h │ ├── osip_route.h │ ├── osip_accept_encoding.h │ ├── osip_record_route.h │ ├── osip_contact.h │ ├── osip_from.h │ ├── osip_to.h │ ├── osip_via.h │ ├── osip_proxy_authentication_info.h │ ├── osip_authentication_info.h │ ├── osip_proxy_authenticate.h │ └── osip_www_authenticate.h │ ├── osip_headers.h │ ├── osip_body.h │ ├── osip_list.h │ └── osip_const.h ├── ptask.cpp ├── prtsp_comm.h ├── pmanager.cpp ├── plog.cpp ├── psip_server.cpp ├── prtsp_comm.cpp └── psip_conn.cpp /librtmp/lib/librtmp.so: -------------------------------------------------------------------------------- 1 | librtmp.so.1 -------------------------------------------------------------------------------- /prtsp_conn.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenjim301/pmedia/HEAD/prtsp_conn.cpp -------------------------------------------------------------------------------- /prtsp_client.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenjim301/pmedia/HEAD/prtsp_client.cpp -------------------------------------------------------------------------------- /librtmp/lib/librtmp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenjim301/pmedia/HEAD/librtmp/lib/librtmp.a -------------------------------------------------------------------------------- /librtmp/lib/librtmp.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greenjim301/pmedia/HEAD/librtmp/lib/librtmp.so.1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pmedia 2 | 简单的流媒体服务器。 3 |
支持RTSP发流。 4 |
支持RTSP收流。 5 |
支持GB28181收流。 6 |
支持RTMP收流。 7 |
支持流复用。 8 |
更多介绍详见https://blog.csdn.net/greenjim301/article/details/89554717 9 | -------------------------------------------------------------------------------- /prtsp_server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ptask.h" 4 | #include "pstring.h" 5 | 6 | class PRtspServer : public PTask 7 | { 8 | public: 9 | PRtspServer(PString& ip, uint16_t port); 10 | ~PRtspServer(); 11 | 12 | void OnRun(); 13 | 14 | private: 15 | PString m_ip; 16 | uint16_t m_port; 17 | int m_sock; 18 | }; 19 | -------------------------------------------------------------------------------- /librtmp/lib/pkgconfig/librtmp.pc: -------------------------------------------------------------------------------- 1 | prefix=/opt/librtmp 2 | exec_prefix=${prefix} 3 | libdir=/opt/librtmp/lib 4 | incdir=${prefix}/include 5 | 6 | Name: librtmp 7 | Description: RTMP implementation 8 | Version: v2.4 9 | Requires: libssl,libcrypto 10 | URL: http://rtmpdump.mplayerhq.hu 11 | Libs: -L${libdir} -lrtmp -lz 12 | Libs.private: 13 | Cflags: -I${incdir} 14 | -------------------------------------------------------------------------------- /ptask_timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ptask.h" 4 | #include 5 | 6 | class PTaskTimer : public PTask 7 | { 8 | public: 9 | void OnRun(); 10 | 11 | void RegistTimer(PTask* task, int inter, bool repeat); 12 | void UnregistTimer(PTask* task); 13 | 14 | private: 15 | struct timer_tick 16 | { 17 | int inter; 18 | bool repeat; 19 | int tick; 20 | }; 21 | 22 | std::map m_timers; 23 | }; -------------------------------------------------------------------------------- /pmedia_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ptask.h" 4 | #include "pstring.h" 5 | #include "prtsp_comm.h" 6 | 7 | class PRtspConn; 8 | class PRtspReq; 9 | 10 | class PMediaClient : public PTask 11 | { 12 | public: 13 | virtual void OnExit(); 14 | 15 | virtual void GetMediaInfo(PRtspConn* conn); 16 | 17 | virtual int on_rtsp_req(PRtspReq& req, PRtspConn* conn) = 0; 18 | 19 | protected: 20 | std::set m_addConn; 21 | std::set m_pendPlay; 22 | PRtspRsp m_descbRsp; 23 | }; 24 | 25 | 26 | -------------------------------------------------------------------------------- /pstring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class PString 7 | { 8 | public: 9 | PString(); 10 | PString(const char* s); 11 | 12 | uint32_t GetMsgSize(); 13 | 14 | const char* c_str() const; 15 | char* data(); 16 | int size() const; 17 | 18 | PString& operator = (const PString& rstr); 19 | bool operator < (const PString& rstr) const; 20 | 21 | void assign(const char* s, int sSize); 22 | void append(const char* s, int sSize); 23 | 24 | private: 25 | uint32_t m_size; 26 | char m_buf[256]; 27 | }; 28 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | #2、定义您自己的可执行文件名称 3 | PROGRAM_1=media 4 | 5 | ##################################################################### # 6 | #3、指定您必须生成的工程文件 7 | 8 | SOURCE_1 = $(wildcard *.cpp) \ 9 | $(wildcard tinyxml2/*.cpp) 10 | 11 | OBJECTS_1 = $(SOURCE_1:.cpp=.o) 12 | 13 | CFLAGS = -g -fpermissive -std=c++11 -Iosip2/include -Ilibrtmp/include 14 | LDFLAGS = -Losip2/lib -losipparser2 -Llibrtmp/lib -lrtmp -lpthread 15 | 16 | .PHONY: all 17 | all: $(PROGRAM_1) 18 | 19 | clean: 20 | @echo "[Cleanning...]" 21 | @rm -f $(OBJECTS_1) $(PROGRAM_1) 22 | 23 | %.o: %.cpp 24 | $(CXX) $(CFLAGS) -o $@ -c $< 25 | 26 | 27 | $(PROGRAM_1): $(OBJECTS_1) 28 | $(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) 29 | -------------------------------------------------------------------------------- /pmedia_client.cpp: -------------------------------------------------------------------------------- 1 | #include "pmedia_client.h" 2 | #include "prtsp_conn.h" 3 | 4 | void PMediaClient::OnExit() 5 | { 6 | PTaskMsg msg(EN_CLIENT_EXIT, NULL); 7 | 8 | for (auto it = m_addConn.begin(); it != m_addConn.end(); ++it) 9 | { 10 | (*it)->EnqueMsg(msg); 11 | (*it)->DelRef(); 12 | } 13 | 14 | for (auto it = m_pendPlay.begin(); it != m_pendPlay.end(); ++it) 15 | { 16 | (*it)->EnqueMsg(msg); 17 | (*it)->DelRef(); 18 | } 19 | 20 | PTask::OnExit(); 21 | } 22 | 23 | void PMediaClient::GetMediaInfo(PRtspConn* conn) 24 | { 25 | if (m_descbRsp.m_ret == 200) 26 | { 27 | conn->on_descb_rsp(m_descbRsp); 28 | } 29 | 30 | conn->AddRef(); 31 | m_addConn.insert(conn); 32 | } -------------------------------------------------------------------------------- /psip_conn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pstring.h" 4 | #include "osipparser2/osip_parser.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class PSipServer; 11 | class PMediaClient; 12 | 13 | class PSipConn 14 | { 15 | public: 16 | PSipConn(PSipServer* server); 17 | ~PSipConn(); 18 | 19 | int process_req(osip_message_t* sip, sockaddr_in& in_addr, socklen_t in_addrlen); 20 | 21 | PMediaClient* init_invite(PString& channel, PString& url); 22 | 23 | private: 24 | void clone_basic(osip_message_t* sip, osip_message_t* rsp, int sCode); 25 | 26 | private: 27 | PString m_nonce; 28 | PSipServer* m_server; 29 | osip_contact_t* m_contact; 30 | int m_cseq; 31 | }; -------------------------------------------------------------------------------- /prtmp_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pmedia_client.h" 4 | #include "librtmp/rtmp.h" 5 | 6 | class PRtmpClient : public PMediaClient 7 | { 8 | public: 9 | PRtmpClient(PString& ulr); 10 | 11 | int on_rtsp_req(PRtspReq& req, PRtspConn* conn); 12 | void OnRun(); 13 | 14 | void OnExit(); 15 | 16 | int process_msg(PTaskMsg& msg); 17 | 18 | private: 19 | void parse_flv(uint8_t* inbuf, int insize, int& inoffset); 20 | void on_sdp_info(int flv_codecid, int channels, int sample_rate, 21 | uint8_t audioObjectType, uint8_t samplingFrequencyIndex); 22 | 23 | private: 24 | PString m_url; 25 | RTMP m_rtmp; 26 | bool m_bfirst; 27 | char m_sendbuf[2048]; 28 | int m_videoseq; 29 | bool m_videoready; 30 | bool m_audioready; 31 | int m_sdptry; 32 | int m_audiosample; 33 | int m_audiochannel; 34 | int m_audiocodecid; 35 | int m_audiopayload; 36 | int m_audioseq; 37 | }; -------------------------------------------------------------------------------- /pencoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "pstring.h" 5 | 6 | class PEncoder 7 | { 8 | public: 9 | static void Encode(char*& buf, uint16_t& value) 10 | { 11 | uint16_t tt = htons(value); 12 | *(uint16_t*)buf = tt; 13 | buf += sizeof(uint16_t); 14 | } 15 | 16 | static void Encode(char*& buf, uint32_t& value) 17 | { 18 | uint32_t tt = htonl(value); 19 | *(uint32_t*)buf = tt; 20 | buf += sizeof(uint32_t); 21 | } 22 | 23 | static void Encode(char*& buf, int32_t& value) 24 | { 25 | int32_t tt = htonl(value); 26 | *(int32_t*)buf = tt; 27 | buf += sizeof(int32_t); 28 | } 29 | 30 | static void Encode(char*& buf, PString& value) 31 | { 32 | Encode(buf, value.m_size); 33 | 34 | if(value.m_size == 0) 35 | return; 36 | 37 | memcpy(buf, value.m_buf, value.m_size); 38 | buf += value.m_size; 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /pdecoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "pstring.h" 5 | 6 | class PDecoder 7 | { 8 | public: 9 | static void Decode(char*& buf, uint16_t& value) 10 | { 11 | uint16_t tt = *(uint16_t*)buf; 12 | value = ntohs(tt); 13 | buf += sizeof(uint16_t); 14 | } 15 | 16 | static void Decode(char*& buf, uint32_t& value) 17 | { 18 | uint32_t tt = *(uint32_t*)buf; 19 | value = ntohl(tt); 20 | buf += sizeof(uint32_t); 21 | } 22 | 23 | static void Decode(char*& buf, int32_t& value) 24 | { 25 | int32_t tt = *(int32_t*)buf; 26 | value = ntohl(tt); 27 | buf += sizeof(int32_t); 28 | } 29 | 30 | 31 | static void Decode(char*& buf, PString& value) 32 | { 33 | Decode(buf, value.m_size); 34 | 35 | if(value.m_size == 0) 36 | return; 37 | 38 | memcpy(value.m_buf, buf, value.m_size); 39 | value.m_buf[value.m_size] = '\0'; 40 | buf += value.m_size; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /plog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "pstring.h" 7 | 8 | class PLog 9 | { 10 | public: 11 | PLog(); 12 | ~PLog(); 13 | 14 | static PLog* Instance(); 15 | 16 | void Init(const char* logFile); 17 | void Exit(); 18 | void OnRun(); 19 | void Log(const char* strlog, ...); 20 | 21 | private: 22 | char* GetLogBuf(); 23 | void RelLogBuf(char* buf); 24 | void EnqueLog(char* log); 25 | void GetLog(std::vector& logs); 26 | void ProcessLog(std::vector& logs); 27 | void RelLog(std::vector& logs); 28 | 29 | static PLog* m_log; 30 | static pthread_mutex_t m_mutex; 31 | static pthread_cond_t m_cond; 32 | 33 | FILE* m_fp; 34 | bool m_exit; 35 | PString m_logFile; 36 | std::queue m_logBuf; 37 | std::queue m_logQue; 38 | }; 39 | 40 | #define P_LOG(FORMAT_STRING, ...) \ 41 | {\ 42 | PLog::Instance()->Log("%s,%d: " FORMAT_STRING, __FILE__, __LINE__, ##__VA_ARGS__); \ 43 | } 44 | 45 | -------------------------------------------------------------------------------- /pmedia.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "plog.h" 8 | #include "prtsp_server.h" 9 | #include "ptask_timer.h" 10 | #include "pmanager.h" 11 | #include "psip_server.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | PString sipDomain = "34020100002000000001"; 16 | PString sipPwd = "12345678"; 17 | PString sipIP = "192.168.1.155"; 18 | uint16_t sipPort = 5060; 19 | int rtsp_port = 5544; 20 | 21 | PLog::Instance()->Init("media.log"); 22 | PManager* pm = PManager::Instance(); 23 | PTaskTimer* timer = new PTaskTimer; 24 | 25 | timer->Start(); 26 | pm->SetTimer(timer); 27 | 28 | PRtspServer* rtspServer = new PRtspServer(sipIP, rtsp_port); 29 | 30 | rtspServer->Start(); 31 | 32 | PSipServer* sipServer = new PSipServer(sipDomain, sipPwd, sipIP, sipPort); 33 | 34 | sipServer->Start(); 35 | pm->SetSipServer(sipServer); 36 | 37 | pm->RunLoop(); 38 | 39 | PLog::Instance()->Exit(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /pmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "pmedia_client.h" 5 | #include "pstring.h" 6 | #include 7 | 8 | class PTaskTimer; 9 | class PSipServer; 10 | 11 | class PManager 12 | { 13 | public: 14 | static PManager* Instance(); 15 | 16 | PManager(); 17 | 18 | void Exit(); 19 | void RunLoop(); 20 | 21 | void AquireLock(); 22 | PMediaClient* GetMediaClient(PRtspConn* rtspConn, int pro, PString& url); 23 | void RegistClient(PString& url, PMediaClient* task); 24 | void UnregistClient(PString& url); 25 | void ReleaseLock(); 26 | void SetTimer(PTaskTimer* timer); 27 | PTaskTimer* GetTimer(); 28 | void SetSipServer(PSipServer* s); 29 | int CreateUdpSock(int& out_sock, PString& out_ip, uint16_t& out_port); 30 | 31 | private: 32 | static PManager* m_manager; 33 | static pthread_mutex_t m_mutex; 34 | static pthread_cond_t m_cond; 35 | bool m_exit; 36 | 37 | std::map m_urlClient; 38 | PTaskTimer* m_timer; 39 | PSipServer* m_sipServer; 40 | 41 | PString m_rtpIP; 42 | uint16_t m_curPort; 43 | uint16_t m_minPort; 44 | uint16_t m_maxPort; 45 | }; -------------------------------------------------------------------------------- /prtsp_conn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ptask.h" 4 | #include "pstring.h" 5 | #include "prtsp_comm.h" 6 | 7 | class PMediaClient; 8 | 9 | class PRtspConn : public PTask 10 | { 11 | public: 12 | PRtspConn(int fd); 13 | ~PRtspConn(); 14 | 15 | void OnRun(); 16 | void OnExit(); 17 | 18 | int on_descb_rsp(PRtspRsp& rsp); 19 | int on_rtsp_rsp(PRtspRsp& rsp); 20 | int send_tcp_stream(char* buf, int size); 21 | 22 | private: 23 | int tcp_recv(); 24 | 25 | int parse_process_req(); 26 | 27 | void skip_to_space(char*& p); 28 | 29 | int parse_method(char*& p, PRtspReq& req); 30 | void parse_url_version(char*& p, PRtspReq& req); 31 | int parse_req_head(PString& str, PRtspReq& req); 32 | int parse_line(PString& str, PRtspReq& req); 33 | int process_req(PRtspReq& req); 34 | int get_pro_url(PRtspReq& req); 35 | int process_msg(PTaskMsg& msg); 36 | 37 | void get_descb(int ret, PString& descb); 38 | int send_rtsp_rsp(PRtspRsp& rsp); 39 | 40 | private: 41 | int m_sock; 42 | char* m_tcpBuf; 43 | int m_tcpOff; 44 | int m_lastCSeq; 45 | PString m_preUrl; 46 | PMediaClient* m_meidaClient; 47 | 48 | std::vector m_req; 49 | }; 50 | -------------------------------------------------------------------------------- /ptask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class PTaskMsg 10 | { 11 | public: 12 | PTaskMsg() 13 | : m_type(0) 14 | , m_body(NULL) 15 | { 16 | } 17 | 18 | PTaskMsg(int type, void* body) 19 | : m_type(type) 20 | , m_body(body) 21 | { 22 | } 23 | 24 | int m_type; 25 | void* m_body; 26 | }; 27 | 28 | class PTask 29 | { 30 | public: 31 | enum { 32 | DEF_MAX_EVENTS = 3, 33 | }; 34 | 35 | PTask(); 36 | 37 | virtual ~PTask(); 38 | 39 | void Start(); 40 | 41 | virtual void OnRun() = 0; 42 | virtual void OnExit(); 43 | 44 | void AddRef(); 45 | void DelRef(); 46 | 47 | int EnqueMsg(PTaskMsg& msg); 48 | void DequeMsg(std::vector& msgs); 49 | 50 | int AddInEvent(int sock); 51 | int WaitEvent(struct epoll_event* outEvents, std::vector& msgs, int timeout); 52 | 53 | protected: 54 | void aquire_lock(); 55 | void release_lock(); 56 | 57 | private: 58 | int m_ref; 59 | pthread_mutex_t m_mutex; 60 | int m_efd; 61 | struct epoll_event m_events[DEF_MAX_EVENTS]; 62 | 63 | std::queue m_msgQue; 64 | int m_eventfd; 65 | bool m_exit; 66 | }; 67 | -------------------------------------------------------------------------------- /pstring.cpp: -------------------------------------------------------------------------------- 1 | #include "pstring.h" 2 | 3 | PString::PString() 4 | : m_size(0) 5 | { 6 | m_buf[0] = '\0'; 7 | } 8 | 9 | PString::PString(const char* s) 10 | { 11 | this->assign(s, strlen(s)); 12 | } 13 | 14 | uint32_t PString::GetMsgSize() 15 | { 16 | return sizeof(uint32_t) + m_size; 17 | } 18 | 19 | const char* PString::c_str() const 20 | { 21 | return m_buf; 22 | } 23 | 24 | char* PString::data() 25 | { 26 | return m_buf; 27 | } 28 | 29 | int PString::size() const 30 | { 31 | return m_size; 32 | } 33 | 34 | bool PString::operator<(const PString& rstr) const 35 | { 36 | if (m_size == rstr.size()) 37 | { 38 | int n = memcmp(m_buf, rstr.c_str(), m_size); 39 | if (n < 0) 40 | { 41 | return true; 42 | } 43 | else 44 | { 45 | return false; 46 | } 47 | } 48 | else 49 | { 50 | return m_size < rstr.size(); 51 | } 52 | } 53 | 54 | void PString::assign(const char* s, int sSize) 55 | { 56 | m_size = 0; 57 | this->append(s, sSize); 58 | } 59 | 60 | void PString::append(const char* s, int sSize) 61 | { 62 | memcpy(m_buf + m_size, s, sSize); 63 | m_size += sSize; 64 | m_buf[m_size] = '\0'; 65 | } 66 | 67 | PString& PString::operator = (const PString& rstr) 68 | { 69 | this->assign(rstr.c_str(), rstr.size()); 70 | 71 | return *this; 72 | } 73 | -------------------------------------------------------------------------------- /psip_server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ptask.h" 4 | #include 5 | #include "osipparser2/osip_parser.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "pstring.h" 11 | #include "prtsp_comm.h" 12 | 13 | class PSipConn; 14 | class PSipClient; 15 | class PMediaClient; 16 | 17 | class PSipServer : public PTask 18 | { 19 | public: 20 | PSipServer(PString& domain, PString& pwd, PString& ip, uint16_t port); 21 | 22 | void OnRun(); 23 | 24 | const PString& get_domain(); 25 | const PString& get_passwd(); 26 | 27 | void send_sip_rsp(osip_message_t* rsp, const char* ip, const char* port); 28 | void send_sip_rsp(osip_message_t* rsp, sockaddr_in& in_addr, socklen_t in_addrlen); 29 | 30 | PMediaClient* CreateClient(PString& url); 31 | 32 | PString& get_ip(); 33 | int get_port(); 34 | 35 | void add_dialog(sip_dialog* dialog); 36 | void del_dialog(PString& callid); 37 | sip_dialog* get_dialog(PString& callid); 38 | 39 | private: 40 | int udp_recv(); 41 | int process_msg(PTaskMsg& msg); 42 | 43 | private: 44 | PString m_ip; 45 | uint16_t m_port; 46 | int m_sock; 47 | PString m_domain; 48 | PString m_passwd; 49 | 50 | std::map m_sipConn; 51 | std::map m_sipDialog; 52 | }; -------------------------------------------------------------------------------- /prtsp_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pmedia_client.h" 4 | #include "pstring.h" 5 | #include "prtsp_comm.h" 6 | #include 7 | #include 8 | 9 | class PRtspConn; 10 | 11 | class PRtspClient : public PMediaClient 12 | { 13 | public: 14 | PRtspClient(PString& url); 15 | ~PRtspClient(); 16 | 17 | void OnRun(); 18 | void OnExit(); 19 | 20 | int on_rtsp_req(PRtspReq& req, PRtspConn* conn); 21 | 22 | private: 23 | int parse_url(PString& url); 24 | void get_method(int method, PString& cmd); 25 | int tcp_recv(); 26 | int send_rtsp_req(PRtspReq& req); 27 | 28 | int parse_rsp_head(PString& str, PRtspRsp& rsp); 29 | int parse_line(PString& str, PRtspRsp& rsp); 30 | int process_rsp(PRtspRsp& rsp); 31 | int parse_process_rsp(); 32 | int process_rsp_body(PRtspRsp& rsp, char*& buf, int& bufSize); 33 | int process_msg(PTaskMsg& msg); 34 | 35 | private: 36 | PString m_url; 37 | PString m_ip; 38 | uint16_t m_port; 39 | int m_sock; 40 | uint32_t m_cseq; 41 | 42 | char* m_tcpBuf; 43 | int m_tcpOff; 44 | std::vector m_rsp; 45 | 46 | struct SRtspReq 47 | { 48 | int method; 49 | PString url; 50 | }; 51 | 52 | std::map m_reqMap; 53 | std::map m_setupRsp; 54 | std::map > m_pendSetup; 55 | 56 | PRtspRsp m_playRsp; 57 | int m_keepMethod; 58 | int m_tiemout; 59 | }; 60 | -------------------------------------------------------------------------------- /ptask_timer.cpp: -------------------------------------------------------------------------------- 1 | #include "ptask_timer.h" 2 | #include 3 | #include "prtsp_comm.h" 4 | 5 | void PTaskTimer::OnRun() 6 | { 7 | struct epoll_event events[DEF_MAX_EVENTS]; 8 | std::vector msgs; 9 | std::map::iterator it; 10 | std::vector removeTask; 11 | std::vector::iterator itRemv; 12 | PTaskMsg msg(EN_TASK_TIMER, NULL); 13 | int ret; 14 | 15 | for (;;) 16 | { 17 | ret = this->WaitEvent(events, msgs, 1000); 18 | 19 | if (ret == 0) 20 | { 21 | this->aquire_lock(); 22 | 23 | for (it = m_timers.begin(); it != m_timers.end(); ++it) 24 | { 25 | timer_tick& tt = it->second; 26 | 27 | if (++tt.tick == tt.inter) 28 | { 29 | it->first->EnqueMsg(msg); 30 | 31 | if (tt.repeat) 32 | { 33 | tt.tick = 0; 34 | } 35 | else 36 | { 37 | removeTask.push_back(it->first); 38 | } 39 | } 40 | } 41 | 42 | for (itRemv = removeTask.begin(); itRemv != removeTask.end(); ++itRemv) 43 | { 44 | m_timers.erase(*itRemv); 45 | } 46 | 47 | this->release_lock(); 48 | 49 | removeTask.clear(); 50 | } 51 | } 52 | } 53 | 54 | void PTaskTimer::RegistTimer(PTask* task, int inter, bool repeat) 55 | { 56 | this->aquire_lock(); 57 | m_timers[task] = { inter, repeat, 0 }; 58 | this->release_lock(); 59 | } 60 | 61 | void PTaskTimer::UnregistTimer(PTask* task) 62 | { 63 | this->aquire_lock(); 64 | m_timers.erase(task); 65 | this->release_lock(); 66 | } 67 | -------------------------------------------------------------------------------- /librtmp/include/librtmp/http.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTMP_HTTP_H__ 2 | #define __RTMP_HTTP_H__ 3 | /* 4 | * Copyright (C) 2010 Howard Chu 5 | * Copyright (C) 2010 Antti Ajanki 6 | * 7 | * This file is part of librtmp. 8 | * 9 | * librtmp is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1, 12 | * or (at your option) any later version. 13 | * 14 | * librtmp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with librtmp see the file COPYING. If not, write to 21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | * Boston, MA 02110-1301, USA. 23 | * http://www.gnu.org/copyleft/lgpl.html 24 | */ 25 | 26 | typedef enum { 27 | HTTPRES_OK, /* result OK */ 28 | HTTPRES_OK_NOT_MODIFIED, /* not modified since last request */ 29 | HTTPRES_NOT_FOUND, /* not found */ 30 | HTTPRES_BAD_REQUEST, /* client error */ 31 | HTTPRES_SERVER_ERROR, /* server reported an error */ 32 | HTTPRES_REDIRECTED, /* resource has been moved */ 33 | HTTPRES_LOST_CONNECTION /* connection lost while waiting for data */ 34 | } HTTPResult; 35 | 36 | struct HTTP_ctx { 37 | char *date; 38 | int size; 39 | int status; 40 | void *data; 41 | }; 42 | 43 | typedef size_t (HTTP_read_callback)(void *ptr, size_t size, size_t nmemb, void *stream); 44 | 45 | HTTPResult HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /prtsp_server.cpp: -------------------------------------------------------------------------------- 1 | #include "prtsp_server.h" 2 | #include "plog.h" 3 | #include "prtsp_conn.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | PRtspServer::PRtspServer(PString& ip, uint16_t port) 13 | : m_ip(ip) 14 | , m_port(port) 15 | , m_sock(-1) 16 | { 17 | 18 | } 19 | 20 | PRtspServer::~PRtspServer() 21 | { 22 | if (m_sock > 0) 23 | { 24 | close(m_sock); 25 | } 26 | } 27 | 28 | void PRtspServer::OnRun() 29 | { 30 | m_sock = socket(AF_INET, SOCK_STREAM, 0); 31 | 32 | if (m_sock < 0) 33 | { 34 | P_LOG("create socket error:%d", errno); 35 | return; 36 | } 37 | 38 | int val = 1; 39 | 40 | if (setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))) 41 | { 42 | P_LOG("set socketopt error:%d", errno); 43 | return; 44 | } 45 | 46 | struct sockaddr_in server_addr; 47 | 48 | memset(&server_addr, 0, sizeof(server_addr)); 49 | server_addr.sin_family = AF_INET; 50 | server_addr.sin_addr.s_addr = inet_addr(m_ip.c_str()); 51 | server_addr.sin_port = htons(m_port); 52 | 53 | if (bind(m_sock, (struct sockaddr*)&server_addr, sizeof(server_addr))) 54 | { 55 | P_LOG("bind socket error:%d", errno); 56 | return; 57 | } 58 | 59 | if (listen(m_sock, 128)) 60 | { 61 | P_LOG("listen socket error:%d", errno); 62 | return; 63 | } 64 | 65 | sockaddr_in in_addr; 66 | socklen_t in_addrlen; 67 | int fd; 68 | 69 | for (;;) 70 | { 71 | in_addrlen = sizeof(sockaddr_in); 72 | 73 | fd = accept(m_sock, (struct sockaddr*)&in_addr, &in_addrlen); 74 | 75 | if (fd < 0) 76 | { 77 | P_LOG("accept socket error:%d", errno); 78 | return; 79 | } 80 | else 81 | { 82 | PRtspConn* conn = new PRtspConn(fd); 83 | conn->Start(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /psip_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pmedia_client.h" 4 | #include "pstring.h" 5 | #include "prtsp_comm.h" 6 | #include 7 | #include "osipparser2/osip_parser.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class PRtspConn; 14 | class PSipServer; 15 | struct sip_dialog; 16 | 17 | class PSipClient : public PMediaClient 18 | { 19 | public: 20 | PSipClient(int sock, PString& callid, PString& url, PSipServer* server); 21 | ~PSipClient(); 22 | 23 | void OnRun(); 24 | void OnExit(); 25 | 26 | int on_rtsp_req(PRtspReq& req, PRtspConn* conn); 27 | 28 | void process_sip(osip_message_t* sip, sip_dialog* dlg); 29 | 30 | struct es_info 31 | { 32 | int es_id; 33 | int type; 34 | }; 35 | 36 | void on_es_info(std::list& es_info_lst); 37 | 38 | private: 39 | int udp_recv(); 40 | int process_msg(PTaskMsg& msg); 41 | void process_pend_rtp(); 42 | void process_cur_rtp(); 43 | void nal_send(const uint8_t *buf, int size, int last, uint32_t ts); 44 | 45 | private: 46 | int m_sock; 47 | PString m_callid; 48 | PString m_url; 49 | PSipServer* m_server; 50 | 51 | sockaddr_in m_cAddr; 52 | socklen_t m_cAddrLen; 53 | char m_buf[2048]; 54 | int m_payload_type; 55 | 56 | bool m_first; 57 | uint16_t m_exp_seq; 58 | 59 | class RtpPack 60 | { 61 | public: 62 | RtpPack(); 63 | RtpPack(uint16_t iseq, int iflags, uint16_t its, uint8_t* ibuf, int ilen); 64 | RtpPack(const RtpPack& rPack); 65 | 66 | uint16_t seq; 67 | uint32_t timestamp; 68 | int flags; 69 | uint8_t buf[64 * 24]; 70 | int len; 71 | }; 72 | 73 | std::vector m_curRtpPacks; 74 | std::map m_pendRtpPacks; 75 | 76 | uint8_t* m_packBuf; 77 | uint8_t* m_psBuf; 78 | int m_psoff; 79 | int64_t m_last_ts; 80 | 81 | char m_sendBuf[2048]; 82 | int m_audio_payload; 83 | int m_audioSeq; 84 | int m_videoSeq; 85 | }; -------------------------------------------------------------------------------- /osip2/include/osipparser2/osip_md5.h: -------------------------------------------------------------------------------- 1 | /* MD5.H - header file for MD5C.C 2 | */ 3 | 4 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 5 | rights reserved. 6 | 7 | License to copy and use this software is granted provided that it 8 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest 9 | Algorithm" in all material mentioning or referencing this software 10 | or this function. 11 | 12 | License is also granted to make and use derivative works provided 13 | that such works are identified as "derived from the RSA Data 14 | Security, Inc. MD5 Message-Digest Algorithm" in all material 15 | mentioning or referencing the derived work. 16 | 17 | RSA Data Security, Inc. makes no representations concerning either 18 | the merchantability of this software or the suitability of this 19 | software for any particular purpose. It is provided "as is" 20 | without express or implied warranty of any kind. 21 | 22 | These notices must be retained in any copies of any part of this 23 | documentation and/or software. 24 | */ 25 | 26 | #ifndef _MD5_H_ 27 | #define _MD5_H_ 28 | 29 | #ifndef DOXYGEN 30 | 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* modified for oSIP: GCC supports this feature */ 37 | #define PROTOTYPES 1 38 | 39 | #ifndef PROTOTYPES 40 | #define PROTOTYPES 0 41 | #endif 42 | 43 | /* POINTER defines a generic pointer type */ 44 | typedef unsigned char *POINTER; 45 | 46 | /* UINT2 defines a two byte word */ 47 | typedef unsigned short int UINT2; 48 | 49 | /* UINT4 defines a four byte word */ 50 | typedef unsigned int UINT4; 51 | 52 | /* PROTO_LIST is defined depending on how PROTOTYPES is defined above. 53 | If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it 54 | returns an empty list. 55 | */ 56 | #if PROTOTYPES 57 | #define PROTO_LIST(list) list 58 | #else 59 | #define PROTO_LIST(list) () 60 | #endif 61 | 62 | 63 | /** 64 | * Structure for holding MD5 context. 65 | * @var MD5_CTX 66 | */ 67 | typedef struct { 68 | UINT4 state[4]; /* state (ABCD) */ 69 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 70 | unsigned char buffer[64]; /* input buffer */ 71 | } osip_MD5_CTX; 72 | 73 | void osip_MD5Init PROTO_LIST ((osip_MD5_CTX *)); 74 | void osip_MD5Update PROTO_LIST ((osip_MD5_CTX *, unsigned char *, unsigned int)); 75 | void osip_MD5Final PROTO_LIST ((unsigned char[16], osip_MD5_CTX *)); 76 | 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | #endif 82 | #endif 83 | -------------------------------------------------------------------------------- /librtmp/include/librtmp/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2009 Andrej Stepanchuk 3 | * Copyright (C) 2009-2010 Howard Chu 4 | * 5 | * This file is part of librtmp. 6 | * 7 | * librtmp is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1, 10 | * or (at your option) any later version. 11 | * 12 | * librtmp is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with librtmp see the file COPYING. If not, write to 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | * http://www.gnu.org/copyleft/lgpl.html 22 | */ 23 | 24 | #ifndef __RTMP_LOG_H__ 25 | #define __RTMP_LOG_H__ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | /* Enable this to get full debugging output */ 35 | /* #define _DEBUG */ 36 | 37 | #ifdef _DEBUG 38 | #undef NODEBUG 39 | #endif 40 | 41 | typedef enum 42 | { RTMP_LOGCRIT=0, RTMP_LOGERROR, RTMP_LOGWARNING, RTMP_LOGINFO, 43 | RTMP_LOGDEBUG, RTMP_LOGDEBUG2, RTMP_LOGALL 44 | } RTMP_LogLevel; 45 | 46 | extern RTMP_LogLevel RTMP_debuglevel; 47 | 48 | typedef void (RTMP_LogCallback)(int level, const char *fmt, va_list); 49 | void RTMP_LogSetCallback(RTMP_LogCallback *cb); 50 | void RTMP_LogSetOutput(FILE *file); 51 | #ifdef __GNUC__ 52 | void RTMP_LogPrintf(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 53 | void RTMP_LogStatus(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 54 | void RTMP_Log(int level, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); 55 | #else 56 | void RTMP_LogPrintf(const char *format, ...); 57 | void RTMP_LogStatus(const char *format, ...); 58 | void RTMP_Log(int level, const char *format, ...); 59 | #endif 60 | void RTMP_LogHex(int level, const uint8_t *data, unsigned long len); 61 | void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len); 62 | void RTMP_LogSetLevel(RTMP_LogLevel lvl); 63 | RTMP_LogLevel RTMP_LogGetLevel(void); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_allow.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ALLOW_H_ 22 | #define _OSIP_ALLOW_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_allow.h 28 | * @brief oSIP osip_allow header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ALLOW oSIP allow header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Allow headers. 39 | * @var osip_allow_t 40 | */ 41 | typedef osip_content_length_t osip_allow_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Allow element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_allow_init(header) osip_content_length_init(header) 53 | /** 54 | * Parse a Allow element. 55 | * @param header The element to work on. 56 | * @param hvalue The string to parse. 57 | */ 58 | #define osip_allow_parse(header, hvalue) osip_content_length_parse(header, hvalue) 59 | /** 60 | * Get a string representation of a Allow element. 61 | * @param header The element to work on. 62 | * @param dest A pointer on the new allocated string. 63 | */ 64 | #define osip_allow_to_str osip_content_length_to_str 65 | /** 66 | * Free a Allow element. 67 | * @param header The element to work on. 68 | */ 69 | #define osip_allow_free osip_content_length_free 70 | /** 71 | * Clone a Allow element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_allow_clone osip_content_length_clone 76 | 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | /** @} */ 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_mime_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_MIME_VERSION_H_ 22 | #define _OSIP_MIME_VERSION_H_ 23 | 24 | #include 25 | #include 26 | 27 | /** 28 | * @file osip_mime_version.h 29 | * @brief oSIP osip_mime_version header definition. 30 | */ 31 | 32 | /** 33 | * @defgroup oSIP_MIME_VERSION oSIP mime-version header definition. 34 | * @ingroup oSIP_HEADERS 35 | * @{ 36 | */ 37 | 38 | /** 39 | * Structure for Mime-Version headers. 40 | * @var osip_mime_version_t 41 | */ 42 | typedef osip_content_length_t osip_mime_version_t; 43 | 44 | #ifdef __cplusplus 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /** 50 | * Allocate a Mime-Version element. 51 | * @param header The element to work on. 52 | */ 53 | #define osip_mime_version_init(header) osip_content_length_init(header) 54 | /** 55 | * Parse a Mime-Version element. 56 | * @param header The element to work on. 57 | * @param hvalue The string to parse. 58 | */ 59 | #define osip_mime_version_parse(header, hvalue) osip_content_length_parse(header, hvalue) 60 | /** 61 | * Get a string representation of a Mime-Version element. 62 | * @param header The element to work on. 63 | * @param dest A pointer on the new allocated string. 64 | */ 65 | #define osip_mime_version_to_str(header, dest) osip_content_length_to_str(header, dest) 66 | /** 67 | * Free a Mime-Version element. 68 | * @param header The element to work on. 69 | */ 70 | #define osip_mime_version_free(header) osip_content_length_free(header) 71 | /** 72 | * Clone a Mime-Version element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_mime_version_clone osip_content_length_clone 77 | 78 | 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | /** @} */ 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_content_encoding.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONTENT_ENCODING_H_ 22 | #define _OSIP_CONTENT_ENCODING_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_content_encoding.h 28 | * @brief oSIP osip_content_encoding header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_CONTENT_ENCODING oSIP content-encoding header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Content-Encoding headers. 39 | * @var osip_content_encoding_t 40 | */ 41 | typedef osip_content_length_t osip_content_encoding_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | 49 | /** 50 | * Allocate a Content-Encoding element. 51 | * @param header The element to work on. 52 | */ 53 | #define osip_content_encoding_init(header) osip_content_length_init(header) 54 | /** 55 | * Parse a Content-Encoding element. 56 | * @param header The element to work on. 57 | * @param hvalue The string to parse. 58 | */ 59 | #define osip_content_encoding_parse(header, hvalue) osip_content_length_parse(header, hvalue) 60 | /** 61 | * Get a string representation of a Content-Encoding element. 62 | * @param header The element to work on. 63 | * @param dest A pointer on the new allocated string. 64 | */ 65 | #define osip_content_encoding_to_str osip_content_length_to_str 66 | /** 67 | * Free a Content-Encoding element. 68 | * @param header The element to work on. 69 | */ 70 | #define osip_content_encoding_free osip_content_length_free 71 | /** 72 | * Clone a Content-Encoding element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_content_encoding_clone osip_content_length_clone 77 | 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | /** @} */ 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/osip_headers.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | 22 | #ifndef _OSIP_HEADERS_H_ 23 | #define _OSIP_HEADERS_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | /** 58 | * @file osip_headers.h 59 | * @brief oSIP osip_headers definition. 60 | */ 61 | 62 | /** 63 | * @defgroup oSIP_HEADERS oSIP headers definitions 64 | * @ingroup osip2_parser 65 | * @{ 66 | */ 67 | 68 | /** @} */ 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_content_length.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONTENT_LENGTH_H_ 22 | #define _OSIP_CONTENT_LENGTH_H_ 23 | 24 | 25 | /** 26 | * @file osip_content_length.h 27 | * @brief oSIP osip_content_length header definition. 28 | */ 29 | 30 | /** 31 | * @defgroup oSIP_CONTENT_LENGTH oSIP content-length definition. 32 | * @ingroup oSIP_HEADERS 33 | * @{ 34 | */ 35 | 36 | /** 37 | * Structure for Content-Length headers. 38 | * @var osip_content_length_t 39 | */ 40 | typedef struct osip_content_length osip_content_length_t; 41 | 42 | /** 43 | * Definition of the Content-Length header. 44 | * @struct osip_content_length 45 | */ 46 | struct osip_content_length 47 | { 48 | char *value; /**< value for Content-Length (size of attachments) */ 49 | }; 50 | 51 | #ifdef __cplusplus 52 | extern "C" 53 | { 54 | #endif 55 | 56 | /** 57 | * Allocate a Content-Length element. 58 | * @param header The element to work on. 59 | */ 60 | int osip_content_length_init (osip_content_length_t ** header); 61 | /** 62 | * Free a Content-Length element. 63 | * @param header The element to work on. 64 | */ 65 | void osip_content_length_free (osip_content_length_t * header); 66 | /** 67 | * Parse a Content-Length element. 68 | * @param header The element to work on. 69 | * @param hvalue The string to parse. 70 | */ 71 | int osip_content_length_parse (osip_content_length_t * header, const char *hvalue); 72 | /** 73 | * Get a string representation of a Content-Length element. 74 | * @param header The element to work on. 75 | * @param dest A pointer on the new allocated string. 76 | */ 77 | int osip_content_length_to_str (const osip_content_length_t * header, char **dest); 78 | /** 79 | * Clone a Content-Length element. 80 | * @param header The element to work on. 81 | * @param dest A pointer on the copy of the element. 82 | */ 83 | int osip_content_length_clone (const osip_content_length_t * header, 84 | osip_content_length_t ** dest); 85 | 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | /** @} */ 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_alert_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ALERT_INFO_H_ 22 | #define _OSIP_ALERT_INFO_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_alert_info.h 28 | * @brief oSIP osip_alert_info header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ALERT_INFO oSIP alert-info definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Alert-Info headers. 39 | * @var osip_alert_info_t 40 | */ 41 | typedef osip_call_info_t osip_alert_info_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Alert-Info element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_alert_info_init(header) osip_call_info_init(header) 53 | /** 54 | * Free a Alert-Info element. 55 | * @param header The element to work on. 56 | */ 57 | #define osip_alert_info_free osip_call_info_free 58 | /** 59 | * Parse a Alert-Info element. 60 | * @param header The element to work on. 61 | * @param hvalue The string to parse. 62 | */ 63 | #define osip_alert_info_parse(header, hvalue) osip_call_info_parse(header, hvalue) 64 | /** 65 | * Get a string representation of a Alert-Info element. 66 | * @param header The element to work on. 67 | * @param dest A pointer on the new allocated string. 68 | */ 69 | #define osip_alert_info_to_str(header,dest) osip_call_info_to_str(header,dest) 70 | /** 71 | * Clone a Alert-Info element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_alert_info_clone osip_call_info_clone 76 | /** 77 | * Get uri from an Alert-Info element. 78 | * @param header The element to work on. 79 | */ 80 | #define osip_alert_info_get_uri(header) osip_call_info_get_uri(header) 81 | /** 82 | * Set the uri of an Alert-Info element. 83 | * @param header The element to work on. 84 | * @param uri The value of the new parameter. 85 | */ 86 | #define osip_alert_info_set_uri(header, uri) osip_call_info_set_uri(header, uri) 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | /** @} */ 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_error_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ERROR_INFO_H_ 22 | #define _OSIP_ERROR_INFO_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_error_info.h 28 | * @brief oSIP osip_error_info header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ERROR_INFO oSIP error-info definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Error-Info headers. 39 | * @var osip_error_info_t 40 | */ 41 | typedef osip_call_info_t osip_error_info_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Error-Info element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_error_info_init(header) osip_call_info_init(header) 53 | /** 54 | * Free a Error-Info element. 55 | * @param header The element to work on. 56 | */ 57 | #define osip_error_info_free osip_call_info_free 58 | /** 59 | * Parse a Error-Info element. 60 | * @param header The element to work on. 61 | * @param hvalue The string to parse. 62 | */ 63 | #define osip_error_info_parse(header, hvalue) osip_call_info_parse(header, hvalue) 64 | /** 65 | * Get a string representation of a Error-Info element. 66 | * @param header The element to work on. 67 | * @param dest A pointer on the new allocated string. 68 | */ 69 | #define osip_error_info_to_str(header,dest) osip_call_info_to_str(header,dest) 70 | /** 71 | * Clone a Error-Info element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_error_info_clone osip_call_info_clone 76 | 77 | /** 78 | * Set the uri in the Error-Info element. 79 | * @param header The element to work on. 80 | * @param uri The uri of the element. 81 | */ 82 | #define osip_error_info_set_uri(header, uri) osip_call_info_set_uri(header, uri) 83 | /** 84 | * Get the uri from a Error-Info header. 85 | * @param header The element to work on. 86 | */ 87 | #define osip_error_info_get_uri(header) osip_call_info_get_uri(header) 88 | 89 | 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | /** @} */ 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_accept.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ACCEPT_H_ 22 | #define _OSIP_ACCEPT_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_accept.h 28 | * @brief oSIP osip_accept header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ACCEPT oSIP accept header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for accept headers. 39 | * @var osip_accept_t 40 | */ 41 | typedef osip_content_type_t osip_accept_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | 49 | /** 50 | * Allocate an Accept element. 51 | * @param header The element to work on. 52 | */ 53 | #define accept_init(header) osip_content_type_init(header) 54 | /** 55 | * Free an Accept element. 56 | * @param header The element to work on. 57 | */ 58 | #define osip_accept_free osip_content_type_free 59 | /** 60 | * Parse an Accept element. 61 | * @param header The element to work on. 62 | * @param hvalue The string to parse. 63 | */ 64 | #define osip_accept_parse(header, hvalue) osip_content_type_parse(header, hvalue) 65 | /** 66 | * Get a string representation of an Accept element. 67 | * @param header The element to work on. 68 | * @param dest A pointer on the new allocated string. 69 | */ 70 | int osip_accept_to_str (const osip_accept_t * header, char **dest); 71 | /** 72 | * Clone an Accept element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_accept_clone osip_content_type_clone 77 | /** 78 | * Allocate and add a header parameter in an Accept element. 79 | * @param header The element to work on. 80 | * @param name The token name. 81 | * @param value The token value. 82 | */ 83 | #define osip_accept_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 84 | /** 85 | * Find a header parameter in an Accept element. 86 | * @param header The element to work on. 87 | * @param name The token name to search. 88 | * @param dest A pointer on the element found. 89 | */ 90 | #define osip_accept_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | /** @} */ 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_content_disposition.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONTENT_DISPOSITION_H_ 22 | #define _OSIP_CONTENT_DISPOSITION_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_content_disposition.h 28 | * @brief oSIP osip_content_disposition header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_CONTENT_DISPOSITION oSIP content-disposition definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Content-Disposition headers. 39 | * @var osip_content_disposition_t 40 | */ 41 | typedef osip_call_info_t osip_content_disposition_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Content-Disposition element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_content_disposition_init(header) osip_call_info_init(header) 53 | /** 54 | * Free a Content-Disposition element. 55 | * @param header The element to work on. 56 | */ 57 | #define osip_content_disposition_free(header) osip_call_info_free(header) 58 | /** 59 | * Parse a Content-Disposition element. 60 | * @param header The element to work on. 61 | * @param hvalue The string to parse. 62 | */ 63 | int osip_content_disposition_parse (osip_content_disposition_t * header, 64 | const char *hvalue); 65 | /** 66 | * Get a string representation of a Content-Disposition element. 67 | * @param header The element to work on. 68 | * @param dest A pointer on the new allocated string. 69 | */ 70 | #define osip_content_disposition_to_str(header,dest) osip_call_info_to_str(header,dest) 71 | /** 72 | * Clone a Content-Disposition element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_content_disposition_clone osip_call_info_clone 77 | 78 | /* type is of: "render" | "session" | "icon" | "alert" */ 79 | /** 80 | * Set the type in the Content-Disposition element. 81 | * @param header The element to work on. 82 | * @param value The value of the element. 83 | */ 84 | #define osip_content_disposition_set_type(header, value) osip_call_info_set_uri(header, value) 85 | /** 86 | * Get the type from a Content-Disposition header. 87 | * @param header The element to work on. 88 | */ 89 | #define osip_content_disposition_get_type(header) osip_call_info_get_uri(header) 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | /** @} */ 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_call_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CALL_INFO_H_ 22 | #define _OSIP_CALL_INFO_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_call_info.h 28 | * @brief oSIP osip_call_info header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_CALL_INFO oSIP call-info header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Call-Info headers. 39 | * @var osip_call_info_t 40 | */ 41 | typedef struct osip_call_info osip_call_info_t; 42 | 43 | /** 44 | * Definition of the Call-Info header. 45 | * @struct osip_call_info 46 | */ 47 | struct osip_call_info 48 | { 49 | char *element; /**< Call-Info main value */ 50 | osip_list_t gen_params; /**< Parameters for Call-Info header */ 51 | }; 52 | 53 | #ifdef __cplusplus 54 | extern "C" 55 | { 56 | #endif 57 | 58 | /** 59 | * Allocate a Call-Info element. 60 | * @param header The element to work on. 61 | */ 62 | int osip_call_info_init (osip_call_info_t ** header); 63 | /** 64 | * Free a Call-Info element. 65 | * @param header The element to work on. 66 | */ 67 | void osip_call_info_free (osip_call_info_t * header); 68 | /** 69 | * Parse a Call-Info element. 70 | * @param header The element to work on. 71 | * @param hvalue The string to parse. 72 | */ 73 | int osip_call_info_parse (osip_call_info_t * header, const char *hvalue); 74 | /** 75 | * Get a string representation of a Call-Info element. 76 | * @param header The element to work on. 77 | * @param dest A pointer on the new allocated string. 78 | */ 79 | int osip_call_info_to_str (const osip_call_info_t * header, char **dest); 80 | /** 81 | * Clone a Call-Info element. 82 | * @param header The element to work on. 83 | * @param dest A pointer on the copy of the element. 84 | */ 85 | int osip_call_info_clone (const osip_call_info_t * header, osip_call_info_t ** dest); 86 | /** 87 | * Get the uri from a Call_Info header. 88 | * @param header The element to work on. 89 | */ 90 | char *osip_call_info_get_uri (osip_call_info_t * header); 91 | /** 92 | * Set the uri in the Call_Info element. 93 | * @param header The element to work on. 94 | * @param uri The value of the element. 95 | */ 96 | void osip_call_info_set_uri (osip_call_info_t * header, char *uri); 97 | 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | /** @} */ 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /ptask.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "plog.h" 7 | #include "ptask.h" 8 | 9 | static void * task_start(void *arg) 10 | { 11 | PTask* task = static_cast(arg); 12 | task->OnRun(); 13 | task->OnExit(); 14 | task->DelRef(); 15 | return NULL; 16 | } 17 | 18 | PTask::PTask() 19 | : m_ref(1) 20 | , m_efd(-1) 21 | , m_exit(false) 22 | { 23 | pthread_mutex_init(&m_mutex, NULL); 24 | 25 | m_eventfd = eventfd(0, EFD_NONBLOCK);; 26 | m_efd = epoll_create(1); 27 | 28 | this->AddInEvent(m_eventfd); 29 | } 30 | 31 | PTask::~PTask() 32 | { 33 | close(m_efd); 34 | close(m_eventfd); 35 | 36 | pthread_mutex_destroy(&m_mutex); 37 | } 38 | 39 | void PTask::Start() 40 | { 41 | pthread_t tid; 42 | pthread_attr_t attr; 43 | 44 | pthread_attr_init(&attr); 45 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 46 | 47 | int ret = pthread_create(&tid, &attr, task_start, this); 48 | if (ret) 49 | { 50 | P_LOG("start thread err:%d", ret); 51 | } 52 | 53 | pthread_attr_destroy(&attr); 54 | } 55 | 56 | void PTask::OnExit() 57 | { 58 | pthread_mutex_lock(&m_mutex); 59 | m_exit = true; 60 | pthread_mutex_unlock(&m_mutex); 61 | } 62 | 63 | void PTask::AddRef() 64 | { 65 | pthread_mutex_lock(&m_mutex); 66 | ++m_ref; 67 | pthread_mutex_unlock(&m_mutex); 68 | } 69 | 70 | void PTask::DelRef() 71 | { 72 | pthread_mutex_lock(&m_mutex); 73 | --m_ref; 74 | 75 | if (m_ref <= 0) 76 | { 77 | pthread_mutex_unlock(&m_mutex); 78 | delete this; 79 | } 80 | else 81 | { 82 | pthread_mutex_unlock(&m_mutex); 83 | } 84 | } 85 | 86 | int PTask::EnqueMsg(PTaskMsg& msg) 87 | { 88 | pthread_mutex_lock(&m_mutex); 89 | 90 | if (m_exit) 91 | { 92 | pthread_mutex_unlock(&m_mutex); 93 | return -1; 94 | } 95 | 96 | m_msgQue.push(msg); 97 | 98 | pthread_mutex_unlock(&m_mutex); 99 | 100 | uint64_t c = 1; 101 | write(m_eventfd, &c, sizeof(c)); 102 | 103 | return 0; 104 | } 105 | 106 | void PTask::DequeMsg(std::vector& msgs) 107 | { 108 | pthread_mutex_lock(&m_mutex); 109 | 110 | while (m_msgQue.size()) 111 | { 112 | msgs.push_back(m_msgQue.front()); 113 | m_msgQue.pop(); 114 | } 115 | 116 | pthread_mutex_unlock(&m_mutex); 117 | 118 | } 119 | 120 | int PTask::AddInEvent(int sock) 121 | { 122 | struct epoll_event ev; 123 | 124 | ev.events = EPOLLIN; 125 | ev.data.fd = sock; 126 | 127 | int ret = epoll_ctl(m_efd, EPOLL_CTL_ADD, sock, &ev); 128 | if (ret < 0) 129 | { 130 | P_LOG("add in event err:%d", errno); 131 | return -1; 132 | } 133 | 134 | return 0; 135 | } 136 | 137 | int PTask::WaitEvent(struct epoll_event* outEvents, std::vector& msgs, int timeout) 138 | { 139 | msgs.clear(); 140 | 141 | int ret = epoll_wait(m_efd, m_events, DEF_MAX_EVENTS, timeout); 142 | int n = 0; 143 | 144 | if (ret > 0) 145 | { 146 | for (int i = 0; i < ret; ++i) 147 | { 148 | struct epoll_event& ev = m_events[i]; 149 | 150 | if (ev.data.fd == m_eventfd) 151 | { 152 | uint64_t c; 153 | if (-1 != read(m_eventfd, &c, sizeof(c))) 154 | { 155 | this->DequeMsg(msgs); 156 | } 157 | } 158 | else 159 | { 160 | outEvents[n] = ev; 161 | ++n; 162 | } 163 | } 164 | } 165 | else if (ret < 0) 166 | { 167 | P_LOG("epoll wait err:%d", errno); 168 | return -1; 169 | } 170 | 171 | return n; 172 | } 173 | 174 | void PTask::aquire_lock() 175 | { 176 | pthread_mutex_lock(&m_mutex); 177 | } 178 | 179 | void PTask::release_lock() 180 | { 181 | pthread_mutex_unlock(&m_mutex); 182 | } 183 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_cseq.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CSEQ_H_ 22 | #define _OSIP_CSEQ_H_ 23 | 24 | /** 25 | * @file osip_cseq.h 26 | * @brief oSIP osip_cseq header definition. 27 | */ 28 | 29 | /** 30 | * @defgroup oSIP_CSEQ oSIP cseq header definition. 31 | * @ingroup oSIP_HEADERS 32 | * @{ 33 | */ 34 | 35 | /** 36 | * Structure for CSeq headers. 37 | * @var osip_cseq_t 38 | */ 39 | typedef struct osip_cseq osip_cseq_t; 40 | 41 | /** 42 | * Definition of the CSeq header. 43 | * @struct osip_cseq 44 | */ 45 | struct osip_cseq 46 | { 47 | char *method; /**< CSeq method */ 48 | char *number; /**< CSeq number */ 49 | }; 50 | 51 | #ifdef __cplusplus 52 | extern "C" 53 | { 54 | #endif 55 | 56 | /** 57 | * Allocate a CSeq element. 58 | * @param header The element to work on. 59 | */ 60 | int osip_cseq_init (osip_cseq_t ** header); 61 | /** 62 | * Free a CSeq element. 63 | * @param header The element to work on. 64 | */ 65 | void osip_cseq_free (osip_cseq_t * header); 66 | /** 67 | * Parse a CSeq element. 68 | * @param header The element to work on. 69 | * @param hvalue The string to parse. 70 | */ 71 | int osip_cseq_parse (osip_cseq_t * header, const char *hvalue); 72 | /** 73 | * Get a string representation of a CSeq element. 74 | * @param header The element to work on. 75 | * @param dest A pointer on the new allocated string. 76 | */ 77 | int osip_cseq_to_str (const osip_cseq_t * header, char **dest); 78 | /** 79 | * Clone a CSeq element. 80 | * @param header The element to work on. 81 | * @param dest A pointer on the copy of the element. 82 | */ 83 | int osip_cseq_clone (const osip_cseq_t * header, osip_cseq_t ** dest); 84 | /** 85 | * Set the number in the CSeq element. 86 | * @param header The element to work on. 87 | * @param value The value of the element. 88 | */ 89 | void osip_cseq_set_number (osip_cseq_t * header, char *value); 90 | /** 91 | * Get the number from a CSeq header. 92 | * @param header The element to work on. 93 | */ 94 | char *osip_cseq_get_number (osip_cseq_t * header); 95 | /** 96 | * Set the method in the CSeq element. 97 | * @param header The element to work on. 98 | * @param value The value of the element. 99 | */ 100 | void osip_cseq_set_method (osip_cseq_t * header, char *value); 101 | /** 102 | * Get the method from a CSeq header. 103 | * @param header The element to work on. 104 | */ 105 | char *osip_cseq_get_method (osip_cseq_t * header); 106 | 107 | /** 108 | * Check if the CSeq headers match. 109 | * NOTE: THIS IS AN INTERNAL METHOD ONLY 110 | * @param cseq1 The initial CSeq header. 111 | * @param cseq2 The new CSeq header. 112 | */ 113 | int osip_cseq_match (osip_cseq_t * cseq1, osip_cseq_t * cseq2); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | /** @} */ 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_content_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONTENT_TYPE_H_ 22 | #define _OSIP_CONTENT_TYPE_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_content_type.h 28 | * @brief oSIP osip_content_type header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_CONTENT_TYPE oSIP content-type header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Content-Type headers. 39 | * @var osip_content_type_t 40 | */ 41 | typedef struct osip_content_type osip_content_type_t; 42 | 43 | /** 44 | * Definition of the Content-Type header. 45 | * @struct osip_content_type 46 | */ 47 | struct osip_content_type 48 | { 49 | char *type; /**< Type of attachement */ 50 | char *subtype; /**< Sub-Type of attachement */ 51 | osip_list_t gen_params; /**< Content-Type parameters */ 52 | }; 53 | 54 | #ifdef __cplusplus 55 | extern "C" 56 | { 57 | #endif 58 | 59 | /** 60 | * Allocate a Content-Type element. 61 | * @param header The element to work on. 62 | */ 63 | int osip_content_type_init (osip_content_type_t ** header); 64 | /** 65 | * Free a Content-Type element. 66 | * @param header The element to work on. 67 | */ 68 | void osip_content_type_free (osip_content_type_t * header); 69 | /** 70 | * Parse a Content-Type element. 71 | * @param header The element to work on. 72 | * @param hvalue The string to parse. 73 | */ 74 | int osip_content_type_parse (osip_content_type_t * header, const char *hvalue); 75 | /** 76 | * Get a string representation of a Content-Type element. 77 | * @param header The element to work on. 78 | * @param dest A pointer on the new allocated string. 79 | */ 80 | int osip_content_type_to_str (const osip_content_type_t * header, char **dest); 81 | /** 82 | * Clone a Content-Type element. 83 | * @param header The element to work on. 84 | * @param dest A pointer on the copy of the element. 85 | */ 86 | int osip_content_type_clone (const osip_content_type_t * header, 87 | osip_content_type_t ** dest); 88 | 89 | /** 90 | * Allocate and add a generic parameter element in a list. 91 | * @param header The element to work on. 92 | * @param name The token name. 93 | * @param value The token value. 94 | */ 95 | #define osip_content_type_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 96 | /** 97 | * Find a header parameter in a Content-Type element. 98 | * @param header The element to work on. 99 | * @param name The token name to search. 100 | * @param dest A pointer on the element found. 101 | */ 102 | #define osip_content_type_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 103 | 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | /** @} */ 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_call_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CALL_ID_H_ 22 | #define _OSIP_CALL_ID_H_ 23 | 24 | /** 25 | * @file osip_call_id.h 26 | * @brief oSIP osip_call_id header definition. 27 | */ 28 | 29 | /** 30 | * @defgroup oSIP_CALL_ID oSIP call-id header definition. 31 | * @ingroup oSIP_HEADERS 32 | * @{ 33 | */ 34 | 35 | /** 36 | * Structure for Call-Id headers. 37 | * @var osip_call_id_t 38 | */ 39 | typedef struct osip_call_id osip_call_id_t; 40 | 41 | /** 42 | * Definition of the Call-Id header. 43 | * @struct osip_call_id 44 | */ 45 | struct osip_call_id 46 | { 47 | char *number; /**< Call-ID number */ 48 | char *host; /**< Call-ID host information */ 49 | }; 50 | 51 | #ifdef __cplusplus 52 | extern "C" 53 | { 54 | #endif 55 | 56 | /** 57 | * Allocate a Call-id element. 58 | * @param header The element to work on. 59 | */ 60 | int osip_call_id_init (osip_call_id_t ** header); 61 | /** 62 | * Free a Call-id element. 63 | * @param header The element to work on. 64 | */ 65 | void osip_call_id_free (osip_call_id_t * header); 66 | /** 67 | * Parse a Call-id element. 68 | * @param header The element to work on. 69 | * @param hvalue The string to parse. 70 | */ 71 | int osip_call_id_parse (osip_call_id_t * header, const char *hvalue); 72 | /** 73 | * Get a string representation of a Call-id element. 74 | * @param header The element to work on. 75 | * @param dest A pointer on the new allocated string. 76 | */ 77 | int osip_call_id_to_str (const osip_call_id_t * header, char **dest); 78 | /** 79 | * Clone a Call-id element. 80 | * @param header The element to work on. 81 | * @param dest A pointer on the copy of the element. 82 | */ 83 | int osip_call_id_clone (const osip_call_id_t * header, osip_call_id_t ** dest); 84 | /** 85 | * Set the number in the Call-Id element. 86 | * @param header The element to work on. 87 | * @param value The value of the element. 88 | */ 89 | void osip_call_id_set_number (osip_call_id_t * header, char *value); 90 | /** 91 | * Get the number from a Call-Id header. 92 | * @param header The element to work on. 93 | */ 94 | char *osip_call_id_get_number (osip_call_id_t * header); 95 | /** 96 | * Set the host in the Call-Id element. 97 | * @param header The element to work on. 98 | * @param value The value of the element. 99 | */ 100 | void osip_call_id_set_host (osip_call_id_t * header, char *value); 101 | /** 102 | * Get the host from a Call-Id header. 103 | * @param header The element to work on. 104 | */ 105 | char *osip_call_id_get_host (osip_call_id_t * header); 106 | 107 | /** 108 | * Check if the Call-Id headers match. 109 | * NOTE: THIS IS AN INTERNAL METHOD ONLY 110 | * @param callid1 The initial Call-Id header. 111 | * @param callid2 The new Call-Id header. 112 | */ 113 | int osip_call_id_match (osip_call_id_t * callid1, osip_call_id_t * callid2); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | /** @} */ 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_accept_language.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ACCEPT_LANGUAGE_H_ 22 | #define _OSIP_ACCEPT_LANGUAGE_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_accept_language.h 28 | * @brief oSIP osip_accept_language header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ACCEPT_LANGUAGE oSIP accept-language header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Accept-Language headers. 39 | * @var osip_accept_language_t 40 | */ 41 | typedef osip_accept_encoding_t osip_accept_language_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate an Accept-Language element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_accept_language_init(header) osip_accept_encoding_init(header) 53 | /** 54 | * Parse an Accept-Language element. 55 | * @param header The element to work on. 56 | * @param hvalue The string to parse. 57 | */ 58 | #define osip_accept_language_parse(header, hvalue) osip_accept_encoding_parse(header, hvalue) 59 | /** 60 | * Get a string representation of an Accept-Language element. 61 | * @param header The element to work on. 62 | * @param dest A pointer on the new allocated string. 63 | */ 64 | #define osip_accept_language_to_str osip_accept_encoding_to_str 65 | /** 66 | * Free an Accept-Language element. 67 | * @param header The element to work on. 68 | */ 69 | #define osip_accept_language_free osip_accept_encoding_free 70 | /** 71 | * Clone an Accept-Language element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_accept_language_clone osip_accept_encoding_clone 76 | 77 | /** 78 | * Get the value of an Accept-Language element. 79 | * @param header The element to work on. 80 | */ 81 | #define osip_accept_language_get_element(header) osip_accept_encoding_get_element(header) 82 | /** 83 | * Set the value of an Accept-Language element. 84 | * @param header The element to work on. 85 | * @param value The value to set. 86 | */ 87 | #define osip_accept_language_set_element(header, value) osip_accept_encoding_set_element(header, value) 88 | /** 89 | * Allocate and add a generic parameter element in an Accept-Language element. 90 | * @param header The element to work on. 91 | * @param name The token name. 92 | * @param value The token value. 93 | */ 94 | #define osip_accept_language_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 95 | /** 96 | * Find a header parameter in a Accept-Language element. 97 | * @param header The element to work on. 98 | * @param name The token name to search. 99 | * @param dest A pointer on the element found. 100 | */ 101 | #define osip_accept_language_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 102 | 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | /** @} */ 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_HEADER_H_ 22 | #define _OSIP_HEADER_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_header.h 28 | * @brief oSIP osip_header definition. 29 | * 30 | */ 31 | 32 | /** 33 | * @defgroup oSIP_HEADER oSIP header definition. 34 | * @ingroup oSIP_HEADERS 35 | * @{ 36 | */ 37 | 38 | /** 39 | * Structure for 'unknown' headers. 40 | * NOTE: 'unknown' header' are used in oSIP for all header that are not 41 | * defined by oSIP in the osip_message_t structure. This means that all 42 | * 'unknown' header has to be handled with the API related to this 43 | * structure. 44 | * @var osip_header_t 45 | */ 46 | typedef struct osip_header osip_header_t; 47 | 48 | /** 49 | * Definition of a generic sip header. 50 | * @struct osip_header 51 | */ 52 | struct osip_header 53 | { 54 | char *hname; /**< Name of header */ 55 | char *hvalue; /**< Value for header */ 56 | }; 57 | 58 | /** 59 | * Structure for generic parameter headers. 60 | * Generic parameter are used in a lot of headers. (To, From, Route, 61 | * Record-Route...) All those headers use a common API but this is 62 | * hidden by MACROs that you can be found in smsg.h. 63 | * @var osip_generic_param_t 64 | */ 65 | typedef osip_uri_param_t osip_generic_param_t; 66 | 67 | #ifdef __cplusplus 68 | extern "C" 69 | { 70 | #endif 71 | 72 | /** 73 | * Allocate a header element. 74 | * @param header The element to work on. 75 | */ 76 | int osip_header_init (osip_header_t ** header); 77 | /** 78 | * Free a header element. 79 | * @param header The element to work on. 80 | */ 81 | void osip_header_free (osip_header_t * header); 82 | /** 83 | * Get a string representation of a header element. 84 | * @param header The element to work on. 85 | * @param dest A pointer on the new allocated buffer. 86 | */ 87 | int osip_header_to_str (const osip_header_t * header, char **dest); 88 | /** 89 | * Get the token name a header element. 90 | * @param header The element to work on. 91 | */ 92 | char *osip_header_get_name (const osip_header_t * header); 93 | /** 94 | * Set the token name a header element. 95 | * @param header The element to work on. 96 | * @param pname The token name to set. 97 | */ 98 | void osip_header_set_name (osip_header_t * header, char *pname); 99 | /** 100 | * Get the token value a header element. 101 | * @param header The element to work on. 102 | */ 103 | char *osip_header_get_value (const osip_header_t * header); 104 | /** 105 | * Set the token value a header element. 106 | * @param header The element to work on. 107 | * @param pvalue The token value to set. 108 | */ 109 | void osip_header_set_value (osip_header_t * header, char *pvalue); 110 | /** 111 | * Clone a header element. 112 | * @param header The element to work on. 113 | * @param dest A pointer on the copy of the element. 114 | */ 115 | int osip_header_clone (const osip_header_t * header, osip_header_t ** dest); 116 | 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | /** @} */ 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /prtsp_comm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pstring.h" 4 | #include 5 | #include "osipparser2/osip_parser.h" 6 | #include 7 | 8 | enum media_pro 9 | { 10 | RTSP, 11 | GB28181, 12 | PRTMP, 13 | }; 14 | 15 | enum rtsp_method 16 | { 17 | OPTIONS = 0, 18 | DESCRIBE = 1, 19 | SETUP = 3, 20 | PLAY = 5, 21 | PAUSE = 7, 22 | TEARDOWN = 9, 23 | SET_PARAMETER = 11, 24 | GET_PARAMETER = 13, 25 | }; 26 | 27 | enum 28 | { 29 | EN_DESCB_REQ = 1, 30 | EN_DESCB_RSP, 31 | EN_SETUP_REQ, 32 | EN_SETUP_RSP, 33 | EN_PLAY_REQ, 34 | EN_PLAY_RSP, 35 | EN_PAUSE_REQ, 36 | EN_PAUSE_RSP, 37 | EN_TEARDOWN_REQ, 38 | EN_TEARDOWN_RSP, 39 | EN_SETPARAM_REQ, 40 | EN_SETPARAM_RSP, 41 | EN_GETPARAM_REQ, 42 | EN_GETPARAM_RSP, 43 | EN_TASK_TIMER, 44 | EN_CONN_EXIT, 45 | EN_CLIENT_EXIT, 46 | }; 47 | 48 | class PRtspReq 49 | { 50 | public: 51 | int m_method; 52 | PString m_url; 53 | PString m_version; 54 | int m_cseq; 55 | PString m_accept; 56 | PString m_transport; 57 | PString m_session; 58 | PString m_range; 59 | 60 | int m_pro; 61 | PString m_proUrl; 62 | }; 63 | 64 | class PRtspRsp 65 | { 66 | public: 67 | PRtspRsp() : m_ret(0), m_cntLen(0){} 68 | 69 | int m_ret; 70 | int m_cseq; 71 | PString m_descb; 72 | PString m_public; 73 | PString m_cntBase; 74 | PString m_cntType; 75 | PString m_session; 76 | PString m_transport; 77 | PString m_range; 78 | PString m_rtpinfo; 79 | int m_cntLen; 80 | 81 | std::vector m_sdp; 82 | }; 83 | 84 | class PSipClient; 85 | 86 | struct sip_dialog 87 | { 88 | PString callid; 89 | PString destUser; 90 | PString destHost; 91 | PString destPort; 92 | PString localContact; 93 | PString via; 94 | PString localTag; 95 | PString remoteTag; 96 | PSipClient* sipClient; 97 | int cseq; 98 | }; 99 | 100 | #define DEF_BUF_SIZE 512 * 1024 101 | 102 | #define RTP_FLAG_MARKER 0x2 ///< RTP marker bit was set for this packet 103 | #define RTP_VERSION 2 104 | #define MAX_PAYLOAD_SIZE 1400 105 | 106 | #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1]) 107 | 108 | #define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \ 109 | (((const uint8_t*)(x))[1] << 8) | \ 110 | ((const uint8_t*)(x))[2]) 111 | 112 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ 113 | (((const uint8_t*)(x))[1] << 16) | \ 114 | (((const uint8_t*)(x))[2] << 8) | \ 115 | ((const uint8_t*)(x))[3]) 116 | 117 | #define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \ 118 | ((const uint8_t*)(x))[0]) 119 | 120 | #define AV_RL32(x) \ 121 | (((uint32_t)((const uint8_t*)(x))[3] << 24) | \ 122 | (((const uint8_t*)(x))[2] << 16) | \ 123 | (((const uint8_t*)(x))[1] << 8) | \ 124 | ((const uint8_t*)(x))[0]) 125 | 126 | void skip_space(char*& p); 127 | 128 | void build_sip_msg(osip_message_t*& sip, sip_dialog* dlg, int cseq, const char* method); 129 | 130 | int avio_r8(uint8_t*& pb); 131 | 132 | unsigned int avio_rb16(uint8_t*& s); 133 | 134 | void avio_skip(uint8_t*& pb, int64_t offset); 135 | 136 | unsigned int avio_rb32(uint8_t*& s); 137 | 138 | unsigned int avio_rb24(uint8_t*& s); 139 | 140 | const uint8_t * ff_avc_find_startcode_internal( 141 | const uint8_t *p, const uint8_t *end); 142 | 143 | const uint8_t * ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); 144 | 145 | class PRtspConn; 146 | 147 | void parse_send_es(const uint8_t* inbuf, const int insize, int64_t ts, 148 | int payload, uint8_t* sendbuf, int& seq, std::set& pendPlay); 149 | 150 | void nal_send(const uint8_t *buf, int size, int last, uint32_t ts, 151 | int payload, uint8_t* sendbuf, int& seq, std::set& pendPlay); 152 | 153 | void avio_w8(uint8_t*& s, int b); 154 | 155 | void avio_wb16(uint8_t*& s, unsigned int val); 156 | 157 | void avio_wb32(uint8_t*& s, unsigned int val); 158 | 159 | 160 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/osip_body.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_BODY_H_ 22 | #define _OSIP_BODY_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_body.h 28 | * @brief oSIP SIP Message Body Routines 29 | * 30 | */ 31 | 32 | /** 33 | * @defgroup oSIP_BODY oSIP body API 34 | * @ingroup osip2_parser 35 | * @{ 36 | */ 37 | 38 | /** 39 | * Structure for holding Body 40 | * @var osip_body_t 41 | */ 42 | typedef struct osip_body osip_body_t; 43 | 44 | /** 45 | * Structure for holding Body 46 | * @struct osip_body 47 | */ 48 | struct osip_body { 49 | char *body; /**< buffer containing data */ 50 | size_t length; /**< length of data */ 51 | osip_list_t *headers; /**< List of headers (when mime is used) */ 52 | osip_content_type_t *content_type; 53 | /**< Content-Type (when mime is used) */ 54 | }; 55 | 56 | 57 | #ifdef __cplusplus 58 | extern "C" { 59 | #endif 60 | 61 | /** 62 | * Allocate a osip_body_t element. 63 | * @param body The element to work on. 64 | */ 65 | int osip_body_init (osip_body_t ** body); 66 | /** 67 | * Free a osip_body_t element. 68 | * @param body The element to work on. 69 | */ 70 | void osip_body_free (osip_body_t * body); 71 | /** 72 | * Parse a osip_body_t element. 73 | * @param body The element to work on. 74 | * @param buf The buffer to parse. 75 | * @param length The length of the buffer to parse. 76 | */ 77 | int osip_body_parse (osip_body_t * body, const char *buf, size_t length); 78 | /** 79 | * Clone a osip_body_t element. 80 | * @param body The element to clone. 81 | * @param dest The cloned element. 82 | */ 83 | int osip_body_clone (const osip_body_t * body, osip_body_t ** dest); 84 | /** 85 | * Parse a osip_body_t element. (for mime message format) (NOT TESTED, use with care) 86 | * @param body The element to work on. 87 | * @param buf The buffer to parse. 88 | * @param length The length of the buffer to parse. 89 | */ 90 | int osip_body_parse_mime (osip_body_t * body, const char *buf, size_t length); 91 | /** 92 | * Get a string representation of a osip_body_t element. 93 | * @param body The element to work on. 94 | * @param dest The resulting buffer. 95 | * @param length The length of the returned buffer. 96 | */ 97 | int osip_body_to_str (const osip_body_t * body, char **dest, size_t * length); 98 | 99 | /** 100 | * Set the Content-Type header in the osip_body_t element. 101 | * @param body The element to work on. 102 | * @param hvalue The content type string value. 103 | */ 104 | int osip_body_set_contenttype (osip_body_t * body, const char *hvalue); 105 | 106 | /** 107 | * Add a header in the osip_body_t element. 108 | * @param body The element to work on. 109 | * @param hname The header string name. 110 | * @param hvalue The header string value. 111 | */ 112 | int osip_body_set_header (osip_body_t * body, const char *hname, const char *hvalue); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | /** @} */ 118 | #endif 119 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_route.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_RECORD_H_ 22 | #define _OSIP_RECORD_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_route.h 28 | * @brief oSIP osip_route header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ROUTE oSIP route header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Route headers. 39 | * @var osip_route_t 40 | */ 41 | typedef osip_from_t osip_route_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | #ifndef MINISIZE 49 | /** 50 | * Allocate a Route element. 51 | * @param header The element to work on. 52 | */ 53 | int osip_route_init (osip_route_t ** header); 54 | /** 55 | * Free a Route element. 56 | * @param header The element to work on. 57 | */ 58 | void osip_route_free (osip_route_t * header); 59 | /** 60 | * Parse a Route element. 61 | * @param header The element to work on. 62 | * @param hvalue The string to parse. 63 | */ 64 | int osip_route_parse (osip_route_t * header, const char *hvalue); 65 | /** 66 | * Get a string representation of a Route element. 67 | * @param header The element to work on. 68 | * @param dest A pointer on the new allocated string. 69 | */ 70 | int osip_route_to_str (const osip_route_t * header, char **dest); 71 | /** 72 | * Clone a Route element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_route_clone osip_from_clone 77 | #else 78 | #define osip_route_init osip_from_init 79 | #define osip_route_free osip_from_free 80 | #define osip_route_parse osip_from_parse 81 | #define osip_route_to_str osip_from_to_str 82 | #define osip_route_clone osip_from_clone 83 | #endif 84 | /** 85 | * Set the url in the Route element. 86 | * @param header The element to work on. 87 | * @param url The value of the element. 88 | */ 89 | #define osip_route_set_url(header,url) osip_from_set_url((osip_from_t*)header,url) 90 | /** 91 | * Get the url from a Route header. 92 | * @param header The element to work on. 93 | */ 94 | #define osip_route_get_url(header) osip_from_get_url((osip_from_t*)header) 95 | /** 96 | * Get a header parameter from a Route element. 97 | * @param header The element to work on. 98 | * @param pos The index of the element to get. 99 | * @param dest A pointer on the element found. 100 | */ 101 | #define osip_route_param_get(header,pos,dest) osip_from_param_get((osip_from_t*)header,pos,dest) 102 | /** 103 | * Allocate and add a generic parameter element in a Route element. 104 | * @param header The element to work on. 105 | * @param name The token name. 106 | * @param value The token value. 107 | */ 108 | #define osip_route_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 109 | /** 110 | * Find a header parameter in a Route element. 111 | * @param header The element to work on. 112 | * @param name The token name to search. 113 | * @param dest A pointer on the element found. 114 | */ 115 | #define osip_route_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | /** @} */ 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_accept_encoding.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_ACCEPT_ENCONDING_H_ 22 | #define _OSIP_ACCEPT_ENCONDING_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_accept_encoding.h 28 | * @brief oSIP osip_accept_encoding header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_ACCEPT_ENCODING oSIP accept-encoding header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Accept-Encoding header. 39 | * @var osip_accept_encoding_t 40 | */ 41 | typedef struct osip_accept_encoding osip_accept_encoding_t; 42 | 43 | /** 44 | * Definition of the Accept-Encoding header. 45 | * @struct osip_accept_encoding 46 | */ 47 | struct osip_accept_encoding 48 | { 49 | char *element; /**< accept encoding main value */ 50 | osip_list_t gen_params; /**< accept encoding parameters */ 51 | }; 52 | 53 | 54 | #ifdef __cplusplus 55 | extern "C" 56 | { 57 | #endif 58 | 59 | /** 60 | * Allocate a Accept-Encoding element. 61 | * @param header The element to work on. 62 | */ 63 | int osip_accept_encoding_init (osip_accept_encoding_t ** header); 64 | /** 65 | * Parse a Accept-Encoding element. 66 | * @param header The element to work on. 67 | * @param hvalue The string to parse. 68 | */ 69 | int osip_accept_encoding_parse (osip_accept_encoding_t * header, const char *hvalue); 70 | /** 71 | * Get a string representation of a Accept-Encoding element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the new allocated string. 74 | */ 75 | int osip_accept_encoding_to_str (const osip_accept_encoding_t * header, char **dest); 76 | /** 77 | * Free a Accept-Encoding element. 78 | * @param header The element to work on. 79 | */ 80 | void osip_accept_encoding_free (osip_accept_encoding_t * header); 81 | /** 82 | * Clone a Accept-Encoding element. 83 | * @param header The element to work on. 84 | * @param dest A pointer on the copy of the element. 85 | */ 86 | int osip_accept_encoding_clone (const osip_accept_encoding_t * header, 87 | osip_accept_encoding_t ** dest); 88 | 89 | /** 90 | * Set the value of an Accept-Encoding element. 91 | * @param header The element to work on. 92 | * @param value The token value to set. 93 | */ 94 | void osip_accept_encoding_set_element (osip_accept_encoding_t * header, 95 | char *value); 96 | /** 97 | * Get the value of an Accept-Encoding element. 98 | * @param header The element to work on. 99 | */ 100 | char *osip_accept_encoding_get_element (const osip_accept_encoding_t * header); 101 | /** 102 | * Allocate and Add a header parameter in an Accept-Encoding element. 103 | * @param header The element to work on. 104 | * @param name The token name for the new parameter. 105 | * @param value The token value for the new parameter. 106 | */ 107 | #define osip_accept_encoding_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 108 | /** 109 | * Find a header parameter in an Accept-Encoding element. 110 | * @param header The element to work on. 111 | * @param name The token name to search. 112 | * @param dest A pointer on the element found. 113 | */ 114 | #define osip_accept_encoding_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 115 | 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | /** @} */ 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /pmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "pmanager.h" 2 | #include "prtsp_client.h" 3 | #include "psip_server.h" 4 | #include "plog.h" 5 | #include 6 | #include "pmedia_client.h" 7 | #include "prtmp_client.h" 8 | 9 | PManager* PManager::m_manager = NULL; 10 | pthread_mutex_t PManager::m_mutex = PTHREAD_MUTEX_INITIALIZER; 11 | pthread_cond_t PManager::m_cond = PTHREAD_COND_INITIALIZER; 12 | 13 | PManager* PManager::Instance() 14 | { 15 | if (PManager::m_manager) 16 | { 17 | return PManager::m_manager; 18 | } 19 | else 20 | { 21 | pthread_mutex_lock(&PManager::m_mutex); 22 | 23 | if (PManager::m_manager) 24 | { 25 | pthread_mutex_unlock(&PManager::m_mutex); 26 | return PManager::m_manager; 27 | } 28 | else 29 | { 30 | PManager::m_manager = new PManager; 31 | pthread_mutex_unlock(&PManager::m_mutex); 32 | return PManager::m_manager; 33 | } 34 | } 35 | } 36 | 37 | PManager::PManager() 38 | : m_timer(NULL) 39 | , m_sipServer(NULL) 40 | , m_rtpIP("192.168.1.155") 41 | , m_minPort(10000) 42 | , m_maxPort(20000) 43 | , m_exit(false) 44 | { 45 | m_curPort = m_minPort; 46 | } 47 | 48 | void PManager::AquireLock() 49 | { 50 | pthread_mutex_lock(&PManager::m_mutex); 51 | } 52 | 53 | PMediaClient* PManager::GetMediaClient(PRtspConn* rtspConn, int pro, PString& url) 54 | { 55 | PMediaClient* cl = NULL; 56 | auto it = m_urlClient.find(url); 57 | 58 | if (it != m_urlClient.end()) 59 | { 60 | cl = it->second; 61 | cl->GetMediaInfo(rtspConn); 62 | 63 | return cl; 64 | } 65 | else 66 | { 67 | if (pro == media_pro::RTSP) 68 | { 69 | cl = new PRtspClient(url); 70 | 71 | cl->Start(); 72 | this->RegistClient(url, cl); 73 | cl->GetMediaInfo(rtspConn); 74 | } 75 | else if (pro == media_pro::GB28181) 76 | { 77 | cl = m_sipServer->CreateClient( url); 78 | 79 | if (cl) 80 | { 81 | this->RegistClient(url, cl); 82 | cl->GetMediaInfo(rtspConn); 83 | } 84 | } 85 | else if (pro == media_pro::PRTMP) 86 | { 87 | cl = new PRtmpClient(url); 88 | 89 | cl->Start(); 90 | this->RegistClient(url, cl); 91 | cl->GetMediaInfo(rtspConn); 92 | } 93 | } 94 | 95 | return cl; 96 | } 97 | 98 | void PManager::RegistClient(PString& url, PMediaClient* task) 99 | { 100 | m_urlClient[url] = task; 101 | } 102 | 103 | void PManager::UnregistClient(PString& url) 104 | { 105 | m_urlClient.erase(url); 106 | } 107 | 108 | void PManager::ReleaseLock() 109 | { 110 | pthread_mutex_unlock(&PManager::m_mutex); 111 | } 112 | 113 | void PManager::SetTimer(PTaskTimer* timer) 114 | { 115 | m_timer = timer; 116 | } 117 | 118 | PTaskTimer* PManager::GetTimer() 119 | { 120 | return m_timer; 121 | } 122 | 123 | void PManager::SetSipServer(PSipServer* s) 124 | { 125 | m_sipServer = s; 126 | } 127 | 128 | int PManager::CreateUdpSock(int& out_sock, PString& out_ip, uint16_t& out_port) 129 | { 130 | int retry = 1000; 131 | 132 | out_ip = m_rtpIP; 133 | 134 | while (retry) 135 | { 136 | --retry; 137 | out_sock = socket(AF_INET, SOCK_DGRAM, 0); 138 | if (out_sock < 0) 139 | { 140 | P_LOG("create udp sock err:%d", errno); 141 | return -1; 142 | } 143 | 144 | struct sockaddr_in bind_addr; 145 | 146 | memset(&bind_addr, 0, sizeof(bind_addr)); 147 | bind_addr.sin_family = AF_INET; 148 | bind_addr.sin_addr.s_addr = inet_addr(m_rtpIP.c_str()); 149 | bind_addr.sin_port = htons(m_curPort); 150 | 151 | if (bind(out_sock, (struct sockaddr*)&bind_addr, sizeof(bind_addr))) 152 | { 153 | close(out_sock); 154 | 155 | ++m_curPort; 156 | if (m_curPort > m_maxPort) 157 | { 158 | m_curPort = m_minPort; 159 | } 160 | } 161 | else 162 | { 163 | out_port = m_curPort; 164 | P_LOG("alloc udp port:%d", out_port); 165 | 166 | ++m_curPort; 167 | if (m_curPort > m_maxPort) 168 | { 169 | m_curPort = m_minPort; 170 | } 171 | 172 | return 0; 173 | } 174 | } 175 | 176 | return -1; 177 | } 178 | 179 | void PManager::Exit() 180 | { 181 | this->AquireLock(); 182 | m_exit = true; 183 | pthread_cond_signal(&PManager::m_cond); 184 | this->ReleaseLock(); 185 | } 186 | 187 | void PManager::RunLoop() 188 | { 189 | this->AquireLock(); 190 | while (!m_exit) 191 | { 192 | pthread_cond_wait(&PManager::m_cond, &PManager::m_mutex); 193 | } 194 | this->ReleaseLock(); 195 | } 196 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_record_route.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_RECORD_ROUTE_H_ 22 | #define _OSIP_RECORD_ROUTE_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_record_route.h 28 | * @brief oSIP osip_record_route header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_RECORD_ROUTE oSIP record-route header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Record-Route headers. 39 | * @var osip_record_route_t 40 | */ 41 | typedef osip_from_t osip_record_route_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | #ifndef MINISIZE 49 | /** 50 | * Allocate a Record-Route element. 51 | * @param header The element to work on. 52 | */ 53 | int osip_record_route_init (osip_record_route_t ** header); 54 | /** 55 | * Free a Record-Route element. 56 | * @param header The element to work on. 57 | */ 58 | void osip_record_route_free (osip_record_route_t * header); 59 | /** 60 | * Parse a Record-Route element. 61 | * @param header The element to work on. 62 | * @param hvalue The string to parse. 63 | */ 64 | int osip_record_route_parse (osip_record_route_t * header, const char *hvalue); 65 | /** 66 | * Get a string representation of a Record-Route element. 67 | * @param header The element to work on. 68 | * @param dest A pointer on the new allocated string. 69 | */ 70 | int osip_record_route_to_str (const osip_record_route_t * header, char **dest); 71 | /** 72 | * Clone a Record-Route element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | #define osip_record_route_clone osip_from_clone 77 | #else 78 | #define osip_record_route_init osip_from_init 79 | #define osip_record_route_free osip_from_free 80 | #define osip_record_route_parse osip_from_parse 81 | #define osip_record_route_to_str osip_from_to_str 82 | #define osip_record_route_clone osip_from_clone 83 | #endif 84 | /** 85 | * Set the url in the Record-Route element. 86 | * @param header The element to work on. 87 | * @param url The value of the element. 88 | */ 89 | #define osip_record_route_set_url(header,url) osip_from_set_url((osip_from_t*)header,url) 90 | /** 91 | * Get the url from a Record-Route header. 92 | * @param header The element to work on. 93 | */ 94 | #define osip_record_route_get_url(header) osip_from_get_url((osip_from_t*)header) 95 | /** 96 | * Get a header parameter from a Record-Route element. 97 | * @param header The element to work on. 98 | * @param pos The index of the element to get. 99 | * @param dest A pointer on the element found. 100 | */ 101 | #define osip_record_route_param_get(header,pos,dest) osip_from_param_get((osip_from_t*)header,pos,dest) 102 | /** 103 | * Allocate and add a generic parameter element in a list. 104 | * @param header The element to work on. 105 | * @param name The token name. 106 | * @param value The token value. 107 | */ 108 | #define osip_record_route_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 109 | /** 110 | * Find a header parameter in a Record-Route element. 111 | * @param header The element to work on. 112 | * @param name The token name to search. 113 | * @param dest A pointer on the element found. 114 | */ 115 | #define osip_record_route_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | /** @} */ 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_contact.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONTACT_H_ 22 | #define _OSIP_CONTACT_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_contact.h 28 | * @brief oSIP osip_contact header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_CONTACT oSIP contact header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Contact headers. 39 | * @var osip_contact_t 40 | */ 41 | typedef osip_from_t osip_contact_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | #ifndef MINISIZE 49 | /** 50 | * Allocate a Contact element. 51 | * @param header The element to work on. 52 | */ 53 | int osip_contact_init (osip_contact_t ** header); 54 | /** 55 | * Free a Contact element. 56 | * @param header The element to work on. 57 | */ 58 | void osip_contact_free (osip_contact_t * header); 59 | #endif 60 | /** 61 | * Parse a Contact element. 62 | * @param header The element to work on. 63 | * @param hvalue The string to parse. 64 | */ 65 | int osip_contact_parse (osip_contact_t * header, const char *hvalue); 66 | /** 67 | * Get a string representation of a Contact element. 68 | * @param header The element to work on. 69 | * @param dest A pointer on the new allocated string. 70 | */ 71 | int osip_contact_to_str (const osip_contact_t * header, char **dest); 72 | #ifndef MINISIZE 73 | /** 74 | * Clone a Contact element. 75 | * @param header The element to work on. 76 | * @param dest A pointer on the copy of the element. 77 | */ 78 | int osip_contact_clone (const osip_contact_t * header, osip_contact_t ** dest); 79 | #else 80 | #define osip_contact_init osip_from_init 81 | #define osip_contact_free osip_from_free 82 | #define osip_contact_clone osip_from_clone 83 | #endif 84 | /** 85 | * Get the displayname from a Contact header. 86 | * @param header The element to work on. 87 | */ 88 | #define osip_contact_get_displayname(header) osip_from_get_displayname((osip_from_t*)header) 89 | /** 90 | * Set the displayname in the Contact element. 91 | * @param header The element to work on. 92 | * @param value The value of the element. 93 | */ 94 | #define osip_contact_set_displayname(header,value) osip_from_set_displayname((osip_from_t*)header, value) 95 | /** 96 | * Get the url from a Contact header. 97 | * @param header The element to work on. 98 | */ 99 | #define osip_contact_get_url(header) osip_from_get_url((osip_from_t*)header) 100 | /** 101 | * Set the url in the Contact element. 102 | * @param header The element to work on. 103 | * @param url The value of the element. 104 | */ 105 | #define osip_contact_set_url(header,url) osip_from_set_url((osip_from_t*)header,url) 106 | /** 107 | * Get a header parameter from a Contact element. 108 | * @param header The element to work on. 109 | * @param pos The index of the element to get. 110 | * @param dest A pointer on the element found. 111 | */ 112 | #define osip_contact_param_get(header,pos,dest) osip_from_param_get((osip_from_t*)header,pos,dest) 113 | /** 114 | * Allocate and add a generic parameter element in a list. 115 | * @param header The element to work on. 116 | * @param name The token name. 117 | * @param value The token value. 118 | */ 119 | #define osip_contact_param_add(header,name, value) osip_generic_param_add((&(header)->gen_params), name,value) 120 | /** 121 | * Find a header parameter in a Contact element. 122 | * @param header The element to work on. 123 | * @param name The token name to search. 124 | * @param dest A pointer on the element found. 125 | */ 126 | #define osip_contact_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 127 | 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | /** @} */ 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /plog.cpp: -------------------------------------------------------------------------------- 1 | #include "plog.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | PLog* PLog::m_log = NULL; 8 | pthread_mutex_t PLog::m_mutex = PTHREAD_MUTEX_INITIALIZER; 9 | pthread_cond_t PLog::m_cond = PTHREAD_COND_INITIALIZER; 10 | 11 | char* PLog::GetLogBuf() 12 | { 13 | if (m_logBuf.size()) 14 | { 15 | char* buf = m_logBuf.front(); 16 | m_logBuf.pop(); 17 | return buf; 18 | } 19 | else 20 | { 21 | char* buf = (char*)malloc(1024); 22 | return buf; 23 | } 24 | } 25 | 26 | void PLog::RelLogBuf(char* buf) 27 | { 28 | if (m_logBuf.size() > 1024) 29 | { 30 | free(buf); 31 | } 32 | else 33 | { 34 | m_logBuf.push(buf); 35 | } 36 | } 37 | 38 | void PLog::EnqueLog(char* log) 39 | { 40 | m_logQue.push(log); 41 | 42 | pthread_cond_signal(&PLog::m_cond); 43 | } 44 | 45 | void PLog::GetLog(std::vector& logs) 46 | { 47 | while (m_logQue.size()) 48 | { 49 | logs.push_back(m_logQue.front()); 50 | m_logQue.pop(); 51 | } 52 | } 53 | 54 | void PLog::ProcessLog(std::vector& logs) 55 | { 56 | for (auto it = logs.begin(); it != logs.end(); ++it) 57 | { 58 | char* log = *it; 59 | time_t tt; 60 | struct tm atm; 61 | 62 | time(&tt); 63 | localtime_r(&tt, &atm); 64 | 65 | fprintf(m_fp, "%04d-%02d-%02d %02d:%02d:%02d ", 66 | atm.tm_year + 1900, atm.tm_mon + 1, atm.tm_mday, atm.tm_hour, atm.tm_min, atm.tm_sec); 67 | fprintf(m_fp, log); 68 | fflush(m_fp); 69 | } 70 | } 71 | 72 | void PLog::RelLog(std::vector& logs) 73 | { 74 | for (auto it = logs.begin(); it != logs.end(); ++it) 75 | { 76 | this->RelLogBuf(*it); 77 | } 78 | 79 | logs.clear(); 80 | } 81 | 82 | PLog* PLog::Instance() 83 | { 84 | if (PLog::m_log) 85 | { 86 | return PLog::m_log; 87 | } 88 | else 89 | { 90 | pthread_mutex_lock(&PLog::m_mutex); 91 | 92 | if (PLog::m_log) 93 | { 94 | pthread_mutex_unlock(&PLog::m_mutex); 95 | return PLog::m_log; 96 | } 97 | else 98 | { 99 | PLog::m_log = new PLog; 100 | pthread_mutex_unlock(&PLog::m_mutex); 101 | return PLog::m_log; 102 | } 103 | } 104 | } 105 | 106 | static void * log_start(void *arg) 107 | { 108 | PLog* log = static_cast(arg); 109 | log->OnRun(); 110 | delete log; 111 | return NULL; 112 | } 113 | 114 | PLog::PLog() 115 | : m_fp(NULL) 116 | , m_exit(false) 117 | { 118 | 119 | } 120 | 121 | PLog::~PLog() 122 | { 123 | if (m_fp) 124 | { 125 | fclose(m_fp); 126 | } 127 | 128 | while (m_logQue.size()) 129 | { 130 | char* log = m_logQue.front(); 131 | free(log); 132 | m_logQue.pop(); 133 | } 134 | 135 | while (m_logBuf.size()) 136 | { 137 | char* log = m_logBuf.front(); 138 | free(log); 139 | m_logBuf.pop(); 140 | } 141 | } 142 | 143 | void PLog::Init(const char* logFile) 144 | { 145 | pthread_mutex_lock(&PLog::m_mutex); 146 | 147 | m_logFile = logFile; 148 | pthread_t tid; 149 | pthread_attr_t attr; 150 | 151 | pthread_attr_init(&attr); 152 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 153 | 154 | int ret = pthread_create(&tid, &attr, log_start, this); 155 | if (ret) 156 | { 157 | printf("create log thread err:%d\n", ret); 158 | pthread_mutex_unlock(&PLog::m_mutex); 159 | 160 | } 161 | else 162 | { 163 | pthread_cond_wait(&PLog::m_cond, &PLog::m_mutex); 164 | pthread_mutex_unlock(&PLog::m_mutex); 165 | } 166 | 167 | pthread_attr_destroy(&attr); 168 | } 169 | 170 | void PLog::Exit() 171 | { 172 | pthread_mutex_lock(&PLog::m_mutex); 173 | m_exit = true; 174 | pthread_cond_signal(&PLog::m_cond); 175 | pthread_mutex_unlock(&PLog::m_mutex); 176 | } 177 | 178 | void PLog::OnRun() 179 | { 180 | pthread_cond_signal(&PLog::m_cond); 181 | 182 | m_fp = fopen(m_logFile.c_str(), "a"); 183 | if (!m_fp) 184 | { 185 | printf("open %s err:%d\n", m_logFile.c_str(), errno); 186 | return; 187 | } 188 | 189 | std::vector logs; 190 | 191 | pthread_mutex_lock(&PLog::m_mutex); 192 | 193 | while (!m_exit) 194 | { 195 | //release lock 196 | pthread_cond_wait(&PLog::m_cond, &PLog::m_mutex); 197 | 198 | //aquire lock 199 | while (m_logQue.size()) 200 | { 201 | this->GetLog(logs); 202 | 203 | //release lock 204 | pthread_mutex_unlock(&PLog::m_mutex); 205 | 206 | //slow write disk 207 | this->ProcessLog(logs); 208 | 209 | //aquire lock 210 | pthread_mutex_lock(&PLog::m_mutex); 211 | 212 | //release log buffer 213 | this->RelLog(logs); 214 | } 215 | } 216 | 217 | pthread_mutex_unlock(&PLog::m_mutex); 218 | } 219 | 220 | void PLog::Log(const char* strLog, ...) 221 | { 222 | pthread_mutex_lock(&PLog::m_mutex); 223 | 224 | if (m_exit) 225 | { 226 | pthread_mutex_unlock(&PLog::m_mutex); 227 | return; 228 | } 229 | 230 | char* logBuf = this->GetLogBuf(); 231 | int maxLen = 1024 - 1; 232 | 233 | va_list argList; 234 | 235 | va_start(argList, strLog); 236 | 237 | int nRet = vsnprintf(logBuf, maxLen, strLog, argList); 238 | 239 | va_end(argList); 240 | 241 | if (nRet < 0) 242 | { 243 | this->RelLogBuf(logBuf); 244 | } 245 | else 246 | { 247 | if (nRet > maxLen - 1) 248 | { 249 | nRet = maxLen - 1; 250 | } 251 | 252 | logBuf[nRet] = '\n'; 253 | logBuf[nRet + 1] = '\0'; 254 | 255 | this->EnqueLog(logBuf); 256 | } 257 | 258 | pthread_mutex_unlock(&PLog::m_mutex); 259 | } 260 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_from.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_FROM_H_ 22 | #define _OSIP_FROM_H_ 23 | 24 | #include 25 | #include 26 | 27 | /** 28 | * @file osip_from.h 29 | * @brief oSIP osip_from header definition. 30 | */ 31 | 32 | /** 33 | * @defgroup oSIP_FROM oSIP from header definition. 34 | * @ingroup oSIP_HEADERS 35 | * @{ 36 | */ 37 | 38 | /** 39 | * Structure for From headers. 40 | * @var osip_from_t 41 | */ 42 | typedef struct osip_from osip_from_t; 43 | 44 | /** 45 | * Definition of the From header. 46 | * @struct osip_from 47 | */ 48 | struct osip_from 49 | { 50 | char *displayname; /**< Display Name */ 51 | osip_uri_t *url; /**< url */ 52 | osip_list_t gen_params; /**< other From parameters */ 53 | }; 54 | 55 | #ifdef __cplusplus 56 | extern "C" 57 | { 58 | #endif 59 | 60 | /** 61 | * Allocate a From element. 62 | * @param header The element to work on. 63 | */ 64 | int osip_from_init (osip_from_t ** header); 65 | /** 66 | * Free a From element. 67 | * @param header The element to work on. 68 | */ 69 | void osip_from_free (osip_from_t * header); 70 | /** 71 | * Parse a From element. 72 | * @param header The element to work on. 73 | * @param hvalue The string to parse. 74 | */ 75 | int osip_from_parse (osip_from_t * header, const char *hvalue); 76 | /** 77 | * Get a string representation of a From element. 78 | * @param header The element to work on. 79 | * @param dest A pointer on the new allocated string. 80 | */ 81 | int osip_from_to_str (const osip_from_t * header, char **dest); 82 | /** 83 | * Clone a From element. 84 | * @param header The element to work on. 85 | * @param dest A pointer on the copy of the element. 86 | */ 87 | int osip_from_clone (const osip_from_t * header, osip_from_t ** dest); 88 | /** 89 | * Set the displayname in the From element. 90 | * @param header The element to work on. 91 | * @param value The value of the element. 92 | */ 93 | void osip_from_set_displayname (osip_from_t * header, char *value); 94 | /** 95 | * Get the displayname from a From header. 96 | * @param header The element to work on. 97 | */ 98 | char *osip_from_get_displayname (osip_from_t * header); 99 | /** 100 | * Set the url in the From element. 101 | * @param header The element to work on. 102 | * @param url The value of the element. 103 | */ 104 | void osip_from_set_url (osip_from_t * header, osip_uri_t * url); 105 | /** 106 | * Get the url from a From header. 107 | * @param header The element to work on. 108 | */ 109 | osip_uri_t *osip_from_get_url (osip_from_t * header); 110 | /** 111 | * Get a header parameter from a From element. 112 | * @param header The element to work on. 113 | * @param pos The index of the element to get. 114 | * @param dest A pointer on the element found. 115 | */ 116 | int osip_from_param_get (osip_from_t * header, int pos, osip_generic_param_t ** dest); 117 | /** 118 | * Allocate and add a generic parameter element in a list. 119 | * @param header The element to work on. 120 | * @param name The token name. 121 | * @param value The token value. 122 | */ 123 | #define osip_from_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 124 | /** 125 | * Find a header parameter in a From element. 126 | * @param header The element to work on. 127 | * @param name The token name to search. 128 | * @param dest A pointer on the element found. 129 | */ 130 | #define osip_from_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 131 | 132 | /** 133 | * Find the tag parameter in a From element. 134 | * @param header The element to work on. 135 | * @param dest A pointer on the element found. 136 | */ 137 | #define osip_from_get_tag(header,dest) osip_generic_param_get_byname((&(header)->gen_params), "tag",dest) 138 | /** 139 | * Allocate and add a tag parameter element in a Contact element. 140 | * @param header The element to work on. 141 | * @param value The token value. 142 | */ 143 | #define osip_from_set_tag(header,value) osip_generic_param_add((&(header)->gen_params), osip_strdup("tag"),value) 144 | 145 | #ifndef DOXYGEN /* avoid DOXYGEN warning */ 146 | /* Compare the username, host and tag part (if exist) of the two froms */ 147 | int osip_from_compare (osip_from_t * header1, osip_from_t * header2); 148 | #endif 149 | 150 | /** 151 | * Check if the tags in the From headers match. 152 | * NOTE: THIS IS AN INTERNAL METHOD ONLY 153 | * @param from1 The first From header. 154 | * @param from2 The second From header. 155 | */ 156 | int osip_from_tag_match (osip_from_t * from1, osip_from_t * from2); 157 | 158 | 159 | #ifdef __cplusplus 160 | } 161 | #endif 162 | 163 | /** @} */ 164 | 165 | #endif 166 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_to.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_TO_H_ 22 | #define _OSIP_TO_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_to.h 28 | * @brief oSIP osip_to header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_TO oSIP to header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for To headers. 39 | * @var osip_to_t 40 | */ 41 | typedef osip_from_t osip_to_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | #ifndef MINISIZE 49 | /** 50 | * Allocate a To element. 51 | * @param header The element to work on. 52 | */ 53 | int osip_to_init (osip_to_t ** header); 54 | /** 55 | * Free a To element. 56 | * @param header The element to work on. 57 | */ 58 | void osip_to_free (osip_to_t * header); 59 | /** 60 | * Parse a To element. 61 | * @param header The element to work on. 62 | * @param hvalue The string to parse. 63 | */ 64 | int osip_to_parse (osip_to_t * header, const char *hvalue); 65 | /** 66 | * Get a string representation of a To element. 67 | * @param header The element to work on. 68 | * @param dest A pointer on the new allocated string. 69 | */ 70 | int osip_to_to_str (const osip_to_t * header, char **dest); 71 | /** 72 | * Clone a To element. 73 | * @param header The element to work on. 74 | * @param dest A pointer on the copy of the element. 75 | */ 76 | int osip_to_clone (const osip_to_t * header, osip_to_t ** dest); 77 | /** 78 | * Check if the tags in the To headers match. 79 | * NOTE: THIS IS AN INTERNAL METHOD ONLY 80 | * @param to1 The first To header. 81 | * @param to2 The second To header. 82 | */ 83 | int osip_to_tag_match (osip_to_t * to1, osip_to_t * to2); 84 | #else 85 | #define osip_to_init osip_from_init 86 | #define osip_to_free osip_from_free 87 | #define osip_to_parse osip_from_parse 88 | #define osip_to_to_str osip_from_to_str 89 | #define osip_to_clone osip_from_clone 90 | #define osip_to_tag_match osip_from_tag_match 91 | #endif 92 | /** 93 | * Set the displayname in the To element. 94 | * @param header The element to work on. 95 | * @param value The value of the element. 96 | */ 97 | #define osip_to_set_displayname(header,value) osip_from_set_displayname((osip_from_t*)header,value) 98 | /** 99 | * Get the displayname from a To header. 100 | * @param header The element to work on. 101 | */ 102 | #define osip_to_get_displayname(header) osip_from_get_displayname((osip_from_t*)header) 103 | /** 104 | * Set the url in the To element. 105 | * @param header The element to work on. 106 | * @param url The value of the element. 107 | */ 108 | #define osip_to_set_url(header,url) osip_from_set_url((osip_from_t*)header,url) 109 | /** 110 | * Get the url from a To header. 111 | * @param header The element to work on. 112 | */ 113 | #define osip_to_get_url(header) osip_from_get_url((osip_from_t*)header) 114 | /** 115 | * Get a header parameter from a To element. 116 | * @param header The element to work on. 117 | * @param pos The index of the element to get. 118 | * @param dest A pointer on the element found. 119 | */ 120 | #define osip_to_param_get(header,pos,dest) osip_from_param_get((osip_from_t*)header,pos,dest) 121 | /** 122 | * Find a header parameter in a To element. 123 | * @param header The element to work on. 124 | * @param name The token name to search. 125 | * @param dest A pointer on the element found. 126 | */ 127 | #define osip_to_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->gen_params),name,dest) 128 | /** 129 | * Allocate and add a generic parameter element in a list. 130 | * @param header The element to work on. 131 | * @param name The token name. 132 | * @param value The token value. 133 | */ 134 | #define osip_to_param_add(header,name,value) osip_generic_param_add((&(header)->gen_params),name,value) 135 | 136 | /** 137 | * Allocate and add a tag parameter element in a list. 138 | * @param header The element to work on. 139 | * @param value The token value. 140 | */ 141 | #define osip_to_set_tag(header,value) osip_generic_param_add((&(header)->gen_params), osip_strdup("tag"),value) 142 | /** 143 | * Find a tag parameter in a To element. 144 | * @param header The element to work on. 145 | * @param dest A pointer on the element found. 146 | */ 147 | #define osip_to_get_tag(header,dest) osip_generic_param_get_byname((&(header)->gen_params), "tag",dest) 148 | 149 | #ifndef DOXYGEN /* avoid DOXYGEN warning */ 150 | /* Compare the username, host and tag part of the two froms */ 151 | #define osip_to_compare(header1, header2) osip_from_compare((osip_from_t *)header1, (osip_from_t *)header2) 152 | #endif 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | /** @} */ 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/osip_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _LIST_H_ 22 | #define _LIST_H_ 23 | 24 | #ifdef ENABLE_MPATROL 25 | #include 26 | #endif 27 | 28 | /** 29 | * @file osip_list.h 30 | * @brief oSIP list Routines 31 | * 32 | * This is a simple implementation of a linked list. 33 | */ 34 | 35 | /** 36 | * @defgroup oSIP_LIST oSIP list Handling 37 | * @{ 38 | */ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #ifndef DOXYGEN 45 | /** 46 | * Structure for referencing a node in a osip_list_t element. 47 | * @var __node_t 48 | */ 49 | typedef struct __node __node_t; 50 | 51 | /** 52 | * Structure for referencing a node in a osip_list_t element. 53 | * @struct __node 54 | */ 55 | struct __node { 56 | __node_t *next; /**< next __node_t containing element */ 57 | void *element; /**< element in Current node */ 58 | }; 59 | #endif 60 | 61 | /** 62 | * Structure for referencing a list of elements. 63 | * @var osip_list_t 64 | */ 65 | typedef struct osip_list osip_list_t; 66 | 67 | /** 68 | * Structure used to iterate list. 69 | * @var osip_list_iterator_t 70 | */ 71 | typedef struct { 72 | __node_t *actual; /**< actual */ 73 | __node_t **prev; /**< prev */ 74 | osip_list_t *li; /**< li */ 75 | int pos; /**< pos */ 76 | } osip_list_iterator_t; 77 | 78 | /** 79 | * Structure for referencing a list of elements. 80 | * @struct osip_list 81 | */ 82 | struct osip_list { 83 | 84 | int nb_elt; /**< Number of element in the list */ 85 | __node_t *node; /**< Next node containing element */ 86 | 87 | }; 88 | 89 | /** 90 | * Initialise a osip_list_t element. 91 | * NOTE: this element MUST be previously allocated with 92 | * osip_malloc(). The osip_free() call on the list is 93 | * still automatically done by osip_list_free(). This 94 | * also means you can't use a static osip_list_t variable 95 | * if you want to use osip_list_free(). 96 | * @param li The element to initialise. 97 | */ 98 | int osip_list_init (osip_list_t * li); 99 | /** 100 | * Free a list of element. 101 | * Each element will be free with the method given as the second parameter. 102 | * @param li The element to work on. 103 | * @param free_func The method that is able to release one element of the list. 104 | */ 105 | void osip_list_special_free (osip_list_t * li, void (*free_func) (void *)); 106 | /** 107 | * Clone a list of element. 108 | * Each element will be cloned with the method given as the second parameter. 109 | * @param src The element to work on. 110 | * @param dst The element to work on. 111 | * @param clone_func The method that is able to release one element of the list. 112 | */ 113 | int osip_list_clone (const osip_list_t * src, osip_list_t * dst, int (*clone_func) (void *, void **)); 114 | /** 115 | * Free a list of element where elements are pointer to 'char'. 116 | * @param li The element to work on. 117 | */ 118 | void osip_list_ofchar_free (osip_list_t * li); 119 | /** 120 | * Get the size of a list of element. 121 | * @param li The element to work on. 122 | */ 123 | int osip_list_size (const osip_list_t * li); 124 | /** 125 | * Check if the end of list is detected . 126 | * @param li The element to work on. 127 | * @param pos The index of the possible element. 128 | */ 129 | int osip_list_eol (const osip_list_t * li, int pos); 130 | /** 131 | * Add an element in a list. 132 | * @param li The element to work on. 133 | * @param element The pointer on the element to add. 134 | * @param pos the index of the element to add. (or -1 to append the element at the end) 135 | */ 136 | int osip_list_add (osip_list_t * li, void *element, int pos); 137 | /** 138 | * Get an element from a list. 139 | * @param li The element to work on. 140 | * @param pos the index of the element to get. 141 | */ 142 | void *osip_list_get (const osip_list_t * li, int pos); 143 | /** 144 | * Remove an element from a list. 145 | * @param li The element to work on. 146 | * @param pos the index of the element to remove. 147 | */ 148 | int osip_list_remove (osip_list_t * li, int pos); 149 | 150 | /** 151 | * Check current iterator state. 152 | * @param it The element to work on. 153 | */ 154 | #define osip_list_iterator_has_elem( it ) ( 0 != (it).actual && (it).pos < (it).li->nb_elt ) 155 | /** 156 | * Get first iterator from list. 157 | * @param li The element to work on. 158 | * @param it The iterator. 159 | */ 160 | void *osip_list_get_first (const osip_list_t * li, osip_list_iterator_t * it); 161 | /** 162 | * GEt next iterator. 163 | * @param it The element to work on. 164 | */ 165 | void *osip_list_get_next (osip_list_iterator_t * it); 166 | /** 167 | * Remove current iterator. 168 | * @param it The element to work on. 169 | */ 170 | void *osip_list_iterator_remove (osip_list_iterator_t * it); 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | /** @} */ 176 | #endif 177 | -------------------------------------------------------------------------------- /psip_server.cpp: -------------------------------------------------------------------------------- 1 | #include "psip_server.h" 2 | #include "psip_conn.h" 3 | #include "plog.h" 4 | #include 5 | #include "psip_client.h" 6 | 7 | PSipServer::PSipServer(PString& domain, PString& pwd, PString& ip, uint16_t port) 8 | : m_domain(domain) 9 | , m_passwd(pwd) 10 | , m_ip(ip) 11 | , m_port(port) 12 | { 13 | std::srand(std::time(NULL)); 14 | } 15 | 16 | void PSipServer::OnRun() 17 | { 18 | m_sock = socket(AF_INET, SOCK_DGRAM, 0); 19 | 20 | if (m_sock < 0) 21 | { 22 | P_LOG("create socket error:%d", errno); 23 | return; 24 | } 25 | 26 | struct sockaddr_in server_addr; 27 | 28 | memset(&server_addr, 0, sizeof(server_addr)); 29 | server_addr.sin_family = AF_INET; 30 | server_addr.sin_addr.s_addr = inet_addr(m_ip.c_str()); 31 | server_addr.sin_port = htons(m_port); 32 | 33 | if (bind(m_sock, (struct sockaddr*)&server_addr, sizeof(server_addr))) 34 | { 35 | P_LOG("bind socket error:%d", errno); 36 | return; 37 | } 38 | 39 | this->AddInEvent(m_sock); 40 | 41 | parser_init(); 42 | 43 | struct epoll_event events[DEF_MAX_EVENTS]; 44 | std::vector msgs; 45 | int ret; 46 | 47 | for (;;) 48 | { 49 | ret = this->WaitEvent(events, msgs, -1); 50 | 51 | if (ret < 0) 52 | { 53 | P_LOG("epoll wait err:%d", errno); 54 | return; 55 | } 56 | else 57 | { 58 | for (int i = 0; i < ret; ++i) 59 | { 60 | struct epoll_event& ev = events[i]; 61 | 62 | if (ev.data.fd == m_sock) 63 | { 64 | if (this->udp_recv()) 65 | { 66 | P_LOG("sip recv err"); 67 | return; 68 | } 69 | } 70 | else 71 | { 72 | P_LOG("epoll no match fd"); 73 | return; 74 | } 75 | } 76 | 77 | for (auto it = msgs.begin(); it != msgs.end(); ++it) 78 | { 79 | if (this->process_msg(*it)) 80 | { 81 | return; 82 | } 83 | } 84 | 85 | } 86 | } 87 | } 88 | 89 | int PSipServer::udp_recv() 90 | { 91 | sockaddr_in cAddr; 92 | socklen_t cAddrLen = sizeof(sockaddr_in); 93 | char buf[2048]; 94 | 95 | int ret = recvfrom(m_sock, buf, 2048, 0, (struct sockaddr *)&cAddr, &cAddrLen); 96 | 97 | if (ret <=0 ) 98 | { 99 | return ret; 100 | } 101 | 102 | osip_message_t* sip; 103 | osip_message_init(&sip); 104 | 105 | ret = osip_message_parse(sip, buf, ret); 106 | 107 | if (ret) 108 | { 109 | P_LOG("illegal msg"); 110 | osip_message_free(sip); 111 | return 0; 112 | } 113 | 114 | char* dest; 115 | size_t length; 116 | 117 | osip_message_to_str(sip, &dest, &length); 118 | 119 | //P_LOG("message:\n%s\n", dest); 120 | osip_free(dest); 121 | 122 | if (MSG_IS_REQUEST(sip)) 123 | { 124 | PSipConn* conn; 125 | PString username = sip->from->url->username; 126 | auto it = m_sipConn.find(username); 127 | 128 | if (it == m_sipConn.end()) 129 | { 130 | conn = new PSipConn(this); 131 | m_sipConn[username] = conn; 132 | } 133 | else 134 | { 135 | conn = it->second; 136 | } 137 | 138 | if (conn->process_req(sip, cAddr, cAddrLen)) 139 | { 140 | m_sipConn.erase(username); 141 | delete conn; 142 | } 143 | } 144 | else if (MSG_IS_STATUS_2XX(sip)) 145 | { 146 | PString callid = sip->call_id->number; 147 | auto it = m_sipDialog.find(callid); 148 | 149 | if (it != m_sipDialog.end()) 150 | { 151 | sip_dialog* sd = it->second; 152 | sd->sipClient->process_sip(sip, sd); 153 | } 154 | } 155 | 156 | osip_message_free(sip); 157 | 158 | return 0; 159 | } 160 | 161 | int PSipServer::process_msg(PTaskMsg& msg) 162 | { 163 | return 0; 164 | } 165 | 166 | const PString& PSipServer::get_domain() 167 | { 168 | return m_domain; 169 | } 170 | 171 | const PString& PSipServer::get_passwd() 172 | { 173 | return m_passwd; 174 | } 175 | 176 | void PSipServer::send_sip_rsp(osip_message_t* rsp, sockaddr_in& in_addr, socklen_t in_addrlen) 177 | { 178 | char *dest = NULL; 179 | size_t length = 0; 180 | 181 | osip_message_to_str(rsp, &dest, &length); 182 | //P_LOG("message:\n%s\n", dest); 183 | 184 | int ret = sendto(m_sock, dest, length, 0, (struct sockaddr*)&in_addr, in_addrlen); 185 | if (ret != length) 186 | { 187 | P_LOG("send failed"); 188 | } 189 | 190 | osip_free(dest); 191 | osip_message_free(rsp); 192 | } 193 | 194 | void PSipServer::send_sip_rsp(osip_message_t* rsp, const char* ip, const char* port) 195 | { 196 | sockaddr_in addr; 197 | socklen_t addrLen = sizeof(addr); 198 | uint16_t nPort = atoi(port); 199 | 200 | addr.sin_family = AF_INET; 201 | addr.sin_addr.s_addr = inet_addr(ip); 202 | addr.sin_port = htons(nPort); 203 | 204 | this->send_sip_rsp(rsp, addr, addrLen); 205 | } 206 | 207 | PMediaClient* PSipServer::CreateClient(PString& url) 208 | { 209 | if (memcmp(url.c_str(), "gb://", strlen("gb://"))) 210 | { 211 | P_LOG("wrong gb url:%s", url.c_str()); 212 | return NULL; 213 | } 214 | 215 | char* p1 = url.data() + strlen("gb://"); 216 | char* p = strchr(p1, '/'); 217 | 218 | if (!p) 219 | { 220 | P_LOG("wrong url:%s", url.c_str()); 221 | return NULL; 222 | } 223 | 224 | PString device; 225 | 226 | device.assign(p1, p - p1); 227 | 228 | auto it = m_sipConn.find(device); 229 | if (it == m_sipConn.end()) 230 | { 231 | P_LOG("no dev:%s", url.c_str()); 232 | return NULL; 233 | } 234 | 235 | PString channel = ++p; 236 | PSipConn* sipConn = it->second; 237 | 238 | return sipConn->init_invite(channel, url); 239 | } 240 | 241 | PString& PSipServer::get_ip() 242 | { 243 | return m_ip; 244 | } 245 | 246 | int PSipServer::get_port() 247 | { 248 | return m_port; 249 | } 250 | 251 | void PSipServer::add_dialog(sip_dialog* dialog) 252 | { 253 | m_sipDialog[dialog->callid] = dialog; 254 | } 255 | 256 | void PSipServer::del_dialog(PString& callid) 257 | { 258 | auto it = m_sipDialog.find(callid); 259 | if (it != m_sipDialog.end()) 260 | { 261 | sip_dialog* p = it->second; 262 | 263 | m_sipDialog.erase(it); 264 | delete p; 265 | } 266 | } 267 | 268 | sip_dialog* PSipServer::get_dialog(PString& callid) 269 | { 270 | auto it = m_sipDialog.find(callid); 271 | if (it != m_sipDialog.end()) 272 | { 273 | return it->second; 274 | } 275 | 276 | return NULL; 277 | } 278 | -------------------------------------------------------------------------------- /librtmp/include/librtmp/amf.h: -------------------------------------------------------------------------------- 1 | #ifndef __AMF_H__ 2 | #define __AMF_H__ 3 | /* 4 | * Copyright (C) 2005-2008 Team XBMC 5 | * http://www.xbmc.org 6 | * Copyright (C) 2008-2009 Andrej Stepanchuk 7 | * Copyright (C) 2009-2010 Howard Chu 8 | * 9 | * This file is part of librtmp. 10 | * 11 | * librtmp is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU Lesser General Public License as 13 | * published by the Free Software Foundation; either version 2.1, 14 | * or (at your option) any later version. 15 | * 16 | * librtmp is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public License 22 | * along with librtmp see the file COPYING. If not, write to 23 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 | * Boston, MA 02110-1301, USA. 25 | * http://www.gnu.org/copyleft/lgpl.html 26 | */ 27 | 28 | #include 29 | 30 | #ifndef TRUE 31 | #define TRUE 1 32 | #define FALSE 0 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif 39 | 40 | typedef enum 41 | { AMF_NUMBER = 0, AMF_BOOLEAN, AMF_STRING, AMF_OBJECT, 42 | AMF_MOVIECLIP, /* reserved, not used */ 43 | AMF_NULL, AMF_UNDEFINED, AMF_REFERENCE, AMF_ECMA_ARRAY, AMF_OBJECT_END, 44 | AMF_STRICT_ARRAY, AMF_DATE, AMF_LONG_STRING, AMF_UNSUPPORTED, 45 | AMF_RECORDSET, /* reserved, not used */ 46 | AMF_XML_DOC, AMF_TYPED_OBJECT, 47 | AMF_AVMPLUS, /* switch to AMF3 */ 48 | AMF_INVALID = 0xff 49 | } AMFDataType; 50 | 51 | typedef enum 52 | { AMF3_UNDEFINED = 0, AMF3_NULL, AMF3_FALSE, AMF3_TRUE, 53 | AMF3_INTEGER, AMF3_DOUBLE, AMF3_STRING, AMF3_XML_DOC, AMF3_DATE, 54 | AMF3_ARRAY, AMF3_OBJECT, AMF3_XML, AMF3_BYTE_ARRAY 55 | } AMF3DataType; 56 | 57 | typedef struct AVal 58 | { 59 | char *av_val; 60 | int av_len; 61 | } AVal; 62 | #define AVC(str) {str,sizeof(str)-1} 63 | #define AVMATCH(a1,a2) ((a1)->av_len == (a2)->av_len && !memcmp((a1)->av_val,(a2)->av_val,(a1)->av_len)) 64 | 65 | struct AMFObjectProperty; 66 | 67 | typedef struct AMFObject 68 | { 69 | int o_num; 70 | struct AMFObjectProperty *o_props; 71 | } AMFObject; 72 | 73 | typedef struct AMFObjectProperty 74 | { 75 | AVal p_name; 76 | AMFDataType p_type; 77 | union 78 | { 79 | double p_number; 80 | AVal p_aval; 81 | AMFObject p_object; 82 | } p_vu; 83 | int16_t p_UTCoffset; 84 | } AMFObjectProperty; 85 | 86 | char *AMF_EncodeString(char *output, char *outend, const AVal * str); 87 | char *AMF_EncodeNumber(char *output, char *outend, double dVal); 88 | char *AMF_EncodeInt16(char *output, char *outend, short nVal); 89 | char *AMF_EncodeInt24(char *output, char *outend, int nVal); 90 | char *AMF_EncodeInt32(char *output, char *outend, int nVal); 91 | char *AMF_EncodeBoolean(char *output, char *outend, int bVal); 92 | 93 | /* Shortcuts for AMFProp_Encode */ 94 | char *AMF_EncodeNamedString(char *output, char *outend, const AVal * name, const AVal * value); 95 | char *AMF_EncodeNamedNumber(char *output, char *outend, const AVal * name, double dVal); 96 | char *AMF_EncodeNamedBoolean(char *output, char *outend, const AVal * name, int bVal); 97 | 98 | unsigned short AMF_DecodeInt16(const char *data); 99 | unsigned int AMF_DecodeInt24(const char *data); 100 | unsigned int AMF_DecodeInt32(const char *data); 101 | void AMF_DecodeString(const char *data, AVal * str); 102 | void AMF_DecodeLongString(const char *data, AVal * str); 103 | int AMF_DecodeBoolean(const char *data); 104 | double AMF_DecodeNumber(const char *data); 105 | 106 | char *AMF_Encode(AMFObject * obj, char *pBuffer, char *pBufEnd); 107 | char *AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd); 108 | char *AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd); 109 | 110 | int AMF_Decode(AMFObject * obj, const char *pBuffer, int nSize, 111 | int bDecodeName); 112 | int AMF_DecodeArray(AMFObject * obj, const char *pBuffer, int nSize, 113 | int nArrayLen, int bDecodeName); 114 | int AMF3_Decode(AMFObject * obj, const char *pBuffer, int nSize, 115 | int bDecodeName); 116 | void AMF_Dump(AMFObject * obj); 117 | void AMF_Reset(AMFObject * obj); 118 | 119 | void AMF_AddProp(AMFObject * obj, const AMFObjectProperty * prop); 120 | int AMF_CountProp(AMFObject * obj); 121 | AMFObjectProperty *AMF_GetProp(AMFObject * obj, const AVal * name, 122 | int nIndex); 123 | 124 | AMFDataType AMFProp_GetType(AMFObjectProperty * prop); 125 | void AMFProp_SetNumber(AMFObjectProperty * prop, double dval); 126 | void AMFProp_SetBoolean(AMFObjectProperty * prop, int bflag); 127 | void AMFProp_SetString(AMFObjectProperty * prop, AVal * str); 128 | void AMFProp_SetObject(AMFObjectProperty * prop, AMFObject * obj); 129 | 130 | void AMFProp_GetName(AMFObjectProperty * prop, AVal * name); 131 | void AMFProp_SetName(AMFObjectProperty * prop, AVal * name); 132 | double AMFProp_GetNumber(AMFObjectProperty * prop); 133 | int AMFProp_GetBoolean(AMFObjectProperty * prop); 134 | void AMFProp_GetString(AMFObjectProperty * prop, AVal * str); 135 | void AMFProp_GetObject(AMFObjectProperty * prop, AMFObject * obj); 136 | 137 | int AMFProp_IsValid(AMFObjectProperty * prop); 138 | 139 | char *AMFProp_Encode(AMFObjectProperty * prop, char *pBuffer, char *pBufEnd); 140 | int AMF3Prop_Decode(AMFObjectProperty * prop, const char *pBuffer, 141 | int nSize, int bDecodeName); 142 | int AMFProp_Decode(AMFObjectProperty * prop, const char *pBuffer, 143 | int nSize, int bDecodeName); 144 | 145 | void AMFProp_Dump(AMFObjectProperty * prop); 146 | void AMFProp_Reset(AMFObjectProperty * prop); 147 | 148 | typedef struct AMF3ClassDef 149 | { 150 | AVal cd_name; 151 | char cd_externalizable; 152 | char cd_dynamic; 153 | int cd_num; 154 | AVal *cd_props; 155 | } AMF3ClassDef; 156 | 157 | void AMF3CD_AddProp(AMF3ClassDef * cd, AVal * prop); 158 | AVal *AMF3CD_GetProp(AMF3ClassDef * cd, int idx); 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif /* __AMF_H__ */ 165 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/osip_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_CONST_H_ 22 | #define _OSIP_CONST_H_ 23 | 24 | #ifdef ENABLE_MPATROL 25 | #include 26 | #endif 27 | 28 | #define CRLF "\r\n\0" 29 | #define CR "\r\0" 30 | #define LF "\n\0" 31 | #define SP " \0" 32 | 33 | 34 | #define ACCEPT "accept" 35 | #define ACCEPT_ENCODING "accept-encoding" 36 | #define ACCEPT_LANGUAGE "accept-language" 37 | #define ALERT_INFO "alert-info" 38 | #define ALLOW "allow" 39 | #define AUTHENTICATION_INFO "authentication-info" 40 | #define AUTHORIZATION "authorization" 41 | #define CALL_ID "call-id" 42 | #define CALL_ID_SHORT "i" 43 | #define CALL_INFO "call-info" 44 | #define CONTACT "contact" 45 | #define CONTACT_SHORT "m" 46 | #define CONTENT_DISPOSITION "content-disposition" 47 | #define CONTENT_ENCODING_SHORT "e" 48 | #define CONTENT_ENCODING "content-encoding" 49 | #define CONTENT_LANGUAGE "content-language" 50 | #define CONTENT_LENGTH_SHORT "l" 51 | #define CONTENT_LENGTH "content-length" 52 | #define CONTENT_TYPE_SHORT "c" 53 | #define CONTENT_TYPE "content-type" 54 | #define CSEQ "cseq" 55 | #define SIPDATE "date" 56 | #define ERROR_INFO "error-info" 57 | #define EXPIRES "expires" 58 | #define FROM "from" 59 | #define FROM_SHORT "f" 60 | #define IN_REPLY_TO "in-reply-to" 61 | #define MAX_FORWARDS "max-forwards" 62 | #define MIME_VERSION "mime-version" 63 | #define MIN_EXPIRES "min-expires" 64 | #define ORGANIZATION "organization" 65 | #define PRIORITY "priority" 66 | #define PROXY_AUTHENTICATE "proxy-authenticate" 67 | #define PROXY_AUTHENTICATION_INFO "proxy-authentication-info" 68 | #define PROXY_AUTHORIZATION "proxy-authorization" 69 | #define PROXY_REQUIRE "proxy-require" 70 | #define RECORD_ROUTE "record-route" 71 | #define REPLY_TO "reply-to" 72 | #define REQUIRE "require" 73 | #define RETRY_AFTER "retry-after" 74 | #define ROUTE "route" 75 | #define SERVER "server" 76 | #define SUBJECT "subject" 77 | #define SUBJECT_SHORT "s" 78 | #define SUPPORTED "supported" 79 | #define TIMESTAMP "timestamp" 80 | #define TO "to" 81 | #define TO_SHORT "t" 82 | #define UNSUPPORTED "unsupported" 83 | #define USER_AGENT "user-agent" 84 | #define VIA "via" 85 | #define VIA_SHORT "v" 86 | #define WARNING "warning" 87 | #define WWW_AUTHENTICATE "www-authenticate" 88 | 89 | 90 | #define RESPONSE_CODES 51 91 | 92 | #define SIP_TRYING 100 93 | #define SIP_RINGING 180 94 | #define SIP_CALL_IS_BEING_FORWARDED 181 95 | #define SIP_QUEUED 182 96 | #define SIP_SESSION_PROGRESS 183 97 | #define SIP_OK 200 98 | #define SIP_ACCEPTED 202 99 | #define SIP_MULTIPLE_CHOICES 300 100 | #define SIP_MOVED_PERMANENTLY 301 101 | #define SIP_MOVED_TEMPORARILY 302 102 | #define SIP_USE_PROXY 305 103 | #define SIP_ALTERNATIVE_SERVICE 380 104 | #define SIP_BAD_REQUEST 400 105 | #define SIP_UNAUTHORIZED 401 106 | #define SIP_PAYMENT_REQUIRED 402 107 | #define SIP_FORBIDDEN 403 108 | #define SIP_NOT_FOUND 404 109 | #define SIP_METHOD_NOT_ALLOWED 405 110 | #define SIP_406_NOT_ACCEPTABLE 406 111 | #define SIP_PROXY_AUTHENTICATION_REQUIRED 407 112 | #define SIP_REQUEST_TIME_OUT 408 113 | #define SIP_GONE 410 114 | #define SIP_REQUEST_ENTITY_TOO_LARGE 413 115 | #define SIP_REQUEST_URI_TOO_LARGE 414 116 | #define SIP_UNSUPPORTED_MEDIA_TYPE 415 117 | #define SIP_UNSUPPORTED_URI_SCHEME 416 118 | #define SIP_BAD_EXTENSION 420 119 | #define SIP_EXTENSION_REQUIRED 421 120 | #define SIP_INTERVAL_TOO_BRIEF 423 121 | #define SIP_TEMPORARILY_UNAVAILABLE 480 122 | #define SIP_CALL_TRANSACTION_DOES_NOT_EXIST 481 123 | #define SIP_LOOP_DETECTED 482 124 | #define SIP_TOO_MANY_HOPS 483 125 | #define SIP_ADDRESS_INCOMPLETE 484 126 | #define SIP_AMBIGUOUS 485 127 | #define SIP_BUSY_HERE 486 128 | #define SIP_REQUEST_TERMINATED 487 129 | #define SIP_NOT_ACCEPTABLE_HERE 488 130 | #define SIP_BAD_EVENT 489 131 | #define SIP_REQUEST_PENDING 491 132 | #define SIP_UNDECIPHERABLE 493 133 | #define SIP_INTERNAL_SERVER_ERROR 500 134 | #define SIP_NOT_IMPLEMENTED 501 135 | #define SIP_BAD_GATEWAY 502 136 | #define SIP_SERVICE_UNAVAILABLE 503 137 | #define SIP_SERVER_TIME_OUT 504 138 | #define SIP_VERSION_NOT_SUPPORTED 505 139 | #define SIP_MESSAGE_TOO_LARGE 513 140 | #define SIP_BUSY_EVRYWHERE 600 141 | #define SIP_DECLINE 603 142 | #define SIP_DOES_NOT_EXIST_ANYWHERE 604 143 | #define SIP_606_NOT_ACCEPTABLE 606 144 | 145 | /** is the status code informational */ 146 | #define OSIP_IS_SIP_INFO(x) (((x) >= 100)&&((x) < 200)) 147 | /** is the status code OK ?*/ 148 | #define OSIP_IS_SIP_SUCCESS(x) (((x) >= 200)&&((x) < 300)) 149 | /** is the status code a redirect */ 150 | #define OSIP_IS_SIP_REDIRECT(x) (((x) >= 300)&&((x) < 400)) 151 | /** is the status code a error (client or server) */ 152 | #define OSIP_IS_SIP_ERROR(x) (((x) >= 400)&&((x) < 600)) 153 | /** is the status code a client error */ 154 | #define OSIP_IS_SIP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500)) 155 | /** is the status code a server error */ 156 | #define OSIP_IS_SIP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600)) 157 | 158 | 159 | #endif /* _CONST_H_ */ 160 | -------------------------------------------------------------------------------- /prtsp_comm.cpp: -------------------------------------------------------------------------------- 1 | #include "prtsp_comm.h" 2 | #include 3 | #include "prtsp_conn.h" 4 | 5 | void skip_space(char*& p) 6 | { 7 | while (*p != '\0' && *p == ' ') 8 | { 9 | ++p; 10 | } 11 | } 12 | 13 | 14 | void build_sip_msg(osip_message_t*& sip, sip_dialog* dlg, int cseq, const char* method) 15 | { 16 | osip_message_init(&sip); 17 | 18 | osip_uri_t* uri; 19 | osip_uri_init(&uri); 20 | 21 | osip_uri_set_scheme(uri, osip_strdup("sip")); 22 | osip_uri_set_username(uri, osip_strdup(dlg->destUser.c_str())); 23 | osip_uri_set_host(uri, osip_strdup(dlg->destHost.c_str())); 24 | osip_uri_set_port(uri, osip_strdup(dlg->destPort.c_str())); 25 | 26 | osip_message_set_method(sip, osip_strdup(method)); 27 | osip_message_set_uri(sip, uri); 28 | osip_message_set_version(sip, osip_strdup("SIP/2.0")); 29 | 30 | char temp[128]; 31 | 32 | sprintf(temp, "%s;branch=z9hG4bK%d", dlg->via.c_str(), std::rand()); 33 | osip_message_set_via(sip, temp); 34 | 35 | osip_message_set_from(sip, dlg->localTag.c_str()); 36 | osip_message_set_to(sip, dlg->remoteTag.c_str()); 37 | osip_message_set_call_id(sip, dlg->callid.c_str()); 38 | 39 | sprintf(temp, "%d %s", cseq, method); 40 | osip_message_set_cseq(sip, temp); 41 | 42 | osip_message_set_contact(sip, dlg->localContact.c_str()); 43 | osip_message_set_max_forwards(sip, "70"); 44 | } 45 | 46 | int avio_r8(uint8_t*& pb) 47 | { 48 | int val = *pb; 49 | ++pb; 50 | return val; 51 | } 52 | 53 | unsigned int avio_rb16(uint8_t*& s) 54 | { 55 | unsigned int val; 56 | val = avio_r8(s) << 8; 57 | val |= avio_r8(s); 58 | return val; 59 | } 60 | 61 | void avio_skip(uint8_t*& pb, int64_t offset) 62 | { 63 | pb += offset; 64 | } 65 | 66 | unsigned int avio_rb32(uint8_t*& s) 67 | { 68 | unsigned int val; 69 | val = avio_rb16(s) << 16; 70 | val |= avio_rb16(s); 71 | return val; 72 | } 73 | 74 | unsigned int avio_rb24(uint8_t*& s) 75 | { 76 | unsigned int val; 77 | val = avio_rb16(s) << 8; 78 | val |= avio_r8(s); 79 | return val; 80 | } 81 | 82 | const uint8_t * ff_avc_find_startcode_internal( 83 | const uint8_t *p, const uint8_t *end) 84 | { 85 | const uint8_t *a = p + 4 - ((intptr_t)p & 3); 86 | 87 | for (end -= 3; p < a && p < end; p++) { 88 | if (p[0] == 0 && p[1] == 0 && p[2] == 1) 89 | return p; 90 | } 91 | 92 | for (end -= 3; p < end; p += 4) { 93 | uint32_t x = *(const uint32_t*)p; 94 | // if ((x - 0x01000100) & (~x) & 0x80008000) // little endian 95 | // if ((x - 0x00010001) & (~x) & 0x00800080) // big endian 96 | if ((x - 0x01010101) & (~x) & 0x80808080) { // generic 97 | if (p[1] == 0) { 98 | if (p[0] == 0 && p[2] == 1) 99 | return p; 100 | if (p[2] == 0 && p[3] == 1) 101 | return p + 1; 102 | } 103 | if (p[3] == 0) { 104 | if (p[2] == 0 && p[4] == 1) 105 | return p + 2; 106 | if (p[4] == 0 && p[5] == 1) 107 | return p + 3; 108 | } 109 | } 110 | } 111 | 112 | for (end += 3; p < end; p++) { 113 | if (p[0] == 0 && p[1] == 0 && p[2] == 1) 114 | return p; 115 | } 116 | 117 | return end + 3; 118 | } 119 | 120 | const uint8_t * ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) 121 | { 122 | const uint8_t *out = ff_avc_find_startcode_internal(p, end); 123 | if (p < out && out < end && !out[-1]) out--; 124 | return out; 125 | } 126 | 127 | void parse_send_es(const uint8_t* inbuf, const int insize, int64_t ts, 128 | int payload, uint8_t* sendbuf, int& seq, std::set& pendPlay) 129 | { 130 | const uint8_t *r, *end = inbuf + insize; 131 | 132 | r = ff_avc_find_startcode(inbuf, end); 133 | 134 | while (r < end) { 135 | const uint8_t *r1; 136 | 137 | while (!*(r++)); 138 | r1 = ff_avc_find_startcode(r, end); 139 | 140 | nal_send(r, r1 - r, r1 == end, ts, payload, sendbuf, seq, pendPlay); 141 | r = r1; 142 | } 143 | } 144 | 145 | void nal_send(const uint8_t *buf, int size, int last, uint32_t ts, 146 | int payload, uint8_t* sendbuf, int& seq, std::set& pendPlay) 147 | { 148 | if (size <= MAX_PAYLOAD_SIZE) 149 | { 150 | uint8_t* p_rtp = sendbuf; 151 | 152 | avio_w8(p_rtp, '$'); 153 | avio_w8(p_rtp, 0); 154 | avio_wb16(p_rtp, size + 12); 155 | 156 | avio_w8(p_rtp, RTP_VERSION << 6); 157 | avio_w8(p_rtp, (payload & 0x7f) | ((last & 0x01) << 7)); 158 | avio_wb16(p_rtp, seq); 159 | avio_wb32(p_rtp, ts); 160 | avio_wb32(p_rtp, 0); 161 | 162 | seq = (seq + 1) & 0xffff; 163 | 164 | memcpy(sendbuf + 4 + 12, buf, size); 165 | 166 | for (auto it = pendPlay.begin(); it != pendPlay.end(); ++it) 167 | { 168 | (*it)->send_tcp_stream(sendbuf, size + 4 + 12); 169 | } 170 | } 171 | else { 172 | uint8_t* p_buf = sendbuf; 173 | 174 | avio_w8(p_buf, '$'); 175 | avio_w8(p_buf, 0); 176 | avio_wb16(p_buf, MAX_PAYLOAD_SIZE + 12); 177 | 178 | avio_w8(p_buf, RTP_VERSION << 6); 179 | avio_w8(p_buf, payload & 0x7f); 180 | avio_wb16(p_buf, seq); 181 | avio_wb32(p_buf, ts); 182 | avio_wb32(p_buf, 0); 183 | 184 | int flag_byte, header_size; 185 | 186 | uint8_t type = buf[0] & 0x1F; 187 | uint8_t nri = buf[0] & 0x60; 188 | 189 | p_buf[0] = 28; /* FU Indicator; Type = 28 ---> FU-A */ 190 | p_buf[0] |= nri; 191 | p_buf[1] = type; 192 | p_buf[1] |= 1 << 7; 193 | buf += 1; 194 | size -= 1; 195 | 196 | flag_byte = 1; 197 | header_size = 2; 198 | uint8_t* ptmp; 199 | 200 | while (size + header_size > MAX_PAYLOAD_SIZE) { 201 | memcpy(&p_buf[header_size], buf, MAX_PAYLOAD_SIZE - header_size); 202 | 203 | ptmp = sendbuf + 6; 204 | avio_wb16(ptmp, seq); 205 | 206 | seq = (seq + 1) & 0xffff; 207 | 208 | for (auto it = pendPlay.begin(); it != pendPlay.end(); ++it) 209 | { 210 | (*it)->send_tcp_stream(sendbuf, MAX_PAYLOAD_SIZE + 4 + 12); 211 | } 212 | 213 | buf += MAX_PAYLOAD_SIZE - header_size; 214 | size -= MAX_PAYLOAD_SIZE - header_size; 215 | p_buf[flag_byte] &= ~(1 << 7); 216 | } 217 | 218 | p_buf[flag_byte] |= 1 << 6; 219 | memcpy(&p_buf[header_size], buf, size); 220 | 221 | ptmp = (uint8_t*)sendbuf + 2; 222 | avio_wb16(ptmp, size + header_size + 12); 223 | 224 | ptmp = (uint8_t*)sendbuf + 5; 225 | avio_w8(ptmp, (payload & 0x7f) | ((last & 0x01) << 7)); 226 | 227 | ptmp = (uint8_t*)sendbuf + 6; 228 | avio_wb16(ptmp, seq); 229 | 230 | seq = (seq + 1) & 0xffff; 231 | 232 | for (auto it = pendPlay.begin(); it != pendPlay.end(); ++it) 233 | { 234 | (*it)->send_tcp_stream(sendbuf, size + header_size + 4 + 12); 235 | } 236 | } 237 | } 238 | 239 | void avio_w8(uint8_t*& s, int b) 240 | { 241 | *s++ = b; 242 | } 243 | 244 | void avio_wb16(uint8_t*& s, unsigned int val) 245 | { 246 | avio_w8(s, (int)val >> 8); 247 | avio_w8(s, (uint8_t)val); 248 | } 249 | 250 | void avio_wb32(uint8_t*& s, unsigned int val) 251 | { 252 | avio_w8(s, val >> 24); 253 | avio_w8(s, (uint8_t)(val >> 16)); 254 | avio_w8(s, (uint8_t)(val >> 8)); 255 | avio_w8(s, (uint8_t)val); 256 | } -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_via.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_VIA_H_ 22 | #define _OSIP_VIA_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_via.h 28 | * @brief oSIP osip_via header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_VIA oSIP via header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Via headers. 39 | * @var osip_via_t 40 | */ 41 | typedef struct osip_via osip_via_t; 42 | 43 | /** 44 | * Definition of the Via header. 45 | * @struct osip_via 46 | */ 47 | struct osip_via 48 | { 49 | char *version; /**< SIP Version */ 50 | char *protocol; /**< Protocol used by SIP Agent */ 51 | char *host; /**< Host where to send answers */ 52 | char *port; /**< Port where to send answers */ 53 | char *comment; /**< Comments about SIP Agent */ 54 | osip_list_t via_params; /**< Via parameters */ 55 | }; 56 | 57 | #ifdef __cplusplus 58 | extern "C" 59 | { 60 | #endif 61 | 62 | /** 63 | * Allocate a Via element. 64 | * @param header The element to work on. 65 | */ 66 | int osip_via_init (osip_via_t ** header); 67 | /** 68 | * Free a Via element. 69 | * @param header The element to work on. 70 | */ 71 | void osip_via_free (osip_via_t * header); 72 | /** 73 | * Parse a Via element. 74 | * @param header The element to work on. 75 | * @param hvalue The string to parse. 76 | */ 77 | int osip_via_parse (osip_via_t * header, const char *hvalue); 78 | /** 79 | * Get a string representation of a Via element. 80 | * @param header The element to work on. 81 | * @param dest A pointer on the new allocated string. 82 | */ 83 | int osip_via_to_str (const osip_via_t * header, char **dest); 84 | /** 85 | * Clone a Via element. 86 | * @param header The element to work on. 87 | * @param dest A pointer on the copy of the element. 88 | */ 89 | int osip_via_clone (const osip_via_t * header, osip_via_t ** dest); 90 | /** 91 | * Set the SIP version in the Via element. 92 | * @param header The element to work on. 93 | * @param value The value of the element. 94 | */ 95 | void via_set_version (osip_via_t * header, char *value); 96 | #define osip_via_set_version via_set_version 97 | /** 98 | * Get the SIP version from a Via header. 99 | * @param header The element to work on. 100 | */ 101 | char *via_get_version (osip_via_t * header); 102 | #define osip_via_get_version via_get_version 103 | /** 104 | * Set the protocol in the Via element. 105 | * @param header The element to work on. 106 | * @param value The value of the element. 107 | */ 108 | void via_set_protocol (osip_via_t * header, char *value); 109 | #define osip_via_set_protocol via_set_protocol 110 | /** 111 | * Get the protocol from a Via header. 112 | * @param header The element to work on. 113 | */ 114 | char *via_get_protocol (osip_via_t * header); 115 | #define osip_via_get_protocol via_get_protocol 116 | /** 117 | * Set the host in the Via element. 118 | * @param header The element to work on. 119 | * @param value The value of the element. 120 | */ 121 | void via_set_host (osip_via_t * header, char *value); 122 | #define osip_via_set_host via_set_host 123 | /** 124 | * Get the host from a Via header. 125 | * @param header The element to work on. 126 | */ 127 | char *via_get_host (osip_via_t * header); 128 | #define osip_via_get_host via_get_host 129 | /** 130 | * Set the port in the Via element. 131 | * @param header The element to work on. 132 | * @param value The value of the element. 133 | */ 134 | void via_set_port (osip_via_t * header, char *value); 135 | #define osip_via_set_port via_set_port 136 | /** 137 | * Get the port from a Via header. 138 | * @param header The element to work on. 139 | */ 140 | char *via_get_port (osip_via_t * header); 141 | #define osip_via_get_port via_get_port 142 | /** 143 | * Set the comment in the Via element. 144 | * @param header The element to work on. 145 | * @param value The value of the element. 146 | */ 147 | void via_set_comment (osip_via_t * header, char *value); 148 | #define osip_via_set_comment via_set_comment 149 | /** 150 | * Get the comment from a Via header. 151 | * @param header The element to work on. 152 | */ 153 | char *via_get_comment (osip_via_t * header); 154 | #define osip_via_get_comment via_get_comment 155 | 156 | /** 157 | * Allocate and add a hidden parameter element in a list. 158 | * @param header The element to work on. 159 | */ 160 | #define osip_via_set_hidden(header) osip_generic_param_add((&(header)->via_params),osip_strdup("hidden"),NULL) 161 | /** 162 | * Allocate and add a ttl parameter element in a list. 163 | * @param header The element to work on. 164 | * @param value The token value. 165 | */ 166 | #define osip_via_set_ttl(header,value) osip_generic_param_add((&(header)->via_params),osip_strdup("ttl"),value) 167 | /** 168 | * Allocate and add a maddr parameter element in a list. 169 | * @param header The element to work on. 170 | * @param value The token value. 171 | */ 172 | #define osip_via_set_maddr(header,value) osip_generic_param_add((&(header)->via_params),osip_strdup("maddr"),value) 173 | /** 174 | * Allocate and add a received parameter element in a list. 175 | * @param header The element to work on. 176 | * @param value The token value. 177 | */ 178 | #define osip_via_set_received(header,value) osip_generic_param_add((&(header)->via_params),osip_strdup("received"),value) 179 | /** 180 | * Allocate and add a branch parameter element in a list. 181 | * @param header The element to work on. 182 | * @param value The token value. 183 | */ 184 | #define osip_via_set_branch(header,value) osip_generic_param_add((&(header)->via_params),osip_strdup("branch"),value) 185 | 186 | /** 187 | * Allocate and add a generic parameter element in a list. 188 | * @param header The element to work on. 189 | * @param name The token name. 190 | * @param value The token value. 191 | */ 192 | #define osip_via_param_add(header,name,value) osip_generic_param_add((&(header)->via_params),name,value) 193 | /** 194 | * Find a header parameter in a Via element. 195 | * @param header The element to work on. 196 | * @param name The token name to search. 197 | * @param dest A pointer on the element found. 198 | */ 199 | #define osip_via_param_get_byname(header,name,dest) osip_generic_param_get_byname((&(header)->via_params),name,dest) 200 | 201 | /** 202 | * Check if the Via headers match. 203 | * NOTE: THIS IS AN INTERNAL METHOD ONLY 204 | * @param via1 The first Via header. 205 | * @param via2 The second Via header. 206 | */ 207 | int osip_via_match (osip_via_t * via1, osip_via_t * via2); 208 | 209 | #ifdef __cplusplus 210 | } 211 | #endif 212 | 213 | /** @} */ 214 | 215 | #endif 216 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_proxy_authentication_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2012 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or(at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_PROXY_AUTHENTICATION_INFO_H_ 22 | #define _OSIP_PROXY_AUTHENTICATION_INFO_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_proxy_authentication_info.h 28 | * @brief oSIP osip_proxy_authentication_info header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_PROXY_AUTH_INFO oSIP proxy-authentication-info header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Proxy-Authentication-Info headers. 39 | * @var osip_proxy_authentication_info_t 40 | */ 41 | typedef osip_authentication_info_t osip_proxy_authentication_info_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Authenication-Info element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_proxy_authentication_info_init(header) osip_authentication_info_init(header) 53 | /** 54 | * Parse a Authenication-Info element. 55 | * @param header The element to work on. 56 | * @param hvalue The string to parse. 57 | */ 58 | #define osip_proxy_authentication_info_parse(header, hvalue) osip_authentication_info_parse(header, hvalue) 59 | /** 60 | * Get a string representation of a Authenication-Info element. 61 | * @param header The element to work on. 62 | * @param dest A pointer on the new allocated string. 63 | */ 64 | #define osip_proxy_authentication_info_to_str(header, dest) osip_authentication_info_to_str(header, dest) 65 | /** 66 | * Free a Authenication-Info element. 67 | * @param header The element to work on. 68 | */ 69 | #define osip_proxy_authentication_info_free osip_authentication_info_free 70 | /** 71 | * Clone a Authenication-Info element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_proxy_authentication_info_clone osip_authentication_info_clone 76 | 77 | /** 78 | * Get value of the nextnonce parameter from a Authenication-Info element. 79 | * @param header The element to work on. 80 | */ 81 | #define osip_proxy_authentication_info_get_nextnonce(header) osip_authentication_info_get_nextnonce(header) 82 | /** 83 | * Add the nextnonce parameter from a Authenication-Info element. 84 | * @param header The element to work on. 85 | * @param value The value of the new parameter. 86 | */ 87 | #define osip_proxy_authentication_info_set_nextnonce(header, value) osip_authentication_info_set_nextnonce(header, value) 88 | /** 89 | * Get value of the cnonce parameter from a Authenication-Info element. 90 | * @param header The element to work on. 91 | */ 92 | #define osip_proxy_authentication_info_get_cnonce(header) osip_authentication_info_get_cnonce(header) 93 | /** 94 | * Add the cnonce parameter from a Authenication-Info element. 95 | * @param header The element to work on. 96 | * @param value The value of the new parameter. 97 | */ 98 | #define osip_proxy_authentication_info_set_cnonce(header, value) osip_authentication_info_set_cnonce(header, value) 99 | /** 100 | * Get value of the qop_options parameter from a Authenication-Info element. 101 | * @param header The element to work on. 102 | */ 103 | #define osip_proxy_authentication_info_get_qop_options(header) osip_authentication_info_get_qop_options(header) 104 | /** 105 | * Add the qop_options parameter from a Authenication-Info element. 106 | * @param header The element to work on. 107 | * @param value The value of the new parameter. 108 | */ 109 | #define osip_proxy_authentication_info_set_qop_options(header, value) osip_authentication_info_set_qop_options(header, value) 110 | /** 111 | * Get value of the rspauth parameter from a Authenication-Info element. 112 | * @param header The element to work on. 113 | */ 114 | #define osip_proxy_authentication_info_get_rspauth(header) osip_authentication_info_get_rspauth(header) 115 | /** 116 | * Add the rspauth parameter from a Authenication-Info element. 117 | * @param header The element to work on. 118 | * @param value The value of the new parameter. 119 | */ 120 | #define osip_proxy_authentication_info_set_rspauth(header, value) osip_authentication_info_set_rspauth(header, value) 121 | /** 122 | * Get value of the nc parameter from a Authenication-Info element. 123 | * @param header The element to work on. 124 | */ 125 | #define osip_proxy_authentication_info_get_nonce_count(header) osip_authentication_info_get_nonce_count(header) 126 | /** 127 | * Add the nc parameter from a Authenication-Info element. 128 | * @param header The element to work on. 129 | * @param value The value of the new parameter. 130 | */ 131 | #define osip_proxy_authentication_info_set_nonce_count(header, value) osip_authentication_info_set_nonce_count(header, value) 132 | /** 133 | * Get value of the snum parameter from a Authenication-Info element. 134 | * @param header The element to work on. 135 | */ 136 | #define osip_proxy_authentication_info_get_snum(header) osip_authentication_info_get_snum(header) 137 | /** 138 | * Add the snum parameter from a Authenication-Info element. 139 | * @param header The element to work on. 140 | * @param value The value of the new parameter. 141 | */ 142 | #define osip_proxy_authentication_info_set_snum(header, value) osip_authentication_info_set_snum(header, value) 143 | /** 144 | * Get value of the srand parameter from a Authenication-Info element. 145 | * @param header The element to work on. 146 | */ 147 | #define osip_proxy_authentication_info_get_srand(header) osip_authentication_info_get_srand(header) 148 | /** 149 | * Add the srand parameter from a Authenication-Info element. 150 | * @param header The element to work on. 151 | * @param value The value of the new parameter. 152 | */ 153 | #define osip_proxy_authentication_info_set_srand(header, value) osip_authentication_info_set_srand(header, value) 154 | /** 155 | * Get value of the targetname parameter from a Authenication-Info element. 156 | * @param header The element to work on. 157 | */ 158 | #define osip_proxy_authentication_info_get_targetname(header) osip_authentication_info_get_targetname(header) 159 | /** 160 | * Add the targetname parameter from a Authenication-Info element. 161 | * @param header The element to work on. 162 | * @param value The value of the new parameter. 163 | */ 164 | #define osip_proxy_authentication_info_set_targetname(header, value) osip_authentication_info_set_targetname(header, value) 165 | /** 166 | * Get value of the realm parameter from a Authenication-Info element. 167 | * @param header The element to work on. 168 | */ 169 | #define osip_proxy_authentication_info_get_realm(header) osip_authentication_info_get_realm(header) 170 | /** 171 | * Add the realm parameter from a Authenication-Info element. 172 | * @param header The element to work on. 173 | * @param value The value of the new parameter. 174 | */ 175 | #define osip_proxy_authentication_info_set_realm(header, value) osip_authentication_info_set_realm(header, value) 176 | /** 177 | * Get value of the opaque parameter from a Authenication-Info element. 178 | * @param header The element to work on. 179 | */ 180 | #define osip_proxy_authentication_info_get_opaque(header) osip_authentication_info_get_opaque(header) 181 | /** 182 | * Add the opaque parameter from a Authenication-Info element. 183 | * @param header The element to work on. 184 | * @param value The value of the new parameter. 185 | */ 186 | #define osip_proxy_authentication_info_set_opaque(header, value) osip_authentication_info_set_opaque(header, value) 187 | 188 | 189 | #ifdef __cplusplus 190 | } 191 | #endif 192 | 193 | /** @} */ 194 | 195 | #endif 196 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_authentication_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2012 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_AUTHENTICATION_INFO_H_ 22 | #define _OSIP_AUTHENTICATION_INFO_H_ 23 | 24 | 25 | /** 26 | * @file osip_authentication_info.h 27 | * @brief oSIP osip_authentication_info header definition. 28 | */ 29 | 30 | /** 31 | * @defgroup oSIP_AUTH_INFO oSIP authentication-info header definition. 32 | * @ingroup oSIP_HEADERS 33 | * @{ 34 | */ 35 | 36 | /** 37 | * Structure for Authentication-Info headers. 38 | * @var osip_authentication_info_t 39 | */ 40 | typedef struct osip_authentication_info osip_authentication_info_t; 41 | 42 | /** 43 | * Definition of the Authentication-Info header. 44 | * @struct osip_authentication_info 45 | */ 46 | struct osip_authentication_info 47 | { 48 | char *auth_type; /**< Authentication Type (Basic or Digest) */ 49 | char *nextnonce; /**< nextnonce value */ 50 | char *qop_options; /**< qop options value */ 51 | char *rspauth; /**< rspauth value */ 52 | char *cnonce; /**< cnonce value */ 53 | char *nonce_count; /**< noncecount value */ 54 | char *snum; /**< snum value */ 55 | char *srand; /**< srand value */ 56 | char *realm; /**< realm value */ 57 | char *targetname; /**< targetname value */ 58 | char *opaque; /**< opaque value */ 59 | }; 60 | 61 | 62 | #ifdef __cplusplus 63 | extern "C" 64 | { 65 | #endif 66 | 67 | /** 68 | * Allocate a Authenication-Info element. 69 | * @param header The element to work on. 70 | */ 71 | int osip_authentication_info_init (osip_authentication_info_t ** header); 72 | /** 73 | * Parse a Authenication-Info element. 74 | * @param header The element to work on. 75 | * @param hvalue The string to parse. 76 | */ 77 | int osip_authentication_info_parse (osip_authentication_info_t * header, const char *hvalue); 78 | /** 79 | * Get a string representation of a Authenication-Info element. 80 | * @param header The element to work on. 81 | * @param dest A pointer on the new allocated string. 82 | */ 83 | int osip_authentication_info_to_str (const osip_authentication_info_t * header, char **dest); 84 | /** 85 | * Free a Authenication-Info element. 86 | * @param header The element to work on. 87 | */ 88 | void osip_authentication_info_free (osip_authentication_info_t * header); 89 | /** 90 | * Clone a Authenication-Info element. 91 | * @param header The element to work on. 92 | * @param dest A pointer on the copy of the element. 93 | */ 94 | int osip_authentication_info_clone (const osip_authentication_info_t * header, 95 | osip_authentication_info_t ** dest); 96 | 97 | 98 | /** 99 | * Get value of the auth_type parameter from a Authenication-Info element. 100 | * @param header The element to work on. 101 | */ 102 | char *osip_authentication_info_get_auth_type (osip_authentication_info_t * header); 103 | /** 104 | * Add the auth_type parameter from a Authenication-Info element. 105 | * @param header The element to work on. 106 | * @param value The value of the new parameter. 107 | */ 108 | void osip_authentication_info_set_auth_type (osip_authentication_info_t * header, char *value); 109 | /** 110 | * Get value of the nextnonce parameter from a Authenication-Info element. 111 | * @param header The element to work on. 112 | */ 113 | char *osip_authentication_info_get_nextnonce (osip_authentication_info_t * header); 114 | /** 115 | * Add the nextnonce parameter from a Authenication-Info element. 116 | * @param header The element to work on. 117 | * @param value The value of the new parameter. 118 | */ 119 | void osip_authentication_info_set_nextnonce (osip_authentication_info_t * header, char *value); 120 | /** 121 | * Get value of the cnonce parameter from a Authenication-Info element. 122 | * @param header The element to work on. 123 | */ 124 | char *osip_authentication_info_get_cnonce (osip_authentication_info_t * header); 125 | /** 126 | * Add the cnonce parameter from a Authenication-Info element. 127 | * @param header The element to work on. 128 | * @param value The value of the new parameter. 129 | */ 130 | void osip_authentication_info_set_cnonce (osip_authentication_info_t * header, char *value); 131 | /** 132 | * Get value of the qop_options parameter from a Authenication-Info element. 133 | * @param header The element to work on. 134 | */ 135 | char *osip_authentication_info_get_qop_options (osip_authentication_info_t * header); 136 | /** 137 | * Add the qop_options parameter from a Authenication-Info element. 138 | * @param header The element to work on. 139 | * @param value The value of the new parameter. 140 | */ 141 | void osip_authentication_info_set_qop_options (osip_authentication_info_t * header, 142 | char *value); 143 | /** 144 | * Get value of the rspauth parameter from a Authenication-Info element. 145 | * @param header The element to work on. 146 | */ 147 | char *osip_authentication_info_get_rspauth (osip_authentication_info_t * header); 148 | /** 149 | * Add the rspauth parameter from a Authenication-Info element. 150 | * @param header The element to work on. 151 | * @param value The value of the new parameter. 152 | */ 153 | void osip_authentication_info_set_rspauth (osip_authentication_info_t * header, char *value); 154 | /** 155 | * Get value of the nc parameter from a Authenication-Info element. 156 | * @param header The element to work on. 157 | */ 158 | char *osip_authentication_info_get_nonce_count (osip_authentication_info_t * header); 159 | /** 160 | * Add the nc parameter from a Authenication-Info element. 161 | * @param header The element to work on. 162 | * @param value The value of the new parameter. 163 | */ 164 | void osip_authentication_info_set_nonce_count (osip_authentication_info_t * header, char *value); 165 | /** 166 | * Get value of the snum parameter from a Authenication-Info element. 167 | * @param header The element to work on. 168 | */ 169 | char *osip_authentication_info_get_snum (osip_authentication_info_t * header); 170 | /** 171 | * Add the snum parameter from a Authenication-Info element. 172 | * @param header The element to work on. 173 | * @param value The value of the new parameter. 174 | */ 175 | void osip_authentication_info_set_snum (osip_authentication_info_t * header, char *value); 176 | /** 177 | * Get value of the srand parameter from a Authenication-Info element. 178 | * @param header The element to work on. 179 | */ 180 | char *osip_authentication_info_get_srand (osip_authentication_info_t * header); 181 | /** 182 | * Add the srand parameter from a Authenication-Info element. 183 | * @param header The element to work on. 184 | * @param value The value of the new parameter. 185 | */ 186 | void osip_authentication_info_set_srand (osip_authentication_info_t * header, char *value); 187 | /** 188 | * Get value of the targetname parameter from a Authenication-Info element. 189 | * @param header The element to work on. 190 | */ 191 | char *osip_authentication_info_get_targetname (osip_authentication_info_t * header); 192 | /** 193 | * Add the targetname parameter from a Authenication-Info element. 194 | * @param header The element to work on. 195 | * @param value The value of the new parameter. 196 | */ 197 | void osip_authentication_info_set_targetname (osip_authentication_info_t * header, char *value); 198 | /** 199 | * Get value of the realm parameter from a Authenication-Info element. 200 | * @param header The element to work on. 201 | */ 202 | char *osip_authentication_info_get_realm (osip_authentication_info_t * header); 203 | /** 204 | * Add the realm parameter from a Authenication-Info element. 205 | * @param header The element to work on. 206 | * @param value The value of the new parameter. 207 | */ 208 | void osip_authentication_info_set_realm (osip_authentication_info_t * header, char *value); 209 | /** 210 | * Get value of the opaque parameter from a Authenication-Info element. 211 | * @param header The element to work on. 212 | */ 213 | char *osip_authentication_info_get_opaque (osip_authentication_info_t * header); 214 | /** 215 | * Add the opaque parameter from a Authenication-Info element. 216 | * @param header The element to work on. 217 | * @param value The value of the new parameter. 218 | */ 219 | void osip_authentication_info_set_opaque (osip_authentication_info_t * header, char *value); 220 | 221 | #ifdef __cplusplus 222 | } 223 | #endif 224 | 225 | /** @} */ 226 | 227 | #endif 228 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_proxy_authenticate.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_PROXY_AUHTHENTICATE_H_ 22 | #define _OSIP_PROXY_AUHTHENTICATE_H_ 23 | 24 | #include 25 | 26 | /** 27 | * @file osip_proxy_authenticate.h 28 | * @brief oSIP osip_proxy_authenticate header definition. 29 | */ 30 | 31 | /** 32 | * @defgroup oSIP_PROXY_AUTHENTICATE oSIP proxy-authenticate header definition. 33 | * @ingroup oSIP_HEADERS 34 | * @{ 35 | */ 36 | 37 | /** 38 | * Structure for Proxy-Authenticate headers. 39 | * @var osip_proxy_authenticate_t 40 | */ 41 | typedef osip_www_authenticate_t osip_proxy_authenticate_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /** 49 | * Allocate a Proxy-Authenticate element. 50 | * @param header The element to work on. 51 | */ 52 | #define osip_proxy_authenticate_init(header) osip_www_authenticate_init(header) 53 | /** 54 | * Parse a Proxy-Authenticate element. 55 | * @param header The element to work on. 56 | * @param hvalue The string to parse. 57 | */ 58 | #define osip_proxy_authenticate_parse(header, hvalue) osip_www_authenticate_parse(header, hvalue) 59 | /** 60 | * Get a string representation of a Proxy-Authenticate element. 61 | * @param header The element to work on. 62 | * @param dest A pointer on the new allocated string. 63 | */ 64 | #define osip_proxy_authenticate_to_str(header, dest) osip_www_authenticate_to_str(header, dest) 65 | /** 66 | * Free a Proxy-Authenticate element. 67 | * @param header The element to work on. 68 | */ 69 | #define osip_proxy_authenticate_free osip_www_authenticate_free 70 | /** 71 | * Clone a Proxy-Authenticate element. 72 | * @param header The element to work on. 73 | * @param dest A pointer on the copy of the element. 74 | */ 75 | #define osip_proxy_authenticate_clone osip_www_authenticate_clone 76 | 77 | /** 78 | * Get value of the auth_type parameter from a Proxy-Authenticate element. 79 | * @param header The element to work on. 80 | */ 81 | #define osip_proxy_authenticate_get_auth_type(header) osip_www_authenticate_get_auth_type(header) 82 | /** 83 | * Add the auth_type parameter from a Proxy-Authenticate element. 84 | * @param header The element to work on. 85 | * @param value The value of the new parameter. 86 | */ 87 | #define osip_proxy_authenticate_set_auth_type(header,value) osip_www_authenticate_set_auth_type(header, value) 88 | /** 89 | * Get value of the realm parameter from a Proxy-Authenticate element. 90 | * @param header The element to work on. 91 | */ 92 | #define osip_proxy_authenticate_get_realm(header) osip_www_authenticate_get_realm(header) 93 | /** 94 | * Add the realm parameter from a Proxy-Authenticate element. 95 | * @param header The element to work on. 96 | * @param value The value of the new parameter. 97 | */ 98 | #define osip_proxy_authenticate_set_realm(header, value) osip_www_authenticate_set_realm(header, value) 99 | /** 100 | * Get value of the domain parameter from a Proxy-Authenticate element. 101 | * @param header The element to work on. 102 | */ 103 | #define osip_proxy_authenticate_get_domain(header) osip_www_authenticate_get_domain(header) 104 | /** 105 | * Add the domain parameter from a Proxy-Authenticate element. 106 | * @param header The element to work on. 107 | * @param value The value of the new parameter. 108 | */ 109 | #define osip_proxy_authenticate_set_domain(header, value) osip_www_authenticate_set_domain(header, value) 110 | /** 111 | * Get value of the nonce parameter from a Proxy-Authenticate element. 112 | * @param header The element to work on. 113 | */ 114 | #define osip_proxy_authenticate_get_nonce(header) osip_www_authenticate_get_nonce(header) 115 | /** 116 | * Add the nonce parameter from a Proxy-Authenticate element. 117 | * @param header The element to work on. 118 | * @param value The value of the new parameter. 119 | */ 120 | #define osip_proxy_authenticate_set_nonce(header, value) osip_www_authenticate_set_nonce(header, value) 121 | /** 122 | * Get value of the opaque parameter from a Proxy-Authenticate element. 123 | * @param header The element to work on. 124 | */ 125 | #define osip_proxy_authenticate_get_opaque(header) osip_www_authenticate_get_opaque(header) 126 | /** 127 | * Add the opaque parameter from a Proxy-Authenticate element. 128 | * @param header The element to work on. 129 | * @param value The value of the new parameter. 130 | */ 131 | #define osip_proxy_authenticate_set_opaque(header, value) osip_www_authenticate_set_opaque(header, value) 132 | /** 133 | * Get value of the stale parameter from a Proxy-Authenticate element. 134 | * @param header The element to work on. 135 | */ 136 | #define osip_proxy_authenticate_get_stale(header) osip_www_authenticate_get_stale(header) 137 | /** 138 | * Add the stale parameter from a Proxy-Authenticate element. 139 | * @param header The element to work on. 140 | * @param value The value of the new parameter. 141 | */ 142 | #define osip_proxy_authenticate_set_stale(header, value) osip_www_authenticate_set_stale(header, value) 143 | /** 144 | * Add a stale parameter set to "true" in a proxy-Authenticate element. 145 | * @param header The element to work on. 146 | */ 147 | #define osip_proxy_authenticate_set_stale_true(header) osip_www_authenticate_set_stale(header,osip_strdup("true")) 148 | /** 149 | * Add a stale parameter set to "false" in a Proxy-Authenticate element. 150 | * @param header The element to work on. 151 | */ 152 | #define osip_proxy_authenticate_set_stale_false(header) osip_www_authenticate_set_stale(header,osip_strdup("false")) 153 | /** 154 | * Get value of the algorithm parameter from a Proxy-Authenticate element. 155 | * @param header The element to work on. 156 | */ 157 | #define osip_proxy_authenticate_get_algorithm(header) osip_www_authenticate_get_algorithm(header) 158 | /** 159 | * Add the algorithm parameter from a Proxy-Authenticate element. 160 | * @param header The element to work on. 161 | * @param value The value of the new parameter. 162 | */ 163 | #define osip_proxy_authenticate_set_algorithm(header, value) osip_www_authenticate_set_algorithm(header, value) 164 | /** 165 | * Add the algorithm parameter set to "MD5" in a Proxy-Authenticate element. 166 | * @param header The element to work on. 167 | */ 168 | #define osip_proxy_authenticate_set_algorithm_MD5(header) osip_www_authenticate_set_algorithm(header,osip_strdup("MD5")) 169 | /** 170 | * Get value of the qop_options parameter from a Proxy-Authenticate element. 171 | * @param header The element to work on. 172 | */ 173 | #define osip_proxy_authenticate_get_qop_options(header) osip_www_authenticate_get_qop_options(header) 174 | /** 175 | * Add the qop_options parameter from a Proxy-Authenticate element. 176 | * @param header The element to work on. 177 | * @param value The value of the new parameter. 178 | */ 179 | #define osip_proxy_authenticate_set_qop_options(header,value) osip_www_authenticate_set_qop_options(header,value) 180 | /** 181 | * Get value of the version parameter from a Proxy-Authenticate element. 182 | * @param header The element to work on. 183 | */ 184 | #define osip_proxy_authenticate_get_version(header) osip_www_authenticate_get_version(header) 185 | /** 186 | * Add the version parameter from a Proxy-Authenticate element. 187 | * @param header The element to work on. 188 | * @param value The value of the new parameter. 189 | */ 190 | #define osip_proxy_authenticate_set_version(header,value) osip_www_authenticate_set_version(header,value) 191 | /** 192 | * Get value of the targetname parameter from a Proxy-Authenticate element. 193 | * @param header The element to work on. 194 | */ 195 | #define osip_proxy_authenticate_get_targetname(header) osip_www_authenticate_get_targetname(header) 196 | /** 197 | * Add the targetname parameter from a Proxy-Authenticate element. 198 | * @param header The element to work on. 199 | * @param value The value of the new parameter. 200 | */ 201 | #define osip_proxy_authenticate_set_targetname(header,value) osip_www_authenticate_set_targetname(header,value) 202 | /** 203 | * Get value of the gssapi_data parameter from a Proxy-Authenticate element. 204 | * @param header The element to work on. 205 | */ 206 | #define osip_proxy_authenticate_get_gssapi_data(header) osip_www_authenticate_get_gssapi_data(header) 207 | /** 208 | * Add the gssapi_data parameter from a Proxy-Authenticate element. 209 | * @param header The element to work on. 210 | * @param value The value of the new parameter. 211 | */ 212 | #define osip_proxy_authenticate_set_gssapi_data(header,value) osip_www_authenticate_set_gssapi_data(header,value) 213 | 214 | 215 | #ifdef __cplusplus 216 | } 217 | #endif 218 | 219 | /** @} */ 220 | 221 | #endif 222 | -------------------------------------------------------------------------------- /psip_conn.cpp: -------------------------------------------------------------------------------- 1 | #include "psip_conn.h" 2 | #include "psip_server.h" 3 | #include "osipparser2/osip_md5.h" 4 | #include "plog.h" 5 | #include "tinyxml2/tinyxml2.h" 6 | #include "pmanager.h" 7 | #include "psip_client.h" 8 | 9 | using namespace tinyxml2; 10 | 11 | static void cvt_to_hex(unsigned char* in, unsigned char* out) 12 | { 13 | unsigned short i; 14 | unsigned char j; 15 | for (i = 0; i < 16; i++) 16 | { 17 | j = (in[i] >> 4) & 0xf; 18 | if (j <= 9) out[i * 2] = (j + '0'); 19 | else out[i * 2] = (j + 'a' - 10); 20 | j = in[i] & 0xf; 21 | if (j <= 9) out[i * 2 + 1] = (j + '0'); 22 | else out[i * 2 + 1] = (j + 'a' - 10); 23 | } 24 | } 25 | 26 | PSipConn::PSipConn(PSipServer* server) 27 | : m_server(server) 28 | , m_contact(NULL) 29 | , m_cseq(0) 30 | { 31 | } 32 | 33 | PSipConn::~PSipConn() 34 | { 35 | if (m_contact) 36 | { 37 | osip_contact_free(m_contact); 38 | } 39 | } 40 | 41 | void PSipConn::clone_basic(osip_message_t* sip, osip_message_t* rsp, int sCode) 42 | { 43 | osip_message_set_status_code(rsp, sCode); 44 | osip_message_set_reason_phrase(rsp, osip_strdup(osip_message_get_reason(sCode))); 45 | 46 | osip_from_clone(sip->from, &rsp->from); 47 | osip_to_clone(sip->to, &rsp->to); 48 | osip_call_id_clone(sip->call_id, &rsp->call_id); 49 | osip_cseq_clone(sip->cseq, &rsp->cseq); 50 | osip_list_clone(&sip->vias, &rsp->vias, (int(*)(void *, void **)) &osip_via_clone); 51 | 52 | char temp[64]; 53 | sprintf(temp, "%d", std::rand()); 54 | osip_to_set_tag(rsp->to, osip_strdup(temp)); 55 | } 56 | 57 | int PSipConn::process_req(osip_message_t* sip, sockaddr_in& in_addr, socklen_t in_addrlen) 58 | { 59 | osip_message_t* rsp; 60 | osip_message_init(&rsp); 61 | 62 | if (MSG_IS_REGISTER(sip)) 63 | { 64 | if (sip->authorizations.nb_elt == 0) 65 | { 66 | char temp[128]; 67 | this->clone_basic(sip, rsp, 401); 68 | 69 | sprintf(temp, "%016lx", std::rand()); 70 | m_nonce = temp; 71 | 72 | sprintf(temp, "Digest realm=\"%s\",nonce=\"%s\",algorithm=MD5", 73 | m_server->get_domain().c_str(), m_nonce.c_str()); 74 | osip_message_set_www_authenticate(rsp, temp); 75 | 76 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 77 | } 78 | else 79 | { 80 | osip_authorization_t* auth; 81 | 82 | osip_message_get_authorization(sip, 0, &auth); 83 | 84 | char* nonce = osip_authorization_get_nonce(auth); 85 | 86 | if (0 != memcmp(nonce + 1, m_nonce.c_str(), m_nonce.size())) 87 | { 88 | this->clone_basic(sip, rsp, 403); 89 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 90 | 91 | return -1; 92 | } 93 | 94 | char* methond = osip_message_get_method(sip); 95 | char* username = osip_authorization_get_username(auth); 96 | char* realm = osip_authorization_get_realm(auth); 97 | char* uri = osip_authorization_get_uri(auth); 98 | char* response = osip_authorization_get_response(auth); 99 | 100 | unsigned char ha1[16]; 101 | unsigned char ha2[16]; 102 | unsigned char res[16]; 103 | 104 | unsigned char ha1_hex[32]; 105 | unsigned char ha2_hex[32]; 106 | unsigned char res_hex[32]; 107 | 108 | unsigned char c1 = ':'; 109 | PString pass = m_server->get_passwd(); 110 | 111 | osip_MD5_CTX md5_ctx; 112 | 113 | osip_MD5Init(&md5_ctx); 114 | osip_MD5Update(&md5_ctx, (unsigned char*)username + 1, strlen(username) - 2); 115 | osip_MD5Update(&md5_ctx, &c1, 1); 116 | osip_MD5Update(&md5_ctx, (unsigned char*)realm + 1, strlen(realm) - 2); 117 | osip_MD5Update(&md5_ctx, &c1, 1); 118 | osip_MD5Update(&md5_ctx, (unsigned char*)pass.data(), pass.size()); 119 | osip_MD5Final(ha1, &md5_ctx); 120 | cvt_to_hex(ha1, ha1_hex); 121 | 122 | osip_MD5Init(&md5_ctx); 123 | osip_MD5Update(&md5_ctx, (unsigned char*)methond, strlen(methond)); 124 | osip_MD5Update(&md5_ctx, &c1, 1); 125 | osip_MD5Update(&md5_ctx, (unsigned char*)uri + 1, strlen(uri) - 2); 126 | osip_MD5Final(ha2, &md5_ctx); 127 | cvt_to_hex(ha2, ha2_hex); 128 | 129 | osip_MD5Init(&md5_ctx); 130 | osip_MD5Update(&md5_ctx, ha1_hex, 32); 131 | osip_MD5Update(&md5_ctx, &c1, 1); 132 | osip_MD5Update(&md5_ctx, (unsigned char*)nonce + 1, strlen(nonce) - 2); 133 | osip_MD5Update(&md5_ctx, &c1, 1); 134 | osip_MD5Update(&md5_ctx, ha2_hex, 32); 135 | osip_MD5Final(res, &md5_ctx); 136 | cvt_to_hex(res, res_hex); 137 | 138 | if (0 != memcmp(response + 1, res_hex, 32)) 139 | { 140 | this->clone_basic(sip, rsp, 403); 141 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 142 | 143 | return -1; 144 | } 145 | else 146 | { 147 | if (m_contact) 148 | { 149 | osip_contact_free(m_contact); 150 | } 151 | 152 | if (sip->contacts.nb_elt) 153 | { 154 | osip_contact_t* contact; 155 | osip_message_get_contact(sip, 0, &contact); 156 | 157 | osip_contact_clone(contact, &m_contact); 158 | 159 | osip_list_clone(&sip->contacts, &rsp->contacts, (int(*)(void *, void **)) &osip_contact_clone); 160 | } 161 | else 162 | { 163 | osip_contact_clone(sip->to, &m_contact); 164 | 165 | char* dest; 166 | 167 | osip_to_to_str(sip->to, &dest); 168 | osip_message_set_contact(rsp, dest); 169 | 170 | osip_free(dest); 171 | } 172 | 173 | osip_header_t* expire; 174 | 175 | osip_message_get_expires(sip, 0, &expire); 176 | if (expire) 177 | { 178 | osip_message_set_expires(rsp, expire->hvalue); 179 | } 180 | else 181 | { 182 | osip_message_set_expires(rsp, "7200"); 183 | } 184 | 185 | this->clone_basic(sip, rsp, 200); 186 | 187 | char temp[64]; 188 | time_t tt; 189 | struct tm atm; 190 | 191 | time(&tt); 192 | localtime_r(&tt, &atm); 193 | 194 | sprintf(temp, "%04d-%02d-%02dT%02d:%02d:%02d", 195 | atm.tm_year + 1900, atm.tm_mon + 1, atm.tm_mday, atm.tm_hour, atm.tm_min, atm.tm_sec); 196 | 197 | osip_message_set_date(rsp, temp); 198 | 199 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 200 | 201 | P_LOG("%s register ok, expire:%s", sip->from->url->username, expire->hvalue); 202 | 203 | return 0; 204 | } 205 | } 206 | } 207 | else if (MSG_IS_MESSAGE(sip) && m_contact) 208 | { 209 | osip_body_t* body; 210 | osip_message_get_body(sip, 0, &body); 211 | 212 | if (body) 213 | { 214 | XMLDocument doc; 215 | XMLError ret = doc.Parse(body->body, body->length); 216 | 217 | if (ret) 218 | { 219 | P_LOG("xml parse err:%d", ret); 220 | } 221 | else 222 | { 223 | XMLText* textNode = doc.FirstChildElement("Notify")->FirstChildElement("CmdType")->FirstChild()->ToText(); 224 | //P_LOG("cmd: %s", textNode->Value()); 225 | } 226 | } 227 | 228 | this->clone_basic(sip, rsp, 200); 229 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 230 | } 231 | else 232 | { 233 | this->clone_basic(sip, rsp, 403); 234 | m_server->send_sip_rsp(rsp, in_addr, in_addrlen); 235 | 236 | return -1; 237 | } 238 | 239 | return 0; 240 | } 241 | 242 | PMediaClient* PSipConn::init_invite(PString& channel, PString& url) 243 | { 244 | if (!m_contact) 245 | { 246 | P_LOG("no contact"); 247 | return NULL; 248 | } 249 | 250 | sip_dialog* sipDialog = new sip_dialog; 251 | 252 | sipDialog->destUser = channel; 253 | sipDialog->destHost = m_contact->url->host; 254 | sipDialog->destPort = m_contact->url->port; 255 | 256 | char temp[128]; 257 | const PString& sDomian = m_server->get_domain(); 258 | 259 | sprintf(temp, "SIP/2.0/UDP %s:%d", m_server->get_ip().c_str(), m_server->get_port()); 260 | sipDialog->via = temp; 261 | 262 | sprintf(temp, ";tag=%d", sDomian.c_str(), m_server->get_ip().c_str(), m_server->get_port(), std::rand()); 263 | sipDialog->localTag = temp; 264 | 265 | sprintf(temp, "", channel.c_str(), m_contact->url->host, m_contact->url->port); 266 | sipDialog->remoteTag = temp; 267 | 268 | sprintf(temp, "%d", std::rand()); 269 | sipDialog->callid = temp; 270 | 271 | sipDialog->cseq = ++m_cseq; 272 | 273 | sprintf(temp, "", sDomian.c_str(), m_server->get_ip().c_str(), m_server->get_port()); 274 | sipDialog->localContact = temp; 275 | 276 | osip_message_t* sip; 277 | 278 | build_sip_msg(sip, sipDialog, sipDialog->cseq, "INVITE"); 279 | 280 | osip_message_set_content_type(sip, "Application/SDP"); 281 | 282 | sprintf(temp, "%s:0,%s:0", channel.c_str(), sDomian.c_str()); 283 | osip_message_set_subject(sip, temp); 284 | 285 | PManager* pm = PManager::Instance(); 286 | int rtp_sock; 287 | uint16_t rtp_port; 288 | PString rtp_ip; 289 | 290 | pm->CreateUdpSock(rtp_sock, rtp_ip, rtp_port); 291 | 292 | char sdp[1024]; 293 | char* p = sdp; 294 | 295 | int n = sprintf(p, "v=0\r\n"); 296 | p += n; 297 | 298 | n = sprintf(p, "o=%s 0 0 IN IP4 %s\r\n", channel.c_str(), rtp_ip.c_str()); 299 | p += n; 300 | 301 | n = sprintf(p, "s=Play\r\n"); 302 | p += n; 303 | 304 | n = sprintf(p, "c=IN IP4 %s\r\n", rtp_ip.c_str()); 305 | p += n; 306 | 307 | n = sprintf(p, "t=0 0\r\n"); 308 | p += n; 309 | 310 | n = sprintf(p, "m=video %d RTP/AVP 96\r\n", rtp_port); 311 | p += n; 312 | 313 | n = sprintf(p, "a=rtpmap:96 PS/90000\r\n"); 314 | p += n; 315 | 316 | n = sprintf(p, "a=recvonly\r\n"); 317 | p += n; 318 | 319 | n = sprintf(p, "y=0999999999\r\n"); 320 | p += n; 321 | 322 | int length = p - sdp; 323 | sprintf(temp, "%d", length); 324 | 325 | osip_message_set_content_length(sip, temp); 326 | osip_message_set_body(sip, sdp, length); 327 | 328 | m_server->send_sip_rsp(sip, m_contact->url->host, m_contact->url->port); 329 | 330 | PSipClient* sipClient = new PSipClient(rtp_sock, sipDialog->callid, url, m_server); 331 | 332 | sipClient->Start(); 333 | sipDialog->sipClient = sipClient; 334 | m_server->add_dialog(sipDialog); 335 | 336 | return sipClient; 337 | } 338 | -------------------------------------------------------------------------------- /osip2/include/osipparser2/headers/osip_www_authenticate.h: -------------------------------------------------------------------------------- 1 | /* 2 | The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 | Copyright (C) 2001-2015 Aymeric MOIZARD amoizard@antisip.com 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | 21 | #ifndef _OSIP_WWW_AUTHENTICATE_H_ 22 | #define _OSIP_WWW_AUTHENTICATE_H_ 23 | 24 | 25 | /** 26 | * @file osip_www_authenticate.h 27 | * @brief oSIP osip_www_authenticate header definition. 28 | */ 29 | 30 | /** 31 | * @defgroup oSIP_WWW_AUTHENTICATE oSIP www-authenticate header definition. 32 | * @ingroup oSIP_HEADERS 33 | * @{ 34 | */ 35 | 36 | /** 37 | * Structure for WWW-Authenticate headers. 38 | * @var osip_www_authenticate_t 39 | */ 40 | typedef struct osip_www_authenticate osip_www_authenticate_t; 41 | 42 | /** 43 | * Definition of the WWW-Authenticate header. 44 | * @struct osip_www_authenticate 45 | */ 46 | struct osip_www_authenticate 47 | { 48 | char *auth_type; /**< Authentication Type (Basic or Digest */ 49 | char *realm; /**< realm (as a quoted-string) */ 50 | char *domain; /**< domain (optional) */ 51 | char *nonce; /**< nonce (optional)*/ 52 | char *opaque; /**< opaque (optional) */ 53 | char *stale; /**< stale (optional) */ 54 | char *algorithm; /**< algorythm (optional) */ 55 | char *qop_options; /**< qop option (optional) */ 56 | char *version; /**< version (optional - NTLM) */ 57 | char *targetname; /**< targetname (optional - NTLM) */ 58 | char *gssapi_data; /**< gssapi-data (optional - NTLM) */ 59 | char *auth_param; /**< other parameters (optional) */ 60 | }; 61 | 62 | 63 | #ifdef __cplusplus 64 | extern "C" 65 | { 66 | #endif 67 | 68 | /** 69 | * Allocate a Www-Authenticate element. 70 | * @param header The element to work on. 71 | */ 72 | int osip_www_authenticate_init (osip_www_authenticate_t ** header); 73 | /** 74 | * Parse a Www-Authenticate element. 75 | * @param header The element to work on. 76 | * @param hvalue The string to parse. 77 | */ 78 | int osip_www_authenticate_parse (osip_www_authenticate_t * header, const char *hvalue); 79 | /** 80 | * Get a string representation of a Www-Authenticate element. 81 | * @param header The element to work on. 82 | * @param dest A pointer on the new allocated string. 83 | */ 84 | int osip_www_authenticate_to_str (const osip_www_authenticate_t * header, char **dest); 85 | /** 86 | * Free a Www-Authenticate element. 87 | * @param header The element to work on. 88 | */ 89 | void osip_www_authenticate_free (osip_www_authenticate_t * header); 90 | /** 91 | * Clone a Www-Authenticate element. 92 | * @param header The element to work on. 93 | * @param dest A pointer on the copy of the element. 94 | */ 95 | int osip_www_authenticate_clone (const osip_www_authenticate_t * header, 96 | osip_www_authenticate_t ** dest); 97 | 98 | /** 99 | * Get value of the auth_type parameter from a Www-Authenticate element. 100 | * @param header The element to work on. 101 | */ 102 | char *osip_www_authenticate_get_auth_type (osip_www_authenticate_t * header); 103 | /** 104 | * Add the auth_type parameter from a Www-Authenticate element. 105 | * @param header The element to work on. 106 | * @param value The value of the new parameter. 107 | */ 108 | void osip_www_authenticate_set_auth_type (osip_www_authenticate_t * header, 109 | char *value); 110 | /** 111 | * Get value of the realm parameter from a Www-Authenticate element. 112 | * @param header The element to work on. 113 | */ 114 | char *osip_www_authenticate_get_realm (osip_www_authenticate_t * header); 115 | /** 116 | * Add the realm parameter from a Www-Authenticate element. 117 | * @param header The element to work on. 118 | * @param value The value of the new parameter. 119 | */ 120 | void osip_www_authenticate_set_realm (osip_www_authenticate_t * header, char *value); 121 | /** 122 | * Get value of the domain parameter from a Www-Authenticate element. 123 | * @param header The element to work on. 124 | */ 125 | char *osip_www_authenticate_get_domain (osip_www_authenticate_t * header); 126 | /** 127 | * Add the domain parameter from a Www-Authenticate element. 128 | * @param header The element to work on. 129 | * @param value The value of the new parameter. 130 | */ 131 | void osip_www_authenticate_set_domain (osip_www_authenticate_t * header, char *value); 132 | /** 133 | * Get value of the nonce parameter from a Www-Authenticate element. 134 | * @param header The element to work on. 135 | */ 136 | char *osip_www_authenticate_get_nonce (osip_www_authenticate_t * header); 137 | /** 138 | * Add the nonce parameter from a Www-Authenticate element. 139 | * @param header The element to work on. 140 | * @param value The value of the new parameter. 141 | */ 142 | void osip_www_authenticate_set_nonce (osip_www_authenticate_t * header, char *value); 143 | /** 144 | * Get value of the opaque parameter from a Www-Authenticate element. 145 | * @param header The element to work on. 146 | */ 147 | char *osip_www_authenticate_get_opaque (osip_www_authenticate_t * header); 148 | /** 149 | * Add the opaque parameter from a Www-Authenticate element. 150 | * @param header The element to work on. 151 | * @param value The value of the new parameter. 152 | */ 153 | void osip_www_authenticate_set_opaque (osip_www_authenticate_t * header, char *value); 154 | /** 155 | * Get value of the stale parameter from a Www-Authenticate element. 156 | * @param header The element to work on. 157 | */ 158 | char *osip_www_authenticate_get_stale (osip_www_authenticate_t * header); 159 | /** 160 | * Add the stale parameter in a Www-Authenticate element. 161 | * @param header The element to work on. 162 | * @param value The value of the new parameter. 163 | */ 164 | void osip_www_authenticate_set_stale (osip_www_authenticate_t * header, char *value); 165 | /** 166 | * Add a stale parameter set to "true" in a Www-Authenticate element. 167 | * @param header The element to work on. 168 | */ 169 | #define osip_www_authenticate_set_stale_true(header) osip_www_authenticate_set_stale(header,osip_strdup("true")) 170 | /** 171 | * Add a stale parameter set to "false" in a Www-Authenticate element. 172 | * @param header The element to work on. 173 | */ 174 | #define osip_www_authenticate_set_stale_false(header) osip_www_authenticate_set_stale(header,osip_strdup("false")) 175 | /** 176 | * Get value of the algorithm parameter from a Www-Authenticate element. 177 | * @param header The element to work on. 178 | */ 179 | char *osip_www_authenticate_get_algorithm (osip_www_authenticate_t * header); 180 | /** 181 | * Add the algorithm parameter in a Www-Authenticate element. 182 | * @param header The element to work on. 183 | * @param value The value of the new parameter. 184 | */ 185 | void osip_www_authenticate_set_algorithm (osip_www_authenticate_t * header, 186 | char *value); 187 | /** 188 | * Add the algorithm parameter set to "MD5" in a Www-Authenticate element. 189 | * @param header The element to work on. 190 | */ 191 | #define osip_www_authenticate_set_algorithm_MD5(header) osip_www_authenticate_set_algorithm(header,osip_strdup("MD5")) 192 | /** 193 | * Get value of the qop_options parameter from a Www-Authenticate element. 194 | * @param header The element to work on. 195 | */ 196 | char *osip_www_authenticate_get_qop_options (osip_www_authenticate_t * header); 197 | /** 198 | * Add the qop_options parameter from a Www-Authenticate element. 199 | * @param header The element to work on. 200 | * @param value The value of the new parameter. 201 | */ 202 | void osip_www_authenticate_set_qop_options (osip_www_authenticate_t * header, 203 | char *value); 204 | /** 205 | * Get value of the version parameter from a Www-Authenticate element. 206 | * @param header The element to work on. 207 | */ 208 | char *osip_www_authenticate_get_version (osip_www_authenticate_t * header); 209 | /** 210 | * Add the version parameter from a Www-Authenticate element. 211 | * @param header The element to work on. 212 | * @param value The value of the new parameter. 213 | */ 214 | void osip_www_authenticate_set_version (osip_www_authenticate_t * header, 215 | char *value); 216 | /** 217 | * Get value of the targetname parameter from a Www-Authenticate element. 218 | * @param header The element to work on. 219 | */ 220 | char *osip_www_authenticate_get_targetname (osip_www_authenticate_t * header); 221 | /** 222 | * Add the targetname parameter from a Www-Authenticate element. 223 | * @param header The element to work on. 224 | * @param value The value of the new parameter. 225 | */ 226 | void osip_www_authenticate_set_targetname (osip_www_authenticate_t * header, 227 | char *value); 228 | /** 229 | * Get value of the gssapi_data parameter from a Www-Authenticate element. 230 | * @param header The element to work on. 231 | */ 232 | char *osip_www_authenticate_get_gssapi_data (osip_www_authenticate_t * header); 233 | /** 234 | * Add the gssapi_data parameter from a Www-Authenticate element. 235 | * @param header The element to work on. 236 | * @param value The value of the new parameter. 237 | */ 238 | void osip_www_authenticate_set_gssapi_data (osip_www_authenticate_t * header, 239 | char *value); 240 | 241 | #ifdef __cplusplus 242 | } 243 | #endif 244 | 245 | /** @} */ 246 | 247 | #endif 248 | --------------------------------------------------------------------------------