OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "update_engine/update_check_action.h" | 5 #include "update_engine/update_check_action.h" |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include <libxml/parser.h> | 8 #include <libxml/parser.h> |
9 #include <libxml/xpath.h> | 9 #include <libxml/xpath.h> |
10 #include <libxml/xpathInternals.h> | 10 #include <libxml/xpathInternals.h> |
11 | 11 |
| 12 #include "chromeos/obsolete_logging.h" |
12 #include "update_engine/action_pipe.h" | 13 #include "update_engine/action_pipe.h" |
| 14 #include "update_engine/utils.h" |
13 | 15 |
14 using std::string; | 16 using std::string; |
15 | 17 |
16 namespace chromeos_update_engine { | 18 namespace chromeos_update_engine { |
17 | 19 |
18 const char* const UpdateCheckParams::kAppId( | 20 const char* const UpdateCheckParams::kAppId( |
19 "87efface-864d-49a5-9bb3-4b050a7c227a"); | 21 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); |
20 const char* const UpdateCheckParams::kOsPlatform("Chrome OS"); | 22 const char* const UpdateCheckParams::kOsPlatform("Chrome OS"); |
21 const char* const UpdateCheckParams::kOsVersion("Indy"); | 23 const char* const UpdateCheckParams::kOsVersion("Indy"); |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const string kGupdateVersion("ChromeOSUpdateEngine-0.1.0.0"); | 27 const string kGupdateVersion("ChromeOSUpdateEngine-0.1.0.0"); |
26 | 28 |
27 // This is handy for passing strings into libxml2 | 29 // This is handy for passing strings into libxml2 |
28 #define ConstXMLStr(x) (reinterpret_cast<const xmlChar*>(x)) | 30 #define ConstXMLStr(x) (reinterpret_cast<const xmlChar*>(x)) |
29 | 31 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // xmlNewDoc(ConstXMLStr("1.0"))); | 86 // xmlNewDoc(ConstXMLStr("1.0"))); |
85 // if (!xml_doc.get()) { | 87 // if (!xml_doc.get()) { |
86 // LOG(ERROR) << "Unable to create xmlDoc"; | 88 // LOG(ERROR) << "Unable to create xmlDoc"; |
87 // return ""; | 89 // return ""; |
88 // } | 90 // } |
89 scoped_ptr_malloc<xmlChar, ScopedPtrXmlFree> str( | 91 scoped_ptr_malloc<xmlChar, ScopedPtrXmlFree> str( |
90 xmlEncodeEntitiesReentrant(NULL, ConstXMLStr(input.c_str()))); | 92 xmlEncodeEntitiesReentrant(NULL, ConstXMLStr(input.c_str()))); |
91 return string(reinterpret_cast<const char *>(str.get())); | 93 return string(reinterpret_cast<const char *>(str.get())); |
92 } | 94 } |
93 | 95 |
94 UpdateCheckAction::UpdateCheckAction(const UpdateCheckParams& params, | 96 UpdateCheckAction::UpdateCheckAction(HttpFetcher* http_fetcher) |
95 HttpFetcher* http_fetcher) | 97 : http_fetcher_(http_fetcher) {} |
96 : params_(params), http_fetcher_(http_fetcher) {} | |
97 | 98 |
98 UpdateCheckAction::~UpdateCheckAction() {} | 99 UpdateCheckAction::~UpdateCheckAction() {} |
99 | 100 |
100 void UpdateCheckAction::PerformAction() { | 101 void UpdateCheckAction::PerformAction() { |
| 102 CHECK(HasInputObject()); |
| 103 params_ = GetInputObject(); |
101 http_fetcher_->set_delegate(this); | 104 http_fetcher_->set_delegate(this); |
102 string request_post(FormatRequest(params_)); | 105 string request_post(FormatRequest(params_)); |
103 http_fetcher_->SetPostData(request_post.data(), request_post.size()); | 106 http_fetcher_->SetPostData(request_post.data(), request_post.size()); |
104 http_fetcher_->BeginTransfer("https://tools.google.com/service/update2"); | 107 http_fetcher_->BeginTransfer("https://tools.google.com/service/update2"); |
105 } | 108 } |
106 | 109 |
107 void UpdateCheckAction::TerminateProcessing() { | 110 void UpdateCheckAction::TerminateProcessing() { |
108 http_fetcher_->TerminateTransfer(); | 111 http_fetcher_->TerminateTransfer(); |
109 } | 112 } |
110 | 113 |
111 // We just store the response in the buffer. Once we've received all bytes, | 114 // We just store the response in the buffer. Once we've received all bytes, |
112 // we'll look in the buffer and decide what to do. | 115 // we'll look in the buffer and decide what to do. |
113 void UpdateCheckAction::ReceivedBytes(HttpFetcher *fetcher, | 116 void UpdateCheckAction::ReceivedBytes(HttpFetcher *fetcher, |
114 const char* bytes, | 117 const char* bytes, |
115 int length) { | 118 int length) { |
116 response_buffer_.reserve(response_buffer_.size() + length); | 119 response_buffer_.reserve(response_buffer_.size() + length); |
117 response_buffer_.insert(response_buffer_.end(), bytes, bytes + length); | 120 response_buffer_.insert(response_buffer_.end(), bytes, bytes + length); |
118 } | 121 } |
119 | 122 |
120 namespace { | 123 namespace { |
121 // A little object to call ActionComplete on the ActionProcessor when | |
122 // it's destructed. | |
123 class ScopedActionCompleter { | |
124 public: | |
125 explicit ScopedActionCompleter(ActionProcessor* processor, | |
126 AbstractAction* action) | |
127 : processor_(processor), action_(action), success_(false) {} | |
128 ~ScopedActionCompleter() { | |
129 processor_->ActionComplete(action_, success_); | |
130 } | |
131 void set_success(bool success) { | |
132 success_ = success; | |
133 } | |
134 private: | |
135 ActionProcessor* processor_; | |
136 AbstractAction* action_; | |
137 bool success_; | |
138 DISALLOW_COPY_AND_ASSIGN(ScopedActionCompleter); | |
139 }; | |
140 | |
141 // If non-NULL response, caller is responsible for calling xmlXPathFreeObject() | 124 // If non-NULL response, caller is responsible for calling xmlXPathFreeObject() |
142 // on the returned object. | 125 // on the returned object. |
143 // This code is roughly based on the libxml tutorial at: | 126 // This code is roughly based on the libxml tutorial at: |
144 // http://xmlsoft.org/tutorial/apd.html | 127 // http://xmlsoft.org/tutorial/apd.html |
145 xmlXPathObject* GetNodeSet(xmlDoc* doc, const xmlChar* xpath, | 128 xmlXPathObject* GetNodeSet(xmlDoc* doc, const xmlChar* xpath, |
146 const xmlChar* ns, const xmlChar* ns_url) { | 129 const xmlChar* ns, const xmlChar* ns_url) { |
147 xmlXPathObject* result = NULL; | 130 xmlXPathObject* result = NULL; |
148 | 131 |
149 scoped_ptr_malloc<xmlXPathContext, ScopedPtrXmlXPathContextFree> context( | 132 scoped_ptr_malloc<xmlXPathContext, ScopedPtrXmlXPathContextFree> context( |
150 xmlXPathNewContext(doc)); | 133 xmlXPathNewContext(doc)); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 output_object.hash = XmlGetProperty(updatecheck_node, "hash"); | 255 output_object.hash = XmlGetProperty(updatecheck_node, "hash"); |
273 output_object.size = ParseInt(XmlGetProperty(updatecheck_node, "size")); | 256 output_object.size = ParseInt(XmlGetProperty(updatecheck_node, "size")); |
274 output_object.needs_admin = | 257 output_object.needs_admin = |
275 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; | 258 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; |
276 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; | 259 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; |
277 SetOutputObject(output_object); | 260 SetOutputObject(output_object); |
278 return; | 261 return; |
279 } | 262 } |
280 | 263 |
281 }; // namespace chromeos_update_engine | 264 }; // namespace chromeos_update_engine |
OLD | NEW |