00001 /* ==================================================================== 00002 * The Kannel Software License, Version 1.0 00003 * 00004 * Copyright (c) 2001-2008 Kannel Group 00005 * Copyright (c) 1998-2001 WapIT Ltd. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Kannel Group (http://www.kannel.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Kannel" and "Kannel Group" must not be used to 00028 * endorse or promote products derived from this software without 00029 * prior written permission. For written permission, please 00030 * contact org@kannel.org. 00031 * 00032 * 5. Products derived from this software may not be called "Kannel", 00033 * nor may "Kannel" appear in their name, without prior written 00034 * permission of the Kannel Group. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 00040 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 00041 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00042 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00043 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00044 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00045 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00046 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Kannel Group. For more information on 00051 * the Kannel Group, please see <http://www.kannel.org/>. 00052 * 00053 * Portions of this software are based upon software originally written at 00054 * WapIT Ltd., Helsinki, Finland for the Kannel project. 00055 */ 00056 00057 /* 00058 * numhash.h - (telephone) number storing/hashing system 00059 * 00060 * Kalle Marjola 2000 for project Kannel 00061 * 00062 * !!! NOTE NOTE NOTE !!! 00063 * 00064 * Phone number precision is limited according to sizeof(long) 00065 * in host machine. that is usually either 32 or 64 bits. In a 00066 * case of 32 bit longs, only last 9 digits are checked, otherwise 00067 * last 18 digits. This means that in some places several numbers 00068 * might map to same hash entry, and thus some caution is needed 00069 * specially with telephone number black lists 00070 * 00071 * USAGE: 00072 * the system is not very dynamic; if you want to resize the table 00073 * or hash, you must first nuke all old data and then recreate it 00074 * 00075 * MEMORY NEEDED: (approximated) 00076 * 00077 * 2* (sizeof(long)+sizeof(void *)) bytes per number 00078 */ 00079 00080 #ifndef NUMHASH_H 00081 #define NUMHASH_H 00082 00083 #include <stdio.h> 00084 00085 /* number hashing/seeking functions 00086 * all return -1 on error and write to general Kannel log 00087 * 00088 * these 2 first are only required if you want to add the numbers 00089 * by hand - otherwise use the last function instead 00090 * 00091 * use prime_hash if you want an automatically generated hash size 00092 */ 00093 00094 typedef struct numhash_table Numhash; 00095 00096 00097 /* get numbers from 'url' and create a new database out of them 00098 * Return NULL if cannot open database or other error, error is logged 00099 * 00100 * Numbers to datafile are saved as follows: 00101 * - one number per line 00102 * - number might have white spaces, '+' and '-' signs 00103 * - number is ended with ':' or end-of-line 00104 * - there can be additional comment after ':' 00105 * 00106 * For example, all following ones are valid lines: 00107 * 040 1234 00108 * +358 40 1234 00109 * +358 40-1234 : Kalle Marjola 00110 */ 00111 Numhash *numhash_create(char *url); 00112 00113 /* destroy hash and all numbers in it */ 00114 void numhash_destroy(Numhash *table); 00115 00116 /* check if the number is in database, return 1 if found, 0 if not, 00117 * -1 on error */ 00118 int numhash_find_number(Numhash *table, Octstr *nro); 00119 00120 /* if we already have the key */ 00121 int numhash_find_key(Numhash *table, long key); 00122 00123 /* if we want to know the key */ 00124 long numhash_get_key(Octstr *nro); 00125 long numhash_get_char_key(char *nro); 00126 00127 00128 /* Return hash fill percent. If 'longest' != NULL, set as longest 00129 * trail in hash */ 00130 double numhash_hash_fill(Numhash *table, int *longest); 00131 00132 /* return number of numbers in hash */ 00133 int numhash_size(Numhash *table); 00134 00135 #endif