PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/usr_avp.h

https://gitlab.com/oded/kamailio
C Header | 222 lines | 117 code | 44 blank | 61 comment | 5 complexity | ebbe98230c12f9168662d8164651ff8b MD5 | raw file
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  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. #ifndef _SER_USR_AVP_H_
  22. #define _SER_USR_AVP_H_
  23. #include <sys/types.h>
  24. #include <regex.h>
  25. /*
  26. * LIST with the allocated flags, their meaning and owner
  27. * flag no. owner description
  28. * -------------------------------------------------------
  29. * 0 avp_core avp has a string name
  30. * 1 avp_core avp has a string value
  31. * 2 avp_core regex search in progress
  32. * 3 avpops module avp was loaded from DB
  33. * 4 lcr module contact avp qvalue change
  34. * 5 core avp is in user list
  35. * 6 core avp is in domain list
  36. * 7 core avp is in global list
  37. * 8 core avp is in the from avp list
  38. * 9 core avp is in the to avp list
  39. * 10 core avp name with positive index
  40. * 11 core avp name with negative index
  41. */
  42. #include "str.h"
  43. #define AVP_UID "uid" /* Unique user identifier */
  44. #define AVP_DID "did" /* Unique domain identifier */
  45. #define AVP_REALM "digest_realm" /* Digest realm */
  46. #define AVP_FR_TIMER "fr_timer" /* Value of final response timer */
  47. #define AVP_FR_INV_TIMER "fr_inv_timer" /* Value of final response invite timer */
  48. #define AVP_RPID "rpid" /* Remote-Party-ID */
  49. #define AVP_GFLAGS "gflags" /* global flags */
  50. struct str_int_data {
  51. str name;
  52. int val;
  53. };
  54. struct str_str_data {
  55. str name;
  56. str val;
  57. };
  58. typedef union {
  59. int n;
  60. str s;
  61. regex_t* re;
  62. } int_str;
  63. #define avp_id_t unsigned short
  64. #define avp_flags_t unsigned int
  65. #define avp_name_t int_str
  66. #define avp_value_t int_str
  67. #define avp_index_t unsigned short
  68. union usr_avp_data{
  69. void *p; /* forces alignment */
  70. long l;
  71. char data[sizeof(void*)]; /* used to access other types, var length */
  72. };
  73. typedef struct usr_avp {
  74. avp_id_t id;
  75. /* Flags that are kept for the AVP lifetime */
  76. avp_flags_t flags;
  77. struct usr_avp *next;
  78. union usr_avp_data d; /* var length */
  79. } avp_t;
  80. typedef avp_t* avp_list_t;
  81. /* AVP identification */
  82. typedef struct avp_ident {
  83. avp_flags_t flags;
  84. avp_name_t name;
  85. avp_index_t index;
  86. } avp_ident_t;
  87. /*
  88. * AVP search state
  89. */
  90. typedef struct search_state {
  91. avp_flags_t flags; /* Type of search and additional flags */
  92. avp_id_t id;
  93. avp_name_t name;
  94. avp_t* avp; /* Current AVP */
  95. // regex_t* search_re; /* Compiled regular expression */
  96. } avp_search_state_t;
  97. /* avp aliases structs*/
  98. typedef struct avp_spec {
  99. avp_flags_t type;
  100. avp_name_t name;
  101. avp_index_t index;
  102. } avp_spec_t;
  103. /* AVP types */
  104. #define AVP_NAME_STR (1<<0)
  105. #define AVP_VAL_STR (1<<1)
  106. #define AVP_NAME_RE (1<<2)
  107. /* AVP classes */
  108. #define AVP_CLASS_URI (1<<4)
  109. #define AVP_CLASS_USER (1<<5)
  110. #define AVP_CLASS_DOMAIN (1<<6)
  111. #define AVP_CLASS_GLOBAL (1<<7)
  112. /* AVP track (either from or to) */
  113. #define AVP_TRACK_FROM (1<<8)
  114. #define AVP_TRACK_TO (1<<9)
  115. #define AVP_TRACK_ALL (AVP_TRACK_FROM|AVP_TRACK_TO)
  116. #define AVP_CLASS_ALL (AVP_CLASS_URI|AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
  117. /* AVP name index */
  118. #define AVP_INDEX_FORWARD (1<<10)
  119. #define AVP_INDEX_BACKWARD (1<<11)
  120. #define AVP_INDEX_ALL (AVP_INDEX_FORWARD | AVP_INDEX_BACKWARD)
  121. /* AVP DB flag used by avpops module - defined in avpops
  122. * - kept here for reference */
  123. // #define AVP_IS_IN_DB (1<<12)
  124. #define AVP_CUSTOM_FLAGS 13
  125. #define GALIAS_CHAR_MARKER '$'
  126. #define AVP_NAME_VALUE_MASK 0x0007
  127. #define AVP_CORE_MASK 0x00ff
  128. #define AVP_SCRIPT_MASK 0xff00
  129. #define avp_core_flags(f) ((f)&0x00ff)
  130. #define avp_script_flags(f) (((f)<<8)&0xff00)
  131. #define avp_get_script_flags(f) (((f)&0xff00)>>8)
  132. #define is_avp_str_name(a) ((a)->flags&AVP_NAME_STR)
  133. #define is_avp_str_val(a) ((a)->flags&AVP_VAL_STR)
  134. #define AVP_IS_ASSIGNABLE(ident) ( ((ident).flags & AVP_NAME_RE) == 0 && (((ident).flags & AVP_NAME) == 0 || (((ident)->flags & AVP_NAME) && (ident).name.s.len)) )
  135. /* Initialize memory structures */
  136. int init_avps(void);
  137. /* add avp to the list of avps */
  138. int add_avp(avp_flags_t flags, avp_name_t name, avp_value_t val);
  139. int add_avp_before(avp_t *avp, avp_flags_t flags, avp_name_t name, avp_value_t val);
  140. int add_avp_list(avp_list_t* list, avp_flags_t flags, avp_name_t name, avp_value_t val);
  141. /* Delete avps with given type and name */
  142. void delete_avp(avp_flags_t flags, avp_name_t name);
  143. int destroy_avps(avp_flags_t flags, avp_name_t name, int all);
  144. /* search functions */
  145. avp_t *search_first_avp( avp_flags_t flags, avp_name_t name,
  146. avp_value_t *val, struct search_state* state);
  147. avp_t *search_avp_by_index( avp_flags_t flags, avp_name_t name,
  148. avp_value_t *val, avp_index_t index);
  149. avp_t *search_avp (avp_ident_t ident, avp_value_t* val, struct search_state* state);
  150. avp_t *search_next_avp(struct search_state* state, avp_value_t *val);
  151. /* Reset one avp list */
  152. int reset_avp_list(int flags);
  153. /* free functions */
  154. void reset_avps(void);
  155. void destroy_avp(avp_t *avp);
  156. void destroy_avp_list(avp_list_t *list );
  157. void destroy_avp_list_unsafe(avp_list_t *list );
  158. /* get func */
  159. void get_avp_val(avp_t *avp, avp_value_t *val );
  160. str* get_avp_name(avp_t *avp);
  161. avp_list_t get_avp_list(avp_flags_t flags);
  162. avp_list_t* set_avp_list(avp_flags_t flags, avp_list_t* list);
  163. /* global alias functions (manipulation and parsing)*/
  164. int add_avp_galias_str(char *alias_definition);
  165. int lookup_avp_galias(str *alias, int *type, int_str *avp_name);
  166. int add_avp_galias(str *alias, int type, int_str avp_name);
  167. int parse_avp_ident( str *name, avp_ident_t* attr);
  168. int parse_avp_name( str *name, int *type, int_str *avp_name, int *index);
  169. int parse_avp_spec( str *name, int *type, int_str *avp_name, int *index);
  170. int km_parse_avp_spec( str *name, int *type, int_str *avp_name);
  171. void free_avp_name( avp_flags_t *type, int_str *avp_name);
  172. /* Free an ident obtained with parse_avp_ident() */
  173. void free_avp_ident(avp_ident_t* attr);
  174. /* AVP flags functions */
  175. #define MAX_AVPFLAG ((unsigned int)( sizeof(avp_flags_t) * CHAR_BIT - 1 - AVP_CUSTOM_FLAGS))
  176. avp_flags_t register_avpflag(char* name);
  177. avp_flags_t get_avpflag_no(char* name);
  178. #endif