On 16/10/2013 7:58 a.m., Alex Rousskov wrote:
On 10/11/2013 06:38 AM, Amos Jeffries wrote:
To aid the conversion of String to SBuf,
It appears that all code using String::undefined() for boolean tests can
remain logically consistent using checks on string size() instead.
This helps by removing part of the
undefined-empty/defined-empty/0-length-empty string state differentiation.
AFAICT, the patch attached to your email was empty:
Strange. Lets try again.
Amos
=== modified file 'src/HttpHdrSc.cc'
--- src/HttpHdrSc.cc 2013-02-02 10:56:53 +0000
+++ src/HttpHdrSc.cc 2013-10-10 13:16:35 +0000
@@ -347,43 +347,43 @@
{
extern const HttpHeaderStat *dump_stat; /* argh! */
const int id = (int) val;
const int valid_id = id >= 0 && id < SC_ENUM_END;
const char *name = valid_id ? ScFieldsInfo[id].name.termedBuf() :
"INVALID";
if (count || valid_id)
storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
id, name, count, xdiv(count,
dump_stat->scParsedCount));
}
HttpHdrScTarget *
HttpHdrSc::findTarget(const char *target)
{
dlink_node *node;
node = targets.head;
while (node) {
HttpHdrScTarget *sct = (HttpHdrScTarget *)node->data;
- if (target && sct->target.defined() && !strcmp (target,
sct->target.termedBuf()))
+ if (target && sct->target.size() > 0 && !strcmp(target,
sct->target.termedBuf()))
return sct;
- else if (!target && sct->target.undefined())
+ else if (!target && sct->target.size() == 0)
return sct;
node = node->next;
}
return NULL;
}
HttpHdrScTarget *
HttpHdrSc::getMergedTarget(const char *ourtarget)
{
HttpHdrScTarget *sctus = findTarget(ourtarget);
HttpHdrScTarget *sctgeneric = findTarget(NULL);
if (sctgeneric || sctus) {
HttpHdrScTarget *sctusable = new HttpHdrScTarget(NULL);
if (sctgeneric)
sctusable->mergeWith(sctgeneric);
=== modified file 'src/HttpReply.cc'
--- src/HttpReply.cc 2013-03-18 06:24:15 +0000
+++ src/HttpReply.cc 2013-10-10 13:23:14 +0000
@@ -253,55 +253,55 @@
*/
int
HttpReply::validatorsMatch(HttpReply const * otherRep) const
{
String one,two;
assert (otherRep);
/* Numbers first - easiest to check */
/* Content-Length */
/* TODO: remove -1 bypass */
if (content_length != otherRep->content_length
&& content_length > -1 &&
otherRep->content_length > -1)
return 0;
/* ETag */
one = header.getStrOrList(HDR_ETAG);
two = otherRep->header.getStrOrList(HDR_ETAG);
- if (one.undefined() || two.undefined() || one.caseCmp(two)!=0 ) {
+ if (one.size()==0 || two.size()==0 || one.caseCmp(two)!=0 ) {
one.clean();
two.clean();
return 0;
}
if (last_modified != otherRep->last_modified)
return 0;
/* MD5 */
one = header.getStrOrList(HDR_CONTENT_MD5);
two = otherRep->header.getStrOrList(HDR_CONTENT_MD5);
- if (one.undefined() || two.undefined() || one.caseCmp(two) != 0 ) {
+ if (one.size()==0 || two.size()==0 || one.caseCmp(two)!=0 ) {
one.clean();
two.clean();
return 0;
}
return 1;
}
void
HttpReply::updateOnNotModified(HttpReply const * freshRep)
{
assert(freshRep);
/* clean cache */
hdrCacheClean();
/* update raw headers */
header.update(&freshRep->header,
(const HttpHeaderMask *) &Denied304HeadersMask);
header.compact();
=== modified file 'src/SquidString.h'
--- src/SquidString.h 2013-10-10 13:24:48 +0000
+++ src/SquidString.h 2013-10-10 13:28:55 +0000
@@ -43,41 +43,40 @@
String &operator =(SBuf s) {
defined_=true;
buf_=s;
return *this;
}
bool operator ==(String const &s) const {return defined() == s.defined()
&& buf_ == s.buf_;}
bool operator !=(String const &s) const {return defined() != s.defined()
|| buf_ != s.buf_;}
char operator [](unsigned int p) const {return buf_[p];}
size_type size() const {return buf_.length();}
/// variant of size() suited to be used for printf-alikes.
/// throws when size() would overflow
int psize() const {
Must(buf_.length() < INT_MAX);
return buf_.length();
}
bool defined() const {return defined_;}
- bool undefined() const {return !defined();}
/**
* Returns a raw pointer to the underlying backing store. The caller has
been
* verified not to make any assumptions about null-termination
*/
char const * rawBuf() const {return termedBuf();}
/**
* Returns a raw pointer to the underlying backing store.
* The caller requires it to be null-terminated.
*/
char const * termedBuf() const {
if (!defined()) return NULL;
// XXX: callers will probably try and write to the buffer,
// but SquidString never offered any more guarantee than SBuf
// does now about buffers existence.
return buf_.c_str();
}
SBuf toSBuf() const {return buf_;}
void limitInit(const char *str, int len) {
clean();
append(str,len);
@@ -169,41 +168,41 @@
String substr(size_type from, size_type to) const {
Must(from < buf_.length());
Must(to > 0 && to <= buf_.length());
Must(to > from);
return String(buf_.substr(from, to-from));
}
void cut(size_type newLength) {
if (newLength > buf_.length()) return;
if (buf_.length() == 0 && !defined()) return;
buf_.setAt(newLength, '\0');
buf_.chop(newLength);
}
private:
mutable SBuf buf_;
// SquidString used to track whether buf_ was NULL or not
// and some code makes use of this property.
- // Until that is all checked and defined()/undefined() erased
+ // Until that is all checked and defined() erased
// we explicitly track whether SquidString would have had
// buf_ allocated.
mutable bool defined_;
};
inline std::ostream & operator<<(std::ostream& os, String const &aString) {
return os << aString.toSBuf();
}
inline bool operator<(const String &a, const String &b) {
return a.toSBuf().cmp(b.toSBuf()) < 0;
}
inline const char *checkNullString(const char *p) {
return p ? p : "(NULL)";
}
inline int stringHasWhitespace(const char *s) {
return strpbrk(s, w_space) != NULL;
}
=== modified file 'src/acl/HttpHeaderData.cc'
--- src/acl/HttpHeaderData.cc 2012-11-26 18:54:43 +0000
+++ src/acl/HttpHeaderData.cc 2013-10-10 13:25:39 +0000
@@ -91,33 +91,33 @@
wordlistAdd(&W, hdrName.termedBuf());
wordlist * regex_dump = regex_rule->dump();
wordlistAddWl(&W, regex_dump);
wordlistDestroy(®ex_dump);
return W;
}
void
ACLHTTPHeaderData::parse()
{
char* t = strtokFile();
assert (t != NULL);
hdrName = t;
hdrId = httpHeaderIdByNameDef(hdrName.rawBuf(), hdrName.size());
regex_rule->parse();
}
bool
ACLHTTPHeaderData::empty() const
{
- return (hdrId == HDR_BAD_HDR && hdrName.undefined()) ||
regex_rule->empty();
+ return (hdrId == HDR_BAD_HDR && hdrName.size()==0) || regex_rule->empty();
}
ACLData<HttpHeader*> *
ACLHTTPHeaderData::clone() const
{
/* Header's don't clone yet. */
ACLHTTPHeaderData * result = new ACLHTTPHeaderData;
result->regex_rule = regex_rule->clone();
result->hdrId = hdrId;
result->hdrName = hdrName;
return result;
}
=== modified file 'src/acl/NoteData.cc'
--- src/acl/NoteData.cc 2013-05-25 07:13:09 +0000
+++ src/acl/NoteData.cc 2013-10-10 13:16:09 +0000
@@ -57,31 +57,31 @@
wordlist *W = NULL;
wordlistAdd(&W, name.termedBuf());
wordlist * dumpR = values->dump();
wordlistAddWl(&W, dumpR);
wordlistDestroy(&dumpR);
return W;
}
void
ACLNoteData::parse()
{
char* t = strtokFile();
assert (t != NULL);
name = t;
values->parse();
}
bool
ACLNoteData::empty() const
{
- return name.undefined();
+ return name.size() == 0;
}
ACLData<HttpRequest *> *
ACLNoteData::clone() const
{
ACLNoteData * result = new ACLNoteData;
result->values = values->clone();
result->name = name;
return result;
}
=== modified file 'src/ftp.cc'
--- src/ftp.cc 2013-06-19 04:59:56 +0000
+++ src/ftp.cc 2013-10-10 13:26:17 +0000
@@ -1402,41 +1402,41 @@
xstrncpy(password, Config.Ftp.anon_user, MAX_URL);
flags.tried_auth_anonymous=1;
return 1;
} else if (!flags.tried_auth_nopass) {
xstrncpy(password, null_string, MAX_URL);
flags.tried_auth_nopass=1;
return 1;
}
}
return 0; /* different username */
}
static String str_type_eq;
void
FtpStateData::checkUrlpath()
{
int l;
size_t t;
- if (str_type_eq.undefined()) //hack. String doesn't support global-static
+ if (str_type_eq.size()==0) //hack. String doesn't support global-static
str_type_eq="type=";
if ((t = request->urlpath.rfind(';')) != String::npos) {
if (request->urlpath.substr(t+1,t+1+str_type_eq.size())==str_type_eq) {
typecode =
(char)xtoupper(request->urlpath[t+str_type_eq.size()+1]);
request->urlpath.cut(t);
}
}
l = request->urlpath.size();
/* check for null path */
if (!l) {
flags.isdir = 1;
flags.root_dir = 1;
flags.need_base_href = 1; /* Work around broken browsers */
} else if (!request->urlpath.cmp("/%2f/")) {
/* UNIX root directory */
flags.isdir = 1;
flags.root_dir = 1;
=== modified file 'src/http.cc'
--- src/http.cc 2013-07-16 00:13:03 +0000
+++ src/http.cc 2013-10-10 13:27:09 +0000
@@ -969,41 +969,41 @@
break;
default:
assert(0);
break;
}
no_cache:
if (!ignoreCacheControl) {
if (rep->cache_control) {
// We are required to revalidate on many conditions.
// For security reasons we do so even if storage was caused by
refresh_pattern ignore-* option
// CC:must-revalidate or CC:proxy-revalidate
const bool ccMustRevalidate =
(rep->cache_control->proxyRevalidate() || rep->cache_control->mustRevalidate());
// CC:no-cache (only if there are no parameters)
- const bool ccNoCacheNoParams = (rep->cache_control->hasNoCache()
&& rep->cache_control->noCache().undefined());
+ const bool ccNoCacheNoParams = (rep->cache_control->hasNoCache()
&& rep->cache_control->noCache().size()==0);
// CC:s-maxage=N
const bool ccSMaxAge = rep->cache_control->hasSMaxAge();
// CC:private (yes, these can sometimes be stored)
const bool ccPrivate = rep->cache_control->hasPrivate();
if (ccMustRevalidate || ccNoCacheNoParams || ccSMaxAge ||
ccPrivate)
EBIT_SET(entry->flags, ENTRY_REVALIDATE);
}
#if USE_HTTP_VIOLATIONS // response header Pragma::no-cache is undefined in
HTTP
else {
// Expensive calculation. So only do it IF the CC: header is not
present.
/* HACK: Pragma: no-cache in _replies_ is not documented in HTTP,
* but servers like "Active Imaging Webcast/2.0" sure do use it */
if (rep->header.has(HDR_PRAGMA) &&
rep->header.hasListMember(HDR_PRAGMA,"no-cache",','))
EBIT_SET(entry->flags, ENTRY_REVALIDATE);
}
=== modified file 'src/store_log.cc'
--- src/store_log.cc 2013-03-18 04:55:51 +0000
+++ src/store_log.cc 2013-10-10 13:27:48 +0000
@@ -45,41 +45,41 @@
"CREATE",
"SWAPIN",
"SWAPOUT",
"RELEASE",
"SO_FAIL",
};
static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
static OBJH storeLogTagsHist;
static Logfile *storelog = NULL;
static String str_unknown;
void
storeLog(int tag, const StoreEntry * e)
{
MemObject *mem = e->mem_obj;
HttpReply const *reply;
- if (str_unknown.undefined())
+ if (str_unknown.size()==0)
str_unknown="unknown"; //hack. Delay initialization as string doesn't
support global variables..
if (NULL == storelog)
return;
++storeLogTagsCounts[tag];
if (mem != NULL) {
if (mem->log_url == NULL) {
debugs(20, DBG_IMPORTANT, "storeLog: NULL log_url for " <<
mem->url);
mem->dump();
mem->log_url = xstrdup(mem->url);
}
reply = e->getReply();
/*
* XXX Ok, where should we print the dir number here?
* Because if we print it before the swap file number, it'll break
* the existing log format.
*/