[asterisk-commits] kpfleming: branch kpfleming/agi_multiple-api-fix r157230 - in /team/kpfleming...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Nov 16 00:48:50 CST 2008


Author: kpfleming
Date: Sun Nov 16 00:48:49 2008
New Revision: 157230

URL: http://svn.digium.com/view/asterisk?view=rev&rev=157230
Log:
correct broken logic in ast_agi_register_multiple

clean up and document ast_agi_fdprintf (now ast_agi_send)


Modified:
    team/kpfleming/agi_multiple-api-fix/apps/app_stack.c
    team/kpfleming/agi_multiple-api-fix/include/asterisk/agi.h
    team/kpfleming/agi_multiple-api-fix/res/res_agi.c

Modified: team/kpfleming/agi_multiple-api-fix/apps/app_stack.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/agi_multiple-api-fix/apps/app_stack.c?view=diff&rev=157230&r1=157229&r2=157230
==============================================================================
--- team/kpfleming/agi_multiple-api-fix/apps/app_stack.c (original)
+++ team/kpfleming/agi_multiple-api-fix/apps/app_stack.c Sun Nov 16 00:48:49 2008
@@ -491,11 +491,11 @@
 		/* Lookup the priority label */
 		if ((priority = ast_findlabel_extension(chan, argv[1], argv[2], argv[3], chan->cid.cid_num)) < 0) {
 			ast_log(LOG_ERROR, "Priority '%s' not found in '%s@%s'\n", argv[3], argv[2], argv[1]);
-			ast_agi_fdprintf(chan, agi->fd, "200 result=-1 Gosub label not found\n");
+			ast_agi_send(agi->fd, chan, "200 result=-1 Gosub label not found\n");
 			return RESULT_FAILURE;
 		}
 	} else if (!ast_exists_extension(chan, argv[1], argv[2], priority, chan->cid.cid_num)) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=-1 Gosub label not found\n");
+		ast_agi_send(agi->fd, chan, "200 result=-1 Gosub label not found\n");
 		return RESULT_FAILURE;
 	}
 
@@ -506,7 +506,7 @@
 
 	if (!(theapp = pbx_findapp("Gosub"))) {
 		ast_log(LOG_ERROR, "Gosub() cannot be found in the list of loaded applications\n");
-		ast_agi_fdprintf(chan, agi->fd, "503 result=-2 Gosub is not loaded\n");
+		ast_agi_send(agi->fd, chan, "503 result=-2 Gosub is not loaded\n");
 		return RESULT_FAILURE;
 	}
 
@@ -540,19 +540,19 @@
 			struct ast_pbx *pbx = chan->pbx;
 			/* Suppress warning about PBX already existing */
 			chan->pbx = NULL;
-			ast_agi_fdprintf(chan, agi->fd, "100 result=0 Trying...\n");
+			ast_agi_send(agi->fd, chan, "100 result=0 Trying...\n");
 			ast_pbx_run(chan);
-			ast_agi_fdprintf(chan, agi->fd, "200 result=0 Gosub complete\n");
+			ast_agi_send(agi->fd, chan, "200 result=0 Gosub complete\n");
 			if (chan->pbx) {
 				ast_free(chan->pbx);
 			}
 			chan->pbx = pbx;
 		} else {
-			ast_agi_fdprintf(chan, agi->fd, "200 result=%d Gosub failed\n", res);
+			ast_agi_send(agi->fd, chan, "200 result=%d Gosub failed\n", res);
 		}
 		ast_free(gosub_args);
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "503 result=-2 Memory allocation failure\n");
+		ast_agi_send(agi->fd, chan, "503 result=-2 Memory allocation failure\n");
 		return RESULT_FAILURE;
 	}
 

Modified: team/kpfleming/agi_multiple-api-fix/include/asterisk/agi.h
URL: http://svn.digium.com/view/asterisk/team/kpfleming/agi_multiple-api-fix/include/asterisk/agi.h?view=diff&rev=157230&r1=157229&r2=157230
==============================================================================
--- team/kpfleming/agi_multiple-api-fix/include/asterisk/agi.h (original)
+++ team/kpfleming/agi_multiple-api-fix/include/asterisk/agi.h Sun Nov 16 00:48:49 2008
@@ -66,7 +66,18 @@
 #define AGI_WEAK
 #endif
 
-int AGI_WEAK ast_agi_fdprintf(struct ast_channel *chan, int fd, char *fmt, ...);
+/*!
+ * \brief
+ *
+ * Sends a string of text to an application connected via AGI.
+ *
+ * \param fd The file descriptor for the AGI session (from struct agi_state)
+ * \param chan Pointer to an associated Asterisk channel, if any
+ * \param fmt printf-style format string
+ * \return 0 for success, -1 for failure
+ *
+ */
+int AGI_WEAK ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...) __attribute__((format(printf, 3, 4)));
 int AGI_WEAK ast_agi_register(struct ast_module *mod, agi_command *cmd);
 int AGI_WEAK ast_agi_unregister(struct ast_module *mod, agi_command *cmd);
 
@@ -85,7 +96,7 @@
  * will be unregistered. In other words, this function registers all the provided commands, or none
  * of them.
  */
-int AGI_WEAK ast_agi_register_multiple(struct ast_module *mod, agi_command *cmd, unsigned int len);
+int AGI_WEAK ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
 
 /*!
  * \brief
@@ -101,7 +112,7 @@
  * \note If any command fails to unregister, this function will continue to unregister the
  * remaining commands in the array; it will not reregister the already-unregistered commands.
  */
-int AGI_WEAK ast_agi_unregister_multiple(struct ast_module *mod, agi_command *cmd, unsigned int len);
+int AGI_WEAK ast_agi_unregister_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/kpfleming/agi_multiple-api-fix/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/agi_multiple-api-fix/res/res_agi.c?view=diff&rev=157230&r1=157229&r2=157230
==============================================================================
--- team/kpfleming/agi_multiple-api-fix/res/res_agi.c (original)
+++ team/kpfleming/agi_multiple-api-fix/res/res_agi.c Sun Nov 16 00:48:49 2008
@@ -304,7 +304,7 @@
 AST_THREADSTORAGE(agi_buf);
 #define AGI_BUF_INITSIZE 256
 
-int ast_agi_fdprintf(struct ast_channel *chan, int fd, char *fmt, ...)
+int ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...)
 {
 	int res = 0;
 	va_list ap;
@@ -771,7 +771,7 @@
 		}
 	}
 
-	if (ast_agi_fdprintf(NULL, s, "agi_network: yes\n") < 0) {
+	if (ast_agi_send(s, NULL, "agi_network: yes\n") < 0) {
 		if (errno != EINTR) {
 			ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
 			close(s);
@@ -782,7 +782,7 @@
 	/* If we have a script parameter, relay it to the fastagi server */
 	/* Script parameters take the form of: AGI(agi://my.example.com/?extension=${EXTEN}) */
 	if (!ast_strlen_zero(script))
-		ast_agi_fdprintf(NULL, s, "agi_network_script: %s\n", script);
+		ast_agi_send(s, NULL, "agi_network_script: %s\n", script);
 
 	ast_debug(4, "Wow, connected!\n");
 	fds[0] = s;
@@ -911,40 +911,40 @@
 
 	/* Print initial environment, with agi_request always being the first
 	   thing */
-	ast_agi_fdprintf(chan, fd, "agi_request: %s\n", request);
-	ast_agi_fdprintf(chan, fd, "agi_channel: %s\n", chan->name);
-	ast_agi_fdprintf(chan, fd, "agi_language: %s\n", chan->language);
-	ast_agi_fdprintf(chan, fd, "agi_type: %s\n", chan->tech->type);
-	ast_agi_fdprintf(chan, fd, "agi_uniqueid: %s\n", chan->uniqueid);
-	ast_agi_fdprintf(chan, fd, "agi_version: %s\n", ast_get_version());
+	ast_agi_send(fd, chan, "agi_request: %s\n", request);
+	ast_agi_send(fd, chan, "agi_channel: %s\n", chan->name);
+	ast_agi_send(fd, chan, "agi_language: %s\n", chan->language);
+	ast_agi_send(fd, chan, "agi_type: %s\n", chan->tech->type);
+	ast_agi_send(fd, chan, "agi_uniqueid: %s\n", chan->uniqueid);
+	ast_agi_send(fd, chan, "agi_version: %s\n", ast_get_version());
 
 	/* ANI/DNIS */
-	ast_agi_fdprintf(chan, fd, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
-	ast_agi_fdprintf(chan, fd, "agi_calleridname: %s\n", S_OR(chan->cid.cid_name, "unknown"));
-	ast_agi_fdprintf(chan, fd, "agi_callingpres: %d\n", chan->cid.cid_pres);
-	ast_agi_fdprintf(chan, fd, "agi_callingani2: %d\n", chan->cid.cid_ani2);
-	ast_agi_fdprintf(chan, fd, "agi_callington: %d\n", chan->cid.cid_ton);
-	ast_agi_fdprintf(chan, fd, "agi_callingtns: %d\n", chan->cid.cid_tns);
-	ast_agi_fdprintf(chan, fd, "agi_dnid: %s\n", S_OR(chan->cid.cid_dnid, "unknown"));
-	ast_agi_fdprintf(chan, fd, "agi_rdnis: %s\n", S_OR(chan->cid.cid_rdnis, "unknown"));
+	ast_agi_send(fd, chan, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
+	ast_agi_send(fd, chan, "agi_calleridname: %s\n", S_OR(chan->cid.cid_name, "unknown"));
+	ast_agi_send(fd, chan, "agi_callingpres: %d\n", chan->cid.cid_pres);
+	ast_agi_send(fd, chan, "agi_callingani2: %d\n", chan->cid.cid_ani2);
+	ast_agi_send(fd, chan, "agi_callington: %d\n", chan->cid.cid_ton);
+	ast_agi_send(fd, chan, "agi_callingtns: %d\n", chan->cid.cid_tns);
+	ast_agi_send(fd, chan, "agi_dnid: %s\n", S_OR(chan->cid.cid_dnid, "unknown"));
+	ast_agi_send(fd, chan, "agi_rdnis: %s\n", S_OR(chan->cid.cid_rdnis, "unknown"));
 
 	/* Context information */
-	ast_agi_fdprintf(chan, fd, "agi_context: %s\n", chan->context);
-	ast_agi_fdprintf(chan, fd, "agi_extension: %s\n", chan->exten);
-	ast_agi_fdprintf(chan, fd, "agi_priority: %d\n", chan->priority);
-	ast_agi_fdprintf(chan, fd, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
+	ast_agi_send(fd, chan, "agi_context: %s\n", chan->context);
+	ast_agi_send(fd, chan, "agi_extension: %s\n", chan->exten);
+	ast_agi_send(fd, chan, "agi_priority: %d\n", chan->priority);
+	ast_agi_send(fd, chan, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
 
 	/* User information */
-	ast_agi_fdprintf(chan, fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
-	ast_agi_fdprintf(chan, fd, "agi_threadid: %ld\n", (long)pthread_self());
+	ast_agi_send(fd, chan, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : "");
+	ast_agi_send(fd, chan, "agi_threadid: %ld\n", (long)pthread_self());
 
 	/* Send any parameters to the fastagi server that have been passed via the agi application */
 	/* Agi application paramaters take the form of: AGI(/path/to/example/script|${EXTEN}) */
 	for(count = 1; count < argc; count++)
-		ast_agi_fdprintf(chan, fd, "agi_arg_%d: %s\n", count, argv[count]);
+		ast_agi_send(fd, chan, "agi_arg_%d: %s\n", count, argv[count]);
 
 	/* End with empty return */
-	ast_agi_fdprintf(chan, fd, "\n");
+	ast_agi_send(fd, chan, "\n");
 }
 
 static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
@@ -955,7 +955,7 @@
 	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -968,7 +968,7 @@
 	if (sscanf(argv[3], "%d", &to) != 1)
 		return RESULT_SHOWUSAGE;
 	res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -987,7 +987,7 @@
 	   parsing, then here, add a newline at the end of the string
 	   before sending it to ast_sendtext --DUDE */
 	res = ast_sendtext(chan, argv[2]);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1000,14 +1000,14 @@
 
 	res = ast_recvchar(chan,atoi(argv[2]));
 	if (res == 0) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d (timeout)\n", res);
+		ast_agi_send(agi->fd, chan, "200 result=%d (timeout)\n", res);
 		return RESULT_SUCCESS;
 	}
 	if (res > 0) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+		ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 		return RESULT_SUCCESS;
 	}
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d (hangup)\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d (hangup)\n", res);
 	return RESULT_FAILURE;
 }
 
@@ -1020,10 +1020,10 @@
 
 	buf = ast_recvtext(chan, atoi(argv[2]));
 	if (buf) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", buf);
+		ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", buf);
 		ast_free(buf);
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+		ast_agi_send(agi->fd, chan, "200 result=-1\n");
 	}
 	return RESULT_SUCCESS;
 }
@@ -1048,9 +1048,9 @@
 	}
 	res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
 	if (res != RESULT_SUCCESS) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 	}
 	return RESULT_SUCCESS;
 }
@@ -1067,7 +1067,7 @@
 	if (!ast_check_hangup(chan)) {
 		res = 0;
 	}
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1102,7 +1102,7 @@
 
 	res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, suspend, NULL, skipms, NULL);
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
@@ -1124,7 +1124,7 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
+		ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", 0, sample_offset);
 		return RESULT_SUCCESS;
 	}
 
@@ -1152,7 +1152,7 @@
 		/* Stop this command, don't print a result line, as there is a new command */
 		return RESULT_SUCCESS;
 	}
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
+	ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1179,7 +1179,7 @@
 	}
 
 	if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
+		ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", 0, sample_offset);
 		ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
 		return RESULT_SUCCESS;
 	}
@@ -1217,7 +1217,7 @@
 			res=0;
 	}
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d endpos=%ld\n", res, sample_offset);
+	ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1237,7 +1237,7 @@
 	res = ast_say_number_full(chan, num, argv[3], chan->language, argc > 4 ? argv[4] : NULL, agi->audio, agi->ctrl);
 	if (res == 1)
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1253,7 +1253,7 @@
 	res = ast_say_digit_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
 	if (res == 1) /* New command */
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1267,7 +1267,7 @@
 	res = ast_say_character_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
 	if (res == 1) /* New command */
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1282,7 +1282,7 @@
 	res = ast_say_date(chan, num, argv[3], chan->language);
 	if (res == 1)
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1297,7 +1297,7 @@
 	res = ast_say_time(chan, num, argv[3], chan->language);
 	if (res == 1)
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1331,7 +1331,7 @@
 	if (res == 1)
 		return RESULT_SUCCESS;
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1345,7 +1345,7 @@
 	res = ast_say_phonetic_str_full(chan, argv[2], argv[3], chan->language, agi->audio, agi->ctrl);
 	if (res == 1) /* New command */
 		return RESULT_SUCCESS;
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
@@ -1368,11 +1368,11 @@
 	if (res == 2)			/* New command */
 		return RESULT_SUCCESS;
 	else if (res == 1)
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%s (timeout)\n", data);
+		ast_agi_send(agi->fd, chan, "200 result=%s (timeout)\n", data);
 	else if (res < 0 )
-		ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+		ast_agi_send(agi->fd, chan, "200 result=-1\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%s\n", data);
+		ast_agi_send(agi->fd, chan, "200 result=%s\n", data);
 	return RESULT_SUCCESS;
 }
 
@@ -1382,7 +1382,7 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	ast_copy_string(chan->context, argv[2], sizeof(chan->context));
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1391,7 +1391,7 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	ast_copy_string(chan->exten, argv[2], sizeof(chan->exten));
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1408,7 +1408,7 @@
 	}
 
 	ast_explicit_goto(chan, NULL, NULL, pri);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1483,12 +1483,12 @@
 	if (!res)
 		res = ast_waitstream(chan, argv[4]);
 	if (res) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
+		ast_agi_send(agi->fd, chan, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
 	} else {
 		fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, AST_FILE_MODE);
 		if (!fs) {
 			res = -1;
-			ast_agi_fdprintf(chan, agi->fd, "200 result=%d (writefile)\n", res);
+			ast_agi_send(agi->fd, chan, "200 result=%d (writefile)\n", res);
 			if (sildet)
 				ast_dsp_free(sildet);
 			return RESULT_FAILURE;
@@ -1508,14 +1508,14 @@
 			res = ast_waitfor(chan, -1);
 			if (res < 0) {
 				ast_closestream(fs);
-				ast_agi_fdprintf(chan, agi->fd, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
+				ast_agi_send(agi->fd, chan, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
 				if (sildet)
 					ast_dsp_free(sildet);
 				return RESULT_FAILURE;
 			}
 			f = ast_read(chan);
 			if (!f) {
-				ast_agi_fdprintf(chan, agi->fd, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
+				ast_agi_send(agi->fd, chan, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
 				ast_closestream(fs);
 				if (sildet)
 					ast_dsp_free(sildet);
@@ -1530,7 +1530,7 @@
 					ast_stream_rewind(fs, 200);
 					ast_truncstream(fs);
 					sample_offset = ast_tellstream(fs);
-					ast_agi_fdprintf(chan, agi->fd, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
+					ast_agi_send(agi->fd, chan, "200 result=%d (dtmf) endpos=%ld\n", f->subclass, sample_offset);
 					ast_closestream(fs);
 					ast_frfree(f);
 					if (sildet)
@@ -1575,7 +1575,7 @@
 			ast_truncstream(fs);
 			sample_offset = ast_tellstream(fs);
 		}
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
+		ast_agi_send(agi->fd, chan, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
 		ast_closestream(fs);
 	}
 
@@ -1605,7 +1605,7 @@
 		whentohangup.tv_usec = (timeout - whentohangup.tv_sec) * 1000000.0;
 	}
 	ast_channel_setwhentohangup_tv(chan, whentohangup);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1616,7 +1616,7 @@
 	if (argc == 1) {
 		/* no argument: hangup the current channel */
 		ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 		return RESULT_SUCCESS;
 	} else if (argc == 2) {
 		/* one argument: look for info on the specified channel */
@@ -1624,12 +1624,12 @@
 		if (c) {
 			/* we have a matching channel */
 			ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT);
-			ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+			ast_agi_send(agi->fd, chan, "200 result=1\n");
 			ast_channel_unlock(c);
 			return RESULT_SUCCESS;
 		}
 		/* if we get this far no channel name matched the argument given */
-		ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+		ast_agi_send(agi->fd, chan, "200 result=-1\n");
 		return RESULT_SUCCESS;
 	} else {
 		return RESULT_SHOWUSAGE;
@@ -1671,7 +1671,7 @@
 		ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
 		res = -2;
 	}
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", res);
+	ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
 
 	/* Even though this is wrong, users are depending upon this result. */
 	return res;
@@ -1694,7 +1694,7 @@
 		ast_set_callerid(chan, l, n, NULL);
 	}
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+	ast_agi_send(agi->fd, chan, "200 result=1\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1703,18 +1703,18 @@
 	struct ast_channel *c;
 	if (argc == 2) {
 		/* no argument: supply info on the current channel */
-		ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", chan->_state);
+		ast_agi_send(agi->fd, chan, "200 result=%d\n", chan->_state);
 		return RESULT_SUCCESS;
 	} else if (argc == 3) {
 		/* one argument: look for info on the specified channel */
 		c = ast_get_channel_by_name_locked(argv[2]);
 		if (c) {
-			ast_agi_fdprintf(chan, agi->fd, "200 result=%d\n", c->_state);
+			ast_agi_send(agi->fd, chan, "200 result=%d\n", c->_state);
 			ast_channel_unlock(c);
 			return RESULT_SUCCESS;
 		}
 		/* if we get this far no channel name matched the argument given */
-		ast_agi_fdprintf(chan, agi->fd, "200 result=-1\n");
+		ast_agi_send(agi->fd, chan, "200 result=-1\n");
 		return RESULT_SUCCESS;
 	} else {
 		return RESULT_SHOWUSAGE;
@@ -1726,7 +1726,7 @@
 	if (argv[3])
 		pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+	ast_agi_send(agi->fd, chan, "200 result=1\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1746,9 +1746,9 @@
 	}
 
 	if (ret)
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", ret);
+		ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ret);
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1767,9 +1767,9 @@
 	}
 	if (chan2) {
 		pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1);
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", tmp);
+		ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", tmp);
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	}
 	if (chan2 && (chan2 != chan))
 		ast_channel_unlock(chan2);
@@ -1788,7 +1788,7 @@
 
 	ast_verb(level, "%s: %s\n", chan->data, argv[1]);
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+	ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1802,9 +1802,9 @@
 		return RESULT_SHOWUSAGE;
 	res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
 	if (res)
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s)\n", tmp);
+		ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", tmp);
 
 	return RESULT_SUCCESS;
 }
@@ -1816,7 +1816,7 @@
 	if (argc != 5)
 		return RESULT_SHOWUSAGE;
 	res = ast_db_put(argv[2], argv[3], argv[4]);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+	ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
 	return RESULT_SUCCESS;
 }
 
@@ -1827,7 +1827,7 @@
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	res = ast_db_del(argv[2], argv[3]);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+	ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
 	return RESULT_SUCCESS;
 }
 
@@ -1842,7 +1842,7 @@
 	else
 		res = ast_db_deltree(argv[2], NULL);
 
-	ast_agi_fdprintf(chan, agi->fd, "200 result=%c\n", res ? '0' : '1');
+	ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
 	return RESULT_SUCCESS;
 }
 
@@ -1877,7 +1877,7 @@
 
 static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, char *argv[])
 {
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1887,7 +1887,7 @@
 		ast_moh_start(chan, argc > 3 ? argv[3] : NULL, NULL);
 	else if (!strncasecmp(argv[2], "off", 3))
 		ast_moh_stop(chan);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return RESULT_SUCCESS;
 }
 
@@ -1895,14 +1895,14 @@
 {
 	/* If a structure already exists, return an error */
         if (agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	if ((agi->speech = ast_speech_new(argv[2], AST_FORMAT_SLINEAR)))
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1915,12 +1915,12 @@
 
 	/* Check to make sure speech structure exists */
 	if (!agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	ast_speech_change(agi->speech, argv[2], argv[3]);
-	ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+	ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1930,9 +1930,9 @@
 	if (agi->speech) {
 		ast_speech_destroy(agi->speech);
 		agi->speech = NULL;
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	}
 
 	return RESULT_SUCCESS;
@@ -1944,14 +1944,14 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	if (ast_speech_grammar_load(agi->speech, argv[3], argv[4]))
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1962,14 +1962,14 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	if (ast_speech_grammar_unload(agi->speech, argv[3]))
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1980,14 +1980,14 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	if (ast_speech_grammar_activate(agi->speech, argv[3]))
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -1998,14 +1998,14 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!agi->speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
 	if (ast_speech_grammar_deactivate(agi->speech, argv[3]))
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	else
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
+		ast_agi_send(agi->fd, chan, "200 result=1\n");
 
 	return RESULT_SUCCESS;
 }
@@ -2045,7 +2045,7 @@
 		return RESULT_SHOWUSAGE;
 
 	if (!speech) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
@@ -2059,7 +2059,7 @@
 	/* We want frames coming in signed linear */
 	old_read_format = chan->readformat;
 	if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
 
@@ -2164,13 +2164,13 @@
 			i++;
 		}
                 /* Print out */
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
+		ast_agi_send(agi->fd, chan, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
 	} else if (!strcasecmp(reason, "dtmf")) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
+		ast_agi_send(agi->fd, chan, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
 	} else if (!strcasecmp(reason, "hangup") || !strcasecmp(reason, "timeout")) {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
+		ast_agi_send(agi->fd, chan, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "200 result=0 endpos=%ld\n", current_offset);
+		ast_agi_send(agi->fd, chan, "200 result=0 endpos=%ld\n", current_offset);
 	}
 
 	return RESULT_SUCCESS;
@@ -2178,7 +2178,7 @@
 
 static int handle_asyncagi_break(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	ast_agi_fdprintf(chan, agi->fd, "200 result=0\n");
+	ast_agi_send(agi->fd, chan, "200 result=0\n");
 	return AST_PBX_KEEPALIVE;
 }
 
@@ -2545,16 +2545,16 @@
 	return unregistered;
 }
 
-int ast_agi_register_multiple(struct ast_module *mod, agi_command *cmd, unsigned int len)
-{
-	unsigned int i;
+int ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
+{
+	unsigned int i, x = 0;
 
 	for (i = 0; i < len; i++) {
 		if (ast_agi_register(mod, cmd + i) != 1) {
 			/* registration failed, unregister everything
 			   that had been registered up to that point
 			*/
-			for (; i > 0; i--) {
+			for (; x > 0; x--) {
 				/* we are intentionally ignoring the
 				   result of ast_agi_unregister() here,
 				   but it should be safe to do so since
@@ -2563,16 +2563,18 @@
 				   to fail is if the command is not
 				   registered
 				*/
-				(void) ast_agi_unregister(mod, cmd + i);
+				(void) ast_agi_unregister(mod, cmd + x - 1);
 				return -1;
 			}
+		} else {
+			x++;
 		}
 	}
 
 	return 0;
 }
 
-int ast_agi_unregister_multiple(struct ast_module *mod, agi_command *cmd, unsigned int len)
+int ast_agi_unregister_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
 {
 	unsigned int i;
 	int res = 0;
@@ -2727,9 +2729,9 @@
 				"Result: %s\r\n", chan->name, command_id, ami_cmd, resultcode, ami_res);
 		switch(res) {
 		case RESULT_SHOWUSAGE:
-			ast_agi_fdprintf(chan, agi->fd, "520-Invalid command syntax.  Proper usage follows:\n");
-			ast_agi_fdprintf(chan, agi->fd, c->usage);
-			ast_agi_fdprintf(chan, agi->fd, "520 End of proper usage.\n");
+			ast_agi_send(agi->fd, chan, "520-Invalid command syntax.  Proper usage follows:\n");
+			ast_agi_send(agi->fd, NULL, "%s", c->usage);
+			ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
 			break;
 		case AST_PBX_KEEPALIVE:
 			/* We've been asked to keep alive, so do so */
@@ -2741,7 +2743,7 @@
 			return -1;
 		}
 	} else if ((c = find_command(argv, 0))) {
-		ast_agi_fdprintf(chan, agi->fd, "511 Command Not Permitted on a dead channel\n");
+		ast_agi_send(agi->fd, chan, "511 Command Not Permitted on a dead channel\n");
 		manager_event(EVENT_FLAG_CALL, "AGIExec",
 				"SubEvent: End\r\n"
 				"Channel: %s\r\n"
@@ -2750,7 +2752,7 @@
 				"ResultCode: 511\r\n"
 				"Result: Command not permitted on a dead channel\r\n", chan->name, command_id, ami_cmd);
 	} else {
-		ast_agi_fdprintf(chan, agi->fd, "510 Invalid or unknown command\n");
+		ast_agi_send(agi->fd, chan, "510 Invalid or unknown command\n");
 		manager_event(EVENT_FLAG_CALL, "AGIExec",
 				"SubEvent: End\r\n"
 				"Channel: %s\r\n"




More information about the asterisk-commits mailing list