diff options
Diffstat (limited to 'methods')
-rw-r--r-- | methods/gpgv.cc | 42 | ||||
-rw-r--r-- | methods/http.cc | 57 | ||||
-rw-r--r-- | methods/http.h | 37 | ||||
-rw-r--r-- | methods/rred.cc | 19 |
4 files changed, 88 insertions, 67 deletions
diff --git a/methods/gpgv.cc b/methods/gpgv.cc index c58e6cc45..a149d67dd 100644 --- a/methods/gpgv.cc +++ b/methods/gpgv.cc @@ -12,6 +12,8 @@ #include <iostream> #include <sstream> +#include <vector> + #define GNUPGPREFIX "[GNUPG:]" #define GNUPGBADSIG "[GNUPG:] BADSIG" #define GNUPGNOPUBKEY "[GNUPG:] NO_PUBKEY" @@ -87,23 +89,18 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile, return string("Couldn't spawn new process") + strerror(errno); else if (pid == 0) { - const char *Args[400]; - unsigned int i = 0; + std::vector<const char *> Args; + Args.reserve(30); - Args[i++] = gpgvpath.c_str(); - Args[i++] = "--status-fd"; - Args[i++] = "3"; - Args[i++] = "--ignore-time-conflict"; + Args.push_back(gpgvpath.c_str()); + Args.push_back("--status-fd"); + Args.push_back("3"); + Args.push_back("--ignore-time-conflict"); for (vector<string>::const_iterator K = keyrings.begin(); K != keyrings.end(); ++K) { - Args[i++] = "--keyring"; - Args[i++] = K->c_str(); - // check overflow (minus a bit of extra space at the end) - if(i >= sizeof(Args)/sizeof(char*)-5) { - std::clog << _("E: Too many keyrings should be passed to gpgv. Exiting.") << std::endl; - exit(111); - } + Args.push_back("--keyring"); + Args.push_back(K->c_str()); } Configuration::Item const *Opts; @@ -115,23 +112,18 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile, { if (Opts->Value.empty() == true) continue; - Args[i++] = Opts->Value.c_str(); - // check overflow (minus a bit of extra space at the end) - if(i >= sizeof(Args)/sizeof(char*)-5) { - std::clog << _("E: Argument list from Acquire::gpgv::Options too long. Exiting.") << std::endl; - exit(111); - } + Args.push_back(Opts->Value.c_str()); } } - Args[i++] = file; - Args[i++] = outfile; - Args[i++] = NULL; + Args.push_back(file); + Args.push_back(outfile); + Args.push_back(NULL); if (Debug == true) { std::clog << "Preparing to exec: " << gpgvpath; - for(unsigned int j=0;Args[j] != NULL; j++) - std::clog << " " << Args[j]; + for(std::vector<const char *>::const_iterator a = Args.begin();*a != NULL; ++a) + std::clog << " " << *a; std::clog << std::endl; } int const nullfd = open("/dev/null", O_RDONLY); @@ -145,7 +137,7 @@ string GPGVMethod::VerifyGetSigners(const char *file, const char *outfile, putenv((char *)"LANG="); putenv((char *)"LC_ALL="); putenv((char *)"LC_MESSAGES="); - execvp(gpgvpath.c_str(), (char **)Args); + execvp(gpgvpath.c_str(), (char **) &Args[0]); exit(111); } diff --git a/methods/http.cc b/methods/http.cc index 904030e0a..3e2227f2b 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -67,7 +67,7 @@ unsigned long CircleBuf::BwReadLimit=0; unsigned long CircleBuf::BwTickReadData=0; struct timeval CircleBuf::BwReadTick={0,0}; const unsigned int CircleBuf::BW_HZ=10; - + // CircleBuf::CircleBuf - Circular input buffer /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -378,7 +378,7 @@ bool ServerState::Close() // --------------------------------------------------------------------- /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header parse error occurred */ -int ServerState::RunHeaders() +ServerState::RunHeadersResult ServerState::RunHeaders() { State = Header; @@ -407,7 +407,7 @@ int ServerState::RunHeaders() string::const_iterator J = I; for (; J != Data.end() && *J != '\n' && *J != '\r';J++); if (HeaderLine(string(I,J)) == false) - return 2; + return RUN_HEADERS_PARSE_ERROR; I = J; } @@ -419,11 +419,11 @@ int ServerState::RunHeaders() if (Encoding == Closes && HaveContent == true) Persistent = false; - return 0; + return RUN_HEADERS_OK; } while (Owner->Go(false,this) == true); - return 1; + return RUN_HEADERS_IO_ERROR; } /*}}}*/ // ServerState::RunData - Transfer the data from the socket /*{{{*/ @@ -734,7 +734,7 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out) Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n"; } Req += "User-Agent: " + _config->Find("Acquire::http::User-Agent", - "Ubuntu APT-HTTP/1.3 ("VERSION")") + "\r\n\r\n"; + "Debian APT-HTTP/1.3 ("VERSION")") + "\r\n\r\n"; if (Debug == true) cerr << Req << endl; @@ -914,15 +914,10 @@ bool HttpMethod::ServerDie(ServerState *Srv) // HttpMethod::DealWithHeaders - Handle the retrieved header data /*{{{*/ // --------------------------------------------------------------------- /* We look at the header data we got back from the server and decide what - to do. Returns - 0 - File is open, - 1 - IMS hit - 3 - Unrecoverable error - 4 - Error with error content page - 5 - Unrecoverable non-server error (close the connection) - 6 - Try again with a new or changed URI + to do. Returns DealWithHeadersResult (see http.h for details). */ -int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) +HttpMethod::DealWithHeadersResult +HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) { // Not Modified if (Srv->Result == 304) @@ -930,7 +925,7 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) unlink(Queue->DestFile.c_str()); Res.IMSHit = true; Res.LastModified = Queue->LastModified; - return 1; + return IMS_HIT; } /* Redirect @@ -949,7 +944,7 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) if (!Srv->Location.empty()) { NextURI = Srv->Location; - return 6; + return TRY_AGAIN_OR_REDIRECT; } /* else pass through for error message */ } @@ -963,8 +958,8 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) SetFailReason(err); _error->Error("%u %s",Srv->Result,Srv->Code); if (Srv->HaveContent == true) - return 4; - return 3; + return ERROR_WITH_CONTENT_PAGE; + return ERROR_UNRECOVERABLE; } // This is some sort of 2xx 'data follows' reply @@ -975,7 +970,7 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) delete File; File = new FileFd(Queue->DestFile,FileFd::WriteAny); if (_error->PendingError() == true) - return 5; + return ERROR_NOT_FROM_SERVER; FailFile = Queue->DestFile; FailFile.c_str(); // Make sure we dont do a malloc in the signal handler @@ -1003,13 +998,13 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) if (Srv->In.Hash->AddFD(File->Fd(),Srv->StartPos) == false) { _error->Errno("read",_("Problem hashing file")); - return 5; + return ERROR_NOT_FROM_SERVER; } lseek(File->Fd(),0,SEEK_END); } SetNonBlock(File->Fd(),true); - return 0; + return FILE_IS_OPEN; } /*}}}*/ // HttpMethod::SigTerm - Handle a fatal signal /*{{{*/ @@ -1037,7 +1032,7 @@ void HttpMethod::SigTerm(int) depth. */ bool HttpMethod::Fetch(FetchItem *) { - if (Server == 0) + if (Server == 0) return true; // Queue the requests @@ -1150,11 +1145,11 @@ int HttpMethod::Loop() // Fetch the next URL header data from the server. switch (Server->RunHeaders()) { - case 0: + case ServerState::RUN_HEADERS_OK: break; // The header data is bad - case 2: + case ServerState::RUN_HEADERS_PARSE_ERROR: { _error->Error(_("Bad header data")); Fail(true); @@ -1164,7 +1159,7 @@ int HttpMethod::Loop() // The server closed a connection during the header get.. default: - case 1: + case ServerState::RUN_HEADERS_IO_ERROR: { FailCounter++; _error->Discard(); @@ -1188,7 +1183,7 @@ int HttpMethod::Loop() switch (DealWithHeaders(Res,Server)) { // Ok, the file is Open - case 0: + case FILE_IS_OPEN: { URIStart(Res); @@ -1241,21 +1236,21 @@ int HttpMethod::Loop() } // IMS hit - case 1: + case IMS_HIT: { URIDone(Res); break; } // Hard server error, not found or something - case 3: + case ERROR_UNRECOVERABLE: { Fail(); break; } // Hard internal error, kill the connection and fail - case 5: + case ERROR_NOT_FROM_SERVER: { delete File; File = 0; @@ -1267,7 +1262,7 @@ int HttpMethod::Loop() } // We need to flush the data, the header is like a 404 w/ error text - case 4: + case ERROR_WITH_CONTENT_PAGE: { Fail(); @@ -1280,7 +1275,7 @@ int HttpMethod::Loop() } // Try again with a new URL - case 6: + case TRY_AGAIN_OR_REDIRECT: { // Clear rest of response if there is content if (Server->HaveContent) diff --git a/methods/http.h b/methods/http.h index bac94e177..d0677bdaa 100644 --- a/methods/http.h +++ b/methods/http.h @@ -117,7 +117,19 @@ struct ServerState void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0; Encoding = Closes; time(&Date); ServerFd = -1; Pipeline = true;}; - int RunHeaders(); + + /** \brief Result of the header acquire */ + enum RunHeadersResult { + /** \brief Header ok */ + RUN_HEADERS_OK, + /** \brief IO error while retrieving */ + RUN_HEADERS_IO_ERROR, + /** \brief Parse error after retrieving */ + RUN_HEADERS_PARSE_ERROR, + }; + /** \brief Get the headers before the data */ + RunHeadersResult RunHeaders(); + /** \brief Transfer the data from the socket */ bool RunData(); bool Open(); @@ -133,7 +145,26 @@ class HttpMethod : public pkgAcqMethod bool Go(bool ToFile,ServerState *Srv); bool Flush(ServerState *Srv); bool ServerDie(ServerState *Srv); - int DealWithHeaders(FetchResult &Res,ServerState *Srv); + + /** \brief Result of the header parsing */ + enum DealWithHeadersResult { + /** \brief The file is open and ready */ + FILE_IS_OPEN, + /** \brief We got a IMS hit, the file has not changed */ + IMS_HIT, + /** \brief The server reported a unrecoverable error */ + ERROR_UNRECOVERABLE, + /** \brief The server reported a error with a error content page */ + ERROR_WITH_CONTENT_PAGE, + /** \brief A error on the client side */ + ERROR_NOT_FROM_SERVER, + /** \brief A redirect or retry request */ + TRY_AGAIN_OR_REDIRECT + }; + /** \brief Handle the retrieved header data */ + DealWithHeadersResult DealWithHeaders(FetchResult &Res,ServerState *Srv); + + /** \brief Try to AutoDetect the proxy */ bool AutoDetectProxy(); virtual bool Configuration(string Message); @@ -149,7 +180,7 @@ class HttpMethod : public pkgAcqMethod string NextURI; string AutoDetectProxyCmd; - + public: friend class ServerState; diff --git a/methods/rred.cc b/methods/rred.cc index 262c78cab..f42c7a072 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -477,23 +477,26 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/ Patch.Close(); To.Close(); - // Transfer the modification times - struct stat Buf; - if (stat(Path.c_str(),&Buf) != 0) + /* Transfer the modification times from the patch file + to be able to see in which state the file should be + and use the access time from the "old" file */ + struct stat BufBase, BufPatch; + if (stat(Path.c_str(),&BufBase) != 0 || + stat(string(Path+".ed").c_str(),&BufPatch) != 0) return _error->Errno("stat",_("Failed to stat")); struct utimbuf TimeBuf; - TimeBuf.actime = Buf.st_atime; - TimeBuf.modtime = Buf.st_mtime; + TimeBuf.actime = BufBase.st_atime; + TimeBuf.modtime = BufPatch.st_mtime; if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0) return _error->Errno("utime",_("Failed to set modification time")); - if (stat(Itm->DestFile.c_str(),&Buf) != 0) + if (stat(Itm->DestFile.c_str(),&BufBase) != 0) return _error->Errno("stat",_("Failed to stat")); // return done - Res.LastModified = Buf.st_mtime; - Res.Size = Buf.st_size; + Res.LastModified = BufBase.st_mtime; + Res.Size = BufBase.st_size; Res.TakeHashes(Hash); URIDone(Res); |