Index: main/manager.c
===================================================================
--- main/manager.c	(revision 257809)
+++ main/manager.c	(working copy)
@@ -3334,15 +3334,21 @@
 	int timeout;
 	format_t format;				/*!< Codecs used for a call */
 	char app[AST_MAX_APP];
+	char apptext[AST_MAX_EXTENSION];
 	char appdata[AST_MAX_EXTENSION];
+	char appdatatext[AST_MAX_EXTENSION];
 	char cid_name[AST_MAX_EXTENSION];
 	char cid_num[AST_MAX_EXTENSION];
 	char context[AST_MAX_CONTEXT];
+	char contexttext[AST_MAX_EXTENSION];
 	char exten[AST_MAX_EXTENSION];
+	char extentext[AST_MAX_EXTENSION];
 	char idtext[AST_MAX_EXTENSION];
 	char account[AST_MAX_ACCOUNT_CODE];
 	int priority;
+	char pritext[AST_MAX_EXTENSION];
 	struct ast_variable *vars;
+	struct mansession *msession;
 };
 
 static void *fast_originate(void *data)
@@ -3350,7 +3356,7 @@
 	struct fast_originate_helper *in = data;
 	int res;
 	int reason = 0;
-	struct ast_channel *chan = NULL, *chans[1];
+	struct ast_channel *chan = NULL;
 	char requested_channel[AST_CHANNEL_NAME];
 
 	if (!ast_strlen_zero(in->app)) {
@@ -3358,35 +3364,62 @@
 			S_OR(in->cid_num, NULL),
 			S_OR(in->cid_name, NULL),
 			in->vars, in->account, &chan);
+
+		snprintf(in->apptext, sizeof(in->apptext), "Application: %s\r\n", in->app);
+
+		if (!ast_strlen_zero(in->appdata)) {
+			snprintf(in->appdatatext, sizeof(in->appdatatext), "Data: %s\r\n", in->appdata);
+		}
+
 	} else {
 		res = ast_pbx_outgoing_exten(in->tech, in->format, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1,
 			S_OR(in->cid_num, NULL),
 			S_OR(in->cid_name, NULL),
 			in->vars, in->account, &chan);
+
+		snprintf(in->contexttext, sizeof(in->contexttext), "Context: %s\r\n", in->context);
+		snprintf(in->extentext, sizeof(in->extentext), "Exten: %s\r\n", in->exten);
+		snprintf(in->pritext, sizeof(in->pritext), "Priority: %d\r\n", in->priority);
 	}
 
 	if (!chan) {
 		snprintf(requested_channel, AST_CHANNEL_NAME, "%s/%s", in->tech, in->data);
 	}
-	/* Tell the manager what happened with the channel */
-	chans[0] = chan;
-	ast_manager_event_multichan(EVENT_FLAG_CALL, "OriginateResponse", chan ? 1 : 0, chans,
-		"%s%s"
-		"Response: %s\r\n"
-		"Channel: %s\r\n"
-		"Context: %s\r\n"
-		"Exten: %s\r\n"
-		"Reason: %d\r\n"
-		"Uniqueid: %s\r\n"
-		"CallerIDNum: %s\r\n"
-		"CallerIDName: %s\r\n",
-		in->idtext, ast_strlen_zero(in->idtext) ? "" : "\r\n", res ? "Failure" : "Success",
-		chan ? chan->name : requested_channel, in->context, in->exten, reason,
-		chan ? chan->uniqueid : "<null>",
-		S_OR(in->cid_num, "<unknown>"),
-		S_OR(in->cid_name, "<unknown>")
+
+	astman_append(in->msession, "Event: OriginateResponse\r\n"
+			"%s"
+			"Result: %s\r\n"
+			"Channel: %s\r\n"
+			"%s"
+			"%s"
+			"%s"
+			"%s"
+			"%s"
+			"Reason: %d\r\n"
+			"Uniqueid: %s\r\n"
+			"CallerIDNum: %s\r\n"
+			"CallerIDName: %s\r\n"
+			"\r\n",
+			in->idtext,
+			ast_channel_reason2str(reason),
+			chan ? chan->name : requested_channel,
+			in->extentext, in->contexttext, in->pritext,
+			in->apptext, in->appdatatext,
+			reason,
+			chan ? chan->uniqueid : "<null>",
+			S_OR(in->cid_num, "<unknown>"),
+			S_OR(in->cid_name, "<unknown>")
 		);
 
+			/*res ? "Failure" : "Success",*/
+
+
+	astman_append(in->msession, "Event: OriginateComplete\r\n"
+			"%s"
+			"\r\n",
+			in->idtext
+		);
+
 	/* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
 	if (chan) {
 		ast_channel_unlock(chan);
@@ -3406,92 +3439,83 @@
 	const char *account = astman_get_header(m, "Account");
 	const char *app = astman_get_header(m, "Application");
 	const char *appdata = astman_get_header(m, "Data");
-	const char *async = astman_get_header(m, "Async");
 	const char *id = astman_get_header(m, "ActionID");
 	const char *codecs = astman_get_header(m, "Codecs");
 	struct ast_variable *vars = astman_get_variables(m);
-	char *tech, *data;
+	char *tech, *data, *buf;
 	char *l = NULL, *n = NULL;
 	int pi = 0;
-	int res;
+	int res = -1;
 	int to = 30000;
-	int reason = 0;
 	char tmp[256];
 	char tmp2[256];
+	char tmp3[256];
 	format_t format = AST_FORMAT_SLINEAR;
 
 	pthread_t th;
+
 	if (ast_strlen_zero(name)) {
 		astman_send_error(s, m, "Channel not specified");
 		return 0;
 	}
+
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%30d", &pi) != 1)) {
 		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
 			astman_send_error(s, m, "Invalid priority");
 			return 0;
 		}
 	}
+
 	if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%30d", &to) != 1)) {
 		astman_send_error(s, m, "Invalid timeout");
 		return 0;
 	}
+
 	ast_copy_string(tmp, name, sizeof(tmp));
 	tech = tmp;
 	data = strchr(tmp, '/');
+
+	ast_copy_string(tmp3, name, sizeof(tmp3));
+	buf = tmp3;
+
 	if (!data) {
 		astman_send_error(s, m, "Invalid channel");
 		return 0;
+	} else if (!ast_get_channel_tech(strsep(&buf,"/"))) {
+		astman_send_error(s, m, "Bad Technology specified in channel");
+		return 0;
 	}
+
 	*data++ = '\0';
 	ast_copy_string(tmp2, callerid, sizeof(tmp2));
 	ast_callerid_parse(tmp2, &n, &l);
+
 	if (n) {
 		if (ast_strlen_zero(n)) {
 			n = NULL;
 		}
 	}
+
 	if (l) {
 		ast_shrink_phone_number(l);
 		if (ast_strlen_zero(l)) {
 			l = NULL;
 		}
 	}
+
 	if (!ast_strlen_zero(codecs)) {
 		format = 0;
 		ast_parse_allow_disallow(NULL, &format, codecs, 1);
 	}
-	if (ast_true(async)) {
-		struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
-		if (!fast) {
-			res = -1;
-		} else {
-			if (!ast_strlen_zero(id))
-				snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s", id);
-			ast_copy_string(fast->tech, tech, sizeof(fast->tech));
-			ast_copy_string(fast->data, data, sizeof(fast->data));
-			ast_copy_string(fast->app, app, sizeof(fast->app));
-			ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
-			if (l) {
-				ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
-			}
-			if (n) {
-				ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
-			}
-			fast->vars = vars;
-			ast_copy_string(fast->context, context, sizeof(fast->context));
-			ast_copy_string(fast->exten, exten, sizeof(fast->exten));
-			ast_copy_string(fast->account, account, sizeof(fast->account));
-			fast->format = format;
-			fast->timeout = to;
-			fast->priority = pi;
-			if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
-				ast_free(fast);
-				res = -1;
-			} else {
-				res = 0;
-			}
+
+	/* Its an APP */
+	if (!ast_strlen_zero(app)) {
+		/*Does the app exist?*/
+		if (!pbx_findapp(app)) {
+			astman_send_error(s, m, "Invalid or missing Application");
+			return 0;
 		}
-	} else if (!ast_strlen_zero(app)) {
+
 		/* To run the System application (or anything else that goes to shell), you must have the additional System privilege */
 		if (!(s->session->writeperm & EVENT_FLAG_SYSTEM)
 			&& (
@@ -3507,20 +3531,62 @@
 			astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have.");
 			return 0;
 		}
-		res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
+
+	} else if (exten && context && pi) {
+		/* Check if extension,context, prio, exists*/
+		if (!ast_exists_extension(NULL, context, exten, pi, NULL)) {
+			astman_send_error(s, m, "Invalid or missing 'Exten', 'Context', or 'Priority'");
+			return 0;
+		}
 	} else {
-		if (exten && context && pi) {
-			res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
+		astman_send_error(s, m, "Originate requires 'Exten' and 'Context' and 'Priority' or an 'Application'");
+		return 0;
+	}
+
+	/* Originate the call */
+	struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
+
+	if (fast) {
+		ast_copy_string(fast->tech, tech, sizeof(fast->tech));
+		ast_copy_string(fast->data, data, sizeof(fast->data));
+		ast_copy_string(fast->app, app, sizeof(fast->app));
+		ast_copy_string(fast->appdata, appdata, sizeof(fast->appdata));
+
+		if (l) {
+			ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
+		}
+
+		if (n) {
+			ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
+		}
+
+		fast->vars = vars;
+		ast_copy_string(fast->context, context, sizeof(fast->context));
+		ast_copy_string(fast->exten, exten, sizeof(fast->exten));
+		ast_copy_string(fast->account, account, sizeof(fast->account));
+		fast->format = format;
+		fast->timeout = to;
+		fast->priority = pi;
+
+		fast->msession = s;
+
+		if (!ast_strlen_zero(id)) {
+			snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
+		}
+
+		if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
+			ast_free(fast);
 		} else {
-			astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
-			return 0;
+			res = 0;
 		}
 	}
+
 	if (!res) {
-		astman_send_ack(s, m, "Originate successfully queued");
+		astman_send_ack(s, m, "Response will follow");
 	} else {
 		astman_send_error(s, m, "Originate failed");
 	}
+
 	return 0;
 }
 
