+static int tryexec_exec(struct ast_channel *chan, void *data)
+{
+ int res=0;
+ struct localuser *u;
+ char *s, *appname, *endargs, args[MAXRESULT] = "";
+ struct ast_app *app;
+
+ LOCAL_USER_ADD(u);
+
+ /* Check and parse arguments */
+ if (data) {
+ if ((s = ast_strdupa(data))) {
+ appname = strsep(&s, "(");
+ if (s) {
+ endargs = strrchr(s, ')');
+ if (endargs)
+ *endargs = '\0';
+ pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
+ }
+ if (appname) {
+ app = pbx_findapp(appname);
+ if (app) {
+ res = pbx_exec(chan, app, args);
+ pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS");
+ } else {
+ ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
+ pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
+ }
+ }
+ } else {
+ ast_log(LOG_ERROR, "Out of memory\n");
+ pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOMEMORY");
+ }
+ }
+
+ LOCAL_USER_REMOVE(u);
+ return 0;
+}
+