String.operator[] now returns a copy of a char rather than a reference.
Implemented StringNg-alike String.find() method. Eventual aim is to get rid of users of String.pos()
HttpRequest *
HttpRequest::clone() const
{
- HttpRequest *copy = new HttpRequest(method, protocol, urlpath.unsafeBuf());
+ HttpRequest *copy = new HttpRequest(method, protocol, urlpath.termedBuf());
// TODO: move common cloning clone to Msg::copyTo() or copy ctor
copy->header.append(&header);
copy->hdrCacheInit();
{
assert(p);
/* pack request-line */
- packerPrintf(p, "%s %s HTTP/1.0\r\n",
- RequestMethodStr(method), urlpath.unsafeBuf());
+ packerPrintf(p, "%s %.*s HTTP/1.0\r\n",
+ RequestMethodStr(method), urlpath.size(), urlpath.rawBuf());
/* headers */
header.packInto(p);
/* trailer */
assert(e);
/* check connection header */
- if (strConn && strListIsMember(strConn, e->name.unsafeBuf(), ','))
+ if (strConn && strListIsMember(strConn, e->name.termedBuf(), ','))
return 0;
return 1;
return urlCanonical((HttpRequest*)this);
if (urlpath.size())
- return urlpath.unsafeBuf();
+ return urlpath.termedBuf();
return "/";
}
return RequestMethodStr[theMethod];
} else {
if (theImage.size()>0) {
- return theImage.unsafeBuf();
+ return theImage.termedBuf();
} else {
return "METHOD_OTHER";
}
void *LoadableModule::openModule(int mode)
{
# if XSTD_USE_LIBLTDL
- return lt_dlopen(theName.unsafeBuf());
+ return lt_dlopen(theName.termedBuf());
# else
return dlopen(theName.c_str(),
mode == lmNow ? RTLD_NOW : RTLD_LAZY);
* Retrieve a single character in the string.
\param pos Position of character to retrieve.
*/
- _SQUID_INLINE_ char &operator [](unsigned int pos);
+ _SQUID_INLINE_ char operator [](unsigned int pos);
_SQUID_INLINE_ int size() const;
_SQUID_INLINE_ char const * unsafeBuf() const;
void absorb(String &old);
_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
+ _SQUID_INLINE_ size_t find(char const ch) const;
_SQUID_INLINE_ const char * rpos(char const ch) const;
_SQUID_INLINE_ int cmp (char const *) const;
_SQUID_INLINE_ int cmp (char const *, size_t count) const;
snew.allocBuffer(snew.len_ + 1);
if (len_)
- xmemcpy(snew.buf_, unsafeBuf(), len_);
+ xmemcpy(snew.buf_, rawBuf(), len_);
if (len)
xmemcpy(snew.buf_ + len_, str, len);
return buf_;
}
-char&
+char
String::operator [](unsigned int pos)
{
assert(pos < size_);
return strchr(termedBuf(), ch);
}
+size_t
+String::find(char const ch) const
+{
+ const char *c;
+ c=pos(ch);
+ if (c==NULL)
+ return std::string::npos;
+ return c-rawBuf();
+}
+
const char *
String::rpos(char const ch) const
{
internalStart(HttpRequest * request, StoreEntry * entry)
{
ErrorState *err;
- const char *upath = request->urlpath.unsafeBuf();
+ const char *upath = request->urlpath.termedBuf();
debugs(76, 3, "internalStart: " << request->client_addr << " requesting '" << upath << "'");
if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) {
if (http->request->auth_user_request)
r->client_ident = http->request->auth_user_request->username();
- else if (http->request->extacl_user.unsafeBuf() != NULL) {
- r->client_ident = http->request->extacl_user.unsafeBuf();
+ else if (http->request->extacl_user.defined()) {
+ r->client_ident = http->request->extacl_user.termedBuf();
}
if (!r->client_ident && (conn != NULL && conn->rfc931[0]))
if (http->request->auth_user_request)
p = http->request->auth_user_request->username();
- else if (http->request->extacl_user.unsafeBuf() != NULL) {
- p = http->request->extacl_user.unsafeBuf();
+ else if (http->request->extacl_user.defined()) {
+ p = http->request->extacl_user.termedBuf();
}
if (!p && (conn != NULL && conn->rfc931[0]))
if (vary.size()) {
/* Again, we own this structure layout */
- rep->header.putStr(HDR_VARY, vary.unsafeBuf());
+ rep->header.putStr(HDR_VARY, vary.termedBuf());
vary.clean();
}
return request->canonical;
if (request->protocol == PROTO_URN) {
- snprintf(urlbuf, MAX_URL, "urn:%s", request->urlpath.unsafeBuf());
+ snprintf(urlbuf, MAX_URL, "urn:%.*s",
+ request->urlpath.size(),
+ request->urlpath.rawBuf());
} else {
/// \todo AYJ: this could use "if..else and method == METHOD_CONNECT" easier.
switch (request->method.id()) {
if (request->port != urlDefaultPort(request->protocol))
snprintf(portbuf, 32, ":%d", request->port);
- snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%s",
+ snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%.*s",
ProtocolStr[request->protocol],
request->login,
*request->login ? "@" : null_string,
request->GetHost(),
portbuf,
- request->urlpath.unsafeBuf());
+ request->urlpath.size(),
+ request->urlpath.rawBuf());
break;
}
char *t;
if (request->protocol == PROTO_URN) {
- snprintf(buf, MAX_URL, "urn:%s", request->urlpath.unsafeBuf());
+ snprintf(buf, MAX_URL, "urn:%.*s",
+ request->urlpath.size(), request->urlpath.rawBuf());
} else {
/// \todo AYJ: this could use "if..else and method == METHOD_CONNECT" easier.
switch (request->method.id()) {
strcat(loginbuf, "@");
}
- snprintf(buf, MAX_URL, "%s://%s%s%s%s",
+ snprintf(buf, MAX_URL, "%s://%s%s%s%.*s",
ProtocolStr[request->protocol],
loginbuf,
request->GetHost(),
portbuf,
- request->urlpath.unsafeBuf());
+ request->urlpath.size(),
+ request->urlpath.rawBuf());
/*
* strip arguments AFTER a question-mark
*/
char *urlbuf = (char *)xmalloc(MAX_URL * sizeof(char));
if (req->protocol == PROTO_URN) {
- snprintf(urlbuf, MAX_URL, "urn:%s", req->urlpath.unsafeBuf());
+ snprintf(urlbuf, MAX_URL, "urn:%.*s",
+ req->urlpath.size(),
+ req->urlpath.rawBuf());
return (urlbuf);
}
if (relUrl[0] == '/') {
strncpy(&urlbuf[urllen], relUrl, MAX_URL - urllen - 1);
} else {
- const char *path = req->urlpath.unsafeBuf();
+ const char *path = req->urlpath.termedBuf();
const char *last_slash = strrchr(path, '/');
if (last_slash == NULL) {
UrnState::getHost (String &urlpath)
{
char * result;
- char const *t;
+ size_t p;
- /* FIXME: this appears to be parsing the URL. *very* badly. */
- /* FIXME: a proper encapsulated URI/URL type needs to clear this up. */
-
- if ((t = urlpath.pos(':')) != NULL) {
- urlpath.set(t, '\0');
- result = xstrdup(urlpath.unsafeBuf());
- urlpath.set(t, ':');
+ /** 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) {
+ result=xstrndup(urlpath.rawBuf(),p-1);
} else {
- result = xstrdup(urlpath.unsafeBuf());
+ result = xstrndup(urlpath.rawBuf(),urlpath.size());
}
-
return result;
}