Go to the documentation of this file.
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <>.)
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16// "liveMedia"
17// Copyright (c) 1996-2024 Live Networks, Inc. All rights reserved.
18// A generic SIP client
19// C++ header
21#ifndef _SIP_CLIENT_HH
22#define _SIP_CLIENT_HH
25#include "MediaSession.hh"
27#ifndef _NET_ADDRESS_HH
28#include "NetAddress.hh"
34// Possible states in the "INVITE" transition diagram (RFC 3261, Figure 5)
37class SIPClient: public Medium {
40 unsigned char desiredAudioRTPPayloadFormat,
41 char const* mimeSubtype = NULL,
42 int verbosityLevel = 0,
43 char const* applicationName = NULL);
45 void setProxyServer(struct sockaddr_storage const& proxyServerAddress,
46 portNumBits proxyServerPortNum);
48 void setClientStartPortNum(portNumBits clientStartPortNum) {
49 fClientStartPortNum = clientStartPortNum;
50 }
52 char* invite(char const* url, Authenticator* authenticator = NULL);
53 // Issues a SIP "INVITE" command
54 // Returns the session SDP description if this command succeeds
55 char* inviteWithPassword(char const* url,
56 char const* username, char const* password);
57 // Uses "invite()" to do an "INVITE" - first
58 // without using "password", then (if we get an Unauthorized
59 // response) with an authentication response computed from "password"
61 Boolean sendACK(); // on current call
62 Boolean sendBYE(); // on current call
64 static Boolean parseSIPURL(UsageEnvironment& env, char const* url,
65 NetAddress& address, portNumBits& portNum);
66 // (ignores any "<username>[:<password>]@" in "url")
67 static Boolean parseSIPURLUsernamePassword(char const* url,
68 char*& username,
69 char*& password);
70 char const* getInviteSdpReply() const { return fInviteSDPDescriptionReturned; }
72 void setUserAgentString(char const* userAgentName);
73 // sets an alternative string to be used in SIP "User-Agent:" headers
76 virtual ~SIPClient();
80 unsigned char desiredAudioRTPPayloadFormat,
81 char const* mimeSubtype,
82 int verbosityLevel,
83 char const* applicationName);
84 // called only by createNew();
86 void reset();
88 // Routines used to implement invite*():
89 char* invite1(Authenticator* authenticator);
90 Boolean processURL(char const* url);
92 static void inviteResponseHandler(void* clientData, int mask);
93 void doInviteStateMachine(unsigned responseCode);
94 void doInviteStateTerminated(unsigned responseCode);
96 static void timerAHandler(void* clientData);
97 static void timerBHandler(void* clientData);
98 static void timerDHandler(void* clientData);
99 unsigned const fT1; // in microseconds
100 unsigned fTimerALen; // in microseconds; initially fT1, then doubles
101 unsigned fTimerACount;
103 // Routines used to implement all commands:
104 char* createAuthenticatorString(Authenticator const* authenticator,
105 char const* cmd, char const* url);
106 Boolean sendRequest(char const* requestString, unsigned requestLength);
107 unsigned getResponseCode();
108 unsigned getResponse(char*& responseBuffer, unsigned responseBufferSize);
109 Boolean parseResponseCode(char const* line, unsigned& responseCode);
112 // Set for all calls:
117 unsigned fCSeq; // sequence number, used in consecutive requests
118 char const* fApplicationName;
120 char const* fOurAddressStr;
127 // Set for each call:
128 char const* fURL;
129 unsigned fURLSize;
130 struct sockaddr_storage fServerAddress;
132 portNumBits fServerPortNum; // in host order
134 unsigned fCallId, fFromTag; // set by us
135 char const* fToTagStr; // set by the responder
138 char const* fUserName; // 'user' name used in "From:" & "Contact:" lines
unsigned char Boolean
Definition: Boolean.hh:25
portNumBits portNum(struct sockaddr_storage const &address)
u_int16_t portNumBits
Definition: NetAddress.hh:102
Definition: SIPClient.hh:35
@ Terminated
Definition: SIPClient.hh:35
@ Proceeding
Definition: SIPClient.hh:35
@ Calling
Definition: SIPClient.hh:35
@ Completed
Definition: SIPClient.hh:35
#define NULL
void * TaskToken
Definition: Media.hh:50
unsigned fUserAgentHeaderStrLen
Definition: SIPClient.hh:125
unsigned fCSeq
Definition: SIPClient.hh:117
int fVerbosityLevel
Definition: SIPClient.hh:116
char const * fOurAddressStr
Definition: SIPClient.hh:120
Boolean parseResponseCode(char const *line, unsigned &responseCode)
unsigned char fDesiredAudioRTPPayloadFormat
Definition: SIPClient.hh:113
inviteClientState fInviteClientState
Definition: SIPClient.hh:146
static void timerDHandler(void *clientData)
void doInviteStateTerminated(unsigned responseCode)
unsigned fFromTag
Definition: SIPClient.hh:134
unsigned fOurAddressStrSize
Definition: SIPClient.hh:121
void doInviteStateMachine(unsigned responseCode)
char * fInviteCmd
Definition: SIPClient.hh:143
Boolean sendBYE()
TaskToken fTimerD
Definition: SIPClient.hh:95
static SIPClient * createNew(UsageEnvironment &env, unsigned char desiredAudioRTPPayloadFormat, char const *mimeSubtype=NULL, int verbosityLevel=0, char const *applicationName=NULL)
char * fInviteSDPDescriptionReturned
Definition: SIPClient.hh:142
Boolean fServerAddressIsSet
Definition: SIPClient.hh:131
char const * fToTagStr
Definition: SIPClient.hh:135
Groupsock * fOurSocket
Definition: SIPClient.hh:123
Boolean sendINVITE()
unsigned fMIMESubtypeSize
Definition: SIPClient.hh:115
unsigned fTimerALen
Definition: SIPClient.hh:100
void reset()
char * fMIMESubtype
Definition: SIPClient.hh:114
char * fUserAgentHeaderStr
Definition: SIPClient.hh:124
char * inviteWithPassword(char const *url, char const *username, char const *password)
char const * getInviteSdpReply() const
Definition: SIPClient.hh:70
char const * fApplicationName
Definition: SIPClient.hh:118
portNumBits fServerPortNum
Definition: SIPClient.hh:132
SIPClient(UsageEnvironment &env, unsigned char desiredAudioRTPPayloadFormat, char const *mimeSubtype, int verbosityLevel, char const *applicationName)
void setUserAgentString(char const *userAgentName)
char * invite1(Authenticator *authenticator)
void setClientStartPortNum(portNumBits clientStartPortNum)
Definition: SIPClient.hh:48
unsigned fApplicationNameSize
Definition: SIPClient.hh:119
char const * fUserName
Definition: SIPClient.hh:138
virtual ~SIPClient()
Authenticator fValidAuthenticator
Definition: SIPClient.hh:137
char * createAuthenticatorString(Authenticator const *authenticator, char const *cmd, char const *url)
static Boolean parseSIPURLUsernamePassword(char const *url, char *&username, char *&password)
char * fInviteSDPDescription
Definition: SIPClient.hh:141
void setProxyServer(struct sockaddr_storage const &proxyServerAddress, portNumBits proxyServerPortNum)
static void inviteResponseHandler(void *clientData, int mask)
Boolean sendRequest(char const *requestString, unsigned requestLength)
portNumBits fClientStartPortNum
Definition: SIPClient.hh:133
Boolean sendACK()
unsigned const fT1
Definition: SIPClient.hh:99
unsigned getResponse(char *&responseBuffer, unsigned responseBufferSize)
char const * fURL
Definition: SIPClient.hh:128
char * invite(char const *url, Authenticator *authenticator=NULL)
unsigned fTimerACount
Definition: SIPClient.hh:101
char fEventLoopStopFlag
Definition: SIPClient.hh:147
static void timerBHandler(void *clientData)
static void timerAHandler(void *clientData)
portNumBits fOurPortNum
Definition: SIPClient.hh:122
unsigned fToTagStrSize
Definition: SIPClient.hh:136
unsigned fCallId
Definition: SIPClient.hh:134
struct sockaddr_storage fServerAddress
Definition: SIPClient.hh:130
TaskToken fTimerB
Definition: SIPClient.hh:95
Boolean processURL(char const *url)
unsigned fUserNameSize
Definition: SIPClient.hh:139
Authenticator * fWorkingAuthenticator
Definition: SIPClient.hh:145
unsigned fInviteCmdSize
Definition: SIPClient.hh:144
TaskToken fTimerA
Definition: SIPClient.hh:95
unsigned getResponseCode()
unsigned fURLSize
Definition: SIPClient.hh:129
static Boolean parseSIPURL(UsageEnvironment &env, char const *url, NetAddress &address, portNumBits &portNum)