static void silc_client_ftp_ask_name(const char *filepath, void *context) { SilcClientFtpSession session = (SilcClientFtpSession)context; SilcSFTPAttributesStruct attr; char *remote_file = NULL; SILC_LOG_DEBUG(("Start")); if (filepath) { remote_file = session->filepath; session->filepath = NULL; silc_free(session->path); session->path = NULL; session->filepath = strdup(filepath); } else { remote_file = strdup(session->filepath); } /* Now open the file */ memset(&attr, 0, sizeof(attr)); silc_sftp_open(session->sftp, remote_file, SILC_SFTP_FXF_READ, &attr, silc_client_ftp_open_handle, session); /* Close the directory handle */ silc_sftp_close(session->sftp, session->dir_handle, NULL, NULL); session->dir_handle = NULL; silc_free(remote_file); }
int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry) { if (entry) { /* Remove from cache */ if (!silc_idcache_del_by_context(id_list->servers, entry, NULL)) { SILC_LOG_DEBUG(("Unknown server, did not delete")); return FALSE; } SILC_LOG_DEBUG(("Deleting server %s id %s", entry->server_name ? entry->server_name : "", entry->id ? silc_id_render(entry->id, SILC_ID_SERVER) : "")); /* Free data */ silc_free(entry->server_name); silc_free(entry->id); silc_free(entry->server_info); memset(entry, 'F', sizeof(*entry)); silc_free(entry); return TRUE; } return FALSE; }
static void silcpurple_buddy_getkey_cb(SilcPurpleBuddyGetkey g, SilcClientCommandReplyContext cmd) { SilcClientEntry client_entry; unsigned char *pk; SilcUInt32 pk_len; /* Get the client entry. */ client_entry = silc_client_get_client_by_id(g->client, g->conn, &g->client_id); if (!client_entry) { purple_notify_error(g->client->application, _("Get Public Key"), _("The remote user is not present in the network any more"), NULL); silc_free(g); return; } if (!client_entry->public_key) { silc_free(g); return; } /* Now verify the public key */ pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len); silcpurple_verify_public_key(g->client, g->conn, client_entry->nickname, SILC_SOCKET_TYPE_CLIENT, pk, pk_len, SILC_SKE_PK_TYPE_SILC, NULL, NULL); silc_free(pk); silc_free(g); }
static void silcpurple_buddy_resetkey(PurpleBlistNode *node, gpointer data) { PurpleBuddy *b; PurpleConnection *gc; SilcPurple sg; char *nickname; SilcClientEntry *clients; SilcUInt32 clients_count; g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); b = (PurpleBuddy *) node; gc = purple_account_get_connection(b->account); sg = gc->proto_data; if (!silc_parse_userfqdn(b->name, &nickname, NULL)) return; /* Find client entry */ clients = silc_client_get_clients_local(sg->client, sg->conn, nickname, b->name, &clients_count); if (!clients) { silc_free(nickname); return; } clients[0]->prv_resp = FALSE; silc_client_del_private_message_key(sg->client, sg->conn, clients[0]); silc_free(clients); silc_free(nickname); }
SilcServerEntry silc_idlist_add_server(SilcIDList id_list, char *server_name, int server_type, SilcServerID *id, SilcServerEntry router, void *connection) { SilcServerEntry server; char *server_namec = NULL; SILC_LOG_DEBUG(("Adding new server entry")); /* Normalize name. This is cached, original is in server context. */ if (server_name) { server_namec = silc_identifier_check(server_name, strlen(server_name), SILC_STRING_UTF8, 256, NULL); if (!server_namec) return NULL; } server = silc_calloc(1, sizeof(*server)); server->server_name = server_name; server->server_type = server_type; server->id = id; server->router = router; server->connection = connection; if (!silc_idcache_add(id_list->servers, server_namec, (void *)server->id, (void *)server)) { silc_free(server); silc_free(server_namec); return NULL; } return server; }
static void silc_server_accept_free(SilcServerAccept ac) { if (ac->connauth) silc_connauth_free(ac->connauth); silc_free(ac->error_string); silc_free(ac); }
SilcBuffer silc_public_key_payload_encode(SilcPublicKey public_key) { SilcBuffer buffer; unsigned char *pk; SilcUInt32 pk_len; SilcPKCSType type; if (!public_key) return NULL; type = silc_pkcs_get_type(public_key); pk = silc_pkcs_public_key_encode(public_key, &pk_len); if (!pk) return NULL; buffer = silc_buffer_alloc_size(4 + pk_len); if (!buffer) { silc_free(pk); return NULL; } if (silc_buffer_format(buffer, SILC_STR_UI_SHORT(pk_len), SILC_STR_UI_SHORT(type), SILC_STR_DATA(pk, pk_len), SILC_STR_END) < 0) { silc_buffer_free(buffer); silc_free(pk); return NULL; } silc_free(pk); return buffer; }
void silc_socket_stream_destroy(SilcStream stream) { SilcSocketStream socket_stream = stream; silc_socket_stream_close(socket_stream); silc_free(socket_stream->ip); silc_free(socket_stream->hostname); if (socket_stream->schedule) silc_schedule_task_del_by_fd(socket_stream->schedule, socket_stream->sock); if (socket_stream->qos) { silc_schedule_task_del_by_context(socket_stream->schedule, socket_stream->qos); if (socket_stream->qos->buffer) { memset(socket_stream->qos->buffer, 0, socket_stream->qos->read_limit_bytes); silc_free(socket_stream->qos->buffer); } silc_free(socket_stream->qos); } if (socket_stream->schedule) silc_schedule_wakeup(socket_stream->schedule); silc_free(socket_stream); }
static void silcpurple_buddy_keyagr_resolved(SilcClient client, SilcClientConnection conn, SilcClientEntry *clients, SilcUInt32 clients_count, void *context) { PurpleConnection *gc = client->application; SilcPurpleResolve r = context; char tmp[256]; if (!clients) { g_snprintf(tmp, sizeof(tmp), _("User %s is not present in the network"), r->nick); purple_notify_error(gc, _("Key Agreement"), _("Cannot perform the key agreement"), tmp); silc_free(r->nick); silc_free(r); return; } silcpurple_buddy_keyagr_do(gc, r->nick, FALSE); silc_free(r->nick); silc_free(r); }
static void silcpurple_buddy_privkey_cb(SilcPurplePrivkey p, const char *passphrase) { SilcClientEntry client_entry; if (!passphrase || !(*passphrase)) { silc_free(p); return; } /* Get the client entry. */ client_entry = silc_client_get_client_by_id(p->client, p->conn, &p->client_id); if (!client_entry) { purple_notify_error(p->client->application, _("IM With Password"), _("The remote user is not present in the network any more"), NULL); silc_free(p); return; } /* Set the private message key */ silc_client_del_private_message_key(p->client, p->conn, client_entry); silc_client_add_private_message_key(p->client, p->conn, client_entry, NULL, NULL, (unsigned char *)passphrase, strlen(passphrase), FALSE, client_entry->prv_resp); if (!client_entry->prv_resp) silc_client_send_private_message_key_request(p->client, p->conn, client_entry); silc_free(p); }
SilcBool silc_pkcs1_verify_no_oid(void *public_key, unsigned char *signature, SilcUInt32 signature_len, unsigned char *data, SilcUInt32 data_len, SilcHash hash) { RsaPublicKey *key = public_key; SilcBool ret = FALSE; SilcMPInt mp_tmp2; SilcMPInt mp_dst; unsigned char *verify, unpadded[2048 + 1], hashr[SILC_HASH_MAXLEN]; SilcUInt32 verify_len, len = (key->bits + 7) / 8; SILC_LOG_DEBUG(("Verify signature")); silc_mp_init(&mp_tmp2); silc_mp_init(&mp_dst); /* Format the signature into MP int */ silc_mp_bin2mp(signature, signature_len, &mp_tmp2); /* Verify */ silc_rsa_public_operation(key, &mp_tmp2, &mp_dst); /* MP to data */ verify = silc_mp_mp2bin(&mp_dst, len, &verify_len); /* Unpad data */ if (!silc_pkcs1_decode(SILC_PKCS1_BT_PRV1, verify, verify_len, unpadded, sizeof(unpadded), &len)) { memset(verify, 0, verify_len); silc_free(verify); silc_mp_uninit(&mp_tmp2); silc_mp_uninit(&mp_dst); return FALSE; } /* Hash data if requested */ if (hash) { silc_hash_make(hash, data, data_len, hashr); data = hashr; data_len = silc_hash_len(hash); } /* Compare */ if (len == data_len && !memcmp(data, unpadded, len)) ret = TRUE; memset(verify, 0, verify_len); memset(unpadded, 0, sizeof(unpadded)); silc_free(verify); silc_mp_uninit(&mp_tmp2); silc_mp_uninit(&mp_dst); if (hash) memset(hashr, 0, sizeof(hashr)); return ret; }
static void silc_net_connect_destructor(SilcFSM fsm, void *fsm_context, void *destructor_context) { SilcNetConnect conn = fsm_context; silc_free(conn->local_ip); silc_free(conn->remote); silc_free(conn); }
void silc_config_close(SilcConfigFile *file) { if (file) { silc_free(file->filename); memset(file->base, 'F', file->len); silc_free(file->base); memset(file, 'F', sizeof(*file)); silc_free(file); } }
void silc_server_command_reply_free(SilcServerCommandReplyContext cmd) { if (cmd) { silc_command_payload_free(cmd->payload); if (cmd->sock) silc_packet_stream_unref(cmd->sock); silc_free(cmd->callbacks); silc_free(cmd); } }
SilcCommandPayload silc_command_payload_parse(const unsigned char *payload, SilcUInt32 payload_len) { SilcBufferStruct buffer; SilcCommandPayload newp; unsigned char args_num; SilcUInt16 p_len; int ret; SILC_LOG_DEBUG(("Parsing command payload")); silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); newp = silc_calloc(1, sizeof(*newp)); if (!newp) return NULL; /* Parse the Command Payload */ ret = silc_buffer_unformat(&buffer, SILC_STR_UI_SHORT(&p_len), SILC_STR_UI_CHAR(&newp->cmd), SILC_STR_UI_CHAR(&args_num), SILC_STR_UI_SHORT(&newp->ident), SILC_STR_END); if (ret == -1) { SILC_LOG_ERROR(("Incorrect command payload in packet")); silc_free(newp); return NULL; } if (p_len != silc_buffer_len(&buffer)) { SILC_LOG_ERROR(("Incorrect command payload in packet")); silc_free(newp); return NULL; } if (newp->cmd == 0) { SILC_LOG_ERROR(("Incorrect command type in command payload")); silc_free(newp); return NULL; } silc_buffer_pull(&buffer, SILC_COMMAND_PAYLOAD_LEN); if (args_num) { newp->args = silc_argument_payload_parse(buffer.data, silc_buffer_len(&buffer), args_num); if (!newp->args) { silc_free(newp); return NULL; } } silc_buffer_push(&buffer, SILC_COMMAND_PAYLOAD_LEN); return newp; }
SilcClientEntry silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username, char *userinfo, SilcClientID *id, SilcServerEntry router, void *connection) { SilcClientEntry client; char *nicknamec = NULL; SILC_LOG_DEBUG(("Adding new client entry")); /* Normalize name. This is cached, original is in client context. */ if (nickname) { nicknamec = silc_identifier_check(nickname, strlen(nickname), SILC_STRING_UTF8, 128, NULL); if (!nicknamec) return NULL; } /* Check username. */ if (username) { char u[128 + 1], h[256 + 1]; int ret; ret = silc_parse_userfqdn(username, u, sizeof(u), h, sizeof(h)); if (!ret) return NULL; if (!silc_identifier_verify(u, strlen(u), SILC_STRING_UTF8, 128)) return NULL; if (ret > 1 && !silc_identifier_verify(h, strlen(h), SILC_STRING_UTF8, 256)) return NULL; } client = silc_calloc(1, sizeof(*client)); if (!client) return NULL; client->nickname = nickname; client->username = username ? strdup(username) : NULL; client->userinfo = userinfo; client->id = id; client->router = router; client->connection = connection; client->channels = silc_hash_table_alloc(3, silc_hash_ptr, NULL, NULL, NULL, NULL, NULL, TRUE); if (!silc_idcache_add(id_list->clients, nicknamec, (void *)client->id, (void *)client)) { silc_hash_table_free(client->channels); silc_free(client); silc_free(nicknamec); return NULL; } return client; }
void silc_sftp_attr_free(SilcSFTPAttributes attr) { int i; for (i = 0; i < attr->extended_count; i++) { silc_buffer_free(attr->extended_type[i]); silc_buffer_free(attr->extended_data[i]); } silc_free(attr->extended_type); silc_free(attr->extended_data); silc_free(attr); }
SilcThread silc_thread_create(SilcThreadStart start_func, void *context, SilcBool waitable) { #ifdef SILC_THREADS SilcSymbianThread *tc; RThread *thread; TInt ret; char tmp[24]; SilcUInt16 wname[24]; SILC_LOG_DEBUG(("Creating new thread")); tc = (SilcSymbianThread *)silc_calloc(1, sizeof(*tc)); if (!tc) return NULL; tc->start_func = start_func; tc->context = context; tc->waitable = waitable; /* Allocate thread */ thread = new RThread; if (!thread) { silc_free(tc); return NULL; } /* Create the thread */ silc_snprintf(tmp, sizeof(tmp), "thread-%p", tc); silc_utf8_c2w((const unsigned char *)tmp, strlen(tmp), wname, sizeof(wname) / sizeof(wname[0])); TBuf<24> name((unsigned short *)wname); name.PtrZ(); ret = thread->Create(name, silc_thread_start, 8192, NULL, tc); if (ret != KErrNone) { SILC_LOG_ERROR(("Could not create new thread, error %d", ret)); delete thread; silc_free(tc); return NULL; } /* Start the thread */ thread->Resume(); /* Close our instance to the thread */ thread->Close(); return (SilcThread)thread; #else /* Call thread callback immediately */ (*start_func)(context); return NULL; #endif }
void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size, SilcHashFunction hash, void *hash_user_context) { int i; SilcHashTableEntry *table, e, tmp; SilcUInt32 table_size, size_index; SilcBool auto_rehash; SILC_HT_DEBUG(("Start")); if (new_size) silc_hash_table_primesize(new_size, &size_index); else silc_hash_table_primesize(ht->entry_count, &size_index); if (size_index == ht->table_size) return; SILC_HT_DEBUG(("Rehashing")); /* Take old hash table */ table = ht->table; table_size = ht->table_size; auto_rehash = ht->auto_rehash; ht->auto_rehash = FALSE; /* Allocate new table */ ht->table = silc_calloc(primesize[size_index], sizeof(*ht->table)); if (!ht->table) return; ht->table_size = size_index; ht->entry_count = 0; /* Rehash */ for (i = 0; i < primesize[table_size]; i++) { e = table[i]; while (e) { silc_hash_table_add_ext(ht, e->key, e->context, hash, hash_user_context); tmp = e; e = e->next; /* Remove old entry */ silc_free(tmp); } } ht->auto_rehash = auto_rehash; /* Remove old table */ silc_free(table); }
SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, SilcUInt16 ident, SilcUInt32 argc, va_list ap) { unsigned char **argv = NULL; SilcUInt32 *argv_lens = NULL, *argv_types = NULL; unsigned char *x; SilcUInt32 x_len; SilcUInt32 x_type; SilcBuffer buffer = NULL; int i, k = 0; if (argc) { argv = silc_calloc(argc, sizeof(unsigned char *)); if (!argv) return NULL; argv_lens = silc_calloc(argc, sizeof(SilcUInt32)); if (!argv_lens) return NULL; argv_types = silc_calloc(argc, sizeof(SilcUInt32)); if (!argv_types) return NULL; for (i = 0, k = 0; i < argc; i++) { x_type = va_arg(ap, SilcUInt32); x = va_arg(ap, unsigned char *); x_len = va_arg(ap, SilcUInt32); if (!x_type || !x || !x_len) continue; argv[k] = silc_memdup(x, x_len); if (!argv[k]) goto out; argv_lens[k] = x_len; argv_types[k] = x_type; k++; } } buffer = silc_command_payload_encode(cmd, k, argv, argv_lens, argv_types, ident); out: for (i = 0; i < k; i++) silc_free(argv[i]); silc_free(argv); silc_free(argv_lens); silc_free(argv_types); return buffer; }
SilcAsyncOperation silc_net_tcp_connect(const char *local_ip_addr, const char *remote_ip_addr, int remote_port, SilcSchedule schedule, SilcNetCallback callback, void *context) { SilcNetConnect conn; if (!remote_ip_addr || remote_port < 1 || !schedule || !callback) return NULL; SILC_LOG_DEBUG(("Creating connection to host %s port %d", remote_ip_addr, remote_port)); conn = silc_calloc(1, sizeof(*conn)); if (!conn) { callback(SILC_NET_NO_MEMORY, NULL, context); return NULL; } /* Start async operation */ conn->op = silc_async_alloc(silc_net_connect_abort, NULL, conn); if (!conn->op) { silc_free(conn); callback(SILC_NET_NO_MEMORY, NULL, context); return NULL; } if (local_ip_addr) conn->local_ip = strdup(local_ip_addr); conn->remote = strdup(remote_ip_addr); if (!conn->remote) { silc_async_free(conn->op); silc_free(conn->local_ip); silc_free(conn); callback(SILC_NET_NO_MEMORY, NULL, context); return NULL; } conn->port = remote_port; conn->callback = callback; conn->context = context; conn->retry = 1; conn->status = SILC_NET_ERROR; silc_fsm_init(&conn->fsm, conn, silc_net_connect_destructor, NULL, schedule); silc_fsm_start(&conn->fsm, silc_net_connect_st_start); return conn->op; }
PurpleXfer *silcpurple_ftp_new_xfer(PurpleConnection *gc, const char *name) { SilcPurple sg = gc->proto_data; SilcClient client = sg->client; SilcClientConnection conn = sg->conn; SilcClientEntry *clients; SilcUInt32 clients_count; SilcPurpleXfer xfer; char *nickname; g_return_val_if_fail(name != NULL, NULL); if (!silc_parse_userfqdn(name, &nickname, NULL)) return NULL; /* Find client entry */ clients = silc_client_get_clients_local(client, conn, nickname, name, &clients_count); if (!clients) { silc_client_get_clients(client, conn, nickname, NULL, silcpurple_ftp_send_file_resolved, strdup(name)); silc_free(nickname); return NULL; } xfer = silc_calloc(1, sizeof(*xfer)); g_return_val_if_fail(xfer != NULL, NULL); xfer->sg = sg; xfer->client_entry = clients[0]; xfer->xfer = purple_xfer_new(xfer->sg->account, PURPLE_XFER_SEND, xfer->client_entry->nickname); if (!xfer->xfer) { silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); g_free(xfer->hostname); silc_free(xfer); return NULL; } purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_send); purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied); purple_xfer_set_cancel_send_fnc(xfer->xfer, silcpurple_ftp_send_cancel); xfer->xfer->data = xfer; silc_free(clients); silc_free(nickname); return xfer->xfer; }
SilcBool silc_pkcs1_decrypt(void *private_key, unsigned char *src, SilcUInt32 src_len, unsigned char *dst, SilcUInt32 dst_size, SilcUInt32 *ret_dst_len) { RsaPrivateKey *key = private_key; SilcMPInt mp_tmp; SilcMPInt mp_dst; unsigned char *padded, unpadded[2048 + 1]; SilcUInt32 padded_len; if (dst_size < (key->bits + 7) / 8) return FALSE; silc_mp_init(&mp_tmp); silc_mp_init(&mp_dst); /* Data to MP */ silc_mp_bin2mp(src, src_len, &mp_tmp); /* Decrypt */ silc_rsa_private_operation(key, &mp_tmp, &mp_dst); /* MP to data */ padded = silc_mp_mp2bin(&mp_dst, (key->bits + 7) / 8, &padded_len); /* Unpad data */ if (!silc_pkcs1_decode(SILC_PKCS1_BT_PUB, padded, padded_len, unpadded, sizeof(unpadded), ret_dst_len)) { memset(padded, 0, padded_len); silc_free(padded); silc_mp_uninit(&mp_tmp); silc_mp_uninit(&mp_dst); return FALSE; } /* Copy to destination */ memcpy(dst, unpadded, *ret_dst_len); memset(padded, 0, padded_len); memset(unpadded, 0, sizeof(unpadded)); silc_free(padded); silc_mp_uninit(&mp_tmp); silc_mp_uninit(&mp_dst); return TRUE; }
void silc_net_close_listener(SilcNetListener listener) { int i; SILC_LOG_DEBUG(("Closing network listener")); for (i = 0; i < listener->socks_count; i++) { silc_schedule_task_del_by_fd(listener->schedule, listener->socks[i]); shutdown(listener->socks[i], 2); close(listener->socks[i]); } silc_free(listener->socks); silc_free(listener); }
static SILC_TASK_CALLBACK(silc_softacc_cipher_aes_completion) { SilcSoftaccCipher c = context; int i; /* Disconnect from key stream queue */ if (silc_thread_queue_disconnect(c->queue)) return; for (i = 0; i < c->num_key_stream; i++) silc_free(c->key_stream[i]); silc_free(c->key_stream); memset(c, 0, sizeof(*c)); silc_free(c); }
SilcChannelEntry silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode, SilcChannelID *id, SilcServerEntry router, SilcCipher send_key, SilcCipher receive_key, SilcHmac hmac) { SilcChannelEntry channel; char *channel_namec = NULL; SILC_LOG_DEBUG(("Adding new channel %s", channel_name)); /* Normalize name. This is cached, original is in client context. */ if (channel_name) { channel_namec = silc_channel_name_check(channel_name, strlen(channel_name), SILC_STRING_UTF8, 256, NULL); if (!channel_namec) return NULL; } channel = silc_calloc(1, sizeof(*channel)); channel->channel_name = channel_name; channel->mode = mode; channel->id = id; channel->router = router; channel->send_key = send_key; channel->receive_key = receive_key; channel->hmac = hmac; channel->created = channel->updated = time(0); if (!channel->hmac) if (!silc_hmac_alloc(SILC_DEFAULT_HMAC, NULL, &channel->hmac)) { silc_free(channel); return NULL; } channel->user_list = silc_hash_table_alloc(3, silc_hash_ptr, NULL, NULL, NULL, NULL, NULL, TRUE); if (!silc_idcache_add(id_list->channels, channel_namec, (void *)channel->id, (void *)channel)) { silc_hmac_free(channel->hmac); silc_hash_table_free(channel->user_list); silc_free(channel); silc_free(channel_namec); return NULL; } return channel; }
SilcBuffer silc_sftp_name_encode(SilcSFTPName name) { SilcBuffer buffer; int i, len = 4; SilcBuffer *attr_buf; attr_buf = silc_calloc(name->count, sizeof(*attr_buf)); if (!attr_buf) return NULL; for (i = 0; i < name->count; i++) { len += (8 + strlen(name->filename[i]) + strlen(name->long_filename[i])); attr_buf[i] = silc_sftp_attr_encode(name->attrs[i]); if (!attr_buf[i]) return NULL; len += silc_buffer_len(attr_buf[i]); } buffer = silc_buffer_alloc(len); if (!buffer) return NULL; silc_buffer_end(buffer); silc_buffer_format(buffer, SILC_STR_UI_INT(name->count), SILC_STR_END); silc_buffer_pull(buffer, 4); for (i = 0; i < name->count; i++) { len = silc_buffer_format(buffer, SILC_STR_UI_INT(strlen(name->filename[i])), SILC_STR_UI32_STRING(name->filename[i]), SILC_STR_UI_INT(strlen(name->long_filename[i])), SILC_STR_UI32_STRING(name->long_filename[i]), SILC_STR_DATA(silc_buffer_data(attr_buf[i]), silc_buffer_len(attr_buf[i])), SILC_STR_END); silc_buffer_pull(buffer, len); silc_free(attr_buf[i]); } silc_free(attr_buf); silc_buffer_push(buffer, buffer->data - buffer->head); return buffer; }
SilcAttributePayload silc_attribute_payload_alloc(SilcAttribute attribute, SilcAttributeFlags flags, void *object, SilcUInt32 object_size) { SilcAttributePayload attr; SilcUInt32 tmp_len; attr = silc_calloc(1, sizeof(*attr)); if (!attr) return NULL; attr->attribute = attribute; attr->flags = flags; attr->data = silc_attribute_payload_encode_int(attribute, flags, object, object_size, &tmp_len); attr->data_len = (SilcUInt16)tmp_len; if (!attr->data) { silc_free(attr); return NULL; } return attr; }
SilcThread silc_thread_create(SilcThreadStart start_func, void *context, SilcBool waitable) { #ifdef SILC_THREADS int ret; SilcOs2Thread thread = silc_calloc(1, sizeof(*thread)); if (!thread) return NULL; thread->start_func = start_func; thread->context = context; thread->waitable = waitable; /* Create the thread, and run it */ thread->thread = _beginthread(silc_thread_os2_start, NULL, 65536, thread); if (thread->thread < 0) { SILC_LOG_ERROR(("Could not create new thread")); silc_free(thread); return NULL; } return (SilcThread)thread->thread; #else /* Call thread callback immediately */ (*start_func)(context); return NULL; #endif }
SilcClient silc_client_alloc(SilcClientOperations *ops, SilcClientParams *params, void *application, const char *version_string) { SilcClient new_client; new_client = silc_calloc(1, sizeof(*new_client)); if (!new_client) return NULL; new_client->application = application; new_client->internal = silc_calloc(1, sizeof(*new_client->internal)); if (!new_client->internal) { silc_free(new_client); return NULL; } new_client->internal->ops = ops; new_client->internal->params = silc_calloc(1, sizeof(*new_client->internal->params)); if (!version_string) version_string = silc_version_string; new_client->internal->silc_client_version = strdup(version_string); if (params) memcpy(new_client->internal->params, params, sizeof(*params)); new_client->internal->params-> nickname_format[sizeof(new_client->internal-> params->nickname_format) - 1] = 0; silc_atomic_init32(&new_client->internal->conns, 0); return new_client; }