bool Server::set_private_key(const void* key, const std::size_t keySize) const { OT_ASSERT(nullptr != parent_); socket::implementation::Socket::SocketCallback cb{[&](const Lock&) -> bool { const int server{1}; auto set = zmq_setsockopt(parent_, ZMQ_CURVE_SERVER, &server, sizeof(server)); if (0 != set) { LogOutput(OT_METHOD)(__FUNCTION__)( ": Failed to set ZMQ_CURVE_SERVER") .Flush(); return false; } set = zmq_setsockopt(parent_, ZMQ_CURVE_SECRETKEY, key, keySize); if (0 != set) { LogOutput(OT_METHOD)(__FUNCTION__)(": Failed to set private key.") .Flush(); return false; } return true; }}; return parent_.apply_socket(std::move(cb)); }
bool OTTransactionType::VerifyContractID() const { // m_AcctID contains the number we read from the xml file // we can compare it to the existing and actual identifier. // m_AcctID contains the "IDENTIFIER" of the object, according to the xml // file. // // Meanwhile m_ID contains the same identifier, except it was generated. // // Now let's compare the two and make sure they match... // Also, for this class, we compare NotaryID as well. They go hand in hand. if ((m_ID != m_AcctID) || (m_NotaryID != m_AcctNotaryID)) { auto str1 = String::Factory(m_ID), str2 = String::Factory(m_AcctID), str3 = String::Factory(m_NotaryID), str4 = String::Factory(m_AcctNotaryID); LogOutput(OT_METHOD)(__FUNCTION__)(": Identifiers mismatch").Flush(); LogOutput("m_AcctID actual: ")(m_AcctID)(" expected: ")(m_ID).Flush(); LogOutput("m_NotaryID actual: ")(m_AcctNotaryID)(" expected: ")( m_NotaryID) .Flush(); return false; } else { return true; } }
void CTextFileLog::LogOutput (DWORD dwFlags, char *pszLine, ...) // LogOutput // // Output a line to the log { CString sParsedLine; char *pArgs = (char *)&pszLine + sizeof(pszLine); sParsedLine = strPattern(CString(pszLine, ::strlen(pszLine), TRUE), (void **)pArgs); LogOutput(dwFlags, sParsedLine); }
void Log(const char* text, ...) { char buffer[MAX_DEBUG_LINE_LEN]; va_list args; va_start(args, text); int buf = _vsnprintf_s(buffer, MAX_DEBUG_LINE_LEN, text, args); assert((buf >= 0) && (buf < MAX_DEBUG_LINE_LEN)); va_end(args); // Log output to debug windows and/or disk depending on options char buffer2[MAX_DEBUG_LINE_LEN]; strcpy_s(buffer2, MAX_DEBUG_LINE_LEN, "DEBUG: "); strcpy_s(buffer2+7, MAX_DEBUG_LINE_LEN-7, buffer); LogOutput(buffer); }
void YamlHelper::GetMapRemainder(std::string& mapName, MapYaml& mapYaml) { for (MapYaml::iterator iter = mapYaml.begin(); iter != mapYaml.end(); ++iter) { if (iter->second.subMap) { std::string subMapName(iter->first); GetMapRemainder(subMapName, *iter->second.subMap); delete iter->second.subMap; } else { const char* pKey = iter->first.c_str(); LogOutput("%s: Unknown key (%s)\n", mapName.c_str(), pKey); LogFileOutput("%s: Unknown key (%s)\n", mapName.c_str(), pKey); } } mapYaml.clear(); }
int LogMessage(void *data, loglevels lev, logtypes type, const char *message, const char *func, int line, const char *file) { struct LogInfo *li=(struct LogInfo *)data; char *msgcopy = NULL; if (!data) return 1; /* Ensures that LOG_NONE level means nothing is logged. */ if (lev >= LEV_NONE) lev = LEV_DEBUG; if (li) { if (type == T_PRE) type = li->deftype; LogOption(data, "LEVEL", levnames[lev]); if (((li->currlev >= lev) && (li->currtype & type)) || (li->currlev == LEV_DEBUG)) { const char *format = li->format; int mode = 0; char *str = NULL; char *holder = NULL; signed int len = 0; msgcopy = strdup(message); holder = msgcopy; if (!msgcopy) return 0; while (*holder != '\0') { if (!isprint(*holder)) *holder = '.'; ++holder; } while (*format) { switch(*format) { case '%': if (mode == 1) { str = StringAdd(str, "%", len); mode=0; } else if (mode == 0) { len = GetLen(&format); mode = 1; } else goto err; break; case 'm': if (mode == 0) str = StringAdd(str, "m", len); else if (mode == 1) { str = StringAdd(str, msgcopy, len); mode = 0; } else goto err; break; case 'd': str = StringAdd(str, "%d", len); break; case 'p': if (mode == 0) str = StringAdd(str, "p", len); else if (mode == 1) { pid_t pid = getpid(); char val[(((sizeof(pid_t)*CHAR_BIT)/3)+2)]; sprintf(val,"%d",(int)pid); str = StringAdd(str, val, len); mode = 0; } else goto err; break; case 's': if (mode == 0) str = StringAdd(str, "s", len); else if (mode == 1) { if (li->service) str = StringAdd(str, li->service, len); } else goto err; break; case 'f': if (mode == 0) str = StringAdd(str, "f", len); else if (mode == 1) { str = StringAdd(str, file, len); } else goto err; break; case 'l': if (mode == 0) str = StringAdd(str, "l", len); else if (mode == 1) { char val[(((sizeof(pid_t)*CHAR_BIT)/3)+2)]; sprintf(val,"%d",line); str = StringAdd(str, val, len); } else goto err; break; case 'T': if (mode == 0) str = StringAdd(str, "N", len); else if (mode == 1) { int i = 0; int k = 0x01; while (!(type&k)) k <<= 1, i++; str = StringAdd(str, typenames[i], len); } else goto err; break; case 't': if (mode == 0) str = StringAdd(str, "n", len); else if (mode == 1) { char val[(((sizeof(pid_t)*CHAR_BIT)/3)+2)]; sprintf(val,"%d",type); str = StringAdd(str, val, len); } else goto err; break; case 'v': if (mode == 0) str = StringAdd(str, "v", len); else if (mode == 1) { char val[(((sizeof(pid_t)*CHAR_BIT)/3)+2)]; sprintf(val,"%d",lev); str = StringAdd(str, val, len); } else goto err; break; case 'V': if (mode == 0) str = StringAdd(str, "V", len); else if (mode == 1) { str = StringAdd(str, levnames[lev], len); } else goto err; break; case 'F': if (mode == 0) str = StringAdd(str, "F", len); else if (mode == 1) { if (func) str = StringAdd(str, func, len); } else goto err; break; case 'h': if (mode == 0) str = StringAdd(str, "h", len); else if (mode == 1) { struct utsname u; if (!uname(&u)) str = StringAdd(str, u.nodename, len); else goto err; } else goto err; break; default: { char s[2]; s[0] = *format; s[1] = '\0'; str = StringAdd(str, s, -1); } mode =0; break; } format++; } str = StringAdd(str, "\n", -1); LogOutput(data, str); free(str); } } free(msgcopy); return 1; err: free(msgcopy); return 0; }
void Logger::LoggerTrace(std::string content) { LogOutput("TRACE", content); }
void Logger::LoggerDebug(std::string content) { LogOutput("DEBUG", content); }
void Logger::LoggerInfo(std::string content) { LogOutput("INFO ", content); }
void Logger::LoggerWarn(std::string content) { LogOutput("WARN ", content); }
void Logger::LoggerError(std::string content) { LogOutput("ERROR", content); }
void Logger::LoggerFatal(std::string content) { LogOutput("FATAL", content); }