// Post a log event to the system NS_IMETHODIMP nsParentalControlsServiceWin::Log(int16_t aEntryType, bool blocked, nsIURI *aSource, nsIFile *aTarget) { if (!mEnabled) return NS_ERROR_NOT_AVAILABLE; NS_ENSURE_ARG_POINTER(aSource); // Confirm we should be logging bool enabled; GetLoggingEnabled(&enabled); if (!enabled) return NS_ERROR_NOT_AVAILABLE; // Register a Vista log event provider associated with the parental controls channel. if (!mProvider) { if (!gEventRegister) return NS_ERROR_NOT_AVAILABLE; if (gEventRegister(&WPCPROV, NULL, NULL, &mProvider) != ERROR_SUCCESS) return NS_ERROR_OUT_OF_MEMORY; } switch(aEntryType) { case ePCLog_URIVisit: // Not needed, Vista's web content filter handles this for us break; case ePCLog_FileDownload: LogFileDownload(blocked, aSource, aTarget); break; default: break; } return NS_OK; }
NS_IMETHODIMP nsMsgFilterList::FlushLogIfNecessary() { // only flush the log if we are logging bool loggingEnabled = false; nsresult rv = GetLoggingEnabled(&loggingEnabled); NS_ENSURE_SUCCESS(rv,rv); if (loggingEnabled) { nsCOMPtr <nsIOutputStream> logStream; rv = GetLogStream(getter_AddRefs(logStream)); if (NS_SUCCEEDED(rv) && logStream) { rv = logStream->Flush(); NS_ENSURE_SUCCESS(rv,rv); } } return rv; }
void Logger::LogError(const String &sMessage) { long lThread = _GetThreadID(); String sTime = GetCurrentTime(); String sData; sData.Format(_T("\"ERROR\"\t%d\t\"%s\"\t\"%s\"\r\n"), lThread, sTime, sMessage); if (m_bEnableLiveLog) _LogLive(sData); _WriteData(sData, Error); // Also log this in the application log if some other logging is enabled. if (GetLoggingEnabled()) _WriteData(sData, Normal); }
NS_IMETHODIMP nsSpamSettings::LogJunkString(const char *string) { bool loggingEnabled; nsresult rv = GetLoggingEnabled(&loggingEnabled); NS_ENSURE_SUCCESS(rv,rv); if (!loggingEnabled) return NS_OK; nsCOMPtr <nsIOutputStream> logStream; rv = GetLogStream(getter_AddRefs(logStream)); NS_ENSURE_SUCCESS(rv,rv); PRUint32 writeCount; rv = logStream->Write(LOG_ENTRY_START_TAG, LOG_ENTRY_START_TAG_LEN, &writeCount); NS_ENSURE_SUCCESS(rv,rv); NS_ASSERTION(writeCount == LOG_ENTRY_START_TAG_LEN, "failed to write out start log tag"); // html escape the log for security reasons. // we don't want some to send us a message with a subject with // html tags, especially <script> char *escapedBuffer = MsgEscapeHTML(string); if (!escapedBuffer) return NS_ERROR_OUT_OF_MEMORY; PRUint32 escapedBufferLen = strlen(escapedBuffer); rv = logStream->Write(escapedBuffer, escapedBufferLen, &writeCount); PR_Free(escapedBuffer); NS_ENSURE_SUCCESS(rv,rv); NS_ASSERTION(writeCount == escapedBufferLen, "failed to write out log hit"); rv = logStream->Write(LOG_ENTRY_END_TAG, LOG_ENTRY_END_TAG_LEN, &writeCount); NS_ENSURE_SUCCESS(rv,rv); NS_ASSERTION(writeCount == LOG_ENTRY_END_TAG_LEN, "failed to write out end log tag"); return NS_OK; }
NS_IMETHODIMP nsSpamSettings::LogJunkHit(nsIMsgDBHdr *aMsgHdr, bool aMoveMessage) { bool loggingEnabled; nsresult rv = GetLoggingEnabled(&loggingEnabled); NS_ENSURE_SUCCESS(rv,rv); if (!loggingEnabled) return NS_OK; PRTime date; nsString authorValue; nsString subjectValue; nsString dateValue; (void)aMsgHdr->GetDate(&date); PRExplodedTime exploded; PR_ExplodeTime(date, PR_LocalTimeParameters, &exploded); if (!mDateFormatter) { mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); if (!mDateFormatter) { return NS_ERROR_FAILURE; } } mDateFormatter->FormatPRExplodedTime(nsnull, kDateFormatShort, kTimeFormatSeconds, &exploded, dateValue); (void)aMsgHdr->GetMime2DecodedAuthor(authorValue); (void)aMsgHdr->GetMime2DecodedSubject(subjectValue); nsCString buffer; // this is big enough to hold a log entry. // do this so we avoid growing and copying as we append to the log. #ifdef MOZILLA_INTERNAL_API buffer.SetCapacity(512); #endif nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIStringBundle> bundle; rv = bundleService->CreateBundle("chrome://messenger/locale/filter.properties", getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); const PRUnichar *junkLogDetectFormatStrings[3] = { authorValue.get(), subjectValue.get(), dateValue.get() }; nsString junkLogDetectStr; rv = bundle->FormatStringFromName( NS_LITERAL_STRING("junkLogDetectStr").get(), junkLogDetectFormatStrings, 3, getter_Copies(junkLogDetectStr)); NS_ENSURE_SUCCESS(rv, rv); buffer += NS_ConvertUTF16toUTF8(junkLogDetectStr); buffer += "\n"; if (aMoveMessage) { nsCString msgId; aMsgHdr->GetMessageId(getter_Copies(msgId)); nsCString junkFolderURI; rv = GetSpamFolderURI(getter_Copies(junkFolderURI)); NS_ENSURE_SUCCESS(rv, rv); NS_ConvertASCIItoUTF16 msgIdValue(msgId); NS_ConvertASCIItoUTF16 junkFolderURIValue(junkFolderURI); const PRUnichar *logMoveFormatStrings[2] = { msgIdValue.get(), junkFolderURIValue.get() }; nsString logMoveStr; rv = bundle->FormatStringFromName( NS_LITERAL_STRING("logMoveStr").get(), logMoveFormatStrings, 2, getter_Copies(logMoveStr)); NS_ENSURE_SUCCESS(rv, rv); buffer += NS_ConvertUTF16toUTF8(logMoveStr); buffer += "\n"; } return LogJunkString(buffer.get()); }