summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2011-09-13 17:52:22 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2011-09-13 17:52:22 +0200
commit74b220028595342028e3309002e4ec359af328f9 (patch)
tree0132b7fd4b4f5fa5e2dbce1f2e0fbeeff2c8e101 /apt-pkg/contrib
parent650faab01603caac04494d54cf6b10a65c00ea13 (diff)
parentb11fe392b2245354591296df88c3be2e6218af12 (diff)
merge with debian/experimental
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc4
-rw-r--r--apt-pkg/contrib/configuration.cc8
-rw-r--r--apt-pkg/contrib/configuration.h2
-rw-r--r--apt-pkg/contrib/error.cc6
-rw-r--r--apt-pkg/contrib/fileutl.cc11
-rw-r--r--apt-pkg/contrib/fileutl.h1
-rw-r--r--apt-pkg/contrib/netrc.cc7
-rw-r--r--apt-pkg/contrib/sha1.cc5
-rw-r--r--apt-pkg/contrib/sha256.h2
-rw-r--r--apt-pkg/contrib/sha2_internal.h9
-rw-r--r--apt-pkg/contrib/strutl.cc85
-rw-r--r--apt-pkg/contrib/strutl.h4
12 files changed, 107 insertions, 37 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 7f30f132d..9de795b60 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -260,7 +260,9 @@ string FindMountPointForDevice(const char *devnode)
if(TokSplitString(' ', buf, out, 10))
{
fclose(f);
- return string(out[1]);
+ // unescape the \0XXX chars in the path
+ string mount_point = out[1];
+ return DeEscapeString(mount_point);
}
}
}
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index b3e9d8863..0f7b37ee9 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -348,7 +348,7 @@ void Configuration::Set(const char *Name,const string &Value)
// Configuration::Set - Set an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
-void Configuration::Set(const char *Name,int const Value)
+void Configuration::Set(const char *Name,int const &Value)
{
Item *Itm = Lookup(Name,true);
if (Itm == 0)
@@ -675,9 +675,9 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
// Put the last fragment into the buffer
std::string::const_iterator NonWhitespaceStart = Start;
std::string::const_iterator NonWhitespaceStop = I;
- for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++)
+ for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; ++NonWhitespaceStart)
;
- for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--)
+ for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; --NonWhitespaceStop)
;
if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0)
LineBuffer += ' ';
@@ -853,7 +853,7 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir,
vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true);
// Read the files
- for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
+ for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I)
if (ReadConfigFile(Conf,*I,AsSectional,Depth) == false)
return false;
return true;
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 3568ce815..2844ec097 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -84,7 +84,7 @@ class Configuration
void CndSet(const char *Name,const string &Value);
void CndSet(const char *Name,const int Value);
void Set(const char *Name,const string &Value);
- void Set(const char *Name,const int Value);
+ void Set(const char *Name,const int &Value);
inline bool Exists(const string &Name) const {return Exists(Name.c_str());};
bool Exists(const char *Name) const;
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index 56bbd1c60..122e2c809 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -194,7 +194,7 @@ bool GlobalError::PopMessage(std::string &Text) {
// check if another error message is pending
for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
+ m != Messages.end(); ++m)
if (m->Type == ERROR || m->Type == FATAL)
return Ret;
@@ -211,7 +211,7 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold,
Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end());
for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
+ m != Messages.end(); ++m)
if (m->Type >= threshold)
out << (*m) << std::endl;
Discard();
@@ -232,7 +232,7 @@ bool GlobalError::empty(MsgType const &trashhold) const {
return true;
for (std::list<Item>::const_iterator m = Messages.begin();
- m != Messages.end(); m++)
+ m != Messages.end(); ++m)
if (m->Type >= trashhold)
return false;
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 2e62846d9..95058cbde 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -447,6 +447,17 @@ string SafeGetCWD()
return S;
}
/*}}}*/
+// GetModificationTime - Get the mtime of the given file or -1 on error /*{{{*/
+// ---------------------------------------------------------------------
+/* We return / on failure. */
+time_t GetModificationTime(string const &Path)
+{
+ struct stat St;
+ if (stat(Path.c_str(), &St) < 0)
+ return -1;
+ return St.st_mtime;
+}
+ /*}}}*/
// flNotDir - Strip the directory from the filename /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 0f2dd4194..973a38cff 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -112,6 +112,7 @@ bool FileExists(string File);
bool RealFileExists(string File);
bool DirectoryExists(string const &Path) __attrib_const;
bool CreateDirectory(string const &Parent, string const &Path);
+time_t GetModificationTime(string const &Path);
/** \brief Ensure the existence of the given Path
*
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
index 456ada950..b9d0749e2 100644
--- a/apt-pkg/contrib/netrc.cc
+++ b/apt-pkg/contrib/netrc.cc
@@ -48,10 +48,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
int specific_login = (login[0] != 0);
char *home = NULL;
bool netrc_alloc = false;
- int state = NOTHING;
- char state_login = 0; /* Found a login keyword */
- char state_password = 0; /* Found a password keyword */
int state_our_login = false; /* With specific_login,
found *our* login name */
@@ -82,6 +79,10 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
bool done = false;
char netrcbuffer[256];
+ int state = NOTHING;
+ char state_login = 0; /* Found a login keyword */
+ char state_password = 0; /* Found a password keyword */
+
while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) {
tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
while (!done && tok) {
diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc
index 31c576611..b5a6a2440 100644
--- a/apt-pkg/contrib/sha1.cc
+++ b/apt-pkg/contrib/sha1.cc
@@ -75,10 +75,9 @@ static void SHA1Transform(uint32_t state[5],uint8_t const buffer[64])
uint32_t l[16];
}
CHAR64LONG16;
- CHAR64LONG16 *block;
+ CHAR64LONG16 workspace, *block;
- uint8_t workspace[64];
- block = (CHAR64LONG16 *)workspace;
+ block = &workspace;
memcpy(block,buffer,sizeof(workspace));
/* Copy context->state[] to working vars */
diff --git a/apt-pkg/contrib/sha256.h b/apt-pkg/contrib/sha256.h
index fe2b30ac2..15146c948 100644
--- a/apt-pkg/contrib/sha256.h
+++ b/apt-pkg/contrib/sha256.h
@@ -3,6 +3,6 @@
#include "sha2.h"
-#warn "This header is deprecated, please include sha2.h instead"
+#warning "This header is deprecated, please include sha2.h instead"
#endif
diff --git a/apt-pkg/contrib/sha2_internal.h b/apt-pkg/contrib/sha2_internal.h
index bf759ad45..d9d429c92 100644
--- a/apt-pkg/contrib/sha2_internal.h
+++ b/apt-pkg/contrib/sha2_internal.h
@@ -35,11 +35,6 @@
#ifndef __SHA2_H__
#define __SHA2_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
/*
* Import u_intXX_t size_t type definitions from system headers. You
* may need to change this, or define these things yourself in this
@@ -189,9 +184,5 @@ char* SHA512_Data();
#endif /* NOPROTO */
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
#endif /* __SHA2_H__ */
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 04226f1b4..aaf44b7ff 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -271,7 +271,7 @@ bool ParseCWord(const char *&String,string &Res)
string QuoteString(const string &Str, const char *Bad)
{
string Res;
- for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
+ for (string::const_iterator I = Str.begin(); I != Str.end(); ++I)
{
if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
*I == 0x25 || // percent '%' char
@@ -298,7 +298,7 @@ string DeQuoteString(string::const_iterator const &begin,
string::const_iterator const &end)
{
string Res;
- for (string::const_iterator I = begin; I != end; I++)
+ for (string::const_iterator I = begin; I != end; ++I)
{
if (*I == '%' && I + 2 < end &&
isxdigit(I[1]) && isxdigit(I[2]))
@@ -632,7 +632,7 @@ string LookupTag(const string &Message,const char *Tag,const char *Default)
{
// Look for a matching tag.
int Length = strlen(Tag);
- for (string::const_iterator I = Message.begin(); I + Length < Message.end(); I++)
+ for (string::const_iterator I = Message.begin(); I + Length < Message.end(); ++I)
{
// Found the tag
if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0)
@@ -640,14 +640,14 @@ string LookupTag(const string &Message,const char *Tag,const char *Default)
// Find the end of line and strip the leading/trailing spaces
string::const_iterator J;
I += Length + 1;
- for (; isspace(*I) != 0 && I < Message.end(); I++);
- for (J = I; *J != '\n' && J < Message.end(); J++);
- for (; J > I && isspace(J[-1]) != 0; J--);
+ for (; isspace(*I) != 0 && I < Message.end(); ++I);
+ for (J = I; *J != '\n' && J < Message.end(); ++J);
+ for (; J > I && isspace(J[-1]) != 0; --J);
return string(I,J);
}
- for (; *I != '\n' && I < Message.end(); I++);
+ for (; *I != '\n' && I < Message.end(); ++I);
}
// Failed to find a match
@@ -1252,7 +1252,7 @@ int tolower_ascii(int const c)
bool CheckDomainList(const string &Host,const string &List)
{
string::const_iterator Start = List.begin();
- for (string::const_iterator Cur = List.begin(); Cur <= List.end(); Cur++)
+ for (string::const_iterator Cur = List.begin(); Cur <= List.end(); ++Cur)
{
if (Cur < List.end() && *Cur != ',')
continue;
@@ -1268,7 +1268,68 @@ bool CheckDomainList(const string &Host,const string &List)
return false;
}
/*}}}*/
+// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string DeEscapeString(const string &input)
+{
+ char tmp[3];
+ string::const_iterator it, escape_start;
+ string output, octal, hex;
+ for (it = input.begin(); it != input.end(); ++it)
+ {
+ // just copy non-escape chars
+ if (*it != '\\')
+ {
+ output += *it;
+ continue;
+ }
+ // deal with double escape
+ if (*it == '\\' &&
+ (it + 1 < input.end()) && it[1] == '\\')
+ {
+ // copy
+ output += *it;
+ // advance iterator one step further
+ ++it;
+ continue;
+ }
+
+ // ensure we have a char to read
+ if (it + 1 == input.end())
+ continue;
+
+ // read it
+ ++it;
+ switch (*it)
+ {
+ case '0':
+ if (it + 2 <= input.end()) {
+ tmp[0] = it[1];
+ tmp[1] = it[2];
+ tmp[2] = 0;
+ output += (char)strtol(tmp, 0, 8);
+ it += 2;
+ }
+ break;
+ case 'x':
+ if (it + 2 <= input.end()) {
+ tmp[0] = it[1];
+ tmp[1] = it[2];
+ tmp[2] = 0;
+ output += (char)strtol(tmp, 0, 16);
+ it += 2;
+ }
+ break;
+ default:
+ // FIXME: raise exception here?
+ break;
+ }
+ }
+ return output;
+}
+ /*}}}*/
// URI::CopyFrom - Copy from an object /*{{{*/
// ---------------------------------------------------------------------
/* This parses the URI into all of its components */
@@ -1277,7 +1338,7 @@ void URI::CopyFrom(const string &U)
string::const_iterator I = U.begin();
// Locate the first colon, this separates the scheme
- for (; I < U.end() && *I != ':' ; I++);
+ for (; I < U.end() && *I != ':' ; ++I);
string::const_iterator FirstColon = I;
/* Determine if this is a host type URI with a leading double //
@@ -1289,7 +1350,7 @@ void URI::CopyFrom(const string &U)
/* Find the / indicating the end of the hostname, ignoring /'s in the
square brackets */
bool InBracket = false;
- for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); SingleSlash++)
+ for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); ++SingleSlash)
{
if (*SingleSlash == '[')
InBracket = true;
@@ -1322,11 +1383,11 @@ void URI::CopyFrom(const string &U)
I = FirstColon + 1;
if (I > SingleSlash)
I = SingleSlash;
- for (; I < SingleSlash && *I != ':'; I++);
+ for (; I < SingleSlash && *I != ':'; ++I);
string::const_iterator SecondColon = I;
// Search for the @ after the colon
- for (; I < SingleSlash && *I != '@'; I++);
+ for (; I < SingleSlash && *I != '@'; ++I);
string::const_iterator At = I;
// Now write the host and user/pass
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index b32198f25..ab4b54722 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -39,6 +39,10 @@ bool ParseCWord(const char *&String,string &Res);
string QuoteString(const string &Str,const char *Bad);
string DeQuoteString(const string &Str);
string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end);
+
+// unescape (\0XX and \xXX) from a string
+string DeEscapeString(const string &input);
+
string SizeToStr(double Bytes);
string TimeToStr(unsigned long Sec);
string Base64Encode(const string &Str);