Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
numhash.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * numhash.h - (telephone) number storing/hashing system
59  *
60  * Kalle Marjola 2000 for project Kannel
61  *
62  * !!! NOTE NOTE NOTE !!!
63  *
64  * Phone number precision is limited according to sizeof(long long)
65  * in host machine. that is usually either 32 or 64 bits. In a
66  * case of 32 bit longs, only last 19 digits are checked, otherwise
67  * last 38 digits. This means that in some places several numbers
68  * might map to same hash entry, and thus some caution is needed
69  * specially with telephone number black lists
70  *
71  * USAGE:
72  * the system is not very dynamic; if you want to resize the table
73  * or hash, you must first nuke all old data and then recreate it
74  *
75  * MEMORY NEEDED: (approximated)
76  *
77  * 2* (sizeof(long long)+sizeof(void *)) bytes per number
78  */
79 
80 #ifndef NUMHASH_H
81 #define NUMHASH_H
82 
83 #include <stdio.h>
84 
85 /* number hashing/seeking functions
86  * all return -1 on error and write to general Kannel log
87  *
88  * these 2 first are only required if you want to add the numbers
89  * by hand - otherwise use the last function instead
90  *
91  * use prime_hash if you want an automatically generated hash size
92  */
93 
94 typedef struct numhash_table Numhash;
95 
96 
97 /* get numbers from 'url' and create a new database out of them
98  * Return NULL if cannot open database or other error, error is logged
99  *
100  * Numbers to datafile are saved as follows:
101  * - one number per line
102  * - number might have white spaces, '+' and '-' signs
103  * - number is ended with ':' or end-of-line
104  * - there can be additional comment after ':'
105  *
106  * For example, all following ones are valid lines:
107  * 040 1234
108  * +358 40 1234
109  * +358 40-1234 : Kalle Marjola
110  */
111 Numhash *numhash_create(const char *url);
112 
113 /* destroy hash and all numbers in it */
115 
116 /* check if the number is in database, return 1 if found, 0 if not,
117  * -1 on error */
119 
120 /* if we already have the key */
121 int numhash_find_key(Numhash *table, long long key);
122 
123 /* if we want to know the key */
124 long long numhash_get_key(Octstr *nro);
125 long long numhash_get_char_key(char *nro);
126 
127 
128 /* Return hash fill percent. If 'longest' != NULL, set as longest
129  * trail in hash */
130 double numhash_hash_fill(Numhash *table, int *longest);
131 
132 /* return number of numbers in hash */
134 
135 #endif
long long numhash_get_key(Octstr *nro)
Definition: numhash.c:242
long long numhash_get_char_key(char *nro)
Definition: numhash.c:257
Numhash * numhash_create(const char *url)
Definition: numhash.c:313
int numhash_size(Numhash *table)
Definition: numhash.c:307
void numhash_destroy(Numhash *table)
Definition: numhash.c:275
double numhash_hash_fill(Numhash *table, int *longest)
Definition: numhash.c:285
int numhash_find_key(Numhash *table, long long key)
Definition: numhash.c:228
Definition: octstr.c:118
int numhash_find_number(Numhash *table, Octstr *nro)
Definition: numhash.c:218
static Octstr * url
Definition: test_xmlrpc.c:84
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.