res_pjsip.h 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef _RES_PJSIP_H
  19. #define _RES_PJSIP_H
  20. #include <pjsip.h>
  21. /* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */
  22. #include <pjsip_simple.h>
  23. #include <pjsip/sip_transaction.h>
  24. #include <pj/timer.h>
  25. /* Needed for pj_sockaddr */
  26. #include <pjlib.h>
  27. #include "asterisk/stringfields.h"
  28. /* Needed for struct ast_sockaddr */
  29. #include "asterisk/netsock2.h"
  30. /* Needed for linked list macros */
  31. #include "asterisk/linkedlists.h"
  32. /* Needed for ast_party_id */
  33. #include "asterisk/channel.h"
  34. /* Needed for ast_sorcery */
  35. #include "asterisk/sorcery.h"
  36. /* Needed for ast_dnsmgr */
  37. #include "asterisk/dnsmgr.h"
  38. /* Needed for ast_endpoint */
  39. #include "asterisk/endpoints.h"
  40. /* Needed for ast_t38_ec_modes */
  41. #include "asterisk/udptl.h"
  42. /* Needed for ast_rtp_dtls_cfg struct */
  43. #include "asterisk/rtp_engine.h"
  44. /* Needed for AST_VECTOR macro */
  45. #include "asterisk/vector.h"
  46. /* Needed for ast_sip_for_each_channel_snapshot struct */
  47. #include "asterisk/stasis_channels.h"
  48. #include "asterisk/stasis_endpoints.h"
  49. /* Forward declarations of PJSIP stuff */
  50. struct pjsip_rx_data;
  51. struct pjsip_module;
  52. struct pjsip_tx_data;
  53. struct pjsip_dialog;
  54. struct pjsip_transport;
  55. struct pjsip_tpfactory;
  56. struct pjsip_tls_setting;
  57. struct pjsip_tpselector;
  58. /*! \brief Maximum number of ciphers supported for a TLS transport */
  59. #define SIP_TLS_MAX_CIPHERS 64
  60. /*!
  61. * \brief Structure for SIP transport information
  62. */
  63. struct ast_sip_transport_state {
  64. /*! \brief Transport itself */
  65. struct pjsip_transport *transport;
  66. /*! \brief Transport factory */
  67. struct pjsip_tpfactory *factory;
  68. /*!
  69. * Transport id
  70. * \since 13.8.0
  71. */
  72. char *id;
  73. /*!
  74. * Transport type
  75. * \since 13.8.0
  76. */
  77. enum ast_transport type;
  78. /*!
  79. * Address and port to bind to
  80. * \since 13.8.0
  81. */
  82. pj_sockaddr host;
  83. /*!
  84. * TLS settings
  85. * \since 13.8.0
  86. */
  87. pjsip_tls_setting tls;
  88. /*!
  89. * Configured TLS ciphers
  90. * \since 13.8.0
  91. */
  92. pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS];
  93. /*!
  94. * Optional local network information, used for NAT purposes.
  95. * "deny" (set) means that it's in the local network. Use the
  96. * ast_sip_transport_is_nonlocal and ast_sip_transport_is_local
  97. * macro's.
  98. * \since 13.8.0
  99. */
  100. struct ast_ha *localnet;
  101. /*!
  102. * DNS manager for refreshing the external signaling address
  103. * \since 13.8.0
  104. */
  105. struct ast_dnsmgr_entry *external_signaling_address_refresher;
  106. /*!
  107. * Optional external signaling address information
  108. * \since 13.8.0
  109. */
  110. struct ast_sockaddr external_signaling_address;
  111. /*!
  112. * DNS manager for refreshing the external media address
  113. * \since 13.18.0
  114. */
  115. struct ast_dnsmgr_entry *external_media_address_refresher;
  116. /*!
  117. * Optional external signaling address information
  118. * \since 13.18.0
  119. */
  120. struct ast_sockaddr external_media_address;
  121. };
  122. #define ast_sip_transport_is_nonlocal(transport_state, addr) \
  123. (!transport_state->localnet || ast_apply_ha(transport_state->localnet, addr) == AST_SENSE_ALLOW)
  124. #define ast_sip_transport_is_local(transport_state, addr) \
  125. (transport_state->localnet && ast_apply_ha(transport_state->localnet, addr) != AST_SENSE_ALLOW)
  126. /*!
  127. * \brief Transport to bind to
  128. */
  129. struct ast_sip_transport {
  130. /*! Sorcery object details */
  131. SORCERY_OBJECT(details);
  132. AST_DECLARE_STRING_FIELDS(
  133. /*! Certificate of authority list file */
  134. AST_STRING_FIELD(ca_list_file);
  135. /*! Certificate of authority list path */
  136. AST_STRING_FIELD(ca_list_path);
  137. /*! Public certificate file */
  138. AST_STRING_FIELD(cert_file);
  139. /*! Optional private key of the certificate file */
  140. AST_STRING_FIELD(privkey_file);
  141. /*! Password to open the private key */
  142. AST_STRING_FIELD(password);
  143. /*! External signaling address */
  144. AST_STRING_FIELD(external_signaling_address);
  145. /*! External media address */
  146. AST_STRING_FIELD(external_media_address);
  147. /*! Optional domain to use for messages if provided could not be found */
  148. AST_STRING_FIELD(domain);
  149. );
  150. /*! Type of transport */
  151. enum ast_transport type;
  152. /*!
  153. * \deprecated Moved to ast_sip_transport_state
  154. * \version 13.8.0 deprecated
  155. * Address and port to bind to
  156. */
  157. pj_sockaddr host;
  158. /*! Number of simultaneous asynchronous operations */
  159. unsigned int async_operations;
  160. /*! Optional external port for signaling */
  161. unsigned int external_signaling_port;
  162. /*!
  163. * \deprecated Moved to ast_sip_transport_state
  164. * \version 13.7.1 deprecated
  165. * TLS settings
  166. */
  167. pjsip_tls_setting tls;
  168. /*!
  169. * \deprecated Moved to ast_sip_transport_state
  170. * \version 13.7.1 deprecated
  171. * Configured TLS ciphers
  172. */
  173. pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS];
  174. /*!
  175. * \deprecated Moved to ast_sip_transport_state
  176. * \version 13.7.1 deprecated
  177. * Optional local network information, used for NAT purposes
  178. */
  179. struct ast_ha *localnet;
  180. /*!
  181. * \deprecated Moved to ast_sip_transport_state
  182. * \version 13.7.1 deprecated
  183. * DNS manager for refreshing the external address
  184. */
  185. struct ast_dnsmgr_entry *external_address_refresher;
  186. /*!
  187. * \deprecated Moved to ast_sip_transport_state
  188. * \version 13.7.1 deprecated
  189. * Optional external address information
  190. */
  191. struct ast_sockaddr external_address;
  192. /*!
  193. * \deprecated
  194. * \version 13.7.1 deprecated
  195. * Transport state information
  196. */
  197. struct ast_sip_transport_state *state;
  198. /*! QOS DSCP TOS bits */
  199. unsigned int tos;
  200. /*! QOS COS value */
  201. unsigned int cos;
  202. /*! Write timeout */
  203. int write_timeout;
  204. /*! Allow reload */
  205. int allow_reload;
  206. /*! Automatically send requests out the same transport requests have come in on */
  207. int symmetric_transport;
  208. };
  209. #define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias"
  210. /*!
  211. * Details about a SIP domain alias
  212. */
  213. struct ast_sip_domain_alias {
  214. /*! Sorcery object details */
  215. SORCERY_OBJECT(details);
  216. AST_DECLARE_STRING_FIELDS(
  217. /*! Domain to be aliased to */
  218. AST_STRING_FIELD(domain);
  219. );
  220. };
  221. /*!
  222. * \brief Structure for SIP nat hook information
  223. */
  224. struct ast_sip_nat_hook {
  225. /*! Sorcery object details */
  226. SORCERY_OBJECT(details);
  227. /*! Callback for when a message is going outside of our local network */
  228. void (*outgoing_external_message)(struct pjsip_tx_data *tdata, struct ast_sip_transport *transport);
  229. };
  230. /*!
  231. * \brief Contact associated with an address of record
  232. */
  233. struct ast_sip_contact {
  234. /*! Sorcery object details, the id is the aor name plus a random string */
  235. SORCERY_OBJECT(details);
  236. AST_DECLARE_STRING_FIELDS(
  237. /*! Full URI of the contact */
  238. AST_STRING_FIELD(uri);
  239. /*! Outbound proxy to use for qualify */
  240. AST_STRING_FIELD(outbound_proxy);
  241. /*! Path information to place in Route headers */
  242. AST_STRING_FIELD(path);
  243. /*! Content of the User-Agent header in REGISTER request */
  244. AST_STRING_FIELD(user_agent);
  245. );
  246. /*! Absolute time that this contact is no longer valid after */
  247. struct timeval expiration_time;
  248. /*! Frequency to send OPTIONS requests to contact. 0 is disabled. */
  249. unsigned int qualify_frequency;
  250. /*! If true authenticate the qualify challenge response if needed */
  251. int authenticate_qualify;
  252. /*! Qualify timeout. 0 is diabled. */
  253. double qualify_timeout;
  254. /*! Endpoint that added the contact, only available in observers */
  255. struct ast_sip_endpoint *endpoint;
  256. /*! The name of the aor this contact belongs to */
  257. char *aor;
  258. /*! Asterisk Server name */
  259. AST_STRING_FIELD_EXTENDED(reg_server);
  260. /*! IP-address of the Via header in REGISTER request */
  261. AST_STRING_FIELD_EXTENDED(via_addr);
  262. /*! Port of the Via header in REGISTER request */
  263. int via_port;
  264. /*! Content of the Call-ID header in REGISTER request */
  265. AST_STRING_FIELD_EXTENDED(call_id);
  266. /*! The name of the endpoint that added the contact */
  267. AST_STRING_FIELD_EXTENDED(endpoint_name);
  268. /*! If true delete the contact on Asterisk restart/boot */
  269. int prune_on_boot;
  270. };
  271. /*!
  272. * \brief Status type for a contact.
  273. */
  274. enum ast_sip_contact_status_type {
  275. UNAVAILABLE,
  276. AVAILABLE,
  277. UNKNOWN,
  278. CREATED,
  279. REMOVED,
  280. };
  281. /*!
  282. * \brief A contact's status.
  283. *
  284. * \detail Maintains a contact's current status and round trip time
  285. * if available.
  286. */
  287. struct ast_sip_contact_status {
  288. AST_DECLARE_STRING_FIELDS(
  289. /*! The original contact's URI */
  290. AST_STRING_FIELD(uri);
  291. /*! The name of the aor this contact_status belongs to */
  292. AST_STRING_FIELD(aor);
  293. );
  294. /*! The round trip time in microseconds */
  295. int64_t rtt;
  296. /*! Current status for a contact (default - unavailable) */
  297. enum ast_sip_contact_status_type status;
  298. /*! Last status for a contact (default - unavailable) */
  299. enum ast_sip_contact_status_type last_status;
  300. /*! Name of the contact */
  301. char name[0];
  302. };
  303. /*!
  304. * \brief A SIP address of record
  305. */
  306. struct ast_sip_aor {
  307. /*! Sorcery object details, the id is the AOR name */
  308. SORCERY_OBJECT(details);
  309. AST_DECLARE_STRING_FIELDS(
  310. /*! Voicemail boxes for this AOR */
  311. AST_STRING_FIELD(mailboxes);
  312. /*! Outbound proxy for OPTIONS requests */
  313. AST_STRING_FIELD(outbound_proxy);
  314. );
  315. /*! Minimum expiration time */
  316. unsigned int minimum_expiration;
  317. /*! Maximum expiration time */
  318. unsigned int maximum_expiration;
  319. /*! Default contact expiration if one is not provided in the contact */
  320. unsigned int default_expiration;
  321. /*! Frequency to send OPTIONS requests to AOR contacts. 0 is disabled. */
  322. unsigned int qualify_frequency;
  323. /*! If true authenticate the qualify challenge response if needed */
  324. int authenticate_qualify;
  325. /*! Maximum number of external contacts, 0 to disable */
  326. unsigned int max_contacts;
  327. /*! Whether to remove any existing contacts not related to an incoming REGISTER when it comes in */
  328. unsigned int remove_existing;
  329. /*! Any permanent configured contacts */
  330. struct ao2_container *permanent_contacts;
  331. /*! Determines whether SIP Path headers are supported */
  332. unsigned int support_path;
  333. /*! Qualify timeout. 0 is diabled. */
  334. double qualify_timeout;
  335. /*! Voicemail extension to set in Message-Account */
  336. char *voicemail_extension;
  337. };
  338. /*!
  339. * \brief A wrapper for contact that adds the aor_id and
  340. * a consistent contact id. Used by ast_sip_for_each_contact.
  341. */
  342. struct ast_sip_contact_wrapper {
  343. /*! The id of the parent aor. */
  344. char *aor_id;
  345. /*! The id of contact in form of aor_id/contact_uri. */
  346. char *contact_id;
  347. /*! Pointer to the actual contact. */
  348. struct ast_sip_contact *contact;
  349. };
  350. /*!
  351. * \brief DTMF modes for SIP endpoints
  352. */
  353. enum ast_sip_dtmf_mode {
  354. /*! No DTMF to be used */
  355. AST_SIP_DTMF_NONE,
  356. /* XXX Should this be 2833 instead? */
  357. /*! Use RFC 4733 events for DTMF */
  358. AST_SIP_DTMF_RFC_4733,
  359. /*! Use DTMF in the audio stream */
  360. AST_SIP_DTMF_INBAND,
  361. /*! Use SIP INFO DTMF (blech) */
  362. AST_SIP_DTMF_INFO,
  363. /*! Use SIP 4733 if supported by the other side or INBAND if not */
  364. AST_SIP_DTMF_AUTO,
  365. /*! Use SIP 4733 if supported by the other side or INFO DTMF (blech) if not */
  366. AST_SIP_DTMF_AUTO_INFO,
  367. };
  368. /*!
  369. * \brief Methods of storing SIP digest authentication credentials.
  370. *
  371. * Note that both methods result in MD5 digest authentication being
  372. * used. The two methods simply alter how Asterisk determines the
  373. * credentials for a SIP authentication
  374. */
  375. enum ast_sip_auth_type {
  376. /*! Credentials stored as a username and password combination */
  377. AST_SIP_AUTH_TYPE_USER_PASS,
  378. /*! Credentials stored as an MD5 sum */
  379. AST_SIP_AUTH_TYPE_MD5,
  380. /*! Credentials not stored this is a fake auth */
  381. AST_SIP_AUTH_TYPE_ARTIFICIAL
  382. };
  383. #define SIP_SORCERY_AUTH_TYPE "auth"
  384. struct ast_sip_auth {
  385. /*! Sorcery ID of the auth is its name */
  386. SORCERY_OBJECT(details);
  387. AST_DECLARE_STRING_FIELDS(
  388. /*! Identification for these credentials */
  389. AST_STRING_FIELD(realm);
  390. /*! Authentication username */
  391. AST_STRING_FIELD(auth_user);
  392. /*! Authentication password */
  393. AST_STRING_FIELD(auth_pass);
  394. /*! Authentication credentials in MD5 format (hash of user:realm:pass) */
  395. AST_STRING_FIELD(md5_creds);
  396. );
  397. /*! The time period (in seconds) that a nonce may be reused */
  398. unsigned int nonce_lifetime;
  399. /*! Used to determine what to use when authenticating */
  400. enum ast_sip_auth_type type;
  401. };
  402. AST_VECTOR(ast_sip_auth_vector, const char *);
  403. /*!
  404. * \brief Different methods by which incoming requests can be matched to endpoints
  405. */
  406. enum ast_sip_endpoint_identifier_type {
  407. /*! Identify based on user name in From header */
  408. AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME = (1 << 0),
  409. /*! Identify based on user name in Auth header first, then From header */
  410. AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME = (1 << 1),
  411. /*! Identify based on source IP address */
  412. AST_SIP_ENDPOINT_IDENTIFY_BY_IP = (1 << 2),
  413. /*! Identify based on arbitrary headers */
  414. AST_SIP_ENDPOINT_IDENTIFY_BY_HEADER = (1 << 3),
  415. };
  416. AST_VECTOR(ast_sip_identify_by_vector, enum ast_sip_endpoint_identifier_type);
  417. enum ast_sip_session_refresh_method {
  418. /*! Use reinvite to negotiate direct media */
  419. AST_SIP_SESSION_REFRESH_METHOD_INVITE,
  420. /*! Use UPDATE to negotiate direct media */
  421. AST_SIP_SESSION_REFRESH_METHOD_UPDATE,
  422. };
  423. enum ast_sip_direct_media_glare_mitigation {
  424. /*! Take no special action to mitigate reinvite glare */
  425. AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE,
  426. /*! Do not send an initial direct media session refresh on outgoing call legs
  427. * Subsequent session refreshes will be sent no matter the session direction
  428. */
  429. AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING,
  430. /*! Do not send an initial direct media session refresh on incoming call legs
  431. * Subsequent session refreshes will be sent no matter the session direction
  432. */
  433. AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING,
  434. };
  435. enum ast_sip_session_media_encryption {
  436. /*! Invalid media encryption configuration */
  437. AST_SIP_MEDIA_TRANSPORT_INVALID = 0,
  438. /*! Do not allow any encryption of session media */
  439. AST_SIP_MEDIA_ENCRYPT_NONE,
  440. /*! Offer SDES-encrypted session media */
  441. AST_SIP_MEDIA_ENCRYPT_SDES,
  442. /*! Offer encrypted session media with datagram TLS key exchange */
  443. AST_SIP_MEDIA_ENCRYPT_DTLS,
  444. };
  445. enum ast_sip_session_redirect {
  446. /*! User portion of the target URI should be used as the target in the dialplan */
  447. AST_SIP_REDIRECT_USER = 0,
  448. /*! Target URI should be used as the target in the dialplan */
  449. AST_SIP_REDIRECT_URI_CORE,
  450. /*! Target URI should be used as the target within chan_pjsip itself */
  451. AST_SIP_REDIRECT_URI_PJSIP,
  452. };
  453. /*!
  454. * \brief Session timers options
  455. */
  456. struct ast_sip_timer_options {
  457. /*! Minimum session expiration period, in seconds */
  458. unsigned int min_se;
  459. /*! Session expiration period, in seconds */
  460. unsigned int sess_expires;
  461. };
  462. /*!
  463. * \brief Endpoint configuration for SIP extensions.
  464. *
  465. * SIP extensions, in this case refers to features
  466. * indicated in Supported or Required headers.
  467. */
  468. struct ast_sip_endpoint_extensions {
  469. /*! Enabled SIP extensions */
  470. unsigned int flags;
  471. /*! Timer options */
  472. struct ast_sip_timer_options timer;
  473. };
  474. /*!
  475. * \brief Endpoint configuration for unsolicited MWI
  476. */
  477. struct ast_sip_mwi_configuration {
  478. AST_DECLARE_STRING_FIELDS(
  479. /*! Configured voicemail boxes for this endpoint. Used for MWI */
  480. AST_STRING_FIELD(mailboxes);
  481. /*! Username to use when sending MWI NOTIFYs to this endpoint */
  482. AST_STRING_FIELD(fromuser);
  483. );
  484. /*! Should mailbox states be combined into a single notification? */
  485. unsigned int aggregate;
  486. /*! Should a subscribe replace unsolicited notifies? */
  487. unsigned int subscribe_replaces_unsolicited;
  488. /*! Voicemail extension to set in Message-Account */
  489. char *voicemail_extension;
  490. };
  491. /*!
  492. * \brief Endpoint subscription configuration
  493. */
  494. struct ast_sip_endpoint_subscription_configuration {
  495. /*! Indicates if endpoint is allowed to initiate subscriptions */
  496. unsigned int allow;
  497. /*! The minimum allowed expiration for subscriptions from endpoint */
  498. unsigned int minexpiry;
  499. /*! Message waiting configuration */
  500. struct ast_sip_mwi_configuration mwi;
  501. /*! Context for SUBSCRIBE requests */
  502. char context[AST_MAX_CONTEXT];
  503. };
  504. /*!
  505. * \brief NAT configuration options for endpoints
  506. */
  507. struct ast_sip_endpoint_nat_configuration {
  508. /*! Whether to force using the source IP address/port for sending responses */
  509. unsigned int force_rport;
  510. /*! Whether to rewrite the Contact header with the source IP address/port or not */
  511. unsigned int rewrite_contact;
  512. };
  513. /*!
  514. * \brief Party identification options for endpoints
  515. *
  516. * This includes caller ID, connected line, and redirecting-related options
  517. */
  518. struct ast_sip_endpoint_id_configuration {
  519. struct ast_party_id self;
  520. /*! Do we accept identification information from this endpoint */
  521. unsigned int trust_inbound;
  522. /*! Do we send private identification information to this endpoint? */
  523. unsigned int trust_outbound;
  524. /*! Do we send P-Asserted-Identity headers to this endpoint? */
  525. unsigned int send_pai;
  526. /*! Do we send Remote-Party-ID headers to this endpoint? */
  527. unsigned int send_rpid;
  528. /*! Do we add Diversion headers to applicable outgoing requests/responses? */
  529. unsigned int send_diversion;
  530. /*! When performing connected line update, which method should be used */
  531. enum ast_sip_session_refresh_method refresh_method;
  532. };
  533. /*!
  534. * \brief Call pickup configuration options for endpoints
  535. */
  536. struct ast_sip_endpoint_pickup_configuration {
  537. /*! Call group */
  538. ast_group_t callgroup;
  539. /*! Pickup group */
  540. ast_group_t pickupgroup;
  541. /*! Named call group */
  542. struct ast_namedgroups *named_callgroups;
  543. /*! Named pickup group */
  544. struct ast_namedgroups *named_pickupgroups;
  545. };
  546. /*!
  547. * \brief Configuration for one-touch INFO recording
  548. */
  549. struct ast_sip_info_recording_configuration {
  550. AST_DECLARE_STRING_FIELDS(
  551. /*! Feature to enact when one-touch recording INFO with Record: On is received */
  552. AST_STRING_FIELD(onfeature);
  553. /*! Feature to enact when one-touch recording INFO with Record: Off is received */
  554. AST_STRING_FIELD(offfeature);
  555. );
  556. /*! Is one-touch recording permitted? */
  557. unsigned int enabled;
  558. };
  559. /*!
  560. * \brief Endpoint configuration options for INFO packages
  561. */
  562. struct ast_sip_endpoint_info_configuration {
  563. /*! Configuration for one-touch recording */
  564. struct ast_sip_info_recording_configuration recording;
  565. };
  566. /*!
  567. * \brief RTP configuration for SIP endpoints
  568. */
  569. struct ast_sip_media_rtp_configuration {
  570. AST_DECLARE_STRING_FIELDS(
  571. /*! Configured RTP engine for this endpoint. */
  572. AST_STRING_FIELD(engine);
  573. );
  574. /*! Whether IPv6 RTP is enabled or not */
  575. unsigned int ipv6;
  576. /*! Whether symmetric RTP is enabled or not */
  577. unsigned int symmetric;
  578. /*! Whether ICE support is enabled or not */
  579. unsigned int ice_support;
  580. /*! Whether to use the "ptime" attribute received from the endpoint or not */
  581. unsigned int use_ptime;
  582. /*! Do we use AVPF exclusively for this endpoint? */
  583. unsigned int use_avpf;
  584. /*! Do we force AVP, AVPF, SAVP, or SAVPF even for DTLS media streams? */
  585. unsigned int force_avp;
  586. /*! Do we use the received media transport in our answer SDP */
  587. unsigned int use_received_transport;
  588. /*! \brief DTLS-SRTP configuration information */
  589. struct ast_rtp_dtls_cfg dtls_cfg;
  590. /*! Should SRTP use a 32 byte tag instead of an 80 byte tag? */
  591. unsigned int srtp_tag_32;
  592. /*! Do we use media encryption? what type? */
  593. enum ast_sip_session_media_encryption encryption;
  594. /*! Do we want to optimistically support encryption if possible? */
  595. unsigned int encryption_optimistic;
  596. /*! Number of seconds between RTP keepalive packets */
  597. unsigned int keepalive;
  598. /*! Number of seconds before terminating channel due to lack of RTP (when not on hold) */
  599. unsigned int timeout;
  600. /*! Number of seconds before terminating channel due to lack of RTP (when on hold) */
  601. unsigned int timeout_hold;
  602. };
  603. /*!
  604. * \brief Direct media options for SIP endpoints
  605. */
  606. struct ast_sip_direct_media_configuration {
  607. /*! Boolean indicating if direct_media is permissible */
  608. unsigned int enabled;
  609. /*! When using direct media, which method should be used */
  610. enum ast_sip_session_refresh_method method;
  611. /*! Take steps to mitigate glare for direct media */
  612. enum ast_sip_direct_media_glare_mitigation glare_mitigation;
  613. /*! Do not attempt direct media session refreshes if a media NAT is detected */
  614. unsigned int disable_on_nat;
  615. };
  616. struct ast_sip_t38_configuration {
  617. /*! Whether T.38 UDPTL support is enabled or not */
  618. unsigned int enabled;
  619. /*! Error correction setting for T.38 UDPTL */
  620. enum ast_t38_ec_modes error_correction;
  621. /*! Explicit T.38 max datagram value, may be 0 to indicate the remote side can be trusted */
  622. unsigned int maxdatagram;
  623. /*! Whether NAT Support is enabled for T.38 UDPTL sessions or not */
  624. unsigned int nat;
  625. /*! Whether to use IPv6 for UDPTL or not */
  626. unsigned int ipv6;
  627. };
  628. /*!
  629. * \brief Media configuration for SIP endpoints
  630. */
  631. struct ast_sip_endpoint_media_configuration {
  632. AST_DECLARE_STRING_FIELDS(
  633. /*! Optional media address to use in SDP */
  634. AST_STRING_FIELD(address);
  635. /*! SDP origin username */
  636. AST_STRING_FIELD(sdpowner);
  637. /*! SDP session name */
  638. AST_STRING_FIELD(sdpsession);
  639. );
  640. /*! RTP media configuration */
  641. struct ast_sip_media_rtp_configuration rtp;
  642. /*! Direct media options */
  643. struct ast_sip_direct_media_configuration direct_media;
  644. /*! T.38 (FoIP) options */
  645. struct ast_sip_t38_configuration t38;
  646. /*! Configured codecs */
  647. struct ast_format_cap *codecs;
  648. /*! DSCP TOS bits for audio streams */
  649. unsigned int tos_audio;
  650. /*! Priority for audio streams */
  651. unsigned int cos_audio;
  652. /*! DSCP TOS bits for video streams */
  653. unsigned int tos_video;
  654. /*! Priority for video streams */
  655. unsigned int cos_video;
  656. /*! Is g.726 packed in a non standard way */
  657. unsigned int g726_non_standard;
  658. /*! Bind the RTP instance to the media_address */
  659. unsigned int bind_rtp_to_media_address;
  660. };
  661. /*!
  662. * \brief An entity with which Asterisk communicates
  663. */
  664. struct ast_sip_endpoint {
  665. SORCERY_OBJECT(details);
  666. AST_DECLARE_STRING_FIELDS(
  667. /*! Context to send incoming calls to */
  668. AST_STRING_FIELD(context);
  669. /*! Name of an explicit transport to use */
  670. AST_STRING_FIELD(transport);
  671. /*! Outbound proxy to use */
  672. AST_STRING_FIELD(outbound_proxy);
  673. /*! Explicit AORs to dial if none are specified */
  674. AST_STRING_FIELD(aors);
  675. /*! Musiconhold class to suggest that the other side use when placing on hold */
  676. AST_STRING_FIELD(mohsuggest);
  677. /*! Configured tone zone for this endpoint. */
  678. AST_STRING_FIELD(zone);
  679. /*! Configured language for this endpoint. */
  680. AST_STRING_FIELD(language);
  681. /*! Default username to place in From header */
  682. AST_STRING_FIELD(fromuser);
  683. /*! Domain to place in From header */
  684. AST_STRING_FIELD(fromdomain);
  685. /*! Context to route incoming MESSAGE requests to */
  686. AST_STRING_FIELD(message_context);
  687. /*! Accountcode to auto-set on channels */
  688. AST_STRING_FIELD(accountcode);
  689. );
  690. /*! Configuration for extensions */
  691. struct ast_sip_endpoint_extensions extensions;
  692. /*! Configuration relating to media */
  693. struct ast_sip_endpoint_media_configuration media;
  694. /*! SUBSCRIBE/NOTIFY configuration options */
  695. struct ast_sip_endpoint_subscription_configuration subscription;
  696. /*! NAT configuration */
  697. struct ast_sip_endpoint_nat_configuration nat;
  698. /*! Party identification options */
  699. struct ast_sip_endpoint_id_configuration id;
  700. /*! Configuration options for INFO packages */
  701. struct ast_sip_endpoint_info_configuration info;
  702. /*! Call pickup configuration */
  703. struct ast_sip_endpoint_pickup_configuration pickup;
  704. /*! Inbound authentication credentials */
  705. struct ast_sip_auth_vector inbound_auths;
  706. /*! Outbound authentication credentials */
  707. struct ast_sip_auth_vector outbound_auths;
  708. /*! DTMF mode to use with this endpoint */
  709. enum ast_sip_dtmf_mode dtmf;
  710. /*! Method(s) by which the endpoint should be identified. */
  711. enum ast_sip_endpoint_identifier_type ident_method;
  712. /*! Order of the method(s) by which the endpoint should be identified. */
  713. struct ast_sip_identify_by_vector ident_method_order;
  714. /*! Boolean indicating if ringing should be sent as inband progress */
  715. unsigned int inband_progress;
  716. /*! Pointer to the persistent Asterisk endpoint */
  717. struct ast_endpoint *persistent;
  718. /*! The number of channels at which busy device state is returned */
  719. unsigned int devicestate_busy_at;
  720. /*! Whether fax detection is enabled or not (CNG tone detection) */
  721. unsigned int faxdetect;
  722. /*! Determines if transfers (using REFER) are allowed by this endpoint */
  723. unsigned int allowtransfer;
  724. /*! Method used when handling redirects */
  725. enum ast_sip_session_redirect redirect_method;
  726. /*! Variables set on channel creation */
  727. struct ast_variable *channel_vars;
  728. /*! Whether to place a 'user=phone' parameter into the request URI if user is a number */
  729. unsigned int usereqphone;
  730. /*! Do we send messages for connected line updates for unanswered incoming calls immediately to this endpoint? */
  731. unsigned int rpid_immediate;
  732. /*! Access control list */
  733. struct ast_acl_list *acl;
  734. /*! Restrict what IPs are allowed in the Contact header (for registration) */
  735. struct ast_acl_list *contact_acl;
  736. /*! The number of seconds into call to disable fax detection. (0 = disabled) */
  737. unsigned int faxdetect_timeout;
  738. /*! Override the user on the outgoing Contact header with this value. */
  739. char *contact_user;
  740. /*! Do we allow an asymmetric RTP codec? */
  741. unsigned int asymmetric_rtp_codec;
  742. /*! Use RTCP-MUX */
  743. unsigned int rtcp_mux;
  744. /*! Do we allow overlap dialling? */
  745. unsigned int allow_overlap;
  746. /*! Whether to notifies all the progress details on blind transfer */
  747. unsigned int refer_blind_progress;
  748. /*! Whether to notifies dialog-info 'early' on INUSE && RINGING state */
  749. unsigned int notify_early_inuse_ringing;
  750. /*! If set, we'll push incoming MWI NOTIFYs to stasis using this mailbox */
  751. AST_STRING_FIELD_EXTENDED(incoming_mwi_mailbox);
  752. /*! Follow forked media with a different To tag */
  753. unsigned int follow_early_media_fork;
  754. /*! Accept updated SDPs on non-100rel 18X and 2XX responses with the same To tag */
  755. unsigned int accept_multiple_sdp_answers;
  756. /*! Suppress Q.850 Reason headers on this endpoint */
  757. unsigned int suppress_q850_reason_headers;
  758. /*! Do we accept connected line updates from this endpoint? */
  759. unsigned int trust_connected_line;
  760. /*! Do we send connected line updates to this endpoint? */
  761. unsigned int send_connected_line;
  762. };
  763. /*! URI parameter for symmetric transport */
  764. #define AST_SIP_X_AST_TXP "x-ast-txp"
  765. #define AST_SIP_X_AST_TXP_LEN 9
  766. /*!
  767. * \brief Initialize an auth vector with the configured values.
  768. *
  769. * \param vector Vector to initialize
  770. * \param auth_names Comma-separated list of names to set in the array
  771. * \retval 0 Success
  772. * \retval non-zero Failure
  773. */
  774. int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names);
  775. /*!
  776. * \brief Free contents of an auth vector.
  777. *
  778. * \param array Vector whose contents are to be freed
  779. */
  780. void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector);
  781. /*!
  782. * \brief Possible returns from ast_sip_check_authentication
  783. */
  784. enum ast_sip_check_auth_result {
  785. /*! Authentication needs to be challenged */
  786. AST_SIP_AUTHENTICATION_CHALLENGE,
  787. /*! Authentication succeeded */
  788. AST_SIP_AUTHENTICATION_SUCCESS,
  789. /*! Authentication failed */
  790. AST_SIP_AUTHENTICATION_FAILED,
  791. /*! Authentication encountered some internal error */
  792. AST_SIP_AUTHENTICATION_ERROR,
  793. };
  794. /*!
  795. * \brief An interchangeable way of handling digest authentication for SIP.
  796. *
  797. * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available
  798. * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication
  799. * should take place and what credentials should be used when challenging and authenticating a request.
  800. */
  801. struct ast_sip_authenticator {
  802. /*!
  803. * \brief Check if a request requires authentication
  804. * See ast_sip_requires_authentication for more details
  805. */
  806. int (*requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
  807. /*!
  808. * \brief Check that an incoming request passes authentication.
  809. *
  810. * The tdata parameter is useful for adding information such as digest challenges.
  811. *
  812. * \param endpoint The endpoint sending the incoming request
  813. * \param rdata The incoming request
  814. * \param tdata Tentative outgoing request.
  815. */
  816. enum ast_sip_check_auth_result (*check_authentication)(struct ast_sip_endpoint *endpoint,
  817. pjsip_rx_data *rdata, pjsip_tx_data *tdata);
  818. };
  819. /*!
  820. * \brief an interchangeable way of responding to authentication challenges
  821. *
  822. * An outbound authenticator takes incoming challenges and formulates a new SIP request with
  823. * credentials.
  824. */
  825. struct ast_sip_outbound_authenticator {
  826. /*!
  827. * \brief Create a new request with authentication credentials
  828. *
  829. * \param auths A vector of IDs of auth sorcery objects
  830. * \param challenge The SIP response with authentication challenge(s)
  831. * \param tsx The transaction in which the challenge was received
  832. * \param new_request The new SIP request with challenge response(s)
  833. * \retval 0 Successfully created new request
  834. * \retval -1 Failed to create a new request
  835. */
  836. int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
  837. struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
  838. /*!
  839. * \brief Create a new request with authentication credentials based on old request
  840. *
  841. * \param auths A vector of IDs of auth sorcery objects
  842. * \param challenge The SIP response with authentication challenge(s)
  843. * \param old_request The request that resulted in challenge(s)
  844. * \param new_request The new SIP request with challenge response(s)
  845. * \retval 0 Successfully created new request
  846. * \retval -1 Failed to create a new request
  847. */
  848. int (*create_request_with_auth_from_old)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
  849. struct pjsip_tx_data *old_request, struct pjsip_tx_data **new_request);
  850. };
  851. /*!
  852. * \brief An entity responsible for identifying the source of a SIP message
  853. */
  854. struct ast_sip_endpoint_identifier {
  855. /*!
  856. * \brief Callback used to identify the source of a message.
  857. * See ast_sip_identify_endpoint for more details
  858. */
  859. struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata);
  860. };
  861. /*!
  862. * \brief Contact retrieval filtering flags
  863. */
  864. enum ast_sip_contact_filter {
  865. /*! \brief Default filter flags */
  866. AST_SIP_CONTACT_FILTER_DEFAULT = 0,
  867. /*! \brief Return only reachable or unknown contacts */
  868. AST_SIP_CONTACT_FILTER_REACHABLE = (1 << 0),
  869. };
  870. /*!
  871. * \brief Register a SIP service in Asterisk.
  872. *
  873. * This is more-or-less a wrapper around pjsip_endpt_register_module().
  874. * Registering a service makes it so that PJSIP will call into the
  875. * service at appropriate times. For more information about PJSIP module
  876. * callbacks, see the PJSIP documentation. Asterisk modules that call
  877. * this function will likely do so at module load time.
  878. *
  879. * \param module The module that is to be registered with PJSIP
  880. * \retval 0 Success
  881. * \retval -1 Failure
  882. */
  883. int ast_sip_register_service(pjsip_module *module);
  884. /*!
  885. * This is the opposite of ast_sip_register_service(). Unregistering a
  886. * service means that PJSIP will no longer call into the module any more.
  887. * This will likely occur when an Asterisk module is unloaded.
  888. *
  889. * \param module The PJSIP module to unregister
  890. */
  891. void ast_sip_unregister_service(pjsip_module *module);
  892. /*!
  893. * \brief Register a SIP authenticator
  894. *
  895. * An authenticator has three main purposes:
  896. * 1) Determining if authentication should be performed on an incoming request
  897. * 2) Gathering credentials necessary for issuing an authentication challenge
  898. * 3) Authenticating a request that has credentials
  899. *
  900. * Asterisk provides a default authenticator, but it may be replaced by a
  901. * custom one if desired.
  902. *
  903. * \param auth The authenticator to register
  904. * \retval 0 Success
  905. * \retval -1 Failure
  906. */
  907. int ast_sip_register_authenticator(struct ast_sip_authenticator *auth);
  908. /*!
  909. * \brief Unregister a SIP authenticator
  910. *
  911. * When there is no authenticator registered, requests cannot be challenged
  912. * or authenticated.
  913. *
  914. * \param auth The authenticator to unregister
  915. */
  916. void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth);
  917. /*!
  918. * \brief Register an outbound SIP authenticator
  919. *
  920. * An outbound authenticator is responsible for creating responses to
  921. * authentication challenges by remote endpoints.
  922. *
  923. * \param auth The authenticator to register
  924. * \retval 0 Success
  925. * \retval -1 Failure
  926. */
  927. int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth);
  928. /*!
  929. * \brief Unregister an outbound SIP authenticator
  930. *
  931. * When there is no outbound authenticator registered, authentication challenges
  932. * will be handled as any other final response would be.
  933. *
  934. * \param auth The authenticator to unregister
  935. */
  936. void ast_sip_unregister_outbound_authenticator(struct ast_sip_outbound_authenticator *auth);
  937. /*!
  938. * \brief Register a SIP endpoint identifier with a name.
  939. *
  940. * An endpoint identifier's purpose is to determine which endpoint a given SIP
  941. * message has come from.
  942. *
  943. * Multiple endpoint identifiers may be registered so that if an endpoint
  944. * cannot be identified by one identifier, it may be identified by another.
  945. *
  946. * \param identifier The SIP endpoint identifier to register
  947. * \param name The name of the endpoint identifier
  948. * \retval 0 Success
  949. * \retval -1 Failure
  950. */
  951. int ast_sip_register_endpoint_identifier_with_name(struct ast_sip_endpoint_identifier *identifier,
  952. const char *name);
  953. /*!
  954. * \brief Register a SIP endpoint identifier
  955. *
  956. * An endpoint identifier's purpose is to determine which endpoint a given SIP
  957. * message has come from.
  958. *
  959. * Multiple endpoint identifiers may be registered so that if an endpoint
  960. * cannot be identified by one identifier, it may be identified by another.
  961. *
  962. * Asterisk provides two endpoint identifiers. One identifies endpoints based
  963. * on the user part of the From header URI. The other identifies endpoints based
  964. * on the source IP address.
  965. *
  966. * If the order in which endpoint identifiers is run is important to you, then
  967. * be sure to load individual endpoint identifier modules in the order you wish
  968. * for them to be run in modules.conf
  969. *
  970. * \note endpoint identifiers registered using this method (no name specified)
  971. * are placed at the front of the endpoint identifiers list ahead of any
  972. * named identifiers.
  973. *
  974. * \param identifier The SIP endpoint identifier to register
  975. * \retval 0 Success
  976. * \retval -1 Failure
  977. */
  978. int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier);
  979. /*!
  980. * \brief Unregister a SIP endpoint identifier
  981. *
  982. * This stops an endpoint identifier from being used.
  983. *
  984. * \param identifier The SIP endoint identifier to unregister
  985. */
  986. void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier);
  987. /*!
  988. * \brief Allocate a new SIP endpoint
  989. *
  990. * This will return an endpoint with its refcount increased by one. This reference
  991. * can be released using ao2_ref().
  992. *
  993. * \param name The name of the endpoint.
  994. * \retval NULL Endpoint allocation failed
  995. * \retval non-NULL The newly allocated endpoint
  996. */
  997. void *ast_sip_endpoint_alloc(const char *name);
  998. /*!
  999. * \brief Change state of a persistent endpoint.
  1000. *
  1001. * \param endpoint_name The SIP endpoint name to change state.
  1002. * \param state The new state
  1003. * \retval 0 Success
  1004. * \retval -1 Endpoint not found
  1005. */
  1006. int ast_sip_persistent_endpoint_update_state(const char *endpoint_name, enum ast_endpoint_state state);
  1007. /*!
  1008. * \brief Publish the change of state for a contact.
  1009. *
  1010. * \param endpoint_name The SIP endpoint name.
  1011. * \param contact_status The contact status.
  1012. */
  1013. void ast_sip_persistent_endpoint_publish_contact_state(const char *endpoint_name, const struct ast_sip_contact_status *contact_status);
  1014. /*!
  1015. * \brief Retrieve the current status for a contact.
  1016. *
  1017. * \param contact The contact.
  1018. *
  1019. * \retval non-NULL Success
  1020. * \retval NULL Status information not found
  1021. *
  1022. * \note The returned contact status object is immutable.
  1023. */
  1024. struct ast_sip_contact_status *ast_sip_get_contact_status(const struct ast_sip_contact *contact);
  1025. /*!
  1026. * \brief Get a pointer to the PJSIP endpoint.
  1027. *
  1028. * This is useful when modules have specific information they need
  1029. * to register with the PJSIP core.
  1030. * \retval NULL endpoint has not been created yet.
  1031. * \retval non-NULL PJSIP endpoint.
  1032. */
  1033. pjsip_endpoint *ast_sip_get_pjsip_endpoint(void);
  1034. /*!
  1035. * \brief Get a pointer to the SIP sorcery structure.
  1036. *
  1037. * \retval NULL sorcery has not been initialized
  1038. * \retval non-NULL sorcery structure
  1039. */
  1040. struct ast_sorcery *ast_sip_get_sorcery(void);
  1041. /*!
  1042. * \brief Retrieve a named AOR
  1043. *
  1044. * \param aor_name Name of the AOR
  1045. *
  1046. * \retval NULL if not found
  1047. * \retval non-NULL if found
  1048. */
  1049. struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name);
  1050. /*!
  1051. * \brief Retrieve the first bound contact for an AOR
  1052. *
  1053. * \param aor Pointer to the AOR
  1054. * \retval NULL if no contacts available
  1055. * \retval non-NULL if contacts available
  1056. */
  1057. struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor);
  1058. /*!
  1059. * \brief Retrieve the first bound contact for an AOR and filter based on flags
  1060. * \since 13.16.0
  1061. *
  1062. * \param aor Pointer to the AOR
  1063. * \param flags Filtering flags
  1064. * \retval NULL if no contacts available
  1065. * \retval non-NULL if contacts available
  1066. */
  1067. struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact_filtered(const struct ast_sip_aor *aor,
  1068. unsigned int flags);
  1069. /*!
  1070. * \brief Retrieve all contacts currently available for an AOR
  1071. *
  1072. * \param aor Pointer to the AOR
  1073. *
  1074. * \retval NULL if no contacts available
  1075. * \retval non-NULL if contacts available
  1076. *
  1077. * \warning
  1078. * Since this function prunes expired contacts before returning, it holds a named write
  1079. * lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.
  1080. */
  1081. struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor);
  1082. /*!
  1083. * \brief Retrieve all contacts currently available for an AOR and filter based on flags
  1084. * \since 13.16.0
  1085. *
  1086. * \param aor Pointer to the AOR
  1087. * \param flags Filtering flags
  1088. *
  1089. * \retval NULL if no contacts available
  1090. * \retval non-NULL if contacts available
  1091. *
  1092. * \warning
  1093. * Since this function prunes expired contacts before returning, it holds a named write
  1094. * lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.
  1095. */
  1096. struct ao2_container *ast_sip_location_retrieve_aor_contacts_filtered(const struct ast_sip_aor *aor,
  1097. unsigned int flags);
  1098. /*!
  1099. * \brief Retrieve all contacts currently available for an AOR without locking the AOR
  1100. * \since 13.9.0
  1101. *
  1102. * \param aor Pointer to the AOR
  1103. *
  1104. * \retval NULL if no contacts available
  1105. * \retval non-NULL if contacts available
  1106. *
  1107. * \warning
  1108. * This function should only be called if you already hold a named write lock on the aor.
  1109. */
  1110. struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock(const struct ast_sip_aor *aor);
  1111. /*!
  1112. * \brief Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flags
  1113. * \since 13.16.0
  1114. *
  1115. * \param aor Pointer to the AOR
  1116. * \param flags Filtering flags
  1117. *
  1118. * \retval NULL if no contacts available
  1119. * \retval non-NULL if contacts available
  1120. *
  1121. * \warning
  1122. * This function should only be called if you already hold a named write lock on the aor.
  1123. */
  1124. struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor,
  1125. unsigned int flags);
  1126. /*!
  1127. * \brief Retrieve the first bound contact from a list of AORs
  1128. *
  1129. * \param aor_list A comma-separated list of AOR names
  1130. * \retval NULL if no contacts available
  1131. * \retval non-NULL if contacts available
  1132. */
  1133. struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list);
  1134. /*!
  1135. * \brief Retrieve all contacts from a list of AORs
  1136. *
  1137. * \param aor_list A comma-separated list of AOR names
  1138. * \retval NULL if no contacts available
  1139. * \retval non-NULL container (which must be freed) if contacts available
  1140. */
  1141. struct ao2_container *ast_sip_location_retrieve_contacts_from_aor_list(const char *aor_list);
  1142. /*!
  1143. * \brief Retrieve the first bound contact AND the AOR chosen from a list of AORs
  1144. *
  1145. * \param aor_list A comma-separated list of AOR names
  1146. * \param aor The chosen AOR
  1147. * \param contact The chosen contact
  1148. */
  1149. void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor,
  1150. struct ast_sip_contact **contact);
  1151. /*!
  1152. * \brief Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags
  1153. * \since 13.16.0
  1154. *
  1155. * \param aor_list A comma-separated list of AOR names
  1156. * \param flags Filtering flags
  1157. * \param aor The chosen AOR
  1158. * \param contact The chosen contact
  1159. */
  1160. void ast_sip_location_retrieve_contact_and_aor_from_list_filtered(const char *aor_list, unsigned int flags,
  1161. struct ast_sip_aor **aor, struct ast_sip_contact **contact);
  1162. /*!
  1163. * \brief Retrieve a named contact
  1164. *
  1165. * \param contact_name Name of the contact
  1166. *
  1167. * \retval NULL if not found
  1168. * \retval non-NULL if found
  1169. */
  1170. struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name);
  1171. /*!
  1172. * \brief Add a new contact to an AOR
  1173. *
  1174. * \param aor Pointer to the AOR
  1175. * \param uri Full contact URI
  1176. * \param expiration_time Optional expiration time of the contact
  1177. * \param path_info Path information
  1178. * \param user_agent User-Agent header from REGISTER request
  1179. * \param via_addr
  1180. * \param via_port
  1181. * \param call_id
  1182. * \param endpoint The endpoint that resulted in the contact being added
  1183. *
  1184. * \retval -1 failure
  1185. * \retval 0 success
  1186. *
  1187. * \warning
  1188. * This function holds a named write lock on the aor. If you already hold the lock
  1189. * you should call ast_sip_location_add_contact_nolock instead.
  1190. */
  1191. int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
  1192. struct timeval expiration_time, const char *path_info, const char *user_agent,
  1193. const char *via_addr, int via_port, const char *call_id,
  1194. struct ast_sip_endpoint *endpoint);
  1195. /*!
  1196. * \brief Add a new contact to an AOR without locking the AOR
  1197. * \since 13.9.0
  1198. *
  1199. * \param aor Pointer to the AOR
  1200. * \param uri Full contact URI
  1201. * \param expiration_time Optional expiration time of the contact
  1202. * \param path_info Path information
  1203. * \param user_agent User-Agent header from REGISTER request
  1204. * \param via_addr
  1205. * \param via_port
  1206. * \param call_id
  1207. * \param endpoint The endpoint that resulted in the contact being added
  1208. *
  1209. * \retval -1 failure
  1210. * \retval 0 success
  1211. *
  1212. * \warning
  1213. * This function should only be called if you already hold a named write lock on the aor.
  1214. */
  1215. int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri,
  1216. struct timeval expiration_time, const char *path_info, const char *user_agent,
  1217. const char *via_addr, int via_port, const char *call_id,
  1218. struct ast_sip_endpoint *endpoint);
  1219. /*!
  1220. * \brief Create a new contact for an AOR without locking the AOR
  1221. * \since 13.18.0
  1222. *
  1223. * \param aor Pointer to the AOR
  1224. * \param uri Full contact URI
  1225. * \param expiration_time Optional expiration time of the contact
  1226. * \param path_info Path information
  1227. * \param user_agent User-Agent header from REGISTER request
  1228. * \param via_addr
  1229. * \param via_port
  1230. * \param call_id
  1231. * \param prune_on_boot Non-zero if the contact cannot survive a restart/boot.
  1232. * \param endpoint The endpoint that resulted in the contact being added
  1233. *
  1234. * \return The created contact or NULL on failure.
  1235. *
  1236. * \warning
  1237. * This function should only be called if you already hold a named write lock on the aor.
  1238. */
  1239. struct ast_sip_contact *ast_sip_location_create_contact(struct ast_sip_aor *aor,
  1240. const char *uri, struct timeval expiration_time, const char *path_info,
  1241. const char *user_agent, const char *via_addr, int via_port, const char *call_id,
  1242. int prune_on_boot, struct ast_sip_endpoint *endpoint);
  1243. /*!
  1244. * \brief Update a contact
  1245. *
  1246. * \param contact New contact object with details
  1247. *
  1248. * \retval -1 failure
  1249. * \retval 0 success
  1250. */
  1251. int ast_sip_location_update_contact(struct ast_sip_contact *contact);
  1252. /*!
  1253. * \brief Delete a contact
  1254. *
  1255. * \param contact Contact object to delete
  1256. *
  1257. * \retval -1 failure
  1258. * \retval 0 success
  1259. */
  1260. int ast_sip_location_delete_contact(struct ast_sip_contact *contact);
  1261. /*!
  1262. * \brief Prune the prune_on_boot contacts
  1263. * \since 13.18.0
  1264. */
  1265. void ast_sip_location_prune_boot_contacts(void);
  1266. /*!
  1267. * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog
  1268. *
  1269. * This callback will have the created request on it. The callback's purpose is to do any extra
  1270. * housekeeping that needs to be done as well as to send the request out.
  1271. *
  1272. * This callback is only necessary if working with a PJSIP API that sits between the application
  1273. * and the dialog layer.
  1274. *
  1275. * \param dlg The dialog to which the request belongs
  1276. * \param tdata The created request to be sent out
  1277. * \param user_data Data supplied with the callback
  1278. *
  1279. * \retval 0 Success
  1280. * \retval -1 Failure
  1281. */
  1282. typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data);
  1283. /*!
  1284. * \brief Set up outbound authentication on a SIP dialog
  1285. *
  1286. * This sets up the infrastructure so that all requests associated with a created dialog
  1287. * can be re-sent with authentication credentials if the original request is challenged.
  1288. *
  1289. * \param dlg The dialog on which requests will be authenticated
  1290. * \param endpoint The endpoint whom this dialog pertains to
  1291. * \param cb Callback to call to send requests with authentication
  1292. * \param user_data Data to be provided to the callback when it is called
  1293. *
  1294. * \retval 0 Success
  1295. * \retval -1 Failure
  1296. */
  1297. int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint,
  1298. ast_sip_dialog_outbound_auth_cb cb, void *user_data);
  1299. /*!
  1300. * \brief Retrieves a reference to the artificial auth.
  1301. *
  1302. * \retval The artificial auth
  1303. */
  1304. struct ast_sip_auth *ast_sip_get_artificial_auth(void);
  1305. /*!
  1306. * \brief Retrieves a reference to the artificial endpoint.
  1307. *
  1308. * \retval The artificial endpoint
  1309. */
  1310. struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void);
  1311. /*! \defgroup pjsip_threading PJSIP Threading Model
  1312. * @{
  1313. * \page PJSIP PJSIP Threading Model
  1314. *
  1315. * There are three major types of threads that SIP will have to deal with:
  1316. * \li Asterisk threads
  1317. * \li PJSIP threads
  1318. * \li SIP threadpool threads (a.k.a. "servants")
  1319. *
  1320. * \par Asterisk Threads
  1321. *
  1322. * Asterisk threads are those that originate from outside of SIP but within
  1323. * Asterisk. The most common of these threads are PBX (channel) threads and
  1324. * the autoservice thread. Most interaction with these threads will be through
  1325. * channel technology callbacks. Within these threads, it is fine to handle
  1326. * Asterisk data from outside of SIP, but any handling of SIP data should be
  1327. * left to servants, \b especially if you wish to call into PJSIP for anything.
  1328. * Asterisk threads are not registered with PJLIB, so attempting to call into
  1329. * PJSIP will cause an assertion to be triggered, thus causing the program to
  1330. * crash.
  1331. *
  1332. * \par PJSIP Threads
  1333. *
  1334. * PJSIP threads are those that originate from handling of PJSIP events, such
  1335. * as an incoming SIP request or response, or a transaction timeout. The role
  1336. * of these threads is to process information as quickly as possible so that
  1337. * the next item on the SIP socket(s) can be serviced. On incoming messages,
  1338. * Asterisk automatically will push the request to a servant thread. When your
  1339. * module callback is called, processing will already be in a servant. However,
  1340. * for other PJSIP events, such as transaction state changes due to timer
  1341. * expirations, your module will be called into from a PJSIP thread. If you
  1342. * are called into from a PJSIP thread, then you should push whatever processing
  1343. * is needed to a servant as soon as possible. You can discern if you are currently
  1344. * in a SIP servant thread using the \ref ast_sip_thread_is_servant function.
  1345. *
  1346. * \par Servants
  1347. *
  1348. * Servants are where the bulk of SIP work should be performed. These threads
  1349. * exist in order to do the work that Asterisk threads and PJSIP threads hand
  1350. * off to them. Servant threads register themselves with PJLIB, meaning that
  1351. * they are capable of calling PJSIP and PJLIB functions if they wish.
  1352. *
  1353. * \par Serializer
  1354. *
  1355. * Tasks are handed off to servant threads using the API call \ref ast_sip_push_task.
  1356. * The first parameter of this call is a serializer. If this pointer
  1357. * is NULL, then the work will be handed off to whatever servant can currently handle
  1358. * the task. If this pointer is non-NULL, then the task will not be executed until
  1359. * previous tasks pushed with the same serializer have completed. For more information
  1360. * on serializers and the benefits they provide, see \ref ast_threadpool_serializer
  1361. *
  1362. * \par Scheduler
  1363. *
  1364. * Some situations require that a task run periodically or at a future time. Normally
  1365. * the ast_sched functionality would be used but ast_sched only uses 1 thread for all
  1366. * tasks and that thread isn't registered with PJLIB and therefore can't do any PJSIP
  1367. * related work.
  1368. *
  1369. * ast_sip_sched uses ast_sched only as a scheduled queue. When a task is ready to run,
  1370. * it's pushed to a Serializer to be invoked asynchronously by a Servant. This ensures
  1371. * that the task is executed in a PJLIB registered thread and allows the ast_sched thread
  1372. * to immediately continue processing the queue. The Serializer used by ast_sip_sched
  1373. * is one of your choosing or a random one from the res_pjsip pool if you don't choose one.
  1374. *
  1375. * \note
  1376. *
  1377. * Do not make assumptions about individual threads based on a corresponding serializer.
  1378. * In other words, just because several tasks use the same serializer when being pushed
  1379. * to servants, it does not mean that the same thread is necessarily going to execute those
  1380. * tasks, even though they are all guaranteed to be executed in sequence.
  1381. */
  1382. typedef int (*ast_sip_task)(void *user_data);
  1383. /*!
  1384. * \brief Create a new serializer for SIP tasks
  1385. *
  1386. * See \ref ast_threadpool_serializer for more information on serializers.
  1387. * SIP creates serializers so that tasks operating on similar data will run
  1388. * in sequence.
  1389. *
  1390. * \retval NULL Failure
  1391. * \retval non-NULL Newly-created serializer
  1392. */
  1393. struct ast_taskprocessor *ast_sip_create_serializer(void);
  1394. /*!
  1395. * \brief Create a new serializer for SIP tasks
  1396. * \since 13.8.0
  1397. *
  1398. * See \ref ast_threadpool_serializer for more information on serializers.
  1399. * SIP creates serializers so that tasks operating on similar data will run
  1400. * in sequence.
  1401. *
  1402. * \param name Name of the serializer. (must be unique)
  1403. *
  1404. * \retval NULL Failure
  1405. * \retval non-NULL Newly-created serializer
  1406. */
  1407. struct ast_taskprocessor *ast_sip_create_serializer_named(const char *name);
  1408. struct ast_serializer_shutdown_group;
  1409. /*!
  1410. * \brief Create a new serializer for SIP tasks
  1411. * \since 13.5.0
  1412. *
  1413. * See \ref ast_threadpool_serializer for more information on serializers.
  1414. * SIP creates serializers so that tasks operating on similar data will run
  1415. * in sequence.
  1416. *
  1417. * \param shutdown_group Group shutdown controller. (NULL if no group association)
  1418. *
  1419. * \retval NULL Failure
  1420. * \retval non-NULL Newly-created serializer
  1421. */
  1422. struct ast_taskprocessor *ast_sip_create_serializer_group(struct ast_serializer_shutdown_group *shutdown_group);
  1423. /*!
  1424. * \brief Create a new serializer for SIP tasks
  1425. * \since 13.8.0
  1426. *
  1427. * See \ref ast_threadpool_serializer for more information on serializers.
  1428. * SIP creates serializers so that tasks operating on similar data will run
  1429. * in sequence.
  1430. *
  1431. * \param name Name of the serializer. (must be unique)
  1432. * \param shutdown_group Group shutdown controller. (NULL if no group association)
  1433. *
  1434. * \retval NULL Failure
  1435. * \retval non-NULL Newly-created serializer
  1436. */
  1437. struct ast_taskprocessor *ast_sip_create_serializer_group_named(const char *name, struct ast_serializer_shutdown_group *shutdown_group);
  1438. /*!
  1439. * \brief Determine the distributor serializer for the SIP message.
  1440. * \since 13.10.0
  1441. *
  1442. * \param rdata The incoming message.
  1443. *
  1444. * \retval Calculated distributor serializer on success.
  1445. * \retval NULL on error.
  1446. */
  1447. struct ast_taskprocessor *ast_sip_get_distributor_serializer(pjsip_rx_data *rdata);
  1448. /*!
  1449. * \brief Record the task's serializer name on the tdata structure.
  1450. * \since 13.15.0
  1451. *
  1452. * \param tdata The outgoing message.
  1453. *
  1454. * \retval PJ_SUCCESS.
  1455. */
  1456. pj_status_t ast_sip_record_request_serializer(pjsip_tx_data *tdata);
  1457. /*!
  1458. * \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized
  1459. *
  1460. * Passing a NULL serializer is a way to remove a serializer from a dialog.
  1461. *
  1462. * \param dlg The SIP dialog itself
  1463. * \param serializer The serializer to use
  1464. */
  1465. void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer);
  1466. /*!
  1467. * \brief Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
  1468. *
  1469. * \param dlg The SIP dialog itself
  1470. * \param endpoint The endpoint that this dialog is communicating with
  1471. */
  1472. void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
  1473. /*!
  1474. * \brief Get the endpoint associated with this dialog
  1475. *
  1476. * This function increases the refcount of the endpoint by one. Release
  1477. * the reference once you are finished with the endpoint.
  1478. *
  1479. * \param dlg The SIP dialog from which to retrieve the endpoint
  1480. * \retval NULL No endpoint associated with this dialog
  1481. * \retval non-NULL The endpoint.
  1482. */
  1483. struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg);
  1484. /*!
  1485. * \brief Pushes a task to SIP servants
  1486. *
  1487. * This uses the serializer provided to determine how to push the task.
  1488. * If the serializer is NULL, then the task will be pushed to the
  1489. * servants directly. If the serializer is non-NULL, then the task will be
  1490. * queued behind other tasks associated with the same serializer.
  1491. *
  1492. * \param serializer The serializer to which the task belongs. Can be NULL
  1493. * \param sip_task The task to execute
  1494. * \param task_data The parameter to pass to the task when it executes
  1495. * \retval 0 Success
  1496. * \retval -1 Failure
  1497. */
  1498. int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
  1499. /*!
  1500. * \brief Push a task to SIP servants and wait for it to complete.
  1501. *
  1502. * Like \ref ast_sip_push_task except that it blocks until the task
  1503. * completes. If the current thread is a SIP servant thread then the
  1504. * task executes immediately. Otherwise, the specified serializer
  1505. * executes the task and the current thread waits for it to complete.
  1506. *
  1507. * \note PJPROJECT callbacks tend to have locks already held when
  1508. * called.
  1509. *
  1510. * \warning \b Never hold locks that may be acquired by a SIP servant
  1511. * thread when calling this function. Doing so may cause a deadlock
  1512. * if all SIP servant threads are blocked waiting to acquire the lock
  1513. * while the thread holding the lock is waiting for a free SIP servant
  1514. * thread.
  1515. *
  1516. * \warning \b Use of this function in an ao2 destructor callback is a
  1517. * bad idea. You don't have control over which thread executes the
  1518. * destructor. Attempting to shift execution to another thread with
  1519. * this function is likely to cause deadlock.
  1520. *
  1521. * \param serializer The SIP serializer to execute the task if the
  1522. * current thread is not a SIP servant. NULL if any of the default
  1523. * serializers can be used.
  1524. * \param sip_task The task to execute
  1525. * \param task_data The parameter to pass to the task when it executes
  1526. *
  1527. * \note The sip_task() return value may need to be distinguished from
  1528. * the failure to push the task.
  1529. *
  1530. * \return sip_task() return value on success.
  1531. * \retval -1 Failure to push the task.
  1532. */
  1533. int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
  1534. /*!
  1535. * \brief Push a task to SIP servants and wait for it to complete.
  1536. * \deprecated Replaced with ast_sip_push_task_wait_servant().
  1537. */
  1538. int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
  1539. /*!
  1540. * \brief Push a task to the serializer and wait for it to complete.
  1541. *
  1542. * Like \ref ast_sip_push_task except that it blocks until the task is
  1543. * completed by the specified serializer. If the specified serializer
  1544. * is the current thread then the task executes immediately.
  1545. *
  1546. * \note PJPROJECT callbacks tend to have locks already held when
  1547. * called.
  1548. *
  1549. * \warning \b Never hold locks that may be acquired by a SIP servant
  1550. * thread when calling this function. Doing so may cause a deadlock
  1551. * if all SIP servant threads are blocked waiting to acquire the lock
  1552. * while the thread holding the lock is waiting for a free SIP servant
  1553. * thread for the serializer to execute in.
  1554. *
  1555. * \warning \b Never hold locks that may be acquired by the serializer
  1556. * when calling this function. Doing so will cause a deadlock.
  1557. *
  1558. * \warning \b Never use this function in the pjsip monitor thread (It
  1559. * is a SIP servant thread). This is likely to cause a deadlock.
  1560. *
  1561. * \warning \b Use of this function in an ao2 destructor callback is a
  1562. * bad idea. You don't have control over which thread executes the
  1563. * destructor. Attempting to shift execution to another thread with
  1564. * this function is likely to cause deadlock.
  1565. *
  1566. * \param serializer The SIP serializer to execute the task. NULL if
  1567. * any of the default serializers can be used.
  1568. * \param sip_task The task to execute
  1569. * \param task_data The parameter to pass to the task when it executes
  1570. *
  1571. * \note It is generally better to call
  1572. * ast_sip_push_task_wait_servant() if you pass NULL for the
  1573. * serializer parameter.
  1574. *
  1575. * \note The sip_task() return value may need to be distinguished from
  1576. * the failure to push the task.
  1577. *
  1578. * \return sip_task() return value on success.
  1579. * \retval -1 Failure to push the task.
  1580. */
  1581. int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
  1582. /*!
  1583. * \brief Determine if the current thread is a SIP servant thread
  1584. *
  1585. * \retval 0 This is not a SIP servant thread
  1586. * \retval 1 This is a SIP servant thread
  1587. */
  1588. int ast_sip_thread_is_servant(void);
  1589. /*!
  1590. * \brief Task flags for the res_pjsip scheduler
  1591. *
  1592. * The default is AST_SIP_SCHED_TASK_FIXED
  1593. * | AST_SIP_SCHED_TASK_DATA_NOT_AO2
  1594. * | AST_SIP_SCHED_TASK_DATA_NO_CLEANUP
  1595. * | AST_SIP_SCHED_TASK_PERIODIC
  1596. */
  1597. enum ast_sip_scheduler_task_flags {
  1598. /*!
  1599. * The defaults
  1600. */
  1601. AST_SIP_SCHED_TASK_DEFAULTS = (0 << 0),
  1602. /*!
  1603. * Run at a fixed interval.
  1604. * Stop scheduling if the callback returns <= 0.
  1605. * Any other value is ignored.
  1606. */
  1607. AST_SIP_SCHED_TASK_FIXED = (0 << 0),
  1608. /*!
  1609. * Run at a variable interval.
  1610. * Stop scheduling if the callback returns <= 0.
  1611. * Any other return value is used as the new interval.
  1612. */
  1613. AST_SIP_SCHED_TASK_VARIABLE = (1 << 0),
  1614. /*!
  1615. * The task data is not an AO2 object.
  1616. */
  1617. AST_SIP_SCHED_TASK_DATA_NOT_AO2 = (0 << 1),
  1618. /*!
  1619. * The task data is an AO2 object.
  1620. * A reference count will be held by the scheduler until
  1621. * after the task has run for the final time (if ever).
  1622. */
  1623. AST_SIP_SCHED_TASK_DATA_AO2 = (1 << 1),
  1624. /*!
  1625. * Don't take any cleanup action on the data
  1626. */
  1627. AST_SIP_SCHED_TASK_DATA_NO_CLEANUP = (0 << 3),
  1628. /*!
  1629. * If AST_SIP_SCHED_TASK_DATA_AO2 is set, decrement the reference count
  1630. * otherwise call ast_free on it.
  1631. */
  1632. AST_SIP_SCHED_TASK_DATA_FREE = ( 1 << 3 ),
  1633. /*!
  1634. * \brief The task is scheduled at multiples of interval
  1635. * \see Interval
  1636. */
  1637. AST_SIP_SCHED_TASK_PERIODIC = (0 << 4),
  1638. /*!
  1639. * \brief The next invocation of the task is at last finish + interval
  1640. * \see Interval
  1641. */
  1642. AST_SIP_SCHED_TASK_DELAY = (1 << 4),
  1643. /*!
  1644. * \brief The scheduled task's events are tracked in the debug log.
  1645. * \details
  1646. * Schedule events such as scheduling, running, rescheduling, canceling,
  1647. * and destroying are logged about the task.
  1648. */
  1649. AST_SIP_SCHED_TASK_TRACK = (1 << 5),
  1650. };
  1651. /*!
  1652. * \brief Scheduler task data structure
  1653. */
  1654. struct ast_sip_sched_task;
  1655. /*!
  1656. * \brief Schedule a task to run in the res_pjsip thread pool
  1657. * \since 13.9.0
  1658. *
  1659. * \param serializer The serializer to use. If NULL, don't use a serializer (see note below)
  1660. * \param interval The invocation interval in milliseconds (see note below)
  1661. * \param sip_task The task to invoke
  1662. * \param name An optional name to associate with the task
  1663. * \param task_data Optional data to pass to the task
  1664. * \param flags One of enum ast_sip_scheduler_task_type
  1665. *
  1666. * \returns Pointer to \ref ast_sip_sched_task ao2 object which must be dereferenced when done.
  1667. *
  1668. * \paragraph Serialization
  1669. *
  1670. * Specifying a serializer guarantees serialized execution but NOT specifying a serializer
  1671. * may still result in tasks being effectively serialized if the thread pool is busy.
  1672. * The point of the serializer BTW is not to prevent parallel executions of the SAME task.
  1673. * That happens automatically (see below). It's to prevent the task from running at the same
  1674. * time as other work using the same serializer, whether or not it's being run by the scheduler.
  1675. *
  1676. * \paragraph Interval
  1677. *
  1678. * The interval is used to calculate the next time the task should run. There are two models.
  1679. *
  1680. * \ref AST_SIP_SCHED_TASK_PERIODIC specifies that the invocations of the task occur at the
  1681. * specific interval. That is, every \ref "interval" milliseconds, regardless of how long the task
  1682. * takes. If the task takes longer than \ref interval, it will be scheduled at the next available
  1683. * multiple of \ref interval. For exmaple: If the task has an interval of 60 seconds and the task
  1684. * takes 70 seconds, the next invocation will happen at 120 seconds.
  1685. *
  1686. * \ref AST_SIP_SCHED_TASK_DELAY specifies that the next invocation of the task should start
  1687. * at \ref interval milliseconds after the current invocation has finished.
  1688. *
  1689. */
  1690. struct ast_sip_sched_task *ast_sip_schedule_task(struct ast_taskprocessor *serializer,
  1691. int interval, ast_sip_task sip_task, const char *name, void *task_data,
  1692. enum ast_sip_scheduler_task_flags flags);
  1693. /*!
  1694. * \brief Cancels the next invocation of a task
  1695. * \since 13.9.0
  1696. *
  1697. * \param schtd The task structure pointer
  1698. * \retval 0 Success
  1699. * \retval -1 Failure
  1700. * \note Only cancels future invocations not the currently running invocation.
  1701. */
  1702. int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd);
  1703. /*!
  1704. * \brief Cancels the next invocation of a task by name
  1705. * \since 13.9.0
  1706. *
  1707. * \param name The task name
  1708. * \retval 0 Success
  1709. * \retval -1 Failure
  1710. * \note Only cancels future invocations not the currently running invocation.
  1711. */
  1712. int ast_sip_sched_task_cancel_by_name(const char *name);
  1713. /*!
  1714. * \brief Gets the last start and end times of the task
  1715. * \since 13.9.0
  1716. *
  1717. * \param schtd The task structure pointer
  1718. * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
  1719. * \param[out] last_start Pointer to a timeval structure to contain the time when last started
  1720. * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
  1721. * \retval 0 Success
  1722. * \retval -1 Failure
  1723. * \note Any of the pointers can be NULL if you don't need them.
  1724. */
  1725. int ast_sip_sched_task_get_times(struct ast_sip_sched_task *schtd,
  1726. struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end);
  1727. /*!
  1728. * \brief Gets the last start and end times of the task by name
  1729. * \since 13.9.0
  1730. *
  1731. * \param name The task name
  1732. * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
  1733. * \param[out] last_start Pointer to a timeval structure to contain the time when last started
  1734. * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
  1735. * \retval 0 Success
  1736. * \retval -1 Failure
  1737. * \note Any of the pointers can be NULL if you don't need them.
  1738. */
  1739. int ast_sip_sched_task_get_times_by_name(const char *name,
  1740. struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end);
  1741. /*!
  1742. * \brief Gets the number of milliseconds until the next invocation
  1743. * \since 13.9.0
  1744. *
  1745. * \param schtd The task structure pointer
  1746. * \return The number of milliseconds until the next invocation or -1 if the task isn't scheduled
  1747. */
  1748. int ast_sip_sched_task_get_next_run(struct ast_sip_sched_task *schtd);
  1749. /*!
  1750. * \brief Gets the number of milliseconds until the next invocation
  1751. * \since 13.9.0
  1752. *
  1753. * \param name The task name
  1754. * \return The number of milliseconds until the next invocation or -1 if the task isn't scheduled
  1755. */
  1756. int ast_sip_sched_task_get_next_run_by_name(const char *name);
  1757. /*!
  1758. * \brief Checks if the task is currently running
  1759. * \since 13.9.0
  1760. *
  1761. * \param schtd The task structure pointer
  1762. * \retval 0 not running
  1763. * \retval 1 running
  1764. */
  1765. int ast_sip_sched_is_task_running(struct ast_sip_sched_task *schtd);
  1766. /*!
  1767. * \brief Checks if the task is currently running
  1768. * \since 13.9.0
  1769. *
  1770. * \param name The task name
  1771. * \retval 0 not running or not found
  1772. * \retval 1 running
  1773. */
  1774. int ast_sip_sched_is_task_running_by_name(const char *name);
  1775. /*!
  1776. * \brief Gets the task name
  1777. * \since 13.9.0
  1778. *
  1779. * \param schtd The task structure pointer
  1780. * \retval 0 success
  1781. * \retval 1 failure
  1782. */
  1783. int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen);
  1784. /*!
  1785. * @}
  1786. */
  1787. /*!
  1788. * \brief SIP body description
  1789. *
  1790. * This contains a type and subtype that will be added as
  1791. * the "Content-Type" for the message as well as the body
  1792. * text.
  1793. */
  1794. struct ast_sip_body {
  1795. /*! Type of the body, such as "application" */
  1796. const char *type;
  1797. /*! Subtype of the body, such as "sdp" */
  1798. const char *subtype;
  1799. /*! The text to go in the body */
  1800. const char *body_text;
  1801. };
  1802. /*!
  1803. * \brief General purpose method for creating a UAC dialog with an endpoint
  1804. *
  1805. * \param endpoint A pointer to the endpoint
  1806. * \param aor_name Optional name of the AOR to target, may even be an explicit SIP URI
  1807. * \param request_user Optional user to place into the target URI
  1808. *
  1809. * \retval non-NULL success
  1810. * \retval NULL failure
  1811. */
  1812. pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user);
  1813. /*!
  1814. * \brief General purpose method for creating a UAS dialog with an endpoint
  1815. *
  1816. * \param endpoint A pointer to the endpoint
  1817. * \param rdata The request that is starting the dialog
  1818. * \param[out] status On failure, the reason for failure in creating the dialog
  1819. */
  1820. pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status);
  1821. /*!
  1822. * \brief General purpose method for creating an rdata structure using specific information
  1823. * \since 13.15.0
  1824. *
  1825. * \param rdata[out] The rdata structure that will be populated
  1826. * \param packet A SIP message
  1827. * \param src_name The source IP address of the message
  1828. * \param src_port The source port of the message
  1829. * \param transport_type The type of transport the message was received on
  1830. * \param local_name The local IP address the message was received on
  1831. * \param local_port The local port the message was received on
  1832. * \param contact_uri The contact URI of the message
  1833. *
  1834. * \retval 0 success
  1835. * \retval -1 failure
  1836. */
  1837. int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet,
  1838. const char *src_name, int src_port, char *transport_type, const char *local_name,
  1839. int local_port, const char *contact_uri);
  1840. /*!
  1841. * \brief General purpose method for creating an rdata structure using specific information
  1842. *
  1843. * \param rdata[out] The rdata structure that will be populated
  1844. * \param packet A SIP message
  1845. * \param src_name The source IP address of the message
  1846. * \param src_port The source port of the message
  1847. * \param transport_type The type of transport the message was received on
  1848. * \param local_name The local IP address the message was received on
  1849. * \param local_port The local port the message was received on
  1850. *
  1851. * \retval 0 success
  1852. * \retval -1 failure
  1853. */
  1854. int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name,
  1855. int src_port, char *transport_type, const char *local_name, int local_port);
  1856. /*!
  1857. * \brief General purpose method for creating a SIP request
  1858. *
  1859. * Its typical use would be to create one-off requests such as an out of dialog
  1860. * SIP MESSAGE.
  1861. *
  1862. * The request can either be in- or out-of-dialog. If in-dialog, the
  1863. * dlg parameter MUST be present. If out-of-dialog the endpoint parameter
  1864. * MUST be present. If both are present, then we will assume that the message
  1865. * is to be sent in-dialog.
  1866. *
  1867. * The uri parameter can be specified if the request should be sent to an explicit
  1868. * URI rather than one configured on the endpoint.
  1869. *
  1870. * \param method The method of the SIP request to send
  1871. * \param dlg Optional. If specified, the dialog on which to request the message.
  1872. * \param endpoint Optional. If specified, the request will be created out-of-dialog to the endpoint.
  1873. * \param uri Optional. If specified, the request will be sent to this URI rather
  1874. * than one configured for the endpoint.
  1875. * \param contact The contact with which this request is associated for out-of-dialog requests.
  1876. * \param[out] tdata The newly-created request
  1877. *
  1878. * The provided contact is attached to tdata with its reference bumped, but will
  1879. * not survive for the entire lifetime of tdata since the contact is cleaned up
  1880. * when all supplements have completed execution.
  1881. *
  1882. * \retval 0 Success
  1883. * \retval -1 Failure
  1884. */
  1885. int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
  1886. struct ast_sip_endpoint *endpoint, const char *uri,
  1887. struct ast_sip_contact *contact, pjsip_tx_data **tdata);
  1888. /*!
  1889. * \brief General purpose method for sending a SIP request
  1890. *
  1891. * This is a companion function for \ref ast_sip_create_request. The request
  1892. * created there can be passed to this function, though any request may be
  1893. * passed in.
  1894. *
  1895. * This will automatically set up handling outbound authentication challenges if
  1896. * they arrive.
  1897. *
  1898. * \param tdata The request to send
  1899. * \param dlg Optional. The dialog in which the request is sent. Otherwise it is out-of-dialog.
  1900. * \param endpoint Optional. If specified, the out-of-dialog request is sent to the endpoint.
  1901. * \param token Data to be passed to the callback upon receipt of out-of-dialog response.
  1902. * \param callback Callback to be called upon receipt of out-of-dialog response.
  1903. *
  1904. * \retval 0 Success
  1905. * \retval -1 Failure (out-of-dialog callback will not be called.)
  1906. */
  1907. int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
  1908. struct ast_sip_endpoint *endpoint, void *token,
  1909. void (*callback)(void *token, pjsip_event *e));
  1910. /*!
  1911. * \brief General purpose method for sending an Out-Of-Dialog SIP request
  1912. *
  1913. * This is a companion function for \ref ast_sip_create_request. The request
  1914. * created there can be passed to this function, though any request may be
  1915. * passed in.
  1916. *
  1917. * This will automatically set up handling outbound authentication challenges if
  1918. * they arrive.
  1919. *
  1920. * \param tdata The request to send
  1921. * \param endpoint Optional. If specified, the out-of-dialog request is sent to the endpoint.
  1922. * \param timeout. If non-zero, after the timeout the transaction will be terminated
  1923. * and the callback will be called with the PJSIP_EVENT_TIMER type.
  1924. * \param token Data to be passed to the callback upon receipt of out-of-dialog response.
  1925. * \param callback Callback to be called upon receipt of out-of-dialog response.
  1926. *
  1927. * \retval 0 Success
  1928. * \retval -1 Failure (out-of-dialog callback will not be called.)
  1929. *
  1930. * \note Timeout processing:
  1931. * There are 2 timers associated with this request, PJSIP timer_b which is
  1932. * set globally in the "system" section of pjsip.conf, and the timeout specified
  1933. * on this call. The timer that expires first (before normal completion) will
  1934. * cause the callback to be run with e->body.tsx_state.type = PJSIP_EVENT_TIMER.
  1935. * The timer that expires second is simply ignored and the callback is not run again.
  1936. */
  1937. int ast_sip_send_out_of_dialog_request(pjsip_tx_data *tdata,
  1938. struct ast_sip_endpoint *endpoint, int timeout, void *token,
  1939. void (*callback)(void *token, pjsip_event *e));
  1940. /*!
  1941. * \brief General purpose method for creating a SIP response
  1942. *
  1943. * Its typical use would be to create responses for out of dialog
  1944. * requests.
  1945. *
  1946. * \param rdata The rdata from the incoming request.
  1947. * \param st_code The response code to transmit.
  1948. * \param contact The contact with which this request is associated.
  1949. * \param[out] tdata The newly-created response
  1950. *
  1951. * The provided contact is attached to tdata with its reference bumped, but will
  1952. * not survive for the entire lifetime of tdata since the contact is cleaned up
  1953. * when all supplements have completed execution.
  1954. *
  1955. * \retval 0 Success
  1956. * \retval -1 Failure
  1957. */
  1958. int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code,
  1959. struct ast_sip_contact *contact, pjsip_tx_data **p_tdata);
  1960. /*!
  1961. * \brief Send a response to an out of dialog request
  1962. *
  1963. * Use this function sparingly, since this does not create a transaction
  1964. * within PJSIP. This means that if the request is retransmitted, it is
  1965. * your responsibility to detect this and not process the same request
  1966. * twice, and to send the same response for each retransmission.
  1967. *
  1968. * \param res_addr The response address for this response
  1969. * \param tdata The response to send
  1970. * \param endpoint The ast_sip_endpoint associated with this response
  1971. *
  1972. * \retval 0 Success
  1973. * \retval -1 Failure
  1974. */
  1975. int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint);
  1976. /*!
  1977. * \brief Send a stateful response to an out of dialog request
  1978. *
  1979. * This creates a transaction within PJSIP, meaning that if the request
  1980. * that we are responding to is retransmitted, we will not attempt to
  1981. * re-handle the request.
  1982. *
  1983. * \param rdata The request that is being responded to
  1984. * \param tdata The response to send
  1985. * \param endpoint The ast_sip_endpoint associated with this response
  1986. *
  1987. * \since 13.4.0
  1988. *
  1989. * \retval 0 Success
  1990. * \retval -1 Failure
  1991. */
  1992. int ast_sip_send_stateful_response(pjsip_rx_data *rdata, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint);
  1993. /*!
  1994. * \brief Determine if an incoming request requires authentication
  1995. *
  1996. * This calls into the registered authenticator's requires_authentication callback
  1997. * in order to determine if the request requires authentication.
  1998. *
  1999. * If there is no registered authenticator, then authentication will be assumed
  2000. * not to be required.
  2001. *
  2002. * \param endpoint The endpoint from which the request originates
  2003. * \param rdata The incoming SIP request
  2004. * \retval non-zero The request requires authentication
  2005. * \retval 0 The request does not require authentication
  2006. */
  2007. int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
  2008. /*!
  2009. * \brief Method to determine authentication status of an incoming request
  2010. *
  2011. * This will call into a registered authenticator. The registered authenticator will
  2012. * do what is necessary to determine whether the incoming request passes authentication.
  2013. * A tentative response is passed into this function so that if, say, a digest authentication
  2014. * challenge should be sent in the ensuing response, it can be added to the response.
  2015. *
  2016. * \param endpoint The endpoint from the request was sent
  2017. * \param rdata The request to potentially authenticate
  2018. * \param tdata Tentative response to the request
  2019. * \return The result of checking authentication.
  2020. */
  2021. enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint,
  2022. pjsip_rx_data *rdata, pjsip_tx_data *tdata);
  2023. /*!
  2024. * \brief Create a response to an authentication challenge
  2025. *
  2026. * This will call into an outbound authenticator's create_request_with_auth callback
  2027. * to create a new request with authentication credentials. See the create_request_with_auth
  2028. * callback in the \ref ast_sip_outbound_authenticator structure for details about
  2029. * the parameters and return values.
  2030. */
  2031. int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
  2032. pjsip_transaction *tsx, pjsip_tx_data **new_request);
  2033. /*!
  2034. * \brief Create a response to an authentication challenge
  2035. *
  2036. * This will call into an outbound authenticator's create_request_with_auth callback
  2037. * to create a new request with authentication credentials. See the create_request_with_auth_from_old
  2038. * callback in the \ref ast_sip_outbound_authenticator structure for details about
  2039. * the parameters and return values.
  2040. */
  2041. int ast_sip_create_request_with_auth_from_old(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
  2042. pjsip_tx_data *old_request, pjsip_tx_data **new_request);
  2043. /*!
  2044. * \brief Determine the endpoint that has sent a SIP message
  2045. *
  2046. * This will call into each of the registered endpoint identifiers'
  2047. * identify_endpoint() callbacks until one returns a non-NULL endpoint.
  2048. * This will return an ao2 object. Its reference count will need to be
  2049. * decremented when completed using the endpoint.
  2050. *
  2051. * \param rdata The inbound SIP message to use when identifying the endpoint.
  2052. * \retval NULL No matching endpoint
  2053. * \retval non-NULL The matching endpoint
  2054. */
  2055. struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata);
  2056. /*!
  2057. * \brief Set the outbound proxy for an outbound SIP message
  2058. *
  2059. * \param tdata The message to set the outbound proxy on
  2060. * \param proxy SIP uri of the proxy
  2061. * \retval 0 Success
  2062. * \retval -1 Failure
  2063. */
  2064. int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy);
  2065. /*!
  2066. * \brief Add a header to an outbound SIP message
  2067. *
  2068. * \param tdata The message to add the header to
  2069. * \param name The header name
  2070. * \param value The header value
  2071. * \retval 0 Success
  2072. * \retval -1 Failure
  2073. */
  2074. int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value);
  2075. /*!
  2076. * \brief Add a body to an outbound SIP message
  2077. *
  2078. * If this is called multiple times, the latest body will replace the current
  2079. * body.
  2080. *
  2081. * \param tdata The message to add the body to
  2082. * \param body The message body to add
  2083. * \retval 0 Success
  2084. * \retval -1 Failure
  2085. */
  2086. int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body);
  2087. /*!
  2088. * \brief Add a multipart body to an outbound SIP message
  2089. *
  2090. * This will treat each part of the input vector as part of a multipart body and
  2091. * add each part to the SIP message.
  2092. *
  2093. * \param tdata The message to add the body to
  2094. * \param bodies The parts of the body to add
  2095. * \retval 0 Success
  2096. * \retval -1 Failure
  2097. */
  2098. int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies);
  2099. /*!
  2100. * \brief Append body data to a SIP message
  2101. *
  2102. * This acts mostly the same as ast_sip_add_body, except that rather than replacing
  2103. * a body if it currently exists, it appends data to an existing body.
  2104. *
  2105. * \param tdata The message to append the body to
  2106. * \param body The string to append to the end of the current body
  2107. * \retval 0 Success
  2108. * \retval -1 Failure
  2109. */
  2110. int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text);
  2111. /*!
  2112. * \brief Copy a pj_str_t into a standard character buffer.
  2113. *
  2114. * pj_str_t is not NULL-terminated. Any place that expects a NULL-
  2115. * terminated string needs to have the pj_str_t copied into a separate
  2116. * buffer.
  2117. *
  2118. * This method copies the pj_str_t contents into the destination buffer
  2119. * and NULL-terminates the buffer.
  2120. *
  2121. * \param dest The destination buffer
  2122. * \param src The pj_str_t to copy
  2123. * \param size The size of the destination buffer.
  2124. */
  2125. void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size);
  2126. /*!
  2127. * \brief Get the looked-up endpoint on an out-of dialog request or response
  2128. *
  2129. * The function may ONLY be called on out-of-dialog requests or responses. For
  2130. * in-dialog requests and responses, it is required that the user of the dialog
  2131. * has the looked-up endpoint stored locally.
  2132. *
  2133. * This function should never return NULL if the message is out-of-dialog. It will
  2134. * always return NULL if the message is in-dialog.
  2135. *
  2136. * This function will increase the reference count of the returned endpoint by one.
  2137. * Release your reference using the ao2_ref function when finished.
  2138. *
  2139. * \param rdata Out-of-dialog request or response
  2140. * \return The looked up endpoint
  2141. */
  2142. struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata);
  2143. /*!
  2144. * \brief Add 'user=phone' parameter to URI if enabled and user is a phone number.
  2145. *
  2146. * \param endpoint The endpoint to use for configuration
  2147. * \param pool The memory pool to allocate the parameter from
  2148. * \param uri The URI to check for user and to add parameter to
  2149. */
  2150. void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri);
  2151. /*!
  2152. * \brief Retrieve any endpoints available to sorcery.
  2153. *
  2154. * \retval Endpoints available to sorcery, NULL if no endpoints found.
  2155. */
  2156. struct ao2_container *ast_sip_get_endpoints(void);
  2157. /*!
  2158. * \brief Retrieve the default outbound endpoint.
  2159. *
  2160. * \retval The default outbound endpoint, NULL if not found.
  2161. */
  2162. struct ast_sip_endpoint *ast_sip_default_outbound_endpoint(void);
  2163. /*!
  2164. * \brief Retrieve relevant SIP auth structures from sorcery
  2165. *
  2166. * \param auths Vector of sorcery IDs of auth credentials to retrieve
  2167. * \param[out] out The retrieved auths are stored here
  2168. */
  2169. int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out);
  2170. /*!
  2171. * \brief Clean up retrieved auth structures from memory
  2172. *
  2173. * Call this function once you have completed operating on auths
  2174. * retrieved from \ref ast_sip_retrieve_auths
  2175. *
  2176. * \param auths An vector of auth structures to clean up
  2177. * \param num_auths The number of auths in the vector
  2178. */
  2179. void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths);
  2180. /*!
  2181. * \brief Checks if the given content type matches type/subtype.
  2182. *
  2183. * Compares the pjsip_media_type with the passed type and subtype and
  2184. * returns the result of that comparison. The media type parameters are
  2185. * ignored.
  2186. *
  2187. * \param content_type The pjsip_media_type structure to compare
  2188. * \param type The media type to compare
  2189. * \param subtype The media subtype to compare
  2190. * \retval 0 No match
  2191. * \retval -1 Match
  2192. */
  2193. int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype);
  2194. /*!
  2195. * \brief Send a security event notification for when an invalid endpoint is requested
  2196. *
  2197. * \param name Name of the endpoint requested
  2198. * \param rdata Received message
  2199. */
  2200. void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata);
  2201. /*!
  2202. * \brief Send a security event notification for when an ACL check fails
  2203. *
  2204. * \param endpoint Pointer to the endpoint in use
  2205. * \param rdata Received message
  2206. * \param name Name of the ACL
  2207. */
  2208. void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name);
  2209. /*!
  2210. * \brief Send a security event notification for when a challenge response has failed
  2211. *
  2212. * \param endpoint Pointer to the endpoint in use
  2213. * \param rdata Received message
  2214. */
  2215. void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
  2216. /*!
  2217. * \brief Send a security event notification for when authentication succeeds
  2218. *
  2219. * \param endpoint Pointer to the endpoint in use
  2220. * \param rdata Received message
  2221. */
  2222. void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
  2223. /*!
  2224. * \brief Send a security event notification for when an authentication challenge is sent
  2225. *
  2226. * \param endpoint Pointer to the endpoint in use
  2227. * \param rdata Received message
  2228. * \param tdata Sent message
  2229. */
  2230. void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata);
  2231. /*!
  2232. * \brief Send a security event notification for when a request is not supported
  2233. *
  2234. * \param endpoint Pointer to the endpoint in use
  2235. * \param rdata Received message
  2236. * \param req_type the type of request
  2237. */
  2238. void ast_sip_report_req_no_support(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata,
  2239. const char* req_type);
  2240. /*!
  2241. * \brief Send a security event notification for when a memory limit is hit.
  2242. *
  2243. * \param endpoint Pointer to the endpoint in use
  2244. * \param rdata Received message
  2245. */
  2246. void ast_sip_report_mem_limit(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
  2247. int ast_sip_add_global_request_header(const char *name, const char *value, int replace);
  2248. int ast_sip_add_global_response_header(const char *name, const char *value, int replace);
  2249. /*!
  2250. * \brief Retrieves the value associated with the given key.
  2251. *
  2252. * \param ht the hash table/dictionary to search
  2253. * \param key the key to find
  2254. *
  2255. * \retval the value associated with the key, NULL otherwise.
  2256. */
  2257. void *ast_sip_dict_get(void *ht, const char *key);
  2258. /*!
  2259. * \brief Using the dictionary stored in mod_data array at a given id,
  2260. * retrieve the value associated with the given key.
  2261. *
  2262. * \param mod_data a module data array
  2263. * \param id the mod_data array index
  2264. * \param key the key to find
  2265. *
  2266. * \retval the value associated with the key, NULL otherwise.
  2267. */
  2268. #define ast_sip_mod_data_get(mod_data, id, key) \
  2269. ast_sip_dict_get(mod_data[id], key)
  2270. /*!
  2271. * \brief Set the value for the given key.
  2272. *
  2273. * Note - if the hash table does not exist one is created first, the key/value
  2274. * pair is set, and the hash table returned.
  2275. *
  2276. * \param pool the pool to allocate memory in
  2277. * \param ht the hash table/dictionary in which to store the key/value pair
  2278. * \param key the key to associate a value with
  2279. * \param val the value to associate with a key
  2280. *
  2281. * \retval the given, or newly created, hash table.
  2282. */
  2283. void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
  2284. const char *key, void *val);
  2285. /*!
  2286. * \brief Utilizing a mod_data array for a given id, set the value
  2287. * associated with the given key.
  2288. *
  2289. * For a given structure's mod_data array set the element indexed by id to
  2290. * be a dictionary containing the key/val pair.
  2291. *
  2292. * \param pool a memory allocation pool
  2293. * \param mod_data a module data array
  2294. * \param id the mod_data array index
  2295. * \param key the key to find
  2296. * \param val the value to associate with a key
  2297. */
  2298. #define ast_sip_mod_data_set(pool, mod_data, id, key, val) \
  2299. mod_data[id] = ast_sip_dict_set(pool, mod_data[id], key, val)
  2300. /*!
  2301. * \brief For every contact on an AOR call the given 'on_contact' handler.
  2302. *
  2303. * \param aor the aor containing a list of contacts to iterate
  2304. * \param on_contact callback on each contact on an AOR. The object
  2305. * received by the callback will be a ast_sip_contact_wrapper structure.
  2306. * \param arg user data passed to handler
  2307. * \retval 0 Success, non-zero on failure
  2308. */
  2309. int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
  2310. ao2_callback_fn on_contact, void *arg);
  2311. /*!
  2312. * \brief Handler used to convert a contact to a string.
  2313. *
  2314. * \param object the ast_sip_aor_contact_pair containing a list of contacts to iterate and the contact
  2315. * \param arg user data passed to handler
  2316. * \param flags
  2317. * \retval 0 Success, non-zero on failure
  2318. */
  2319. int ast_sip_contact_to_str(void *object, void *arg, int flags);
  2320. /*!
  2321. * \brief For every aor in the comma separated aors string call the
  2322. * given 'on_aor' handler.
  2323. *
  2324. * \param aors a comma separated list of aors
  2325. * \param on_aor callback for each aor
  2326. * \param arg user data passed to handler
  2327. * \retval 0 Success, non-zero on failure
  2328. */
  2329. int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg);
  2330. /*!
  2331. * \brief For every auth in the array call the given 'on_auth' handler.
  2332. *
  2333. * \param array an array of auths
  2334. * \param on_auth callback for each auth
  2335. * \param arg user data passed to handler
  2336. * \retval 0 Success, non-zero on failure
  2337. */
  2338. int ast_sip_for_each_auth(const struct ast_sip_auth_vector *array,
  2339. ao2_callback_fn on_auth, void *arg);
  2340. /*!
  2341. * \brief Converts the given auth type to a string
  2342. *
  2343. * \param type the auth type to convert
  2344. * \retval a string representative of the auth type
  2345. */
  2346. const char *ast_sip_auth_type_to_str(enum ast_sip_auth_type type);
  2347. /*!
  2348. * \brief Converts an auths array to a string of comma separated values
  2349. *
  2350. * \param auths an auth array
  2351. * \param buf the string buffer to write the object data
  2352. * \retval 0 Success, non-zero on failure
  2353. */
  2354. int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf);
  2355. /*!
  2356. * \brief AMI variable container
  2357. */
  2358. struct ast_sip_ami {
  2359. /*! Manager session */
  2360. struct mansession *s;
  2361. /*! Manager message */
  2362. const struct message *m;
  2363. /*! Manager Action ID */
  2364. const char *action_id;
  2365. /*! user specified argument data */
  2366. void *arg;
  2367. /*! count of objects */
  2368. int count;
  2369. };
  2370. /*!
  2371. * \brief Creates a string to store AMI event data in.
  2372. *
  2373. * \param event the event to set
  2374. * \param ami AMI session and message container
  2375. * \retval an initialized ast_str or NULL on error.
  2376. */
  2377. struct ast_str *ast_sip_create_ami_event(const char *event,
  2378. struct ast_sip_ami *ami);
  2379. /*!
  2380. * \brief An entity responsible formatting endpoint information.
  2381. */
  2382. struct ast_sip_endpoint_formatter {
  2383. /*!
  2384. * \brief Callback used to format endpoint information over AMI.
  2385. */
  2386. int (*format_ami)(const struct ast_sip_endpoint *endpoint,
  2387. struct ast_sip_ami *ami);
  2388. AST_RWLIST_ENTRY(ast_sip_endpoint_formatter) next;
  2389. };
  2390. /*!
  2391. * \brief Register an endpoint formatter.
  2392. *
  2393. * \param obj the formatter to register
  2394. * \retval 0 Success
  2395. * \retval -1 Failure
  2396. */
  2397. int ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
  2398. /*!
  2399. * \brief Unregister an endpoint formatter.
  2400. *
  2401. * \param obj the formatter to unregister
  2402. */
  2403. void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
  2404. /*!
  2405. * \brief Converts a sorcery object to a string of object properties.
  2406. *
  2407. * \param obj the sorcery object to convert
  2408. * \param str the string buffer to write the object data
  2409. * \retval 0 Success, non-zero on failure
  2410. */
  2411. int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf);
  2412. /*!
  2413. * \brief Formats the endpoint and sends over AMI.
  2414. *
  2415. * \param endpoint the endpoint to format and send
  2416. * \param endpoint ami AMI variable container
  2417. * \param count the number of formatters operated on
  2418. * \retval 0 Success, otherwise non-zero on error
  2419. */
  2420. int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint,
  2421. struct ast_sip_ami *ami, int *count);
  2422. /*!
  2423. * \brief Formats the contact and sends over AMI.
  2424. *
  2425. * \param obj a pointer an ast_sip_contact_wrapper structure
  2426. * \param arg a pointer to an ast_sip_ami structure
  2427. * \param flags ignored
  2428. * \retval 0 Success, otherwise non-zero on error
  2429. */
  2430. int ast_sip_format_contact_ami(void *obj, void *arg, int flags);
  2431. /*!
  2432. * \brief Format auth details for AMI.
  2433. *
  2434. * \param auths an auth array
  2435. * \param ami ami variable container
  2436. * \retval 0 Success, non-zero on failure
  2437. */
  2438. int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths,
  2439. struct ast_sip_ami *ami);
  2440. /*!
  2441. * \brief Retrieve the endpoint snapshot for an endpoint
  2442. *
  2443. * \param endpoint The endpoint whose snapshot is to be retreieved.
  2444. * \retval The endpoint snapshot
  2445. */
  2446. struct ast_endpoint_snapshot *ast_sip_get_endpoint_snapshot(
  2447. const struct ast_sip_endpoint *endpoint);
  2448. /*!
  2449. * \brief Retrieve the device state for an endpoint.
  2450. *
  2451. * \param endpoint The endpoint whose state is to be retrieved.
  2452. * \retval The device state.
  2453. */
  2454. const char *ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint);
  2455. /*!
  2456. * \brief For every channel snapshot on an endpoint snapshot call the given
  2457. * 'on_channel_snapshot' handler.
  2458. *
  2459. * \param endpoint_snapshot snapshot of an endpoint
  2460. * \param on_channel_snapshot callback for each channel snapshot
  2461. * \param arg user data passed to handler
  2462. * \retval 0 Success, non-zero on failure
  2463. */
  2464. int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot,
  2465. ao2_callback_fn on_channel_snapshot,
  2466. void *arg);
  2467. /*!
  2468. * \brief For every channel snapshot on an endpoint all the given
  2469. * 'on_channel_snapshot' handler.
  2470. *
  2471. * \param endpoint endpoint
  2472. * \param on_channel_snapshot callback for each channel snapshot
  2473. * \param arg user data passed to handler
  2474. * \retval 0 Success, non-zero on failure
  2475. */
  2476. int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint,
  2477. ao2_callback_fn on_channel_snapshot,
  2478. void *arg);
  2479. enum ast_sip_supplement_priority {
  2480. /*! Top priority. Supplements with this priority are those that need to run before any others */
  2481. AST_SIP_SUPPLEMENT_PRIORITY_FIRST = 0,
  2482. /*! Channel creation priority.
  2483. * chan_pjsip creates a channel at this priority. If your supplement depends on being run before
  2484. * or after channel creation, then set your priority to be lower or higher than this value.
  2485. */
  2486. AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL = 1000000,
  2487. /*! Lowest priority. Supplements with this priority should be run after all other supplements */
  2488. AST_SIP_SUPPLEMENT_PRIORITY_LAST = INT_MAX,
  2489. };
  2490. /*!
  2491. * \brief A supplement to SIP message processing
  2492. *
  2493. * These can be registered by any module in order to add
  2494. * processing to incoming and outgoing SIP out of dialog
  2495. * requests and responses
  2496. */
  2497. struct ast_sip_supplement {
  2498. /*! Method on which to call the callbacks. If NULL, call on all methods */
  2499. const char *method;
  2500. /*! Priority for this supplement. Lower numbers are visited before higher numbers */
  2501. enum ast_sip_supplement_priority priority;
  2502. /*!
  2503. * \brief Called on incoming SIP request
  2504. * This method can indicate a failure in processing in its return. If there
  2505. * is a failure, it is required that this method sends a response to the request.
  2506. * This method is always called from a SIP servant thread.
  2507. *
  2508. * \note
  2509. * The following PJSIP methods will not work properly:
  2510. * pjsip_rdata_get_dlg()
  2511. * pjsip_rdata_get_tsx()
  2512. * The reason is that the rdata passed into this function is a cloned rdata structure,
  2513. * and its module data is not copied during the cloning operation.
  2514. * If you need to get the dialog, you can get it via session->inv_session->dlg.
  2515. *
  2516. * \note
  2517. * There is no guarantee that a channel will be present on the session when this is called.
  2518. */
  2519. int (*incoming_request)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
  2520. /*!
  2521. * \brief Called on an incoming SIP response
  2522. * This method is always called from a SIP servant thread.
  2523. *
  2524. * \note
  2525. * The following PJSIP methods will not work properly:
  2526. * pjsip_rdata_get_dlg()
  2527. * pjsip_rdata_get_tsx()
  2528. * The reason is that the rdata passed into this function is a cloned rdata structure,
  2529. * and its module data is not copied during the cloning operation.
  2530. * If you need to get the dialog, you can get it via session->inv_session->dlg.
  2531. *
  2532. * \note
  2533. * There is no guarantee that a channel will be present on the session when this is called.
  2534. */
  2535. void (*incoming_response)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
  2536. /*!
  2537. * \brief Called on an outgoing SIP request
  2538. * This method is always called from a SIP servant thread.
  2539. */
  2540. void (*outgoing_request)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
  2541. /*!
  2542. * \brief Called on an outgoing SIP response
  2543. * This method is always called from a SIP servant thread.
  2544. */
  2545. void (*outgoing_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
  2546. /*! Next item in the list */
  2547. AST_LIST_ENTRY(ast_sip_supplement) next;
  2548. };
  2549. /*!
  2550. * \brief Register a supplement to SIP out of dialog processing
  2551. *
  2552. * This allows for someone to insert themselves in the processing of out
  2553. * of dialog SIP requests and responses. This, for example could allow for
  2554. * a module to set channel data based on headers in an incoming message.
  2555. * Similarly, a module could reject an incoming request if desired.
  2556. *
  2557. * \param supplement The supplement to register
  2558. * \retval 0 Success
  2559. * \retval -1 Failure
  2560. */
  2561. int ast_sip_register_supplement(struct ast_sip_supplement *supplement);
  2562. /*!
  2563. * \brief Unregister a an supplement to SIP out of dialog processing
  2564. *
  2565. * \param supplement The supplement to unregister
  2566. */
  2567. void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
  2568. /*!
  2569. * \brief Retrieve the global MWI taskprocessor high water alert trigger level.
  2570. *
  2571. * \since 13.12.0
  2572. *
  2573. * \retval the system MWI taskprocessor high water alert trigger level
  2574. */
  2575. unsigned int ast_sip_get_mwi_tps_queue_high(void);
  2576. /*!
  2577. * \brief Retrieve the global MWI taskprocessor low water clear alert level.
  2578. *
  2579. * \since 13.12.0
  2580. *
  2581. * \retval the system MWI taskprocessor low water clear alert level
  2582. */
  2583. int ast_sip_get_mwi_tps_queue_low(void);
  2584. /*!
  2585. * \brief Retrieve the global setting 'disable sending unsolicited mwi on startup'.
  2586. * \since 13.12.0
  2587. *
  2588. * \retval non zero if disable.
  2589. */
  2590. unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void);
  2591. /*!
  2592. * \brief Retrieve the global setting 'use_callerid_contact'.
  2593. * \since 13.24.0
  2594. *
  2595. * \retval non zero if CALLERID(num) is to be used as the default username in the contact
  2596. */
  2597. unsigned int ast_sip_get_use_callerid_contact(void);
  2598. /*!
  2599. * \brief Retrieve the global setting 'ignore_uri_user_options'.
  2600. * \since 13.12.0
  2601. *
  2602. * \retval non zero if ignore the user field options.
  2603. */
  2604. unsigned int ast_sip_get_ignore_uri_user_options(void);
  2605. /*!
  2606. * \brief Retrieve the global setting 'send_contact_status_on_update_registration'.
  2607. * \since 13.25.0
  2608. *
  2609. * \retval non zero if need to send AMI ContactStatus event when a contact is updated.
  2610. */
  2611. unsigned int ast_sip_get_send_contact_status_on_update_registration(void);
  2612. /*!
  2613. * \brief Truncate the URI user field options string if enabled.
  2614. * \since 13.12.0
  2615. *
  2616. * \param str URI user field string to truncate if enabled
  2617. *
  2618. * \details
  2619. * We need to be able to handle URI's looking like
  2620. * "sip:1235557890;phone-context=national@x.x.x.x;user=phone"
  2621. *
  2622. * Where the URI user field is:
  2623. * "1235557890;phone-context=national"
  2624. *
  2625. * When truncated the string will become:
  2626. * "1235557890"
  2627. */
  2628. #define AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(str) \
  2629. do { \
  2630. char *__semi = strchr((str), ';'); \
  2631. if (__semi && ast_sip_get_ignore_uri_user_options()) { \
  2632. *__semi = '\0'; \
  2633. } \
  2634. } while (0)
  2635. /*!
  2636. * \brief Retrieve the system debug setting (yes|no|host).
  2637. *
  2638. * \note returned string needs to be de-allocated by caller.
  2639. *
  2640. * \retval the system debug setting.
  2641. */
  2642. char *ast_sip_get_debug(void);
  2643. /*!
  2644. * \brief Retrieve the global regcontext setting.
  2645. *
  2646. * \since 13.8.0
  2647. *
  2648. * \note returned string needs to be de-allocated by caller.
  2649. *
  2650. * \retval the global regcontext setting
  2651. */
  2652. char *ast_sip_get_regcontext(void);
  2653. /*!
  2654. * \brief Retrieve the global endpoint_identifier_order setting.
  2655. *
  2656. * Specifies the order by which endpoint identifiers should be regarded.
  2657. *
  2658. * \retval the global endpoint_identifier_order value
  2659. */
  2660. char *ast_sip_get_endpoint_identifier_order(void);
  2661. /*!
  2662. * \brief Retrieve the default voicemail extension.
  2663. * \since 13.9.0
  2664. *
  2665. * \note returned string needs to be de-allocated by caller.
  2666. *
  2667. * \retval the default voicemail extension
  2668. */
  2669. char *ast_sip_get_default_voicemail_extension(void);
  2670. /*!
  2671. * \brief Retrieve the global default realm.
  2672. *
  2673. * This is the value placed in outbound challenges' realm if there
  2674. * is no better option (such as an auth-configured realm).
  2675. *
  2676. * \param[out] realm The default realm
  2677. * \param size The buffer size of realm
  2678. * \return nothing
  2679. */
  2680. void ast_sip_get_default_realm(char *realm, size_t size);
  2681. /*!
  2682. * \brief Retrieve the global default from user.
  2683. *
  2684. * This is the value placed in outbound requests' From header if there
  2685. * is no better option (such as an endpoint-configured from_user or
  2686. * caller ID number).
  2687. *
  2688. * \param[out] from_user The default from user
  2689. * \param size The buffer size of from_user
  2690. * \return nothing
  2691. */
  2692. void ast_sip_get_default_from_user(char *from_user, size_t size);
  2693. /*! \brief Determines whether the res_pjsip module is loaded */
  2694. #define CHECK_PJSIP_MODULE_LOADED() \
  2695. do { \
  2696. if (!ast_module_check("res_pjsip.so") \
  2697. || !ast_sip_get_pjsip_endpoint()) { \
  2698. return AST_MODULE_LOAD_DECLINE; \
  2699. } \
  2700. } while(0)
  2701. /*!
  2702. * \brief Retrieve the system keep alive interval setting.
  2703. *
  2704. * \retval the keep alive interval.
  2705. */
  2706. unsigned int ast_sip_get_keep_alive_interval(void);
  2707. /*!
  2708. * \brief Retrieve the system contact expiration check interval setting.
  2709. *
  2710. * \retval the contact expiration check interval.
  2711. */
  2712. unsigned int ast_sip_get_contact_expiration_check_interval(void);
  2713. /*!
  2714. * \brief Retrieve the system setting 'disable multi domain'.
  2715. * \since 13.9.0
  2716. *
  2717. * \retval non zero if disable multi domain.
  2718. */
  2719. unsigned int ast_sip_get_disable_multi_domain(void);
  2720. /*!
  2721. * \brief Retrieve the system max initial qualify time.
  2722. *
  2723. * \retval the maximum initial qualify time.
  2724. */
  2725. unsigned int ast_sip_get_max_initial_qualify_time(void);
  2726. /*!
  2727. * \brief translate ast_sip_contact_status_type to character string.
  2728. *
  2729. * \retval the character string equivalent.
  2730. */
  2731. const char *ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status);
  2732. const char *ast_sip_get_contact_short_status_label(const enum ast_sip_contact_status_type status);
  2733. /*!
  2734. * \brief Retrieve the local host address in IP form
  2735. *
  2736. * \param af The address family to retrieve
  2737. * \param addr A place to store the local host address
  2738. *
  2739. * \retval 0 success
  2740. * \retval -1 failure
  2741. *
  2742. * \since 13.6.0
  2743. */
  2744. int ast_sip_get_host_ip(int af, pj_sockaddr *addr);
  2745. /*!
  2746. * \brief Retrieve the local host address in string form
  2747. *
  2748. * \param af The address family to retrieve
  2749. *
  2750. * \retval non-NULL success
  2751. * \retval NULL failure
  2752. *
  2753. * \since 13.6.0
  2754. *
  2755. * \note An empty string may be returned if the address family is valid but no local address exists
  2756. */
  2757. const char *ast_sip_get_host_ip_string(int af);
  2758. /*!
  2759. * \brief Return the size of the SIP threadpool's task queue
  2760. * \since 13.7.0
  2761. */
  2762. long ast_sip_threadpool_queue_size(void);
  2763. /*!
  2764. * \brief Retrieve transport state
  2765. * \since 13.7.1
  2766. *
  2767. * @param transport_id
  2768. * @returns transport_state
  2769. *
  2770. * \note ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object
  2771. */
  2772. struct ast_sip_transport_state *ast_sip_get_transport_state(const char *transport_id);
  2773. /*!
  2774. * \brief Retrieves all transport states
  2775. * \since 13.7.1
  2776. *
  2777. * @returns ao2_container
  2778. *
  2779. * \note ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object
  2780. */
  2781. struct ao2_container *ast_sip_get_transport_states(void);
  2782. /*!
  2783. * \brief Sets pjsip_tpselector from ast_sip_transport
  2784. * \since 13.8.0
  2785. *
  2786. * \param transport The transport to be used
  2787. * \param selector The selector to be populated
  2788. * \retval 0 success
  2789. * \retval -1 failure
  2790. */
  2791. int ast_sip_set_tpselector_from_transport(const struct ast_sip_transport *transport, pjsip_tpselector *selector);
  2792. /*!
  2793. * \brief Sets pjsip_tpselector from ast_sip_transport
  2794. * \since 13.8.0
  2795. *
  2796. * \param transport_name The name of the transport to be used
  2797. * \param selector The selector to be populated
  2798. * \retval 0 success
  2799. * \retval -1 failure
  2800. */
  2801. int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector);
  2802. /*!
  2803. * \brief Set name and number information on an identity header.
  2804. *
  2805. * \param pool Memory pool to use for string duplication
  2806. * \param id_hdr A From, P-Asserted-Identity, or Remote-Party-ID header to modify
  2807. * \param id The identity information to apply to the header
  2808. */
  2809. void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr,
  2810. const struct ast_party_id *id);
  2811. /*!
  2812. * \brief Retrieve the unidentified request security event thresholds
  2813. * \since 13.8.0
  2814. *
  2815. * \param count The maximum number of unidentified requests per source ip to accumulate before emitting a security event
  2816. * \param period The period in seconds over which to accumulate unidentified requests
  2817. * \param prune_interval The interval in seconds at which expired entries will be pruned
  2818. */
  2819. void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period,
  2820. unsigned int *prune_interval);
  2821. /*!
  2822. * \brief Get the transport name from an endpoint or request uri
  2823. * \since 13.15.0
  2824. *
  2825. * \param endpoint
  2826. * \param sip_uri
  2827. * \param buf Buffer to receive transport name
  2828. * \param buf_len Buffer length
  2829. *
  2830. * \retval 0 Success
  2831. * \retval -1 Failure
  2832. *
  2833. * \note
  2834. * If endpoint->transport is not NULL, it is returned in buf.
  2835. * Otherwise if sip_uri has an 'x-ast-txp' parameter AND the sip_uri host is
  2836. * an ip4 or ip6 address, its value is returned,
  2837. */
  2838. int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint,
  2839. pjsip_sip_uri *sip_uri, char *buf, size_t buf_len);
  2840. /*!
  2841. * \brief Sets pjsip_tpselector from an endpoint or uri
  2842. * \since 13.15.0
  2843. *
  2844. * \param endpoint If endpoint->transport is set, it's used
  2845. * \param sip_uri If sip_uri contains a x-ast-txp parameter, it's used
  2846. * \param selector The selector to be populated
  2847. *
  2848. * \retval 0 success
  2849. * \retval -1 failure
  2850. */
  2851. int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint,
  2852. pjsip_sip_uri *sip_uri, pjsip_tpselector *selector);
  2853. /*!
  2854. * \brief Set the transport on a dialog
  2855. * \since 13.15.0
  2856. *
  2857. * \param endpoint
  2858. * \param dlg
  2859. * \param selector (optional)
  2860. *
  2861. * \note
  2862. * This API calls ast_sip_get_transport_name(endpoint, dlg->target) and if the result is
  2863. * non-NULL, calls pjsip_dlg_set_transport. If 'selector' is non-NULL, it is updated with
  2864. * the selector used.
  2865. */
  2866. int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
  2867. pjsip_tpselector *selector);
  2868. /*!
  2869. * \brief Convert the DTMF mode enum value into a string
  2870. * \since 13.18.0
  2871. *
  2872. * \param dtmf the dtmf mode
  2873. * \param buf Buffer to receive dtmf mode string
  2874. * \param buf_len Buffer length
  2875. *
  2876. * \retval 0 Success
  2877. * \retval -1 Failure
  2878. *
  2879. */
  2880. int ast_sip_dtmf_to_str(const enum ast_sip_dtmf_mode dtmf,
  2881. char *buf, size_t buf_len);
  2882. /*!
  2883. * \brief Convert the DTMF mode name into an enum
  2884. * \since 13.18.0
  2885. *
  2886. * \param dtmf_mode dtmf mode as a string
  2887. *
  2888. * \retval >= 0 The enum value
  2889. * \retval -1 Failure
  2890. *
  2891. */
  2892. int ast_sip_str_to_dtmf(const char *dtmf_mode);
  2893. /*!
  2894. * \brief Transport shutdown monitor callback.
  2895. * \since 13.18.0
  2896. *
  2897. * \param data User data to know what to do when transport shuts down.
  2898. *
  2899. * \note The callback does not need to care that data is an ao2 object.
  2900. *
  2901. * \return Nothing
  2902. */
  2903. typedef void (*ast_transport_monitor_shutdown_cb)(void *data);
  2904. /*!
  2905. * \brief Transport shutdown monitor data matcher
  2906. * \since 13.20.0
  2907. *
  2908. * \param a User data to compare.
  2909. * \param b User data to compare.
  2910. *
  2911. * \retval 1 The data objects match
  2912. * \retval 0 The data objects don't match
  2913. */
  2914. typedef int (*ast_transport_monitor_data_matcher)(void *a, void *b);
  2915. enum ast_transport_monitor_reg {
  2916. /*! \brief Successfully registered the transport monitor */
  2917. AST_TRANSPORT_MONITOR_REG_SUCCESS,
  2918. /*! \brief Replaced the already existing transport monitor with new one. */
  2919. AST_TRANSPORT_MONITOR_REG_REPLACED,
  2920. /*!
  2921. * \brief Transport not found to monitor.
  2922. * \note Transport is either already shutdown or is not reliable.
  2923. */
  2924. AST_TRANSPORT_MONITOR_REG_NOT_FOUND,
  2925. /*! \brief Error while registering transport monitor. */
  2926. AST_TRANSPORT_MONITOR_REG_FAILED,
  2927. };
  2928. /*!
  2929. * \brief Register a reliable transport shutdown monitor callback.
  2930. * \since 13.20.0
  2931. *
  2932. * \param transport Transport to monitor for shutdown.
  2933. * \param cb Who to call when transport is shutdown.
  2934. * \param ao2_data Data to pass with the callback.
  2935. *
  2936. * \note The data object passed will have its reference count automatically
  2937. * incremented by this call and automatically decremented after the callback
  2938. * runs or when the callback is unregistered.
  2939. *
  2940. * There is no checking for duplicate registrations.
  2941. *
  2942. * \return enum ast_transport_monitor_reg
  2943. */
  2944. enum ast_transport_monitor_reg ast_sip_transport_monitor_register(pjsip_transport *transport,
  2945. ast_transport_monitor_shutdown_cb cb, void *ao2_data);
  2946. /*!
  2947. * \brief Unregister a reliable transport shutdown monitor
  2948. * \since 13.20.0
  2949. *
  2950. * \param transport Transport to monitor for shutdown.
  2951. * \param cb The callback that was used for the original register.
  2952. * \param data Data to pass to the matcher. May be NULL and does NOT need to be an ao2 object.
  2953. * If NULL, all monitors with the provided callbck are unregistered.
  2954. * \param matches Matcher function that returns true if data matches the previously
  2955. * registered data object. If NULL, a simple pointer comparison is done.
  2956. *
  2957. * \note The data object passed into the original register will have its reference count
  2958. * automatically decremeneted.
  2959. *
  2960. * \return Nothing
  2961. */
  2962. void ast_sip_transport_monitor_unregister(pjsip_transport *transport,
  2963. ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches);
  2964. /*!
  2965. * \brief Unregister a transport shutdown monitor from all reliable transports
  2966. * \since 13.20.0
  2967. *
  2968. * \param cb The callback that was used for the original register.
  2969. * \param data Data to pass to the matcher. May be NULL and does NOT need to be an ao2 object.
  2970. * If NULL, all monitors with the provided callbck are unregistered.
  2971. * \param matches Matcher function that returns true if ao2_data matches the previously
  2972. * registered data object. If NULL, a simple pointer comparison is done.
  2973. *
  2974. * \note The data object passed into the original register will have its reference count
  2975. * automatically decremeneted.
  2976. *
  2977. * \return Nothing
  2978. */
  2979. void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb cb,
  2980. void *data, ast_transport_monitor_data_matcher matches);
  2981. /*! Transport state notification registration element. */
  2982. struct ast_sip_tpmgr_state_callback {
  2983. /*! PJPROJECT transport state notification callback */
  2984. pjsip_tp_state_callback cb;
  2985. AST_LIST_ENTRY(ast_sip_tpmgr_state_callback) node;
  2986. };
  2987. /*!
  2988. * \brief Register a transport state notification callback element.
  2989. * \since 13.18.0
  2990. *
  2991. * \param element What we are registering.
  2992. *
  2993. * \return Nothing
  2994. */
  2995. void ast_sip_transport_state_register(struct ast_sip_tpmgr_state_callback *element);
  2996. /*!
  2997. * \brief Unregister a transport state notification callback element.
  2998. * \since 13.18.0
  2999. *
  3000. * \param element What we are unregistering.
  3001. *
  3002. * \return Nothing
  3003. */
  3004. void ast_sip_transport_state_unregister(struct ast_sip_tpmgr_state_callback *element);
  3005. #endif /* _RES_PJSIP_H */