mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-03 04:16:43 +00:00
Fri Feb 21 07:00:01 CET 2003
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@620 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -18,7 +18,7 @@ APPS=app_dial.so app_playback.so app_voicemail.so app_directory.so app_intercom.
|
|||||||
app_zapateller.so app_datetime.so app_setcallerid.so app_festival.so \
|
app_zapateller.so app_datetime.so app_setcallerid.so app_festival.so \
|
||||||
app_queue.so app_senddtmf.so app_parkandannounce.so app_striplsd.so \
|
app_queue.so app_senddtmf.so app_parkandannounce.so app_striplsd.so \
|
||||||
app_setcidname.so app_lookupcidname.so app_substring.so app_macro.so \
|
app_setcidname.so app_lookupcidname.so app_substring.so app_macro.so \
|
||||||
app_authenticate.so
|
app_authenticate.so app_softhangup.so app_lookupblacklist.so
|
||||||
|
|
||||||
#APPS+=app_sql_postgres.so
|
#APPS+=app_sql_postgres.so
|
||||||
#APPS+=app_sql_odbc.so
|
#APPS+=app_sql_odbc.so
|
||||||
|
|||||||
112
apps/app_lookupblacklist.c
Executable file
112
apps/app_lookupblacklist.c
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Asterisk -- A telephony toolkit for Linux.
|
||||||
|
*
|
||||||
|
* App to lookup the callerid number, and see if it is blacklisted
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999, Mark Spencer
|
||||||
|
*
|
||||||
|
* Mark Spencer <markster@linux-support.net>
|
||||||
|
*
|
||||||
|
* This program is free software, distributed under the terms of
|
||||||
|
* the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asterisk/lock.h>
|
||||||
|
#include <asterisk/file.h>
|
||||||
|
#include <asterisk/logger.h>
|
||||||
|
#include <asterisk/options.h>
|
||||||
|
#include <asterisk/channel.h>
|
||||||
|
#include <asterisk/pbx.h>
|
||||||
|
#include <asterisk/module.h>
|
||||||
|
#include <asterisk/translate.h>
|
||||||
|
#include <asterisk/image.h>
|
||||||
|
#include <asterisk/callerid.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
static char *tdesc = "Look up number from local blacklist database";
|
||||||
|
|
||||||
|
static char *app = "LookupBlacklist";
|
||||||
|
|
||||||
|
static char *synopsis = "Look up number from local blacklist database";
|
||||||
|
|
||||||
|
static char *descrip =
|
||||||
|
" LookupBlacklist: Looks up the Caller*ID number on the active\n"
|
||||||
|
"channel in the Asterisk database (family 'blacklist'). If the\n"
|
||||||
|
"number is found, and if there exists a priority n + 101,\n"
|
||||||
|
"where 'n' is the priority of the current instance, then the\n"
|
||||||
|
"channel will be setup to continue at that priority level.\n"
|
||||||
|
"Otherwise, it returns 0. Does nothing if no Caller*ID was received on the\n"
|
||||||
|
"channel.\n";
|
||||||
|
|
||||||
|
STANDARD_LOCAL_USER;
|
||||||
|
|
||||||
|
LOCAL_USER_DECL;
|
||||||
|
|
||||||
|
static int
|
||||||
|
lookupblacklist_exec (struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
|
char old_cid[144] = "", *num, *name;
|
||||||
|
char blacklist[1];
|
||||||
|
char shrunknum[64] = "";
|
||||||
|
struct localuser *u;
|
||||||
|
int bl = 0;
|
||||||
|
|
||||||
|
LOCAL_USER_ADD (u);
|
||||||
|
if (chan->callerid)
|
||||||
|
{
|
||||||
|
strncpy (old_cid, chan->callerid, sizeof (old_cid) - 1);
|
||||||
|
ast_callerid_parse (old_cid, &name, &num); /* this destroys the original string */
|
||||||
|
if (num) /* It's possible to get an empty number */
|
||||||
|
strncpy (shrunknum, num, sizeof (shrunknum) - 1);
|
||||||
|
else
|
||||||
|
num = shrunknum;
|
||||||
|
ast_shrink_phone_number (shrunknum);
|
||||||
|
if (!ast_db_get ("blacklist", shrunknum, blacklist, sizeof (blacklist)))
|
||||||
|
{
|
||||||
|
if (option_verbose > 2)
|
||||||
|
ast_verbose (VERBOSE_PREFIX_3 "Blacklisted number %s found\n",shrunknum);
|
||||||
|
bl = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (bl && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
|
||||||
|
chan->priority+=100;
|
||||||
|
LOCAL_USER_REMOVE (u);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
unload_module (void)
|
||||||
|
{
|
||||||
|
STANDARD_HANGUP_LOCALUSERS;
|
||||||
|
return ast_unregister_application (app);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
load_module (void)
|
||||||
|
{
|
||||||
|
return ast_register_application (app, lookupblacklist_exec, synopsis,
|
||||||
|
descrip);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
description (void)
|
||||||
|
{
|
||||||
|
return tdesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
usecount (void)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
STANDARD_USECOUNT (res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
key ()
|
||||||
|
{
|
||||||
|
return ASTERISK_GPL_KEY;
|
||||||
|
}
|
||||||
88
apps/app_softhangup.c
Executable file
88
apps/app_softhangup.c
Executable file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Asterisk -- A telephony toolkit for Linux.
|
||||||
|
*
|
||||||
|
* SoftHangup application
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999, Mark Spencer
|
||||||
|
*
|
||||||
|
* Mark Spencer <markster@linux-support.net>
|
||||||
|
*
|
||||||
|
* This program is free software, distributed under the terms of
|
||||||
|
* the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asterisk/file.h>
|
||||||
|
#include <asterisk/logger.h>
|
||||||
|
#include <asterisk/channel.h>
|
||||||
|
#include <asterisk/pbx.h>
|
||||||
|
#include <asterisk/module.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
|
static char *synopsis = "Soft Hangup Application";
|
||||||
|
|
||||||
|
static char *tdesc = "Hangs up the requested channel";
|
||||||
|
|
||||||
|
static char *desc = " SoftHangup(Technology/resource)\n"
|
||||||
|
"Hangs up the requested channel. Always returns 0\n";
|
||||||
|
|
||||||
|
static char *app = "SoftHangup";
|
||||||
|
|
||||||
|
STANDARD_LOCAL_USER;
|
||||||
|
|
||||||
|
LOCAL_USER_DECL;
|
||||||
|
|
||||||
|
static int softhangup_exec(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
|
struct localuser *u;
|
||||||
|
struct ast_channel *c=NULL;
|
||||||
|
if (!data) {
|
||||||
|
ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LOCAL_USER_ADD(u);
|
||||||
|
c = ast_channel_walk(NULL);
|
||||||
|
while (c) {
|
||||||
|
if (!strcasecmp(c->name, data)) {
|
||||||
|
ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c = ast_channel_walk(c);
|
||||||
|
}
|
||||||
|
LOCAL_USER_REMOVE(u);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unload_module(void)
|
||||||
|
{
|
||||||
|
STANDARD_HANGUP_LOCALUSERS;
|
||||||
|
return ast_unregister_application(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
int load_module(void)
|
||||||
|
{
|
||||||
|
return ast_register_application(app, softhangup_exec, synopsis, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *description(void)
|
||||||
|
{
|
||||||
|
return tdesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usecount(void)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
STANDARD_USECOUNT(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *key()
|
||||||
|
{
|
||||||
|
return ASTERISK_GPL_KEY;
|
||||||
|
}
|
||||||
@@ -787,7 +787,7 @@ static char *cli_complete(EditLine *el, int ch)
|
|||||||
LineInfo *lf = (LineInfo *)el_line(el);
|
LineInfo *lf = (LineInfo *)el_line(el);
|
||||||
|
|
||||||
*lf->cursor = '\0';
|
*lf->cursor = '\0';
|
||||||
ptr = (char *)lf->cursor-1;
|
ptr = (char *)lf->cursor;
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
while (ptr > lf->buffer) {
|
while (ptr > lf->buffer) {
|
||||||
if (isspace(*ptr)) {
|
if (isspace(*ptr)) {
|
||||||
|
|||||||
26
manager.c
26
manager.c
@@ -69,14 +69,39 @@ static int handle_showmancmds(int fd, int argc, char *argv[])
|
|||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handle_showmanconn(int fd, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct mansession *s;
|
||||||
|
|
||||||
|
ast_pthread_mutex_lock(&sessionlock);
|
||||||
|
s = sessions;
|
||||||
|
ast_cli(fd, " Username\tIP Address\n");
|
||||||
|
while(s) {
|
||||||
|
ast_cli(fd, " %s\t\t%s\r\n",s->username, inet_ntoa(s->sin.sin_addr));
|
||||||
|
s = s->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_pthread_mutex_unlock(&sessionlock);
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static char showmancmds_help[] =
|
static char showmancmds_help[] =
|
||||||
"Usage: show manager commands\n"
|
"Usage: show manager commands\n"
|
||||||
" Prints a listing of all the available manager commands.\n";
|
" Prints a listing of all the available manager commands.\n";
|
||||||
|
|
||||||
|
static char showmanconn_help[] =
|
||||||
|
"Usage: show manager connected\n"
|
||||||
|
" Prints a listing of the users that are connected to the\n"
|
||||||
|
"manager interface.\n";
|
||||||
|
|
||||||
static struct ast_cli_entry show_mancmds_cli =
|
static struct ast_cli_entry show_mancmds_cli =
|
||||||
{ { "show", "manager", "commands", NULL },
|
{ { "show", "manager", "commands", NULL },
|
||||||
handle_showmancmds, "Show manager commands", showmancmds_help };
|
handle_showmancmds, "Show manager commands", showmancmds_help };
|
||||||
|
|
||||||
|
static struct ast_cli_entry show_manconn_cli =
|
||||||
|
{ { "show", "manager", "connected", NULL },
|
||||||
|
handle_showmanconn, "Show connected manager users", showmanconn_help };
|
||||||
|
|
||||||
static void destroy_session(struct mansession *s)
|
static void destroy_session(struct mansession *s)
|
||||||
{
|
{
|
||||||
struct mansession *cur, *prev = NULL;
|
struct mansession *cur, *prev = NULL;
|
||||||
@@ -616,6 +641,7 @@ int init_manager(void)
|
|||||||
ast_manager_register( "Command", EVENT_FLAG_COMMAND, action_command, "Execute Command" );
|
ast_manager_register( "Command", EVENT_FLAG_COMMAND, action_command, "Execute Command" );
|
||||||
|
|
||||||
ast_cli_register(&show_mancmds_cli);
|
ast_cli_register(&show_mancmds_cli);
|
||||||
|
ast_cli_register(&show_manconn_cli);
|
||||||
registered = 1;
|
registered = 1;
|
||||||
}
|
}
|
||||||
portno = DEFAULT_MANAGER_PORT;
|
portno = DEFAULT_MANAGER_PORT;
|
||||||
|
|||||||
248
pbx.c
248
pbx.c
@@ -674,82 +674,15 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, char *cont
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *pbx_substitute_variables(struct ast_channel *c, struct ast_exten *e) {
|
static void pbx_substitute_variables_temp(struct ast_channel *c,char *cp3,char **cp4)
|
||||||
char *cp1,*cp3,*cp4,*cp5;
|
{
|
||||||
void *cp2;
|
int offset;
|
||||||
char c1,c2;
|
|
||||||
int m,mve,origlen,quoted,dolsign,docopy,offset;
|
|
||||||
struct ast_var_t *variables;
|
struct ast_var_t *variables;
|
||||||
|
char *name, *num; /* for callerid name + num variables */
|
||||||
struct varshead *headp;
|
struct varshead *headp;
|
||||||
char pri[80];
|
char pri[80];
|
||||||
char *name, *num; /* for callerid name + num variables */
|
|
||||||
|
|
||||||
headp=&c->varshead;
|
headp=&c->varshead;
|
||||||
origlen=strlen(e->data)+1;
|
*cp4=NULL;
|
||||||
cp2=malloc(origlen);
|
|
||||||
memset(cp2,0,origlen);
|
|
||||||
|
|
||||||
if ((strchr(e->data,'$')==NULL) && (strchr(e->data,'[')==NULL)) {
|
|
||||||
strncpy(cp2,e->data,strlen(e->data));
|
|
||||||
return(cp2);
|
|
||||||
/* No variables or expressions in e->data, so why scan it? */
|
|
||||||
}
|
|
||||||
|
|
||||||
cp4=NULL;
|
|
||||||
cp1=e->data;
|
|
||||||
quoted=0;
|
|
||||||
dolsign=0;
|
|
||||||
docopy=1;
|
|
||||||
|
|
||||||
/* First stage, variable substitution */
|
|
||||||
|
|
||||||
do {
|
|
||||||
c1=*cp1;
|
|
||||||
mve=0;
|
|
||||||
switch (c1) {
|
|
||||||
case '\\' :
|
|
||||||
dolsign=0;
|
|
||||||
if (quoted==1) {
|
|
||||||
quoted=0;
|
|
||||||
docopy=1;
|
|
||||||
} else {
|
|
||||||
quoted=1;
|
|
||||||
docopy=0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '$' :
|
|
||||||
if (quoted==1) {
|
|
||||||
quoted=0;
|
|
||||||
docopy=1;
|
|
||||||
dolsign=0;
|
|
||||||
} else {
|
|
||||||
docopy=0;
|
|
||||||
dolsign=1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '{' :
|
|
||||||
if (quoted==1) {
|
|
||||||
quoted=0;
|
|
||||||
dolsign=0;
|
|
||||||
docopy=1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (dolsign==0) {
|
|
||||||
docopy=1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
docopy=0;
|
|
||||||
dolsign=0;
|
|
||||||
m=0;
|
|
||||||
cp1++;
|
|
||||||
while (((c2=*(cp1+m))!='}') && (c2!='\0')) {
|
|
||||||
m++;
|
|
||||||
}
|
|
||||||
mve=1;
|
|
||||||
cp3=malloc(m+2);
|
|
||||||
strncpy(cp3,cp1,m);
|
|
||||||
cp3[m]='\0';
|
|
||||||
cp1+=m;
|
|
||||||
/* Now we have the variable name on cp3 */
|
/* Now we have the variable name on cp3 */
|
||||||
if (!strcmp(cp3, "CALLERIDNUM")) {
|
if (!strcmp(cp3, "CALLERIDNUM")) {
|
||||||
char cid[256] = "";
|
char cid[256] = "";
|
||||||
@@ -758,100 +691,145 @@ static void *pbx_substitute_variables(struct ast_channel *c, struct ast_exten *e
|
|||||||
ast_callerid_parse(cid, &name, &num);
|
ast_callerid_parse(cid, &name, &num);
|
||||||
if (num) {
|
if (num) {
|
||||||
ast_shrink_phone_number(num);
|
ast_shrink_phone_number(num);
|
||||||
cp4 = num;
|
*cp4 = num;
|
||||||
} else
|
} else
|
||||||
cp4 = "";
|
*cp4 = "";
|
||||||
break;
|
|
||||||
} else if (!strcmp(cp3, "CALLERIDNAME")) {
|
} else if (!strcmp(cp3, "CALLERIDNAME")) {
|
||||||
char cid[256] = "";
|
char cid[256] = "";
|
||||||
if (c->callerid)
|
if (c->callerid)
|
||||||
strncpy(cid, c->callerid, sizeof(cid) - 1);
|
strncpy(cid, c->callerid, sizeof(cid) - 1);
|
||||||
ast_callerid_parse(cid, &name, &num);
|
ast_callerid_parse(cid, &name, &num);
|
||||||
if (name)
|
if (name)
|
||||||
cp4 = name;
|
*cp4 = name;
|
||||||
else
|
else
|
||||||
cp4 = "";
|
*cp4 = "";
|
||||||
break;
|
|
||||||
} else if (!strcmp(cp3, "CALLERID")) {
|
} else if (!strcmp(cp3, "CALLERID")) {
|
||||||
cp4 = c->callerid;
|
*cp4 = c->callerid;
|
||||||
if (!cp4)
|
if (!(*cp4))
|
||||||
cp4 = "";
|
*cp4 = "";
|
||||||
break;
|
|
||||||
} else if (!strcmp(cp3, "EXTEN")) {
|
} else if (!strcmp(cp3, "EXTEN")) {
|
||||||
cp4 = c->exten;
|
*cp4 = c->exten;
|
||||||
break;
|
|
||||||
} else if (!strncmp(cp3, "EXTEN-", strlen("EXTEN-")) &&
|
} else if (!strncmp(cp3, "EXTEN-", strlen("EXTEN-")) &&
|
||||||
(sscanf(cp3 + strlen("EXTEN-"), "%d", &offset) == 1)) {
|
(sscanf(cp3 + strlen("EXTEN-"), "%d", &offset) == 1)) {
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
offset=0;
|
offset=0;
|
||||||
if (offset > strlen(c->exten))
|
if (offset > strlen(c->exten))
|
||||||
offset = strlen(c->exten);
|
offset = strlen(c->exten);
|
||||||
cp4 = c->exten + offset;
|
*cp4 = c->exten + offset;
|
||||||
} else if (!strcmp(cp3, "RDNIS")) {
|
} else if (!strcmp(cp3, "RDNIS")) {
|
||||||
cp4 = c->rdnis;
|
*cp4 = c->rdnis;
|
||||||
if (!cp4)
|
if (!(*cp4))
|
||||||
cp4 = "";
|
*cp4 = "";
|
||||||
break;
|
|
||||||
} else if (!strcmp(cp3, "CONTEXT")) {
|
} else if (!strcmp(cp3, "CONTEXT")) {
|
||||||
cp4 = c->context;
|
*cp4 = c->context;
|
||||||
break;
|
|
||||||
} else if (!strcmp(cp3, "PRIORITY")) {
|
} else if (!strcmp(cp3, "PRIORITY")) {
|
||||||
snprintf(pri, sizeof(pri), "%d", c->priority);
|
snprintf(pri, sizeof(pri), "%d", c->priority);
|
||||||
cp4 = pri;
|
*cp4 = pri;
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
AST_LIST_TRAVERSE(headp,variables,entries) {
|
AST_LIST_TRAVERSE(headp,variables,entries) {
|
||||||
// ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",cp3,ast_var_name(variables));
|
// ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",cp3,ast_var_name(variables));
|
||||||
if (strncasecmp(ast_var_name(variables),cp3,m)==0) {
|
if (strncasecmp(ast_var_name(variables),cp3,strlen(cp3))==0)
|
||||||
cp4=ast_var_value(variables);
|
*cp4=ast_var_value(variables);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!cp4) {
|
if (!(*cp4)) {
|
||||||
/* Try globals */
|
/* Try globals */
|
||||||
AST_LIST_TRAVERSE(&globals,variables,entries) {
|
AST_LIST_TRAVERSE(&globals,variables,entries) {
|
||||||
// ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",cp3,ast_var_name(variables));
|
// ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",cp3,ast_var_name(variables));
|
||||||
if (strncasecmp(ast_var_name(variables),cp3,m)==0) {
|
if (strncasecmp(ast_var_name(variables),cp3,strlen(cp3))==0)
|
||||||
cp4=ast_var_value(variables);
|
*cp4=ast_var_value(variables);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(cp3);
|
}
|
||||||
break;
|
|
||||||
default :
|
static void pbx_substitute_variables_helper(struct ast_channel *c,char *cp1,char **ecp2)
|
||||||
if (dolsign==1) {
|
{
|
||||||
strncat((char *)cp2,"$",1);
|
char *cp4,*cp2;
|
||||||
}
|
char *tmp,*wherearewe,*finish;
|
||||||
if (quoted==1) {
|
int length;
|
||||||
quoted=0;
|
|
||||||
}
|
wherearewe=tmp=cp1;
|
||||||
mve=0;
|
cp2=*ecp2;
|
||||||
dolsign=0;
|
*cp2='\0';
|
||||||
docopy=1;
|
do {
|
||||||
break;
|
if (!(*wherearewe)) break;
|
||||||
}
|
if ((tmp=strstr(wherearewe,"${"))) {
|
||||||
if (cp1!='\0') {
|
length=(int)(tmp-wherearewe);
|
||||||
if (mve==0) {
|
strncat(cp2,wherearewe,length);
|
||||||
if (docopy==1) {
|
wherearewe=tmp;
|
||||||
strncat((char *)cp2,&c1,1);
|
if (!strncmp(tmp+2,"${",2)) {
|
||||||
}
|
char *ltmp,*lval;
|
||||||
} else {
|
ltmp=malloc(sizeof(char)*256);
|
||||||
if (cp4!=NULL) {
|
finish=strchr(tmp+2,'}');
|
||||||
cp2=realloc(cp2,origlen+strlen(cp4)+1);
|
/* get the one before the last closing bracket */
|
||||||
strncat((char *)cp2,cp4,strlen(cp4));
|
do {
|
||||||
origlen += strlen(cp4);
|
if (strlen(finish)<2)
|
||||||
} else {
|
break;
|
||||||
ast_log(LOG_WARNING,"mve!=0 and cp4=NULL, something gone astray\n");
|
if (finish[1]=='}' && finish[2]=='}')
|
||||||
}
|
finish++;
|
||||||
}
|
else break;
|
||||||
}
|
} while (1);
|
||||||
cp4 = NULL;
|
|
||||||
} while (*cp1++!='\0');
|
if (!finish) {
|
||||||
|
ast_log(LOG_WARNING, "Something went wrong with ${VARIABLE}\n");
|
||||||
|
*ecp2="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
length=(int)(finish-tmp-1);
|
||||||
|
wherearewe+=length+3;
|
||||||
|
lval=strndup(tmp+2,length);
|
||||||
|
pbx_substitute_variables_helper(c,lval,<mp);
|
||||||
|
free(lval);
|
||||||
|
pbx_substitute_variables_temp(c,ltmp,&cp4);
|
||||||
|
if (cp4) {
|
||||||
|
length=strlen(cp4);
|
||||||
|
strncat(cp2,cp4,length);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char value[256];
|
||||||
|
finish=strchr(tmp+2,'}');
|
||||||
|
if (!finish) {
|
||||||
|
ast_log(LOG_WARNING, "Something went wrong with ${VARIABLE}\n");
|
||||||
|
*ecp2="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
length=(int)(finish-tmp)-2;
|
||||||
|
wherearewe+=length+3;
|
||||||
|
strncpy(value,tmp+2,length);
|
||||||
|
value[length]='\0';
|
||||||
|
pbx_substitute_variables_temp(c,value,&cp4);
|
||||||
|
if (cp4) {
|
||||||
|
length=strlen(cp4);
|
||||||
|
strncat(cp2,cp4,length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (*wherearewe) {
|
||||||
|
length=strlen(wherearewe);
|
||||||
|
strncat(cp2,wherearewe,length);
|
||||||
|
}
|
||||||
|
strcat(cp2,"\0");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *pbx_substitute_variables(struct ast_channel *c, struct ast_exten *e) {
|
||||||
|
char *cp1,*cp3,*cp4,*cp5;
|
||||||
|
char *cp2;
|
||||||
|
char c1,c2;
|
||||||
|
int m,mve,origlen,quoted,dolsign,docopy;
|
||||||
|
|
||||||
|
/* No variables or expressions in e->data, so why scan it? */
|
||||||
|
if (!strstr(e->data,"${") && !strstr(e->data,"$[")) {
|
||||||
|
return strndup(e->data,strlen(e->data)+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cp1=e->data;
|
||||||
|
cp2=malloc(sizeof(char)*256);
|
||||||
|
pbx_substitute_variables_helper(c,cp1,(char **)&cp2);
|
||||||
|
|
||||||
/* Second stage, expression evaluation */
|
/* Second stage, expression evaluation */
|
||||||
|
|
||||||
if ((strstr(cp2,"$[")==NULL)) {
|
if ((strstr(cp2,"$[")==NULL)) {
|
||||||
/* No expressions in cp2, return it */
|
/* No expressions in cp2, return it */
|
||||||
return(cp2);
|
return(cp2);
|
||||||
|
|||||||
Reference in New Issue
Block a user