route_struct.h
c07508e2
 /*
  * $Id$
  *
7dd0b342
  *
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
f141bc93
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
7dd0b342
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c07508e2
  */
3e8c3475
 /* History:
  * --------
  *
  *  2003-04-12  FORCE_RPORT_T added (andrei)
1d9f91d6
  *  2003-04-22  strip_tail added (jiri)
dda578ba
  *  2003-10-10  >,<,>=,<=, != and MSGLEN_O added (andrei)
59653eb8
  *  2003-10-28  FORCE_TCP_ALIAS added (andrei)
1bee75ad
  *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
0d88ce78
  *  2005-12-11  added SND{IP,PORT,PROTO,AF}_O & TO{IP,PORT}_O (andrei)
a0fb4e8b
  *  2005-12-19  select framework added SELECT_O and SELECT_ST (mma)
f62c96d8
  *  2008-12-17  added UDP_MTU_TRY_PROTO_T (andrei)
3e8c3475
  */
c07508e2
 
7dd0b342
 
c07508e2
 #ifndef route_struct_h
 #define route_struct_h
 
4a745629
 #include <sys/types.h>
74ce7043
 #include <regex.h>
3fb428ed
 #include "select.h"
74ce7043
 #include "usr_avp.h"
 
a1041efe
 #define EXPR_DROP -127  /* used only by the expression and if evaluator */
 /*
  * Other important values (no macros for them yet):
  * expr true = 1
  * expr false = 0 (used only inside the expression and if evaluator)
f141bc93
  *
a1041efe
  * action continue  or if used in condition true = 1
  * action drop/quit/stop script processing = 0
  * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
f141bc93
  *
a1041efe
  */
 
 
aa9fa735
 /* expression type */
 enum expr_type { EXP_T=1, ELEM_T };
 enum expr_op {
 	/* expression operator if type==EXP_T */
 	LOGAND_OP=1, LOGOR_OP, NOT_OP, BINAND_OP, BINOR_OP,
 	/* expression operator if type==ELEM_T */
 	EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP
 };
 /* expression left member "special" type (if type==ELEM_T)
   (start at 51 for debugging purposes: it's better to not overlap with 
    expr_r_type)
 */
 enum _expr_l_type{
 	   METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
 	   DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
f141bc93
 	   NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
2f34ba7d
 	   SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
aa9fa735
 /* action types */
 enum action_type{
 		FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
f141bc93
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
cec6ad97
 		SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T,
d240dd18
 		SET_USERPHONE_T,
a29a8b6d
 		IF_T, SWITCH_T /* only until fixup*/,
cfeefb4a
 		BLOCK_T, EVAL_T, SWITCH_JT_T, SWITCH_COND_T, MATCH_COND_T, WHILE_T,
cad98b04
 		/* module function calls with string only parameters */
 		MODULE0_T, MODULE1_T, MODULE2_T, MODULE3_T, MODULE4_T, MODULE5_T,
 		MODULE6_T, MODULEX_T,
 		/* module function calls, that have some RVE parameters */
 		MODULE1_RVE_T, MODULE2_RVE_T, MODULE3_RVE_T,
 		MODULE4_RVE_T, MODULE5_RVE_T, MODULE6_RVE_T, MODULEX_RVE_T,
1f377e97
 		SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
85d4627f
 		AVPFLAG_OPER_T,
1d9f91d6
 		LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
9fa304f1
 		APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
0c5da34b
 		REVERT_URI_T,
 		FORWARD_TCP_T,
f2f969dd
 		FORWARD_UDP_T,
e9b02e8e
 		FORWARD_TLS_T,
ed990c31
 		FORWARD_SCTP_T,
3e8c3475
 		SEND_TCP_T,
6bfaa042
 		FORCE_RPORT_T,
c37c22b4
 		ADD_LOCAL_RPORT_T,
6bfaa042
 		SET_ADV_ADDR_T,
59653eb8
 		SET_ADV_PORT_T,
1580c821
 		FORCE_TCP_ALIAS_T,
1bee75ad
 		LOAD_AVP_T,
6cd48835
 		AVP_TO_URI_T,
ed990c31
 		FORCE_SEND_SOCKET_T,
 		ASSIGN_T,
f62c96d8
 		ADD_T,
58cbf7f7
 		UDP_MTU_TRY_PROTO_T,
 		SET_FWD_NO_CONNECT_T,
 		SET_RPL_NO_CONNECT_T,
 		SET_FWD_CLOSE_T,
415f24a4
 		SET_RPL_CLOSE_T,
 		CFG_SELECT_T,
 		CFG_RESET_T
3e8c3475
 };
aa9fa735
 /* parameter types for actions or types for expression right operands
    (WARNING right operands only, not working for left operands) */
 enum _operand_subtype{
 		NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
f141bc93
 		EXPR_ST, ACTIONS_ST, MODEXP_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
ab7f82d2
 		MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST, ACTION_ST, AVP_ST,
7fa369e3
 		SELECT_ST, PVAR_ST,
 		LVAL_ST,  RVE_ST,
a29a8b6d
 		RETCODE_ST, CASE_ST,
2f34ba7d
 		BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
99cff510
 		SELECT_UNFIXED_ST,
35657139
 		STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
d002aae9
 		RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
415f24a4
 		FPARAM_DYN_ST /* temporary only (fparam hack) */,
 		CFG_GROUP_ST
a29a8b6d
 };
01dea124
 
aa9fa735
 typedef enum _expr_l_type expr_l_type;
 typedef enum _operand_subtype expr_r_type;
 typedef enum _operand_subtype action_param_type;
 
01dea124
 /* run flags */
 #define EXIT_R_F   1
 #define RETURN_R_F 2
955535a4
 #define BREAK_R_F  4
8ebb586d
 #define DROP_R_F   8
28a88287
 #define IGNORE_ON_BREAK_R_F 256
74ce7043
 
9a31872c
 
 struct cfg_pos{
 	int s_line;
 	int e_line;
 	unsigned short s_col;
 	unsigned short e_col;
d2056519
 	char *fname;
9a31872c
 };
 
 
74ce7043
 /* Expression operand */
 union exp_op {
e9220390
 	void* param;
 	long numval; /* must have the same size as a void*/
74ce7043
 	struct expr* expr;
 	char* string;
 	avp_spec_t* attr;
3fb428ed
 	select_t* select;
74ce7043
 	regex_t* re;
 	struct net* net;
e9220390
 	struct _str str;
74ce7043
 };
f141bc93
 
c07508e2
 struct expr{
aa9fa735
 	enum expr_type type; /* exp, exp_elem */
 	enum expr_op op; /* and, or, not | ==,  =~ */
 	expr_l_type l_type;
 	expr_r_type r_type;
74ce7043
 	union exp_op l;
 	union exp_op r;
c07508e2
 };
 
f141bc93
 typedef struct {
aa9fa735
 	action_param_type type;
f141bc93
 	union {
 		long number;
 		char* string;
5b1455d0
 		struct _str str;
f141bc93
 		void* data;
 		avp_spec_t* attr;
 		select_t* select;
 	} u;
24c93522
 } action_u_t;
c07508e2
 
a2da0c58
 /* maximum internal array/params
  * for module function calls val[0] and val[1] store a pointer to the
  * function and the number of params, the rest are the function params 
  */
 #define MAX_ACTIONS (2+6)
f141bc93
 
c07508e2
 struct action{
eac773a6
 	int cline;
 	char *cfile;
aa9fa735
 	enum action_type type;  /* forward, drop, log, send ...*/
f141bc93
 	int count;
c07508e2
 	struct action* next;
a2da0c58
 	action_u_t val[MAX_ACTIONS];
c07508e2
 };
 
c68ba021
 typedef struct action cfg_action_t;
 
c07508e2
 struct expr* mk_exp(int op, struct expr* left, struct expr* right);
aa9fa735
 struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
 							 expr_r_type rtype, void* rparam);
 
 /* @param type - type of the action
    @param count - count of couples {type,val} (variable number of parameters)*/
 struct action* mk_action(enum action_type type, int count, ...);
74ce7043
 
09e52ebb
 struct action* append_action(struct action* a, struct action* b);
 
c07508e2
 void print_action(struct action* a);
74ce7043
 void print_actions(struct action* a);
c07508e2
 void print_expr(struct expr* exp);
 
33d56025
 /** joins to cfg file positions into a new one. */
 void cfg_pos_join(struct cfg_pos* res,
 							struct cfg_pos* pos1, struct cfg_pos* pos2);
486ace87
 
 struct action *get_action_from_param(void **param, int param_no);
c07508e2
 #endif