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-2012 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 
00071 protected:
00072   virtual ~SIPClient();
00073 
00074 private:
00075   SIPClient(UsageEnvironment& env,
00076             unsigned char desiredAudioRTPPayloadFormat,
00077             char const* mimeSubtype,
00078             int verbosityLevel,
00079             char const* applicationName);
00080       // called only by createNew();
00081 
00082   void reset();
00083 
00084   // Routines used to implement invite*():
00085   char* invite1(Authenticator* authenticator);
00086   Boolean processURL(char const* url);
00087   Boolean sendINVITE();
00088   static void inviteResponseHandler(void* clientData, int mask);
00089   void doInviteStateMachine(unsigned responseCode);
00090   void doInviteStateTerminated(unsigned responseCode);
00091   TaskToken fTimerA, fTimerB, fTimerD;
00092   static void timerAHandler(void* clientData);
00093   static void timerBHandler(void* clientData);
00094   static void timerDHandler(void* clientData);
00095   unsigned const fT1; // in microseconds
00096   unsigned fTimerALen; // in microseconds; initially fT1, then doubles
00097   unsigned fTimerACount;
00098 
00099   // Routines used to implement all commands:
00100   char* createAuthenticatorString(Authenticator const* authenticator,
00101                                   char const* cmd, char const* url);
00102   Boolean sendRequest(char const* requestString, unsigned requestLength);
00103   unsigned getResponseCode();
00104   unsigned getResponse(char*& responseBuffer, unsigned responseBufferSize);
00105   Boolean parseResponseCode(char const* line, unsigned& responseCode);
00106 
00107 private:
00108   // Set for all calls:
00109   unsigned char fDesiredAudioRTPPayloadFormat;
00110   char* fMIMESubtype;
00111       unsigned fMIMESubtypeSize;
00112   int fVerbosityLevel;
00113   unsigned fCSeq; // sequence number, used in consecutive requests
00114   char const* fApplicationName;
00115       unsigned fApplicationNameSize;
00116   char const* fOurAddressStr;
00117       unsigned fOurAddressStrSize;
00118   portNumBits fOurPortNum;
00119   Groupsock* fOurSocket;
00120   char* fUserAgentHeaderStr;
00121       unsigned fUserAgentHeaderStrSize;
00122 
00123   // Set for each call:
00124   char const* fURL;
00125       unsigned fURLSize;
00126   struct in_addr fServerAddress;
00127   portNumBits fServerPortNum; // in host order
00128   portNumBits fClientStartPortNum; // in host order
00129   unsigned fCallId, fFromTag; // set by us
00130   char const* fToTagStr; // set by the responder
00131       unsigned fToTagStrSize;
00132   Authenticator fValidAuthenticator;
00133   char const* fUserName; // 'user' name used in "From:" & "Contact:" lines
00134       unsigned fUserNameSize;
00135 
00136   char* fInviteSDPDescription;
00137   char* fInviteCmd;
00138       unsigned fInviteCmdSize;
00139   Authenticator* fWorkingAuthenticator;
00140   inviteClientState fInviteClientState;
00141   char fEventLoopStopFlag;
00142 };
00143 
00144 #endif

Generated on Thu May 17 07:11:46 2012 for live by  doxygen 1.5.2