From f3fe6f1b3bac2aaad7c6a335f0b87bf0af9b4160 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 4 Jul 2007 17:21:55 +0000 Subject: [PATCH] Added SilcStack support to SILC File Util API. --- CHANGES.RUNTIME | 11 ++++++++++- apps/irssi/src/silc/core/silc-queries.c | 6 +++--- lib/silchttp/tests/test_silchttpserver.c | 2 +- lib/silcutil/silcbuffer.h | 21 +++++++++++++++++++++ lib/silcutil/silcconfig.c | 2 +- lib/silcutil/silcfileutil.c | 3 ++- lib/silcutil/silcfileutil.h | 12 +++++++++--- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/CHANGES.RUNTIME b/CHANGES.RUNTIME index 761361cb..56734857 100644 --- a/CHANGES.RUNTIME +++ b/CHANGES.RUNTIME @@ -1,4 +1,13 @@ -Wed Jul 4 16:31:05 EEST 2007 Pekka Riikonen +Wed Jul 4 20:20:05 EEST 2007 Pekka Riikonen + + * Unified the SILC_STR_FUNC callback. Affected files are + lib/silcutil/silcbuffmt.[ch]. + + * Added SilcStack support to SILC File Util API. Affected files + are lib/silcutil/silcfileutil.[ch]. + + * Added SilcStack support to SILC FD Stream API. Affected files + are lib/silcutil/silcfdstream.[ch]. * Added SilcStack support to SILC Scheduler API. The scheduler now creates stack always. It can be retrieved by diff --git a/apps/irssi/src/silc/core/silc-queries.c b/apps/irssi/src/silc/core/silc-queries.c index 1e7f7513..271e3d5e 100644 --- a/apps/irssi/src/silc/core/silc-queries.c +++ b/apps/irssi/src/silc/core/silc-queries.c @@ -292,7 +292,7 @@ void silc_query_attributes_default(SilcClient client, /* Put USER_INFO */ silc_client_attribute_del(silc_client, conn, SILC_ATTRIBUTE_USER_INFO, NULL); - tmp = silc_file_readfile(sv, &tmp_len); + tmp = silc_file_readfile(sv, &tmp_len, NULL); if (tmp) { tmp[tmp_len] = 0; if (silc_vcard_decode(tmp, tmp_len, &vcard)) @@ -384,7 +384,7 @@ void silc_query_attributes_default(SilcClient client, /* Put STATUS_MESSAGE */ silc_client_attribute_del(silc_client, conn, SILC_ATTRIBUTE_STATUS_MESSAGE, NULL); - tmp = silc_file_readfile(sv, &tmp_len); + tmp = silc_file_readfile(sv, &tmp_len, NULL); if (tmp) { mime = silc_mime_decode(NULL, tmp, tmp_len); if (mime) @@ -529,7 +529,7 @@ void silc_query_attributes_default(SilcClient client, list = g_strsplit(sv, " ", -1); for (entry = list; *entry != NULL; entry++) { if (!strncasecmp(*entry, "silc-rsa:", 8)) { - tmp = silc_file_readfile((*entry) + 8, &tmp_len); + tmp = silc_file_readfile((*entry) + 8, &tmp_len, NULL); if (tmp) { tmp[tmp_len] = 0; pk.type = "silc-rsa"; diff --git a/lib/silchttp/tests/test_silchttpserver.c b/lib/silchttp/tests/test_silchttpserver.c index e8b3f0a2..cb9050b1 100644 --- a/lib/silchttp/tests/test_silchttpserver.c +++ b/lib/silchttp/tests/test_silchttpserver.c @@ -65,7 +65,7 @@ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, SILC_LOG_DEBUG(("Filename: '%s'", filename)); if (!usephp) { - filedata = silc_file_readfile(filename, &data_len); + filedata = silc_file_readfile(filename, &data_len, NULL); if (!filedata) { silc_http_server_send_error(httpd, conn, "404 Not Found", "

404 Not Found

The page you are looking for cannot be located"); diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 5ce67117..7dec1149 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -961,6 +961,9 @@ SilcBool silc_buffer_enlarge(SilcBuffer sb, SilcUInt32 size) * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1005,6 +1008,9 @@ SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len) * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1034,6 +1040,9 @@ SilcBuffer silc_buffer_salloc_size(SilcStack stack, SilcUInt32 len) * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1090,6 +1099,9 @@ SilcBuffer silc_buffer_srealloc(SilcStack stack, * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1124,6 +1136,9 @@ SilcBuffer silc_buffer_srealloc_size(SilcStack stack, * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1157,6 +1172,9 @@ SilcBool silc_buffer_senlarge(SilcStack stack, SilcBuffer sb, SilcUInt32 size) * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline @@ -1188,6 +1206,9 @@ SilcBuffer silc_buffer_scopy(SilcStack stack, SilcBuffer sb) * This routine use SilcStack are memory source. If `stack' is NULL * reverts back to normal allocating routine. * + * Note that this call consumes the `stack'. The caller should push the + * stack before calling the function and pop it later. + * ***/ static inline diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index 97760b3f..49507005 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -263,7 +263,7 @@ SilcConfigFile *silc_config_open(const char *configfile) SilcUInt32 filelen; SilcConfigFile *ret; - if (!(buffer = silc_file_readfile(configfile, &filelen))) + if (!(buffer = silc_file_readfile(configfile, &filelen, NULL))) return NULL; ret = silc_calloc(1, sizeof(*ret)); diff --git a/lib/silcutil/silcfileutil.c b/lib/silcutil/silcfileutil.c index 02620b04..5404183a 100644 --- a/lib/silcutil/silcfileutil.c +++ b/lib/silcutil/silcfileutil.c @@ -124,7 +124,8 @@ int silc_file_writefile_mode(const char *filename, const char *buffer, /* Reads a file to a buffer. The allocated buffer is returned. Length of the file read is returned to the return_len argument. */ -char *silc_file_readfile(const char *filename, SilcUInt32 *return_len) +char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, + SilcStack stack) { int fd; char *buffer; diff --git a/lib/silcutil/silcfileutil.h b/lib/silcutil/silcfileutil.h index 80e9d99a..70887760 100644 --- a/lib/silcutil/silcfileutil.h +++ b/lib/silcutil/silcfileutil.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2005 Pekka Riikonen + Copyright (C) 1997 - 2007 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 @@ -117,7 +117,8 @@ int silc_file_set_nonblock(int fd); * * SYNOPSIS * - * char *silc_file_readfile(const char *filename, SilcUInt32 *return_len); + * char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, + * SilcStack stack); * * DESCRIPTION * @@ -129,8 +130,13 @@ int silc_file_set_nonblock(int fd); * If the `return_len' pointer is not NULL, it's filled with the length of * the file. * + * If `stack' is non-NULL the returned buffer is allocated from `stack'. + * The allocation consumes `stack' so caller should push the stack before + * calling this function and pop it later. + * ***/ -char *silc_file_readfile(const char *filename, SilcUInt32 *return_len); +char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, + SilcStack stack); /****f* silcutil/SilcFileUtilAPI/silc_file_writefile * -- 2.24.0