MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / w_shuffle_avps

Function w_shuffle_avps

modules/cfgutils/cfgutils.c:886–928  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886static int w_shuffle_avps(struct sip_msg* msg, pv_spec_t *pv_name)
887{
888 struct usr_avp *src_avp, *rnd_avp;
889 struct usr_avp *temp_avp = NULL;
890 int_str src_val, rnd_val;
891 unsigned short avp_type;
892 int avp_name;
893 int n, rnd_idx;
894
895 /* get the name */
896 if(pv_get_avp_name(msg, &pv_name->pvp, &avp_name, &avp_type)!=0)
897 {
898 LM_ERR("invalid name\n");
899 return -1;
900 }
901
902 /* count AVPs */
903 n = 0;
904 while ((temp_avp=search_first_avp(avp_type, avp_name, NULL, temp_avp)) != 0)
905 n++;
906
907 /* randomize AVPs */
908 for ( ; n>1; n-- ) {
909 rnd_idx = random() % n;
910 if (rnd_idx == (n-1))
911 continue;
912
913 LM_DBG("swapping [%d] <--> [%d]\n", (n-1), rnd_idx);
914
915 src_avp = search_index_avp(avp_type, avp_name, &src_val, (n-1));
916 rnd_avp = search_index_avp(avp_type, avp_name, &rnd_val, rnd_idx);
917
918 if ( replace_avp(avp_type|(rnd_avp->flags&AVP_VAL_STR), avp_name, rnd_val, (n-1))==-1 ||
919 replace_avp(avp_type|(src_avp->flags&AVP_VAL_STR), avp_name, src_val, rnd_idx)==-1 ) {
920 LM_ERR("failed to swap avp\n");
921 goto error;
922 }
923 }
924
925 return 1;
926error:
927 return -1;
928}
929

Callers

nothing calls this directly

Calls 4

pv_get_avp_nameFunction · 0.85
search_first_avpFunction · 0.85
search_index_avpFunction · 0.85
replace_avpFunction · 0.85

Tested by

no test coverage detected