libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 00014 #include "zypp/base/Logger.h" 00015 #include "zypp/base/InputStream.h" 00016 #include "zypp/parser/IniDict.h" 00017 00018 #include "zypp/media/CredentialFileReader.h" 00019 00020 using std::endl; 00021 00022 #undef ZYPP_BASE_LOGGER_LOGGROUP 00023 #define ZYPP_BASE_LOGGER_LOGGROUP "parser" 00024 00025 00027 namespace zypp 00028 { 00029 00030 namespace media 00031 { 00032 00033 00035 // 00036 // CLASS NAME : CredentialFileReader 00037 // 00039 00040 CredentialFileReader::CredentialFileReader( 00041 const Pathname & crfile, 00042 const ProcessCredentials & callback) 00043 { 00044 InputStream is(crfile); 00045 parser::IniDict dict(is); 00046 for (parser::IniDict::section_const_iterator its = dict.sectionsBegin(); 00047 its != dict.sectionsEnd(); 00048 ++its) 00049 { 00050 Url storedUrl; 00051 if (!its->empty()) 00052 { 00053 try { storedUrl = Url(*its); } 00054 catch (const url::UrlException &) 00055 { 00056 ERR << "invalid URL '" << *its << "' in credentials in file: " 00057 << crfile << endl; 00058 continue; 00059 } 00060 } 00061 00062 AuthData_Ptr credentials; 00063 credentials.reset(new AuthData()); 00064 00065 // set url 00066 if (storedUrl.isValid()) 00067 credentials->setUrl(storedUrl); 00068 00069 for (parser::IniDict::entry_const_iterator it = dict.entriesBegin(*its); 00070 it != dict.entriesEnd(*its); 00071 ++it) 00072 { 00073 if (it->first == "username") 00074 credentials->setUsername(it->second); 00075 else if (it->first == "password") 00076 credentials->setPassword(it->second); 00077 else 00078 ERR << "Unknown attribute in [" << crfile << "]: " 00079 << it->second << " ignored" << endl; 00080 } 00081 00082 if (credentials->valid()) 00083 callback(credentials); 00084 else 00085 ERR << "invalid credentials in file: " << crfile << endl; 00086 } // sections 00087 } 00088 00089 00090 CredentialFileReader::~CredentialFileReader() 00091 {} 00092 00093 00095 } // media 00098 } // zypp 00100