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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ |
7 | 7 |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include <curl/curl.h> | 14 #include <curl/curl.h> |
15 | 15 |
16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
17 #include "update_engine/action.h" | 17 #include "update_engine/action.h" |
18 #include "update_engine/http_fetcher.h" | 18 #include "update_engine/http_fetcher.h" |
19 | 19 |
20 // The Update Check action makes an update check request to Omaha and | 20 // The Omaha Request action makes a request to Omaha and can output |
21 // can output the response on the output ActionPipe. | 21 // the response on the output ActionPipe. |
22 | 22 |
23 namespace chromeos_update_engine { | 23 namespace chromeos_update_engine { |
24 | 24 |
25 // Encodes XML entities in a given string with libxml2. input must be | 25 // Encodes XML entities in a given string with libxml2. input must be |
26 // UTF-8 formatted. Output will be UTF-8 formatted. | 26 // UTF-8 formatted. Output will be UTF-8 formatted. |
27 std::string XmlEncode(const std::string& input); | 27 std::string XmlEncode(const std::string& input); |
28 | 28 |
29 // This struct encapsulates the data Omaha gets for the update check. | 29 // This struct encapsulates the data Omaha gets for the request. |
30 // These strings in this struct should not be XML escaped. | 30 // These strings in this struct should not be XML escaped. |
31 struct UpdateCheckParams { | 31 struct OmahaRequestParams { |
32 UpdateCheckParams() | 32 OmahaRequestParams() |
33 : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {} | 33 : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {} |
34 UpdateCheckParams(const std::string& in_machine_id, | 34 OmahaRequestParams(const std::string& in_machine_id, |
35 const std::string& in_user_id, | 35 const std::string& in_user_id, |
36 const std::string& in_os_platform, | 36 const std::string& in_os_platform, |
37 const std::string& in_os_version, | 37 const std::string& in_os_version, |
38 const std::string& in_os_sp, | 38 const std::string& in_os_sp, |
39 const std::string& in_os_board, | 39 const std::string& in_os_board, |
40 const std::string& in_app_id, | 40 const std::string& in_app_id, |
41 const std::string& in_app_version, | 41 const std::string& in_app_version, |
42 const std::string& in_app_lang, | 42 const std::string& in_app_lang, |
43 const std::string& in_app_track, | 43 const std::string& in_app_track, |
44 const std::string& in_update_url) | 44 const std::string& in_update_url) |
45 : machine_id(in_machine_id), | 45 : machine_id(in_machine_id), |
46 user_id(in_user_id), | 46 user_id(in_user_id), |
47 os_platform(in_os_platform), | 47 os_platform(in_os_platform), |
48 os_version(in_os_version), | 48 os_version(in_os_version), |
49 os_sp(in_os_sp), | 49 os_sp(in_os_sp), |
50 os_board(in_os_board), | 50 os_board(in_os_board), |
51 app_id(in_app_id), | 51 app_id(in_app_id), |
52 app_version(in_app_version), | 52 app_version(in_app_version), |
53 app_lang(in_app_lang), | 53 app_lang(in_app_lang), |
54 app_track(in_app_track), | 54 app_track(in_app_track), |
55 update_url(in_update_url) {} | 55 update_url(in_update_url) {} |
56 | 56 |
57 std::string machine_id; | 57 std::string machine_id; |
58 std::string user_id; | 58 std::string user_id; |
59 std::string os_platform; | 59 std::string os_platform; |
60 std::string os_version; | 60 std::string os_version; |
61 std::string os_sp; | 61 std::string os_sp; |
62 std::string os_board; | 62 std::string os_board; |
63 std::string app_id; | 63 std::string app_id; |
64 std::string app_version; | 64 std::string app_version; |
65 std::string app_lang; | 65 std::string app_lang; |
66 std::string app_track; | 66 std::string app_track; |
67 | 67 |
68 std::string update_url; | 68 std::string update_url; |
69 | 69 |
70 // Suggested defaults | 70 // Suggested defaults |
71 static const char* const kAppId; | 71 static const char* const kAppId; |
72 static const char* const kOsPlatform; | 72 static const char* const kOsPlatform; |
73 static const char* const kOsVersion; | 73 static const char* const kOsVersion; |
74 static const char* const kUpdateUrl; | 74 static const char* const kUpdateUrl; |
75 }; | 75 }; |
76 | 76 |
77 // This struct encapsulates the data Omaha returns for the update check. | 77 // This struct encapsulates the data Omaha's response for the request. |
78 // These strings in this struct are not XML escaped. | 78 // These strings in this struct are not XML escaped. |
79 struct UpdateCheckResponse { | 79 struct OmahaResponse { |
80 UpdateCheckResponse() | 80 OmahaResponse() |
81 : update_exists(false), size(0), needs_admin(false), prompt(false) {} | 81 : update_exists(false), size(0), needs_admin(false), prompt(false) {} |
82 // True iff there is an update to be downloaded. | 82 // True iff there is an update to be downloaded. |
83 bool update_exists; | 83 bool update_exists; |
84 | 84 |
85 // These are only valid if update_exists is true: | 85 // These are only valid if update_exists is true: |
86 std::string display_version; | 86 std::string display_version; |
87 std::string codebase; | 87 std::string codebase; |
88 std::string more_info_url; | 88 std::string more_info_url; |
89 std::string hash; | 89 std::string hash; |
90 off_t size; | 90 off_t size; |
91 bool needs_admin; | 91 bool needs_admin; |
92 bool prompt; | 92 bool prompt; |
93 }; | 93 }; |
94 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit); | 94 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit); |
95 | 95 |
96 class UpdateCheckAction; | 96 class OmahaRequestAction; |
97 class NoneType; | 97 class NoneType; |
98 | 98 |
99 template<> | 99 template<> |
100 class ActionTraits<UpdateCheckAction> { | 100 class ActionTraits<OmahaRequestAction> { |
101 public: | 101 public: |
102 // Takes parameters on the input pipe | 102 // Takes parameters on the input pipe |
103 typedef UpdateCheckParams InputObjectType; | 103 typedef OmahaRequestParams InputObjectType; |
104 // On success, puts the output path on output | 104 // On success, puts the output path on output |
105 typedef UpdateCheckResponse OutputObjectType; | 105 typedef OmahaResponse OutputObjectType; |
106 }; | 106 }; |
107 | 107 |
108 class UpdateCheckAction : public Action<UpdateCheckAction>, | 108 class OmahaRequestAction : public Action<OmahaRequestAction>, |
109 public HttpFetcherDelegate { | 109 public HttpFetcherDelegate { |
110 public: | 110 public: |
111 // The ctor takes in all the parameters that will be used for | 111 // The ctor takes in all the parameters that will be used for |
112 // making the request to Omaha. For some of them we have constants | 112 // making the request to Omaha. For some of them we have constants |
113 // that should be used. | 113 // that should be used. |
114 // Takes ownership of the passed in HttpFetcher. Useful for testing. | 114 // Takes ownership of the passed in HttpFetcher. Useful for testing. |
115 // A good calling pattern is: | 115 // A good calling pattern is: |
116 // UpdateCheckAction(..., new WhateverHttpFetcher); | 116 // OmahaRequestAction(..., new WhateverHttpFetcher); |
117 UpdateCheckAction(HttpFetcher* http_fetcher); | 117 OmahaRequestAction(HttpFetcher* http_fetcher); |
118 virtual ~UpdateCheckAction(); | 118 virtual ~OmahaRequestAction(); |
119 typedef ActionTraits<UpdateCheckAction>::InputObjectType InputObjectType; | 119 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; |
120 typedef ActionTraits<UpdateCheckAction>::OutputObjectType OutputObjectType; | 120 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; |
121 void PerformAction(); | 121 void PerformAction(); |
122 void TerminateProcessing(); | 122 void TerminateProcessing(); |
123 | 123 |
124 // Debugging/logging | 124 // Debugging/logging |
125 static std::string StaticType() { return "UpdateCheckAction"; } | 125 static std::string StaticType() { return "OmahaRequestAction"; } |
126 std::string Type() const { return StaticType(); } | 126 std::string Type() const { return StaticType(); } |
127 | 127 |
128 // Delegate methods (see http_fetcher.h) | 128 // Delegate methods (see http_fetcher.h) |
129 virtual void ReceivedBytes(HttpFetcher *fetcher, | 129 virtual void ReceivedBytes(HttpFetcher *fetcher, |
130 const char* bytes, int length); | 130 const char* bytes, int length); |
131 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); | 131 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); |
132 | 132 |
133 private: | 133 private: |
134 // These are data that are passed in the request to the Omaha server | 134 // These are data that are passed in the request to the Omaha server |
135 UpdateCheckParams params_; | 135 OmahaRequestParams params_; |
136 | 136 |
137 // pointer to the HttpFetcher that does the http work | 137 // pointer to the HttpFetcher that does the http work |
138 scoped_ptr<HttpFetcher> http_fetcher_; | 138 scoped_ptr<HttpFetcher> http_fetcher_; |
139 | 139 |
140 // Stores the response from the omaha server | 140 // Stores the response from the omaha server |
141 std::vector<char> response_buffer_; | 141 std::vector<char> response_buffer_; |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(UpdateCheckAction); | 143 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); |
144 }; | 144 }; |
145 | 145 |
146 } // namespace chromeos_update_engine | 146 } // namespace chromeos_update_engine |
147 | 147 |
148 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_CHECK_ACTION_H__ | 148 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ |
OLD | NEW |