[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11121 - gnunet/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11121 - gnunet/src/fs |
Date: |
Fri, 30 Apr 2010 00:48:11 +0200 |
Author: grothoff
Date: 2010-04-30 00:48:11 +0200 (Fri, 30 Apr 2010)
New Revision: 11121
Modified:
gnunet/src/fs/fs.c
gnunet/src/fs/fs.h
gnunet/src/fs/fs_file_information.c
Log:
fi deserialization
Modified: gnunet/src/fs/fs.c
===================================================================
--- gnunet/src/fs/fs.c 2010-04-29 21:52:48 UTC (rev 11120)
+++ gnunet/src/fs/fs.c 2010-04-29 22:48:11 UTC (rev 11121)
@@ -284,9 +284,160 @@
* @return NULL on error
*/
static struct GNUNET_FS_FileInformation *
-deserialize_fi_node (struct GNUNET_BIO_ReadHandle *rh)
+deserialize_file_information (struct GNUNET_FS_Handle *h,
+ const char *filename);
+
+
+/**
+ * Using the given serialization filename, try to deserialize
+ * the file-information tree associated with it.
+ *
+ * @param h master context
+ * @param fn name of the file (without directory) with
+ * the infromation
+ * @param rh handle for reading
+ * @return NULL on error
+ */
+static struct GNUNET_FS_FileInformation *
+deserialize_fi_node (struct GNUNET_FS_Handle *h,
+ const char *fn,
+ struct GNUNET_BIO_ReadHandle *rh)
{
+ struct GNUNET_FS_FileInformation *ret;
+ struct GNUNET_FS_FileInformation *nxt;
+ char b;
+ char *ksks;
+ char *chks;
+ char *filename;
+ uint32_t dsize;
+
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "termination flag", &b, sizeof(b)))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+ ksks = NULL;
+ chks = NULL;
+ filename = NULL;
+ if ( (GNUNET_OK !=
+ GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32*1024)) ||
+ (NULL ==
+ (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
+ (GNUNET_YES !=
+ GNUNET_FS_uri_test_ksk (ret->keywords)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
+ ( (chks != NULL) &&
+ ( (NULL ==
+ (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
+ (GNUNET_YES !=
+ GNUNET_FS_uri_test_chk (ret->chk_uri)) ) ) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->expirationTime.value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->start_time.value)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16*1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16*1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &ret->anonymity)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &ret->priority)) )
+ goto cleanup;
+ switch (b)
+ {
+ case 0: /* file-insert */
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
+ goto cleanup;
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_NO;
+ ret->data.file.have_hash = GNUNET_NO;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ break;
+ case 1: /* file-index, no hash */
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
+ goto cleanup;
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_NO;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ break;
+ case 2: /* file-index-with-hash */
+ if ( (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof
(GNUNET_HashCode))) )
+ goto cleanup;
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_YES;
+ ret->data.file.index_start_confirmed = GNUNET_NO;
+ break;
+ case 3: /* file-index-with-hash-confirmed */
+ if ( (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, sizeof
(GNUNET_HashCode))) )
+ goto cleanup;
+ ret->is_directory = GNUNET_NO;
+ ret->data.file.do_index = GNUNET_YES;
+ ret->data.file.have_hash = GNUNET_YES;
+ ret->data.file.index_start_confirmed = GNUNET_YES;
+ break;
+ case 4: /* directory */
+ if ( (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (rh, &dsize)) ||
+ (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "ent-filename", &filename, 16*1024)) )
+ goto cleanup;
+ ret->data.dir.dir_size = (uint32_t) dsize;
+ ret->is_directory = GNUNET_YES;
+ if (filename != NULL)
+ {
+ ret->data.dir.entries = deserialize_file_information (h, filename);
+ GNUNET_free (filename);
+ filename = NULL;
+ nxt = ret->data.dir.entries;
+ while (nxt != NULL)
+ {
+ nxt->dir = ret;
+ nxt = nxt->next;
+ }
+ }
+ break;
+ default:
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ /* FIXME: adjust ret->start_time! */
+ ret->serialization = GNUNET_strdup (fn);
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "nxt-filename", &filename, 16*1024))
+ goto cleanup;
+ if (filename != NULL)
+ {
+ ret->next = deserialize_file_information (h, filename);
+ GNUNET_free (filename);
+ filename = NULL;
+ }
+ return ret;
+ cleanup:
+ GNUNET_free_non_null (ksks);
+ GNUNET_free_non_null (chks);
+ GNUNET_free_non_null (filename);
+ GNUNET_FS_file_information_destroy (ret, NULL, NULL);
return NULL;
+
}
@@ -310,7 +461,7 @@
rh = get_read_handle (h, "publish-fi", filename);
if (rh == NULL)
return NULL;
- ret = deserialize_fi_node (rh);
+ ret = deserialize_fi_node (h, filename, rh);
if (GNUNET_OK !=
GNUNET_BIO_read_close (rh, &emsg))
{
@@ -341,7 +492,7 @@
while (pos != NULL)
{
if (0 == strcmp (srch,
- pos->serialization_name))
+ pos->serialization))
return pos;
if (pos->is_directory)
{
Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h 2010-04-29 21:52:48 UTC (rev 11120)
+++ gnunet/src/fs/fs.h 2010-04-29 22:48:11 UTC (rev 11121)
@@ -343,12 +343,6 @@
char *emsg;
/**
- * Filename on disk that is used to track the progress of this
- * upload (short name, not the full path).
- */
- char *serialization_name;
-
- /**
* Name of the file or directory (must be an absolute path).
*/
char *filename;
Modified: gnunet/src/fs/fs_file_information.c
===================================================================
--- gnunet/src/fs/fs_file_information.c 2010-04-29 21:52:48 UTC (rev 11120)
+++ gnunet/src/fs/fs_file_information.c 2010-04-29 22:48:11 UTC (rev 11121)
@@ -849,7 +849,9 @@
else
{
/* call clean-up function of the reader */
- fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
+ if (fi->data.file.reader != NULL)
+ fi->data.file.reader (fi->data.file.reader_cls, 0, 0,
+ NULL, NULL);
/* clean up client-info */
if (NULL != cleaner)
cleaner (cleaner_cls,
@@ -874,7 +876,8 @@
fi->serialization);
if (NULL != fi->keywords)
GNUNET_FS_uri_destroy (fi->keywords);
- GNUNET_CONTAINER_meta_data_destroy (fi->meta);
+ if (NULL != fi->meta)
+ GNUNET_CONTAINER_meta_data_destroy (fi->meta);
GNUNET_free_non_null (fi->serialization);
if (fi->te != NULL)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11121 - gnunet/src/fs,
gnunet <=