PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lump_struct.h

https://gitlab.com/oded/kamailio
C Header | 122 lines | 42 code | 16 blank | 64 comment | 0 complexity | f64fdae138bfbfeb115d19ab5e2aa23f MD5 | raw file
  1. /*
  2. *
  3. * adding/removing headers or any other data chunk from a message
  4. *
  5. * Copyright (C) 2001-2003 FhG Fokus
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*!
  24. * \file
  25. * \brief Kamailio core :: Adding/removing headers or any other data chunk from a message
  26. * \ingroup core
  27. * \author jiri, andrei, janakj
  28. * Module: \ref core
  29. */
  30. #ifndef lump_struct_h
  31. #define lump_struct_h
  32. #include "./parser/hf.h"
  33. enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
  34. enum lump_subst{ SUBST_NOP=0, /* do nothing */
  35. SUBST_RCV_IP, SUBST_SND_IP, /* add ip address */
  36. SUBST_RCV_PORT, SUBST_SND_PORT, /* add port no */
  37. SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
  38. SUBST_RCV_ALL, SUBST_SND_ALL /* ip:port;transport=proto */
  39. };
  40. /* Where:
  41. SND = sending, e.g the src ip of the outgoing message
  42. RCV = received e.g the dst ip of the original incoming msg,
  43. or the ip of the ser socket on which the msg was received
  44. For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
  45. and transport=proto only if proto!=udp
  46. */
  47. enum lump_conditions { COND_FALSE, /* always false */
  48. COND_TRUE, /* always true */
  49. COND_IF_DIFF_REALMS,/* true if RCV realm != SND realm */
  50. COND_IF_DIFF_AF, /* true if RCV af != SND af */
  51. COND_IF_DIFF_PROTO, /* true if RCV proto != SND proto */
  52. COND_IF_DIFF_PORT, /* true if RCV port != SND port */
  53. COND_IF_DIFF_IP, /* true if RCV ip != SND ip */
  54. COND_IF_RAND /* 50-50 random prob.of being true*/
  55. };
  56. /* Where:
  57. REALM= ip_addr:port:proto
  58. af = address family (ipv4 or ipv6)
  59. proto = protocol (tcp, udp, tls)
  60. */
  61. enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2,
  62. LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8 };
  63. #define LUMP_SET_COND_TRUE(_lump) (_lump)->flags |= LUMPFLAG_COND_TRUE
  64. #define LUMP_IS_COND_TRUE(_lump) ((_lump)->flags & LUMPFLAG_COND_TRUE)
  65. typedef struct lump{
  66. enum _hdr_types_t type; /* HDR_VIA_T, HDR_OTHER_T (0), ... */
  67. enum lump_op op; /* DEL, ADD, NOP, UNSPEC(=0) */
  68. union{
  69. int offset; /* used for DEL, MODIFY */
  70. enum lump_subst subst; /*what to subst: ip addr, port, proto*/
  71. enum lump_conditions cond; /* condition for LUMP_ADD_OPT */
  72. char * value; /* used for ADD */
  73. }u;
  74. int len; /* length of this header field */
  75. struct lump* before; /* list of headers to be inserted in front of the
  76. current one */
  77. struct lump* after; /* list of headers to be inserted immediately after
  78. the current one */
  79. struct lump* next;
  80. enum lump_flag flags; /* additional hints for use from TM's shmem */
  81. } sr_lump_t;
  82. /*
  83. * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC)
  84. * and/or their position (ADD). E.g.:
  85. * - to delete header Z insert it in to the list according to its offset
  86. * and with op=DELETE
  87. * - if you want to add a new header X after a header Y, insert Y in the list
  88. * with op NOP and after it X (op ADD).
  89. * - if you want X before Y, insert X in Y's before list.
  90. * - if you want X to be the first header just put it first in hdr_lst.
  91. * -if you want to replace Y with X, insert Y with op=DELETE and then X with
  92. * op=ADD.
  93. * before and after must contain only ADD ops!
  94. *
  95. * Difference between "after" & "next" when Adding:
  96. * "after" forces the new header immediately after the current one while
  97. * "next" means another header can be inserted between them.
  98. *
  99. */
  100. /* frees the content of a lump struct */
  101. void free_lump(struct lump* l);
  102. /* frees an entire lump list, recursively */
  103. void free_lump_list(struct lump* lump_list);
  104. /* count applied lumps in a list having a specific type */
  105. unsigned int count_applied_lumps(struct lump *ll, int type);
  106. #endif