1 /*
2  * Copyright (C)  2007-2008 Voice Sistem SRL
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 
22 /*!
23  * \file
24  * \brief Kamailio dialplan :: Module interface
25  * \ingroup dialplan
26  * Module: \ref dialplan
27  */
28 
29 
30 #ifndef _DP_DIALPLAN_H
31 #define _DP_DIALPLAN_H
32 
33 #include <pcre.h>
34 #include "../../core/pvar.h"
35 #include "../../core/parser/msg_parser.h"
36 
37 #define DP_EQUAL_OP		0
38 #define DP_REGEX_OP		1
39 #define DP_FNMATCH_OP	2
40 
41 #define MAX_REPLACE_WITH	10
42 
43 #define DP_TFLAGS_PV_MATCH		(1 << 0)
44 #define DP_TFLAGS_PV_SUBST		(1 << 1)
45 
46 typedef struct dpl_node {
47 	int dpid;         /* dialplan id */
48 	int pr;           /* priority */
49 	int matchop;      /* matching operator */
50 	int matchlen;     /* matching value length */
51 	str match_exp;    /* match-first string */
52 	str subst_exp;    /* match string with subtitution groupping */
53 	str repl_exp;     /* replacement expression string */
54 	pcre *match_comp; /* compiled matching expression */
55 	pcre *subst_comp; /* compiled substitution expression */
56 	struct subst_expr *repl_comp; /* compiled replacement */
57 	str attrs;        /* attributes string */
58 	unsigned int tflags; /* flags for type of values for matching */
59 
60 	struct dpl_node * next; /* next rule */
61 } dpl_node_t, *dpl_node_p;
62 
63 /*For every distinct length of a matching string*/
64 typedef struct dpl_index{
65 	int len;
66 	dpl_node_t * first_rule;
67 	dpl_node_t * last_rule;
68 
69 	struct dpl_index * next;
70 }dpl_index_t, *dpl_index_p;
71 
72 /*For every DPID*/
73 typedef struct dpl_id{
74 	int dp_id;
75 	dpl_index_t* first_index;/*fast access :rules with specific length*/
76 	struct dpl_id * next;
77 }dpl_id_t,*dpl_id_p;
78 
79 
80 #define DP_VAL_INT		0
81 #define DP_VAL_SPEC		1
82 
83 typedef struct dp_param{
84 	int type;
85 	union {
86 		int id;
87 		pv_spec_t* sp[2];
88 	} v;
89 }dp_param_t, *dp_param_p;
90 
91 int init_data();
92 void destroy_data();
93 int dp_load_db();
94 
95 dpl_id_p select_dpid(int id);
96 
97 struct subst_expr* repl_exp_parse(str subst);
98 void repl_expr_free(struct subst_expr *se);
99 int dp_translate_helper(sip_msg_t *msg, str *user_name, str *repl_user,
100 		dpl_id_p idp, str *);
101 int rule_translate(sip_msg_t *msg, str *instr, dpl_node_t *rule,
102 		pcre *subst_comp, str *);
103 
104 pcre *reg_ex_comp(const char *pattern, int *cap_cnt, int mtype);
105 #endif
106