xavp.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * History:
  20. * --------
  21. * 2009-05-20 created by daniel
  22. */
  23. #ifndef _SR_XAVP_H_
  24. #define _SR_XAVP_H_
  25. #ifdef WITH_XAVP
  26. #include <time.h>
  27. #include "str.h"
  28. struct _sr_xavp;
  29. /* types for xavp values */
  30. typedef enum {
  31. SR_XTYPE_NULL=0,
  32. SR_XTYPE_INT, /* integer value */
  33. SR_XTYPE_STR, /* str value */
  34. SR_XTYPE_TIME, /* timestamp value */
  35. SR_XTYPE_LONG, /* long value */
  36. SR_XTYPE_LLONG, /* long long value */
  37. SR_XTYPE_XAVP, /* xavp value */
  38. SR_XTYPE_DATA /* custom data value */
  39. } sr_xtype_t;
  40. typedef void (*sr_xavp_sfree_f)(void *d);
  41. typedef void (*sr_data_free_f)(void *d, sr_xavp_sfree_f sfree);
  42. /* structure custom data value */
  43. typedef struct _sr_data {
  44. void *p;
  45. sr_data_free_f pfree;
  46. } sr_data_t;
  47. /* avp value */
  48. typedef struct _sr_xval {
  49. sr_xtype_t type; /* type of the value */
  50. union {
  51. int i;
  52. str s; /* cloned in shared memory */
  53. time_t t;
  54. long l;
  55. long long ll;
  56. struct _sr_xavp *xavp; /* must be given in shm (not cloned) */
  57. sr_data_t *data; /* must be given in shm (not cloned) */
  58. } v;
  59. } sr_xval_t;
  60. /* structure for extended avp */
  61. typedef struct _sr_xavp {
  62. unsigned int id; /* internal hash id */
  63. str name; /* name of the xavp */
  64. sr_xval_t val; /* value of the xavp */
  65. struct _sr_xavp *next; /* pointer to next xavp in list */
  66. } sr_xavp_t;
  67. int xavp_init_head(void);
  68. void avpx_free(sr_xavp_t *xa);
  69. int xavp_add(sr_xavp_t *xavp, sr_xavp_t **list);
  70. int xavp_add_last(sr_xavp_t *xavp, sr_xavp_t **list);
  71. sr_xavp_t *xavp_add_value(str *name, sr_xval_t *val, sr_xavp_t **list);
  72. sr_xavp_t *xavp_add_xavp_value(str *rname, str *name, sr_xval_t *val, sr_xavp_t **list);
  73. sr_xavp_t *xavp_set_value(str *name, int idx, sr_xval_t *val, sr_xavp_t **list);
  74. sr_xavp_t *xavp_get(str *name, sr_xavp_t *start);
  75. sr_xavp_t *xavp_get_by_index(str *name, int idx, sr_xavp_t **start);
  76. sr_xavp_t *xavp_get_next(sr_xavp_t *start);
  77. int xavp_rm_by_name(str *name, int all, sr_xavp_t **head);
  78. int xavp_rm_by_index(str *name, int idx, sr_xavp_t **head);
  79. int xavp_rm(sr_xavp_t *xa, sr_xavp_t **head);
  80. int xavp_count(str *name, sr_xavp_t **start);
  81. void xavp_destroy_list_unsafe(sr_xavp_t **head);
  82. void xavp_destroy_list(sr_xavp_t **head);
  83. void xavp_reset_list(void);
  84. sr_xavp_t **xavp_set_list(sr_xavp_t **head);
  85. sr_xavp_t **xavp_get_crt_list(void);
  86. int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list);
  87. sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list);
  88. void xavp_print_list(sr_xavp_t **head);
  89. sr_xavp_t *xavp_clone_level_nodata(sr_xavp_t *xold);
  90. #endif
  91. #endif