SilcChannelEntry * silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id, SilcUInt32 *channels_count) { SilcList list; SilcIDCacheEntry id_cache = NULL; SilcChannelEntry *channels = NULL; int i = 0; SILC_LOG_DEBUG(("Start")); if (!channel_id) { if (!silc_idcache_get_all(id_list->channels, &list)) return NULL; channels = silc_calloc(silc_list_count(list), sizeof(*channels)); i = 0; silc_list_start(list); while ((id_cache = silc_list_get(list))) channels[i++] = (SilcChannelEntry)id_cache->context; } else { if (!silc_idcache_find_by_id_one(id_list->channels, channel_id, &id_cache)) return NULL; i = 1; channels = silc_calloc(1, sizeof(*channels)); channels[0] = (SilcChannelEntry)id_cache->context; } if (channels_count) *channels_count = i; return channels; }
SilcPrivateMessageKeys silc_client_list_private_message_keys(SilcClient client, SilcClientConnection conn, SilcUInt32 *key_count) { SilcPrivateMessageKeys keys; SilcUInt32 count = 0; SilcList list; SilcIDCacheEntry id_cache; SilcClientEntry entry; if (!client || !conn) return NULL; silc_mutex_lock(conn->internal->lock); if (!silc_idcache_get_all(conn->internal->client_cache, &list)) { silc_mutex_unlock(conn->internal->lock); return NULL; } keys = silc_calloc(silc_list_count(list), sizeof(*keys)); if (!keys) { silc_mutex_unlock(conn->internal->lock); return NULL; } silc_list_start(list); while ((id_cache = silc_list_get(list))) { entry = id_cache->context; if (entry->internal.send_key) { keys[count].client_entry = entry; keys[count].cipher = (char *)silc_cipher_get_name(entry->internal. send_key); keys[count].key = (entry->internal.generated == FALSE ? entry->internal.key : NULL); keys[count].key_len = (entry->internal.generated == FALSE ? entry->internal.key_len : 0); count++; } } silc_mutex_unlock(conn->internal->lock); if (key_count) *key_count = count; return keys; }
SilcServerEntry silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, int port, SilcBool registered, SilcIDCacheEntry *ret_entry) { SilcList list; SilcIDCacheEntry id_cache = NULL; SilcServerEntry server = NULL; SilcPacketStream sock; const char *host = NULL, *ip = NULL; SILC_LOG_DEBUG(("Server by hostname %s and port %d", hostname, port)); if (!silc_idcache_get_all(id_list->servers, &list)) return NULL; silc_list_start(list); while ((id_cache = silc_list_get(list))) { server = id_cache->context; sock = server->connection; if (sock && silc_socket_stream_get_info( silc_packet_stream_get_stream(sock), NULL, &host, &ip, NULL)) { if (((host && !strcasecmp(host, hostname)) || (ip && !strcasecmp(ip, hostname))) && server->id->port == SILC_SWAB_16(port)) break; } id_cache = NULL; server = NULL; } if (server && registered && !(server->data.status & SILC_IDLIST_STATUS_REGISTERED)) return NULL; if (ret_entry) *ret_entry = id_cache; SILC_LOG_DEBUG(("Found")); return server; }
void silc_client_del_connection(SilcClient client, SilcClientConnection conn) { SilcList list; SilcIDCacheEntry entry; SilcFSMThread thread; SILC_LOG_DEBUG(("Freeing connection %p", conn)); silc_schedule_task_del_by_context(conn->internal->schedule, conn); /* Free all cache entries */ if (conn->internal->server_cache) { if (silc_idcache_get_all(conn->internal->server_cache, &list)) { silc_list_start(list); while ((entry = silc_list_get(list))) silc_client_del_server(client, conn, entry->context); } } if (conn->internal->channel_cache) { if (silc_idcache_get_all(conn->internal->channel_cache, &list)) { silc_list_start(list); while ((entry = silc_list_get(list))) { silc_client_empty_channel(client, conn, entry->context); silc_client_del_channel(client, conn, entry->context); } } } if (conn->internal->client_cache) { if (silc_idcache_get_all(conn->internal->client_cache, &list)) { silc_list_start(list); while ((entry = silc_list_get(list))) silc_client_del_client(client, conn, entry->context); } } /* Free ID caches */ if (conn->internal->client_cache) silc_idcache_free(conn->internal->client_cache); if (conn->internal->channel_cache) silc_idcache_free(conn->internal->channel_cache); if (conn->internal->server_cache) silc_idcache_free(conn->internal->server_cache); /* Free thread pool */ silc_list_start(conn->internal->thread_pool); while ((thread = silc_list_get(conn->internal->thread_pool))) silc_fsm_free(thread); silc_free(conn->remote_host); silc_buffer_free(conn->internal->local_idp); silc_buffer_free(conn->internal->remote_idp); silc_mutex_free(conn->internal->lock); if (conn->internal->hash) silc_hash_free(conn->internal->hash); if (conn->internal->sha1hash) silc_hash_free(conn->internal->sha1hash); silc_atomic_uninit16(&conn->internal->cmd_ident); silc_free(conn->internal->away_message); if (conn->internal->rekey) silc_ske_free_rekey_material(conn->internal->rekey); if (conn->internal->cop) silc_async_free(conn->internal->cop); silc_free(conn->internal); memset(conn, 'F', sizeof(*conn)); silc_free(conn); }