SIPClient.hh 5.2 KB

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