unsigned long append_1 (unsigned long prefix) { static unsigned short prefix_bit[16] = { 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001 }; unsigned char len = (prefix >> 16) & 0xf; return (append_0(prefix) + prefix_bit[len]); }
int ops_pushto_avp (struct sip_msg* msg, struct fis_param* dst, struct fis_param* src) { struct action act; struct usr_avp *avp; unsigned short name_type; int_str avp_val; int avp_name; str val; int act_type; int n; int flags; pv_value_t xvalue; avp = NULL; flags = 0; if(src->u.sval.type==PVT_AVP) { /* search for the avp */ if(avpops_get_aname(msg, src, &avp_name, &name_type)!=0) { LM_ERR("failed to get src AVP name\n"); goto error; } avp = search_first_avp( name_type, avp_name, &avp_val, 0); if (avp==0) { LM_DBG(" no src avp found\n"); goto error; } flags = avp->flags; } else { if(pv_get_spec_value(msg, &(src->u.sval), &xvalue)!=0) { LM_ERR("cannot get src value\n"); goto error; } if(xvalue.flags&PV_TYPE_INT) { avp_val.n = xvalue.ri; } else { flags = AVP_VAL_STR; avp_val.s = xvalue.rs; } } n = 0; do { /* the avp val will be used all the time as str */ if (flags&AVP_VAL_STR) { val = avp_val.s; } else { val.s = int2str((unsigned long)avp_val.n, &val.len); } act_type = 0; /* push the value into right position */ if (dst->opd&AVPOPS_USE_RURI) { if (dst->opd&AVPOPS_FLAG_USER0) act_type = SET_USER_T; else if (dst->opd&AVPOPS_FLAG_DOMAIN0) act_type = SET_HOST_T; else act_type = SET_URI_T; if ( flags&AVP_VAL_STR && append_0( &val, &val)!=0 ) { LM_ERR("failed to make 0 term.\n"); goto error; } } else if (dst->opd&AVPOPS_USE_DURI) { if (!(flags&AVP_VAL_STR)) { goto error; } } else if (dst->opd&AVPOPS_USE_BRANCH) { if (!(flags&AVP_VAL_STR)) { goto error; } } else { LM_CRIT("destination unknown (%d/%d)\n", dst->opd, dst->ops); goto error; } if ( act_type ) { /* rewrite part of ruri */ if (n) { /* if is not the first modification, push the current uri as * branch */ if (append_branch( msg, 0, 0, 0, Q_UNSPECIFIED, 0, 0)!=1 ) { LM_ERR("append_branch action failed\n"); goto error; } } memset(&act, 0, sizeof(act)); act.elem[0].type = STR_ST; act.elem[0].u.s = val; act.type = act_type; if (do_action(&act, msg)<0) { LM_ERR("SET_XXXX_T action failed\n"); goto error; } } else if (dst->opd&AVPOPS_USE_DURI) { if(set_dst_uri(msg, &val)!=0) { LM_ERR("changing dst uri failed\n"); goto error; } } else if (dst->opd&AVPOPS_USE_BRANCH) { if (append_branch( msg, &val, 0, 0, Q_UNSPECIFIED, 0, msg->force_send_socket)!=1 ) { LM_ERR("append_branch action failed\n"); goto error; } } else { LM_ERR("unknown destination\n"); goto error; } n++; if ( !(src->ops&AVPOPS_FLAG_ALL) ) break; if(avp==NULL) break; if((avp = search_first_avp( name_type, avp_name, &avp_val, avp))!=NULL) flags = avp->flags; } while (avp);/* end while */ LM_DBG("%d avps were processed\n",n); return 1; error: return -1; }