/*
- * $Id: cachemgr.cc,v 1.2 2006/05/12 16:05:10 hno Exp $
+ * $Id: cachemgr.cc,v 1.3 2006/09/10 20:08:20 serassio Exp $
*
* DEBUG: section 0 CGI Cache Manager
* AUTHOR: Duane Wessels
static void error_html(const char *msg);
static char *menu_url(cachemgr_request * req, const char *action);
static int parse_status_line(const char *sline, const char **statusStr);
-#ifdef _SQUID_MSWIN_
-static cachemgr_request *read_request(char *);
-#else
static cachemgr_request *read_request(void);
-#endif
static char *read_get_request(void);
static char *read_post_request(void);
#ifdef _SQUID_MSWIN_
static int s_iInitCount = 0;
+
int Win32SockInit(void)
{
int iVersionRequested;
#ifdef _SQUID_MSWIN_
int reply;
- FILE *fp = tmpfile();
+ char *tmpfile = tempnam(NULL, "tmp0000");
+ FILE *fp = fopen(tmpfile, "w+");
#else
FILE *fp = fdopen(s, "r");
parse_menu = 1;
if (fp == NULL) {
+#ifdef _SQUID_MSWIN_
+ perror(tmpfile);
+ xfree(tmpfile);
+#else
+
perror("fdopen");
+#endif
+
+ close(s);
return 1;
}
while ((reply=recv(s, buf , sizeof(buf), 0)) > 0)
fwrite(buf, 1, reply, fp);
- close(s);
rewind(fp);
#endif
}
fclose(fp);
+#ifdef _SQUID_MSWIN_
+
+ remove(tmpfile);
+ xfree(tmpfile);
+ close(s);
+
+#endif
+
return 0;
}
static struct sockaddr_in S;
int s;
int l;
-#ifdef _SQUID_MSWIN_
-
- int answer;
-#endif
static char buf[2 * 1024];
make_auth_header(req));
write(s, buf, l);
debug(1) fprintf(stderr, "wrote request: '%s'\n", buf);
-#ifdef _SQUID_MSWIN_
-
- answer=read_reply(s, req);
- close(s);
- return answer;
-#else
-
return read_reply(s, req);
-#endif
}
int
{
char *s;
cachemgr_request *req;
-#ifdef _SQUID_MSWIN_
-
- int answer;
-#endif
safe_inet_addr("255.255.255.255", &no_addr);
now = time(NULL);
#ifdef _SQUID_MSWIN_
Win32SockInit();
-
+ atexit(Win32SockCleanup);
_setmode( _fileno( stdin ), _O_BINARY );
_setmode( _fileno( stdout ), _O_BINARY );
_fmode = _O_BINARY;
if ((s = getenv("SCRIPT_NAME")) != NULL)
script_name = xstrdup(s);
-#ifdef _SQUID_MSWIN_
-
- req = read_request(NULL);
-
- answer=process_request(req);
-
- Win32SockCleanup();
-
- return answer;
-
-#else
-
req = read_request();
return process_request(req);
-
-#endif
}
static char *
return xstrdup(s);
}
-#ifdef _SQUID_MSWIN_
static cachemgr_request *
-read_request(char* buf)
+read_request(void)
{
-#else
-static cachemgr_request *
-read_request(void) {
char *buf;
-#endif
cachemgr_request *req;
char *s;
* Currently no powerful encryption is used.
*/
static void
-make_pub_auth(cachemgr_request * req) {
+make_pub_auth(cachemgr_request * req)
+{
static char buf[1024];
safe_free(req->pub_auth);
debug(3) fprintf(stderr, "cmgr: encoding for pub...\n");
}
static void
-decode_pub_auth(cachemgr_request * req) {
+decode_pub_auth(cachemgr_request * req)
+{
char *buf;
const char *host_name;
const char *time_str;
}
static void
-reset_auth(cachemgr_request * req) {
+reset_auth(cachemgr_request * req)
+{
safe_free(req->passwd);
safe_free(req->pub_auth);
}
static const char *
-make_auth_header(const cachemgr_request * req) {
+make_auth_header(const cachemgr_request * req)
+{
static char buf[1024];
size_t stringLength = 0;
const char *str64;
}
static int
-check_target_acl(const char *hostname, int port) {
+check_target_acl(const char *hostname, int port)
+{
char config_line[BUFSIZ];
FILE *fp = NULL;
int ret = 0;