• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

route_struct.h

00001 /*
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028 /* History:
00029  * --------
00030  *
00031  *  2003-04-12  FORCE_RPORT_T added (andrei)
00032  *  2003-04-22  strip_tail added (jiri)
00033  *  2003-10-10  >,<,>=,<=, != and MSGLEN_O added (andrei)
00034  *  2003-10-28  FORCE_TCP_ALIAS added (andrei)
00035  *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
00036  *  2005-12-11  added SND{IP,PORT,PROTO,AF}_O & TO{IP,PORT}_O (andrei)
00037  *  2005-12-19  select framework added SELECT_O and SELECT_ST (mma)
00038  *  2008-12-17  added UDP_MTU_TRY_PROTO_T (andrei)
00039  */
00040 
00041 
00042 #ifndef route_struct_h
00043 #define route_struct_h
00044 
00045 #include <sys/types.h>
00046 #include <regex.h>
00047 #include "select.h"
00048 #include "usr_avp.h"
00049 
00050 #define EXPR_DROP -127  /* used only by the expression and if evaluator */
00051 /*
00052  * Other important values (no macros for them yet):
00053  * expr true = 1
00054  * expr false = 0 (used only inside the expression and if evaluator)
00055  *
00056  * action continue  or if used in condition true = 1
00057  * action drop/quit/stop script processing = 0
00058  * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
00059  *
00060  */
00061 
00062 
00063 /* expression type */
00064 enum expr_type { EXP_T=1, ELEM_T };
00065 enum expr_op {
00066         /* expression operator if type==EXP_T */
00067         LOGAND_OP=1, LOGOR_OP, NOT_OP, BINAND_OP, BINOR_OP,
00068         /* expression operator if type==ELEM_T */
00069         EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP
00070 };
00071 /* expression left member "special" type (if type==ELEM_T)
00072   (start at 51 for debugging purposes: it's better to not overlap with 
00073    expr_r_type)
00074 */
00075 enum _expr_l_type{
00076            METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
00077            DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
00078            NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
00079            SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
00080 /* action types */
00081 enum action_type{
00082                 FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
00083                 SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
00084                 SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T,
00085                 SET_USERPHONE_T,
00086                 IF_T, SWITCH_T /* only until fixup*/,
00087                 BLOCK_T, EVAL_T, SWITCH_JT_T, SWITCH_COND_T, MATCH_COND_T, WHILE_T,
00088                 /* module function calls with string only parameters */
00089                 MODULE0_T, MODULE1_T, MODULE2_T, MODULE3_T, MODULE4_T, MODULE5_T,
00090                 MODULE6_T, MODULEX_T,
00091                 /* module function calls, that have some RVE parameters */
00092                 MODULE1_RVE_T, MODULE2_RVE_T, MODULE3_RVE_T,
00093                 MODULE4_RVE_T, MODULE5_RVE_T, MODULE6_RVE_T, MODULEX_RVE_T,
00094                 SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
00095                 AVPFLAG_OPER_T,
00096                 LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
00097                 APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
00098                 REVERT_URI_T,
00099                 FORWARD_TCP_T,
00100                 FORWARD_UDP_T,
00101                 FORWARD_TLS_T,
00102                 FORWARD_SCTP_T,
00103                 SEND_TCP_T,
00104                 FORCE_RPORT_T,
00105                 ADD_LOCAL_RPORT_T,
00106                 SET_ADV_ADDR_T,
00107                 SET_ADV_PORT_T,
00108                 FORCE_TCP_ALIAS_T,
00109                 LOAD_AVP_T,
00110                 AVP_TO_URI_T,
00111                 FORCE_SEND_SOCKET_T,
00112                 ASSIGN_T,
00113                 ADD_T,
00114                 UDP_MTU_TRY_PROTO_T,
00115                 SET_FWD_NO_CONNECT_T,
00116                 SET_RPL_NO_CONNECT_T,
00117                 SET_FWD_CLOSE_T,
00118                 SET_RPL_CLOSE_T,
00119                 CFG_SELECT_T,
00120                 CFG_RESET_T
00121 };
00122 
00123 #define is_mod_func(a) ((a)->type>=MODULE0_T && (a)->type<=MODULEX_RVE_T)
00124 
00125 /* parameter types for actions or types for expression right operands
00126    (WARNING right operands only, not working for left operands) */
00127 enum _operand_subtype{
00128                 NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
00129                 EXPR_ST, ACTIONS_ST, MODEXP_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
00130                 MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST, ACTION_ST, AVP_ST,
00131                 SELECT_ST, PVAR_ST,
00132                 LVAL_ST,  RVE_ST,
00133                 RETCODE_ST, CASE_ST,
00134                 BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
00135                 SELECT_UNFIXED_ST,
00136                 STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
00137                 RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
00138                 FPARAM_DYN_ST /* temporary only (fparam hack) */,
00139                 CFG_GROUP_ST
00140 };
00141 
00142 typedef enum _expr_l_type expr_l_type;
00143 typedef enum _operand_subtype expr_r_type;
00144 typedef enum _operand_subtype action_param_type;
00145 
00146 /* run flags */
00147 #define EXIT_R_F   1
00148 #define RETURN_R_F 2
00149 #define BREAK_R_F  4
00150 #define DROP_R_F   8
00151 #define IGNORE_ON_BREAK_R_F 256
00152 
00153 
00154 struct cfg_pos{
00155         int s_line;
00156         int e_line;
00157         unsigned short s_col;
00158         unsigned short e_col;
00159         char *fname;
00160 };
00161 
00162 
00163 /* Expression operand */
00164 union exp_op {
00165         void* param;
00166         long numval; /* must have the same size as a void*/
00167         struct expr* expr;
00168         char* string;
00169         avp_spec_t* attr;
00170         select_t* select;
00171         regex_t* re;
00172         struct net* net;
00173         struct _str str;
00174 };
00175 
00176 struct expr{
00177         enum expr_type type; /* exp, exp_elem */
00178         enum expr_op op; /* and, or, not | ==,  =~ */
00179         expr_l_type l_type;
00180         expr_r_type r_type;
00181         union exp_op l;
00182         union exp_op r;
00183 };
00184 
00185 typedef struct {
00186         action_param_type type;
00187         union {
00188                 long number;
00189                 char* string;
00190                 struct _str str;
00191                 void* data;
00192                 avp_spec_t* attr;
00193                 select_t* select;
00194         } u;
00195 } action_u_t;
00196 
00197 /* maximum internal array/params
00198  * for module function calls val[0] and val[1] store a pointer to the
00199  * function and the number of params, the rest are the function params 
00200  */
00201 #define MAX_ACTIONS (2+6)
00202 
00203 struct action{
00204         int cline;
00205         char *cfile;
00206         enum action_type type;  /* forward, drop, log, send ...*/
00207         int count;
00208         struct action* next;
00209         action_u_t val[MAX_ACTIONS];
00210 };
00211 
00212 typedef struct action cfg_action_t;
00213 
00214 struct expr* mk_exp(int op, struct expr* left, struct expr* right);
00215 struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
00216                                                          expr_r_type rtype, void* rparam);
00217 
00218 /* @param type - type of the action
00219    @param count - count of couples {type,val} (variable number of parameters)*/
00220 struct action* mk_action(enum action_type type, int count, ...);
00221 
00222 struct action* append_action(struct action* a, struct action* b);
00223 
00224 void print_action(struct action* a);
00225 void print_actions(struct action* a);
00226 void print_expr(struct expr* exp);
00227 
00229 void cfg_pos_join(struct cfg_pos* res,
00230                                                         struct cfg_pos* pos1, struct cfg_pos* pos2);
00231 
00232 struct action *get_action_from_param(void **param, int param_no);
00233 #endif
00234 

Generated on Tue May 22 2012 13:10:14 for SIP Router by  doxygen 1.7.1