Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

enum.c File Reference

#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>

Include dependency graph for enum.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  enum_search
struct  naptr
struct  enum_context

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__


Define Documentation

#define TOPLEV   "e164.arpa."
 

Definition at line 47 of file enum.c.

Referenced by ast_enum_init().


Function Documentation

int ast_enum_init void   ) 
 

Definition at line 401 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().

00402 { 00403 struct ast_config *cfg; 00404 struct enum_search *s, *sl; 00405 struct ast_variable *v; 00406 00407 /* Destroy existing list */ 00408 ast_mutex_lock(&enumlock); 00409 s = toplevs; 00410 while(s) { 00411 sl = s; 00412 s = s->next; 00413 free(sl); 00414 } 00415 toplevs = NULL; 00416 cfg = ast_load("enum.conf"); 00417 if (cfg) { 00418 sl = NULL; 00419 v = ast_variable_browse(cfg, "general"); 00420 while(v) { 00421 if (!strcasecmp(v->name, "search")) { 00422 s = enum_newtoplev(v->value); 00423 if (s) { 00424 if (sl) 00425 sl->next = s; 00426 else 00427 toplevs = s; 00428 sl = s; 00429 } 00430 } 00431 v = v->next; 00432 } 00433 ast_destroy(cfg); 00434 } else { 00435 toplevs = enum_newtoplev(TOPLEV); 00436 } 00437 enumver++; 00438 ast_mutex_unlock(&enumlock); 00439 return 0; 00440 }

int ast_enum_reload void   ) 
 

Definition at line 442 of file enum.c.

References ast_enum_init().

Referenced by ast_module_reload().

00443 { 00444 return ast_enum_init(); 00445 }

int ast_get_enum struct ast_channel chan,
const char *  number,
char *  dst,
int  dstlen,
char *  tech,
int  techlen
 

Definition at line 274 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.

00275 { 00276 struct enum_context context; 00277 char tmp[259 + 80]; 00278 char naptrinput[80] = "+"; 00279 int pos = strlen(number) - 1; 00280 int newpos = 0; 00281 int ret = -1; 00282 struct enum_search *s = NULL; 00283 int version = -1; 00284 00285 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00286 00287 context.naptrinput = naptrinput; 00288 context.dst = dst; 00289 context.dstlen = dstlen; 00290 context.tech = tech; 00291 context.techlen = techlen; 00292 00293 if (pos > 128) 00294 pos = 128; 00295 while(pos >= 0) { 00296 tmp[newpos++] = number[pos--]; 00297 tmp[newpos++] = '.'; 00298 } 00299 00300 if (chan && ast_autoservice_start(chan) < 0) 00301 return -1; 00302 00303 for(;;) { 00304 ast_mutex_lock(&enumlock); 00305 if (version != enumver) { 00306 /* Ooh, a reload... */ 00307 s = toplevs; 00308 version = enumver; 00309 } else { 00310 s = s->next; 00311 } 00312 if (s) { 00313 strcpy(tmp + newpos, s->toplev); 00314 } 00315 ast_mutex_unlock(&enumlock); 00316 if (!s) 00317 break; 00318 ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback); 00319 if (ret > 0) 00320 break; 00321 } 00322 if (ret < 0) { 00323 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00324 ret = 0; 00325 } 00326 if (chan) 00327 ret |= ast_autoservice_stop(chan); 00328 return ret; 00329 }

int ast_get_txt struct ast_channel chan,
const char *  number,
char *  dst,
int  dstlen,
char *  tech,
int  techlen,
char *  txt,
int  txtlen
 

Definition at line 331 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.

00332 { 00333 struct enum_context context; 00334 char tmp[259 + 80]; 00335 char naptrinput[80] = "+"; 00336 int pos = strlen(number) - 1; 00337 int newpos = 0; 00338 int ret = -1; 00339 struct enum_search *s = NULL; 00340 int version = -1; 00341 00342 strncat(naptrinput, number, sizeof(naptrinput) - 2); 00343 00344 context.naptrinput = naptrinput; 00345 context.dst = dst; 00346 context.dstlen = dstlen; 00347 context.tech = tech; 00348 context.techlen = techlen; 00349 context.txt = txt; 00350 context.txtlen = txtlen; 00351 00352 if (pos > 128) 00353 pos = 128; 00354 while(pos >= 0) { 00355 tmp[newpos++] = number[pos--]; 00356 tmp[newpos++] = '.'; 00357 } 00358 00359 if (chan && ast_autoservice_start(chan) < 0) 00360 return -1; 00361 00362 for(;;) { 00363 ast_mutex_lock(&enumlock); 00364 if (version != enumver) { 00365 /* Ooh, a reload... */ 00366 s = toplevs; 00367 version = enumver; 00368 } else { 00369 s = s->next; 00370 } 00371 if (s) { 00372 strcpy(tmp + newpos, s->toplev); 00373 } 00374 ast_mutex_unlock(&enumlock); 00375 if (!s) 00376 break; 00377 ret = ast_search_dns(&context, tmp, C_IN, T_TXT, txt_callback); 00378 if (ret > 0) 00379 break; 00380 } 00381 if (ret < 0) { 00382 ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno)); 00383 ret = 0; 00384 } 00385 if (chan) 00386 ret |= ast_autoservice_stop(chan); 00387 return ret; 00388 }

AST_MUTEX_DEFINE_STATIC enumlock   ) 
 


Variable Documentation

struct naptr __packed__
 


Generated on Sat Jun 12 16:41:32 2004 for Asterisk by doxygen 1.3.7