#include <stdio.h>Include dependency graph for numhash.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Typedefs | |
| typedef numhash_table | Numhash |
Functions | |
| Numhash * | numhash_create (char *url) |
| void | numhash_destroy (Numhash *table) |
| int | numhash_find_number (Numhash *table, Octstr *nro) |
| int | numhash_find_key (Numhash *table, long key) |
| long | numhash_get_key (Octstr *nro) |
| long | numhash_get_char_key (char *nro) |
| double | numhash_hash_fill (Numhash *table, int *longest) |
| int | numhash_size (Numhash *table) |
|
|
Definition at line 94 of file numhash.h. Referenced by add_item(), numhash_add_number(), numhash_create(), numhash_destroy(), numhash_find_key(), numhash_find_number(), numhash_hash_fill(), numhash_init(), numhash_size(), urltrans_black_list(), and urltrans_white_list(). |
|
|
Definition at line 307 of file numhash.c. References charset, data, debug(), error(), gwlist_create, gwlist_destroy(), http_destroy_headers(), http_get_real(), http_header_get_content_type(), HTTP_METHOD_GET, info(), numhash_table::number_total, Numhash, numhash_add_number(), NUMHASH_AUTO_HASH, numhash_init(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_str_compare(), type, and warning(). Referenced by create_onetrans(), create_oneuser(), init_smsbox(), and smsc2_start(). 00308 {
00309 int loc, lines = 0;
00310 List *request_headers, *reply_headers;
00311 Octstr *url, *final_url, *reply_body;
00312 Octstr *type, *charset;
00313
00314 char *data, *ptr, numbuf[100];
00315 int status;
00316 Numhash *table;
00317
00318 url = octstr_create(seek_url);
00319 request_headers = gwlist_create();
00320 status = http_get_real(HTTP_METHOD_GET, url, request_headers, &final_url,
00321 &reply_headers, &reply_body);
00322 octstr_destroy(url);
00323 octstr_destroy(final_url);
00324 gwlist_destroy(request_headers, NULL);
00325
00326 if (status != HTTP_OK) {
00327 http_destroy_headers(reply_headers);
00328 octstr_destroy(reply_body);
00329 error(0, "Cannot load numhash!");
00330 return NULL;
00331 }
00332 http_header_get_content_type(reply_headers, &type, &charset);
00333 octstr_destroy(charset);
00334 http_destroy_headers(reply_headers);
00335
00336 if (octstr_str_compare(type, "text/plain") != 0) {
00337 octstr_destroy(reply_body);
00338 error(0, "Strange content type <%s> for numhash - expecting 'text/plain'"
00339 ", operatiom fails", octstr_get_cstr(type));
00340 octstr_destroy(type);
00341 return NULL;
00342 }
00343 octstr_destroy(type);
00344
00345 ptr = data = octstr_get_cstr(reply_body);
00346 while(*ptr) {
00347 if (*ptr == '\n') lines++;
00348 ptr++;
00349 }
00350 debug("numhash", 0, "Total %d lines in %s", lines, seek_url);
00351
00352 table = numhash_init(lines+10, NUMHASH_AUTO_HASH); /* automatic hash */
00353
00354 /* now, parse the number information */
00355
00356 lines = 0;
00357
00358 while((ptr = strchr(data, '\n'))) { /* each line is ended with linefeed */
00359 *ptr = '\0';
00360 while(*data != '\0' && isspace(*data))
00361 data++;
00362 if (*data != '#') {
00363 loc = 0;
00364 while (*data != '\0') {
00365 if (isdigit(*data))
00366 numbuf[loc++] = *data;
00367 else if (*data == ' ' || *data == '+' || *data == '-')
00368 ;
00369 else break;
00370 data++;
00371 }
00372 if (loc) {
00373 numbuf[loc] = '\0';
00374 numhash_add_number(table, numbuf);
00375 lines++;
00376 }
00377 else
00378 warning(0, "Corrupted line '%s'", data);
00379 }
00380 data = ptr+1; /* next row... */
00381 }
00382 octstr_destroy(reply_body);
00383
00384 info(0, "Read from <%s> total of %ld numbers", seek_url, table->number_total);
00385 return table;
00386 }
|
Here is the call graph for this function:

|
|
Definition at line 269 of file numhash.c. References numhash_table::hash, numhash_table::numbers, and Numhash. Referenced by destroy_onetrans(), destroy_oneuser(), main(), and smsc2_cleanup(). 00270 {
00271 if (table == NULL)
00272 return;
00273 gw_free(table->numbers);
00274 gw_free(table->hash);
00275 gw_free(table);
00276 }
|
|
||||||||||||
|
Definition at line 225 of file numhash.c. References numhash_table::hash, numhash_table::hash_size, numhash_number::key, numhash_number::next, and Numhash. Referenced by numhash_find_number(). 00226 {
00227 struct numhash_number *ptr;
00228
00229 ptr = table->hash[key % table->hash_size];
00230 while (ptr) {
00231 if (ptr->key == key) return 1;
00232 ptr = ptr->next;
00233 }
00234 return 0; /* not found */
00235 }
|
|
||||||||||||
|
Definition at line 216 of file numhash.c. References Numhash, numhash_find_key(), and numhash_get_key(). Referenced by bb_smscconn_receive(), blacklisted(), check_allowed_translation(), smsbox_req_handle(), and whitelisted(). 00217 {
00218 long key = numhash_get_key(nro);
00219 if (key<0) return key;
00220
00221 return numhash_find_key(table, key);
00222 }
|
Here is the call graph for this function:

|
|
Definition at line 253 of file numhash.c. References precision. Referenced by numhash_add_number(). 00254 {
00255 int len;
00256 long key;
00257 if (!nro) return -1;
00258 len = strlen(nro);
00259
00260 if (len > precision)
00261 key = atoi(nro + len -precision);
00262 else
00263 key = atoi(nro);
00264
00265 return key;
00266 }
|
|
|
Definition at line 239 of file numhash.c. References octstr_get_cstr, octstr_len(), and precision. Referenced by numhash_find_number(). 00240 {
00241 long key;
00242 if (!nro) return -1;
00243
00244 if (octstr_len(nro) > precision)
00245 key = atoi(octstr_get_cstr(nro) + octstr_len(nro) -precision);
00246 else
00247 key = atoi(octstr_get_cstr(nro));
00248
00249 return key;
00250 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 279 of file numhash.c. References numhash_table::hash, numhash_table::hash_size, numhash_number::next, and Numhash. 00280 {
00281 int i, l, max = 0, tot = 0;
00282 struct numhash_number *ptr;
00283
00284 for (i=0; i < table->hash_size; i++)
00285 if (table->hash[i]) {
00286 tot++;
00287 ptr = table->hash[i];
00288 for (l=0; ptr->next; ptr = ptr->next)
00289 l++;
00290 if (l > max)
00291 max = l;
00292 }
00293
00294 if (longest != NULL)
00295 *longest = max;
00296
00297 return (double)(tot*100.0/(table->hash_size));
00298 }
|
|
|
Definition at line 301 of file numhash.c. References numhash_table::number_total, and Numhash. 00302 {
00303 return table->number_total;
00304 }
|