static inline struct uac_credential *get_avp_credential(struct sip_msg *msg, str *realm) { static struct uac_credential crd; pv_value_t pv_val; if(pv_get_spec_value( msg, &auth_realm_spec, &pv_val)!=0) return 0; if (pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0) { /* if realm parameter is empty or NULL, match any realm asked for */ crd.realm = *realm; } else { crd.realm = pv_val.rs; /* is it the domain we are looking for? */ if (realm->len!=crd.realm.len || strncmp( realm->s, crd.realm.s, realm->len)!=0 ) { return 0; } } /* get username and password */ if(pv_get_spec_value( msg, &auth_username_spec, &pv_val)!=0 || pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0) return 0; crd.user = pv_val.rs; if(pv_get_spec_value( msg, &auth_password_spec, &pv_val)!=0 || pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0) return 0; crd.passwd = pv_val.rs; return &crd; }
/* Checks, if the IP PORT is a LB destination */ int lb_is_dst(struct lb_data *data, struct sip_msg *_m, pv_spec_t *pv_ip, pv_spec_t *pv_port, int grp, int active) { pv_value_t val; struct ip_addr *ip; int port; struct lb_dst *dst; int k; /* get the address to test */ if (pv_get_spec_value( _m, pv_ip, &val)!=0) { LM_ERR("failed to get IP value from PV\n"); return -1; } if ( (val.flags&PV_VAL_STR)==0 ) { LM_ERR("IP PV val is not string\n"); return -1; } if ( (ip=str2ip( &val.rs ))==NULL ) { LM_ERR("IP val is not IP <%.*s>\n",val.rs.len,val.rs.s); return -1; } /* get the port to test */ if (pv_port) { if (pv_get_spec_value( _m, pv_port, &val)!=0) { LM_ERR("failed to get PORT value from PV\n"); return -1; } if ( (val.flags&PV_VAL_INT)==0 ) { LM_ERR("PORT PV val is not integer\n"); return -1; } port = val.ri; } else { port = 0; } /* and now search !*/ for( dst=data->dsts ; dst ; dst=dst->next) { if ( ((grp==-1) || (dst->group==grp)) && /*group matches*/ ( !active || (active && (dst->flags&LB_DST_STAT_DSBL_FLAG)==0 ) ) ) { /* check the IPs */ for(k=0 ; k<dst->ips_cnt ; k++ ) { if ( (dst->ports[k]==0 || port==0 || port==dst->ports[k]) && ip_addr_cmp( ip, &dst->ips[k]) ) { /* found */ return 1; } } } } return -1; }
static inline int auth_get_ha1(struct sip_msg *msg, struct username* _username, str* _domain, char* _ha1) { pv_value_t sval; /* get username from PV */ memset(&sval, 0, sizeof(pv_value_t)); if(pv_get_spec_value(msg, &user_spec, &sval)==0) { if(sval.flags==PV_VAL_NONE || (sval.flags&PV_VAL_NULL) || (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR))) { pv_value_destroy(&sval); return 1; } if(sval.rs.len!= _username->whole.len || strncasecmp(sval.rs.s, _username->whole.s, sval.rs.len)) { LM_DBG("username mismatch [%.*s] [%.*s]\n", _username->whole.len, _username->whole.s, sval.rs.len, sval.rs.s); pv_value_destroy(&sval); return 1; } } else { return 1; } /* get password from PV */ memset(&sval, 0, sizeof(pv_value_t)); if(pv_get_spec_value(msg, &passwd_spec, &sval)==0) { if(sval.flags==PV_VAL_NONE || (sval.flags&PV_VAL_NULL) || (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR))) { pv_value_destroy(&sval); return 1; } } else { return 1; } if (auth_calc_ha1) { /* Only plaintext passwords are stored in database, * we have to calculate HA1 */ calc_HA1(HA_MD5, &_username->whole, _domain, &sval.rs, 0, 0, _ha1); LM_DBG("HA1 string calculated: %s\n", _ha1); } else { memcpy(_ha1, sval.rs.s, sval.rs.len); _ha1[sval.rs.len] = '\0'; } return 0; }
static int w_rl_check_forced(struct sip_msg* msg, char *p1, char *p2) { int pipe = -1; pv_value_t pv_val; if (p1 && (pv_get_spec_value(msg, (pv_spec_t *)p1, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_INT) { pipe = pv_val.ri; LM_DBG("pipe=%d\n", pipe); } else if (pv_val.flags & PV_VAL_STR) { if(str2int(&(pv_val.rs), (unsigned int*)&pipe) != 0) { LM_ERR("Unable to get pipe from pv '%.*s'" "=> defaulting to method type checking\n", pv_val.rs.len, pv_val.rs.s); pipe = -1; } } else { LM_ERR("pv not a str or int => defaulting to method type checking\n"); pipe = -1; } } else { LM_ERR("Unable to get pipe from pv:%p" " => defaulting to method type checking\n", p1); pipe = -1; } return rl_check(msg, pipe); }
int cmd_send_rpl(struct sip_msg *msg, int *cluster_id, int *node_id, str *gen_msg, pv_spec_t *param_tag) { pv_value_t tag_val; int rc; if (pv_get_spec_value(msg, param_tag, &tag_val) < 0) { LM_ERR("Failed to fetch tag parameter\n"); return -1; } if (tag_val.flags & PV_VAL_NULL || (tag_val.flags & PV_VAL_STR && tag_val.rs.len == 0)) { LM_ERR("Empty tag\n"); return -1; } rc = send_gen_msg(*cluster_id, *node_id, gen_msg, &tag_val.rs, 0); switch (rc) { case 0: return 1; case 1: return -1; case -1: return -2; case -2: return -3; default: return -3; } }
int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name) { if(msg==NULL || ip==NULL || name==NULL) return -1; memset(name, 0, sizeof(pv_value_t)); if(ip->pvn.type==PV_NAME_INTSTR) { if(ip->pvn.u.isname.type&AVP_NAME_STR) { name->rs = ip->pvn.u.isname.name.s; name->flags = PV_VAL_STR; } else { name->ri = ip->pvn.u.isname.name.n; name->flags = PV_VAL_INT|PV_TYPE_INT; } return 0; } else if(ip->pvn.type==PV_NAME_PVAR) { /* pvar */ if(pv_get_spec_value(msg, (pv_spec_p)(ip->pvn.u.dname), name)!=0) { LM_ERR("cannot get name value\n"); return -1; } if(name->flags&PV_VAL_NULL || name->flags&PV_VAL_EMPTY) { LM_ERR("null or empty name\n"); return -1; } return 0; } LM_ERR("name type is PV_NAME_OTHER - cannot resolve\n"); return -1; }
int sca_set_called_line(struct sip_msg *msg, char *line_var) { pv_value_t value; str line; if (no_dialog_support) { LM_ERR("dialog support is disabled, cannot use this function\n"); return -1; } if (msg->REQ_METHOD != METHOD_INVITE) return 1; /* get the name of line first */ if (line_var) { /* take it from param */ if ( pv_get_spec_value( msg, (pv_spec_p)line_var, &value) < 0 ) { LM_ERR("failed to evaluate parameter\n"); return -1; } if ( (value.flags&PV_VAL_STR)==0 ) { LM_ERR("line value is not a string (flags are %d)\n",value.flags); return -1; } line = value.rs; } else { /* take it from RURI msg */ line = *GET_RURI(msg); } return sca_set_line(msg, &line, 0/*called*/); }
static inline char* append2buf( char *buf, int len, struct sip_msg *req, struct append_elem *elem) { pv_value_t value; char *end; end = buf+len; while (elem) { /* get the value */ if (pv_get_spec_value(req, &elem->spec, &value)!=0) { LM_ERR("failed to get '%.*s'\n", elem->name.len,elem->name.s); } /* empty element? */ if ( !(value.flags&PV_VAL_NULL) ) { /* write the value into the buffer */ buf = add2buf( buf, end, &elem->name, &value.rs); if (!buf) { LM_ERR("overflow -> append exceeded %d len\n",len); return 0; } } elem = elem->next; } return buf; }
static int pv_set_count(struct sip_msg* msg, pv_spec_t *pv_name, pv_spec_t *pv_result) { pv_value_t pv_val; memset(&pv_val, 0, sizeof(pv_value_t)); pv_name->pvp.pvi.type = PV_IDX_INT; pv_name->pvp.pvi.u.ival = 0; while(pv_val.flags != PV_VAL_NULL) { if(pv_get_spec_value(msg, pv_name, &pv_val) < 0) { LM_ERR("PV get function failed\n"); return -1; } pv_name->pvp.pvi.u.ival++; } pv_val.flags = PV_TYPE_INT; pv_val.ri = pv_name->pvp.pvi.u.ival-1; if (pv_set_value( msg, pv_result, 0, &pv_val) != 0) { LM_ERR("SET output value failed.\n"); return -1; } LM_DBG("Set count = %d\n", pv_val.ri); return 1; }
static int lua_sr_pv_is_null (lua_State *L) { str pvn; pv_spec_t pvs; pv_value_t val; sr_lua_env_t *env_L; env_L = sr_lua_env_get(); pvn.s = (char*)lua_tostring(L, -1); if(pvn.s==NULL || env_L->msg==NULL) return 0; pvn.len = strlen(pvn.s); LM_DBG("pv is null test: %s\n", pvn.s); if(pv_parse_spec(&pvn, &pvs)<0) { LM_ERR("unable to parse pv [%s]\n", pvn.s); return 0; } memset(&val, 0, sizeof(pv_value_t)); if(pv_get_spec_value(env_L->msg, &pvs, &val) != 0) { LM_ERR("unable to get pv value for [%s]\n", pvn.s); return 0; } if(val.flags&PV_VAL_NULL) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } return 1; }
int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags) { pv_value_t tv; if(ip==NULL || idx==NULL || flags==NULL) return -1; *idx = 0; *flags = 0; if(ip->pvi.type == PV_IDX_ALL) { *flags = PV_IDX_ALL; return 0; } if(ip->pvi.type == PV_IDX_INT) { *idx = ip->pvi.u.ival; return 0; } /* pvar */ if(pv_get_spec_value(msg, (pv_spec_p)ip->pvi.u.dval, &tv)!=0) { LM_ERR("cannot get index value\n"); return -1; } if(!(tv.flags&PV_VAL_INT)) { LM_ERR("invalid index value\n"); return -1; } *idx = tv.ri; return 0; }
/* * Check if user part of URI in pseudo variable is an e164 number */ int is_uri_user_e164(struct sip_msg* _m, char* _sp, char* _s2) { pv_spec_t *sp; pv_value_t pv_val; struct sip_uri puri; sp = (pv_spec_t *)_sp; if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_DBG("missing uri\n"); return -1; } if (parse_uri(pv_val.rs.s, pv_val.rs.len, &puri) < 0) { LM_ERR("parsing URI failed\n"); return -1; } return e164_check(&(puri.user)); } else { LM_ERR("pseudo variable value is not string\n"); return -1; } } else { LM_ERR("failed to get pseudo variable value\n"); return -1; } }
/** * Set the dialog's AVP value so the dialog module will use this value * and not the default when returning from the dialog callback. * * @param msg The current message to bind the AVP to. * @param value The value you want to set the AVP to. * * @return 0 on success, -1 on an error. */ static int set_timeout_avp(struct sip_msg *msg, unsigned int value) { int rtn = -1; /* assume failure */ pv_value_t pv_val; int result = 0; /* Set the dialog timeout HERE */ if (timeout_avp) { if ((result = pv_get_spec_value(msg, timeout_avp, &pv_val)) == 0) { /* We now hold a reference to the AVP */ if (pv_val.flags & PV_VAL_INT && pv_val.ri == value) { /* INT AVP with the same value */ LM_DBG("Current timeout value already set to %d\n", value); rtn = 0; } else { /* AVP not found or non-INT value -> add a new one*/ pv_val.flags = PV_VAL_INT|PV_TYPE_INT; pv_val.ri = value; if (timeout_avp->setf(msg,&timeout_avp->pvp,EQ_T,&pv_val)!=0) { LM_ERR("failed to set new dialog timeout value\n"); } else { rtn = 0; } } } else { LM_ERR("SST not reset. get avp result is %d\n", result); } } else { LM_ERR("SST needs to know the name of the dialog timeout AVP!\n"); } return(rtn); }
static int xlog_3_helper(struct sip_msg* msg, char* fac, char* lev, char* frm, int mode) { long level; int facility; xl_level_p xlp; pv_value_t value; xlp = (xl_level_p)lev; if(xlp->type==1) { if(pv_get_spec_value(msg, &xlp->v.sp, &value)!=0 || value.flags&PV_VAL_NULL || !(value.flags&PV_VAL_INT)) { LM_ERR("invalid log level value [%d]\n", value.flags); return -1; } level = (long)value.ri; } else { level = xlp->v.level; } facility = *(int*)fac; if(!is_printable((int)level)) return 1; return xlog_helper(msg, (xl_msg_t*)frm, (int)level, mode, facility); }
/* * Check if domain given as value of pseudo variable parameter is local. */ int w_is_domain_local(struct sip_msg* _msg, char* _sp, char* _s2) { pv_spec_t *sp; pv_value_t pv_val; struct attr_list *attrs; str did; sp = (pv_spec_t *)_sp; if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_DBG("missing domain name\n"); return -1; } return hash_table_lookup(&(pv_val.rs), &did, &attrs); } else { LM_DBG("domain pseudo variable value is not string\n"); return -1; } } else { LM_DBG("cannot get domain pseudo variable value\n"); return -1; } }
int make_send_message(struct sip_msg* msg, int index, VALUE_PAIR **send) { pv_value_t pt; map_list *mp = sets[index]->parsed; for (; mp; mp = mp->next) { pv_get_spec_value(msg, mp->pv, &pt); if (pt.flags & PV_VAL_INT) { //LM_DBG("%.*s---->%d---->%d---->%d\n",mp->name.len, mp->name.s, // pt.ri, mp->value, pt.flags); if (!rc_avpair_add(rh, send, ATTRID(mp->value), &pt.ri, -1, VENDOR(mp->value))) return -1; } else if (pt.flags & PV_VAL_STR) { //LM_DBG("%.*s----->%.*s---->%d---->%d---->%d\n",mp->name.len, // mp->name.s, pt.rs.len, pt.rs.s, mp->value, pt.flags, pt.rs.len); if (rc_dict_getattr(rh,mp->value)->type == PW_TYPE_IPADDR) { uint32_t ipaddr=rc_get_ipaddr(pt.rs.s); if (!rc_avpair_add(rh, send, ATTRID(mp->value), &ipaddr, -1, VENDOR(mp->value))) return -1; } else { if (!rc_avpair_add(rh, send, ATTRID(mp->value), pt.rs.s, pt.rs.len, VENDOR(mp->value))) return -1; } } } return 0; }
static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo) { struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; pv_value_t pv_val; stat_var *stat; if (sopv->stat) { reset_stat( sopv->stat ); } else { if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || (pv_val.flags & PV_VAL_STR)==0 ) { LM_ERR("failed to get pv string value\n"); return -1; } stat = get_stat( &(pv_val.rs) ); if ( stat == 0 ) { LM_ERR("variable <%.*s> not defined\n", pv_val.rs.len, pv_val.rs.s); return -1; } reset_stat( stat ); } return 1; }
struct to_body* get_appearance_name_addr(struct sip_msg* msg) { int len = 0; if(appearance_name_addr_spec_param.s) { memset(&appearance_name_addr_tok, 0, sizeof(pv_value_t)); if(pv_get_spec_value(msg, &appearance_name_addr_spec, &appearance_name_addr_tok) < 0) { LM_ERR("Failed to get appearance_name_addr value\n"); return NULL; } //LM_DBG("got appearance_name_addr_spec_param flags [%d]\n", appearance_name_addr_tok.flags); if(!(appearance_name_addr_tok.flags&PV_VAL_INT) && (appearance_name_addr_tok.flags&PV_VAL_STR)) { //LM_DBG("got PV_SPEC appearance_name_addr [%.*s]\n", // appearance_name_addr_tok.rs.len, appearance_name_addr_tok.rs.s); if(appearance_name_addr_tok.rs.len+CRLF_LEN > APPEARANCE_NAME_ADDR_BUF_LEN) { LM_ERR("Buffer overflow\n"); return NULL; } trim(&appearance_name_addr_tok.rs); memcpy(appearance_name_addr_buf, appearance_name_addr_tok.rs.s, appearance_name_addr_tok.rs.len); len = appearance_name_addr_tok.rs.len; if(strncmp(appearance_name_addr_tok.rs.s + len - CRLF_LEN, CRLF, CRLF_LEN)) { memcpy(appearance_name_addr_buf + len, CRLF, CRLF_LEN); len+= CRLF_LEN; } parse_to(appearance_name_addr_buf, appearance_name_addr_buf+len, &appearance_name_addr); if (appearance_name_addr.error != PARSE_OK) { LM_ERR("Failed to parse PV_SPEC appearance_name_addr [%.*s]\n", len, appearance_name_addr_buf); return NULL; } if (parse_uri(appearance_name_addr.uri.s, appearance_name_addr.uri.len, &appearance_name_addr.parsed_uri)<0) { LM_ERR("failed to parse PV_SPEC appearance_name_addr uri [%.*s]\n", appearance_name_addr.uri.len, appearance_name_addr.uri.s); return NULL; } return &appearance_name_addr; } } /* If the appearance_name_addr_spec_param is not set, use the From uri */ /* if (msg->from->parsed == NULL) { if (parse_from_header(msg)<0) { LM_ERR("cannot parse From header\n"); return NULL; } } */ return msg->from->parsed; }
/* * Check from Radius if URI given in pvar argument belongs to a local user. * If so, loads AVPs based on reply items returned from Radius. */ int radius_does_uri_exist_1(struct sip_msg* _m, char* _sp, char* _s2) { pv_spec_t *sp; pv_value_t pv_val; struct sip_uri parsed_uri; sp = (pv_spec_t *)_sp; if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_ERR("pvar argument is empty\n"); return -1; } } else { LM_ERR("pvar value is not string\n"); return -1; } } else { LM_ERR("cannot get pvar value\n"); return -1; } if (parse_uri(pv_val.rs.s, pv_val.rs.len, &parsed_uri) < 0) { LM_ERR("parsing of URI in pvar failed\n"); return -1; } return radius_does_uri_user_host_exist(_m, parsed_uri.user, parsed_uri.host); }
static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* mode_s) { pv_spec_t *spv; pv_value_t val; unsigned int mode; mode = (unsigned int)(long)mode_s; spv = (pv_spec_t*)src; if(pv_get_spec_value(msg, spv, &val) != 0) { LM_ERR("cannot get src uri value\n"); return -1; } if (!(val.flags & PV_VAL_STR)) { LM_ERR("src pv value is not string\n"); return -1; } if (mode > 1) { LM_ERR("invalid mode\n"); return -1; } return uac_reg_request_to(msg, &val.rs, mode); }
int xlog_2(struct sip_msg* msg, char* lev, char* frm) { int log_len; long level; xl_level_p xlp; pv_value_t value; xlp = (xl_level_p)lev; if(xlp->type==1) { if(pv_get_spec_value(msg, &xlp->v.sp, &value)!=0 || value.flags&PV_VAL_NULL || !(value.flags&PV_VAL_INT)) { LM_ERR("invalid log level value [%d]\n", value.flags); return -1; } level = (long)value.ri; } else { level = xlp->v.level; } if(!is_printable((int)level)) return 1; log_len = xlog_buf_size; if(xl_print_log(msg, (pv_elem_t*)frm, &log_len)<0) return -1; /* log_buf[log_len] = '\0'; */ LM_GEN1((int)level, "%.*s", log_len, log_buf); return 1; }
/** * match the type of the variable value */ static int pv_typeof(sip_msg_t *msg, char *pv, char *t) { pv_value_t val; if (pv==NULL || t==NULL) return -1; if(pv_get_spec_value(msg, (pv_spec_t*)pv, &val) != 0) return -1; switch(t[0]) { case 'i': case 'I': if(val.flags & PV_TYPE_INT) return 1; return -1; case 'n': case 'N': if(val.flags & PV_VAL_NULL) return 1; return -1; case 's': case 'S': if(!(val.flags & PV_VAL_STR)) return -1; if(val.flags & PV_TYPE_INT) return -1; return 1; default: return -1; } }
/* * Check from AAA if URI user giving in pvar argument belongs * to a local user. If so, loads AVPs based on reply items returned * from AAA. */ int aaa_does_uri_user_exist_1(struct sip_msg* _m, char* _sp, char* _s2) { pv_spec_t *sp; pv_value_t pv_val; sp = (pv_spec_t *)_sp; if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) { LM_ERR("pvar argument is empty\n"); return -1; } } else { LM_ERR("pvar value is not string\n"); return -1; } } else { LM_ERR("cannot get pvar value\n"); return -1; } if ( !_m->callid && (parse_headers(_m, HDR_CALLID_F, 0) == -1 || !_m->callid)) { LM_ERR("msg parsing failed or callid not present"); return -1; } return aaa_does_uri_user_exist(pv_val.rs, _m->callid->body); }
int fixup_get_partition(struct sip_msg *msg, const gpartition_t *gpart, ds_partition_t **partition) { if (gpart->type == GPART_TYPE_POINTER) { *partition = gpart->v.p; return 0; } pv_value_t value; if(pv_get_spec_value(msg, gpart->v.pvs, &value)!=0 || value.flags&PV_VAL_NULL || !(value.flags&PV_VAL_STR)) { LM_ERR("no valid PV value found (error in scripts)\n"); return -1; } if (value.rs.len == 0) { *partition = default_partition; return 0; } ds_partition_t *part_it = partitions; for (; part_it; part_it = part_it->next) if (part_it->name.len == value.rs.len && memcmp(part_it->name.s, value.rs.s, value.rs.len) == 0) { *partition = part_it; return 0; } *partition = NULL; return 0; }
int alias_db_find(struct sip_msg* _msg, str table, char* _in, char* _out, char* flags) { pv_value_t val; struct sip_uri puri; /* get the input value */ if (pv_get_spec_value(_msg, (pv_spec_t*)_in, &val)!=0) { LM_ERR("failed to get PV value\n"); return -1; } if ( (val.flags&PV_VAL_STR)==0 ) { LM_ERR("PV vals is not string\n"); return -1; } if (parse_uri(val.rs.s, val.rs.len, &puri)<0) { LM_ERR("failed to parse uri %.*s\n",val.rs.len,val.rs.s); return -1; } return alias_db_query(_msg, table, &puri, (unsigned long)flags, set_alias_to_pvar, _out); }
int extra2strar(struct acc_extra *extra, struct sip_msg *rq, str *val_arr, int *int_arr, char *type_arr) { pv_value_t value; int n; int i; n = 0; i = 0; while (extra) { /* get the value */ if (pv_get_spec_value( rq, &extra->spec, &value)!=0) { LM_ERR("failed to get '%.*s'\n", extra->name.len,extra->name.s); } /* check for overflow */ if (n==MAX_ACC_EXTRA) { LM_WARN("array to short -> ommiting extras for accounting\n"); goto done; } if(value.flags&PV_VAL_NULL) { /* convert <null> to empty to have consistency */ val_arr[n].s = 0; val_arr[n].len = 0; type_arr[n] = TYPE_NULL; } else { val_arr[n].s = (char *)pkg_malloc(value.rs.len); if (val_arr[n].s == NULL ) { LM_ERR("extra2strar: out of memory.\n"); /* Cleanup already allocated memory and return that we didn't do anything */ for (i = 0; i < n ; i++) { if (NULL != val_arr[i].s){ pkg_free(val_arr[i].s); val_arr[i].s = NULL; } } n = 0; goto done; } memcpy(val_arr[n].s, value.rs.s, value.rs.len); val_arr[n].len = value.rs.len; if (value.flags&PV_VAL_INT) { int_arr[n] = value.ri; type_arr[n] = TYPE_INT; } else { type_arr[n] = TYPE_STR; } } n++; extra = extra->next; } done: return n; }
struct to_body* get_b2bl_from(struct sip_msg* msg) { int len = 0; if(b2bl_from_spec_param.s) { memset(&b2bl_from_tok, 0, sizeof(pv_value_t)); if(pv_get_spec_value(msg, &b2bl_from_spec, &b2bl_from_tok) < 0) { LM_ERR("Failed to get b2bl_from value\n"); return NULL; } //LM_DBG("got b2bl_from_spec_param flags [%d]\n", b2bl_from_tok.flags); if(b2bl_from_tok.flags&PV_VAL_INT) { /* the PV might be empty */ return NULL; } if(b2bl_from_tok.flags&PV_VAL_STR) { //LM_DBG("got PV_SPEC b2bl_from [%.*s]\n", // b2bl_from_tok.rs.len, b2bl_from_tok.rs.s); if(b2bl_from_tok.rs.len+CRLF_LEN > B2BL_FROM_BUF_LEN) { LM_ERR("Buffer overflow\n"); return NULL; } trim(&b2bl_from_tok.rs); memcpy(b2bl_from_buf, b2bl_from_tok.rs.s, b2bl_from_tok.rs.len); len = b2bl_from_tok.rs.len; if(strncmp(b2bl_from_tok.rs.s + len - CRLF_LEN, CRLF, CRLF_LEN)) { memcpy(b2bl_from_buf + len, CRLF, CRLF_LEN); len+= CRLF_LEN; } parse_to(b2bl_from_buf, b2bl_from_buf+len, &b2bl_from); if (b2bl_from.error != PARSE_OK) { LM_ERR("Failed to parse PV_SPEC b2bl_from [%.*s]\n", len, b2bl_from_buf); return NULL; } if (parse_uri(b2bl_from.uri.s, b2bl_from.uri.len, &b2bl_from.parsed_uri)<0) { LM_ERR("failed to parse PV_SPEC b2bl_from uri [%.*s]\n", b2bl_from.uri.len, b2bl_from.uri.s); return NULL; } /* side effect of parsing - nobody should need them later on, * so free them right now */ free_to_params(&b2bl_from); return &b2bl_from; } } return NULL; }
int b2b_bridge_request(struct sip_msg* msg, str* p1, str* p2) { pv_value_t pv_val; str key = {NULL, 0}; int entity_no; if (p1 && (pv_get_spec_value(msg, (pv_spec_t *)p1, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { LM_DBG("got key:'%.*s'\n", pv_val.rs.len, pv_val.rs.s); key = pv_val.rs; } else { LM_ERR("Unable to get key from PV that is not a string\n"); return -1; } } else { LM_ERR("Unable to get key from pv:%p\n", p1); return -1; } if (p2 && (pv_get_spec_value(msg, (pv_spec_t *)p2, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_INT) { entity_no = pv_val.ri; LM_DBG("got entity_no %d\n", entity_no); } else if (pv_val.flags & PV_VAL_STR) { if(str2int(&(pv_val.rs), (unsigned int*)&entity_no) != 0) { LM_ERR("Unable to get entity_no from pv '%.*s'i\n", pv_val.rs.len, pv_val.rs.s); return -1; } } else { LM_ERR("second pv not a str or int type\n"); return -1; } } else { LM_ERR("Unable to get entity from pv:%p\n", p1); return -1; } return b2bl_bridge_msg(msg, &key, entity_no); }
static int w_pres_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2) { pv_spec_t *sp; pv_value_t pv_val; str watcher_uri, presentity_uri; sp = (pv_spec_t *)_sp1; if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { watcher_uri = pv_val.rs; if (watcher_uri.len == 0 || watcher_uri.s == NULL) { LM_ERR("missing watcher uri\n"); return -1; } } else { LM_ERR("watcher pseudo variable value is not string\n"); return -1; } } else { LM_ERR("cannot get watcher pseudo variable value\n"); return -1; } sp = (pv_spec_t *)_sp2; if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) { if (pv_val.flags & PV_VAL_STR) { presentity_uri = pv_val.rs; if (presentity_uri.len == 0 || presentity_uri.s == NULL) { LM_DBG("missing presentity uri\n"); return -1; } } else { LM_ERR("presentity pseudo variable value is not string\n"); return -1; } } else { LM_ERR("cannot get presentity pseudo variable value\n"); return -1; } return pres_auth_status(_msg, watcher_uri, presentity_uri); }
/** Get the function parameter value as integer. * @return 0 - Success * -1 - Cannot get value */ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param) { int_str val; int ret; avp_t* avp; str tmp; pv_value_t pv_val; switch(param->type) { case FPARAM_INT: *dst = param->v.i; return 0; case FPARAM_REGEX: case FPARAM_UNSPEC: case FPARAM_STRING: case FPARAM_STR: return -1; case FPARAM_AVP: avp = search_first_avp(param->v.avp.flags, param->v.avp.name, &val, 0); if (unlikely(!avp)) { DBG("Could not find AVP from function parameter '%s'\n", param->orig); return -1; } if (avp->flags & AVP_VAL_STR) { if (str2int(&val.s, (unsigned int*)dst) < 0) { LM_ERR("Could not convert AVP string value to int\n"); return -1; } } else { *dst = val.n; } break; case FPARAM_SELECT: ret = run_select(&tmp, param->v.select, msg); if (unlikely(ret < 0 || ret > 0)) return -1; if (unlikely(str2int(&tmp, (unsigned int*)dst) < 0)) { LM_ERR("Could not convert select result to int\n"); return -1; } break; case FPARAM_PVS: if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) && ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT))){ *dst=pv_val.ri; }else{ LM_ERR("Could not convert PV to int\n"); return -1; } break; case FPARAM_PVE: return -1; } return 0; }