| 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 #ifndef OMAHA_NET_BITS_UTILS_H__ | |
| 17 #define OMAHA_NET_BITS_UTILS_H__ | |
| 18 | |
| 19 #include <windows.h> | |
| 20 #include <bits.h> | |
| 21 #include <atlbase.h> | |
| 22 #include <atlstr.h> | |
| 23 #include <functional> | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 // Gets the instance of BITS manager. | |
| 28 HRESULT GetBitsManager(IBackgroundCopyManager** bits_manager); | |
| 29 | |
| 30 // Compares the local name of a job. | |
| 31 struct JobLocalNameEqual | |
| 32 : public std::binary_function<IBackgroundCopyJob*, const TCHAR*, bool> { | |
| 33 | |
| 34 bool operator()(IBackgroundCopyJob* job, const TCHAR* local_name) const; | |
| 35 }; | |
| 36 | |
| 37 // Compares the display name of a job. | |
| 38 struct JobDisplayNameEqual | |
| 39 : public std::binary_function<IBackgroundCopyJob*, const TCHAR*, bool> { | |
| 40 | |
| 41 bool operator()(IBackgroundCopyJob* job, const TCHAR* local_name) const; | |
| 42 }; | |
| 43 | |
| 44 // Finds a job that matches the given predicate. | |
| 45 // TODO(omaha): do we need to search across all users? | |
| 46 template<class Predicate> | |
| 47 HRESULT FindBitsJobIf(Predicate pred, | |
| 48 IBackgroundCopyManager* bits_manager, | |
| 49 IBackgroundCopyJob** job) { | |
| 50 if (!bits_manager || !job || *job) { | |
| 51 return E_INVALIDARG; | |
| 52 } | |
| 53 | |
| 54 // Enumerate the jobs that belong to the calling user. | |
| 55 CComPtr<IEnumBackgroundCopyJobs> jobs; | |
| 56 HRESULT hr = bits_manager->EnumJobs(0, &jobs); | |
| 57 if (FAILED(hr)) { | |
| 58 return hr; | |
| 59 } | |
| 60 ULONG job_count = 0; | |
| 61 hr = jobs->GetCount(&job_count); | |
| 62 if (FAILED(hr)) { | |
| 63 return hr; | |
| 64 } | |
| 65 for (size_t i = 0; i != job_count; ++i) { | |
| 66 CComPtr<IBackgroundCopyJob> current_job; | |
| 67 if (jobs->Next(1, ¤t_job, NULL) != S_OK) { | |
| 68 break; | |
| 69 } | |
| 70 if (pred(current_job)) { | |
| 71 *job = current_job.Detach(); | |
| 72 return S_OK; | |
| 73 } | |
| 74 } | |
| 75 return E_FAIL; | |
| 76 } | |
| 77 | |
| 78 // Sets using the implicit credentials to authenticate to proxy servers. | |
| 79 HRESULT SetProxyAuthImplicitCredentials(IBackgroundCopyJob* job, | |
| 80 BG_AUTH_SCHEME auth_scheme); | |
| 81 | |
| 82 // Sets credentials to authenticate to proxy servers. username and password can | |
| 83 // be NULL, in which case BITS will try connecting with implicit/autologon | |
| 84 // credentials. | |
| 85 HRESULT SetProxyAuthCredentials(IBackgroundCopyJob* job, | |
| 86 TCHAR* username, | |
| 87 TCHAR* password, | |
| 88 BG_AUTH_SCHEME auth_scheme); | |
| 89 | |
| 90 // Returns an HTTP status code from the BITS error code. | |
| 91 int GetHttpStatusFromBitsError(HRESULT error); | |
| 92 | |
| 93 // Cancels a job. | |
| 94 HRESULT CancelBitsJob(IBackgroundCopyJob* job); | |
| 95 | |
| 96 HRESULT PauseBitsJob(IBackgroundCopyJob* job); | |
| 97 | |
| 98 HRESULT ResumeBitsJob(IBackgroundCopyJob* job); | |
| 99 | |
| 100 // Converts a job state to a string. | |
| 101 CString JobStateToString(BG_JOB_STATE job_state); | |
| 102 | |
| 103 // Converts a BITS auth scheme to a string. | |
| 104 CString BitsAuthSchemeToString(int auth_scheme); | |
| 105 | |
| 106 } // namespace omaha | |
| 107 | |
| 108 #endif // OMAHA_NET_BITS_UTILS_H__ | |
| 109 | |
| OLD | NEW |