#include <stdio.h>
#include <errno.h>
#include <string.h>
-#include <iostream>
#include <apti18n.h>
// Internet stuff
/*}}}*/
// ServerState::RunHeaders - Get the headers before the data /*{{{*/
// ---------------------------------------------------------------------
-/* Returns 0 if things are OK, 1 if an IO error occursed and 2 if a header
- parse error occured */
+/* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
+ parse error occurred */
int ServerState::RunHeaders()
{
State = Header;
Req += string("Authorization: Basic ") +
Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
- Req += "User-Agent: Debian APT-HTTP/1.3 ("VERSION")\r\n\r\n";
+ Req += "User-Agent: Ubuntu APT-HTTP/1.3 ("VERSION")\r\n\r\n";
if (Debug == true)
cerr << Req << endl;
failure */
if (Srv->Result < 200 || Srv->Result >= 300)
{
+ char err[255];
+ snprintf(err,sizeof(err)-1,"HttpError%i",Srv->Result);
+ SetFailReason(err);
_error->Error("%u %s",Srv->Result,Srv->Code);
if (Srv->HaveContent == true)
return 4;
if (Srv->StartPos >= 0)
{
Res.ResumePoint = Srv->StartPos;
- ftruncate(File->Fd(),Srv->StartPos);
+ if (ftruncate(File->Fd(),Srv->StartPos) < 0)
+ _error->Errno("ftruncate", _("Failed to truncate file"));
}
// Set the start point
depth. */
bool HttpMethod::Fetch(FetchItem *)
{
- if (Server == 0)
+ if (Server == 0)
return true;
// Queue the requests
URIDone(Res);
}
else
- {
- if (Server->ServerFd == -1)
+ {
+ if (Server->ServerFd == -1)
+ {
+ FailCounter++;
+ _error->Discard();
+ Server->Close();
+
+ if (FailCounter >= 2)
{
- FailCounter++;
- _error->Discard();
- Server->Close();
-
- if (FailCounter >= 2)
- {
- Fail(_("Connection failed"),true);
- FailCounter = 0;
- }
-
- QueueBack = Queue;
+ Fail(_("Connection failed"),true);
+ FailCounter = 0;
}
- else
- Fail(true);
- }
-
+
+ QueueBack = Queue;
+ }
+ else
+ Fail(true);
+ }
break;
}
}
/*}}}*/
-int main()
-{
- setlocale(LC_ALL, "");
-
- HttpMethod Mth;
-
- return Mth.Loop();
-}