/** * Loads user carrier from subscriber table and stores it in an AVP. * * @param _msg the current SIP message * @param _user the user to determine the carrier data * @param _domain the domain to determine the domain data * @param _dstavp the name of the AVP where to store the carrier id * * @return 1 on success, -1 on failure */ int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user, gparam_t *_domain, gparam_t *_dstavp) { str user, domain; int_str avp_val; if (fixup_get_svalue(_msg, _user, &user)<0) { LM_ERR("cannot print the user\n"); return -1; } if (fixup_get_svalue(_msg, _domain, &domain)<0) { LM_ERR("cannot print the domain\n"); return -1; } /* get carrier id */ if ((avp_val.n = load_user_carrier(&user, &domain)) < 0) { LM_ERR("error in load user carrier"); return -1; } else { /* set avp */ if (add_avp(_dstavp->v.pve->spec->pvp.pvn.u.isname.type, _dstavp->v.pve->spec->pvp.pvn.u.isname.name, avp_val)<0) { LM_ERR("add AVP failed\n"); return -1; } } return 1; }
/** * Loads user carrier from subscriber table and stores it in an AVP. * * @param _msg the current SIP message * @param _user the user to determine the route tree * @param _domain the domain to determine the route tree * @param _dstavp the name of the AVP where to store the carrier tree id * * @return 1 on success, -1 on failure */ int cr_load_user_carrier(struct sip_msg * _msg, pv_elem_t *_user, pv_elem_t *_domain, struct multiparam_t *_dstavp) { str user; str domain; int_str avp_val; if (pv_printf_s(_msg, _user, &user)<0) { LM_ERR("cannot print the user\n"); return -1; } if (pv_printf_s(_msg, _domain, &domain)<0) { LM_ERR("cannot print the domain\n"); return -1; } /* get carrier id */ if ((avp_val.n = load_user_carrier(&user, &domain)) < 0) { LM_ERR("error in load user carrier"); return -1; } else { /* set avp ! */ if (add_avp(_dstavp->u.a.flags, _dstavp->u.a.name, avp_val)<0) { LM_ERR("add AVP failed\n"); return -1; } } return 1; }
/** * rewrites the request URI of msg by calculating a rule, using * crc32 for hashing. The request URI is used to determine tree node * the given _user is used to determine the routing tree. * * @param msg the current SIP message * @param _uri the URI to determine the route tree (string or pseudo-variable) * @param _domain the requested routing domain * * @return 1 on success, -1 on failure */ int user_route_uri(struct sip_msg * _msg, char * _uri, char * _domain) { pv_elem_t *model; str uri, user, str_domain, ruser, ruri; struct sip_uri puri; int carrier_id, domain, index; domain = (int)(long)_domain; struct rewrite_data * rd = NULL; struct carrier_tree * ct = NULL; if (!_uri) { LM_ERR("bad parameter\n"); return -1; } if (parse_sip_msg_uri(_msg) < 0) { return -1; } /* Retrieve uri from parameter */ model = (pv_elem_t*)_uri; if (pv_printf_s(_msg, model, &uri)<0) { LM_ERR("cannot print the format\n"); return -1; } if (parse_uri(uri.s, uri.len, &puri) < 0) { LM_ERR("Error while parsing URI\n"); return -5; } user = puri.user; str_domain = puri.host; ruser.s = _msg->parsed_uri.user.s; ruser.len = _msg->parsed_uri.user.len; ruri.s = _msg->parsed_uri.user.s; ruri.len = _msg->parsed_uri.user.len; do { rd = get_data(); } while (rd == NULL); if ((carrier_id = load_user_carrier(&user, &str_domain)) < 0) { release_data(rd); return -1; } else if (carrier_id == 0) { index = rd->default_carrier_index; } else { if ((ct = get_carrier_tree(carrier_id, rd)) == NULL) { if (fallback_default) { index = rd->default_carrier_index; } else { LM_ERR("desired routing tree with id %i doesn't exist\n", carrier_id); release_data(rd); return -1; } } else { index = ct->index; } } release_data(rd); return carrier_rewrite_msg(index, domain, &ruri, _msg, &ruser, shs_call_id, alg_crc32); }