Beispiel #1
0
    static void do_action(const Peer_Addr &address, Peer_Actions action, const Action_Context &context)
    {
        if (is_valid_action(action))
        {
            Peer_Store_t::iterator peer_iter = peer_store.find(address);
            if (peer_iter != peer_store.end())
            {
                Peer_Info &peer_info = peer_iter->second;
                Peer_State current_state = peer_info.state;
                if (is_valid(current_state))
                {
                    SM_Action_t act = actions_map[current_state][action];
                    Peer_State new_state = states_map[current_state][action];

                    if (act(peer_info, context))
                    {
                        peer_info.state = new_state;
                    }
                }
            }
        }
    }
Beispiel #2
0
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
																switch_ivr_menu_t ** menu_stack, switch_xml_t xml_menus, switch_xml_t xml_menu)
{
	switch_status_t status = SWITCH_STATUS_FALSE;

	if (xml_menu_ctx != NULL && menu_stack != NULL && xml_menu != NULL) {
		const char *menu_name = switch_xml_attr_soft(xml_menu, "name");	/* if the attr doesn't exist, return "" */
		const char *greet_long = switch_xml_attr(xml_menu, "greet-long");	/* if the attr doesn't exist, return NULL */
		const char *greet_short = switch_xml_attr(xml_menu, "greet-short");	/* if the attr doesn't exist, return NULL */
		const char *invalid_sound = switch_xml_attr(xml_menu, "invalid-sound");	/* if the attr doesn't exist, return NULL */
		const char *exit_sound = switch_xml_attr(xml_menu, "exit-sound");	/* if the attr doesn't exist, return NULL */
		const char *timeout = switch_xml_attr_soft(xml_menu, "timeout");	/* if the attr doesn't exist, return "" */
		const char *max_failures = switch_xml_attr_soft(xml_menu, "max-failures");	/* if the attr doesn't exist, return "" */
		const char *max_timeouts = switch_xml_attr_soft(xml_menu, "max-timeouts");
		const char *confirm_macro = switch_xml_attr(xml_menu, "confirm-macro");
		const char *confirm_key = switch_xml_attr(xml_menu, "confirm-key");
		const char *tts_engine = switch_xml_attr(xml_menu, "tts-engine");
		const char *tts_voice = switch_xml_attr(xml_menu, "tts-voice");
		const char *confirm_attempts = switch_xml_attr_soft(xml_menu, "confirm-attempts");
		const char *digit_len = switch_xml_attr_soft(xml_menu, "digit-len");
		const char *inter_timeout = switch_xml_attr_soft(xml_menu, "inter-digit-timeout");

		switch_ivr_menu_t *menu = NULL;

		if (zstr(max_timeouts)) {
			max_timeouts = max_failures;
		}

		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "building menu '%s'\n", menu_name);

		status = switch_ivr_menu_init(&menu,
									  *menu_stack,
									  menu_name,
									  greet_long,
									  greet_short,
									  invalid_sound,
									  exit_sound,
									  confirm_macro,
									  confirm_key,
									  tts_engine,
									  tts_voice,
									  atoi(confirm_attempts),
									  atoi(inter_timeout),
									  atoi(digit_len),
									  atoi(timeout),
									  strlen(max_failures) ? atoi(max_failures) : 0, strlen(max_timeouts) ? atoi(max_timeouts) : 0, xml_menu_ctx->pool);
		/* set the menu_stack for the caller */
		if (status == SWITCH_STATUS_SUCCESS && *menu_stack == NULL) {
			*menu_stack = menu;

			if (xml_menu_ctx->autocreated) {
				switch_set_flag(menu, SWITCH_IVR_MENU_FLAG_FREEPOOL);
			}
		}

		if (status == SWITCH_STATUS_SUCCESS && menu != NULL) {
			switch_xml_t xml_kvp;

			/* build menu entries */
			for (xml_kvp = switch_xml_child(xml_menu, "entry"); xml_kvp != NULL && status == SWITCH_STATUS_SUCCESS; xml_kvp = xml_kvp->next) {
				const char *action = switch_xml_attr(xml_kvp, "action");
				const char *digits = switch_xml_attr(xml_kvp, "digits");
				const char *param = switch_xml_attr_soft(xml_kvp, "param");

				if (is_valid_action(action) && !zstr(digits)) {
					switch_ivr_menu_xml_map_t *xml_map = xml_menu_ctx->map;
					int found = 0;

					/* find and appropriate xml handler */
					while (xml_map != NULL && !found) {
						if (!(found = (strcasecmp(xml_map->name, action) == 0))) {
							xml_map = xml_map->next;
						}
					}

					if (found && xml_map != NULL) {
						/* do we need to build a new sub-menu ? */
						if (xml_map->action == SWITCH_IVR_ACTION_EXECMENU && switch_ivr_menu_find(*menu_stack, param) == NULL) {
							if ((xml_menu = switch_xml_find_child(xml_menus, "menu", "name", param)) != NULL) {
								status = switch_ivr_menu_stack_xml_build(xml_menu_ctx, menu_stack, xml_menus, xml_menu);
							}
						}
						/* finally bind the menu entry */
						if (status == SWITCH_STATUS_SUCCESS) {
							if (xml_map->function != NULL) {
								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
												  "binding menu caller control '%s'/'%s' to '%s'\n", xml_map->name, param, digits);
								status = switch_ivr_menu_bind_function(menu, xml_map->function, param, digits);
							} else {
								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "binding menu action '%s' to '%s'\n", xml_map->name, digits);
								status = switch_ivr_menu_bind_action(menu, xml_map->action, param, digits);
							}
						}
					}
				} else {
					status = SWITCH_STATUS_FALSE;
				}
			}
		}
	}

	if (status != SWITCH_STATUS_SUCCESS) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to build xml menu\n");
	}

	return status;
}
/* action in the chshut mode */
void parse_shutdown_options(int argc, char **argv)
{
    int cse, action, rc, vmcmd_length;
    const struct option long_options[] = {
        { "help",	 no_argument,		NULL, 'h' },
        { "version",	 no_argument,		NULL, 'v' },
        { NULL,		 0,			NULL,  0  }
    };
    char vmcmd[128];

    rc = 0;
    vmcmd_length = 0;
    /* dont run without any argument */
    if (argc == 0 || argc == 1)
        print_usage_sa(argv[0]);
    while (optind < argc) {
        int index = -1;
        struct option *opt = 0;
        int result = getopt_long(argc, argv, "hv",
                                 long_options, &index);
        if (result == -1)
            break;		/* end of list */
        switch (result) {
        case 'h':
            print_usage_sa(argv[0]);
            break;
        case 'v':
            print_version();
            break;
        case 0:
            /*
             * all parameter that do not appear in the optstring
             */
            opt = (struct option *)&(long_options[index]);
            printf("'%s' was specified.",
                   opt->name);
            if (opt->has_arg == required_argument)
                printf("Arg: <%s>", optarg);
            printf("\n");
            break;
        case '?':
            printf("Try '%s' --help' for more information.\n",
                   argv[0]);
            break;
        default:
            print_usage_sa(argv[0]);
        }
    }
    if (argc >= 2) {
        cse = is_valid_case(argv[1]);
        if (cse == -1)  {
            fprintf(stderr, "%s: Invalid case specified\n", name);
            exit(1);
        }
        action = is_valid_action(argv[2]);
        if (action == -1) {
            fprintf(stderr, "%s: Invalid action specified\n", name);
            exit(1);
        }
        /*
         * vmcmd does not work in a lpar environment and needs an
         * additional argument
         */
        if ((action == 4) && (argv[3] != NULL)) {
            if (islpar()  == 0) {
                fprintf(stderr, "%s: vmcmd works only "
                        "inside z/VM.\n", name);
                exit(1);
            }
        }
        if ((action == 4) && (argv[3] == NULL)) {
            fprintf(stderr, "%s: vmcmd needs an additional "
                    "argument\n", name);
            exit(1);
        }
        /*
        * input needs to be upper case and may not exceed 127 chars
        */
        if (argv[3] != NULL && strlen(argv[3]) >= 127) {
            fprintf(stderr, "%s: the vmcmd command may not "
                    "exceed 127 characters.\n", name);
            exit(1);
        }
        vmcmd_length += strlen(argv[3]);
        switch (cse) {
        case 0:
            rc = strwrt(argv[2],
                        "/sys/firmware/shutdown_actions/on_halt");
            if (action == 4 && rc == 0)
                rc = ustrwrt(argv[3],
                             "/sys/firmware/vmcmd/on_halt");
            break;
        case 1:
            rc = strwrt(argv[2],
                        "/sys/firmware/shutdown_actions/on_poff");
            if (action == 4 && rc == 0)
                rc = ustrwrt(argv[3],
                             "/sys/firmware/vmcmd/on_poff");
            break;
        case 2:
            rc = strwrt(argv[2],
                        "/sys/firmware/shutdown_actions/on_reboot");
            if (action == 4 && rc == 0) {
                rc = ustrwrt(argv[3],
                             "/sys/firmware/vmcmd/on_reboot");
            }
            break;
        }
        if (rc != 0) {
            fprintf(stderr, "%s: Failed to change shutdown"
                    " action\n", name);
            exit(1);
        }
        /*
         * we now allow more than one vmcmd command
         * example:
         * chshut reboot vmcmd "MSG..." vmcmd "LOGOFF"
         */
        int i;
        strncpy(vmcmd, argv[3], strlen(argv[3]));
        for (i = 4; i <= argc; i++) {
            if (argv[i] == NULL)
                exit(1);
            if (strncmp(argv[i], "vmcmd", strlen("vmcmd")) != 0) {
                fprintf(stderr, "%s: Invalid vmcmd command"
                        " issued\n", name);
                exit(1);
            }
            if ((strlen(argv[i+1]) + vmcmd_length) >= 127) {
                fprintf(stderr, "%s: the vmcmd command may"
                        " not exceed 127 characters.\n", name);
                exit(1);
            }
            strncat(vmcmd, "\n", strlen(argv[i+1]));
            strncat(vmcmd, argv[i+1], strlen(argv[i+1]));
            switch (cse) {
            case 0:
                rc = strwrt(argv[2], "/sys/firmware/"
                            "shutdown_actions/on_halt");
                if (action == 4 && rc == 0)
                    rc = ustrwrt(vmcmd,
                                 "/sys/firmware/vmcmd/on_halt");
                break;
            case 1:
                rc = strwrt(argv[2], "/sys/firmware/"
                            "shutdown_actions/on_poff");
                if (action == 4 && rc == 0)
                    rc = ustrwrt(vmcmd,
                                 "/sys/firmware/vmcmd/on_poff");
                break;
            case 2:
                rc = strwrt(argv[2],
                            "/sys/firmware/shutdown_actions/"
                            "on_reboot");
                if (action == 4 && rc == 0) {
                    rc = ustrwrt(vmcmd, "/sys/firmware/"
                                 "vmcmd/on_reboot");
                }
                break;
            }
            vmcmd_length += strlen(argv[i+1]);
            i++;
        }
        if (rc != 0) {
            fprintf(stderr, "%s: Failed to change vmcmd\n", name);
            exit(1);
        }
    }
}