static void test_accept_connection(SilcNetStatus status, SilcStream stream, void *context) { Foo f = context; SILC_LOG_DEBUG(("Accepted new connection")); f->client_status = status; f->client_stream = stream; SILC_FSM_EVENT_SIGNAL(&f->sema); }
void silc_client_close_connection(SilcClient client, SilcClientConnection conn) { SILC_LOG_DEBUG(("Closing connection %p", conn)); /* Signal to close connection */ conn->internal->status = SILC_CLIENT_CONN_DISCONNECTED; if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } }
static void silc_client_connection_finished(SilcFSMThread fsm, void *fsm_context, void *destructor_context) { SilcClient client = silc_fsm_get_state_context(fsm); /* Signal client that we have finished */ silc_atomic_sub_int32(&client->internal->conns, 1); client->internal->connection_closed = TRUE; SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); silc_fsm_free(fsm); }
static void silc_client_packet_eos(SilcPacketEngine engine, SilcPacketStream stream, void *callback_context, void *stream_context) { SilcClientConnection conn = stream_context; SILC_LOG_DEBUG(("Remote disconnected connection")); /* Signal to close connection */ conn->internal->status = SILC_CLIENT_CONN_DISCONNECTED; if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } }
void silc_client_stop(SilcClient client, SilcClientStopped stopped, void *context) { SILC_LOG_DEBUG(("Stopping client")); if (!silc_fsm_is_started(&client->internal->fsm)) { SILC_LOG_WARNING(("Attempting to stop client library before it has been " "started (silc_client_init not called)")); return; } client->internal->running = (SilcClientRunning)stopped; client->internal->running_context = context; /* Signal to stop */ client->internal->stop = TRUE; SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); }
static void silc_client_connect_abort(SilcAsyncOperation op, void *context) { SilcClientConnection conn = context; SILC_LOG_DEBUG(("Connection %p aborted by application", conn)); /* Connection callback will not be called after user aborted connecting */ conn->callback = NULL; conn->internal->cop = NULL; /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; /* If user aborts before connection machine is even up yet, then don't send signal yet. It will process this event when it comes up. */ if (silc_fsm_is_started(&conn->internal->fsm)) SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } }
void silc_server_command_pending_signal(SilcServerCommand cmd) { SilcServerThread thread = cmd->thread; SilcServerPending pending = cmd->pending; if (!pending) return; silc_mutex_lock(thread->server->lock); /* Signal */ pending->reply = cmd; SILC_FSM_EVENT_SIGNAL(&pending->wait_reply); /* Remove from pending */ silc_hash_table_del_by_context(thread->server->pending_commands, SILC_32_TO_PTR(pending->cmd_ident), pending); silc_mutex_unlock(thread->server->lock); }
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; }