dlg_hash.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * Copyright (C) 2006 Voice System SRL
  3. * Copyright (C) 2011 Carsten Bock, [email protected]
  4. *
  5. * This file is part of Kamailio, a free SIP server.
  6. *
  7. * Kamailio is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. /*!
  23. * \file
  24. * \brief Functions and definitions related to dialog creation and searching
  25. * \ingroup dialog
  26. * Module: \ref dialog
  27. */
  28. #ifndef _DIALOG_DLG_HASH_H_
  29. #define _DIALOG_DLG_HASH_H_
  30. #include "../../locking.h"
  31. #include "../../lib/kmi/mi.h"
  32. #include "../../timer.h"
  33. #include "../../atomic_ops.h"
  34. #include "dlg_timer.h"
  35. #include "dlg_cb.h"
  36. /* states of a dialog */
  37. #define DLG_STATE_UNCONFIRMED 1 /*!< unconfirmed dialog */
  38. #define DLG_STATE_EARLY 2 /*!< early dialog */
  39. #define DLG_STATE_CONFIRMED_NA 3 /*!< confirmed dialog without a ACK yet */
  40. #define DLG_STATE_CONFIRMED 4 /*!< confirmed dialog */
  41. #define DLG_STATE_DELETED 5 /*!< deleted dialog */
  42. /* events for dialog processing */
  43. #define DLG_EVENT_TDEL 1 /*!< transaction was destroyed */
  44. #define DLG_EVENT_RPL1xx 2 /*!< 1xx request */
  45. #define DLG_EVENT_RPL2xx 3 /*!< 2xx request */
  46. #define DLG_EVENT_RPL3xx 4 /*!< 3xx request */
  47. #define DLG_EVENT_REQPRACK 5 /*!< PRACK request */
  48. #define DLG_EVENT_REQACK 6 /*!< ACK request */
  49. #define DLG_EVENT_REQBYE 7 /*!< BYE request */
  50. #define DLG_EVENT_REQ 8 /*!< other requests */
  51. /* dialog internal flags only in memory */
  52. #define DLG_FLAG_NEW (1<<0) /*!< new dialog */
  53. #define DLG_FLAG_CHANGED (1<<1) /*!< dialog was changed */
  54. #define DLG_FLAG_HASBYE (1<<2) /*!< bye was received */
  55. #define DLG_FLAG_CALLERBYE (1<<4) /*!< bye from caller */
  56. #define DLG_FLAG_CALLEEBYE (1<<5) /*!< bye from callee */
  57. #define DLG_FLAG_LOCALDLG (1<<6) /*!< local dialog, unused */
  58. #define DLG_FLAG_CHANGED_VARS (1<<7) /*!< dialog-variables changed */
  59. /* dialog-variable flags (in addition to dialog-flags) */
  60. #define DLG_FLAG_DEL (1<<8) /*!< delete this var */
  61. #define DLG_FLAG_TM (1<<9) /*!< dialog is set in transaction */
  62. #define DLG_FLAG_EXPIRED (1<<10)/*!< dialog is expired */
  63. /* internal flags stored in db */
  64. #define DLG_IFLAG_TIMEOUTBYE (1<<0) /*!< send bye on time-out */
  65. #define DLG_IFLAG_KA_SRC (1<<1) /*!< send keep alive to src */
  66. #define DLG_IFLAG_KA_DST (1<<2) /*!< send keep alive to dst */
  67. #define DLG_IFLAG_TIMER_NORESET (1<<3) /*!< don't reset dialog timers on in-dialog messages reception */
  68. #define DLG_IFLAG_CSEQ_DIFF (1<<4) /*!< CSeq changed in dialog */
  69. #define DLG_CALLER_LEG 0 /*!< attribute that belongs to a caller leg */
  70. #define DLG_CALLEE_LEG 1 /*!< attribute that belongs to a callee leg */
  71. #define DLG_DIR_NONE 0 /*!< dialog has no direction */
  72. #define DLG_DIR_DOWNSTREAM 1 /*!< dialog has downstream direction */
  73. #define DLG_DIR_UPSTREAM 2 /*!< dialog has upstream direction */
  74. #define DLG_EVENTRT_START 0
  75. #define DLG_EVENTRT_END 1
  76. #define DLG_EVENTRT_FAILED 2
  77. #define DLG_EVENTRT_MAX 3
  78. /*! internal unique ide per dialog */
  79. typedef struct dlg_iuid {
  80. unsigned int h_id; /*!< id in the hash table entry (seq nr in slot) */
  81. unsigned int h_entry; /*!< index of hash table entry (the slot number) */
  82. } dlg_iuid_t;
  83. /*! entries in the dialog list */
  84. typedef struct dlg_cell
  85. {
  86. volatile int ref; /*!< reference counter */
  87. struct dlg_cell *next; /*!< next entry in the list */
  88. struct dlg_cell *prev; /*!< previous entry in the list */
  89. unsigned int h_id; /*!< id in the hash table entry (seq nr in slot) */
  90. unsigned int h_entry; /*!< index of hash table entry (the slot number) */
  91. unsigned int state; /*!< dialog state */
  92. unsigned int lifetime; /*!< dialog lifetime */
  93. unsigned int init_ts; /*!< init (creation) time (absolute UNIX ts)*/
  94. unsigned int start_ts; /*!< start time (absolute UNIX ts)*/
  95. unsigned int dflags; /*!< internal dialog memory flags */
  96. unsigned int iflags; /*!< internal dialog persistent flags */
  97. unsigned int sflags; /*!< script dialog persistent flags */
  98. unsigned int toroute; /*!< index of route that is executed on timeout */
  99. str toroute_name; /*!< name of route that is executed on timeout */
  100. unsigned int from_rr_nb; /*!< information from record routing */
  101. struct dlg_tl tl; /*!< dialog timer list */
  102. str callid; /*!< callid from SIP message */
  103. str from_uri; /*!< from uri from SIP message */
  104. str to_uri; /*!< to uri from SIP message */
  105. str req_uri; /*!< r-uri from SIP message */
  106. str tag[2]; /*!< from tags of caller and to tag of callee */
  107. str cseq[2]; /*!< CSEQ of caller and callee */
  108. str route_set[2]; /*!< route set of caller and callee */
  109. str contact[2]; /*!< contact of caller and callee */
  110. struct socket_info * bind_addr[2]; /*! binded address of caller and callee */
  111. struct dlg_head_cbl cbs; /*!< dialog callbacks */
  112. struct dlg_profile_link *profile_links; /*!< dialog profiles */
  113. struct dlg_var *vars; /*!< dialog variables */
  114. } dlg_cell_t;
  115. /*! entries in the main dialog table */
  116. typedef struct dlg_entry
  117. {
  118. struct dlg_cell *first; /*!< dialog list */
  119. struct dlg_cell *last; /*!< optimisation, end of the dialog list */
  120. unsigned int next_id; /*!< next id */
  121. gen_lock_t lock; /* mutex to access items in the slot */
  122. atomic_t locker_pid; /* pid of the process that holds the lock */
  123. int rec_lock_level; /* recursive lock count */
  124. } dlg_entry_t;
  125. /*! main dialog table */
  126. typedef struct dlg_table
  127. {
  128. unsigned int size; /*!< size of the dialog table */
  129. struct dlg_entry *entries; /*!< dialog hash table */
  130. } dlg_table_t;
  131. typedef struct dlg_ka {
  132. dlg_iuid_t iuid;
  133. ticks_t katime;
  134. unsigned iflags;
  135. struct dlg_ka *next;
  136. } dlg_ka_t;
  137. /*! global dialog table */
  138. extern dlg_table_t *d_table;
  139. /*!
  140. * \brief Set a dialog lock (re-entrant)
  141. * \param _table dialog table
  142. * \param _entry locked entry
  143. */
  144. #define dlg_lock(_table, _entry) \
  145. do { \
  146. int mypid; \
  147. mypid = my_pid(); \
  148. if (likely(atomic_get( &(_entry)->locker_pid) != mypid)) { \
  149. lock_get( &(_entry)->lock); \
  150. atomic_set( &(_entry)->locker_pid, mypid); \
  151. } else { \
  152. /* locked within the same process that executed us */ \
  153. (_entry)->rec_lock_level++; \
  154. } \
  155. } while(0)
  156. /*!
  157. * \brief Release a dialog lock
  158. * \param _table dialog table
  159. * \param _entry locked entry
  160. */
  161. #define dlg_unlock(_table, _entry) \
  162. do { \
  163. if (likely((_entry)->rec_lock_level == 0)) { \
  164. atomic_set( &(_entry)->locker_pid, 0); \
  165. lock_release( &(_entry)->lock); \
  166. } else { \
  167. /* recursive locked => decrease lock count */ \
  168. (_entry)->rec_lock_level--; \
  169. } \
  170. } while(0)
  171. /*!
  172. * \brief Unlink a dialog from the list without locking
  173. * \see unref_dlg_unsafe
  174. * \param d_entry unlinked entry
  175. * \param dlg unlinked dialog
  176. */
  177. static inline void unlink_unsafe_dlg(dlg_entry_t *d_entry, dlg_cell_t *dlg)
  178. {
  179. if (dlg->next)
  180. dlg->next->prev = dlg->prev;
  181. else
  182. d_entry->last = dlg->prev;
  183. if (dlg->prev)
  184. dlg->prev->next = dlg->next;
  185. else
  186. d_entry->first = dlg->next;
  187. dlg->next = dlg->prev = 0;
  188. return;
  189. }
  190. /*!
  191. * \brief Destroy a dialog, run callbacks and free memory
  192. * \param dlg destroyed dialog
  193. */
  194. void destroy_dlg(dlg_cell_t *dlg);
  195. /*!
  196. * \brief Initialize the global dialog table
  197. * \param size size of the table
  198. * \return 0 on success, -1 on failure
  199. */
  200. int init_dlg_table(unsigned int size);
  201. /*!
  202. * \brief Destroy the global dialog table
  203. */
  204. void destroy_dlg_table(void);
  205. /*!
  206. * \brief Create a new dialog structure for a SIP dialog
  207. * \param callid dialog callid
  208. * \param from_uri dialog from uri
  209. * \param to_uri dialog to uri
  210. * \param from_tag dialog from tag
  211. * \param req_uri dialog r-uri
  212. * \return created dialog structure on success, NULL otherwise
  213. */
  214. dlg_cell_t* build_new_dlg(str *callid, str *from_uri,
  215. str *to_uri, str *from_tag, str *req_uri);
  216. /*!
  217. * \brief Set the leg information for an existing dialog
  218. * \param dlg dialog
  219. * \param tag from tag or to tag
  220. * \param rr record-routing information
  221. * \param contact caller or callee contact
  222. * \param cseq CSEQ of caller or callee
  223. * \param leg must be either DLG_CALLER_LEG, or DLG_CALLEE_LEG
  224. * \return 0 on success, -1 on failure
  225. */
  226. int dlg_set_leg_info(dlg_cell_t *dlg, str* tag, str *rr, str *contact,
  227. str *cseq, unsigned int leg);
  228. /*!
  229. * \brief Update or set the CSEQ for an existing dialog
  230. * \param dlg dialog
  231. * \param leg must be either DLG_CALLER_LEG, or DLG_CALLEE_LEG
  232. * \param cseq CSEQ of caller or callee
  233. * \return 0 on success, -1 on failure
  234. */
  235. int dlg_update_cseq(dlg_cell_t *dlg, unsigned int leg, str *cseq);
  236. /*!
  237. * \brief Set time-out route
  238. * \param dlg dialog
  239. * \param route name of route
  240. * \return 0 on success, -1 on failure
  241. */
  242. int dlg_set_toroute(dlg_cell_t *dlg, str *route);
  243. /*!
  244. * \brief Lookup a dialog in the global list
  245. *
  246. * Note that the caller is responsible for decrementing (or reusing)
  247. * the reference counter by one again if a dialog has been found.
  248. * \param h_entry number of the hash table entry
  249. * \param h_id id of the hash table entry
  250. * \return dialog structure on success, NULL on failure
  251. */
  252. dlg_cell_t* dlg_lookup(unsigned int h_entry, unsigned int h_id);
  253. /*!
  254. * \brief Search and return dialog in the global list by iuid
  255. *
  256. * Note that the caller is responsible for decrementing (or reusing)
  257. * the reference counter by one again if a dialog has been found.
  258. * \param diuid internal unique id per dialog
  259. * \return dialog structure on success, NULL on failure
  260. */
  261. dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid);
  262. /*!
  263. * \brief Get dialog that correspond to CallId, From Tag and To Tag
  264. *
  265. * Get dialog that correspond to CallId, From Tag and To Tag.
  266. * See RFC 3261, paragraph 4. Overview of Operation:
  267. * "The combination of the To tag, From tag, and Call-ID completely
  268. * defines a peer-to-peer SIP relationship between [two UAs] and is
  269. * referred to as a dialog."
  270. * Note that the caller is responsible for decrementing (or reusing)
  271. * the reference counter by one again iff a dialog has been found.
  272. * \param callid callid
  273. * \param ftag from tag
  274. * \param ttag to tag
  275. * \param dir direction
  276. * \return dialog structure on success, NULL on failure
  277. */
  278. dlg_cell_t* get_dlg(str *callid, str *ftag, str *ttag, unsigned int *dir);
  279. /*!
  280. * \brief Search dialog that corresponds to CallId, From Tag and To Tag
  281. *
  282. * Get dialog that correspond to CallId, From Tag and To Tag.
  283. * See RFC 3261, paragraph 4. Overview of Operation:
  284. * "The combination of the To tag, From tag, and Call-ID completely
  285. * defines a peer-to-peer SIP relationship between [two UAs] and is
  286. * referred to as a dialog."
  287. * Note that the caller is responsible for decrementing (or reusing)
  288. * the reference counter by one again if a dialog has been found.
  289. * If the dialog is not found, the hash slot is left locked, to allow
  290. * linking the structure of a new dialog.
  291. * \param callid callid
  292. * \param ftag from tag
  293. * \param ttag to tag
  294. * \param dir direction
  295. * \return dialog structure on success, NULL on failure (and slot locked)
  296. */
  297. dlg_cell_t* search_dlg(str *callid, str *ftag, str *ttag, unsigned int *dir);
  298. /*!
  299. * \brief Lock hash table slot by call-id
  300. * \param callid call-id value
  301. */
  302. void dlg_hash_lock(str *callid);
  303. /*!
  304. * \brief Release hash table slot by call-id
  305. * \param callid call-id value
  306. */
  307. void dlg_hash_release(str *callid);
  308. /*!
  309. * \brief Link a dialog structure
  310. * \param dlg dialog
  311. * \param n extra increments for the reference counter
  312. * \param mode link in safe mode (0 - lock slot; 1 - don't)
  313. */
  314. void link_dlg(struct dlg_cell *dlg, int n, int mode);
  315. /*!
  316. * \brief Unreference a dialog with locking
  317. * \see unref_dlg_unsafe
  318. * \param dlg dialog
  319. * \param cnt decrement for the reference counter
  320. */
  321. void dlg_unref(dlg_cell_t *dlg, unsigned int cnt);
  322. /*!
  323. * \brief Refefence a dialog with locking
  324. * \see ref_dlg_unsafe
  325. * \param dlg dialog
  326. * \param cnt increment for the reference counter
  327. */
  328. void dlg_ref(dlg_cell_t *dlg, unsigned int cnt);
  329. /*!
  330. * \brief Release a dialog from ref counter by 1
  331. * \see dlg_unref
  332. * \param dlg dialog
  333. */
  334. void dlg_release(dlg_cell_t *dlg);
  335. /*!
  336. * \brief Update a dialog state according a event and the old state
  337. *
  338. * This functions implement the main state machine that update a dialog
  339. * state according a processed event and the current state. If necessary
  340. * it will delete the processed dialog. The old and new state are also
  341. * saved for reference.
  342. * \param dlg updated dialog
  343. * \param event current event
  344. * \param old_state old dialog state
  345. * \param new_state new dialog state
  346. * \param unref set to 1 when the dialog was deleted, 0 otherwise
  347. */
  348. void next_state_dlg(dlg_cell_t *dlg, int event,
  349. int *old_state, int *new_state, int *unref);
  350. /*!
  351. * \brief Output all dialogs via the MI interface
  352. * \param cmd_tree MI root node
  353. * \param param unused
  354. * \return a mi node with the dialog information, or NULL on failure
  355. */
  356. struct mi_root * mi_print_dlgs(struct mi_root *cmd, void *param );
  357. /*!
  358. * \brief Print a dialog context via the MI interface
  359. * \param cmd_tree MI command tree
  360. * \param param unused
  361. * \return mi node with the dialog information, or NULL on failure
  362. */
  363. struct mi_root * mi_print_dlgs_ctx(struct mi_root *cmd, void *param );
  364. /*!
  365. * \brief Terminate selected dialogs via the MI interface
  366. * \param cmd_tree MI command tree
  367. * \param param unused
  368. * \return mi node with the dialog information, or NULL on failure
  369. */
  370. struct mi_root * mi_terminate_dlgs(struct mi_root *cmd_tree, void *param );
  371. /*!
  372. * \brief Check if a dialog structure matches to a SIP message dialog
  373. * \param dlg dialog structure
  374. * \param callid SIP message Call-ID
  375. * \param ftag SIP message from tag
  376. * \param ttag SIP message to tag
  377. * \param dir direction of the message, if DLG_DIR_NONE it will set
  378. * \return 1 if dialog structure and message content matches, 0 otherwise
  379. */
  380. static inline int match_dialog(dlg_cell_t *dlg, str *callid,
  381. str *ftag, str *ttag, unsigned int *dir) {
  382. if (dlg->tag[DLG_CALLEE_LEG].len == 0) {
  383. // dialog to tag is undetermined ATM.
  384. if (*dir==DLG_DIR_DOWNSTREAM) {
  385. if (dlg->callid.len == callid->len &&
  386. dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
  387. strncmp(dlg->callid.s, callid->s, callid->len)==0 &&
  388. strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0) {
  389. return 1;
  390. }
  391. } else if (*dir==DLG_DIR_UPSTREAM) {
  392. if (dlg->callid.len == callid->len &&
  393. dlg->tag[DLG_CALLER_LEG].len == ttag->len &&
  394. strncmp(dlg->callid.s, callid->s, callid->len)==0 &&
  395. strncmp(dlg->tag[DLG_CALLER_LEG].s, ttag->s, ttag->len)==0) {
  396. return 1;
  397. }
  398. } else {
  399. if (dlg->callid.len != callid->len)
  400. return 0;
  401. if (dlg->tag[DLG_CALLER_LEG].len == ttag->len &&
  402. strncmp(dlg->tag[DLG_CALLER_LEG].s, ttag->s, ttag->len)==0 &&
  403. strncmp(dlg->callid.s, callid->s, callid->len)==0) {
  404. *dir = DLG_DIR_UPSTREAM;
  405. return 1;
  406. } else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
  407. strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
  408. strncmp(dlg->callid.s, callid->s, callid->len)==0) {
  409. *dir = DLG_DIR_DOWNSTREAM;
  410. return 1;
  411. }
  412. }
  413. } else {
  414. if (*dir==DLG_DIR_DOWNSTREAM) {
  415. if (dlg->callid.len == callid->len &&
  416. dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
  417. dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
  418. strncmp(dlg->callid.s, callid->s, callid->len)==0 &&
  419. strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
  420. strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0) {
  421. return 1;
  422. }
  423. } else if (*dir==DLG_DIR_UPSTREAM) {
  424. if (dlg->callid.len == callid->len &&
  425. dlg->tag[DLG_CALLEE_LEG].len == ftag->len &&
  426. dlg->tag[DLG_CALLER_LEG].len == ttag->len &&
  427. strncmp(dlg->callid.s, callid->s, callid->len)==0 &&
  428. strncmp(dlg->tag[DLG_CALLEE_LEG].s, ftag->s, ftag->len)==0 &&
  429. strncmp(dlg->tag[DLG_CALLER_LEG].s, ttag->s, ttag->len)==0) {
  430. return 1;
  431. }
  432. } else {
  433. if (dlg->callid.len != callid->len)
  434. return 0;
  435. if (dlg->tag[DLG_CALLEE_LEG].len == ftag->len &&
  436. dlg->tag[DLG_CALLER_LEG].len == ttag->len &&
  437. strncmp(dlg->tag[DLG_CALLEE_LEG].s, ftag->s, ftag->len)==0 &&
  438. strncmp(dlg->tag[DLG_CALLER_LEG].s, ttag->s, ttag->len)==0 &&
  439. strncmp(dlg->callid.s, callid->s, callid->len)==0) {
  440. *dir = DLG_DIR_UPSTREAM;
  441. return 1;
  442. } else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
  443. dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
  444. strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
  445. strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
  446. strncmp(dlg->callid.s, callid->s, callid->len)==0) {
  447. *dir = DLG_DIR_DOWNSTREAM;
  448. return 1;
  449. }
  450. /* if no ACK yet, might be a lookup of dlg from a TM callback that
  451. * runs on 200ok but with initial INVITE that has no to-tag */
  452. if(ttag->len==0 && dlg->state==DLG_STATE_CONFIRMED_NA
  453. && dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
  454. strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
  455. strncmp(dlg->callid.s, callid->s, callid->len)==0) {
  456. *dir = DLG_DIR_DOWNSTREAM;
  457. return 1;
  458. }
  459. }
  460. }
  461. return 0;
  462. }
  463. /*!
  464. * \brief Check if a downstream dialog structure matches a SIP message dialog
  465. * \param dlg dialog structure
  466. * \param callid SIP message callid
  467. * \param ftag SIP message from tag
  468. * \return 1 if dialog structure matches the SIP dialog, 0 otherwise
  469. */
  470. static inline int match_downstream_dialog(dlg_cell_t *dlg, str *callid, str *ftag)
  471. {
  472. if(dlg==NULL || callid==NULL)
  473. return 0;
  474. if (ftag==NULL) {
  475. if (dlg->callid.len!=callid->len ||
  476. strncmp(dlg->callid.s,callid->s,callid->len)!=0)
  477. return 0;
  478. } else {
  479. if (dlg->callid.len!=callid->len ||
  480. dlg->tag[DLG_CALLER_LEG].len!=ftag->len ||
  481. strncmp(dlg->callid.s,callid->s,callid->len)!=0 ||
  482. strncmp(dlg->tag[DLG_CALLER_LEG].s,ftag->s,ftag->len)!=0)
  483. return 0;
  484. }
  485. return 1;
  486. }
  487. /*!
  488. *
  489. */
  490. void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate);
  491. int dlg_ka_add(dlg_cell_t *dlg);
  492. int dlg_ka_run(ticks_t ti);
  493. int dlg_clean_run(ticks_t ti);
  494. /*!
  495. * \brief Update dialog lifetime - for internal callers.
  496. */
  497. int update_dlg_timeout(dlg_cell_t *, int);
  498. /*!
  499. * \brief Output a dialog via the MI interface
  500. * \param rpl MI node that should be filled
  501. * \param dlg printed dialog
  502. * \param with_context if 1 then the dialog context will be also printed
  503. * \return 0 on success, -1 on failure
  504. */
  505. int mi_print_dlg(struct mi_node *rpl, dlg_cell_t *dlg, int with_context);
  506. #endif