~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to xavp.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <stdio.h>
28
28
#include <string.h>
29
29
 
 
30
#include "mem/mem.h"
30
31
#include "mem/shm_mem.h"
31
32
#include "dprint.h"
32
33
#include "hashes.h"
538
539
}
539
540
 
540
541
/**
 
542
 * returns a list of str with key names.
 
543
 * Example:
 
544
 * If we have this structure
 
545
 * $xavp(test=>one) = 1
 
546
 * $xavp(test[0]=>two) = "2"
 
547
 * $xavp(test[0]=>three) = 3
 
548
 * $xavp(test[0]=>four) = $xavp(whatever)
 
549
 * $xavp(test[0]=>two) = "other 2"
 
550
 *
 
551
 * xavp_get_list_keys_names(test[0]) returns
 
552
 * {"one", "two", "three", "four"}
 
553
 *
 
554
 * free the struct str_list afterwards
 
555
 * but do *NO* free the strings inside
 
556
 */
 
557
struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
 
558
{
 
559
        sr_xavp_t *avp = NULL;
 
560
        struct str_list *result = NULL;
 
561
        struct str_list *r = NULL;
 
562
        struct str_list *f = NULL;
 
563
        int total = 0;
 
564
 
 
565
        if(xavp==NULL){
 
566
                LM_ERR("xavp is NULL\n");
 
567
                return 0;
 
568
        }
 
569
 
 
570
        if(xavp->val.type!=SR_XTYPE_XAVP){
 
571
                LM_ERR("%s not xavp?\n", xavp->name.s);
 
572
                return 0;
 
573
        }
 
574
 
 
575
        avp = xavp->val.v.xavp;
 
576
 
 
577
        if (avp)
 
578
        {
 
579
                result = (struct str_list*)pkg_malloc(sizeof(struct str_list));
 
580
                if (result==NULL) {
 
581
                        PKG_MEM_ERROR;
 
582
                        return 0;
 
583
                }
 
584
                r = result;
 
585
                r->s.s = avp->name.s;
 
586
                r->s.len = avp->name.len;
 
587
                r->next = NULL;
 
588
                avp = avp->next;
 
589
        }
 
590
 
 
591
        while(avp)
 
592
        {
 
593
                f = result;
 
594
                while(f)
 
595
                {
 
596
                        if((avp->name.len==f->s.len)&&
 
597
                                (strncmp(avp->name.s, f->s.s, f->s.len)==0))
 
598
                        {
 
599
                                break; /* name already on list */
 
600
                        }
 
601
                        f = f->next;
 
602
                }
 
603
                if (f==NULL)
 
604
                {
 
605
                        r = append_str_list(avp->name.s, avp->name.len, &r, &total);
 
606
                        if(r==NULL){
 
607
                                while(result){
 
608
                                        r = result;
 
609
                                        result = result->next;
 
610
                                        pkg_free(r);
 
611
                                }
 
612
                                return 0;
 
613
                        }
 
614
                }
 
615
                avp = avp->next;
 
616
        }
 
617
        return result;
 
618
}
 
619
 
 
620
/**
541
621
 * clone the xavp without values that are custom data
542
622
 * - only one list level is cloned, other sublists are ignored
543
623
 */
707
787
        }
708
788
        return NULL;
709
789
}
 
790
 
 
791
/**
 
792
 * return child node of an xavp
 
793
 * - $xavp(rname=>cname)
 
794
 */
 
795
sr_xavp_t* xavp_get_child(str *rname, str *cname)
 
796
{
 
797
        sr_xavp_t *ravp=NULL;
 
798
 
 
799
        ravp = xavp_get(rname, NULL);
 
800
        if(ravp==NULL || ravp->val.type!=SR_XTYPE_XAVP)
 
801
                return NULL;
 
802
 
 
803
        return xavp_get(cname, ravp->val.v.xavp);
 
804
}
 
805
 
 
806
 
 
807
/**
 
808
 * return child node of an xavp if it has int value
 
809
 * - $xavp(rname=>cname)
 
810
 */
 
811
sr_xavp_t* xavp_get_child_with_ival(str *rname, str *cname)
 
812
{
 
813
        sr_xavp_t *vavp=NULL;
 
814
 
 
815
        vavp = xavp_get_child(rname, cname);
 
816
 
 
817
        if(vavp==NULL || vavp->val.type!=SR_XTYPE_INT)
 
818
                return NULL;
 
819
 
 
820
        return vavp;
 
821
}
 
822
 
 
823
 
 
824
/**
 
825
 * return child node of an xavp if it has string value
 
826
 * - $xavp(rname=>cname)
 
827
 */
 
828
sr_xavp_t* xavp_get_child_with_sval(str *rname, str *cname)
 
829
{
 
830
        sr_xavp_t *vavp=NULL;
 
831
 
 
832
        vavp = xavp_get_child(rname, cname);
 
833
 
 
834
        if(vavp==NULL || vavp->val.type!=SR_XTYPE_STR)
 
835
                return NULL;
 
836
 
 
837
        return vavp;
 
838
}
710
839
#endif