| 39 | #include <string.h> |
| 40 | |
| 41 | int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val) |
| 42 | { |
| 43 | struct sr_module* t; |
| 44 | const param_export_t* param; |
| 45 | regex_t preg; |
| 46 | int mod_found, param_found, len; |
| 47 | char* reg; |
| 48 | int n; |
| 49 | |
| 50 | len = strlen(regex); |
| 51 | reg = pkg_malloc(len + 2 + 2 + 1); |
| 52 | if (reg == 0) { |
| 53 | LM_ERR("no pkg memory left\n"); |
| 54 | return -1; |
| 55 | } |
| 56 | reg[0] = '^'; |
| 57 | reg[1] = '('; |
| 58 | memcpy(reg + 2, regex, len); |
| 59 | reg[len + 2] = ')'; |
| 60 | reg[len + 3] = '$'; |
| 61 | reg[len + 4] = '\0'; |
| 62 | |
| 63 | if (regcomp(&preg, reg, REG_EXTENDED | REG_NOSUB | REG_ICASE)) { |
| 64 | LM_ERR("failed to compile regular expression\n"); |
| 65 | pkg_free(reg); |
| 66 | return -2; |
| 67 | } |
| 68 | |
| 69 | mod_found = 0; |
| 70 | |
| 71 | for(t = modules; t; t = t->next) { |
| 72 | if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) { |
| 73 | LM_DBG("%s matches module %s\n",regex, t->exports->name); |
| 74 | mod_found = 1; |
| 75 | param_found = 0; |
| 76 | |
| 77 | for(param=t->exports->params;param && param->name ; param++) { |
| 78 | |
| 79 | if (strcmp(name, param->name) == 0) { |
| 80 | param_found = 1; |
| 81 | |
| 82 | if (PARAM_TYPE_MASK(param->type) & type) { |
| 83 | LM_DBG("found <%s> in module %s [%s]\n", |
| 84 | name, t->exports->name, t->path); |
| 85 | |
| 86 | if (param->type&USE_FUNC_PARAM) { |
| 87 | n = ((param_func_t)(param->param_pointer))(type, val ); |
| 88 | if (n<0) |
| 89 | return -4; |
| 90 | } else { |
| 91 | switch(type) { |
| 92 | case STR_PARAM: |
| 93 | *((char**)(param->param_pointer)) = |
| 94 | strdup((char*)val); |
| 95 | break; |
| 96 | case INT_PARAM: |
| 97 | *((int*)(param->param_pointer)) = |
| 98 | (int)(long)val; |