| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/goopdate/worker_utils.h" | |
| 17 #include "omaha/base/constants.h" | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/error.h" | |
| 20 #include "omaha/base/file.h" | |
| 21 #include "omaha/base/logging.h" | |
| 22 #include "omaha/base/safe_format.h" | |
| 23 #include "omaha/base/signatures.h" | |
| 24 #include "omaha/common/const_goopdate.h" | |
| 25 #include "omaha/common/event_logger.h" | |
| 26 #include "omaha/goopdate/server_resource.h" | |
| 27 #include "omaha/goopdate/string_formatter.h" | |
| 28 #include "omaha/net/network_request.h" | |
| 29 | |
| 30 namespace omaha { | |
| 31 | |
| 32 namespace worker_utils { | |
| 33 | |
| 34 bool FormatMessageForNetworkError(HRESULT error, | |
| 35 const CString& language, | |
| 36 CString* msg) { | |
| 37 ASSERT1(msg); | |
| 38 StringFormatter formatter(language); | |
| 39 | |
| 40 switch (error) { | |
| 41 case GOOPDATE_E_NO_NETWORK: | |
| 42 VERIFY1(SUCCEEDED(formatter.FormatMessage(msg, | |
| 43 IDS_NO_NETWORK_PRESENT_ERROR, | |
| 44 kOmahaShellFileName))); | |
| 45 break; | |
| 46 case GOOPDATE_E_NETWORK_UNAUTHORIZED: | |
| 47 VERIFY1(SUCCEEDED( | |
| 48 formatter.LoadString(IDS_ERROR_HTTPSTATUS_UNAUTHORIZED, msg))); | |
| 49 break; | |
| 50 case GOOPDATE_E_NETWORK_FORBIDDEN: | |
| 51 VERIFY1(SUCCEEDED( | |
| 52 formatter.LoadString(IDS_ERROR_HTTPSTATUS_FORBIDDEN, msg))); | |
| 53 break; | |
| 54 case GOOPDATE_E_NETWORK_PROXYAUTHREQUIRED: | |
| 55 VERIFY1(SUCCEEDED( | |
| 56 formatter.LoadString(IDS_ERROR_HTTPSTATUS_PROXY_AUTH_REQUIRED, msg))); | |
| 57 break; | |
| 58 default: | |
| 59 VERIFY1(SUCCEEDED(formatter.FormatMessage(msg, | |
| 60 IDS_NO_NETWORK_PRESENT_ERROR, | |
| 61 kOmahaShellFileName))); | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 void AddHttpRequestDataToEventLog(HRESULT hr, | |
| 69 int http_status_code, | |
| 70 const CString& http_trace, | |
| 71 bool is_machine) { | |
| 72 CString msg; | |
| 73 SafeCStringFormat(&msg, | |
| 74 _T("Http Request Error.\r\n") | |
| 75 _T("Error: 0x%08x. Http status code: %d.\r\n%s"), | |
| 76 hr, | |
| 77 http_status_code, | |
| 78 http_trace); | |
| 79 | |
| 80 GoogleUpdateLogEvent http_request_event(EVENTLOG_INFORMATION_TYPE, | |
| 81 kNetworkRequestEventId, | |
| 82 is_machine); | |
| 83 http_request_event.set_event_desc(msg); | |
| 84 http_request_event.WriteEvent(); | |
| 85 } | |
| 86 | |
| 87 // TODO(omaha): there can be more install actions for each install event. | |
| 88 // Minor thing: the return value and the out params are redundant, meaning | |
| 89 // there is no need to have them both. This eliminates an assert at the call | |
| 90 // site. | |
| 91 bool GetInstallActionForEvent( | |
| 92 const std::vector<xml::InstallAction>& install_actions, | |
| 93 xml::InstallAction::InstallEvent install_event, | |
| 94 const xml::InstallAction** action) { | |
| 95 ASSERT1(action); | |
| 96 | |
| 97 for (size_t i = 0; i < install_actions.size(); ++i) { | |
| 98 if (install_actions[i].install_event == install_event) { | |
| 99 *action = &install_actions[i]; | |
| 100 return true; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 } // namespace worker_utils | |
| 108 | |
| 109 } // namespace omaha | |
| 110 | |
| OLD | NEW |