示例#1
0
static void handle_setup(void) {
    init_conflate(&conf);
    conf.log = null_logger; /* Comment this line out for logging */
    handle = calloc(1, sizeof(conflate_handle_t));
    fail_if(handle == NULL, "calloc failed");
    handle->conf = &conf;

    fail_if(tmpnam(db_loc) == NULL, "Couldn't make a tmp db.");
}
示例#2
0
static void init_config(conflate_config_t* conf)
{
    init_conflate(conf);
    conf->jid = "*****@*****.**";
    conf->pass = "******";
    conf->host = NULL;
    conf->software = "test";
    conf->version = "1.x";
    conf->save_path = "/tmp/something.db";
    conf->userdata = "some user data";
    conf->log = log_cb;
    conf->new_config = conf_cb;
}
示例#3
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();
}
示例#4
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;
}