Skip to content

Commit

Permalink
updates resulting from PR comments. fixed some bugs in how log files …
Browse files Browse the repository at this point in the history
…are produced. added another logging mask.
  • Loading branch information
rw2 committed Sep 25, 2024
1 parent 4d68765 commit 9ca57df
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ static void dump_plain(const char *text, FILE *stream, unsigned char *ptr,
fprintf(stream, "%s\n", ptr);
}

int debug_callback(CURL *handle, curl_infotype ci, char *data, size_t size,
void *clientp) {
int debugCallback(CURL *handle, curl_infotype ci, char *data, size_t size,
void *clientp) {
const char *text;
(void)handle; /* prevent compiler warning */
(void)clientp;
Expand Down Expand Up @@ -174,7 +174,6 @@ int debug_callback(CURL *handle, curl_infotype ci, char *data, size_t size,
text = "<= Recv SSL data";
break;
}

dump(text, stderr, (unsigned char *)data, size);

return 0;
Expand Down Expand Up @@ -427,8 +426,10 @@ bool HTTPRequest::sendPreparedRequest(const std::string &protocol,
}
return false;
}
// rv = curl_easy_setopt(curl.get(), CURLOPT_DEBUGFUNCTION, debug_callback);
// rv = curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L);
if (m_log.getMsgMask() & LogMask::Dump) {
rv = curl_easy_setopt(curl.get(), CURLOPT_DEBUGFUNCTION, debugCallback);
rv = curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L);
}

retry:
rv = curl_easy_perform(curl.get());
Expand Down
2 changes: 1 addition & 1 deletion src/S3Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool AmazonRequest::parseURL(const std::string &url, std::string &bucket_path,
// everything between
// :// up until the last /, but with <bucket> appended to the front.
host = bucket + "." + substring(url, hostStartIdx);
if (retain_object) {
if (retainObject) {
path = "/" + object;
} else {
path = "/";
Expand Down
8 changes: 3 additions & 5 deletions src/S3Commands.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AmazonRequest : public HTTPRequest {
: HTTPRequest(s, log, nullptr), accessKeyFile(akf), secretKeyFile(skf),
signatureVersion(sv), bucket(b), object(o), m_style(style) {
requiresSignature = true;
retain_object = ro;
retainObject = ro;
// Start off by parsing the hostUrl, which we use in conjunction with
// the bucket to fill in the host (for setting host header). For
// example, if the incoming hostUrl (which we get from config) is
Expand Down Expand Up @@ -88,7 +88,7 @@ class AmazonRequest : public HTTPRequest {
protected:
bool sendV4Request(const std::string &payload, bool sendContentSHA = false);

bool retain_object;
bool retainObject;

std::string accessKeyFile;
std::string secretKeyFile;
Expand Down Expand Up @@ -263,9 +263,7 @@ class AmazonS3List : public AmazonRequest {
public:
AmazonS3List(const S3AccessInfo &ai, const std::string &objectName,
size_t maxKeys, XrdSysError &log)
: AmazonRequest(ai, objectName, log, false), m_maxKeys(maxKeys) {
retain_object = false;
}
: AmazonRequest(ai, objectName, log, false), m_maxKeys(maxKeys) {}

virtual ~AmazonS3List() {}

Expand Down
8 changes: 8 additions & 0 deletions src/S3FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ bool S3FileSystem::Config(XrdSysLogger *lp, const char *configfn) {
Config.Attach(cfgFD);
std::shared_ptr<S3AccessInfo> newAccessInfo(new S3AccessInfo());
std::string exposedPath;
m_log.setMsgMask(0);
while ((temporary = Config.GetMyFirstWord())) {
attribute = temporary;
if (attribute == "s3.trace") {
if (!XrdHTTPServer::ConfigLog(Config, m_log)) {
m_log.Emsg("Config", "Failed to configure the log level");
}
continue;
}

temporary = Config.GetWord();
if (attribute == "s3.end") {
m_s3_access_map[exposedPath] = newAccessInfo;
Expand Down
7 changes: 6 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ std::string XrdHTTPServer::LogMaskToString(int mask) {

bool has_entry = false;
std::stringstream ss;
if (mask & LogMask::Dump) {
ss << "dump";
has_entry = true;
}
if (mask & LogMask::Debug) {
ss << "debug";
has_entry = true;
Expand All @@ -53,7 +57,6 @@ std::string XrdHTTPServer::LogMaskToString(int mask) {

bool XrdHTTPServer::ConfigLog(XrdOucStream &conf, XrdSysError &log) {
std::string map_filename;
log.setMsgMask(0);
char *val = nullptr;
if (!(val = conf.GetToken())) {
log.Emsg("Config",
Expand All @@ -70,6 +73,8 @@ bool XrdHTTPServer::ConfigLog(XrdOucStream &conf, XrdSysError &log) {
log.setMsgMask(log.getMsgMask() | LogMask::Warning);
} else if (!strcmp(val, "info")) {
log.setMsgMask(log.getMsgMask() | LogMask::Info);
} else if (!strcmp(val, "dump")) {
log.setMsgMask(log.getMsgMask() | LogMask::Dump);
} else if (!strcmp(val, "debug")) {
log.setMsgMask(log.getMsgMask() | LogMask::Debug);
} else if (!strcmp(val, "none")) {
Expand Down
3 changes: 2 additions & 1 deletion src/logging.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum LogMask {
Info = 0x02,
Warning = 0x04,
Error = 0x08,
All = 0xff
All = 0x0f,
Dump = 0x10
};

// Given a bitset based on LogMask, return a human-readable string of the set
Expand Down

0 comments on commit 9ca57df

Please sign in to comment.