liveMedia/include/SIPClient.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // A generic SIP client
00019 // C++ header
00020 
00021 #ifndef _SIP_CLIENT_HH
00022 #define _SIP_CLIENT_HH
00023 
00024 #ifndef _MEDIA_SESSION_HH
00025 #include "MediaSession.hh"
00026 #endif
00027 #ifndef _NET_ADDRESS_HH
00028 #include "NetAddress.hh"
00029 #endif
00030 #ifndef _DIGEST_AUTHENTICATION_HH
00031 #include "DigestAuthentication.hh"
00032 #endif
00033 
00034 // Possible states in the "INVITE" transition diagram (RFC 3261, Figure 5)
00035 enum inviteClientState { Calling, Proceeding, Completed, Terminated };
00036 
00037 class SIPClient: public Medium {
00038 public:
00039   static SIPClient* createNew(UsageEnvironment& env,
00040                               unsigned char desiredAudioRTPPayloadFormat,
00041                               char const* mimeSubtype = NULL,
00042                               int verbosityLevel = 0,
00043                               char const* applicationName = NULL);
00044 
00045   void setProxyServer(unsigned proxyServerAddress,
00046                       portNumBits proxyServerPortNum);
00047 
00048   void setClientStartPortNum(portNumBits clientStartPortNum) {
00049     fClientStartPortNum = clientStartPortNum;
00050   }
00051 
00052   char* invite(char const* url, Authenticator* authenticator = NULL);
00053       // Issues a SIP "INVITE" command
00054       // Returns the session SDP description if this command succeeds
00055   char* inviteWithPassword(char const* url,
00056                            char const* username, char const* password);
00057       // Uses "invite()" to do an "INVITE" - first
00058       // without using "password", then (if we get an Unauthorized
00059       // response) with an authentication response computed from "password"
00060 
00061   Boolean sendACK(); // on current call
00062   Boolean sendBYE(); // on current call
00063 
00064   static Boolean parseSIPURL(UsageEnvironment& env, char const* url,
00065                              NetAddress& address, portNumBits& portNum);
00066       // (ignores any "<username>[:<password>]@" in "url")
00067   static Boolean parseSIPURLUsernamePassword(char const* url,
00068                                              char*& username,
00069                                              char*& password);
00070   char const* getInviteSdpReply() const { return fInviteSDPDescriptionReturned; }
00071 
00072 protected:
00073   virtual ~SIPClient();
00074 
00075 private:
00076   SIPClient(UsageEnvironment& env,
00077             unsigned char desiredAudioRTPPayloadFormat,
00078             char const* mimeSubtype,
00079             int verbosityLevel,
00080             char const* applicationName);
00081       // called only by createNew();
00082 
00083   void reset();
00084 
00085   // Routines used to implement invite*():
00086   char* invite1(Authenticator* authenticator);
00087   Boolean processURL(char const* url);
00088   Boolean sendINVITE();
00089   static void inviteResponseHandler(void* clientData, int mask);
00090   void doInviteStateMachine(unsigned responseCode);
00091   void doInviteStateTerminated(unsigned responseCode);
00092   TaskToken fTimerA, fTimerB, fTimerD;
00093   static void timerAHandler(void* clientData);
00094   static void timerBHandler(void* clientData);
00095   static void timerDHandler(void* clientData);
00096   unsigned const fT1; // in microseconds
00097   unsigned fTimerALen; // in microseconds; initially fT1, then doubles
00098   unsigned fTimerACount;
00099 
00100   // Routines used to implement all commands:
00101   char* createAuthenticatorString(Authenticator const* authenticator,
00102                                   char const* cmd, char const* url);
00103   Boolean sendRequest(char const* requestString, unsigned requestLength);
00104   unsigned getResponseCode();
00105   unsigned getResponse(char*& responseBuffer, unsigned responseBufferSize);
00106   Boolean parseResponseCode(char const* line, unsigned& responseCode);
00107 
00108 private:
00109   // Set for all calls:
00110   unsigned char fDesiredAudioRTPPayloadFormat;
00111   char* fMIMESubtype;
00112   unsigned fMIMESubtypeSize;
00113   int fVerbosityLevel;
00114   unsigned fCSeq; // sequence number, used in consecutive requests
00115   char const* fApplicationName;
00116   unsigned fApplicationNameSize;
00117   char const* fOurAddressStr;
00118   unsigned fOurAddressStrSize;
00119   portNumBits fOurPortNum;
00120   Groupsock* fOurSocket;
00121   char* fUserAgentHeaderStr;
00122   unsigned fUserAgentHeaderStrSize;
00123 
00124   // Set for each call:
00125   char const* fURL;
00126   unsigned fURLSize;
00127   struct in_addr fServerAddress;
00128   portNumBits fServerPortNum; // in host order
00129   portNumBits fClientStartPortNum; // in host order
00130   unsigned fCallId, fFromTag; // set by us
00131   char const* fToTagStr; // set by the responder
00132   unsigned fToTagStrSize;
00133   Authenticator fValidAuthenticator;
00134   char const* fUserName; // 'user' name used in "From:" & "Contact:" lines
00135   unsigned fUserNameSize;
00136 
00137   char* fInviteSDPDescription;
00138   char* fInviteSDPDescriptionReturned;
00139   char* fInviteCmd;
00140   unsigned fInviteCmdSize;
00141   Authenticator* fWorkingAuthenticator;
00142   inviteClientState fInviteClientState;
00143   char fEventLoopStopFlag;
00144 };
00145 
00146 #endif

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2