From: Amos Jeffries Date: Fri, 27 Oct 2023 07:47:26 +0000 (+0000) Subject: Remove tool 'purge' for management of UFS/AUFS/DiskD caches (#1541) X-Git-Tag: SQUID_7_0_1~314 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f47406cb096846b661060a81a3ab3b45b9250416;p=thirdparty%2Fsquid.git Remove tool 'purge' for management of UFS/AUFS/DiskD caches (#1541) --- diff --git a/CREDITS b/CREDITS index 09c51d13d3..cd2e4cdb22 100644 --- a/CREDITS +++ b/CREDITS @@ -1765,139 +1765,6 @@ tools/helper-mux.pl: ============================================================================== -tools/purge/conffile.cc, -tools/purge/conffile.hh - -// Author: Jens-S. V?ckler - -// (c) 2000 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. - -============================================================================== - -tools/purge/convert.cc, -tools/purge/convert.hh - -// Author: Jens-S. V?ckler - -// (c) 1997 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. - -============================================================================== - -tools/purge/copyout.cc, -tools/purge/copyout.hh, -tools/purge/purge.cc, -tools/purge/squid-tlv.cc, -tools/purge/squid-tlv.hh - -// Author: Jens-S. V?ckler - -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. - -============================================================================== - -tools/purge/signal.cc, -tools/purge/signal.hh, -tools/purge/socket.cc, -tools/purge/socket.hh - -// Author: Jens-S. V?ckler - -// (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. - -============================================================================== - shm_portable_segment_name_is_path() implementation: Derived from boost/interprocess/shared_memory_object.hpp and diff --git a/configure.ac b/configure.ac index 77e0790404..389206c8bc 100644 --- a/configure.ac +++ b/configure.ac @@ -3091,7 +3091,6 @@ AC_CONFIG_FILES([ tools/Makefile tools/apparmor/Makefile tools/helper-mux/Makefile - tools/purge/Makefile tools/systemd/Makefile tools/sysvinit/Makefile ]) diff --git a/doc/release-notes/release-7.sgml.in b/doc/release-notes/release-7.sgml.in index e37da79ca5..60e43ba786 100644 --- a/doc/release-notes/release-7.sgml.in +++ b/doc/release-notes/release-7.sgml.in @@ -32,6 +32,7 @@ The Squid-@SQUID_RELEASE@ change history can be +Removed purge tool +

The purge tool (also known as squidpurge, and squid-purge) + was limited to managing UFS/AUFS/DiskD caches and had problems parsing non-trivial squid.conf files. + +

The cache contents display and search it provided can be obtained with a script + searching the cache manager objects report. + +

This tool used the custom PURGE HTTP method to remove cache + objects. This can be performed directly on any Squid configured to allow + the method. Like so: + + acl PURGE method PURGE + http_access allow localhost PURGE + + Any HTTP client (such as curl) can then be used to evict objects from the cache, for example: + + curl -XPURGE --proxy http://127.0.0.1:3128 http://url.to/evict/ + + Alternatively the HTCP CLR mechanism can be used. + + Changes to squid.conf since Squid-@SQUID_RELEASE_OLD@

This section gives an account of those changes in three categories: diff --git a/po4a.conf b/po4a.conf index 29a64ff776..a94d575b9c 100644 --- a/po4a.conf +++ b/po4a.conf @@ -47,5 +47,3 @@ [type: man] src/squid.8.in $lang:doc/manuals/$lang/squid.8.in [type: man] tools/cachemgr.cgi.8.in $lang:doc/manuals/$lang/cachemgr.cgi.8.in - -[type: man] tools/purge/purge.1 $lang:doc/manuals/$lang/purge.1 diff --git a/tools/Makefile.am b/tools/Makefile.am index e17d23a91d..e1cc645684 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -10,7 +10,7 @@ include $(top_srcdir)/src/Common.am ## we need our local files too (but avoid -I. at all costs) AM_CPPFLAGS += -I$(srcdir) -SUBDIRS= apparmor helper-mux purge systemd sysvinit +SUBDIRS= apparmor helper-mux systemd sysvinit EXTRA_DIST= man_MANS= DISTCLEANFILES= diff --git a/tools/purge/Makefile.am b/tools/purge/Makefile.am deleted file mode 100644 index e53e4d2df5..0000000000 --- a/tools/purge/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -## Copyright (C) 1996-2023 The Squid Software Foundation and contributors -## -## Squid software is distributed under GPLv2+ license and includes -## contributions from numerous individuals and organizations. -## Please see the COPYING and CONTRIBUTORS files for details. -## - -include $(top_srcdir)/src/Common.am - -if !ENABLE_WIN32SPECIFIC -bin_PROGRAMS = purge -man_MANS = purge.1 -endif - -purge_SOURCES = \ - conffile.cc \ - conffile.hh \ - convert.cc \ - convert.hh \ - copyout.cc \ - copyout.hh \ - purge.cc \ - signal.cc \ - signal.hh \ - socket.cc \ - socket.hh \ - squid-tlv.cc \ - squid-tlv.hh - -purge_LDADD = \ - $(COMPAT_LIB) \ - $(XTRA_LIBS) - -EXTRA_DIST = purge.1 diff --git a/tools/purge/conffile.cc b/tools/purge/conffile.cc deleted file mode 100644 index 48cd95cf90..0000000000 --- a/tools/purge/conffile.cc +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: conffile.cc -// Fri Sep 15 2000 -// -// (c) 2000 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.1 2000/09/21 09:44:53 voeckler -// Initial revision -// - -#include "squid.h" -#include "conffile.hh" - -#include -#include -#include -#include -#include - -#if HAVE_REGEX_H -#include -#endif - -#include - -int -readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug ) -// purpose: read squid.conf file and extract cache_dir entries -// paramtr: cachedir (OUT): vector with an entry for each cache_dir found -// fn (IN): file name of squid.conf to use -// returns: number of entries, or negative to warn of errors -{ - static const char* expression = - "^[ \t]*cache_dir([ \t]+([[:alpha:]]+))?[ \t]+([[:graph:]]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)"; - - // try to open file - if ( debug ) fprintf( debug, "# trying to open %s\n", fn ? fn : "(null)" ); - std::ifstream cfgin(fn); - if (!cfgin) { - fprintf( stderr, "fopen %s: %s\n", fn, strerror(errno) ); - return -1; - } - - // prepare regular expression for matching - if ( debug ) fprintf( debug, "# trying to compile \"%s\"\n", expression ); - regex_t rexp; - int result = regcomp( &rexp, expression, REG_EXTENDED ); - if ( result != 0 ) { - char buffer[256]; - regerror( result, &rexp, buffer, sizeof(buffer) ); - fprintf( stderr, "regular expression \"%s\": %s\n", expression, buffer ); - return -1; - } - - // read line by line - if ( debug ) fputs( "# trying to read lines\n", debug ); - - regmatch_t subs[8]; - char *s, line[1024]; - CacheDir cd; - while ( cfgin.getline( line, sizeof(line)) ) { - // TODO: overly long lines - - // terminate line at start of comment - if ( (s = (char*) memchr( line, '#', sizeof(line) )) ) *s = '\0'; - - // quick skip - if ( *line == '\0' || *line == '\n' ) continue; - - // test line - if ( (result=regexec( &rexp, line, 7, subs, 0 )) != 0 ) { - // error or no match - if ( result != REG_NOMATCH ) { - char buffer[256]; - regerror( result, &rexp, buffer, sizeof(buffer) ); - fprintf( stderr, "while matching \"%s\" against %s%s\n", - expression, line, buffer ); - regfree(&rexp); - cfgin.close(); - return -1; - } - } else { - // match, please record - memset( &cd, 0, sizeof(cd) ); - if ( debug ) fprintf( debug, "# match from %d-%d on line %s", - (int)subs[0].rm_so, (int)subs[0].rm_eo, - line ); - - // terminate line after matched expression - line[ subs[0].rm_eo ] = '\0'; - - // extract information. If 6th parenthesis is filled, this is - // a new squid with disk types, otherwise it is an older version - int offset = 2; - if ( subs[6].rm_so == -1 ) { - // old version, disk type at position 2 is always UFS - cd.type = CacheDir::CDT_UFS; - } else { - // new version, disk type at position 2 - line[ subs[offset].rm_eo ] = '\0'; - if ( debug ) fprintf( debug, "# match from %d-%d on \"%s\"\n", - (int)subs[offset].rm_so, - (int)subs[offset].rm_eo, - line+subs[offset].rm_so ); - if ( strcmp( line + subs[offset].rm_so, "ufs" ) == 0 ) - cd.type = CacheDir::CDT_UFS; - else if ( strcmp( line + subs[offset].rm_so, "asyncufs" ) == 0 ) - cd.type = CacheDir::CDT_AUFS; - else if ( strcmp( line + subs[offset].rm_so, "diskd" ) == 0 ) - cd.type = CacheDir::CDT_DISKD; - else - cd.type = CacheDir::CDT_OTHER; - ++offset; - } - - // extract base directory - line[ subs[offset].rm_eo ] = '\0'; - if ( debug ) fprintf( debug, "# match from %d-%d on \"%s\"\n", - (int)subs[offset].rm_so, - (int)subs[offset].rm_eo, - line+subs[offset].rm_so ); - cd.base = xstrdup( line+subs[offset].rm_so ); - ++offset; - - // extract size information - line[ subs[offset].rm_eo ] = '\0'; - if ( debug ) fprintf( debug, "# match from %d-%d on \"%s\"\n", - (int)subs[offset].rm_so, - (int)subs[offset].rm_eo, - line+subs[offset].rm_so ); - cd.size = strtoul( line+subs[offset].rm_so, nullptr, 10 ); - ++offset; - - // extract 1st level directories - line[ subs[offset].rm_eo ] = '\0'; - if ( debug ) fprintf( debug, "# match from %d-%d on \"%s\"\n", - (int)subs[offset].rm_so, - (int)subs[offset].rm_eo, - line+subs[offset].rm_so ); - cd.level[0] = strtoul( line+subs[offset].rm_so, nullptr, 10 ); - ++offset; - - // extract 2nd level directories - line[ subs[offset].rm_eo ] = '\0'; - if ( debug ) fprintf( debug, "# match from %d-%d on \"%s\"\n", - (int)subs[offset].rm_so, - (int)subs[offset].rm_eo, - line+subs[offset].rm_so ); - cd.level[1] = strtoul( line+subs[offset].rm_so, nullptr, 10 ); - ++offset; - - cachedir.push_back( cd ); - } - } - - cfgin.close(); - regfree(&rexp); - return cachedir.size(); -} - diff --git a/tools/purge/conffile.hh b/tools/purge/conffile.hh deleted file mode 100644 index 06794ea3db..0000000000 --- a/tools/purge/conffile.hh +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: conffile.hh -// Fri Sep 15 2000 -// -// (c) 2000 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.2 2000/09/21 10:17:17 cached -// namespace std:: needed for Sun WS compiler. -// -// Revision 1.1 2000/09/21 09:45:14 voeckler -// Initial revision -// -// -#ifndef _CONFFILE_HH -#define _CONFFILE_HH - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL -typedef int bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -#include - -struct CacheDir { - enum CacheDirType { CDT_NONE, CDT_UFS, CDT_AUFS, CDT_DISKD, CDT_OTHER }; - - const char* base; - CacheDirType type; - size_t size; - unsigned level[2]; -}; - -typedef std::vector CacheDirVector; - -int -readConfigFile( CacheDirVector& cachedir, - const char* fn, - FILE* debug = nullptr ); - // purpose: read squid.conf file and extract cache_dir entries - // paramtr: cachedir (OUT): vector with an entry for each cache_dir found - // fn (IN): file name of squid.conf to use - // debug (IO): if not null, place debug information there - // returns: number of entries, or negative to warn of errors - -#endif // _CONFFILE_HH diff --git a/tools/purge/convert.cc b/tools/purge/convert.cc deleted file mode 100644 index 2f22128283..0000000000 --- a/tools/purge/convert.cc +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: convert.cc -// Thu Oct 30 1997 -// -// (c) 1997 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.3 2000/06/20 09:43:01 voeckler -// added FreeBSD related fixes and support. -// -// Revision 1.2 1999/01/19 11:00:50 voeckler -// Linux glibc2 fixes for sockets. -// -// Revision 1.1 1998/08/13 21:38:04 voeckler -// Initial revision -// - -#include "squid.h" -#include "convert.hh" - -#include -#include -#include -#include -#include - -#ifndef SA -#define SA struct sockaddr -#endif - -const char* -my_inet_ntoa( const struct in_addr& a, HostAddress output ) -// purpose: thread-safely convert IPv4 address -> ASCII representation -// paramtr: a (IN): networked representation of IPv4 address -// buffer (OUT): storage area to store representation into. -// returns: pointer to buffer -// goodies: INADDR_ANY will be converted to "*" -{ - if ( a.s_addr == ntohl(INADDR_ANY) ) { - // 'default' or '*' or ... - output[0] = '*'; - output[1] = '\0'; - } else { - // ANSI C++ forbids casting to an array type, nag, nag, nag... - unsigned char s[sizeof(a.s_addr)]; - memcpy( s, &a.s_addr, sizeof(a.s_addr) ); - - snprintf(output, sizeof(HostAddress), "%d.%d.%d.%d", s[0], s[1], s[2], s[3] ); - } - return output; -} - -const char* -my_sock_ntoa( const struct sockaddr_in& a, SockAddress buffer ) -// purpose: thread-safely convert IPv4 socket pair into ASCII rep. -// paramtr: a (IN): sockaddr_in address -// buffer (OUT): storage area to store representation into. -// returns: pointer to buffer -{ - HostAddress host; - snprintf( buffer, sizeof(SockAddress), "%s:%u", - my_inet_ntoa(a.sin_addr,host), ntohs(a.sin_port) ); - return buffer; -} - -const char* -my_sock_fd2a( int fd, SockAddress buffer, bool peer ) -// purpose: thread-safely convert IPv4 socket FD associated address -// to ASCII representation -// paramtr: fd (IN): open socket FD -// buffer (OUT): storage area -// peer (IN): true, use peer (remote) socket pair -// false, use own (local) socket pair -// returns: NULL in case of error, or pointer to buffer otherwise -// Refer to errno in case of error (usually unconnected fd...) -{ - struct sockaddr_in socket; - socklen_t len = sizeof(socket); - - if ( (peer ? getpeername( fd, (SA*) &socket, &len ) : - getsockname( fd, (SA*) &socket, &len )) == -1 ) - return nullptr; - else - return my_sock_ntoa( socket, buffer ); -} - -int -convertHostname( const char* host, in_addr& dst ) -// purpose: convert a numeric or symbolic hostname -// paramtr: host (IN): host description to convert -// dst (OUT): the internet address in network byteorder. -// returns: -1 in case of error, see h_errno; 0 otherwise. -{ - if ( host == nullptr ) return -1; - unsigned long int h = inet_addr(host); - if ( h == 0xFFFFFFFF && strncmp(host,"255.255.255.255",15) != 0 ) { - // symbolic host - struct hostent* dns = gethostbyname(host); - if ( dns == nullptr ) return -1; - else memcpy( &dst.s_addr, dns->h_addr, dns->h_length ); - } else { - // numeric host - dst.s_addr = h; - } - return 0; -} - -int -convertPortname( const char* port, unsigned short& dst ) -// purpose: convert a numeric or symbolic port number -// paramtr: port (IN): port description to convert -// dst (OUT): port number in network byteorder. -// returns: -1 in case of error, see errno; 0 otherwise. -{ - int p = strtoul(port,nullptr,0); - - if ( p == 0 ) { - // symbolic port - struct servent* proto = getservbyname( port, "tcp" ); - if ( proto == nullptr ) return -1; - else dst = proto->s_port; - } else { - // numeric port - dst = htons(p); - } - return 0; -} - diff --git a/tools/purge/convert.hh b/tools/purge/convert.hh deleted file mode 100644 index 2afc04b68a..0000000000 --- a/tools/purge/convert.hh +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: convert.hh -// Thu Oct 30 1997 -// -// (c) 1997 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.2 1999/01/19 11:00:50 voeckler -// added bool type workaround. -// -// Revision 1.1 1998/08/13 21:38:04 voeckler -// Initial revision -// -// -#ifndef _CONVERT_HH -#define _CONVERT_HH - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL 1 -typedef char bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -#include -#include - -typedef char HostAddress[16]; // strlen("xxx.xxx.xxx.xxx\0") <= 16 -typedef char SockAddress[24]; // strlen("xxx.xxx.xxx.xxx:xxxxx\0" ) < 24 - -const char* -my_inet_ntoa( const struct in_addr& a, HostAddress buffer ); - // purpose: thread-safely convert IPv4 address -> ASCII representation - // paramtr: a (IN): networked representation of IPv4 address - // buffer (OUT): storage area to store representation into. - // returns: pointer to buffer - // goodies: INADDR_ANY will be converted to "*" - -const char* -my_sock_ntoa( const struct sockaddr_in& a, SockAddress buffer ); - // purpose: thread-safely convert IPv4 socket pair into ASCII rep. - // paramtr: a (IN): socket_in address - // buffer (OUT): storage area to store representation into. - // returns: pointer to buffer - -const char* -my_sock_fd2a( int fd, SockAddress buffer, bool peer = true ); - // purpose: thread-safely convert IPv4 socket FD associated address - // to ASCII representation - // paramtr: fd (IN): open socket FD - // buffer (OUT): storage area - // peer (IN): true, use peer (remote) socket pair - // false, use own (local) socket pair - // returns: NULL in case of error, or pointer to buffer otherwise - // Refer to errno in case of error (usually unconnected fd...) - -int -convertHostname( const char* host, struct in_addr& dst ); - // purpose: convert a numeric or symbolic hostname - // paramtr: host (IN): host description to convert - // dst (OUT): the internet address in network byteorder. - // returns: -1 in case of error, see h_errno; 0 otherwise. - -int -convertPortname( const char* port, unsigned short& dst ); - // purpose: convert a numeric or symbolic port number - // paramtr: port (IN): port description to convert - // dst (OUT): port number in network byteorder. - // returns: -1 in case of error, see errno; 0 otherwise. - -#endif // _CONVERT_HH diff --git a/tools/purge/copyout.cc b/tools/purge/copyout.cc deleted file mode 100644 index 5b5748fd89..0000000000 --- a/tools/purge/copyout.cc +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: copyout.cc -// Tue Jun 15 1999 -// -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.2 1999/06/16 13:05:26 voeckler -// mmap file copying on Solaris. -// -// Revision 1.1 1999/06/15 21:10:47 voeckler -// Initial revision -// -// -#include "squid.h" -#include "copyout.hh" - -#include -#include -#include -#include -#include -#include - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif // MAP_FILE - -int -assert_copydir( const char* copydir ) -// purpose: check, if copydir is a directory and that we can write into it. -// paramtr: copydir (IN): name of directory for copying bodies. -// returns: 0 if ok, -1 otherwise. -// further: errors are handled within. If the directory does not exist, -// the assertion function will try to create it. -{ - struct stat st; - int status = stat( copydir, &st ); - - // check, if either "copydir" points to a valid directory, - // or if copydir can be created. - if ( status == 0 && ! S_ISDIR(st.st_mode) ) { - // stat() returned true, but did not point to a directory - fprintf( stderr, "copy dir \"%s\" is a file!\n", copydir ); - return -1; - } else if ( S_ISDIR(st.st_mode) && - !( (st.st_uid == geteuid() && ( (st.st_mode & S_IWUSR) > 0 )) || - (st.st_gid == getegid() && ( (st.st_mode & S_IWGRP) > 0 )) || - ((st.st_mode & S_IWOTH) > 0) ) ) { - fprintf( stderr, "copy dir \"%s\" is not accessible to me\n", copydir ); - return -1; - } - if ( status == -1 ) { - // stat() returned with an error. 'File not found' is a legal error. - if ( errno != ENOENT ) { - // not a 'file not found' error, so this is hard error. - fprintf( stderr, "accessing copy-out dir \"%s\": %s\n", - copydir, strerror(errno) ); - return -1; - } else { - // directory does not exist. Try to create it. - if ( mkdir( copydir, 0750 ) == -1 ) { - fprintf( stderr, "mkdir(%s): %s\n", copydir, strerror(errno) ); - return -1; - } - } - } - - // postcondition: copydir exists and is a directory. - return 0; -} - -inline -unsigned -xlate( char ch ) -{ - if ( ch == '\r' ) return 0u; - else if ( ch == '\n' ) return 1u; - else return 2u; -} - -// shortcut for monotoneous typings... -#define BAUTZ(x) delete[] filename; close(input); close(out); return (x) - -bool -copy_out( size_t filesize, size_t metasize, unsigned debug, - const char* fn, const char* url, const char* copydir, - bool copyHdr ) -// purpose: copy content from squid disk file into separate file -// paramtr: metasize (IN): size of metadata to skip -// fn (IN): current filename of squid disk file -// url (IN): currently looked at URL to generate separate file -// copydir (IN): base directory where to generate the file -// copyHdr (IN): copy HTTP header, too, if set to true. -// returns: true, if successful, false otherwise. -{ - static const char* index = "index.html"; - - // find hostname part after the scheme (okok, not counting port, etc.) - const char* ptr = strstr( url, "://" ); - if ( ptr == nullptr || strlen(ptr) < 4 ) return false; - - // create filename to store contents into - // NP: magic extra 5 bytes for the component delimiter and termination octets - char *filename = new char[ strlen(ptr) + strlen(copydir) + strlen(index) +5 ]; - assert( filename != nullptr ); - strcpy( filename, copydir ); - strcat( filename, "/" ); - char* here = filename + strlen(filename); - strcat( filename, ptr+3 ); - - // handle server root (e.g. "http://www.focus.de" ) - if ( strchr( ptr+3, '/' ) == nullptr ) strcat( filename, "/" ); - - // handle directories (e.g. "http://www.focus.de/A/" ) - if ( filename[strlen(filename)-1] == '/' ) strcat( filename, index ); - - // create subdirectory structure - for ( char* t = strchr(here,'/'); t; t = strchr(t,'/') ) { - *t = 0; - if ( mkdir( filename, 0775 ) == -1 && errno != EEXIST ) { - fprintf( stderr, "mkdir(%s): %s\n", filename, strerror(errno) ); - delete[] filename; - return false; - } else if ( debug & 0x02 ) { - fprintf( stderr, "# creating %s\n", filename ); - } - *t = '/'; - ++t; - } - - // create file - int out = open( filename, O_CREAT | O_RDWR | O_TRUNC, 0664 ); - if ( out == -1 ) { - fprintf( stderr, "open(%s,RDWR): %s\n", filename, strerror(errno) ); - delete[] filename; - return false; - } else if ( debug & 0x02 ) { - fprintf( stderr, "# creating %s\n", filename ); - } - - // (re)open cache file - int input = open( fn, O_RDONLY ); - if ( input == -1 ) { - fprintf( stderr, "open(%s,RDONLY): %s\n", fn, strerror(errno) ); - delete[] filename; - close(out); - return false; - } - - // find double CRLF sequence (actually, look at the FSM below) - // XXX: this only looks at the already known buffer read previously, - // which is globally passed (yuck)! As a limitation, the content data - // *must* begin within the buffer size (that is: 16k)! - if ( ! copyHdr ) { - extern char* linebuffer; // import from purge.cc - extern size_t buffersize; // import from purge.cc - - unsigned state = 0; - char* s = linebuffer + metasize; - while ( s < linebuffer + buffersize && state < 4 ) { - // state transition machine - static unsigned table[4][3] = { {3,2,0}, {0,4,0}, {1,4,0}, {4,2,0} }; - // old || \r | \n |else| - // =====++====+====+====+ - // 0 || 3 | 2 | 0 | - // 1 || 0 | 4 | 0 | - // 2 || 1 | 4 | 0 | - // 3 || 4 | 2 | 0 | - state = table[ state ][ xlate(*s) ]; - ++s; - } - - if ( state < 4 ) - // complain bitterly, if the HTTP header was too large ( > 16k ). - fprintf( stderr, "WARNING: %s will contain partial HTTP header data!\n", - filename ); - - // adjust to different seek size - metasize = s - linebuffer; - } - - // no need to copy zero content files - if ( filesize - metasize <= 0 ) { - BAUTZ( filesize-metasize == 0 ); - } - -#ifdef USE_REGULAR_COPY - // position input at start of server answer (contains HTTP headers) - if ( lseek( input, metasize, SEEK_SET ) == -1 ) { - fprintf( stderr, "lseek(%s,%lu): %s\n", fn, metasize, strerror(errno) ); - BAUTZ(false); - } - - // file copy input into output via buffer (regular io) - char buffer[32768]; - int rsize, wsize; - while ( (rsize=read(input,buffer,sizeof(buffer))) > 0 ) { - if ( (wsize=write(out,buffer,rsize)) <= 0 ) break; - } - if ( rsize < 0 || wsize < 0 ) perror( "while copying" ); -#else // use mmap copy (compare: Stevens APUE 12.9) - // precondition: filesize-metasize > 0 - // seek end of output file ... - off_t position = lseek( out, filesize-metasize-1, SEEK_SET ); - if ( position == -1 ) { - fprintf( stderr, "lseek(%s,%lu): %s\n", filename, - (unsigned long)filesize-metasize, - strerror(errno) ); - BAUTZ(false); - } else if ( debug & 0x02 ) { - fprintf( stderr, "# filesize=%lu, metasize=%lu, filepos=%ld\n", - (unsigned long)filesize, (unsigned long)metasize, - (long)position ); - } - - // ...and write 1 byte there (create a file that length) - if ( write( out, "", 1 ) != 1 ) { - perror( "write to output" ); - BAUTZ(false); - } - - // create source mmap to copy from (mmap complete file) - const auto src = static_cast(mmap(nullptr, filesize, PROT_READ, MAP_FILE | MAP_SHARED, input, 0)); - if (src == reinterpret_cast(-1)) { - perror( "mmap input" ); - BAUTZ(false); - } - - // create destination mmap to copy into (mmap data portion) - auto dst = static_cast(mmap(nullptr, filesize-metasize, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, out, 0)); - if (dst == reinterpret_cast(-1)) { - perror( "mmap output" ); - munmap( src, filesize ); - BAUTZ(false); - } - - // copy file (beware of offset into wanted data, skip meta data) - memcpy( dst, src+metasize, filesize-metasize ); - - // clean up - munmap( dst, filesize-metasize ); - munmap( src, filesize ); -#endif // USE_REGULAR_COPY - - BAUTZ(true); -} - diff --git a/tools/purge/copyout.hh b/tools/purge/copyout.hh deleted file mode 100644 index f2e9f9e93c..0000000000 --- a/tools/purge/copyout.hh +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: copyout.hh -// Tue Jun 15 1999 -// -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.1 1999/06/15 21:10:47 voeckler -// Initial revision -// -#ifndef _COPYOUT_HH -#define _COPYOUT_HH - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL -typedef int bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -int -assert_copydir( const char* copydir ); - // purpose: check, if copydir is a directory and that we can write into it. - // paramtr: copydir (IN): name of directory for copying bodies. - // returns: 0 if ok, -1 otherwise. - // further: errors are handled within. If the directory does not exist, - // the assertion function will try to create it. - -bool -copy_out( size_t filesize, size_t metasize, unsigned debug, - const char* fn, const char* url, const char* copydir, - bool copyHdr = true ); - // purpose: copy content from squid disk file into separate file - // paramtr: filesize (IN): complete size of input file - // metasize (IN): size of metadata to skip - // fn (IN): current filename of squid disk file - // url (IN): currently looked at URL to generate separate file - // copydir (IN): base directory where to generate the file - // copyHdr (IN): copy HTTP header, too, if set to true. - // returns: true, if successful, false otherwise. - -#endif // _COPYOUT_HH diff --git a/tools/purge/purge.1 b/tools/purge/purge.1 deleted file mode 100644 index 8cb596b330..0000000000 --- a/tools/purge/purge.1 +++ /dev/null @@ -1,288 +0,0 @@ -.if !'po4a'hide' .TH purge 8 "October 12, 2014" "" "" -. -.SH NAME -purge \- magnifying glass into your squid cache -. -.SH SYNOPSIS -.if !'po4a'hide' .B purge -.if !'po4a'hide' .B " [\-a] [\-c cf] [\-d l] [\-(f|F) fn | \-(e|E) re] [\-p h[:p]] [\-P #] [\-s] [\-v] [\-C dir [\-H]] [\-n]" -. -.SH DESCRIPTION -.PP -.B purge -is used to have a look at what URLs are stored in which file within -your cache. The -.B purge -tool can also be used to release objects which URLs -match user specified regular expressions. A more troublesome feature is the -ability to remove files -.B squid -does not seem to know about any longer. -.PP -This is a tool for expert usage only, use it under your own responsibility. -. -.SH OPTIONS -.if !'po4a'hide' .TP 12 -.if !'po4a'hide' .B \-a -a kind of "i am alive" flag. It can only be activated, if -your stdout is a tty. If active, it will display a little -rotating line to indicate that there is actually something -happening. You should not use this switch if you capture -your stdout in a file or if your expression list produces -many matches. The \-a flag is also incompatible with the -(default) multi cache_dir mode. -.br -default: off See also: \-n -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-c cd -this option lets you specify the location of the squid.conf file. -Purge understands about more than one cache_dir, and does so -by parsing squid.conf. It knows about both ways of Squid\-2 cache_dir -specifications, and will automatically try to use the correct one. -.br -default: /usr/local/squid/etc/squid.conf -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-C cf -if you want to rescue files from your cache, you need to specify -the directory into which the files will be copied. Please note -that purge will try to establish the original server directory -structure. This switch also activates copy\-out mode. Please do -not use copy\-out mode with any purge mode (\-P) other than 0. -.br -For instance, if you specified "\-C /tmp", purge will try to -recreate /tmp/www.server.1/url/path/file, and so forth. -.br -default: off See also: \-H, \-P -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-d l -lets you specify a debug level. Different bits are reserved for -different output. -.br -default: 0 -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-e|\-E re -Specify one regular expression to be searched for in the cache. -This is useful if there is only a handful of objects you -want to check. Please remember to escape the shell meta characters -used in your regular expression. The use of single quotes -around your expression is recommended. The capital letter -version works case sensitive, the lower caps version does not. -.br -default: (no default) -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-f|\-F fn -if you have more than a handful of expressions, or want to check -the same set at regular intervals, the file option might be more -useful to you. Each line in the text file will be regarded as -one regular expression. Again, the capital letter version works -case sensitive, the lower caps version does not. -.br -default: (no default) -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-H -if in copy\-out mode (see: \-C), you can specify to keep the -HTTP Header in the recreated file. -.br -default: off See also: \-C -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-n -tell purge to process one cache_dir after another, -instead of doing things in parallel. -If you have more than one cache_dir in your configuration -purge will fork off a worker process for each cache_dir to -do the checks for optimum speed, assuming a decently designed -cache. Since parallel execution will put quite some load on the -system and its controllers, it is sometimes preferred to use -less resources, though it will take longer. -.br -default: parallel mode for more than one cache_dir -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-p h[:p] -Some cache admins use a different port than 3128. The -purge tool will need to connect to your cache in order to send -the PURGE request (see \-P). This option lets you specify the -host and port to connect to. The port is optional. The port -can be a name (check your /etc/services) or number. It is -separated from the host name portion by a single colon, no -spaces allowed. -.br -default: localhost:3128 -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-P # -If you want to do more than just print your cache content, you -will need to specify this option. Each bit is reserved for a -different action. Only the use of the LSB is recommended, the -rest should be considered experimental. -.PP -.RS -.B no bit set: just print -.br -.B bit#0 set: send PURGE for matches -.br -.B bit#1 set: unlink object file for 404 not found PURGEs -.br -.B bit#2 set: unlink weird object files -.RE -.PP -If you use a value other than 0 or 1, you will need to slow -rebuild your cache content. A warning message will remind you -of that. If you use bit#1, all unsuccessful PURGEs will result -in the object file in your cache directory to be removed, because -squid does not seem to know about it any longer. Beware that the -asyncio might try to remove it after the purge tool, and thus -complains bitterly. Bit#1 only makes sense, if Bit#0 is also -set, otherwise it has no effect (since the HTTP status 404 is -never returned). -.PP -Bit#2 is reserved for strange files which do not even contain -a URL. Beware that these files may indicate a new object squid -currently intends to swap onto disk. If the file suddenly went -away, or is removed when squid tries to fetch the object, it -will complain bitterly. You must slow rebuild your cache, if -you use this option. -.PP -It is recommended that if you dare to use bit#1 or bit#2, you -should only grant the purge tool access to your squid, e.g. -move the HTTP and ICP listening port of squid to a different -non\-standard location during the purge. -.br -default: 0 (just print) -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-s -If you specify this switch, all commandline parameters will be -shown after they were parsed. -.br -default: off -. -.if !'po4a'hide' .TP -.if !'po4a'hide' .B \-v -be verbose in the things reported about the file. See the output -section below. -. -.SH CONFIGURATION -.PP -In order to use -.B purge -to affect a running proxy with PURGE method, you will have to enable this feature -in squid.conf. By default, PURGE is disabled. You should watch closely for whom -you enable the PURGE ability, otherwise a total stranger just might wipe your -cache content. Lines similar to the following will need to be added to your squid.conf: -.if !'po4a'hide' .PP -.if !'po4a'hide' .RS -.if !'po4a'hide' .P -.if !'po4a'hide' .B acl purge method PURGE -.if !'po4a'hide' .br -.if !'po4a'hide' .B http_access allow localhost purge -.if !'po4a'hide' .br -.if !'po4a'hide' .B http_access deny purge -.if !'po4a'hide' .RE -.PP -Reconfigure or restart (preferred) your squid after changing the -configuration file. -. -.SH OUTPUT -.PP -In regular mode, the output of purge consists of four columns. If the -URL contains not encoded whitespaces, it may look as if there are more -columns, but the last one is the URI. -. - # name meaning - = ====== =========================================================== - 1 file name of cache file eximed which matches the regular expression. - 2 status return result of purge request, " 0" in print mode. - 3 size object size including stored headers, not file size. - 4 uri perceived uri - -Example for non\-verbose output in print\-mode: - -/cache3/00/00/0000004A 0 5682 http://graphics.userfriendly.org/images/slovenia.gif -. -.PP -In verbose mode, additional columns are inserted before the uri. Time -stamps are reported using hexadecimal notation, and Squid's standard -for reporting "no such timestamp" == \-1, and "unparsable timestamp" == \-2. -. - # name meaning - = ====== =========================================================== - 1 file name of cache file eximed which matches the re. - 2 status return result of purge request, " 0" in print mode "\-P 0". - 3 size object size including stored headers, not file size. - 4 md5 MD5 of URI from file, or "(no_md5_data_available)" string. - 5 ts UTC of Value of Date: header in hex notation - 6 lr UTC of last time the object was referenced - 7 ex UTC of Expires: header - 8 lr UTC of Last\-Modified: header - 9 flags Value of objects flags field in hex, see: Programmers Guide -10 refcnt number of times the object was referenced. -11 uri STORE_META_URL uri or "strange_file" -. -Example for verbose output in print\-mode: -. -/cache1/00/00/000000B7 0 406 7CFCB1D319F158ADC9CFD991BB8F6DCE 397d449b 39bf677b ffffffff 3820abfc 0460 1 http://www.netscape.com/images/nc_vera_tile.gif -. -.SH KNOWN ISSUES -Purge does not slow rebuild the cache for you. -.PP -It is still relatively slow, especially if your machine is low on memory -and/or unable to hold all OS directory cache entries in main memory. -.PP -Should never be used on "busy" caches with purge modes higher than 1. -. -.SH TODO -.PP -1) use the stat() result on weird files to have a look at their ctime and -mtime. If they are younger than, lets say 30 seconds, they were just -created by -.B squid -and should not be removed. -.PP -2) Add a query before purging objects or removing files, and add another -option to remove nagging for the experienced user. -.PP -3) The reported object size may be off by one. -. -.SH AUTHOR -This program and manual was written by -.if !'po4a'hide' .B Santiago Garcia Mantinan -.if !'po4a'hide' .I Amos Jeffries -.PP -Based on original squidpurge README. -. -.SH COPYRIGHT -.PP - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. -. -.SH QUESTIONS -Questions on the usage of this program can be sent to the -.I Squid Users mailing list -.if !'po4a'hide' -. -.SH REPORTING BUGS -See https://wiki.squid-cache.org/SquidFaq/BugReporting for details of what you need to include with your bug report. -.PP -Report bugs or bug fixes using https://bugs.squid-cache.org/ -.PP -Report serious security bugs to -.I Squid Bugs -.PP -Report ideas for new improvements to the -.I Squid Developers mailing list -.if !'po4a'hide' -. -.SH SEE ALSO -.if !'po4a'hide' .BR squid "(8), " -.if !'po4a'hide' .BR cachemgr.cgi "(8)" diff --git a/tools/purge/purge.cc b/tools/purge/purge.cc deleted file mode 100644 index 89502b67b2..0000000000 --- a/tools/purge/purge.cc +++ /dev/null @@ -1,995 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: purge.cc -// Wed Jan 13 1999 -// -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.17 2000/09/21 10:59:53 cached -// *** empty log message *** -// -// Revision 1.16 2000/09/21 09:45:18 cached -// Fixed some small bugs. -// -// Revision 1.15 2000/09/21 09:05:56 cached -// added multi cache_dir support, thus changing -c cmdline option. -// modified file reading to support /dev/fd/0 reading for non-disclosed items. -// -// Revision 1.14 2000/06/20 09:43:01 voeckler -// added FreeBSD related fixes and support. -// -// Revision 1.13 2000/03/29 08:12:21 voeckler -// fixed wrong header file. -// -// Revision 1.12 2000/03/29 07:54:41 voeckler -// added mechanism to give a port specification precedence over a host -// specification with the -p option and not colon. -// -// Revision 1.11 1999/06/18 13:18:28 voeckler -// added refcount, fixed missing LF in -s output. -// -// Revision 1.10 1999/06/16 13:06:05 voeckler -// reversed meaning of -M flag. -// -// Revision 1.9 1999/06/15 21:11:53 voeckler -// added extended logging feature which extract the squid meta data available -// within the disk files. moved the content extraction and squid meta data -// handling parts into separate files. added options for copy-out and verbose. -// -// Revision 1.8 1999/06/14 20:14:46 voeckler -// intermediate version when adding understanding about the way -// Squid does log the metadata into the file. -// -// Revision 1.7 1999/01/23 21:01:10 root -// stumbled over libc5 header/lib inconsistency bug.... -// -// Revision 1.6 1999/01/23 20:47:54 root -// added Linux specifics for psignal... -// Hope this helps. -// -// Revision 1.5 1999/01/20 09:48:12 voeckler -// added warning as first line of output. -// -// Revision 1.4 1999/01/19 11:53:49 voeckler -// added psignal() from handling. -// -// Revision 1.3 1999/01/19 11:00:50 voeckler -// added keyboard interrupt handling, exit handling, removed C++ strings and -// regular expression syntax in favour of less source code, added comments, -// added a reminder to remove swap.state in case of unlinks, added IAA flag, -// added a few assertions, changed policy to enforce the definition of at -// least one regular expression, and catch a few signals. -// -// Revision 1.2 1999/01/15 23:06:28 voeckler -// downgraded to simple C strings... -// -// Revision 1.1 1999/01/14 12:05:32 voeckler -// Initial revision -// -// -#include "squid.h" -#include "util.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if HAVE_REGEX_H -#include -#endif - -#if HAVE_SIGINFO_H -#include -#endif - -#include -#include -#include -#include - -#include "conffile.hh" -#include "convert.hh" -#include "copyout.hh" -#include "signal.hh" -#include "socket.hh" -#include "squid-tlv.hh" - -#ifndef DEFAULTHOST -#define DEFAULTHOST "localhost" -#endif // DEFAULTHOST - -#ifndef DEFAULTPORT -#define DEFAULTPORT 3128 -#endif // DEFAULTPORT - -volatile sig_atomic_t term_flag = 0; // 'terminate' is a gcc 2.8.x internal... -char* linebuffer = nullptr; -size_t buffersize = 128*1024; -static char* copydir = nullptr; -static uint32_t debugFlag = 0; -static unsigned purgeMode = 0; -static bool iamalive = false; -static bool reminder = false; -static bool verbose = false; -static bool envelope = false; -static bool no_fork = false; -static const char* programname = nullptr; - -// ---------------------------------------------------------------------- - -struct REList { - REList( const char* what, bool doCase ); - ~REList(); - bool match( const char* check ) const; - - REList* next; - const char* data; - regex_t rexp; -}; - -REList::REList( const char* what, bool doCase ) - :next(nullptr),data(xstrdup(what)) -{ - int result = regcomp( &rexp, what, - REG_EXTENDED | REG_NOSUB | (doCase ? 0 : REG_ICASE) ); - if ( result != 0 ) { - char buffer[256]; - regerror( result, &rexp, buffer, 256 ); - fprintf( stderr, "unable to compile re \"%s\": %s\n", what, buffer ); - exit(EXIT_FAILURE); - } -} - -REList::~REList() -{ - if ( next ) delete next; - if ( data ) xfree((void*) data); - regfree(&rexp); -} - -bool -REList::match( const char* check ) const -{ - int result = regexec( &rexp, check, 0, nullptr, 0 ); - if ( result != 0 && result != REG_NOMATCH ) { - char buffer[256]; - regerror( result, &rexp, buffer, 256 ); - fprintf( stderr, "unable to execute re \"%s\"\n+ on line \"%s\": %s\n", - data, check, buffer ); - exit(EXIT_FAILURE); - } - return ( result == 0 ); -} - -// ---------------------------------------------------------------------- - -static char * -concat(const char *start, ...) -// purpose: concatinate an arbitrary number of C strings. -// paramtr: start (IN): first C string -// ... (IN): further C strings, terminated with a NULL pointer -// returns: memory allocated via new(), containing the concatenated string. -{ - va_list ap; - const char* s; - - // first run: determine size - unsigned size = strlen(start)+1; - va_start( ap, start ); - while ( (s=va_arg(ap,const char*)) != nullptr ) - size += strlen(s); - va_end(ap); - - // allocate - char* result = new char[size]; - if ( result == nullptr ) { - perror( "string memory allocation" ); - exit(EXIT_FAILURE); - } - - // second run: copy content - strcpy( result, start ); - va_start( ap, start ); - while ( (s=va_arg(ap,const char*)) != nullptr ) strcat( result, s ); - va_end(ap); - - return result; -} - -static bool -isxstring( const char* s, size_t testlen ) -// purpose: test a string for conforming to xdigit -// paramtr: s (IN): string to test -// testlen (IN): length the string must have -// returns: true, iff strlen(s)==testlen && all_x_chars(s), false otherwise -{ - if ( strlen(s) != testlen ) return false; - - size_t i=0; - while ( isearch( STORE_META_KEY_MD5 )) ) { - unsigned char* s = (unsigned char*) findings->data; - for ( int j=0; j<16; ++j, ++s ) { - md5[j*2+0] = hexdigit[ *s >> 4 ]; - md5[j*2+1] = hexdigit[ *s & 15 ]; - } - md5[32] = '\0'; // terminate string - } else { - snprintf( md5, sizeof(md5), "%-32s", "(no_md5_data_available)" ); - } - - char timeb[256]; - if ( meta && (findings = meta->search( STORE_META_STD )) ) { - StoreMetaStd temp; - // make data aligned, avoid SIGBUS on RISC machines (ARGH!) - memcpy( &temp, findings->data, sizeof(StoreMetaStd) ); - snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5hu ", - (unsigned long)temp.timestamp, (unsigned long)temp.lastref, - (unsigned long)temp.expires, (unsigned long)temp.lastmod, temp.flags, temp.refcount ); - } else if ( meta && (findings = meta->search( STORE_META_STD_LFS )) ) { - StoreMetaStdLFS temp; - // make data aligned, avoid SIGBUS on RISC machines (ARGH!) - memcpy( &temp, findings->data, sizeof(StoreMetaStdLFS) ); - snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5hu ", - (unsigned long)temp.timestamp, (unsigned long)temp.lastref, - (unsigned long)temp.expires, (unsigned long)temp.lastmod, temp.flags, temp.refcount ); - } else { - unsigned long ul = ULONG_MAX; // Match type of StoreMetaTLV fields - unsigned short hu = 0; // Match type of StoreMetaTLV refcount fields - snprintf( timeb, sizeof(timeb), "%08lx %08lx %08lx %08lx %04x %5d ", ul, ul, ul, ul, 0, hu); - } - - // make sure that there is just one printf() - if ( meta && (findings = meta->search( STORE_META_URL )) ) { - return printf( "%s %3d %8ld %s %s %s\n", - fn, code, size, md5, timeb, findings->data ); - } else { - return printf( "%s %3d %8ld %s %s strange_file\n", - fn, code, size, md5, timeb ); - } -} - -// o.k., this is pure laziness... -static struct in_addr serverHost; -static unsigned short serverPort; - -static bool -action(int fd, size_t metasize, - const char *fn, const char *url, const SquidMetaList &meta) -// purpose: if cmdline-requested, send the purge request to the cache -// paramtr: fd (IN): open FD for the object file -// metasize (IN): offset into data portion of file (meta data size) -// fn (IN): name of the object file -// url (IN): URL string stored in the object file -// meta (IN): list containing further meta data -// returns: true for a successful action, false otherwise. The action -// may just print the file, send the purge request or even -// remove unwanted files. -// globals: ::purgeMode (IN): bit#0 set -> send purge request. -// bit#1 set -> remove 404 object files. -// ::serverHost (IN): cache host address -// ::serverPort (IN): cache port number -{ - static const char* schablone = "PURGE %s HTTP/1.0\r\nAccept: */*\r\n\r\n"; - struct stat st; - long size = ( fstat(fd,&st) == -1 ? -1 : long(st.st_size - metasize) ); - - // if we want to copy out the file, do that first of all. - if ( ::copydir && *copydir && size > 0 ) - copy_out( st.st_size, metasize, ::debugFlag, - fn, url, ::copydir, ::envelope ); - - // do we need to PURGE the file, yes, if purgemode bit#0 was set. - int status = 0; - if ( ::purgeMode & 0x01 ) { - unsigned long bufsize = strlen(url) + strlen(schablone) + 4; - char* buffer = new char[bufsize]; - - snprintf( buffer, bufsize, schablone, url ); - int sockfd = connectTo( serverHost, serverPort, true ); - if ( sockfd == -1 ) { - fprintf( stderr, "unable to connect to server: %s\n", strerror(errno) ); - delete[] buffer; - return false; - } - - int content_size = strlen(buffer); - if ( write( sockfd, buffer, content_size ) != content_size ) { - // error while talking to squid - fprintf( stderr, "unable to talk to server: %s\n", strerror(errno) ); - close(sockfd); - delete[] buffer; - return false; - } - memset( buffer+8, 0, 4 ); - int readLen = read(sockfd, buffer, bufsize); - if (readLen < 1) { - // error while reading squid's answer - fprintf( stderr, "unable to read answer: %s\n", strerror(errno) ); - close(sockfd); - delete[] buffer; - return false; - } - buffer[bufsize-1] = '\0'; - close(sockfd); - int64_t s = strtol(buffer+8,nullptr,10); - if (s > 0 && s < 1000) - status = s; - else { - // error while reading squid's answer - fprintf( stderr, "invalid HTTP status in reply: %s\n", buffer+8); - } - delete[] buffer; - } - - // log the output of our operation - bool flag = true; - if ( ::verbose ) flag = ( log_extended( fn, status, size, &meta ) >= 0 ); - else flag = ( log_output( fn, status, size, url ) >= 0 ); - - // remove the file, if purgemode bit#1, and HTTP result status 404). - if ( (::purgeMode & 0x02) && status == 404 ) { - reminder = true; - if ( unlink(fn) == -1 ) - // error while unlinking file, this may happen due to the cache - // unlinking a file while it is still in the readdir() cache of purge. - fprintf( stderr, "WARNING: unable to unlink %s: %s\n", - fn, strerror(errno) ); - } - - return flag; -} - -static bool -match(const char *fn, const REList *list) -// purpose: do something with the given cache content filename -// paramtr: fn (IN): filename of cache file -// returns: true for successful action, false otherwise. -// warning: only return false, if you want the loop to terminate! -{ - static const size_t addon = sizeof(unsigned char) + sizeof(unsigned int); - bool flag = true; - - if ( debugFlag & 0x01 ) fprintf( stderr, "# [3] %s\n", fn ); - int fd = open( fn, O_RDONLY ); - if ( fd != -1 ) { - memset(::linebuffer, 0, ::buffersize); - size_t readLen = read(fd,::linebuffer,::buffersize-1); - if ( readLen > 60 ) { - ::linebuffer[ ::buffersize-1 ] = '\0'; // force-terminate string - - // check the offset into the start of object data. The offset is - // stored in a host endianness after the first byte. - unsigned int datastart; - memcpy( &datastart, ::linebuffer + 1, sizeof(unsigned int) ); - if ( datastart > ::buffersize - addon - 1 ) { - // check offset into server reply header (start of cache data). - fputs( "WARNING: Using a truncated URL string.\n", stderr ); - datastart = ::buffersize - addon - 1; - } - - // NEW: Parse squid meta data, which is a kind of linked list - // flattened out into a file byte stream. Somewhere within is - // the URL as part of the list. First, gobble all meta data. - unsigned int offset = addon; - SquidMetaList meta; - while ( offset + addon <= datastart ) { - unsigned int size = 0; - memcpy( &size, linebuffer+offset+sizeof(char), sizeof(unsigned int) ); - if (size+offset < size) { - fputs("WARNING: file corruption detected. 32-bit overflow in size field.\n", stderr); - break; - } - if (size+offset > readLen) { - fputs( "WARNING: Partial meta data loaded.\n", stderr ); - break; - } - meta.append( SquidMetaType(*(linebuffer+offset)), - size, linebuffer+offset+addon ); - offset += ( addon + size ); - } - - // Now extract the key URL from the meta data. - const SquidTLV* urlmeta = meta.search( STORE_META_URL ); - if ( urlmeta ) { - // found URL in meta data. Try to process the URL - if ( list == nullptr ) - flag = action( fd, datastart, fn, (char*) urlmeta->data, meta ); - else { - REList* head = (REList*) list; // YUCK! - while ( head != nullptr ) { - if ( head->match( (char*) urlmeta->data ) ) break; - head = head->next; - } - if ( head != nullptr ) - flag = action( fd, datastart, fn, (char*) urlmeta->data, meta ); - else flag = true; - } - } - - // "meta" will be deleted when exiting from this block - } else { - // weird file, TODO: stat() it! - struct stat st; - long size = ( fstat(fd,&st) == -1 ? -1 : st.st_size ); - if ( ::verbose ) flag = ( log_extended( fn, -1, size, nullptr ) >= 0 ); - else flag = ( log_output( fn, -1, size, "strange file" ) >= 0 ); - - if ( (::purgeMode & 0x04) ) { - reminder = true; - if ( unlink(fn) == -1 ) - // error while unlinking file, this may happen due to the cache - // unlinking a file while it is in the readdir() cache of purge. - fprintf( stderr, "WARNING: unable to unlink %s: %s\n", - fn, strerror(errno) ); - } - } - close(fd); - } else { - // error while opening file, this may happen due to the cache - // unlinking a file while it is still in the readdir() cache of purge. - fprintf( stderr, "WARNING: open \"%s\": %s\n", fn, strerror(errno) ); - } - - return flag; -} - -static bool -filelevel(const char *directory, const REList *list) -// purpose: from given starting point, look for squid xxxxxxxx files. -// example: "/var/spool/cache/08/7F" as input, do action over files -// paramtr: directory (IN): starting point -// list (IN): list of rexps to match URLs against -// returns: true, if every subdir && action was successful. -{ - dirent_t * entry; - if ( debugFlag & 0x01 ) - fprintf( stderr, "# [2] %s\n", directory ); - - DIR* dir = opendir( directory ); - if ( dir == nullptr ) { - fprintf( stderr, "unable to open directory \"%s\": %s\n", - directory, strerror(errno) ); - return false; - } - - // display a rotating character as "i am alive" signal (slows purge). - if ( ::iamalive ) { - static char alivelist[4][3] = { "\\\b", "|\b", "/\b", "-\b" }; - static unsigned short alivecount = 0; - const int write_success = write(STDOUT_FILENO, alivelist[alivecount++ & 3], 2); - assert(write_success == 2); - } - - bool flag = true; - while ( (entry=readdir(dir)) && flag ) { - if ( isxstring(entry->d_name,8) ) { - char* name = concat( directory, "/", entry->d_name, 0 ); - flag = match( name, list ); - delete[] name; - } - } - - closedir(dir); - return flag; -} - -static bool -dirlevel(const char *dirname, const REList *list, bool level = false) -// purpose: from given starting point, look for squid 00..FF directories. -// paramtr: dirname (IN): starting point -// list (IN): list of rexps to match URLs against -// level (IN): false==toplevel, true==1st level -// example: "/var/spool/cache", false as input, traverse subdirs w/ action. -// example: "/var/spool/cache/08", true as input, traverse subdirs w/ action. -// returns: true, if every subdir && action was successful. -// warning: this function is once-recursive, no deeper. -{ - dirent_t* entry; - if ( debugFlag & 0x01 ) - fprintf( stderr, "# [%d] %s\n", (level ? 1 : 0), dirname ); - - DIR* dir = opendir( dirname ); - if ( dir == nullptr ) { - fprintf( stderr, "unable to open directory \"%s\": %s\n", - dirname, strerror(errno) ); - return false; - } - - bool flag = true; - while ( (entry=readdir(dir)) && flag ) { - if ( strlen(entry->d_name) == 2 && - isxdigit(entry->d_name[0]) && - isxdigit(entry->d_name[1]) ) { - char* name = concat( dirname, "/", entry->d_name, 0 ); - flag = level ? filelevel( name, list ) : dirlevel( name, list, true ); - delete[] name; - } - } - - closedir(dir); - return flag; -} - -static int -checkForPortOnly(const char *arg) -// purpose: see if somebody just put in a port instead of a hostname -// paramtr: optarg (IN): argument from commandline -// returns: 0..65535 is the valid port number in network byte order, -// -1 if not a port -{ - // if there is a period in there, it must be a valid hostname - if ( strchr( arg, '.' ) != nullptr ) return -1; - - // if it is just a number between 0 and 65535, it must be a port - char* errstr = nullptr; - unsigned long result = strtoul( arg, &errstr, 0 ); - if ( result < 65536 && errstr != arg ) return htons(result); - - return -1; -} - -static void -helpMe(void) -// purpuse: write help message and exit -{ - printf( "\nUsage:\t%s\t[-a] [-c cf] [-d l] [-(f|F) fn | -(e|E) re] " - "[-p h[:p]]\n\t\t[-P #] [-s] [-v] [-C dir [-H]] [-n]\n\n", - ::programname ); - printf( - " -a\tdisplay a little rotating thingy to indicate that I am alive (tty only).\n" - " -c c\tsquid.conf location, default \"%s\".\n" - " -C dir\tbase directory for content extraction (copy-out mode).\n" - " -d l\tdebug level, an OR mask of different debug options.\n" - " -e re\tsingle regular expression per -e instance (use quotes!).\n" - " -E re\tsingle case sensitive regular expression like -e.\n" - " -f fn\tname of textfile containing one regular expression per line.\n" - " -F fn\tname of textfile like -f containing case sensitive REs.\n" - " -H\tprepend HTTP reply header to destination files in copy-out mode.\n" - " -n\tdo not fork() when using more than one cache_dir.\n" - " -p h:p\tcache runs on host h and optional port p, default is %s:%u.\n" - " -P #\tif 0, just print matches; otherwise OR the following purge modes:\n" - "\t 0x01 really send PURGE to the cache.\n" - "\t 0x02 remove all caches files reported as 404 (not found).\n" - "\t 0x04 remove all weird (inaccessible or too small) cache files.\n" - "\t0 and 1 are recommended - slow rebuild your cache with other modes.\n" - " -s\tshow all options after option parsing, but before really starting.\n" - " -v\tshow more information about the file, e.g. MD5, timestamps and flags.\n" - "\n", DEFAULT_CONFIG_FILE, DEFAULTHOST, DEFAULTPORT ); - -} - -static void -parseCommandline(int argc, char *argv[], REList *&head, - char *&conffile, char *©DirPath, - struct in_addr &serverHostIp, unsigned short &serverHostPort) -// paramtr: argc: see ::main(). -// argv: see ::main(). -// returns: Does terminate the program on errors! -// purpose: suck in any commandline options, and set the global vars. -{ - int option, port, showme = 0; - char* ptr, *colon; - FILE* rfile; - - // program basename - if ( (ptr = strrchr(argv[0],'/')) == nullptr ) - ptr=argv[0]; - else - ++ptr; - ::programname = ptr; - - // extract commandline parameters - REList* tail = head = nullptr; - opterr = 0; - while ( (option = getopt( argc, argv, "ac:C:d:E:e:F:f:Hnp:P:sv" )) != -1 ) { - switch ( option ) { - case 'a': - ::iamalive = ! ::iamalive; - break; - case 'C': - if ( optarg && *optarg ) { - if ( copyDirPath ) xfree( (void*) copyDirPath ); - copyDirPath = xstrdup(optarg); - assert(copyDirPath); - } - break; - case 'c': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c requires a regex pattern argument!\n", option ); - exit(EXIT_FAILURE); - } - if ( *conffile ) xfree((void*) conffile); - conffile = xstrdup(optarg); - assert(conffile); - break; - - case 'd': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c expects a mask parameter. Debug disabled.\n", option ); - ::debugFlag = 0; - } else - ::debugFlag = (strtoul(optarg, nullptr, 0) & 0xFFFFFFFF); - break; - - case 'E': - case 'e': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c requires a regex pattern argument!\n", option ); - exit(EXIT_FAILURE); - } - if ( head == nullptr ) - tail = head = new REList( optarg, option=='E' ); - else { - tail->next = new REList( optarg, option=='E' ); - tail = tail->next; - } - break; - - case 'f': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c requires a filename argument!\n", option ); - exit(EXIT_FAILURE); - } - if ( (rfile = fopen( optarg, "r" )) != nullptr ) { - unsigned long lineno = 0; -#define LINESIZE 512 - char line[LINESIZE]; - while ( fgets( line, LINESIZE, rfile ) != nullptr ) { - ++lineno; - int len = strlen(line)-1; - if ( len+2 >= LINESIZE ) { - fprintf( stderr, "%s:%lu: line too long, sorry.\n", - optarg, lineno ); - exit(EXIT_FAILURE); - } - - // remove trailing line breaks - while ( len > 0 && ( line[len] == '\n' || line[len] == '\r' ) ) { - line[len] = '\0'; - --len; - } - - // insert into list of expressions - if ( head == nullptr ) tail = head = new REList(line,option=='F'); - else { - tail->next = new REList(line,option=='F'); - tail = tail->next; - } - } - fclose(rfile); - } else - fprintf( stderr, "unable to open %s: %s\n", optarg, strerror(errno)); - break; - - case 'H': - ::envelope = ! ::envelope; - break; - case 'n': - ::no_fork = ! ::no_fork; - break; - case 'p': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c requires a port argument!\n", option ); - exit(EXIT_FAILURE); - } - colon = strchr( optarg, ':' ); - if ( colon == nullptr ) { - // no colon, only look at host - - // fix: see if somebody just put in there a port (no periods) - // give port number precedence over host names - port = checkForPortOnly( optarg ); - if ( port == -1 ) { - // assume that main() did set the default port - if ( convertHostname(optarg,serverHostIp) == -1 ) { - fprintf( stderr, "unable to resolve host %s!\n", optarg ); - exit(EXIT_FAILURE); - } - } else { - // assume that main() did set the default host - serverHostPort = port; - } - } else { - // colon used, port is extra - *colon = 0; - ++colon; - if ( convertHostname(optarg,serverHostIp) == -1 ) { - fprintf( stderr, "unable to resolve host %s!\n", optarg ); - exit(EXIT_FAILURE); - } - if ( convertPortname(colon,serverHostPort) == -1 ) { - fprintf( stderr, "unable to resolve port %s!\n", colon ); - exit(EXIT_FAILURE); - } - } - break; - case 'P': - if ( !optarg || !*optarg ) { - fprintf( stderr, "%c requires a mode argument!\n", option ); - exit(EXIT_FAILURE); - } - ::purgeMode = ( strtol( optarg, nullptr, 0 ) & 0x07 ); - break; - case 's': - showme=1; - break; - case 'v': - ::verbose = ! ::verbose; - break; - case '?': - default: - helpMe(); - exit(EXIT_FAILURE); - } - } - - // adjust - if ( ! isatty(fileno(stdout)) || (::debugFlag & 0x01) ) ::iamalive = false; - if ( head == nullptr ) { - fputs( "There was no regular expression defined. If you intend\n", stderr ); - fputs( "to match all possible URLs, use \"-e .\" instead.\n", stderr ); - exit(EXIT_FAILURE); - } - - // postcondition: head != 0 - assert( head != nullptr ); - - // make sure that the copy out directory is there and accessible - if ( copyDirPath && *copyDirPath ) - if ( assert_copydir( copyDirPath ) != 0 ) exit(1); - - // show results - if ( showme ) { - printf( "#\n# Currently active values for %s:\n", - ::programname); - printf( "# Debug level : " ); - if ( ::debugFlag ) printf( "%#6.4x", ::debugFlag ); - else printf( "production level" ); // printf omits 0x prefix for 0! - printf( " + %s mode", ::no_fork ? "linear" : "parallel" ); - puts( ::verbose ? " + extra verbosity" : "" ); - - printf( "# Copy-out directory: %s ", - copyDirPath ? copyDirPath : "copy-out mode disabled" ); - if ( copyDirPath ) - printf( "(%s HTTP header)\n", ::envelope ? "prepend" : "no" ); - else - puts(""); - - printf( "# Squid config file : %s\n", conffile ); - printf( "# Cacheserveraddress: %s:%u\n", - inet_ntoa( serverHostIp ), ntohs( serverHostPort ) ); - printf( "# purge mode : 0x%02x\n", ::purgeMode ); - printf( "# Regular expression: " ); - - unsigned count(0); - for ( tail = head; tail != nullptr; tail = tail->next ) { - if ( count++ ) - printf( "#%22u", count ); -#if defined(LINUX) && putc==_IO_putc - // I HATE BROKEN LINUX HEADERS! - // purge.o(.text+0x1040): undefined reference to `_IO_putc' - // If your compilation breaks here, remove the undefinition -#undef putc -#endif - else putchar('1'); - printf( " \"%s\"\n", tail->data ); - } - puts( "#" ); - } - fflush( stdout ); -} - -extern "C" { - - static - void - exiter( void ) { - if ( ::term_flag ) psignal( ::term_flag, "received signal" ); - delete[] ::linebuffer; - if ( ::reminder ) { - fputs( - "WARNING! Caches files were removed. Please shut down your cache, remove\n" - "your swap.state files and restart your cache again, i.e. effictively do\n" - "a slow rebuild your cache! Otherwise your squid *will* choke!\n", stderr ); - } - } - - static - void - handler( int signo ) { - ::term_flag = signo; - if ( getpid() == getpgrp() ) kill( -getpgrp(), signo ); - exit(EXIT_FAILURE); - } - -} // extern "C" - -static -int -makelinebuffered( FILE* fp, const char* fn = nullptr ) -// purpose: make the given FILE line buffered -// paramtr: fp (IO): file pointer which to put into line buffer mode -// fn (IN): name of file to print in case of error -// returns: 0 is ok, -1 to indicate an error -// warning: error messages will already be printed -{ - if ( setvbuf( fp, nullptr, _IOLBF, 0 ) == 0 ) { - // ok - return 0; - } else { - // error - fprintf( stderr, "unable to make \"%s\" line buffered: %s\n", - fn ? fn : "", strerror(errno) ); - return -1; - } -} - -int -main( int argc, char* argv[] ) -{ - // setup variables - REList* list = nullptr; - char* conffile = xstrdup(DEFAULT_CONFIG_FILE); - serverPort = htons(DEFAULTPORT); - if ( convertHostname(DEFAULTHOST,serverHost) == -1 ) { - fprintf( stderr, "unable to resolve host %s!\n", DEFAULTHOST ); - exit(EXIT_FAILURE); - } - - // setup line buffer - ::linebuffer = new char[ ::buffersize ]; - assert( ::linebuffer != nullptr ); - - // parse commandline - puts( "### Use at your own risk! No guarantees whatsoever. You were warned. ###"); - parseCommandline( argc, argv, list, conffile, ::copydir, - serverHost, serverPort ); - - // prepare execution - if ( atexit( exiter ) != 0 || - Signal( SIGTERM, handler, true ) == SIG_ERR || - Signal( SIGINT, handler, true ) == SIG_ERR || - Signal( SIGHUP, handler, true ) == SIG_ERR ) { - perror( "unable to install signal/exit function" ); - exit(EXIT_FAILURE); - } - - // try to read squid.conf file to determine all cache_dir locations - CacheDirVector cdv(0); - if ( readConfigFile( cdv, conffile, debugFlag ? stderr : nullptr ) > 0 ) { - // there are some valid cache_dir entries. - // unless forking was forbidden by cmdline option, - // for a process for each cache_dir entry to remove files. - - if ( ::no_fork || cdv.size() == 1 ) { - // linear mode, one cache_dir after the next - for ( CacheDirVector::iterator i = cdv.begin(); i != cdv.end(); ++i ) { - // execute OR complain - if ( ! dirlevel(i->base,list) ) - fprintf( stderr, "program terminated due to error: %s", - strerror(errno) ); - xfree((void*) i->base); - } - } else { - // parallel mode, all cache_dir in parallel - pid_t* child = new pid_t[ cdv.size() ]; - - // make stdout/stderr line bufferd - makelinebuffered( stdout, "stdout" ); - makelinebuffered( stderr, "stderr" ); - - // make parent process group leader for easier killings - if ( setpgid(getpid(), getpid()) != 0 ) { - perror( "unable to set process group leader" ); - exit(EXIT_FAILURE); - } - - // -a is mutually exclusive with fork mode - if ( ::iamalive ) { - puts( "# i-am-alive flag incompatible with fork mode, resetting" ); - ::iamalive = false; - } - - for ( size_t i=0; i < cdv.size(); ++i ) { - if ( getpid() == getpgrp() ) { - // only parent == group leader may fork off new processes - if ( (child[i]=fork()) < 0 ) { - // fork error, this is bad! - perror( "unable to fork" ); - kill( -getpgrp(), SIGTERM ); - exit(EXIT_FAILURE); - } else if ( child[i] == 0 ) { - // child mode - // execute OR complain - if ( ! dirlevel(cdv[i].base,list) ) - fprintf( stderr, "program terminated due to error: %s\n", - strerror(errno) ); - xfree((void*) cdv[i].base); - exit(EXIT_SUCCESS); - } else { - // parent mode - if ( ::debugFlag ) printf( "forked child %d\n", (int) child[i] ); - } - } - } - - // collect the garbase - pid_t temp; - int status; - for ( size_t i=0; i < cdv.size(); ++i ) { - while ( (temp=waitpid( (pid_t)-1, &status, 0 )) == -1 ) - if ( errno == EINTR ) continue; - if ( ::debugFlag ) printf( "collected child %d\n", (int) temp ); - } - delete[] child; - } - } else { - fprintf( stderr, "no cache_dir or error accessing \"%s\"\n", conffile ); - } - - // clean up - if ( copydir ) xfree( (void*) copydir ); - xfree((void*) conffile); - delete list; - return EXIT_SUCCESS; -} - diff --git a/tools/purge/signal.cc b/tools/purge/signal.cc deleted file mode 100644 index c8ab98dfc5..0000000000 --- a/tools/purge/signal.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// File: signal.cc -// Date: Sat Feb 28 1998 -// Compiler: gcc 2.7.2.x series -// -// Books: W. Richard Steven, "Advanced Programming in the UNIX Environment", -// Addison-Wesley, 1992. -// -// (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.3 1999/01/19 13:11:52 cached -// adaptations necessary for AIX. -// -// Revision 1.2 1999/01/19 11:00:50 voeckler -// added psignal(int,const char*) compatibility function. -// -// Revision 1.1 1998/08/13 21:51:58 voeckler -// Initial revision -// - -#include "squid.h" -#include "signal.hh" - -#include -#include -#include -#include -#include - -SigFunc* -Signal( int signo, SigFunc* newhandler, bool doInterrupt ) -// purpose: install reliable signals -// paramtr: signo (IN): signal for which a handler is to be installed -// newhandler (IN): function pointer to the signal handler -// doInterrupt (IN): interrupted system calls wanted! -// returns: the old signal handler, or SIG_ERR in case of error. -{ - struct sigaction action, old; - - memset( &old, 0, sizeof(old) ); - memset( &action, 0, sizeof(action) ); - - // action.sa_handler = newhandler; I HATE TYPE-OVERCORRECTNESS ! - memmove( &action.sa_handler, &newhandler, sizeof(SigFunc*) ); - sigemptyset( &action.sa_mask ); - - if ( signo == SIGCHLD ) { - action.sa_flags |= SA_NOCLDSTOP; - -#ifdef SA_NODEFER - action.sa_flags |= SA_NODEFER; // SYSV: don't block current signal -#endif - } - - if ( signo == SIGALRM || doInterrupt ) { -#ifdef SA_INTERRUPT - action.sa_flags |= SA_INTERRUPT; // SunOS, obsoleted by POSIX -#endif - } else { -#ifdef SA_RESTART - action.sa_flags |= SA_RESTART; // BSD, SVR4 -#endif - } - - return ( sigaction( signo, &action, &old ) < 0 ) ? - (SigFunc*) SIG_ERR : - (SigFunc*) old.sa_handler; -} - -void -sigChild( int signo ) -// purpose: supply ad hoc child handler with output on stderr -// paramtr: signo (IN): == SIGCHLD -// returns: only if OS uses a return type for signal handler -// seealso: Stevens, UNP, figure 5.11 *and* Stevens, APUE, figure 8.3 -{ - pid_t pid; - int status = signo; // to stop GNU from complaining... - - int saveerr = errno; - while ( (pid = waitpid( -1, &status, WNOHANG )) > 0 ) { - if ( WIFEXITED(status) ) { - fprintf( stderr, "child (pid=%ld) reaped, status %d\n%c", - (long) pid, WEXITSTATUS(status), 0 ); - } else if ( WIFSIGNALED(status) ) { - fprintf( stderr, "child (pid=%ld) died on signal %d%s\n%c", - (long) pid, WTERMSIG(status), -#ifdef WCOREDUMP - WCOREDUMP(status) ? " (core generated)" : "", -#else - "", -#endif - 0 ); - } else { - fprintf( stderr, "detected dead child (pid=%ld), status %d\n%c", - (long) pid, status, 0 ); - } - } - errno = saveerr; -} - diff --git a/tools/purge/signal.hh b/tools/purge/signal.hh deleted file mode 100644 index ff4f291f50..0000000000 --- a/tools/purge/signal.hh +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// File: signal.hh -// Date: Sat Feb 28 1998 -// Compiler: gcc 2.7.2.x series -// -// Books: W. Richard Steven, "Advanced Programming in the UNIX Environment", -// Addison-Wesley, 1992. -// -// (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.4 2000/09/21 10:59:27 cached -// introduced extern "C" to function pointer type. -// -// Revision 1.3 1999/01/19 11:53:49 voeckler -// added bool compatibility definitions. -// -// Revision 1.2 1999/01/19 11:00:50 voeckler -// added psignal(int,const char*) compatibility function declaration. -// -// Revision 1.1 1998/08/13 21:51:58 voeckler -// Initial revision -// -// - -#ifndef _SIGNAL_HH -#define _SIGNAL_HH - -#include "squid.h" - -#include - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL -typedef int bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -#if defined(SUNOS) && defined(SUN) -# define SIGPARAM void -#else // SOLARIS, LINUX, IRIX, AIX, SINIXY -# define SIGPARAM int -#endif - -extern "C" { - typedef void SigFunc( SIGPARAM ); -} - -SigFunc* -Signal( int signo, SigFunc* newhandler, bool doInterrupt ); - // purpose: install reliable signals - // paramtr: signo (IN): signal for which a handler is to be installed - // newhandler (IN): function pointer to the signal handler - // doInterrupt (IN): interrupted system calls wanted! - // returns: the old signal handler, or SIG_ERR in case of error. - -void -sigChild( int signo ); - // purpose: supply ad hoc child handler with output on stderr - // paramtr: signo (IN): == SIGCHLD - // returns: only if OS uses a return type for signal handler - -#endif // _SIGNAL_HH diff --git a/tools/purge/socket.cc b/tools/purge/socket.cc deleted file mode 100644 index c09bb9d33b..0000000000 --- a/tools/purge/socket.cc +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: socket.hh -// Sun May 3 1998 -// -// (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Books: W. Richard Steven, "Advanced Programming in the UNIX Environment", -// Addison-Wesley, 1992. -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.3 1999/01/19 11:00:50 voeckler -// Linux glibc2 fixes for socket size parameters. -// -// Revision 1.2 1998/08/27 15:23:39 voeckler -// added TCP_NODELAY options at several places. -// -// Revision 1.1 1998/08/13 21:52:55 voeckler -// Initial revision -// - -#include "squid.h" -#include "socket.hh" - -#include -#include -#include -#include -#include - -#include - -#include "convert.hh" - -int -setSocketBuffers( int sockfd, int size ) -// purpose: set socket buffers for both directions to the specified size -// paramtr: sockfd (IN): socket file descriptor -// size (IN): new socket buffer size -// returns: -1 on setsockopt() errors, 0 otherwise -// warning: prints error message on stderr, errno will be changed -{ - if ( setsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, - (char*) &size, sizeof(size) ) == -1 ) { - perror( "setsockopt( SO_RCVBUF )" ); - return -1; - } - - if ( setsockopt( sockfd, SOL_SOCKET, SO_SNDBUF, - (char*) &size, sizeof(size) ) == -1 ) { - perror( "setsockopt( SO_SNDBUF )" ); - return -1; - } - - return 0; -} - -int -getSocketNoDelay( int sockfd ) -// purpose: get state of the TCP_NODELAY of the socket -// paramtr: sockfd (IN): socket descriptor -// returns: 1, if TCP_NODELAY is set, -// 0, if TCP_NODELAY is not set, -// -1, if an error occurred (e.g. datagram socket) -{ - int delay = 0; - socklen_t len = sizeof(delay); - if ( getsockopt( sockfd, IPPROTO_TCP, TCP_NODELAY, - (char*) &delay, &len ) == -1 ) { - perror( "# getsockopt( TCP_NODELAY ) failed" ); - return -1; - } else - return ( delay ? 1 : 0 ); -} - -int -setSocketNoDelay( int sockfd, bool) -// purpose: get state of the TCP_NODELAY of the socket -// paramtr: sockfd (IN): socket descriptor -// nodelay (IN): true, if TCP_NODELAY is to be set, false otherwise. -// returns: 0, if everything worked out o.k. -// -1, if an error occurred (e.g. datagram socket) -{ - const int delay = 1; - if ( setsockopt( sockfd, IPPROTO_TCP, TCP_NODELAY, - (const char*) &delay, sizeof(delay) ) == -1 ) { - perror( "setsockopt( TCP_NODELAY ) failed" ); - return -1; - } else - return 0; -} - -static int -commonCode(int &sockfd, bool nodelay, int sendBufferSize, int recvBufferSize) -// purpose: common code in server sockets and client sockets -// paramtr: sockfd (IO): socket filedescriptor -// nodelay (IN): true=set TCP_NODELAY option. -// sendBufferSize (IN): don't set (use sys defaults) if < 0 -// recvBufferSize (IN): don't set (use sys defaults) if < 0 -// returns: 0 == if everything went ok, -1 otherwise -// warning: sockfd will be closed, if -1 is returned! -{ - // set TCP_NODELAY option, if that is wanted. - // The socket API default is unset. - if ( nodelay ) { - const int delay = 1; - if ( setsockopt( sockfd, IPPROTO_TCP, TCP_NODELAY, - (const char*) &delay, sizeof(delay) ) == -1 ) { - perror( "setsockopt( TCP_NODELAY ) failed" ); - close(sockfd); - return -1; - } - } - - // set the socket send buffer size explicitly, or use the system default - if ( sendBufferSize >= 0 ) { - if ( setsockopt( sockfd, SOL_SOCKET, SO_SNDBUF, (char*) &sendBufferSize, - sizeof(sendBufferSize) ) == -1 ) { - perror( "setsockopt( SO_SNDBUF )" ); - close(sockfd); - return -1; - } - } - - // set the socket recv buffer size explicitly, or use the system default - if ( recvBufferSize >= 0 ) { - if ( setsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, (char*) &recvBufferSize, - sizeof(recvBufferSize) ) == -1 ) { - perror( "setsockopt( SO_RCVBUF )" ); - close(sockfd); - return -1; - } - } - return 0; -} - -int -connectTo( struct in_addr host, unsigned short port, bool nodelay, - int sendBufferSize, int recvBufferSize ) -// purpose: connect to a server as a client -// paramtr: host (IN): address describing the server -// port (IN): port to connect at the server -// nodelay (IN): true=set TCP_NODELAY option. -// sendBufferSize (IN): don't set (use sys defaults) if < 0 -// recvBufferSize (IN): don't set (use sys defaults) if < 0 -// returns: >=0 is the descriptor of the opened, connected socket, -// -1 is an indication of an error (errno may have been reset). -{ - int sockfd = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP ); - if ( sockfd == -1 ) { - perror( "socket() failed" ); - return -1; - } - - if ( commonCode( sockfd, nodelay, sendBufferSize, recvBufferSize ) == -1 ) - return -1; - - struct sockaddr_in server; - memset( &server, 0, sizeof(server) ); - server.sin_family = AF_INET; - server.sin_addr = host; - server.sin_port = port; - if ( connect( sockfd, (struct sockaddr*) &server, sizeof(server) ) == -1 ) { - perror( "connect() failure" ); - close(sockfd); - return -1; - } - - return sockfd; -} - -int -serverSocket( struct in_addr host, unsigned short port, - int backlog, bool reuse, bool nodelay, - int sendBufferSize, int recvBufferSize ) -// purpose: open a server socket for listening -// paramtr: host (IN): host to bind locally to, use INADDRY_ANY for * -// port (IN): port to bind to, use 0 for system assigned -// backlog (IN): listen backlog queue length -// reuse (IN): set SO_REUSEADDR option - default usefully -// nodelay (IN): true=set TCP_NODELAY option. -// SETTING TCP_NODELAY ON A SERVER SOCKET DOES NOT MAKE SENSE! -// sendBufferSize (IN): don't set (use sys defaults) if < 0 -// recvBufferSize (IN): don't set (use sys defaults) if < 0 -// returns: opened listening fd, or -1 on error. -// warning: error message will be printed on stderr and errno reset. -{ - int sockfd = socket( AF_INET, SOCK_STREAM, 0 ); - if ( sockfd == -1 ) { - perror( "socket" ); - return -1; - } - - if ( reuse ) { - int opt = 1; - if ( setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, - (char*) &opt, sizeof(int) ) == -1) { - perror( "setsockopt( SO_REUSEADDR )" ); - close( sockfd ); - return -1; - } - } - - if ( commonCode( sockfd, nodelay, sendBufferSize, recvBufferSize ) == -1 ) - return -1; - - struct sockaddr_in server; - memset( &server, 0, sizeof(server) ); - server.sin_family = AF_INET; - server.sin_port = port; - server.sin_addr = host; - if ( bind( sockfd, (SA*) &server, sizeof(server) ) == -1 ) { - SockAddress socket; - fprintf( stderr, "bind(%s): %s\n", - my_sock_ntoa(server,socket), strerror(errno) ); - close(sockfd); - return -1; - } - - if ( listen( sockfd, backlog ) == -1 ) { - perror( "listen" ); - close(sockfd); - return -1; - } - - return sockfd; -} - diff --git a/tools/purge/socket.hh b/tools/purge/socket.hh deleted file mode 100644 index ec3d6af399..0000000000 --- a/tools/purge/socket.hh +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: socket.hh -// Sun May 3 1998 -// -// (c) 1998 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Books: W. Richard Steven, "Advanced Programming in the UNIX Environment", -// Addison-Wesley, 1992. -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.3 1999/01/19 11:00:50 voeckler -// added bool type workaround. -// -// Revision 1.2 1998/08/27 15:23:24 voeckler -// added TCP_NODELAY options at several places. -// -// Revision 1.1 1998/08/13 21:52:55 voeckler -// Initial revision -// -// -#ifndef _SOCKET_HH -#define _SOCKET_HH - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL -typedef int bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -#include -#include -#include - -#if SOMAXCONN <= 5 -#undef SOMAXCONN -#endif - -#ifndef SOMAXCONN -#if defined(SOLARIS) -#if MAJOR < 5 -#define SOMAXCONN 32 -#else -#define SOMAXCONN 128 -#endif -#elif defined(LINUX) -#define SOMAXCONN 128 -#else -#define SOMAXCONN 5 // BSD -#endif // OS selection -#endif // !SOMAXCONN - -#ifndef SA -#define SA struct sockaddr -#endif - -int -setSocketBuffers( int fd, int size ); - // purpose: set socket buffers for both directions to the specified size - // paramtr: size (IN): new socket buffer size - // returns: -1 on setsockopt() errors, 0 otherwise - // warning: prints error message on stderr, errno will be changed - -int -getSocketNoDelay( int sockfd ); - // purpose: get state of the TCP_NODELAY of the socket - // paramtr: sockfd (IN): socket descriptor - // returns: 1, if TCP_NODELAY is set, - // 0, if TCP_NODELAY is not set, - // -1, if an error occurred (e.g. datagram socket) - - -int -setSocketNoDelay( int sockfd, bool nodelay = true ); - // purpose: get state of the TCP_NODELAY of the socket - // paramtr: sockfd (IN): socket descriptor - // nodelay (IN): true, if TCP_NODELAY is to be set, false otherwise. - // returns: 0, if everything worked out o.k. - // -1, if an error occurred (e.g. datagram socket) - -int -connectTo( struct in_addr host, unsigned short port, bool nodelay = false, - int sendBufferSize = -1, int recvBufferSize = -1 ); - // purpose: connect to a server as a client - // paramtr: host (IN): address describing the server - // port (IN): port to connect at the server - // nodelay (IN): true=set TCP_NODELAY option. - // sendBufferSize (IN): don't set (use sys defaults) if < 0 - // recvBufferSize (IN): don't set (use sys defaults) if < 0 - // returns: >=0 is the descriptor of the opened, connected socket, - // -1 is an indication of an error (errno may have been reset). - -int -serverSocket( struct in_addr host, unsigned short port, - int backlog = SOMAXCONN, bool reuse = true, bool nodelay = false, - int sendBufferSize = -1, int recvBufferSize = -1 ); - // purpose: open a server socket for listening - // paramtr: host (IN): host to bind locally to, use INADDRY_ANY for * - // port (IN): port to bind to, use 0 for system assigned - // backlog (IN): listen backlog queue length - // reuse (IN): set SO_REUSEADDR option - default usefully - // nodelay (IN): true=set TCP_NODELAY option. - // SETTING TCP_NODELAY ON A SERVER SOCKET DOES NOT MAKE SENSE! - // sendBufferSize (IN): don't set (use sys defaults) if < 0 - // recvBufferSize (IN): don't set (use sys defaults) if < 0 - // returns: opened listening fd, or -1 on error. - // warning: error message will be printed on stderr and errno reset. - -#endif // _SOCKET_HH diff --git a/tools/purge/squid-tlv.cc b/tools/purge/squid-tlv.cc deleted file mode 100644 index 47f03c0667..0000000000 --- a/tools/purge/squid-tlv.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: squid-tlv.cc -// Tue Jun 15 1999 -// -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.1 1999/06/15 21:10:16 voeckler -// Initial revision -// - -#include "squid.h" -#include "squid-tlv.hh" - -SquidTLV::SquidTLV( SquidMetaType _type, size_t _size, void* _data ) - :next(nullptr),size(_size) -{ - type = _type; - data = (char*) _data; -} - -SquidMetaList::SquidMetaList() -{ - head = tail = nullptr; -} - -SquidMetaList::~SquidMetaList() -{ - for ( SquidTLV* temp = head; temp; temp = head ) { - head = temp->next; - delete temp; - } -} - -void -SquidMetaList::append( SquidMetaType type, size_t size, void* data ) -{ - SquidTLV* temp = new SquidTLV( type, size, data ); - if ( head == nullptr ) head = tail = temp; - else { - tail->next = temp; - tail = temp; - } -} - -const SquidTLV* -SquidMetaList::search( SquidMetaType type ) const -{ - const SquidTLV* temp = head; - while ( temp && temp->type != type ) temp = temp->next; - return temp; -} - diff --git a/tools/purge/squid-tlv.hh b/tools/purge/squid-tlv.hh deleted file mode 100644 index df8dcb7ff7..0000000000 --- a/tools/purge/squid-tlv.hh +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 1996-2023 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -// Author: Jens-S. V?ckler -// -// File: squid-tlv.hh -// Tue Jun 15 1999 -// -// (c) 1999 Lehrgebiet Rechnernetze und Verteilte Systeme -// Universit?t Hannover, Germany -// -// Permission to use, copy, modify, distribute, and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that (i) the above copyright notices and this permission -// notice appear in all copies of the software and related documentation, -// and (ii) the names of the Lehrgebiet Rechnernetze und Verteilte -// Systeme and the University of Hannover may not be used in any -// advertising or publicity relating to the software without the -// specific, prior written permission of Lehrgebiet Rechnernetze und -// Verteilte Systeme and the University of Hannover. -// -// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -// -// IN NO EVENT SHALL THE LEHRGEBIET RECHNERNETZE UND VERTEILTE SYSTEME OR -// THE UNIVERSITY OF HANNOVER BE LIABLE FOR ANY SPECIAL, INCIDENTAL, -// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT -// ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, -// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -// SOFTWARE. -// -// Revision 1.1 1999/06/15 21:10:16 voeckler -// Initial revision -// -#ifndef SQUID_TLV_HH -#define SQUID_TLV_HH - -#if !defined(__cplusplus) -#ifndef HAVE_BOOL -#define HAVE_BOOL -typedef int bool; -#define false 0 -#define true 1 -#endif -#endif /* __cplusplus */ - -#include -#include -#include -#include - -// taken from Squid-2.x -// NOTE! We must preserve the order of this list! -enum SquidMetaType { - STORE_META_VOID, // should not come up - STORE_META_KEY_URL, // key w/ keytype - STORE_META_KEY_SHA, - STORE_META_KEY_MD5, - STORE_META_URL, // the url , if not in the header - STORE_META_STD, // standard metadata - STORE_META_HITMETERING, // reserved for hit metering - STORE_META_VALID, - STORE_META_VARY_HEADERS, // Stores Vary request headers - STORE_META_STD_LFS, // standard metadata in lfs format - STORE_META_OBJSIZE // object size, if its known -}; - -// taken from Squid-2.x -struct StoreMetaStd { - time_t timestamp; - time_t lastref; - time_t expires; - time_t lastmod; - size_t swap_file_sz; - uint16_t refcount; - uint16_t flags; -}; - -struct StoreMetaStdLFS { - time_t timestamp; - time_t lastref; - time_t expires; - time_t lastmod; - uint64_t swap_file_sz; - uint16_t refcount; - uint16_t flags; -}; - -struct SquidTLV { - // create a shallow reference pointing into the "buffer" variable - // do not copy --> saves times, saves memory. - SquidTLV( SquidMetaType _type, size_t _size = 0, void* _data = nullptr ); - ~SquidTLV() {} - - SquidTLV* next; - size_t size; - SquidMetaType type; - char* data; -}; - -class SquidMetaList { -public: - SquidMetaList(); - ~SquidMetaList(); - - void append( SquidMetaType type, size_t size, void* data ); - const SquidTLV* search( SquidMetaType type ) const; - -private: - SquidTLV* head; - SquidTLV* tail; -}; - -#endif // SQUID_TLV_HH