application performed the connecting outside the library. The library
however may use this internally. */
-SilcClientConnection silc_client_add_connection(SilcClient client,
- char *hostname,
- int port,
- void *context)
+SilcClientConnection
+silc_client_add_connection(SilcClient client,
+ SilcClientConnectionParams *params,
+ char *hostname, int port, void *context)
{
SilcClientConnection conn;
int i;
conn->pending_commands = silc_dlist_init();
conn->ftp_sessions = silc_dlist_init();
+ if (params) {
+ if (params->detach_data)
+ conn->params.detach_data = silc_memdup(params->detach_data,
+ params->detach_data_len);
+ conn->params.detach_data_len = params->detach_data_len;
+ }
+
/* Add the connection to connections table */
for (i = 0; i < client->internal->conns_count; i++)
if (client->internal->conns && !client->internal->conns[i]) {
case then this function is not used at all. When the connecting is
done the `connect' client operation is called. */
-int silc_client_connect_to_server(SilcClient client, int port,
- char *host, void *context)
+int silc_client_connect_to_server(SilcClient client,
+ SilcClientConnectionParams *params,
+ int port, char *host, void *context)
{
SilcClientInternalConnectContext *ctx;
SilcClientConnection conn;
SILC_LOG_DEBUG(("Connecting to port %d of server %s",
port, host));
- conn = silc_client_add_connection(client, host, port, context);
+ conn = silc_client_add_connection(client, params, host, port, context);
client->internal->ops->say(client, conn, SILC_CLIENT_MESSAGE_AUDIT,
"Connecting to port %d of server %s", port, host);
if (SILC_IS_DISCONNECTING(sock)) {
if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
client->internal->ops->disconnect(client, conn);
- silc_client_close_connection(client, sock, conn);
+ silc_client_close_connection_real(client, sock, conn);
return;
}
SILC_LOG_DEBUG(("EOF from connection %d", sock->sock));
if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
client->internal->ops->disconnect(client, conn);
- silc_client_close_connection(client, sock, conn);
+ silc_client_close_connection_real(client, sock, conn);
return;
}
connection but `conn->sock' might be actually a different connection
than the `sock'). */
-void silc_client_close_connection(SilcClient client,
- SilcSocketConnection sock,
- SilcClientConnection conn)
+void silc_client_close_connection_real(SilcClient client,
+ SilcSocketConnection sock,
+ SilcClientConnection conn)
{
int del = FALSE;
silc_socket_free(sock);
}
+/* Closes the connection to the remote end */
+
+void silc_client_close_connection(SilcClient client,
+ SilcClientConnection conn)
+{
+ silc_client_close_connection_real(client, NULL, conn);
+}
+
/* Called when we receive disconnection packet from server. This
closes our end properly and displays the reason of the disconnection
on the screen. */
if (sock == NULL)
return;
- silc_client_close_connection(client, sock, sock->user_data);
+ silc_client_close_connection_real(client, sock, sock->user_data);
}
/* Called when we receive disconnection packet from server. This
SilcChannelUser chu;
silc_hash_table_list(client_entry->channels, &htl);
- while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
+ while (silc_hash_table_get(&htl, NULL, (void **)&chu)) {
silc_hash_table_del(chu->client->channels, chu->channel);
silc_hash_table_del(chu->channel->user_list, chu->client);
silc_free(chu);
SilcChannelUser chu;
silc_hash_table_list(old->channels, &htl);
- while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
+ while (silc_hash_table_get(&htl, NULL, (void **)&chu)) {
/* Replace client entry */
silc_hash_table_del(chu->client->channels, chu->channel);
silc_hash_table_del(chu->channel->user_list, chu->client);
client->internal->params->connauth_request_secs, 0,
SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
}
+
+SilcBuffer silc_client_get_detach_data(SilcClient client,
+ SilcClientConnection conn)
+{
+ SilcBuffer detach;
+ SilcHashTableList htl;
+ SilcChannelUser chu;
+
+ SILC_LOG_DEBUG(("Creating detachment data"));
+
+ /* Save the nickname, Client ID and user mode in SILC network */
+ detach = silc_buffer_alloc_size(2 + strlen(conn->nickname) +
+ 2 + conn->local_id_data_len + 4);
+ silc_buffer_format(detach,
+ SILC_STR_UI_SHORT(strlen(conn->nickname)),
+ SILC_STR_UI_XNSTRING(conn->nickname,
+ strlen(conn->nickname)),
+ SILC_STR_UI_SHORT(conn->local_id_data_len),
+ SILC_STR_UI_XNSTRING(conn->local_id_data,
+ conn->local_id_data_len),
+ SILC_STR_UI_INT(conn->local_entry->mode),
+ SILC_STR_END);
+
+ /* Save all joined channels */
+ silc_hash_table_list(conn->local_entry->channels, &htl);
+ while (silc_hash_table_get(&htl, NULL, (void **)&chu)) {
+ unsigned char *chid = silc_id_id2str(chu->channel->id, SILC_ID_CHANNEL);
+ SilcUInt16 chid_len = silc_id_get_len(chu->channel->id, SILC_ID_CHANNEL);
+
+ detach = silc_buffer_realloc(detach, detach->truelen + 2 +
+ strlen(chu->channel->channel_name) +
+ 2 + chid_len + 4);
+ silc_buffer_pull(detach, detach->len);
+ silc_buffer_format(detach,
+ SILC_STR_UI_SHORT(strlen(chu->channel->channel_name)),
+ SILC_STR_UI_XNSTRING(chu->channel->channel_name,
+ strlen(chu->channel->channel_name)),
+ SILC_STR_UI_SHORT(chid_len),
+ SILC_STR_UI_XNSTRING(chid, chid_len),
+ SILC_STR_UI_INT(chu->channel->mode),
+ SILC_STR_END);
+
+ silc_free(chid);
+ }
+ silc_hash_table_list_reset(&htl);
+
+ silc_buffer_push(detach, detach->data - detach->head);
+
+ SILC_LOG_HEXDUMP(("Detach data"), detach->data, detach->len);
+
+ return detach;
+}