4 * Copyright (C) 2001-2003 FhG Fokus
6 * This file is part of ser, a free SIP server.
8 * ser is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
13 * For a license to use the ser software under conditions
14 * other than those described here, or to purchase support for this
15 * software, please contact iptel.org by e-mail at the following addresses:
18 * ser is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "../../parser/msg_parser.h"
37 #include "../../mem/shm_mem.h"
39 /* Allow postponing the cloning of SIP msg:
40 * t_newtran() copies the requests to shm mem without the lumps,
41 * and t_forward_nonack() clones the lumps later when it is called
43 * Replies use only one memory block.
45 #define POSTPONE_MSG_CLONING
47 #ifdef POSTPONE_MSG_CLONING
48 #include "../../atomic_ops.h" /* membar_depends() */
51 #ifdef POSTPONE_MSG_CLONING
52 /* msg is a reply: one memory block was allocated
53 * msg is a request: two memory blocks were allocated:
54 * - one for the sip_msg struct
55 * - another one for the lumps which is linked to
56 * add_rm, body_lumps, or reply_lump.
58 #define _sip_msg_free(_free_func, _p_msg) \
60 if (_p_msg->first_line.type==SIP_REPLY) { \
61 _free_func( (_p_msg) ); \
64 if ((_p_msg)->add_rm) \
65 _free_func((_p_msg)->add_rm); \
66 else if ((_p_msg)->body_lumps) \
67 _free_func((_p_msg)->body_lumps); \
68 else if ((_p_msg)->reply_lump) \
69 _free_func((_p_msg)->reply_lump); \
71 _free_func( (_p_msg) ); \
75 #else /* POSTPONE_MSG_CLONING */
77 /* only one memory block was allocated */
78 #define _sip_msg_free(_free_func, _p_msg) \
79 _free_func( (_p_msg) )
81 #endif /* POSTPONE_MSG_CLONING */
83 #define sip_msg_free(_p_msg) _sip_msg_free(shm_free, _p_msg)
84 #define sip_msg_free_unsafe(_p_msg) _sip_msg_free(shm_free_unsafe, _p_msg)
87 struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg, int *sip_msg_len );
89 #ifdef POSTPONE_MSG_CLONING
90 extern unsigned char lumps_are_cloned;
92 int save_msg_lumps( struct sip_msg *shm_msg, struct sip_msg *pkg_msg);