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