From 392c65ba9e06f633115ab2b88ebdbbb63ccc59c8 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 29 Jan 2002 20:24:41 +0000 Subject: [PATCH] updates --- CHANGES | 12 ++ Makefile.defines.pre | 3 +- TODO | 6 +- apps/irssi/src/core/nick-rec.h | 2 - apps/irssi/src/core/nicklist.c | 2 - apps/irssi/src/fe-text/screen.c | 10 +- apps/irssi/src/fe-text/screen.h | 2 + apps/irssi/src/fe-text/silc.c | 12 +- apps/irssi/src/silc/core/clientutil.c | 6 +- apps/irssi/src/silc/core/silc-servers.c | 7 +- apps/silcd/command.c | 2 + configure.in.pre | 4 +- distributions | 6 +- doc/CodingStyle | 6 +- includes/silcincludes.h | 15 +- lib/Makefile.am.pre | 8 +- lib/silcclient/client.c | 15 +- lib/silcclient/command.c | 2 - lib/silcclient/idlist.c | 1 + lib/silccrypt/silccipher.c | 2 + lib/silccrypt/silchash.c | 23 ++- lib/silccrypt/silcpkcs.c | 4 + lib/silccrypt/silcrng.c | 2 +- lib/silcsftp/sftp_client.c | 1 - lib/silcutil/Makefile.am | 2 + lib/silcutil/silcbuffer.h | 20 +- lib/silcutil/silcbufutil.h | 8 +- lib/silcutil/silcdlist.h | 156 ++++++++++++++ lib/silcutil/silclist.h | 261 ++++++++++++++++++++++++ prepare | 8 - prepare-clean | 4 - win32/Makefile.am | 2 +- win32/libsilc/libsilc.def | 65 ------ win32/trq_conf.h | 62 ------ 34 files changed, 536 insertions(+), 205 deletions(-) create mode 100644 lib/silcutil/silcdlist.h create mode 100644 lib/silcutil/silclist.h delete mode 100644 win32/trq_conf.h diff --git a/CHANGES b/CHANGES index c6e15aca..c6eef9a9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +Tue Jan 29 19:49:31 EET 2002 Pekka Riikonen + + * Applied patches from cras: + + Memory leak fixes around libaries, irssi window resize fix, + new silclist.h and silcdlist.h, all extern inline changed to + static inline. + + * Removed dotconf from lib/dotconf, not needed anymore. + + * Removed TRQ from lib/trq, not needed anymore. + Tue Jan 29 10:35:03 CET 2002 Pekka Riikonen * Fixed a crash in server related to channel announcements. diff --git a/Makefile.defines.pre b/Makefile.defines.pre index af48710c..e85d49b6 100644 --- a/Makefile.defines.pre +++ b/Makefile.defines.pre @@ -55,8 +55,7 @@ INCLUDES = $(ADD_INCLUDES) $(SILC_CFLAGS) \ -I$(silc_top_srcdir)/lib/silcclient \ -I$(silc_top_srcdir)/lib/contrib \ -I$(silc_top_srcdir)/includes \ - -I$(silc_top_srcdir)/doc \ - -I$(silc_top_srcdir)/lib/trq + -I$(silc_top_srcdir)/doc # #includes-install: Makefile diff --git a/TODO b/TODO index 66182444..d076aa66 100644 --- a/TODO +++ b/TODO @@ -30,6 +30,9 @@ TODO/bugs in Irssi SILC client TODO/bugs In SILC Client Library ================================ + o Rewrite the channel's user list thingy and cross list it to the + Client entry. + o The PRIVATE_MESSAGE_KEY packet is not handled (it is implemented though). This should be added and perhaps new client operation should be added to notify application that it was received and @@ -68,8 +71,7 @@ TODO/bugs In SILC Server each JOIN command will create and distribute the new channel key to everybody on the channel. - o New configuration file format must be added. The new one will be - done using the dotconf config library (lib/dotconf). The following + o New configuration file format must be added. The following tasks relates closely to this as well and must be done at the same time when adding the new config file format: diff --git a/apps/irssi/src/core/nick-rec.h b/apps/irssi/src/core/nick-rec.h index 7dff6f32..c4cd8bfd 100644 --- a/apps/irssi/src/core/nick-rec.h +++ b/apps/irssi/src/core/nick-rec.h @@ -20,8 +20,6 @@ unsigned int op:1; unsigned int halfop:1; unsigned int voice:1; -GHashTable *module_data; - void *unique_id; /* unique ID to use for comparing if one nick is in another channels, or NULL = nicks are unique, just keep comparing them. */ NICK_REC *next; /* support for multiple identically named nicks */ diff --git a/apps/irssi/src/core/nicklist.c b/apps/irssi/src/core/nicklist.c index f9539ff3..96f6a8ea 100644 --- a/apps/irssi/src/core/nicklist.c +++ b/apps/irssi/src/core/nicklist.c @@ -76,8 +76,6 @@ static void nick_hash_remove(CHANNEL_REC *channel, NICK_REC *nick) /* Add new nick to list */ void nicklist_insert(CHANNEL_REC *channel, NICK_REC *nick) { - MODULE_DATA_INIT(nick); - nick->type = module_get_uniq_id("NICK", 0); nick->chat_type = channel->chat_type; diff --git a/apps/irssi/src/fe-text/screen.c b/apps/irssi/src/fe-text/screen.c index 5378b5c9..89a63613 100644 --- a/apps/irssi/src/fe-text/screen.c +++ b/apps/irssi/src/fe-text/screen.c @@ -41,13 +41,19 @@ static int scrx, scry; static int use_colors; static int freeze_refresh; +static int resized; static int init_screen_int(void); static void deinit_screen_int(void); #ifdef SIGWINCH - static void sig_winch(int p) +{ + resized = TRUE; +} +#endif + +void screen_check_resizes(void) { #if defined (TIOCGWINSZ) && defined (HAVE_CURSES_RESIZETERM) struct winsize ws; @@ -73,8 +79,8 @@ static void sig_winch(int p) #endif mainwindows_resize(COLS, LINES); + resized = FALSE; } -#endif static void read_signals(void) { diff --git a/apps/irssi/src/fe-text/screen.h b/apps/irssi/src/fe-text/screen.h index c1449bfb..700aba5c 100644 --- a/apps/irssi/src/fe-text/screen.h +++ b/apps/irssi/src/fe-text/screen.h @@ -31,6 +31,8 @@ #define is_big5(hi,lo) is_big5_hi(hi) && (is_big5_los(lo) || is_big5_lox(lo)) #endif WANT_BIG5 +void screen_check_resizes(void); + int init_screen(void); /* Initialize screen, detect screen length */ void deinit_screen(void); /* Deinitialize screen */ diff --git a/apps/irssi/src/fe-text/silc.c b/apps/irssi/src/fe-text/silc.c index a4203e47..32ec6bd2 100644 --- a/apps/irssi/src/fe-text/silc.c +++ b/apps/irssi/src/fe-text/silc.c @@ -83,7 +83,7 @@ static int display_firsttimer = FALSE; static void sig_exit(void) { - g_main_quit(main_loop); + quitting = TRUE; } /* redraw irssi's screen.. */ @@ -160,7 +160,6 @@ static void textui_finish_init(void) static void textui_deinit(void) { - quitting = TRUE; signal(SIGINT, SIG_DFL); screen_refresh_freeze(); @@ -280,6 +279,8 @@ int main(int argc, char **argv) textdomain(PACKAGE); #endif + quitting = FALSE; + textui_init(); args_execute(argc, argv); silc_init_finish(); @@ -289,7 +290,12 @@ int main(int argc, char **argv) textui_finish_init(); main_loop = g_main_new(TRUE); - g_main_run(main_loop); + + while (!quitting) { + g_main_iteration(TRUE); + screen_check_resizes(); + } + g_main_destroy(main_loop); textui_deinit(); diff --git a/apps/irssi/src/silc/core/clientutil.c b/apps/irssi/src/silc/core/clientutil.c index bd559484..b6480e6a 100644 --- a/apps/irssi/src/silc/core/clientutil.c +++ b/apps/irssi/src/silc/core/clientutil.c @@ -303,14 +303,16 @@ int silc_client_check_silc_dir() memset(file_public_key, 0, sizeof(file_public_key)); memset(file_private_key, 0, sizeof(file_private_key)); + identifier = silc_client_create_identifier(); + pw = getpwuid(getuid()); if (!pw) { fprintf(stderr, "silc: %s\n", strerror(errno)); + if (identifier) + silc_free(identifier); return FALSE; } - identifier = silc_client_create_identifier(); - /* We'll take home path from /etc/passwd file to be sure. */ snprintf(filename, sizeof(filename) - 1, "%s/.silc/", pw->pw_dir); snprintf(servfilename, sizeof(servfilename) - 1, "%s/.silc/serverkeys", diff --git a/apps/irssi/src/silc/core/silc-servers.c b/apps/irssi/src/silc/core/silc-servers.c index e4e73933..ef0170b7 100644 --- a/apps/irssi/src/silc/core/silc-servers.c +++ b/apps/irssi/src/silc/core/silc-servers.c @@ -203,6 +203,7 @@ static void sig_connected(SILC_SERVER_REC *server) fd = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle)); silc_client_start_key_exchange(silc_client, conn, fd); + server->ftp_sessions = silc_dlist_init(); server->isnickflag = isnickflag_func; server->ischannel = ischannel_func; server->get_nick_flags = get_nick_flags; @@ -213,7 +214,9 @@ static void sig_disconnected(SILC_SERVER_REC *server) { if (!IS_SILC_SERVER(server)) return; - + + silc_dlist_uninit(server->ftp_sessions); + if (server->conn && server->conn->sock != NULL) { silc_client_close_connection(silc_client, NULL, server->conn); @@ -249,8 +252,6 @@ SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn) return NULL; } - server->ftp_sessions = silc_dlist_init(); - return server; } diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 62ada13e..b0f3f98f 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -561,6 +561,8 @@ silc_server_command_whois_check(SilcServerCommandContext cmd, int i, k; bool no_res = TRUE; + SILC_LOG_DEBUG(("Start")); + for (i = 0; i < clients_count; i++) { entry = clients[i]; if (!entry) diff --git a/configure.in.pre b/configure.in.pre index dc2d40ba..b7acfd23 100644 --- a/configure.in.pre +++ b/configure.in.pre @@ -67,7 +67,7 @@ AC_HEADER_STAT # More header checking AC_CHECK_HEADERS(unistd.h string.h getopt.h errno.h fcntl.h assert.h) -AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/time.h) +AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/time.h stddef.h) AC_CHECK_HEADERS(netinet/in.h netinet/tcp.h xti.h netdb.h) AC_CHECK_HEADERS(pwd.h grp.h termcap.h paths.h) AC_CHECK_HEADERS(ncurses.h signal.h ctype.h regex.h) @@ -755,8 +755,6 @@ fi # # Other configure scripts # -#AC_CONFIG_SUBDIRS(lib/dotconf) -AC_CONFIG_SUBDIRS(lib/trq) AC_CONFIG_SUBDIRS(irssi) AC_CONFIG_SUBDIRS(lib/silcmath/mpi) #AC_CONFIG_SUBDIRS(lib/zlib) diff --git a/distributions b/distributions index 0c1eb928..ae8e787f 100644 --- a/distributions +++ b/distributions @@ -57,14 +57,14 @@ toolkit_EXTRA_DIST=README.CVS README.WIN32 silcer # Irssi SILC Client distribution client_SUBDIRS=lib irssi doc includes -client_SUBDIRS_lib=contrib silccore silccrypt silcsim silcmath silcske silcutil trq silcclient silcsftp +client_SUBDIRS_lib=contrib silccore silccrypt silcsim silcmath silcske silcutil silcclient silcsftp client_SUBDIRS_doc=$(COMMONDIRS) client_DISTLABEL=SILC_DIST_CLIENT client_EXTRA_DIST=# # SILC Server distribution server_SUBDIRS=lib silcd doc includes -server_SUBDIRS_lib=contrib silccore silccrypt silcsim silcmath silcske silcutil trq silcsftp +server_SUBDIRS_lib=contrib silccore silccrypt silcsim silcmath silcske silcutil silcsftp server_SUBDIRS_doc=$(COMMONDIRS) server_DISTLABEL=SILC_DIST_SERVER server_EXTRA_DIST=# @@ -72,7 +72,7 @@ server_EXTRA_DIST=# # Native WIN32 SILC library distribution (will include only the libraries) # XXX This is not really used at all! win32dll_SUBDIRS=lib doc includes -win32dll_SUBDIRS_lib=silccore silccrypt silcsim silcmath silcske silcutil trq silcclient +win32dll_SUBDIRS_lib=silccore silccrypt silcsim silcmath silcske silcutil silcclient win32dll_SUBDIRS_doc=$(COMMONDIRS) win32dll_DISTLABEL=SILC_DIST_WIN32DLL win32dll_EXTRA_DIST=README.CVS README.WIN32 diff --git a/doc/CodingStyle b/doc/CodingStyle index 3f34557f..1a891424 100644 --- a/doc/CodingStyle +++ b/doc/CodingStyle @@ -576,9 +576,9 @@ Lists ===== SILC has two different list API's. The List API and the Dynamic List API. -Both are based on the TRQ library. For definitions of List API see -lib/trq/silclist.h and for Dynamic List API see lib/trq/silcdlist.h. -Following short example of the List API. +For definitions of List API see lib/silcutil/silclist.h and for Dynamic +List API see lib/silcutil/silcdlist.h. Following short example of the +List API. List API diff --git a/includes/silcincludes.h b/includes/silcincludes.h index 9117082c..56e26539 100644 --- a/includes/silcincludes.h +++ b/includes/silcincludes.h @@ -138,6 +138,10 @@ #include #endif +#ifdef HAVE_STDDEF_H +#include +#endif + #endif /* !SILC_WIN32 */ #ifndef HAVE_GETOPT_LONG @@ -151,6 +155,11 @@ #define FALSE 0 #endif +/* Define offsetof */ +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + /* Define types. The types must be at least of the specified size */ #undef uint8 #undef uint16 @@ -237,6 +246,8 @@ typedef uint32 * void *; #include "silchashtable.h" #include "silclog.h" #include "silcmemory.h" +#include "silclist.h" +#include "silcdlist.h" #include "silcbuffer.h" #include "silcbufutil.h" #include "silcbuffmt.h" @@ -258,10 +269,6 @@ typedef uint32 * void *; #include "silcauth.h" #include "silcprivate.h" -/* TRQ (SilcList API and SilcDList API) */ -#include "silclist.h" -#include "silcdlist.h" - #ifdef SILC_SIM /* SILC Module library includes */ #include "silcsim.h" diff --git a/lib/Makefile.am.pre b/lib/Makefile.am.pre index d7770ce1..6a256dbc 100644 --- a/lib/Makefile.am.pre +++ b/lib/Makefile.am.pre @@ -27,9 +27,7 @@ COMMONDIRS = \ silcske \ silcutil \ silcclient \ - silcsftp \ - trq -# dotconf + silcsftp # zlib SUBDIRS = SILC_DISTRIBUTION_SUBDIRS @@ -44,9 +42,7 @@ SILCLIB_DIRS = \ silcmath \ silcske \ silcutil \ - silcsftp \ - trq -# dotconf + silcsftp # SILC Client Library dirs SILCCLIENTLIB_DIRS = \ diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index fd0e87bc..964df180 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -457,6 +457,8 @@ SILC_TASK_CALLBACK(silc_client_connect_failure) SilcClient client = (SilcClient)ctx->client; client->internal->ops->connect(client, ctx->sock->user_data, FALSE); + if (ctx->packet) + silc_packet_context_free(ctx->packet); silc_free(ctx); } @@ -1058,7 +1060,8 @@ void silc_client_packet_parse_type(SilcClient client, if (proto_ctx->packet) silc_packet_context_free(proto_ctx->packet); - + if (proto_ctx->dest_id) + silc_free(proto_ctx->dest_id); proto_ctx->packet = silc_packet_context_dup(packet); proto_ctx->dest_id_type = packet->src_id_type; proto_ctx->dest_id = silc_id_str2id(packet->src_id, packet->src_id_len, @@ -1367,13 +1370,15 @@ void silc_client_close_connection(SilcClient client, /* Clear ID caches */ if (conn->client_cache) - silc_idcache_del_all(conn->client_cache); + silc_idcache_free(conn->client_cache); if (conn->channel_cache) - silc_idcache_del_all(conn->channel_cache); + silc_idcache_free(conn->channel_cache); if (conn->server_cache) - silc_idcache_del_all(conn->server_cache); + silc_idcache_free(conn->server_cache); /* Free data (my ID is freed in above silc_client_del_client) */ + if (conn->nickname) + silc_free(conn->nickname); if (conn->remote_host) silc_free(conn->remote_host); if (conn->local_id_data) @@ -1504,7 +1509,7 @@ void silc_client_receive_new_id(SilcClient client, if (!conn->local_entry) conn->local_entry = silc_calloc(1, sizeof(*conn->local_entry)); - conn->local_entry->nickname = conn->nickname; + conn->local_entry->nickname = strdup(conn->nickname); if (!conn->local_entry->username) conn->local_entry->username = strdup(client->username); if (!conn->local_entry->hostname) diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index aebcf54e..f91beae0 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -2350,6 +2350,4 @@ void silc_client_commands_unregister(SilcClient client) SILC_CLIENT_CMDU(leave, LEAVE, "LEAVE"); SILC_CLIENT_CMDU(users, USERS, "USERS"); SILC_CLIENT_CMDU(getkey, GETKEY, "GETKEY"); - - silc_list_uninit(client->internal->commands); } diff --git a/lib/silcclient/idlist.c b/lib/silcclient/idlist.c index 4cf7a5ee..0dd94e4a 100644 --- a/lib/silcclient/idlist.c +++ b/lib/silcclient/idlist.c @@ -649,6 +649,7 @@ void silc_client_del_client_entry(SilcClient client, silc_free(client_entry->nickname); silc_free(client_entry->username); silc_free(client_entry->realname); + silc_free(client_entry->hostname); silc_free(client_entry->server); silc_free(client_entry->id); silc_free(client_entry->fingerprint); diff --git a/lib/silccrypt/silccipher.c b/lib/silccrypt/silccipher.c index 785cec1f..70276c51 100644 --- a/lib/silccrypt/silccipher.c +++ b/lib/silccrypt/silccipher.c @@ -128,6 +128,8 @@ bool silc_cipher_unregister(SilcCipherObject *cipher) while ((entry = silc_dlist_get(silc_cipher_list)) != SILC_LIST_END) { if (cipher == SILC_ALL_CIPHERS || entry == cipher) { silc_dlist_del(silc_cipher_list, entry); + silc_free(entry->name); + silc_free(entry); if (silc_dlist_count(silc_cipher_list) == 0) { silc_dlist_uninit(silc_cipher_list); diff --git a/lib/silccrypt/silchash.c b/lib/silccrypt/silchash.c index 4ec556bc..f508c836 100644 --- a/lib/silccrypt/silchash.c +++ b/lib/silccrypt/silchash.c @@ -209,13 +209,21 @@ void silc_hash_make(SilcHash hash, const unsigned char *data, char *silc_hash_fingerprint(SilcHash hash, const unsigned char *data, uint32 data_len) { + SilcHash new_hash = NULL; unsigned char h[32]; + char *ret; - if (!hash) - silc_hash_alloc("sha1", &hash); + if (!hash) { + silc_hash_alloc("sha1", &new_hash); + hash = new_hash; + } silc_hash_make(hash, data, data_len, h); - return silc_fingerprint(h, hash->hash->hash_len); + ret = silc_fingerprint(h, hash->hash->hash_len); + + if (new_hash != NULL) + silc_hash_free(new_hash); + return ret; } static const char vo[]= "aeiouy"; @@ -229,13 +237,16 @@ static const char co[]= "bcdfghklmnprstvzx"; char *silc_hash_babbleprint(SilcHash hash, const unsigned char *data, uint32 data_len) { + SilcHash new_hash = NULL; char *babbleprint; unsigned char hval[32]; unsigned int a, b, c, d, e, check; int i, k, out_len; - if (!hash) - silc_hash_alloc("sha1", &hash); + if (!hash) { + silc_hash_alloc("sha1", &new_hash); + hash = new_hash; + } /* Take fingerprint */ silc_hash_make(hash, data, data_len, hval); @@ -280,5 +291,7 @@ char *silc_hash_babbleprint(SilcHash hash, const unsigned char *data, } babbleprint[k + 3] = co[16]; + if (new_hash != NULL) + silc_hash_free(new_hash); return babbleprint; } diff --git a/lib/silccrypt/silcpkcs.c b/lib/silccrypt/silcpkcs.c index 6353a219..2f9699bb 100644 --- a/lib/silccrypt/silcpkcs.c +++ b/lib/silccrypt/silcpkcs.c @@ -1039,6 +1039,10 @@ int silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key, break; case SILC_PKCS_FILE_PEM: data = silc_decode_pem(data, len, &len); + memset(old, 0, data_len); + silc_free(old); + old = data; + data_len = len; break; } diff --git a/lib/silccrypt/silcrng.c b/lib/silccrypt/silcrng.c index 051e222c..7bed81e1 100644 --- a/lib/silccrypt/silcrng.c +++ b/lib/silccrypt/silcrng.c @@ -350,7 +350,7 @@ static void silc_rng_exec_command(SilcRng rng, char *command) pclose(fd); /* Add the buffer into random pool */ - silc_rng_add_noise(rng, buf, strlen(buf)); + silc_rng_add_noise(rng, buf, i); memset(buf, 0, sizeof(buf)); #endif } diff --git a/lib/silcsftp/sftp_client.c b/lib/silcsftp/sftp_client.c index 0aa1b91c..89cc6fc8 100644 --- a/lib/silcsftp/sftp_client.c +++ b/lib/silcsftp/sftp_client.c @@ -333,7 +333,6 @@ void silc_sftp_client_shutdown(SilcSFTP context) { SilcSFTPClient sftp = (SilcSFTPClient)context; - silc_list_uninit(sftp->requests); if (sftp->packet) silc_buffer_free(sftp->packet); silc_free(sftp); diff --git a/lib/silcutil/Makefile.am b/lib/silcutil/Makefile.am index 93cd4a3b..af1f7fb7 100644 --- a/lib/silcutil/Makefile.am +++ b/lib/silcutil/Makefile.am @@ -53,6 +53,8 @@ include_HEADERS = \ silcsockconn.h \ silcprotocol.h \ silcthread.h \ + silclist.h \ + silcdlist.h \ silcutil.h endif diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 8c822cd7..b91d6cb6 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -128,7 +128,7 @@ typedef struct { /* Inline functions */ -extern inline +static inline SilcBuffer silc_buffer_alloc(uint32 len) { SilcBuffer sb; @@ -150,7 +150,7 @@ SilcBuffer silc_buffer_alloc(uint32 len) /* Free's a SilcBuffer */ -extern inline +static inline void silc_buffer_free(SilcBuffer sb) { if (sb) { @@ -165,7 +165,7 @@ void silc_buffer_free(SilcBuffer sb) can be used to set the data to static buffer without needing any memory allocations. The `data' will not be copied to the buffer. */ -extern inline +static inline void silc_buffer_set(SilcBuffer sb, unsigned char *data, uint32 data_len) { sb->data = sb->head = data; @@ -190,7 +190,7 @@ void silc_buffer_set(SilcBuffer sb, unsigned char *data, uint32 data_len) ^ */ -extern inline +static inline unsigned char *silc_buffer_pull(SilcBuffer sb, uint32 len) { unsigned char *old_data = sb->data; @@ -222,7 +222,7 @@ unsigned char *silc_buffer_pull(SilcBuffer sb, uint32 len) ^ */ -extern inline +static inline unsigned char *silc_buffer_push(SilcBuffer sb, uint32 len) { unsigned char *old_data = sb->data; @@ -254,7 +254,7 @@ unsigned char *silc_buffer_push(SilcBuffer sb, uint32 len) ^ */ -extern inline +static inline unsigned char *silc_buffer_pull_tail(SilcBuffer sb, uint32 len) { unsigned char *old_tail = sb->tail; @@ -286,7 +286,7 @@ unsigned char *silc_buffer_pull_tail(SilcBuffer sb, uint32 len) ^ */ -extern inline +static inline unsigned char *silc_buffer_push_tail(SilcBuffer sb, uint32 len) { unsigned char *old_tail = sb->tail; @@ -312,7 +312,7 @@ unsigned char *silc_buffer_push_tail(SilcBuffer sb, uint32 len) Puts data to the head section. */ -extern inline +static inline unsigned char *silc_buffer_put_head(SilcBuffer sb, const unsigned char *data, uint32 len) @@ -334,7 +334,7 @@ unsigned char *silc_buffer_put_head(SilcBuffer sb, Puts data to the data section. */ -extern inline +static inline unsigned char *silc_buffer_put(SilcBuffer sb, const unsigned char *data, uint32 len) @@ -356,7 +356,7 @@ unsigned char *silc_buffer_put(SilcBuffer sb, Puts data to the tail section. */ -extern inline +static inline unsigned char *silc_buffer_put_tail(SilcBuffer sb, const unsigned char *data, uint32 len) diff --git a/lib/silcutil/silcbufutil.h b/lib/silcutil/silcbufutil.h index 7016b71e..ecf99e03 100644 --- a/lib/silcutil/silcbufutil.h +++ b/lib/silcutil/silcbufutil.h @@ -26,7 +26,7 @@ /* Clears and initialiazes the buffer to the state as if it was just allocated by silc_buffer_alloc. */ -extern inline +static inline void silc_buffer_clear(SilcBuffer sb) { memset(sb->head, 0, sb->truelen); @@ -39,7 +39,7 @@ void silc_buffer_clear(SilcBuffer sb) currently valid data area, nothing more. Use silc_buffer_clone to copy entire buffer. */ -extern inline +static inline SilcBuffer silc_buffer_copy(SilcBuffer sb) { SilcBuffer sb_new; @@ -55,7 +55,7 @@ SilcBuffer silc_buffer_copy(SilcBuffer sb) everything from the source buffer. The result is exact clone of the original buffer. */ -extern inline +static inline SilcBuffer silc_buffer_clone(SilcBuffer sb) { SilcBuffer sb_new; @@ -74,7 +74,7 @@ SilcBuffer silc_buffer_clone(SilcBuffer sb) new SilcBuffer pointer. The buffer is exact clone of the old one except that there is now more space at the end of buffer. */ -extern inline +static inline SilcBuffer silc_buffer_realloc(SilcBuffer sb, uint32 newsize) { SilcBuffer sb_new; diff --git a/lib/silcutil/silcdlist.h b/lib/silcutil/silcdlist.h new file mode 100644 index 00000000..ef4a9d64 --- /dev/null +++ b/lib/silcutil/silcdlist.h @@ -0,0 +1,156 @@ +/* + + silcdlist.h + + Author: Pekka Riikonen + + Copyright (C) 2000 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#ifndef SILDCLIST_H +#define SILDCLIST_H + +#include "silclist.h" + +/* + SILC Dynamic List API + + SILC Dynamic List API can be used to add opaque contexts to list that will + automatically allocate list entries. Normal SILC List API cannot be used + for this purpose because in that case the context passed to the list must + be defined as list structure already. This is not the case in SilcDList. + + This is slower than SilcList because this requires one extra memory + allocation when adding new entries to the list. The context is probably + allocated already and the new list entry requires one additional memory + allocation. The memory allocation and free'ing is done automatically in + the API and does not show to the caller. + + I left sorting functions out because I don't know whether we need them. + If needed, just copy them from silclist.h + +*/ + +/* SilcDList object. This is the actual SilcDList object that is used by + application. Application defines this object and adds context's to this + list with functions defined below. */ +typedef struct { + SilcList list; +} *SilcDList; + +/* SilcDListEntry structure, one entry in the list. This MUST NOT be used + directly by the application. */ +typedef struct SilcDListEntryStruct { + void *context; + struct SilcDListEntryStruct *next; +} *SilcDListEntry; + +/* Initializes SilcDList. */ + +static inline +SilcDList silc_dlist_init() +{ + SilcDList list; + + list = (SilcDList)silc_calloc(1, sizeof(*list)); + silc_list_init(list->list, struct SilcDListEntryStruct, next); + + return list; +} + +/* Uninits and free's all memory. Must be called to free memory. Does NOT + free the contexts saved by caller. */ + +static inline +void silc_dlist_uninit(SilcDList list) +{ + if (list) { + SilcDListEntry e; + silc_list_start(list->list); + while ((e = (SilcDListEntry)silc_list_get(list->list)) != SILC_LIST_END) { + silc_list_del(list->list, e); + silc_free(e); + } + silc_free(list); + } +} + +/* Return the number of entries in the list */ + +static inline +int silc_dlist_count(SilcDList list) +{ + return silc_list_count(list->list); +} + +/* Set the start of the list. This prepares the list for traversing entries + from the start of the list. */ + +static inline +void silc_dlist_start(SilcDList list) +{ + silc_list_start(list->list); +} + +/* Adds new entry to the list. This is the default function to add new + entries to the list. */ + +static inline +void silc_dlist_add(SilcDList list, void *context) +{ + SilcDListEntry e = (SilcDListEntry)silc_calloc(1, sizeof(*e)); + e->context = context; + silc_list_add(list->list, e); +} + +/* Remove entry from the list. Returns < 0 on error, 0 otherwise. */ + +static inline +void silc_dlist_del(SilcDList list, void *context) +{ + SilcDListEntry e; + + silc_list_start(list->list); + while ((e = (SilcDListEntry)silc_list_get(list->list)) != SILC_LIST_END) { + if (e->context == context) { + silc_list_del(list->list, e); + silc_free(e); + break; + } + } +} + +/* Returns current entry from the list and moves the list pointer forward + so that calling this next time returns the next entry from the list. This + can be used to traverse the list. Return SILC_LIST_END when the entire + list has ben traversed. Later, silc_list_start must be called again when + re-starting list traversing. Example: + + // Traverse the list from the beginning to the end + silc_dlist_start(list) + while ((entry = silc_dlist_get(list)) != SILC_LIST_END) { + ... + } + +*/ +static inline +void *silc_dlist_get(SilcDList list) +{ + SilcDListEntry e = (SilcDListEntry)silc_list_get(list->list); + if (e != SILC_LIST_END) + return e->context; + return SILC_LIST_END; +} + +#endif diff --git a/lib/silcutil/silclist.h b/lib/silcutil/silclist.h new file mode 100644 index 00000000..6f309349 --- /dev/null +++ b/lib/silcutil/silclist.h @@ -0,0 +1,261 @@ +/* + + silclist.h + + Author: Timo Sirainen + + Copyright (C) 2002 Timo Sirainen + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/****h* silcutil/SilcList + * + * DESCRIPTION + * + * Implementation of the SilcList interface. This interface provides + * simple linked list. + * + ***/ + +#ifndef SILCLIST_H +#define SILCLIST_H + +/****s* silcutil/SilcList/SilcList + * + * NAME + * + * typedef struct { ... } SilcList; + * + * DESCRIPTION + * + * This is the SilcList context, and is initialized by calling the + * function silc_list_init. + * + * EXAMPLE + * + * SilcList list; + * silc_list_init(list, struct SilcInternalEntryStruct, next); + * + ***/ +typedef struct { + void *head, *tail; + void *current; + int offset; +} SilcList; + +/****d* silcutil/SilcList/SILC_LIST_END + * + * NAME + * + * #define SILC_LIST_END ... + * + * DESCRIPTION + * + * Functions return this when the list is invalid or when traversing + * the list there is no more entires in the list. + * + * SOURCE + */ +#define SILC_LIST_END NULL +/***/ + +/* Initializes SilcList object. Example: + + SilcList list; + + silc_list_init(list, struct SilcInternalEntryStruct, next); + + Where `list' is the defined list, and second argument is the structure + of the entries in the list and last argument is the pointer in the entry + structure that is used as list member. SilcInternalEntry might be as + follows: + + struct SilcInternalEntryStruct { + char *dummy; + struct SilcInternalEntryStruct *next; // The list member pointer + }; + + The `next' pointer in the structure (or some other pointer for that matter) + is given for the silc_list_init as the last argument. This pointer is used + by the list routines to link the entries together in the list. Your code + should not touch the member pointer manually. +*/ + +/****f* silcutil/SilcList/silc_list_init + * + * SYNOPSIS + * + * #define silc_list_init(list, type, field) ... + * + * DESCRIPTION + * + * This macro initializes the SilcList list. The `list' is the defined + * list, second argument is the structure of the entries in the list, + * and last argument is the pointer in the entry structure that is used + * as list member. When using SilcList, you should not touch the + * structure member pointer (the `next' for example) manually. + * + * EXAMPLE + * + * struct SilcInternalEntryStruct { + * char *dummy; + * struct SilcInternalEntryStruct *next; // The list member pointer + * }; + * + * SilcList list; + * silc_list_init(list, struct SilcInternalEntryStruct, next); + * + ***/ +#define silc_list_init(list, type, field) \ + __silc_list_init(&(list), offsetof(type, field)) + +static inline void __silc_list_init(SilcList *list, int offset) +{ + list->head = list->tail = list->current = SILC_LIST_END; + list->offset = offset; +} + +#define list_next(list, pos) ((void **) ((char *) (pos) + (list)->offset)) + +/****f* silcutil/SilcList/silc_list_count + * + * SYNOPSIS + * + * #define silc_list_count(list) ... + * + * DESCRIPTION + * + * Returns the number of entries in the list indicated by `list'. + * + ***/ +#define silc_list_count(list) __silc_list_count(&(list)) +static inline int __silc_list_count(SilcList *list) +{ + int count = 0; + void *pos; + + for (pos = list->head; pos != NULL; pos = *list_next(list, pos)) + count++; + + return count; +} + +/****f* silcutil/SilcList/silc_list_start + * + * SYNOPSIS + * + * #define silc_list_start(list) ... + * + * DESCRIPTION + * + * Sets the start of the list. This prepares the list for traversing + * the entries from the start of the list. + * + ***/ +#define silc_list_start(list) (list).current = (list).head; + +/****f* silcutil/SilcList/silc_list_add + * + * SYNOPSIS + * + * #define silc_list_add(list, entry) ... + * + * DESCRIPTION + * + * Adds new entry indicated by `entry' to the end of the list indicated + * by `list'. + * + ***/ +#define silc_list_add(list, entry) __silc_list_add(&(list), entry) +static inline void __silc_list_add(SilcList *list, void *data) +{ + if (list->head == NULL) + list->head = data; + else + *list_next(list, list->tail) = data; + + list->tail = data; + *list_next(list, data) = NULL; +} + +/****f* silcutil/SilcList/silc_list_del + * + * SYNOPSIS + * + * #define silc_list_del(list, entry) ... + * + * DESCRIPTION + * + * Remove entry indicated by `entry' from the list indicated by `list'. + * + ***/ +#define silc_list_del(list, data) __silc_list_del(&(list), data) +static inline void __silc_list_del(SilcList *list, void *data) +{ + void **pos, *prev; + + prev = NULL; + for (pos = &list->head; *pos != NULL; pos = list_next(list, *pos)) { + if (*pos == data) { + *pos = *list_next(list, data); + if (list->current == data) + list->current = *pos; + break; + } + + prev = *pos; + } + + if (data == list->tail) + list->tail = prev; +} + +/****f* silcutil/SilcList/silc_list_get + * + * SYNOPSIS + * + * #define silc_list_get(list, entry) ... + * + * DESCRIPTION + * + * Returns the current entry from the list indicated by `list' and + * moves the list pointer forward so that calling this next time will + * return the next entry from the list. This can be used to traverse + * the list. Returns SILC_LIST_END when the entire list has been + * tarversed and no additional entries exist in the list. Later, + * silc_list_start must be called again when re-starting the list + * tarversing. + * + * EXAMPLE + * + * // Traverse the list from the beginning to the end + * silc_list_start(list) + * while ((entry = silc_list_get(list)) != SILC_LIST_END) { + * ... + * } + * + ***/ +#define silc_list_get(x) __silc_list_get(&(x)) + +static inline +void *__silc_list_get(SilcList *list) +{ + void *pos; + + pos = list->current; + if (pos != NULL) + list->current = *list_next(list, pos); + return pos; +} + +#endif diff --git a/prepare b/prepare index 68c4a428..c3ab1ef9 100755 --- a/prepare +++ b/prepare @@ -130,14 +130,6 @@ autoconf autoheader >/dev/null 2>/dev/null automake -echo "Preparing trq" -cd lib/trq -aclocal -autoconf -autoheader /dev/null -automake >/dev/null 2>/dev/null -cd ../.. - echo "Preparing mpi" cd lib/silcmath/mpi aclocal diff --git a/prepare-clean b/prepare-clean index ee9567c6..a07ab1c6 100755 --- a/prepare-clean +++ b/prepare-clean @@ -39,8 +39,6 @@ echo "Cleaning entire SILC source tree..." echo "All errors and warnings may be safely ignored." $MAKE clean -k $MAKE distclean -k -rm -f ltmain.sh -rm -f ltconfig rm -f ltcf* rm -f Makefile.am rm -f Makefile.defines @@ -72,8 +70,6 @@ rm -f lib/silcmath/Makefile.in rm -f lib/silcsim/Makefile.in rm -f lib/silcsim/modules/Makefile.in rm -f lib/silcske/Makefile.in -rm -f lib/trq/tests/Makefile -rm -f lib/trq/trq_test/Makefile rm -rf lib/silcmath/gmp/.deps rm -f silcd/Makefile.in silcd/log* silcd/*.log rm -f silc/Makefile.in silc/log* silc/*.log diff --git a/win32/Makefile.am b/win32/Makefile.am index d00bf796..93cd235e 100644 --- a/win32/Makefile.am +++ b/win32/Makefile.am @@ -20,6 +20,6 @@ AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign SUBDIRS = libsilc libsilcclient -EXTRA_DIST = silcdefs.h trq_conf.h silc.dsw copy_dll +EXTRA_DIST = silcdefs.h silc.dsw copy_dll include $(top_srcdir)/Makefile.defines.in diff --git a/win32/libsilc/libsilc.def b/win32/libsilc/libsilc.def index cee9eacc..43b1b2d9 100644 --- a/win32/libsilc/libsilc.def +++ b/win32/libsilc/libsilc.def @@ -505,71 +505,6 @@ EXPORTS silc_twofish_encrypt_cbc @ 718 ; silc_twofish_set_key @ 719 ; silc_twofish_set_key_with_string @ 720 ; - trq_deque_bubblesort @ 724 ; - trq_deque_clear___func @ 725 ; - trq_deque_compatible___func @ 726 ; - trq_deque_empty_p___func @ 727 ; - trq_deque_find @ 728 ; - trq_deque_get_head___func @ 729 ; - trq_deque_get_nth @ 730 ; - trq_deque_get_tail___func @ 731 ; - trq_deque_in_order @ 732 ; - trq_deque_init_with_offset___func @ 733 ; - trq_deque_insert_head___func @ 734 ; - trq_deque_insert_in_order @ 735 ; - trq_deque_insert_nth @ 736 ; - trq_deque_insert_tail___func @ 737 ; - trq_deque_insertionsort @ 738 ; - trq_deque_join_head @ 739 ; - trq_deque_join_tail @ 740 ; - trq_deque_length___func @ 741 ; - trq_deque_mapcar @ 742 ; - trq_deque_mapcar_reverse @ 743 ; - trq_deque_member @ 744 ; - trq_deque_mergesort @ 745 ; - trq_deque_quicksort @ 746 ; - trq_deque_remove @ 747 ; - trq_deque_reverse___func @ 748 ; - trq_deque_swap @ 749 ; - trq_deque_to_list @ 750 ; - trq_list_bubblesort @ 751 ; - trq_list_bw @ 752 ; - trq_list_clear___func @ 753 ; - trq_list_compatible___func @ 754 ; - trq_list_current___func @ 755 ; - trq_list_end___func @ 756 ; - trq_list_find @ 757 ; - trq_list_fw @ 758 ; - trq_list_get_bw___func @ 759 ; - trq_list_get_fw___func @ 760 ; - trq_list_get_head___func @ 761 ; - trq_list_get_nth @ 762 ; - trq_list_get_tail___func @ 763 ; - trq_list_in_order @ 764 ; - trq_list_insert_head___func @ 765 ; - trq_list_insert_in_order @ 766 ; - trq_list_insert_nth @ 767 ; - trq_list_insert_tail___func @ 768 ; - trq_list_insertionsort @ 769 ; - trq_list_join_head @ 770 ; - trq_list_join_tail @ 771 ; - trq_list_length___func @ 772 ; - trq_list_mapcar @ 773 ; - trq_list_mapcar_reverse @ 774 ; - trq_list_member @ 775 ; - trq_list_mergesort @ 776 ; - trq_list_pointer_invalidate___func @ 777 ; - trq_list_pointer_valid___func @ 778 ; - trq_list_put_after___func @ 779 ; - trq_list_put_before___func @ 780 ; - trq_list_quicksort @ 781 ; - trq_list_remove___func @ 782 ; - trq_list_reverse @ 783 ; - trq_list_rewind___func @ 784 ; - trq_list_rewind_find @ 785 ; - trq_list_rewind_to @ 786 ; - trq_list_swap @ 787 ; - trq_list_to_deque @ 788 ; silc_buffer_format_vp @ 789 ; silc_buffer_unformat_vp @ 790 ; silc_sftp_client_start @ 791 ; diff --git a/win32/trq_conf.h b/win32/trq_conf.h deleted file mode 100644 index 21c895f8..00000000 --- a/win32/trq_conf.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- c -*- - * - * ---------------------------------------------------------------------- - * Deque for struct type with only one link pointer (x->next). - * ---------------------------------------------------------------------- - * Created : Fri Dec 5 11:19:37 1997 tri - * Last modified: Thu Apr 16 17:35:57 1998 tri - * ---------------------------------------------------------------------- - * Copyright © 1995-1998 - * Timo J. Rinne - * All rights reserved. See file COPYRIGHT for details. - * - * Address: Cirion oy, PO-BOX 250, 00121 Helsinki, Finland - * ---------------------------------------------------------------------- - * Any express or implied warranties are disclaimed. In no event - * shall the author be liable for any damages caused (directly or - * otherwise) by the use of this software. - * - * Please, send your patches to . - * ---------------------------------------------------------------------- - * - * $Id$ - * - * $Log$ - * Revision 1.1 2001/07/23 11:07:56 priikone - * updates. - * - * Revision 1.1.1.1 2000/10/31 19:59:30 priikone - * Imported TRQ and SilList and SilcDList API's. - * - * Revision 1.1 1998/04/16 14:39:42 tri - * Initial revision - * - * - */ -#ifndef __TRQ_CONF__H__ -#define __TRQ_CONF__H__ 1 - -/* - * stddef.h is included here if such file exists. - * offsetof should be defined there. - */ -#include - -/* - * If compiler supports inline functions, __TRQ__INLINE__FUNCTION__ - * is defined to the correct keyword. Usually this is defined - * as inline, __inline__ or __inline. If inline functions are - * not supported, __TRQ__INLINE__FUNCTION__ is undefined. - */ -#define __TRQ__INLINE__FUNCTION__ __inline - -typedef unsigned long trq_p_i_t; /* Integral type size of an pointer */ - -#ifdef offsetof -#define _Q_STRUCT_OFFSET(t, m) ((trq_p_i_t)(offsetof(t, m))) -#else -#define _Q_STRUCT_OFFSET(t, m) (((trq_p_i_t)(&(((t *)0)->m)))) -#endif - -#endif /* !__TRQ_CONF__H__ */ -/* eof (trq_conf.h) */ -- 2.24.0