usr_avp.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * History:
  28. * ---------
  29. * 2004-07-21 created (bogdan)
  30. * 2004-11-14 global aliases support added
  31. * 2005-02-14 list with FLAGS USAGE added (bogdan)
  32. */
  33. #ifndef _SER_USR_AVP_H_
  34. #define _SER_USR_AVP_H_
  35. #include <sys/types.h>
  36. #include <regex.h>
  37. /*
  38. * LIST with the allocated flags, their meaning and owner
  39. * flag no. owner description
  40. * -------------------------------------------------------
  41. * 0 avp_core avp has a string name
  42. * 1 avp_core avp has a string value
  43. * 2 avp_core regex search in progress
  44. * 3 avpops module avp was loaded from DB
  45. * 4 lcr module contact avp qvalue change
  46. * 5 core avp is in user list
  47. * 6 core avp is in domain list
  48. * 7 core avp is in global list
  49. * 8 core avp is in the from avp list
  50. * 9 core avp is in the to avp list
  51. * 10 core avp name with positive index
  52. * 11 core avp name with negative index
  53. */
  54. #include "str.h"
  55. #define AVP_UID "uid" /* Unique user identifier */
  56. #define AVP_DID "did" /* Unique domain identifier */
  57. #define AVP_REALM "digest_realm" /* Digest realm */
  58. #define AVP_FR_TIMER "fr_timer" /* Value of final response timer */
  59. #define AVP_FR_INV_TIMER "fr_inv_timer" /* Value of final response invite timer */
  60. #define AVP_RPID "rpid" /* Remote-Party-ID */
  61. #define AVP_GFLAGS "gflags" /* global flags */
  62. struct str_int_data {
  63. str name;
  64. int val;
  65. };
  66. struct str_str_data {
  67. str name;
  68. str val;
  69. };
  70. typedef union {
  71. int n;
  72. str s;
  73. regex_t* re;
  74. } int_str;
  75. #define avp_id_t unsigned short
  76. #define avp_flags_t unsigned int
  77. #define avp_name_t int_str
  78. #define avp_value_t int_str
  79. #define avp_index_t unsigned short
  80. union usr_avp_data{
  81. void *p; /* forces alignment */
  82. long l;
  83. char data[sizeof(void*)]; /* used to access other types, var length */
  84. };
  85. typedef struct usr_avp {
  86. avp_id_t id;
  87. /* Flags that are kept for the AVP lifetime */
  88. avp_flags_t flags;
  89. struct usr_avp *next;
  90. union usr_avp_data d; /* var length */
  91. } avp_t;
  92. typedef avp_t* avp_list_t;
  93. /* AVP identification */
  94. typedef struct avp_ident {
  95. avp_flags_t flags;
  96. avp_name_t name;
  97. avp_index_t index;
  98. } avp_ident_t;
  99. /*
  100. * AVP search state
  101. */
  102. typedef struct search_state {
  103. avp_flags_t flags; /* Type of search and additional flags */
  104. avp_id_t id;
  105. avp_name_t name;
  106. avp_t* avp; /* Current AVP */
  107. // regex_t* search_re; /* Compiled regular expression */
  108. } avp_search_state_t;
  109. /* avp aliases structs*/
  110. typedef struct avp_spec {
  111. avp_flags_t type;
  112. avp_name_t name;
  113. avp_index_t index;
  114. } avp_spec_t;
  115. /* AVP types */
  116. #define AVP_NAME_STR (1<<0)
  117. #define AVP_VAL_STR (1<<1)
  118. #define AVP_NAME_RE (1<<2)
  119. /* AVP classes */
  120. #define AVP_CLASS_URI (1<<4)
  121. #define AVP_CLASS_USER (1<<5)
  122. #define AVP_CLASS_DOMAIN (1<<6)
  123. #define AVP_CLASS_GLOBAL (1<<7)
  124. /* AVP track (either from or to) */
  125. #define AVP_TRACK_FROM (1<<8)
  126. #define AVP_TRACK_TO (1<<9)
  127. #define AVP_TRACK_ALL (AVP_TRACK_FROM|AVP_TRACK_TO)
  128. #define AVP_CLASS_ALL (AVP_CLASS_URI|AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
  129. /* AVP name index */
  130. #define AVP_INDEX_FORWARD (1<<10)
  131. #define AVP_INDEX_BACKWARD (1<<11)
  132. #define AVP_INDEX_ALL (AVP_INDEX_FORWARD | AVP_INDEX_BACKWARD)
  133. /* AVP DB flag used by avpops module - defined in avpops
  134. * - kept here for reference */
  135. // #define AVP_IS_IN_DB (1<<12)
  136. #define AVP_CUSTOM_FLAGS 13
  137. #define GALIAS_CHAR_MARKER '$'
  138. #define AVP_NAME_VALUE_MASK 0x0007
  139. #define AVP_CORE_MASK 0x00ff
  140. #define AVP_SCRIPT_MASK 0xff00
  141. #define avp_core_flags(f) ((f)&0x00ff)
  142. #define avp_script_flags(f) (((f)<<8)&0xff00)
  143. #define avp_get_script_flags(f) (((f)&0xff00)>>8)
  144. #define is_avp_str_name(a) ((a)->flags&AVP_NAME_STR)
  145. #define is_avp_str_val(a) ((a)->flags&AVP_VAL_STR)
  146. #define AVP_IS_ASSIGNABLE(ident) ( ((ident).flags & AVP_NAME_RE) == 0 && (((ident).flags & AVP_NAME) == 0 || (((ident)->flags & AVP_NAME) && (ident).name.s.len)) )
  147. /* Initialize memory structures */
  148. int init_avps(void);
  149. /* add avp to the list of avps */
  150. int add_avp(avp_flags_t flags, avp_name_t name, avp_value_t val);
  151. int add_avp_before(avp_t *avp, avp_flags_t flags, avp_name_t name, avp_value_t val);
  152. int add_avp_list(avp_list_t* list, avp_flags_t flags, avp_name_t name, avp_value_t val);
  153. /* Delete avps with given type and name */
  154. void delete_avp(avp_flags_t flags, avp_name_t name);
  155. int destroy_avps(avp_flags_t flags, avp_name_t name, int all);
  156. /* search functions */
  157. avp_t *search_first_avp( avp_flags_t flags, avp_name_t name,
  158. avp_value_t *val, struct search_state* state);
  159. avp_t *search_avp_by_index( avp_flags_t flags, avp_name_t name,
  160. avp_value_t *val, avp_index_t index);
  161. avp_t *search_avp (avp_ident_t ident, avp_value_t* val, struct search_state* state);
  162. avp_t *search_next_avp(struct search_state* state, avp_value_t *val);
  163. /* Reset one avp list */
  164. int reset_avp_list(int flags);
  165. /* free functions */
  166. void reset_avps(void);
  167. void destroy_avp(avp_t *avp);
  168. void destroy_avp_list(avp_list_t *list );
  169. void destroy_avp_list_unsafe(avp_list_t *list );
  170. /* get func */
  171. void get_avp_val(avp_t *avp, avp_value_t *val );
  172. str* get_avp_name(avp_t *avp);
  173. avp_list_t get_avp_list(avp_flags_t flags);
  174. avp_list_t* set_avp_list(avp_flags_t flags, avp_list_t* list);
  175. /* global alias functions (manipulation and parsing)*/
  176. int add_avp_galias_str(char *alias_definition);
  177. int lookup_avp_galias(str *alias, int *type, int_str *avp_name);
  178. int add_avp_galias(str *alias, int type, int_str avp_name);
  179. int parse_avp_ident( str *name, avp_ident_t* attr);
  180. int parse_avp_name( str *name, int *type, int_str *avp_name, int *index);
  181. int parse_avp_spec( str *name, int *type, int_str *avp_name, int *index);
  182. int km_parse_avp_spec( str *name, int *type, int_str *avp_name);
  183. void free_avp_name( avp_flags_t *type, int_str *avp_name);
  184. /* Free an ident obtained with parse_avp_ident() */
  185. void free_avp_ident(avp_ident_t* attr);
  186. /* AVP flags functions */
  187. #define MAX_AVPFLAG ((unsigned int)( sizeof(avp_flags_t) * CHAR_BIT - 1 - AVP_CUSTOM_FLAGS))
  188. avp_flags_t register_avpflag(char* name);
  189. avp_flags_t get_avpflag_no(char* name);
  190. #endif