00001 /* 00002 * $Id: lump_struct.h 4518 2008-07-28 15:39:28Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 /*! 00024 * \file lump_struct.h 00025 * \brief Data structures for adding or removing data chunks from messages. 00026 */ 00027 00028 00029 #ifndef lump_struct_h 00030 #define lump_struct_h 00031 00032 #include "./parser/hf.h" 00033 00034 /*! \brief 00035 * Operations on lumps. 00036 */ 00037 enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT }; 00038 00039 /*! \brief 00040 * Substitutions for lumps. 00041 * Where: 00042 * SND = sending, e.g the src ip of the outgoing message 00043 * RCV = received e.g the dst ip of the original incoming msg, 00044 * or the ip of the socket on which the msg was received. 00045 * For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060 00046 * and transport=proto only if proto!=udp is specified. 00047 */ 00048 enum lump_subst{ SUBST_NOP=0, /*!< do nothing */ 00049 SUBST_RCV_IP, SUBST_SND_IP, /*!< add ip address */ 00050 SUBST_RCV_PORT, SUBST_SND_PORT, /*!< add port no */ 00051 SUBST_RCV_PROTO, SUBST_SND_PROTO,/*!< add protocol(udp,tcp,tls)*/ 00052 SUBST_RCV_ALL, SUBST_SND_ALL /*!< ip:port;transport=proto */ 00053 }; 00054 00055 /*! \brief 00056 * Conditions for lumps. 00057 * Where: 00058 * REALM= ip_addr:port:proto 00059 * af = address family (ipv4 or ipv6) 00060 * proto = protocol (tcp, udp, tls) 00061 */ 00062 enum lump_conditions { COND_FALSE, /*!< always false */ 00063 COND_TRUE, /*!< always true */ 00064 COND_IF_DIFF_REALMS,/*!< true if RCV realm != SND realm */ 00065 COND_IF_DIFF_AF, /*!< true if RCV af != SND af */ 00066 COND_IF_DIFF_PROTO, /*!< true if RCV proto != SND proto */ 00067 COND_IF_DIFF_PORT, /*!< true if RCV port != SND port */ 00068 COND_IF_DIFF_IP, /*!< true if RCV ip != SND ip */ 00069 }; 00070 00071 /*! \brief 00072 * Flags for lumps, mainly used from the tm module. 00073 */ 00074 enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, 00075 LUMPFLAG_SHMEM=2 , LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8}; 00076 00077 00078 /*! \brief 00079 * Main lump structure. 00080 */ 00081 struct lump{ 00082 enum _hdr_types_t type; /*!< HDR_VIA_T, HDR_OTHER_T (0), ... */ 00083 enum lump_op op; /*!< DEL, ADD, NOP, UNSPEC(=0) */ 00084 00085 union{ 00086 unsigned int offset; /*!< used for DEL, MODIFY */ 00087 enum lump_subst subst; /*!< what to subst: ip addr, port, proto*/ 00088 enum lump_conditions cond; /*!< condition for LUMP_ADD_OPT */ 00089 char * value; /*!< used for ADD */ 00090 }u; 00091 unsigned int len; /*!< length of this header field */ 00092 00093 00094 struct lump* before; /*!< list of headers to be inserted in front of the 00095 current one */ 00096 struct lump* after; /*!< list of headers to be inserted immediately after 00097 the current one */ 00098 struct lump* next; 00099 00100 enum lump_flag flags; /*!< additional hints for use from TM's shmem */ 00101 }; 00102 00103 00104 /* 00105 * hdrs must be kept sorted after their offset (DEL, NOP, UNSPEC) 00106 * and/or their position (ADD). E.g.: 00107 * - to delete header Z insert it in to the list according to its offset 00108 * and with op=DELETE 00109 * - if you want to add a new header X after a header Y, insert Y in the list 00110 * with op NOP and after it X (op ADD). 00111 * - if you want X before Y, insert X in Y's before list. 00112 * - if you want X to be the first header just put it first in hdr_lst. 00113 * -if you want to replace Y with X, insert Y with op=DELETE and then X with 00114 * op=ADD. 00115 * before and after must contain only ADD ops! 00116 * 00117 * Difference between "after" & "next" when Adding: 00118 * "after" forces the new header immediately after the current one while 00119 * "next" means another header can be inserted between them. 00120 * 00121 */ 00122 00123 /*! \brief frees the content of a lump struct */ 00124 void free_lump(struct lump* l); 00125 /*! \brief frees an entire lump list, recursively */ 00126 void free_lump_list(struct lump* lump_list); 00127 00128 #endif
1.5.6