CernVM-FS  2.9.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, const char delim, const unsigned max_chunks)
 
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)
 
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], const signed char *d_table, unsigned char output[3])
 
bool Debase64 (const string &data, string *decoded)
 
string Tail (const string &source, unsigned num_lines)
 
std::string GetGMTimestamp (std::string format)
 

Variables

const char b64_table []
 
const signed char db64_table []
 

Macro Definition Documentation

#define __STDC_FORMAT_MACROS

This file is part of the CernVM File System.

Some common functions.

Definition at line 8 of file string.cc.

Function Documentation

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

Definition at line 465 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 504 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 532 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],
const signed char *  d_table,
unsigned char  output[3] 
)
static

Definition at line 515 of file string.cc.

Referenced by Debase64().

Here is the caller graph for this function:

std::string GetGMTimestamp ( 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 583 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 396 of file string.cc.

Referenced by FuseMain(), publish::ServerLockFile::IsLocked(), 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 
)
bool HasSuffix ( const std::string &  str,
const std::string &  suffix,
const bool  ignore_case 
)
std::string IsoTimestamp ( )

Current time in format YYYYMMDDTHHMMSSZ. Used in AWS4 requests.

Definition at line 148 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 timstamp of the form YYYY-MM-DDTHH:MM:SSZ Return 0 on error

Definition at line 197 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 329 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 358 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 453 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,
const char  delim,
const unsigned  max_chunks 
)

Definition at line 287 of file string.cc.

Referenced by download::AutoProxy(), publish::SyncItem::CheckGraft(), CheckStrictMount(), ExternalCacheManager::ConnectLocator(), publish::CheckoutMarker::CreateFrom(), XattrList::CreateFromFile(), notify::SubscriberSSE::CurlRecvCB(), 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(), FileSystem::SetupExternalCacheMgr(), FileSystem::SetupNfsMaps(), upload::SpoolerDefinition::SpoolerDefinition(), AuthzExternalFetcher::StripAuthzSchema(), download::DownloadManager::StripDirect(), publish::SyncUnionTarball::Traverse(), and download::DownloadManager::ValidateGeoReply().

uint64_t String2Uint64 ( const string &  value)

Definition at line 227 of file string.cc.

Referenced by swissknife::CommandEditTag::AddNewTag(), manifest::Breadcrumb::Breadcrumb(), receiver::CheckToken(), publish::CmdEnter::CleanupSession(), ExternalCacheManager::ConnectLocator(), PluginRamCache::Create(), MountPoint::CreateCatalogManager(), MountPoint::CreateDownloadManagers(), publish::SettingsBuilder::CreateSettingsPublisher(), MountPoint::CreateTables(), MountPoint::CreateTracer(), s3fanout::S3FanoutManager::DetectThrottleIndicator(), 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::CommandCheck::Main(), swissknife::CommandPull::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::SetupLogging(), FileSystem::SetupNfsMaps(), FileSystem::SetupRamCacheMgr(), 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 260 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 242 of file string.cc.

Referenced by publish::SyncItem::CheckGraft(), 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)

This file is part of the CernVM File System.

Definition at line 75 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 89 of file string.cc.

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

Definition at line 77 of file string.cc.

Referenced by publish::ServerLockFile::Acquire(), 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(), MountPoint::FetchHistory(), JsonStringGenerator::JsonEntry::Format(), TalkManager::FormatHostInfo(), TalkManager::FormatProxyInfo(), FuseMain(), swissknife::CommandMigrate::ChownMigrationWorker::GenerateMappingStatement(), Watchdog::GenerateStackTrace(), catalog::TreeCountersBase< FieldT >::GetCsvMap(), LHashMagicXattr::GetValue(), NCleanup24MagicXattr::GetValue(), NClgMagicXattr::GetValue(), RxMagicXattr::GetValue(), SpeedMagicXattr::GetValue(), ExpiresMagicXattr::GetValue(), InodeMaxMagicXattr::GetValue(), MaxFdMagicXattr::GetValue(), PidMagicXattr::GetValue(), UptimeMagicXattr::GetValue(), CachePlugin::HandleHandshake(), AuthzExternalFetcher::Handshake(), swissknife::CommandInfoTag::HumanReadableFilesize(), Init(), PosixQuotaManager::InitDatabase(), anonymous_namespace{pack.cc}::InitializeHeader(), catalog::ClientCatalogManager::LoadCatalogCas(), FileSystem::LockWorkspace(), CachePlugin::LogSessionError(), CachePlugin::LogSessionInfo(), swissknife::CommandInfo::Main(), publish::CmdEnter::Main(), swissknife::CommandPull::Main(), main(), PosixQuotaManager::MainCacheManager(), Tracer::MainFlush(), swissknife::CommandFileStats::MainProcessing(), TalkManager::MainResponder(), MaintenanceMode(), MakeAcquireRequest(), anonymous_namespace{repository_session.cc}::MakeAcquireRequest(), publish::SettingsStorage::MakeGateway(), 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(), 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 184 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 560 of file string.cc.

string ToUpper ( const string &  mixed_case)

Converts all characters to upper case

Definition at line 445 of file string.cc.

Referenced by OptionsManager::IsOn().

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 168 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 32 of file string.cc.

Referenced by Base64().

const signed char 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 42 of file string.cc.

Referenced by Debase64(), and Debase64Block().