Ejemplo n.º 1
0
static int command_handler(xmpp_conn_t * const conn,
                           xmpp_stanza_t * const stanza,
                           void * const userdata)
{
    xmpp_stanza_t *reply = NULL, *req = NULL;
    char *cmd = NULL;

    /* Figure out what the command is */
    req = xmpp_stanza_get_child_by_name(stanza, "command");
    assert(req);
    assert(strcmp(xmpp_stanza_get_name(req), "command") == 0);
    cmd = xmpp_stanza_get_attribute(req, "node");
    assert(cmd);

    CONFLATE_LOG(((conflate_handle_t *)userdata), LOG_LVL_INFO,
                 "Command:  %s", cmd);

    reply = command_dispatch(conn, stanza, userdata, cmd, req, true);

    if (reply) {
        xmpp_send(conn, reply);
        xmpp_stanza_release(reply);
    }

    return 1;
}
Ejemplo n.º 2
0
int command_parse_and_dispatch(const char * cmd) {
    char* args[MAX_ARGC];
    int tokens = command_parse(cmd, args);
	
    if (tokens == -1) return -1;
    return command_dispatch(tokens, (const char **) args);
}
Ejemplo n.º 3
0
/* Switch function which should only be called with 'raw' (i.e. inline
 * mode, not shell mode) argv/argc.  If appropriate, it enters
 * flag_dispatch to parse program flags.
 */
void
command_or_flag_dispatch (cli_infos_t *infos, gint in_argc, gchar **in_argv)
{
	/* First argument looks like a flag */
	if (in_argc > 0 && in_argv[0][0] == '-') {
		flag_dispatch (infos, in_argc, in_argv);
	} else {
		command_dispatch (infos, in_argc, in_argv);
	}
}
Ejemplo n.º 4
0
/**
 * Library initialization and operation parsing
 */
int main(int argc, char *argv[])
{
	atexit(library_deinit);
	if (!library_init(NULL))
	{
		exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
	}
	if (lib->integrity &&
		!lib->integrity->check_file(lib->integrity, "pki", argv[0]))
	{
		fprintf(stderr, "integrity check of pki failed\n");
		exit(SS_RC_DAEMON_INTEGRITY);
	}
	if (!lib->plugins->load(lib->plugins, NULL,
			lib->settings->get_str(lib->settings, "pki.load", PLUGINS)))
	{
		exit(SS_RC_INITIALIZATION_FAILED);
	}
	return command_dispatch(argc, argv);
}
Ejemplo n.º 5
0
/**
 * Library initialization and operation parsing
 */
int main(int argc, char *argv[])
{
	atexit(cleanup);
	if (!library_init(NULL, "swanctl"))
	{
		exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
	}
	if (lib->integrity &&
		!lib->integrity->check_file(lib->integrity, "swanctl", argv[0]))
	{
		fprintf(stderr, "integrity check of swanctl failed\n");
		exit(SS_RC_DAEMON_INTEGRITY);
	}
	if (!lib->plugins->load(lib->plugins,
			lib->settings->get_str(lib->settings, "swanctl.load", PLUGINS)))
	{
		exit(SS_RC_INITIALIZATION_FAILED);
	}
	dbg_default_set_level(0);
	lib->processor->set_threads(lib->processor, 4);
	dbg_default_set_level(1);

	return command_dispatch(argc, argv);
}
Ejemplo n.º 6
0
static int message_handler(xmpp_conn_t * const conn,
                           xmpp_stanza_t * const stanza,
                           void * const userdata)
{
    xmpp_stanza_t* event = NULL, *items = NULL, *item = NULL,
        *command = NULL, *reply = NULL;
    conflate_handle_t *handle = (conflate_handle_t*)userdata;
    CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Got a message from %s",
                 xmpp_stanza_get_attribute(stanza, "from"));

    event = xmpp_stanza_get_child_by_name(stanza, "event");
    assert(event);
    items = xmpp_stanza_get_child_by_name(event, "items");
    assert(items);
    item = xmpp_stanza_get_child_by_name(items, "item");

    if (item) {
        command = xmpp_stanza_get_child_by_name(item, "command");
        assert(command);

        CONFLATE_LOG(handle, LOG_LVL_INFO, "Pubsub comand:  %s",
                     xmpp_stanza_get_attribute(command, "command"));

        reply = command_dispatch(conn, stanza, userdata,
                                 xmpp_stanza_get_attribute(command, "command"),
                                 command, false);

        if (reply) {
            xmpp_stanza_release(reply);
        }
    } else {
        CONFLATE_LOG(handle, LOG_LVL_INFO, "Received pubsub event with no items.");
    }

    return 1;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: chrippa/xmms2
void
command_run (cli_infos_t *infos, gchar *input)
{
	while (input && *input == ' ') ++input;

	if (input == NULL) {
		if (infos->status != CLI_ACTION_STATUS_ALIAS) {
			/* End of stream, quit */
			cli_infos_loop_stop (infos);
			g_printf ("\n");
		}
	} else if (*input != 0) {
		gint argc;
		gchar **argv, *listop;
		GError *error = NULL;

		if ((listop = strchr (input, ';'))) {
			*listop++ = '\0';
		}

		if (g_shell_parse_argv (input, &argc, &argv, &error)) {
			if (infos->status != CLI_ACTION_STATUS_ALIAS) {
				add_history (input);
			}
			command_dispatch (infos, argc, argv);
			g_strfreev (argv);
			if (listop && *listop) {
				g_printf ("\n");
				command_run (infos, listop);
			}
		} else {
			g_printf (_("Error: %s\n"), error->message);
			g_error_free (error);
		}
	}
}