From: Pekka Riikonen Date: Sat, 23 Dec 2006 17:51:57 +0000 (+0000) Subject: Nickname formatting/parsing rewrite. X-Git-Tag: silc.client.1.1.beta1~92 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=49bd4f6cd6a28a9bcb8081eaef48567538ba486f Nickname formatting/parsing rewrite. SILC FSM API changes. --- diff --git a/lib/silcclient/README b/lib/silcclient/README index dc0fcae7..f2755c31 100644 --- a/lib/silcclient/README +++ b/lib/silcclient/README @@ -54,27 +54,27 @@ Using FSM threads that need execution time also. -When to use FSM semaphore signalling? +When to use FSM event signalling? - FSM semaphore signalling should be used only when multiple threads + FSM event signalling should be used only when multiple threads (FSM threads) may be waiting for something to happen. If only one thread is waiting for something it should merely return SILC_FSM_WAIT and when that something happens it should use silc_fsm_continue or silc_fsm_continue_sync to continue in the waiting thread. OTOH, if - multiple threads are waiting SILC_FSM_SEMA_POST is the only way to + multiple threads are waiting SILC_FSM_EVENT_SIGNAL is the only way to deliver the signal. Always remember that posting is signal is not donbe synchronously (it won't be delivered immediately). OTOH, if there is only one thread waiting for somtehing to happen but there can be multiple threads signalling that something has happened - only way to do this is to use semaphore signalling. + only way to do this is to use event signalling. - Semaphore signals should be pre-allocated SilcFSMSemaStruct structures + Event signals should be pre-allocated SilcFSMEventStruct structures and for signalling use they are always initialized as: - silc_fsm_sema_init(&sema, fsm, 0); + silc_fsm_event_init(&event, fsm); - The call cannot fail. Semaphores need not be uninitialized and the same + The call cannot fail. Events need not be uninitialized and the same context may be reused. Finishing threads when closing connection diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index c7e4e6d8..f8931441 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -59,7 +59,7 @@ static void silc_client_connection_finished(SilcFSMThread fsm, /* Signal client that we have finished */ silc_atomic_sub_int16(&client->internal->conns, 1); client->internal->connection_closed = TRUE; - SILC_FSM_SEMA_POST(&client->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); silc_fsm_free(fsm); } @@ -147,7 +147,7 @@ static void silc_client_packet_eos(SilcPacketEngine engine, /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } } @@ -189,7 +189,7 @@ static void silc_client_connect_abort(SilcAsyncOperation op, void *context) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } } @@ -210,17 +210,17 @@ SILC_FSM_STATE(silc_client_connection_st_start) connfsm = &conn->internal->fsm; silc_fsm_init(connfsm, conn, silc_client_connection_destructor, fsm, conn->internal->schedule); - silc_fsm_sema_init(&conn->internal->wait_event, connfsm, 0); + silc_fsm_event_init(&conn->internal->wait_event, connfsm); silc_fsm_start_sync(connfsm, silc_client_connection_st_run); /* Schedule any events set in initialization */ if (conn->internal->connect) - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); if (conn->internal->key_exchange) - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); /* Wait until this thread is terminated from the machine destructor */ - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Connection machine main state. This handles various connection related @@ -233,7 +233,7 @@ SILC_FSM_STATE(silc_client_connection_st_run) SilcFSMThread thread; /* Wait for events */ - SILC_FSM_SEMA_WAIT(&conn->internal->wait_event); + SILC_FSM_EVENT_WAIT(&conn->internal->wait_event); /* Process events */ thread = &conn->internal->event_thread; @@ -246,7 +246,7 @@ SILC_FSM_STATE(silc_client_connection_st_run) silc_fsm_thread_init(thread, &conn->internal->fsm, conn, NULL, NULL, FALSE); silc_fsm_start_sync(thread, silc_client_st_connect); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (conn->internal->key_exchange) { @@ -257,7 +257,7 @@ SILC_FSM_STATE(silc_client_connection_st_run) silc_fsm_thread_init(thread, &conn->internal->fsm, conn, NULL, NULL, FALSE); silc_fsm_start_sync(thread, silc_client_st_connect_set_stream); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (conn->internal->rekeying) { @@ -268,19 +268,19 @@ SILC_FSM_STATE(silc_client_connection_st_run) silc_fsm_thread_init(thread, &conn->internal->fsm, conn, NULL, NULL, FALSE); silc_fsm_start_sync(thread, silc_client_st_rekey); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (conn->internal->disconnected) { /** Event: disconnected */ SILC_LOG_DEBUG(("Event: disconnected")); silc_fsm_next(fsm, silc_client_connection_st_close); - return SILC_FSM_YIELD; + SILC_FSM_YIELD; } /* NOT REACHED */ SILC_ASSERT(FALSE); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Packet processor thread. Each incoming packet is processed in FSM @@ -365,19 +365,19 @@ SILC_FSM_STATE(silc_client_connection_st_packet) /* Signal to start rekey */ conn->internal->rekey_responder = TRUE; conn->internal->rekeying = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; break; default: silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; break; } - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Disconnection event to close remote connection. We close the connection @@ -404,7 +404,7 @@ SILC_FSM_STATE(silc_client_connection_st_close) } /* Give threads time to finish */ - return SILC_FSM_YIELD; + SILC_FSM_YIELD; } /* Abort ongoing event */ @@ -418,7 +418,7 @@ SILC_FSM_STATE(silc_client_connection_st_close) if (silc_fsm_is_started(&conn->internal->event_thread)) { SILC_LOG_DEBUG(("Finish event thread")); silc_fsm_continue_sync(&conn->internal->event_thread); - return SILC_FSM_YIELD; + SILC_FSM_YIELD; } SILC_LOG_DEBUG(("Closing remote connection")); @@ -428,7 +428,7 @@ SILC_FSM_STATE(silc_client_connection_st_close) SILC_LOG_DEBUG(("Finishing connection machine")); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Received error packet from server. Send it to application. */ @@ -448,7 +448,7 @@ SILC_FSM_STATE(silc_client_error) silc_free(msg); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Received disconnect packet from server. We close the connection and @@ -466,7 +466,7 @@ SILC_FSM_STATE(silc_client_disconnect) if (silc_buffer_len(&packet->buffer) < 1) { silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } status = (SilcStatus)packet->buffer.data[0]; @@ -490,10 +490,10 @@ SILC_FSM_STATE(silc_client_disconnect) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /*************************** Main client machine ****************************/ @@ -505,7 +505,7 @@ SILC_FSM_STATE(silc_client_st_run) SilcClient client = fsm_context; /* Wait for events */ - SILC_FSM_SEMA_WAIT(&client->internal->wait_event); + SILC_FSM_EVENT_WAIT(&client->internal->wait_event); /* Process events */ @@ -514,7 +514,7 @@ SILC_FSM_STATE(silc_client_st_run) SILC_LOG_DEBUG(("We are up, call running callback")); client->internal->run_callback = FALSE; client->internal->running(client, client->internal->running_context); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (client->internal->connection_closed) { @@ -523,8 +523,8 @@ SILC_FSM_STATE(silc_client_st_run) client->internal->connection_closed = FALSE; if (silc_atomic_get_int16(&client->internal->conns) == 0 && client->internal->stop) - SILC_FSM_SEMA_POST(&client->internal->wait_event); - return SILC_FSM_CONTINUE; + SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); + SILC_FSM_CONTINUE; } if (client->internal->stop) { @@ -533,12 +533,12 @@ SILC_FSM_STATE(silc_client_st_run) SILC_LOG_DEBUG(("Event: stop")); if (silc_atomic_get_int16(&client->internal->conns) == 0) silc_fsm_next(fsm, silc_client_st_stop); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* NOT REACHED */ SILC_ASSERT(FALSE); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Stop event. Stops the client library. */ @@ -557,7 +557,7 @@ SILC_FSM_STATE(silc_client_st_stop) if (client->internal->running) client->internal->running(client, client->internal->running_context); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /******************************* Private API ********************************/ @@ -853,7 +853,7 @@ void silc_client_close_connection(SilcClient client, /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } } @@ -1121,12 +1121,12 @@ SilcBool silc_client_init(SilcClient client, const char *username, client->internal->running = running; client->internal->running_context = context; silc_fsm_init(&client->internal->fsm, client, NULL, NULL, client->schedule); - silc_fsm_sema_init(&client->internal->wait_event, &client->internal->fsm, 0); + 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_SEMA_POST(&client->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); return TRUE; } @@ -1163,5 +1163,5 @@ void silc_client_stop(SilcClient client, SilcClientStopped stopped, /* Signal to stop */ client->internal->stop = TRUE; - SILC_FSM_SEMA_POST(&client->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&client->internal->wait_event); } diff --git a/lib/silcclient/client_channel.c b/lib/silcclient/client_channel.c index 34d51c64..59902d84 100644 --- a/lib/silcclient/client_channel.c +++ b/lib/silcclient/client_channel.c @@ -166,7 +166,7 @@ SILC_FSM_STATE(silc_client_channel_message) if (silc_unlikely(packet->dst_id_type != SILC_ID_CHANNEL)) { /** Invalid packet */ silc_fsm_next(fsm, silc_client_channel_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (silc_unlikely(!silc_id_str2id(packet->src_id, @@ -174,7 +174,7 @@ SILC_FSM_STATE(silc_client_channel_message) &remote_id, sizeof(remote_id)))) { /** Invalid source ID */ silc_fsm_next(fsm, silc_client_channel_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Get sender client entry */ @@ -194,7 +194,7 @@ SILC_FSM_STATE(silc_client_channel_message) sizeof(channel_id)))) { /** Invalid destination ID */ silc_fsm_next(fsm, silc_client_channel_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Find the channel */ @@ -202,7 +202,7 @@ SILC_FSM_STATE(silc_client_channel_message) if (silc_unlikely(!channel)) { /** Unknown channel */ silc_fsm_next(fsm, silc_client_channel_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Check that user is on channel */ @@ -211,7 +211,7 @@ SILC_FSM_STATE(silc_client_channel_message) SILC_LOG_WARNING(("Message from user not on channel, client or " "server bug")); silc_fsm_next(fsm, silc_client_channel_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* If there is no channel private key then just decrypt the message @@ -295,7 +295,7 @@ SILC_FSM_STATE(silc_client_channel_message) silc_client_unref_channel(client, conn, channel); if (payload) silc_message_payload_free(payload); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Channel message error. */ @@ -304,7 +304,7 @@ SILC_FSM_STATE(silc_client_channel_message_error) { SilcPacket packet = state_context; silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /******************************* Channel Key ********************************/ @@ -455,7 +455,7 @@ SILC_FSM_STATE(silc_client_channel_key) silc_client_save_channel_key(client, conn, &packet->buffer, NULL); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /**************************** Channel Private Key ***************************/ diff --git a/lib/silcclient/client_connect.c b/lib/silcclient/client_connect.c index ccf5793c..b9267fb1 100644 --- a/lib/silcclient/client_connect.c +++ b/lib/silcclient/client_connect.c @@ -370,7 +370,7 @@ SILC_FSM_STATE(silc_client_st_connect) conn->callback(client, conn, SILC_CLIENT_CONN_ERROR, 0, NULL, conn->callback_context); silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Connect (UDP) */ @@ -404,7 +404,7 @@ SILC_FSM_STATE(silc_client_st_connect_set_stream) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Create packet stream */ @@ -417,14 +417,14 @@ SILC_FSM_STATE(silc_client_st_connect_set_stream) conn->callback(client, conn, SILC_CLIENT_CONN_ERROR, 0, NULL, conn->callback_context); silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } silc_packet_set_context(conn->stream, conn); /** Start key exchange */ silc_fsm_next(fsm, silc_client_st_connect_key_exchange); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Starts key exchange protocol with remote host */ @@ -447,7 +447,7 @@ SILC_FSM_STATE(silc_client_st_connect_key_exchange) conn->callback(client, conn, SILC_CLIENT_CONN_ERROR_KE, 0, NULL, conn->callback_context); silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Set SKE callbacks */ @@ -494,7 +494,7 @@ SILC_FSM_STATE(silc_client_st_connect_setup_udp) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Create new UDP stream */ @@ -508,13 +508,12 @@ SILC_FSM_STATE(silc_client_st_connect_setup_udp) conn->callback(client, conn, SILC_CLIENT_CONN_ERROR, 0, NULL, conn->callback_context); silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Set the new stream to packet stream */ old = silc_packet_stream_get_stream(conn->stream); - silc_packet_stream_set_stream(conn->stream, stream, - conn->internal->schedule); + silc_packet_stream_set_stream(conn->stream, stream); silc_packet_stream_set_iv_included(conn->stream); silc_packet_set_sid(conn->stream, 0); @@ -523,7 +522,7 @@ SILC_FSM_STATE(silc_client_st_connect_setup_udp) /** Start authentication */ silc_fsm_next(fsm, silc_client_st_connect_auth); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Get authentication method to be used in authentication protocol */ @@ -538,7 +537,7 @@ SILC_FSM_STATE(silc_client_st_connect_auth) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } silc_fsm_next(fsm, silc_client_st_connect_auth_start); @@ -555,7 +554,7 @@ SILC_FSM_STATE(silc_client_st_connect_auth) conn->internal->params.auth = conn->private_key; /* We have authentication data */ - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Start connection authentication with remote host */ @@ -571,7 +570,7 @@ SILC_FSM_STATE(silc_client_st_connect_auth_start) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Allocate connection authentication protocol */ @@ -583,7 +582,7 @@ SILC_FSM_STATE(silc_client_st_connect_auth_start) conn->callback(client, conn, SILC_CLIENT_CONN_ERROR_AUTH, 0, NULL, conn->callback_context); silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /** Start connection authentication */ @@ -610,7 +609,7 @@ SILC_FSM_STATE(silc_client_st_connected) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_connect_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } SILC_LOG_DEBUG(("Connection established")); @@ -634,7 +633,7 @@ SILC_FSM_STATE(silc_client_st_connected) silc_fsm_next(fsm, silc_client_st_register); } - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } silc_schedule_task_del_by_all(conn->internal->schedule, 0, @@ -644,7 +643,7 @@ SILC_FSM_STATE(silc_client_st_connected) conn->callback(client, conn, SILC_CLIENT_CONN_SUCCESS, 0, NULL, conn->callback_context); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Error during connecting */ @@ -661,13 +660,13 @@ SILC_FSM_STATE(silc_client_st_connect_error) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } silc_schedule_task_del_by_all(conn->internal->schedule, 0, silc_client_connect_timeout, conn); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /****************************** Connect rekey *******************************/ @@ -681,7 +680,7 @@ SILC_TASK_CALLBACK(silc_client_rekey_timer) /* Signal to start rekey */ conn->internal->rekey_responder = FALSE; conn->internal->rekeying = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); /* Reinstall rekey timer */ silc_schedule_task_add_timeout(conn->internal->schedule, @@ -699,7 +698,7 @@ SILC_FSM_STATE(silc_client_st_rekey) SILC_LOG_DEBUG(("Rekey")); if (conn->internal->disconnected) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; /* Allocate SKE */ conn->internal->ske = @@ -707,7 +706,7 @@ SILC_FSM_STATE(silc_client_st_rekey) conn->internal->params.repository, conn->public_key, conn->private_key, fsm); if (!conn->internal->ske) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; /* Set SKE callbacks */ silc_ske_set_callbacks(conn->internal->ske, NULL, diff --git a/lib/silcclient/client_entry.c b/lib/silcclient/client_entry.c index 09276069..e3f2eafa 100644 --- a/lib/silcclient/client_entry.c +++ b/lib/silcclient/client_entry.c @@ -730,7 +730,7 @@ SilcClientEntry silc_client_add_client(SilcClient client, } /* Format the nickname */ - silc_client_nickname_format(client, conn, client_entry); + silc_client_nickname_format(client, conn, client_entry, FALSE); silc_mutex_lock(conn->internal->lock); @@ -790,7 +790,8 @@ void silc_client_update_client(SilcClient client, return; /* Format nickname */ - silc_client_nickname_format(client, conn, client_entry); + silc_client_nickname_format(client, conn, client_entry, + client_entry == conn->local_entry); /* Update cache entry */ silc_mutex_lock(conn->internal->lock); @@ -836,7 +837,8 @@ SilcBool silc_client_change_nickname(SilcClient client, memset(client_entry->nickname, 0, sizeof(client_entry->nickname)); memcpy(client_entry->nickname, new_nick, strlen(new_nick)); client_entry->nickname_normalized = tmp; - silc_client_nickname_format(client, conn, client_entry); + silc_client_nickname_format(client, conn, client_entry, + client_entry == conn->local_entry); /* For my client entry, update ID and set new ID to packet stream */ if (client_entry == conn->local_entry) { @@ -955,11 +957,13 @@ void silc_client_list_free(SilcClient client, SilcClientConnection conn, /* Formats the nickname of the client specified by the `client_entry'. If the format is specified by the application this will format the nickname and replace the old nickname in the client entry. If the - format string is not specified then this function has no effect. */ + format string is not specified then this function has no effect. + Returns the client entry that was formatted. */ -void silc_client_nickname_format(SilcClient client, - SilcClientConnection conn, - SilcClientEntry client_entry) +SilcClientEntry silc_client_nickname_format(SilcClient client, + SilcClientConnection conn, + SilcClientEntry client_entry, + SilcBool priority) { char *cp; char newnick[128 + 1]; @@ -968,44 +972,45 @@ void silc_client_nickname_format(SilcClient client, SilcDList clients; SilcClientEntry entry, unformatted = NULL; - SILC_LOG_DEBUG(("Start")); + SILC_LOG_DEBUG(("Format nickname")); if (!client->internal->params->nickname_format[0]) - return; - + return client_entry; if (!client_entry->nickname[0]) - return; + return NULL; /* Get all clients with same nickname. Do not perform the formatting if there aren't any clients with same nickname unless the application is forcing us to do so. */ clients = silc_client_get_clients_local(client, conn, client_entry->nickname, NULL); - if (!clients && !client->internal->params->nickname_force_format) - return; + if (!clients) + return NULL; + if (silc_dlist_count(clients) == 1 && + !client->internal->params->nickname_force_format) { + silc_client_list_free(client, conn, clients); + return client_entry; + } - if (clients) { - len = 0; - freebase = TRUE; - while ((entry = silc_dlist_get(clients))) { - if (entry->internal.valid && entry != client_entry) - len++; - if (entry->internal.valid && entry != client_entry && - silc_utf8_strcasecmp(entry->nickname, client_entry->nickname)) { - freebase = FALSE; - unformatted = entry; - } - } - if (!len || freebase) { - silc_client_list_free(client, conn, clients); - return; + len = 0; + freebase = TRUE; + while ((entry = silc_dlist_get(clients))) { + if (entry->internal.valid && entry != client_entry) + len++; + if (entry->internal.valid && entry != client_entry && + silc_utf8_strcasecmp(entry->nickname, client_entry->nickname)) { + freebase = FALSE; + unformatted = entry; + break; } } + if (!len || freebase) { + silc_client_list_free(client, conn, clients); + return client_entry; + } - /* If we are changing nickname of our local entry we'll enforce - that we will always get the unformatted nickname. Give our - format number to the one that is not formatted now. */ - if (unformatted && client_entry == conn->local_entry) + /* If priority formatting, this client always gets unformatted nickname. */ + if (unformatted && priority) client_entry = unformatted; memset(newnick, 0, sizeof(newnick)); @@ -1066,20 +1071,18 @@ void silc_client_nickname_format(SilcClient client, char tmp[6]; int num, max = 1; - if (clients && silc_dlist_count(clients) == 1) + if (silc_dlist_count(clients) == 1) break; - if (clients) { - silc_dlist_start(clients); - while ((entry = silc_dlist_get(clients))) { - if (!silc_utf8_strncasecmp(entry->nickname, newnick, off)) - continue; - if (strlen(entry->nickname) <= off) - continue; - num = atoi(&entry->nickname[off]); - if (num > max) - max = num; - } + silc_dlist_start(clients); + while ((entry = silc_dlist_get(clients))) { + if (!silc_utf8_strncasecmp(entry->nickname, newnick, off)) + continue; + if (strlen(entry->nickname) <= off) + continue; + num = atoi(&entry->nickname[off]); + if (num > max) + max = num; } memset(tmp, 0, sizeof(tmp)); @@ -1102,6 +1105,79 @@ void silc_client_nickname_format(SilcClient client, newnick[off] = 0; memcpy(client_entry->nickname, newnick, strlen(newnick)); silc_client_list_free(client, conn, clients); + + return client_entry; +} + +/* Parses nickname according to nickname format string */ + +SilcBool silc_client_nickname_parse(SilcClient client, + SilcClientConnection conn, + char *nickname, + char **ret_nick) +{ + char *cp, s = 0, e = 0, *nick; + SilcBool n = FALSE; + int len; + + if (!client->internal->params->nickname_format[0]) + return TRUE; + + if (!nickname || !nickname[0]) + return FALSE; + + cp = client->internal->params->nickname_format; + while (cp && *cp) { + if (*cp == '%') { + cp++; + continue; + } + + switch(*cp) { + case 'n': + n = TRUE; + break; + + case 'h': + case 'H': + case 's': + case 'S': + case 'a': + break; + + default: + /* Get separator character */ + if (n) + e = *cp; + else + s = *cp; + break; + } + + cp++; + } + if (!n) + return FALSE; + + /* Parse the nickname */ + nick = nickname; + len = strlen(nick); + if (s) + if (strchr(nickname, s)) + nick = strchr(nickname, s) + 1; + if (e) + if (strchr(nick, e)) + len = strchr(nick, e) - nick; + if (!len) + return FALSE; + + *ret_nick = silc_memdup(nick, len); + if (!(*ret_nick)) + return FALSE; + + SILC_LOG_DEBUG(("Parsed nickname: %s", *ret_nick)); + + return TRUE; } /************************ Channel Searching Locally *************************/ diff --git a/lib/silcclient/client_entry.h b/lib/silcclient/client_entry.h index 195edd58..cc53370e 100644 --- a/lib/silcclient/client_entry.h +++ b/lib/silcclient/client_entry.h @@ -66,8 +66,9 @@ bool silc_client_replace_channel_id(SilcClient client, SilcClientConnection conn, SilcChannelEntry channel, SilcChannelID *new_id); -void silc_client_nickname_format(SilcClient client, - SilcClientConnection conn, - SilcClientEntry client_entry); +SilcBool silc_client_nickname_parse(SilcClient client, + SilcClientConnection conn, + char *nickname, + char **ret_nick); #endif /* CLIENT_ENTRY_H */ diff --git a/lib/silcclient/client_internal.h b/lib/silcclient/client_internal.h index 4478142f..75425acb 100644 --- a/lib/silcclient/client_internal.h +++ b/lib/silcclient/client_internal.h @@ -138,7 +138,7 @@ typedef struct SilcClientCommandContextStruct { /* Internal context for the client->internal pointer in the SilcClient. */ struct SilcClientInternalStruct { SilcFSMStruct fsm; /* Client's FSM */ - SilcFSMSemaStruct wait_event; /* Event signaller */ + SilcFSMEventStruct wait_event; /* Event signaller */ SilcClientOperations *ops; /* Client operations */ SilcClientParams *params; /* Client parameters */ SilcPacketEngine packet_engine; /* Packet engine */ @@ -160,7 +160,7 @@ struct SilcClientConnectionInternalStruct { SilcClientConnectionParams params; /* Connection parameters */ SilcFSMStruct fsm; /* Connection FSM */ SilcFSMThreadStruct event_thread; /* FSM thread for events */ - SilcFSMSemaStruct wait_event; /* Event signaller */ + SilcFSMEventStruct wait_event; /* Event signaller */ SilcSchedule schedule; /* Connection's scheduler */ SilcMutex lock; /* Connection lock */ SilcSKE ske; /* Key exchange protocol */ diff --git a/lib/silcclient/client_keyagr.c b/lib/silcclient/client_keyagr.c index d5f90485..34a160b9 100644 --- a/lib/silcclient/client_keyagr.c +++ b/lib/silcclient/client_keyagr.c @@ -649,14 +649,14 @@ SILC_FSM_STATE(silc_client_key_agreement) if (packet->src_id_type != SILC_ID_CLIENT) { /** Invalid packet */ silc_fsm_next(fsm, silc_client_key_agreement_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (!silc_id_str2id(packet->src_id, packet->src_id_len, SILC_ID_CLIENT, &remote_id, sizeof(remote_id))) { /** Invalid source ID */ silc_fsm_next(fsm, silc_client_key_agreement_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Check whether we know this client already */ @@ -677,7 +677,7 @@ SILC_FSM_STATE(silc_client_key_agreement) /** Malformed Payload */ SILC_LOG_DEBUG(("Malformed key agreement payload")); silc_fsm_next(fsm, silc_client_key_agreement_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* If remote did not provide connection endpoint, we will assume that we @@ -697,7 +697,7 @@ SILC_FSM_STATE(silc_client_key_agreement) silc_key_agreement_payload_free(payload); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Key agreement packet processing error */ @@ -706,5 +706,5 @@ SILC_FSM_STATE(silc_client_key_agreement_error) { SilcPacket packet = state_context; silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index e8665f74..a8bdf31a 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -95,21 +95,21 @@ SILC_FSM_STATE(silc_client_notify) if (!payload) { SILC_LOG_DEBUG(("Malformed notify payload")); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } if (!silc_notify_get_args(payload)) { SILC_LOG_DEBUG(("Malformed notify %d", silc_notify_get_type(payload))); silc_notify_payload_free(payload); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } notify = silc_calloc(1, sizeof(*notify)); if (!notify) { silc_notify_payload_free(payload); silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Save notify payload to packet context during processing */ @@ -206,11 +206,11 @@ SILC_FSM_STATE(silc_client_notify) silc_notify_payload_free(payload); silc_packet_free(packet); silc_free(notify); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; break; } - return SILC_FSM_YIELD; + SILC_FSM_YIELD; } /* Notify processed, finish the packet processing thread */ @@ -224,7 +224,7 @@ SILC_FSM_STATE(silc_client_notify_processed) silc_notify_payload_free(payload); silc_packet_free(packet); silc_free(notify); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** NONE ************************************/ @@ -245,7 +245,7 @@ SILC_FSM_STATE(silc_client_notify_none) /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* INVITE ***********************************/ @@ -318,7 +318,7 @@ SILC_FSM_STATE(silc_client_notify_invite) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** JOIN ************************************/ @@ -379,7 +379,7 @@ SILC_FSM_STATE(silc_client_notify_join) } if (client_entry != conn->local_entry) - silc_client_nickname_format(client, conn, client_entry); + silc_client_nickname_format(client, conn, client_entry, FALSE); /* Join the client to channel */ if (!silc_client_add_to_channel(client, conn, channel, client_entry, 0)) @@ -394,7 +394,7 @@ SILC_FSM_STATE(silc_client_notify_join) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** LEAVE ***********************************/ @@ -456,7 +456,7 @@ SILC_FSM_STATE(silc_client_notify_leave) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* SIGNOFF **********************************/ @@ -503,7 +503,7 @@ SILC_FSM_STATE(silc_client_notify_signoff) out: /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** TOPIC_SET *********************************/ @@ -620,7 +620,7 @@ SILC_FSM_STATE(silc_client_notify_topic_set) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /****************************** NICK_CHANGE *********************************/ @@ -704,7 +704,7 @@ SILC_FSM_STATE(silc_client_notify_nick_change) /** Notify processed */ silc_client_unref_client(client, conn, client_entry); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /****************************** CMODE_CHANGE ********************************/ @@ -884,7 +884,7 @@ SILC_FSM_STATE(silc_client_notify_cmode_change) /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /***************************** CUMODE_CHANGE ********************************/ @@ -1022,7 +1022,7 @@ SILC_FSM_STATE(silc_client_notify_cumode_change) /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* MOTD *************************************/ @@ -1053,7 +1053,7 @@ SILC_FSM_STATE(silc_client_notify_motd) out: /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /**************************** CHANNEL CHANGE ********************************/ @@ -1108,7 +1108,7 @@ SILC_FSM_STATE(silc_client_notify_channel_change) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** KICKED ************************************/ @@ -1204,7 +1204,7 @@ SILC_FSM_STATE(silc_client_notify_kicked) /** Notify processed */ silc_client_unref_channel(client, conn, channel); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** KILLED ************************************/ @@ -1307,7 +1307,7 @@ SILC_FSM_STATE(silc_client_notify_killed) /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /**************************** SERVER SIGNOFF ********************************/ @@ -1359,7 +1359,7 @@ SILC_FSM_STATE(silc_client_notify_server_signoff) /** Notify processed */ silc_client_list_free(client, conn, clients); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** ERROR *************************************/ @@ -1406,7 +1406,7 @@ SILC_FSM_STATE(silc_client_notify_error) out: /** Notify processed */ silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** WATCH *************************************/ @@ -1465,11 +1465,8 @@ SILC_FSM_STATE(silc_client_notify_watch) if (tmp) { char *tmp_nick = NULL; - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(client_entry->nickname, - &tmp_nick); - else - tmp_nick = strdup(tmp); + silc_client_nickname_parse(client, conn, client_entry->nickname, + &tmp_nick); /* If same nick, the client was new to us and has become "present" to network. Send NULL as nick to application. */ @@ -1517,5 +1514,5 @@ SILC_FSM_STATE(silc_client_notify_watch) /** Notify processed */ silc_client_unref_client(client, conn, client_entry); silc_fsm_next(fsm, silc_client_notify_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index ab5665ea..be129c1c 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -117,7 +117,7 @@ SILC_FSM_STATE(silc_client_private_message) if (silc_unlikely(packet->src_id_type != SILC_ID_CLIENT)) { /** Invalid packet */ silc_fsm_next(fsm, silc_client_private_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (silc_unlikely(!silc_id_str2id(packet->src_id, packet->src_id_len, @@ -125,7 +125,7 @@ SILC_FSM_STATE(silc_client_private_message) sizeof(remote_id)))) { /** Invalid source ID */ silc_fsm_next(fsm, silc_client_private_message_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Check whether we know this client already */ @@ -207,7 +207,7 @@ SILC_FSM_STATE(silc_client_private_message) silc_client_unref_client(client, conn, remote_client); if (payload) silc_message_payload_free(payload); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Private message error. */ @@ -216,7 +216,7 @@ SILC_FSM_STATE(silc_client_private_message_error) { SilcPacket packet = state_context; silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } #if 0 /* XXX we need to rethink this */ @@ -429,13 +429,13 @@ SILC_FSM_STATE(silc_client_private_message_key) if (packet->src_id_type != SILC_ID_CLIENT) { silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } if (!silc_id_str2id(packet->src_id, packet->src_id_len, SILC_ID_CLIENT, &remote_id, sizeof(remote_id))) { silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Always resolve the remote client. The actual packet is processed diff --git a/lib/silcclient/client_register.c b/lib/silcclient/client_register.c index c5f4cfc9..f029c480 100644 --- a/lib/silcclient/client_register.c +++ b/lib/silcclient/client_register.c @@ -144,7 +144,7 @@ SILC_FSM_STATE(silc_client_new_id) out: /** Packet processed */ silc_packet_free(packet); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } @@ -170,14 +170,14 @@ SILC_FSM_STATE(silc_client_st_register) SILC_STR_END)) { /** Error sending packet */ silc_fsm_next(fsm, silc_client_st_register_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /** Wait for new ID */ conn->internal->registering = TRUE; silc_fsm_next_later(fsm, silc_client_st_register_complete, conn->internal->retry_timer, 0); - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Wait for NEW_ID packet to arrive */ @@ -190,7 +190,7 @@ SILC_FSM_STATE(silc_client_st_register_complete) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_register_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (!conn->local_id) { @@ -200,7 +200,7 @@ SILC_FSM_STATE(silc_client_st_register_complete) conn->internal->retry_count = 0; conn->internal->retry_timer = SILC_CLIENT_RETRY_MIN; silc_fsm_next(fsm, silc_client_st_register_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /** Resend registering packet */ @@ -209,7 +209,7 @@ SILC_FSM_STATE(silc_client_st_register_complete) SILC_CLIENT_RETRY_MUL) + (silc_rng_get_rn16(client->rng) % SILC_CLIENT_RETRY_RAND)); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } SILC_LOG_DEBUG(("Registered to network")); @@ -243,7 +243,7 @@ SILC_FSM_STATE(silc_client_st_register_complete) silc_schedule_task_del_by_all(conn->internal->schedule, 0, silc_client_connect_timeout, conn); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Error registering to network */ @@ -258,7 +258,7 @@ SILC_FSM_STATE(silc_client_st_register_error) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } /* Call connect callback */ @@ -270,7 +270,7 @@ SILC_FSM_STATE(silc_client_st_register_error) silc_schedule_task_del_by_all(conn->internal->schedule, 0, silc_client_connect_timeout, conn); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /************************* Resume detached session **************************/ @@ -294,7 +294,7 @@ SILC_FSM_STATE(silc_client_st_resume) if (!resume) { /** Out of memory */ silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } silc_fsm_set_state_context(fsm, resume); @@ -316,7 +316,7 @@ SILC_FSM_STATE(silc_client_st_resume) /** Malformed detach data */ SILC_LOG_DEBUG(("Malformed detachment data")); silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (!silc_id_str2id(id, id_len, SILC_ID_CLIENT, &client_id, @@ -324,7 +324,7 @@ SILC_FSM_STATE(silc_client_st_resume) /** Malformed ID */ SILC_LOG_DEBUG(("Malformed ID")); silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Generate authentication data that server will verify */ @@ -336,7 +336,7 @@ SILC_FSM_STATE(silc_client_st_resume) if (!auth) { /** Out of memory */ silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Send RESUME_CLIENT packet to resume to network */ @@ -349,13 +349,13 @@ SILC_FSM_STATE(silc_client_st_resume) /** Error sending packet */ SILC_LOG_DEBUG(("Error sending packet")); silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /** Wait for new ID */ conn->internal->registering = TRUE; silc_fsm_next_later(fsm, silc_client_st_resume_resolve_channels, 15, 0); - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Resolve the old session information, user mode and joined channels. */ @@ -372,16 +372,19 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_channels) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (!conn->local_id) { /** Timeout, ID not received */ conn->internal->registering = FALSE; silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } + /** Wait for channels */ + silc_fsm_next(fsm, silc_client_st_resume_resolve_cmodes); + /* Change our nickname */ silc_client_change_nickname(client, conn, conn->local_entry, resume->nickname, NULL, NULL, 0); @@ -393,6 +396,9 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_channels) 1, 1, silc_buffer_data(conn->internal->local_idp), silc_buffer_len(conn->internal->local_idp)); + if (!resume->channel_count) + SILC_FSM_YIELD; + /* Send IDENTIFY command for all channels we know about. These are the channels we've joined to according our detachment data. */ for (i = 0; i < resume->channel_count; i++) { @@ -447,9 +453,7 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_channels) silc_free(res_argv_lens); silc_free(res_argv_types); - /** Wait for channels */ - silc_fsm_next(fsm, silc_client_st_resume_resolve_cmodes); - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Resolve joined channel modes, users and topics. */ @@ -467,7 +471,7 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_cmodes) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } SILC_LOG_DEBUG(("Resolving channel details")); @@ -476,7 +480,7 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_cmodes) silc_fsm_next(fsm, silc_client_st_resume_completed); if (!silc_idcache_get_all(conn->internal->channel_cache, &channels)) - return SILC_FSM_CONTINUE; + SILC_FSM_YIELD; /* Resolve channels' mode, users and topic */ resume->channel_count = silc_list_count(channels) * 3; @@ -502,7 +506,7 @@ SILC_FSM_STATE(silc_client_st_resume_resolve_cmodes) silc_buffer_free(idp); } - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Resuming completed */ @@ -519,13 +523,13 @@ SILC_FSM_STATE(silc_client_st_resume_completed) if (conn->internal->disconnected) { /** Disconnected */ silc_fsm_next(fsm, silc_client_st_resume_error); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } if (resume->channel_count > 0) { resume->channel_count--; if (resume->channel_count) - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } SILC_LOG_DEBUG(("Resuming completed")); @@ -548,6 +552,11 @@ SILC_FSM_STATE(silc_client_st_resume_completed) conn->callback(client, conn, SILC_CLIENT_CONN_SUCCESS_RESUME, 0, NULL, conn->callback_context); + /* Call UMODE command reply. */ + if (conn->local_entry->mode) + silc_client_resume_command_callback(client, conn, SILC_COMMAND_UMODE, + conn->local_entry->mode); + /* Call NICK command reply. */ silc_client_resume_command_callback(client, conn, SILC_COMMAND_NICK, conn->local_entry, @@ -582,7 +591,7 @@ SILC_FSM_STATE(silc_client_st_resume_completed) silc_free(resume->nickname); silc_free(resume); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Error resuming to network */ @@ -598,7 +607,7 @@ SILC_FSM_STATE(silc_client_st_resume_error) silc_free(resume->nickname); silc_free(resume); } - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } SILC_LOG_DEBUG(("Error resuming to network")); @@ -606,7 +615,7 @@ SILC_FSM_STATE(silc_client_st_resume_error) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } /* Call connect callback */ @@ -623,7 +632,7 @@ SILC_FSM_STATE(silc_client_st_resume_error) silc_free(resume); } - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Generates the session detachment data. This data can be used later diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 602c5278..a1050556 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -68,7 +68,7 @@ static SilcUInt16 silc_client_cmd_ident(SilcClientConnection conn) SILC_FSM_STATE(silc_client_command_continue_error) { /* Destructor will free all resources */ - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Command reply callback to continue with the execution of a command. @@ -626,7 +626,7 @@ SILC_FSM_STATE(silc_client_command_whois) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } for (i = 1; i < cmd->argc; i++) { @@ -717,10 +717,10 @@ SILC_FSM_STATE(silc_client_command_whois) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /******************************** WHOWAS ************************************/ @@ -740,7 +740,7 @@ SILC_FSM_STATE(silc_client_command_whowas) "Usage: /WHOWAS [@] []"); COMMAND_ERROR((cmd->argc < 2 ? SILC_STATUS_ERR_NOT_ENOUGH_PARAMS : SILC_STATUS_ERR_TOO_MANY_PARAMS)); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } if (cmd->argc == 2) { @@ -759,7 +759,7 @@ SILC_FSM_STATE(silc_client_command_whowas) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** IDENTIFY **********************************/ @@ -775,7 +775,7 @@ SILC_FSM_STATE(silc_client_command_identify) int c; if (cmd->argc < 2 || cmd->argc > 3) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; if (cmd->argc == 2) { silc_client_command_send_va(conn, cmd, cmd->cmd, NULL, NULL, @@ -790,7 +790,7 @@ SILC_FSM_STATE(silc_client_command_identify) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** NICK ************************************/ @@ -840,10 +840,10 @@ SILC_FSM_STATE(silc_client_command_nick) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** LIST ************************************/ @@ -877,7 +877,7 @@ SILC_FSM_STATE(silc_client_command_list) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** TOPIC ***********************************/ @@ -940,10 +940,10 @@ SILC_FSM_STATE(silc_client_command_topic) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************* INVITE ***********************************/ @@ -993,10 +993,7 @@ SILC_FSM_STATE(silc_client_command_invite) /* Parse the typed nickname. */ if (cmd->argc == 3) { if (cmd->argv[2][0] != '+' && cmd->argv[2][0] != '-') { - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(cmd->argv[2], &nickname); - else - nickname = strdup(cmd->argv[2]); + silc_client_nickname_parse(client, conn, cmd->argv[2], &nickname); /* Find client entry */ clients = silc_client_get_clients_local(client, conn, nickname, @@ -1067,11 +1064,11 @@ SILC_FSM_STATE(silc_client_command_invite) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: silc_free(nickname); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** QUIT ************************************/ @@ -1098,10 +1095,10 @@ SILC_FSM_STATE(silc_client_command_quit_final) /* Signal to close connection */ if (!conn->internal->disconnected) { conn->internal->disconnected = TRUE; - SILC_FSM_SEMA_POST(&conn->internal->wait_event); + SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event); } - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Command QUIT. Closes connection with current server. */ @@ -1122,7 +1119,7 @@ SILC_FSM_STATE(silc_client_command_quit) /* We close the connection with a little timeout */ silc_fsm_next_later(fsm, silc_client_command_quit_final, 2, 0); - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /********************************** KILL ************************************/ @@ -1145,16 +1142,12 @@ SILC_FSM_STATE(silc_client_command_kill) SAY(conn->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /KILL [] [-pubkey]"); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Parse the typed nickname. */ - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(cmd->argv[1], &nickname); - else - nickname = strdup(cmd->argv[1]); - if (!nickname) - return SILC_FSM_FINISH; + if (!silc_client_nickname_parse(client, conn, cmd->argv[1], &nickname)) + SILC_FSM_FINISH; /* Get the target client */ clients = silc_client_get_clients_local(client, conn, nickname, @@ -1199,7 +1192,7 @@ SILC_FSM_STATE(silc_client_command_kill) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** INFO ************************************/ @@ -1224,7 +1217,7 @@ SILC_FSM_STATE(silc_client_command_info) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** STATS ***********************************/ @@ -1246,7 +1239,7 @@ SILC_FSM_STATE(silc_client_command_stats) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** PING ************************************/ @@ -1260,7 +1253,7 @@ SILC_FSM_STATE(silc_client_command_ping) if (cmd->argc < 2) { COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Send the command */ @@ -1276,7 +1269,7 @@ SILC_FSM_STATE(silc_client_command_ping) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** JOIN ************************************/ @@ -1391,10 +1384,10 @@ SILC_FSM_STATE(silc_client_command_join) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** MOTD ************************************/ @@ -1411,7 +1404,7 @@ SILC_FSM_STATE(silc_client_command_motd) "Usage: /MOTD []"); COMMAND_ERROR((cmd->argc < 1 ? SILC_STATUS_ERR_NOT_ENOUGH_PARAMS : SILC_STATUS_ERR_TOO_MANY_PARAMS)); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Send the command */ @@ -1428,7 +1421,7 @@ SILC_FSM_STATE(silc_client_command_motd) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** UMODE ***********************************/ @@ -1448,7 +1441,7 @@ SILC_FSM_STATE(silc_client_command_umode) SAY(conn->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /UMODE +|-"); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } mode = conn->local_entry->mode; @@ -1549,7 +1542,7 @@ SILC_FSM_STATE(silc_client_command_umode) break; default: COMMAND_ERROR(SILC_STATUS_ERR_UNKNOWN_MODE); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; break; } } @@ -1567,7 +1560,7 @@ SILC_FSM_STATE(silc_client_command_umode) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** CMODE ***********************************/ @@ -1860,10 +1853,10 @@ SILC_FSM_STATE(silc_client_command_cmode) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************* CUMODE ***********************************/ @@ -1910,10 +1903,7 @@ SILC_FSM_STATE(silc_client_command_cumode) } /* Parse the typed nickname. */ - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(cmd->argv[3], &nickname); - else - nickname = strdup(cmd->argv[3]); + silc_client_nickname_parse(client, conn, cmd->argv[3], &nickname); /* Find client entry */ clients = silc_client_get_clients_local(client, conn, nickname, @@ -2042,12 +2032,12 @@ SILC_FSM_STATE(silc_client_command_cumode) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: silc_client_list_free(client, conn, clients); silc_free(nickname); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** KICK ************************************/ @@ -2096,10 +2086,7 @@ SILC_FSM_STATE(silc_client_command_kick) } /* Parse the typed nickname. */ - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(cmd->argv[2], &nickname); - else - nickname = strdup(cmd->argv[2]); + silc_client_nickname_parse(client, conn, cmd->argv[2], &nickname); /* Get the target client */ clients = silc_client_get_clients_local(client, conn, nickname, @@ -2135,11 +2122,11 @@ SILC_FSM_STATE(silc_client_command_kick) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: silc_free(nickname); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /***************************** OPER & SILCOPER ******************************/ @@ -2204,7 +2191,7 @@ SILC_FSM_STATE(silc_client_command_oper_send) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* OPER command. Used to obtain server operator privileges. */ @@ -2219,14 +2206,14 @@ SILC_FSM_STATE(silc_client_command_oper) SAY(conn->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /OPER [-pubkey]"); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Get passphrase */ if (cmd->argc < 3) { oper = silc_calloc(1, sizeof(*oper)); if (!oper) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; cmd->context = oper; SILC_FSM_CALL(conn->client->internal-> ops->ask_passphrase(conn->client, conn, @@ -2234,7 +2221,7 @@ SILC_FSM_STATE(silc_client_command_oper) } silc_fsm_next(fsm, silc_client_command_oper_send); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* SILCOPER command. Used to obtain router operator privileges. */ @@ -2249,14 +2236,14 @@ SILC_FSM_STATE(silc_client_command_silcoper) SAY(conn->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /SILCOPER [-pubkey]"); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Get passphrase */ if (cmd->argc < 3) { oper = silc_calloc(1, sizeof(*oper)); if (!oper) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; cmd->context = oper; SILC_FSM_CALL(conn->client->internal-> ops->ask_passphrase(conn->client, conn, @@ -2264,7 +2251,7 @@ SILC_FSM_STATE(silc_client_command_silcoper) } silc_fsm_next(fsm, silc_client_command_oper_send); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /*********************************** BAN ************************************/ @@ -2351,10 +2338,10 @@ SILC_FSM_STATE(silc_client_command_ban) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************* DETACH ***********************************/ @@ -2373,7 +2360,7 @@ SILC_FSM_STATE(silc_client_command_detach) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** WATCH ***********************************/ @@ -2445,10 +2432,10 @@ SILC_FSM_STATE(silc_client_command_watch) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** LEAVE ***********************************/ @@ -2503,10 +2490,10 @@ SILC_FSM_STATE(silc_client_command_leave) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************** USERS ***********************************/ @@ -2546,10 +2533,10 @@ SILC_FSM_STATE(silc_client_command_users) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; out: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /********************************* GETKEY ***********************************/ @@ -2571,17 +2558,13 @@ SILC_FSM_STATE(silc_client_command_getkey) client->internal->ops->say(client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /GETKEY "); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Parse the typed nickname. */ - if (client->internal->params->nickname_parse) - client->internal->params->nickname_parse(cmd->argv[1], &nickname); - else - nickname = strdup(cmd->argv[1]); - if (!nickname) { + if (!silc_client_nickname_parse(client, conn, cmd->argv[1], &nickname)) { COMMAND_ERROR(SILC_STATUS_ERR_RESOURCE_LIMIT); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Find client entry */ @@ -2596,7 +2579,7 @@ SILC_FSM_STATE(silc_client_command_getkey) errors are handled in the resolving callback. */ COMMAND_ERROR(SILC_STATUS_ERR_NO_SUCH_NICK); COMMAND_ERROR(SILC_STATUS_ERR_NO_SUCH_SERVER); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* No client or server exist with this name, query for both. */ @@ -2631,7 +2614,7 @@ SILC_FSM_STATE(silc_client_command_getkey) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* SERVICE **********************************/ @@ -2651,7 +2634,7 @@ SILC_FSM_STATE(silc_client_command_service) SAY(conn->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /SERVICE [] [-pubkey]"); COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } name = cmd->argv[1]; @@ -2671,7 +2654,7 @@ SILC_FSM_STATE(silc_client_command_service) /** Wait for command reply */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Register all default commands provided by the client library for the @@ -2812,7 +2795,7 @@ SILC_FSM_STATE(silc_client_command) silc_buffer_len(&packet->buffer)); if (!payload) { SILC_LOG_DEBUG(("Bad command packet")); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Get arguments */ @@ -2824,7 +2807,7 @@ SILC_FSM_STATE(silc_client_command) case SILC_COMMAND_WHOIS: /* Ignore everything if requested by application */ - if (client->internal->params->ignore_requested_attributes) + if (conn->internal->params.ignore_requested_attributes) break; silc_client_command_process_whois(client, conn, payload, args); @@ -2835,5 +2818,5 @@ SILC_FSM_STATE(silc_client_command) } silc_command_payload_free(payload); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index bfc114fa..cf68fddd 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -47,7 +47,7 @@ do { \ ERROR_CALLBACK(cmd->error); \ silc_client_command_process_error(cmd, state_context, cmd->error); \ silc_fsm_next(fsm, silc_client_command_reply_processed); \ - return SILC_FSM_CONTINUE; \ + SILC_FSM_CONTINUE; \ } /* Check for correct arguments */ @@ -56,7 +56,7 @@ do { \ silc_argument_get_arg_num(args) > max) { \ ERROR_CALLBACK(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); \ silc_fsm_next(fsm, silc_client_command_reply_processed); \ - return SILC_FSM_CONTINUE; \ + SILC_FSM_CONTINUE; \ } #define SAY cmd->conn->client->internal->ops->say @@ -174,7 +174,7 @@ SILC_FSM_STATE(silc_client_command_reply) silc_packet_free(packet); if (!payload) { SILC_LOG_DEBUG(("Bad command reply packet")); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } cmd_ident = silc_command_get_ident(payload); @@ -196,7 +196,7 @@ SILC_FSM_STATE(silc_client_command_reply) SILC_LOG_DEBUG(("Unknown command reply %s, ident %d", silc_get_command_name(command), cmd_ident)); silc_command_payload_free(payload); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Signal command thread that command reply has arrived */ @@ -204,7 +204,7 @@ SILC_FSM_STATE(silc_client_command_reply) silc_fsm_next(&cmd->thread, silc_client_command_reply_process); silc_fsm_continue_sync(&cmd->thread); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Wait here for command reply to arrive from remote host */ @@ -219,7 +219,7 @@ SILC_FSM_STATE(silc_client_command_reply_wait) silc_fsm_set_state_context(fsm, NULL); silc_fsm_next_later(fsm, silc_client_command_reply_timeout, cmd->cmd != SILC_COMMAND_PING ? 25 : 60, 0); - return SILC_FSM_WAIT; + SILC_FSM_WAIT; } /* Timeout occurred while waiting command reply */ @@ -233,7 +233,7 @@ SILC_FSM_STATE(silc_client_command_reply_timeout) if (conn->internal->disconnected) { SILC_LOG_DEBUG(("Command %s canceled", silc_get_command_name(cmd->cmd))); silc_list_del(conn->internal->pending_commands, cmd); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } SILC_LOG_DEBUG(("Command %s timeout", silc_get_command_name(cmd->cmd))); @@ -241,7 +241,7 @@ SILC_FSM_STATE(silc_client_command_reply_timeout) /* Timeout, reply not received in timely fashion */ silc_list_del(conn->internal->pending_commands, cmd); ERROR_CALLBACK(SILC_STATUS_ERR_TIMEDOUT); - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } /* Process received command reply payload */ @@ -363,10 +363,10 @@ SILC_FSM_STATE(silc_client_command_reply_process) silc_fsm_next(fsm, silc_client_command_reply_service); break; default: - return SILC_FSM_FINISH; + SILC_FSM_FINISH; } - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /* Completes command reply processing */ @@ -381,7 +381,7 @@ SILC_FSM_STATE(silc_client_command_reply_processed) if (cmd->status == SILC_STATUS_OK || cmd->status == SILC_STATUS_LIST_END || SILC_STATUS_IS_ERROR(cmd->status)) - return SILC_FSM_FINISH; + SILC_FSM_FINISH; /* Add back to pending command reply list */ silc_mutex_lock(conn->internal->lock); @@ -391,7 +391,7 @@ SILC_FSM_STATE(silc_client_command_reply_processed) /** Wait more command payloads */ silc_fsm_next(fsm, silc_client_command_reply_wait); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** WHOIS *************************************/ @@ -511,7 +511,7 @@ SILC_FSM_STATE(silc_client_command_reply_whois) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** WHOWAS ************************************/ @@ -559,7 +559,7 @@ SILC_FSM_STATE(silc_client_command_reply_whowas) out: silc_client_unref_client(client, conn, client_entry); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** IDENTIFY **********************************/ @@ -675,7 +675,7 @@ SILC_FSM_STATE(silc_client_command_reply_identify) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** NICK ************************************/ @@ -730,7 +730,7 @@ SILC_FSM_STATE(silc_client_command_reply_nick) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** LIST ************************************/ @@ -756,7 +756,7 @@ SILC_FSM_STATE(silc_client_command_reply_list) /* There were no channels in the network. */ silc_client_command_callback(cmd, NULL, NULL, NULL, 0); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } CHECK_ARGS(3, 5); @@ -792,7 +792,7 @@ SILC_FSM_STATE(silc_client_command_reply_list) out: silc_client_unref_channel(client, conn, channel_entry); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* TOPIC ************************************/ @@ -840,7 +840,7 @@ SILC_FSM_STATE(silc_client_command_reply_topic) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* INVITE ***********************************/ @@ -890,7 +890,7 @@ SILC_FSM_STATE(silc_client_command_reply_invite) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** KILL ************************************/ @@ -931,7 +931,7 @@ SILC_FSM_STATE(silc_client_command_reply_kill) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** INFO ************************************/ @@ -992,7 +992,7 @@ SILC_FSM_STATE(silc_client_command_reply_info) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** STATS ***********************************/ @@ -1049,7 +1049,7 @@ SILC_FSM_STATE(silc_client_command_reply_stats) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** PING ************************************/ @@ -1073,7 +1073,7 @@ SILC_FSM_STATE(silc_client_command_reply_ping) silc_client_command_callback(cmd); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** JOIN ************************************/ @@ -1285,7 +1285,7 @@ SILC_FSM_STATE(silc_client_command_reply_join) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** MOTD ************************************/ @@ -1339,7 +1339,7 @@ SILC_FSM_STATE(silc_client_command_reply_motd) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** UMODE ***********************************/ @@ -1373,7 +1373,7 @@ SILC_FSM_STATE(silc_client_command_reply_umode) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** CMODE ***********************************/ @@ -1451,7 +1451,7 @@ SILC_FSM_STATE(silc_client_command_reply_cmode) if (public_key) silc_pkcs_public_key_free(public_key); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** CUMODE **********************************/ @@ -1522,7 +1522,7 @@ SILC_FSM_STATE(silc_client_command_reply_cumode) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** KICK ************************************/ @@ -1575,7 +1575,7 @@ SILC_FSM_STATE(silc_client_command_reply_kick) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /******************************** SILCOPER **********************************/ @@ -1594,7 +1594,7 @@ SILC_FSM_STATE(silc_client_command_reply_silcoper) silc_client_command_callback(cmd); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** OPER ************************************/ @@ -1613,7 +1613,7 @@ SILC_FSM_STATE(silc_client_command_reply_oper) silc_client_command_callback(cmd); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* DETACH ***********************************/ @@ -1644,7 +1644,7 @@ SILC_FSM_STATE(silc_client_command_reply_detach) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** WATCH ***********************************/ @@ -1663,7 +1663,7 @@ SILC_FSM_STATE(silc_client_command_reply_watch) silc_client_command_callback(cmd); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /*********************************** BAN ************************************/ @@ -1711,7 +1711,7 @@ SILC_FSM_STATE(silc_client_command_reply_ban) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** LEAVE ***********************************/ @@ -1757,7 +1757,7 @@ SILC_FSM_STATE(silc_client_command_reply_leave) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************* USERS ************************************/ @@ -1904,7 +1904,7 @@ SILC_FSM_STATE(silc_client_command_reply_users) out: silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** GETKEY **********************************/ @@ -1991,7 +1991,7 @@ SILC_FSM_STATE(silc_client_command_reply_getkey) if (public_key) silc_pkcs_public_key_free(public_key); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /********************************** SERVICE *********************************/ @@ -2020,7 +2020,7 @@ SILC_FSM_STATE(silc_client_command_reply_service) silc_client_command_callback(cmd, service_list, name); silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } /*********************************** QUIT ***********************************/ @@ -2030,5 +2030,5 @@ SILC_FSM_STATE(silc_client_command_reply_service) SILC_FSM_STATE(silc_client_command_reply_quit) { silc_fsm_next(fsm, silc_client_command_reply_processed); - return SILC_FSM_CONTINUE; + SILC_FSM_CONTINUE; } diff --git a/lib/silcclient/silcclient.h b/lib/silcclient/silcclient.h index a94648bc..69083194 100644 --- a/lib/silcclient/silcclient.h +++ b/lib/silcclient/silcclient.h @@ -610,25 +610,6 @@ typedef struct { } SilcClientOperations; /***/ -/****f* silcclient/SilcClientAPI/SilcNicknameFormatParse - * - * SYNOPSIS - * - * typedef void (*SilcNicknameFormatParse)(const char *nickname, - * char **ret_nickname); - * - * DESCRIPTION - * - * A callback function provided by the application for the library in - * SilcClientParams structure. This function parses the formatted - * nickname string `nickname' and returns the true nickname to the - * `ret_nickname' pointer. The library can call this function at - * any time. - * - ***/ -typedef void (*SilcNicknameFormatParse)(const char *nickname, - char **ret_nickname); - /****s* silcclient/SilcClientAPI/SilcClientParams * * NAME @@ -661,11 +642,9 @@ typedef struct { to save the nicknames in the library in a certain format. Since nicknames are not unique in SILC it is possible to have multiple same nicknames. Using this format string it is possible to order the library - to separate the multiple same nicknames from each other. The format - types are defined below and they can appear in any order in the format - string. If this is NULL then default format is used which is the - default nickname without anything else. The string MUST be NULL - terminated. + to separate the multiple same nicknames from each other. If this is + empty then default format is used which is the default nickname + without anything else. The string MUST be NULL terminated. Following format types are available: @@ -681,11 +660,10 @@ typedef struct { "%a!%n@%s" (fe. nick@server, 2!nick@server) "%n@%H" (fe. nick@host.domain.com) - By default this format is employed to the nicknames by the libary - only when there appears multiple same nicknames. If the library has - only one nickname cached the nickname is saved as is and without the - defined format. If you want always to save the nickname in the defined - format set the boolean field `nickname_force_format' to value TRUE. + Note that there must always be some separator characters around '%n' + format. It is not possible to put format characters before or after + '%n' without separators (such ash '@'). Also note that the separator + character should be a character that cannot be part of normal nickname. */ char nickname_format[32]; @@ -697,24 +675,6 @@ typedef struct { value. */ SilcBool nickname_force_format; - /* A callback function provided by the application for the library to - parse the nickname from the formatted nickname string. Even though - the libary formats the nicknames the application knows generally the - format better so this function should be provided for the library - if the application sets the `nickname_format' field. The library - will call this to get the true nickname from the provided formatted - nickname string whenever it needs the true nickname. */ - SilcNicknameFormatParse nickname_parse; - - /* If this is set to TRUE then the client will ignore all incoming - Requested Attributes queries and does not reply anything back. This - usually leads into situation where server does not anymore send - the queries after seeing that client does not reply anything back. - If your application does not support Requested Attributes or you do - not want to use them set this to TRUE. See SilcAttribute and - silc_client_attribute_add for more information on attributes. */ - SilcBool ignore_requested_attributes; - /* If this is set to TRUE, the silcclient library will not register and deregister the cipher, pkcs, hash and hmac algorithms. The application itself will need to handle that. */ @@ -780,10 +740,10 @@ void silc_client_free(SilcClient client); * the client ready to be run. One must call silc_client_run to run the * client. Returns FALSE if error occurred, TRUE otherwise. * - * The `username', `hostname' and `realname' strings must be given and - * they must be UTF-8 encoded. The `username' is the client's username - * in the operating system, `hostname' is the client's host name and - * the `realname' is the user's real name. + * The `username' and `hostname' strings must be given and they must be + * UTF-8 encoded. The `username' is the client's username in the + * operating system, `hostname' is the client's host name and the + * `realname' is the user's real name. * * The `running' callback is called after the client is running after * silc_client_run or silc_client_run_one has been called. Application @@ -905,7 +865,7 @@ typedef struct { SilcUInt32 auth_len; /* If this boolean is set to TRUE then the connection will use UDP instead - of TCP. If UDP is set the also the next `local_ip' and `local_port' + of TCP. If UDP is set then also the next `local_ip' and `local_port' must be set. */ SilcBool udp; @@ -949,6 +909,15 @@ typedef struct { (3600 seconds, 1 hour). */ unsigned int rekey_secs; + /* If this is set to TRUE then the client will ignore all incoming + Requested Attributes queries and does not reply anything back. This + usually leads into situation where server does not anymore send + the queries after seeing that client does not reply anything back. + If your application does not support Requested Attributes or you do + not want to use them set this to TRUE. See SilcAttribute and + silc_client_attribute_add for more information on attributes. */ + SilcBool ignore_requested_attributes; + } SilcClientConnectionParams; /***/ @@ -1737,6 +1706,23 @@ void silc_client_current_channel_private_key(SilcClient client, * There can be only one active key agreement for `client_entry'. Old * key agreement may be aborted by calling silc_client_abort_key_agreement. * + * EXAMPLE + * + * // Send key agreement request (we don't provide connection endpoint) + * silc_client_send_key_agreement(client, conn, remote_client, + * NULL, public_key, private_key, + * my_keyagr_completion, my_context); + * + * // Another example where we provide connection endpoint (TCP). + * SilcClientConnectionParams params; + * memset(¶ms, 0, sizeof(params)); + * params.local_ip = local_ip; + * params.local_port = local_port; + * params.timeout_secs = 60; + * silc_client_send_key_agreement(client, conn, remote_client, + * ¶ms, public_key, private_key, + * my_keyagr_completion, my_context); + * ***/ void silc_client_send_key_agreement(SilcClient client, SilcClientConnection conn, @@ -2288,6 +2274,41 @@ SilcHashTable silc_client_attributes_get(SilcClient client, ***/ SilcBuffer silc_client_attributes_request(SilcAttribute attribute, ...); +/****f* silcclient/SilcClientAPI/silc_client_nickname_format + * + * SYNOPSIS + * + * SilcClientEntry + * silc_client_nickname_format(SilcClient client, + * SilcClientConnection conn, + * SilcClientEntry client_entry, + * SilcBool priority); + * + * DESCRIPTION + * + * Formats the nickname of `client_entry' according to the nickname + * formatting rules set in SilcClientParams. If the `priority' is TRUE + * then the `client_entry' will always get the unformatted nickname. + * If FALSE and there are more than one same nicknames in the client + * the nickname will be formatted. + * + * This returns NULL on error. Otherwise, the client entry that was + * formatted is returned. If `priority' is FALSE this always returns + * the `client_entry'. If it is TRUE, this may return the client entry + * that was formatted after giving the `client_entry' the unformatted + * nickname. + * + * Usually application does not need to call this function, as the library + * automatically formats nicknames. However, if application wants to + * for example force the `client_entry' to always have the unformatted + * nickname it may call this function to do so. + * + ***/ +SilcClientEntry silc_client_nickname_format(SilcClient client, + SilcClientConnection conn, + SilcClientEntry client_entry, + SilcBool priority); + #ifdef __cplusplus } #endif