Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00066 #include "defs.h"
00067
00068
00069 #include "sip_msg.h"
00070 #include "../../dprint.h"
00071 #include "../../mem/mem.h"
00072 #include "../../data_lump.h"
00073 #include "../../data_lump_rpl.h"
00074 #include "../../ut.h"
00075 #include "../../sip_msg_clone.h"
00076 #include "../../fix_lumps.h"
00077
00078
00086 struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg, int *sip_msg_len )
00087 {
00088
00089
00090 if (org_msg->first_line.type==SIP_REPLY)
00091
00092 return sip_msg_shm_clone(org_msg, sip_msg_len, 1);
00093
00094 return sip_msg_shm_clone(org_msg, sip_msg_len, 0);
00095 }
00096
00100 unsigned char lumps_are_cloned = 0;
00101
00102
00103
00110 int save_msg_lumps( struct sip_msg *shm_msg, struct sip_msg *pkg_msg)
00111 {
00112 int ret;
00113 struct lump* add_rm;
00114 struct lump* body_lumps;
00115 struct lump_rpl* reply_lump;
00116
00117
00118 if (lumps_are_cloned) {
00119 LOG(L_DBG, "DEBUG: save_msg_lumps: lumps have been already cloned\n" );
00120 return 0;
00121 }
00122
00123 if (unlikely(!shm_msg || ((shm_msg->msg_flags & FL_SHM_CLONE)==0))) {
00124 LOG(L_ERR, "ERROR: save_msg_lumps: BUG, there is no shmem-ized message"
00125 " (shm_msg=%p)\n", shm_msg);
00126 return -1;
00127 }
00128 if (unlikely(shm_msg->first_line.type!=SIP_REQUEST)) {
00129 LOG(L_ERR, "ERROR: save_msg_lumps: BUG, the function should be called only for requests\n" );
00130 return -1;
00131 }
00132
00133 #ifdef EXTRA_DEBUG
00134 membar_depends();
00135 if (shm_msg->add_rm || shm_msg->body_lumps || shm_msg->reply_lump) {
00136 LOG(L_ERR, "ERROR: save_msg_lumps: BUG, trying to overwrite the already cloned lumps\n");
00137 return -1;
00138 }
00139 #endif
00140
00141
00142 if (shm_msg->REQ_METHOD == METHOD_ACK)
00143 return 0;
00144
00145
00146
00147 free_via_clen_lump(&pkg_msg->add_rm);
00148
00149 lumps_are_cloned = 1;
00150 ret=msg_lump_cloner(pkg_msg, &add_rm, &body_lumps, &reply_lump);
00151 if (likely(ret==0)){
00152
00153
00154 membar_write();
00155 shm_msg->add_rm = add_rm;
00156 shm_msg->body_lumps = body_lumps;
00157 shm_msg->reply_lump = reply_lump;
00158 }
00159 return ret<0?-1:0;
00160 }