usr_avp.h
717bc5da
 /*
  * $Id$
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
717bc5da
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * History:
  * ---------
2be21e31
  *  2004-07-21  created (bogdan)
7dfb54d7
  *  2004-11-14  global aliases support added
d0fdbd45
  *  2005-02-14  list with FLAGS USAGE added (bogdan)
717bc5da
  */
 
3da52f21
 #ifndef _SER_USR_AVP_H_
 #define _SER_USR_AVP_H_
717bc5da
 
9d7f3515
 #include <sys/types.h>
 #include <regex.h>
 
 
d0fdbd45
 /*
  *   LIST with the allocated flags, their meaning and owner
  *   flag no.    owner            description
  *   -------------------------------------------------------
  *     0        avp_core          avp has a string name
  *     1        avp_core          avp has a string value
35f927fb
  *     2        avp_core          regex search in progress
d0fdbd45
  *     3        avpops module     avp was loaded from DB
75a0b581
  *     4        lcr module        contact avp qvalue change
35f927fb
  *     5        core              avp is in user list
  *     6        core              avp is in domain list
  *     7        core              avp is in global list
3da52f21
  *     8        core              avp is in the from avp list
  *     9        core              avp is in the to avp list
d0fdbd45
  *
  */
717bc5da
 
2be21e31
 #include "str.h"
 
35f927fb
 
598694f6
 #define AVP_UID          "uid"           /* Unique user identifier */
 #define AVP_DID          "did"           /* Unique domain identifier */
 #define AVP_REALM        "digest_realm"  /* Digest realm */
 #define AVP_FR_TIMER     "fr_timer"      /* Value of final response timer */
 #define AVP_FR_INV_TIMER "fr_inv_timer"  /* Value of final response invite timer */
 #define AVP_RPID         "rpid"          /* Remote-Party-ID */
3da52f21
 #define AVP_GFLAGS       "gflags"        /* global flags */
598694f6
 
9d7f3515
 struct str_int_data {
 	str name;
 	int val;
 };
 
 struct str_str_data {
 	str name;
 	str val;
 };
 
2be21e31
 typedef union {
 	int  n;
3da52f21
 	str  s;
9d7f3515
 	regex_t* re;
2be21e31
 } int_str;
 
717bc5da
 
35f927fb
 typedef struct usr_avp {
2be21e31
 	unsigned short id;
9d7f3515
 	     /* Flags that are kept for the AVP lifetime */
2be21e31
 	unsigned short flags;
717bc5da
 	struct usr_avp *next;
2be21e31
 	void *data;
35f927fb
 } avp_t;
 
3da52f21
 typedef avp_t* avp_list_t;
 
35f927fb
 
 /*
  * AVP search state
  */
 struct search_state {
 	unsigned short flags;  /* Type of search and additional flags */
 	unsigned short id;
 	int_str name;
 	avp_t* avp;            /* Current AVP */
 	regex_t* search_re;    /* Compiled regular expression */
717bc5da
 };
 
3da52f21
 /* avp aliases structs*/
7a2138c3
 typedef struct avp_spec {
3da52f21
 	int type;
 	int_str name;
7a2138c3
 } avp_spec_t;
7dfb54d7
 
3da52f21
 /* AVP types */
2be21e31
 #define AVP_NAME_STR     (1<<0)
 #define AVP_VAL_STR      (1<<1)
9d7f3515
 #define AVP_NAME_RE      (1<<2)
35f927fb
 
3da52f21
 /* AVP classes */
 #define AVP_CLASS_USER   (1<<5)
 #define AVP_CLASS_DOMAIN (1<<6)
 #define AVP_CLASS_GLOBAL (1<<7)
35f927fb
 
3da52f21
 /* AVP track (either from or to) */
 #define AVP_TRACK_FROM   (1<<8)
 #define AVP_TRACK_TO     (1<<9)
 #define AVP_TRACK_ALL    (AVP_TRACK_FROM|AVP_TRACK_TO)
35f927fb
 
3da52f21
 #define AVP_CLASS_ALL (AVP_CLASS_USER|AVP_CLASS_DOMAIN|AVP_CLASS_GLOBAL)
717bc5da
 
d34839a3
 #define GALIAS_CHAR_MARKER  '$'
 
3da52f21
 /* Initialize memory structures */
 int init_avps(void);
 
 /* add avp to the list of avps */
35f927fb
 int add_avp(unsigned short flags, int_str name, int_str val);
3da52f21
 int add_avp_list(avp_list_t* list, unsigned short flags, int_str name, int_str val);
717bc5da
 
3da52f21
 /* Delete avps with given type and name */
3d942590
 void delete_avp(unsigned short flags, int_str name);
598694f6
 
53c7e0f1
 /* search functions */
35f927fb
 avp_t *search_first_avp( unsigned short flags, int_str name,
 			 int_str *val, struct search_state* state);
 avp_t *search_next_avp(struct search_state* state, int_str *val);
590612d3
 
2be21e31
 /* free functions */
3da52f21
 void reset_avps(void);
35f927fb
 
 void destroy_avp(avp_t *avp);
3da52f21
 void destroy_avp_list(avp_list_t *list );
 void destroy_avp_list_unsafe(avp_list_t *list );
717bc5da
 
a564ae7a
 /* get func */
35f927fb
 void get_avp_val(avp_t *avp, int_str *val );
 str* get_avp_name(avp_t *avp);
 
3da52f21
 avp_list_t get_avp_list(unsigned short flags);
7a2138c3
 avp_list_t* set_avp_list(unsigned short flags, avp_list_t* list);
35f927fb
 
717bc5da
 
7dfb54d7
 /* global alias functions (manipulation and parsing)*/
 int add_avp_galias_str(char *alias_definition);
d34839a3
 int lookup_avp_galias(str *alias, int *type, int_str *avp_name);
7dfb54d7
 int add_avp_galias(str *alias, int type, int_str avp_name);
 int parse_avp_name( str *name, int *type, int_str *avp_name);
d34839a3
 int parse_avp_spec( str *name, int *type, int_str *avp_name);
717bc5da
 
 #endif