aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-common.c')
-rw-r--r--src/fs/gnunet-fs-gtk-common.c93
1 files changed, 54 insertions, 39 deletions
diff --git a/src/fs/gnunet-fs-gtk-common.c b/src/fs/gnunet-fs-gtk-common.c
index c4058cd1..586c51fd 100644
--- a/src/fs/gnunet-fs-gtk-common.c
+++ b/src/fs/gnunet-fs-gtk-common.c
@@ -42,38 +42,38 @@ char *
42GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format, 42GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format,
43 const char *data, size_t data_len) 43 const char *data, size_t data_len)
44{ 44{
45 gchar *result = NULL; 45 switch (format)
46
47 if (format == EXTRACTOR_METAFORMAT_UTF8)
48 { 46 {
47 case EXTRACTOR_METAFORMAT_UTF8:
49 /* data must not contain NULLs (hence the -1) */ 48 /* data must not contain NULLs (hence the -1) */
50 if (g_utf8_validate (data, data_len - 1, NULL)) 49 if (g_utf8_validate (data, data_len - 1, NULL))
51 result = GNUNET_strdup (data); 50 return GNUNET_strdup (data);
52 else 51 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
53 { 52 _("Failed to validate supposedly utf-8 string `%s' of length %u, assuming it to be a C string\n"),
54 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 53 data,
55 "Failed to validate supposedly utf-8 string `%s' of length %u, assuming it to be a C string\n", 54 (unsigned int) data_len);
56 data, data_len); 55 format = EXTRACTOR_METAFORMAT_C_STRING;
57 format = EXTRACTOR_METAFORMAT_C_STRING; 56 /* fall-through */
58 } 57 case EXTRACTOR_METAFORMAT_C_STRING:
59 }
60 if (format == EXTRACTOR_METAFORMAT_C_STRING)
61 {
62 if (data_len > 0) 58 if (data_len > 0)
63 { /* There are no guarantees that data is NULL-terminated, AFAIU, 59 {
64 * so let's play it safe, shall we? 60 /* There are no guarantees that data is NULL-terminated, AFAIU,
65 */ 61 * so let's play it safe, shall we?
66 char *data_copy = GNUNET_malloc (data_len + 1); 62 */
63 char data_copy[data_len + 1];
67 64
68 memcpy (data_copy, data, data_len); 65 memcpy (data_copy, data, data_len);
69 data_copy[data_len] = '\0'; 66 data_copy[data_len] = '\0';
70 result = GNUNET_GTK_from_loc_to_utf8 (data_copy); 67 return GNUNET_GTK_from_loc_to_utf8 (data_copy);
71 GNUNET_free (data_copy);
72 } 68 }
69 break;
70 default:
71 break;
73 } 72 }
74 return result; 73 return NULL;
75} 74}
76 75
76
77/** 77/**
78 * Add meta data to list store. 78 * Add meta data to list store.
79 * 79 *
@@ -98,18 +98,15 @@ GNUNET_FS_GTK_add_meta_data_to_list_store (void *cls, const char *plugin_name,
98 const char *data, size_t data_len) 98 const char *data, size_t data_len)
99{ 99{
100 GtkListStore *ls = GTK_LIST_STORE (cls); 100 GtkListStore *ls = GTK_LIST_STORE (cls);
101 gchar *data_to_insert = NULL; 101 char *data_to_insert;
102 102
103 data_to_insert = GNUNET_FS_GTK_dubious_meta_to_utf8 (format, data, data_len); 103 data_to_insert = GNUNET_FS_GTK_dubious_meta_to_utf8 (format, data, data_len);
104 104 if (NULL == data_to_insert)
105 if (NULL != data_to_insert) 105 return 0;
106 { 106 gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format,
107 gtk_list_store_insert_with_values (ls, NULL, G_MAXINT, 0, type, 1, format, 107 2, EXTRACTOR_metatype_to_string (type),
108 2, EXTRACTOR_metatype_to_string (type), 108 3, data_to_insert, -1);
109 3, data_to_insert, -1); 109 GNUNET_free (data_to_insert);
110 g_free (data_to_insert);
111 }
112
113 return 0; 110 return 0;
114} 111}
115 112
@@ -117,6 +114,9 @@ GNUNET_FS_GTK_add_meta_data_to_list_store (void *cls, const char *plugin_name,
117/** 114/**
118 * Convert the year from the spin button to an expiration 115 * Convert the year from the spin button to an expiration
119 * time (on midnight, January 1st of that year). 116 * time (on midnight, January 1st of that year).
117 *
118 * @param spin button with an expiration year
119 * @return expiration time in the usual GNUnet format
120 */ 120 */
121struct GNUNET_TIME_Absolute 121struct GNUNET_TIME_Absolute
122GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin) 122GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin)
@@ -132,6 +132,14 @@ GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin)
132} 132}
133 133
134 134
135/**
136 * Initialize the 'expiration_year_adjustment' of the given
137 * builder to have a lower range of current-year+1 and a
138 * default of current-year+2.
139 *
140 * @param builder builder object for which we should manipulate
141 * the adjustment
142 */
135void 143void
136GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder) 144GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
137{ 145{
@@ -146,6 +154,12 @@ GNUNET_FS_GTK_setup_expiration_year_adjustment (GtkBuilder * builder)
146} 154}
147 155
148 156
157/**
158 * Obtain pixbuf from thumbnail data in meta data.
159 *
160 * @param meta input meta data
161 * @return NULL on error, otherwise the embedded thumbnail
162 */
149GdkPixbuf * 163GdkPixbuf *
150GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct 164GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
151 GNUNET_CONTAINER_MetaData *meta) 165 GNUNET_CONTAINER_MetaData *meta)
@@ -157,13 +171,13 @@ GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
157 171
158 thumb = NULL; 172 thumb = NULL;
159 ts = GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb); 173 ts = GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb);
160 if (ts == 0) 174 if (0 == ts)
161 return NULL; 175 return NULL;
162 loader = gdk_pixbuf_loader_new (); 176 loader = gdk_pixbuf_loader_new ();
163 gdk_pixbuf_loader_write (loader, (const guchar *) thumb, ts, NULL); 177 gdk_pixbuf_loader_write (loader, (const guchar *) thumb, ts, NULL);
164 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); 178 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
165 gdk_pixbuf_loader_close (loader, NULL); 179 gdk_pixbuf_loader_close (loader, NULL);
166 if (pixbuf != NULL) 180 if (NULL != pixbuf)
167 g_object_ref (pixbuf); 181 g_object_ref (pixbuf);
168 g_object_unref (loader); 182 g_object_unref (loader);
169 GNUNET_free (thumb); 183 GNUNET_free (thumb);
@@ -174,6 +188,10 @@ GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
174/** 188/**
175 * mmap the given file and run the GNUNET_FS_directory_list_contents 189 * mmap the given file and run the GNUNET_FS_directory_list_contents
176 * function on it. 190 * function on it.
191 *
192 * @param filename name with the directory
193 * @param dep function to call on each entry
194 * @param dep_cls closure for 'dep'
177 */ 195 */
178void 196void
179GNUNET_FS_GTK_mmap_and_scan (const char *filename, 197GNUNET_FS_GTK_mmap_and_scan (const char *filename,
@@ -190,16 +208,13 @@ GNUNET_FS_GTK_mmap_and_scan (const char *filename,
190 GNUNET_break (0); 208 GNUNET_break (0);
191 return; 209 return;
192 } 210 }
193 fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 211 if (NULL == (fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
194 GNUNET_DISK_PERM_NONE); 212 GNUNET_DISK_PERM_NONE)))
195 if (fh == NULL)
196 { 213 {
197 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 214 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
198 return; 215 return;
199 } 216 }
200 ddata = 217 if (NULL == (ddata = GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_TYPE_READ, (size_t) fsize)))
201 GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_TYPE_READ, (size_t) fsize);
202 if (ddata == NULL)
203 { 218 {
204 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename); 219 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
205 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); 220 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));