--------------------- PatchSet 1130 Date: 2001/01/06 19:16:13 Author: hno Branch: nt-2_4 Tag: (none) Log: Ported changes from nt-2_3 Members: include/psapi.h:1.1.2.1->1.1.2.2(DEAD) src/ssl.c:1.3->1.3.24.1 src/store_dir.c:1.4.4.1->1.4.4.1.2.1 src/structs.h:1.6.2.3->1.6.2.3.2.1 src/test_cache_digest.c:1.4->1.4.14.1 src/tools.c:1.3.4.1->1.3.4.1.2.1 src/typedefs.h:1.3.4.1->1.3.4.1.2.1 src/wais.c:1.3->1.3.24.1 src/wccp.c:1.3->1.3.16.1 src/win32.c:1.1->1.1.4.1 --- squid/include/psapi.h Wed Feb 14 00:48:06 2007 +++ /dev/null Wed Feb 14 00:45:56 2007 @@ -1,253 +0,0 @@ -/*++ BUILD Version: 0001 // Increment this if a change has global effects - -Copyright (c) 1994 Microsoft Corporation - -Module Name: - - psapi.h - -Abstract: - - Include file for APIs provided by PSAPI.DLL - -Author: - - Richard Shupak [richards] 06-Jan-1994 - -Revision History: - ---*/ - -#ifndef _PSAPI_H_ -#define _PSAPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -BOOL -WINAPI -EnumProcesses( - DWORD * lpidProcess, - DWORD cb, - DWORD * cbNeeded - ); - -BOOL -WINAPI -EnumProcessModules( - HANDLE hProcess, - HMODULE *lphModule, - DWORD cb, - LPDWORD lpcbNeeded - ); - -DWORD -WINAPI -GetModuleBaseNameA( - HANDLE hProcess, - HMODULE hModule, - LPSTR lpBaseName, - DWORD nSize - ); - -DWORD -WINAPI -GetModuleBaseNameW( - HANDLE hProcess, - HMODULE hModule, - LPWSTR lpBaseName, - DWORD nSize - ); - -#ifdef UNICODE -#define GetModuleBaseName GetModuleBaseNameW -#else -#define GetModuleBaseName GetModuleBaseNameA -#endif // !UNICODE - - -DWORD -WINAPI -GetModuleFileNameExA( - HANDLE hProcess, - HMODULE hModule, - LPSTR lpFilename, - DWORD nSize - ); - -DWORD -WINAPI -GetModuleFileNameExW( - HANDLE hProcess, - HMODULE hModule, - LPWSTR lpFilename, - DWORD nSize - ); - -#ifdef UNICODE -#define GetModuleFileNameEx GetModuleFileNameExW -#else -#define GetModuleFileNameEx GetModuleFileNameExA -#endif // !UNICODE - - -typedef struct _MODULEINFO { - LPVOID lpBaseOfDll; - DWORD SizeOfImage; - LPVOID EntryPoint; -} MODULEINFO, *LPMODULEINFO; - - -BOOL -WINAPI -GetModuleInformation( - HANDLE hProcess, - HMODULE hModule, - LPMODULEINFO lpmodinfo, - DWORD cb - ); - - -BOOL -WINAPI -EmptyWorkingSet( - HANDLE hProcess - ); - - -BOOL -WINAPI -QueryWorkingSet( - HANDLE hProcess, - PVOID pv, - DWORD cb - ); - -BOOL -WINAPI -InitializeProcessForWsWatch( - HANDLE hProcess - ); - - -typedef struct _PSAPI_WS_WATCH_INFORMATION { - LPVOID FaultingPc; - LPVOID FaultingVa; -} PSAPI_WS_WATCH_INFORMATION, *PPSAPI_WS_WATCH_INFORMATION; - -BOOL -WINAPI -GetWsChanges( - HANDLE hProcess, - PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, - DWORD cb - ); - -DWORD -WINAPI -GetMappedFileNameW( - HANDLE hProcess, - LPVOID lpv, - LPWSTR lpFilename, - DWORD nSize - ); - -DWORD -WINAPI -GetMappedFileNameA( - HANDLE hProcess, - LPVOID lpv, - LPSTR lpFilename, - DWORD nSize - ); - -#ifdef UNICODE -#define GetMappedFilenameEx GetMappedFilenameExW -#else -#define GetMappedFilenameEx GetMappedFilenameExA -#endif // !UNICODE - -BOOL -WINAPI -EnumDeviceDrivers( - LPVOID *lpImageBase, - DWORD cb, - LPDWORD lpcbNeeded - ); - - -DWORD -WINAPI -GetDeviceDriverBaseNameA( - LPVOID ImageBase, - LPSTR lpBaseName, - DWORD nSize - ); - -DWORD -WINAPI -GetDeviceDriverBaseNameW( - LPVOID ImageBase, - LPWSTR lpBaseName, - DWORD nSize - ); - -#ifdef UNICODE -#define GetDeviceDriverBaseName GetDeviceDriverBaseNameW -#else -#define GetDeviceDriverBaseName GetDeviceDriverBaseNameA -#endif // !UNICODE - - -DWORD -WINAPI -GetDeviceDriverFileNameA( - LPVOID ImageBase, - LPSTR lpFilename, - DWORD nSize - ); - -DWORD -WINAPI -GetDeviceDriverFileNameW( - LPVOID ImageBase, - LPWSTR lpFilename, - DWORD nSize - ); - -#ifdef UNICODE -#define GetDeviceDriverFileName GetDeviceDriverFileNameW -#else -#define GetDeviceDriverFileName GetDeviceDriverFileNameA -#endif // !UNICODE - -// Structure for GetProcessMemoryInfo() - -typedef struct _PROCESS_MEMORY_COUNTERS { - DWORD cb; - DWORD PageFaultCount; - DWORD PeakWorkingSetSize; - DWORD WorkingSetSize; - DWORD QuotaPeakPagedPoolUsage; - DWORD QuotaPagedPoolUsage; - DWORD QuotaPeakNonPagedPoolUsage; - DWORD QuotaNonPagedPoolUsage; - DWORD PagefileUsage; - DWORD PeakPagefileUsage; -} PROCESS_MEMORY_COUNTERS; -typedef PROCESS_MEMORY_COUNTERS *PPROCESS_MEMORY_COUNTERS; - -BOOL -WINAPI -GetProcessMemoryInfo( - HANDLE Process, - PPROCESS_MEMORY_COUNTERS ppsmemCounters, - DWORD cb - ); - -#ifdef __cplusplus -} -#endif - -#endif Index: squid/src/ssl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ssl.c,v retrieving revision 1.3 retrieving revision 1.3.24.1 diff -u -r1.3 -r1.3.24.1 --- squid/src/ssl.c 23 Oct 2000 15:04:22 -0000 1.3 +++ squid/src/ssl.c 6 Jan 2001 19:17:17 -0000 1.3.24.1 @@ -1,6 +1,6 @@ /* - * $Id: ssl.c,v 1.3 2000/10/23 15:04:22 hno Exp $ + * $Id: ssl.c,v 1.3.24.1 2001/01/06 19:17:17 hno Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -200,7 +200,11 @@ read_sz = delayBytesWanted(sslState->delay_id, 1, read_sz); #endif statCounter.syscalls.sock.reads++; +#ifdef _SQUID_MSWIN_ + len = recv(fd, sslState->server.buf + sslState->server.len, read_sz); +#else len = read(fd, sslState->server.buf + sslState->server.len, read_sz); +#endif debug(26, 3) ("sslReadServer: FD %d, read %d bytes\n", fd, len); if (len > 0) { fd_bytes(fd, len, FD_READ); @@ -236,9 +240,13 @@ fd, SQUID_TCP_SO_RCVBUF - sslState->client.len, sslState->client.len); statCounter.syscalls.sock.reads++; +#ifdef _SQUID_MSWIN_ + len = recv(fd, sslState->client.buf + sslState->client.len, SQUID_TCP_SO_RCVBUF - sslState->client.len); +#else len = read(fd, sslState->client.buf + sslState->client.len, SQUID_TCP_SO_RCVBUF - sslState->client.len); +#endif debug(26, 3) ("sslReadClient: FD %d, read %d bytes\n", fd, len); if (len > 0) { fd_bytes(fd, len, FD_READ); @@ -248,12 +256,19 @@ cbdataLock(sslState); if (len < 0) { int level = 1; +#ifdef _SQUID_MSWIN_ + if (WSAECONNRESET == WSAGetLastError()) + level = 2; + if (WSAignoreErrno(WSAGetLastError()) + level = 3; +#else #ifdef ECONNRESET if (errno == ECONNRESET) level = 2; #endif if (ignoreErrno(errno)) level = 3; +#endif /* _SQUID_MSWIN_ */ debug(50, level) ("sslReadClient: FD %d: read failure: %s\n", fd, xstrerror()); if (!ignoreErrno(errno)) @@ -276,9 +291,13 @@ debug(26, 3) ("sslWriteServer: FD %d, %d bytes to write\n", fd, sslState->client.len); statCounter.syscalls.sock.writes++; +#ifdef _SQUID_MSWIN_ + len = send(fd, sslState->client.buf, sslState->client.len); +#else len = write(fd, sslState->client.buf, sslState->client.len); +#endif debug(26, 3) ("sslWriteServer: FD %d, %d bytes written\n", fd, len); if (len > 0) { fd_bytes(fd, len, FD_WRITE); @@ -315,9 +334,13 @@ debug(26, 3) ("sslWriteClient: FD %d, %d bytes to write\n", fd, sslState->server.len); statCounter.syscalls.sock.writes++; +#ifdef _SQUID_MSWIN_ + len = send(fd, sslState->server.buf, sslState->server.len); +#else len = write(fd, sslState->server.buf, sslState->server.len); +#endif debug(26, 3) ("sslWriteClient: FD %d, %d bytes written\n", fd, len); if (len > 0) { fd_bytes(fd, len, FD_WRITE); @@ -468,7 +491,11 @@ statCounter.server.other.requests++; /* Create socket. */ sock = comm_open(SOCK_STREAM, +#ifdef _SQUID_MSWIN_ + IPPROTO_TCP, +#else 0, +#endif Config.Addrs.tcp_outgoing, 0, COMM_NONBLOCKING, Index: squid/src/store_dir.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_dir.c,v retrieving revision 1.4.4.1 retrieving revision 1.4.4.1.2.1 diff -u -r1.4.4.1 -r1.4.4.1.2.1 --- squid/src/store_dir.c 6 Jan 2001 13:32:44 -0000 1.4.4.1 +++ squid/src/store_dir.c 6 Jan 2001 19:17:17 -0000 1.4.4.1.2.1 @@ -1,6 +1,6 @@ /* - * $Id: store_dir.c,v 1.4.4.1 2001/01/06 13:32:44 hno Exp $ + * $Id: store_dir.c,v 1.4.4.1.2.1 2001/01/06 19:17:17 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -81,12 +81,15 @@ pid_t pid; int status; for (i = 0; i < Config.cacheSwap.n_configured; i++) { +#ifndef _SQUID_MSWIN_ if (fork()) continue; +#endif sd = &Config.cacheSwap.swapDirs[i]; sd->newfs(sd); exit(0); } +#ifndef _SQUID_MSWIN_ do { #ifdef _SQUID_NEXT_ pid = wait3(&status, WNOHANG, NULL); @@ -94,6 +97,7 @@ pid = waitpid(-1, &status, 0); #endif } while (pid > 0 || (pid < 0 && errno == EINTR)); +#endif } /* Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.3.2.1 diff -u -r1.6.2.3 -r1.6.2.3.2.1 --- squid/src/structs.h 6 Jan 2001 13:32:45 -0000 1.6.2.3 +++ squid/src/structs.h 6 Jan 2001 19:17:17 -0000 1.6.2.3.2.1 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.6.2.3 2001/01/06 13:32:45 hno Exp $ + * $Id: structs.h,v 1.6.2.3.2.1 2001/01/06 19:17:17 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -584,10 +584,54 @@ int weak; /* true if it is a weak validator */ }; +#ifdef _SQUID_MSWIN_ +struct _sde { + unsigned int type; + u_short local_port; + u_short remote_port; + char ipaddr[16]; /* dotted decimal address of peer */ + char desc[FD_DESC_SZ]; + struct { + unsigned int open:1; + unsigned int close_request:1; + unsigned int write_daemon:1; + unsigned int closing:1; + unsigned int socket_eof:1; + unsigned int nolinger:1; + unsigned int nonblocking:1; + unsigned int ipc:1; + unsigned int called_connect:1; +#ifdef OPTIMISTIC_IO + unsigned int calling_io_handler:1; +#endif + } flags; + int bytes_read; + int bytes_written; + int uses; /* ie # req's over persistent conn */ + PF *read_handler; + void *read_data; + PF *write_handler; + void *write_data; + PF *timeout_handler; + time_t timeout; + void *timeout_data; + void *lifetime_data; + close_handler *close_handler; /* linked list */ + DEFER *defer_check; /* check if we should defer read */ + void *defer_data; + CommWriteStateData *rwstate; /* State data for comm_write */ +}; + +#endif + + struct _fde { unsigned int type; u_short local_port; u_short remote_port; +#ifdef _SQUID_MSWIN_ + FILE *fbuf; +#endif char ipaddr[16]; /* dotted decimal address of peer */ char desc[FD_DESC_SZ]; struct { Index: squid/src/test_cache_digest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/test_cache_digest.c,v retrieving revision 1.4 retrieving revision 1.4.14.1 diff -u -r1.4 -r1.4.14.1 --- squid/src/test_cache_digest.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/test_cache_digest.c 6 Jan 2001 19:17:18 -0000 1.4.14.1 @@ -1,6 +1,6 @@ /* - * $Id: test_cache_digest.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: test_cache_digest.c,v 1.4.14.1 2001/01/06 19:17:18 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -37,7 +37,7 @@ */ #include "squid.h" - +#include "hash.h" typedef struct { int query_count; int true_hit_count; Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.3.4.1 retrieving revision 1.3.4.1.2.1 diff -u -r1.3.4.1 -r1.3.4.1.2.1 --- squid/src/tools.c 6 Jan 2001 13:32:45 -0000 1.3.4.1 +++ squid/src/tools.c 6 Jan 2001 19:17:18 -0000 1.3.4.1.2.1 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.3.4.1 2001/01/06 13:32:45 hno Exp $ + * $Id: tools.c,v 1.3.4.1.2.1 2001/01/06 19:17:18 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -34,7 +34,10 @@ */ #include "squid.h" - +#ifdef _SQUID_MSWIN_ +#include +#include +#endif #define DEAD_MSG "\ The Squid Cache (version %s) died.\n\ \n\ @@ -69,12 +72,24 @@ /* Release the main ports as early as possible */ for (i = 0; i < NHttpSockets; i++) { if (HttpSockets[i] >= 0) +#ifdef _SQUID_MSWIN_ + closesocket(HttpSockets[i]); +#else close(HttpSockets[i]); +#endif } if (theInIcpConnection >= 0) +#ifdef _SQUID_MSWIN_ + closesocket(theInIcpConnection); +#else close(theInIcpConnection); +#endif if (theOutIcpConnection >= 0 && theOutIcpConnection != theInIcpConnection) +#ifdef _SQUID_MSWIN_ + closesocket(theOutIcpConnection); +#else close(theOutIcpConnection); +#endif } static char * @@ -168,7 +183,29 @@ void squid_getrusage(struct rusage *r) { +#ifdef _SQUID_MSWIN_PSAPI + HANDLE hProcess; + PROCESS_MEMORY_COUNTERS pmc; + FILETIME ftCreate, ftExit, ftKernel, ftUser; +#endif memset(r, '\0', sizeof(struct rusage)); +#ifdef _SQUID_MSWIN_PSAPI + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | + PROCESS_VM_READ, + FALSE, GetCurrentProcessId()); + + if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) { + LONGLONG tUser64 = *(LONGLONG *) & ftUser; + LONGLONG tKernel64 = *(LONGLONG *) & ftKernel; + r->ru_utime.tv_usec = (DWORD) (tUser64 / 10); + r->ru_stime.tv_usec = (DWORD) (tKernel64 / 10); + } + if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) { + r->ru_maxrss = (DWORD) (pmc.WorkingSetSize / 1024); + r->ru_majflt = pmc.PageFaultCount; + } + CloseHandle(hProcess); +#else #if HAVE_GETRUSAGE && defined(RUSAGE_SELF) #ifdef _SQUID_SOLARIS_ /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */ @@ -179,6 +216,7 @@ leave_suid(); #endif #endif +#endif } double @@ -410,6 +448,7 @@ void sig_child(int sig) { +#ifndef _SQUID_MSWIN_ #ifdef _SQUID_NEXT_ union wait status; #else @@ -430,6 +469,7 @@ } while (pid > 0 || (pid < 0 && errno == EINTR)); signal(sig, sig_child); #endif +#endif } const char * @@ -506,6 +546,7 @@ leave_suid(void) { debug(21, 3) ("leave_suid: PID %d called\n", getpid()); +#ifndef _SQUID_MSWIN_ if (geteuid() != 0) return; /* Started as a root, check suid option */ @@ -528,18 +569,21 @@ if (setuid(Config2.effectiveUserID) < 0) debug(50, 0) ("ALERT: setuid: %s\n", xstrerror()); #endif +#endif } /* Enter a privilegied section */ void enter_suid(void) { +#ifndef _SQUID_MSWIN_ debug(21, 3) ("enter_suid: PID %d taking root priveleges\n", getpid()); #if HAVE_SETRESUID setresuid(-1, 0, -1); #else setuid(0); #endif +#endif } /* Give up the posibility to gain privilegies. @@ -548,6 +592,7 @@ void no_suid(void) { +#ifndef _SQUID_MSWIN_ uid_t uid; leave_suid(); uid = geteuid(); @@ -560,6 +605,7 @@ if (setuid(uid) < 0) debug(50, 1) ("no_suid: setuid: %s\n", xstrerror()); #endif +#endif } void @@ -682,6 +728,18 @@ #endif /* RLIMIT_VMEM */ } +#ifdef _SQUID_MSWIN_ +void +gettimeofday(struct timeval *pcur_time, void *tz) +{ + struct _timeb current; + _ftime(¤t); + pcur_time->tv_sec = current.time; + pcur_time->tv_usec = current.millitm * 1000; +} + +#endif + time_t getCurrentTime(void) { @@ -898,6 +956,9 @@ xrename(const char *from, const char *to) { debug(21, 2) ("xrename: renaming %s to %s\n", from, to); +#ifdef _SQUID_MSWIN_ + remove(to); +#endif if (0 == rename(from, to)) return 0; debug(21, errno == ENOENT ? 2 : 1) ("xrename: Cannot rename %s to %s: %s\n", Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.3.4.1 retrieving revision 1.3.4.1.2.1 diff -u -r1.3.4.1 -r1.3.4.1.2.1 --- squid/src/typedefs.h 14 Nov 2000 13:33:29 -0000 1.3.4.1 +++ squid/src/typedefs.h 6 Jan 2001 19:17:18 -0000 1.3.4.1.2.1 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.3.4.1 2000/11/14 13:33:29 adri Exp $ + * $Id: typedefs.h,v 1.3.4.1.2.1 2001/01/06 19:17:18 hno Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -84,6 +84,9 @@ typedef struct _dwrite_q dwrite_q; typedef struct _ETag ETag; typedef struct _fde fde; +#ifdef _SQUID_MSWIN_ +typedef struct _sde sde; +#endif typedef struct _fileMap fileMap; typedef struct _HttpReply http_reply; typedef struct _HttpStatusLine HttpStatusLine; Index: squid/src/wais.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wais.c,v retrieving revision 1.3 retrieving revision 1.3.24.1 diff -u -r1.3 -r1.3.24.1 --- squid/src/wais.c 23 Oct 2000 15:04:22 -0000 1.3 +++ squid/src/wais.c 6 Jan 2001 19:17:18 -0000 1.3.24.1 @@ -1,6 +1,6 @@ /* - * $Id: wais.c,v 1.3 2000/10/23 15:04:22 hno Exp $ + * $Id: wais.c,v 1.3.24.1 2001/01/06 19:17:18 hno Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -103,7 +103,11 @@ read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif statCounter.syscalls.sock.reads++; +#ifdef _SQUID_MSWIN_ + len = recv(fd, buf, read_sz); +#else len = read(fd, buf, read_sz); +#endif if (len > 0) { fd_bytes(fd, len, FD_READ); #if DELAY_POOLS Index: squid/src/wccp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wccp.c,v retrieving revision 1.3 retrieving revision 1.3.16.1 diff -u -r1.3 -r1.3.16.1 --- squid/src/wccp.c 23 Oct 2000 15:04:22 -0000 1.3 +++ squid/src/wccp.c 6 Jan 2001 19:17:18 -0000 1.3.16.1 @@ -1,6 +1,6 @@ /* - * $Id: wccp.c,v 1.3 2000/10/23 15:04:22 hno Exp $ + * $Id: wccp.c,v 1.3.16.1 2001/01/06 19:17:18 hno Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Glenn Chisholm @@ -32,6 +32,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ + #include "squid.h" #if USE_WCCP @@ -125,7 +126,11 @@ return; } theInWccpConnection = comm_open(SOCK_DGRAM, +#ifdef _SQUID_MSWIN_ + IPPROTO_UDP, +#else 0, +#endif Config.Wccp.incoming, port, COMM_NONBLOCKING, @@ -141,7 +146,11 @@ (int) port, theInWccpConnection); if (Config.Wccp.outgoing.s_addr != no_addr.s_addr) { theOutWccpConnection = comm_open(SOCK_DGRAM, +#ifdef _SQUID_MSWIN_ + IPPROTO_UDP, +#else 0, +#endif Config.Wccp.outgoing, port, COMM_NONBLOCKING, @@ -262,7 +271,7 @@ wccp_here_i_am.id = wccp_i_see_you.id; send(theOutWccpConnection, - &wccp_here_i_am, + (void *)&wccp_here_i_am, sizeof(wccp_here_i_am), 0); --- /dev/null Wed Feb 14 00:45:56 2007 +++ squid/src/win32.c Wed Feb 14 00:48:06 2007 @@ -0,0 +1,290 @@ +#include "squid.h" + +static int s_iInitCount = 0; +#define VENDOR "Nobody.org" +#define SOFTWARE "SquidNT" +#define VERSION "2.3Stable4 beta" +#define REGKEY "SOFTWARE\\" VENDOR "\\" SOFTWARE "\\" VERSION +TCHAR servname[512]=SQUID_SERVICE_NAME; + +SERVICE_STATUS svcStatus; + +static int create_key(void) +{ + static char *keys[] = + { "SOFTWARE", + VENDOR, + SOFTWARE, + VERSION, + NULL + }; + int index; + HKEY hKey; + HKEY hKeyNext; + int retval; + int rv; + + hKey = HKEY_LOCAL_MACHINE; + index = 0; + retval = 0; + + /* Walk the tree, creating at each stage if necessary */ + while (keys[index]) { + unsigned long result; + + rv = RegCreateKeyEx(hKey, + keys[index], /* subkey */ + 0, /* reserved */ + NULL, /* class */ + REG_OPTION_NON_VOLATILE, + KEY_WRITE, + NULL, + &hKeyNext, + &result); + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegCreateKeyEx(%s),%d\n", keys[index],rv); + retval = -4; + } + + /* Close the old key */ + rv = RegCloseKey(hKey); + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegCloseKey %d\n", rv); + if (retval == 0) { + /* Keep error status from RegCreateKeyEx, if any */ + retval = -4; + } + } + + if (retval) { + break; + } + + hKey = hKeyNext; + index++; + } + + if (keys[index] == NULL) { + /* Close the final key we opened, if we walked the entire + * tree + */ + rv = RegCloseKey(hKey); + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegCloseKey %d\n", rv); + if (retval == 0) { + /* Keep error status from RegCreateKeyEx, if any */ + retval = -4; + } + } + } + + return retval; +} + +static int store_key(const char *key, DWORD type, unsigned char *value, int value_size) +{ + long rv; + HKEY hKey; + int retval; + + rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + REGKEY, + 0, + KEY_WRITE, + &hKey); + + if (rv == ERROR_FILE_NOT_FOUND) { + /* Key could not be opened -- try to create it + */ + if (create_key() < 0) { + /* Creation failed (error already reported) */ + return -4; + } + + /* Now it has been created we should be able to open it + */ + rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + REGKEY, + 0, + KEY_WRITE, + &hKey); + + if (rv == ERROR_FILE_NOT_FOUND) { + debug(1,1)("Registry does not contain key %s after creation",REGKEY ); + return -1; + } + } + + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegOpenKeyEx HKLM\\%s, %d\n", REGKEY,rv); + return -4; + } + + /* Now set the value and data */ + rv = RegSetValueEx(hKey, + key, /* value key name */ + 0, /* reserved */ + type, /* type */ + value, /* value data */ + (DWORD)value_size); /* for size of "value" */ + + retval = 0; /* Return value */ + + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegQueryValueEx(key %s),%d\n",key,rv); + retval = -4; + } + else { + debug(1,1)("Registry stored HKLM\\%s\\%s value %s\n", + REGKEY, + key, + type == REG_SZ ? value : (unsigned char*)"(not displayable)"); + } + + /* Make sure we close the key even if there was an error storing + * the data + */ + rv = RegCloseKey(hKey); + if (rv != ERROR_SUCCESS) { + debug(1,1)("RegCloseKey HKLM\\%s, %d\n", REGKEY,rv); + if (retval == 0) { + /* Keep error status from RegQueryValueEx, if any */ + retval = -4; + } + } + + return retval; +} + +void RemoveService() +{ + SC_HANDLE schService; + SC_HANDLE schSCManager; + schSCManager = OpenSCManager( + NULL, // machine (NULL == local) + NULL, // database (NULL == default) + SC_MANAGER_ALL_ACCESS // access required + ); + if (!schSCManager) debug(1,1)("OpenSCManager failed"); + else { + schService = OpenService(schSCManager, servname, SERVICE_ALL_ACCESS); + + if (schService == NULL) debug(1,1)("OpenService failed"); + /* Could not open the service */ + else { + /* try to stop the service */ + if (ControlService(schService, SERVICE_CONTROL_STOP, &svcStatus)) { + Sleep(1000); + while(QueryServiceStatus(schService, &svcStatus)) { + if(svcStatus.dwCurrentState == SERVICE_STOP_PENDING) + Sleep(1000); + else + break; + } + } + + // now remove the service + if (DeleteService(schService) == 0) debug(1,1)("DeleteService failed"); + else printf("Service SquidNT2.3stable4 beta deleted successfuly, see ya'round :)\n"); + + CloseServiceHandle(schService); + } + + CloseServiceHandle(schSCManager); + } + +} + +void InstallService() +{ + SC_HANDLE schService; + SC_HANDLE schSCManager; + + TCHAR szPath[512]; + int lenpath; + if ((lenpath=GetModuleFileName( NULL, szPath, 512 )) == 0) + { + exit(1); + return; + } + + schSCManager = OpenSCManager( + NULL, // machine (NULL == local) + NULL, // database (NULL == default) + SC_MANAGER_ALL_ACCESS // access required + ); + if (!schSCManager) debug(1,1)("OpenSCManager failed"); + else { + schService = CreateService( + schSCManager, // SCManager database + servname, // name of service + servname, // name to display + SERVICE_ALL_ACCESS, // desired access + SERVICE_WIN32_OWN_PROCESS, // service type + SERVICE_AUTO_START, // start type + SERVICE_ERROR_NORMAL, // error control type + (const char*)szPath, // service's binary + NULL, // no load ordering group + NULL, // no tag identifier + NULL, // dependencies + NULL, // LocalSystem account + NULL); // no password + + if (schService) { + CloseServiceHandle(schService); + + /* Now store the server_root in the registry */ + store_key("ServerRoot", REG_SZ,(unsigned char*) szPath, lenpath+1); + printf("Service SquidNT2.3 stable4 beta installed successfuly, enjoy :)\n"); + printf("that is, u may start it from the Services applet of control panel\n"); + printf("Don't forget to edit squid.conf before starting it\n\n"); + printf("Romeo Anghelache, http://www.andrew.cmu.edu/~romeo/ \n"); + printf("Guido Serassio, http://serassio.interfree.it \n"); + printf("No warranties of any kind, no time for support!\n"); + printf("This work derived from GNU Squid2.3 stable 4\n"); + } + else debug(1,1)("CreateService failed"); + + CloseServiceHandle(schSCManager); + } +} + +int Win32SockInit(void) +{ + int iVersionRequested; + WSADATA wsaData; + int err; + + if (s_iInitCount > 0) { + s_iInitCount++; + return (0); + } + else if (s_iInitCount < 0) + return (s_iInitCount); + + /* s_iInitCount == 0. Do the initailization */ + iVersionRequested = MAKEWORD(2, 0); + err = WSAStartup((WORD) iVersionRequested, &wsaData); + if (err) { + s_iInitCount = -1; + return (s_iInitCount); + } + if (LOBYTE(wsaData.wVersion) != 2 || + HIBYTE(wsaData.wVersion) != 0) { + s_iInitCount = -2; + WSACleanup(); + return (s_iInitCount); + } + debug(1,1)("Windows sockets initialised"); + s_iInitCount++; + return (s_iInitCount); + +} + + +void Win32SockCleanup(void) +{ + if (--s_iInitCount == 0) + WSACleanup(); + return; +}