app_txtcidname.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Caller*id name lookup - Look up the caller's name via DNS
  5. *
  6. * Copyright (C) 1999-2004, Digium
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/options.h>
  19. #include <asterisk/config.h>
  20. #include <asterisk/module.h>
  21. #include <asterisk/enum.h>
  22. #include <asterisk/utils.h>
  23. #include <stdlib.h>
  24. #include <unistd.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <ctype.h>
  28. static char *tdesc = "TXTCIDName";
  29. static char *app = "TXTCIDName";
  30. static char *synopsis = "Lookup caller name from TXT record";
  31. static char *descrip =
  32. " TXTLookup(CallerID): Looks up a Caller Name via DNS and sets\n"
  33. "the variable 'TXTCIDNAME'. TXTCIDName will either be blank\n"
  34. "or return the value found in the TXT record in DNS.\n" ;
  35. #define ENUM_CONFIG "enum.conf"
  36. static char h323driver[80] = "";
  37. #define H323DRIVERDEFAULT "H323"
  38. STANDARD_LOCAL_USER;
  39. LOCAL_USER_DECL;
  40. static int txtcidname_exec(struct ast_channel *chan, void *data)
  41. {
  42. int res=0;
  43. char tech[80];
  44. char txt[256] = "";
  45. char dest[80];
  46. struct localuser *u;
  47. if (!data || !strlen(data)) {
  48. ast_log(LOG_WARNING, "TXTCIDName requires an argument (extension)\n");
  49. res = 1;
  50. }
  51. LOCAL_USER_ADD(u);
  52. if (!res) {
  53. res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
  54. }
  55. LOCAL_USER_REMOVE(u);
  56. /* Parse it out */
  57. if (res > 0) {
  58. if (!ast_strlen_zero(txt)) {
  59. pbx_builtin_setvar_helper(chan, "TXTCIDNAME", txt);
  60. #if 0
  61. ast_log(LOG_DEBUG, "TXTCIDNAME got '%s'\n", txt);
  62. #endif
  63. }
  64. }
  65. if (!res) {
  66. /* Look for a "busy" place */
  67. if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  68. chan->priority += 100;
  69. } else if (res > 0)
  70. res = 0;
  71. return res;
  72. }
  73. static int load_config(void)
  74. {
  75. struct ast_config *cfg;
  76. char *s;
  77. cfg = ast_load(ENUM_CONFIG);
  78. if (cfg) {
  79. if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) {
  80. strncpy(h323driver, H323DRIVERDEFAULT, sizeof(h323driver) - 1);
  81. } else {
  82. strncpy(h323driver, s, sizeof(h323driver) - 1);
  83. }
  84. ast_destroy(cfg);
  85. return 0;
  86. }
  87. ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n");
  88. return 0;
  89. }
  90. int unload_module(void)
  91. {
  92. STANDARD_HANGUP_LOCALUSERS;
  93. return ast_unregister_application(app);
  94. }
  95. int load_module(void)
  96. {
  97. int res;
  98. res = ast_register_application(app, txtcidname_exec, synopsis, descrip);
  99. if (res)
  100. return(res);
  101. if ((res=load_config())) {
  102. return(res);
  103. }
  104. return(0);
  105. }
  106. int reload(void)
  107. {
  108. return(load_config());
  109. }
  110. char *description(void)
  111. {
  112. return tdesc;
  113. }
  114. int usecount(void)
  115. {
  116. int res;
  117. STANDARD_USECOUNT(res);
  118. return res;
  119. }
  120. char *key()
  121. {
  122. return ASTERISK_GPL_KEY;
  123. }