00001 /* 00002 * $Id$ 00003 * 00004 * Copyright (C) 2005-2006 iptelorg GmbH 00005 * 00006 * This file is part of ser, a free SIP server. 00007 * 00008 * ser 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 * For a license to use the ser software under conditions 00014 * other than those described here, or to purchase support for this 00015 * software, please contact iptel.org by e-mail at the following addresses: 00016 * info@iptel.org 00017 * 00018 * ser is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 * 00027 * History: 00028 * -------- 00029 * 2005-12-19 select framework (mma) 00030 * 2006-01-19 multiple nested calls, IS_ALIAS -> NESTED flag renamed (mma) 00031 */ 00032 00033 00034 #ifndef _SELECT_H 00035 #define _SELECT_H 00036 00037 #include "str.h" 00038 #include "parser/msg_parser.h" 00039 00040 #define MAX_SELECT_PARAMS 32 00041 #define MAX_NESTED_CALLS 4 00042 00043 /* Flags for parser table FLAG bitfiels 00044 */ 00045 #define DIVERSION_MASK 0x00FF 00046 00047 /* if DIVERSION is set and the function is accepted 00048 * the param is changed into SEL_PARAM_DIV and the value is set to (flags & DIVERSION_MASK) 00049 * - it is valuable for STR params (saves parsing time) 00050 * - does not release the memory occupied by the parameter 00051 */ 00052 #define DIVERSION 1<<8 00053 00054 /* set if any parameter is expected at this stage 00055 * (the function must be resolved further) 00056 */ 00057 #define SEL_PARAM_EXPECTED 1<<9 00058 00059 /* accept if following parameter is STR (any) 00060 * consume that extra parameter in one step 00061 */ 00062 #define CONSUME_NEXT_STR 1<<10 00063 00064 /* accept if following parameter is INT 00065 * consume that extra parameter in one ste 00066 */ 00067 #define CONSUME_NEXT_INT 1<<11 00068 00069 /* accept all the following parameters 00070 * without checking them 00071 */ 00072 #define CONSUME_ALL 1<<12 00073 00074 /* next parameter is optional (use with CONSUME_NEXT_STR or CONSUME_NEXT_INT 00075 * resolution is accepted even if there is no other parameter 00076 * or the parameter is of wrong type 00077 */ 00078 #define OPTIONAL 1<<13 00079 00080 /* left function is noted to be called 00081 * rigth function continues in resolution 00082 * NOTE: the parameter is not consumed for PARENT, 00083 * so you can leave it as ..,SEL_PARAM_INT, 0,.. 00084 * 00085 * run_select then calls all functions with PARENT flag 00086 * in the order of resolution until the final call or 00087 * the result is != 0 (<0 error, 1 null str) 00088 * the only one parameter passed between nested calls 00089 * is the result str* 00090 */ 00091 #define NESTED 1<<14 00092 00093 /* "fixup call" would be done, when the structure is resolved to this node 00094 * which means call with res and msg NULL 00095 * 00096 * if the fixup call return value <0, the select resolution will fail 00097 */ 00098 #define FIXUP_CALL 1<<15 00099 00100 /* 00101 * Selector call parameter 00102 */ 00103 typedef enum { 00104 SEL_PARAM_INT, /* Integer parameter */ 00105 SEL_PARAM_STR, /* String parameter */ 00106 SEL_PARAM_DIV, /* Integer value got from parsing table */ 00107 SEL_PARAM_PTR /* void* data got from e.g. fixup call */ 00108 } select_param_type_t; 00109 00110 typedef union { 00111 int i; /* Integer value */ 00112 str s; /* String value */ 00113 void* p;/* Any data ptr */ 00114 } select_param_value_t; 00115 00116 typedef struct sel_param { 00117 select_param_type_t type; 00118 select_param_value_t v; 00119 } select_param_t; 00120 00121 struct select; 00122 00123 typedef int (*select_f)(str* res, struct select* s, struct sip_msg* msg); 00124 00125 typedef struct select { 00126 select_f f[MAX_NESTED_CALLS]; 00127 int param_offset[MAX_NESTED_CALLS+1]; 00128 /* contains broken down select string (@foo.bar[-2].foo -> 4 entries) */ 00129 select_param_t params[MAX_SELECT_PARAMS]; 00130 /* how many elements are used in 'params' */ 00131 int n; 00132 } select_t; 00133 00134 typedef struct { 00135 select_f curr_f; 00136 select_param_type_t type; 00137 str name; 00138 select_f new_f; 00139 int flags; 00140 } select_row_t; 00141 00142 typedef struct select_table { 00143 select_row_t *table; 00144 struct select_table *next; 00145 } select_table_t; 00146 00147 /* the level of the select call that is beeing evaluated 00148 * by the child process 00149 */ 00150 extern int select_level; 00151 00152 /* pointer to the SIP uri beeing processed. 00153 * Nested function calls can pass information to each 00154 * other using this pointer. Only for performace reasons. 00155 * (Miklos) 00156 */ 00157 extern struct sip_uri *select_uri_p; 00158 00159 /* 00160 * Lookup corresponding select function based on 00161 * the select parameters 00162 */ 00163 int resolve_select(select_t* s); 00164 00165 /* 00166 * Run the select function 00167 */ 00168 int run_select(str* res, select_t* s, struct sip_msg* msg); 00169 00170 /* 00171 * Print select for debugging purposes 00172 */ 00173 void print_select(select_t* s); 00174 00175 /* 00176 * Register modules' own select parser table 00177 */ 00178 int register_select_table(select_row_t *table); 00179 00180 /* 00181 * Tries to parse string pointed by *p (up to first non alpha char) into select structure 00182 * if parsing succeeded, call resolve_select 00183 * if resolving passes, returns final structure 00184 * *p moves to first unused char 00185 * return 0 00186 * 00187 * if memory allocation fails, returns -1 00188 * if parsing or resolving fails, returns -2 00189 */ 00190 int parse_select (char** p, select_t** s); 00191 00195 void free_select(select_t *s); 00196 /* 00197 * Select parser, result is stored in SHARED memory 00198 * 00199 * If you call this, you must ensure, that the string which 00200 * is beeing parsed MUST be at the same place for all child 00201 * processes, e.g. allocated in the shared memory as well 00202 * 00203 * parameters and results same as parse_select 00204 */ 00205 int shm_parse_select (char** p, select_t** s); 00206 00210 void shm_free_select(select_t *s); 00211 00212 00213 #define SELECT_F(function) extern int function (str* res, select_t* s, struct sip_msg* msg); 00214 #define ABSTRACT_F(function) int function (str* res, select_t* s, struct sip_msg* msg) {return -1;} 00215 00216 #endif /* _SELECT_H */
1.7.1