00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029
00030 #include "asterisk.h"
00031
00032 #ifndef BUILTIN_FUNC
00033 #include "asterisk/module.h"
00034 #endif
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/utils.h"
00038
00039 #include "asterisk/lock.h"
00040 #include "asterisk/file.h"
00041 #include "asterisk/logger.h"
00042
00043 #include "asterisk/pbx.h"
00044 #include "asterisk/options.h"
00045
00046 #include "asterisk/enum.h"
00047
00048 static char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])\n";
00049
00050 STANDARD_LOCAL_USER;
00051
00052 LOCAL_USER_DECL;
00053
00054 static char *function_enum(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00055 {
00056 int res=0;
00057 char tech[80];
00058 char dest[256] = "";
00059 char *zone;
00060 char *options;
00061 struct localuser *u;
00062 char *params[4];
00063 char *p = data;
00064 char *s;
00065 int i = 0;
00066
00067
00068 if (ast_strlen_zero(data)) {
00069 ast_log(LOG_WARNING, synopsis);
00070 return "";
00071 }
00072
00073 do {
00074 if(i>3){
00075 ast_log(LOG_WARNING, synopsis);
00076 return "";
00077 }
00078 params[i++] = p;
00079 p = strchr(p, '|');
00080 if(p){
00081 *p = '\0';
00082 p++;
00083 }
00084 } while(p);
00085
00086 if(i < 1){
00087 ast_log(LOG_WARNING, synopsis);
00088 return "";
00089 }
00090
00091 if( (i > 1 && strlen(params[1]) == 0) || i < 2){
00092 ast_copy_string(tech, "sip", sizeof(tech));
00093 } else {
00094 ast_copy_string(tech, params[1], sizeof(tech));
00095 }
00096
00097 if( (i > 3 && strlen(params[3]) == 0) || i<4){
00098 zone = "e164.arpa";
00099 } else {
00100 zone = params[3];
00101 }
00102
00103 if( (i > 2 && strlen(params[2]) == 0) || i<3){
00104 options = "1";
00105 } else {
00106 options = params[2];
00107 }
00108
00109
00110 p = params[0];
00111
00112
00113
00114
00115
00116 s = p;
00117 i = 0;
00118 while(*p && *s){
00119 if(*s == '-'){
00120 s++;
00121 } else {
00122 p[i++] = *s++;
00123 }
00124 }
00125 p[i] = 0;
00126
00127 LOCAL_USER_ACF_ADD(u);
00128
00129 res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), zone, options);
00130
00131 LOCAL_USER_REMOVE(u);
00132
00133 p = strchr(dest, ':');
00134 if(p && strncasecmp(tech, "ALL", sizeof(tech))) {
00135 ast_copy_string(buf, p+1, sizeof(dest));
00136 } else {
00137 ast_copy_string(buf, dest, sizeof(dest));
00138 }
00139
00140 return buf;
00141 }
00142
00143 #ifndef BUILTIN_FUNC
00144 static
00145 #endif
00146 struct ast_custom_function enum_function = {
00147 .name = "ENUMLOOKUP",
00148 .synopsis = "ENUMLOOKUP allows for general or specific querying of NAPTR records"
00149 " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
00150 .syntax = "ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])",
00151 .desc = "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
00152 "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
00153 "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
00154 "For more information, see README.enum",
00155 .read = function_enum,
00156 };
00157
00158 static char *function_txtcidname(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00159 {
00160 int res;
00161 char tech[80];
00162 char txt[256] = "";
00163 char dest[80];
00164 struct localuser *u;
00165
00166 LOCAL_USER_ACF_ADD(u);
00167
00168 buf[0] = '\0';
00169
00170 if (ast_strlen_zero(data)) {
00171 ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
00172 LOCAL_USER_REMOVE(u);
00173 return buf;
00174 }
00175
00176 res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
00177
00178 if (!ast_strlen_zero(txt))
00179 ast_copy_string(buf, txt, len);
00180
00181 LOCAL_USER_REMOVE(u);
00182
00183 return buf;
00184 }
00185
00186 #ifndef BUILTIN_FUNC
00187 static
00188 #endif
00189 struct ast_custom_function txtcidname_function = {
00190 .name = "TXTCIDNAME",
00191 .synopsis = "TXTCIDNAME looks up a caller name via DNS",
00192 .syntax = "TXTCIDNAME(<number>)",
00193 .desc = "This function looks up the given phone number in DNS to retrieve\n"
00194 "the caller id name. The result will either be blank or be the value\n"
00195 "found in the TXT record in DNS.\n",
00196 .read = function_txtcidname,
00197 };
00198
00199 #ifndef BUILTIN_FUNC
00200
00201 static char *tdesc = "ENUM Related Functions";
00202
00203 int unload_module(void)
00204 {
00205 ast_custom_function_unregister(&enum_function);
00206 ast_custom_function_unregister(&txtcidname_function);
00207
00208 STANDARD_HANGUP_LOCALUSERS;
00209
00210 return 0;
00211 }
00212
00213 int load_module(void)
00214 {
00215 int res;
00216
00217 res = ast_custom_function_register(&enum_function);
00218 if (!res)
00219 ast_custom_function_register(&txtcidname_function);
00220
00221 return res;
00222 }
00223
00224 char *description(void)
00225 {
00226 return tdesc;
00227 }
00228
00229 int usecount(void)
00230 {
00231 int res;
00232
00233 STANDARD_USECOUNT(res);
00234
00235 return res;
00236 }
00237
00238 char *key()
00239 {
00240 return ASTERISK_GPL_KEY;
00241 }
00242 #endif
00243