From: Pekka Riikonen Date: Fri, 13 Feb 2004 17:30:01 +0000 (+0000) Subject: Added SILC_32|64_TO_PTR, SILC_PTR_TO_32|64 macros. Fixes compiler X-Git-Tag: silc.server.0.9.17~24 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=0e046c2c22d170617cd6a24ac1073cd1c03dd99b Added SILC_32|64_TO_PTR, SILC_PTR_TO_32|64 macros. Fixes compiler warnings on 64-bit systems (received on amd64). --- diff --git a/CHANGES b/CHANGES index 8b790919..aa7547ae 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,13 @@ Fri Feb 13 12:04:41 CET 2004 Jochen Eisinger Fixes problem when the primary router goes down. Affected files silcd/server.c, silcd/server_backup.c +Thu Feb 12 20:09:59 EET 2004 Pekka Riikonen + + * Added SILC_[32|64]_TO_PTR and SILC_PTR_TO_[32|64] macros. + Fixed various compilation warnings when type casting ints + to pointers or vice versa, of different size. Updates around + the source free. + Tue Feb 3 23:25:17 EET 2004 Pekka Riikonen * Surrogates not allowed in UTF-8 strings, updated decoder. diff --git a/apps/irssi/src/perl/Makefile.am b/apps/irssi/src/perl/Makefile.am index 08552bd7..4026b5f2 100644 --- a/apps/irssi/src/perl/Makefile.am +++ b/apps/irssi/src/perl/Makefile.am @@ -133,7 +133,7 @@ EXTRA_DIST = \ $(silc_sources) all-local: - for dir in $(perl_dirs); do \ + for dir in "$(perl_dirs)"; do \ cd $$dir && \ if [ ! -f Makefile ]; then \ $(perlpath) Makefile.PL $(PERL_MM_PARAMS); \ diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 9c014cb6..afb0cb1f 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -1607,7 +1607,7 @@ silc_server_accept_new_connection_lookup(SilcSocketConnection sock, sock->ip)); /* Listenning port */ - if (!server->sockets[(SilcUInt32)proto_ctx->context]) { + if (!server->sockets[SILC_PTR_TO_32(proto_ctx->context)]) { silc_server_disconnect_remote(server, sock, SILC_STATUS_ERR_RESOURCE_LIMIT, "Connection refused"); @@ -1615,7 +1615,7 @@ silc_server_accept_new_connection_lookup(SilcSocketConnection sock, silc_free(proto_ctx); return; } - port = server->sockets[(SilcUInt32)proto_ctx->context]->port; + port = server->sockets[SILC_PTR_TO_32(proto_ctx->context)]->port; /* Check whether this connection is denied to connect to us. */ deny = silc_server_config_find_denied(server, sock->ip); @@ -1741,7 +1741,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection) is accepted further. */ proto_ctx = silc_calloc(1, sizeof(*proto_ctx)); proto_ctx->server = server; - proto_ctx->context = (void *)fd; + proto_ctx->context = SILC_32_TO_PTR(fd); silc_socket_host_lookup(newsocket, TRUE, silc_server_accept_new_connection_lookup, (void *)proto_ctx, server->schedule); diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index e023ff23..ef15e546 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2003 Pekka Riikonen + Copyright (C) 1997 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -636,7 +636,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_start) silc_free(ctx); /* Notify application of failure */ - client->internal->ops->connected(client, conn, + client->internal->ops->connected(client, conn, SILC_CLIENT_CONN_ERROR_TIMEOUT); } return; @@ -1863,7 +1863,7 @@ void silc_client_process_failure(SilcClient client, /* Notify application */ client->internal->ops->failure(client, sock->user_data, sock->protocol, - (void *)failure); + SILC_32_TO_PTR(failure)); } } diff --git a/lib/silcclient/client_attrs.c b/lib/silcclient/client_attrs.c index 65a8b03e..7fee40ab 100644 --- a/lib/silcclient/client_attrs.c +++ b/lib/silcclient/client_attrs.c @@ -1,10 +1,10 @@ /* - client_attrs.c + client_attrs.c Author: Pekka Riikonen - Copyright (C) 2002 Pekka Riikonen + Copyright (C) 2002 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ typedef struct { static void silc_client_attributes_process_foreach(void *key, void *context, void *user_context) { - SilcAttribute attribute = (SilcAttribute)(SilcUInt32)key; + SilcAttribute attribute = (SilcAttribute)SILC_PTR_TO_32(key); SilcAttributePayload attr = context; SilcAttrForeach *f = user_context; const unsigned char *data; @@ -113,7 +113,7 @@ SilcBuffer silc_client_attributes_process(SilcClient client, continue; silc_hash_table_find_foreach(conn->internal->attrs, - (void *)(SilcUInt32)attribute, + SILC_32_TO_PTR(attribute), silc_client_attributes_process_foreach, &f); } @@ -163,7 +163,7 @@ SilcAttributePayload silc_client_attribute_add(SilcClient client, NULL, silc_client_attribute_destruct, NULL, TRUE); silc_hash_table_add(conn->internal->attrs, - (void *)(SilcUInt32)attribute, attr); + SILC_32_TO_PTR(attribute), attr); return attr; } @@ -177,7 +177,7 @@ static void silc_client_attribute_del_foreach(void *key, void *context, return; attribute = silc_attribute_get_attribute(attr); silc_hash_table_del_by_context(conn->internal->attrs, - (void *)(SilcUInt32)attribute, attr); + SILC_32_TO_PTR(attribute), attr); } /* Delete one attribute */ @@ -195,10 +195,10 @@ bool silc_client_attribute_del(SilcClient client, if (attr) { attribute = silc_attribute_get_attribute(attr); ret = silc_hash_table_del_by_context(conn->internal->attrs, - (void *)(SilcUInt32)attribute, attr); + SILC_32_TO_PTR(attribute), attr); } else if (attribute) { silc_hash_table_find_foreach(conn->internal->attrs, - (void *)(SilcUInt32)attribute, + SILC_32_TO_PTR(attribute), silc_client_attribute_del_foreach, conn); ret = TRUE; } else{ diff --git a/lib/silccore/silcidcache.c b/lib/silccore/silcidcache.c index fb284c22..9d93db20 100644 --- a/lib/silccore/silcidcache.c +++ b/lib/silccore/silcidcache.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2000 - 2001 Pekka Riikonen + Copyright (C) 2000 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -109,9 +109,9 @@ SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type, if (!cache) return NULL; cache->id_table = silc_hash_table_alloc(count, silc_hash_id, - (void *)(SilcUInt32)id_type, + SILC_32_TO_PTR(id_type), silc_hash_id_compare, - (void *)(SilcUInt32)id_type, + SILC_32_TO_PTR(id_type), silc_idcache_destructor, NULL, TRUE); cache->name_table = silc_hash_table_alloc(count, silc_hash_string, NULL, silc_hash_string_compare, NULL, diff --git a/lib/silcsftp/sftp_fs_memory.c b/lib/silcsftp/sftp_fs_memory.c index 7d1cba04..7fa78cfb 100644 --- a/lib/silcsftp/sftp_fs_memory.c +++ b/lib/silcsftp/sftp_fs_memory.c @@ -1,10 +1,10 @@ /* - sftp_fs_memory.c + sftp_fs_memory.c Author: Pekka Riikonen - Copyright (C) 2001 Pekka Riikonen + Copyright (C) 2001 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,8 +76,8 @@ static bool mem_add_entry(MemFSEntry dir, MemFSEntry entry, int i; /* Must be both write and exec permissions */ - if (check_perm && - !((dir->perm & SILC_SFTP_FS_PERM_WRITE) && + if (check_perm && + !((dir->perm & SILC_SFTP_FS_PERM_WRITE) && (dir->perm & SILC_SFTP_FS_PERM_EXEC))) return FALSE; @@ -150,7 +150,7 @@ static bool mem_del_entry(MemFSEntry entry, bool check_perm) return TRUE; } -/* Finds first occurence of entry named `name' under the directory `dir'. +/* Finds first occurence of entry named `name' under the directory `dir'. This does not check subdirectories recursively. */ static MemFSEntry mem_find_entry(MemFSEntry dir, const char *name, @@ -458,7 +458,7 @@ bool silc_sftp_fs_memory_del_file(SilcSFTPFilesystem fs, void *dir, if (!filename) return FALSE; - return mem_del_entry_name(dir ? dir : memfs->root, filename, + return mem_del_entry_name(dir ? dir : memfs->root, filename, strlen(filename), FALSE); } @@ -492,7 +492,7 @@ unsigned char *mem_encode_handle(void *context, SilcSFTP sftp, return data; } -void mem_open(void *context, SilcSFTP sftp, +void mem_open(void *context, SilcSFTP sftp, const char *filename, SilcSFTPFileOperation pflags, SilcSFTPAttributes attrs, @@ -520,20 +520,20 @@ void mem_open(void *context, SilcSFTP sftp, if (entry->directory || !entry->data) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } /* Check for reading */ - if ((pflags & SILC_SFTP_FXF_READ) && + if ((pflags & SILC_SFTP_FXF_READ) && !(entry->perm & SILC_SFTP_FS_PERM_READ)) { - (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, callback_context); return; - } + } /* Check for writing */ - if (((pflags & SILC_SFTP_FXF_WRITE) || (pflags & SILC_SFTP_FXF_APPEND)) && + if (((pflags & SILC_SFTP_FXF_WRITE) || (pflags & SILC_SFTP_FXF_APPEND)) && !(entry->perm & SILC_SFTP_FS_PERM_WRITE)) { - (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, callback_context); return; } @@ -548,7 +548,7 @@ void mem_open(void *context, SilcSFTP sftp, flags |= O_APPEND; /* Attempt to open the file for real. */ - fd = silc_file_open_mode(entry->data + 7, flags, + fd = silc_file_open_mode(entry->data + 7, flags, (attrs->flags & SILC_SFTP_ATTR_PERMISSIONS ? attrs->permissions : 0600)); if (fd == -1) { @@ -559,10 +559,10 @@ void mem_open(void *context, SilcSFTP sftp, /* File opened, return handle */ handle = mem_create_handle(fs, fd, entry); if (handle) - (*callback)(sftp, SILC_SFTP_STATUS_OK, (SilcSFTPHandle)handle, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (SilcSFTPHandle)handle, callback_context); else - (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, callback_context); } @@ -578,7 +578,7 @@ void mem_close(void *context, SilcSFTP sftp, if (h->fd != -1) { ret = silc_file_close(h->fd); if (ret == -1) { - (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, + (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, callback_context); return; } @@ -590,7 +590,7 @@ void mem_close(void *context, SilcSFTP sftp, void mem_read(void *context, SilcSFTP sftp, SilcSFTPHandle handle, - SilcUInt64 offset, + SilcUInt64 offset, SilcUInt32 len, SilcSFTPDataCallback callback, void *callback_context) @@ -621,7 +621,7 @@ void mem_read(void *context, SilcSFTP sftp, } /* Return data */ - (*callback)(sftp, SILC_SFTP_STATUS_OK, (const unsigned char *)data, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (const unsigned char *)data, ret, callback_context); silc_free(data); @@ -643,7 +643,7 @@ void mem_write(void *context, SilcSFTP sftp, /* Attempt to write */ ret = silc_file_write(h->fd, data, data_len); if (ret <= 0) { - (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, + (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, callback_context); return; } @@ -657,7 +657,7 @@ void mem_remove(void *context, SilcSFTP sftp, void *callback_context) { /* Remove is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -668,7 +668,7 @@ void mem_rename(void *context, SilcSFTP sftp, void *callback_context) { /* Rename is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -679,7 +679,7 @@ void mem_mkdir(void *context, SilcSFTP sftp, void *callback_context) { /* Mkdir is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -689,7 +689,7 @@ void mem_rmdir(void *context, SilcSFTP sftp, void *callback_context) { /* Rmdir is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -715,11 +715,11 @@ void mem_opendir(void *context, SilcSFTP sftp, if (!entry->directory) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } /* Must be read permissions to open a directory */ if (!(entry->perm & SILC_SFTP_FS_PERM_READ)) { - (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, callback_context); return; } @@ -727,10 +727,10 @@ void mem_opendir(void *context, SilcSFTP sftp, /* Directory opened, return handle */ handle = mem_create_handle(fs, 0, entry); if (handle) - (*callback)(sftp, SILC_SFTP_STATUS_OK, (SilcSFTPHandle)handle, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (SilcSFTPHandle)handle, callback_context); else - (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_PERMISSION_DENIED, NULL, callback_context); } @@ -795,8 +795,8 @@ void mem_readdir(void *context, SilcSFTP sftp, ((entry->perm & SILC_SFTP_FS_PERM_WRITE) ? 'w' : '-'), ((entry->perm & SILC_SFTP_FS_PERM_EXEC) ? 'x' : '-'), (entry->directory ? (int)entry->entry_count : 1), - filesize, date, entry->name, - (entry->directory ? "/" : + (unsigned long long)filesize, date, entry->name, + (entry->directory ? "/" : ((entry->perm & SILC_SFTP_FS_PERM_EXEC) ? "*" : ""))); /* Add attributes */ @@ -864,7 +864,7 @@ void mem_stat(void *context, SilcSFTP sftp, if (entry->directory || !entry->data) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } /* Get real stat */ ret = stat(entry->data + 7, &stats); @@ -877,7 +877,7 @@ void mem_stat(void *context, SilcSFTP sftp, if (!attrs) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } attrs->flags = (SILC_SFTP_ATTR_SIZE | SILC_SFTP_ATTR_UIDGID | SILC_SFTP_ATTR_ACMODTIME); @@ -888,7 +888,7 @@ void mem_stat(void *context, SilcSFTP sftp, attrs->mtime = stats.st_mtime; /* Return attributes */ - (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, callback_context); silc_sftp_attr_free(attrs); @@ -918,7 +918,7 @@ void mem_lstat(void *context, SilcSFTP sftp, if (entry->directory || !entry->data) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } /* Get real stat */ #ifndef SILC_WIN32 @@ -935,7 +935,7 @@ void mem_lstat(void *context, SilcSFTP sftp, if (!attrs) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } attrs->flags = (SILC_SFTP_ATTR_SIZE | SILC_SFTP_ATTR_UIDGID | SILC_SFTP_ATTR_ACMODTIME); @@ -946,7 +946,7 @@ void mem_lstat(void *context, SilcSFTP sftp, attrs->mtime = stats.st_mtime; /* Return attributes */ - (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, callback_context); silc_sftp_attr_free(attrs); @@ -965,7 +965,7 @@ void mem_fstat(void *context, SilcSFTP sftp, if (h->entry->directory || !h->entry->data) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } /* Get real stat */ ret = fstat(h->fd, &stats); @@ -978,7 +978,7 @@ void mem_fstat(void *context, SilcSFTP sftp, if (!attrs) { (*callback)(sftp, SILC_SFTP_STATUS_FAILURE, NULL, callback_context); return; - } + } attrs->flags = (SILC_SFTP_ATTR_SIZE | SILC_SFTP_ATTR_UIDGID | SILC_SFTP_ATTR_ACMODTIME); @@ -989,12 +989,12 @@ void mem_fstat(void *context, SilcSFTP sftp, attrs->mtime = stats.st_mtime; /* Return attributes */ - (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPAttributes)attrs, callback_context); silc_sftp_attr_free(attrs); } - + void mem_setstat(void *context, SilcSFTP sftp, const char *path, SilcSFTPAttributes attrs, @@ -1002,7 +1002,7 @@ void mem_setstat(void *context, SilcSFTP sftp, void *callback_context) { /* Setstat is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -1013,7 +1013,7 @@ void mem_fsetstat(void *context, SilcSFTP sftp, void *callback_context) { /* Fsetstat is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -1034,7 +1034,7 @@ void mem_symlink(void *context, SilcSFTP sftp, void *callback_context) { /* Symlink is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, NULL, callback_context); } @@ -1074,7 +1074,7 @@ void mem_realpath(void *context, SilcSFTP sftp, goto fail; name->count = 1; - (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPName)name, + (*callback)(sftp, SILC_SFTP_STATUS_OK, (const SilcSFTPName)name, callback_context); silc_sftp_name_free(name); @@ -1092,7 +1092,7 @@ void mem_extended(void *context, SilcSFTP sftp, void *callback_context) { /* Extended is not supported */ - (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, 0, + (*callback)(sftp, SILC_SFTP_STATUS_OP_UNSUPPORTED, NULL, 0, callback_context); } diff --git a/lib/silcsftp/sftp_server.c b/lib/silcsftp/sftp_server.c index 8c96355a..f23d1e86 100644 --- a/lib/silcsftp/sftp_server.c +++ b/lib/silcsftp/sftp_server.c @@ -1,10 +1,10 @@ /* - sftp_server.c + sftp_server.c Author: Pekka Riikonen - Copyright (C) 2001 Pekka Riikonen + Copyright (C) 2001 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ typedef struct { /* General routine to send SFTP packet to the SFTP client. */ static void silc_sftp_send_packet(SilcSFTPServer sftp, - SilcSFTPPacket type, + SilcSFTPPacket type, SilcUInt32 len, ...) { SilcBuffer tmp; @@ -50,7 +50,7 @@ static void silc_sftp_send_packet(SilcSFTPServer sftp, return; sftp->packet = tmp; - SILC_LOG_HEXDUMP(("SFTP packet to client"), sftp->packet->data, + SILC_LOG_HEXDUMP(("SFTP packet to client"), sftp->packet->data, sftp->packet->len); /* Send the packet */ @@ -86,12 +86,12 @@ static void silc_sftp_server_status(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); int mlen, llen; SILC_LOG_DEBUG(("Status callback")); SILC_LOG_DEBUG(("Request ID: %d", id)); - + if (!message) message = ""; if (!language_tag) @@ -117,7 +117,7 @@ static void silc_sftp_server_handle(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); unsigned char *hdata; SilcUInt32 hdata_len; @@ -152,7 +152,7 @@ static void silc_sftp_server_data(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); SILC_LOG_DEBUG(("Data callback")); SILC_LOG_DEBUG(("Request ID: %d", id)); @@ -177,7 +177,7 @@ static void silc_sftp_server_name(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); SilcBuffer namebuf; SILC_LOG_DEBUG(("Name callback")); @@ -208,7 +208,7 @@ static void silc_sftp_server_attr(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); SilcBuffer attr_buf; SILC_LOG_DEBUG(("Attr callback")); @@ -242,7 +242,7 @@ static void silc_sftp_server_extended(SilcSFTP sftp, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; - SilcUInt32 id = (SilcUInt32)context; + SilcUInt32 id = SILC_PTR_TO_32(context); SILC_LOG_DEBUG(("Extended callback")); SILC_LOG_DEBUG(("Request ID: %d", id)); @@ -300,7 +300,7 @@ void silc_sftp_server_shutdown(SilcSFTP sftp) void silc_sftp_server_set_monitor(SilcSFTP sftp, SilcSFTPMonitors monitors, - SilcSFTPMonitor monitor, + SilcSFTPMonitor monitor, void *context) { SilcSFTPServer server = (SilcSFTPServer)sftp; @@ -332,7 +332,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, SILC_LOG_DEBUG(("Start")); /* Parse the packet */ - type = silc_sftp_packet_decode(packet->buffer, (unsigned char **)&payload, + type = silc_sftp_packet_decode(packet->buffer, (unsigned char **)&payload, &payload_len); if (!type) return; @@ -380,7 +380,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, SILC_STR_UI_INT(&id), SILC_STR_UI32_STRING_ALLOC(&filename), SILC_STR_UI_INT(&pflags), - SILC_STR_UI32_NSTRING(&attr_buf, + SILC_STR_UI32_NSTRING(&attr_buf, &attr_len), SILC_STR_END); if (ret < 0) @@ -407,7 +407,8 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Open operation */ server->fs->fs->sftp_open(server->fs->fs_context, sftp, filename, pflags, - attrs, silc_sftp_server_handle, (void *)id); + attrs, silc_sftp_server_handle, + SILC_32_TO_PTR(id)); silc_free(filename); silc_sftp_attr_free(attrs); @@ -423,7 +424,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_END); if (ret < 0) @@ -446,7 +447,8 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Close operation */ server->fs->fs->sftp_close(server->fs->fs_context, sftp, handle, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); + } break; @@ -461,7 +463,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_UI_INT64(&offset), SILC_STR_UI_INT(&len), @@ -487,9 +489,9 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, } /* Read operation */ - server->fs->fs->sftp_read(server->fs->fs_context, sftp, + server->fs->fs->sftp_read(server->fs->fs_context, sftp, handle, offset, len, - silc_sftp_server_data, (void *)id); + silc_sftp_server_data, SILC_32_TO_PTR(id)); } break; @@ -505,10 +507,10 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_UI_INT64(&offset), - SILC_STR_UI32_NSTRING(&data, + SILC_STR_UI32_NSTRING(&data, &data_len), SILC_STR_END); if (ret < 0) @@ -532,9 +534,9 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, } /* Write operation */ - server->fs->fs->sftp_write(server->fs->fs_context, sftp, handle, offset, + server->fs->fs->sftp_write(server->fs->fs_context, sftp, handle, offset, (const unsigned char *)data, data_len, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); } break; @@ -558,7 +560,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Remove operation */ server->fs->fs->sftp_remove(server->fs->fs_context, sftp, filename, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_free(filename); } @@ -587,9 +589,9 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, } /* Rename operation */ - server->fs->fs->sftp_rename(server->fs->fs_context, sftp, + server->fs->fs->sftp_rename(server->fs->fs_context, sftp, filename, newname, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_free(filename); silc_free(newname); @@ -633,7 +635,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Mkdir operation */ server->fs->fs->sftp_mkdir(server->fs->fs_context, sftp, path, attrs, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_sftp_attr_free(attrs); silc_free(path); @@ -660,7 +662,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Rmdir operation */ server->fs->fs->sftp_rmdir(server->fs->fs_context, sftp, path, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_free(path); } @@ -686,7 +688,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Opendir operation */ server->fs->fs->sftp_opendir(server->fs->fs_context, sftp, path, - silc_sftp_server_handle, (void *)id); + silc_sftp_server_handle, SILC_32_TO_PTR(id)); silc_free(path); } @@ -701,7 +703,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_END); if (ret < 0) @@ -724,7 +726,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Readdir operation */ server->fs->fs->sftp_readdir(server->fs->fs_context, sftp, handle, - silc_sftp_server_name, (void *)id); + silc_sftp_server_name, SILC_32_TO_PTR(id)); } break; @@ -748,7 +750,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Stat operation */ server->fs->fs->sftp_stat(server->fs->fs_context, sftp, path, - silc_sftp_server_attr, (void *)id); + silc_sftp_server_attr, SILC_32_TO_PTR(id)); silc_free(path); } @@ -774,7 +776,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Lstat operation */ server->fs->fs->sftp_lstat(server->fs->fs_context, sftp, path, - silc_sftp_server_attr, (void *)id); + silc_sftp_server_attr, SILC_32_TO_PTR(id)); silc_free(path); } @@ -789,7 +791,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_END); if (ret < 0) @@ -812,7 +814,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Fstat operation */ server->fs->fs->sftp_fstat(server->fs->fs_context, sftp, handle, - silc_sftp_server_attr, (void *)id); + silc_sftp_server_attr, SILC_32_TO_PTR(id)); } break; @@ -853,7 +855,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Setstat operation */ server->fs->fs->sftp_setstat(server->fs->fs_context, sftp, path, attrs, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_sftp_attr_free(attrs); silc_free(path); @@ -870,7 +872,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&id), - SILC_STR_UI32_NSTRING(&hdata, + SILC_STR_UI32_NSTRING(&hdata, &hdata_len), SILC_STR_UI32_NSTRING(&attr_buf, &attr_len), @@ -905,9 +907,10 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, } /* Fsetstat operation */ - server->fs->fs->sftp_fsetstat(server->fs->fs_context, sftp, + server->fs->fs->sftp_fsetstat(server->fs->fs_context, sftp, handle, attrs, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, + SILC_32_TO_PTR(id)); silc_sftp_attr_free(attrs); } @@ -933,7 +936,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Readlink operation */ server->fs->fs->sftp_readlink(server->fs->fs_context, sftp, path, - silc_sftp_server_name, (void *)id); + silc_sftp_server_name, SILC_32_TO_PTR(id)); silc_free(path); } @@ -963,7 +966,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Symlink operation */ server->fs->fs->sftp_symlink(server->fs->fs_context, sftp, path, target, - silc_sftp_server_status, (void *)id); + silc_sftp_server_status, SILC_32_TO_PTR(id)); silc_free(path); silc_free(target); @@ -990,7 +993,7 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, /* Realpath operation */ server->fs->fs->sftp_realpath(server->fs->fs_context, sftp, path, - silc_sftp_server_name, (void *)id); + silc_sftp_server_name, SILC_32_TO_PTR(id)); silc_free(path); } @@ -1027,9 +1030,10 @@ void silc_sftp_server_receive_process(SilcSFTP sftp, } /* Extended operation */ - server->fs->fs->sftp_extended(server->fs->fs_context, sftp, + server->fs->fs->sftp_extended(server->fs->fs_context, sftp, request, data, data_len, - silc_sftp_server_extended, (void *)id); + silc_sftp_server_extended, + SILC_32_TO_PTR(id)); silc_free(request); } diff --git a/lib/silcutil/silclog.c b/lib/silcutil/silclog.c index 736edb03..ccbb8efc 100644 --- a/lib/silcutil/silclog.c +++ b/lib/silcutil/silclog.c @@ -4,7 +4,7 @@ Author: Giovanni Giacobbi - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 1997 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -123,7 +123,7 @@ static void silc_log_checksize(SilcLog log) /* It's too big */ fprintf(log->fp, "[%s] [%s] Cycling log file, over max " "logsize (%lu kilobytes)\n", - silc_get_time(0), log->typename, log->maxsize / 1024); + silc_get_time(0), log->typename, (unsigned long)log->maxsize / 1024); fflush(log->fp); fclose(log->fp); memset(newname, 0, sizeof(newname)); @@ -302,7 +302,7 @@ bool silc_log_set_file(SilcLogType type, char *filename, SilcUInt32 maxsize, if (silc_log_scheduled) return TRUE; - /* Add schedule hook with a short delay to make sure we'll use + /* Add schedule hook with a short delay to make sure we'll use right delay */ silc_schedule_task_add(scheduler, 0, silc_log_fflush_callback, (void *) scheduler, 10, 0, diff --git a/lib/silcutil/silctypes.h b/lib/silcutil/silctypes.h index c763f8fa..1b016eda 100644 --- a/lib/silcutil/silctypes.h +++ b/lib/silcutil/silctypes.h @@ -1,10 +1,10 @@ /* - silctypes.h + silctypes.h Author: Pekka Riikonen - Copyright (C) 2002 Pekka Riikonen + Copyright (C) 2002 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -491,4 +491,91 @@ do { \ (((SilcUInt32)(l) & (SilcUInt32)0xFF000000UL) >> 24)) /***/ +/****d* silcutil/SILCTypes/SILC_PTR_TO_32 + * + * NAME + * + * #define SILC_PTR_TO_32 ... + * + * DESCRIPTION + * + * Type casts a pointer's value into a 32-bit integer. Use this to + * avoid compiler warnings when type casting pointers to integers + * of different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_PTR_TO_32(_ptr__) ((SilcUInt32)(_ptr__)) +#else +#define SILC_PTR_TO_32(_ptr__) \ + ((SilcUInt32)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL)) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_PTR_TO_64 + * + * NAME + * + * #define SILC_PTR_TO_64 ... + * + * DESCRIPTION + * + * Type casts a pointer's value into a 64-bit integer. Use this to + * avoid compiler warnings when type casting pointers to integers + * of different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_PTR_TO_64(_ptr__) ((SilcUInt64)((SilcUInt32)(_ptr__))) +#else +#define SILC_PTR_TO_64(_ptr__) \ + ((SilcUInt64)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL)) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_32_TO_PTR + * + * NAME + * + * #define SILC_PTR_TO_32 ... + * + * DESCRIPTION + * + * Type casts a 32-bit integer value into a pointer. Use this to + * avoid compiler warnings when type casting integers to pointers of + * different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt32)(_ival__))) +#else +#define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__))) +#endif +/***/ + +/****d* silcutil/SILCTypes/SILC_64_TO_PTR + * + * NAME + * + * #define SILC_PTR_TO_64 ... + * + * DESCRIPTION + * + * Type casts a 64-bit integer value into a pointer. Use this to + * avoid compiler warnings when type casting integers to pointers of + * different size. + * + * SOURCE + */ +#if SILC_SIZEOF_VOID_P < 8 +#define SILC_64_TO_PTR(_ival__) \ + ((void *)((SilcUInt32)((SilcUInt64)(_ival__) & (SilcUInt32)0xFFFFFFFFUL))) +#else +#define SILC_64_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__))) +#endif +/***/ + #endif /* SILCTYPES_H */ diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index f665344e..4715e926 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2003 Pekka Riikonen + Copyright (C) 1997 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -478,14 +478,14 @@ SilcUInt32 silc_hash_uint(void *key, void *user_context) SilcUInt32 silc_hash_ptr(void *key, void *user_context) { - return (SilcUInt32)key; + return SILC_PTR_TO_32(key); } /* Hash a ID. The `user_context' is the ID type. */ SilcUInt32 silc_hash_id(void *key, void *user_context) { - SilcIdType id_type = (SilcIdType)(SilcUInt32)user_context; + SilcIdType id_type = (SilcIdType)SILC_PTR_TO_32(user_context); SilcUInt32 h = 0; int i; @@ -553,7 +553,7 @@ SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context) SilcUInt32 silc_hash_data(void *key, void *user_context) { - SilcUInt32 len = (SilcUInt32)user_context, h = 0; + SilcUInt32 len = SILC_PTR_TO_32(user_context), h = 0; unsigned char *data = (unsigned char *)key; int i; @@ -571,7 +571,7 @@ SilcUInt32 silc_hash_public_key(void *key, void *user_context) SilcPublicKey pk = (SilcPublicKey)key; return (pk->len + silc_hash_string(pk->name, NULL) + silc_hash_string(pk->identifier, NULL) + - silc_hash_data(pk->pk, (void *)pk->pk_len)); + silc_hash_data(pk->pk, SILC_32_TO_PTR(pk->pk_len))); } /* Compares two strings. It may be used as SilcHashTable comparison @@ -588,7 +588,7 @@ bool silc_hash_string_compare(void *key1, void *key2, void *user_context) bool silc_hash_id_compare(void *key1, void *key2, void *user_context) { - SilcIdType id_type = (SilcIdType)(SilcUInt32)user_context; + SilcIdType id_type = (SilcIdType)SILC_PTR_TO_32(user_context); return (id_type == SILC_ID_CLIENT ? SILC_ID_COMPARE_HASH((SilcClientID *)key1, (SilcClientID *)key2) : SILC_ID_COMPARE_TYPE(key1, key2, id_type)); @@ -605,7 +605,7 @@ bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context) bool silc_hash_data_compare(void *key1, void *key2, void *user_context) { - SilcUInt32 len = (SilcUInt32)user_context; + SilcUInt32 len = SILC_PTR_TO_32(user_context); return !memcmp(key1, key2, len); }