/** * Handler for DELETE message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_delete_message (void *cls, const struct DeleteMessage *dm) { struct Ego *ego; const char *name; char *fn; struct GNUNET_SERVICE_Client *client = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); name = (const char *) &dm[1]; for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, name)) { GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_delete, ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); fn = get_ego_filename (ego); if (0 != UNLINK (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); GNUNET_free (ego->identifier); ego->identifier = NULL; notify_listeners (ego); GNUNET_free (ego->pk); GNUNET_free (ego); send_result_code (client, 0, NULL); GNUNET_SERVICE_client_continue (client); return; } } send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVICE_client_continue (client); }
/** * Handler for DELETE message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_IDENTITY_DeleteMessage *dm; uint16_t size; uint16_t name_len; struct Ego *ego; const char *name; char *fn; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); size = ntohs (message->size); if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } dm = (const struct GNUNET_IDENTITY_DeleteMessage *) message; name = (const char *) &dm[1]; name_len = ntohs (dm->name_len); if ( (name_len + sizeof (struct GNUNET_IDENTITY_DeleteMessage) != size) || (0 != ntohs (dm->reserved)) || ('\0' != name[name_len - 1]) ) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, name)) { GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_delete, ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); fn = get_ego_filename (ego); if (0 != UNLINK (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); GNUNET_free (ego->identifier); ego->identifier = NULL; notify_listeners (ego); GNUNET_free (ego->pk); GNUNET_free (ego); send_result_code (client, 0, NULL); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
/** * Handler for RENAME message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_IDENTITY_RenameMessage *rm; uint16_t size; uint16_t old_name_len; uint16_t new_name_len; struct Ego *ego; const char *old_name; const char *new_name; struct RenameContext rename_ctx; char *fn_old; char *fn_new; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); size = ntohs (message->size); if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } rm = (const struct GNUNET_IDENTITY_RenameMessage *) message; old_name_len = ntohs (rm->old_name_len); new_name_len = ntohs (rm->new_name_len); old_name = (const char *) &rm[1]; new_name = &old_name[old_name_len]; if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) || ('\0' != old_name[old_name_len - 1]) || ('\0' != new_name[new_name_len - 1]) ) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } /* check if new name is already in use */ for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, new_name)) { send_result_code (client, 1, gettext_noop ("target name already exists")); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } /* locate old name and, if found, perform rename */ for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, old_name)) { fn_old = get_ego_filename (ego); GNUNET_free (ego->identifier); rename_ctx.old_name = old_name; rename_ctx.new_name = new_name; GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_rename, &rename_ctx); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); ego->identifier = GNUNET_strdup (new_name); fn_new = get_ego_filename (ego); if (0 != RENAME (fn_old, fn_new)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); GNUNET_free (fn_old); GNUNET_free (fn_new); notify_listeners (ego); send_result_code (client, 0, NULL); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } /* failed to locate old name */ send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
/** * Process arm requests. * * @param cls closure * @param serv the initialized server * @param c configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *serv, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0}, {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0}, {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN, sizeof (struct GNUNET_MessageHeader)}, {&handle_list, NULL, GNUNET_MESSAGE_TYPE_ARM_LIST, sizeof (struct GNUNET_MessageHeader)}, {NULL, NULL, 0, 0} }; char *defaultservices; const char *pos; struct ServiceList *sl; cfg = c; server = serv; GNUNET_assert (serv != NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); child_death_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), &maint_child_death, NULL); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_PREFIX", &prefix_command)) prefix_command = GNUNET_strdup (""); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_POSTFIX", &final_option)) final_option = GNUNET_strdup (""); GNUNET_CONFIGURATION_iterate_sections (cfg, &setup_service, NULL); /* start default services... */ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "DEFAULTSERVICES", &defaultservices)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting default services `%s'\n"), defaultservices); if (0 < strlen (defaultservices)) { for (pos = strtok (defaultservices, " "); NULL != pos; pos = strtok (NULL, " ")) { sl = find_service (pos); if (NULL == sl) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Default service `%s' not configured correctly!\n"), pos); continue; } sl->is_default = GNUNET_YES; start_process (sl); } } GNUNET_free (defaultservices); } else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("No default services configured, GNUnet will not really start right now.\n")); } /* process client requests */ GNUNET_SERVER_add_handlers (server, handlers); }
/** * Main function that will be run by the scheduler. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param cfg configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *mycfg) { struct GNUNET_CONFIGURATION_Handle *properties; char *file; end_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); cfg = mycfg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sysdaemon starting ... \n"); if (GNUNET_SYSERR ==GNUNET_CONFIGURATION_get_value_filename (mycfg, "sysmon", "CFGFILE", &file)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sysmon configuration file not set, exit! \n"); shutdown_now(); ret = 1; return; } properties = GNUNET_CONFIGURATION_create(); if (NULL == properties) { GNUNET_break (0); shutdown_now(); ret = 1; return; } if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (properties, file)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (properties); GNUNET_free (file); ret = 1; shutdown_now(); return; } GNUNET_free (file); GNUNET_CONFIGURATION_iterate_sections (properties, &load_property, properties); GNUNET_CONFIGURATION_destroy (properties); /* Creating statistics */ stats = GNUNET_STATISTICS_create ("sysmon", mycfg); if (NULL == stats) { GNUNET_break (0); shutdown_now(); ret = 1; return; } /* load properties */ if (GNUNET_SYSERR == load_default_properties ()) { GNUNET_break (0); shutdown_now(); ret = 1; return; } /* run properties */ if (GNUNET_SYSERR == run_properties ()) { GNUNET_break (0); shutdown_now(); ret = 1; return; } }