File 10805.patch of Package squid-beta

---------------------
PatchSet 10805 
Date: 2007/05/18 06:44:35
Author: amosjeffries
Branch: HEAD
Tag: (none) 
Log:
SqString core apparently not automatically added to cvs by patch.

Members: 
	src/SqString.cc:INITIAL->1.1 
	src/SqString.cci:INITIAL->1.1 
	src/SqString.h:INITIAL->1.1 

--- /dev/null	Fri May 18 06:52:30 2007
+++ squid3/src/SqString.cc	Fri May 18 06:52:30 2007
@@ -0,0 +1,391 @@
+
+/*
+ * $Id: SqString.cc,v 1.1 2007/05/18 06:44:35 amosjeffries Exp $
+ *
+ * DEBUG: section 67    String
+ * AUTHOR: Duane Wessels
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  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 distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "squid.h"
+#include "SqString.h"
+#include "Store.h"
+
+void
+SqString::initBuf(size_t sz)
+{
+    PROF_start(StringInitBuf);
+    clear();
+    buf_ = (char *)memAllocString(sz, &sz);
+    assert(sz < 65536);
+    size_ = sz;
+    PROF_stop(StringInitBuf);
+}
+
+void
+SqString::limitInit(const char *str, int len)
+{
+    PROF_start(StringLimitInit);
+    assert(this && str);
+    initBuf(len + 1);
+    len_ = len;
+    xmemcpy(buf_, str, len);
+    buf_[len] = '\0';
+    PROF_stop(StringLimitInit);
+}
+
+void
+SqString::init(char const *str)
+{
+    assert(this);
+
+    PROF_start(StringInit);
+
+    if (str)
+        limitInit(str, strlen(str));
+    else
+        clear();
+    PROF_stop(StringInit);
+}
+
+void
+SqString::clear()
+{
+    PROF_start(StringClean);
+    assert(this);
+
+    if (buf_)
+        memFreeString(size_, buf_);
+
+    len_ = 0;
+    size_ = 0;
+    buf_ = NULL;
+    PROF_stop(StringClean);
+}
+
+SqString::~SqString()
+{
+    clear();
+#if DEBUGSTRINGS
+
+    SqStringRegistry::Instance().remove(this);
+#endif
+}
+
+SqString::SqString (char const *aString)
+{
+    memset(this, 0, sizeof(SqString));
+
+    init(aString);
+#if DEBUGSTRINGS
+
+    SqStringRegistry::Instance().add(this);
+#endif
+}
+
+SqString &
+SqString::operator =(char const *aString)
+{
+    assert(this);
+    init(aString);
+    return *this;
+}
+
+SqString &
+SqString::operator = (SqString const &old)
+{
+    if (old.size())
+        limitInit(old.c_str(), old.size());
+    else
+        clear();
+
+    return *this;
+}
+
+bool
+SqString::operator == (SqString const &that) const
+{
+    return (this->compare(that) == 0);
+}
+
+bool
+SqString::operator != (SqString const &that) const
+{
+    return (this->compare(that) != 0);
+}
+
+bool
+SqString::operator >= (SqString const &that) const
+{
+    return (this->compare(that) >= 0);
+}
+
+bool
+SqString::operator <= (SqString const &that) const
+{
+    return (this->compare(that) <= 0);
+}
+
+bool
+SqString::operator > (SqString const &that) const
+{
+    return (this->compare(that) > 0);
+}
+
+bool
+SqString::operator < (SqString const &that) const
+{
+    return (this->compare(that) < 0);
+}
+
+SqString::SqString (SqString const &old)
+{
+    memset(this, 0, sizeof(SqString));
+
+    init (old.c_str());
+#if DEBUGSTRINGS
+
+    SqStringRegistry::Instance().add(this);
+#endif
+}
+
+void
+SqString::append(const char *str, int len)
+{
+    assert(this);
+
+    PROF_start(StringAppend);
+
+    if(len < 1 || str == NULL)
+        return;
+
+    if (len_ + len < size_) {
+        strncat(buf_, str, len);
+        len_ += len;
+    } else {
+        unsigned int ssz = len_ + len;
+        unsigned int bsz = len_ + len + 1;
+        char* tmp = (char *)memAllocString(ssz, &bsz);
+        assert(bsz < 65536);
+
+        if (buf_)
+            xmemcpy(tmp, buf_, len_);
+
+        if (len)
+            xmemcpy(tmp + len_, str, len);
+
+        tmp[ssz + 1] = '\0';
+
+        clear();
+
+        size_ = bsz;
+        len_ = ssz;
+        buf_ = tmp;
+        tmp = NULL;
+    }
+    PROF_stop(StringAppend);
+}
+
+void
+SqString::append(char const *str)
+{
+    assert (str);
+    append (str, strlen(str));
+}
+
+void
+SqString::append (char chr)
+{
+    char myString[2];
+    myString[0]=chr;
+    myString[1]='\0';
+    append (myString, 1);
+}
+
+void
+SqString::append(SqString const &old)
+{
+    append (old.c_str(), old.len_);
+}
+
+char&
+SqString::operator [](unsigned int pos)
+{
+    assert(pos < size_ );
+
+    return buf_[pos];
+}
+
+#if DEBUGSTRINGS
+void
+SqString::stat(StoreEntry *entry) const
+{
+    storeAppendPrintf(entry, "%p : %d/%d \"%s\"\n",this,len_, size_, c_str());
+}
+
+SqStringRegistry &
+SqStringRegistry::Instance()
+{
+    return Instance_;
+}
+
+template <class C>
+int
+ptrcmp(C const &lhs, C const &rhs)
+{
+    return lhs - rhs;
+}
+
+void
+SqStringRegistry::registerWithCacheManager(CacheManager & manager)
+{
+    manager.registerAction("strings",
+                           "Strings in use in squid", Stat, 0, 1);
+}
+
+void
+SqStringRegistry::add(SqString const *entry)
+{
+    entries.insert(entry, ptrcmp);
+}
+
+void
+SqStringRegistry::remove(SqString const *entry)
+{
+    entries.remove(entry, ptrcmp);
+}
+
+SqStringRegistry SqStringRegistry::Instance_;
+
+extern size_t memStringCount();
+
+void
+SqStringRegistry::Stat(StoreEntry *entry)
+{
+    storeAppendPrintf(entry, "%lu entries, %lu reported from MemPool\n", (unsigned long) Instance().entries.elements, (unsigned long) memStringCount());
+    Instance().entries.head->walk(Stater, entry);
+}
+
+void
+SqStringRegistry::Stater(SqString const * const & nodedata, void *state)
+{
+    StoreEntry *entry = (StoreEntry *) state;
+    nodedata->stat(entry);
+}
+
+#endif
+
+/*
+ * Similar to strtok, but has some rudimentary knowledge
+ * of quoting
+ */
+char *
+strwordtok(char *buf, char **t)
+{
+    unsigned char *word = NULL;
+    unsigned char *p = (unsigned char *) buf;
+    unsigned char *d;
+    unsigned char ch;
+    int quoted = 0;
+
+    if (!p)
+        p = (unsigned char *) *t;
+
+    if (!p)
+        goto error;
+
+    while (*p && xisspace(*p))
+        p++;
+
+    if (!*p)
+        goto error;
+
+    word = d = p;
+
+    while ((ch = *p)) {
+        switch (ch) {
+
+        case '\\':
+            p++;
+
+            switch (*p) {
+
+            case 'n':
+                ch = '\n';
+
+                break;
+
+            case 'r':
+                ch = '\r';
+
+                break;
+
+            default:
+                ch = *p;
+
+                break;
+
+            }
+
+            *d++ = ch;
+
+            if (ch)
+                p++;
+
+            break;
+
+        case '"':
+            quoted = !quoted;
+
+            p++;
+
+            break;
+
+        default:
+            if (!quoted && xisspace(*p)) {
+                p++;
+                goto done;
+            }
+
+            *d++ = *p++;
+            break;
+        }
+    }
+
+done:
+    *d++ = '\0';
+
+error:
+    *t = (char *) p;
+    return (char *) word;
+}
+
+#ifndef _USE_INLINE_
+#include "SqString.cci"
+#endif
--- /dev/null	Fri May 18 06:52:30 2007
+++ squid3/src/SqString.cci	Fri May 18 06:52:30 2007
@@ -0,0 +1,166 @@
+
+/*
+ * $Id: SqString.cci,v 1.1 2007/05/18 06:44:35 amosjeffries Exp $
+ *
+ * DEBUG: section 67    String
+ * AUTHOR: Duane Wessels
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  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 distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+SqString::SqString() : size_(0), len_(0), buf_ (NULL)
+{
+#if DEBUGSTRINGS
+    SqStringRegistry::Instance().add(this);
+#endif
+}
+
+void
+SqString::absorb(SqString &old)
+{
+    clear();
+    size_ = old.size_;
+    buf_ = old.buf_;
+    len_ = old.len_;
+    old.size_ = 0;
+    old.buf_ = NULL;
+    old.len_ = 0;
+}
+
+int
+SqString::size() const
+{
+    return len_;
+}
+
+char const *
+SqString::c_str() const
+{
+    return buf_;
+}
+
+const char *
+SqString::pos(char const *aString) const
+{
+    return strstr(c_str(), aString);
+}
+
+const char *
+SqString::pos(char const ch) const
+{
+    return strchr(c_str(), ch);
+}
+
+const char *
+SqString::rpos(char const ch) const
+{
+    return strrchr(c_str(), ch);
+}
+
+bool
+SqString::empty() const
+{
+    return (buf_ == NULL || len_ == 0);
+}
+
+int
+SqString::compare(char const *aString) const
+{
+    /* strcmp fails on NULLS */
+
+    if (size() == 0 && (aString == NULL || aString[0] == '\0'))
+        return 0;
+
+    if (size() == 0)
+        return -1;
+
+    if (aString == NULL || aString[0] == '\0')
+        return 1;
+
+    return strcmp(c_str(), aString);
+}
+
+int
+SqString::compare(char const *aString, size_t count) const
+{
+    /* always the same at length 0 */
+
+    if (count == 0)
+        return 0;
+
+    if (size() == 0 && (aString == NULL || aString[0] == '\0'))
+        return 0;
+
+    if (size() == 0)
+        return -1;
+
+    if (aString == NULL || aString[0] == '\0')
+        return 1;
+
+    return strncmp(c_str(), aString, count);
+}
+
+int
+SqString::compare(SqString const &aString) const
+{
+    /* strcmp fails on NULLS */
+
+    if (size() == 0 && aString.size() == 0)
+        return 0;
+
+    if (size() == 0)
+        return -1;
+
+    if (aString.size() == 0)
+        return 1;
+
+    return strcmp(c_str(), aString.c_str());
+}
+
+/* FIXME: this is can perform buffer overflows and underflows! */
+void
+SqString::set (char const *loc, char const ch)
+{
+    buf_[loc-buf_] = ch;
+}
+
+/* FIXME: this is can perform buffer overflows and underflows! */
+void
+SqString::cut (size_t newLength)
+{
+    len_ = newLength;
+    buf_[newLength] = '\0';
+}
+
+/* FIXME: this is can perform buffer overflows and underflows! */
+void
+SqString::cutPointer (char const *loc)
+{
+    len_ = loc-buf_;
+    buf_[len_] = '\0';
+}
--- /dev/null	Fri May 18 06:52:30 2007
+++ squid3/src/SqString.h	Fri May 18 06:52:30 2007
@@ -0,0 +1,155 @@
+
+/*
+ * $Id: SqString.h,v 1.1 2007/05/18 06:44:35 amosjeffries Exp $
+ *
+ * DEBUG: section 67    String
+ * AUTHOR: Duane Wessels
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  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 distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#ifndef SQSTRING_H
+#define SQSTRING_H
+
+/* forward decls */
+
+class CacheManager;
+
+#define DEBUGSTRINGS 0
+#if DEBUGSTRINGS
+#include "splay.h"
+
+class SqString;
+
+class SqStringRegistry
+{
+
+public:
+    static StringRegistry &Instance();
+
+    void add
+        (SqString const *);
+
+    void registerWithCacheManager(CacheManager & manager);
+
+    void remove
+        (SqString const *);
+
+private:
+    static OBJH Stat;
+
+    static StringRegistry Instance_;
+
+    static SplayNode<SqString const *>::SPLAYWALKEE Stater;
+
+    Splay<SqString const *> entries;
+
+    bool registered;
+
+};
+
+class StoreEntry;
+#endif
+
+class SqString
+{
+
+public:
+
+    /* std::string API available */
+    _SQUID_INLINE_ SqString();
+    SqString (char const *);
+    SqString (SqString const &);
+    ~SqString();
+
+    SqString &operator =(char const *);
+    SqString &operator =(SqString const &);
+    bool operator ==(SqString const &) const;
+    bool operator !=(SqString const &) const;
+    bool operator >=(SqString const &) const;
+    bool operator <=(SqString const &) const;
+    bool operator >(SqString const &) const;
+    bool operator <(SqString const &) const;
+
+    _SQUID_INLINE_ int size() const;
+    _SQUID_INLINE_ char const * c_str() const;
+
+    char& operator [](unsigned int);
+
+    void clear();
+
+    void append(char const *buf, int len);
+    void append(char const *buf);
+    void append(char const);
+    void append(SqString const &);
+
+    _SQUID_INLINE_ bool empty() const;
+    _SQUID_INLINE_ int compare(char const *) const;
+    _SQUID_INLINE_ int compare(char const *, size_t count) const;
+    _SQUID_INLINE_ int compare(SqString const &) const;
+
+/* Custom Squid Operations available */
+    /// Super-efficient string assignment. Moves internal content from one object to another.
+    /// then resets the initial pobject to empty.
+    _SQUID_INLINE_ void absorb(SqString &old);
+    _SQUID_INLINE_ const char * pos(char const *) const;
+    _SQUID_INLINE_ const char * pos(char const ch) const;
+    _SQUID_INLINE_ const char * rpos(char const ch) const;
+
+    _SQUID_INLINE_ void set
+        (char const *loc, char const ch);
+
+    _SQUID_INLINE_ void cut (size_t newLength);
+
+    _SQUID_INLINE_ void cutPointer (char const *loc);
+
+#if DEBUGSTRINGS
+
+    void stat (StoreEntry *) const;
+
+#endif
+
+    void limitInit(const char *str, int len);
+private:
+    void initBuf(size_t sz);
+    void init (char const *);
+
+    /* never reference these directly! */
+    unsigned short int size_;	/* buffer size; 64K limit */
+
+    unsigned short int len_;	/* current length  */
+
+    char *buf_;
+};
+
+#ifdef _USE_INLINE_
+#include "SqString.cci"
+#endif
+
+#endif /* SQSTRING_H */
+
openSUSE Build Service is sponsored by