int get_redirect( struct sip_msg *msg , int maxt, int maxb, pv_elem_t *reason) { struct cell *t; int max; int cts_added; int n; int i; /* get transaction */ t = rd_tmb.t_gett(); if (t==T_UNDEFINED || t==T_NULL_CELL) { LM_CRIT("no current transaction found\n"); goto error; } LM_DBG("resume branch=%d\n", t->first_branch); cts_added = 0; /* no contact added */ /* look if there are any 3xx branches starting from resume_branch */ for( i=t->first_branch ; i<t->nr_of_outgoings ; i++) { LM_DBG("checking branch=%d (added=%d)\n", i, cts_added); /* is a redirected branch? */ if (t->uac[i].last_received<300 || t->uac[i].last_received>399) continue; LM_DBG("branch=%d is a redirect (added=%d)\n", i, cts_added); /* ok - we have a new redirected branch -> how many contacts can * we get from it*/ if (maxb==0) { max = maxt?(maxt-cts_added):(-1); } else { max = maxt?((maxt-cts_added>=maxb)?maxb:(maxt-cts_added)):maxb; } if (max==0) continue; /* get the contact from it */ n = shmcontact2dset( msg, t->uac[i].reply, max, reason); if ( n<0 ) { LM_ERR("get contact from shm_reply branch %d failed\n",i); /* do not go to error, try next branches */ } else { /* count the added contacts */ cts_added += n; } } /* return false if no contact was appended */ return (cts_added>0)?1:-1; error: return -1; }
int get_redirect( struct sip_msg *msg , int maxt, int maxb, str *reason) { struct cell *t; str backup_uri; int max; int cts_added; int n; int i; /* get transaction */ t = rd_tmb.t_gett(); if (t==T_UNDEFINED || t==T_NULL_CELL) { LOG(LOG_CRIT,"BUG:uac_redirect:get_redirect: no current " "transaction found\n"); goto error; } DBG("DEBUG:uac_redirect:get_redirect: resume branch=%d\n", t->first_branch); cts_added = 0; /* no contact added */ backup_uri = msg->new_uri; /* shmcontact2dset will ater this value */ /* look if there are any 3xx branches starting from resume_branch */ for( i=t->first_branch ; i<t->nr_of_outgoings ; i++) { DBG("DEBUG:uac_redirect:get_redirect: checking branch=%d " "(added=%d)\n", i, cts_added); /* is a redirected branch? */ if (t->uac[i].last_received<300 || t->uac[i].last_received>399) continue; DBG("DEBUG:uac_redirect:get_redirect: branch=%d is a redirect " "(added=%d)\n", i, cts_added); /* ok - we have a new redirected branch -> how many contacts can * we get from it*/ if (maxb==0) { max = maxt?(maxt-cts_added):(-1); } else { max = maxt?((maxt-cts_added>=maxb)?maxb:(maxt-cts_added)):maxb; } if (max==0) continue; /* get the contact from it */ n = shmcontact2dset( msg, t->uac[i].reply, max, reason); if ( n<0 ) { LOG(L_ERR,"ERROR:uac_redirect:get_redirects: get contact from " "shm_reply branch %d failed\n",i); /* do not go to error, try next branches */ } else { /* count the added contacts */ cts_added += n; } } /* restore original new_uri */ msg->new_uri = backup_uri; /* return false if no contact was appended */ return (cts_added>0)?1:-1; error: return -1; }
int get_redirect( struct sip_msg *msg , int maxt, int maxb, struct acc_param *reason, unsigned int bflags) { struct cell *t; str backup_uri; int max; int cts_added; int n; int i; int first_branch; char code_buf[INT2STR_MAX_LEN]; /* get transaction */ t = rd_tmb.t_gett(); if (t==T_UNDEFINED || t==T_NULL_CELL) { LM_CRIT("no current transaction found\n"); goto error; } for(first_branch=t->nr_of_outgoings-1; first_branch>=0; first_branch--) if(t->uac[first_branch].flags&TM_UAC_FLAG_FB) break; if(first_branch<0) { LM_CRIT("no current first branch found\n"); goto error; } LM_DBG("resume branch=%d\n", first_branch); cts_added = 0; /* no contact added */ backup_uri = msg->new_uri; /* shmcontact2dset will ater this value */ /* look if there are any 3xx branches starting from resume_branch */ for( i=first_branch ; i<t->nr_of_outgoings ; i++) { LM_DBG("checking branch=%d (added=%d)\n", i, cts_added); /* is a redirected branch? */ if (t->uac[i].last_received<300 || t->uac[i].last_received>399) continue; LM_DBG("branch=%d is a redirect (added=%d)\n", i, cts_added); /* ok - we have a new redirected branch -> how many contacts can * we get from it*/ if (maxb==0) { max = maxt?(maxt-cts_added):(-1); } else { max = maxt?((maxt-cts_added>=maxb)?maxb:(maxt-cts_added)):maxb; } if (max==0) continue; if(reason!=NULL) { /* put the response code into the acc_param reason struct */ reason->code = t->uac[i].last_received; reason->code_s.s = int2bstr((unsigned long)reason->code, code_buf, &reason->code_s.len); } /* get the contact from it */ n = shmcontact2dset( msg, t->uac[i].reply, max, reason, bflags); if ( n<0 ) { LM_ERR("get contact from shm_reply branch %d failed\n",i); /* do not go to error, try next branches */ } else { /* count the added contacts */ cts_added += n; } } /* restore original new_uri */ msg->new_uri = backup_uri; /* return false if no contact was appended */ return (cts_added>0)?1:-1; error: return -1; }