[sr-dev] git:master: core[xavp]: Added helper function to get a list of keys from a xavp variable.
Daniel-Constantin Mierla
miconda at gmail.com
Thu Apr 25 10:09:46 CEST 2013
Module: sip-router
Branch: master
Commit: 288e2739da28251e12086b52358c3a0d18e91fa5
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=288e2739da28251e12086b52358c3a0d18e91fa5
Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Mon Apr 22 10:46:17 2013 +0200
core[xavp]: Added helper function to get a list of keys from a xavp variable.
---
xavp.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xavp.h | 2 ++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/xavp.c b/xavp.c
index 6c8566d..adce5d1 100644
--- a/xavp.c
+++ b/xavp.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
+#include "mem/mem.h"
#include "mem/shm_mem.h"
#include "dprint.h"
#include "hashes.h"
@@ -538,6 +539,67 @@ void xavp_print_list(sr_xavp_t **head)
}
/**
+ * returns a list of str with key names.
+ * Example:
+ * If we have this structure
+ * $xavp(test=>one) = 1
+ * $xavp(test[0]=>two) = "2"
+ * $xavp(test[0]=>three) = 3
+ * $xavp(test[0]=>four) = $xavp(whatever)
+ *
+ * xavp_get_list_keys_names(test[0]) returns
+ * {"one", "two", "three", "four"}
+ */
+struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
+{
+ sr_xavp_t *avp = NULL;
+ struct str_list *result = NULL;
+ struct str_list *r = NULL;
+ int total = 0;
+
+ if(xavp==NULL){
+ LM_ERR("xavp is NULL\n");
+ return 0;
+ }
+
+ if(xavp->val.type!=SR_XTYPE_XAVP){
+ LM_ERR("%s not xavp?\n", xavp->name.s);
+ return 0;
+ }
+
+ avp = xavp->val.v.xavp;
+
+ if (avp)
+ {
+ result = (struct str_list*)pkg_malloc(sizeof(struct str_list));
+ if (result==NULL) {
+ PKG_MEM_ERROR;
+ return 0;
+ }
+ r = result;
+ r->s.s = avp->name.s;
+ r->s.len = avp->name.len;
+ r->next = NULL;
+ avp = avp->next;
+ }
+
+ while(avp)
+ {
+ r = append_str_list(avp->name.s, avp->name.len, &r, &total);
+ if(r==NULL){
+ while(result){
+ r = result;
+ result = result->next;
+ pkg_free(r);
+ }
+ return 0;
+ }
+ avp = avp->next;
+ }
+ return result;
+}
+
+/**
* clone the xavp without values that are custom data
* - only one list level is cloned, other sublists are ignored
*/
diff --git a/xavp.h b/xavp.h
index b581c08..7d5d517 100644
--- a/xavp.h
+++ b/xavp.h
@@ -29,6 +29,7 @@
#include <time.h>
#include "str.h"
+#include "str_list.h"
struct _sr_xavp;
@@ -95,6 +96,7 @@ 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);
+struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp);
int xavp_insert(sr_xavp_t *xavp, int idx, sr_xavp_t **list);
sr_xavp_t *xavp_extract(str *name, sr_xavp_t **list);
More information about the sr-dev
mailing list