1 | /* $Id: CloudUserProfileListImpl.cpp 73167 2018-07-17 07:41:21Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ICloudUserProfileList COM class implementations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | #include <iprt/path.h>
|
---|
20 | #include <iprt/cpp/utils.h>
|
---|
21 | #include <VBox/com/array.h>
|
---|
22 |
|
---|
23 | #include "CloudUserProfileListImpl.h"
|
---|
24 | #include "VirtualBoxImpl.h"
|
---|
25 | #include "Global.h"
|
---|
26 | #include "ProgressImpl.h"
|
---|
27 | #include "MachineImpl.h"
|
---|
28 | #include "AutoCaller.h"
|
---|
29 | #include "Logging.h"
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 |
|
---|
33 | ////////////////////////////////////////////////////////////////////////////////
|
---|
34 | //
|
---|
35 | // SimpleConfigFile implementation
|
---|
36 | //
|
---|
37 | ////////////////////////////////////////////////////////////////////////////////
|
---|
38 | SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError, const char *pszFilename)
|
---|
39 | : GeneralTextScript(pSetError, pszFilename)
|
---|
40 | {
|
---|
41 | LogRel(("SimpleConfigFile::SimpleConfigFile(VirtualBoxBase *pSetError,...)\n"));
|
---|
42 | }
|
---|
43 |
|
---|
44 | SimpleConfigFile::~SimpleConfigFile()
|
---|
45 | {
|
---|
46 | LogRel(("SimpleConfigFile::~SimpleConfigFile()\n"));
|
---|
47 | }
|
---|
48 |
|
---|
49 | HRESULT SimpleConfigFile::parse()
|
---|
50 | {
|
---|
51 | LogRel(("Starting to parse the existing profiles\n"));
|
---|
52 | HRESULT hrc = S_OK;
|
---|
53 | hrc = GeneralTextScript::parse();
|
---|
54 | if (SUCCEEDED(hrc))
|
---|
55 | {
|
---|
56 | size_t lines = getLineNumbersOfScript();
|
---|
57 | LogRel(("Initial parsing (GeneralTextScript::parse()) was succeeded \n"));
|
---|
58 | LogRel(("Read lines is %d \n", lines));
|
---|
59 | size_t startSectionPos=0;
|
---|
60 | bool fInSection = false;
|
---|
61 | std::map <Utf8Str, Utf8Str> sectionConfiguration;
|
---|
62 | Utf8Str strSectionName("Default section ");
|
---|
63 |
|
---|
64 | for (size_t i=0; i<lines; ++i)
|
---|
65 | {
|
---|
66 | //find the beginning of section, it starts from the line like "[section name]"
|
---|
67 | //next find the end of section, it ends up when we find the beginning
|
---|
68 | //of the next section or reach the end of the contents.
|
---|
69 | //Go through the found lines and split each of them up by "=".
|
---|
70 | //Each correct line must look like "key=value"
|
---|
71 | //if there is not the character "=" in the line one is skipped
|
---|
72 | //class Utf8Str contains the function parseKeyValue() for this action
|
---|
73 | LogRel(("Parsing the line %d \n", i));
|
---|
74 | Utf8Str strLineContent = getContentOfLine(i);
|
---|
75 | if (strLineContent.isEmpty() || strLineContent.startsWith("#"))
|
---|
76 | continue;
|
---|
77 |
|
---|
78 | LogRel(("Content of the line %d is %s \n", i, strLineContent.c_str()));
|
---|
79 |
|
---|
80 | if ( strLineContent.startsWith("[") && strLineContent.endsWith("]") )
|
---|
81 | {
|
---|
82 | LogRel(("Found section in the line %d\n", i));
|
---|
83 | if ( fInSection == true )
|
---|
84 | {
|
---|
85 | if ( i > startSectionPos )//at least we can have here 1 line in the section
|
---|
86 | {
|
---|
87 | LogRel(("Add section \"%s\" to the map \n", strSectionName.c_str()));
|
---|
88 | mSections.insert(make_pair(strSectionName, sectionConfiguration));
|
---|
89 | sectionConfiguration.clear();
|
---|
90 | strSectionName.append(Utf8StrFmt("%d",i).c_str());
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | strSectionName = strLineContent.substr(strLineContent.find("[")+1,
|
---|
95 | strLineContent.find("]")-1);
|
---|
96 | LogRel(("Section name is \"%s\" \n", strSectionName.c_str()));
|
---|
97 | fInSection = true;
|
---|
98 | startSectionPos = i+1;
|
---|
99 | }
|
---|
100 | else
|
---|
101 | {
|
---|
102 | if ( fInSection == true )
|
---|
103 | {
|
---|
104 | LogRel(("Continue to parse section \"%s\" \n", strSectionName.c_str()));
|
---|
105 | if ( i >= startSectionPos )
|
---|
106 | {
|
---|
107 | LogRel(("Extracting key and value:\n"));
|
---|
108 | Utf8Str key, value;
|
---|
109 | size_t offEnd = strLineContent.parseKeyValue(key, value);
|
---|
110 | if (offEnd == strLineContent.length())
|
---|
111 | {
|
---|
112 | LogRel(("%s=%s \n", key.c_str(), value.c_str()));
|
---|
113 | sectionConfiguration.insert(make_pair(key,value));
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | //else something goes wrong, skip the line
|
---|
118 | LogRel(("Coudn't extract key and value from the line %d\n", i));
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else
|
---|
123 | {
|
---|
124 | LogRel(("Goes to the next line %d\n", i+1));
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (fInSection == false)//there is not any section
|
---|
130 | {
|
---|
131 | LogRel(("There are not any sections in the config\n"));
|
---|
132 | hrc = VWRN_NOT_FOUND;
|
---|
133 | }
|
---|
134 | else //the last section hasn't a close tag (the close tag is just the beginning of next section)
|
---|
135 | {
|
---|
136 | //just insert the last section into the map
|
---|
137 | LogRel(("Add the last section %s to the map \n", strSectionName.c_str()));
|
---|
138 | mSections.insert(make_pair(strSectionName, sectionConfiguration));
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | return hrc;
|
---|
143 | }
|
---|
144 |
|
---|
145 | HRESULT SimpleConfigFile::addSection(const Utf8Str &aSectionName, const std::map <Utf8Str, Utf8Str>& section)
|
---|
146 | {
|
---|
147 | HRESULT hrc = S_OK;
|
---|
148 | if (aSectionName.isEmpty())
|
---|
149 | hrc = VERR_INVALID_PARAMETER;
|
---|
150 | else
|
---|
151 | mSections.insert(make_pair(aSectionName, section));
|
---|
152 |
|
---|
153 | return hrc;
|
---|
154 | }
|
---|
155 |
|
---|
156 | std::vector <Utf8Str> SimpleConfigFile::getSectionsNames() const
|
---|
157 | {
|
---|
158 | std::vector <Utf8Str> res;
|
---|
159 | std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit = mSections.begin();
|
---|
160 | while (cit!=mSections.end())
|
---|
161 | {
|
---|
162 | res.push_back(cit->first);
|
---|
163 | ++cit;
|
---|
164 | }
|
---|
165 | return res;
|
---|
166 | }
|
---|
167 |
|
---|
168 | std::map <Utf8Str, Utf8Str> SimpleConfigFile::getSectionByName (const Utf8Str &strSectionName) const
|
---|
169 | {
|
---|
170 | std::map <Utf8Str, Utf8Str> res;
|
---|
171 | std::map < Utf8Str, std::map <Utf8Str, Utf8Str> >::const_iterator cit;
|
---|
172 | if ( (cit=mSections.find(strSectionName)) != mSections.end() )
|
---|
173 | {
|
---|
174 | res=cit->second;
|
---|
175 | }
|
---|
176 | return res;
|
---|
177 | }
|
---|
178 |
|
---|
179 | HRESULT SimpleConfigFile::updateSection (const Utf8Str &strSectionName,
|
---|
180 | const std::map <Utf8Str, Utf8Str> &newSection)
|
---|
181 | {
|
---|
182 | HRESULT hrc = S_OK;
|
---|
183 | std::map <Utf8Str, Utf8Str> oldSection = getSectionByName(strSectionName);
|
---|
184 | if (oldSection.empty())
|
---|
185 | {
|
---|
186 | //add new section
|
---|
187 | hrc = addSection(strSectionName, newSection);
|
---|
188 | }
|
---|
189 | else
|
---|
190 | {
|
---|
191 | //update old section by new values or add new pair key/value if there isn't such key
|
---|
192 | std::map <Utf8Str, Utf8Str>::const_iterator cit = newSection.begin();
|
---|
193 | while (cit != newSection.end())
|
---|
194 | {
|
---|
195 | oldSection[cit->first] = cit->second;
|
---|
196 | ++cit;
|
---|
197 | }
|
---|
198 |
|
---|
199 | }
|
---|
200 | return hrc;
|
---|
201 | }
|
---|
202 |
|
---|
203 | bool SimpleConfigFile::isSectionExist(const Utf8Str &strSectionName) const
|
---|
204 | {
|
---|
205 | return ((mSections.find(strSectionName) == mSections.end()) ? false : true);
|
---|
206 | }
|
---|
207 |
|
---|
208 | ////////////////////////////////////////////////////////////////////////////////
|
---|
209 | //
|
---|
210 | // ICloudUserProfileList implementation
|
---|
211 | //
|
---|
212 | ////////////////////////////////////////////////////////////////////////////////
|
---|
213 | CloudUserProfileList::CloudUserProfileList()
|
---|
214 | : mParent(NULL)
|
---|
215 | {
|
---|
216 | }
|
---|
217 |
|
---|
218 | CloudUserProfileList::~CloudUserProfileList()
|
---|
219 | {
|
---|
220 | LogRel(("CloudUserProfileListImpl::~CloudUserProfileListImpl()\n"));
|
---|
221 | unconst(mParent) = NULL;
|
---|
222 | }
|
---|
223 |
|
---|
224 | HRESULT CloudUserProfileList::FinalConstruct()
|
---|
225 | {
|
---|
226 | return BaseFinalConstruct();
|
---|
227 | }
|
---|
228 |
|
---|
229 | void CloudUserProfileList::FinalRelease()
|
---|
230 | {
|
---|
231 | uninit();
|
---|
232 |
|
---|
233 | BaseFinalRelease();
|
---|
234 | }
|
---|
235 |
|
---|
236 | void CloudUserProfileList::uninit()
|
---|
237 | {
|
---|
238 |
|
---|
239 | }
|
---|
240 |
|
---|
241 | HRESULT CloudUserProfileList::init(VirtualBox *aParent)
|
---|
242 | {
|
---|
243 | unconst(mParent) = aParent;
|
---|
244 |
|
---|
245 | return S_OK;
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | HRESULT CloudUserProfileList::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames)
|
---|
250 | {
|
---|
251 | LogRel(("CloudUserProfileList::getSupportedPropertiesNames:\n"));
|
---|
252 | aPropertiesNames.clear();
|
---|
253 | return VERR_NOT_IMPLEMENTED;
|
---|
254 | }
|
---|
255 |
|
---|
256 | HRESULT CloudUserProfileList::readProfiles(const Utf8Str &strConfigPath)
|
---|
257 | {
|
---|
258 | LogRel(("CloudUserProfileList::readProfiles: %s\n", strConfigPath.c_str()));
|
---|
259 | return VERR_NOT_IMPLEMENTED;
|
---|
260 | }
|
---|
261 |
|
---|
262 | HRESULT CloudUserProfileList::getProvider(CloudProviderId_T *aProvider)
|
---|
263 | {
|
---|
264 | *aProvider = CloudProviderId_Unknown;
|
---|
265 | LogRel(("CloudUserProfileList::getProvider: %d\n", *aProvider));
|
---|
266 | return VERR_NOT_IMPLEMENTED;
|
---|
267 | }
|
---|
268 |
|
---|
269 | HRESULT CloudUserProfileList::createProfile(const com::Utf8Str &aProfileName,
|
---|
270 | const std::vector<com::Utf8Str> &aNames,
|
---|
271 | const std::vector<com::Utf8Str> &aValues)
|
---|
272 | {
|
---|
273 | LogRel(("CloudUserProfileList::createProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size()));
|
---|
274 | return VERR_NOT_IMPLEMENTED;
|
---|
275 | }
|
---|
276 |
|
---|
277 | HRESULT CloudUserProfileList::updateProfile(const com::Utf8Str &aProfileName,
|
---|
278 | const std::vector<com::Utf8Str> &aNames,
|
---|
279 | const std::vector<com::Utf8Str> &aValues)
|
---|
280 | {
|
---|
281 | LogRel(("CloudUserProfileList::updateProfile: %s, %d, %d\n", aProfileName.c_str(), aNames.size(), aValues.size()));
|
---|
282 | return VERR_NOT_IMPLEMENTED;
|
---|
283 | }
|
---|
284 |
|
---|
285 | HRESULT CloudUserProfileList::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames)
|
---|
286 | {
|
---|
287 |
|
---|
288 | LogRel(("CloudUserProfileList::getStoredProfilesNames:\n"));
|
---|
289 | aProfilesNames.clear();
|
---|
290 | return VERR_NOT_IMPLEMENTED;
|
---|
291 | }
|
---|
292 |
|
---|
293 | HRESULT CloudUserProfileList::getProfileProperties(const com::Utf8Str &aProfileName,
|
---|
294 | std::vector<com::Utf8Str> &aReturnNames,
|
---|
295 | std::vector<com::Utf8Str> &aReturnValues)
|
---|
296 | {
|
---|
297 | LogRel(("CloudUserProfileList::getProfileProperties: %s\n", aProfileName.c_str()));
|
---|
298 | aReturnNames.clear();
|
---|
299 | aReturnValues.clear();
|
---|
300 | return VERR_NOT_IMPLEMENTED;
|
---|
301 | }
|
---|
302 |
|
---|
303 | HRESULT CloudUserProfileList::getPropertyDescription(const com::Utf8Str &aName,
|
---|
304 | com::Utf8Str &aDescription)
|
---|
305 | {
|
---|
306 | LogRel(("CloudUserProfileList::getPropertyDescription: %s, %s\n", aName.c_str(), aDescription.c_str()));
|
---|
307 | return VERR_NOT_IMPLEMENTED;
|
---|
308 | }
|
---|
309 |
|
---|
310 | HRESULT CloudUserProfileList::createCloudClient(const com::Utf8Str &aProfileName,
|
---|
311 | ComPtr<ICloudClient> &aCloudClient)
|
---|
312 | {
|
---|
313 | LogRel(("CloudUserProfileList::createCloudClient: %s\n", aProfileName.c_str()));
|
---|
314 |
|
---|
315 | if (aCloudClient.isNull())
|
---|
316 | {
|
---|
317 | LogRel(("aCloudClient is NULL\n"));
|
---|
318 | }
|
---|
319 |
|
---|
320 | return VERR_NOT_IMPLEMENTED;
|
---|
321 | }
|
---|
322 |
|
---|
323 | ////////////////////////////////////////////////////////////////////////////////
|
---|
324 | //
|
---|
325 | // CloudConnectionOCI implementation
|
---|
326 | //
|
---|
327 | ////////////////////////////////////////////////////////////////////////////////
|
---|
328 | static struct
|
---|
329 | {
|
---|
330 | const char *pszOCIConfigEntry, *pszDesciption;
|
---|
331 | } const g_aOCIConfigEntryToDescription[] =
|
---|
332 | {
|
---|
333 | { "user", "OCID of the user calling the API." },
|
---|
334 | { "tenancy", "OCID of your tenancy." },
|
---|
335 | { "compartment", "OCID of your compartment." },
|
---|
336 | { "fingerprint", "Fingerprint for the key pair being used." },
|
---|
337 | { "key_file", "Full path and filename of the private key."
|
---|
338 | "If you encrypted the key with a passphrase, you must also include "
|
---|
339 | "the pass_phrase entry in the config file."},
|
---|
340 | { "pass_phrase", "Passphrase used for the key, if it is encrypted." },
|
---|
341 | { "region", "An Oracle Cloud Infrastructure region" },
|
---|
342 | };
|
---|
343 |
|
---|
344 |
|
---|
345 | OCIUserProfileList::OCIUserProfileList()
|
---|
346 | {
|
---|
347 | LogRel(("OCIUserProfileList::OCIUserProfileList()\n"));
|
---|
348 | mpProfiles = new SimpleConfigFile(mParent);
|
---|
349 | LogRel(("Succeeded create SimpleConfigFile\n"));
|
---|
350 | }
|
---|
351 |
|
---|
352 | OCIUserProfileList::~OCIUserProfileList()
|
---|
353 | {
|
---|
354 | LogRel(("OCIUserProfileList::~OCIUserProfileList()\n"));
|
---|
355 | if (mpProfiles)
|
---|
356 | delete mpProfiles;
|
---|
357 | }
|
---|
358 |
|
---|
359 | HRESULT OCIUserProfileList::createCloudClient(const com::Utf8Str &aProfileName,
|
---|
360 | ComPtr<ICloudClient> &aCloudClient)
|
---|
361 | {
|
---|
362 | CloudProviderId_T providerId;
|
---|
363 | HRESULT hrc = getProvider(&providerId);
|
---|
364 |
|
---|
365 | ComObjPtr<CloudClient> ptrCloudClient;
|
---|
366 | hrc = ptrCloudClient.createObject();
|
---|
367 | if (SUCCEEDED(hrc))
|
---|
368 | {
|
---|
369 | ComObjPtr<CloudClientOCI> ptrCloudClientOCI;
|
---|
370 | hrc = ptrCloudClientOCI.createObject();
|
---|
371 | AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
|
---|
372 | hrc = ptrCloudClientOCI->initCloudClient(this, mParent, providerId, aProfileName);
|
---|
373 | if (SUCCEEDED(hrc))
|
---|
374 | {
|
---|
375 | ptrCloudClient = ptrCloudClientOCI;
|
---|
376 | hrc = ptrCloudClient.queryInterfaceTo(aCloudClient.asOutParam());
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | return hrc;
|
---|
381 | }
|
---|
382 |
|
---|
383 | HRESULT OCIUserProfileList::readProfiles(const Utf8Str &strConfigPath)
|
---|
384 | {
|
---|
385 | LogRel(("Reading profiles from %s\n", strConfigPath.c_str()));
|
---|
386 | HRESULT hrc = S_OK;
|
---|
387 | if ( !strConfigPath.isEmpty() )
|
---|
388 | {
|
---|
389 | mStrConfigPath = strConfigPath;
|
---|
390 | hrc = mpProfiles->read(mStrConfigPath);
|
---|
391 | if (SUCCEEDED(hrc))
|
---|
392 | {
|
---|
393 | LogRel(("Successfully read the profiles from the config %s\n", mStrConfigPath.c_str()));
|
---|
394 | hrc = mpProfiles->parse();
|
---|
395 | if (FAILED(hrc))
|
---|
396 | {
|
---|
397 | throw hrc;
|
---|
398 | }
|
---|
399 | LogRel(("Successfully parsed %d profiles\n", mpProfiles->getNumberOfSections()));
|
---|
400 | }
|
---|
401 | }
|
---|
402 | else
|
---|
403 | {
|
---|
404 | LogRel(("Empty path to config file\n"));
|
---|
405 | hrc = VERR_INVALID_PARAMETER;
|
---|
406 | }
|
---|
407 |
|
---|
408 | return hrc;
|
---|
409 | }
|
---|
410 |
|
---|
411 | HRESULT OCIUserProfileList::createProfile(const com::Utf8Str &aProfileName,
|
---|
412 | const std::vector<com::Utf8Str> &aNames,
|
---|
413 | const std::vector<com::Utf8Str> &aValues)
|
---|
414 | {
|
---|
415 | HRESULT hrc = S_OK;
|
---|
416 |
|
---|
417 | if (!mpProfiles->isSectionExist(aProfileName))
|
---|
418 | {
|
---|
419 | std::map <Utf8Str, Utf8Str> newProfile;
|
---|
420 |
|
---|
421 | for (size_t i=0;i<aNames.size();++i)
|
---|
422 | {
|
---|
423 | com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : "";
|
---|
424 | newProfile[aNames.at(i)] = newValue;
|
---|
425 | }
|
---|
426 |
|
---|
427 | hrc = mpProfiles->addSection(aProfileName, newProfile);
|
---|
428 | }
|
---|
429 | else
|
---|
430 | hrc = VERR_ALREADY_EXISTS;
|
---|
431 |
|
---|
432 | return hrc;
|
---|
433 | }
|
---|
434 |
|
---|
435 | HRESULT OCIUserProfileList::updateProfile(const com::Utf8Str &aProfileName,
|
---|
436 | const std::vector<com::Utf8Str> &aNames,
|
---|
437 | const std::vector<com::Utf8Str> &aValues)
|
---|
438 | {
|
---|
439 | HRESULT hrc = S_OK;
|
---|
440 | if (mpProfiles->isSectionExist(aProfileName))
|
---|
441 | {
|
---|
442 | std::map <Utf8Str, Utf8Str> newProfile;
|
---|
443 |
|
---|
444 | for (size_t i=0;i<aNames.size();++i)
|
---|
445 | {
|
---|
446 | com::Utf8Str newValue = (i<aValues.size()) ? aValues.at(i) : "";
|
---|
447 | newProfile[aNames.at(i)] = newValue;
|
---|
448 | }
|
---|
449 |
|
---|
450 | hrc = mpProfiles->updateSection(aProfileName, newProfile);
|
---|
451 | }
|
---|
452 | else
|
---|
453 | hrc = VERR_NOT_FOUND;
|
---|
454 |
|
---|
455 | return hrc;
|
---|
456 | }
|
---|
457 |
|
---|
458 | HRESULT OCIUserProfileList::getStoredProfilesNames(std::vector<com::Utf8Str> &aProfilesNames)
|
---|
459 | {
|
---|
460 | HRESULT hrc = S_OK;
|
---|
461 | aProfilesNames = mpProfiles->getSectionsNames();
|
---|
462 | if (aProfilesNames.empty())
|
---|
463 | hrc = VERR_NOT_FOUND;
|
---|
464 |
|
---|
465 | return hrc;
|
---|
466 | }
|
---|
467 |
|
---|
468 | HRESULT OCIUserProfileList::getProfileProperties(const com::Utf8Str &aProfileName,
|
---|
469 | std::vector<com::Utf8Str> &aReturnNames,
|
---|
470 | std::vector<com::Utf8Str> &aReturnValues)
|
---|
471 | {
|
---|
472 | HRESULT hrc = S_OK;
|
---|
473 |
|
---|
474 | if (mpProfiles->isSectionExist(aProfileName))
|
---|
475 | {
|
---|
476 | std::map <Utf8Str, Utf8Str> profile;
|
---|
477 | hrc = getProfileProperties(aProfileName, profile);
|
---|
478 | if (SUCCEEDED(hrc))
|
---|
479 | {
|
---|
480 | aReturnNames.clear();
|
---|
481 | aReturnValues.clear();
|
---|
482 | std::map <Utf8Str, Utf8Str>::const_iterator cit = profile.begin();
|
---|
483 | while (cit!=profile.end())
|
---|
484 | {
|
---|
485 | aReturnNames.push_back(cit->first);
|
---|
486 | aReturnValues.push_back(cit->second);
|
---|
487 | }
|
---|
488 | }
|
---|
489 | }
|
---|
490 | else
|
---|
491 | hrc = VERR_NOT_FOUND;
|
---|
492 |
|
---|
493 | return hrc;
|
---|
494 | }
|
---|
495 |
|
---|
496 | HRESULT OCIUserProfileList::getSupportedPropertiesNames(std::vector<com::Utf8Str> &aPropertiesNames)
|
---|
497 | {
|
---|
498 | HRESULT hrc = S_OK;
|
---|
499 | for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
|
---|
500 | aPropertiesNames.push_back(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry);
|
---|
501 | return hrc;
|
---|
502 | }
|
---|
503 |
|
---|
504 | HRESULT OCIUserProfileList::getPropertyDescription(const com::Utf8Str &aName, com::Utf8Str &aDescription)
|
---|
505 | {
|
---|
506 | HRESULT hrc = S_OK;
|
---|
507 | for (size_t i = 0; i < RT_ELEMENTS(g_aOCIConfigEntryToDescription); ++i)
|
---|
508 | if (aName.contains(g_aOCIConfigEntryToDescription[i].pszOCIConfigEntry, Utf8Str::CaseInsensitive))
|
---|
509 | {
|
---|
510 | aDescription = g_aOCIConfigEntryToDescription[i].pszDesciption;
|
---|
511 | }
|
---|
512 | return hrc;
|
---|
513 | }
|
---|
514 |
|
---|
515 |
|
---|
516 | HRESULT OCIUserProfileList::createProfile(const com::Utf8Str &aProfileName,
|
---|
517 | const std::map <Utf8Str, Utf8Str> &aProfile)
|
---|
518 | {
|
---|
519 | HRESULT hrc = S_OK;
|
---|
520 |
|
---|
521 | hrc = mpProfiles->addSection(aProfileName, aProfile);
|
---|
522 |
|
---|
523 | return hrc;
|
---|
524 | }
|
---|
525 |
|
---|
526 | HRESULT OCIUserProfileList::updateProfile(const com::Utf8Str &aProfileName,
|
---|
527 | const std::map <Utf8Str, Utf8Str> &aProfile)
|
---|
528 | {
|
---|
529 | HRESULT hrc = S_OK;
|
---|
530 | if (mpProfiles->isSectionExist(aProfileName))
|
---|
531 | hrc = mpProfiles->updateSection(aProfileName, aProfile);
|
---|
532 | else
|
---|
533 | hrc = VERR_NOT_FOUND;
|
---|
534 |
|
---|
535 | return hrc;
|
---|
536 | }
|
---|
537 |
|
---|
538 | HRESULT OCIUserProfileList::getProfileProperties(const com::Utf8Str &aProfileName,
|
---|
539 | std::map <Utf8Str, Utf8Str> &aProfile)
|
---|
540 | {
|
---|
541 | HRESULT hrc = S_OK;
|
---|
542 | std::map <Utf8Str, Utf8Str> defProfile = mpProfiles->getSectionByName("DEFAULT");
|
---|
543 | std::map <Utf8Str, Utf8Str> reqProfile = mpProfiles->getSectionByName(aProfileName);
|
---|
544 |
|
---|
545 | std::map <Utf8Str, Utf8Str>::iterator itDefProfile = defProfile.begin();
|
---|
546 | while (itDefProfile != defProfile.end())
|
---|
547 | {
|
---|
548 | std::map <Utf8Str, Utf8Str>::iterator itProfile = reqProfile.find(itDefProfile->first);
|
---|
549 | if (itProfile == reqProfile.end())
|
---|
550 | {
|
---|
551 | //Add a key=value pair from defProfile into the reqProfile if the key doesn't exist in the reqProfile.
|
---|
552 | reqProfile.insert(*itDefProfile);
|
---|
553 | }
|
---|
554 | ++itDefProfile;
|
---|
555 | }
|
---|
556 |
|
---|
557 | if (!reqProfile.empty())
|
---|
558 | aProfile = reqProfile;
|
---|
559 | else
|
---|
560 | hrc = VERR_NOT_FOUND;
|
---|
561 |
|
---|
562 | return hrc;
|
---|
563 | }
|
---|
564 |
|
---|