/* check target VE RATE on destination node */ int check_rate(struct string_list *rate) { int rc = 0; struct string_list_el *r; char *str, *p, *dev, *id; struct string_list iflist; struct string_list idlist; logger(LOG_DEBUG, "check rate"); string_list_init(&iflist); string_list_init(&idlist); if ((rc = read_iflist(&iflist))) return rc; if ((rc = read_idlist(&idlist))) return rc; string_list_for_each(rate, r) { /* parse rate record */ if ((str = strdup(r->s)) == NULL) return putErr(MIG_ERR_SYSTEM, MIG_MSG_SYSTEM); dev = str; if ((p = strchr(str, ':')) == NULL) { rc = putErr(MIG_ERR_RATE, "invalid rate : %s", r->s); goto cleanup; } *p = '\0'; id = p + 1; if ((p = strchr(id, ':')) == NULL) { rc = putErr(MIG_ERR_RATE, "invalid rate : %s", r->s); goto cleanup; } *p = '\0'; /* check interface */ if (strcmp(dev, "*")) { if (string_list_find(&iflist, dev) == NULL) { rc = putErr(MIG_ERR_RATE, "rate device %s not found", dev); goto cleanup; } } /* check class id */ if (strcmp(id, "*")) { if (string_list_find(&idlist, id) == NULL) { rc = putErr(MIG_ERR_RATE, "rate class %s not found", id); goto cleanup; } } cleanup: free((void *)str); if (rc) break; } string_list_clean(&idlist); string_list_clean(&iflist); return rc; }
void configuration_combine_string_lists (void *main_configuration, void *site_configuration, int tag_field_offset) { StringList *main_configuration_list = (StringList *) main_configuration; StringList *site_configuration_list = (StringList *) site_configuration; StringListItem *main_configuration_item; for (main_configuration_item = main_configuration_list->first; main_configuration_item; ) { /* Required since we may delete some items. */ StringListItem *next_main_configuration_item = main_configuration_item->next; const char *tag = * ((const char **) ((char *) main_configuration_item + tag_field_offset)); if (tag && !string_list_find (site_configuration_list, tag)) { string_list_delete_item (main_configuration_list, main_configuration_item); } main_configuration_item = next_main_configuration_item; } while (!string_list_is_empty (site_configuration_list)) { StringListItem *site_configuration_item = string_list_steal_first_item (site_configuration_list); if (site_configuration_item->text) { for (main_configuration_item = main_configuration_list->first; main_configuration_item; main_configuration_item = main_configuration_item->next) { const char *tag = * ((const char **) ((char *) main_configuration_item + tag_field_offset)); if (tag && strcmp (tag, site_configuration_item->text) == 0) break; } if (!main_configuration_item) { * ((char **) ((char *) site_configuration_item + tag_field_offset)) = utils_duplicate_string (site_configuration_item->text); string_list_add_ready_item (main_configuration_list, site_configuration_item); continue; } } string_list_dispose_item (site_configuration_list, site_configuration_item); } }
/* * Internal function for `unzip_book'. * This is used to compress an EPWING book. */ static int ebzip_unzip_book_epwing(EB_Book *book, const char *out_top_path, const char *book_path, EB_Subbook_Code *subbook_list, int subbook_count) { EB_Subbook *subbook; EB_Error_Code error_code; EB_Font *font; String_List string_list; char in_path_name[PATH_MAX + 1]; char out_sub_path[PATH_MAX + 1]; char out_path_name[PATH_MAX + 1]; char catalogs_file_name[EB_MAX_FILE_NAME_LENGTH]; mode_t out_directory_mode; Zio_Code in_zio_code; int i, j; /* * If `out_top_path' and/or `book_path' represents "/", replace it * to an empty string. */ if (strcmp(out_top_path, "/") == 0) out_top_path++; if (strcmp(book_path, "/") == 0) book_path++; /* * Initialize variables. */ out_directory_mode = 0777 ^ get_umask(); string_list_initialize(&string_list); error_code = eb_load_all_subbooks(book); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code)); } /* * Uncompress a book. */ for (i = 0; i < subbook_count; i++) { subbook = book->subbooks + subbook_list[i]; /* * Make an output directory for the current subbook. */ eb_compose_path_name(out_top_path, subbook->directory_name, out_sub_path); if (!ebzip_test_flag && make_missing_directory(out_sub_path, out_directory_mode) < 0) { fprintf(stderr, _("%s: failed to create a directory, %s: %s\n"), invoked_name, strerror(errno), out_sub_path); goto failed; } /* * Make `data' sub directory for the current subbook. */ eb_compose_path_name2(out_top_path, subbook->directory_name, subbook->data_directory_name, out_sub_path); if (!ebzip_test_flag && make_missing_directory(out_sub_path, out_directory_mode) < 0) { fprintf(stderr, _("%s: failed to create a directory, %s: %s\n"), invoked_name, strerror(errno), out_sub_path); goto failed; } /* * Uncompress HONMON/HONMON2 file. */ in_zio_code = zio_mode(&subbook->text_zio); eb_compose_path_name3(book->path, subbook->directory_name, subbook->data_directory_name, subbook->text_file_name, in_path_name); eb_compose_path_name3(out_top_path, subbook->directory_name, subbook->data_directory_name, subbook->text_file_name, out_path_name); if (in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (strncasecmp(subbook->text_file_name, "honmon2", 7) == 0) eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_ORG); else eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; string_list_add(&string_list, in_path_name); } /* * Uncompress HONMONS file. */ in_zio_code = zio_mode(&subbook->sound_zio); eb_compose_path_name3(book->path, subbook->directory_name, subbook->data_directory_name, subbook->sound_file_name, in_path_name); eb_compose_path_name3(out_top_path, subbook->directory_name, subbook->data_directory_name, subbook->sound_file_name, out_path_name); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (!ebzip_skip_flag_sound && in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; string_list_add(&string_list, in_path_name); } /* * Uncompress HONMONG file. */ in_zio_code = zio_mode(&subbook->graphic_zio); eb_compose_path_name3(book->path, subbook->directory_name, subbook->data_directory_name, subbook->graphic_file_name, in_path_name); eb_compose_path_name3(out_top_path, subbook->directory_name, subbook->data_directory_name, subbook->graphic_file_name, out_path_name); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (!ebzip_skip_flag_graphic && in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; string_list_add(&string_list, in_path_name); } /* * Make `gaiji' sub directory for the current subbook. */ if (!ebzip_skip_flag_font) { eb_compose_path_name2(out_top_path, subbook->directory_name, subbook->gaiji_directory_name, out_sub_path); if (!ebzip_test_flag && make_missing_directory(out_sub_path, out_directory_mode) < 0) { fprintf(stderr, _("%s: failed to create a directory, %s: %s\n"), invoked_name, strerror(errno), out_sub_path); goto failed; } /* * Uncompress narrow font files. */ for (j = 0; j < EB_MAX_FONTS; j++) { font = subbook->narrow_fonts + j; if (font->font_code == EB_FONT_INVALID) continue; in_zio_code = zio_mode(&font->zio); eb_compose_path_name3(book->path, subbook->directory_name, subbook->gaiji_directory_name, font->file_name, in_path_name); eb_compose_path_name3(out_top_path, subbook->directory_name, subbook->gaiji_directory_name, font->file_name, out_path_name); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; string_list_add(&string_list, in_path_name); } } /* * Uncompress wide font files. */ for (j = 0; j < EB_MAX_FONTS; j++) { font = subbook->wide_fonts + j; if (font->font_code == EB_FONT_INVALID) continue; in_zio_code = zio_mode(&font->zio); eb_compose_path_name3(book->path, subbook->directory_name, subbook->gaiji_directory_name, font->file_name, in_path_name); eb_compose_path_name3(out_top_path, subbook->directory_name, subbook->gaiji_directory_name, font->file_name, out_path_name); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; string_list_add(&string_list, in_path_name); } } } /* * Copy movie files. */ if (!ebzip_skip_flag_movie) { eb_compose_path_name2(book->path, subbook->directory_name, subbook->movie_directory_name, in_path_name); eb_compose_path_name2(out_top_path, subbook->directory_name, subbook->movie_directory_name, out_path_name); if (ebzip_copy_files_in_directory(out_path_name, in_path_name) < 0) goto failed; } } /* * Copy CATALOGS file. */ if (eb_find_file_name(book->path, "catalogs", catalogs_file_name) == EB_SUCCESS) { eb_compose_path_name(book->path, catalogs_file_name, in_path_name); eb_compose_path_name(out_top_path, catalogs_file_name, out_path_name); if (ebzip_copy_file(out_path_name, in_path_name) < 0) goto failed; } string_list_finalize(&string_list); return 0; /* * An error occurs... */ failed: string_list_finalize(&string_list); return -1; }
/* * Internal function for `unzip_book'. * This is used to compress an EB book. */ static int ebzip_unzip_book_eb(EB_Book *book, const char *out_top_path, const char *book_path, EB_Subbook_Code *subbook_list, int subbook_count) { EB_Subbook *subbook; EB_Error_Code error_code; String_List string_list; char in_path_name[PATH_MAX + 1]; char out_sub_path[PATH_MAX + 1]; char out_path_name[PATH_MAX + 1]; char catalog_file_name[EB_MAX_FILE_NAME_LENGTH]; char language_file_name[EB_MAX_FILE_NAME_LENGTH]; mode_t out_directory_mode; Zio_Code in_zio_code; int i; /* * If `out_top_path' and/or `book_path' represents "/", replace it * to an empty string. */ if (strcmp(out_top_path, "/") == 0) out_top_path++; if (strcmp(book_path, "/") == 0) book_path++; /* * Initialize variables. */ out_directory_mode = 0777 ^ get_umask(); string_list_initialize(&string_list); error_code = eb_load_all_subbooks(book); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code)); } /* * Uncompress a book. */ for (i = 0; i < subbook_count; i++) { subbook = book->subbooks + subbook_list[i]; /* * Make an output directory for the current subbook. */ eb_compose_path_name(out_top_path, subbook->directory_name, out_sub_path); if (!ebzip_test_flag && make_missing_directory(out_sub_path, out_directory_mode) < 0) { fprintf(stderr, _("%s: failed to create a directory, %s: %s\n"), invoked_name, strerror(errno), out_sub_path); goto failed; } /* * Uncompress START file. */ in_zio_code = zio_mode(&subbook->text_zio); eb_compose_path_name2(book->path, subbook->directory_name, subbook->text_file_name, in_path_name); eb_compose_path_name2(out_top_path, subbook->directory_name, subbook->text_file_name, out_path_name); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (in_zio_code != ZIO_INVALID && !string_list_find(&string_list, in_path_name)) { if (ebzip_unzip_start_file(out_path_name, in_path_name, in_zio_code, subbook->index_page) < 0) goto failed; } if (!ebzip_test_flag && rewrite_sebxa_start(out_path_name, subbook->index_page) < 0) goto failed; string_list_add(&string_list, in_path_name); } /* * Uncompress a language file. */ if (eb_find_file_name(book->path, "language", language_file_name) == EB_SUCCESS) { eb_compose_path_name(book->path, language_file_name, in_path_name); eb_compose_path_name(out_top_path, language_file_name, out_path_name); eb_path_name_zio_code(in_path_name, ZIO_PLAIN, &in_zio_code); eb_fix_path_name_suffix(out_path_name, EBZIP_SUFFIX_NONE); if (ebzip_unzip_file(out_path_name, in_path_name, in_zio_code) < 0) goto failed; } /* * Copy CATALOG file. */ if (eb_find_file_name(book->path, "catalog", catalog_file_name) == EB_SUCCESS) { eb_compose_path_name(book->path, catalog_file_name, in_path_name); eb_compose_path_name(out_top_path, catalog_file_name, out_path_name); if (ebzip_copy_file(out_path_name, in_path_name) < 0) goto failed; } string_list_finalize(&string_list); return 0; /* * An error occurs... */ failed: string_list_finalize(&string_list); return -1; }