#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>
Go to the source code of this file.
Data Structures | |
struct | enum_context |
struct | enum_search |
struct | naptr |
Defines | |
#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 | |
naptr | __packed__ |
|
Definition at line 41 of file enum.c. Referenced by ast_enum_init(). |
|
Definition at line 312 of file enum.c. References ast_destroy(), ast_load(), ast_mutex_lock, ast_mutex_unlock, ast_variable_browse(), free, s, and TOPLEV. Referenced by ast_enum_reload(), and main().
00313 { 00314 struct ast_config *cfg; 00315 struct enum_search *s, *sl; 00316 struct ast_variable *v; 00317 00318 /* Destroy existing list */ 00319 ast_mutex_lock(&enumlock); 00320 s = toplevs; 00321 while(s) { 00322 sl = s; 00323 s = s->next; 00324 free(sl); 00325 } 00326 toplevs = NULL; 00327 cfg = ast_load("enum.conf"); 00328 if (cfg) { 00329 sl = NULL; 00330 v = ast_variable_browse(cfg, "general"); 00331 while(v) { 00332 if (!strcasecmp(v->name, "search")) { 00333 s = enum_newtoplev(v->value); 00334 if (s) { 00335 if (sl) 00336 sl->next = s; 00337 else 00338 toplevs = s; 00339 sl = s; 00340 } 00341 } 00342 v = v->next; 00343 } 00344 ast_destroy(cfg); 00345 } else { 00346 toplevs = enum_newtoplev(TOPLEV); 00347 } 00348 enumver++; 00349 ast_mutex_unlock(&enumlock); 00350 return 0; 00351 } |
|
Definition at line 353 of file enum.c. References ast_enum_init(). Referenced by ast_module_reload().
00354 { 00355 return ast_enum_init(); 00356 } |
|
Definition at line 244 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.
00245 { 00246 struct enum_context context; 00247 char tmp[259 + 80]; 00248 char naptrinput[80] = "+"; 00249 int pos = strlen(number) - 1; 00250 int newpos = 0; 00251 int ret = -1; 00252 struct enum_search *s = NULL; 00253 int version = -1; 00254 00255 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00256 00257 context.naptrinput = naptrinput; 00258 context.dst = dst; 00259 context.dstlen = dstlen; 00260 context.tech = tech; 00261 context.techlen = techlen; 00262 00263 if (pos > 128) 00264 pos = 128; 00265 while(pos >= 0) { 00266 tmp[newpos++] = number[pos--]; 00267 tmp[newpos++] = '.'; 00268 } 00269 00270 if (chan && ast_autoservice_start(chan) < 0) 00271 return -1; 00272 00273 for(;;) { 00274 ast_mutex_lock(&enumlock); 00275 if (version != enumver) { 00276 /* Ooh, a reload... */ 00277 s = toplevs; 00278 version = enumver; 00279 } else { 00280 s = s->next; 00281 } 00282 if (s) { 00283 strcpy(tmp + newpos, s->toplev); 00284 } 00285 ast_mutex_unlock(&enumlock); 00286 if (!s) 00287 break; 00288 ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback); 00289 if (ret > 0) 00290 break; 00291 } 00292 if (ret < 0) { 00293 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00294 ret = 0; 00295 } 00296 if (chan) 00297 ret |= ast_autoservice_stop(chan); 00298 return ret; 00299 } |
|
|