modules_s/rr/fix_lumps.h

00001 /*
00002  * $Id$
00003  *
00004  * here, we delete message lumps which are generated in
00005  * core functions using pkg_malloc and applied to shmem
00006  * requests; not doing so would result ugly memory problems
00007  *
00008  * I admit it is not a nice hack; -jiri 
00009  *
00010  * Copyright (C) 2001-2003 FhG Fokus
00011  *
00012  * This file is part of ser, a free SIP server.
00013  *
00014  * ser is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU General Public License as published by
00016  * the Free Software Foundation; either version 2 of the License, or
00017  * (at your option) any later version
00018  *
00019  * For a license to use the ser software under conditions
00020  * other than those described here, or to purchase support for this
00021  * software, please contact iptel.org by e-mail at the following addresses:
00022  *    info@iptel.org
00023  *
00024  * ser is distributed in the hope that it will be useful,
00025  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027  * GNU General Public License for more details.
00028  *
00029  * You should have received a copy of the GNU General Public License 
00030  * along with this program; if not, write to the Free Software 
00031  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00032  */
00033 
00034 /*
00035  * History:
00036  * ........
00037  *  2006-04-19: copy-pasted form TM module (Miklos)
00038  */
00039 
00040 #ifndef _FIX_LUMPS_H
00041 #define _FIX_LUMPS_H
00042 
00043 
00044 inline static void free_rr_lump( struct lump **list )
00045 {
00046         struct lump *prev_lump, *lump, *a, *foo, *next;
00047         int first_shmem;
00048 
00049         first_shmem=1;
00050         next=0;
00051         prev_lump=0;
00052         for(lump=*list;lump;lump=next) {
00053                 next=lump->next;
00054                 if (lump->type==HDR_RECORDROUTE_T) {
00055                         /* may be called from railure_route */
00056                         /* if (lump->flags & (LUMPFLAG_DUPED|LUMPFLAG_SHMEM)){
00057                                 LOG(L_CRIT, "BUG: free_rr_lmp: lump %p, flags %x\n",
00058                                                 lump, lump->flags);
00059                         */      /* ty to continue */
00060                         /*}*/
00061                         a=lump->before;
00062                         while(a) {
00063                                 foo=a; a=a->before;
00064                                 if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
00065                                         free_lump(foo);
00066                                 if (!(foo->flags&LUMPFLAG_SHMEM))
00067                                         pkg_free(foo);
00068                         }
00069                         a=lump->after;
00070                         while(a) {
00071                                 foo=a; a=a->after;
00072                                 if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
00073                                         free_lump(foo);
00074                                 if (!(foo->flags&LUMPFLAG_SHMEM))
00075                                         pkg_free(foo);
00076                         }
00077                         
00078                         if (first_shmem && (lump->flags&LUMPFLAG_SHMEM)) {
00079                                 /* This is the first element of the
00080                                 shmemzied lump list, we can not unlink it!
00081                                 It wound corrupt the list otherwise if we
00082                                 are in failure_route. -- No problem, only the
00083                                 anchor is left in the list */
00084                                 
00085                                 LOG(L_DBG, "DEBUG: free_rr_lump: lump %p" \
00086                                                 " is left in the list\n",
00087                                                 lump);
00088                                 
00089                                 if (lump->len)
00090                                     LOG(L_CRIT, "BUG: free_rr_lump: lump %p" \
00091                                                 " can not be removed, but len=%d\n",
00092                                                 lump, lump->len);
00093                                                 
00094                                 prev_lump=lump;
00095                         } else {
00096                                 if (prev_lump) prev_lump->next = lump->next;
00097                                 else *list = lump->next;
00098                                 if (!(lump->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
00099                                         free_lump(lump);
00100                                 if (!(lump->flags&LUMPFLAG_SHMEM))
00101                                         pkg_free(lump);
00102                         }
00103                 } else {
00104                         /* store previous position */
00105                         prev_lump=lump;
00106                 }
00107                 if (first_shmem && (lump->flags&LUMPFLAG_SHMEM))
00108                         first_shmem=0;
00109         }
00110 }
00111 
00112 #endif