permissions/hash.h

Go to the documentation of this file.
00001 /*
00002  * $Id: hash.h 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Header file for trusted and address hash table functions
00005  *
00006  * Copyright (C) 2003-2006 Juha Heinanen
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 #ifndef _PERM_HASH_H_
00026 #define _PERM_HASH_H_
00027 
00028 #include <stdio.h>
00029 #include "../../parser/msg_parser.h"
00030 #include "../../str.h"
00031 #include "../../usr_avp.h"
00032 #include "../../mi/mi.h"
00033 
00034 #define PERM_HASH_SIZE 128
00035 
00036 /*
00037  * Structure stored in trusted hash table
00038  */
00039 struct trusted_list {
00040    str src_ip;                 /* Source IP of SIP message */
00041    int proto;                  /* Protocol -- UDP, TCP, TLS, or SCTP */
00042    char *pattern;              /* Pattern matching From header field */
00043    str tag;                    /* Tag to be assigned to AVP */
00044    struct trusted_list *next;  /* Next element in the list */
00045 };
00046 
00047 
00048 /*
00049  * Parse and init tag avp specification
00050  */
00051 int init_tag_avp(str *tag_avp_param);
00052 
00053 
00054 /*
00055  * Gets tag avp specs
00056  */
00057 void get_tag_avp(int_str *tag_avp_p, int *tag_avp_type_p);
00058 
00059 
00060 /*
00061  * Create and initialize a hash table
00062  */
00063 struct trusted_list** new_hash_table(void);
00064 
00065 
00066 /*
00067  * Release all memory allocated for a hash table
00068  */
00069 void free_hash_table(struct trusted_list** table);
00070 
00071 
00072 /*
00073  * Destroy a hash table
00074  */
00075 void destroy_hash_table(struct trusted_list** table);
00076 
00077 
00078 /* 
00079  * Add <src_ip, proto, pattern> into hash table, where proto is integer
00080  * representation of string argument proto.
00081  */
00082 int hash_table_insert(struct trusted_list** hash_table, char* src_ip,
00083             char* proto, char* pattern, char* tag);
00084 
00085 
00086 /* 
00087  * Check if an entry exists in hash table that has given src_ip and protocol
00088  * value and pattern that matches to From URI.
00089  */
00090 int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
00091            char *scr_ip, int proto);
00092 
00093 
00094 /* 
00095  * Print entries stored in hash table 
00096  */
00097 void hash_table_print(struct trusted_list** hash_table, FILE* reply_file);
00098 int hash_table_mi_print(struct trusted_list **hash_table, struct mi_node* rpl);
00099 
00100 /* 
00101  * Empty hash table
00102  */
00103 void empty_hash_table(struct trusted_list** hash_table);
00104 
00105 
00106 /*
00107  * Structure stored in address hash table
00108  */
00109 struct addr_list {
00110     unsigned int grp;
00111     unsigned int ip_addr;
00112     unsigned int port;
00113     struct addr_list *next;  /* Next element in the list */
00114 };
00115 
00116 
00117 /*
00118  * Create and initialize a hash table
00119  */
00120 struct addr_list** new_addr_hash_table(void);
00121 
00122 
00123 /*
00124  * Release all memory allocated for a hash table
00125  */
00126 void free_addr_hash_table(struct addr_list** table);
00127 
00128 
00129 /*
00130  * Destroy a hash table
00131  */
00132 void destroy_addr_hash_table(struct addr_list** table);
00133 
00134 
00135 /* 
00136  * Add <group, ip_addr, port> into hash table
00137  */
00138 int addr_hash_table_insert(struct addr_list** hash_table, unsigned int grp,
00139             unsigned int ip_addr, unsigned int port);
00140 
00141 
00142 /* 
00143  * Check if an entry exists in hash table that has given group, ip_addr, and
00144  * port.  Port 0 in hash table matches any port.
00145  */
00146 int match_addr_hash_table(struct addr_list** table, unsigned int grp,
00147            unsigned int ip_addr, unsigned int port);
00148 
00149 
00150 /* 
00151  * Checks if an ip_addr/port entry exists in address hash table in any group.
00152  * Port 0 in hash table matches any port.   Returns group of the first match
00153  * or -1 if no match is found.
00154  */
00155 int find_group_in_addr_hash_table(struct addr_list** table,
00156               unsigned int ip_addr, unsigned int port);
00157 
00158 
00159 /* 
00160  * Print addresses stored in hash table
00161  */
00162 void addr_hash_table_print(struct addr_list** hash_table, FILE* reply_file);
00163 int addr_hash_table_mi_print(struct addr_list** hash_table,
00164               struct mi_node* rpl);
00165 
00166 
00167 /* 
00168  * Empty hash table
00169  */
00170 void empty_addr_hash_table(struct addr_list** hash_table);
00171 
00172 
00173 #define PERM_MAX_SUBNETS 128 
00174 
00175 
00176 /*
00177  * Structure used to store a subnet
00178  */
00179 struct subnet {
00180     unsigned int grp;        /* address group, subnet count in last record */
00181     unsigned int subnet;     /* IP subnet in host byte order with host bits shifted out */
00182     unsigned int port;       /* port or 0 */
00183     unsigned int mask;       /* how many bits belong to network part */
00184 };
00185 
00186 
00187 /*
00188  * Create a subnet table
00189  */
00190 struct subnet* new_subnet_table(void);
00191 
00192 
00193 /* 
00194  * Check if an entry exists in subnet table that matches given group, ip_addr,
00195  * and port.  Port 0 in subnet table matches any port.
00196  */
00197 int match_subnet_table(struct subnet* table, unsigned int group,
00198              unsigned int ip_addr, unsigned int port);
00199 
00200 
00201 /* 
00202  * Checks if an entry exists in subnet table that matches given ip_addr,
00203  * and port.  Port 0 in subnet table matches any port.  Returns group of
00204  * the first match or -1 if no match is found.
00205  */
00206 int find_group_in_subnet_table(struct subnet* table,
00207                 unsigned int ip_addr, unsigned int port);
00208 
00209 /* 
00210  * Empty contents of subnet table
00211  */
00212 void empty_subnet_table(struct subnet *table);
00213 
00214 
00215 /*
00216  * Release memory allocated for a subnet table
00217  */
00218 void free_subnet_table(struct subnet* table);
00219 
00220 
00221 /* 
00222  * Add <grp, subnet, mask, port> into subnet table so that table is
00223  * kept ordered according to subnet, port, grp.
00224  */
00225 int subnet_table_insert(struct subnet* table, unsigned int grp,
00226          unsigned int subnet, unsigned int mask,
00227          unsigned int port);
00228 
00229 
00230 /* 
00231  * Print subnets stored in subnet table
00232  */
00233 void subnet_table_print(struct subnet* table, FILE* reply_file);
00234 int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl);
00235 
00236 
00237 #endif /* _PERM_HASH_H_ */

Generated on Thu May 24 02:00:26 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6