aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-30 13:41:07 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-30 13:41:07 +0000
commite67c5886c645a5fda7753d3f72f62ea655d6655b (patch)
tree3058a0f96ddc820a97e38e47d87e6ebf685b23b8 /src/fs
parentd59ea5663203392637e84dea69feb9671ca2a3de (diff)
downloadgnunet-e67c5886c645a5fda7753d3f72f62ea655d6655b.tar.gz
gnunet-e67c5886c645a5fda7753d3f72f62ea655d6655b.zip
fixes
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.c59
-rw-r--r--src/fs/fs.h24
-rw-r--r--src/fs/fs_file_information.c37
3 files changed, 79 insertions, 41 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index e7a52d235..062870cd6 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -325,6 +325,42 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
325 325
326 326
327/** 327/**
328 * Function that provides data by copying from a buffer.
329 *
330 * @param cls closure (points to the buffer)
331 * @param offset offset to read from; it is possible
332 * that the caller might need to go backwards
333 * a bit at times
334 * @param max maximum number of bytes that should be
335 * copied to buf; readers are not allowed
336 * to provide less data unless there is an error;
337 * a value of "0" will be used at the end to allow
338 * the reader to clean up its internal state
339 * @param buf where the reader should write the data
340 * @param emsg location for the reader to store an error message
341 * @return number of bytes written, usually "max", 0 on error
342 */
343size_t
344GNUNET_FS_data_reader_copy_ (void *cls,
345 uint64_t offset,
346 size_t max,
347 void *buf,
348 char **emsg)
349{
350 char *data = cls;
351
352 if (max == 0)
353 {
354 GNUNET_free_non_null (data);
355 return 0;
356 }
357 memcpy (buf, &data[offset], max);
358 return max;
359}
360
361
362
363/**
328 * Return the full filename where we would store state information 364 * Return the full filename where we would store state information
329 * (for serialization/deserialization). 365 * (for serialization/deserialization).
330 * 366 *
@@ -525,11 +561,24 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
525 ret->data.file.do_index = GNUNET_NO; 561 ret->data.file.do_index = GNUNET_NO;
526 ret->data.file.have_hash = GNUNET_NO; 562 ret->data.file.have_hash = GNUNET_NO;
527 ret->data.file.index_start_confirmed = GNUNET_NO; 563 ret->data.file.index_start_confirmed = GNUNET_NO;
528 /* FIXME: what's our approach for dealing with the 564 if (GNUNET_NO == ret->is_published)
529 'reader' and 'reader_cls' fields? I guess the only 565 {
530 good way would be to dump "small" files into 566 if (NULL == ret->filename)
531 'rh' and to not support serialization of "large" 567 {
532 files (!?) */ 568 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
569 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
570 if (ret->data.file.reader_cls == NULL)
571 goto cleanup;
572 if (GNUNET_OK !=
573 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
574 goto cleanup;
575 }
576 else
577 {
578 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
579 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
580 }
581 }
533 break; 582 break;
534 case 1: /* file-index, no hash */ 583 case 1: /* file-index, no hash */
535 if (NULL == ret->filename) 584 if (NULL == ret->filename)
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 953e1e51b..2e870bb3b 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -602,6 +602,30 @@ void *
602GNUNET_FS_make_file_reader_context_ (const char *filename); 602GNUNET_FS_make_file_reader_context_ (const char *filename);
603 603
604 604
605
606/**
607 * Function that provides data by copying from a buffer.
608 *
609 * @param cls closure (points to the buffer)
610 * @param offset offset to read from; it is possible
611 * that the caller might need to go backwards
612 * a bit at times
613 * @param max maximum number of bytes that should be
614 * copied to buf; readers are not allowed
615 * to provide less data unless there is an error;
616 * a value of "0" will be used at the end to allow
617 * the reader to clean up its internal state
618 * @param buf where the reader should write the data
619 * @param emsg location for the reader to store an error message
620 * @return number of bytes written, usually "max", 0 on error
621 */
622size_t
623GNUNET_FS_data_reader_copy_(void *cls,
624 uint64_t offset,
625 size_t max,
626 void *buf,
627 char **emsg);
628
605/** 629/**
606 * Notification of FS that a search probe has made progress. 630 * Notification of FS that a search probe has made progress.
607 * This function is used INSTEAD of the client's event handler 631 * This function is used INSTEAD of the client's event handler
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index df5593f75..df53bcc1c 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -131,41 +131,6 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
131 131
132 132
133/** 133/**
134 * Function that provides data by copying from a buffer.
135 *
136 * @param cls closure (points to the buffer)
137 * @param offset offset to read from; it is possible
138 * that the caller might need to go backwards
139 * a bit at times
140 * @param max maximum number of bytes that should be
141 * copied to buf; readers are not allowed
142 * to provide less data unless there is an error;
143 * a value of "0" will be used at the end to allow
144 * the reader to clean up its internal state
145 * @param buf where the reader should write the data
146 * @param emsg location for the reader to store an error message
147 * @return number of bytes written, usually "max", 0 on error
148 */
149static size_t
150data_reader_copy(void *cls,
151 uint64_t offset,
152 size_t max,
153 void *buf,
154 char **emsg)
155{
156 char *data = cls;
157
158 if (max == 0)
159 {
160 GNUNET_free (data);
161 return 0;
162 }
163 memcpy (buf, &data[offset], max);
164 return max;
165}
166
167
168/**
169 * Create an entry for a file in a publish-structure. 134 * Create an entry for a file in a publish-structure.
170 * 135 *
171 * @param h handle to the file sharing subsystem 136 * @param h handle to the file sharing subsystem
@@ -205,7 +170,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
205 return GNUNET_FS_file_information_create_from_reader (h, 170 return GNUNET_FS_file_information_create_from_reader (h,
206 client_info, 171 client_info,
207 length, 172 length,
208 &data_reader_copy, 173 &GNUNET_FS_data_reader_copy_,
209 data, 174 data,
210 keywords, 175 keywords,
211 meta, 176 meta,