| 5843 | } |
| 5844 | |
| 5845 | static int pv_add_extra(const pv_export_t *e) |
| 5846 | { |
| 5847 | const char *p; |
| 5848 | const str_const *in; |
| 5849 | pv_extra_t *pvi = NULL; |
| 5850 | pv_extra_t *pvj = NULL; |
| 5851 | pv_extra_t *pvn = NULL; |
| 5852 | int found; |
| 5853 | |
| 5854 | if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE) |
| 5855 | { |
| 5856 | LM_ERR("invalid parameters\n"); |
| 5857 | return -1; |
| 5858 | } |
| 5859 | |
| 5860 | if(_pv_extra_list==0) |
| 5861 | { |
| 5862 | LM_DBG("extra items list is not initialized\n"); |
| 5863 | if(pv_init_extra_list()!=0) |
| 5864 | { |
| 5865 | LM_ERR("cannot intit extra list\n"); |
| 5866 | return -1; |
| 5867 | } |
| 5868 | } |
| 5869 | in = &(e->name); |
| 5870 | p = in->s; |
| 5871 | while(is_in_str(p,in) && is_pv_valid_char(*p)) |
| 5872 | p++; |
| 5873 | if(is_in_str(p,in)) |
| 5874 | { |
| 5875 | LM_ERR("invalid char [%c] in [%.*s]\n", *p, in->len, in->s); |
| 5876 | return -1; |
| 5877 | } |
| 5878 | found = 0; |
| 5879 | pvi = *_pv_extra_list; |
| 5880 | while(pvi) |
| 5881 | { |
| 5882 | if(pvi->pve.name.len > in->len) |
| 5883 | break; |
| 5884 | if(pvi->pve.name.len==in->len) |
| 5885 | { |
| 5886 | found = strncmp(pvi->pve.name.s, in->s, in->len); |
| 5887 | if(found>0) |
| 5888 | break; |
| 5889 | if(found==0) |
| 5890 | { |
| 5891 | LM_ERR("pvar [%.*s] already exists\n", in->len, in->s); |
| 5892 | return -1; |
| 5893 | } |
| 5894 | } |
| 5895 | pvj = pvi; |
| 5896 | pvi = pvi->next; |
| 5897 | } |
| 5898 | |
| 5899 | pvn = (pv_extra_t*)pkg_malloc(sizeof(pv_extra_t)); |
| 5900 | if(pvn==0) |
| 5901 | { |
| 5902 | LM_ERR("no more memory\n"); |
no test coverage detected