1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/CredentialFileReader.cc
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/InputStream.h"
16 #include "zypp/parser/IniDict.h"
18 #include "zypp/media/CredentialFileReader.h"
22 #undef ZYPP_BASE_LOGGER_LOGGROUP
23 #define ZYPP_BASE_LOGGER_LOGGROUP "parser"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////
36 // CLASS NAME : CredentialFileReader
38 //////////////////////////////////////////////////////////////////////
40 CredentialFileReader::CredentialFileReader(
41 const Pathname & crfile,
42 const ProcessCredentials & callback)
44 InputStream is(crfile);
45 parser::IniDict dict(is);
46 for (parser::IniDict::section_const_iterator its = dict.sectionsBegin();
47 its != dict.sectionsEnd();
53 try { storedUrl = Url(*its); }
54 catch (const url::UrlException &)
56 ERR << "invalid URL '" << *its << "' in credentials in file: "
62 AuthData_Ptr credentials;
63 credentials.reset(new AuthData());
66 if (storedUrl.isValid())
67 credentials->setUrl(storedUrl);
69 for (parser::IniDict::entry_const_iterator it = dict.entriesBegin(*its);
70 it != dict.entriesEnd(*its);
73 if (it->first == "username")
74 credentials->setUsername(it->second);
75 else if (it->first == "password")
76 credentials->setPassword(it->second);
78 ERR << "Unknown attribute in [" << crfile << "]: "
79 << it->second << " ignored" << endl;
82 if (credentials->valid())
83 callback(credentials);
85 ERR << "invalid credentials in file: " << crfile << endl;
90 CredentialFileReader::~CredentialFileReader()
94 /////////////////////////////////////////////////////////////////
96 ///////////////////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////