1 /* 2 * Copyright (C) 2019 Red Hat, Inc. 3 * 4 * Licensed under the GNU Lesser General Public License Version 2.1 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #ifndef _OS_RELEASE_HPP_ 22 #define _OS_RELEASE_HPP_ 23 24 #include <map> 25 #include <string> 26 #include <vector> 27 28 #define USER_AGENT "libdnf" 29 30 namespace libdnf { 31 32 /** 33 * @brief Parse the os-release file and return its contents in a map. 34 * 35 * The file /etc/os-release takes precedence over /usr/lib/os-release which 36 * acts as a fallback should the former not exist (see os-release(5) for 37 * details). 38 * 39 * @return a map containing os-release data 40 */ 41 std::map<std::string, std::string> 42 getOsReleaseData(); 43 44 /** 45 * @brief Construct and return the User-Agent string for libdnf to send in HTTP 46 * headers. 47 * 48 * The format returned is as follows: 49 * 50 * libdnf (NAME VERSION_ID; VARIANT_ID; OS.BASEARCH) 51 * 52 * where NAME, VERSION_ID and VARIANT_ID are OS identifiers read from the 53 * passed os-release data, and OS and BASEARCH are the canonical OS name and 54 * base architecture, respectively, detected using RPM. 55 * 56 * @param osReleaseData a map containing os-release data (will be loaded from 57 * disk if not specified) 58 * @return a User-Agent string 59 */ 60 std::string 61 getUserAgent(const std::map<std::string, std::string> & osReleaseData); 62 std::string 63 getUserAgent(); 64 65 } 66 67 #endif 68