httpup: sync with bzr repo (0.4.0g)

This commit is contained in:
Johannes Winkelmann 2006-02-23 14:18:42 +00:00
parent 18c22c5a41
commit b103cf5e68
8 changed files with 59 additions and 24 deletions

View File

@ -7,3 +7,4 @@ THANKS:
Simone Rota for testing and bug reports
Jürgen Daubert for testing
Han Boetes for optimizing the repgen script
Oleksiy V. Khilkevich for the operation_timeout patch prototype

View File

@ -1,4 +1,8 @@
* 0.4.0f 22.09.2005 Johannes Winkelmann
* 0.4.0g 23.02.2006 Johannes Winkelmann
- change default timeout to 60s
- add configuration variable for timeout: operation_timeout
* 0.4.0f 22.09.2005 Johannes Winkelmann
- remove deflate option again
* 0.4.0e 20.09.2005 Johannes Winkelmann

View File

@ -5,7 +5,7 @@ all: httpup
## Configuration
#
NAME=httpup
VERSION="0.4.0f"
VERSION="0.4.0g"
CXX=g++
CXXFLAGS=-Wall -ansi -pedantic -DMF_VERSION='${VERSION}'
LDFLAGS=-lcurl

View File

@ -3,10 +3,10 @@
// AUTHOR: Johannes Winkelmann, jw@tks6.net
// COPYRIGHT: (c) 2002-2005 by Johannes Winkelmann
// ---------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
////////////////////////////////////////////////////////////////////////
#include <iostream>
@ -21,37 +21,44 @@ int ConfigParser::parseConfig(const std::string& fileName,
if (!fp) {
return -1;
}
char line[512];
string s;
while (fgets(line, 512, fp)) {
if (line[strlen(line)-1] == '\n') {
line[strlen(line)-1] = '\0';
}
}
s = line;
// strip comments
string::size_type pos = s.find("#");
if (pos != string::npos) {
s = s.substr(0, pos);
}
if (s.length() > 10) {
string key = s.substr(0, 10);
string val = stripWhiteSpace(s.substr(10));
// whitespace separates
pos = s.find(' ');
if (pos == string::npos) {
pos = s.find('\t');
}
if (pos != string::npos) {
string key = s.substr(0, pos);
string val = stripWhiteSpace(s.substr(pos));
if (key == "proxy_host") {
config.proxyHost = val;
} else if (s.substr(0, 10) == "proxy_port") {
} else if (key == "proxy_port") {
config.proxyPort = val;
} else if (s.substr(0, 10) == "proxy_user") {
} else if (key == "proxy_user") {
config.proxyUser = val;
} else if (s.substr(0, 10) == "proxy_pass") {
} else if (key == "proxy_pass") {
config.proxyPassword = val;
} else if (key == "operation_timeout") {
config.operationTimeout = val;
}
}
}
fclose(fp);
return 0;
}
@ -65,6 +72,6 @@ string ConfigParser::stripWhiteSpace(const string& input)
while (isspace(output[output.length()-1])) {
output = output.substr(0, output.length()-1);
}
return output;
}

View File

@ -3,10 +3,10 @@
// AUTHOR: Johannes Winkelmann, jw@tks6.net
// COPYRIGHT: (c) 2002-2005 by Johannes Winkelmann
// ---------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
////////////////////////////////////////////////////////////////////////
#ifndef _CONFIGPARSER_H_
@ -16,12 +16,19 @@
struct Config
{
Config() : proxyHost(""), proxyPort(""), proxyUser(""), proxyPassword("")
Config()
: proxyHost(""),
proxyPort(""),
proxyUser(""),
proxyPassword(""),
operationTimeout("")
{}
std::string proxyHost;
std::string proxyPort;
std::string proxyUser;
std::string proxyPassword;
std::string operationTimeout;
};
class ConfigParser

View File

@ -4,3 +4,6 @@ proxy_host http://test.proxy.ch
proxy_port 80
proxy_user winkj
proxy_pass very_secret
# timeout settings
operation_timeout 60

View File

@ -27,6 +27,7 @@ const string HttpUp::REPOCURRENTFILEOLD = "REPO.CURRENT";
const string HttpUp::REPOCURRENTFILE = ".httpup-repo.current";
const string HttpUp::URLINFO = ".httpup-urlinfo";
const int HttpUp::DEFAULT_TIMEOUT = 60;
HttpUp::HttpUp(const HttpupArgparser& argParser,
const string& url, const string& target,
@ -227,8 +228,18 @@ int HttpUp::exec(ExecType type)
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
long timeout = DEFAULT_TIMEOUT;
if (config.operationTimeout != "") {
char* end = 0;
long config_timeout = 0;
config_timeout = strtol(config.operationTimeout.c_str(), &end, 10);
if (*end == 0) {
timeout = config_timeout;
}
}
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
// proxy, proxy auth
if (config.proxyHost != "") {

View File

@ -49,6 +49,8 @@ public:
static const std::string REPOCURRENTFILE;
static const std::string REPOCURRENTFILEOLD;
static const std::string URLINFO;
static const int DEFAULT_TIMEOUT;
private:
int syncOrReturn(CURL* curl, char* curlErrorBuffer);