| 934 | |
| 935 | |
| 936 | int do_lb_reset(struct sip_msg *req, struct lb_data *data) |
| 937 | { |
| 938 | struct usr_avp *id_avp; |
| 939 | struct usr_avp *res_avp, *del_res_avp; |
| 940 | int_str id_val; |
| 941 | int_str res_val; |
| 942 | |
| 943 | struct dlg_cell *dlg; |
| 944 | struct lb_dst *it_d, *last_dst; |
| 945 | struct lb_resource *it_r; |
| 946 | |
| 947 | if ( (dlg=lb_dlg_binds.get_dlg())==NULL ) { |
| 948 | LM_ERR("no dialog found for this call, LB not started\n"); |
| 949 | return -1; |
| 950 | } |
| 951 | |
| 952 | /* remove any saved AVPs */ |
| 953 | destroy_avps(0, group_avp_name, 0); |
| 954 | destroy_avps(0, flags_avp_name, 0); |
| 955 | destroy_avps(0, mask_avp_name, 0); |
| 956 | |
| 957 | /* get previous iteration destination, if any */ |
| 958 | last_dst = NULL; |
| 959 | id_avp = search_first_avp(0, id_avp_name, &id_val, NULL); |
| 960 | if( id_avp && (is_avp_str_val(id_avp) == 0) ) { |
| 961 | for( it_d=data->dsts ; it_d ; it_d=it_d->next ) { |
| 962 | if( it_d->id == id_val.n ) { |
| 963 | last_dst = it_d; |
| 964 | LM_DBG("reset LB - found previous dst %d [%.*s]\n", |
| 965 | last_dst->id, |
| 966 | last_dst->profile_id.len, last_dst->profile_id.s); |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | destroy_avps(0, id_avp_name, 0); |
| 972 | |
| 973 | /* any valid previous iteration ? */ |
| 974 | if(last_dst == NULL) { |
| 975 | /* simply delete all possible resources */ |
| 976 | destroy_avps(0, res_avp_name, 1); |
| 977 | } else { |
| 978 | /* search and clean up previous iteration resources, if any */ |
| 979 | res_avp = search_first_avp(0, res_avp_name, &res_val, NULL); |
| 980 | while (res_avp) { |
| 981 | if ( (it_r=get_resource_by_name( data, &res_val.s))!=NULL ) { |
| 982 | if( lb_dlg_binds.unset_profile(dlg, &last_dst->profile_id, |
| 983 | it_r->profile) != 1 ) |
| 984 | LM_ERR("reset LB - failed to remove from profile [%.*s]->" |
| 985 | "[%.*s]\n", res_val.s.len, res_val.s.s, |
| 986 | last_dst->profile_id.len, last_dst->profile_id.s ); |
| 987 | } else { |
| 988 | LM_WARN("reset LB - ignore unknown previous resource " |
| 989 | "[%.*s]\n", res_val.s.len, res_val.s.s); |
| 990 | } |
| 991 | |
| 992 | del_res_avp = res_avp; |
| 993 | res_avp = search_next_avp(del_res_avp, &res_val); |
no test coverage detected