eXosip.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. eXosip - This is the eXtended osip library.
  3. Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
  4. eXosip is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. eXosip is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. In addition, as a special exception, the copyright holders give
  16. permission to link the code of portions of this program with the
  17. OpenSSL library under certain conditions as described in each
  18. individual source file, and distribute linked combinations
  19. including the two.
  20. You must obey the GNU General Public License in all respects
  21. for all of the code used other than OpenSSL. If you modify
  22. file(s) with this exception, you may extend this exception to your
  23. version of the file(s), but you are not obligated to do so. If you
  24. do not wish to do so, delete this exception statement from your
  25. version. If you delete this exception statement from all source
  26. files in the program, then also delete it here.
  27. */
  28. #ifdef ENABLE_MPATROL
  29. #include <mpatrol.h>
  30. #endif
  31. #ifndef __EXOSIP_H__
  32. #define __EXOSIP_H__
  33. #include <eXosip2/eX_setup.h>
  34. #include <eXosip2/eX_register.h>
  35. #include <eXosip2/eX_call.h>
  36. #include <eXosip2/eX_options.h>
  37. #include <eXosip2/eX_subscribe.h>
  38. #include <eXosip2/eX_message.h>
  39. #include <eXosip2/eX_publish.h>
  40. #include <osipparser2/osip_parser.h>
  41. #include <osipparser2/sdp_message.h>
  42. #include <time.h>
  43. /**
  44. * @file eXosip.h
  45. * @brief eXosip API
  46. *
  47. * eXosip is a high layer library for rfc3261: the SIP protocol.
  48. * It offers a simple API to make it easy to use. eXosip2 offers
  49. * great flexibility for implementing SIP endpoint like:
  50. * <ul>
  51. * <li>SIP User-Agents</li>
  52. * <li>SIP Voicemail or IVR</li>
  53. * <li>any SIP server acting as an endpoint (music server...)</li>
  54. * </ul>
  55. *
  56. * If you need to implement proxy or complex SIP applications,
  57. * you should consider using osip instead.
  58. *
  59. * Here are the eXosip capabilities:
  60. * <pre>
  61. * REGISTER to handle registration.
  62. * INVITE/BYE to start/stop VoIP sessions.
  63. * INFO to send DTMF within a VoIP sessions.
  64. * OPTIONS to simulate VoIP sessions.
  65. * re-INVITE to modify VoIP sessions.
  66. * REFER/NOTIFY to transfer calls.
  67. * MESSAGE to send Instant Message.
  68. * SUBSCRIBE/REFER/NOTIFY to handle presence capabilities.
  69. * any other request to handle what you want (outside dialogs)!
  70. * </pre>
  71. * <P>
  72. */
  73. #ifdef __cplusplus
  74. extern "C" {
  75. #endif
  76. /**
  77. * Structure for event description.
  78. * @var eXosip_event_t
  79. */
  80. typedef struct eXosip_event eXosip_event_t;
  81. /**
  82. * @defgroup eXosip2_authentication eXosip2 authentication API
  83. * @ingroup eXosip2_msg
  84. * @{
  85. */
  86. /**
  87. * Add authentication credentials. These are used when an outgoing
  88. * request comes back with an authorization required response.
  89. *
  90. * @param excontext eXosip_t instance.
  91. * @param username username
  92. * @param userid login (usually equals the username)
  93. * @param passwd password
  94. * @param ha1 MD5 ha1
  95. * @param realm realm within which credentials apply, or NULL to apply credentials to unrecognized realms
  96. */
  97. int eXosip_add_authentication_info(struct eXosip_t *excontext, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm);
  98. /**
  99. * Remove authentication credentials.
  100. *
  101. * @param excontext eXosip_t instance.
  102. * @param username username
  103. * @param realm realm must be exact same arg as for eXosip_add_authentication_info
  104. */
  105. int eXosip_remove_authentication_info(struct eXosip_t *excontext, const char *username, const char *realm);
  106. /**
  107. * Clear all authentication credentials stored in eXosip
  108. *
  109. * @param excontext eXosip_t instance.
  110. */
  111. int eXosip_clear_authentication_info(struct eXosip_t *excontext);
  112. /**
  113. * Initiate some default actions:
  114. *
  115. * Retry with credentials upon reception of 401/407.
  116. * Retry with Contact header upon reception of 3xx request.
  117. *
  118. * Usefull & required when eXosip_automatic_action() can't do the automatic action:
  119. * 1/ if you receive a 401 or 407 for BYE (event EXOSIP_CALL_MESSAGE_REQUESTFAILURE).
  120. * 2/ if you receive 401 or 407 for any sip request outside of dialog (EXOSIP_MESSAGE_REQUESTFAILURE)
  121. *
  122. * @param excontext eXosip_t instance.
  123. * @param je event to work on.
  124. */
  125. int eXosip_default_action(struct eXosip_t *excontext, eXosip_event_t *je);
  126. /**
  127. * Initiate some automatic actions:
  128. *
  129. * Retry with credentials upon reception of 401/407.
  130. * Retry with higher Session-Expires upon reception of 422.
  131. * Refresh REGISTER and SUBSCRIBE/REFER before the expiration delay.
  132. * Retry with Contact header upon reception of 3xx request.
  133. * Send automatic UPDATE for session-timer feature.
  134. *
  135. * @param excontext eXosip_t instance.
  136. */
  137. void eXosip_automatic_action(struct eXosip_t *excontext);
  138. #ifndef MINISIZE
  139. /**
  140. * Automatic internal handling of dialog package.
  141. *
  142. * @param excontext eXosip_t instance.
  143. * @param evt Incoming SUBSCRIBE for dialog package.
  144. */
  145. int eXosip_insubscription_automatic(struct eXosip_t *excontext, eXosip_event_t *evt);
  146. #endif
  147. /**
  148. * Generate random string: (only digit, and maximum unsigned int)
  149. *
  150. * @param buf destination buffer for random string.
  151. * @param buf_size size of destination buffer
  152. */
  153. int eXosip_generate_random(char *buf, int buf_size);
  154. /**
  155. * Generate random string: (low entropy, only hexa)
  156. *
  157. * @param buf destination buffer for random string.
  158. * @param buf_size size of destination buffer
  159. * @param str1 random1 input string
  160. * @param str2 random2 input string
  161. * @param str3 random3 input string
  162. */
  163. int eXosip_hexa_generate_random(char *buf, int buf_size, char *str1, char *str2, char *str3);
  164. /**
  165. * Generate random string: (high entropy when compiled with openssl)
  166. *
  167. * @param buf destination buffer for random string.
  168. * @param buf_size size of destination buffer
  169. */
  170. int eXosip_byte_generate_random(char *buf, int buf_size);
  171. /** @} */
  172. /**
  173. * @defgroup eXosip2_sdp eXosip2 SDP helper API.
  174. * @ingroup eXosip2_msg
  175. * @{
  176. */
  177. /**
  178. * Get remote SDP body for the latest INVITE of call.
  179. *
  180. * @param excontext eXosip_t instance.
  181. * @param did dialog id of call.
  182. */
  183. sdp_message_t *eXosip_get_remote_sdp(struct eXosip_t *excontext, int did);
  184. /**
  185. * Get local SDP body for the latest INVITE of call.
  186. *
  187. * @param excontext eXosip_t instance.
  188. * @param did dialog id of call.
  189. */
  190. sdp_message_t *eXosip_get_local_sdp(struct eXosip_t *excontext, int did);
  191. /**
  192. * Get local SDP body for the previous latest INVITE of call.
  193. *
  194. * @param excontext eXosip_t instance.
  195. * @param did dialog id of call.
  196. */
  197. sdp_message_t *eXosip_get_previous_local_sdp(struct eXosip_t *excontext, int did);
  198. /**
  199. * Get remote SDP body for the latest INVITE of call.
  200. *
  201. * @param excontext eXosip_t instance.
  202. * @param tid transction id of transaction.
  203. */
  204. sdp_message_t *eXosip_get_remote_sdp_from_tid(struct eXosip_t *excontext, int tid);
  205. /**
  206. * Get local SDP body for the latest INVITE of call.
  207. *
  208. * @param excontext eXosip_t instance.
  209. * @param tid transction id of transaction.
  210. */
  211. sdp_message_t *eXosip_get_local_sdp_from_tid(struct eXosip_t *excontext, int tid);
  212. /**
  213. * Get local SDP body for the given message.
  214. *
  215. * @param message message containing the SDP.
  216. */
  217. sdp_message_t *eXosip_get_sdp_info(osip_message_t *message);
  218. /**
  219. * Get audio connection information for call.
  220. *
  221. * @param sdp sdp information.
  222. */
  223. sdp_connection_t *eXosip_get_audio_connection(sdp_message_t *sdp);
  224. /**
  225. * Get audio media information for call.
  226. *
  227. * @param sdp sdp information.
  228. */
  229. sdp_media_t *eXosip_get_audio_media(sdp_message_t *sdp);
  230. /**
  231. * Get video connection information for call.
  232. *
  233. * @param sdp sdp information.
  234. */
  235. sdp_connection_t *eXosip_get_video_connection(sdp_message_t *sdp);
  236. /**
  237. * Get video media information for call.
  238. *
  239. * @param sdp sdp information.
  240. */
  241. sdp_media_t *eXosip_get_video_media(sdp_message_t *sdp);
  242. /**
  243. * Get media connection information for call.
  244. *
  245. * @param sdp sdp information.
  246. * @param media media to search.
  247. */
  248. sdp_connection_t *eXosip_get_connection(sdp_message_t *sdp, const char *media);
  249. /**
  250. * Get media information for call.
  251. *
  252. * @param sdp sdp information.
  253. * @param media media to search.
  254. */
  255. sdp_media_t *eXosip_get_media(sdp_message_t *sdp, const char *media);
  256. /** @} */
  257. /**
  258. * @defgroup eXosip2_event eXosip2 event API
  259. * @ingroup eXosip2_setup
  260. * @{
  261. */
  262. /**
  263. * Structure for event type description
  264. * @var eXosip_event_type
  265. */
  266. typedef enum eXosip_event_type {
  267. /* REGISTER related events */
  268. EXOSIP_REGISTRATION_SUCCESS, /**< user is successfully registred. */
  269. EXOSIP_REGISTRATION_FAILURE, /**< user is not registred. */
  270. /* INVITE related events within calls */
  271. EXOSIP_CALL_INVITE, /**< announce a new call */
  272. EXOSIP_CALL_REINVITE, /**< announce a new INVITE within call */
  273. EXOSIP_CALL_NOANSWER, /**< announce no answer within the timeout */
  274. EXOSIP_CALL_PROCEEDING, /**< announce processing by a remote app */
  275. EXOSIP_CALL_RINGING, /**< announce ringback */
  276. EXOSIP_CALL_ANSWERED, /**< announce start of call */
  277. EXOSIP_CALL_REDIRECTED, /**< announce a redirection */
  278. EXOSIP_CALL_REQUESTFAILURE, /**< announce a request failure */
  279. EXOSIP_CALL_SERVERFAILURE, /**< announce a server failure */
  280. EXOSIP_CALL_GLOBALFAILURE, /**< announce a global failure */
  281. EXOSIP_CALL_ACK, /**< ACK received for 200ok to INVITE */
  282. EXOSIP_CALL_CANCELLED, /**< announce that call has been cancelled */
  283. /* request related events within calls (except INVITE) */
  284. EXOSIP_CALL_MESSAGE_NEW, /**< announce new incoming request. */
  285. EXOSIP_CALL_MESSAGE_PROCEEDING, /**< announce a 1xx for request. */
  286. EXOSIP_CALL_MESSAGE_ANSWERED, /**< announce a 200ok */
  287. EXOSIP_CALL_MESSAGE_REDIRECTED, /**< announce a failure. */
  288. EXOSIP_CALL_MESSAGE_REQUESTFAILURE, /**< announce a failure. */
  289. EXOSIP_CALL_MESSAGE_SERVERFAILURE, /**< announce a failure. */
  290. EXOSIP_CALL_MESSAGE_GLOBALFAILURE, /**< announce a failure. */
  291. EXOSIP_CALL_CLOSED, /**< a BYE was received for this call */
  292. /* for both UAS & UAC events */
  293. EXOSIP_CALL_RELEASED, /**< call context is cleared. */
  294. /* events received for request outside calls */
  295. EXOSIP_MESSAGE_NEW, /**< announce new incoming request. */
  296. EXOSIP_MESSAGE_PROCEEDING, /**< announce a 1xx for request. */
  297. EXOSIP_MESSAGE_ANSWERED, /**< announce a 200ok */
  298. EXOSIP_MESSAGE_REDIRECTED, /**< announce a failure. */
  299. EXOSIP_MESSAGE_REQUESTFAILURE, /**< announce a failure. */
  300. EXOSIP_MESSAGE_SERVERFAILURE, /**< announce a failure. */
  301. EXOSIP_MESSAGE_GLOBALFAILURE, /**< announce a failure. */
  302. /* Presence and Instant Messaging */
  303. EXOSIP_SUBSCRIPTION_NOANSWER, /**< announce no answer */
  304. EXOSIP_SUBSCRIPTION_PROCEEDING, /**< announce a 1xx */
  305. EXOSIP_SUBSCRIPTION_ANSWERED, /**< announce a 200ok */
  306. EXOSIP_SUBSCRIPTION_REDIRECTED, /**< announce a redirection */
  307. EXOSIP_SUBSCRIPTION_REQUESTFAILURE, /**< announce a request failure */
  308. EXOSIP_SUBSCRIPTION_SERVERFAILURE, /**< announce a server failure */
  309. EXOSIP_SUBSCRIPTION_GLOBALFAILURE, /**< announce a global failure */
  310. EXOSIP_SUBSCRIPTION_NOTIFY, /**< announce new NOTIFY request */
  311. EXOSIP_IN_SUBSCRIPTION_NEW, /**< announce new incoming SUBSCRIBE/REFER.*/
  312. EXOSIP_NOTIFICATION_NOANSWER, /**< announce no answer */
  313. EXOSIP_NOTIFICATION_PROCEEDING, /**< announce a 1xx */
  314. EXOSIP_NOTIFICATION_ANSWERED, /**< announce a 200ok */
  315. EXOSIP_NOTIFICATION_REDIRECTED, /**< announce a redirection */
  316. EXOSIP_NOTIFICATION_REQUESTFAILURE, /**< announce a request failure */
  317. EXOSIP_NOTIFICATION_SERVERFAILURE, /**< announce a server failure */
  318. EXOSIP_NOTIFICATION_GLOBALFAILURE, /**< announce a global failure */
  319. EXOSIP_EVENT_COUNT /**< MAX number of events */
  320. } eXosip_event_type_t;
  321. /**
  322. * Structure for event description
  323. * @struct eXosip_event
  324. */
  325. struct eXosip_event {
  326. eXosip_event_type_t type; /**< type of the event */
  327. char textinfo[256]; /**< text description of event */
  328. void *external_reference; /**< external reference (for calls) */
  329. osip_message_t *request; /**< request within current transaction */
  330. osip_message_t *response; /**< last response within current transaction */
  331. osip_message_t *ack; /**< ack within current transaction */
  332. int tid; /**< unique id for transactions (to be used for answers) */
  333. int did; /**< unique id for SIP dialogs */
  334. int rid; /**< unique id for registration */
  335. int cid; /**< unique id for SIP calls (but multiple dialogs!) */
  336. int sid; /**< unique id for outgoing subscriptions */
  337. int nid; /**< unique id for incoming subscriptions */
  338. int ss_status; /**< current Subscription-State for subscription */
  339. int ss_reason; /**< current Reason status for subscription */
  340. };
  341. /**
  342. * Free ressource in an eXosip event.
  343. *
  344. * @param je event to work on.
  345. */
  346. void eXosip_event_free(eXosip_event_t *je);
  347. /**
  348. * Wait for an eXosip event.
  349. *
  350. * @param excontext eXosip_t instance.
  351. * @param tv_s timeout value (seconds).
  352. * @param tv_ms timeout value (mseconds).
  353. */
  354. eXosip_event_t *eXosip_event_wait(struct eXosip_t *excontext, int tv_s, int tv_ms);
  355. /**
  356. * Wait for next eXosip event.
  357. * **DEPRECATED API**
  358. * This API will block - You should use eXosip_event_wait instead which is more convenient.
  359. * limitation: This method will not process automatic 200ok retransmission for INVITE transaction.
  360. *
  361. * @param excontext eXosip_t instance.
  362. */
  363. eXosip_event_t *eXosip_event_get(struct eXosip_t *excontext);
  364. /**
  365. * This socket receive some data yhen an event happens internally.
  366. * NOTE: you must call eXosip_event_wait until there is no more events
  367. * in the fifo.
  368. *
  369. * @param excontext eXosip_t instance.
  370. */
  371. int eXosip_event_geteventsocket(struct eXosip_t *excontext);
  372. /** @} */
  373. #ifdef __cplusplus
  374. }
  375. #endif
  376. #endif