fix_lumps.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Copyright (C) 2001-2003 FhG Fokus
  11. *
  12. * This file is part of ser, a free SIP server.
  13. *
  14. * ser is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. /*
  29. * History:
  30. * -------
  31. * 2003-11-24 changed free_via_lump to free_via_clen_lump and make it
  32. * handle CONTENTLENGTH lumps also (andrei)
  33. * 2005-07-04 lumps in SHM or dup'ed lumps are not freed and an warning
  34. * message is logged (temporary fix) (andrei)
  35. */
  36. #ifndef _FIX_LUMPS_H
  37. #define _FIX_LUMPS_H
  38. /** @brief used to delete attached via lumps from msg;
  39. msg can be either an original pkg msg, whose Via lump I want
  40. to delete before generating next branch, or a shmem-stored
  41. message processed during on_reply -- then I want to
  42. delete the Via lump for the same reason
  43. the other case when I want to delete them is when a message
  44. is stored in shmem for branch picking, forwarded lated and
  45. Via removal is applied to the shmem-ed message
  46. the same thing for Content-Length lumps (FIXME: this
  47. should be done in a nicer way)
  48. */
  49. inline static void free_via_clen_lump( struct lump **list )
  50. {
  51. struct lump *prev_lump, *lump, *a, *foo, *next;
  52. next=0;
  53. prev_lump=0;
  54. for(lump=*list;lump;lump=next) {
  55. next=lump->next;
  56. if (lump->type==HDR_VIA_T||lump->type==HDR_CONTENTLENGTH_T) {
  57. if (lump->flags & (LUMPFLAG_DUPED|LUMPFLAG_SHMEM)){
  58. LM_CRIT("free_via_clen_lmp: lump %p, flags %x\n",
  59. lump, lump->flags);
  60. /* ty to continue */
  61. }
  62. a=lump->before;
  63. while(a) {
  64. foo=a; a=a->before;
  65. if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
  66. free_lump(foo);
  67. if (!(foo->flags&LUMPFLAG_SHMEM))
  68. pkg_free(foo);
  69. }
  70. a=lump->after;
  71. while(a) {
  72. foo=a; a=a->after;
  73. if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
  74. free_lump(foo);
  75. if (!(foo->flags&LUMPFLAG_SHMEM))
  76. pkg_free(foo);
  77. }
  78. if (prev_lump) prev_lump->next = lump->next;
  79. else *list = lump->next;
  80. if (!(lump->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
  81. free_lump(lump);
  82. if (!(lump->flags&LUMPFLAG_SHMEM))
  83. pkg_free(lump);
  84. } else {
  85. /* store previous position */
  86. prev_lump=lump;
  87. }
  88. }
  89. }
  90. #endif