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

Generated on Fri Dec 19 21:58:18 2008 for live by  doxygen 1.5.2