00001 /* 00002 * $Id: fix_lumps.h 4738 2008-08-25 17:08:36Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * History: 00023 * ------- 00024 * 2003-11-24 changed free_via_lump to free_via_clen_lump and make it 00025 * handle CONTENTLENGTH lumps also (andrei) 00026 * 2005-07-04 lumps in SHM or dup'ed lumps are not freed and an warning 00027 * message is logged (temporary fix) (andrei) 00028 */ 00029 00030 /*!\file 00031 * \brief TM :: Lump handling 00032 * 00033 * Delete message lumps which are generated in core functions 00034 * using pkg_malloc and applied to shmem requests; 00035 * not doing so would result ugly memory problems. 00036 * \ingroup tm 00037 * - Module: \ref tm 00038 */ 00039 00040 00041 #ifndef _FIX_LUMPS_H 00042 #define _FIX_LUMPS_H 00043 00044 /*! 00045 * \brief Used to delete attached via lumps from msg 00046 * 00047 * A msg can be either an original pkg msg, whose Via lump I want 00048 * to delete before generating next branch, or a shmem-stored 00049 * message processed during on_reply -- then I want to 00050 * delete the Via lump for the same reason. 00051 * The other case when I want to delete them is when a message 00052 * is stored in shmem for branch picking, forwarded lated and 00053 * Via removal is applied to the shmem-ed message. 00054 * The same thing apply for Content-Length lumps. 00055 * \param list list of lumps 00056 \todo (FIXME: this should be done in a nicer way) 00057 */ 00058 inline static void free_via_clen_lump( struct lump **list ) 00059 { 00060 struct lump *prev_lump, *lump, *a, *foo, *next; 00061 00062 next=0; 00063 prev_lump=0; 00064 for(lump=*list;lump;lump=next) { 00065 next=lump->next; 00066 if (lump->type==HDR_VIA_T||lump->type==HDR_CONTENTLENGTH_T) { 00067 if (lump->flags & (LUMPFLAG_DUPED|LUMPFLAG_SHMEM)){ 00068 LM_CRIT("free_via_clen_lmp: lump %p, flags %x\n", 00069 lump, lump->flags); 00070 /* ty to continue */ 00071 } 00072 a=lump->before; 00073 while(a) { 00074 foo=a; a=a->before; 00075 if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM))) 00076 free_lump(foo); 00077 if (!(foo->flags&LUMPFLAG_SHMEM)) 00078 pkg_free(foo); 00079 } 00080 a=lump->after; 00081 while(a) { 00082 foo=a; a=a->after; 00083 if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM))) 00084 free_lump(foo); 00085 if (!(foo->flags&LUMPFLAG_SHMEM)) 00086 pkg_free(foo); 00087 } 00088 if (prev_lump) prev_lump->next = lump->next; 00089 else *list = lump->next; 00090 if (!(lump->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM))) 00091 free_lump(lump); 00092 if (!(lump->flags&LUMPFLAG_SHMEM)) 00093 pkg_free(lump); 00094 } else { 00095 /* store previous position */ 00096 prev_lump=lump; 00097 } 00098 } 00099 } 00100 00101 #endif
1.5.6