CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
string.cc File Reference
#include "string.h"
#include "cvmfs_config.h"
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
Include dependency graph for string.cc:

Go to the source code of this file.

Classes

struct  anonymous_namespace{string.cc}::IgnoreCaseComperator
 

Namespaces

 anonymous_namespace{string.cc}
 

Macros

#define __STDC_FORMAT_MACROS
 

Functions

string StringifyBool (const bool value)
 
string StringifyInt (const int64_t value)
 
std::string StringifyUint (const uint64_t value)
 
string StringifyByteAsHex (const unsigned char value)
 
string StringifyDouble (const double value)
 
string StringifyTime (const time_t seconds, const bool utc)
 
std::string RfcTimestamp ()
 
std::string IsoTimestamp ()
 
std::string WhitelistTimestamp (time_t when)
 
string StringifyTimeval (const timeval value)
 
time_t IsoTimestamp2UtcTime (const std::string &iso8601)
 
int64_t String2Int64 (const string &value)
 
uint64_t String2Uint64 (const string &value)
 
bool String2Uint64Parse (const std::string &value, uint64_t *result)
 
void String2Uint64Pair (const string &value, uint64_t *a, uint64_t *b)
 
bool HasPrefix (const string &str, const string &prefix, const bool ignore_case)
 
bool HasSuffix (const std::string &str, const std::string &suffix, const bool ignore_case)
 
vector< string > SplitString (const string &str, char delim)
 
vector< string > SplitStringBounded (unsigned max_chunks, const string &str, char delim)
 
string JoinStrings (const vector< string > &strings, const string &joint)
 
void ParseKeyvalMem (const unsigned char *buffer, const unsigned buffer_size, map< char, string > *content)
 
bool ParseKeyvalPath (const string &filename, map< char, string > *content)
 
string GetLineMem (const char *text, const int text_size)
 
bool GetLineFile (FILE *f, std::string *line)
 
bool GetLineFd (const int fd, std::string *line)
 
string Trim (const string &raw, bool trim_newline)
 
std::string TrimString (const std::string &path, const std::string &toTrim, const int trimMode)
 
string ToUpper (const string &mixed_case)
 
string ReplaceAll (const string &haystack, const string &needle, const string &replace_by)
 
static void Base64Block (const unsigned char input[3], const char *table, char output[4])
 
string Base64 (const string &data)
 
string Base64Url (const string &data)
 
static bool Debase64Block (const unsigned char input[4], unsigned char output[3])
 
bool Debase64 (const string &data, string *decoded)
 
string Tail (const string &source, unsigned num_lines)
 
std::string GetGMTimestamp (const std::string &format)
 

Variables

const char b64_table []
 
const int8_t db64_table []
 

Macro Definition Documentation

#define __STDC_FORMAT_MACROS

This file is part of the CernVM File System.

Some common functions.

Definition at line 9 of file string.cc.

Function Documentation

static void Base64Block ( const unsigned char  input[3],
const char *  table,
char  output[4] 
)
inlinestatic

Definition at line 496 of file string.cc.

Referenced by Base64().

Here is the caller graph for this function:

string Base64Url ( const string &  data)

Safe encoding for URIs and path names: replace + by - and / by _

Definition at line 535 of file string.cc.

Referenced by anonymous_namespace{pack.cc}::AppendItemToHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Debase64 ( const string &  data,
string *  decoded 
)

Can decode both base64 and base64url

Definition at line 564 of file string.cc.

Referenced by receiver::CheckToken(), notify::msg::Activity::FromJSONString(), receiver::GetTokenPublicId(), s3fanout::S3FanoutManager::MkAzureAuthz(), ObjectPackConsumer::ParseItem(), AuthzExternalFetcher::ParsePermit(), and letter::Letter::Verify().

Here is the call graph for this function:

Here is the caller graph for this function:

static bool Debase64Block ( const unsigned char  input[4],
unsigned char  output[3] 
)
static

Definition at line 547 of file string.cc.

Referenced by Debase64().

Here is the caller graph for this function:

std::string GetGMTimestamp ( const std::string &  format)

Get UTC Time.

Parameters
formatformat if timestamp (YYYY-MM-DD HH:MM:SS by default)
Returns
a timestamp string on success, empty string on failure

Definition at line 615 of file string.cc.

Referenced by swissknife::CommandGc::Main(), swissknife::Ingest::Main(), main(), swissknife::CommandSync::Main(), StatisticsDatabase::StoreGCStatistics(), and StatisticsDatabase::StorePublishStatistics().

Here is the caller graph for this function:

bool GetLineFd ( const int  fd,
std::string *  line 
)

Definition at line 404 of file string.cc.

Referenced by FuseMain(), BashOptionsManager::ParsePath(), manifest::Reflog::ReadChecksum(), and publish::SetInConfig().

Here is the caller graph for this function:

string GetLineMem ( const char *  text,
const int  text_size 
)
std::string IsoTimestamp ( )

Current time in format YYYYMMDDTHHMMSSZ. Used in AWS4 requests.

Definition at line 149 of file string.cc.

Referenced by s3fanout::S3FanoutManager::MkV4Authz().

Here is the caller graph for this function:

time_t IsoTimestamp2UtcTime ( const std::string &  iso8601)

Parses a timestamp of the form YYYY-MM-DDTHH:MM:SSZ Return 0 on error

Definition at line 198 of file string.cc.

Referenced by MountPoint::DetermineRootHash().

Here is the call graph for this function:

Here is the caller graph for this function:

void ParseKeyvalMem ( const unsigned char *  buffer,
const unsigned  buffer_size,
map< char, string > *  content 
)

Definition at line 337 of file string.cc.

Referenced by manifest::Manifest::LoadMem(), ObjectPackConsumer::ParseHeader(), ParseKeyvalPath(), and letter::Letter::Verify().

Here is the caller graph for this function:

bool ParseKeyvalPath ( const string &  filename,
map< char, string > *  content 
)

Definition at line 366 of file string.cc.

Referenced by manifest::Manifest::LoadFile().

Here is the call graph for this function:

Here is the caller graph for this function:

string ReplaceAll ( const string &  haystack,
const string &  needle,
const string &  replace_by 
)

Definition at line 484 of file string.cc.

Referenced by gateway::ParseKey(), and download::DownloadManager::SetUrlOptions().

Here is the caller graph for this function:

vector<string> SplitString ( const string &  str,
char  delim 
)

Definition at line 290 of file string.cc.

Referenced by download::AutoProxy(), manifest::Breadcrumb::Breadcrumb(), publish::SyncItem::CheckGraft(), CheckStrictMount(), ExternalCacheManager::ConnectLocator(), MountPoint::CreateDownloadManagers(), publish::CheckoutMarker::CreateFrom(), XattrList::CreateFromFile(), notify::SubscriberSSE::CurlRecvCB(), cvmfs::cvmfs_getxattr(), DefaultOptionsTemplateManager::DefaultOptionsTemplateManager(), FindExecutable(), swissknife::CommandCheck::FindSubtreeRootCatalog(), FuseMain(), ResolvConfEventHandler::GetDnsAddresses(), receiver::GetSpoolerTempDir(), InitOptionsMgr(), dns::Resolver::IsIpv4Address(), SpecTree::IsMatching(), libcvmfs_initialize(), SpecTree::ListDir(), CachePlugin::Listen(), XattrList::ListKeysPosix(), signature::SignatureManager::LoadPublicRsaKeys(), signature::SignatureManager::LoadTrustedCaCrl(), swissknife::CommandLease::Main(), publish::CmdHelp::Main(), swissknife::CommandPull::Main(), publish::CmdTransaction::Main(), main(), PosixQuotaManager::MainCacheManager(), s3fanout::S3FanoutManager::MkV4Authz(), download::PacProxy2Cvmfs(), SpecTree::Parse(), catalog::VirtualCatalog::ParseActions(), OptionsManager::ParseDefault(), PosixQuotaManager::ParseDirectories(), gateway::ParseKey(), upload::S3Uploader::ParseSpoolerDefinition(), posix_archive_config(), perf::Statistics::PrintJSON(), receiver::CommitProcessor::Process(), swissknife::CommandEditTag::RemoveTags(), download::ResolveProxyDescription(), OptionsManager::SanitizeParameterAssignment(), CachePlugin::SessionInfo::SessionInfo(), publish::SettingsStorage::SetLocator(), download::DownloadManager::SetProxyChain(), MountPoint::SetupBehavior(), FileSystem::SetupExternalCacheMgr(), FileSystem::SetupNfsMaps(), upload::SpoolerDefinition::SpoolerDefinition(), AuthzExternalFetcher::StripAuthzSchema(), download::DownloadManager::StripDirect(), anonymous_namespace{cmd_abort.cc}::StripTrailingPath(), publish::SyncUnionTarball::Traverse(), and download::DownloadManager::ValidateGeoReply().

Here is the call graph for this function:

vector<string> SplitStringBounded ( unsigned  max_chunks,
const string &  str,
char  delim 
)

Definition at line 294 of file string.cc.

Referenced by publish::SyncItem::CheckGraft(), publish::CmdCommit::Main(), publish::CmdTransaction::Main(), and SplitString().

Here is the caller graph for this function:

uint64_t String2Uint64 ( const string &  value)

Definition at line 228 of file string.cc.

Referenced by publish::SettingsBuilder::ApplyOptionsFromServerPath(), manifest::Breadcrumb::Breadcrumb(), receiver::CheckToken(), publish::CmdEnter::CleanupSession(), ExternalCacheManager::ConnectLocator(), PluginRamCache::Create(), MountPoint::CreateCatalogManager(), MountPoint::CreateDownloadManagers(), MountPoint::CreateTables(), MountPoint::CreateTracer(), cvmfs::cvmfs_getxattr(), s3fanout::S3FanoutManager::DetectThrottleIndicator(), publish::ExitShell(), FuseMain(), StatisticsDatabase::GetDBParams(), receiver::GetParamsFromFile(), IngestionPipeline::IngestionPipeline(), LibGlobals::Initialize(), dns::Resolver::IsIpv4Address(), CachePlugin::Listen(), manifest::Manifest::Load(), Lsof(), swissknife::CommandGc::Main(), swissknife::CommandInfo::Main(), main(), swissknife::CommandLetter::Main(), swissknife::CommandPull::Main(), swissknife::CommandCheck::Main(), swissknife::CommandCreate::Main(), swissknife::CommandSync::Main(), TalkManager::MainResponder(), s3fanout::S3FanoutManager::MkV4Authz(), ObjectPackConsumer::ParseHeader(), ObjectPackConsumer::ParseItem(), upload::S3Uploader::ParseSpoolerDefinition(), swissknife::CommandSync::ReadFileChunkingArgs(), MountPoint::SetupBehavior(), MountPoint::SetupDnsTuning(), FileSystem::SetupExternalCacheMgr(), MountPoint::SetupExternalDownloadMgr(), MountPoint::SetupHttpTuning(), MountPoint::SetupInodeAnnotation(), FileSystem::SetupLoggingStandalone(), FileSystem::SetupNfsMaps(), FileSystem::SetupRamCacheMgr(), FileSystem::TriageCacheMgr(), download::DownloadManager::ValidateGeoReply(), and letter::Letter::Verify().

Here is the caller graph for this function:

void String2Uint64Pair ( const string &  value,
uint64_t *  a,
uint64_t *  b 
)

Definition at line 263 of file string.cc.

Referenced by TalkManager::MainResponder().

Here is the caller graph for this function:

bool String2Uint64Parse ( const std::string &  value,
uint64_t *  result 
)

Parse a string into a a uint64_t.

Unlike String2Uint64, this:

  • Checks to make sure the full string is parsed
  • Can indicate an error occurred.

If an error occurs, this returns false and sets errno appropriately.

Definition at line 245 of file string.cc.

Referenced by publish::SyncItem::CheckGraft(), CloseAllFildesInProcSelfFd(), AuthzExternalFetcher::ExecHelper(), catalog::ClientCatalogManager::IsRevisionBlacklisted(), swissknife::CommandGraft::Main(), main(), Url::Parse(), and Url::ValidateHost().

Here is the caller graph for this function:

string StringifyBool ( const bool  value)

Definition at line 76 of file string.cc.

Referenced by manifest::Manifest::ExportString(), swissknife::CommandInfo::Main(), and TalkManager::MainResponder().

Here is the caller graph for this function:

string StringifyByteAsHex ( const unsigned char  value)

Definition at line 90 of file string.cc.

string StringifyDouble ( const double  value)
string StringifyInt ( const int64_t  value)

Definition at line 78 of file string.cc.

Referenced by anonymous_namespace{pack.cc}::AppendItemToHeader(), PosixQuotaManager::BindReturnPipe(), swissknife::CommandListCatalogs::CatalogCallback(), swissknife::CommandFileStats::CatalogCallback(), catalog::WritableCatalog::CopyToParent(), PosixQuotaManager::CreateShared(), publish::CmdEnter::CreateUnderlay(), CreateUserNamespace(), cvmfs_options_clone_legacy(), cvmfs_options_init_legacy(), sqlite::Sql::DebugResultTable(), RamCacheManager::Describe(), upload::SessionContext::DoUpload(), anonymous_namespace{cmd_enter.cc}::EnterRootContainer(), swissknife::Error(), manifest::Manifest::ExportString(), AuthzExternalFetcher::Fetch(), download::DownloadManager::Fetch(), catalog::ClientCatalogManager::FetchCatalogByHash(), MountPoint::FetchHistory(), LHashMagicXattr::FinalizeValue(), NCleanup24MagicXattr::FinalizeValue(), NClgMagicXattr::FinalizeValue(), NIOErrMagicXattr::FinalizeValue(), RxMagicXattr::FinalizeValue(), SpeedMagicXattr::FinalizeValue(), TimestampLastIOErrMagicXattr::FinalizeValue(), ExpiresMagicXattr::FinalizeValue(), InodeMaxMagicXattr::FinalizeValue(), MaxFdMagicXattr::FinalizeValue(), PidMagicXattr::FinalizeValue(), JsonStringGenerator::JsonEntry::Format(), TalkManager::FormatHostInfo(), TalkManager::FormatProxyInfo(), FuseMain(), swissknife::CommandMigrate::ChownMigrationWorker::GenerateMappingStatement(), Watchdog::GenerateStackTrace(), catalog::TreeCountersBase< FieldT >::GetCsvMap(), CachePlugin::HandleHandshake(), AuthzExternalFetcher::Handshake(), swissknife::CommandInfoTag::HumanReadableFilesize(), Init(), PosixQuotaManager::InitDatabase(), anonymous_namespace{pack.cc}::InitializeHeader(), FileSystem::LockWorkspace(), CachePlugin::LogSessionError(), CachePlugin::LogSessionInfo(), swissknife::CommandInfo::Main(), swissknife::CommandPull::Main(), publish::CmdEnter::Main(), main(), PosixQuotaManager::MainCacheManager(), Tracer::MainFlush(), swissknife::CommandFileStats::MainProcessing(), TalkManager::MainResponder(), MaintenanceMode(), MakeAcquireRequest(), anonymous_namespace{repository_session.cc}::MakeAcquireRequest(), perf::TelemetryAggregatorInflux::MakeDeltaPayload(), publish::SettingsStorage::MakeGateway(), perf::TelemetryAggregatorInflux::MakePayload(), PosixQuotaManager::MakeReturnPipe(), s3fanout::S3FanoutManager::MkAzureAuthz(), publish::CmdEnter::MountCvmfs(), publish::CmdEnter::MountOverlayfs(), ChunkListMagicXattr::PrepareValueFenced(), perf::Counter::Print(), s3fanout::Statistics::Print(), download::DownloadManager::ProxyInfo::Print(), glue::InodeTracker::Statistics::Print(), swissknife::CommandListTags::PrintHumanReadableTagList(), cvmfs::PrintInodeGeneration(), perf::Counter::PrintK(), perf::Counter::PrintKi(), perf::Counter::PrintM(), catalog::Catalog::PrintMemStatistics(), perf::Counter::PrintMi(), JsonDocument::PrintValue(), swissknife::CommandGraft::Publish(), publish::Publisher(), loader::Reload(), anonymous_namespace{cmd_enter.cc}::RemoveSingle(), anonymous_namespace{cmd_enter.cc}::RemoveUnderlay(), swissknife::CommandMigrate::StatsMigrationWorker::RepairStatisticsCounters(), Watchdog::ReportStacktrace(), RestoreState(), publish::RunSuidHelper(), SaveState(), Watchdog::SendTrace(), FileSystem::SetupCrashGuard(), letter::Letter::Sign(), ExternalCacheManager::SpawnPlugin(), catalog::SqlAllChunks::SqlAllChunks(), Watchdog::Supervise(), download::DownloadManager::SwitchHost(), notify::msg::Activity::ToJSONString(), manifest::Breadcrumb::ToString(), perf::Counter::ToString(), PosixQuotaManager::UnlinkReturnPipe(), Url::Url(), and AuthzExternalFetcher::~AuthzExternalFetcher().

string StringifyTimeval ( const timeval  value)

Definition at line 185 of file string.cc.

Referenced by Tracer::MainFlush().

Here is the caller graph for this function:

string Tail ( const string &  source,
unsigned  num_lines 
)

Assumes that source is terminated by a newline

Definition at line 592 of file string.cc.

string ToUpper ( const string &  mixed_case)

Converts all characters to upper case

Definition at line 476 of file string.cc.

Referenced by OptionsManager::IsOff(), OptionsManager::IsOn(), and MountPoint::SetupBehavior().

Here is the caller graph for this function:

std::string TrimString ( const std::string &  path,
const std::string &  toTrim,
const int  trimMode 
)

Definition at line 450 of file string.cc.

Referenced by swissknife::Ingest::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string WhitelistTimestamp ( time_t  when)

UTC time in format YYYYMMDDHHMMSS. Used in cvmfs whitelists.

Definition at line 169 of file string.cc.

Referenced by whitelist::Whitelist::CreateString().

Here is the caller graph for this function:

Variable Documentation

const char b64_table[]
Initial value:
= {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', '+', '/'}

Definition at line 33 of file string.cc.

Referenced by Base64().

const int8_t db64_table[]
Initial value:
= {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
}

Decode Base64 and Base64Url

Definition at line 43 of file string.cc.

Referenced by Debase64Block().