updates.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 17 Feb 2002 19:50:05 +0000 (19:50 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 17 Feb 2002 19:50:05 +0000 (19:50 +0000)
26 files changed:
CHANGES
apps/silcd/command.c
apps/silcd/command_reply.c
apps/silcd/packet_receive.c
apps/silcd/packet_send.c
apps/silcd/protocol.c
apps/silcd/server.c
includes/silcincludes.h
lib/silcclient/client.c
lib/silcclient/client_channel.c
lib/silcclient/client_prvmsg.c
lib/silcclient/command_reply.c
lib/silcclient/protocol.c
lib/silccore/silcauth.c
lib/silccore/silccommand.c
lib/silccore/silcid.c
lib/silccore/silcnotify.c
lib/silcutil/DIRECTORY
lib/silcutil/Makefile.am
lib/silcutil/silcbuffer.h
lib/silcutil/silcbufutil.h [deleted file]
lib/silcutil/silcconfig.h
lib/silcutil/silclist.h
lib/silcutil/silcmemory.c
lib/silcutil/silcmemory.h
win32/libsilc/libsilc.def

diff --git a/CHANGES b/CHANGES
index 7d34d074a012ee7b5366928d68b8e0e52d221d8e..01d6bbf5af442e7a4b4545cbdd860b08c39a57a3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,12 @@ Sun Feb 17 19:02:56 EET 2002  Pekka Riikonen <priikone@silcnet.org>
          docs from all kinds of filenames.  Affected files are
          util/robodoc/Source/generator.c, scripts/silcdoc/silcdoc
 
+       * ROBOdoc documented lib/silcutil/silcmemory.h.
+         Added also new function silc_memdup.
+
+       * Removed lib/silcutil/silcbufutil.h and moved those routines
+         to the lib/silcutil/silcbuffer.h.
+
 Sun Feb 17 15:52:30 EET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Added `user_count' to the SilcChannelEntry which now tells the
index 7a4d7aa7e45236952d2371d2f1a0b8776564062b..807faee2cf8743ed787d06a14f15ee52bc19eb36 100644 (file)
@@ -3141,10 +3141,8 @@ static void silc_server_command_join_channel(SilcServer server,
   if (channel->mode & SILC_CHANNEL_MODE_PASSPHRASE) {
     /* Get passphrase */
     tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
-    if (tmp) {
-      passphrase = silc_calloc(tmp_len, sizeof(*passphrase));
-      memcpy(passphrase, tmp, tmp_len);
-    }
+    if (tmp)
+      passphrase = silc_memdup(tmp, tmp_len);
   
     if (!passphrase || !channel->passphrase ||
         memcmp(passphrase, channel->passphrase, strlen(channel->passphrase))) {
@@ -4109,9 +4107,7 @@ SILC_SERVER_CMD_FUNC(cmode)
 
        if (channel->founder_method == SILC_AUTH_PASSWORD) {
          tmp = silc_auth_get_data(auth, &tmp_len);
-         channel->founder_passwd = 
-           silc_calloc(tmp_len + 1, sizeof(*channel->founder_passwd));
-         memcpy(channel->founder_passwd, tmp, tmp_len);
+         channel->founder_passwd = silc_memdup(tmp, tmp_len);
          channel->founder_passwd_len = tmp_len;
        } else {
          /* Verify the payload before setting the mode */
index d191b6b66a4ade12d1d8fb508270bc8ab385d678..dee4e0bef9bcd7a1838c08a96a06445caec96082 100644 (file)
@@ -918,16 +918,14 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
   tmp = silc_argument_get_arg_type(cmd->args, 8, &len);
   if (tmp) {
     silc_free(entry->ban_list);
-    entry->ban_list = silc_calloc(len, sizeof(*entry->ban_list));
-    memcpy(entry->ban_list, tmp, len);
+    entry->ban_list = silc_memdup(tmp, len);
   }
 
   /* Get the invite list */
   tmp = silc_argument_get_arg_type(cmd->args, 9, &len);
   if (tmp) {
     silc_free(entry->invite_list);
-    entry->invite_list = silc_calloc(len, sizeof(*entry->invite_list));
-    memcpy(entry->invite_list, tmp, len);
+    entry->invite_list = silc_memdup(tmp, len);
   }
 
   /* Get the topic */
index 7d210e83c24a71bc8517c65fd539b7afd0ba2943..65aba7318907e6c024dc0769da3c76a1570b54b2 100644 (file)
@@ -1589,8 +1589,7 @@ SilcClientEntry silc_server_new_client(SilcServer server,
     int tlen = strcspn(username, "@");
     char *phostname = NULL;
 
-    hostname = silc_calloc((strlen(username) - tlen) + 1, sizeof(char));
-    memcpy(hostname, username + tlen + 1, strlen(username) - tlen - 1);
+    hostname = silc_memdup(username + tlen + 1, strlen(username) - tlen - 1);
 
     if (strcmp(sock->hostname, sock->ip) && 
        strcmp(sock->hostname, hostname)) {
index d2d21517068d73afe44e4b0cf78d543a2fad3669..8062551faa4d9393e83a1745095ec68ee961391e 100644 (file)
@@ -875,8 +875,7 @@ void silc_server_packet_relay_to_channel(SilcServer server,
        /* If private key mode is not set then decrypt the packet
           and re-encrypt it */
        if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
-         unsigned char *tmp = silc_calloc(data_len, sizeof(*data));
-         memcpy(tmp, data, data_len);
+         unsigned char *tmp = silc_memdup(data, data_len);
 
          /* Decrypt the channel message (we don't check the MAC) */
          if (channel->channel_key &&
index d92b2c3e87d5050a5fc8d1d4e47780d626e42193..794a20880279462c6b473c8896443a1c971969e2 100644 (file)
@@ -276,11 +276,8 @@ int silc_server_protocol_ke_set_keys(SilcServer server,
   }
 
   idata->rekey = silc_calloc(1, sizeof(*idata->rekey));
-  idata->rekey->send_enc_key = 
-    silc_calloc(keymat->enc_key_len / 8,
-               sizeof(*idata->rekey->send_enc_key));
-  memcpy(idata->rekey->send_enc_key, 
-        keymat->send_enc_key, keymat->enc_key_len / 8);
+  idata->rekey->send_enc_key = silc_memdup(keymat->send_enc_key,
+                                          keymat->enc_key_len / 8);
   idata->rekey->enc_key_len = keymat->enc_key_len / 8;
 
   if (ske->prop->flags & SILC_SKE_SP_FLAG_PFS)
@@ -1247,11 +1244,8 @@ silc_server_protocol_rekey_validate(SilcServer server,
   if (!send) {
     memset(idata->rekey->send_enc_key, 0, idata->rekey->enc_key_len);
     silc_free(idata->rekey->send_enc_key);
-    idata->rekey->send_enc_key = 
-      silc_calloc(keymat->enc_key_len / 8,
-                 sizeof(*idata->rekey->send_enc_key));
-    memcpy(idata->rekey->send_enc_key, keymat->send_enc_key, 
-          keymat->enc_key_len / 8);
+    idata->rekey->send_enc_key = silc_memdup(keymat->send_enc_key,
+                                            keymat->enc_key_len / 8);
     idata->rekey->enc_key_len = keymat->enc_key_len / 8;
   }
 }
index 04912e9c18567d12f98eada3fe9a031bd8d10216..fab3d975a72344ea6c0c22dc404a0e3c88f060a1 100644 (file)
@@ -3066,8 +3066,7 @@ bool silc_server_create_channel_key(SilcServer server,
 
   /* Save the key */
   channel->key_len = len * 8;
-  channel->key = silc_calloc(len, sizeof(*channel->key));
-  memcpy(channel->key, channel_key, len);
+  channel->key = silc_memdup(channel_key, len);
   memset(channel_key, 0, sizeof(channel_key));
 
   /* Generate HMAC key from the channel key data and set it */
@@ -3178,8 +3177,7 @@ SilcChannelEntry silc_server_save_channel_key(SilcServer server,
 
   /* Save the key */
   channel->key_len = tmp_len * 8;
-  channel->key = silc_calloc(tmp_len, sizeof(unsigned char));
-  memcpy(channel->key, tmp, tmp_len);
+  channel->key = silc_memdup(tmp, tmp_len);
   silc_cipher_set_key(channel->channel_key, tmp, channel->key_len);
 
   /* Generate HMAC key from the channel key data and set it */
index d15953faaaa13c1b3817af9020f1ae47d0af1a68..c7182023028bd443f67b36dd1f12fde9c08223f8 100644 (file)
@@ -263,7 +263,6 @@ typedef uint32 * void *;
 #include "silclist.h"
 #include "silcdlist.h"
 #include "silcbuffer.h"
-#include "silcbufutil.h"
 #include "silcbuffmt.h"
 #include "silcnet.h"
 #include "silcfileutil.h"
index 4674c0921b230087a9333778f49f46929b200e8e..620e3de07318002e6e9c3306e56d27dedf613d00 100644 (file)
@@ -611,8 +611,7 @@ void silc_client_resolve_auth_method(bool success,
   proto_ctx->auth_meth = auth_meth;
 
   if (auth_data && auth_data_len) {
-    proto_ctx->auth_data = silc_calloc(auth_data_len, sizeof(*auth_data));
-    memcpy(proto_ctx->auth_data, auth_data, auth_data_len);
+    proto_ctx->auth_data = silc_memdup(auth_data, auth_data_len);
     proto_ctx->auth_data_len = auth_data_len;
   }
 
@@ -1438,8 +1437,7 @@ void silc_client_disconnected_by_server(SilcClient client,
 
   SILC_LOG_DEBUG(("Server disconnected us, sock %d", sock->sock));
 
-  msg = silc_calloc(message->len + 1, sizeof(char));
-  memcpy(msg, message->data, message->len);
+  msg = silc_memdup(message->data, message->len);
   client->internal->ops->say(client, sock->user_data, 
                             SILC_CLIENT_MESSAGE_AUDIT, msg);
   silc_free(msg);
@@ -1462,8 +1460,7 @@ void silc_client_error_by_server(SilcClient client,
 {
   char *msg;
 
-  msg = silc_calloc(message->len + 1, sizeof(char));
-  memcpy(msg, message->data, message->len);
+  msg = silc_memdup(message->data, message->len);
   client->internal->ops->say(client, sock->user_data, 
                             SILC_CLIENT_MESSAGE_AUDIT, msg);
   silc_free(msg);
index 4f89d7270b01458f2fc23a81516c8d4aab10d099..1a4a6d5968a7dc86acd239d228369e0ce975f571 100644 (file)
@@ -396,8 +396,7 @@ void silc_client_save_channel_key(SilcClient client,
   key = silc_channel_key_get_key(payload, &tmp_len);
   cipher = silc_channel_key_get_cipher(payload, NULL);
   channel->key_len = tmp_len * 8;
-  channel->key = silc_calloc(tmp_len, sizeof(*channel->key));
-  memcpy(channel->key, key, tmp_len);
+  channel->key = silc_memdup(key, tmp_len);
 
   if (!silc_cipher_alloc(cipher, &channel->channel_key)) {
     client->internal->ops->say(
@@ -520,8 +519,7 @@ int silc_client_add_channel_private_key(SilcClient client,
 
   /* Save the key */
   entry = silc_calloc(1, sizeof(*entry));
-  entry->key = silc_calloc(keymat->enc_key_len / 8, sizeof(*entry->key));
-  memcpy(entry->key, keymat->send_enc_key, keymat->enc_key_len / 8);
+  entry->key = silc_memdup(keymat->send_enc_key, keymat->enc_key_len / 8);
   entry->key_len = keymat->enc_key_len / 8;
 
   /* Allocate the cipher and set the key*/
index 450fb40537b3e7a5cf910c99c1b9ad116cf25c83..88bedabea4158f8e72481fa7591307c9aceefb68 100644 (file)
@@ -344,8 +344,7 @@ int silc_client_add_private_message_key(SilcClient client,
   }
 
   /* Save the key */
-  client_entry->key = silc_calloc(key_len, sizeof(*client_entry->key));
-  memcpy(client_entry->key, key, key_len);
+  client_entry->key = silc_memdup(key, key_len);
   client_entry->key_len = key_len;
 
   /* Produce the key material as the protocol defines */
index f565899481c881624f606b5d5833714659eee14c..9e8d9a9ecb28868df5dfc4e32c63a5fb1360be8a 100644 (file)
@@ -278,10 +278,7 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd,
   }
 
   if (fingerprint && !client_entry->fingerprint) {
-    client_entry->fingerprint = 
-      silc_calloc(fingerprint_len, 
-                 sizeof(*client_entry->fingerprint));
-    memcpy(client_entry->fingerprint, fingerprint, fingerprint_len);
+    client_entry->fingerprint = silc_memdup(fingerprint, fingerprint_len);
     client_entry->fingerprint_len = fingerprint_len;
   }
 
index 3354f1d0b53f04cc98696b0734caf8d5a253b07a..da7bc07fb352423627398550db7c670bd609cb86 100644 (file)
@@ -151,11 +151,8 @@ void silc_client_protocol_ke_set_keys(SilcSKE ske,
 
   /* Rekey stuff */
   conn->rekey = silc_calloc(1, sizeof(*conn->rekey));
-  conn->rekey->send_enc_key = 
-    silc_calloc(keymat->enc_key_len / 8,
-               sizeof(*conn->rekey->send_enc_key));
-  memcpy(conn->rekey->send_enc_key, 
-        keymat->send_enc_key, keymat->enc_key_len / 8);
+  conn->rekey->send_enc_key = silc_memdup(keymat->send_enc_key, 
+                                         keymat->enc_key_len / 8);
   conn->rekey->enc_key_len = keymat->enc_key_len / 8;
 
   if (ske->start_payload->flags & SILC_SKE_SP_FLAG_PFS)
@@ -785,11 +782,8 @@ silc_client_protocol_rekey_validate(SilcClient client,
   if (!send) {
     memset(conn->rekey->send_enc_key, 0, conn->rekey->enc_key_len);
     silc_free(conn->rekey->send_enc_key);
-    conn->rekey->send_enc_key = 
-      silc_calloc(keymat->enc_key_len / 8,
-                 sizeof(*conn->rekey->send_enc_key));
-    memcpy(conn->rekey->send_enc_key, keymat->send_enc_key, 
-          keymat->enc_key_len / 8);
+    conn->rekey->send_enc_key = silc_memdup(keymat->send_enc_key,
+                                           keymat->enc_key_len / 8);
     conn->rekey->enc_key_len = keymat->enc_key_len / 8;
   }
 }
index e66f9653834e69de3e69b0099bf82d4ef81a268d..3ee76ca41eccfcf3f2d789a16f0546e1e23c2274 100644 (file)
@@ -181,8 +181,7 @@ silc_auth_public_key_encode_data(SilcPublicKey public_key,
                     SILC_STR_UI_XNSTRING(pk, pk_len),
                     SILC_STR_END);
   
-  ret = silc_calloc(buf->len + 1, sizeof(*ret));
-  memcpy(ret, buf->data, buf->len);
+  ret = silc_memdup(buf->data, buf->len);
 
   if (ret_len)
     *ret_len = buf->len;
index 0d64787d06cd8d3ad778757ae0d3c05864d19562..04f03d6b6a6d1acc02fcbd7e4c22cc50cb6f24fc 100644 (file)
@@ -228,8 +228,7 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
       if (!x_type || !x || !x_len)
        continue;
       
-      argv[k] = silc_calloc(x_len + 1, sizeof(unsigned char));
-      memcpy(argv[k], x, x_len);
+      argv[k] = silc_memdup(x, x_len);
       argv_lens[k] = x_len;
       argv_types[k] = x_type;
       k++;
@@ -290,8 +289,7 @@ silc_command_reply_payload_encode_vap(SilcCommand cmd,
   argv_types = silc_calloc(argc, sizeof(uint32));
 
   SILC_PUT16_MSB(status, status_data);
-  argv[0] = silc_calloc(sizeof(status_data) + 1, sizeof(unsigned char));
-  memcpy(argv[0], status_data, sizeof(status_data));
+  argv[0] = silc_memdup(status_data, sizeof(status_data));
   argv_lens[0] = sizeof(status_data);
   argv_types[0] = 1;
 
@@ -303,8 +301,7 @@ silc_command_reply_payload_encode_vap(SilcCommand cmd,
     if (!x_type || !x || !x_len)
       continue;
 
-    argv[k] = silc_calloc(x_len + 1, sizeof(unsigned char));
-    memcpy(argv[k], x, x_len);
+    argv[k] = silc_memdup(x, x_len);
     argv_lens[k] = x_len;
     argv_types[k] = x_type;
     k++;
index 9a35723a38832fc94ac599558dfe18edc07dc271..e3a37d8e99d91c312b1a7ba316eda11933c0af4d 100644 (file)
@@ -182,14 +182,10 @@ void *silc_id_payload_get_id(SilcIDPayload payload)
 
 unsigned char *silc_id_payload_get_data(SilcIDPayload payload)
 {
-  unsigned char *ret;
-
   if (!payload)
     return NULL;
 
-  ret = silc_calloc(payload->len, sizeof(*ret));
-  memcpy(ret, payload->id, payload->len);
-  return ret;
+  return silc_memdup(payload->id, payload->len);
 }
 
 /* Get length of ID */
@@ -336,26 +332,20 @@ void *silc_id_dup(const void *id, SilcIdType type)
   switch(type) {
   case SILC_ID_SERVER:
     {
-      SilcServerID *server_id = (SilcServerID *)id, *new;
-      new = silc_calloc(1, sizeof(*server_id));
-      memcpy(new, server_id, sizeof(*server_id));
-      return new;
+      SilcServerID *server_id = (SilcServerID *)id;
+      return silc_memdup(server_id, sizeof(*server_id));
     }
     break;
   case SILC_ID_CLIENT:
     {
-      SilcClientID *client_id = (SilcClientID *)id, *new;
-      new = silc_calloc(1, sizeof(*client_id));
-      memcpy(new, client_id, sizeof(*client_id));
-      return new;
+      SilcClientID *client_id = (SilcClientID *)id;
+      return silc_memdup(client_id, sizeof(*client_id));
     }
     break;
   case SILC_ID_CHANNEL:
     {
-      SilcChannelID *channel_id = (SilcChannelID *)id, *new;
-      new = silc_calloc(1, sizeof(*channel_id));
-      memcpy(new, channel_id, sizeof(*channel_id));
-      return new;
+      SilcChannelID *channel_id = (SilcChannelID *)id;
+      return silc_memdup(channel_id, sizeof(*channel_id));
     }
     break;
   }
index 99f342cff65493b06064b25e00afcfef6340dab5..c3600c52eefcfe428a40bd0ccefe700c4788f7c2 100644 (file)
@@ -101,8 +101,7 @@ SilcBuffer silc_notify_payload_encode(SilcNotifyType type, uint32 argc,
       if (!x || !x_len)
        continue;
       
-      argv[k] = silc_calloc(x_len + 1, sizeof(unsigned char));
-      memcpy(argv[k], x, x_len);
+      argv[k] = silc_memdup(x, x_len);
       argv_lens[k] = x_len;
       argv_types[k] = i + 1;
       k++;
index 1caefbf34b7df41ffaa6e2f4641f56b6c4569bb3..a48ad6b02d2862d91380dca1c788a20df9bc3916 100644 (file)
@@ -3,7 +3,6 @@
 @FILENAME=silcutillib.html
 @LINK=silcbuffer.html:SILC Buffer Interface
 @LINK=silcbuffmt.html:SILC Buffer Format Interface
-@LINK=silcbufutil.html:SILC Buffer Utility Interface
 @LINK=silchashtable.html:SILC Hash Table Interface
 @LINK=silclog.html:SILC Logging Interface
 @LINK=silcmemory.html:SILC Memory Interface
index a88f243ba4c8cd2cbc21b3c3e77b06c310d41ec5..ac4e73e0d7cca1997c143ebce0ec5c0a4d3d916d 100644 (file)
@@ -46,7 +46,6 @@ if SILC_DIST_TOOLKIT
 include_HEADERS =      \
        silcbuffer.h    \
        silcbuffmt.h    \
-       silcbufutil.h   \
        silcconfig.h    \
        silchashtable.h \
        silclog.h       \
index b91d6cb67ad50f79b658818bddeea43ebd5a3d6e..9a64329e6c3e426c5de7c353f269367882b584da 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcbuffer.h
+  silcbuffer.h 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2000 Pekka Riikonen
+  Copyright (C) 1998 - 2002 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.
-  
+  the Free Software Foundation; version 2 of the License.
+
   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
@@ -367,4 +366,78 @@ unsigned char *silc_buffer_put_tail(SilcBuffer sb,
   return (unsigned char *)memcpy(sb->tail, data, len);
 }
 
+/* Clears and initialiazes the buffer to the state as if it was just
+   allocated by silc_buffer_alloc. */
+
+static inline
+void silc_buffer_clear(SilcBuffer sb)
+{
+  memset(sb->head, 0, sb->truelen);
+  sb->data = sb->head;
+  sb->tail = sb->head;
+  sb->len = 0;
+}
+
+/* Generates copy of a SilcBuffer. This copies everything inside the
+   currently valid data area, nothing more. Use silc_buffer_clone to
+   copy entire buffer. */
+
+static inline
+SilcBuffer silc_buffer_copy(SilcBuffer sb)
+{
+  SilcBuffer sb_new;
+
+  sb_new = silc_buffer_alloc(sb->len);
+  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+  silc_buffer_put(sb_new, sb->data, sb->len);
+
+  return sb_new;
+}
+
+/* Clones SilcBuffer. This generates new SilcBuffer and copies
+   everything from the source buffer. The result is exact clone of
+   the original buffer. */
+
+static inline
+SilcBuffer silc_buffer_clone(SilcBuffer sb)
+{
+  SilcBuffer sb_new;
+
+  sb_new = silc_buffer_alloc(sb->truelen);
+  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+  silc_buffer_put(sb_new, sb->head, sb->truelen);
+  sb_new->data = sb_new->head + (sb->data - sb->head);
+  sb_new->tail = sb_new->data + sb->len;
+  sb_new->len = sb->len;
+
+  return sb_new;
+}
+
+/* Reallocates buffer. Old data is saved into the new buffer. Returns
+   new SilcBuffer pointer. The buffer is exact clone of the old one
+   except that there is now more space at the end of buffer. */
+
+static inline
+SilcBuffer silc_buffer_realloc(SilcBuffer sb, uint32 newsize)
+{
+  SilcBuffer sb_new;
+
+  if (!sb)
+    return silc_buffer_alloc(newsize);
+
+  if (newsize <= sb->truelen)
+    return sb;
+
+  sb_new = silc_buffer_alloc(newsize);
+  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+  silc_buffer_put(sb_new, sb->head, sb->truelen);
+  sb_new->data = sb_new->head + (sb->data - sb->head);
+  sb_new->tail = sb_new->data + sb->len;
+  sb_new->len = sb->len;
+
+  silc_buffer_free(sb);
+
+  return sb_new;
+}
+
 #endif
diff --git a/lib/silcutil/silcbufutil.h b/lib/silcutil/silcbufutil.h
deleted file mode 100644 (file)
index ecf99e0..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
-
-  silcbufutil.h
-
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
-
-  Copyright (C) 1997 - 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 SILCBUFUTIL_H
-#define SILCBUFUTIL_H
-
-#include "silcbuffer.h"
-
-/* Clears and initialiazes the buffer to the state as if it was just
-   allocated by silc_buffer_alloc. */
-
-static inline
-void silc_buffer_clear(SilcBuffer sb)
-{
-  memset(sb->head, 0, sb->truelen);
-  sb->data = sb->head;
-  sb->tail = sb->head;
-  sb->len = 0;
-}
-
-/* Generates copy of a SilcBuffer. This copies everything inside the
-   currently valid data area, nothing more. Use silc_buffer_clone to
-   copy entire buffer. */
-
-static inline
-SilcBuffer silc_buffer_copy(SilcBuffer sb)
-{
-  SilcBuffer sb_new;
-
-  sb_new = silc_buffer_alloc(sb->len);
-  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
-  silc_buffer_put(sb_new, sb->data, sb->len);
-
-  return sb_new;
-}
-
-/* Clones SilcBuffer. This generates new SilcBuffer and copies
-   everything from the source buffer. The result is exact clone of
-   the original buffer. */
-
-static inline
-SilcBuffer silc_buffer_clone(SilcBuffer sb)
-{
-  SilcBuffer sb_new;
-
-  sb_new = silc_buffer_alloc(sb->truelen);
-  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
-  silc_buffer_put(sb_new, sb->head, sb->truelen);
-  sb_new->data = sb_new->head + (sb->data - sb->head);
-  sb_new->tail = sb_new->data + sb->len;
-  sb_new->len = sb->len;
-
-  return sb_new;
-}
-
-/* Reallocates buffer. Old data is saved into the new buffer. Returns
-   new SilcBuffer pointer. The buffer is exact clone of the old one
-   except that there is now more space at the end of buffer. */
-
-static inline
-SilcBuffer silc_buffer_realloc(SilcBuffer sb, uint32 newsize)
-{
-  SilcBuffer sb_new;
-
-  if (!sb)
-    return silc_buffer_alloc(newsize);
-
-  if (newsize <= sb->truelen)
-    return sb;
-
-  sb_new = silc_buffer_alloc(newsize);
-  silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
-  silc_buffer_put(sb_new, sb->head, sb->truelen);
-  sb_new->data = sb_new->head + (sb->data - sb->head);
-  sb_new->tail = sb_new->data + sb->len;
-  sb_new->len = sb->len;
-
-  silc_buffer_free(sb);
-
-  return sb_new;
-}
-
-#endif
index 132657349acc5d0c3be6427875711db70da8d9e8..b4f5a70482e677b2054f3973f3b131a631ed0e3a 100644 (file)
  * (or File object) and SilcConfigEntity (or Entity).  The File objects are
  * structs directly corresponding to the real files in the filesystem, while
  * Entities are a little more abstract.
+ *
  * An Entity is composed by delimited area on a File object (it can take the
  * whole File object or just part of it), plus a group of known options.
- *
  * In order to parse this file, first you need to create a File object with
  * the silc_config_open() function, and then you need to create the Entity
  * with the silc_config_init() function.
+ *
  * Now you can use the newly created Entity to register a group of expected
  * known options and sub-blocks, and then you can call the main parsing loop
- * with the silc_config_main() function.
- * When silc_config_main() will return, if some error encoured the object file
- * will point to the file that caused this error (this can be different from
- * the originally opened file if it contained `Include' directives).  If no
- * errors encoured then the File objects will still point to the original
- * file.
+ * with the silc_config_main() function. When silc_config_main() will 
+ * return, if some error encoured the object file will point to the file 
+ * that caused this error (this can be different from the originally 
+ * opened file if it contained `Include' directives).  If no errors 
+ * encoured then the File objects will still point to the original file.
+ *
  * While silc_config_main() will take care of destroying Entities before
  * returning, you need to take care that the File object you created is freed
  * with the silc_config_close() function.
@@ -51,6 +52,7 @@
  * The config file syntax is pretty straightforward.  All lines starting
  * with `#' will be skipped, while sub-blocks are delimited by braces (see
  * the example below).
+ *
  * Options with argument must have the `=' character between the option
  * name and the value.  Simple words and numbers does not require quoting.
  * There is a special built-in directive "Include" which allows you to include
index 6f309349ef01703ca5936d8c8e97d1b8b9da2d02..326837e10c4ed4d2835238499b3f585dae143c5c 100644 (file)
@@ -18,7 +18,7 @@
 
 */
 
-/****h* silcutil/SilcList
+/****h* silcutil/SilcListAPI
  *
  * DESCRIPTION
  *
index 2df6fee495f03ea02a595f6942c3f63f2603b6e8..eb246557b7b99e2c2a58af70d8d65b53bfe45198 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcmemory.c
+  silcmemory.c 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1999 - 2000 Pekka Riikonen
+  Copyright (C) 1999 - 2002 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.
-  
+  the Free Software Foundation; version 2 of the License.
+
   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
@@ -49,3 +48,12 @@ void silc_free(void *ptr)
 {
   free(ptr);
 }
+
+void *silc_memdup(const void *ptr, size_t size)
+{
+  unsigned char *addr = silc_malloc(size + 1);
+  assert(addr != NULL);
+  memcpy((void *)addr, ptr, size);
+  addr[size] = '\0';
+  return (void *)addr;
+}
index 100f511d39e02fa4fb20200704487d95bda78323..f05800bec6bf98fa623c81eec712bbbd4eeae58b 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silcmemory.h
+  silcmemory.h 
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1999 - 2000 Pekka Riikonen
+  Copyright (C) 1999 - 2002 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.
-  
+  the Free Software Foundation; version 2 of the License.
+
   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
 
 */
 
+/****h* silcutil/SilcMemoryAPI
+ *
+ * DESCRIPTION
+ *
+ * Basic utility functions for allocating memory. All SILC routines, and
+ * applications use these functions when they need to allocate, manipulate
+ * and free memory.
+ *
+ * Currently all allocation routines assert() that the memory was allocated
+ * successfully. Hence, if memory allocation fails it is fatal error.
+ *
+ ***/
+
 #ifndef SILCMEMORY_H
 #define SILCMEMORY_H
 
 /* Prototypes */
+
+/****f* silcutil/SilcMemoryAPI/silc_malloc
+ *
+ * SYNOPSIS
+ *
+ *    void *silc_malloc(size_t size);
+ *
+ * DESCRIPTION
+ *
+ *    Allocates memory of `size' bytes and returns pointer to the allocated
+ *    memory area.  Free the memory by calling silc_free.
+ *
+ ***/
 void *silc_malloc(size_t size);
+
+/****f* silcutil/SilcMemoryAPI/silc_calloc
+ *
+ * SYNOPSIS
+ *
+ *    void *silc_calloc(size_t items, size_t size);
+ *
+ * DESCRIPTION
+ *
+ *    Allocates memory of for an array of `items' elements of `size' bytes
+ *    and returns pointer to the allocated memory area.  The memory are is
+ *    also zeroed.  Free the memory by calling silc_free.
+ *
+ ***/
 void *silc_calloc(size_t items, size_t size);
+
+/****f* silcutil/SilcMemoryAPI/silc_realloc
+ *
+ * SYNOPSIS
+ *
+ *    void *silc_realloc(void *ptr, size_t size);
+ *
+ * DESCRIPTION
+ *
+ *    Change the size of the memory block indicated by `ptr' to the new
+ *    size of `size' bytes.  The contents of `ptr' will not be changed.
+ *    If `ptr' is NULL the call is equivalent to silc_malloc.  If the
+ *    `size' is zero (0) the call is equivalent to silc_free.  Free the
+ *    memory by calling silc_free.
+ *
+ * NOTES
+ *
+ *    The pointer returned to the reallocated memory area might not be
+ *    same as `ptr'.
+ *
+ ***/
 void *silc_realloc(void *ptr, size_t size);
+
+/****f* silcutil/SilcMemoryAPI/silc_free
+ *
+ * SYNOPSIS
+ *
+ *    void silc_free(void *ptr);
+ *
+ * DESCRIPTION
+ *
+ *    Frees the memory area indicated by the `ptr'. If `ptr' is NULL no
+ *    operation is performed.
+ *
+ ***/
 void silc_free(void *ptr);
 
-#endif
+/****f* silcutil/SilcMemoryAPI/silc_memdup
+ *
+ * SYNOPSIS
+ *
+ *    void *silc_memdup(const void *ptr, size_t size);
+ *
+ * DESCRIPTION
+ *
+ *    Duplicates the memory area indicated by `ptr' which is of size
+ *    of `size' bytes. Returns pointer to the duplicated memory area.
+ *    This NULL terminates the dupped memory area by allocating `size' + 1
+ *    bytes, so this function can be used to duplicate strings that does
+ *    not have NULL termination.
+ *
+ ***/
+void *silc_memdup(const void *ptr, size_t size);
+
+#endif /* SILCMEMORY_H */
index 81a750d89736e63b2f3667e6fab34a3a5587c590..3691c4cae3d83b116e0b7b671b7b2fa2270dc379 100644 (file)
@@ -557,3 +557,4 @@ EXPORTS
        silc_log_flushdelay @ 848 DATA ;
        silc_hash_table_list_reset @ 849 ;
        silc_debug_hexdump @ 850 DATA ;
+       silc_memdup @ 851 ;