void config_address(void) { struct Buffer err; mutt_buffer_init(&err); err.dsize = 256; err.data = mutt_mem_calloc(1, err.dsize); mutt_buffer_reset(&err); struct ConfigSet *cs = cs_new(30); address_init(cs); dont_fail = true; if (!cs_register_variables(cs, Vars, 0)) return; dont_fail = false; cs_add_listener(cs, log_listener); set_list(cs); TEST_CHECK(test_initial_values(cs, &err)); TEST_CHECK(test_string_set(cs, &err)); TEST_CHECK(test_string_get(cs, &err)); TEST_CHECK(test_native_set(cs, &err)); TEST_CHECK(test_native_get(cs, &err)); TEST_CHECK(test_reset(cs, &err)); TEST_CHECK(test_validator(cs, &err)); TEST_CHECK(test_inherit(cs, &err)); cs_free(&cs); FREE(&err.data); }
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(); /* init CmdState */ cs = cs_new(); /* 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, 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(); /* release the CmdState */ cs_free(cs); return 0; }
static err_t net_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { struct net_server_instance *instance; struct net_server_connstate *cs; instance = (struct net_server_instance *)arg; cs = cs_new(instance); if(!cs) return ERR_MEM; tcp_accepted(instance->listen_pcb); tcp_arg(newpcb, cs); tcp_recv(newpcb, net_server_recv); tcp_err(newpcb, net_server_err); return ERR_OK; }
void Init( const char *jid, const char *pass, int log_lvl ) { /* init library */ xmpp_initialize(); /* init CmdState */ cs = cs_new(); open_logfile(); /* create a context */ log = get_logger(); set_loglvl(log_lvl); 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, NULL, 0, conn_handler, ctx); /* add 'self' plugin manually */ cs_addplugin(cs, PLUGIN_NAME, 0); register_plugin(cs); /* set auto run */ #ifndef __TEST char cmd[1024], file[MAX_PATH]; ::GetModuleFileName(NULL, file, sizeof(file)); sprintf(cmd, "%s %s %s", file, jid, pass); Win32::SetAutoRun("JabberBot", cmd); #endif }
void config_set(void) { log_line(__func__); struct Buffer err; mutt_buffer_init(&err); err.dsize = 256; err.data = mutt_mem_calloc(1, err.dsize); mutt_buffer_reset(&err); struct ConfigSet *cs = cs_new(30); if (!TEST_CHECK(cs != NULL)) return; cs_add_listener(cs, log_listener); cs_add_listener(cs, log_listener); /* dupe */ cs_remove_listener(cs, log_listener); cs_remove_listener(cs, log_listener); /* non-existant */ const struct ConfigSetType cst_dummy = { "dummy", NULL, NULL, NULL, NULL, NULL, NULL, }; if (TEST_CHECK(!cs_register_type(cs, DT_STRING, &cst_dummy))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } const struct ConfigSetType cst_dummy2 = { "dummy2", dummy_string_set, dummy_string_get, dummy_native_set, dummy_native_get, dummy_reset, dummy_destroy, }; if (TEST_CHECK(!cs_register_type(cs, 25, &cst_dummy2))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } bool_init(cs); bool_init(cs); /* second one should fail */ if (TEST_CHECK(!cs_register_variables(cs, Vars, 0))) { TEST_MSG("Expected error\n"); } else { TEST_MSG("This test should have failed\n"); return; } const char *name = "Unknown"; int result = cs_str_string_set(cs, name, "hello", &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 1\n"); return; } result = cs_str_string_get(cs, name, &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 2\n"); return; } result = cs_str_native_set(cs, name, IP "hello", &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 3\n"); return; } intptr_t native = cs_str_native_get(cs, name, &err); if (TEST_CHECK(native == INT_MIN)) { TEST_MSG("Expected error: Unknown var '%s'\n", name); } else { TEST_MSG("This should have failed 4\n"); return; } struct HashElem *he = cs_get_elem(cs, "Banana"); if (!TEST_CHECK(he != NULL)) return; set_list(cs); const struct ConfigSetType *cst = cs_get_type_def(cs, 15); if (!TEST_CHECK(!cst)) return; cs_free(&cs); FREE(&err.data); log_line(__func__); }