示例#1
0
int main(int argc, char **argv) {

    if (argc < 3) {
        fprintf(stderr, "Usage: bot <jid> <pass> [host]\n");
        exit(EX_USAGE);
    }

    /* Initialize callbacks for provided functionality.
     *
     * These callbacks are global and thus initialized once for your
     * entire application.
     */
    conflate_register_mgmt_cb("client_stats", "Retrieves stats from the agent",
                              process_stats);
    conflate_register_mgmt_cb("reset_stats", "Reset stats on the agent",
                              process_reset_stats);

    conflate_register_mgmt_cb("ping_test", "Perform a ping test",
                              process_ping_test);

	conflate_register_mgmt_cb("alarm", "Create an alarm",
                              process_alarm_create);

    /* Perform default configuration initialization. */
    conflate_config_t conf;
    init_conflate(&conf);

    /* Specify application-specific configuration parameters. */
    conf.jid = argv[1];
    conf.pass = argv[2];
    conf.host = (argc == 4 ? argv[3] : NULL);
    conf.software = "conflate sample bot";
    conf.version = "1.0";
    conf.save_path = "/tmp/conflate.db";
    conf.log = conflate_stderr_logger;

    conf.userdata = "something awesome";
    conf.new_config = display_config;

    /* Begin the connection. */
    if(!start_conflate(conf)) {
        fprintf(stderr, "Couldn't initialize libconflate.\n");
        exit(1);
    }

    /* Typically, your application would go about its business here.
       Since this is just a demo, the caller has nothing else to do,
       so we wait forever. */
    pause();
}
示例#2
0
proxy_main *cproxy_init_agent_start(char *jid,
                                    char *jpw,
                                    char *config_path,
                                    char *host,
                                    proxy_behavior behavior,
                                    int nthreads) {
    assert(jid);
    assert(jpw);
    assert(config_path);

    if (settings.verbose > 2) {
        fprintf(stderr, "cproxy_init_agent_start\n");;
    }

    proxy_main *m = calloc(1, sizeof(proxy_main));
    if (m != NULL) {
        m->proxy_head = NULL;
        m->nthreads   = nthreads;
        m->behavior   = behavior;

        m->stat_configs      = 0;
        m->stat_config_fails = 0;
        m->stat_proxy_starts      = 0;
        m->stat_proxy_start_fails = 0;
        m->stat_proxy_existings   = 0;
        m->stat_proxy_shutdowns   = 0;

        conflate_config_t config;

        memset(&config, 0, sizeof(config));

        init_conflate(&config);

        // Different jid's possible for production, staging, etc.
        config.jid  = jid;  // "*****@*****.**"
        config.pass = jpw;  // "password"
        config.host = host; // "localhost"
        config.software   = PACKAGE;
        config.version    = VERSION;
        config.save_path  = config_path;
        config.userdata   = m;
        config.new_config = on_conflate_new_config;
        config.log        = agent_logger;

        if (start_conflate(config)) {
            if (settings.verbose > 2) {
                fprintf(stderr, "cproxy_init done\n");
            }

            return m;
        }

        free(m);
    }

    if (settings.verbose > 1) {
        fprintf(stderr, "cproxy could not start conflate\n");
    }

    return NULL;
}