head 1.6; access; symbols PETIDOMO_4_0b6:1.6 PETIDOMO_4_0b5:1.6 PETIDOMO_4_0b4:1.6 PETIDOMO_4_0b3:1.6 BEFORETHL:1.6 petidomo-2-2:1.1.1.1 petidomo:1.1.1; locks; strict; comment @ * @; 1.6 date 2001.01.19.13.20.34; author simons; 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.25; author simons; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2000.12.13.13.19.25; author simons; state Exp; branches; next ; desc @@ 1.6 log @Mailing list config files may now have the suffix ".config" or ".conf". Similarly, if the list config file is in a separate directory, it may be called /config or /conf. @ text @/* $Source: /e/ossp/cvs/ossp-pkg/petidomo/tool.c,v $ $Revision: 1.5 $ 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 "libtext/text.h" #include "petidomo.h" bool isSubscribed(const char * listname, const char * address, char ** listfile, char ** subscriber, bool dofuzzy) { const struct List_Config * ListConfig; struct stat sb; char * list; char * p; unsigned int len; bool rc; if (isValidListName(listname)) ListConfig = getListConfig(listname); else return FALSE; if (stat(ListConfig->address_file, &sb) != 0) return FALSE; list = loadfile(ListConfig->address_file); if (list == NULL) return FALSE; for (len = strlen(address), p = list; *p != '\0'; p = text_find_next_line(p)) { if (strncasecmp(p, address, len) == 0 && (p == list || p[-1] == '\n') && (isspace((int)p[len]) || p[len] == '\0')) { break; } } if (*p == '\0' && dofuzzy == TRUE) { address = buildFuzzyMatchAddress(address); if (address != NULL) { for (len = strlen(address), p = list; *p != '\0'; p = text_find_next_line(p)) { if (text_easy_pattern_match(p, address) == TRUE && (p == list || p[-1] == '\n')) { break; } } } } /* Save the returncode now, because p may be invalid in a few moments. */ rc = ((*p != '\0') ? TRUE : FALSE); /* Did the caller want results back? Then give them to him. */ if (listfile != NULL) { *listfile = list; if (subscriber != NULL) *subscriber = (*p != '\0') ? p : NULL; } else free(list); /* Return the result. */ return rc; } char * buildFuzzyMatchAddress(const char * address) { char * fuzzyaddress; int rc; fuzzyaddress = xmalloc(strlen(address)+16); rc = text_transform_text(fuzzyaddress, address, "([^@@]+)@@[^\\.]+\\.([^\\.]+\\..*)", "\\1@@([^\\\\.]+\\\\.)?\\2"); if (rc == TEXT_REGEX_TRANSFORM_DIDNT_MATCH) { rc = text_transform_text(fuzzyaddress, address, "([^@@]+)@@([^\\.]+\\.[^\\.]+)", "\\1@@([^\\\\.]+\\\\.)?\\2"); } switch (rc) { case TEXT_REGEX_ERROR: syslog(LOG_CRIT, "Internal error in buildFuzzyMatchAddress(): "\ "Regular expression can't be compiled."); break; case TEXT_REGEX_TRANSFORM_DIDNT_MATCH: break; case TEXT_REGEX_OK: return fuzzyaddress; default: syslog(LOG_CRIT, "Internal error: Unexpected returncode in ParseMessageIdLine()."); } free(fuzzyaddress); return NULL; } bool isValidListName(const char * listname) { struct stat sb; char * buffer; const struct PD_Config * MasterConfig = getMasterConfig(); assert(listname != NULL); if ((strchr(listname, '/') != NULL) || (strchr(listname, ':') != NULL)) return FALSE; buffer = text_easy_sprintf("%s/%s/config", MasterConfig->list_dir, listname); if (stat(buffer, &sb) != 0) { free(buffer); buffer = text_easy_sprintf("%s/%s/conf", MasterConfig->list_dir, listname); if (stat(buffer, &sb) != 0) { free(buffer); buffer = text_easy_sprintf("%s/%s.config", MasterConfig->list_dir, listname); if (stat(buffer, &sb) != 0) { free(buffer); buffer = text_easy_sprintf("%s/%s.conf", MasterConfig->list_dir, listname); if (stat(buffer, &sb) != 0) { free(buffer); return FALSE; } } } } free(buffer); return TRUE; } @ 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 $ d146 1 a146 1 buffer = text_easy_sprintf("%s/%s.config", MasterConfig->list_dir, listname); d150 11 a160 1 return FALSE; @ 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/tool.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 $ d31 2 a32 1 { a33 1 char * buffer; d37 1 a37 1 bool rc; d39 8 a46 4 buffer = text_easy_sprintf("lists/%s/list", listname); if (stat(buffer, &sb) != 0) return FALSE; list = loadfile(buffer); d48 1 a48 1 return FALSE; d50 2 a51 1 for (len = strlen(address), p = list; *p != '\0'; p = text_find_next_line(p)) { d54 2 a55 1 (isspace((int)p[len]) || p[len] == '\0')) { d57 1 a58 1 } d60 2 a61 1 if (*p == '\0' && dofuzzy == TRUE) { d63 4 a66 2 if (address != NULL) { for (len = strlen(address), p = list; *p != '\0'; p = text_find_next_line(p)) { d68 2 a69 1 (p == list || p[-1] == '\n')) { d71 1 a74 1 } d84 2 a85 1 if (listfile != NULL) { d88 2 a89 2 *subscriber = (*p != '\0') ? p : NULL; } d91 1 a91 1 free(list); d96 1 a96 1 } d132 1 a132 1 { d135 1 d142 1 a142 1 buffer = text_easy_sprintf("lists/%s", listname); d144 3 a146 5 return FALSE; /* Doesn't exist at all. */ else if ((sb.st_mode & S_IFDIR) == 0) return FALSE; /* Entry isn't a directory. */ else { buffer = text_easy_sprintf("lists/%s/config", listname); d148 7 a154 1 return FALSE; a155 2 return TRUE; } @ 1.2 log @ - Added correct GNU GPL copyright statements to the files. - Removed unnecessary include statements. @ text @d2 2 a3 2 $Source$ $Revision$ a45 3 debug((DEBUG_COMMAND, 3, "Searching for subscriber \"%s\" in list \"%s\".", address, listname)); a54 1 debug((DEBUG_COMMAND, 3, "No success, trying fuzzy matching.")); a65 8 #ifdef DEBUG if (*p != '\0') { debug((DEBUG_COMMAND, 3, "Found address: \"%s\".", p)); } else { debug((DEBUG_COMMAND, 3, "Nope, couldn't find address.")); } #endif a92 2 debug((DEBUG_COMMAND, 5, "Turning \"%s\" into a fuzzy match address.", address)); a108 1 debug((DEBUG_COMMAND, 4, "Fuzzy-match address is \"%s\".", fuzzyaddress)); a112 1 debug((DEBUG_COMMAND, 3, "No fuzzy match address could be built.")); d127 1 a127 2 if ((strchr(listname, '/') != NULL) || (strchr(listname, ':') != NULL)) { debug((DEBUG_COMMAND, 1, "listname '%s' contains a slash or colon!", listname)); a128 1 } @ 1.1 log @Initial revision @ text @d2 17 a18 7 * $Source: /usr/local/libdata/cvs/simons/petidomo/src/petidomo/tool.c,v $ * $Revision: 1.14 $ * $Date: 1998/08/14 22:54:41 $ * * Copyright (C) 1996 by CyberSolutions GmbH. * All rights reserved. */ d25 2 a26 2 #include #include d70 1 a70 1 #if DEBUG @ 1.1.1.1 log @Imported Petidomo 2.2 as found on www.petidomo.com. @ text @@