data_lump.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * $Id$
  3. *
  4. * adding/removing headers or any other data chunk from a message
  5. *
  6. * Copyright (C) 2001-2003 Fhg Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. #ifndef data_lump_h
  30. #define data_lump_h
  31. enum { LUMP_NOP=0, LUMP_DEL, LUMP_ADD };
  32. enum { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2 };
  33. struct lump{
  34. int type; /* VIA, OTHER, UNSPEC(=0), ... */
  35. int op; /* DEL, ADD, NOP, UNSPEC(=0) */
  36. union{
  37. int offset; /* used for DEL, MODIFY */
  38. char * value; /* used for ADD */
  39. }u;
  40. int len; /* length of this header field */
  41. struct lump* before; /* list of headers to be inserted in front of the
  42. current one */
  43. struct lump* after; /* list of headers to be inserted immediately after
  44. the current one */
  45. struct lump* next;
  46. int flags; /* additional hints for use from TM's shmem */
  47. };
  48. /*
  49. * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
  50. * and/or their position (ADD). E.g.:
  51. * - to delete header Z insert it in to the list according to its offset
  52. * and with op=DELETE
  53. * - if you want to add a new header X after a header Y, insert Y in the list
  54. * with op NOP and after it X (op ADD).
  55. * - if you want X before Y, insert X in Y's before list.
  56. * - if you want X to be the first header just put it first in hdr_lst.
  57. * -if you want to replace Y with X, insert Y with op=DELETE and then X with
  58. * op=ADD.
  59. * before and after must contain only ADD ops!
  60. *
  61. * Difference between "after" & "next" when ADDing:
  62. * "after" forces the new header immediately after the current one while
  63. * "next" means another header can be inserted between them.
  64. *
  65. */
  66. /* adds a header to the end */
  67. struct lump* append_new_lump(struct lump** list, char* new_hdr,
  68. int len, int type);
  69. /* inserts a header to the beginning */
  70. struct lump* insert_new_lump(struct lump** list, char* new_hdr,
  71. int len, int type);
  72. struct lump* insert_new_lump_after(struct lump* after,
  73. char* new_hdr, int len, int type);
  74. struct lump* insert_new_lump_before(struct lump* before, char* new_hdr,
  75. int len,int type);
  76. /* removes an already existing header */
  77. struct lump* del_lump(struct lump** list, int offset, int len, int type);
  78. /* set an anchor */
  79. struct lump* anchor_lump(struct lump** list, int offset, int len, int type);
  80. /* frees the content of a lump struct */
  81. void free_lump(struct lump* l);
  82. /*frees an entire lump list, recursively */
  83. void free_lump_list(struct lump* lump_list);
  84. /* duplicates a lump list shallowly in pkg-mem */
  85. struct lump* dup_lump_list( struct lump *l );
  86. /* frees a shallowly duplicated lump list */
  87. void free_duped_lump_list(struct lump* l);
  88. #endif