diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/setup/gnunet-setup-gns.c | 430 |
1 files changed, 239 insertions, 191 deletions
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c index edd38126..f1956e27 100644 --- a/src/setup/gnunet-setup-gns.c +++ b/src/setup/gnunet-setup-gns.c | |||
@@ -167,29 +167,6 @@ enum LIST_COLUMNS | |||
167 | 167 | ||
168 | 168 | ||
169 | /** | 169 | /** |
170 | * | ||
171 | */ | ||
172 | struct UpdateContext | ||
173 | { | ||
174 | |||
175 | /** | ||
176 | * | ||
177 | */ | ||
178 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
179 | |||
180 | /** | ||
181 | * | ||
182 | */ | ||
183 | char * name; | ||
184 | |||
185 | /** | ||
186 | * | ||
187 | */ | ||
188 | unsigned int rd_count; | ||
189 | }; | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Name of our zone as a string. | 170 | * Name of our zone as a string. |
194 | */ | 171 | */ |
195 | static char *zone_as_string; | 172 | static char *zone_as_string; |
@@ -247,88 +224,144 @@ static int iteration; | |||
247 | 224 | ||
248 | 225 | ||
249 | /** | 226 | /** |
227 | * Context we use for making changes to the namestore. | ||
228 | * (closure for 'add_new_records_after_removing_old_records'). | ||
229 | */ | ||
230 | struct UpdateContext | ||
231 | { | ||
232 | |||
233 | /** | ||
234 | * Array of records to add. | ||
235 | */ | ||
236 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
237 | |||
238 | /** | ||
239 | * Name under which we should add the records. | ||
240 | */ | ||
241 | char * name; | ||
242 | |||
243 | /** | ||
244 | * Size of the 'rd' array. | ||
245 | */ | ||
246 | unsigned int rd_count; | ||
247 | }; | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Display an error message for the user. | ||
252 | * | ||
253 | * @param title title of the error message | ||
254 | * @param emsg error message to show | ||
255 | */ | ||
256 | static void | ||
257 | show_error_message (const char *title, | ||
258 | const char *emsg) | ||
259 | { | ||
260 | GtkWindow *main_window; | ||
261 | GtkDialog *dialog; | ||
262 | |||
263 | /* FIXME: consider replacing with widget in the main window */ | ||
264 | main_window = GTK_WINDOW (GNUNET_SETUP_get_object ("GNUNET_setup_dialog")); | ||
265 | dialog = GTK_DIALOG(gtk_message_dialog_new (main_window, | ||
266 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
267 | GTK_MESSAGE_ERROR, | ||
268 | GTK_BUTTONS_CLOSE, | ||
269 | _("%s\n%s\n"), | ||
270 | title, | ||
271 | emsg)); | ||
272 | g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); | ||
273 | gtk_widget_show_all (GTK_WIDGET(dialog)); | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Function called after we removed the old record. If the | ||
279 | * removal was successful, add the new records from the | ||
280 | * update context. | ||
250 | * | 281 | * |
282 | * @param cls the 'struct UpdateContext' | ||
283 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
284 | * GNUNET_NO if content was already there or not found | ||
285 | * GNUNET_YES (or other positive value) on success | ||
286 | * @param emsg NULL on success, otherwise an error message | ||
251 | */ | 287 | */ |
252 | static void | 288 | static void |
253 | check_name_validity_and_commit_remove_proc (void *cls, | 289 | add_new_records_after_removing_old_records (void *cls, |
254 | int32_t success, | 290 | int32_t success, |
255 | const char *emsg) | 291 | const char *emsg) |
256 | { | 292 | { |
257 | struct UpdateContext * uc = cls; | 293 | struct UpdateContext * uc = cls; |
258 | unsigned int c; | 294 | unsigned int c; |
259 | 295 | ||
260 | if ((GNUNET_OK == success) || (GNUNET_NO == success)) | 296 | switch (success) |
261 | { | ||
262 | for (c = 0; c < uc->rd_count; c++) | ||
263 | { | ||
264 | GNUNET_NAMESTORE_record_create(namestore, pkey, | ||
265 | uc->name, &uc->rd[c],NULL, NULL); | ||
266 | GNUNET_free ((void *) uc->rd[c].data); | ||
267 | } | ||
268 | GNUNET_free (uc->rd); | ||
269 | GNUNET_free (uc->name); | ||
270 | GNUNET_free (uc); | ||
271 | } | ||
272 | else if (GNUNET_SYSERR == success) | ||
273 | { | ||
274 | for (c = 0; c < uc->rd_count; c++) | ||
275 | GNUNET_free ((void *) uc->rd[c].data); | ||
276 | GNUNET_free (uc->rd); | ||
277 | GNUNET_free (uc->name); | ||
278 | GNUNET_free (uc); | ||
279 | } | ||
280 | else | ||
281 | { | 297 | { |
298 | case GNUNET_OK: | ||
299 | case GNUNET_NO: | ||
300 | for (c = 0; c < uc->rd_count; c++) | ||
301 | GNUNET_NAMESTORE_record_create (namestore, pkey, | ||
302 | uc->name, &uc->rd[c], | ||
303 | NULL, NULL); | ||
304 | break; | ||
305 | case GNUNET_SYSERR: | ||
306 | show_error_message (_("Failed to remove record"), | ||
307 | emsg); | ||
308 | break; | ||
309 | default: | ||
282 | GNUNET_break (0); | 310 | GNUNET_break (0); |
283 | GNUNET_free (uc); | 311 | break; |
284 | } | 312 | } |
313 | for (c = 0; c < uc->rd_count; c++) | ||
314 | GNUNET_free ((void *) uc->rd[c].data); | ||
315 | GNUNET_free (uc->rd); | ||
316 | GNUNET_free (uc->name); | ||
317 | GNUNET_free (uc); | ||
285 | } | 318 | } |
286 | 319 | ||
287 | 320 | ||
288 | /** | 321 | /** |
322 | * Check that the data at the given 'path' (see gtk_tree_model_get_iter_from_string) | ||
323 | * is valid and if so commit it after removing the old data. | ||
289 | * | 324 | * |
325 | * @param path path identifying the new record (FIXME: use GtkTreeIter instead!?) | ||
326 | * @param oldname name of the old record, NULL if this is a fresh name | ||
290 | */ | 327 | */ |
291 | static void | 328 | static void |
292 | check_name_validity_and_commit (gchar *path, char * oldname) | 329 | check_name_validity_and_commit (const gchar *path, const char * oldname) |
293 | { | 330 | { |
294 | GtkTreeIter it; | 331 | GtkTreeIter it; |
295 | GtkTreeIter parent; | 332 | GtkTreeIter parent; /* parent record with the 'name' */ |
296 | int records; | 333 | char * name; /* name of the records */ |
297 | int children; | 334 | struct GNUNET_NAMESTORE_RecordData *rd; |
298 | int append_pseu; | 335 | unsigned int records; /* number of records in 'rd' */ |
336 | int children; /* number of records below 'parent' */ | ||
337 | int append_pseu; /* do we need to create a '+' PSEU record? */ | ||
338 | struct UpdateContext * uc; | ||
299 | int c; | 339 | int c; |
300 | int valid = GNUNET_YES; | ||
301 | char * name; | ||
302 | void * data; | ||
303 | size_t data_size; | ||
304 | const gchar * pseu; | ||
305 | char *n_name; | ||
306 | int n_type; | ||
307 | gboolean n_public; | ||
308 | char *n_exp_color; | ||
309 | guint64 n_exp_time; | ||
310 | char *n_exp_str; | ||
311 | gboolean n_is_relative; | ||
312 | char *n_value; | ||
313 | char *n_value_color; | ||
314 | 340 | ||
315 | gtk_tree_model_get_iter_from_string(tm, &it, path); | 341 | gtk_tree_model_get_iter_from_string(tm, &it, path); |
316 | 342 | if (! gtk_tree_model_iter_parent (tm, &parent, &it)) | |
317 | if (FALSE == gtk_tree_model_iter_parent (tm, &parent, &it)) | 343 | { |
344 | if (NULL != oldname) | ||
345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
346 | "Name of existing record `%s' was changed, moving associated records\n", | ||
347 | oldname); | ||
318 | parent = it; | 348 | parent = it; |
319 | 349 | } | |
350 | gtk_tree_model_get (tm, &parent, | ||
351 | GNS_TREESTORE_COL_NAME, &name, | ||
352 | -1); | ||
320 | children = gtk_tree_model_iter_n_children (tm, &parent); | 353 | children = gtk_tree_model_iter_n_children (tm, &parent); |
321 | if (children < 1) | 354 | if (children < 1) |
322 | { | 355 | { |
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
357 | "Changed name `%s' has no associated records, not committing to namestore\n", | ||
358 | name); | ||
359 | g_free (name); | ||
323 | return; | 360 | return; |
324 | } | 361 | } |
325 | |||
326 | gtk_tree_model_get(tm, &parent, | ||
327 | GNS_TREESTORE_COL_NAME, &name, | ||
328 | -1); | ||
329 | |||
330 | if (0 == strcmp (name, ROOT_STR)) | 362 | if (0 == strcmp (name, ROOT_STR)) |
331 | { | 363 | { |
364 | /* FIXME: only if this is our 'primary' zone (not for private/shorten zones!) */ | ||
332 | /* We have to append PSEU RECORD */ | 365 | /* We have to append PSEU RECORD */ |
333 | append_pseu = GNUNET_YES; | 366 | append_pseu = GNUNET_YES; |
334 | records = children + 1; | 367 | records = children + 1; |
@@ -339,51 +372,42 @@ check_name_validity_and_commit (gchar *path, char * oldname) | |||
339 | records = children; | 372 | records = children; |
340 | } | 373 | } |
341 | 374 | ||
342 | struct GNUNET_NAMESTORE_RecordData *rd = GNUNET_malloc (records * sizeof (struct GNUNET_NAMESTORE_RecordData)); | 375 | rd = GNUNET_malloc (records * sizeof (struct GNUNET_NAMESTORE_RecordData)); |
343 | 376 | GNUNET_assert (gtk_tree_model_iter_children (tm, &it, &parent)); | |
344 | if (FALSE == gtk_tree_model_iter_children (tm, &it, &parent)) | ||
345 | return; | ||
346 | 377 | ||
347 | for (c = 0; c < children; c++) | 378 | for (c = 0; c < children; c++) |
348 | { | 379 | { |
349 | gtk_tree_model_get(tm, &it, | 380 | gchar *n_name; |
350 | GNS_TREESTORE_COL_NAME, &n_name, | 381 | gint n_type; |
351 | GNS_TREESTORE_COL_RECORD_TYPE, &n_type, | 382 | gboolean n_public; |
352 | GNS_TREESTORE_COL_IS_PUBLIC, &n_public, | 383 | guint64 n_exp_time; |
353 | GNS_TREESTORE_COL_EXP_TIME_COLOR, &n_exp_color, | 384 | gboolean n_is_relative; |
354 | GNS_TREESTORE_COL_EXP_TIME, &n_exp_time, | 385 | gchar *n_value; |
355 | GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative, | 386 | void * data; |
356 | GNS_TREESTORE_COL_EXP_TIME_AS_STR, &n_exp_str, | 387 | size_t data_size; |
357 | GNS_TREESTORE_COL_VAL_AS_STR, &n_value, | 388 | |
358 | GNS_TREESTORE_COL_VAL_COLOR, &n_value_color, | 389 | gtk_tree_model_get (tm, &it, |
359 | -1); | 390 | GNS_TREESTORE_COL_NAME, &n_name, |
360 | /* valid name */ | 391 | GNS_TREESTORE_COL_RECORD_TYPE, &n_type, |
361 | if (NULL == n_name) | 392 | GNS_TREESTORE_COL_IS_PUBLIC, &n_public, |
362 | valid = GNUNET_NO; | 393 | GNS_TREESTORE_COL_EXP_TIME, &n_exp_time, |
363 | else | 394 | GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative, |
364 | { | 395 | GNS_TREESTORE_COL_VAL_AS_STR, &n_value, |
365 | if (GNUNET_SYSERR == GNUNET_NAMESTORE_check_name (n_name)) | 396 | -1); |
366 | valid = GNUNET_NO; | 397 | if ( (NULL == n_name) || |
367 | } | 398 | (GNUNET_SYSERR == GNUNET_NAMESTORE_check_name (n_name)) || |
368 | 399 | (0 == n_type) || | |
369 | /* valid record type */ | 400 | (0 == n_exp_time) || |
370 | if (0 == n_type) | 401 | (NULL == n_value) || |
371 | valid = GNUNET_NO; | 402 | (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, &data_size)) ) |
372 | |||
373 | /* valid expiration */ | ||
374 | if ((n_exp_color != NULL) || (NULL == n_exp_str) || (0 == n_exp_time)) | ||
375 | valid = GNUNET_NO; | ||
376 | |||
377 | /* valid value */ | ||
378 | if ((n_value_color != NULL) || (NULL == n_value)) | ||
379 | valid = GNUNET_NO; | ||
380 | if (NULL != n_value) | ||
381 | { | 403 | { |
382 | if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(n_type, n_value, &data, &data_size)) | 404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
383 | valid = GNUNET_NO; | 405 | "Invalid record, skipping\n"); |
406 | records--; | ||
407 | children--; | ||
408 | c--; | ||
384 | } | 409 | } |
385 | 410 | else | |
386 | if (GNUNET_YES == valid) | ||
387 | { | 411 | { |
388 | if (FALSE == n_public) | 412 | if (FALSE == n_public) |
389 | rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE; | 413 | rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE; |
@@ -396,113 +420,114 @@ check_name_validity_and_commit (gchar *path, char * oldname) | |||
396 | memcpy ((void *) rd[c].data, data, data_size); | 420 | memcpy ((void *) rd[c].data, data, data_size); |
397 | } | 421 | } |
398 | g_free (n_name); | 422 | g_free (n_name); |
399 | g_free (n_exp_color); | ||
400 | g_free (n_exp_str); | ||
401 | g_free (n_value); | 423 | g_free (n_value); |
402 | g_free (n_value_color); | 424 | GNUNET_assert (gtk_tree_model_iter_next (tm, &it)); |
403 | |||
404 | if (FALSE == gtk_tree_model_iter_next (tm, &it)) | ||
405 | break; | ||
406 | } | 425 | } |
407 | 426 | ||
408 | if (GNUNET_NO == valid) | 427 | if (GNUNET_YES == append_pseu) |
409 | { | 428 | { |
410 | for (c = 0; c < children; c++) | 429 | GtkEntry * entry; |
411 | GNUNET_free_non_null ((void *) rd[c].data); | 430 | const gchar * pseu; |
412 | GNUNET_free_non_null (rd); | 431 | |
413 | } | 432 | /* Append PSEU record */ |
414 | else | 433 | GNUNET_assert (children == (records -1)); |
415 | { | 434 | entry = GTK_ENTRY (GNUNET_SETUP_get_object ("GNUNET_SETUP_gns_pseu_entry")); |
416 | 435 | pseu = gtk_entry_get_text (GTK_ENTRY(entry)); | |
417 | if (GNUNET_YES == append_pseu) | 436 | if ( (NULL == pseu) || |
437 | (0 == strcmp (PSEU_EMPTY_STR, pseu)) || | ||
438 | (0 == strcmp ("", pseu)) ) | ||
418 | { | 439 | { |
419 | GNUNET_assert (children == (records -1)); | 440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
420 | 441 | "No zone pseudonym given, not creating PSEU record\n"); | |
421 | /* Append PSEU record */ | 442 | records--; |
422 | GtkEntry * entry = GTK_ENTRY (GNUNET_SETUP_get_object ("GNUNET_SETUP_gns_pseu_entry")); | 443 | } |
423 | pseu = gtk_entry_get_text (GTK_ENTRY(entry)); | 444 | else |
424 | if ((NULL != pseu) && (0 != strcmp (PSEU_EMPTY_STR, pseu)) && (0 != strcmp ("", pseu))) | 445 | { |
446 | if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value (GNUNET_NAMESTORE_TYPE_PSEU, | ||
447 | pseu, | ||
448 | (void **) &rd[records - 1].data, | ||
449 | &rd[records - 1].data_size)) | ||
425 | { | 450 | { |
426 | if (GNUNET_OK != GNUNET_NAMESTORE_string_to_value(GNUNET_NAMESTORE_TYPE_PSEU, | 451 | show_error_message (_("Invalid pseudonym specified for zone"), |
427 | pseu, | 452 | pseu); |
428 | (void **) &rd[records - 1].data, | 453 | records--; |
429 | &rd[records - 1].data_size)) | ||
430 | { | ||
431 | GNUNET_break (0); | ||
432 | for (c = 0; c < records; c++) | ||
433 | GNUNET_free_non_null ((void *) rd[c].data); | ||
434 | GNUNET_free_non_null (rd); | ||
435 | } | ||
436 | rd[records - 1].record_type = GNUNET_NAMESTORE_TYPE_PSEU; | ||
437 | rd[records - 1].expiration_time = UINT64_MAX; | ||
438 | rd[records - 1].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE; | ||
439 | } | 454 | } |
440 | else | 455 | else |
441 | { | 456 | { |
442 | GNUNET_break (0); | 457 | rd[records - 1].record_type = GNUNET_NAMESTORE_TYPE_PSEU; |
458 | rd[records - 1].expiration_time = UINT64_MAX; | ||
459 | rd[records - 1].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE; | ||
443 | } | 460 | } |
444 | } | 461 | } |
445 | |||
446 | /* Remove old entries */ | ||
447 | struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext)); | ||
448 | uc->rd = rd; | ||
449 | uc->rd_count = records; | ||
450 | uc->name = strdup (name); | ||
451 | if (oldname != NULL) | ||
452 | GNUNET_NAMESTORE_record_remove (namestore, pkey, oldname, NULL, &check_name_validity_and_commit_remove_proc, uc); | ||
453 | else | ||
454 | GNUNET_NAMESTORE_record_remove (namestore, pkey, name, NULL, &check_name_validity_and_commit_remove_proc, uc); | ||
455 | g_free (name); | ||
456 | } | 462 | } |
463 | if (0 == records) | ||
464 | { | ||
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "No valid records remaining, not storing to namestore\n"); | ||
467 | GNUNET_free (rd); | ||
468 | return; | ||
469 | } | ||
470 | |||
471 | /* Store update information in context and remove old entries */ | ||
472 | uc = GNUNET_malloc (sizeof (struct UpdateContext)); | ||
473 | uc->rd = rd; | ||
474 | uc->rd_count = records; | ||
475 | uc->name = name; | ||
476 | GNUNET_NAMESTORE_record_remove (namestore, | ||
477 | pkey, | ||
478 | (NULL != oldname) ? oldname : name, | ||
479 | NULL, | ||
480 | &add_new_records_after_removing_old_records, uc); | ||
457 | } | 481 | } |
458 | 482 | ||
459 | 483 | ||
460 | /** | 484 | /** |
461 | * | 485 | * Closure for 'check_name_validity_and_remove_proc'. |
462 | */ | 486 | */ |
463 | struct Remove_Context | 487 | struct RemoveContext |
464 | { | 488 | { |
465 | 489 | ||
466 | /** | 490 | /** |
467 | * | 491 | * Path for 'gtk_tree_model_get_iter_from_string' for removing |
492 | * the record from the tree view IF the operation was successful. | ||
493 | * FIXME: replace with a 'GtkTreeIter'? | ||
468 | */ | 494 | */ |
469 | char *path; | 495 | char *path; |
470 | }; | 496 | }; |
471 | 497 | ||
472 | 498 | ||
473 | /** | 499 | /** |
500 | * We tried to remove a record from the namestore, if we were | ||
501 | * successful, also remove it from the model. | ||
474 | * | 502 | * |
503 | * @param cls the 'struct RemoveContext' | ||
504 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
505 | * GNUNET_NO if content was already there or not found | ||
506 | * GNUNET_YES (or other positive value) on success | ||
507 | * @param emsg NULL on success, otherwise an error message | ||
475 | */ | 508 | */ |
476 | static void | 509 | static void |
477 | check_name_validity_and_remove_proc (void *cls, | 510 | update_treemodel_after_remove (void *cls, |
478 | int32_t success, | 511 | int32_t success, |
479 | const char *emsg) | 512 | const char *emsg) |
480 | { | 513 | { |
481 | struct Remove_Context *rcc = cls; | 514 | struct RemoveContext *rcc = cls; |
482 | GtkDialog *dialog; | ||
483 | GtkTreeIter it; | 515 | GtkTreeIter it; |
484 | 516 | ||
485 | if (GNUNET_SYSERR == success) | 517 | switch (success) |
486 | { | ||
487 | const char * message = _("Record could not be deleted:"); | ||
488 | GtkWindow *main_window; | ||
489 | |||
490 | main_window = GTK_WINDOW (GNUNET_SETUP_get_object ("GNUNET_setup_dialog")); | ||
491 | dialog = GTK_DIALOG(gtk_message_dialog_new (main_window, | ||
492 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
493 | GTK_MESSAGE_ERROR, | ||
494 | GTK_BUTTONS_CLOSE, | ||
495 | _("%s\n%s\n"), | ||
496 | message, | ||
497 | emsg)); | ||
498 | |||
499 | g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); | ||
500 | gtk_widget_show_all (GTK_WIDGET(dialog)); | ||
501 | } | ||
502 | else | ||
503 | { | 518 | { |
519 | case GNUNET_YES: | ||
520 | case GNUNET_NO: | ||
504 | gtk_tree_model_get_iter_from_string(tm, &it, rcc->path); | 521 | gtk_tree_model_get_iter_from_string(tm, &it, rcc->path); |
505 | gtk_tree_store_remove (ts, &it); | 522 | gtk_tree_store_remove (ts, &it); |
523 | break; | ||
524 | case GNUNET_SYSERR: | ||
525 | show_error_message (_("Failed to remove record"), | ||
526 | emsg); | ||
527 | break; | ||
528 | default: | ||
529 | GNUNET_break (0); | ||
530 | break; | ||
506 | } | 531 | } |
507 | GNUNET_free (rcc->path); | 532 | GNUNET_free (rcc->path); |
508 | GNUNET_free (rcc); | 533 | GNUNET_free (rcc); |
@@ -510,7 +535,9 @@ check_name_validity_and_remove_proc (void *cls, | |||
510 | 535 | ||
511 | 536 | ||
512 | /** | 537 | /** |
513 | * | 538 | * FIXME... |
539 | * | ||
540 | * @param path | ||
514 | */ | 541 | */ |
515 | static void | 542 | static void |
516 | check_name_validity_and_remove (gchar *path) | 543 | check_name_validity_and_remove (gchar *path) |
@@ -520,7 +547,7 @@ check_name_validity_and_remove (gchar *path) | |||
520 | char *name; | 547 | char *name; |
521 | int valid = GNUNET_YES; | 548 | int valid = GNUNET_YES; |
522 | struct GNUNET_NAMESTORE_RecordData rd; | 549 | struct GNUNET_NAMESTORE_RecordData rd; |
523 | struct Remove_Context *rcc; | 550 | struct RemoveContext *rcc; |
524 | 551 | ||
525 | char *n_name; | 552 | char *n_name; |
526 | int n_type; | 553 | int n_type; |
@@ -583,9 +610,9 @@ check_name_validity_and_remove (gchar *path) | |||
583 | rd.data = GNUNET_malloc(rd.data_size); | 610 | rd.data = GNUNET_malloc(rd.data_size); |
584 | memcpy ((void *) rd.data, n_value, rd.data_size); | 611 | memcpy ((void *) rd.data, n_value, rd.data_size); |
585 | 612 | ||
586 | rcc = GNUNET_malloc(sizeof (struct Remove_Context)); | 613 | rcc = GNUNET_malloc(sizeof (struct RemoveContext)); |
587 | rcc->path = strdup (path); | 614 | rcc->path = strdup (path); |
588 | GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd, &check_name_validity_and_remove_proc, rcc); | 615 | GNUNET_NAMESTORE_record_remove (namestore, pkey, name, &rd, &update_treemodel_after_remove, rcc); |
589 | GNUNET_free ((void *) rd.data); | 616 | GNUNET_free ((void *) rd.data); |
590 | } | 617 | } |
591 | else | 618 | else |
@@ -602,9 +629,9 @@ check_name_validity_and_remove (gchar *path) | |||
602 | else if (0 != strcmp (name, ROOT_STR)) | 629 | else if (0 != strcmp (name, ROOT_STR)) |
603 | { | 630 | { |
604 | /* Removing the whole name record */ | 631 | /* Removing the whole name record */ |
605 | rcc = GNUNET_malloc(sizeof (struct Remove_Context)); | 632 | rcc = GNUNET_malloc(sizeof (struct RemoveContext)); |
606 | rcc->path = strdup (path); | 633 | rcc->path = strdup (path); |
607 | GNUNET_NAMESTORE_record_remove (namestore, pkey, name, NULL, &check_name_validity_and_remove_proc, rcc); | 634 | GNUNET_NAMESTORE_record_remove (namestore, pkey, name, NULL, &update_treemodel_after_remove, rcc); |
608 | } | 635 | } |
609 | g_free (name); | 636 | g_free (name); |
610 | } | 637 | } |
@@ -762,7 +789,9 @@ check_time (const char * text) | |||
762 | 789 | ||
763 | int count = SSCANF (text, "%02u/%02u/%04u %02u:%02u", &t_mon, &t_day, &t_year, &t_hrs, &t_min); | 790 | int count = SSCANF (text, "%02u/%02u/%04u %02u:%02u", &t_mon, &t_day, &t_year, &t_hrs, &t_min); |
764 | if ((EOF == count) || (5 != count)) | 791 | if ((EOF == count) || (5 != count)) |
792 | { | ||
765 | return GNUNET_SYSERR; | 793 | return GNUNET_SYSERR; |
794 | } | ||
766 | 795 | ||
767 | if (t_mon > 12) | 796 | if (t_mon > 12) |
768 | return GNUNET_SYSERR; | 797 | return GNUNET_SYSERR; |
@@ -802,13 +831,19 @@ convert_string_to_abs_time (const char * text) | |||
802 | 831 | ||
803 | if (GNUNET_SYSERR == check_time(text)) | 832 | if (GNUNET_SYSERR == check_time(text)) |
804 | { | 833 | { |
834 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
835 | _("Invalid time `%s'\n"), text); | ||
805 | GNUNET_break (0); | 836 | GNUNET_break (0); |
806 | return GNUNET_TIME_UNIT_ZERO_ABS; | 837 | return GNUNET_TIME_UNIT_ZERO_ABS; |
807 | } | 838 | } |
808 | 839 | ||
809 | int count = SSCANF (text, "%02d/%02d/%04d %02d:%02d", &t_mon, &t_day, &t_year, &t_hrs, &t_min); | 840 | int count = SSCANF (text, "%02d/%02d/%04d %02d:%02d", &t_mon, &t_day, &t_year, &t_hrs, &t_min); |
810 | if ((EOF == count) || (5 != count)) | 841 | if ((EOF == count) || (5 != count)) |
842 | { | ||
843 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
844 | _("Invalid time `%s', returning 0\n"), text); | ||
811 | return GNUNET_TIME_UNIT_ZERO_ABS; | 845 | return GNUNET_TIME_UNIT_ZERO_ABS; |
846 | } | ||
812 | 847 | ||
813 | time.tm_mon = (t_mon - 1); | 848 | time.tm_mon = (t_mon - 1); |
814 | time.tm_mday = t_day; | 849 | time.tm_mday = t_day; |
@@ -847,6 +882,9 @@ GNUNET_setup_gns_expiration_cellrenderertext_edited_cb (GtkCellRendererText *ren | |||
847 | 882 | ||
848 | if (NULL == new_text) | 883 | if (NULL == new_text) |
849 | return; /* can this happen? */ | 884 | return; /* can this happen? */ |
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
886 | "New expiration time: `%s'\n", | ||
887 | new_text); | ||
850 | gtk_tree_model_get_iter_from_string(tm, &it, path); | 888 | gtk_tree_model_get_iter_from_string(tm, &it, path); |
851 | gtk_tree_model_get(tm, &it, | 889 | gtk_tree_model_get(tm, &it, |
852 | GNS_TREESTORE_COL_EXP_TIME_AS_STR, &old_text, | 890 | GNS_TREESTORE_COL_EXP_TIME_AS_STR, &old_text, |
@@ -1050,14 +1088,24 @@ create_popup_menu () | |||
1050 | GtkTreeIter it; | 1088 | GtkTreeIter it; |
1051 | GtkMenu *popup; | 1089 | GtkMenu *popup; |
1052 | GtkTreeSelection * ts; | 1090 | GtkTreeSelection * ts; |
1053 | int not_dummy; | 1091 | gboolean not_dummy; |
1054 | 1092 | ||
1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1094 | "Considering creating popup menu...\n"); | ||
1055 | ts = gtk_tree_view_get_selection(tv); | 1095 | ts = gtk_tree_view_get_selection(tv); |
1056 | if (! gtk_tree_selection_get_selected (ts, &tm, &it)) | 1096 | if (! gtk_tree_selection_get_selected (ts, &tm, &it)) |
1097 | { | ||
1098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1099 | "No row selected\n"); | ||
1057 | return FALSE; | 1100 | return FALSE; |
1101 | } | ||
1058 | gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, ¬_dummy, -1); | 1102 | gtk_tree_model_get(tm, &it, GNS_TREESTORE_COL_NOT_DUMMY_ROW, ¬_dummy, -1); |
1059 | if (GNUNET_NO == not_dummy) | 1103 | if (! not_dummy) |
1104 | { | ||
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1106 | "Dummy row selected\n"); | ||
1060 | return FALSE; | 1107 | return FALSE; |
1108 | } | ||
1061 | popup = GTK_MENU (GNUNET_SETUP_get_object ("GNUNET_setup_gns_delete_popup_menu")); | 1109 | popup = GTK_MENU (GNUNET_SETUP_get_object ("GNUNET_setup_gns_delete_popup_menu")); |
1062 | gtk_widget_show_all (GTK_WIDGET(popup)); | 1110 | gtk_widget_show_all (GTK_WIDGET(popup)); |
1063 | gtk_menu_popup(popup, NULL, NULL, NULL, NULL, 0, 0); | 1111 | gtk_menu_popup(popup, NULL, NULL, NULL, NULL, 0, 0); |