From 985ed2690cc1f5c748402fafbaa0ba4186fbdff0 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 27 Feb 2008 09:34:18 +0000 Subject: [PATCH] Drastically improved APT HTTP error messages and actually set the proxy server configuration. M cfnetwork.diff git-svn-id: http://svn.telesphoreo.org/trunk@115 514c082c-b64e-11dc-b46d-3d985efe055d --- methods/http.cc | 66 ++++++++++++++++++++++++++++++++++++++------ methods/http.cc.orig | 66 ++++++++++++++++++++++++++++++++++++++------ methods/makefile | 2 +- 3 files changed, 117 insertions(+), 17 deletions(-) diff --git a/methods/http.cc b/methods/http.cc index 012d450..4cea76a 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -50,6 +50,7 @@ extern "C" { #include #include +#include #include "connect.h" #include "rfc2553emu.h" @@ -58,6 +59,47 @@ extern "C" { /*}}}*/ 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; @@ -1097,6 +1139,10 @@ int HttpMethod::Loop() 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); @@ -1110,7 +1156,7 @@ int HttpMethod::Loop() Status("Connecting to %s", uri.Host.c_str()); if (!CFReadStreamOpen(rs)) { - _error->Error("Unable to open stream"); + CfrsError(rs); Fail(true); goto done; } @@ -1118,7 +1164,7 @@ int HttpMethod::Loop() CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); if (rd == -1) { - _error->Error("Stream read failure"); + CfrsError(rs); Fail(true); goto done; } @@ -1135,7 +1181,7 @@ int HttpMethod::Loop() if (!CFStringGetCString(sr, cr, ln, se)) { Fail(); - goto done; + goto done_; } CFRelease(sr); @@ -1143,13 +1189,13 @@ int HttpMethod::Loop() 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")); @@ -1168,7 +1214,7 @@ int HttpMethod::Loop() if (!CFStringGetCString(sr, cr, ln, se)) { Fail(); - goto done; + goto done_; } CFRelease(sr); @@ -1176,7 +1222,7 @@ int HttpMethod::Loop() if (!StrToTime(cr, Res.LastModified)) { _error->Error(_("Unknown date format")); Fail(); - goto done; + goto done_; } } @@ -1224,7 +1270,7 @@ int HttpMethod::Loop() URIStart(Res); read: if (rd == -1) { - _error->Error("Stream read failure"); + CfrsError(rs); Fail(true); } else if (rd == 0) { if (Res.Size == 0) @@ -1261,7 +1307,11 @@ int HttpMethod::Loop() } } + goto done; + done_: + CFRelease(hm); done: + CFReadStreamClose(rs); CFRelease(rs); FailCounter = 0; diff --git a/methods/http.cc.orig b/methods/http.cc.orig index b53b5da..8a9d594 100644 --- a/methods/http.cc.orig +++ b/methods/http.cc.orig @@ -46,6 +46,7 @@ #include #include +#include #include "connect.h" #include "rfc2553emu.h" @@ -54,6 +55,47 @@ /*}}}*/ 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; @@ -1093,6 +1135,10 @@ int HttpMethod::Loop() 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); @@ -1106,7 +1152,7 @@ int HttpMethod::Loop() Status("Connecting to %s", uri.Host.c_str()); if (!CFReadStreamOpen(rs)) { - _error->Error("Unable to open stream"); + CfrsError(rs); Fail(true); goto done; } @@ -1114,7 +1160,7 @@ int HttpMethod::Loop() CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); if (rd == -1) { - _error->Error("Stream read failure"); + CfrsError(rs); Fail(true); goto done; } @@ -1131,7 +1177,7 @@ int HttpMethod::Loop() if (!CFStringGetCString(sr, cr, ln, se)) { Fail(); - goto done; + goto done_; } CFRelease(sr); @@ -1139,13 +1185,13 @@ int HttpMethod::Loop() 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")); @@ -1164,7 +1210,7 @@ int HttpMethod::Loop() if (!CFStringGetCString(sr, cr, ln, se)) { Fail(); - goto done; + goto done_; } CFRelease(sr); @@ -1172,7 +1218,7 @@ int HttpMethod::Loop() if (!StrToTime(cr, Res.LastModified)) { _error->Error(_("Unknown date format")); Fail(); - goto done; + goto done_; } } @@ -1220,7 +1266,7 @@ int HttpMethod::Loop() URIStart(Res); read: if (rd == -1) { - _error->Error("Stream read failure"); + CfrsError(rs); Fail(true); } else if (rd == 0) { if (Res.Size == 0) @@ -1257,7 +1303,11 @@ int HttpMethod::Loop() } } + goto done; + done_: + CFRelease(hm); done: + CFReadStreamClose(rs); CFRelease(rs); FailCounter = 0; diff --git a/methods/makefile b/methods/makefile index 27beb53..ce272aa 100644 --- a/methods/makefile +++ b/methods/makefile @@ -47,7 +47,7 @@ include $(PROGRAM_H) # 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) -- 2.45.2