domains.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG FOKUS
00005  * Copyright (C) 2008 iptelorg GmbH
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028                        
00029 #ifndef _DOMAINS_H_
00030 #define _DOMAINS_H_
00031 
00032 #include "../../str.h"
00033 
00034 #define MAX_HSIZE_TWO_POW 20
00035 #define MAX_HASH_SIZE 1<<MAX_HSIZE_TWO_POW 
00036 
00037 #define PDT_ADD                 1
00038 #define PDT_DELETE              2
00039 
00040 #define get_hash_entry(c,s) (c)&((s)-1)
00041 
00042 typedef struct _pd
00043 {
00044     str prefix;
00045     str domain;
00046         int flag;
00047     unsigned int dhash;
00048     struct _pd *p;
00049     struct _pd *n;
00050 } pd_t;
00051 
00052 typedef struct _pd_entry
00053 {
00054     gen_lock_t lock;
00055     pd_t *e;
00056 } pd_entry_t;
00057 
00058 typedef struct _pd_op
00059 {
00060     pd_t *cell;
00061         int op;
00062         int id;
00063     int count;
00064     struct _pd_op *p;
00065     struct _pd_op *n;
00066 } pd_op_t;
00067 
00068 typedef struct _pdt_hash
00069 {
00070         pd_entry_t* dhash;
00071         unsigned int hash_size;
00072 
00073         pd_op_t *diff;
00074     gen_lock_t diff_lock;
00075         int max_id;
00076         int workers;
00077 } pdt_hash_t;
00078 
00079 pd_t* new_cell(str* p, str *d);
00080 void free_cell(pd_t *cell);
00081 
00082 pd_op_t* new_pd_op(pd_t *cell, int id, int op);
00083 void free_pd_op(pd_op_t *pdo);
00084 
00085 int pdt_add_to_hash(pdt_hash_t *ph, str *sp, str *sd);
00086 int pdt_remove_from_hash(pdt_hash_t *ph, str *sd);
00087 
00088 str* pdt_get_prefix(pdt_hash_t *ph, str* sd);
00089 int pdt_check_pd(pdt_hash_t *ph, str *sp, str *sd);
00090 
00091 void pdt_print_hash(pdt_hash_t *ph);
00092 
00093 pdt_hash_t* pdt_init_hash(int hash_size);
00094 void pdt_free_hash(pdt_hash_t* ph);
00095 
00096 unsigned int pdt_compute_hash(char *s);
00097 
00098 #endif