Merge branch 'master' into treimann/master_tm-extend-callbacks
authorTimo Reimann <sr@foo-lounge.de>
Wed, 21 Dec 2011 19:01:06 +0000 (20:01 +0100)
committerTimo Reimann <sr@foo-lounge.de>
Wed, 21 Dec 2011 19:01:06 +0000 (20:01 +0100)
* master: (201 commits)
  modules: bunch of READMEs regenerated to be sync'ed with docbook
  modules: coherent naming of Statistics section in docbook
  sl: regenerated the readme
  sl: documented exported statistics
  core/tcp: define option TCP_CLONE_RCVBUF to turn off/on tcp rcv buffer cloning
  pdt(k): added rpc command pdt.reload
  pdt(k): MI commands can be disabled via define PDT_NO_MI
  pdt(k): updates to documentation
  pdt: refactored prefix-domain translation
  tcp: fix for ENOTCONN on newer FreeBSDs
  dialplan: added fnmatch (2) matching operator
  core/tcp: init max_tls_connections in tcp options check
  core/tcp: proper init of parameter tls_max_connections
  textopsx: added fnmatch(value, expr, flags) function
  core: added function to help fixup of PVE, string and expressions
  registrar(k): maintaining one contact per AoR has priority over max_contacts
  lib/srdb1: Enable non-pooled database connections to be defined.
  modules_k/presence: Added additional return value to pres_auth_status() for polite-block
  tls: new parameter 'renegotiation' to enable/disable client renegotiation
  tls: use pkg-config to get cflags and libs for compilation
  ...

1  2 
modules/tm/t_fwd.c
modules/tm/t_reply.c

diff --combined modules/tm/t_fwd.c
@@@ -374,6 -374,10 +374,10 @@@ static int prepare_new_uac( struct cel
                           ignored) */
                        next_hop=&i_req->dst_uri;
                }
+               /* no path vector initially, but now is set after branch route and
+                * callbacks execution */
+               if(i_req->path_vec.s!=0 && free_path==0)
+                       free_path=1;
        }else{
                /* no branch route and no TMCB_REQUEST_FWDED callback => set
                   msg uri and path to the new values (if needed) */
@@@ -1188,12 -1192,14 +1192,12 @@@ void e2e_cancel( struct sip_msg *cancel
                                if (SEND_BUFFER(&t_cancel->uac[i].request) == -1) {
                                        LOG(L_ERR, "ERROR: e2e_cancel: send failed\n");
                                }
 -#ifdef TMCB_ONSEND
                                else{
                                        if (unlikely(has_tran_tmcbs(t_cancel, TMCB_REQUEST_SENT)))
 -                                              run_onsend_callbacks(TMCB_REQUEST_SENT, 
 -                                                                                              &t_cancel->uac[i].request,
 -                                                                                              cancel_msg, 0, TMCB_LOCAL_F);
 +                                              run_trans_callbacks_with_buf(TMCB_REQUEST_SENT,
 +                                                                           &t_cancel->uac[i].request,
 +                                                                           cancel_msg, 0, TMCB_LOCAL_F);
                                }
 -#endif
                                if (start_retr( &t_cancel->uac[i].request )!=0)
                                        LOG(L_CRIT, "BUG: e2e_cancel: failed to start retr."
                                                        " for %p\n", &t_cancel->uac[i].request);
@@@ -1380,8 -1386,10 +1384,8 @@@ int t_send_branch( struct cell *t, int 
                if (proxy) { proxy->errors++; proxy->ok=0; }
                return -2;
        } else {
 -#ifdef TMCB_ONSEND
                if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 -                      run_onsend_callbacks(TMCB_REQUEST_SENT, &uac->request, p_msg, 0,0);
 -#endif
 +                      run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, &uac->request, p_msg, 0,0);
                /* start retr. only if the send succeeded */
                if (start_retr( &uac->request )!=0){
                        LOG(L_CRIT, "BUG: t_send_branch: retr. already started for %p\n",
@@@ -1542,12 -1550,8 +1546,12 @@@ int t_forward_nonack( struct cell *t, s
                        
                        branch_ret=t_send_branch(t, i, p_msg , proxy, lock_replies);
                        if (branch_ret>=0){ /* some kind of success */
 -                              if (branch_ret==i) /* success */
 +                              if (branch_ret==i) /* success */
                                        success_branch++;
 +                                      if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
 +                                              run_trans_callbacks_with_buf( TMCB_REQUEST_OUT, &t->uac[i].request,
 +                                                                            p_msg, 0, -p_msg->REQ_METHOD);
 +                              }
                                else /* new branch added */
                                        added_branches |= 1<<branch_ret;
                        }
diff --combined modules/tm/t_reply.c
@@@ -564,7 -564,9 +564,7 @@@ static int _reply_light( struct cell *t
        struct retr_buf *rb;
        unsigned int buf_len;
        struct cancel_info cancel_data;
 -#ifdef TMCB_ONSEND
        struct tmcb_params onsend_params;
 -#endif
  
        init_cancel_info(&cancel_data);
        if (!buf)
                                                                        0, FAKED_REPLY, code);
                } else {
                        if(unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_READY))) {
 -                              run_trans_callbacks(TMCB_RESPONSE_READY, trans,
 +                              run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, rb,
                                        trans->uas.request, FAKED_REPLY, code);
                        }
                }
                start_final_repl_retr(  trans );
        }
  
 +      if (code==100) {
 +              if(unlikely(has_tran_tmcbs(trans, TMCB_REQUEST_PENDING)))
 +                      run_trans_callbacks_with_buf(TMCB_REQUEST_PENDING, rb,
 +                                      trans->uas.request, FAKED_REPLY, code);
 +      }
 +
        /* send it out */
        /* first check if we managed to resolve topmost Via -- if
           not yet, don't try to retransmit
        } else {
                if (likely(SEND_PR_BUFFER( rb, buf, len )>=0)){
                        if (unlikely(code>=200 && !is_local(trans) &&
 -                                              has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) )
 -                              run_trans_callbacks(TMCB_RESPONSE_OUT, trans,
 -                                                                      trans->uas.request, FAKED_REPLY, code);
 -#ifdef TMCB_ONSEND
 +                                              has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) ){
 +                              INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
 +                                                              FAKED_REPLY, rb, &rb->dst,
 +                                                              buf, len, TMCB_LOCAL_F, rb->branch, code);
 +                              run_trans_callbacks_off_params(TMCB_RESPONSE_OUT, trans,
 +                                                             &onsend_params);
 +                      }
                        if (unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))){
                                INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request,
                                                                FAKED_REPLY, rb, &rb->dst, 
                                                                buf, len, TMCB_LOCAL_F, rb->branch, code);
 -                              run_onsend_callbacks2(TMCB_RESPONSE_SENT, trans,
 -                                                                              &onsend_params);
 +                              run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, trans,
 +                                                             &onsend_params);
                        }
 -#endif /* TMCB_ONSEND */
                }
                DBG("DEBUG: reply sent out. buf=%p: %.20s..., shmem=%p: %.20s\n",
                        buf, buf, rb->buffer, rb->buffer );
@@@ -770,6 -764,11 +770,11 @@@ void faked_env( struct cell *t, struct 
  #endif
        static struct socket_info* backup_si;
  
+       static struct lump *backup_add_rm;
+       static struct lump *backup_body_lumps;
+       static struct lump_rpl *backup_reply_lump;
        if (msg) {
                /* remember we are back in request processing, but process
                 * a shmem-ed replica of the request; advertise it in route type;
                /* set default send address to the saved value */
                backup_si=bind_address;
                bind_address=t->uac[0].request.dst.send_sock;
+               /* backup lump lists */
+               backup_add_rm = t->uas.request->add_rm;
+               backup_body_lumps = t->uas.request->body_lumps;
+               backup_reply_lump = t->uas.request->reply_lump;
        } else {
                /* restore original environment */
                set_t(backup_t, backup_branch);
                xavp_set_list(backup_xavps);
  #endif
                bind_address=backup_si;
+               /* restore lump lists */
+               t->uas.request->add_rm = backup_add_rm;
+               t->uas.request->body_lumps = backup_body_lumps;
+               t->uas.request->reply_lump = backup_reply_lump;
        }
  }
  
@@@ -1450,12 -1457,14 +1463,12 @@@ int t_retransmit_reply( struct cell *t 
        memcpy( b, t->uas.response.buffer, len );
        UNLOCK_REPLIES( t );
        SEND_PR_BUFFER( & t->uas.response, b, len );
 -#ifdef TMCB_ONSEND
        if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){ 
                /* we don't know if it's a retransmission of a local reply or a 
                 * forwarded reply */
 -              run_onsend_callbacks(TMCB_RESPONSE_SENT, &t->uas.response, 0, 0,
 -                                                              TMCB_RETR_F);
 +              run_trans_callbacks_with_buf(TMCB_RESPONSE_SENT, &t->uas.response, 0, 0,
 +                                           TMCB_RETR_F);
        }
 -#endif
        DBG("DEBUG: reply retransmitted. buf=%p: %.9s..., shmem=%p: %.9s\n",
                b, b, t->uas.response.buffer, t->uas.response.buffer );
        return 1;
@@@ -1639,7 -1648,9 +1652,7 @@@ enum rps relay_reply( struct cell *t, s
        struct retr_buf *uas_rb;
        str* to_tag;
        str reason;
 -#ifdef TMCB_ONSEND
        struct tmcb_params onsend_params;
 -#endif
  
        /* keep compiler warnings about use of uninit vars silent */
        res_len=0;
        /* send it now (from the private buffer) */
        if (relay >= 0) {
                if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_READY))){
 -                      run_trans_callbacks(TMCB_RESPONSE_READY, t,
 +                      run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, uas_rb,
                                        t->uas.request, relayed_msg, relayed_code);
                }
                /* Set retransmission timer before the reply is sent out to avoid
                if (likely(uas_rb->dst.send_sock &&
                                        SEND_PR_BUFFER( uas_rb, buf, res_len ) >= 0)){
                        if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT))){
 -                              run_trans_callbacks( TMCB_RESPONSE_OUT, t, t->uas.request,
 -                                      relayed_msg, relayed_code);
 +                              run_trans_callbacks_with_buf( TMCB_RESPONSE_OUT, uas_rb, t->uas.request,
 +                                                            relayed_msg, relayed_code);
                        }
 -#ifdef TMCB_ONSEND
                        if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){
                                INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request,
                                                                        relayed_msg, uas_rb, &uas_rb->dst, buf,
                                                                        res_len,
                                                                        (relayed_msg==FAKED_REPLY)?TMCB_LOCAL_F:0,
                                                                        uas_rb->branch, relayed_code);
 -                              run_onsend_callbacks2(TMCB_RESPONSE_SENT, t, &onsend_params);
 +                              run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, t, &onsend_params);
                        }
 -#endif
                } else if (unlikely(uas_rb->dst.send_sock == 0))
                        ERR("no resolved dst to send reply to\n");
                /* Call put_on_wait() only if we really send out
@@@ -2013,7 -2026,9 +2026,7 @@@ int reply_received( struct sip_msg  *p_
        int blst_503_timeout;
        struct hdr_field* hf;
  #endif
 -#ifdef TMCB_ONSEND
        struct tmcb_params onsend_params;
 -#endif
        struct run_act_ctx ctx;
  
        /* make sure we know the associated transaction ... */
                        if (msg_status >= 300) {
                                ack = build_ack(p_msg, t, branch, &ack_len);
                                if (ack) {
 -#ifdef        TMCB_ONSEND
                                        if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0)
                                                if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){ 
                                                        INIT_TMCB_ONSEND_PARAMS(onsend_params, 
                                                                        t->uas.request, p_msg, &uac->request,
                                                                        &uac->request.dst, ack, ack_len,
                                                                        TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
 -                                                      run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
 -                                                                                                      &onsend_params);
 +                                                      run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
 +                                                                                     &onsend_params);
 +                                              }
 +                                              if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))){
 +                                                      INIT_TMCB_ONSEND_PARAMS(onsend_params,
 +                                                                      t->uas.request, p_msg, &uac->request,
 +                                                                      &uac->request.dst, ack, ack_len,
 +                                                                      TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
 +                                                      run_trans_callbacks_off_params(TMCB_ACK_NEG_IN, t,
 +                                                                                     &onsend_params);
                                                }
 -#else
 -                                      SEND_PR_BUFFER(&uac->request, ack, ack_len);
 -#endif
                                        shm_free(ack);
                                }
                        } else if (is_local(t) /*&& 200 <= msg_status < 300*/) {
                                if (ack) {
                                        if (msg_send(&lack_dst, ack, ack_len)<0)
                                                LOG(L_ERR, "Error while sending local ACK\n");
 -#ifdef        TMCB_ONSEND
                                        else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
                                                        INIT_TMCB_ONSEND_PARAMS(onsend_params, 
                                                                        t->uas.request, p_msg, &uac->request,
                                                                        &lack_dst, ack, ack_len, TMCB_LOCAL_F,
                                                                        branch, TYPE_LOCAL_ACK);
 -                                                      run_onsend_callbacks2(TMCB_REQUEST_SENT, t,
 -                                                                                                      &onsend_params);
 +                                                      run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
 +                                                                                     &onsend_params);
                                        }
 -#endif
  #ifndef WITH_AS_SUPPORT
                                        shm_free(ack);
  #endif
                                                                  local_cancel */
                                /* re-transmit if cancel already built */
                                DBG("tm: reply_received: branch CANCEL retransmit\n");
 -#ifdef TMCB_ONSEND
                                if (SEND_BUFFER( &uac->local_cancel)>=0){
                                        if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
 -                                              run_onsend_callbacks(TMCB_REQUEST_SENT,
 -                                                                                      &uac->local_cancel,
 -                                                                                      0, 0, TMCB_LOCAL_F);
 +                                              run_trans_callbacks_with_buf(TMCB_REQUEST_SENT,
 +                                                                           &uac->local_cancel,
 +                                                                           0, 0, TMCB_LOCAL_F);
                                }
 -#else
 -                              SEND_BUFFER( &uac->local_cancel );
 -#endif
                                /* retrs. should be already started so do nothing */
                        }else if (atomic_cmpxchg_long((void*)&uac->local_cancel.buffer, 0,
                                                                                (long)BUSY_BUFFER)==0){