#include <SBuf.h>

Collaboration diagram for SBuf:

Classes

class  Locker
 

Public Types

typedef MemBlob::size_type size_type
 
typedef SBufIterator const_iterator
 
typedef SBufReverseIterator const_reverse_iterator
 

Public Member Functions

 SBuf ()
 create an empty (zero-size) SBuf More...
 
 SBuf (const SBuf &S)
 
 SBuf (SBuf &&S)
 
 SBuf (const char *S, size_type n)
 
 SBuf (const char *S)
 
 SBuf (const std::string &s)
 Constructor: import std::string. Contents are copied. More...
 
 ~SBuf ()
 
SBufassign (const SBuf &S)
 
SBufoperator= (const SBuf &S)
 
SBufoperator= (SBuf &&S)
 
SBufassign (const char *S, size_type n)
 
SBufassign (const char *S)
 
SBufoperator= (const char *S)
 
void clear ()
 
SBufappend (const SBuf &S)
 
SBufappend (const char c)
 Append a single character. The character may be NUL (\0). More...
 
SBufappend (const char *S, size_type Ssize)
 
SBufappend (const char *S)
 
SBufPrintf (const char *fmt,...)
 
SBufappendf (const char *fmt,...)
 
SBufvappendf (const char *fmt, va_list vargs)
 
std::ostream & print (std::ostream &os) const
 print the SBuf contents to the supplied ostream More...
 
std::ostream & dump (std::ostream &os) const
 
char operator[] (size_type pos) const
 
char at (size_type pos) const
 
void setAt (size_type pos, char toset)
 
int compare (const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const
 
int compare (const SBuf &S, const SBufCaseSensitive isCaseSensitive) const
 
int cmp (const SBuf &S, const size_type n) const
 shorthand version for compare() More...
 
int cmp (const SBuf &S) const
 
int caseCmp (const SBuf &S, const size_type n) const
 shorthand version for case-insensitive compare() More...
 
int caseCmp (const SBuf &S) const
 
int compare (const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const
 Comparison with a C-string. More...
 
int compare (const char *s, const SBufCaseSensitive isCaseSensitive) const
 
int cmp (const char *S, const size_type n) const
 Shorthand version for C-string compare(). More...
 
int cmp (const char *S) const
 
int caseCmp (const char *S, const size_type n) const
 Shorthand version for case-insensitive C-string compare(). More...
 
int caseCmp (const char *S) const
 
bool startsWith (const SBuf &S, const SBufCaseSensitive isCaseSensitive=caseSensitive) const
 
bool operator== (const SBuf &S) const
 
bool operator!= (const SBuf &S) const
 
bool operator< (const SBuf &S) const
 
bool operator> (const SBuf &S) const
 
bool operator<= (const SBuf &S) const
 
bool operator>= (const SBuf &S) const
 
SBuf consume (size_type n=npos)
 
size_type copy (char *dest, size_type n) const
 
const char * rawContent () const
 
char * rawAppendStart (size_type anticipatedSize)
 
void rawAppendFinish (const char *start, size_type actualSize)
 
size_type spaceSize () const
 
const char * c_str ()
 
size_type length () const
 Returns the number of bytes stored in SBuf. More...
 
int plength () const
 
bool isEmpty () const
 
void reserveSpace (size_type minSpace)
 
void reserveCapacity (size_type minCapacity)
 
size_type reserve (const SBufReservationRequirements &requirements)
 
SBufchop (size_type pos, size_type n=npos)
 
SBuftrim (const SBuf &toRemove, bool atBeginning=true, bool atEnd=true)
 
SBuf substr (size_type pos, size_type n=npos) const
 
size_type find (char c, size_type startPos=0) const
 
size_type find (const SBuf &str, size_type startPos=0) const
 
size_type rfind (char c, size_type endPos=npos) const
 
size_type rfind (const SBuf &str, size_type endPos=npos) const
 
size_type findFirstOf (const CharacterSet &set, size_type startPos=0) const
 
size_type findLastOf (const CharacterSet &set, size_type endPos=npos) const
 
size_type findFirstNotOf (const CharacterSet &set, size_type startPos=0) const
 
size_type findLastNotOf (const CharacterSet &set, size_type endPos=npos) const
 
void toLower ()
 converts all characters to lower case; More...
 
void toUpper ()
 converts all characters to upper case; More...
 
std::string toStdString () const
 std::string export function More...
 
const_iterator begin () const
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 

Static Public Member Functions

static const SBufStatsGetStats ()
 gets global statistic informations More...
 

Public Attributes

const InstanceId< SBufid
 

Static Public Attributes

static const size_type npos = 0xffffffff
 
static const size_type maxSize = 0xfffffff
 Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb. More...
 

Private Member Functions

char * buf () const
 
char * bufEnd () const
 
size_type estimateCapacity (size_type desired) const
 
void reAlloc (size_type newsize)
 
void cow (size_type minsize=npos)
 
void checkAccessBounds (size_type pos) const
 
char * rawSpace (size_type minSize)
 
SBuflowAppend (const char *memArea, size_type areaSize)
 

Static Private Member Functions

static MemBlob::Pointer GetStorePrototype ()
 

Private Attributes

MemBlob::Pointer store_
 memory block, possibly shared with other SBufs More...
 
size_type off_ = 0
 our content start offset from the beginning of shared store_ More...
 
size_type len_ = 0
 number of our content bytes in shared store_ More...
 

Static Private Attributes

static SBufStats stats
 class-wide statistics More...
 

Friends

class Locker
 

Detailed Description

A String or Buffer. Features: refcounted backing store, cheap copy and sub-stringing operations, copy-on-write to isolate change operations to each instance. Where possible, we're trying to mimic std::string's interface.

Definition at line 87 of file SBuf.h.

Member Typedef Documentation

Definition at line 91 of file SBuf.h.

Definition at line 92 of file SBuf.h.

Definition at line 90 of file SBuf.h.

Constructor & Destructor Documentation

SBuf::SBuf ( )

Definition at line 39 of file SBuf.cc.

References SBufStats::alloc, debugs, SBufStats::live, and stats.

SBuf::SBuf ( const SBuf S)

Definition at line 46 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocCopy, debugs, id, SBufStats::live, and stats.

SBuf::SBuf ( SBuf &&  S)
inline

Definition at line 101 of file SBuf.h.

References SBufStats::moves, and stats.

SBuf::SBuf ( const char *  S,
size_type  n 
)
explicit

Constructor: import c-style string

Create a new SBuf containing a COPY of the contents of the c-string

Parameters
Sthe c string to be copied
nhow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring
Note
it is the caller's responsibility not to go out of bounds
bounds is 0 <= pos < length(); caller must pay attention to signedness

Definition at line 63 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocFromCString, append(), SBufStats::live, and stats.

SBuf::SBuf ( const char *  S)
explicit

Definition at line 71 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocFromCString, append(), SBufStats::live, npos, and stats.

SBuf::SBuf ( const std::string &  s)
explicit

Definition at line 55 of file SBuf.cc.

References SBufStats::alloc, debugs, SBufStats::live, lowAppend(), and stats.

SBuf::~SBuf ( )

Definition at line 79 of file SBuf.cc.

References debugs, len_, SBufStats::live, recordSBufSizeAtDestruct(), and stats.

Member Function Documentation

SBuf & SBuf::append ( const SBuf S)

Append operation

Append the supplied SBuf to the current one; extend storage as needed.

Definition at line 207 of file SBuf.cc.

References buf(), GetStorePrototype(), isEmpty(), length(), lowAppend(), and store_.

Referenced by URL::absolute(), HttpHeader::addVia(), Adaptation::History::allLogString(), applyTlsDetailsToSSL(), Format::Format::assemble(), assembleVaryKey(), assign(), URL::authority(), bio_sbuf_puts(), bio_sbuf_write(), Auth::User::BuildUserKey(), carpSelectParent(), Auth::UserRequest::denyMessageFromHelper(), MessageDelayPool::dump(), NotePairs::find(), Ftp::Gateway::ftpRealm(), AccessLogEntry::getLogMethod(), Downloader::handleReply(), httpHeaderQuoteString(), Ssl::InRamCertificateDbKey(), JoinContainerIntoSBuf(), makeExternalAclKey(), mimeGetIconURL(), Ipc::Mem::Segment::Name(), SBufStreamBuf::overflow(), IcmpConfig::parse(), ESICustomParser::parse(), HttpHeaderEntry::parse(), Notes::parse(), parse_externalAclHelper(), parse_obsolete(), parseHttpRequest(), PidFilenameCalc(), SBufFindTest::placeNeedle(), prepareAcceleratedURL(), HttpStateData::processReplyHeader(), ProcessRoles(), Http::One::Tokenizer::qdText(), SBufFindTest::RandomSBuf(), SBuf(), Ssl::Helper::sslSubmit(), Ssl::CertValidationHelper::sslSubmit(), Adaptation::History::sumLogString(), SBufStreamBuf::sync(), testSBuf::testAppendCString(), testSBuf::testAppendSBuf(), testSBuf::testAppendStdString(), testHttp1Parser::testDripFeed(), testSBuf::testFindSBuf(), testSBuf::testGrow(), testHttp1Parser::testParseRequestLineInvalid(), testHttp1Parser::testParseRequestLineMethods(), testHttp1Parser::testParseRequestLineProtocols(), testHttp1Parser::testParseRequestLineStrange(), testHttp1Parser::testParseRequestLineTerminators(), testSBuf::testRawContent(), testSBuf::testReserve(), Notes::toString(), tunnelStartShoveling(), Security::PeerOptions::updateTlsVersionLimits(), Ftp::UrlWith2f(), and SBufStreamBuf::xsputn().

SBuf & SBuf::append ( const char  c)

Definition at line 230 of file SBuf.cc.

References lowAppend().

SBuf & SBuf::append ( const char *  S,
size_type  Ssize 
)

Append operation for C-style strings.

Append the supplied c-string to the SBuf; extend storage as needed.

Parameters
Sthe c string to be copied. Can be NULL.
Ssizehow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring. If S is NULL, Ssize is ignored.
Note
to append a std::string use the pattern cstr_append(stdstr.data(), stdstd.length())

Definition at line 217 of file SBuf.cc.

References debugs, lowAppend(), npos, and NULL.

SBuf& SBuf::append ( const char *  S)
inline

Definition at line 198 of file SBuf.h.

References append(), and npos.

Referenced by append().

SBuf & SBuf::appendf ( const char *  fmt,
  ... 
)

Append operation with printf-style arguments

Note
arguments may be evaluated more than once, be careful of side-effects

Definition at line 251 of file SBuf.cc.

References vappendf().

Referenced by HttpHeader::addVia(), Adaptation::History::allLogString(), Format::Format::assemble(), URL::authority(), carpSelectParent(), Ftp::Gateway::ftpRealm(), OutOfBoundsException::OutOfBoundsException(), Adaptation::History::sumLogString(), testSBuf::testAppendf(), Note::toString(), and NotePairs::toString().

SBuf & SBuf::assign ( const char *  S,
size_type  n 
)

Import a c-string into a SBuf, copying the data.

It is the caller's duty to free the imported string, if needed.

Parameters
Sthe c string to be copied
nhow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring
Note
it is the caller's responsibility not to go out of bounds
to assign a std::string use the pattern: assign(stdstr.data(), stdstd.length())

Definition at line 107 of file SBuf.cc.

References append(), clear(), and debugs.

SBuf& SBuf::assign ( const char *  S)
inline

Definition at line 160 of file SBuf.h.

References assign(), and npos.

Referenced by assign().

char SBuf::at ( size_type  pos) const
inline

random-access read to any char within the SBuf.

Exceptions
OutOfBoundsExceptionwhen access is out of bounds
Note
bounds is 0 <= pos < length(); caller must pay attention to signedness

Definition at line 239 of file SBuf.h.

References checkAccessBounds(), and operator[]().

Referenced by Http::One::Parser::skipLineTerminator(), and testSBuf::testSubscriptOpFail().

const_iterator SBuf::begin ( ) const
inline

Definition at line 574 of file SBuf.h.

Referenced by compileRE(), and testSBuf::testIterators().

char* SBuf::buf ( ) const
inlineprivate

obtains a char* to the beginning of this SBuf in memory.

Note
the obtained string is NOT null-terminated.

Definition at line 636 of file SBuf.h.

References MemBlob::mem, off_, and store_.

Referenced by append(), c_str(), compare(), copy(), dump(), find(), findFirstNotOf(), findFirstOf(), findLastNotOf(), findLastOf(), operator==(), print(), Printf(), rawContent(), reAlloc(), rfind(), toStdString(), trim(), and vappendf().

char* SBuf::bufEnd ( ) const
inlineprivate

returns the pointer to the first char after this SBuf end

No checks are made that the space returned is safe, checking that is up to the caller.

Definition at line 643 of file SBuf.h.

References len_, MemBlob::mem, off_, and store_.

Referenced by findFirstNotOf(), findFirstOf(), rawAppendFinish(), rawSpace(), and trim().

const char * SBuf::c_str ( )

exports a null-terminated reference to the SBuf internal storage.

Warning
ACCESSING RAW STORAGE IS DANGEROUS! DO NOT EVER USE THE RETURNED POINTER FOR WRITING

The returned value points to an internal location whose contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the SBuf object. Such a call may be implicit (e.g., when SBuf is destroyed upon leaving the current context). This is a very UNSAFE way of accessing the data. This call never returns NULL.

See Also
rawContent
Note
the memory management system guarantees that the exported region of memory will remain valid will remain valid only if the caller keeps holding a valid reference to the SBuf object and does not write or append to it

Definition at line 546 of file SBuf.cc.

References buf(), SBufStats::nulTerminate, SBufStats::rawAccess, rawSpace(), SBufStats::setChar, MemBlob::size, stats, and store_.

Referenced by Adaptation::Ecap::HeaderRep::add(), HttpHeader::addVia(), Ftp::Gateway::appendSuccessHeader(), applyTlsDetailsToSSL(), Format::Format::assemble(), ConnStateData::buildFakeRequest(), Downloader::buildRequest(), ConnStateData::buildSslCertGenerationParams(), compileRE(), constructHelperQuery(), ErrorState::Convert(), Ipc::Port::CoordinatorAddr(), copyOneHeaderFromClientsideRequestToUpstreamRequest(), MimeIcon::created(), Ftp::Relay::createHttpReply(), Security::ServerOptions::createSigningContexts(), Auth::UserRequest::denyMessageFromHelper(), DiskerOpen(), ClientHttpRequest::doCallouts(), MessageDelayPool::dump(), HeaderManglers::find(), Acl::OptionsParser::findOption(), Ftp::Gateway::ftpAuthRequired(), ftpSendType(), ConnStateData::handleRequestBodyData(), htcpClear(), htcpQuery(), HttpStateData::httpBuildRequestHeader(), Acl::TypedOption< Recipient >::import(), Ipc::StoreMap::Init(), Ssl::InitClientContext(), MimeIcon::load(), Ftp::Gateway::loginFailed(), Ipc::Port::MakeAddr(), ACLPeerNameStrategy::match(), ACLServerNameStrategy::match(), Client::maybePurgeOthers(), mimeGetIconURL(), IcmpSquid::Open(), File::open(), OutOfBoundsException::OutOfBoundsException(), ESICustomParser::parse(), Notes::parse(), parse_externalAclHelper(), parse_obsolete(), ParseAclWithAction(), Http::Message::parseHeader(), Ftp::Server::parseOneRequest(), ConnStateData::parseProxy1p0(), ProcessMacros(), refreshCheck(), RemoveInstance(), Ftp::Relay::sendCommand(), Ssl::ServerBump::ServerBump(), ssl_verify_cb(), Ssl::Helper::sslSubmit(), storeSwapMetaBuild(), testSBuf::testComparisons(), testSBuf::testFindFirstNotOf(), SBufFindTest::testFindFirstOf(), testSBuf::testRawContent(), testSBuf::testSBufConstructDestruct(), Notes::toString(), NotePairs::toString(), Note::Value::Value(), Adaptation::Ecap::ServiceRep::wantsUrl(), WIN32_InstallService(), WIN32_RemoveService(), WIN32_sendSignal(), WIN32_SetServiceCommandLine(), WIN32_StartService(), and WIN32_Subsystem_Init().

int SBuf::caseCmp ( const SBuf S) const
inline

Definition at line 276 of file SBuf.h.

References caseInsensitive, compare(), and npos.

int SBuf::caseCmp ( const char *  S,
const size_type  n 
) const
inline

Definition at line 295 of file SBuf.h.

References caseInsensitive, and compare().

int SBuf::caseCmp ( const char *  S) const
inline

Definition at line 298 of file SBuf.h.

References caseInsensitive, compare(), and npos.

void SBuf::checkAccessBounds ( size_type  pos) const
private

checks whether the requested 'pos' is within the bounds of the SBuf

Exceptions
OutOfBoundsExceptionif access is out of bounds

Definition at line 871 of file SBuf.cc.

References length().

Referenced by at(), and setAt().

SBuf & SBuf::chop ( size_type  pos,
size_type  n = npos 
)

slicing method

Removes SBuf prefix and suffix, leaving a sequence of 'n' bytes starting from position 'pos', first byte is at pos 0. It is an in-place-modifying version of substr.

Parameters
posstart sub-stringing from this byte. If it is npos or it is greater than the SBuf length, the SBuf is cleared and an empty SBuf is returned.
nmaximum number of bytes of the resulting SBuf. npos means "to end of SBuf". if it is 0, the SBuf is cleared and an empty SBuf is returned. if it overflows the end of the SBuf, it is capped to the end of SBuf
See Also
substr, trim

Definition at line 560 of file SBuf.cc.

References SBufStats::chop, clear(), len_, length(), npos, off_, and stats.

Referenced by consume(), Http::One::Parser::getHeaderField(), Ftp::Server::handleUserRequest(), substr(), testSBuf::testChop(), testSBuf::testCopy(), HttpStateData::truncateVirginBody(), and Security::PeerOptions::updateTlsVersionLimits().

int SBuf::cmp ( const SBuf S) const
inline

Definition at line 268 of file SBuf.h.

References caseSensitive, compare(), and npos.

int SBuf::cmp ( const char *  S,
const size_type  n 
) const
inline

Definition at line 287 of file SBuf.h.

References caseSensitive, and compare().

int SBuf::cmp ( const char *  S) const
inline

Definition at line 290 of file SBuf.h.

References caseSensitive, compare(), and npos.

int SBuf::compare ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive,
const size_type  n 
) const

compare to other SBuf, str(case)cmp-style

Parameters
isCaseSensitiveone of caseSensitive or caseInsensitive
ncompare up to this many bytes. if npos (default), compare whole SBufs
Return values
>0argument of the call is greater than called SBuf
<0argument of the call is smaller than called SBuf
0argument of the call has the same contents of called SBuf

Definition at line 382 of file SBuf.cc.

References buf(), caseSensitive, compare(), SBufStats::compareSlow, debugs, length(), memcasecmp(), min(), npos, stats, and substr().

Referenced by caseCmp(), cmp(), compare(), SBufEqual::operator()(), startsWith(), and testSBuf::testStringOps().

int SBuf::compare ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive 
) const
inline

Definition at line 260 of file SBuf.h.

References compare(), and npos.

int SBuf::compare ( const char *  s,
const SBufCaseSensitive  isCaseSensitive,
const size_type  n 
) const
int SBuf::compare ( const char *  s,
const SBufCaseSensitive  isCaseSensitive 
) const
inline

Definition at line 282 of file SBuf.h.

References compare(), and npos.

SBuf SBuf::consume ( size_type  n = npos)

Consume bytes at the head of the SBuf

Consume N chars at SBuf head, or to SBuf's end, whichever is shorter. If more bytes are consumed than available, the SBuf is emptied

Parameters
nhow many bytes to remove; could be zero. npos (or no argument) means 'to the end of SBuf'
Returns
a new SBuf containing the consumed bytes.

Definition at line 511 of file SBuf.cc.

References chop(), debugs, length(), min(), npos, and substr().

Referenced by Parser::Tokenizer::consume(), ConnStateData::consumeInput(), Parser::Tokenizer::consumeTrailing(), TunnelStateData::copyClientBytes(), TunnelStateData::copyServerBytes(), Http::One::Parser::getHeaderField(), ConnStateData::parseProxy2p0(), Parser::Tokenizer::suffix(), tunnelStartShoveling(), and HttpStateData::writeReplyBody().

SBuf::size_type SBuf::copy ( char *  dest,
size_type  n 
) const

Copy SBuf contents into user-supplied C buffer.

Export a copy of the SBuf's contents into the user-supplied buffer, up to the user-supplied-length. No zero-termination is performed

Returns
num the number of actually-copied chars.

Definition at line 530 of file SBuf.cc.

References buf(), SBufStats::copyOut, length(), min(), and stats.

Referenced by Ftp::Gateway::loginParser(), and SBufToCstring().

void SBuf::cow ( SBuf::size_type  newsize = npos)
private

copy-on-write: make sure that we are the only holder of the backing store. If not, reallocate. If a new size is specified, and it is greater than the current length, the backing store will be extended as needed

Definition at line 916 of file SBuf.cc.

References SBufStats::cowFast, debugs, length(), npos, reAlloc(), stats, and store_.

Referenced by rawSpace(), reserveCapacity(), and setAt().

std::ostream & SBuf::dump ( std::ostream &  os) const

print SBuf contents and debug information about the SBuf to an ostream

Debug function, dumps to a stream informations on the current SBuf, including low-level details and statistics.

Definition at line 333 of file SBuf.cc.

References buf(), MemBlob::dump(), len_, length(), off_, print(), and store_.

const_iterator SBuf::end ( ) const
inline

Definition at line 578 of file SBuf.h.

References length().

size_type SBuf::estimateCapacity ( size_type  desired) const
inlineprivate

Try to guesstimate how big a MemBlob to allocate. The result is guarranteed to be to be at least the desired size.

Definition at line 649 of file SBuf.h.

SBuf::size_type SBuf::find ( char  c,
size_type  startPos = 0 
) const

Find first occurrence of character in SBuf

Returns the index in the SBuf of the first occurrence of char c.

Returns
npos if the char was not found
Parameters
startPosif specified, ignore any occurrences before that position if startPos is npos or greater than length() npos is always returned if startPos is less than zero, it is ignored

Definition at line 614 of file SBuf.cc.

References buf(), SBufStats::find, i, length(), npos, NULL, and stats.

Referenced by EssentialVersion(), find(), UrnState::getHost(), Ftp::Gateway::loginParser(), clientReplyContext::purgeDoPurgeHead(), SBufFindTest::testFind(), SBufFindTest::testFindChar(), testSBuf::testFindChar(), SBufFindTest::testFindCharDefs(), SBufFindTest::testFindDefs(), and testSBuf::testFindSBuf().

SBuf::size_type SBuf::find ( const SBuf str,
size_type  startPos = 0 
) const

Find first occurrence of SBuf in SBuf.

Returns the index in the SBuf of the first occurrence of the sequence contained in the str argument.

Parameters
startPosif specified, ignore any occurrences before that position if startPos is npos or greater than length() npos is always returned
Returns
npos if the SBuf was not found

Definition at line 634 of file SBuf.cc.

References buf(), debugs, SBufStats::find, find(), length(), npos, NULL, and stats.

SBuf::size_type SBuf::findFirstNotOf ( const CharacterSet set,
size_type  startPos = 0 
) const

Find first occurrence character NOT in character set

Returns
npos if all characters in the SBuf are from set
Parameters
startPosif specified, ignore any occurrences before that position if npos, then npos is always returned

TODO: rename to camelCase

Definition at line 776 of file SBuf.cc.

References buf(), bufEnd(), cur, debugs, SBufStats::find, length(), CharacterSet::name, npos, and stats.

Referenced by testSBuf::testFindFirstNotOf(), and Notes::validateKey().

SBuf::size_type SBuf::findFirstOf ( const CharacterSet set,
size_type  startPos = 0 
) const

Find first occurrence of character of set in SBuf

Finds the first occurrence of ANY of the characters in the supplied set in the SBuf.

Returns
npos if no character in the set could be found
Parameters
startPosif specified, ignore any occurrences before that position if npos, then npos is always returned

TODO: rename to camelCase

Definition at line 753 of file SBuf.cc.

References buf(), bufEnd(), cur, debugs, SBufStats::find, length(), CharacterSet::name, npos, and stats.

Referenced by HttpHeader::parse(), SBufFindTest::testFindFirstOf(), and testSBuf::testFindFirstOf().

SBuf::size_type SBuf::findLastNotOf ( const CharacterSet set,
size_type  endPos = npos 
) const

Find last occurrence character NOT in character set

Returns
npos if all characters in the SBuf are from set
Parameters
endPosif specified, ignore any occurrences after that position if npos, then the entire SBuf is searched

Definition at line 820 of file SBuf.cc.

References buf(), cur, debugs, SBufStats::find, isEmpty(), length(), CharacterSet::name, npos, and stats.

SBuf::size_type SBuf::findLastOf ( const CharacterSet set,
size_type  endPos = npos 
) const

Find last occurrence of character of set in SBuf

Finds the last occurrence of ANY of the characters in the supplied set in the SBuf.

Returns
npos if no character in the set could be found
Parameters
endPosif specified, ignore any occurrences after that position if npos, the entire SBuf is searched

Definition at line 799 of file SBuf.cc.

References buf(), cur, debugs, SBufStats::find, isEmpty(), length(), CharacterSet::name, npos, and stats.

Referenced by testTokenizer::testTokenizerSuffix().

const SBufStats & SBuf::GetStats ( )
static

Definition at line 524 of file SBuf.cc.

References stats.

Referenced by SBufStatsAction::collect(), and testSBuf::testDumpStats().

MemBlob::Pointer SBuf::GetStorePrototype ( )
staticprivate

obtain prototype store

Just-created SBufs all share to the same MemBlob. This call instantiates and returns it.

Definition at line 87 of file SBuf.cc.

Referenced by append(), and clear().

bool SBuf::isEmpty ( ) const
inline

Check whether the SBuf is empty

Returns
true if length() == 0

Definition at line 422 of file SBuf.h.

References len_.

Referenced by URL::absolute(), HttpHeader::addVia(), StoreEntry::adjustVary(), Adaptation::History::allLogString(), append(), AppendTokens(), applyTlsDetailsToSSL(), Format::Format::assemble(), assembleVaryKey(), Parser::Tokenizer::atEnd(), URL::authority(), ConnStateData::buildSslCertGenerationParams(), carpSelectParent(), StoreMetaVary::checkConsistency(), helper_server::checkForTimedOutRequests(), ConnStateData::checkLogging(), ConnStateData::clientParseRequests(), configDoConfigure(), ConnStateData::connFinishedWithConn(), Server::doClientRead(), ACL::dumpOptions(), ACLHTTPHeaderData::empty(), ACLNoteData::empty(), Auth::SchemesConfig::expand(), ConnStateData::fakeAConnectRequest(), NotePairs::find(), findLastNotOf(), findLastOf(), ConnStateData::getSslContextStart(), ConnStateData::handleChunkedRequestBody(), Ftp::Server::handleUserRequest(), HttpStateData::haveParsedReplyHeaders(), HttpRequestMethod::HttpRequestMethod(), HttpRequestMethod::image(), Ssl::InitClientContext(), internalRemoteUri(), Ftp::Gateway::loginParser(), ACLPeerNameStrategy::match(), ACLStringData::match(), ACLServerNameStrategy::match(), mimeGetIconURL(), ACLHTTPHeaderData::parse(), Security::HandshakeParser::parseExtensions(), parseHttpRequest(), Ftp::Server::parseOneRequest(), parsePortCfg(), MessageDelayConfig::parseResponseDelayPool(), Security::HandshakeParser::parseSniExtension(), ConnStateData::parseTlsHandshake(), URL::path(), prepareAcceleratedURL(), clientReplyContext::processExpired(), clientReplyContext::purgeDoPurgeHead(), HttpStateData::readReply(), RemoveInstance(), MemStore::shouldCache(), Log::Format::SquidReferer(), ConnStateData::sslCrtdHandleReply(), MemObject::stat(), storeKeyPublicByRequestMethod(), storeSwapMetaBuild(), Adaptation::History::sumLogString(), ACLFilledChecklist::syncAle(), testHttp1Parser::testParserConstruct(), testTokenizer::testTokenizerInt64(), Notes::toString(), NotePairs::toString(), trim(), tunnelStartShoveling(), Adaptation::Ecap::RequestLineRep::uri(), varyEvaluateMatch(), WIN32_InstallService(), WIN32_RemoveService(), WIN32_sendSignal(), and WIN32_SetServiceCommandLine().

size_type SBuf::length ( ) const
inline

Definition at line 405 of file SBuf.h.

References len_.

Referenced by ConnStateData::abortRequestParsing(), HttpHeader::addEntry(), HttpHeader::addVia(), adjustSSL(), append(), bio_sbuf_puts(), Ftp::Gateway::buildTitleUrl(), carpSelectParent(), Security::PeerConnector::certDownloadingDone(), checkAccessBounds(), helper_server::checkForTimedOutRequests(), ConnStateData::checkLogging(), Ftp::Gateway::checkUrlpath(), chop(), ConnStateData::clientParseRequests(), compare(), Parser::Tokenizer::consume(), consume(), ConnStateData::consumeInput(), HttpStateData::continueAfterParsingHeader(), ErrorState::Convert(), copy(), TunnelStateData::copyClientBytes(), TunnelStateData::copyServerBytes(), cow(), HttpHeader::delAt(), Http::One::RequestParser::doParse(), dump(), end(), NotePairs::find(), find(), findFirstNotOf(), findFirstOf(), findLastNotOf(), findLastOf(), Http::One::ResponseParser::firstLineSize(), Http::One::RequestParser::firstLineSize(), Parser::BinaryTokenizer::got(), ConnStateData::handleChunkedRequestBody(), Downloader::handleReply(), ConnStateData::handleRequestBodyData(), Ftp::Server::handleUserRequest(), HttpHeader::hasNamed(), Http::One::Parser::headerBlockSize(), headersEnd(), HttpHeader::insertEntry(), internalRemoteUri(), JoinContainerIntoSBuf(), Ftp::Gateway::loginParser(), Http::HeaderLookupTable_t::lookup(), mainParseOptions(), makeExternalAclKey(), Adaptation::Icap::ModXact::makeRequestHeaders(), Adaptation::Icap::Options::TransferList::matches(), HttpStateData::maybeMakeSpaceAvailable(), ConnStateData::mayNeedToReadMoreBody(), SBufAddLength::operator()(), operator==(), OutOfBoundsException::OutOfBoundsException(), HttpHeaderEntry::packInto(), HttpHeader::packInto(), ESICustomParser::parse(), Http::One::ResponseParser::parse(), Http::One::RequestParser::parse(), Http::One::TeChunkedParser::parse(), parse_externalAclHelper(), Security::HandshakeParser::ParseCertificate(), Security::HandshakeParser::parseCiphers(), Security::HandshakeParser::parseCompressionMethods(), Security::HandshakeParser::parseHandshakeMessage(), parseHttpRequest(), Http::One::RequestParser::parseHttpVersionField(), Security::HandshakeParser::parseModernRecord(), Ftp::Server::parseOneRequest(), ConnStateData::parseProxy1p0(), ConnStateData::parseProxy2p0(), ConnStateData::parseProxyProtocolHeader(), Http::One::ResponseParser::parseResponseFirstLine(), Http::One::ResponseParser::parseResponseStatusAndReason(), Security::HandshakeParser::parseServerCertificates(), Http::One::RequestParser::parseUriField(), SBufFindTest::placeNeedle(), plength(), HttpRequest::prefixLen(), print(), HttpStateData::processReplyHeader(), rawAppendFinish(), rawSpace(), rbegin(), File::readSmall(), Server::readSomeData(), reAlloc(), reserveSpace(), rfind(), SBufFindTest::run(), SBufSubstrAutoTest::SBufSubstrAutoTest(), SBufToCstring(), SBufToString(), Parser::Tokenizer::skip(), Http::One::Parser::skipLineTerminator(), Parser::Tokenizer::skipSuffix(), startsWith(), statClientRequests(), ConnStateData::stopSending(), storeKeyPublicByRequestMethod(), storeSwapMetaBuild(), SBufFindTest::testAllMethods(), testSBuf::testChop(), testSBuf::testComparisons(), testHttp1Parser::testDripFeed(), testSBuf::testFindChar(), testSBuf::testFindFirstNotOf(), testSBuf::testFindFirstOf(), testHttp1Parser::testParseRequestLineInvalid(), testHttp1Parser::testParseRequestLineMethods(), testHttp1Parser::testParseRequestLineProtocols(), testHttp1Parser::testParseRequestLineStrange(), testHttp1Parser::testParseRequestLineTerminators(), testSBuf::testRawContent(), testSBuf::testReserve(), testResults(), testSBuf::testSBufConstructDestruct(), testSBuf::testSBufLength(), testSBuf::testSubscriptOpFail(), testTokenizer::testTokenizerInt64(), testTokenizer::testTokenizerSuffix(), toLower(), toStdString(), Note::toString(), toUpper(), trim(), HttpStateData::truncateVirginBody(), Adaptation::Ecap::RequestLineRep::uri(), Notes::validateKey(), ShmWriter::vappendf(), File::writeAll(), and HttpStateData::writeReplyBody().

SBuf & SBuf::lowAppend ( const char *  memArea,
size_type  areaSize 
)
private

Low-level append operation

Takes as input a contiguous area of memory and appends its contents to the SBuf, taking care of memory management. Does no bounds checking on the supplied memory buffer, it is the duty of the caller to ensure that the supplied area is valid.

Definition at line 901 of file SBuf.cc.

References SBufStats::append, MemBlob::append(), len_, rawSpace(), stats, and store_.

Referenced by append(), and SBuf().

bool SBuf::operator!= ( const SBuf S) const

Definition at line 505 of file SBuf.cc.

bool SBuf::operator< ( const SBuf S) const
inline

Definition at line 311 of file SBuf.h.

References cmp().

bool SBuf::operator<= ( const SBuf S) const
inline

Definition at line 313 of file SBuf.h.

References cmp().

SBuf& SBuf::operator= ( const SBuf S)
inline

Assignment operator.

Current SBuf will share backing store with the assigned one.

Definition at line 135 of file SBuf.h.

References assign().

SBuf& SBuf::operator= ( SBuf &&  S)
inline

Definition at line 136 of file SBuf.h.

References len_, SBufStats::moves, NULL, off_, stats, and store_.

SBuf& SBuf::operator= ( const char *  S)
inline

Assignment operator. Copy a NULL-terminated c-style string into a SBuf.

Copy a c-style string into a SBuf. Shortcut for SBuf.assign(S) It is the caller's duty to free the imported string, if needed.

Note
not \0-clean

Definition at line 168 of file SBuf.h.

References assign().

bool SBuf::operator== ( const SBuf S) const

Definition at line 485 of file SBuf.cc.

References buf(), SBufStats::compareFast, SBufStats::compareSlow, debugs, id, length(), off_, stats, and store_.

bool SBuf::operator> ( const SBuf S) const
inline

Definition at line 312 of file SBuf.h.

References cmp().

bool SBuf::operator>= ( const SBuf S) const
inline

Definition at line 314 of file SBuf.h.

References cmp().

char SBuf::operator[] ( size_type  pos) const
inline

random-access read to any char within the SBuf

does not check access bounds. If you need that, use at()

Definition at line 232 of file SBuf.h.

References SBufStats::getChar, MemBlob::mem, off_, stats, and store_.

Referenced by at().

int SBuf::plength ( ) const
inline

Get the length of the SBuf, as a signed integer

Compatibility function for printf(3) which requires a signed int

Exceptions
SBufTooBigExceptionif the SBuf is too big for a signed integer

Definition at line 412 of file SBuf.h.

References INT_MAX, and length().

Referenced by strListIsMember().

std::ostream & SBuf::print ( std::ostream &  os) const

Definition at line 325 of file SBuf.cc.

References buf(), length(), stats, and SBufStats::toStream.

Referenced by dump(), and operator<<().

SBuf & SBuf::Printf ( const char *  fmt,
  ... 
)

Assignment operation with printf(3)-style definition

Note
arguments may be evaluated more than once, be careful of side-effects

Definition at line 236 of file SBuf.cc.

References buf(), clear(), and vappendf().

Referenced by Auth::User::BuildUserKey(), ACLTimeData::dump(), ACLIntRange::dump(), ACLMaxConnection::dump(), ACLMaxUserIP::dump(), ACLASN::dump(), ACLExternal::dump(), ParseAclWithAction(), Ftp::Relay::sendCommand(), testSBuf::testPrintf(), acl_httpstatus_data::toStr(), Note::Value::Value(), and Instance::WriteOurPid().

void SBuf::rawAppendFinish ( const char *  start,
size_type  actualSize 
)

Updates SBuf metadata to reflect appending actualSize bytes to the buffer returned by the corresponding rawAppendStart() call. Throws if rawAppendStart(actualSize) would have returned a different value now.

Parameters
startraw buffer previously returned by rawAppendStart()
actualSizethe number of appended bytes

Definition at line 155 of file SBuf.cc.

References bufEnd(), MemBlob::canAppend(), MemBlob::capacity, debugs, len_, length(), maxSize, min(), Must, off_, MemBlob::size, and store_.

Referenced by Comm::ReadNow(), File::readSmall(), and testSBuf::testRawSpace().

char * SBuf::rawAppendStart ( size_type  anticipatedSize)
Returns
a buffer suitable for appending at most anticipatedSize bytes The buffer must be used "immediately" because it is invalidated by most non-constant SBuf method calls, including such calls against other SBuf objects that just happen to share the same underlying MemBlob storage!

Definition at line 147 of file SBuf.cc.

References debugs, and rawSpace().

Referenced by Comm::ReadNow(), File::readSmall(), and testSBuf::testRawSpace().

const char * SBuf::rawContent ( ) const

exports a pointer to the SBuf internal storage.

Warning
ACCESSING RAW STORAGE IS DANGEROUS!

Returns a ead-only pointer to SBuf's content. No terminating null character is appended (use c_str() for that). The returned value points to an internal location whose contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the SBuf object. Such a call may be implicit (e.g., when SBuf is destroyed upon leaving the current context). This is a very UNSAFE way of accessing the data. This call never returns NULL.

See Also
c_str
Note
the memory management system guarantees that the exported region of memory will remain valid if the caller keeps holding a valid reference to the SBuf object and does not write or append to it. For example:
SBuf foo("some string");
const char *bar = foo.rawContent();
doSomething(bar); //safe
foo.append(" other string");
doSomething(bar); //unsafe

Definition at line 539 of file SBuf.cc.

References buf(), SBufStats::rawAccess, and stats.

Referenced by adjustSSL(), Ftp::Gateway::buildTitleUrl(), carpSelectParent(), Security::PeerConnector::certDownloadingDone(), helper_server::checkForTimedOutRequests(), ErrorState::Convert(), TunnelStateData::copyClientBytes(), TunnelStateData::copyServerBytes(), Parser::BinaryTokenizer::got(), HttpHeader::hasNamed(), headersEnd(), Parser::Tokenizer::int64(), internalRemoteUri(), Http::HeaderLookupTable_t::lookup(), Adaptation::Icap::ModXact::makeRequestHeaders(), HttpHeaderEntry::packInto(), HttpHeader::packInto(), Security::HandshakeParser::ParseCertificate(), Http::One::RequestParser::parseHttpVersionField(), ConnStateData::parseProxy2p0(), SBufToString(), statClientRequests(), storeKeyPublicByRequestMethod(), SBufFindTest::testAllMethods(), testSBuf::testAppendSBuf(), testSBuf::testAppendStdString(), testSBuf::testComparisons(), testSBuf::testGrow(), testSBuf::testRawContent(), testSBuf::testSBufConstructDestruct(), Adaptation::Ecap::RequestLineRep::uri(), Notes::validateKey(), ShmWriter::vappendf(), File::writeAll(), and HttpStateData::writeReplyBody().

char * SBuf::rawSpace ( size_type  minSize)
private

Exports a writable pointer to the SBuf internal storage.

Warning
Use with EXTREME caution, this is a dangerous operation.

Returns a pointer to the first unused byte in the SBuf's storage, which can be be used for appending. At least minSize bytes will be available for writing. The returned pointer must not be stored by the caller, as it will be invalidated by the first call to a non-const method call on the SBuf. This call guarantees to never return nullptr.

See Also
reserveSpace
Note
Unlike reserveSpace(), this method does not guarantee exclusive buffer ownership. It is instead optimized for a one writer (appender), many readers scenario by avoiding unnecessary copying and allocations.
Exceptions
SBufTooBigExceptionif the user tries to allocate too big a SBuf

Definition at line 169 of file SBuf.cc.

References bufEnd(), MemBlob::canAppend(), cow(), debugs, len_, length(), maxSize, Must, off_, SBufStats::rawAccess, stats, and store_.

Referenced by c_str(), lowAppend(), rawAppendStart(), and vappendf().

const_reverse_iterator SBuf::rbegin ( ) const
inline

Definition at line 582 of file SBuf.h.

References length().

Referenced by Parser::Tokenizer::suffix().

void SBuf::reAlloc ( size_type  newsize)
private

re-allocate the backing store of the SBuf.

If there are contents in the SBuf, they will be copied over. NO verifications are made on the size parameters, it's up to the caller to make sure that the new size is big enough to hold the copied contents. The re-allocated storage MAY be bigger than the requested size due to size-chunking algorithms in MemBlock, it is guarranteed NOT to be smaller.

Definition at line 886 of file SBuf.cc.

References MemBlob::append(), buf(), MemBlob::capacity, SBufStats::cowSlow, debugs, length(), maxSize, off_, stats, and store_.

Referenced by cow().

const_reverse_iterator SBuf::rend ( ) const
inline

Definition at line 586 of file SBuf.h.

Referenced by Parser::Tokenizer::suffix().

void SBuf::reserveCapacity ( size_type  minCapacity)

Request to guarantee the SBuf's store capacity

After this method is called, the SBuf is guaranteed to have at least minCapacity bytes of total buffer size, including the currently-used portion; it is also guaranteed that after this call this SBuf has unique ownership of the underlying memory store.

Exceptions
SBufTooBigExceptionif the user tries to allocate too big a SBuf

Definition at line 116 of file SBuf.cc.

References cow(), maxSize, and Must.

Referenced by URL::absolute(), SBufFindTest::RandomSBuf(), reserve(), reserveSpace(), testSBuf::testGrow(), and testSBuf::testReserve().

void SBuf::reserveSpace ( size_type  minSpace)
inline

Request to guarantee the SBuf's free store space.

After the reserveSpace request, the SBuf is guaranteed to have at least minSpace bytes of unused backing store following the currently used portion and single ownership of the backing store.

Exceptions
SBufTooBigExceptionif the user tries to allocate too big a SBuf

Definition at line 431 of file SBuf.h.

References length(), maxSize, Must, and reserveCapacity().

Referenced by HttpStateData::maybeMakeSpaceAvailable().

SBuf::size_type SBuf::rfind ( char  c,
SBuf::size_type  endPos = npos 
) const

Find last occurrence of character in SBuf

Returns the index in the SBuf of the last occurrence of char c.

Returns
npos if the char was not found
Parameters
endPosif specified, ignore any occurrences after that position. if npos or greater than length(), the whole SBuf is considered

Definition at line 722 of file SBuf.cc.

References buf(), SBufStats::find, i, length(), memrchr(), npos, NULL, and stats.

Referenced by Ftp::Gateway::appendSuccessHeader(), Ftp::Server::handleUserRequest(), rfind(), testSBuf::testFindChar(), testSBuf::testFindSBuf(), SBufFindTest::testRFind(), SBufFindTest::testRFindChar(), testSBuf::testRFindChar(), SBufFindTest::testRFindCharDefs(), SBufFindTest::testRFindDefs(), testSBuf::testRFindSBuf(), and urlMakeAbsolute().

SBuf::size_type SBuf::rfind ( const SBuf str,
SBuf::size_type  endPos = npos 
) const

Find last occurrence of SBuf in SBuf

Returns the index in the SBuf of the last occurrence of the sequence contained in the str argument.

Returns
npos if the sequence was not found
Parameters
endPosif specified, ignore any occurrences after that position if npos or greater than length(), the whole SBuf is considered

Definition at line 686 of file SBuf.cc.

References buf(), cur, SBufStats::find, length(), npos, rfind(), and stats.

void SBuf::setAt ( size_type  pos,
char  toset 
)

direct-access set a byte at a specified operation.

Parameters
posthe position to be overwritten
tosetthe value to be written
Exceptions
OutOfBoundsExceptionwhen pos is of bounds
Note
bounds is 0 <= pos < length(); caller must pay attention to signedness
performs a copy-on-write if needed.

Definition at line 358 of file SBuf.cc.

References checkAccessBounds(), cow(), MemBlob::mem, off_, SBufStats::setChar, stats, and store_.

Referenced by testSBuf::testComparisons(), testSBuf::testSubscriptOp(), toLower(), and toUpper().

size_type SBuf::spaceSize ( ) const
inline

Obtain how much free space is available in the backing store.

Note
: unless the client just cow()ed, it is not guaranteed that the free space can be used.

Definition at line 383 of file SBuf.h.

References MemBlob::spaceSize(), and store_.

Referenced by Server::maybeMakeSpaceAvailable(), HttpStateData::maybeMakeSpaceAvailable(), Comm::ReadNow(), HttpStateData::readReply(), reserve(), statClientRequests(), testSBuf::testReserve(), and vappendf().

bool SBuf::startsWith ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive = caseSensitive 
) const

check whether the entire supplied argument is a prefix of the SBuf.

Parameters
Sthe prefix to match against
isCaseSensitiveone of caseSensitive or caseInsensitive
Return values
trueargument is a prefix of the SBuf

Definition at line 472 of file SBuf.cc.

References compare(), SBufStats::compareFast, debugs, id, length(), and stats.

Referenced by internalCheck(), internalStart(), internalStaticCheck(), SBufStartsWith::operator()(), ConnStateData::parseProxyProtocolHeader(), testSBuf::testStartsWith(), and testTokenizer::testTokenizerSkip().

void SBuf::toLower ( )
See Also
man tolower(3)

Definition at line 841 of file SBuf.cc.

References SBufStats::caseChange, debugs, length(), setAt(), and stats.

Referenced by assembleVaryKey(), AnyP::UriScheme::Init(), ACLUserData::parse(), and ToLower().

std::string SBuf::toStdString ( ) const
inline
void SBuf::toUpper ( )
See Also
man toupper(3)

Definition at line 854 of file SBuf.cc.

References SBufStats::caseChange, debugs, length(), setAt(), and stats.

Referenced by Ftp::Server::handleFeatReply(), Ftp::Server::parseOneRequest(), and ToUpper().

SBuf & SBuf::trim ( const SBuf toRemove,
bool  atBeginning = true,
bool  atEnd = true 
)

Remove characters in the toremove set at the beginning, end or both

Parameters
toremovecharacters to be removed. Stops chomping at the first found char not in the set
atBeginningif true (default), strips at the beginning of the SBuf
atEndif true (default), strips at the end of the SBuf

Definition at line 581 of file SBuf.cc.

References buf(), bufEnd(), clear(), isEmpty(), len_, length(), NULL, off_, p, stats, and SBufStats::trim.

Referenced by StoreMetaVary::checkConsistency(), Http::One::Parser::getHeaderField(), Ftp::Server::parseOneRequest(), and testSBuf::testChomp().

SBuf & SBuf::vappendf ( const char *  fmt,
va_list  vargs 
)

Append operation, with vsprintf(3)-style arguments.

Note
arguments may be evaluated more than once, be careful of side-effects

Definition at line 261 of file SBuf.cc.

References SBufStats::append, buf(), len_, Must, NULL, rawSpace(), MemBlob::size, spaceSize(), stats, and store_.

Referenced by appendf(), Printf(), and ShmWriter::vappendf().

Friends And Related Function Documentation

friend class Locker
friend

Definition at line 618 of file SBuf.h.

Member Data Documentation

const InstanceId<SBuf> SBuf::id

SBuf object identifier meant for test cases and debugging. Does not change when object does, including during assignment.

Definition at line 595 of file SBuf.h.

Referenced by assign(), operator<<(), operator==(), SBuf(), and startsWith().

size_type SBuf::len_ = 0
private
size_type SBuf::off_ = 0
private

The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors