rem: avp = search_first_avp(contact_avp_name_str, contact_name, &val); do { DBG("load_contacts(): DEBUG: Loaded <%s>, q_flag <%d>\n", val.s->s, avp->flags & Q_FLAG); avp = search_next_avp(avp, &val); } while (avp);
context: int load_contacts(struct sip_msg* msg, char* key, char* value){	    	str branch, *ruri;	qvalue_t q, ruri_q;	struct contact *contacts, *next, *prev, *curr;	int_str val;	struct usr_avp *avp;	/* Check if anything needs to be done */	if (nr_branches == 0) {	    DBG("load_contacts(): DEBUG: Nothing to do - no branches!\n");	    return 1;	}	ruri = GET_RURI(msg);	if (!ruri) {	    LOG(L_ERR, "ERROR: load_contacts(): No Request-URI found\n");	    return -1;	}	ruri_q = get_ruri_q();	init_branch_iterator();	while((branch.s = next_branch(&branch.len, &q, 0, 0, 0))) {	    if (q != ruri_q) {		goto rest;	    }	}	DBG("load_contacts(): DEBUG: Nothing to do - all same q!\n");	return 1;rest:	/* Insert Request-URI to contact list */	contacts = (struct contact *)pkg_malloc(sizeof(struct contact));	if (!contacts) {	    LOG(L_ERR, "ERROR: load_contacts(): No memory for Request-URI\n");	    return -1;	}	contacts->uri.s = ruri->s;	contacts->uri.len = ruri->len;	contacts->q = ruri_q;	contacts->next = (struct contact *)0;	/* Insert branch URIs to contact list in increasing q order */	init_branch_iterator();	while((branch.s = next_branch(&branch.len, &q, 0, 0, 0))) {	    next = (struct contact *)pkg_malloc(sizeof(struct contact));	    if (!next) {		LOG(L_ERR, "ERROR: load_contacts(): No memory for branch URI\n");		free_contact_list(contacts);		return -1;	    }	    next->uri = branch;	    next->q = q;	    prev = (struct contact *)0;	    curr = contacts;	    while (curr && (curr->q < q)) {		prev = curr;		curr = curr->next;	    }	    if (!curr) {		next->next = (struct contact *)0;		prev->next = next;	    } else {		next->next = curr;		if (prev) {		    prev->next = next;		} else {		    contacts = next;		}	    }		    	}	/* Assign values for q_flags */	curr = contacts;	curr->q_flag = 0;	while (curr->next) {	    if (curr->q < curr->next->q) {		curr->next->q_flag = Q_FLAG;	    } else {		curr->next->q_flag = 0;	    }	    curr = curr->next;	}	/* Add contacts to "contacts" AVP */	curr = contacts;	while (curr) {	    val.s = &(curr->uri);	    add_avp(contact_avp_name_str|AVP_VAL_STR|(curr->q_flag),		    contact_name, val);	    curr = curr->next;	}	/* Clear all branches */	clear_branches();	/* Free contacts list */	free_contact_list(contacts);	/* Print all avp_contact_avp attributes */	avp = search_first_avp(contact_avp_name_str, contact_name, &val);	do {	    DBG("load_contacts(): DEBUG: Loaded <%s>, q_flag <%d>\n",		val.s->s, avp->flags & Q_FLAG);	    avp = search_next_avp(avp, &val);	} while (avp);		return 1;}