2
0

dlg_profile.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright (C) 2008 Voice System SRL
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. /*!
  22. * \file
  23. * \brief Profile handling
  24. * \ingroup dialog
  25. * Module: \ref dialog
  26. */
  27. #ifndef _DIALOG_DLG_PROFILE_H_
  28. #define _DIALOG_DLG_PROFILE_H_
  29. #include <time.h>
  30. #include "../../parser/msg_parser.h"
  31. #include "../../lib/srutils/srjson.h"
  32. #include "../../lib/srutils/sruid.h"
  33. #include "../../locking.h"
  34. #include "../../str.h"
  35. #include "../../modules/tm/h_table.h"
  36. /*!
  37. * \file
  38. * \brief Profile related functions for the dialog module
  39. * \ingroup dialog
  40. * Module: \ref dialog
  41. */
  42. /*! dialog profile hash list */
  43. typedef struct dlg_profile_hash {
  44. str value; /*!< hash value */
  45. struct dlg_cell *dlg; /*!< dialog cell */
  46. char puid[SRUID_SIZE];
  47. int puid_len;
  48. time_t expires;
  49. int flags;
  50. struct dlg_profile_link *linker;
  51. struct dlg_profile_hash *next;
  52. struct dlg_profile_hash *prev;
  53. unsigned int hash; /*!< position in the hash table */
  54. } dlg_profile_hash_t;
  55. /*! list with links to dialog profiles */
  56. typedef struct dlg_profile_link {
  57. struct dlg_profile_hash hash_linker;
  58. struct dlg_profile_link *next;
  59. struct dlg_profile_table *profile;
  60. } dlg_profile_link_t;
  61. /*! dialog profile entry */
  62. typedef struct dlg_profile_entry {
  63. struct dlg_profile_hash *first;
  64. unsigned int content; /*!< content of the entry */
  65. } dlg_profile_entry_t;
  66. #define FLAG_PROFILE_REMOTE 1
  67. /*! dialog profile table */
  68. typedef struct dlg_profile_table {
  69. str name; /*!< name of the dialog profile */
  70. unsigned int size; /*!< size of the dialog profile */
  71. unsigned int has_value; /*!< 0 for profiles without value, otherwise it has a value */
  72. int flags; /*!< flags related to the profile */
  73. gen_lock_t lock; /*! lock for concurrent access */
  74. struct dlg_profile_entry *entries;
  75. struct dlg_profile_table *next;
  76. } dlg_profile_table_t;
  77. /*!
  78. * \brief Add profile definitions to the global list
  79. * \see new_dlg_profile
  80. * \param profiles profile name
  81. * \param has_value set to 0 for a profile without value, otherwise it has a value
  82. * \return 0 on success, -1 on failure
  83. */
  84. int add_profile_definitions( char* profiles, unsigned int has_value);
  85. /*!
  86. * \brief Destroy the global dialog profile list
  87. */
  88. void destroy_dlg_profiles(void);
  89. /*!
  90. * \brief Search a dialog profile in the global list
  91. * \note Linear search, this won't have the best performance for huge profile lists
  92. * \param name searched dialog profile
  93. * \return pointer to the profile on success, NULL otherwise
  94. */
  95. struct dlg_profile_table* search_dlg_profile(str *name);
  96. /*!
  97. * \brief Callback for cleanup of profile local vars
  98. * \param msg SIP message
  99. * \param flags unused
  100. * \param param unused
  101. * \return 1
  102. */
  103. int cb_profile_reset( struct sip_msg *msg, unsigned int flags, void *param );
  104. /*!
  105. * \brief Cleanup a profile
  106. * \param msg SIP message
  107. * \param flags unused
  108. * \param param unused
  109. * \return 1
  110. */
  111. int profile_cleanup(sip_msg_t *msg, unsigned int flags, void *param );
  112. /*!
  113. * \brief Destroy dialog linkers
  114. * \param linker dialog linker
  115. */
  116. void destroy_linkers(dlg_profile_link_t *linker);
  117. /*!
  118. * \brief Set the global variables to the current dialog
  119. * \param msg SIP message
  120. * \param dlg dialog cell
  121. */
  122. void set_current_dialog(sip_msg_t *msg, struct dlg_cell *dlg);
  123. /*!
  124. * \brief Set the dialog profile
  125. * \param msg SIP message
  126. * \param value value
  127. * \param profile dialog profile table
  128. * \return 0 on success, -1 on failure
  129. */
  130. int set_dlg_profile(sip_msg_t *msg, str *value,
  131. dlg_profile_table_t *profile);
  132. /*!
  133. * \brief Unset a dialog profile
  134. * \param msg SIP message
  135. * \param value value
  136. * \param profile dialog profile table
  137. * \return 1 on success, -1 on failure
  138. */
  139. int unset_dlg_profile(sip_msg_t *msg, str *value,
  140. dlg_profile_table_t *profile);
  141. /*!
  142. * \brief Check if a dialog belongs to a profile
  143. * \param msg SIP message
  144. * \param profile dialog profile table
  145. * \param value value
  146. * \return 1 on success, -1 on failure
  147. */
  148. int is_dlg_in_profile(sip_msg_t *msg, dlg_profile_table_t *profile,
  149. str *value);
  150. /*!
  151. * \brief Get the size of a profile
  152. * \param profile evaluated profile
  153. * \param value value
  154. * \return the profile size
  155. */
  156. unsigned int get_profile_size(dlg_profile_table_t *profile, str *value);
  157. /*!
  158. * \brief Output a profile via MI interface
  159. * \param cmd_tree MI command tree
  160. * \param param MI parameter
  161. * \return MI root output on success, NULL on failure
  162. */
  163. struct mi_root * mi_get_profile(struct mi_root *cmd_tree, void *param );
  164. /*!
  165. * \brief List the profiles via MI interface
  166. * \param cmd_tree MI command tree
  167. * \param param unused
  168. * \return MI root output on success, NULL on failure
  169. */
  170. struct mi_root * mi_profile_list(struct mi_root *cmd_tree, void *param );
  171. /*!
  172. * \brief return true if the messages belongs to a tracked dialog
  173. */
  174. int is_known_dlg(sip_msg_t *msg);
  175. /*!
  176. * \brief Adjust timeout in all dialogs within a profile.
  177. */
  178. int dlg_set_timeout_by_profile(struct dlg_profile_table *, str *, int);
  179. /*!
  180. * \brief Add dialog to a profile
  181. * \param dlg dialog
  182. * \param value value
  183. * \param profile dialog profile table
  184. * \return 0 on success, -1 on failure
  185. */
  186. int dlg_add_profile(dlg_cell_t *dlg, str *value, struct dlg_profile_table *profile,
  187. str *puid, time_t expires, int flags);
  188. /*!
  189. * \brief Serialize dialog profiles to json
  190. */
  191. int dlg_profiles_to_json(dlg_cell_t *dlg, srjson_doc_t *jdoc);
  192. /*!
  193. * \brief Deserialize dialog profiles to json
  194. */
  195. int dlg_json_to_profiles(dlg_cell_t *dlg, srjson_doc_t *jdoc);
  196. /*!
  197. * \brief Remove expired remove profiles
  198. */
  199. void remove_expired_remote_profiles(time_t te);
  200. /*!
  201. *
  202. */
  203. int dlg_cmd_remote_profile(str *cmd, str *pname, str *value, str *puid,
  204. time_t expires, int flags);
  205. #endif