int pv_get_nh(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct sip_uri parsed_uri; str uri; if(msg==NULL || res==NULL) return -1; if(msg->first_line.type == SIP_REPLY) /* REPLY doesnt have r/d-uri */ return pv_get_null(msg, param, res); if (msg->dst_uri.s != NULL && msg->dst_uri.len>0) { uri = msg->dst_uri; } else { if (msg->new_uri.s!=NULL && msg->new_uri.len>0) { uri = msg->new_uri; } else { uri = msg->first_line.u.request.uri; } } if(param->pvn.u.isname.name.n==0) /* uri */ { return pv_get_strval(msg, param, res, &uri); } if(parse_uri(uri.s, uri.len, &parsed_uri)!=0) { LM_ERR("failed to parse nh uri [%.*s]\n", uri.len, uri.s); return pv_get_null(msg, param, res); } if(param->pvn.u.isname.name.n==1) /* username */ { if(parsed_uri.user.s==NULL || parsed_uri.user.len<=0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &parsed_uri.user); } else if(param->pvn.u.isname.name.n==2) /* domain */ { if(parsed_uri.host.s==NULL || parsed_uri.host.len<=0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &parsed_uri.host); } else if(param->pvn.u.isname.name.n==3) /* port */ { if(parsed_uri.port.s==NULL) return pv_get_5060(msg, param, res); return pv_get_strintval(msg, param, res, &parsed_uri.port, (int)parsed_uri.port_no); } else if(param->pvn.u.isname.name.n==4) /* protocol */ { if(parsed_uri.transport_val.s==NULL) return pv_get_udp(msg, param, res); return pv_get_strintval(msg, param, res, &parsed_uri.transport_val, (int)parsed_uri.proto); } LM_ERR("unknown specifier\n"); return pv_get_null(msg, param, res); }
int pv_get_dbr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { sql_pv_t *spv; int row; int col; spv = (sql_pv_t*)param->pvn.u.dname; if(spv->res==NULL) { spv->res = sql_get_result(&spv->resname); if(spv->res==NULL) return pv_get_null(msg, param, res); } switch(spv->type) { case 1: return pv_get_sintval(msg, param, res, spv->res->nrows); break; case 2: return pv_get_sintval(msg, param, res, spv->res->ncols); break; case 3: if(fixup_get_ivalue(msg, &spv->row, &row)!=0) return pv_get_null(msg, param, res); if(fixup_get_ivalue(msg, &spv->col, &col)!=0) return pv_get_null(msg, param, res); if(row>=spv->res->nrows) return pv_get_null(msg, param, res); if(col>=spv->res->ncols) return pv_get_null(msg, param, res); if(spv->res->vals[row][col].flags&PV_VAL_NULL) return pv_get_null(msg, param, res); if(spv->res->vals[row][col].flags&PV_VAL_INT) return pv_get_sintval(msg, param, res, spv->res->vals[row][col].value.n); return pv_get_strval(msg, param, res, &spv->res->vals[row][col].value.s); break; case 4: if(fixup_get_ivalue(msg, &spv->col, &col)!=0) return pv_get_null(msg, param, res); if(col>=spv->res->ncols) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &spv->res->cols[col].name); break; } return 0; }
static int pv_get_color(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str s = {"", 0}; if(log_stderr==0 && force_color==0) { LM_DBG("ignoring colors\n"); return pv_get_strval(msg, param, res, &s); } dprint_term_color(param->pvn.u.isname.name.s.s[0], param->pvn.u.isname.name.s.s[1], &s); return pv_get_strval(msg, param, res, &s); }
static int pv_get_mongodb(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { mongodbc_pv_t *rpv; rpv = (mongodbc_pv_t*)param->pvn.u.dname; if(rpv->reply==NULL) { rpv->reply = mongodbc_get_reply(&rpv->rname); if(rpv->reply==NULL) return pv_get_null(msg, param, res); } switch(rpv->rkeyid) { case 1: /* value */ if(rpv->reply->jsonrpl.s==NULL) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &rpv->reply->jsonrpl); case 2: /* info */ return pv_get_null(msg, param, res); case 3: /* size */ return pv_get_null(msg, param, res); case 0: /* type */ return pv_get_sintval(msg, param, res, 0); default: /* We do nothing. */ return pv_get_null(msg, param, res); } }
int pv_get_ht_expired_cell(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { if (res == NULL || ht_expired_cell == NULL) { return -1; } if (param->pvn.u.isname.name.s.len == 3 && strncmp(param->pvn.u.isname.name.s.s, "key", 3) == 0) { res->rs = ht_expired_cell->name; } else if (param->pvn.u.isname.name.s.len == 5 && strncmp(param->pvn.u.isname.name.s.s, "value", 5) == 0) { if(ht_expired_cell->flags&AVP_VAL_STR) { return pv_get_strval(msg, param, res, &ht_expired_cell->value.s); } else { return pv_get_sintval(msg, param, res, ht_expired_cell->value.n); } } if (res->rs.s == NULL) res->flags = PV_VAL_NULL; else res->flags = PV_VAL_STR; return 0; }
static int pv_get_sdp(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { sdp_info_t *sdp = NULL; if(msg==NULL || param==NULL) return -1; if(parse_sdp(msg) < 0) { LM_INFO("Unable to parse sdp\n"); return pv_get_null(msg, param, res); } sdp = (sdp_info_t*)msg->body; if (sdp==NULL) { LM_DBG("No SDP\n"); return pv_get_null(msg, param, res); } switch(param->pvn.u.isname.name.n) { case 0: return pv_get_strval(msg, param, res, &sdp->raw_sdp); default: return pv_get_null(msg, param, res); } }
/** * return strftime() formatted time */ int pv_get_strftime(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str s; #define PV_STRFTIME_BUF_SIZE 64 static char _pv_strftime_buf[PV_STRFTIME_BUF_SIZE]; if(msg==NULL || param==NULL) return -1; if(msg_ctx_id_match(msg, &_cfgutils_msgid)!=1) { msg_set_time(msg); msg_ctx_id_set(msg, &_cfgutils_msgid); if(localtime_r(&msg->tval.tv_sec, &_cfgutils_ts) == NULL) { LM_ERR("unable to break time to attributes\n"); return -1; } } s.len = strftime(_pv_strftime_buf, PV_STRFTIME_BUF_SIZE, param->pvn.u.isname.name.s.s, &_cfgutils_ts); if(s.len<=0) return pv_get_null(msg, param, res); s.s = _pv_strftime_buf; return pv_get_strval(msg, param, res, &s); }
static int pv_get_from_tag_initial(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { struct to_body *xto; if(msg==NULL) return -1; if(parse_from_header(msg)<0) { LM_ERR("cannot parse From header\n"); return pv_get_null(msg, param, res); } if(msg->from==NULL || get_from(msg)==NULL) { LM_DBG("no From header\n"); return pv_get_null(msg, param, res); } xto = get_from(msg); if(is_direction(msg, RR_FLOW_UPSTREAM)==0) { if(msg->to==NULL && parse_headers(msg, HDR_TO_F, 0)==-1) { LM_ERR("cannot parse To header\n"); return pv_get_null(msg, param, res); } if(msg->to==NULL || get_to(msg)==NULL) { LM_DBG("no To header\n"); return pv_get_null(msg, param, res); } xto = get_to(msg); } if (xto->tag_value.s==NULL || xto->tag_value.len<=0) { LM_DBG("no Tag parameter\n"); return pv_get_null(msg, param, res); } return pv_get_strval(msg, param, res, &xto->tag_value); }
static int pv_get_huri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { if(msg==NULL || res==NULL) return -1; return pv_get_strval(msg, param, res, &msg->first_line.u.request.uri); }
/* * Get the asserted Identity for the current user */ static int pv_get_registration_contact_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str * ret_val = get_registration_contact(msg); if (ret_val != NULL) return pv_get_strval(msg, param, res, ret_val); else return -1; }
static int pv_get_rdir(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { if(msg==NULL || param==NULL) return -1; switch(param->pvn.u.isname.name.n) { case 1: if(is_direction(msg, RR_FLOW_UPSTREAM)==0) return pv_get_strval(msg, param, res, &pv_rr_flow_list[1]); return pv_get_strval(msg, param, res, &pv_rr_flow_list[0]); default: if(is_direction(msg, RR_FLOW_UPSTREAM)==0) return pv_get_uintval(msg, param, res, RR_FLOW_UPSTREAM); return pv_get_uintval(msg, param, res, RR_FLOW_DOWNSTREAM); } }
/* * Get the asserted Identity for the current user */ static int pv_get_asserted_identity_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str * ret_val = get_asserted_identity(msg); if (ret_val != NULL) return pv_get_strval(msg, param, res, ret_val); else return -1; }
int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct cell *t; tm_ctx_t *tcx = 0; int branch; if(msg==NULL || res==NULL) return -1; /* first get the transaction */ if (_tmx_tmb.t_check( msg , 0 )==-1) return -1; if ( (t=_tmx_tmb.t_gett())==0) { /* no T */ return pv_get_strempty(msg, param, res); } else { switch (get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: /* use the reason of the winning reply */ if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) { LM_CRIT("no picked branch (%d) for a final response" " in MODE_ONFAILURE\n", branch); return pv_get_strempty(msg, param, res); } LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s); return pv_get_strval(msg, param, res, &t->uac[branch].ruid); break; case TM_ONREPLY_ROUTE: tcx = _tmx_tmb.tm_ctx_get(); if(tcx == NULL) { return pv_get_strempty(msg, param, res); } branch = tcx->branch_index; if(branch<0 || branch>=t->nr_of_outgoings) { return pv_get_strempty(msg, param, res); } LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s); return pv_get_strval(msg, param, res, &t->uac[branch].ruid); default: LM_ERR("unsupported route_type %d\n", get_route_type()); return pv_get_strempty(msg, param, res); } } }
static int pv_get_sruid_val(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { if(res==NULL) return -1; if(sruid_next(&_kex_sruid)<0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &_kex_sruid.uid); }
int pv_get_sndto(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct onsend_info* snd_inf; struct ip_addr ip; str s; snd_inf=get_onsend_info(); if (! likely(snd_inf && snd_inf->send_sock)) return pv_get_null(msg, param, res); switch(param->pvn.u.isname.name.n) { case 1: /* af */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->address.af); case 2: /* port */ return pv_get_uintval(msg, param, res, (int)su_getport(snd_inf->to)); case 3: /* proto */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->proto); case 4: /* buf */ s.s = snd_inf->buf; s.len = snd_inf->len; return pv_get_strval(msg, param, res, &s); case 5: /* len */ return pv_get_uintval(msg, param, res, (int)snd_inf->len); case 6: /* sproto */ if(get_valid_proto_string((int)snd_inf->send_sock->proto, 0, 0, &s)<0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &s); default: /* 0 - ip */ su2ip_addr(&ip, snd_inf->to); s.s = ip_addr2a(&ip); s.len = strlen(s.s); return pv_get_strval(msg, param, res, &s); } return 0; }
int pv_xavp_get_value(struct sip_msg *msg, pv_param_t *param, pv_value_t *res, sr_xavp_t *avp) { static char _pv_xavp_buf[128]; str s; switch(avp->val.type) { case SR_XTYPE_NULL: return pv_get_null(msg, param, res); break; case SR_XTYPE_INT: return pv_get_sintval(msg, param, res, avp->val.v.i); break; case SR_XTYPE_STR: return pv_get_strval(msg, param, res, &avp->val.v.s); break; case SR_XTYPE_TIME: if(snprintf(_pv_xavp_buf, 128, "%lu", (long unsigned)avp->val.v.t)<0) return pv_get_null(msg, param, res); break; case SR_XTYPE_LONG: if(snprintf(_pv_xavp_buf, 128, "%ld", (long unsigned)avp->val.v.l)<0) return pv_get_null(msg, param, res); break; case SR_XTYPE_LLONG: if(snprintf(_pv_xavp_buf, 128, "%lld", avp->val.v.ll)<0) return pv_get_null(msg, param, res); break; case SR_XTYPE_XAVP: if(snprintf(_pv_xavp_buf, 128, "<<xavp:%p>>", avp->val.v.xavp)<0) return pv_get_null(msg, param, res); break; case SR_XTYPE_DATA: if(snprintf(_pv_xavp_buf, 128, "<<data:%p>>", avp->val.v.data)<0) return pv_get_null(msg, param, res); break; default: return pv_get_null(msg, param, res); } s.s = _pv_xavp_buf; s.len = strlen(_pv_xavp_buf); return pv_get_strval(msg, param, res, &s); }
int pv_get_dlg_variable(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { dlg_cell_t *dlg; str * value; str spv; if (param==NULL || param->pvn.type!=PV_NAME_INTSTR || param->pvn.u.isname.type!=AVP_NAME_STR || param->pvn.u.isname.name.s.s==NULL) { LM_CRIT("BUG - bad parameters\n"); return -1; } /* Retrieve the dialog for current message */ dlg=dlg_get_msg_dialog( msg); if (dlg) { /* Lock the dialog */ dlg_lock(d_table, &(d_table->entries[dlg->h_entry])); } else { /* Verify the local list */ get_local_varlist_pointer(msg, 0); } /* dcm: todo - the value should be cloned for safe usage */ value = get_dlg_variable_unsafe(dlg, ¶m->pvn.u.isname.name.s); spv.s = NULL; if(value) { spv.len = pv_get_buffer_size(); if(spv.len<value->len+1) { LM_ERR("pv buffer too small (%d) - needed %d\n", spv.len, value->len); } else { spv.s = pv_get_buffer(); strncpy(spv.s, value->s, value->len); spv.len = value->len; spv.s[spv.len] = '\0'; } } print_lists(dlg); /* unlock dialog */ if (dlg) { dlg_unlock(d_table, &(d_table->entries[dlg->h_entry])); dlg_release(dlg); } if (spv.s) return pv_get_strval(msg, param, res, &spv); return pv_get_null(msg, param, res); }
/* * PV - return curl redirect URL for httpcon * $curlredirect("httpcon"); */ static int pv_get_curlredirect(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str redirecturl; if(param==NULL) { return -1; } // DO SOMETHING HERE return pv_get_strval(msg, param, res, &redirecturl); }
int pv_get_select(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str s = {0, 0}; select_t *sel = 0; sel = (select_t*)param->pvn.u.dname; if(sel==0 || run_select(&s, sel, msg)<0 || s.s==0) return pv_get_null(msg, param, res); return pv_get_strval(msg, param, res, &s); }
int pv_geoip2_get_strzval(struct sip_msg *msg, pv_param_t *param, pv_value_t *res, char *sval) { str s; if(sval==NULL) return pv_get_null(msg, param, res); s.s = sval; s.len = strlen(s.s); return pv_get_strval(msg, param, res, &s); }
static int ah_get_err(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { if (ah_reply) { if (ah_error.s) { return pv_get_strval(msg, param, res, &ah_error); } else { return pv_get_null(msg, param, res); } } else { LM_ERR("the async variables can only be read from an async http worker\n"); return pv_get_null(msg, param, res); } }
int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { tm_ctx_t *tcx = 0; tm_cell_t *t; int branch; if ((msg == NULL) || (param == NULL)) return -1; t = _tmx_tmb.t_gett(); if ((t == NULL) || (t == T_UNDEFINED)) { /* no T */ return pv_get_null(msg, param, res); } switch(param->pvn.u.isname.name.n) { case 5: /* $T_branch(flags) */ switch (get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: /* use the reason of the winning reply */ if ((branch=_tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" " in MODE_ONFAILURE\n", branch); return pv_get_null(msg, param, res); } res->ri = t->uac[branch].branch_flags; res->flags = PV_VAL_INT; LM_DBG("branch flags is [%u]\n", res->ri); break; default: LM_ERR("unsupported route_type %d\n", get_route_type()); return pv_get_null(msg, param, res); } break; case 6: /* $T_branch(uri) */ if (get_route_type() != TM_ONREPLY_ROUTE) { LM_ERR("$T_branch(uri) - unsupported route_type %d\n", get_route_type()); return pv_get_null(msg, param, res); } tcx = _tmx_tmb.tm_ctx_get(); if(tcx == NULL) { return pv_get_null(msg, param, res); } branch = tcx->branch_index; if(branch<0 || branch>=t->nr_of_outgoings) { return pv_get_null(msg, param, res); } return pv_get_strval(msg, param, res, &t->uac[branch].uri); } return 0; }
int pv_get_ht_expired_cell(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { if (res == NULL || ht_expired_cell == NULL) { return -1; } switch(param->pvn.u.isname.name.n) { case 0: return pv_get_strval(msg, param, res, &ht_expired_cell->name); case 1: if(ht_expired_cell->flags&AVP_VAL_STR) { return pv_get_strval(msg, param, res, &ht_expired_cell->value.s); } else { return pv_get_sintval(msg, param, res, ht_expired_cell->value.n); } default: return pv_get_null(msg, param, res); } }
static int pv_get_evr(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { if(param==NULL || pv_evr_data==NULL) { return pv_get_null(msg, param, res); } switch(param->pvn.u.isname.name.n) { case 0: /* data */ return pv_get_strval(msg, param, res, pv_evr_data); default: return pv_get_null(msg, param, res); } }
int pv_get_iterator_key(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { ht_cell_t *it=NULL; if (res == NULL) { return -1; } it = ht_iterator_get_current(¶m->pvn.u.isname.name.s); if(it==NULL) { return pv_get_null(msg, param, res); } return pv_get_strval(msg, param, res, &it->name); }
int pv_get_sndfrom(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct onsend_info* snd_inf; str s; snd_inf=get_onsend_info(); if (! likely(snd_inf && snd_inf->send_sock)) return pv_get_null(msg, param, res); switch(param->pvn.u.isname.name.n) { case 1: /* af */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->address.af); case 2: /* port */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->port_no); case 3: /* proto */ return pv_get_uintval(msg, param, res, (int)snd_inf->send_sock->proto); case 4: /* buf */ s.s = snd_inf->buf; s.len = snd_inf->len; return pv_get_strval(msg, param, res, &s); case 5: /* len */ return pv_get_uintval(msg, param, res, (int)snd_inf->len); default: /* 0 - ip */ return pv_get_strval(msg, param, res, &snd_inf->send_sock->address_str); } return 0; }
int pv_get_iterator_val(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { ht_cell_t *it=NULL; if (res == NULL) { return -1; } it = ht_iterator_get_current(¶m->pvn.u.isname.name.s); if(it==NULL) { return pv_get_null(msg, param, res); } if(it->flags&AVP_VAL_STR) return pv_get_strval(msg, param, res, &it->value.s); /* integer */ return pv_get_sintval(msg, param, res, it->value.n); }
int pv_get_timeval(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct timeval tv; str s; if(msg==NULL || param==NULL) return -1; switch(param->pvn.u.isname.name.n) { case 1: msg_set_time(msg); return pv_get_uintval(msg, param, res, (unsigned int)msg->tval.tv_usec); case 2: if(gettimeofday(&_timeval_ts, NULL)!=0) { LM_ERR("unable to get time val attributes\n"); return pv_get_null(msg, param, res); } return pv_get_uintval(msg, param, res, (unsigned int)_timeval_ts.tv_sec); case 3: return pv_get_uintval(msg, param, res, (unsigned int)_timeval_ts.tv_usec); case 4: if(gettimeofday(&tv, NULL)!=0) { LM_ERR("unable to get time val attributes\n"); return pv_get_null(msg, param, res); } s.len = snprintf(_timeval_ts_buf, 32, "%u.%06u", (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec); if(s.len<0) return pv_get_null(msg, param, res); s.s = _timeval_ts_buf; return pv_get_strval(msg, param, res, &s); default: msg_set_time(msg); return pv_get_uintval(msg, param, res, (unsigned int)msg->tval.tv_sec); } }
int pv_get_ht_cell(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str htname; ht_cell_t *htc=NULL; ht_pv_t *hpv; hpv = (ht_pv_t*)param->pvn.u.dname; if(hpv->ht==NULL) { hpv->ht = ht_get_table(&hpv->htname); if(hpv->ht==NULL) return pv_get_null(msg, param, res); } if(pv_printf_s(msg, hpv->pve, &htname)!=0) { LM_ERR("cannot get $ht name\n"); return -1; } htc = ht_cell_pkg_copy(hpv->ht, &htname, _htc_local); if(htc==NULL) { if(hpv->ht->flags==PV_VAL_INT) return pv_get_sintval(msg, param, res, hpv->ht->initval.n); return pv_get_null(msg, param, res); } if(_htc_local!=htc) { ht_cell_pkg_free(_htc_local); _htc_local=htc; } if(htc->flags&AVP_VAL_STR) return pv_get_strval(msg, param, res, &htc->value.s); /* integer */ return pv_get_sintval(msg, param, res, htc->value.n); }
/* * Return the URI of the topmost Route-Header. */ static int pv_get_route_uri_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct hdr_field* hdr; rr_t* rt; str uri; if (!msg) { LM_ERR("No message?!?\n"); return -1; } /* Parse the message until the First-Route-Header: */ if (parse_headers(msg, HDR_ROUTE_F, 0) == -1) { LM_ERR("while parsing message\n"); return -1; } if (!msg->route) { LM_INFO("No route header present.\n"); return -1; } hdr = msg->route; /* Parse the contents of the header: */ if (parse_rr(hdr) == -1) { LM_ERR("Error while parsing Route header\n"); return -1; } /* Retrieve the Route-Header */ rt = (rr_t*)hdr->parsed; uri = rt->nameaddr.uri; return pv_get_strval(msg, param, res, &uri); }