aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_festival.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-19 18:19:02 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-19 18:19:02 +0000
commit58818426d60d583c4becc6a99b398cbac1b7b12f (patch)
tree5fee3540f8d72d45cd1b2e5bf15e5860581dd4f8 /apps/app_festival.c
parenta4d6ea67a7536e2cb2337527357ce6d3db8639f3 (diff)
Massive cleanups to applications for LOCAL_USER handling and some other things.
In general, LOCAL_USER_ADD/REMOVE should be the first/last thing called in an application. An exception is if there is some *fast* setup code that might halt the execution of the application, such as checking to see if an argument exists. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6832 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_festival.c')
-rwxr-xr-xapps/app_festival.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/apps/app_festival.c b/apps/app_festival.c
index 59b0c5be5..56691ff3d 100755
--- a/apps/app_festival.c
+++ b/apps/app_festival.c
@@ -292,13 +292,21 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
int fdesc = -1;
char buffer[16384];
int seekpos = 0;
- char data[256] = "";
+ char *data;
char *intstr;
-
struct ast_config *cfg;
+
+ if (!vdata || ast_strlen_zero(vdata)) {
+ ast_log(LOG_WARNING, "festival requires an argument (text)\n");
+ return -1;
+ }
+
+ LOCAL_USER_ADD(u);
+
cfg = ast_config_load(FESTIVAL_CONFIG);
if (!cfg) {
ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
+ LOCAL_USER_REMOVE(u);
return -1;
}
if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
@@ -320,19 +328,23 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n";
}
- if (!vdata || ast_strlen_zero(vdata)) {
- ast_log(LOG_WARNING, "festival requires an argument (text)\n");
+
+ data = ast_strdupa(vdata);
+ if (!data) {
+ ast_log(LOG_ERROR, "Out of memery\n");
ast_config_destroy(cfg);
+ LOCAL_USER_REMOVE(u);
return -1;
}
- strncpy(data, vdata, sizeof(data) - 1);
- if ((intstr = strchr(data, '|'))) {
+
+ intstr = strchr(data, '|');
+ if (intstr) {
*intstr = '\0';
intstr++;
if (!strcasecmp(intstr, "any"))
intstr = AST_DIGIT_ANY;
}
- LOCAL_USER_ADD(u);
+
ast_log(LOG_DEBUG, "Text passed to festival server : %s\n",(char *)data);
/* Connect to local festival server */
@@ -341,6 +353,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
if (fd < 0) {
ast_log(LOG_WARNING,"festival_client: can't get socket\n");
ast_config_destroy(cfg);
+ LOCAL_USER_REMOVE(u);
return -1;
}
memset(&serv_addr, 0, sizeof(serv_addr));
@@ -350,6 +363,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
if (serverhost == (struct hostent *)0) {
ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n");
ast_config_destroy(cfg);
+ LOCAL_USER_REMOVE(u);
return -1;
}
memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length);
@@ -360,6 +374,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) {
ast_log(LOG_WARNING,"festival_client: connect to server failed\n");
ast_config_destroy(cfg);
+ LOCAL_USER_REMOVE(u);
return -1;
}
@@ -463,7 +478,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata)
} while (strcmp(ack,"OK\n") != 0);
close(fd);
ast_config_destroy(cfg);
- LOCAL_USER_REMOVE(u);
+ LOCAL_USER_REMOVE(u);
return res;
}