tm: option to compile without reason support
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Fri, 13 Aug 2010 15:20:26 +0000 (17:20 +0200)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Fri, 13 Aug 2010 15:27:19 +0000 (17:27 +0200)
If compiled with -DNO_CANCEL_REASON_SUPPORT, the reason header
support will not be enabled.

modules/tm/h_table.c
modules/tm/h_table.h
modules/tm/t_cancel.c
modules/tm/t_cancel.h
modules/tm/t_fwd.c
modules/tm/t_msgbuilder.c
modules/tm/t_msgbuilder.h
modules/tm/t_reply.c
modules/tm/t_reply.h
modules/tm/timer.c

index e379f21..520bc32 100644 (file)
@@ -138,8 +138,10 @@ void free_cell( struct cell* dead_cell )
                sip_msg_free_unsafe( dead_cell->uas.request );
        if ( dead_cell->uas.response.buffer )
                shm_free_unsafe( dead_cell->uas.response.buffer );
+#ifdef CANCEL_REASON_SUPPORT
        if (unlikely(dead_cell->uas.cancel_reas))
                shm_free_unsafe(dead_cell->uas.cancel_reas);
+#endif /* CANCEL_REASON_SUPPORT */
 
        /* callbacks */
        for( cbs=(struct tm_callback*)dead_cell->tmcb_hl.first ; cbs ; ) {
index 38ecf07..6622e8c 100644 (file)
@@ -191,8 +191,10 @@ typedef struct ua_server
         * we need them for dialog-wise matching of ACKs;
         * the pointer shows to shmem-ed reply */
        str                              local_totag;
+#ifdef CANCEL_REASON_SUPPORT
        struct cancel_reason* cancel_reas; /* pointer to cancel reason, used
                                                                                  for e2e cancels */
+#endif /* CANCEL_REASON_SUPPORT */
        unsigned int     status;
 }ua_server_type;
 
index e1cf97e..0281fc1 100644 (file)
@@ -123,7 +123,9 @@ int cancel_uacs( struct cell *t, struct cancel_info* cancel_data, int flags)
                        r=cancel_branch(
                                t,
                                i,
+#ifdef CANCEL_REASON_SUPPORT
                                &cancel_data->reason,
+#endif /* CANCEL_REASON_SUPPORT */
                                flags | ((t->uac[i].request.buffer==NULL)?
                                        F_CANCEL_B_FAKE_REPLY:0) /* blind UAC? */
                        );
@@ -206,7 +208,10 @@ int cancel_all_uacs(struct cell *trans, int how)
  *          - checking for buffer==0 under REPLY_LOCK is no enough, an 
  *           atomic_cmpxhcg or atomic_get_and_set _must_ be used.
  */
-int cancel_branch( struct cell *t, int branch, struct cancel_reason* reason,
+int cancel_branch( struct cell *t, int branch,
+       #ifdef CANCEL_REASON_SUPPORT
+                                       struct cancel_reason* reason,
+       #endif /* CANCEL_REASON_SUPPORT */
                                        int flags )
 {
        char *cancel;
@@ -278,11 +283,18 @@ int cancel_branch( struct cell *t, int branch, struct cancel_reason* reason,
        if (cfg_get(tm, tm_cfg, reparse_invite)) {
                /* build the CANCEL from the INVITE which was sent out */
                cancel = build_local_reparse(t, branch, &len, CANCEL, CANCEL_LEN,
-                                                                        &t->to, reason);
+                                                                        &t->to
+       #ifdef CANCEL_REASON_SUPPORT
+                                                                        , reason
+       #endif /* CANCEL_REASON_SUPPORT */
+                                                                        );
        } else {
-               /* build the CANCEL from the reveived INVITE */
-               cancel = build_local(t, branch, &len, CANCEL, CANCEL_LEN, &t->to,
-                                                        reason);
+               /* build the CANCEL from the received INVITE */
+               cancel = build_local(t, branch, &len, CANCEL, CANCEL_LEN, &t->to
+       #ifdef CANCEL_REASON_SUPPORT
+                                                               , reason
+       #endif /* CANCEL_REASON_SUPPORT */
+                                                               );
        }
        if (!cancel) {
                LOG(L_ERR, "ERROR: attempt to build a CANCEL failed\n");
index ddb1e9e..b03231d 100644 (file)
 void prepare_to_cancel(struct cell *t, branch_bm_t *cancel_bm, branch_bm_t s);
 int cancel_uacs( struct cell *t, struct cancel_info* cancel_data, int flags );
 int cancel_all_uacs(struct cell *trans, int how);
-int cancel_branch( struct cell *t, int branch, struct cancel_reason* reason,
+int cancel_branch( struct cell *t, int branch,
+#ifdef CANCEL_REASON_SUPPORT
+                                       struct cancel_reason* reason,
+#endif /* CANCEL_REASON_SUPPORT */
                                        int flags );
 
 typedef int(*cancel_uacs_f)( struct cell *t, branch_bm_t cancel_bm,
index 51d23d5..4e6271a 100644 (file)
@@ -918,7 +918,11 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
                        "thus lumps are not applied to the message!\n");
                }
                shbuf=build_local_reparse( t_invite, branch, &len, CANCEL,
-                                                                       CANCEL_LEN, &t_invite->to, 0);
+                                                                       CANCEL_LEN, &t_invite->to
+#ifdef CANCEL_REASON_SUPPORT
+                                                                       , 0
+#endif /* CANCEL_REASON_SUPPORT */
+                                                                       );
                if (unlikely(!shbuf)) {
                        LOG(L_ERR, "e2e_cancel_branch: printing e2e cancel failed\n");
                        ret=ser_error=E_OUT_OF_MEM;
@@ -951,6 +955,7 @@ error:
 
 
 
+#ifdef CANCEL_REASON_SUPPORT
 /** create a cancel reason structure packed into a single shm. block.
   * From a cause and a pointer to a str or cancel_msg, build a
   * packed cancel reason structure (CANCEL_REAS_PACKED_HDRS), using a
@@ -975,6 +980,8 @@ static struct cancel_reason* cancel_reason_pack(short cause, void* data,
                reason_len = 0;
                txt = 0;
                e2e_cancel = 0;
+               reas1 = 0;
+               reas_last = 0;
                if (likely(cause == CANCEL_REAS_RCVD_CANCEL &&
                                        data && !(t->flags & T_NO_E2E_CANCEL_REASON))) {
                        /* parse the entire cancel, to get all the Reason headers */
@@ -1046,6 +1053,7 @@ static struct cancel_reason* cancel_reason_pack(short cause, void* data,
 error:
        return 0;
 }
+#endif /* CANCEL_REASON_SUPPORT */
 
 
 
@@ -1055,7 +1063,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
        branch_bm_t cancel_bm;
 #ifndef E2E_CANCEL_HOP_BY_HOP
        branch_bm_t tmp_bm;
-#else /* def E2E_CANCEL_HOP_BY_HOP */
+#elif defined (CANCEL_REASON_SUPPORT)
        struct cancel_reason* reason;
        int free_reason;
 #endif /* E2E_CANCEL_HOP_BY_HOP */
@@ -1103,6 +1111,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
         * have 0 branches and we check for the branch number in 
         * t_reply_matching() ).
         */
+#ifdef CANCEL_REASON_SUPPORT
        free_reason = 0;
        reason = 0;
        if (likely(t_invite->uas.cancel_reas == 0)){
@@ -1116,6 +1125,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
                        free_reason = 1;
                }
        }
+#endif /* CANCEL_REASON_SUPPORT */
        for (i=0; i<t_invite->nr_of_outgoings; i++)
                if (cancel_bm & (1<<i)) {
                        /* it's safe to get the reply lock since e2e_cancel is
@@ -1125,7 +1135,9 @@ void e2e_cancel( struct sip_msg *cancel_msg,
                        ret=cancel_branch(
                                t_invite,
                                i,
+#ifdef CANCEL_REASON_SUPPORT
                                reason,
+#endif /* CANCEL_REASON_SUPPORT */
                                cfg_get(tm,tm_cfg, cancel_b_flags)
                                        | ((t_invite->uac[i].request.buffer==NULL)?
                                                F_CANCEL_B_FAKE_REPLY:0) /* blind UAC? */
@@ -1133,10 +1145,12 @@ void e2e_cancel( struct sip_msg *cancel_msg,
                        if (ret<0) cancel_bm &= ~(1<<i);
                        if (ret<lowest_error) lowest_error=ret;
                }
+#ifdef CANCEL_REASON_SUPPORT
        if (unlikely(free_reason)) {
                /* reason was not set as the global reason => free it */
                shm_free(reason);
        }
+#endif /* CANCEL_REASON_SUPPORT */
 #else /* ! E2E_CANCEL_HOP_BY_HOP */
        /* fix label -- it must be same for reply matching (the label is part of
         * the generated via branch for the cancels sent upstream and if it
index c0f8cfc..d012723 100644 (file)
    customers of this function are local ACK and local CANCEL
  */
 char *build_local(struct cell *Trans,unsigned int branch,
-       unsigned int *len, char *method, int method_len, str *to,
-       struct cancel_reason* reason)
+       unsigned int *len, char *method, int method_len, str *to
+#ifdef CANCEL_REASON_SUPPORT
+       , struct cancel_reason* reason
+#endif /* CANCEL_REASON_SUPPORT */
+       )
 {
        char                *cancel_buf, *p, *via;
        unsigned int         via_len;
@@ -97,8 +100,10 @@ char *build_local(struct cell *Trans,unsigned int branch,
        str branch_str;
        str via_id;
        struct hostport hp;
+#ifdef CANCEL_REASON_SUPPORT
        int reason_len, code_len;
        struct hdr_field *reas1, *reas_last;
+#endif /* CANCEL_REASON_SUPPORT */
 
        /* init */
        via_id.s=0;
@@ -163,6 +168,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
        }
        /* Content Length, EoM */
        *len+=CONTENT_LENGTH_LEN+1 + CRLF_LEN;
+#ifdef CANCEL_REASON_SUPPORT
        reason_len = 0;
        reas1 = 0;
        reas_last = 0;
@@ -193,6 +199,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
                        BUG("unhandled reason cause %d\n", reason->cause);
        }
        *len+= reason_len;
+#endif /* CANCEL_REASON_SUPPORT */
        *len+= CRLF_LEN; /* end of msg. */
 
        cancel_buf=shm_malloc( *len+1 );
@@ -235,6 +242,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
        }
        /* Content Length */
        append_str(p, CONTENT_LENGTH "0" CRLF, CONTENT_LENGTH_LEN + 1 + CRLF_LEN);
+#ifdef CANCEL_REASON_SUPPORT
        /* add reason if needed */
        if (reason_len) {
                if (likely(reason->cause > 0)) {
@@ -262,6 +270,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
                        }
                }
        }
+#endif /* CANCEL_REASON_SUPPORT */
        append_str(p, CRLF, CRLF_LEN); /* msg. end */
        *p=0;
 
@@ -280,8 +289,11 @@ error:
  * Can not be used to build other type of requests!
  */
 char *build_local_reparse(struct cell *Trans,unsigned int branch,
-       unsigned int *len, char *method, int method_len, str *to,
-       struct cancel_reason *reason)
+       unsigned int *len, char *method, int method_len, str *to
+#ifdef CANCEL_REASON_SUPPORT
+       , struct cancel_reason *reason
+#endif /* CANCEL_REASON_SUPPORT */
+       )
 {
        char    *invite_buf, *invite_buf_end;
        char    *cancel_buf;
@@ -289,8 +301,11 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
        short   invite_len;
        enum _hdr_types_t       hf_type;
        int     first_via, to_len;
-       int cancel_buf_len, reason_len, code_len;
+       int cancel_buf_len;
+#ifdef CANCEL_REASON_SUPPORT
+       int reason_len, code_len;
        struct hdr_field *reas1, *reas_last, *hdr;
+#endif /* CANCEL_REASON_SUPPORT */
 
        invite_buf = Trans->uac[branch].request.buffer;
        invite_len = Trans->uac[branch].request.buffer_len;
@@ -305,6 +320,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
                goto error;
        }
        
+#ifdef CANCEL_REASON_SUPPORT
        reason_len = 0;
        reas1 = 0;
        reas_last = 0;
@@ -334,6 +350,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
                } else if (unlikely(reason->cause < CANCEL_REAS_MIN))
                        BUG("unhandled reason cause %d\n", reason->cause);
        }
+#endif /* CANCEL_REASON_SUPPORT */
 
        invite_buf_end = invite_buf + invite_len;
        s = invite_buf;
@@ -343,7 +360,11 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
        I just extend it with the length of new To HF to be sure.
        Ugly, but we avoid lots of checks and memory allocations this way */
        to_len = to ? to->len : 0;
+#ifdef CANCEL_REASON_SUPPORT
        cancel_buf_len = invite_len + to_len + reason_len;
+#else
+       cancel_buf_len = invite_len + to_len;
+#endif /* CANCEL_REASON_SUPPORT */
        cancel_buf = shm_malloc(sizeof(char)*cancel_buf_len);
        if (!cancel_buf)
        {
@@ -437,6 +458,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 
                        case HDR_EOH_T:
                                /* end of SIP message found */
+#ifdef CANCEL_REASON_SUPPORT
                                /* add reason if needed */
                                if (reason_len) {
                                        /* if reason_len !=0, no need for any reason enabled
@@ -469,6 +491,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
                                                }
                                        }
                                }
+#endif /* CANCEL_REASON_SUPPORT */
                                /* final (end-of-headers) CRLF */
                                append_str(d, CRLF, CRLF_LEN);
                                *len = d - cancel_buf;
index 95a6db1..56170c0 100644 (file)
@@ -37,6 +37,7 @@
 #include "../../ip_addr.h"
 #include "defs.h"
 #include "dlg.h"
+#include "h_table.h"
 
 
 #define CSEQ "CSeq: "
 
 
 char *build_local(struct cell *Trans, unsigned int branch,
-       unsigned int *len, char *method, int method_len, str *to,
-       struct cancel_reason* reason);
+       unsigned int *len, char *method, int method_len, str *to
+#ifdef CANCEL_REASON_SUPPORT
+       , struct cancel_reason* reason
+#endif /* CANCEL_REASON_SUPPORT */
+       );
 
 char *build_local_reparse(struct cell *Trans, unsigned int branch,
-       unsigned int *len, char *method, int method_len, str *to,
-       struct cancel_reason* reason);
+       unsigned int *len, char *method, int method_len, str *to
+#ifdef CANCEL_REASON_SUPPORT
+       , struct cancel_reason* reason
+#endif /* CANCEL_REASON_SUPPORT */
+       );
 
 char *build_uac_request(  str msg_type, str dst, str from,
        str fromtag, int cseq, str callid, str headers, 
index f37e4e2..a533925 100644 (file)
@@ -392,11 +392,19 @@ static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch,
        if (cfg_get(tm, tm_cfg, reparse_invite)) {
                /* build the ACK from the INVITE which was sent out */
                return build_local_reparse( trans, branch, ret_len,
-                                       ACK, ACK_LEN, &to, 0 );
+                                       ACK, ACK_LEN, &to
+       #ifdef CANCEL_REASON_SUPPORT
+                                       , 0
+       #endif /* CANCEL_REASON_SUPPORT */
+                                       );
        } else {
                /* build the ACK from the reveived INVITE */
                return build_local( trans, branch, ret_len,
-                                       ACK, ACK_LEN, &to, 0 );
+                                       ACK, ACK_LEN, &to
+       #ifdef CANCEL_REASON_SUPPORT
+                                       , 0
+       #endif /* CANCEL_REASON_SUPPORT */
+                                       );
        }
 }
 
@@ -594,7 +602,9 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
                cleanup_uac_timers( trans );
                if (is_invite(trans)){
                        prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0);
+#ifdef CANCEL_REASON_SUPPORT
                        cancel_data.reason.cause=code;
+#endif /* CANCEL_REASON_SUPPORT */
                        cancel_uacs( trans, &cancel_data, F_CANCEL_B_KILL );
                }
                start_final_repl_retr(  trans );
@@ -1140,7 +1150,9 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
                                          if the 6xx handling is not disabled */
                                        prepare_to_cancel(Trans, &cancel_data->cancel_bitmap, 0);
                                        Trans->flags|=T_6xx;
+#ifdef CANCEL_REASON_SUPPORT
                                        cancel_data->reason.cause=new_code;
+#endif /* CANCEL_REASON_SUPPORT */
                                }
                        }
                        return RPS_STORE;
@@ -1295,7 +1307,9 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
                *should_relay= new_code==100? -1 : branch;
                if (new_code>=200 ) {
                        prepare_to_cancel( Trans, &cancel_data->cancel_bitmap, 0);
+#ifdef CANCEL_REASON_SUPPORT
                        cancel_data->reason.cause=new_code;
+#endif /* CANCEL_REASON_SUPPORT */
                        return RPS_COMPLETED;
                } else return RPS_PROVISIONAL;
        }
@@ -2041,6 +2055,7 @@ int reply_received( struct sip_msg  *p_msg )
                                 * if BUSY or set just exit, a cancel will be (or was) sent 
                                 * shortly on this branch */
                                DBG("tm: reply_received: branch CANCEL created\n");
+#ifdef CANCEL_REASON_SUPPORT
                                if (t->uas.cancel_reas) {
                                        /* cancel reason was saved, use it */
                                        cancel_branch(t, branch, t->uas.cancel_reas,
@@ -2055,6 +2070,9 @@ int reply_received( struct sip_msg  *p_msg )
                                        cancel_branch(t, branch, &cancel_data.reason,
                                                                                                                F_CANCEL_B_FORCE_C);
                                }
+#else /* CANCEL_REASON_SUPPORT */
+                               cancel_branch(t, branch, F_CANCEL_B_FORCE_C);
+#endif /* CANCEL_REASON_SUPPORT */
                        }
                        goto done; /* nothing to do */
                }
index 31d6d20..1ff2d4e 100644 (file)
 #ifndef _T_REPLY_H
 #define _T_REPLY_H
 
+/* CANCEL_REASON_SUPPORT on by default */
+#ifndef NO_CANCEL_REASON_SUPPORT
+#define CANCEL_REASON_SUPPORT
+#endif /* NO_CANCEL_REASON_SUPPORT */
+
 #include "defs.h"
 #include "../../rpc.h"
 #include "../../tags.h"
@@ -64,6 +69,7 @@ int unmatched_totag(struct cell *t, struct sip_msg *ack);
 /* branch bitmap type */
 typedef unsigned int branch_bm_t;
 
+#ifdef CANCEL_REASON_SUPPORT
 
 /* reason building blocks (see rfc3326) */
 #define REASON_PREFIX "Reason: SIP;cause="
@@ -106,6 +112,20 @@ struct cancel_info {
                init_cancel_reason(&(ci)->reason); \
        }while (0);
 
+#else /* ! CANCEL_REASON_SUPPORT */
+
+struct cancel_info {
+       branch_bm_t cancel_bitmap; /**< cancel branch bitmap */
+};
+
+#define init_cancel_info(ci) \
+       do {\
+               (ci)->cancel_bitmap=0; \
+       }while (0);
+
+#endif /* CANCEL_REASON_SUPPORT */
+
+
 /* reply export types */
 typedef int (*treply_f)(struct sip_msg * , unsigned int , char * );
 typedef int (*treply_wb_f)( struct cell* trans,
@@ -162,12 +182,12 @@ int t_reply( struct cell *t, struct sip_msg * , unsigned int , char * );
 int t_reply_unsafe( struct cell *t, struct sip_msg * , unsigned int , char * );
 
 
-enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, 
+enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
        unsigned int msg_status, struct cancel_info *cancel_data,
        int do_put_on_wait );
 
 enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch,
-    unsigned int msg_status, struct cancel_info *cancel_data );
+       unsigned int msg_status, struct cancel_info *cancel_data );
 
 void set_final_timer( /* struct s_table *h_table,*/ struct cell *t );
 
index 3d4eb2f..a140298 100644 (file)
@@ -339,7 +339,11 @@ static void fake_reply(struct cell *t, int branch, int code )
                                          &cancel_data, 0 );
        }
        /* now when out-of-lock do the cancel I/O */
+#ifdef CANCEL_REASON_SUPPORT
        if (do_cancel_branch) cancel_branch(t, branch, &cancel_data.reason, 0);
+#else /* CANCEL_REASON_SUPPORT */
+       if (do_cancel_branch) cancel_branch(t, branch, 0);
+#endif /* CANCEL_REASON_SUPPORT */
        /* it's cleaned up on error; if no error occurred and transaction
           completed regularly, I have to clean-up myself
        */