route_struct.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /*!
  21. * \file
  22. * \brief Kamailio core :: Route structure
  23. * \ingroup core
  24. * Module: \ref core
  25. * \author andrei, bogdan
  26. */
  27. #ifndef route_struct_h
  28. #define route_struct_h
  29. #include <sys/types.h>
  30. #include <regex.h>
  31. #include "select.h"
  32. #include "usr_avp.h"
  33. #define EXPR_DROP -127 /* used only by the expression and if evaluator */
  34. /*
  35. * Other important values (no macros for them yet):
  36. * expr true = 1
  37. * expr false = 0 (used only inside the expression and if evaluator)
  38. *
  39. * action continue or if used in condition true = 1
  40. * action drop/quit/stop script processing = 0
  41. * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
  42. *
  43. */
  44. /* expression type */
  45. enum expr_type { EXP_T=1, ELEM_T };
  46. enum expr_op {
  47. /* expression operator if type==EXP_T */
  48. LOGAND_OP=1, LOGOR_OP, NOT_OP, BINAND_OP, BINOR_OP,
  49. /* expression operator if type==ELEM_T */
  50. EQUAL_OP=10, MATCH_OP, GT_OP, LT_OP, GTE_OP, LTE_OP, DIFF_OP, NO_OP
  51. };
  52. /* expression left member "special" type (if type==ELEM_T)
  53. (start at 51 for debugging purposes: it's better to not overlap with
  54. expr_r_type)
  55. */
  56. enum _expr_l_type{
  57. METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
  58. DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
  59. NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
  60. SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
  61. /* action types */
  62. enum action_type{
  63. FORWARD_T=1, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
  64. SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
  65. SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T,
  66. SET_USERPHONE_T,
  67. IF_T, SWITCH_T /* only until fixup*/,
  68. BLOCK_T, EVAL_T, SWITCH_JT_T, SWITCH_COND_T, MATCH_COND_T, WHILE_T,
  69. /* module function calls with string only parameters */
  70. MODULE0_T, MODULE1_T, MODULE2_T, MODULE3_T, MODULE4_T, MODULE5_T,
  71. MODULE6_T, MODULEX_T,
  72. /* module function calls, that have some RVE parameters */
  73. MODULE1_RVE_T, MODULE2_RVE_T, MODULE3_RVE_T,
  74. MODULE4_RVE_T, MODULE5_RVE_T, MODULE6_RVE_T, MODULEX_RVE_T,
  75. SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
  76. AVPFLAG_OPER_T,
  77. LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
  78. APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
  79. REVERT_URI_T,
  80. FORWARD_TCP_T,
  81. FORWARD_UDP_T,
  82. FORWARD_TLS_T,
  83. FORWARD_SCTP_T,
  84. FORCE_RPORT_T,
  85. ADD_LOCAL_RPORT_T,
  86. SET_ADV_ADDR_T,
  87. SET_ADV_PORT_T,
  88. FORCE_TCP_ALIAS_T,
  89. LOAD_AVP_T,
  90. AVP_TO_URI_T,
  91. FORCE_SEND_SOCKET_T,
  92. ASSIGN_T,
  93. ADD_T,
  94. UDP_MTU_TRY_PROTO_T,
  95. SET_FWD_NO_CONNECT_T,
  96. SET_RPL_NO_CONNECT_T,
  97. SET_FWD_CLOSE_T,
  98. SET_RPL_CLOSE_T,
  99. CFG_SELECT_T,
  100. CFG_RESET_T
  101. };
  102. #define is_mod_func(a) ((a)->type>=MODULE0_T && (a)->type<=MODULEX_RVE_T)
  103. /* parameter types for actions or types for expression right operands
  104. (WARNING right operands only, not working for left operands) */
  105. enum _operand_subtype{
  106. NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
  107. EXPR_ST, ACTIONS_ST, MODEXP_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,
  108. MYSELF_ST, STR_ST, SOCKID_ST, SOCKETINFO_ST, ACTION_ST, AVP_ST,
  109. SELECT_ST, PVAR_ST,
  110. LVAL_ST, RVE_ST,
  111. RETCODE_ST, CASE_ST,
  112. BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
  113. SELECT_UNFIXED_ST,
  114. STRING_RVE_ST /* RVE converted to a string (fparam hack) */,
  115. RVE_FREE_FIXUP_ST /* (str)RVE fixed up by a reversable fixup */,
  116. FPARAM_DYN_ST /* temporary only (fparam hack) */,
  117. CFG_GROUP_ST
  118. };
  119. typedef enum _expr_l_type expr_l_type;
  120. typedef enum _operand_subtype expr_r_type;
  121. typedef enum _operand_subtype action_param_type;
  122. /* run flags */
  123. #define EXIT_R_F 1
  124. #define RETURN_R_F 2
  125. #define BREAK_R_F 4
  126. #define DROP_R_F 8
  127. #define IGNORE_ON_BREAK_R_F 256
  128. struct cfg_pos{
  129. int s_line;
  130. int e_line;
  131. unsigned short s_col;
  132. unsigned short e_col;
  133. char *fname;
  134. char *rname;
  135. };
  136. /* Expression operand */
  137. union exp_op {
  138. void* param;
  139. long numval; /* must have the same size as a void*/
  140. struct expr* expr;
  141. char* string;
  142. avp_spec_t* attr;
  143. select_t* select;
  144. regex_t* re;
  145. struct net* net;
  146. struct _str str;
  147. };
  148. struct expr{
  149. enum expr_type type; /* exp, exp_elem */
  150. enum expr_op op; /* and, or, not | ==, =~ */
  151. expr_l_type l_type;
  152. expr_r_type r_type;
  153. union exp_op l;
  154. union exp_op r;
  155. };
  156. typedef struct {
  157. action_param_type type;
  158. union {
  159. long number;
  160. char* string;
  161. struct _str str;
  162. void* data;
  163. avp_spec_t* attr;
  164. select_t* select;
  165. } u;
  166. } action_u_t;
  167. /* maximum internal array/params
  168. * for module function calls val[0] and val[1] store a pointer to the
  169. * function and the number of params, the rest are the function params
  170. */
  171. #define MAX_ACTIONS (2+6)
  172. struct action{
  173. int cline;
  174. char *cfile;
  175. char *rname;
  176. enum action_type type; /* forward, drop, log, send ...*/
  177. int count;
  178. struct action* next;
  179. action_u_t val[MAX_ACTIONS];
  180. };
  181. typedef struct action cfg_action_t;
  182. struct expr* mk_exp(int op, struct expr* left, struct expr* right);
  183. struct expr* mk_elem(int op, expr_l_type ltype, void* lparam,
  184. expr_r_type rtype, void* rparam);
  185. /* @param type - type of the action
  186. @param count - count of couples {type,val} (variable number of parameters)*/
  187. struct action* mk_action(enum action_type type, int count, ...);
  188. struct action* append_action(struct action* a, struct action* b);
  189. void print_action(struct action* a);
  190. void print_actions(struct action* a);
  191. void print_expr(struct expr* exp);
  192. /** joins to cfg file positions into a new one. */
  193. void cfg_pos_join(struct cfg_pos* res,
  194. struct cfg_pos* pos1, struct cfg_pos* pos2);
  195. struct action *get_action_from_param(void **param, int param_no);
  196. #endif