OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #if LOGGING |
| 6 |
| 7 #include "chrome/browser/sync/notifier/communicator/xmpp_log.h" |
| 8 |
| 9 #include <iomanip> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "chrome/browser/sync/notifier/base/time.h" |
| 14 #include "talk/base/common.h" |
| 15 #include "talk/base/logging.h" |
| 16 |
| 17 namespace notifier { |
| 18 |
| 19 static bool IsAuthTag(const char* str, size_t len) { |
| 20 // Beware that str is not NULL terminated |
| 21 if (str[0] == '<' && |
| 22 str[1] == 'a' && |
| 23 str[2] == 'u' && |
| 24 str[3] == 't' && |
| 25 str[4] == 'h' && |
| 26 str[5] <= ' ') { |
| 27 std::string tag(str, len); |
| 28 if (tag.find("mechanism") != std::string::npos) |
| 29 return true; |
| 30 } |
| 31 return false; |
| 32 } |
| 33 |
| 34 static bool IsChatText(const char* str, size_t len) { |
| 35 // Beware that str is not NULL terminated |
| 36 if (str[0] == '<' && |
| 37 str[1] == 'm' && |
| 38 str[2] == 'e' && |
| 39 str[3] == 's' && |
| 40 str[4] == 's' && |
| 41 str[5] == 'a' && |
| 42 str[6] == 'g' && |
| 43 str[7] == 'e' && |
| 44 str[8] <= ' ') { |
| 45 std::string tag(str, len); |
| 46 if (tag.find("chat") != std::string::npos) |
| 47 return true; |
| 48 } |
| 49 return false; |
| 50 } |
| 51 |
| 52 void XmppLog::XmppPrint(bool output) { |
| 53 std::vector<char>* buffer = output ? |
| 54 &xmpp_output_buffer_ : &xmpp_input_buffer_; |
| 55 const bool log_chat = LOG_CHECK_LEVEL(LS_SENSITIVE); |
| 56 if (buffer->size()) { |
| 57 char* time_string = GetLocalTimeAsString(); |
| 58 LOG(INFO) << (output ? "SEND >>>>>>>>>>>>>>>>>>>>>>>>>" : |
| 59 "RECV <<<<<<<<<<<<<<<<<<<<<<<<<") |
| 60 << " : " << time_string; |
| 61 |
| 62 int start = 0; |
| 63 int nest = 3; |
| 64 for (int i = 0; i < static_cast<int>(buffer->size()); ++i) { |
| 65 if ((*buffer)[i] == '>') { |
| 66 bool indent; |
| 67 if ((i > 0) && ((*buffer)[i - 1] == '/')) { |
| 68 indent = false; |
| 69 } else if ((start + 1 < static_cast<int>(buffer->size())) && |
| 70 ((*buffer)[start + 1] == '/')) { |
| 71 indent = false; |
| 72 nest -= 2; |
| 73 } else { |
| 74 indent = true; |
| 75 } |
| 76 |
| 77 // Output a tag |
| 78 LOG(INFO) << std::setw(nest) << " " |
| 79 << std::string(&((*buffer)[start]), i + 1 - start); |
| 80 |
| 81 if (indent) |
| 82 nest += 2; |
| 83 |
| 84 // Note if it's a PLAIN auth tag |
| 85 if (IsAuthTag(&((*buffer)[start]), i + 1 - start)) { |
| 86 censor_password_ = true; |
| 87 } else if (!log_chat && IsChatText(&((*buffer)[start]), |
| 88 i + 1 - start)) { |
| 89 censor_password_ = true; |
| 90 } |
| 91 |
| 92 start = i + 1; |
| 93 } |
| 94 |
| 95 if ((*buffer)[i] == '<' && start < i) { |
| 96 if (censor_password_) { |
| 97 LOG(INFO) << std::setw(nest) << " " << "## TEXT REMOVED ##"; |
| 98 censor_password_ = false; |
| 99 } else { |
| 100 LOG(INFO) << std::setw(nest) << " " |
| 101 << std::string(&((*buffer)[start]), i - start); |
| 102 } |
| 103 start = i; |
| 104 } |
| 105 } |
| 106 buffer->erase(buffer->begin(), buffer->begin() + start); |
| 107 } |
| 108 } |
| 109 } // namespace notifier |
| 110 |
| 111 #endif // if LOGGING |
OLD | NEW |