]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implemented String::npos to parametrize 'search not found' results
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 12 Feb 2009 11:17:16 +0000 (12:17 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 12 Feb 2009 11:17:16 +0000 (12:17 +0100)
Converted some printf to macro-based.

src/ICAP/ICAPModXact.cc
src/SquidString.h
src/String.cci
src/adaptation/Config.cc
src/ftp.cc
src/urn.cc
src/whois.cc

index 0a919f5c7dfab413015cd0f6225004a504e904f0..a929d5ec9905b2aa86f34b4f109a06a317caec9f 100644 (file)
@@ -1029,8 +1029,8 @@ void ICAPModXact::makeRequestHeaders(MemBuf &buf)
      * XXX These should use HttpHdr interfaces instead of Printfs
      */
     const Adaptation::ServiceConfig &s = service().cfg();
-    buf.Printf("%s %.*s ICAP/1.0\r\n", s.methodStr(), s.uri.size(), s.uri.rawBuf());
-    buf.Printf("Host: %.*s:%d\r\n", s.host.size(), s.host.rawBuf(), s.port);
+    buf.Printf("%s " SQUIDSTRINGPH " ICAP/1.0\r\n", s.methodStr(), SQUIDSTRINGPRINT(s.uri));
+    buf.Printf("Host: " SQUIDSTRINGPPH ":%d\r\n", SQUIDSTRINGPRINT(s.host), s.port);
     buf.Printf("Date: %s\r\n", mkrfc1123(squid_curtime));
 
     if (!TheICAPConfig.reuse_connections)
index 897ce13d723e93d5727ef0307b5d5e0eb4486148..6ff08e890e7700e4e3c0ba9542ef7ca4ec2523a3 100644 (file)
@@ -93,6 +93,7 @@ public:
     ~String();
 
     typedef size_t size_type; //storage size intentionally unspecified
+    const static size_type npos = std::string::npos;
 
     String &operator =(char const *);
     String &operator =(String const &);
@@ -139,7 +140,7 @@ public:
     _SQUID_INLINE_ const char * pos(char const *) const;
     _SQUID_INLINE_ const char * pos(char const ch) const;
     ///offset from string start of the first occurrence of ch
-    /// returns std::string::npos if ch is not found
+    /// returns String::npos if ch is not found
     _SQUID_INLINE_ size_type find(char const ch) const;
     _SQUID_INLINE_ const char * rpos(char const ch) const;
     _SQUID_INLINE_ size_type rfind(char const ch) const;
index adbf8916dea1b73e8f02dc10ef15e67e7225ec38..71b68ba22bc3cfe5741031855c4ea0b8976f55d4 100644 (file)
@@ -106,7 +106,7 @@ String::find(char const ch) const
     const char *c;
     c=pos(ch);
     if (c==NULL)
-        return std::string::npos;
+        return npos;
     return c-rawBuf();
 }
 
@@ -122,7 +122,7 @@ String::rfind(char const ch) const
     const char *c;
     c=rpos(ch);
     if (c==NULL)
-        return std::string::npos;
+        return npos;
     return c-rawBuf();
 }
 
index 1ae4ee486313c38aa02abdfe39aa48a07437d782..f8833eea1741b775c7d4f505e99218b2977fd289 100644 (file)
@@ -144,7 +144,7 @@ Adaptation::Config::DumpServiceSet(StoreEntry *entry, const char *name)
 {
     typedef Groups::iterator GI;
     for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i)
-        storeAppendPrintf(entry, "%s %.*s\n", name, (*i)->id.psize(), (*i)->id.rawBuf());
+        storeAppendPrintf(entry, "%s " SQUIDSTRINGPH "\n", name, SQUIDSTRINGPRINT((*i)->id));
 }
 
 void
@@ -184,7 +184,7 @@ Adaptation::Config::DumpAccess(StoreEntry *entry, const char *name)
 
     typedef AccessRules::iterator CI;
     for (CI i = AllRules().begin(); i != AllRules().end(); ++i) {
-        snprintf(nom, 64, "%s %.*s", name, (*i)->groupId.psize(), (*i)->groupId.rawBuf());
+        snprintf(nom, 64, "%s " SQUIDSTRINGPH, name, SQUIDSTRINGPRINT((*i)->groupId));
         dump_acl_access(entry, nom, (*i)->acl);
     }
 }
index dfccaf3e6330a819495664888bdaed12c6bdec26..cf4e1e28547375dfd06d7447c5b56b9457dc1f82 100644 (file)
@@ -1455,7 +1455,7 @@ FtpStateData::checkUrlpath()
     if (str_type_eq.undefined()) //hack. String doesn't support global-static
         str_type_eq="type=";
 
-    if ((t = request->urlpath.rfind(';')) != std::string::npos) {
+    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);
index 0c77a47fb05c131aa6ecff785b0069e045e37c91..d4cd5261bfa1c88cc0e881409c41bf593f7e89d0 100644 (file)
@@ -171,7 +171,7 @@ UrnState::getHost (String &urlpath)
 
     /** FIXME: this appears to be parsing the URL. *very* badly. */
     /*   a proper encapsulated URI/URL type needs to clear this up. */
-    if ((p=urlpath.find(':')) != std::string::npos) {
+    if ((p=urlpath.find(':')) != String::npos) {
         result=xstrndup(urlpath.rawBuf(),p-1);
     } else {
         result = xstrndup(urlpath.rawBuf(),urlpath.size());
@@ -201,7 +201,8 @@ UrnState::createUriResRequest (String &uri)
 {
     LOCAL_ARRAY(char, local_urlres, 4096);
     char *host = getHost (uri);
-    snprintf(local_urlres, 4096, "http://%s/uri-res/N2L?urn:%.*s", host, uri.psize(), uri.rawBuf());
+    snprintf(local_urlres, 4096, "http://%s/uri-res/N2L?urn:" SQUIDSTRINGPH,
+        host, SQUIDSTRINGPRINT(uri));
     safe_free (host);
     safe_free (urlres);
     urlres = xstrdup (local_urlres);
index c72e7ea025bbf8b7df69f7cd150140b784dab521..34fcf7f0768471572438a8cbcd0e18bc7e60a756 100644 (file)
@@ -98,7 +98,8 @@ whoisStart(FwdState * fwd)
 
     buf = (char *)xmalloc(l);
 
-    snprintf(buf, l, "%.*s\r\n", p->request->urlpath.psize()-1, p->request->urlpath.rawBuf() + 1);
+    String str_print=p->request->urlpath.substr(1,p->request->urlpath.size());
+    snprintf(buf, l, SQUIDSTRINGPH"\r\n", SQUIDSTRINGPRINT(str_print));
 
     comm_write(fd, buf, strlen(buf), whoisWriteComplete, p, NULL);
     comm_read(fd, p->buf, BUFSIZ, whoisReadReply, p);