sip_dialog.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJSIP_SIP_DIALOG_H__
  20. #define __PJSIP_SIP_DIALOG_H__
  21. /**
  22. * @file sip_dialog.h
  23. * @brief SIP Dialog abstraction
  24. */
  25. #include <pjsip/sip_msg.h>
  26. #include <pjsip/sip_auth.h>
  27. #include <pjsip/sip_errno.h>
  28. #include <pjsip/sip_transport.h>
  29. #include <pjsip/sip_util.h>
  30. #include <pj/sock.h>
  31. #include <pj/assert.h>
  32. /**
  33. * @defgroup PJSIP_DIALOG Base Dialog
  34. * @ingroup PJSIP_UA
  35. * @brief The base dialog framework to support dialog usages.
  36. * @{
  37. *
  38. * The base dialog framework provides management for base dialog
  39. * properties such as <b>From</b> header, <b>To</b> header, <b>CSeq</b>
  40. * sequencing, <b>Call-ID</b> header, <b>Contact</b> header management,
  41. * dialog <b>route-set</b> management, and common <b>authentication</b>.
  42. * This basic dialog functionality will be shared by all <b>dialog
  43. * usages</b> of a particular dialog.
  44. *
  45. * More detailed information is explained in
  46. * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
  47. * PDF document, and readers are encouraged to read the document to
  48. * get the concept behind dialog, dialog usages, and INVITE sessions.
  49. *
  50. * Application MUST initialize the user agent layer module by calling
  51. * #pjsip_ua_init_module() before using any of the dialog API, and link
  52. * the application with with <b>pjsip-core</b> library.
  53. */
  54. PJ_BEGIN_DECL
  55. /** Deprecated API pjsip_dlg_create_uas() due to a fatal bug of possible
  56. * premature dialog destroy. Application should not change this setting,
  57. * unless it uses single worker thread.
  58. * See also https://github.com/pjsip/pjproject/issues/1902.
  59. */
  60. #ifndef DEPRECATED_FOR_TICKET_1902
  61. # define DEPRECATED_FOR_TICKET_1902 1
  62. #endif
  63. /**
  64. * This structure is used to describe dialog's participants, which in this
  65. * case is local party (i.e. us) and remote party.
  66. */
  67. typedef struct pjsip_dlg_party
  68. {
  69. pjsip_fromto_hdr *info; /**< From/To header, inc tag. */
  70. pj_str_t info_str; /**< String rep of info header. */
  71. pj_uint32_t tag_hval; /**< Hashed value of the tag. */
  72. pjsip_contact_hdr *contact; /**< Contact header. */
  73. pj_int32_t first_cseq;/**< First CSeq seen. */
  74. pj_int32_t cseq; /**< Next sequence number. */
  75. } pjsip_dlg_party;
  76. /**
  77. * Dialog state.
  78. */
  79. typedef enum pjsip_dialog_state
  80. {
  81. /** Dialog is not established. */
  82. PJSIP_DIALOG_STATE_NULL,
  83. /** Dialog has been established (probably early) */
  84. PJSIP_DIALOG_STATE_ESTABLISHED
  85. } pjsip_dialog_state;
  86. /**
  87. * Dialog capability status.
  88. */
  89. typedef enum pjsip_dialog_cap_status
  90. {
  91. /** Capability is unsupported. */
  92. PJSIP_DIALOG_CAP_UNSUPPORTED = 0,
  93. /** Capability is supported */
  94. PJSIP_DIALOG_CAP_SUPPORTED = 1,
  95. /**
  96. * Unknown capability status. This is usually because we lack the
  97. * capability info which is retrieved from capability header specified
  98. * in the dialog messages.
  99. */
  100. PJSIP_DIALOG_CAP_UNKNOWN = 2
  101. } pjsip_dialog_cap_status;
  102. /**
  103. * This structure describes the dialog structure. Application MUST NOT
  104. * try to SET the values here directly, but instead it MUST use the
  105. * appropriate dialog API. The dialog declaration only needs to be made
  106. * visible because other PJSIP modules need to see it (e.g. INVITE session,
  107. * the event framework, etc.).
  108. *
  109. * Application MAY READ the dialog contents directly after it acquires
  110. * dialog lock.
  111. *
  112. * To acquire dialog lock, use #pjsip_dlg_inc_lock(), and to release it,
  113. * use #pjsip_dlg_dec_lock(). DO NOT USE pj_mutex_lock()/pj_mutex_unlock()
  114. * on the dialog's mutex directly, because this will not protect against
  115. * dialog being destroyed.
  116. */
  117. struct pjsip_dialog
  118. {
  119. /** The dialog set list. */
  120. PJ_DECL_LIST_MEMBER(pjsip_dialog);
  121. /* Dialog's system properties. */
  122. char obj_name[PJ_MAX_OBJ_NAME]; /**< Standard id. */
  123. pj_pool_t *pool; /**< Dialog's pool. */
  124. pjsip_user_agent *ua; /**< User agent instance. */
  125. pjsip_endpoint *endpt; /**< Endpoint instance. */
  126. pj_grp_lock_t *grp_lock_; /**< Dialog's grp lock. Do not call!!
  127. Use pjsip_dlg_inc_lock() instead! */
  128. /** The dialog set which this dialog belongs (opaque type). */
  129. void *dlg_set;
  130. /* Dialog's session properties. */
  131. pjsip_dialog_state state; /**< Dialog state. */
  132. pjsip_uri *target; /**< Current target. */
  133. pjsip_target_set target_set; /**< Target set, for UAC only. */
  134. pjsip_hdr inv_hdr; /**< Headers from hparam in dest URL */
  135. pjsip_dlg_party local; /**< Local party info. */
  136. pjsip_dlg_party remote; /**< Remote party info. */
  137. pjsip_hdr rem_cap_hdr;/**< List of remote capability header. */
  138. pjsip_role_e role; /**< Initial role. */
  139. pj_bool_t uac_has_2xx;/**< UAC has received 2xx response? */
  140. pj_bool_t secure; /**< Use secure transport? */
  141. pj_bool_t add_allow; /**< Add Allow header in requests? */
  142. pj_bool_t ack_sent; /**< ACK has been sent? */
  143. pjsip_cid_hdr *call_id; /**< Call-ID header. */
  144. pjsip_route_hdr route_set; /**< Route set. */
  145. pj_bool_t route_set_frozen; /**< Route set has been set. */
  146. pjsip_auth_clt_sess auth_sess; /**< Client authentication session. */
  147. pj_str_t initial_dest;/**< Initial destination host (used for
  148. verifying remote TLS cert). */
  149. /** Session counter. */
  150. int sess_count; /**< Number of sessions. */
  151. /** Transaction counter. */
  152. int tsx_count; /**< Number of pending transactions. */
  153. /** Transport selector. */
  154. pjsip_tpselector tp_sel;
  155. /* Dialog usages. */
  156. unsigned usage_cnt; /**< Number of registered usages. */
  157. pjsip_module *usage[PJSIP_MAX_MODULE]; /**< Array of usages,
  158. priority sorted */
  159. /** Module specific data. */
  160. void *mod_data[PJSIP_MAX_MODULE]; /**< Module data. */
  161. /**
  162. * If via_addr is set, it will be used as the "sent-by" field of the
  163. * Via header for outgoing requests as long as the request uses via_tp
  164. * transport. Normally application should not use or access these fields.
  165. */
  166. pjsip_host_port via_addr; /**< Via address. */
  167. const void *via_tp; /**< Via transport. */
  168. };
  169. /**
  170. * The parameter for \a pjsip_dlg_create_uac2().
  171. */
  172. typedef struct pjsip_dlg_create_uac_param {
  173. /**
  174. * The user agent module instance.
  175. */
  176. pjsip_user_agent *ua;
  177. /**
  178. * Dialog local URI (i.e. From header).
  179. */
  180. pj_str_t local_uri;
  181. /**
  182. * Optional dialog local Contact to be put as Contact header value,
  183. * hence the format must follow RFC 3261 Section 20.10:
  184. * When the header field value contains a display name, the URI including
  185. * all URI parameters is enclosed in "<" and ">". If no "<" and ">" are
  186. * present, all parameters after the URI are header parameters, not
  187. * URI parameters. The display name can be tokens, or a quoted string,
  188. * if a larger character set is desired. If this argument is NULL,
  189. * the Contact will be taken from the local URI.
  190. */
  191. pj_str_t local_contact;
  192. /**
  193. * Dialog remote URI (i.e. To header).
  194. */
  195. pj_str_t remote_uri;
  196. /**
  197. * Optional initial remote target. If this argument is NULL, the initial
  198. * target will be set to remote URI.
  199. */
  200. pj_str_t target;
  201. /**
  202. * Optional group lock to use by this dialog. If the value is NULL,
  203. * the dialog will create its own group lock.
  204. */
  205. pj_grp_lock_t *grp_lock;
  206. } pjsip_dlg_create_uac_param;
  207. /**
  208. * This utility function returns PJ_TRUE if the specified method is a
  209. * dialog creating request. This method property is used to determine
  210. * whether Contact header should be included in outgoing request.
  211. *
  212. * @param m The SIP method.
  213. *
  214. * @return PJ_TRUE if the method creates a dialog.
  215. */
  216. PJ_DECL(pj_bool_t) pjsip_method_creates_dialog(const pjsip_method *m);
  217. /**
  218. * Create a new dialog and return the instance in p_dlg parameter.
  219. * After creating the dialog, application can add modules as dialog usages
  220. * by calling #pjsip_dlg_add_usage().
  221. *
  222. * If the request has To tag parameter, dialog's local tag will be initialized
  223. * from this value. Otherwise a globally unique id generator will be invoked to
  224. * create dialog's local tag.
  225. *
  226. * This function also initializes the dialog's route set based on the
  227. * Record-Route headers in the request, if present.
  228. *
  229. * Note that initially, the session count in the dialog will be initialized
  230. * to zero.
  231. *
  232. * @param ua The user agent module instance.
  233. * @param local_uri Dialog local URI (i.e. From header).
  234. * @param local_contact Optional dialog local Contact to be put as Contact
  235. * header value, hence the format must follow
  236. * RFC 3261 Section 20.10:
  237. * When the header field value contains a display
  238. * name, the URI including all URI parameters is
  239. * enclosed in "<" and ">". If no "<" and ">" are
  240. * present, all parameters after the URI are header
  241. * parameters, not URI parameters. The display name
  242. * can be tokens, or a quoted string, if a larger
  243. * character set is desired.
  244. * If this argument is NULL, the Contact will be taken
  245. * from the local URI.
  246. * @param remote_uri Dialog remote URI (i.e. To header).
  247. * @param target Optional initial remote target. If this argument
  248. * is NULL, the initial target will be set to
  249. * remote URI.
  250. * @param p_dlg Pointer to receive the dialog.
  251. *
  252. * @return PJ_SUCCESS on success.
  253. */
  254. PJ_DECL(pj_status_t) pjsip_dlg_create_uac( pjsip_user_agent *ua,
  255. const pj_str_t *local_uri,
  256. const pj_str_t *local_contact,
  257. const pj_str_t *remote_uri,
  258. const pj_str_t *target,
  259. pjsip_dialog **p_dlg);
  260. /**
  261. * Variant of pjsip_dlg_create_uac() with additional parameter to specify
  262. * the group lock to use. Group lock can be used to synchronize locking
  263. * among several objects to prevent deadlock, and to synchronize the
  264. * lifetime of objects sharing the same group lock.
  265. *
  266. * See \a pjsip_dlg_create_uac() for general info about this function.
  267. *
  268. * @param create_param The parameter, refer to
  269. * \a pjsip_dlg_create_uac_param
  270. * @param p_dlg Pointer to receive the dialog.
  271. *
  272. * @return PJ_SUCCESS on success.
  273. */
  274. PJ_DECL(pj_status_t) pjsip_dlg_create_uac2(
  275. const pjsip_dlg_create_uac_param *create_param,
  276. pjsip_dialog **p_dlg);
  277. #if !DEPRECATED_FOR_TICKET_1902
  278. /**
  279. * Initialize UAS dialog from the information found in the incoming request
  280. * that creates a dialog (such as INVITE, REFER, or SUBSCRIBE), and set the
  281. * local Contact to contact. If contact is not specified, the local contact
  282. * is initialized from the URI in the To header in the request.
  283. *
  284. * This function will also create UAS transaction for the incoming request,
  285. * and associate the transaction to the rdata. Application can query the
  286. * transaction used to handle this request by calling #pjsip_rdata_get_tsx()
  287. * after this function returns.
  288. *
  289. * Note that initially, the session count in the dialog will be initialized
  290. * to zero.
  291. *
  292. *
  293. * @param ua The user agent module instance.
  294. * @param rdata The incoming request that creates the dialog,
  295. * such as INVITE, SUBSCRIBE, or REFER.
  296. * @param contact Optional dialog local Contact to be put as Contact
  297. * header value, hence the format must follow
  298. * RFC 3261 Section 20.10:
  299. * When the header field value contains a display
  300. * name, the URI including all URI parameters is
  301. * enclosed in "<" and ">". If no "<" and ">" are
  302. * present, all parameters after the URI are header
  303. * parameters, not URI parameters. The display name
  304. * can be tokens, or a quoted string, if a larger
  305. * character set is desired.
  306. * If this argument is NULL, the local contact will be
  307. * initialized from the value of To header in the
  308. * request.
  309. * @param p_dlg Pointer to receive the dialog.
  310. *
  311. * @return PJ_SUCCESS on success.
  312. */
  313. PJ_DECL(pj_status_t) pjsip_dlg_create_uas( pjsip_user_agent *ua,
  314. pjsip_rx_data *rdata,
  315. const pj_str_t *contact,
  316. pjsip_dialog **p_dlg);
  317. #endif
  318. /**
  319. * Initialize UAS dialog from the information found in the incoming request
  320. * that creates a dialog (such as INVITE, REFER, or SUBSCRIBE), and set the
  321. * local Contact to contact. If contact is not specified, the local contact
  322. * is initialized from the URI in the To header in the request.
  323. *
  324. * This function will also create UAS transaction for the incoming request,
  325. * and associate the transaction to the rdata. Application can query the
  326. * transaction used to handle this request by calling #pjsip_rdata_get_tsx()
  327. * after this function returns.
  328. *
  329. * Note that initially, the session count in the dialog will be initialized
  330. * to 1 (one), and the dialog is locked. Application needs to explicitly call
  331. * #pjsip_dlg_dec_lock() to release the lock and decrease the session count.
  332. *
  333. *
  334. * @param ua The user agent module instance.
  335. * @param rdata The incoming request that creates the dialog,
  336. * such as INVITE, SUBSCRIBE, or REFER.
  337. * @param contact Optional dialog local Contact to be put as Contact
  338. * header value, hence the format must follow
  339. * RFC 3261 Section 20.10:
  340. * When the header field value contains a display
  341. * name, the URI including all URI parameters is
  342. * enclosed in "<" and ">". If no "<" and ">" are
  343. * present, all parameters after the URI are header
  344. * parameters, not URI parameters. The display name
  345. * can be tokens, or a quoted string, if a larger
  346. * character set is desired.
  347. * If this argument is NULL, the local contact will be
  348. * initialized from the value of To header in the
  349. * request.
  350. * @param p_dlg Pointer to receive the dialog.
  351. *
  352. * @return PJ_SUCCESS on success.
  353. */
  354. PJ_DECL(pj_status_t)
  355. pjsip_dlg_create_uas_and_inc_lock( pjsip_user_agent *ua,
  356. pjsip_rx_data *rdata,
  357. const pj_str_t *contact,
  358. pjsip_dialog **p_dlg);
  359. /**
  360. * Lock/bind dialog to a specific transport/listener. This is optional,
  361. * as normally transport will be selected automatically based on the
  362. * destination of messages upon resolver completion. When the dialog is
  363. * explicitly bound to the specific transport/listener, all transactions
  364. * originated by this dialog will use the specified transport/listener
  365. * when sending outgoing requests.
  366. *
  367. * Note that this doesn't affect the Contact header generated by this
  368. * dialog. Application must manually update the Contact header if
  369. * necessary, to adjust the address according to the transport being
  370. * selected.
  371. *
  372. * @param dlg The dialog instance.
  373. * @param sel Transport selector containing the specification of
  374. * transport or listener to be used by this dialog
  375. * to send requests.
  376. *
  377. * @return PJ_SUCCESS on success, or the appropriate error code.
  378. */
  379. PJ_DECL(pj_status_t) pjsip_dlg_set_transport(pjsip_dialog *dlg,
  380. const pjsip_tpselector *sel);
  381. /**
  382. * Set the "sent-by" field of the Via header for outgoing requests.
  383. *
  384. * @param dlg The dialog instance.
  385. * @param via_addr Set via_addr to use for the Via header or NULL to use
  386. * the transport's published name.
  387. * @param via_tp via_addr will only be used if we are using via_tp
  388. * transport.
  389. *
  390. * @return PJ_SUCCESS on success.
  391. */
  392. PJ_DECL(pj_status_t) pjsip_dlg_set_via_sent_by(pjsip_dialog *dlg,
  393. pjsip_host_port *via_addr,
  394. pjsip_transport *via_tp);
  395. /**
  396. * Create a new (forked) dialog on receipt on forked response in rdata.
  397. * The new dialog will be created from original_dlg, except that it will have
  398. * new remote tag as copied from the To header in the response. Upon return,
  399. * the new_dlg will have been registered to the user agent. Applications just
  400. * need to add modules as dialog's usages.
  401. *
  402. * Note that initially, the session count in the dialog will be initialized
  403. * to zero.
  404. *
  405. * @param original_dlg The original UAC dialog.
  406. * @param rdata The incoming forked response message.
  407. * @param new_dlg Pointer to receive the new dialog.
  408. *
  409. * @return PJ_SUCCESS on success.
  410. */
  411. PJ_DECL(pj_status_t) pjsip_dlg_fork(const pjsip_dialog *original_dlg,
  412. const pjsip_rx_data *rdata,
  413. pjsip_dialog **new_dlg );
  414. /**
  415. * Forcefully terminate the dialog. Application can only call this function
  416. * when there is no session associated to the dialog. If there are sessions
  417. * that use this dialog, this function will refuse to terminate the dialog.
  418. * For this case, application MUST call the appropriate termination function
  419. * for each dialog session (e.g. #pjsip_inv_terminate() to terminate INVITE
  420. * session).
  421. *
  422. * @param dlg The dialog.
  423. *
  424. * @return PJ_SUCCESS if dialog has been terminated.
  425. */
  426. PJ_DECL(pj_status_t) pjsip_dlg_terminate( pjsip_dialog *dlg );
  427. /**
  428. * Set dialog's initial route set to route_set list. This can only be called
  429. * for UAC dialog, before any request is sent. After dialog has been
  430. * established, the route set can not be changed.
  431. *
  432. * For UAS dialog, the route set will be initialized in
  433. * pjsip_dlg_create_uas_and_inc_lock() from the Record-Route headers in
  434. * the incoming request.
  435. *
  436. * The route_set argument is standard list of Route headers (i.e. with
  437. * sentinel).
  438. *
  439. * @param dlg The UAC dialog.
  440. * @param route_set List of Route header.
  441. *
  442. * @return PJ_SUCCESS on success.
  443. */
  444. PJ_DECL(pj_status_t) pjsip_dlg_set_route_set( pjsip_dialog *dlg,
  445. const pjsip_route_hdr *route_set );
  446. /**
  447. * Increment the number of sessions in the dialog. Note that initially
  448. * (after created) the dialog has the session counter set to zero.
  449. *
  450. * @param dlg The dialog.
  451. * @param mod The module that increments the session counter.
  452. *
  453. * @return PJ_SUCCESS on success.
  454. */
  455. PJ_DECL(pj_status_t) pjsip_dlg_inc_session( pjsip_dialog *dlg,
  456. pjsip_module *mod);
  457. /**
  458. * Decrement the number of sessions in the dialog. Once the session counter
  459. * reach zero and there is no pending transaction, the dialog will be
  460. * destroyed. Note that this function may destroy the dialog immediately
  461. * if there is no pending transaction when this function is called.
  462. *
  463. * @param dlg The dialog.
  464. * @param mod The module that decrements the session counter.
  465. *
  466. * @return PJ_SUCCESS on success.
  467. */
  468. PJ_DECL(pj_status_t) pjsip_dlg_dec_session( pjsip_dialog *dlg,
  469. pjsip_module *mod);
  470. /**
  471. * Add a module as dialog usage, and optionally set the module specific data.
  472. *
  473. * @param dlg The dialog.
  474. * @param module The module to be registered as dialog usage.
  475. * @param mod_data Optional arbitrary data to be attached to dialog's
  476. * mod_data array at the module's index.
  477. *
  478. * @return PJ_SUCCESS on success.
  479. */
  480. PJ_DECL(pj_status_t) pjsip_dlg_add_usage( pjsip_dialog *dlg,
  481. pjsip_module *module,
  482. void *mod_data );
  483. /**
  484. * Check if the specified module has been registered as usage to the dialog.
  485. *
  486. * @param dlg The dialog.
  487. * @param module The module.
  488. *
  489. * @return PJ_TRUE if the specified module is currently
  490. * registered as a usage to the dialog.
  491. */
  492. PJ_DECL(pj_bool_t) pjsip_dlg_has_usage(pjsip_dialog *dlg,
  493. pjsip_module *module);
  494. /**
  495. * Attach module specific data to the dialog. Application can also set
  496. * the value directly by accessing dlg->mod_data[module_id].
  497. *
  498. * @param dlg The dialog
  499. * @param mod_id The ID of the module from which the data is to be
  500. * set to the dialog.
  501. * @param data Arbitrary data.
  502. *
  503. * @return PJ_SUCCESS on success.
  504. */
  505. PJ_DECL(pj_status_t) pjsip_dlg_set_mod_data( pjsip_dialog *dlg,
  506. int mod_id,
  507. void *data );
  508. /**
  509. * Get module specific data previously attached to the dialog. Application
  510. * can also get value directly by accessing dlg->mod_data[module_id].
  511. *
  512. * @param dlg The dialog
  513. * @param mod_id The ID of the module from which the data is to be
  514. * retrieved from the dialog.
  515. *
  516. * @return The data that was previously set, or NULL.
  517. */
  518. PJ_DECL(void*) pjsip_dlg_get_mod_data( pjsip_dialog *dlg,
  519. int mod_id);
  520. /**
  521. * Lock dialog and increment session counter termporarily, to prevent it
  522. * from being destroyed.
  523. *
  524. * @param dlg The dialog.
  525. */
  526. PJ_DECL(void) pjsip_dlg_inc_lock( pjsip_dialog *dlg );
  527. /**
  528. * Try to acquire dialog's lock, but return immediately if lock can not
  529. * be acquired.
  530. *
  531. * @param dlg The dialog.
  532. *
  533. * @return PJ_SUCCESS if lock has been acquired.
  534. */
  535. PJ_DECL(pj_status_t) pjsip_dlg_try_inc_lock( pjsip_dialog *dlg );
  536. /**
  537. * Unlock dialog and decrement temporary session counter. After this function
  538. * is called, dialog may be destroyed.
  539. *
  540. * @param dlg The dialog.
  541. */
  542. PJ_DECL(void) pjsip_dlg_dec_lock( pjsip_dialog *dlg );
  543. /**
  544. * Get the group lock for the SIP dialog. Note that prior to calling this
  545. * method, it is recommended to hold reference to the dialog
  546. * (e.g: call #pjsip_dlg_inc_session() or #pjsip_dlg_inc_lock()).
  547. *
  548. * @param dlg The dialog.
  549. *
  550. * @return The group lock.
  551. */
  552. PJ_DECL(pj_grp_lock_t *) pjsip_dlg_get_lock( pjsip_dialog *dlg );
  553. /**
  554. * Get the dialog instance in the incoming rdata. If an incoming message
  555. * matches an existing dialog, the user agent must have put the matching
  556. * dialog instance in the rdata, or otherwise this function will return
  557. * NULL if the message didn't match any existing dialog.
  558. *
  559. * This function can only be called after endpoint distributes the message
  560. * to the transaction layer or UA layer. In other words, application can
  561. * only call this function in the context of module that runs in priority
  562. * number higher than PJSIP_MOD_PRIORITY_UA_PROXY_LAYER.
  563. *
  564. * @param rdata Incoming message buffer.
  565. *
  566. * @return The dialog instance that "owns" the message.
  567. */
  568. PJ_DECL(pjsip_dialog*) pjsip_rdata_get_dlg( pjsip_rx_data *rdata );
  569. /**
  570. * Get the dialog instance for the outgoing tdata. Returns NULL if the message
  571. * wasn't sent from a dialog.
  572. *
  573. * @param tdata Outgoing message buffer.
  574. *
  575. * @return The dialog instance that "owns" the message.
  576. */
  577. PJ_DECL(pjsip_dialog*) pjsip_tdata_get_dlg( pjsip_tx_data *tdata );
  578. /**
  579. * Get the associated dialog for the specified transaction, if any.
  580. *
  581. * @param tsx The transaction.
  582. *
  583. * @return The dialog instance which has been registered
  584. * to the transaction as transaction user, or
  585. * NULL if the transaction is outside any dialogs.
  586. */
  587. PJ_DECL(pjsip_dialog*) pjsip_tsx_get_dlg( pjsip_transaction *tsx );
  588. /**
  589. * Create a basic/generic request with the specified method and optionally
  590. * specify the cseq. Use value -1 for cseq to have the dialog automatically
  591. * put next cseq number for the request. Otherwise for some requests,
  592. * e.q. CANCEL and ACK, application must put the CSeq in the original
  593. * INVITE request as the parameter.
  594. *
  595. * This function will also put Contact header where appropriate.
  596. *
  597. * @param dlg The dialog instance.
  598. * @param method The method of the request.
  599. * @param cseq Optional CSeq, which only needs to be specified
  600. * when creating ACK and CANCEL. For other requests,
  601. * specify -1 to use dialog's internal counter.
  602. * @param tdata Pointer to receive the request's transmit
  603. * data buffer.
  604. *
  605. * @return PJ_SUCCESS on success.
  606. */
  607. PJ_DECL(pj_status_t) pjsip_dlg_create_request( pjsip_dialog *dlg,
  608. const pjsip_method *method,
  609. int cseq,
  610. pjsip_tx_data **tdata);
  611. /**
  612. * Send request message to remote peer. If the request is not an ACK request,
  613. * the dialog will send the request statefully, by creating an UAC transaction
  614. * and send the request with the transaction.
  615. *
  616. * Also when the request is not ACK or CANCEL, the dialog will increment its
  617. * local cseq number and update the cseq in the request according to dialog's
  618. * cseq.
  619. *
  620. * If p_tsx is not null, this argument will be set with the transaction
  621. * instance that was used to send the request.
  622. *
  623. * This function will decrement the transmit data's reference counter
  624. * regardless the status of the operation.
  625. *
  626. * @param dlg The dialog.
  627. * @param tdata The request message to be sent.
  628. * @param mod_data_id Optional module data index to put an optional data
  629. * into the transaction. If no module data is to be
  630. * attached, this value should be -1.
  631. * @param mod_data Optional module data to be attached to the
  632. * transaction at mod_data_id index.
  633. *
  634. * @return PJ_SUCCESS on success.
  635. */
  636. PJ_DECL(pj_status_t) pjsip_dlg_send_request ( pjsip_dialog *dlg,
  637. pjsip_tx_data *tdata,
  638. int mod_data_id,
  639. void *mod_data);
  640. /**
  641. * Create a response message for the incoming request in rdata with status
  642. * code st_code and optional status text st_text. This function is different
  643. * than endpoint's API #pjsip_endpt_create_response() in that the dialog
  644. * function adds Contact header and Record-Routes headers in the response
  645. * where appropriate.
  646. *
  647. * @param dlg The dialog.
  648. * @param rdata The incoming request message for which the
  649. * response will be created.
  650. * @param st_code Status code.
  651. * @param st_text Optional string for custom status reason text.
  652. * @param tdata Pointer to receive the response message transmit
  653. * data buffer.
  654. *
  655. * @return PJ_SUCCESS on success.
  656. */
  657. PJ_DECL(pj_status_t) pjsip_dlg_create_response( pjsip_dialog *dlg,
  658. pjsip_rx_data *rdata,
  659. int st_code,
  660. const pj_str_t *st_text,
  661. pjsip_tx_data **tdata);
  662. /**
  663. * Modify previously sent response with other status code. Contact header
  664. * will be added when appropriate.
  665. *
  666. * @param dlg The dialog.
  667. * @param tdata The transmit data buffer containing response
  668. * message to be modified. Upon successful return,
  669. * the reference count will be incremented.
  670. * @param st_code New status code to be set.
  671. * @param st_text Optional string for custom status reason text.
  672. *
  673. * @return PJ_SUCCESS on success.
  674. */
  675. PJ_DECL(pj_status_t) pjsip_dlg_modify_response( pjsip_dialog *dlg,
  676. pjsip_tx_data *tdata,
  677. int st_code,
  678. const pj_str_t *st_text);
  679. /**
  680. * Send response message statefully. The transaction instance MUST be the
  681. * transaction that was reported on on_rx_request() callback.
  682. *
  683. * This function decrements the transmit data's reference counter regardless
  684. * the status of the operation.
  685. *
  686. * @param dlg The dialog.
  687. * @param tsx The UAS transaction associated with the incoming
  688. * request. If the request is within a dialog, or
  689. * a dialog has been created for the request that
  690. * creates the dialog, application can get the
  691. * transaction instance for the request by calling
  692. * #pjsip_rdata_get_tsx().
  693. * @param tdata Response message to be sent.
  694. *
  695. * @return PJ_SUCCESS on success.
  696. */
  697. PJ_DECL(pj_status_t) pjsip_dlg_send_response( pjsip_dialog *dlg,
  698. pjsip_transaction *tsx,
  699. pjsip_tx_data *tdata);
  700. /**
  701. * This composite function sends response message statefully to an incoming
  702. * request message inside dialog.
  703. *
  704. * @param dlg The endpoint instance.
  705. * @param rdata The incoming request message.
  706. * @param st_code Status code of the response.
  707. * @param st_text Optional status text of the response.
  708. * @param hdr_list Optional header list to be added to the response.
  709. * @param body Optional message body to be added to the response.
  710. *
  711. * @return PJ_SUCCESS if response message has successfully been
  712. * sent.
  713. */
  714. PJ_DECL(pj_status_t) pjsip_dlg_respond( pjsip_dialog *dlg,
  715. pjsip_rx_data *rdata,
  716. int st_code,
  717. const pj_str_t *st_text,
  718. const pjsip_hdr *hdr_list,
  719. const pjsip_msg_body *body );
  720. /**
  721. * Check if remote peer have the specified capability as published
  722. * in the dialog messages from remote peer.
  723. *
  724. * Notes:
  725. * - The capability \a token lookup will apply exact match, but not
  726. * case-sensitive, for example: <tt>"text/html"</tt> will not match
  727. * <tt>"text / html"</tt> (notice the spaces).
  728. *
  729. * @param dlg The dialog.
  730. * @param htype The header type to be checked, which value may be:
  731. * - PJSIP_H_ACCEPT
  732. * - PJSIP_H_ALLOW
  733. * - PJSIP_H_SUPPORTED
  734. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  735. * must be supplied in this argument. Otherwise the value
  736. * must be set to NULL.
  737. * @param token The capability token to check. For example, if \a htype
  738. * is PJSIP_H_ALLOW, then \a token specifies the method
  739. * names; if \a htype is PJSIP_H_SUPPORTED, then \a token
  740. * specifies the extension names such as "100rel".
  741. *
  742. * @return PJSIP_DIALOG_CAP_SUPPORTED if the specified capability
  743. * is explicitly supported, see pjsip_dialog_cap_status
  744. * for more info.
  745. */
  746. PJ_DECL(pjsip_dialog_cap_status) pjsip_dlg_remote_has_cap(
  747. pjsip_dialog *dlg,
  748. int htype,
  749. const pj_str_t *hname,
  750. const pj_str_t *token);
  751. /**
  752. * Get the specified capability header from the remote capability headers
  753. * stored in the dialog.
  754. *
  755. * @param dlg The dialog.
  756. * @param htype The header type to be retrieved, which value may be:
  757. * - PJSIP_H_ACCEPT
  758. * - PJSIP_H_ALLOW
  759. * - PJSIP_H_SUPPORTED
  760. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  761. * must be supplied in this argument. Otherwise the value
  762. * must be set to NULL.
  763. *
  764. * @return The appropriate header, or NULL if the header is not
  765. * available.
  766. */
  767. PJ_DECL(const pjsip_hdr*) pjsip_dlg_get_remote_cap_hdr(pjsip_dialog *dlg,
  768. int htype,
  769. const pj_str_t *hname);
  770. /**
  771. * Set remote capability from a SIP header containing array of capability
  772. * tags/values.
  773. *
  774. * @param dlg The dialog.
  775. * @param cap_hdr The SIP header.
  776. *
  777. * @return PJ_SUCCESS when successful, otherwise the appropriate
  778. * error code will be returned.
  779. */
  780. PJ_DECL(pj_status_t) pjsip_dlg_set_remote_cap_hdr(
  781. pjsip_dialog *dlg,
  782. const pjsip_generic_array_hdr *cap_hdr);
  783. /**
  784. * Remove a remote capability header.
  785. *
  786. * @param dlg The dialog.
  787. * @param htype The header type to be removed, which value may be:
  788. * - PJSIP_H_ACCEPT
  789. * - PJSIP_H_ALLOW
  790. * - PJSIP_H_SUPPORTED
  791. * @param hname If htype specifies PJSIP_H_OTHER, then the header name
  792. * must be supplied in this argument. Otherwise the value
  793. * must be set to NULL.
  794. *
  795. * @return PJ_SUCCESS when successful, otherwise the appropriate
  796. * error code will be returned.
  797. */
  798. PJ_DECL(pj_status_t) pjsip_dlg_remove_remote_cap_hdr(pjsip_dialog *dlg,
  799. int htype,
  800. const pj_str_t *hname);
  801. /**
  802. * Update remote capabilities from a received message. The header types
  803. * to be updated from the message will only be \a PJSIP_H_ACCEPT,
  804. * \a PJSIP_H_ALLOW, and \a PJSIP_H_SUPPORTED.
  805. *
  806. * @param dlg The dialog.
  807. * @param msg The received message.
  808. * @param strict If this is set to PJ_TRUE, any header types missing
  809. * from the message will cause removal of existing
  810. * header types in the capability list. Otherwise, the
  811. * capability list will not be modified when any header
  812. * type is missing.
  813. *
  814. * @return PJ_SUCCESS when successful, otherwise the appropriate
  815. * error code will be returned.
  816. */
  817. PJ_DECL(pj_status_t) pjsip_dlg_update_remote_cap(pjsip_dialog *dlg,
  818. const pjsip_msg *msg,
  819. pj_bool_t strict);
  820. /**
  821. * @}
  822. */
  823. /*
  824. * Internal (called by sip_ua_layer.c)
  825. */
  826. /** Internal: receives transaction event (called by user_agent module) */
  827. void pjsip_dlg_on_tsx_state( pjsip_dialog *dlg,
  828. pjsip_transaction *tsx,
  829. pjsip_event *e );
  830. /** Internal */
  831. void pjsip_dlg_on_rx_request( pjsip_dialog *dlg,
  832. pjsip_rx_data *rdata );
  833. /** Internal */
  834. void pjsip_dlg_on_rx_response( pjsip_dialog *dlg,
  835. pjsip_rx_data *rdata );
  836. PJ_END_DECL
  837. #endif /* __PJSIP_SIP_DIALOG_H__ */