head 1.7; access; symbols PETIDOMO_4_0b6:1.7 PETIDOMO_4_0b5:1.7 PETIDOMO_4_0b4:1.7 PETIDOMO_4_0b3:1.7 BEFORETHL:1.7 petidomo-2-2:1.1.1.1 petidomo:1.1.1; locks; strict; comment @ * @; 1.7 date 2001.01.19.21.21.41; author simons; state Exp; branches; next 1.6; 1.6 date 2001.01.19.08.27.49; author rse; state Exp; branches; next 1.5; 1.5 date 2001.01.18.20.30.50; author rse; state Exp; branches; next 1.4; 1.4 date 2001.01.08.20.36.19; author simons; state Exp; branches; next 1.3; 1.3 date 2000.12.15.15.48.00; author simons; state Exp; branches; next 1.2; 1.2 date 2000.12.13.15.35.14; author simons; state Exp; branches; next 1.1; 1.1 date 2000.12.13.13.19.22; author simons; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2000.12.13.13.19.22; author simons; state Exp; branches; next ; desc @@ 1.7 log @Enhanced portability. This commit also contains an older change made by Ralf, which I have to re-commit after screwing up with the "cvs admin" command. Sorry!!! @ text @/* $Source: /e/ossp/cvs/ossp-pkg/petidomo/archive.c,v $ $Revision: 1.8 $ Copyright (C) 2000 by CyberSolutions GmbH, Germany. This file is part of Petidomo. Petidomo 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 2, or (at your option) any later version. Petidomo 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. */ #include #include #include #include #include #include #include "libtext/text.h" #include "petidomo.h" int ArchiveMail(const struct Mail * MailStruct, const char * listname) { const struct List_Config * ListConfig; struct stat sb; FILE * fh; char * filename; unsigned int counter; int rc; struct tm * timeptr; char * date; time_t t; assert(MailStruct != NULL); assert(listname != NULL); /* Initialize internals. */ ListConfig = getListConfig(listname); t = time(NULL); timeptr = localtime(&t); date = asctime(timeptr); rc = -1; /* Sanity checks. */ if (ListConfig->archivepath == NULL) return 0; /* Check whether we have a file or a directory. */ if (stat(ListConfig->archivepath, &sb) == 0 && (sb.st_mode & S_IFDIR) != 0) { /* Read the "active"-file to see at what article number we were. */ filename = text_easy_sprintf("%s/.active", ListConfig->archivepath); fh = fopen(filename, "r"); if (fh != NULL) { fscanf(fh, "%u", &counter); fclose(fh); } else { if (errno != ENOENT) syslog(LOG_ERR, "Failed to read file \"%s\": %s", filename, strerror(errno)); else counter = 0; } /* Store the article. */ do { filename = text_easy_sprintf("%s/%u", ListConfig->archivepath, counter); if (stat(filename, &sb) == -1) { if (errno == ENOENT) { fh = fopen(filename, "a"); if (fh != NULL) { fprintf(fh, "From %s-owner@@%s %s", listname, ListConfig->fqdn, date); fprintf(fh, "%s\n", MailStruct->Header); fprintf(fh, "%s\n", MailStruct->Body); fclose(fh); rc = 0; } else syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %s", filename, strerror(errno)); break; } else { syslog(LOG_ERR, "An error while trying to access the log " \ "directory \"%s\": %s", ListConfig->archivepath, strerror(errno)); break; } } } while (++counter); /* until break */ /* Write the current "active" number back to the file. */ counter++; filename = text_easy_sprintf("%s/.active", ListConfig->archivepath); fh = fopen(filename, "w"); if (fh != NULL) { fprintf(fh, "%u", counter); fclose(fh); } else syslog(LOG_ERR, "Failed to write to file \"%s\": %s", filename, strerror(errno)); } else { /* Simply append the article to this file. */ fh = fopen(ListConfig->archivepath, "a"); if (fh != NULL) { /* Write an envelope first. */ fprintf(fh, "From %s-owner@@%s %s", listname, ListConfig->fqdn, date); fprintf(fh, "%s\n", MailStruct->Header); fprintf(fh, "%s\n", MailStruct->Body); fclose(fh); rc = 0; } else syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %s", ListConfig->archivepath, strerror(errno)); } return rc; } @ 1.6 log @As GCC complained: There is an ISO 9899:1990 (``ISO C'') function clock(3), so we have a symbol conflict here. Get rid of this by renaming our symbol. @ text @d3 1 a3 1 $Revision: 1.5 $ d37 1 a37 1 u_int counter; d77 1 a77 1 syslog(LOG_ERR, "Failed to read file \"%s\": %m", filename); d101 1 a101 1 syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %m", filename); d107 1 a107 1 "directory \"%s\": %m", ListConfig->archivepath); d125 1 a125 1 syslog(LOG_ERR, "Failed to write to file \"%s\": %m", filename); d144 1 a144 1 syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %m", ListConfig->archivepath); @ 1.5 log @As we agreed today, Petidomo is now open because licensed under GPL and always will be licensed under GPL, so use "Petidomo" as the program name everywhere and consistently. @ text @d3 1 a3 1 $Revision: 1.4 $ d41 1 a41 1 time_t clock; d49 2 a50 2 clock = time(NULL); timeptr = localtime(&clock); @ 1.4 log @Rewrote Petidomo so that virtually any file's path can be configured at run-time now. @ text @d2 2 a3 2 $Source: /d1/e/petidomo/cvs/petidomo/source/archive.c,v $ $Revision: 1.3 $ d7 1 a7 1 This file is part of OpenPetidomo. d9 1 a9 1 OpenPetidomo is free software; you can redistribute it and/or modify d14 1 a14 1 OpenPetidomo is distributed in the hope that it will be useful, but @ 1.3 log @ - Removed all debugging code. Now that Petidomo will be "rewritten" in C++, I need a new paradigm for debugging anyway and the old solution of mine was to messy for my taste anyway. - Petidomo no longer cares under what name it has been started. The different modes of operation will now be distinguished by a mandatory command line parameter. @ text @d3 1 a3 1 $Revision: 1.2 $ d32 1 a32 1 { a36 1 char * path; d57 1 a57 10 return 0; /* Construct the path to the log file or directory. */ if (*(ListConfig->archivepath) == '/') path = xstrdup(ListConfig->archivepath); else { path = text_easy_sprintf("lists/%s/%s", listname, ListConfig->archivepath); path = xstrdup(path); } d61 2 a62 1 if (stat(path, &sb) == 0 && (sb.st_mode & S_IFDIR) != 0) { d67 1 a67 1 filename = text_easy_sprintf("%s/.active", path); d84 7 a90 4 do { filename = text_easy_sprintf("%s/%u", path, counter); if (stat(filename, &sb) == -1) { if (errno == ENOENT) { d92 2 a93 1 if (fh != NULL) { d99 1 a99 1 } d101 1 a101 1 syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %m", filename); d103 3 a105 2 } else { d107 1 a107 1 "directory \"%s\": %m", path); d109 1 d112 1 a112 1 } while (++counter); /* until break */ d117 1 a117 1 filename = text_easy_sprintf("%s/.active", path); d119 2 a120 1 if (fh != NULL) { d123 3 d127 2 a128 4 else syslog(LOG_ERR, "Failed to write to file \"%s\": %m", filename); } else { d132 3 a134 2 fh = fopen(path, "a"); if (fh != NULL) { d142 3 a145 3 else syslog(LOG_ERR, "Failed opening file \"%s\" for writing: %m", path); } a146 1 free(path); d148 1 a148 1 } @ 1.2 log @ - Added correct GNU GPL copyright statements to the files. - Removed unnecessary include statements. @ text @d2 2 a3 2 $Source$ $Revision$ a67 1 debug((DEBUG_ARCHIVE, 2, "Our archive path is \"%s\".", path)); a72 4 /* Store the article to the current number into the directory. */ debug((DEBUG_ARCHIVE, 3, "\"%s\" is a directory.", path)); d78 2 a79 1 if (fh != NULL) { a80 1 debug((DEBUG_ARCHIVE, 5, ".active file contained '%u'.", counter)); d82 3 a84 2 } else { d86 1 a86 1 syslog(LOG_ERR, "Failed to read file \"%s\": %m", filename); d88 2 a89 3 debug((DEBUG_ARCHIVE, 1, "File \".active\" did not exist.")); counter = 0; } a94 2 debug((DEBUG_ARCHIVE, 4, "Testing whether file \"%s\" exists already.", filename)); a95 1 debug((DEBUG_ARCHIVE, 7, "Nope, it doesn't.")); a96 1 debug((DEBUG_ARCHIVE, 1, "Writing mail to file \"%s\".", filename)); a114 2 else debug((DEBUG_ARCHIVE, 7, "Yep, it does.")); a123 1 debug((DEBUG_ARCHIVE, 5, "Wrote '%u' to .active file.", counter)); a132 1 debug((DEBUG_ARCHIVE, 1, "Appending mail to logfile \"%s\".", path)); @ 1.1 log @Initial revision @ text @d2 17 a18 7 * $Source: /usr/local/libdata/cvs/simons/petidomo/src/petidomo/archive.c,v $ * $Revision: 1.9 $ * $Date: 1997/10/19 14:13:42 $ * * Copyright (C) 1996 by CyberSolutions GmbH. * All rights reserved. */ d27 2 a28 2 #include #include @ 1.1.1.1 log @Imported Petidomo 2.2 as found on www.petidomo.com. @ text @@