From 7d15572bc3124b15c043e38bdc3d90bcc94f108a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 Dec 2009 14:25:20 +0100 Subject: add optional gcc features as deprecated, unused and (un)likely --- apt-pkg/contrib/system.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/system.h b/apt-pkg/contrib/system.h index 7ec3d7feb..f68df6265 100644 --- a/apt-pkg/contrib/system.h +++ b/apt-pkg/contrib/system.h @@ -55,4 +55,26 @@ #define CLRFLAG(v,f) ((v) &=~FLAG(f)) #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false) +// some nice optional GNUC features +#if __GNUC__ >= 3 + #define __must_check __attribute__ ((warn_unused_result)) + #define __deprecated __attribute__ ((deprecated)) + /* likely() and unlikely() can be used to mark boolean expressions + as (not) likely true which will help the compiler to optimise */ + #define likely(x) __builtin_expect (!!(x), 1) + #define unlikely(x) __builtin_expect (!!(x), 0) +#else + #define __must_check /* no warn_unused_result */ + #define __deprecated /* no deprecated */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif + +// cold functions are unlikely() to be called +#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 + #define __cold __attribute__ ((__cold__)) +#else + #define __cold /* no cold marker */ +#endif + #endif -- cgit v1.2.3 From 201d1fa0d25deeda77c2570ee5342eaf18499699 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 Dec 2009 14:27:21 +0100 Subject: mark the Error/Warning method as __cold --- apt-pkg/contrib/error.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index a3be6a575..d92e40e9c 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -52,6 +52,7 @@ #endif #include +#include using std::string; @@ -71,13 +72,13 @@ class GlobalError public: // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2; - bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2; + bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; + bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2 __cold; /* A warning should be considered less severe than an error, and may be ignored by the client. */ - bool Error(const char *Description,...) APT_MFORMAT1; - bool Warning(const char *Description,...) APT_MFORMAT1; + bool Error(const char *Description,...) APT_MFORMAT1 __cold; + bool Warning(const char *Description,...) APT_MFORMAT1 __cold; // Simple accessors inline bool PendingError() {return PendingFlag;}; -- cgit v1.2.3 From 5dd4c8b811d9c7bc33e50254811f5bc0fc37f872 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 23 Dec 2009 12:38:19 +0100 Subject: merge Goswin Brederlow "support download of index files for different archs" patch which includes the following big changes: - Declare the unused [vendor] field in sources.list as option field, e.g. deb [arch=amd64,i386 lang=en_GB have=fun] http://example.org - When fetching index files download them for all APT::Architectures (overrideable with the options field above) - Allow all architectures of APT::Architectures to be in the Cache - Add the architecture to status and progress informations - Add b= (Binary architecture) to policy This commit doesn't incude the "pin-hack" as the Group structure will take care of this (and does it already to some extend). --- apt-pkg/contrib/strutl.cc | 17 +++++++++++++++++ apt-pkg/contrib/strutl.h | 1 + 2 files changed, 18 insertions(+) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 4c05f2df8..bed51881f 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -983,6 +983,23 @@ bool TokSplitString(char Tok,char *Input,char **List, return true; } /*}}}*/ +// ExplodeString - Split a string up into a vector /*{{{*/ +// --------------------------------------------------------------------- +/* This can be used to split a given string up into a vector, so the + propose is the same as in the method above and this one is a bit slower + also, but the advantage is that we an iteratable vector */ +vector ExplodeString(string const &haystack, char const &split) { + string::const_iterator start = haystack.begin(); + string::const_iterator end = start; + vector exploded; + do { + for (; end != haystack.end() && *end != split; ++end); + exploded.push_back(string(start, end)); + start = end; + } while (end != haystack.end() && (++end) != haystack.end()); + return exploded; +} + /*}}}*/ // RegexChoice - Simple regex list/list matcher /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 2b2e147fb..3bdb65b4d 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -59,6 +59,7 @@ bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0) bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length); bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); +vector ExplodeString(string const &haystack, char const &split=','); void ioprintf(ostream &out,const char *format,...) APT_FORMAT2; void strprintf(string &out,const char *format,...) APT_FORMAT2; char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_FORMAT3; -- cgit v1.2.3 From 83742b3cf4b541fd61533dfecdc97e0e4502a7a4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 14 Feb 2010 23:34:56 +0100 Subject: Add support for the LANGUAGE environment variable --- apt-pkg/contrib/strutl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index b285a9f2e..d3d6e2739 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1012,7 +1012,7 @@ vector ExplodeString(string const &haystack, char const &split) { do { for (; end != haystack.end() && *end != split; ++end); exploded.push_back(string(start, end)); - start = end; + start = end + 1; } while (end != haystack.end() && (++end) != haystack.end()); return exploded; } -- cgit v1.2.3 From 06afffcc24f339e8735acd4698af6e5995ad24aa Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 27 Feb 2010 02:02:25 +0100 Subject: =?UTF-8?q?*=20apt-pkg/contrib/mmap.{h,cc}:=20=20=20-=20add=20char?= =?UTF-8?q?[]=20fallback=20for=20filesystems=20without=20shared=20writable?= =?UTF-8?q?=20=20=20=20=20mmap()=20like=20JFFS2.=20Thanks=20to=20Marius=20?= =?UTF-8?q?Vollmer=20for=20writing=20=20=20=20=20and=20to=20Lo=C3=AFc=20Mi?= =?UTF-8?q?nier=20for=20pointing=20to=20the=20patch!=20(Closes:=20#314334)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/contrib/mmap.cc | 70 +++++++++++++++++++++++++++++++++++++++++-------- apt-pkg/contrib/mmap.h | 5 ++++ 2 files changed, 64 insertions(+), 11 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index f440f9489..b3f29032c 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include /*}}}*/ @@ -35,7 +36,7 @@ // --------------------------------------------------------------------- /* */ MMap::MMap(FileFd &F,unsigned long Flags) : Flags(Flags), iSize(0), - Base(0) + Base(0), SyncToFd(NULL) { if ((Flags & NoImmMap) != NoImmMap) Map(F); @@ -45,7 +46,7 @@ MMap::MMap(FileFd &F,unsigned long Flags) : Flags(Flags), iSize(0), // --------------------------------------------------------------------- /* */ MMap::MMap(unsigned long Flags) : Flags(Flags), iSize(0), - Base(0) + Base(0), SyncToFd(NULL) { } /*}}}*/ @@ -78,7 +79,24 @@ bool MMap::Map(FileFd &Fd) // Map it. Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0); if (Base == (void *)-1) - return _error->Errno("mmap",_("Couldn't make mmap of %lu bytes"),iSize); + { + if (errno == ENODEV || errno == EINVAL) + { + // The filesystem doesn't support this particular kind of mmap. + // So we allocate a buffer and read the whole file into it. + int const dupped_fd = dup(Fd.Fd()); + if (dupped_fd == -1) + return _error->Errno("mmap", _("Couldn't duplicate file descriptor %i"), Fd.Fd()); + + Base = new unsigned char[iSize]; + SyncToFd = new FileFd (dupped_fd); + if (!SyncToFd->Seek(0L) || !SyncToFd->Read(Base, iSize)) + return false; + } + else + return _error->Errno("mmap",_("Couldn't make mmap of %lu bytes"), + iSize); + } return true; } @@ -93,10 +111,19 @@ bool MMap::Close(bool DoSync) if (DoSync == true) Sync(); - - if (munmap((char *)Base,iSize) != 0) - _error->Warning("Unable to munmap"); - + + if (SyncToFd != NULL) + { + delete[] (char *)Base; + delete SyncToFd; + SyncToFd = NULL; + } + else + { + if (munmap((char *)Base, iSize) != 0) + _error->WarningE("mmap", _("Unable to close mmap")); + } + iSize = 0; Base = 0; return true; @@ -113,8 +140,18 @@ bool MMap::Sync() #ifdef _POSIX_SYNCHRONIZED_IO if ((Flags & ReadOnly) != ReadOnly) - if (msync((char *)Base,iSize,MS_SYNC) < 0) - return _error->Errno("msync","Unable to write mmap"); + { + if (SyncToFd != NULL) + { + if (!SyncToFd->Seek(0) || !SyncToFd->Write(Base, iSize)) + return false; + } + else + { + if (msync((char *)Base, iSize, MS_SYNC) < 0) + return _error->Errno("msync", _("Unable to synchronize mmap")); + } + } #endif return true; } @@ -130,8 +167,19 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop) #ifdef _POSIX_SYNCHRONIZED_IO unsigned long PSize = sysconf(_SC_PAGESIZE); if ((Flags & ReadOnly) != ReadOnly) - if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) < 0) - return _error->Errno("msync","Unable to write mmap"); + { + if (SyncToFd != 0) + { + if (!SyncToFd->Seek(0) || + !SyncToFd->Write (((char *)Base)+Start, Stop-Start)) + return false; + } + else + { + if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) < 0) + return _error->Errno("msync", _("Unable to synchronize mmap")); + } + } #endif return true; } diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h index cd2b15ba2..5ca951204 100644 --- a/apt-pkg/contrib/mmap.h +++ b/apt-pkg/contrib/mmap.h @@ -44,6 +44,11 @@ class MMap unsigned long iSize; void *Base; + // In case mmap can not be used, we keep a dup of the file + // descriptor that should have been mmaped so that we can write to + // the file in Sync(). + FileFd *SyncToFd; + bool Map(FileFd &Fd); bool Close(bool DoSync = true); -- cgit v1.2.3 From 2bb255740bf18b5e0524fe833523303abb5c9051 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Mar 2010 19:41:30 +0100 Subject: * apt-pkg/deb/dpkgpm.cc: - if available store the Commandline in the history * apt-pkg/contrib/cmndline.cc: - save Commandline in Commandline::AsString for logging --- apt-pkg/contrib/cmndline.cc | 42 +++++++++++++++++++++++++++++++++++++++++- apt-pkg/contrib/cmndline.h | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index bfd53695e..0b16bf51a 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -135,7 +135,9 @@ bool CommandLine::Parse(int argc,const char **argv) for (; I != argc; I++) *Files++ = argv[I]; *Files = 0; - + + SaveInConfig(argc, argv); + return true; } /*}}}*/ @@ -351,3 +353,41 @@ bool CommandLine::DispatchArg(Dispatch *Map,bool NoMatch) return false; } /*}}}*/ +// CommandLine::SaveInConfig - for output later in a logfile or so /*{{{*/ +// --------------------------------------------------------------------- +/* We save the commandline here to have it around later for e.g. logging. + It feels a bit like a hack here and isn't bulletproof, but it is better + than nothing after all. */ +void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * const argv) +{ + char cmdline[300]; + unsigned int length = 0; + bool lastWasOption = false; + bool closeQuote = false; + for (unsigned int i = 0; i < argc; ++i, ++length) + { + for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-1; ++j, ++length) + { + cmdline[length] = argv[i][j]; + if (lastWasOption == true && argv[i][j] == '=') + { + // That is possibly an option: Quote it if it includes spaces, + // the benefit is that this will eliminate also most false positives + const char* c = &argv[i][j+1]; + for (; *c != '\0' && *c != ' '; ++c); + if (*c == '\0') continue; + cmdline[++length] = '"'; + closeQuote = true; + } + } + if (closeQuote == true) + cmdline[length++] = '"'; + // Problem: detects also --hello + if (cmdline[length-1] == 'o') + lastWasOption = true; + cmdline[length] = ' '; + } + cmdline[--length] = '\0'; + _config->Set("CommandLine::AsString", cmdline); +} + /*}}}*/ diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h index e28071e81..7c0c71aa7 100644 --- a/apt-pkg/contrib/cmndline.h +++ b/apt-pkg/contrib/cmndline.h @@ -60,6 +60,7 @@ class CommandLine Configuration *Conf; bool HandleOpt(int &I,int argc,const char *argv[], const char *&Opt,Args *A,bool PreceedeMatch = false); + void static SaveInConfig(unsigned int const &argc, char const * const * const argv); public: -- cgit v1.2.3 From 6dc60370a750334cb701386cfa4ef9719db9078a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 30 Mar 2010 12:38:38 +0200 Subject: replace every call to toupper with one to our own tolower_ascii This sounds like a premature optimization and since Mr. Knuth we all know that they are the root of all evil - but, and here it starts to be interesting: As the tolower_ascii method is by far the most called method we have (~60 Mio. times) and as we compare only strings containing ascii characters (package names, configuration options) using our own method reduces execution time of APT by 4% plus it avoids that the locale settings can influence us. --- apt-pkg/contrib/error.h | 8 ++++---- apt-pkg/contrib/macros.h | 10 ++++++---- apt-pkg/contrib/strutl.cc | 49 +++++++++++++++++++++++++---------------------- apt-pkg/contrib/strutl.h | 21 ++++++-------------- 4 files changed, 42 insertions(+), 46 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 90747ff7e..8d5ec05ea 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -60,13 +60,13 @@ class GlobalError public: // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) __like_printf_2 __cold; - bool WarningE(const char *Function,const char *Description,...) __like_printf_2 __cold; + bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold; + bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold; /* A warning should be considered less severe than an error, and may be ignored by the client. */ - bool Error(const char *Description,...) __like_printf_1 __cold; - bool Warning(const char *Description,...) __like_printf_1 __cold; + bool Error(const char *Description,...) __like_printf(2) __cold; + bool Warning(const char *Description,...) __like_printf(2) __cold; // Simple accessors inline bool PendingError() {return PendingFlag;}; diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index c39caf198..62e7b65db 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -58,6 +58,7 @@ #if __GNUC__ >= 3 #define __must_check __attribute__ ((warn_unused_result)) #define __deprecated __attribute__ ((deprecated)) + #define __attrib_const __attribute__ ((__const__)) /* likely() and unlikely() can be used to mark boolean expressions as (not) likely true which will help the compiler to optimise */ #define likely(x) __builtin_expect (!!(x), 1) @@ -65,6 +66,7 @@ #else #define __must_check /* no warn_unused_result */ #define __deprecated /* no deprecated */ + #define __attrib_const /* no const attribute */ #define likely(x) (x) #define unlikely(x) (x) #endif @@ -72,17 +74,17 @@ // cold functions are unlikely() to be called #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 #define __cold __attribute__ ((__cold__)) + #define __hot __attribute__ ((__hot__)) #else #define __cold /* no cold marker */ + #define __hot /* no hot marker */ #endif #ifdef __GNUG__ // Methods have a hidden this parameter that is visible to this attribute - #define __like_printf_1 __attribute__ ((format (printf, 2, 3))) - #define __like_printf_2 __attribute__ ((format (printf, 3, 4))) + #define __like_printf(n) __attribute__((format(printf, n, n + 1))) #else - #define __like_printf_1 /* no like-printf */ - #define __like_printf_2 /* no like-printf */ + #define __like_printf(n) /* no like-printf */ #endif #endif diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 1b9922a31..ab47cdede 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -566,7 +566,7 @@ int stringcmp(string::const_iterator A,string::const_iterator AEnd, int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) { for (; A != AEnd && B != BEnd; A++, B++) - if (toupper(*A) != toupper(*B)) + if (tolower_ascii(*A) != tolower_ascii(*B)) break; if (A == AEnd && B == BEnd) @@ -575,7 +575,7 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return 1; if (B == BEnd) return -1; - if (toupper(*A) < toupper(*B)) + if (tolower_ascii(*A) < tolower_ascii(*B)) return -1; return 1; } @@ -584,7 +584,7 @@ int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, const char *B,const char *BEnd) { for (; A != AEnd && B != BEnd; A++, B++) - if (toupper(*A) != toupper(*B)) + if (tolower_ascii(*A) != tolower_ascii(*B)) break; if (A == AEnd && B == BEnd) @@ -593,7 +593,7 @@ int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, return 1; if (B == BEnd) return -1; - if (toupper(*A) < toupper(*B)) + if (tolower_ascii(*A) < tolower_ascii(*B)) return -1; return 1; } @@ -601,7 +601,7 @@ int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, string::const_iterator B,string::const_iterator BEnd) { for (; A != AEnd && B != BEnd; A++, B++) - if (toupper(*A) != toupper(*B)) + if (tolower_ascii(*A) != tolower_ascii(*B)) break; if (A == AEnd && B == BEnd) @@ -610,7 +610,7 @@ int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, return 1; if (B == BEnd) return -1; - if (toupper(*A) < toupper(*B)) + if (tolower_ascii(*A) < tolower_ascii(*B)) return -1; return 1; } @@ -789,28 +789,28 @@ bool ReadMessages(int Fd, vector &List) // MonthConv - Converts a month string into a number /*{{{*/ // --------------------------------------------------------------------- /* This was lifted from the boa webserver which lifted it from 'wn-v1.07' - Made it a bit more robust with a few touppers though. */ + Made it a bit more robust with a few tolower_ascii though. */ static int MonthConv(char *Month) { - switch (toupper(*Month)) + switch (tolower_ascii(*Month)) { - case 'A': - return toupper(Month[1]) == 'P'?3:7; - case 'D': + case 'a': + return tolower_ascii(Month[1]) == 'p'?3:7; + case 'd': return 11; - case 'F': + case 'f': return 1; - case 'J': - if (toupper(Month[1]) == 'A') + case 'j': + if (tolower_ascii(Month[1]) == 'a') return 0; - return toupper(Month[2]) == 'N'?5:6; - case 'M': - return toupper(Month[2]) == 'R'?2:4; - case 'N': + return tolower_ascii(Month[2]) == 'n'?5:6; + case 'm': + return tolower_ascii(Month[2]) == 'r'?2:4; + case 'n': return 10; - case 'O': + case 'o': return 9; - case 'S': + case 's': return 8; // Pretend it is January.. @@ -1133,10 +1133,13 @@ char *safe_snprintf(char *Buffer,char *End,const char *Format,...) // tolower_ascii - tolower() function that ignores the locale /*{{{*/ // --------------------------------------------------------------------- -/* */ -int tolower_ascii(int c) +/* This little function is the most called method we have and tries + therefore to do the absolut minimum - and is noteable faster than + standard tolower/toupper and as a bonus avoids problems with different + locales - we only operate on ascii chars anyway. */ +int tolower_ascii(int const c) { - if (c >= 'A' and c <= 'Z') + if (c >= 'A' && c <= 'Z') return c + 32; return c; } diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index e72288f4c..cdf78f317 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -25,19 +25,12 @@ #include #include +#include "macros.h" + using std::string; using std::vector; using std::ostream; -#ifdef __GNUG__ -// Methods have a hidden this parameter that is visible to this attribute -#define APT_FORMAT2 __attribute__ ((format (printf, 2, 3))) -#define APT_FORMAT3 __attribute__ ((format (printf, 3, 4))) -#else -#define APT_FORMAT2 -#define APT_FORMAT3 -#endif - bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest); char *_strstrip(char *String); char *_strtabexpand(char *String,size_t Len); @@ -60,11 +53,11 @@ bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length); bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); vector ExplodeString(string const &haystack, char const &split); -void ioprintf(ostream &out,const char *format,...) APT_FORMAT2; -void strprintf(string &out,const char *format,...) APT_FORMAT2; -char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_FORMAT3; +void ioprintf(ostream &out,const char *format,...) __like_printf(2); +void strprintf(string &out,const char *format,...) __like_printf(2); +char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3); bool CheckDomainList(const string &Host, const string &List); -int tolower_ascii(int c); +int tolower_ascii(int const c) __attrib_const __hot; #define APT_MKSTRCMP(name,func) \ inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \ @@ -144,6 +137,4 @@ struct RxChoiceList unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, const char **ListEnd); -#undef APT_FORMAT2 - #endif -- cgit v1.2.3 From 3f42500d6b9eb318c46cacafdcfd6beb707ef9e9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 30 Mar 2010 14:25:57 +0200 Subject: rename ExplodeString to VectorizeString --- apt-pkg/contrib/strutl.cc | 6 +++--- apt-pkg/contrib/strutl.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index ab47cdede..7eb986ac0 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1000,12 +1000,12 @@ bool TokSplitString(char Tok,char *Input,char **List, return true; } /*}}}*/ -// ExplodeString - Split a string up into a vector /*{{{*/ +// VectorizeString - Split a string up into a vector of strings /*{{{*/ // --------------------------------------------------------------------- /* This can be used to split a given string up into a vector, so the propose is the same as in the method above and this one is a bit slower - also, but the advantage is that we an iteratable vector */ -vector ExplodeString(string const &haystack, char const &split) + also, but the advantage is that we have an iteratable vector */ +vector VectorizeString(string const &haystack, char const &split) { string::const_iterator start = haystack.begin(); string::const_iterator end = start; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index cdf78f317..d8070d3f5 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -52,7 +52,7 @@ bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0) bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length); bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); -vector ExplodeString(string const &haystack, char const &split); +vector VectorizeString(string const &haystack, char const &split) __attrib_const; void ioprintf(ostream &out,const char *format,...) __like_printf(2); void strprintf(string &out,const char *format,...) __like_printf(2); char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3); -- cgit v1.2.3 From 436d7eab92bb8f9cc6498acfbf2055e717be6fd0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 31 Mar 2010 17:19:10 +0200 Subject: Userinfo is urlencoded in URIs (RFC 3986) Thanks to Jean-Baptiste Lallement for spotting and fixing it! * apt-pkg/contrib/strutl.cc: - always escape '%' (LP: #130289) (Closes: #500560) - unescape '%' sequence only if followed by 2 hex digit - username/password are urlencoded in proxy string (RFC 3986) --- apt-pkg/contrib/strutl.cc | 21 +++++++++++++++------ apt-pkg/contrib/strutl.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 7eb986ac0..c7d63ce8a 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -198,7 +198,8 @@ bool ParseQuoteWord(const char *&String,string &Res) char *I; for (I = Buffer; I < Buffer + sizeof(Buffer) && Start != C; I++) { - if (*Start == '%' && Start + 2 < C) + if (*Start == '%' && Start + 2 < C && + isxdigit(Start[1]) && isxdigit(Start[2])) { Tmp[0] = Start[1]; Tmp[1] = Start[2]; @@ -273,7 +274,8 @@ string QuoteString(const string &Str, const char *Bad) for (string::const_iterator I = Str.begin(); I != Str.end(); I++) { if (strchr(Bad,*I) != 0 || isprint(*I) == 0 || - *I <= 0x20 || *I >= 0x7F) + *I == 0x25 || // percent '%' char + *I <= 0x20 || *I >= 0x7F) // control chars { char Buf[10]; sprintf(Buf,"%%%02x",(int)*I); @@ -289,11 +291,17 @@ string QuoteString(const string &Str, const char *Bad) // --------------------------------------------------------------------- /* This undoes QuoteString */ string DeQuoteString(const string &Str) +{ + return DeQuoteString(Str.begin(),Str.end()); +} +string DeQuoteString(string::const_iterator const &begin, + string::const_iterator const &end) { string Res; - for (string::const_iterator I = Str.begin(); I != Str.end(); I++) + for (string::const_iterator I = begin; I != end; I++) { - if (*I == '%' && I + 2 < Str.end()) + if (*I == '%' && I + 2 < end && + isxdigit(I[1]) && isxdigit(I[2])) { char Tmp[3]; Tmp[0] = I[1]; @@ -1238,9 +1246,10 @@ void URI::CopyFrom(const string &U) else { Host.assign(At+1,SingleSlash); - User.assign(FirstColon,SecondColon); + // username and password must be encoded (RFC 3986) + User.assign(DeQuoteString(FirstColon,SecondColon)); if (SecondColon < At) - Password.assign(SecondColon+1,At); + Password.assign(DeQuoteString(SecondColon+1,At)); } // Now we parse the RFC 2732 [] hostnames. diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index d8070d3f5..e509145f9 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -38,6 +38,7 @@ bool ParseQuoteWord(const char *&String,string &Res); 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); string SizeToStr(double Bytes); string TimeToStr(unsigned long Sec); string Base64Encode(const string &Str); -- cgit v1.2.3