]> git.saurik.com Git - apt.git/commitdiff
reorganize server-states resetting in http/https
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 11 Aug 2016 14:59:13 +0000 (16:59 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Tue, 16 Aug 2016 16:49:37 +0000 (18:49 +0200)
We keep various information bits about the server around, some only
effecting the currently handled file (like sizes) while others
should be persistent (like pipeline detections). http used to reset all
file-related manually, which is a bit silly if we already have a Reset()
method – which does reset all through –, so extending it with a
parameter for reuse and calling it from https too (as this was
previously resetting by just creating a new state struct – it uses no
value of the persistent state-keeping yet as it supports no pipelining).

Gbp-Dch: Ignore

methods/http.cc
methods/http.h
methods/https.cc
methods/server.cc
methods/server.h

index 0358b50cd25bc37e0031e30f93e82eeb1e2aaa1d..8d34aa6e3b271e2f2fb7dc698a27bbd4a39bce1c 100644 (file)
@@ -647,6 +647,13 @@ bool HttpServerState::InitHashes(HashStringList const &ExpectedHashes)     /*{{{*/
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
+void HttpServerState::Reset(bool const Everything)                     /*{{{*/
+{
+   ServerState::Reset(Everything);
+   if (Everything)
+      ServerFd = -1;
+}
+                                                                       /*}}}*/
 
 APT_PURE Hashes * HttpServerState::GetHashes()                         /*{{{*/
 {
 
 APT_PURE Hashes * HttpServerState::GetHashes()                         /*{{{*/
 {
index 644e576f0646dc02e015d86076ecee77c08c33b9..b7341f5f8671c0f817a4a9db05b12ce949bc4be9 100644 (file)
@@ -103,7 +103,7 @@ struct HttpServerState: public ServerState
    virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE;
 
    public:
    virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE;
 
    public:
-   virtual void Reset() APT_OVERRIDE { ServerState::Reset(); ServerFd = -1; };
+   virtual void Reset(bool const Everything = true) APT_OVERRIDE;
 
    virtual bool RunData(FileFd * const File) APT_OVERRIDE;
    virtual bool RunDataToDevNull() APT_OVERRIDE;
 
    virtual bool RunData(FileFd * const File) APT_OVERRIDE;
    virtual bool RunDataToDevNull() APT_OVERRIDE;
index 283126f6b3e1a01f6fcc4e36edc544bed3fc530f..c86f9407e2041880054a30f7219bae4842386567 100644 (file)
@@ -399,7 +399,10 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
 
    // go for it - if the file exists, append on it
    File = new FileFd(Itm->DestFile, FileFd::WriteAny);
 
    // go for it - if the file exists, append on it
    File = new FileFd(Itm->DestFile, FileFd::WriteAny);
-   Server = CreateServerState(Itm->Uri);
+   if (Server == nullptr || Server->Comp(Itm->Uri) == false)
+      Server = CreateServerState(Itm->Uri);
+   else
+      Server->Reset(false);
    if (Server->InitHashes(Itm->ExpectedHashes) == false)
       return false;
 
    if (Server->InitHashes(Itm->ExpectedHashes) == false)
       return false;
 
index 3f0e8845751ad0702c9789f6afa544ba671dde2b..d0b6ef3d7c5d4141f05285f9885592f67897d14e 100644 (file)
@@ -46,20 +46,9 @@ time_t ServerMethod::FailTime = 0;
 ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File,
                                                       const std::string &Uri)
 {
 ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File,
                                                       const std::string &Uri)
 {
-   State = Header;
-   
+   Reset(false);
    Owner->Status(_("Waiting for headers"));
 
    Owner->Status(_("Waiting for headers"));
 
-   Major = 0; 
-   Minor = 0; 
-   Result = 0; 
-   TotalFileSize = 0;
-   JunkSize = 0;
-   StartPos = 0;
-   Encoding = Closes;
-   HaveContent = false;
-   time(&Date);
-
    do
    {
       string Data;
    do
    {
       string Data;
@@ -254,6 +243,18 @@ bool ServerState::AddPartialFileToHashes(FileFd &File)                     /*{{{*/
    return GetHashes()->AddFD(File, StartPos);
 }
                                                                        /*}}}*/
    return GetHashes()->AddFD(File, StartPos);
 }
                                                                        /*}}}*/
+void ServerState::Reset(bool const Everything)                         /*{{{*/
+{
+   Major = 0; Minor = 0; Result = 0; Code[0] = '\0';
+   TotalFileSize = 0; JunkSize = 0; StartPos = 0;
+   Encoding = Closes; time(&Date); HaveContent = false;
+   State = Header; MaximumSize = 0;
+   if (Everything)
+   {
+      Persistent = false; Pipeline = false; PipelineAllowed = true;
+   }
+}
+                                                                       /*}}}*/
 
 // ServerMethod::DealWithHeaders - Handle the retrieved header data    /*{{{*/
 // ---------------------------------------------------------------------
 
 // ServerMethod::DealWithHeaders - Handle the retrieved header data    /*{{{*/
 // ---------------------------------------------------------------------
index 1d114354f2a85ae7149b454111b1240d78746a9c..63acceae69d8527a3402cea55062804374e959f5 100644 (file)
@@ -84,9 +84,7 @@ struct ServerState
    bool AddPartialFileToHashes(FileFd &File);
 
    bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
    bool AddPartialFileToHashes(FileFd &File);
 
    bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
-   virtual void Reset() {Major = 0; Minor = 0; Result = 0; Code[0] = '\0'; TotalFileSize = 0; JunkSize = 0;
-                StartPos = 0; Encoding = Closes; time(&Date); HaveContent = false;
-                State = Header; Persistent = false; Pipeline = false; MaximumSize = 0; PipelineAllowed = true;};
+   virtual void Reset(bool const Everything = true);
    virtual bool WriteResponse(std::string const &Data) = 0;
 
    /** \brief Transfer the data from the socket */
    virtual bool WriteResponse(std::string const &Data) = 0;
 
    /** \brief Transfer the data from the socket */