@@ -924,6 +924,52 @@ static char *handle_show_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cl
924
924
return CLI_SUCCESS ;
925
925
}
926
926
927
+ /*! \brief CLI support for executing function */
928
+ static char * handle_eval_function (struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
929
+ {
930
+ struct ast_channel * c = NULL ;
931
+ char * fn , * substituted ;
932
+ int ret ;
933
+ char workspace [1024 ];
934
+
935
+ switch (cmd ) {
936
+ case CLI_INIT :
937
+ e -> command = "dialplan eval function" ;
938
+ e -> usage =
939
+ "Usage: dialplan eval function <name(args)>\n"
940
+ " Evaluate a dialplan function call\n"
941
+ " A dummy channel is used to evaluate\n"
942
+ " the function call, so only global\n"
943
+ " variables should be used.\n" ;
944
+ return NULL ;
945
+ case CLI_GENERATE :
946
+ return NULL ;
947
+ }
948
+
949
+ if (a -> argc != e -> args + 1 ) {
950
+ return CLI_SHOWUSAGE ;
951
+ }
952
+
953
+ c = ast_dummy_channel_alloc ();
954
+ if (!c ) {
955
+ ast_cli (a -> fd , "Unable to allocate bogus channel for function evaluation.\n" );
956
+ return CLI_FAILURE ;
957
+ }
958
+
959
+ fn = (char * ) a -> argv [3 ];
960
+ pbx_substitute_variables_helper (c , fn , workspace , sizeof (workspace ));
961
+ substituted = ast_strdupa (workspace );
962
+ workspace [0 ] = '\0' ;
963
+ ret = ast_func_read (c , substituted , workspace , sizeof (workspace ));
964
+
965
+ c = ast_channel_unref (c );
966
+
967
+ ast_cli (a -> fd , "Return Value: %s (%d)\n" , ret ? "Failure" : "Success" , ret );
968
+ ast_cli (a -> fd , "Result: %s\n" , workspace );
969
+
970
+ return CLI_SUCCESS ;
971
+ }
972
+
927
973
static char * handle_set_global (struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
928
974
{
929
975
switch (cmd ) {
@@ -1218,6 +1264,7 @@ void pbx_builtin_clear_globals(void)
1218
1264
static struct ast_cli_entry vars_cli [] = {
1219
1265
AST_CLI_DEFINE (handle_show_globals , "Show global dialplan variables" ),
1220
1266
AST_CLI_DEFINE (handle_show_chanvar , "Show channel variables" ),
1267
+ AST_CLI_DEFINE (handle_eval_function , "Evaluate dialplan function" ),
1221
1268
AST_CLI_DEFINE (handle_set_global , "Set global dialplan variable" ),
1222
1269
AST_CLI_DEFINE (handle_set_chanvar , "Set a channel variable" ),
1223
1270
};
0 commit comments