lump_struct.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. /* History:
  30. * --------
  31. * 2003-01-29 s/int/enum ... more convenient for gdb (jiri)
  32. * 2003-03-31 added subst lumps -- they expand in ip addr, port a.s.o (andrei)
  33. * 2003-04-01 added opt (condition) lumps (andrei)
  34. * 2003-04-02 added more subst lumps: SUBST_{SND,RCV}_ALL
  35. * => ip:port;transport=proto (andrei)
  36. * 2003-10-20 split from data_lump.h (andrei)
  37. * 2005-03-24 the type of type attribute changed to enum _hdr_types_t (janakj)
  38. *
  39. */
  40. #ifndef lump_struct_h
  41. #define lump_struct_h
  42. #include "./parser/hf.h"
  43. enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
  44. enum lump_subst{ SUBST_NOP=0, /* do nothing */
  45. SUBST_RCV_IP, SUBST_SND_IP, /* add ip address */
  46. SUBST_RCV_PORT, SUBST_SND_PORT, /* add port no */
  47. SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
  48. SUBST_RCV_ALL, SUBST_SND_ALL /* ip:port;transport=proto */
  49. };
  50. /* Where:
  51. SND = sending, e.g the src ip of the outgoing message
  52. RCV = received e.g the dst ip of the original incoming msg,
  53. or the ip of the ser socket on which the msg was received
  54. For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
  55. and transport=proto only if proto!=udp
  56. */
  57. enum lump_conditions { COND_FALSE, /* always false */
  58. COND_TRUE, /* always true */
  59. COND_IF_DIFF_REALMS,/* true if RCV realm != SND realm */
  60. COND_IF_DIFF_AF, /* true if RCV af != SND af */
  61. COND_IF_DIFF_PROTO, /* true if RCV proto != SND proto */
  62. COND_IF_DIFF_PORT, /* true if RCV port != SND port */
  63. COND_IF_DIFF_IP, /* true if RCV ip != SND ip */
  64. COND_IF_RAND /* 50-50 random prob.of being true*/
  65. };
  66. /* Where:
  67. REALM= ip_addr:port:proto
  68. af = address family (ipv4 or ipv6)
  69. proto = protocol (tcp, udp, tls)
  70. */
  71. enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2,
  72. LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8 };
  73. #define LUMP_SET_COND_TRUE(_lump) (_lump)->flags |= LUMPFLAG_COND_TRUE
  74. #define LUMP_IS_COND_TRUE(_lump) ((_lump)->flags & LUMPFLAG_COND_TRUE)
  75. struct lump{
  76. enum _hdr_types_t type; /* HDR_VIA_T, HDR_OTHER_T (0), ... */
  77. enum lump_op op; /* DEL, ADD, NOP, UNSPEC(=0) */
  78. union{
  79. int offset; /* used for DEL, MODIFY */
  80. enum lump_subst subst; /*what to subst: ip addr, port, proto*/
  81. enum lump_conditions cond; /* condition for LUMP_ADD_OPT */
  82. char * value; /* used for ADD */
  83. }u;
  84. int len; /* length of this header field */
  85. struct lump* before; /* list of headers to be inserted in front of the
  86. current one */
  87. struct lump* after; /* list of headers to be inserted immediately after
  88. the current one */
  89. struct lump* next;
  90. enum lump_flag flags; /* additional hints for use from TM's shmem */
  91. };
  92. /*
  93. * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
  94. * and/or their position (ADD). E.g.:
  95. * - to delete header Z insert it in to the list according to its offset
  96. * and with op=DELETE
  97. * - if you want to add a new header X after a header Y, insert Y in the list
  98. * with op NOP and after it X (op ADD).
  99. * - if you want X before Y, insert X in Y's before list.
  100. * - if you want X to be the first header just put it first in hdr_lst.
  101. * -if you want to replace Y with X, insert Y with op=DELETE and then X with
  102. * op=ADD.
  103. * before and after must contain only ADD ops!
  104. *
  105. * Difference between "after" & "next" when Adding:
  106. * "after" forces the new header immediately after the current one while
  107. * "next" means another header can be inserted between them.
  108. *
  109. */
  110. /* frees the content of a lump struct */
  111. void free_lump(struct lump* l);
  112. /* frees an entire lump list, recursively */
  113. void free_lump_list(struct lump* lump_list);
  114. /* count applied lumps in a list having a specific type */
  115. unsigned int count_applied_lumps(struct lump *ll, int type);
  116. #endif