From 9e328007bd59ec2ac99a198ecbd6cd863fcd27a8 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 15 Apr 2010 14:42:45 +0000 Subject: [PATCH] --- src/hostlist/hostlist-client.c | 68 ++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index d84d0eb82..ccc00a2ab 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -1025,14 +1025,24 @@ static int load_hostlist_file () } /* add code to read hostlists to file using bio */ - char * buffer = GNUNET_malloc (100 * sizeof (char)); - GNUNET_BIO_read_string (rh, NULL , &buffer, 100); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - ("Read from file %s : %s \n"), filename, buffer); + char *buffer = GNUNET_malloc (1000 * sizeof (char)); + /* char *token; - if ( GNUNET_OK != GNUNET_BIO_read_close ( rh , &buffer) ) + while (GNUNET_OK == GNUNET_BIO_read_string (rh, NULL , &buffer, 1000) ) + { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - ("Error while closing file %s\n"), filename); + ("Read from file %s : %s \n"), filename, buffer); + + pch = strtok (str," ,.-"); + while (pch != NULL) + { + printf ("%s\n",pch); + pch = strtok (NULL, " ,.-"); + } + + } + */ + GNUNET_BIO_read_close ( rh , &buffer); return GNUNET_OK; } @@ -1066,8 +1076,52 @@ static int save_hostlist_file () } /* add code to write hostlists to file using bio */ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Writing hostlist to disk\n"); + struct GNUNET_Hostlist * actual = dll_head; + struct GNUNET_Hostlist * next; + char * content = GNUNET_malloc(1000 * sizeof (char)); + char * buffer = GNUNET_malloc(1000 * sizeof (char)); - /* iterate over all entries in dll */ + actual = dll_head; + while ( GNUNET_YES) + { + /* serialize content */ + /* uri;hello_count;quality; */ + strcpy(content,actual->hostlist_uri); + strcat(content,";"); + sprintf(buffer, "%lu", actual->hello_count); + strcat(content,buffer); + strcat(content,";"); + sprintf(buffer, "%llu", (long long unsigned int) actual->quality); + strcat(content,buffer); + strcat(content,";"); + sprintf(buffer, "%llu", (long long unsigned int) actual->time_creation.value); + strcat(content,buffer); + strcat(content,";"); + sprintf(buffer, "%llu", (long long unsigned int) actual->time_last_usage.value); + strcat(content,buffer); + strcat(content,";"); + sprintf(buffer, "%lu", actual->times_used); + strcat(content,buffer); + strcat(content,";"); + + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + ("Content to write: %s\n"), + content); + + GNUNET_BIO_write_string ( wh, content ); + + + if (actual == dll_tail) break; + next = actual->next; + GNUNET_free (actual->hostlist_uri); + GNUNET_free (actual); + actual = next; + } + GNUNET_free (actual->hostlist_uri); + GNUNET_free (actual); + GNUNET_free (content); if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, -- 2.25.1