live
SIPClient.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2021 Live Networks, Inc. All rights reserved.
18 // A generic SIP client
19 // C++ header
20 
21 #ifndef _SIP_CLIENT_HH
22 #define _SIP_CLIENT_HH
23 
24 #ifndef _MEDIA_SESSION_HH
25 #include "MediaSession.hh"
26 #endif
27 #ifndef _NET_ADDRESS_HH
28 #include "NetAddress.hh"
29 #endif
30 #ifndef _DIGEST_AUTHENTICATION_HH
31 #include "DigestAuthentication.hh"
32 #endif
33 
34 // Possible states in the "INVITE" transition diagram (RFC 3261, Figure 5)
36 
37 class SIPClient: public Medium {
38 public:
40  unsigned char desiredAudioRTPPayloadFormat,
41  char const* mimeSubtype = NULL,
42  int verbosityLevel = 0,
43  char const* applicationName = NULL);
44 
45  void setProxyServer(struct sockaddr_storage const& proxyServerAddress,
46  portNumBits proxyServerPortNum);
47 
48  void setClientStartPortNum(portNumBits clientStartPortNum) {
49  fClientStartPortNum = clientStartPortNum;
50  }
51 
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"
60 
61  Boolean sendACK(); // on current call
62  Boolean sendBYE(); // on current call
63 
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; }
71 
72  void setUserAgentString(char const* userAgentName);
73  // sets an alternative string to be used in SIP "User-Agent:" headers
74 
75 protected:
76  virtual ~SIPClient();
77 
78 private:
80  unsigned char desiredAudioRTPPayloadFormat,
81  char const* mimeSubtype,
82  int verbosityLevel,
83  char const* applicationName);
84  // called only by createNew();
85 
86  void reset();
87 
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;
102 
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);
110 
111 private:
112  // Set for all calls:
117  unsigned fCSeq; // sequence number, used in consecutive requests
118  char const* fApplicationName;
120  char const* fOurAddressStr;
126 
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
136  unsigned fToTagStrSize;
138  char const* fUserName; // 'user' name used in "From:" & "Contact:" lines
139  unsigned fUserNameSize;
140 
143  char* fInviteCmd;
144  unsigned fInviteCmdSize;
148 };
149 
150 #endif
unsigned char Boolean
Definition: Boolean.hh:25
portNumBits portNum(struct sockaddr_storage const &address)
u_int16_t portNumBits
Definition: NetAddress.hh:102
inviteClientState
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
static SIPClient * createNew(UsageEnvironment &env, unsigned char desiredAudioRTPPayloadFormat, char const *mimeSubtype=NULL, int verbosityLevel=0, char const *applicationName=NULL)
char * inviteWithPassword(char const *url, char const *username, char const *password)
unsigned fOurAddressStrSize
Definition: SIPClient.hh:121
void doInviteStateMachine(unsigned responseCode)
char * fInviteCmd
Definition: SIPClient.hh:143
Boolean sendBYE()
TaskToken fTimerD
Definition: SIPClient.hh:95
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()
char * invite(char const *url, Authenticator *authenticator=NULL)
unsigned fMIMESubtypeSize
Definition: SIPClient.hh:115
unsigned fTimerALen
Definition: SIPClient.hh:100
void reset()
char * createAuthenticatorString(Authenticator const *authenticator, char const *cmd, char const *url)
char * fMIMESubtype
Definition: SIPClient.hh:114
char * fUserAgentHeaderStr
Definition: SIPClient.hh:124
char const * fApplicationName
Definition: SIPClient.hh:118
portNumBits fServerPortNum
Definition: SIPClient.hh:132
char const * getInviteSdpReply() const
Definition: SIPClient.hh:70
SIPClient(UsageEnvironment &env, unsigned char desiredAudioRTPPayloadFormat, char const *mimeSubtype, int verbosityLevel, char const *applicationName)
void setUserAgentString(char const *userAgentName)
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
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
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
char * invite1(Authenticator *authenticator)
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)