示例#1
0
int control_prestart_dispatch_all(struct stasis_app_control *control,
	struct ast_channel *chan)
{
	struct ao2_container *command_queue;
	int count = 0;
	struct ao2_iterator iter;
	struct stasis_app_command *command;

	ast_channel_lock(chan);
	command_queue = command_prestart_get_container(chan);
	ast_channel_unlock(chan);
	if (!command_queue) {
		return 0;
	}

	iter = ao2_iterator_init(command_queue, AO2_ITERATOR_UNLINK);

	while ((command = ao2_iterator_next(&iter))) {
		command_invoke(command, control, chan);
		ao2_cleanup(command);
		++count;
	}

	ao2_iterator_destroy(&iter);
	ao2_cleanup(command_queue);
	return count;
}
示例#2
0
文件: shell.c 项目: Coderz333/cyassl
/********* SHEULL MAIN LOOP ***********************************/
void shell_main(void) {
    int i ; 
    func_args args ;
    int bf_flg ;
   
    i = BackGround ; 
        /* Dummy for avoiding warning: BackGround is defined but not used. */
    
    
 #if defined(HAVE_KEIL_RTX)
    InitMutex(&command_mutex) ;
#endif
    time_main(NULL) ;
    printf("Starting Shell\n") ;
    while(1) {
        if(getline(line,  LINESIZE, &args, &bf_flg) > 0) {
        for(i=0; commandTable[i].func != NULL; i++) {
            if(strcmp(commandTable[i].command, args.argv[0]) == 0) {
            args.argv[0] = (char *) commandTable[i].func ;
                if(bf_flg == FORGROUND) {
                    #ifdef  HAVE_KEIL_RTX
                    UnLockMutex((CyaSSL_Mutex *)&command_mutex) ;
                    os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7,
                            command_stack, COMMAND_STACK_SIZE, &args) ;
                    #else
                    command_invoke(&args) ;
                    #endif
                    #ifdef  HAVE_KEIL_RTX
                    LockMutex((CyaSSL_Mutex *)&command_mutex) ;
                    #endif
                } else {
                    #if (!defined(NO_SIMPLE_SERVER) && \
                         !defined(NO_ECHOSERVER)) && \
                         defined(HAVE_KEIL_RTX)
                    if(BackGround != 0) {
                        printf("Multiple background servers not supported.\n") ;
                    } else {
                        printf("\"%s\" is running with the background mode.\n", 
                                                     commandTable[i].command) ;
                        os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke, 
                                   6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ;
                    }
                    #else
                    printf("Invalid Command: no background job\n") ;
                    #endif
                }
                break ;
            }
        }
        if(commandTable[i].func == NULL)
            printf("Command not found\n") ;
        }
    }
}
示例#3
0
int control_dispatch_all(struct stasis_app_control *control,
	struct ast_channel *chan)
{
	int count = 0;
	struct ao2_iterator iter;
	struct stasis_app_command *command;

	ast_assert(control->channel == chan);

	iter = ao2_iterator_init(control->command_queue, AO2_ITERATOR_UNLINK);
	while ((command = ao2_iterator_next(&iter))) {
		command_invoke(command, control, chan);
		ao2_ref(command, -1);
		++count;
	}
	ao2_iterator_destroy(&iter);

	return count;
}
示例#4
0
文件: control.c 项目: vzar/asterisk
int control_dispatch_all(struct stasis_app_control *control,
                         struct ast_channel *chan)
{
    int count = 0;
    struct ao2_iterator i;
    void *obj;

    ast_assert(control->channel == chan);

    i = ao2_iterator_init(control->command_queue, AO2_ITERATOR_UNLINK);

    while ((obj = ao2_iterator_next(&i))) {
        RAII_VAR(struct stasis_app_command *, command, obj, ao2_cleanup);
        command_invoke(command, control, chan);
        ++count;
    }

    ao2_iterator_destroy(&i);
    return count;
}
示例#5
0
文件: hub.c 项目: imobilis/uhub
int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc_message* cmd)
{
	char* message = adc_msg_get_argument(cmd, 0);
	char* message_decoded = NULL;
	int ret = 0;
	int relay = 1;
	int broadcast;
	int private_msg;
	int command;
	int offset;

	if (!message)
		return 0;

	message_decoded = adc_msg_unescape(message);
	if (!message_decoded)
	{
		hub_free(message);
		return 0;
	}

	if (!user_is_logged_in(u))
	{
		hub_free(message);
		return 0;
	}

	broadcast = (cmd->cache[0] == 'B');
	private_msg = (cmd->cache[0] == 'D' || cmd->cache[0] == 'E');
	command = (message[0] == '!' || message[0] == '+');

	if (broadcast && command)
	{
		/*
		 * A message such as "++message" is handled as "+message", by removing the first character.
		 * The first character is removed by memmoving the string one byte to the left.
		 */
		if (message[1] == message[0])
		{
			relay = 1;
			offset = adc_msg_get_arg_offset(cmd);
			memmove(cmd->cache+offset+1, cmd->cache+offset+2, cmd->length - offset);
			cmd->length--;
		}
		else
		{
			relay = command_invoke(hub->commands, u, message_decoded);
		}
	}

	/* FIXME: Plugin should do this! */
	if (relay && (((hub->config->chat_is_privileged && !user_is_protected(u)) || (user_flag_get(u, flag_muted))) && broadcast))
	{
		relay = 0;
	}

	if (relay)
	{
		plugin_st status = st_default;
		if (broadcast)
		{
			status = plugin_handle_chat_message(hub, u, message_decoded, 0);
		}
		else if (private_msg)
		{
			struct hub_user* target = uman_get_user_by_sid(hub->users, cmd->target);
			if (target)
				status = plugin_handle_private_message(hub, u, target, message_decoded, 0);
			else
				relay = 0;
		}

		if (status == st_deny)
			relay = 0;
	}

	if (relay)
	{
		/* adc_msg_remove_named_argument(cmd, "PM"); */
		if (broadcast)
		{
			plugin_log_chat_message(hub, u, message_decoded, 0);
		}
		ret = route_message(hub, u, cmd);
	}
	hub_free(message);
	hub_free(message_decoded);
	return ret;
}
示例#6
0
/********* SHEULL MAIN LOOP ***********************************/
void shell_main(void *arg) {
    int i ; 
    func_args args ;
    int bf_flg ;
    osThreadId 	 cmd ;
    i = BackGround ; 
        /* Dummy for avoiding warning: BackGround is defined but not used. */
    
 #if defined(HAVE_KEIL_RTX) 
    wc_InitMutex(&command_mutex) ;
#endif
    help_comm(NULL) ;
    
    printf("Starting Shell\n") ;
    while(1) {
        if(getline(line,  LINESIZE, &args, &bf_flg) > 0) {
        for(i=0; commandTable[i].func != NULL; i++) {
            if(strcmp(commandTable[i].command, args.argv[0]) == 0) {
            args.argv[0] = (char *) commandTable[i].func ;
                if(bf_flg == FORGROUND) {
                    #if defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
                        wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
                        os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7,
                                 command_stack, COMMAND_STACK_SIZE, &args) ;
                        os_tsk_pass ();
                    #else
                        #if defined(WOLFSSL_CMSIS_RTOS)
                             wc_UnLockMutex((wolfSSL_Mutex *)&command_mutex) ;
                             cmd = osThreadCreate (osThread (command_invoke) , &args); 
                             if(cmd == NULL) {
															     printf("Cannon create command thread\n") ;
														 }
												     osThreadYield ();
                        #else
                              command_invoke(&args) ;
                        #endif
                    #endif
                    #ifdef  HAVE_KEIL_RTX
                    wc_LockMutex((wolfSSL_Mutex *)&command_mutex) ;
                    #endif
                } else {
                    #if (!defined(NO_SIMPLE_SERVER) && \
                         !defined(NO_ECHOSERVER)) && \
                         defined(HAVE_KEIL_RTX)
                    if(BackGround != 0) {
                        printf("Multiple background servers not supported.\n") ;
                    } else {
                        printf("\"%s\" is running with the background mode.\n", 
                                                     commandTable[i].command) ;
                        #if  defined(HAVE_KEIL_RTX) && !defined(WOLFSSL_CMSIS_RTOS)
                             os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke, 
                                   6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ;
                        #else
                                osThreadCreate (osThread (bg_job_invoke),  &args); 
                                osDelay (500) ;
                        #endif
                    }
                    #else
                    printf("Invalid Command: no background job\n") ;
                    #endif
                }
                break ;
            }
        }
        if(commandTable[i].func == NULL)
            printf("Command not found\n") ;
        }
    }
}