#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <errno.h>
#include <ctype.h>
#include <regex.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/enum.h>
#include <asterisk/channel.h>
#include <asterisk/config.h>
Go to the source code of this file.
Data Structures | |
struct | dn_answer |
struct | dns_HEADER |
struct | enum_search |
struct | naptr |
Defines | |
#define | MAX_SIZE 4096 |
#define | TOPLEV "e164.arpa." |
Functions | |
int | ast_get_enum (struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen) |
int | ast_enum_init (void) |
int | ast_enum_reload (void) |
Variables | |
dn_answer | __packed__ |
|
Definition at line 34 of file enum.c. Referenced by ast_get_enum(), and ast_get_srv(). |
|
Definition at line 36 of file enum.c. Referenced by ast_enum_init(). |
|
Definition at line 447 of file enum.c. References ast_destroy(), ast_load(), ast_mutex_lock, ast_mutex_unlock, ast_variable_browse(), free, and TOPLEV. Referenced by ast_enum_reload(), and main().
00448 { 00449 struct ast_config *cfg; 00450 struct enum_search *s, *sl; 00451 struct ast_variable *v; 00452 00453 /* Destroy existing list */ 00454 ast_mutex_lock(&enumlock); 00455 s = toplevs; 00456 while(s) { 00457 sl = s; 00458 s = s->next; 00459 free(sl); 00460 } 00461 toplevs = NULL; 00462 cfg = ast_load("enum.conf"); 00463 if (cfg) { 00464 sl = NULL; 00465 v = ast_variable_browse(cfg, "general"); 00466 while(v) { 00467 if (!strcasecmp(v->name, "search")) { 00468 s = enum_newtoplev(v->value); 00469 if (s) { 00470 if (sl) 00471 sl->next = s; 00472 else 00473 toplevs = s; 00474 sl = s; 00475 } 00476 } 00477 v = v->next; 00478 } 00479 ast_destroy(cfg); 00480 } else { 00481 toplevs = enum_newtoplev(TOPLEV); 00482 } 00483 enumver++; 00484 ast_mutex_unlock(&enumlock); 00485 return 0; 00486 } |
|
Definition at line 488 of file enum.c. References ast_enum_init(). Referenced by ast_module_reload().
00489 { 00490 return ast_enum_init(); 00491 } |
|
Definition at line 371 of file enum.c. References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_DEBUG, LOG_WARNING, and MAX_SIZE.
00372 { 00373 unsigned char answer[MAX_SIZE]; 00374 char tmp[259 + 80]; 00375 char naptrinput[80] = "+"; 00376 int pos = strlen(number) - 1; 00377 int newpos=0; 00378 int res = -1; 00379 int ret = -1; 00380 struct enum_search *s = NULL; 00381 int version = -1; 00382 struct __res_state enumstate; 00383 res_ninit(&enumstate); 00384 if (chan && ast_autoservice_start(chan) < 0) 00385 return -1; 00386 00387 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00388 00389 if (pos > 128) 00390 pos = 128; 00391 while(pos >= 0) { 00392 tmp[newpos++] = number[pos--]; 00393 tmp[newpos++] = '.'; 00394 } 00395 #if 0 00396 printf("Looking for '%s'\n", tmp); 00397 #endif 00398 00399 for(;;) { 00400 ast_mutex_lock(&enumlock); 00401 if (version != enumver) { 00402 /* Ooh, a reload... */ 00403 s = toplevs; 00404 version = enumver; 00405 } else { 00406 s = s->next; 00407 } 00408 if (s) { 00409 strcpy(tmp + newpos, s->toplev); 00410 } 00411 ast_mutex_unlock(&enumlock); 00412 if (!s) 00413 break; 00414 res = res_nsearch(&enumstate, tmp, C_IN, T_NAPTR, answer, sizeof(answer)); 00415 if (res > 0) 00416 break; 00417 } 00418 if (res > 0) { 00419 if ((res = parse_answer(dst, dstlen, tech, techlen, answer, res, naptrinput))) { 00420 ast_log(LOG_WARNING, "Parse error returned %d\n", res); 00421 ret = 0; 00422 } else { 00423 ast_log(LOG_DEBUG, "Found technology '%s', destination '%s'\n", tech, dst); 00424 ret = 1; 00425 } 00426 } else { 00427 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00428 ret = 0; 00429 } 00430 if (chan) 00431 ret |= ast_autoservice_stop(chan); 00432 res_nclose(&enumstate); 00433 return ret; 00434 } |
|
|