modules_k/permissions/rule.h

00001 /*
00002  * $Id$
00003  *
00004  * PERMISSIONS module
00005  *
00006  * Copyright (C) 2003 Miklós Tirpák (mtirpak@sztaki.hu)
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025  
00026 #ifndef RULE_H
00027 #define RULE_H 1
00028 
00029 #include <regex.h>
00030 
00031 #define EXPRESSION_LENGTH 256   /* maximum length of an expression */
00032 #define LINE_LENGTH 500         /* maximum length of lines in the config file */
00033 
00034 
00035 struct rule_struct;
00036 typedef struct rule_struct rule;
00037 
00038 struct expression_struct;
00039 typedef struct expression_struct expression;
00040         
00041 rule *new_rule(void);
00042 void free_rule(rule *r);
00043 void print_rule(rule *r);
00044 int search_rule(rule *r, char *left, char *right);
00045 
00046 expression *new_expression(char *str);
00047 void free_expression(expression *e);
00048 void print_expression(expression *e);
00049 int search_expression(expression *e, char *value);
00050 
00051 /*
00052  * stores an expression
00053  * value represents the string, and reg_value is the compiled string to POSIX regular expression
00054 */
00055 struct expression_struct  {
00056         char    value[EXPRESSION_LENGTH+1];
00057         regex_t *reg_value;
00058         struct expression_struct        *next;
00059 };
00060 
00061 
00062 /*
00063  * stores 4 lists of expressions in the following way:
00064  *
00065  * a, b, c EXCEPT d, e : f, g EXCEPT h
00066  * left = a, b, c
00067  * left_exceptions = d, e
00068  * right = f, g
00069  * right_exceptions = h
00070  */
00071 struct rule_struct {
00072         expression *left, *left_exceptions, *right, *right_exceptions;
00073         struct rule_struct      *next;
00074 };
00075 
00076 
00077 #endif /* RULE_H */