#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <regex.h>
#include <unistd.h>
#include <errno.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/enum.h>
#include <asterisk/dns.h>
#include <asterisk/channel.h>
#include <asterisk/config.h>
#include <asterisk/utils.h>
Go to the source code of this file.
Defines | |
#define | TOPLEV "e164.arpa." |
Functions | |
AST_MUTEX_DEFINE_STATIC (enumlock) | |
int | ast_get_enum (struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen) |
int | ast_get_txt (struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char *txt, int txtlen) |
int | ast_enum_init (void) |
int | ast_enum_reload (void) |
Variables | |
naptr | __packed__ |
|
Definition at line 47 of file enum.c. Referenced by ast_enum_init(). |
|
Definition at line 416 of file enum.c. References ast_destroy(), ast_load(), ast_mutex_lock, ast_mutex_unlock, ast_variable_browse(), free, ast_variable::name, ast_variable::next, TOPLEV, and ast_variable::value. Referenced by ast_enum_reload(), and main(). 00417 { 00418 struct ast_config *cfg; 00419 struct enum_search *s, *sl; 00420 struct ast_variable *v; 00421 00422 /* Destroy existing list */ 00423 ast_mutex_lock(&enumlock); 00424 s = toplevs; 00425 while(s) { 00426 sl = s; 00427 s = s->next; 00428 free(sl); 00429 } 00430 toplevs = NULL; 00431 cfg = ast_load("enum.conf"); 00432 if (cfg) { 00433 sl = NULL; 00434 v = ast_variable_browse(cfg, "general"); 00435 while(v) { 00436 if (!strcasecmp(v->name, "search")) { 00437 s = enum_newtoplev(v->value); 00438 if (s) { 00439 if (sl) 00440 sl->next = s; 00441 else 00442 toplevs = s; 00443 sl = s; 00444 } 00445 } 00446 v = v->next; 00447 } 00448 ast_destroy(cfg); 00449 } else { 00450 toplevs = enum_newtoplev(TOPLEV); 00451 } 00452 enumver++; 00453 ast_mutex_unlock(&enumlock); 00454 return 0; 00455 }
|
|
Definition at line 457 of file enum.c. References ast_enum_init(). Referenced by ast_module_reload(), and main(). 00458 { 00459 return ast_enum_init(); 00460 }
|
|
Definition at line 289 of file enum.c. References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_search_dns(), enum_context::dst, enum_context::dstlen, LOG_DEBUG, enum_context::naptrinput, s, enum_context::tech, and enum_context::techlen. 00290 { 00291 struct enum_context context; 00292 char tmp[259 + 80]; 00293 char naptrinput[80] = "+"; 00294 int pos = strlen(number) - 1; 00295 int newpos = 0; 00296 int ret = -1; 00297 struct enum_search *s = NULL; 00298 int version = -1; 00299 00300 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00301 00302 context.naptrinput = naptrinput; 00303 context.dst = dst; 00304 context.dstlen = dstlen; 00305 context.tech = tech; 00306 context.techlen = techlen; 00307 00308 if (pos > 128) 00309 pos = 128; 00310 while(pos >= 0) { 00311 tmp[newpos++] = number[pos--]; 00312 tmp[newpos++] = '.'; 00313 } 00314 00315 if (chan && ast_autoservice_start(chan) < 0) 00316 return -1; 00317 00318 for(;;) { 00319 ast_mutex_lock(&enumlock); 00320 if (version != enumver) { 00321 /* Ooh, a reload... */ 00322 s = toplevs; 00323 version = enumver; 00324 } else { 00325 s = s->next; 00326 } 00327 if (s) { 00328 strncpy(tmp + newpos, s->toplev, sizeof(tmp) - newpos - 1); 00329 } 00330 ast_mutex_unlock(&enumlock); 00331 if (!s) 00332 break; 00333 ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback); 00334 if (ret > 0) 00335 break; 00336 } 00337 if (ret < 0) { 00338 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00339 ret = 0; 00340 } 00341 if (chan) 00342 ret |= ast_autoservice_stop(chan); 00343 return ret; 00344 }
|
|
Definition at line 346 of file enum.c. References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_search_dns(), enum_context::dst, enum_context::dstlen, LOG_DEBUG, enum_context::naptrinput, s, enum_context::tech, enum_context::techlen, enum_context::txt, and enum_context::txtlen. 00347 { 00348 struct enum_context context; 00349 char tmp[259 + 80]; 00350 char naptrinput[80] = "+"; 00351 int pos = strlen(number) - 1; 00352 int newpos = 0; 00353 int ret = -1; 00354 struct enum_search *s = NULL; 00355 int version = -1; 00356 00357 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00358 00359 context.naptrinput = naptrinput; 00360 context.dst = dst; 00361 context.dstlen = dstlen; 00362 context.tech = tech; 00363 context.techlen = techlen; 00364 context.txt = txt; 00365 context.txtlen = txtlen; 00366 00367 if (pos > 128) 00368 pos = 128; 00369 while(pos >= 0) { 00370 tmp[newpos++] = number[pos--]; 00371 tmp[newpos++] = '.'; 00372 } 00373 00374 if (chan && ast_autoservice_start(chan) < 0) 00375 return -1; 00376 00377 for(;;) { 00378 ast_mutex_lock(&enumlock); 00379 if (version != enumver) { 00380 /* Ooh, a reload... */ 00381 s = toplevs; 00382 version = enumver; 00383 } else { 00384 s = s->next; 00385 } 00386 if (s) { 00387 strncpy(tmp + newpos, s->toplev, sizeof(tmp) - newpos - 1); 00388 } 00389 ast_mutex_unlock(&enumlock); 00390 if (!s) 00391 break; 00392 ret = ast_search_dns(&context, tmp, C_IN, T_TXT, txt_callback); 00393 if (ret > 0) 00394 break; 00395 } 00396 if (ret < 0) { 00397 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00398 ret = 0; 00399 } 00400 if (chan) 00401 ret |= ast_autoservice_stop(chan); 00402 return ret; 00403 }
|
|
|
|
|