本文整理汇总了C++中silc_calloc函数的典型用法代码示例。如果您正苦于以下问题:C++ silc_calloc函数的具体用法?C++ silc_calloc怎么用?C++ silc_calloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了silc_calloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: silc_idlist_get_channels
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;
}
示例2: silc_client_alloc
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;
}
示例3: silc_command_payload_encode_vap
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;
}
示例4: silc_thread_create
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
}
示例5: purple_whiteboard_get_session
PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry)
{
SilcClientConnection conn;
PurpleWhiteboard *wb;
SilcPurpleWb wbs;
conn = sg->conn;
wb = purple_whiteboard_get_session(sg->account, client_entry->nickname);
if (!wb)
wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0);
if (!wb)
return NULL;
if (!wb->proto_data) {
wbs = silc_calloc(1, sizeof(*wbs));
if (!wbs)
return NULL;
wbs->type = 0;
wbs->u.client = client_entry;
wbs->width = SILCPURPLE_WB_WIDTH;
wbs->height = SILCPURPLE_WB_HEIGHT;
wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL;
wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK;
wb->proto_data = wbs;
/* Start the whiteboard */
purple_whiteboard_start(wb);
purple_whiteboard_clear(wb);
}
return wb;
}
示例6: silc_server_command_alloc
SilcServerCommand silc_server_command_alloc(SilcServerThread thread)
{
SilcServerCommand cmd;
silc_mutex_lock(thread->server->lock);
/* Get command context from freelist or allocate new one. */
cmd = silc_list_get(thread->server->command_pool);
if (!cmd) {
silc_mutex_unlock(thread->server->lock);
cmd = silc_calloc(1, sizeof(*cmd));
if (!cmd)
return NULL;
SILC_LOG_DEBUG(("Allocating command context %p", cmd));
cmd->thread = thread;
return cmd;
}
SILC_LOG_DEBUG(("Get command context %p", cmd));
/* Delete from freelist */
silc_list_del(thread->server->command_pool, cmd);
cmd->thread = thread;
silc_mutex_unlock(thread->server->lock);
return cmd;
}
示例7: silc_client_add_to_channel
SilcBool silc_client_add_to_channel(SilcClient client,
SilcClientConnection conn,
SilcChannelEntry channel,
SilcClientEntry client_entry,
SilcUInt32 cumode)
{
SilcChannelUser chu;
if (silc_client_on_channel(channel, client_entry))
return TRUE;
SILC_LOG_DEBUG(("Add client %s to channel", client_entry->nickname));
chu = silc_calloc(1, sizeof(*chu));
if (!chu)
return FALSE;
chu->client = client_entry;
chu->channel = channel;
chu->mode = cumode;
silc_client_ref_client(client, conn, client_entry);
silc_client_ref_channel(client, conn, channel);
silc_hash_table_add(channel->user_list, client_entry, chu);
silc_hash_table_add(client_entry->channels, channel, chu);
return TRUE;
}
示例8: silc_thread_create
SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
SilcBool waitable)
{
#ifdef SILC_THREADS
SilcWin32Thread thread;
unsigned id;
SILC_LOG_DEBUG(("Creating new thread"));
thread = silc_calloc(1, sizeof(*thread));
thread->start_func = start_func;
thread->context = context;
thread->waitable = waitable;
thread->thread =
_beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE)silc_thread_win32_start,
(void *)thread, 0, &id);
if (!thread->thread) {
SILC_LOG_ERROR(("Could not create new thread"));
silc_free(thread);
return NULL;
}
return (SilcThread)thread;
#else
/* Call thread callback immediately */
(*start_func)(context);
return NULL;
#endif
}
示例9: event_joined
static void event_joined(struct event *event)
{
struct channel *channel = event_get_control(event, channel);
struct channel_connection *chconn = channel_get_connection(channel);
struct i_silc_channel_connection *silc_chconn;
struct i_silc_gateway_connection *silc_gwconn;
SilcJoinResolve *r;
i_assert(chconn != NULL);
if( !IS_SILC_CHCONN(chconn) )
return;
silc_chconn = (struct i_silc_channel_connection *)chconn;
silc_gwconn = (struct i_silc_gateway_connection *)chconn->gwconn;
r = silc_calloc(1, sizeof(*r));
r->channel = silc_chconn->channel_entry;
r->retry = 0;
if( event_isset(event, "init") ) {
silc_client_get_clients_by_channel(silc_gwconn->client,
silc_gwconn->conn, silc_chconn->channel_entry,
refresh_nicklist_resolved, r);
}
}
示例10: silc_hash_table_replace_internal
static inline SilcBool
silc_hash_table_replace_internal(SilcHashTable ht, void *key, void *context,
SilcHashFunction hash,
void *hash_user_context)
{
SilcHashTableEntry *entry;
SilcUInt32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
SILC_HT_DEBUG(("index %d key %p", i, key));
entry = &ht->table[i];
if (*entry) {
/* The entry exists already. We have a collision, replace the old
key and context. */
if (ht->destructor)
ht->destructor((*entry)->key, (*entry)->context,
ht->destructor_user_context);
} else {
/* New key */
*entry = silc_calloc(1, sizeof(**entry));
if (!(*entry))
return FALSE;
ht->entry_count++;
}
(*entry)->key = key;
(*entry)->context = context;
if (SILC_HASH_REHASH_INC)
silc_hash_table_rehash(ht, 0);
return TRUE;
}
示例11: silc_attribute_payload_alloc
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;
}
示例12: silc_connauth_alloc
SilcConnAuth silc_connauth_alloc(SilcSchedule schedule,
SilcSKE ske,
SilcUInt32 timeout_secs)
{
SilcConnAuth connauth;
if (!schedule || !ske)
return NULL;
connauth = silc_calloc(1, sizeof(*connauth));
if (!connauth)
return NULL;
connauth->fsm = silc_fsm_alloc(connauth, silc_connauth_fsm_destructor,
NULL, schedule);
if (!connauth->fsm) {
silc_connauth_free(connauth);
return NULL;
}
connauth->timeout_secs = timeout_secs;
connauth->ske = ske;
ske->refcnt++;
return connauth;
}
示例13: silc_idlist_add_server
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;
}
示例14: silc_sftp_server_start
SilcSFTP silc_sftp_server_start(SilcStream stream,
SilcSchedule schedule,
SilcSFTPErrorCallback error_cb,
void *context,
SilcSFTPFilesystem fs)
{
SilcSFTPServer server;
if (!schedule)
schedule = silc_schedule_get_global();
server = silc_calloc(1, sizeof(*server));
if (!server)
return NULL;
server->stream = stream;
server->schedule = schedule;
server->error = error_cb;
server->context = context;
server->fs = fs;
/* We handle the stream now */
silc_stream_set_notifier(stream, schedule, silc_sftp_server_io, server);
SILC_LOG_DEBUG(("Starting SFTP server %p", server));
return (SilcSFTP)server;
}
示例15: silcpurple_buddy_keyagr_request
void silcpurple_buddy_keyagr_request(SilcClient client,
SilcClientConnection conn,
SilcClientEntry client_entry,
const char *hostname, SilcUInt16 port)
{
char tmp[128], tmp2[128];
SilcPurpleKeyAgrAsk a;
PurpleConnection *gc = client->application;
g_snprintf(tmp, sizeof(tmp),
_("Key agreement request received from %s. Would you like to "
"perform the key agreement?"), client_entry->nickname);
if (hostname)
g_snprintf(tmp2, sizeof(tmp2),
_("The remote user is waiting key agreement on:\n"
"Remote host: %s\nRemote port: %d"), hostname, port);
a = silc_calloc(1, sizeof(*a));
if (!a)
return;
a->client = client;
a->conn = conn;
a->client_id = *client_entry->id;
if (hostname)
a->hostname = strdup(hostname);
a->port = port;
purple_request_action(client->application, _("Key Agreement Request"), tmp,
hostname ? tmp2 : NULL, 1, gc->account, client_entry->nickname,
NULL, a, 2, _("Yes"), G_CALLBACK(silcpurple_buddy_keyagr_request_cb),
_("No"), G_CALLBACK(silcpurple_buddy_keyagr_request_cb));
}