static int xl_get_ruri(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) /* REPLY doesnt have a ruri */ return xl_get_null(msg, res, hp, hi, hf); if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) { LOG(L_ERR, "XLOG: xl_get_ruri: ERROR while parsing the R-URI\n"); return xl_get_null(msg, res, hp, hi, hf); } if (msg->new_uri.s!=NULL) { res->s = msg->new_uri.s; res->len = msg->new_uri.len; } else { res->s = msg->first_line.u.request.uri.s; res->len = msg->first_line.u.request.uri.len; } return 0; }
static int xl_get_contact(struct sip_msg* msg, str* res) { if(msg==NULL || res==NULL) return -1; if(msg->contact==NULL && parse_headers(msg, HDR_CONTACT, 0)==-1) { DBG("XLOG: xl_get_contact: no contact header\n"); return xl_get_null(msg, res); } if(!msg->contact || !msg->contact->body.s || msg->contact->body.len<=0) { DBG("XLOG: xl_get_contact: no contact header!\n"); return xl_get_null(msg, res); } res->s = msg->contact->body.s; res->len = msg->contact->body.len; // res->s = ((struct to_body*)msg->contact->parsed)->uri.s; // res->len = ((struct to_body*)msg->contact->parsed)->uri.len; return 0; }
static int xl_get_ruri(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) /* REPLYs dont have a ruri */ return xl_get_null(msg, res); if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) { LOG(L_ERR, "XLOG: xl_get_ruri: ERROR while parsing the R-URI\n"); return xl_get_null(msg, res); } res->s = msg->parsed_uri.user.len>0 ? msg->parsed_uri.user.s : msg->parsed_uri.host.s; res->len = msg->parsed_uri.user.len+ msg->parsed_uri.passwd.len+ msg->parsed_uri.host.len+ msg->parsed_uri.port.len+ msg->parsed_uri.params.len+ msg->parsed_uri.headers.len+ (msg->parsed_uri.user.len>0?1:0)+ (msg->parsed_uri.passwd.len>0?1:0)+ (msg->parsed_uri.port.len>0?1:0)+ (msg->parsed_uri.params.len>0?1:0)+ (msg->parsed_uri.headers.len>0?1:0); return 0; }
static int xl_get_select(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { int i; if ((i=run_select(res, (select_t*)hp->s, msg))==1) return xl_get_null(msg, res, hp, hi, hf); return i; }
static int xl_get_to(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->to==NULL && parse_headers(msg, HDR_TO, 0)==-1) { LOG(L_ERR, "XLOG: xl_get_to: ERROR cannot parse TO header\n"); return xl_get_null(msg, res); } if(msg->to==NULL || get_to(msg)==NULL) return xl_get_null(msg, res); res->s = get_to(msg)->uri.s; res->len = get_to(msg)->uri.len; return 0; }
static int xl_get_refer_to(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(parse_refer_to_header(msg)==-1) { LOG(L_ERR, "XLOG: xl_get_refer_to: ERROR cannot parse Refer-To header\n"); return xl_get_null(msg, res, hp, hi, hf); } if(msg->refer_to==NULL || get_refer_to(msg)==NULL) return xl_get_null(msg, res, hp, hi, hf); res->s = get_refer_to(msg)->uri.s; res->len = get_refer_to(msg)->uri.len; return 0; }
static int xl_get_from(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(parse_from_header(msg)==-1) { LOG(L_ERR, "XLOG: xl_get_from: ERROR cannot parse FROM header\n"); return xl_get_null(msg, res); } if(msg->from==NULL || get_from(msg)==NULL) return xl_get_null(msg, res); res->s = get_from(msg)->uri.s; res->len = get_from(msg)->uri.len; return 0; }
static int xl_get_to_tag(struct sip_msg* msg, str* res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(msg->to==NULL && ((parse_headers(msg, HDR_TO_F, 0)==-1) || (msg->to==NULL)) ) { LOG(L_ERR, "XLOG: xl_get_to: ERROR cannot parse TO header\n"); return xl_get_null(msg, res, hp, hi, hf); } if (get_to(msg)->tag_value.len <= 0) return xl_get_null(msg, res, hp, hi, hf); res->s = get_to(msg)->tag_value.s; res->len = get_to(msg)->tag_value.len; return 0; }
static int xl_get_from_tag(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(parse_from_header(msg)==-1) { LOG(L_ERR, "XLOG: xl_get_from: ERROR cannot parse FROM header\n"); return xl_get_null(msg, res, hp, hi, hf); } if(msg->from==NULL || get_from(msg)==NULL || get_from(msg)->tag_value.s==NULL) return xl_get_null(msg, res, hp, hi, hf); res->s = get_from(msg)->tag_value.s; res->len = get_from(msg)->tag_value.len; return 0; }
static int xl_get_dset(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; res->s = print_dset(msg, &res->len); if ((res->s) == NULL) return xl_get_null(msg, res, hp, hi, hf); res->len -= CRLF_LEN; return 0; }
static int xl_get_rcvport(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(msg->rcv.bind_address==NULL || msg->rcv.bind_address->port_no_str.s==NULL) return xl_get_null(msg, res, hp, hi, hf); res->s = msg->rcv.bind_address->port_no_str.s; res->len = msg->rcv.bind_address->port_no_str.len; return 0; }
static int xl_get_branch(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { str branch; qvalue_t q; if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) return xl_get_null(msg, res, hp, hi, hf); init_branch_iterator(); branch.s = next_branch(&branch.len, &q, 0, 0, 0); if (!branch.s) { return xl_get_null(msg, res, hp, hi, hf); } res->s = branch.s; res->len = branch.len; return 0; }
static int xl_get_status(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) { res->s = msg->first_line.u.reply.status.s; res->len = msg->first_line.u.reply.status.len; } else return xl_get_null(msg, res, hp, hi, hf); return 0; }
static int xl_get_reason(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) { res->s = msg->first_line.u.reply.reason.s; res->len = msg->first_line.u.reply.reason.len; } else return xl_get_null(msg, res); return 0; }
static int xl_get_method(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REQUEST) { res->s = msg->first_line.u.request.method.s; res->len = msg->first_line.u.request.method.len; } else return xl_get_null(msg, res); return 0; }
static int xl_get_cseq(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->cseq==NULL && parse_headers(msg, HDR_CSEQ, 0)==-1) { LOG(L_ERR, "XLOG: xl_get_cseq: ERROR cannot parse CSEQ header\n"); return xl_get_null(msg, res); } res->s = get_cseq(msg)->number.s; res->len = get_cseq(msg)->number.len; return 0; }
static int xl_get_useragent(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { if(msg==NULL || res==NULL) return -1; if(msg->user_agent==NULL && ((parse_headers(msg, HDR_USERAGENT_F, 0)==-1) || (msg->user_agent==NULL))) { DBG("XLOG: xl_get_useragent: User-Agent header not found\n"); return xl_get_null(msg, res, hp, hi, hf); } res->s = msg->user_agent->body.s; res->len = msg->user_agent->body.len; trim(res); return 0; }
static int xl_get_callid(struct sip_msg *msg, str *res) { if(msg==NULL || res==NULL) return -1; if(msg->callid==NULL && parse_headers(msg, HDR_CALLID, 0)==-1) { LOG(L_ERR, "XLOG: xl_get_cseq: ERROR cannot parse Call-Id header\n"); return xl_get_null(msg, res); } res->s = msg->callid->body.s; res->len = msg->callid->body.len; trim(res); return 0; }
static int xl_get_host(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { switch (hi) { case XL_HOST_NAME: *res = str_hostname; return 0; case XL_HOST_DOMAIN: *res = str_domainname; return 0; case XL_HOST_FULL: *res = str_fullname; return 0; case XL_HOST_IPADDR: *res = str_ipaddr; return 0; default: return xl_get_null(msg, res, hp, hi, hf); } }
static int xl_get_avp(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { int_str name, val; struct usr_avp *avp, *lavp; struct search_state st; if(msg==NULL || res==NULL || hp==NULL) return -1; name.s=*hp; if (0){ lavp=NULL; for(avp=search_first_avp(AVP_NAME_STR, name, NULL, &st); avp; avp=search_next_avp(&st, NULL)) { lavp=avp; if (hi>0) hi--; else if (hi==0) break; } if (lavp && (hi<=0)) { get_avp_val(lavp, &val); *res=val.s; return 0; } } if ((avp=search_avp_by_index(hf, name, &val, hi))) { if (avp->flags & AVP_VAL_STR) { *res=val.s; } else { res->s=int2str(val.n, &res->len); } return 0; } return xl_get_null(msg, res, hp, hi, hf); }
static int xl_get_branches(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { str uri; qvalue_t q; int len, cnt, i; unsigned int qlen; char *p, *qbuf; if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) return xl_get_null(msg, res, hp, hi, hf); cnt = len = 0; init_branch_iterator(); while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0))) { cnt++; len += uri.len; if (q != Q_UNSPECIFIED) { len += 1 + Q_PARAM_LEN + len_q(q); } } if (cnt == 0) return xl_get_empty(msg, res, hp, hi, hf); len += (cnt - 1) * XLOG_FIELD_DELIM_LEN; if (len + 1 > LOCAL_BUF_SIZE) { LOG(L_ERR, "ERROR:xl_get_branches: local buffer length exceeded\n"); return xl_get_null(msg, res, hp, hi, hf); } i = 0; p = local_buf; init_branch_iterator(); while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0))) { if (i) { memcpy(p, XLOG_FIELD_DELIM, XLOG_FIELD_DELIM_LEN); p += XLOG_FIELD_DELIM_LEN; } if (q != Q_UNSPECIFIED) { *p++ = '<'; } memcpy(p, uri.s, uri.len); p += uri.len; if (q != Q_UNSPECIFIED) { memcpy(p, Q_PARAM, Q_PARAM_LEN); p += Q_PARAM_LEN; qbuf = q2str(q, &qlen); memcpy(p, qbuf, qlen); p += qlen; } i++; } res->s = &(local_buf[0]); res->len = len; return 0; }
static int xl_get_header(struct sip_msg *msg, str *res, str *hp, int hi, int hf) { struct hdr_field *hdrf, *hdrf0; char *p; if(msg==NULL || res==NULL) return -1; if(hp==NULL || hp->len==0) return xl_get_null(msg, res, hp, hi, hf); hdrf0 = NULL; p = local_buf; /* we need to be sure we have parsed all headers */ parse_headers(msg, HDR_EOH_F, 0); for (hdrf=msg->headers; hdrf; hdrf=hdrf->next) { if(hp->s==NULL) { if (hp->len!=hdrf->type) continue; } else { if (hdrf->name.len!=hp->len) continue; if (strncasecmp(hdrf->name.s, hp->s, hdrf->name.len)!=0) continue; } hdrf0 = hdrf; if(hi==XLOG_PRINT_ALL) { if(p!=local_buf) { if(p-local_buf+XLOG_FIELD_DELIM_LEN+1>LOCAL_BUF_SIZE) { LOG(L_ERR, "ERROR:xl_get_header: local buffer length exceeded\n"); return xl_get_null(msg, res, hp, hi, hf); } memcpy(p, XLOG_FIELD_DELIM, XLOG_FIELD_DELIM_LEN); p += XLOG_FIELD_DELIM_LEN; } if(p-local_buf+hdrf0->body.len+1>LOCAL_BUF_SIZE) { LOG(L_ERR, "ERROR:xl_get_header: local buffer length exceeded!\n"); return xl_get_null(msg, res, hp, hi, hf); } memcpy(p, hdrf0->body.s, hdrf0->body.len); p += hdrf0->body.len; continue; } if(hi==0) goto done; if(hi>0) hi--; } done: if(hi==XLOG_PRINT_ALL) { *p = 0; res->s = local_buf; res->len = p - local_buf; return 0; } if(hdrf0==NULL || hi>0) return xl_get_null(msg, res, hp, hi, hf); res->s = hdrf0->body.s; res->len = hdrf0->body.len; trim(res); return 0; }