int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass; char *server; /* take a jid and password on the command line, with optional server to connect to */ if ((argc < 3) || (argc > 4)) { fprintf(stderr, "Usage: basic <jid> <pass> [<server>]\n\n"); return 1; } jid = argv[1]; pass = argv[2]; server = NULL; /* Normally we pass NULL for the connection domain, in which case the library derives the target host from the jid, but we can override this for testing. */ if (argc >= 4) server = argv[3]; /* init library */ xmpp_initialize(); /* create a context */ // log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ // log = xmpp_get_default_logger(NULL); /* pass NULL instead to silence output */ ctx = xmpp_ctx_new(NULL, NULL); /* create a connection */ conn = xmpp_conn_new(ctx); /* setup authentication information */ xmpp_conn_set_jid(conn, jid); xmpp_conn_set_pass(conn, pass); /* initiate connection */ xmpp_connect_client(conn, server, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* final shutdown of the library */ xmpp_shutdown(); return 0; }
int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass; /* take a jid and password on the command line */ if (argc != 3) { fprintf(stderr, "Usage: bot <jid> <pass>\n\n"); return 1; } jid = argv[1]; pass = argv[2]; /* init library */ xmpp_initialize(); /* create a context */ log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ ctx = xmpp_ctx_new(NULL, log); /* create a connection */ conn = xmpp_conn_new(ctx); /* * also you can disable TLS support or force legacy SSL * connection without STARTTLS * * see xmpp_conn_set_flags() or examples/basic.c */ /* setup authentication information */ xmpp_conn_set_jid(conn, jid); xmpp_conn_set_pass(conn, pass); /* initiate connection */ xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* final shutdown of the library */ xmpp_shutdown(); return 0; }
int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass, *host; /* take a jid and password on the command line */ if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: basic <jid> <pass> [<host>]\n\n"); return 1; } jid = argv[1]; pass = argv[2]; host = NULL; if (argc == 4) host = argv[3]; /* init library */ xmpp_initialize(); /* create a context */ log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ ctx = xmpp_ctx_new(NULL, log); /* create a connection */ conn = xmpp_conn_new(ctx); /* setup authentication information */ xmpp_conn_set_jid(conn, jid); xmpp_conn_set_pass(conn, pass); /* initiate connection */ xmpp_connect_client(conn, host, 0, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* final shutdown of the library */ xmpp_shutdown(); return 0; }
void* run_conflate(void *arg) { conflate_handle_t* handle = (conflate_handle_t*)arg; /* Before connecting and all that, load the stored config */ kvpair_t* conf = load_kvpairs(handle, handle->conf->save_path); if (conf) { handle->conf->new_config(handle->conf->userdata, conf); free_kvpair(conf); } xmpp_log_t strophe_logger = { &conflate_strophe_logger, handle }; /* Run forever */ for (;;) { handle->ctx = xmpp_ctx_new(NULL, &strophe_logger); assert(handle->ctx); handle->conn = xmpp_conn_new(handle->ctx); assert(handle->conn); /* Use the stored jid if there is one */ char *db_jid = conflate_get_private(handle, STORED_JID_KEY, handle->conf->save_path); if (db_jid) { CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Using jid from db: %s", db_jid); xmpp_conn_set_jid(handle->conn, db_jid); free(db_jid); } else { CONFLATE_LOG(handle, LOG_LVL_DEBUG, "Using provided jid: %s", handle->conf->jid); xmpp_conn_set_jid(handle->conn, handle->conf->jid); } xmpp_conn_set_pass(handle->conn, handle->conf->pass); xmpp_connect_client(handle->conn, handle->conf->host, 0, conn_handler, handle); xmpp_run(handle->ctx); CONFLATE_LOG(handle, LOG_LVL_INFO, "xmpp_run exited"); xmpp_conn_release(handle->conn); xmpp_ctx_free(handle->ctx); sleep(5); CONFLATE_LOG(handle, LOG_LVL_INFO, "reconnecting"); } CONFLATE_LOG(handle, LOG_LVL_FATAL, "Exited an infinite loop."); return NULL; }
int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; if (argc != 3) { fprintf(stderr, "Usage: active <jid> <pass>\n\n"); return 1; } /* initialize lib */ xmpp_initialize(); /* create a context */ ctx = xmpp_ctx_new(NULL, NULL); /* create a connection */ conn = xmpp_conn_new(ctx); /* * also you can disable TLS support or force legacy SSL * connection without STARTTLS * * see xmpp_conn_set_flags() or examples/basic.c */ /* setup authentication information */ xmpp_conn_set_jid(conn, argv[1]); xmpp_conn_set_pass(conn, argv[2]); /* initiate connection */ xmpp_connect_client(conn, NULL, 0, NULL, conn_handler, ctx); /* start the event loop */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* shutdown lib */ xmpp_shutdown(); return 0; }
int main(int argc, char **argv) { struct nefit_easy easy; char *serial_number, *access_key, *password; EASY_UNUSED(argc); EASY_UNUSED(argv); /* init library */ xmpp_initialize(); serial_number = getenv("NEFIT_SERIAL_NUMBER"); access_key = getenv("NEFIT_ACCESS_KEY"); password = getenv("NEFIT_PASSWORD"); if (!serial_number || !access_key || !password) { printf("The following environmental variabled must be set\n"); printf("NEFIT_SERIAL_NUMBER=123456789\n"); printf("NEFIT_ACCESS_KEY=abcdefhijklmnopq\n"); printf("NEFIT_PASSWORD=wachtw\n"); exit(1); } easy_connect(&easy, serial_number, access_key, password, value_obtained); get_values(&easy); //manual_temperature(&easy, 23); //clock_mode(&easy); /* enter the event loop */ xmpp_run(easy.xmpp_ctx); /* release our connection and context */ xmpp_conn_release(easy.xmpp_conn); xmpp_ctx_free(easy.xmpp_ctx); /* shutdown lib */ xmpp_shutdown(); return 0; }
int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; if (argc != 3) { fprintf(stderr, "Usage: active <jid> <pass>\n\n"); return 1; } /* initialize lib */ xmpp_initialize(); /* create a context */ ctx = xmpp_ctx_new(NULL, NULL); /* create a connection */ conn = xmpp_conn_new(ctx); /* setup authentication information */ xmpp_conn_set_jid(conn, argv[1]); xmpp_conn_set_pass(conn, argv[2]); /* initiate connection */ xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* start the event loop */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* shutdown lib */ xmpp_shutdown(); return 0; }
int main(int argc, char *argv[]) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; const char *username; const char *password; username = bot_get_username(); password = bot_get_password(); xmpp_initialize(); /* context */ log = xmpp_get_default_logger(XMPP_LEVEL_INFO); ctx = xmpp_ctx_new(NULL, log); /* 创建连接 */ conn = xmpp_conn_new(ctx); /* 设置认证信息 */ xmpp_conn_set_jid(conn, username); xmpp_conn_set_pass(conn, password); /* 初始化连接 */ xmpp_connect_client(conn, NULL, 0, bot_conn_handler, ctx); /* 进入主循环 */ xmpp_run(ctx); /* 断开连接和释放资源 */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); xmpp_shutdown(); return 0; }
int main(int argc, char **argv) { xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass, *host = NULL; long flags = 0; int i; /* take a jid and password on the command line */ for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--disable-tls") == 0) flags |= XMPP_CONN_FLAG_DISABLE_TLS; else if (strcmp(argv[i], "--mandatory-tls") == 0) flags |= XMPP_CONN_FLAG_MANDATORY_TLS; else if (strcmp(argv[i], "--legacy-ssl") == 0) flags |= XMPP_CONN_FLAG_LEGACY_SSL; else break; } if ((argc - i) < 2 || (argc - i) > 3) { fprintf(stderr, "Usage: basic [options] <jid> <pass> [<host>]\n\n" "Options:\n" " --disable-tls Disable TLS.\n" " --mandatory-tls Deny plaintext connection.\n" " --legacy-ssl Use old style SSL.\n\n" "Note: --disable-tls conflicts with --mandatory-tls or " "--legacy-ssl\n"); return 1; } jid = argv[i]; pass = argv[i + 1]; if (i + 2 < argc) host = argv[i + 2]; /* * Note, this example doesn't handle errors. Applications should check * return values of non-void functions. */ /* init library */ xmpp_initialize(); /* create a context */ log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ ctx = xmpp_ctx_new(NULL, log); /* create a connection */ conn = xmpp_conn_new(ctx); /* configure connection properties (optional) */ xmpp_conn_set_flags(conn, flags); /* setup authentication information */ xmpp_conn_set_jid(conn, jid); xmpp_conn_set_pass(conn, pass); /* initiate connection */ xmpp_connect_client(conn, host, 0, NULL, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx); /* release our connection and context */ xmpp_conn_release(conn); xmpp_ctx_free(ctx); /* final shutdown of the library */ xmpp_shutdown(); return 0; }
void *xmpp_routine(void *arg) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)arg; xmpp_run(ctx); return NULL; }
static DWORD WINAPI _work_thread(LPVOID lpThreadParameter) { xmpp_run(_xmpp_ctx); return 0; }