Module: kamailio Branch: master Commit: e68bf3a73f02aeab9d4014f18c8b2195684c2399 URL: https://github.com/kamailio/kamailio/commit/e68bf3a73f02aeab9d4014f18c8b2195...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-05-02T09:09:35+02:00
core: helper functions to get str names for kemi types
---
Modified: kemi.c Modified: kemi.h
---
Diff: https://github.com/kamailio/kamailio/commit/e68bf3a73f02aeab9d4014f18c8b2195... Patch: https://github.com/kamailio/kamailio/commit/e68bf3a73f02aeab9d4014f18c8b2195...
---
diff --git a/kemi.c b/kemi.c index 7b08a83..d32843f 100644 --- a/kemi.c +++ b/kemi.c @@ -1014,3 +1014,63 @@ str* sr_kemi_cbname_lookup_idx(int idx) } return &_sr_kemi_cbname_list[idx-1].name; } + +/** + * + */ +typedef struct sr_kemi_param_map { + int ptype; + str pname; +} sr_kemi_param_map_t; + +/** + * + */ +static sr_kemi_param_map_t _sr_kemi_param_map[] = { + { SR_KEMIP_NONE, str_init("none") }, + { SR_KEMIP_INT, str_init("int") }, + { SR_KEMIP_STR, str_init("str") }, + { SR_KEMIP_BOOL, str_init("bool") }, + { 0, STR_NULL } +}; + +/** + * + */ +str *sr_kemi_param_map_get_name(int ptype) +{ + int i; + + for(i=0; _sr_kemi_param_map[i].pname.s!=NULL; i++) { + if(_sr_kemi_param_map[i].ptype==ptype) + return &_sr_kemi_param_map[i].pname; + } + return NULL; +} + +/** + * + */ +str *sr_kemi_param_map_get_params(int *ptypes) +{ + int i; + static char pbuf[64]; + static str sret = STR_NULL; + str *pn; + + pbuf[0] = '\0'; + for(i=0; i<SR_KEMI_PARAMS_MAX; i++) { + if(ptypes[i]==SR_KEMIP_NONE) break; + if(i>0) strcat(pbuf, ", "); + pn = sr_kemi_param_map_get_name(ptypes[i]); + if(pn==NULL) return NULL; + strcat(pbuf, pn->s); + } + if(pbuf[0]=='\0') { + pn = sr_kemi_param_map_get_name(SR_KEMIP_NONE); + strcat(pbuf, pn->s); + } + sret.s = pbuf; + sret.len = strlen(sret.s); + return &sret; +} diff --git a/kemi.h b/kemi.h index 57b14a0..0671518 100644 --- a/kemi.h +++ b/kemi.h @@ -120,4 +120,7 @@ str* sr_kemi_cbname_lookup_idx(int idx); void sr_kemi_act_ctx_set(run_act_ctx_t *ctx); run_act_ctx_t* sr_kemi_act_ctx_get(void);
+str *sr_kemi_param_map_get_name(int ptype); +str *sr_kemi_param_map_get_params(int *ptypes); + #endif