xavp.h
ef79b7be
 /*
  * $Id$
  *
  * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com) 
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * copyright notice and this permission notice appear in all copies.
  *
  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:
  * --------
  *  2009-05-20  created by daniel
  */
 
 
 #ifndef _SR_XAVP_H_
 #define _SR_XAVP_H_
 
 #ifdef WITH_XAVP
 
 #include <time.h>
 #include "str.h"
 
 struct _sr_xavp;
 
dccf5ede
 /* types for xavp values */
ef79b7be
 typedef enum {
 	SR_XTYPE_NULL=0,
dccf5ede
 	SR_XTYPE_INT,     /* integer value */
 	SR_XTYPE_STR,     /* str value */
 	SR_XTYPE_TIME,    /* timestamp value */
 	SR_XTYPE_LONG,    /* long value */
 	SR_XTYPE_LLONG,   /* long long value */
 	SR_XTYPE_XAVP,    /* xavp value */
 	SR_XTYPE_DATA     /* custom data value */
ef79b7be
 } sr_xtype_t;
 
 typedef void (*sr_xavp_sfree_f)(void *d);
 typedef void (*sr_data_free_f)(void *d, sr_xavp_sfree_f sfree);
 
dccf5ede
 /* structure custom data value */
ef79b7be
 typedef struct _sr_data {
 	void *p;
 	sr_data_free_f pfree;
 } sr_data_t;
 
dccf5ede
 /* avp value */
ef79b7be
 typedef struct _sr_xval {
dccf5ede
 	sr_xtype_t type;           /* type of the value */
ef79b7be
 	union {
 		int i;
dccf5ede
 		str s;                 /* cloned in shared memory */
ef79b7be
 		time_t t;
 		long l;
 		long long ll;
dccf5ede
 		struct _sr_xavp *xavp; /* must be given in shm (not cloned) */
 		sr_data_t *data;       /* must be given in shm (not cloned) */
ef79b7be
 	} v;
 } sr_xval_t;
 
dccf5ede
 /* structure for extended avp */
ef79b7be
 typedef struct _sr_xavp {
dccf5ede
 	unsigned int id;          /* internal hash id */
 	str name;                 /* name of the xavp */
 	sr_xval_t val;            /* value of the xavp */
 	struct _sr_xavp *next;    /* pointer to next xavp in list */
ef79b7be
 } sr_xavp_t;
 
 int xavp_init_head(void);
 void avpx_free(sr_xavp_t *xa);
 
6f31c603
 int xavp_add(sr_xavp_t *xavp, sr_xavp_t **list);
 int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list);
ef79b7be
 sr_xavp_t *xavp_add_value(str *name, sr_xval_t *val, sr_xavp_t **list);
aea40431
 sr_xavp_t *xavp_add_xavp_value(str *rname, str *name, sr_xval_t *val, sr_xavp_t **list);
ef79b7be
 sr_xavp_t *xavp_set_value(str *name, int idx, sr_xval_t *val, sr_xavp_t **list);
 sr_xavp_t *xavp_get(str *name, sr_xavp_t *start);
 sr_xavp_t *xavp_get_by_index(str *name, int idx, sr_xavp_t **start);
 sr_xavp_t *xavp_get_next(sr_xavp_t *start);
 int xavp_rm_by_name(str *name, int all, sr_xavp_t **head);
 int xavp_rm_by_index(str *name, int idx, sr_xavp_t **head);
 int xavp_rm(sr_xavp_t *xa, sr_xavp_t **head);
 int xavp_count(str *name, sr_xavp_t **start);
 void xavp_destroy_list_unsafe(sr_xavp_t **head);
 void xavp_destroy_list(sr_xavp_t **head);
 void xavp_reset_list(void);
 sr_xavp_t **xavp_set_list(sr_xavp_t **head);
 sr_xavp_t **xavp_get_crt_list(void);
 
6f31c603
 int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list);
 sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list);
 
ef79b7be
 void xavp_print_list(sr_xavp_t **head);
6f31c603
 
 sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold);
ef79b7be
 #endif
 
 #endif