Added custom function VANITYNUMBER to convert letters into digits.

This commit is contained in:
MelwareDE 2005-09-17 10:49:34 +00:00
parent 8f30035ca2
commit d73253a545
3 changed files with 89 additions and 2 deletions

12
README
View File

@ -287,4 +287,14 @@ CALLINGSUBADDRESS
CALLEDSUBADDRESS
If set on dial(), the called subaddress will be set to the content.
Functions (available with newer Asterisk only)
==============================================
VANITYNUMBER(<vanitynumber>)
Converts the 'vanitynumber' into a digit-only string. International keypad is
used, e.g. ABC=1, DEF=2, ...

View File

@ -38,6 +38,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
@ -4301,7 +4302,7 @@ static int cc_init_capi(void)
if (capi20_isinstalled() != 0) {
ast_log(LOG_WARNING, "CAPI not installed, CAPI disabled!\n");
return 0;
return -1;
}
if (capi20_register(AST_CAPI_BCHANS, AST_CAPI_MAX_B3_BLOCKS,
@ -4629,6 +4630,66 @@ static int capi_eval_config(struct ast_config *cfg)
return 0;
}
#ifdef CC_AST_CUSTOM_FUNCTION
/*
* convert letters into digits according to international keypad
*/
static char *vanitynumber(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
int pos;
unsigned char c;
*buf = 0;
if (!data) {
ast_log(LOG_WARNING, "This function requires a parameter name.\n");
return NULL;
}
for (pos = 0; (pos < strlen(data)) && (pos < len); pos++) {
c = toupper(data[pos]);
switch(c) {
case 'A': case 'B': case 'C':
buf[pos] = '2';
break;
case 'D': case 'E': case 'F':
buf[pos] = '3';
break;
case 'G': case 'H': case 'I':
buf[pos] = '4';
break;
case 'J': case 'K': case 'L':
buf[pos] = '5';
break;
case 'M': case 'N': case 'O':
buf[pos] = '6';
break;
case 'P': case 'Q': case 'R': case 'S':
buf[pos] = '7';
break;
case 'T': case 'U': case 'V':
buf[pos] = '8';
break;
case 'W': case 'X': case 'Y': case 'Z':
buf[pos] = '9';
break;
default:
buf[pos] = data[pos];
}
}
buf[pos] = 0;
return buf;
}
static struct ast_custom_function vanitynumber_function = {
.name = "VANITYNUMBER",
.synopsis = "Vanity number: convert letter into digits according to international dialpad.",
.syntax = "VANITYNUMBER(<vanitynumber to convert>)",
.read = vanitynumber,
};
#endif
/*
* main: load the module
*/
@ -4682,6 +4743,10 @@ int load_module(void)
ast_register_application(commandapp, capicommand_exec, commandsynopsis, commandtdesc);
#ifdef CC_AST_CUSTOM_FUNCTION
ast_custom_function_register(&vanitynumber_function);
#endif
if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
monitor_thread = (pthread_t)(0-1);
ast_log(LOG_ERROR, "Unable to start monitor thread!\n");
@ -4699,6 +4764,10 @@ int unload_module()
struct ast_capi_pvt *i, *itmp;
int controller;
#ifdef CC_AST_CUSTOM_FUNCTION
ast_custom_function_unregister(&vanitynumber_function);
#endif
ast_unregister_application(commandapp);
ast_cli_unregister(&cli_info);

View File

@ -106,6 +106,14 @@ else
echo " * no 'AST_CONTROL_HOLD'"
fi
if grep -q "struct ast_custom_function" $INCLUDEDIR/pbx.h; then
echo "#define CC_AST_CUSTOM_FUNCTION" >>$CONFIGFILE
echo " * found 'struct ast_custom_function'"
else
echo "#undef CC_AST_CUSTOM_FUNCTION" >>$CONFIGFILE
echo " * no 'struct ast_custom_function'"
fi
echo "" >>$CONFIGFILE
echo "#endif /* CHAN_CAPI_CONFIG_H */" >>$CONFIGFILE
echo "" >>$CONFIGFILE