00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <stdio.h>
00023 #include <errno.h>
00024
00025 #ifdef HAVE_SYS_TYPES_H
00026 #include <sys/types.h>
00027 #endif
00028
00029 #include <sys/socket.h>
00030
00031 #ifdef HAVE_STRING_H
00032 #include <string.h>
00033 #endif
00034
00035 #ifdef HAVE_NETINET_IN_H
00036 #include <netinet/in.h>
00037 #endif
00038
00039 #ifdef HAVE_ARPA_INET_H
00040 #include <arpa/inet.h>
00041 #endif
00042
00043
00044 #include "protocol.h"
00045
00063 int check_dwp(Port_T p) {
00064
00065 #define REQ_LENGTH 1024
00066
00067 int n;
00068 int status;
00069 char buf[STRLEN];
00070 char proto[STRLEN];
00071 char request[REQ_LENGTH];
00072
00073 ASSERT(p);
00074
00075 snprintf(request, REQ_LENGTH,
00076 "HEAD / HTTP/1.1\r\n"
00077 "Connection: close\r\n\r\n");
00078
00079 if(port_send(p, request, strlen(request), 0) < 0) {
00080 log("DWP: error sending data -- %s\n", STRERROR);
00081 return FALSE;
00082 }
00083
00084 if(port_recv(p, buf, sizeof(buf), 0) <= 0) {
00085 log("DWP: error receiving data -- %s\n", STRERROR);
00086 return FALSE;
00087 }
00088
00089 chomp(buf);
00090
00091 n= sscanf(buf, "%s %d", proto, &status);
00092 if(n!=2 || (status >= 400)) {
00093 log("DWP error: %s\n", buf);
00094 return FALSE;
00095 }
00096
00097 return TRUE;
00098
00099 }
00100