int select_ruri(str* res, select_t* s, struct sip_msg* msg) { /* Parse the RURI even if it is not needed right now * because the nested select calls can access the * parsed URI in this case. * Go ahead even if the parsing fails, so the * value of the broken RURI can be accessed at least. * Subsequent select calls will fail when they try to parse * the URI anyway. (Miklos) */ if(parse_sip_msg_uri(msg)<0) { LM_ERR("failed to parse sip msg uri\n"); return -1; } if (msg->parsed_uri_ok) select_uri_p = &msg->parsed_uri; if (msg->first_line.type==SIP_REQUEST) { if(msg->new_uri.s) { RETURN0_res(msg->new_uri); } else { RETURN0_res(msg->first_line.u.request.uri); } } return -1; }
int select_ruri(str* res, select_t* s, struct sip_msg* msg) { if (msg->first_line.type==SIP_REQUEST) { if(msg->new_uri.s) { RETURN0_res(msg->new_uri); } else { RETURN0_res(msg->first_line.u.request.uri); } } return -1; }
/* Return the value of the "rn" parameter if exists, otherwise the user name. * The user name is normalized if needed, i.e. visual separators are removed, * the "rn" param is always normalized. */ int select_uri_rn_user(str* res, select_t* s, struct sip_msg* msg) { int ret; str val; if (select_uri_p == NULL) { if (parse_uri(res->s, res->len, &uri)<0) return -1; select_uri_p = &uri; } /* search for the "rn" parameter */ if ((ret = search_param(select_uri_p->params, "rn", 2, &val)) != 0) goto done; if (select_uri_p->sip_params.s != select_uri_p->params.s) { /* check also the original sip: URI parameters */ if ((ret = search_param(select_uri_p->sip_params, "rn", 2, &val)) != 0) goto done; } if ((select_uri_p->flags & URI_USER_NORMALIZE) == 0) RETURN0_res(select_uri_p->user); /* else normalize the user name */ val = select_uri_p->user; done: if (ret < 0) return -1; /* error */ if (!(res->s=get_static_buffer(val.len))) return -1; if ((res->len=normalize_tel_user(res->s, &val))==0) return 1; return 0; }
int select_uri_port(str* res, select_t* s, struct sip_msg* msg) { if (parse_uri(res->s, res->len, &uri)<0) return -1; RETURN0_res(uri.port); }
int select_uri_params(str* res, select_t* s, struct sip_msg* msg) { int ret; if (!msg || !res) { return select_any_params(res, s, msg); } if (select_uri_p == NULL) { if (parse_uri(res->s, res->len, &uri)<0) return -1; select_uri_p = &uri; } if (s->param_offset[select_level+1]-s->param_offset[select_level]==1) RETURN0_res(select_uri_p->params); *res=select_uri_p->params; ret = select_any_params(res, s, msg); if ((ret < 0) && (select_uri_p->sip_params.s != NULL) && (select_uri_p->sip_params.s != select_uri_p->params.s) ) { /* Search also in the original sip: uri parameters. */ *res = select_uri_p->sip_params; ret = select_any_params(res, s, msg); } return ret; }
int select_uri_port(str* res, select_t* s, struct sip_msg* msg) { if (select_uri_p == NULL) { if (parse_uri(res->s, res->len, &uri)<0) return -1; select_uri_p = &uri; } RETURN0_res(select_uri_p->port); }
int select_via_comment(str* res, select_t* s, struct sip_msg* msg) { struct via_body *p = NULL; // it's not neccessary to test if (s->n > 1) if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1; else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1; if (!p) return -1; RETURN0_res(p->comment); }
int select_rr_name(str* res, select_t* s, struct sip_msg* msg) { rr_t* r; if (parse_rr_header(msg)<0) return -1; r = get_rr(msg); if (!r) return 1; RETURN0_res(r->nameaddr.name); }
int select_contact_name(str* res, select_t* s, struct sip_msg* msg) { contact_t* c; if (parse_contact_header(msg)<0) return -1; c = get_contact(msg)->contacts; if (!c) return 1; RETURN0_res(c->name); }
int select_next_hop(str* res, select_t* s, struct sip_msg* msg) { if (msg->first_line.type==SIP_REQUEST) { if(msg->dst_uri.s) { RETURN0_res(msg->dst_uri); } else if(msg->new_uri.s) { if (msg->parsed_uri_ok) select_uri_p = &msg->parsed_uri; RETURN0_res(msg->new_uri); } else { if (msg->parsed_uri_ok) select_uri_p = &msg->parsed_uri; else if (msg->parsed_orig_ruri_ok) select_uri_p = &msg->parsed_orig_ruri; RETURN0_res(msg->first_line.u.request.uri); } } return -1; }
int select_uri_user(str* res, select_t* s, struct sip_msg* msg) { if (parse_uri(res->s, res->len, &uri)<0) return -1; if (uri.flags & URI_USER_NORMALIZE) { if (!(res->s=get_static_buffer(uri.user.len))) return -1; if ((res->len=normalize_tel_user(res->s, (&uri.user)))==0) return 1; return 0; } RETURN0_res(uri.user); }
int select_uri_params(str* res, select_t* s, struct sip_msg* msg) { if (!msg || !res) { return select_any_params(res, s, msg); } if (parse_uri(res->s, res->len, &uri)<0) return -1; if (s->param_offset[s->lvl+1]-s->param_offset[s->lvl]==1) RETURN0_res(uri.params); *res=uri.params; return select_any_params(res, s, msg); }
int select_auth(str* res, select_t* s, struct sip_msg* msg) { struct hdr_field* hdr; if (s->n != 2 && s->params[1].type != SEL_PARAM_STR) return -1; if (s->params[0].type != SEL_PARAM_DIV) { BUG("Last parameter should have type DIV (converted)\n"); return -1; } hdr = get_credentials(msg, s); if (!hdr) return -1; RETURN0_res(hdr->body); }
int select_expires(str* res, select_t* s, struct sip_msg* msg) { if (!msg->expires && (parse_headers(msg, HDR_EXPIRES_F, 0) == -1)) { return -1; /* error */ } if (!msg->expires) { return 1; /* null */ } if (msg->expires->parsed == NULL && parse_expires(msg->expires) < 0) { return -1; } RETURN0_res(((struct exp_body*)msg->expires->parsed)->text); }
int select_via_params(str* res, select_t* s, struct sip_msg* msg) { struct via_body *p = NULL; struct via_param *q; // it's not neccessary to test if (s->n > 1) if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1; else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1; if (!p) return -1; for (q = p->param_lst;q;q=q->next) { if ((q->name.len==s->params[s->n-1].v.s.len) && !strncasecmp(q->name.s, s->params[s->n-1].v.s.s,q->name.len)) { RETURN0_res(q->value); } } return 1; }
int select_contact_params(str* res, select_t* s, struct sip_msg* msg) { contact_t* c; param_t* p; if (parse_contact_header(msg)<0) return -1; c = get_contact(msg)->contacts; if (!c) return 1; p = c->params; while (p) { if ((p->name.len==s->params[s->n-1].v.s.len) && !strncasecmp(p->name.s, s->params[s->n-1].v.s.s,p->name.len)) { RETURN0_res(p->body) } p = p->next; } return 1; }
int select_rr_params(str* res, select_t* s, struct sip_msg* msg) { rr_t* r; param_t* p; if (parse_rr_header(msg)<0) return -1; r = get_rr(msg); if (!r) return 1; p = r->params; while (p) { if ((p->name.len==s->params[s->n-1].v.s.len) && !strncasecmp(p->name.s, s->params[s->n-1].v.s.s,p->name.len)) { RETURN0_res(p->body) } p = p->next; } return 0; }
int select_msg_first_line(str* res, select_t* s, struct sip_msg* msg) { RETURN0_res(msg->first_line.line); }
static int select_tm_uac_uri(str* res, select_t* s, struct sip_msg* msg) { SELECT_check_branch(s, msg); RETURN0_res(t->uac[BRANCH_NO(s)].uri); }
int select_auth_param(str* res, select_t* s, struct sip_msg* msg) { int ret; struct hdr_field* hdr; dig_cred_t* cred; if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1; ret = get_credentials(msg, s, &hdr); if (!hdr) return ret; cred = &((auth_body_t*)hdr->parsed)->digest; switch(s->params[s->n - 1].v.i) { case SEL_AUTH_USER: RETURN0_res(cred->username.user); case SEL_AUTH_DOMAIN: RETURN0_res(cred->username.domain); case SEL_AUTH_USERNAME: RETURN0_res(cred->username.whole); case SEL_AUTH_REALM: RETURN0_res(cred->realm); case SEL_AUTH_NONCE: RETURN0_res(cred->nonce); case SEL_AUTH_URI: RETURN0_res(cred->uri); case SEL_AUTH_CNONCE: RETURN0_res(cred->cnonce); case SEL_AUTH_NC: RETURN0_res(cred->nc); case SEL_AUTH_RESPONSE: RETURN0_res(cred->response); case SEL_AUTH_OPAQUE: RETURN0_res(cred->opaque); case SEL_AUTH_ALG: RETURN0_res(cred->alg.alg_str); case SEL_AUTH_QOP: RETURN0_res(cred->qop.qop_str); default: BUG("Unsupported digest credentials parameter in select\n"); return -1; } }
static int select_tm_method(str* res, select_t* s, struct sip_msg* msg) { SELECT_check(msg); RETURN0_res(t->method); }
int select_dst_uri(str* res, select_t* s, struct sip_msg* msg) { if (msg->first_line.type!=SIP_REQUEST) return -1; RETURN0_res(msg->dst_uri); }
int select_contact(str* res, select_t* s, struct sip_msg* msg) { if (parse_contact_header(msg)<0) return -1; RETURN0_res(msg->contact->body); }
int select_rr(str* res, select_t* s, struct sip_msg* msg) { if (parse_rr_header(msg)<0) return -1; RETURN0_res(msg->record_route->body); }
static int select_tm_uas_local_to_tag(str* res, select_t* s, struct sip_msg* msg) { SELECT_check(msg); RETURN0_res(t->uas.local_totag); }