int main(int argc, char **argv) { Client client = silc_calloc(1, sizeof(*client)); gclient = client; if (argc > 1) { if (!strcmp(argv[1], "-d")) silc_log_debug(TRUE); if (argc > 2 && !strcmp(argv[2], "-x")) silc_log_debug_hexdump(TRUE); silc_log_set_debug_string("*"); } client->schedule = silc_schedule_init(0, NULL); if (!client->schedule) return -1; /* Connecto to server */ silc_net_tcp_connect(NULL, "127.0.0.1", 5000, client->schedule, connect_callback, client); silc_schedule(client->schedule); return 0; }
int main(int argc, char **argv) { SilcBool success = FALSE; SilcSchedule schedule; SilcFSM fsm; Foo f; if (argc > 1 && !strcmp(argv[1], "-d")) { silc_log_debug(TRUE); silc_log_debug_hexdump(TRUE); silc_log_quick(TRUE); silc_log_set_debug_string("*fsm*,*async*"); } SILC_LOG_DEBUG(("Allocating scheduler")); schedule = silc_schedule_init(0, NULL); f = silc_calloc(1, sizeof(*f)); if (!f) goto err; f->schedule = schedule; SILC_LOG_DEBUG(("Allocating FSM context")); f->fsm = fsm = silc_fsm_alloc(f, destructor, f, schedule); if (!fsm) goto err; silc_fsm_start(fsm, test_st_start); SILC_LOG_DEBUG(("Running scheduler")); silc_schedule(schedule); if (f->error) goto err; silc_schedule_uninit(schedule); silc_free(f); success = TRUE; err: SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE")); fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE"); return success; }
int main(int argc, char **argv) { SilcFSM fsm; if (argc > 1 && !strcmp(argv[1], "-d")) { silc_log_debug(TRUE); silc_log_debug_hexdump(TRUE); silc_log_set_debug_string("*fdstream*"); } SILC_LOG_DEBUG(("Allocating scheduler")); schedule = silc_schedule_init(0, NULL); if (!schedule) goto err; SILC_LOG_DEBUG(("Allocating FSM")); fsm = silc_fsm_alloc(NULL, fsm_dest, NULL, schedule); if (!fsm) goto err; silc_fsm_start(fsm, st_write); SILC_LOG_DEBUG(("Running scheduler")); silc_schedule(schedule); if (!success) goto err; silc_schedule_uninit(schedule); success = TRUE; err: SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE")); fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE"); return success; }
int main(int argc, char **argv) { SilcFSM fsm; silc_runtime_init(); if (argc > 1 && !strcmp(argv[1], "-d")) { silc_log_debug(TRUE); silc_log_debug_hexdump(TRUE); silc_log_set_debug_string("*thread*"); } SILC_LOG_DEBUG(("Allocating scheduler")); schedule = silc_schedule_init(0, NULL, NULL, NULL); if (!schedule) goto err; SILC_LOG_DEBUG(("Allocating FSM context")); fsm = silc_fsm_alloc(NULL, destructor, NULL, schedule); if (!fsm) goto err; silc_fsm_start(fsm, test_st_start); SILC_LOG_DEBUG(("Running scheduler")); silc_schedule(schedule); silc_schedule_uninit(schedule); err: SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE")); fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE"); silc_runtime_uninit(); return !success; }
int main(int argc, char **argv) { SilcBool success = FALSE; SilcSchedule schedule; SilcSKR skr; SilcSKRFind find; SilcPublicKey pk; if (argc > 1 && !strcmp(argv[1], "-d")) { silc_log_debug(TRUE); silc_log_debug_hexdump(TRUE); silc_log_set_debug_string("*skr*"); } SILC_LOG_DEBUG(("Allocating scheduler")); schedule = silc_schedule_init(0, NULL, NULL); SILC_LOG_DEBUG(("Allocating SKR")); skr = silc_skr_alloc(); if (!skr) goto err; SILC_LOG_DEBUG(("Adding public key to SKR")); pk = silc_calloc(1, sizeof(*pk)); pk->len = 1; pk->pk_type = SILC_PKCS_SILC; pk->name = strdup("rsa"); pk->pk = strdup(" "); pk->pk_len = 2; pk->identifier = silc_pkcs_encode_identifier("foo", "foo.com", "Foo T. Bar", "*****@*****.**", "ORG", "FI"); silc_skr_add_public_key(skr, pk, 0, NULL); SILC_LOG_DEBUG(("Adding public key to SKR")); pk = silc_calloc(1, sizeof(*pk)); pk->len = 1; pk->pk_type = SILC_PKCS_SILC; pk->name = strdup("rsa"); pk->pk = strdup(" "); pk->pk_len = 2; pk->identifier = silc_pkcs_encode_identifier("bar", "bar.com", "Bar T. Bar", "*****@*****.**", "ORG", "FI"); silc_skr_add_public_key(skr, pk, SILC_SKR_USAGE_IDENTIFICATION | SILC_SKR_USAGE_AUTH, NULL); SILC_LOG_DEBUG(("Attempting to add key twice")); if (silc_skr_add_public_key(skr, pk, 0, NULL) == SILC_SKR_OK) { SILC_LOG_DEBUG(("Adding key twice not detected")); goto err; } SILC_LOG_DEBUG(("Finding public key by email")); find = silc_skr_find_alloc(); silc_skr_find_set_email(find, "*****@*****.**"); silc_skr_find(skr, schedule, find, skr_found, NULL); silc_skr_find_free(find); if (!found) goto err; SILC_LOG_DEBUG(("Finding public key by country")); find = silc_skr_find_alloc(); silc_skr_find_set_country(find, "FI"); silc_skr_find(skr, schedule, find, skr_found, NULL); silc_skr_find_free(find); if (!found) goto err; SILC_LOG_DEBUG(("Finding public key by country, ORG and hostname")); find = silc_skr_find_alloc(); silc_skr_find_set_country(find, "FI"); silc_skr_find_set_org(find, "ORG"); silc_skr_find_set_host(find, "foo.com"); silc_skr_find(skr, schedule, find, skr_found, NULL); silc_skr_find_free(find); if (!found) goto err; SILC_LOG_DEBUG(("Finding public key by SILC public key")); silc_skr_find_silc(skr, pk, skr_found, NULL); if (!found) goto err; SILC_LOG_DEBUG(("Finding public key by country and usage (must not find)")); find = silc_skr_find_alloc(); silc_skr_find_set_country(find, "FI"); silc_skr_find_set_usage(find, SILC_SKR_USAGE_ENC); silc_skr_find(skr, schedule, find, skr_found, NULL); silc_skr_find_free(find); if (found) goto err; SILC_LOG_DEBUG(("Finding public key by country and usage")); find = silc_skr_find_alloc(); silc_skr_find_set_country(find, "FI"); silc_skr_find_set_usage(find, SILC_SKR_USAGE_IDENTIFICATION); silc_skr_find(skr, schedule, find, skr_found, NULL); silc_skr_find_free(find); if (!found) goto err; silc_skr_free(skr); silc_schedule_uninit(schedule); success = TRUE; err: SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE")); fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE"); return success; }
SilcBool silc_client_init(SilcClient client, const char *username, const char *hostname, const char *realname, SilcClientRunning running, void *context) { SILC_LOG_DEBUG(("Initializing client")); if (!client) return FALSE; if (!username || !hostname) { SILC_LOG_ERROR(("Username and hostname must be given to " "silc_client_init")); return FALSE; } if (!realname) realname = username; /* Validate essential strings */ if (!silc_identifier_verify(username, strlen(username), SILC_STRING_UTF8, 128)) { SILC_LOG_ERROR(("Malformed username '%s'. Username must be UTF-8 string", client->username)); return FALSE; } if (!silc_identifier_verify(hostname, strlen(hostname), SILC_STRING_UTF8, 256)) { SILC_LOG_ERROR(("Malformed hostname '%s'. Hostname must be UTF-8 string", client->hostname)); return FALSE; } if (!silc_utf8_valid(realname, strlen(realname))) { SILC_LOG_ERROR(("Malformed realname '%s'. Realname must be UTF-8 string", client->realname)); return FALSE; } /* Take the name strings */ client->username = strdup(username); client->hostname = strdup(hostname); client->realname = strdup(realname); if (!username || !hostname || !realname) return FALSE; client->internal->ftp_sessions = silc_dlist_init(); if (!client->internal->ftp_sessions) return FALSE; if (!client->internal->params->dont_register_crypto_library) { /* Initialize the crypto library. If application has done this already this has no effect. Also, we will not be overriding something application might have registered earlier. */ silc_cipher_register_default(); silc_pkcs_register_default(); silc_hash_register_default(); silc_hmac_register_default(); } /* Initialize random number generator */ client->rng = silc_rng_alloc(); if (!client->rng) return FALSE; silc_rng_init(client->rng); silc_rng_global_init(client->rng); /* Initialize the scheduler */ client->schedule = silc_schedule_init(0, client); if (!client->schedule) return FALSE; /* Allocate client lock */ silc_mutex_alloc(&client->internal->lock); /* Register commands */ silc_client_commands_register(client); /* Start packet engine */ client->internal->packet_engine = silc_packet_engine_start(client->rng, FALSE, &silc_client_stream_cbs, client); if (!client->internal->packet_engine) return FALSE; /* Initialize and start the client FSM */ client->internal->running = running; client->internal->running_context = context; silc_fsm_init(&client->internal->fsm, client, NULL, NULL, client->schedule); silc_fsm_event_init(&client->internal->wait_event, &client->internal->fsm); silc_fsm_start_sync(&client->internal->fsm, silc_client_st_run); /* Signal the application when we are running */ client->internal->run_callback = TRUE; SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); return TRUE; }