Changed MIME code to use SILC Rand API to create fragment ID.
[runtime.git] / lib / silcutil / silcmime.c
index 839eb354b9ea6841c129d104e765f184588a6b69..b9ef38cd81d03a5b34926f962086b8312c5ac28a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 - 2007 Pekka Riikonen
+  Copyright (C) 2005 - 2008 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
@@ -17,7 +17,7 @@
 
 */
 
-#include "silc.h"
+#include "silcruntime.h"
 
 /************************** Types and definitions ***************************/
 
@@ -29,14 +29,6 @@ typedef struct {
 
 /************************ Static utility functions **************************/
 
-/* MIME fields destructor */
-
-static void silc_mime_field_dest(void *key, void *context, void *user_context)
-{
-  silc_free(key);
-  silc_free(context);
-}
-
 /* Assembler fragment destructor */
 
 static void silc_mime_assembler_dest(void *key, void *context,
@@ -91,7 +83,7 @@ SilcMime silc_mime_alloc(void)
 
   mime->fields = silc_hash_table_alloc(NULL, 0, silc_hash_string_case, mime,
                                       silc_hash_string_case_compare, mime,
-                                      silc_mime_field_dest, mime, TRUE);
+                                      silc_hash_destructor, mime, TRUE);
   if (!mime->fields) {
     silc_mime_free(mime);
     return NULL;
@@ -682,11 +674,9 @@ SilcDList silc_mime_encode_partial(SilcMime mime, int max_size)
   if (buf_len > max_size) {
     memset(id, 0, sizeof(id));
     memset(type, 0, sizeof(type));
-    gethostname(type, sizeof(type) - 1);
-    srand((time(NULL) + buf_len) ^ rand());
-    silc_snprintf(id, sizeof(id) - 1, "%X%X%X%s",
-            (unsigned int)rand(), (unsigned int)time(NULL),
-            (unsigned int)buf_len, type);
+    silc_snprintf(id, sizeof(id) - 1, "%X%x%X%x",
+                 (unsigned int)silc_rand(), (unsigned int)silc_time_usec(),
+                 (unsigned int)buf_len, (unsigned int)silc_rand());
 
     SILC_LOG_DEBUG(("Fragment ID %s", id));