#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
+#include <SystemConfiguration/SystemConfiguration.h>
#include "connect.h"
#include "rfc2553emu.h"
/*}}}*/
using namespace std;
+void CfrsError(CFReadStreamRef rs) {
+ CFStreamError se = CFReadStreamGetError(rs);
+
+ if (se.domain == kCFStreamErrorDomainCustom) {
+ } else if (se.domain == kCFStreamErrorDomainPOSIX) {
+ _error->Error("POSIX: %s", strerror(se.error));
+ } else if (se.domain == kCFStreamErrorDomainMacOSStatus) {
+ _error->Error("MacOSStatus: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainNetDB) {
+ _error->Error("NetDB: %s", gai_strerror(se.error));
+ } else if (se.domain == kCFStreamErrorDomainMach) {
+ _error->Error("Mach: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainHTTP) {
+ switch (se.error) {
+ case kCFStreamErrorHTTPParseFailure:
+ _error->Error("Parse failure");
+ break;
+
+ case kCFStreamErrorHTTPRedirectionLoop:
+ _error->Error("Redirection loop");
+ break;
+
+ case kCFStreamErrorHTTPBadURL:
+ _error->Error("Bad URL");
+ break;
+
+ default:
+ _error->Error("Unknown HTTP error: %ld", se.error);
+ break;
+ }
+ } else if (se.domain == kCFStreamErrorDomainSOCKS) {
+ _error->Error("SOCKS: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainSystemConfiguration) {
+ _error->Error("SystemConfiguration: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainSSL) {
+ _error->Error("SSL: %ld", se.error);
+ } else {
+ _error->Error("Domain #%d: %ld", se.domain, se.error);
+ }
+}
+
string HttpMethod::FailFile;
int HttpMethod::FailFd = -1;
time_t HttpMethod::FailTime = 0;
CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm);
CFRelease(hm);
+ CFDictionaryRef dr = SCDynamicStoreCopyProxies(NULL);
+ CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPProxy, dr);
+ CFRelease(dr);
+
CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
Status("Connecting to %s", uri.Host.c_str());
if (!CFReadStreamOpen(rs)) {
- _error->Error("Unable to open stream");
+ CfrsError(rs);
Fail(true);
goto done;
}
CFIndex rd = CFReadStreamRead(rs, data, sizeof(data));
if (rd == -1) {
- _error->Error("Stream read failure");
+ CfrsError(rs);
Fail(true);
goto done;
}
if (!CFStringGetCString(sr, cr, ln, se)) {
Fail();
- goto done;
+ goto done_;
}
CFRelease(sr);
if (sscanf(cr, "bytes %lu-%*u/%lu", &offset, &Res.Size) != 2) {
_error->Error(_("The HTTP server sent an invalid Content-Range header"));
Fail();
- goto done;
+ goto done_;
}
if (offset > Res.Size) {
_error->Error(_("This HTTP server has broken range support"));
Fail();
- goto done;
+ goto done_;
}
} else {
sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Length"));
if (!CFStringGetCString(sr, cr, ln, se)) {
Fail();
- goto done;
+ goto done_;
}
CFRelease(sr);
if (!StrToTime(cr, Res.LastModified)) {
_error->Error(_("Unknown date format"));
Fail();
- goto done;
+ goto done_;
}
}
URIStart(Res);
read: if (rd == -1) {
- _error->Error("Stream read failure");
+ CfrsError(rs);
Fail(true);
} else if (rd == 0) {
if (Res.Size == 0)
}
}
+ goto done;
+ done_:
+ CFRelease(hm);
done:
+ CFReadStreamClose(rs);
CFRelease(rs);
FailCounter = 0;
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
+#include <SystemConfiguration/SystemConfiguration.h>
#include "connect.h"
#include "rfc2553emu.h"
/*}}}*/
using namespace std;
+void CfrsError(CFReadStreamRef rs) {
+ CFStreamError se = CFReadStreamGetError(rs);
+
+ if (se.domain == kCFStreamErrorDomainCustom) {
+ } else if (se.domain == kCFStreamErrorDomainPOSIX) {
+ _error->Error("POSIX: %s", strerror(se.error));
+ } else if (se.domain == kCFStreamErrorDomainMacOSStatus) {
+ _error->Error("MacOSStatus: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainNetDB) {
+ _error->Error("NetDB: %s", gai_strerror(se.error));
+ } else if (se.domain == kCFStreamErrorDomainMach) {
+ _error->Error("Mach: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainHTTP) {
+ switch (se.error) {
+ case kCFStreamErrorHTTPParseFailure:
+ _error->Error("Parse failure");
+ break;
+
+ case kCFStreamErrorHTTPRedirectionLoop:
+ _error->Error("Redirection loop");
+ break;
+
+ case kCFStreamErrorHTTPBadURL:
+ _error->Error("Bad URL");
+ break;
+
+ default:
+ _error->Error("Unknown HTTP error: %ld", se.error);
+ break;
+ }
+ } else if (se.domain == kCFStreamErrorDomainSOCKS) {
+ _error->Error("SOCKS: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainSystemConfiguration) {
+ _error->Error("SystemConfiguration: %ld", se.error);
+ } else if (se.domain == kCFStreamErrorDomainSSL) {
+ _error->Error("SSL: %ld", se.error);
+ } else {
+ _error->Error("Domain #%d: %ld", se.domain, se.error);
+ }
+}
+
string HttpMethod::FailFile;
int HttpMethod::FailFd = -1;
time_t HttpMethod::FailTime = 0;
CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm);
CFRelease(hm);
+ CFDictionaryRef dr = SCDynamicStoreCopyProxies(NULL);
+ CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPProxy, dr);
+ CFRelease(dr);
+
CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
Status("Connecting to %s", uri.Host.c_str());
if (!CFReadStreamOpen(rs)) {
- _error->Error("Unable to open stream");
+ CfrsError(rs);
Fail(true);
goto done;
}
CFIndex rd = CFReadStreamRead(rs, data, sizeof(data));
if (rd == -1) {
- _error->Error("Stream read failure");
+ CfrsError(rs);
Fail(true);
goto done;
}
if (!CFStringGetCString(sr, cr, ln, se)) {
Fail();
- goto done;
+ goto done_;
}
CFRelease(sr);
if (sscanf(cr, "bytes %lu-%*u/%lu", &offset, &Res.Size) != 2) {
_error->Error(_("The HTTP server sent an invalid Content-Range header"));
Fail();
- goto done;
+ goto done_;
}
if (offset > Res.Size) {
_error->Error(_("This HTTP server has broken range support"));
Fail();
- goto done;
+ goto done_;
}
} else {
sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Length"));
if (!CFStringGetCString(sr, cr, ln, se)) {
Fail();
- goto done;
+ goto done_;
}
CFRelease(sr);
if (!StrToTime(cr, Res.LastModified)) {
_error->Error(_("Unknown date format"));
Fail();
- goto done;
+ goto done_;
}
}
URIStart(Res);
read: if (rd == -1) {
- _error->Error("Stream read failure");
+ CfrsError(rs);
Fail(true);
} else if (rd == 0) {
if (Res.Size == 0)
}
}
+ goto done;
+ done_:
+ CFRelease(hm);
done:
+ CFReadStreamClose(rs);
CFRelease(rs);
FailCounter = 0;
# The http method
PROGRAM=http
-SLIBS = -lapt-pkg $(SOCKETLIBS) -framework CFNetwork -framework CoreFoundation
+SLIBS = -lapt-pkg $(SOCKETLIBS) -framework CFNetwork -framework CoreFoundation -framework SystemConfiguration
LIB_MAKES = apt-pkg/makefile
SOURCE = http.cc rfc2553emu.cc connect.cc
include $(PROGRAM_H)