bignag change -- lot of things primarily added in relationship with
[sip-router] / modules / tm / fix_lumps.h
1 /*
2  * $Id$
3  *
4  * here, we delete message lumps which are generated in
5  * core functions using pkg_malloc and applied to shmem
6  * requests; not doing so would result ugly memory problems
7  *
8  * I admit it is not a nice hack; -jiri 
9  */
10
11 #ifndef _FIX_LUMPS_H
12 #define _FIX_LUMPS_H
13
14 /* used to delete attached via lumps from msg; msg can
15    be either an original pkg msg, whose Via lump I want
16    to delete before generating next branch, or a shmem-stored
17    message processed during on_reply -- then I want to
18    delete the Via lump for the same reason
19
20    the other case when I want to delete them is when a message
21    is stored in shmem for branch picking, forwarded lated and
22    Via removal is applied to the shmem-ed message
23 */
24 inline static void free_via_lump( struct lump **list )
25 {
26         struct lump *prev_lump, *lump, *a, *foo;
27
28         prev_lump=0;
29         for(lump=*list;lump;lump=lump->next) {
30                 if (lump->type==HDR_VIA) {
31                         a=lump->before;
32                         while(a) {
33                                 foo=a; a=a->before;
34                                 free_lump(foo);
35                                 pkg_free(foo);
36                         }
37                         a=lump->after;
38                         while(a) {
39                                 foo=a; a=a->after;
40                                 free_lump(foo);
41                                 pkg_free(foo);
42                         }
43                         if (prev_lump) prev_lump->next = lump->next;
44                         else *list = lump->next;
45                         free_lump(lump);pkg_free(lump);
46                 } else {
47                         /* store previous position */
48                         prev_lump=lump;
49                 }
50         }
51 }
52
53 #endif