Fixed identifier string handling. Added support for automatic
authorPekka Riikonen <priikone@silcnet.org>
Wed, 30 Mar 2005 12:25:45 +0000 (12:25 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 30 Mar 2005 12:25:45 +0000 (12:25 +0000)
deletion of ID's and names if desired by caller.

CHANGES
lib/silcclient/client.c
lib/silccore/silcidcache.c
lib/silccore/silcidcache.h

diff --git a/CHANGES b/CHANGES
index 0b3d0474feb8f3ed8b3bfe8c26222af7996a1a30..11c5600ca4ce666997bb8a0aacfec050b19d3660 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,18 @@
+Wed Mar 30 10:50:02 EEST 2005  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed idcache to work with the new identifier strings.
+         Affected file lib/silccore/silcidcache.c.
+
+       * Added UTF-8 hash and compare function for SilcHashTable.
+         Affected file lib/silcutil/silcutil.[ch].
+
+       * Added casefolding stringprep, SILC_CASEFOLD_PREP.
+         Affected file lib/silcutil/silcstringprep.[ch].
+
+       * Changed the identifier string handling to include the original
+         format in client, server, channel entries and normalized
+         format in cache.  Affected files in silcd/.
+
 Tue Mar 29 16:51:35 EEST 2005  Pekka Riikonen <priikone@silcnet.org>
 
        * Added support for the new identifier strings and their
index 9dfeaf2cc6595e342b54575548250e40ce2c19b8..a43a52afd1d0075ab5ddb5da70a8a0970e4c0f23 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2004 Pekka Riikonen
+  Copyright (C) 1997 - 2005 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
@@ -87,7 +87,7 @@ void silc_client_free(SilcClient client)
   if (client) {
     if (client->rng)
       silc_rng_free(client->rng);
-       
+
     if (!client->internal->params->dont_register_crypto_library) {
       silc_cipher_unregister_all();
       silc_pkcs_unregister_all();
@@ -238,9 +238,12 @@ silc_client_add_connection(SilcClient client,
   conn->remote_port = port;
   conn->context = context;
   conn->internal->client_cache =
-    silc_idcache_alloc(0, SILC_ID_CLIENT, silc_client_entry_destructor);
-  conn->internal->channel_cache = silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL);
-  conn->internal->server_cache = silc_idcache_alloc(0, SILC_ID_SERVER, NULL);
+    silc_idcache_alloc(0, SILC_ID_CLIENT, silc_client_entry_destructor,
+                      FALSE, FALSE);
+  conn->internal->channel_cache = silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL,
+                                                    FALSE, FALSE);
+  conn->internal->server_cache = silc_idcache_alloc(0, SILC_ID_SERVER, NULL,
+                                                   FALSE, FALSE);
   conn->internal->pending_commands = silc_dlist_init();
   conn->internal->ftp_sessions = silc_dlist_init();
 
index 16e995f877f6a7ce007f1994ccd2db09cbab5509..da86f7437a5cc51409c6662ebd4c9772b6ec371b 100644 (file)
@@ -68,6 +68,8 @@ struct SilcIDCacheStruct {
   SilcHashTable context_table;
   SilcIDCacheDestructor destructor;
   SilcIdType type;
+  unsigned int delete_id : 1;
+  unsigned int delete_name : 1;
 };
 
 /*
@@ -99,7 +101,8 @@ struct SilcIDCacheListStruct {
    cache. */
 
 SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
-                              SilcIDCacheDestructor destructor)
+                              SilcIDCacheDestructor destructor,
+                              bool delete_id, bool delete_name)
 {
   SilcIDCache cache;
 
@@ -112,14 +115,17 @@ SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
                                          SILC_32_TO_PTR(id_type),
                                          silc_hash_id_compare,
                                          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_data_compare, NULL,
+                                         silc_idcache_destructor,
+                                         cache, TRUE);
+  cache->name_table = silc_hash_table_alloc(count, silc_hash_utf8_string, NULL,
+                                           silc_hash_utf8_compare, NULL,
                                            NULL, NULL, TRUE);
   cache->context_table = silc_hash_table_alloc(count, silc_hash_ptr, NULL,
                                               NULL, NULL, NULL, NULL, TRUE);
   cache->destructor = destructor;
   cache->type = id_type;
+  cache->delete_id = delete_id;
+  cache->delete_name = delete_name;
 
   if (!cache->id_table || !cache->name_table || !cache->context_table) {
     if (cache->id_table)
@@ -191,6 +197,13 @@ static void silc_idcache_destructor(void *key, void *context,
 {
   SilcIDCacheEntry c = context;
   if (c) {
+    SilcIDCache cache = user_context;
+    if (cache) {
+      if (cache->delete_id)
+       silc_free(c->id);
+      if (cache->delete_name)
+       silc_free(c->name);
+    }
     memset(c, 'F', sizeof(*c));
     silc_free(c);
   }
@@ -257,7 +270,6 @@ bool silc_idcache_del_by_id_ext(SilcIDCache cache, void *id,
     ret = silc_hash_table_del_ext(cache->id_table, c->id, hash,
                                  hash_context, compare, compare_context,
                                  NULL, NULL);
-
   return ret;
 }
 
index 71f8f445635bb152451898c4cdcdbb32a0338d8d..69c5290f1bdb8a639d2a74c0f56f6b8a9bbca88a 100644 (file)
@@ -1,16 +1,16 @@
 /*
+
   silcidcache.h
+
   Author: Pekka Riikonen <priikone@silcnet.org>
-  Copyright (C) 2000 - 2001 Pekka Riikonen
+
+  Copyright (C) 2000 - 2005 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
@@ -21,7 +21,7 @@
 /****h* silccore/SILC ID Cache Interface
  *
  * DESCRIPTION
- * 
+ *
  * SILC ID Cache is an cache for all kinds of ID's used in the SILC
  * protocol.  Application can save here the ID's it uses and the interface
  * provides fast retrieval of the ID's from the cache.
 /****s* silccore/SilcIDCacheAPI/SilcIDCacheEntry
  *
  * NAME
- * 
+ *
  *    typedef struct { ... } SilcIDCacheEntry;
  *
  * DESCRIPTION
  *
  *    This is one entry in the SILC ID Cache system. Contents of this is
- *    allocated outside the ID cache system, however, all the fields are 
+ *    allocated outside the ID cache system, however, all the fields are
  *    filled with ID cache utility functions. The ID cache system does not
  *    allocate any of these fields nor free them.
  *
@@ -76,13 +76,13 @@ typedef struct {
 /****s* silccore/SilcIDCacheAPI/SilcIDCache
  *
  * NAME
- * 
+ *
  *    typedef struct SilcIDCacheStruct *SilcIDCache;
  *
  * DESCRIPTION
  *
- *    This context is the actual ID Cache and is allocated by 
- *    silc_idcache_alloc and given as argument usually to all 
+ *    This context is the actual ID Cache and is allocated by
+ *    silc_idcache_alloc and given as argument usually to all
  *    silc_idcache_* functions.  It is freed by the
  *    silc_idcache_free function.
  *
@@ -92,12 +92,12 @@ typedef struct SilcIDCacheStruct *SilcIDCache;
 /****s* silccore/SilcIDCacheAPI/SilcIDCacheList
  *
  * NAME
- * 
+ *
  *    typedef struct SilcIDCacheListStruct *SilcIDCacheList;
  *
  * DESCRIPTION
  *
- *    This context is the ID Cache List and is allocated by 
+ *    This context is the ID Cache List and is allocated by
  *    some of the silc_idcache_* functions. Functions that may return
  *    multiple entries from the cache allocate the entries in to the
  *    SilcIDCacheList. The context is freed by silc_idcache_list_free
@@ -139,13 +139,18 @@ typedef void (*SilcIDCacheDestructor)(SilcIDCache cache,
  * DESCRIPTION
  *
  *    Allocates new ID cache object. The initial amount of allocated entries
- *    can be sent as argument. If `count' is 0 the system uses default values. 
+ *    can be sent as argument. If `count' is 0 the system uses default values.
  *    The `id_type' defines the types of the ID's that will be saved to the
  *    cache.
  *
+ *    If 'delete_id' is TRUE then library will free the ID when a
+ *    cache entry is deleted.  If 'delete_name' is TRUE then library
+ *    will delete the associated name when a cache entry is deleted.
+ *
  ***/
 SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
-                              SilcIDCacheDestructor destructor);
+                              SilcIDCacheDestructor destructor,
+                              bool delete_id, bool delete_name);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_free
  *
@@ -164,7 +169,7 @@ void silc_idcache_free(SilcIDCache cache);
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_add(SilcIDCache cache, char *name, void *id, 
+ *    bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
  *                          void *context, int expire, SilcIDCacheEntry *ret);
  *
  * DESCRIPTION
@@ -180,11 +185,11 @@ void silc_idcache_free(SilcIDCache cache);
  *    of deleting the cache entry.  Otherwise the cache will have the freed
  *    pointers stored.
  *
- *    If the `ret' is non-NULL the created ID Cache entry is returned to 
+ *    If the `ret' is non-NULL the created ID Cache entry is returned to
  *    that pointer.
  *
  ***/
-bool silc_idcache_add(SilcIDCache cache, char *name, void *id, 
+bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
                      void *context, int expire, SilcIDCacheEntry *ret);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_del
@@ -220,9 +225,9 @@ bool silc_idcache_del_by_id(SilcIDCache cache, void *id);
  * SYNOPSIS
  *
  *    bool silc_idcache_del_by_id_ext(SilcIDCache cache, void *id,
- *                                    SilcHashFunction hash, 
+ *                                    SilcHashFunction hash,
  *                                    void *hash_context,
- *                                    SilcHashCompare compare, 
+ *                                    SilcHashCompare compare,
  *                                    void *compare_context);
  *
  * DESCRIPTION
@@ -230,13 +235,13 @@ bool silc_idcache_del_by_id(SilcIDCache cache, void *id);
  *    Same as silc_idcache_del_by_id but with specific hash and comparison
  *    functions. If the functions are NULL then default values are used.
  *    Returns TRUE if the entry was deleted. The destructor function is
- *    not called.
+ *    called.
  *
  ***/
 bool silc_idcache_del_by_id_ext(SilcIDCache cache, void *id,
-                               SilcHashFunction hash, 
+                               SilcHashFunction hash,
                                void *hash_context,
-                               SilcHashCompare compare, 
+                               SilcHashCompare compare,
                                void *compare_context);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_del_by_context
@@ -290,7 +295,7 @@ bool silc_idcache_purge(SilcIDCache cache);
  *
  * DESCRIPTION
  *
- *    Purges the cache by context and removes expired cache entires. 
+ *    Purges the cache by context and removes expired cache entires.
  *    Returns TRUE if the puring was successful. The destructor function
  *    is called for the purged cache entry.
  *
@@ -316,7 +321,7 @@ bool silc_idcache_get_all(SilcIDCache cache, SilcIDCacheList *ret);
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_find_by_id(SilcIDCache cache, void *id, 
+ *    bool silc_idcache_find_by_id(SilcIDCache cache, void *id,
  *                                 SilcIDCacheList *ret);
  *
  * DESCRIPTION
@@ -326,14 +331,14 @@ bool silc_idcache_get_all(SilcIDCache cache, SilcIDCacheList *ret);
  *    found. The caller must free the returned SilcIDCacheList.
  *
  ***/
-bool silc_idcache_find_by_id(SilcIDCache cache, void *id, 
+bool silc_idcache_find_by_id(SilcIDCache cache, void *id,
                             SilcIDCacheList *ret);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id_one
  *
  * SYNOPSIS
  *
- *     bool silc_idcache_find_by_id_one(SilcIDCache cache, void *id, 
+ *     bool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
  *                                      SilcIDCacheEntry *ret);
  *
  * DESCRIPTION
@@ -343,17 +348,17 @@ bool silc_idcache_find_by_id(SilcIDCache cache, void *id,
  *    if the entry was found.
  *
  ***/
-bool silc_idcache_find_by_id_one(SilcIDCache cache, void *id, 
+bool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
                                 SilcIDCacheEntry *ret);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_id_one_ext
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id, 
- *                                         SilcHashFunction hash, 
+ *    bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id,
+ *                                         SilcHashFunction hash,
  *                                         void *hash_context,
- *                                         SilcHashCompare compare, 
+ *                                         SilcHashCompare compare,
  *                                         void *compare_context,
  *                                         SilcIDCacheEntry *ret);
  *
@@ -365,10 +370,10 @@ bool silc_idcache_find_by_id_one(SilcIDCache cache, void *id,
  *    is used. Returns TRUE if the entry was found.
  *
  ***/
-bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id, 
-                                    SilcHashFunction hash, 
+bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id,
+                                    SilcHashFunction hash,
                                     void *hash_context,
-                                    SilcHashCompare compare, 
+                                    SilcHashCompare compare,
                                     void *compare_context,
                                     SilcIDCacheEntry *ret);
 
@@ -376,7 +381,7 @@ bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id,
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_find_by_context(SilcIDCache cache, void *context, 
+ *    bool silc_idcache_find_by_context(SilcIDCache cache, void *context,
  *                                      SilcIDCacheEntry *ret);
  *
  * DESCRIPTION
@@ -385,14 +390,14 @@ bool silc_idcache_find_by_id_one_ext(SilcIDCache cache, void *id,
  *    entry was found.
  *
  ***/
-bool silc_idcache_find_by_context(SilcIDCache cache, void *context, 
+bool silc_idcache_find_by_context(SilcIDCache cache, void *context,
                                  SilcIDCacheEntry *ret);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_find_by_name(SilcIDCache cache, char *name, 
+ *    bool silc_idcache_find_by_name(SilcIDCache cache, char *name,
  *                                   SilcIDCacheList *ret);
  *
  * DESCRIPTION
@@ -402,7 +407,7 @@ bool silc_idcache_find_by_context(SilcIDCache cache, void *context,
  *    TRUE if the entry was found. The caller must free the SIlcIDCacheList.
  *
  ***/
-bool silc_idcache_find_by_name(SilcIDCache cache, char *name, 
+bool silc_idcache_find_by_name(SilcIDCache cache, char *name,
                               SilcIDCacheList *ret);
 
 /****f* silccore/SilcIDCacheAPI/silc_idcache_find_by_name_one
@@ -440,7 +445,7 @@ int silc_idcache_list_count(SilcIDCacheList list);
  *
  * SYNOPSIS
  *
- *    bool silc_idcache_list_first(SilcIDCacheList list, 
+ *    bool silc_idcache_list_first(SilcIDCacheList list,
  *                                 SilcIDCacheEntry *ret);
  *
  * DESCRIPTION