/* wydawca - automatic release submission daemon Copyright (C) 2009 Sergey Poznyakoff Wydawca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. Wydawca is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with wydawca. If not, see . */ #include "wydawca.h" struct virt_tab_reg { char *scheme; struct virt_tab vtab; }; static struct virt_tab_reg reg[] = { { "file", { dir_test_url, dir_move_file, dir_archive_file, dir_symlink_file, dir_rmsymlink_file } }, { "dir", { dir_test_url, dir_move_file, dir_archive_file, dir_symlink_file, dir_rmsymlink_file } }, { "null", { NULL, null_move_file, null_archive_file, null_symlink_file, null_rmsymlink_file } }, { NULL } }; int url_to_vtab (mu_url_t url, struct virt_tab *vtab) { const char *scheme; int i; if (mu_url_sget_scheme (url, &scheme)) return 1; for (i = 0; reg[i].scheme; i++) if (strcmp (reg[i].scheme, scheme) == 0) { *vtab = reg[i].vtab; return 0; } return 1; } int move_file (struct file_triplet *trp, const struct spool *spool, enum file_type file_id, const char *reldir) { int rc = spool->vtab.move_file (trp, spool, file_id, reldir); report_add ("Move %s to %s: %s", trp->file[file_id].name, reldir, rc == 0 ? "OK" : "FAILED"); return rc; } int archive_file (struct file_triplet *trp, const struct spool *spool, const char *reldir, const char *file_name) { int rc = spool->vtab.archive_file (trp, spool, reldir, file_name); report_add ("Archive and remove %s/%s: %s", reldir, file_name, rc == 0 ? "OK" : "FAILED"); return rc; } int symlink_file (struct file_triplet *trp, const struct spool *spool, const char *reldir, const char *wanted_src, const char *wanted_dst) { int rc = spool->vtab.symlink_file (trp, spool, reldir, wanted_src, wanted_dst); report_add ("Symlink %s to %s in %s/: %s", wanted_src, wanted_dst, reldir, rc == 0 ? "OK" : "FAILED"); return rc; } int rmsymlink_file (struct file_triplet *trp, const struct spool *spool, const char *reldir, const char *file_name) { int rc = spool->vtab.rmsymlink_file (trp, spool, reldir, file_name); report_add ("Remove symlink %s/%s: %s", reldir, file_name, rc == 0 ? "OK" : "FAILED"); return rc; }