/** * parses a "pipe_no:method" line * \return 0 on success */ static int parse_queue_params(char * line, rl_queue_params_t * params) { regmatch_t m[3]; int len; if (! params_inited && init_params()) return -1; if (regexec(&queue_params_regex, line, 3, m, 0)) { LM_ERR("invalid param tuple: %s\n", line); return -1; } LM_DBG("queue: [%.*s|%.*s]\n", RXLS(m, line, 1), RXLS(m, line, 2)); params->pipe = atoi(RXS(m, line, 1)); len = RXL(m, line, 2); params->method.s = (char *)pkg_malloc(len+1); if (params->method.s == 0) { LM_ERR("no memory left for method in params\n"); return -1; } params->method.len = len; memcpy(params->method.s, RXS(m, line, 2), len+1); return 0; }
/** * parses a "pipe_no:algorithm:bandwidth" line * \return 0 on success */ static int parse_pipe_params(char * line, pipe_params_t * params) { regmatch_t m[4]; str algo_str; if (! params_inited && init_params()) return -1; if (regexec(&pipe_params_regex, line, 4, m, 0)) { LM_ERR("invalid param tuple: %s\n", line); return -1; } LM_DBG("pipe: [%.*s|%.*s|%.*s]\n", RXLS(m, line, 1), RXLS(m, line, 2), RXLS(m, line, 3)); params->no = atoi(RXS(m, line, 1)); params->limit = atoi(RXS(m, line, 3)); algo_str.s = RXS(m, line, 2); algo_str.len = RXL(m, line, 2); if (str_map_str(algo_names, &algo_str, ¶ms->algo)) return -1; return 0; }
static int add_uac_params(modparam_t type, void *val) { regmatch_t m[UAC_MAX_PARAMS_NO]; char *p, *line = (char *)val; char *_s; int _l; unsigned int size; uac_reg_map_t *uac_param; str host; int port, proto; if (!params_inited && init_params()) return -1; if (regexec(&uac_params_regex, line, UAC_MAX_PARAMS_NO, m, 0)) { LM_ERR("invalid param: %s\n", (char *)val); return -1; } LM_DBG("registrar=[%.*s] AOR=[%.*s] auth_user=[%.*s] password=[%.*s]" " expire=[%.*s] proxy=[%.*s] contact=[%.*s] third_party=[%.*s]\n", RXLS(m, line, UAC_REGISTRAR_URI_PARAM), RXLS(m, line, UAC_AOR_URI_PARAM), RXLS(m, line, UAC_AUTH_USER_PARAM), RXLS(m, line, UAC_AUTH_PASSWORD_PARAM), RXLS(m, line, UAC_EXPIRES_PARAM), RXLS(m, line, UAC_PROXY_URI_PARAM), RXLS(m, line, UAC_CONTACT_URI_PARAM), RXLS(m, line, UAC_THIRD_PARTY_REGISTRANT_URI_PARAM)); size = sizeof(uac_reg_map_t) + RXL(m, line, 0); uac_param = (uac_reg_map_t *)pkg_malloc(size); if (!uac_param) { LM_ERR("oom\n"); return -1; } memset(uac_param, 0, size); p = (char*)(uac_param + 1); RX_L_S(m, line, UAC_REGISTRAR_URI_PARAM); if (parse_uri(_s, _l, &uri)<0) { LM_ERR("cannot parse registrar uri [%.*s]\n", _l, _s); return -1; } if (uri.user.s && uri.user.len) { LM_ERR("registrant uri must not have user [%.*s]\n", uri.user.len, uri.user.s); return -1; } uac_param->registrar_uri.len = _l; uac_param->registrar_uri.s = p; memcpy(p, _s, _l); p += _l; RX_L_S(m, line, UAC_PROXY_URI_PARAM); if (_l != 0) { if (parse_uri(_s, _l, &uri)<0) { LM_ERR("cannot parse proxy uri [%.*s]\n", _l, _s); return -1; } if (uri.user.s && uri.user.len) { LM_ERR("proxy uri must not have user [%.*s]\n", uri.user.len, uri.user.s); return -1; } uac_param->proxy_uri.len = _l; uac_param->proxy_uri.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_AOR_URI_PARAM); if (parse_uri(_s, _l, &uri)<0) { LM_ERR("cannot parse aor uri [%.*s]\n", _l, _s); return -1; } uac_param->to_uri.len = _l; uac_param->to_uri.s = p; memcpy(p, _s, _l); p += _l; uac_param->hash_code = core_hash(&uac_param->to_uri, NULL, reg_hsize); RX_L_S(m, line, UAC_THIRD_PARTY_REGISTRANT_URI_PARAM); if (_l != 0) { if (parse_uri(_s, _l, &uri)<0) { LM_ERR("cannot parse third party registrant uri [%.*s]\n", _l, _s); return -1; } uac_param->from_uri.len = _l; uac_param->from_uri.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_CONTACT_URI_PARAM); if (parse_uri(_s, _l, &uri)<0) { LM_ERR("cannot parse contact uri [%.*s]\n", _l, _s); return -1; } uac_param->contact_uri.len = _l; uac_param->contact_uri.s = p; memcpy(p, _s, _l); p += _l; RX_L_S(m, line, UAC_AUTH_USER_PARAM); if (_l) { uac_param->auth_user.len = _l; uac_param->auth_user.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_AUTH_PASSWORD_PARAM); if (_l) { uac_param->auth_password.len = _l; uac_param->auth_password.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_CONTACT_PARAMS_PARAM); if (_l) { if (*p == ';') { LM_ERR("contact params must start with ';'\n"); return -1; } uac_param->contact_params.len = _l; uac_param->contact_params.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_EXPIRES_PARAM); if (_l) { uac_param->expires.len = _l; uac_param->expires.s = p; memcpy(p, _s, _l); p += _l; } RX_L_S(m, line, UAC_FORCED_SOCKET_PARAM); if (_l) { if (parse_phostport(_s, _l, &host.s, &host.len, &port, &proto)<0) { LM_ERR("cannot parse forced socket [%.*s]\n", _l, _s); return -1; } uac_param->send_sock = grep_sock_info(&host, (unsigned short) port, (unsigned short) proto); } if (uac_params) uac_param->next = uac_params; uac_params = uac_param; return 0; }