Blame SOURCES/satyr-0.13-os-add-support-for-OS-Variant.patch

f41043
From 20cafc9b23448aaab4fd8f07a5a1defd0cd7038a Mon Sep 17 00:00:00 2001
f41043
From: Jakub Filak <jfilak@redhat.com>
f41043
Date: Tue, 1 Sep 2015 13:05:48 +0200
f41043
Subject: [PATCH] os: add support for OS Variant
f41043
f41043
VARIANT= and VARIANT_ID= fields are optional.
f41043
f41043
http://www.freedesktop.org/software/systemd/man/os-release.html
f41043
f41043
Related to abrt/abrt#995
f41043
Resolves: #1342469
f41043
f41043
Signed-off-by: Jakub Filak <jfilak@redhat.com>
f41043
f41043
Conflicts:
f41043
	include/operating_system.h
f41043
	lib/operating_system.c
f41043
---
f41043
 include/operating_system.h |  1 +
f41043
 lib/operating_system.c     | 16 ++++++++++++++++
f41043
 tests/operating_system.at  | 43 +++++++++++++++++++++++++++++++++++++++----
f41043
 3 files changed, 56 insertions(+), 4 deletions(-)
f41043
f41043
diff --git a/include/operating_system.h b/include/operating_system.h
f41043
index f26e322..84fcce0 100644
f41043
--- a/include/operating_system.h
f41043
+++ b/include/operating_system.h
f41043
@@ -37,6 +37,7 @@ struct sr_operating_system
f41043
     char *cpe;
f41043
     /* Uptime in seconds. */
f41043
     uint64_t uptime;
f41043
+    char *variant;
f41043
 };
f41043
 
f41043
 struct sr_operating_system *
f41043
diff --git a/lib/operating_system.c b/lib/operating_system.c
f41043
index 64f7439..9bebe5b 100644
f41043
--- a/lib/operating_system.c
f41043
+++ b/lib/operating_system.c
f41043
@@ -43,6 +43,7 @@ sr_operating_system_init(struct sr_operating_system *operating_system)
f41043
     operating_system->version = NULL;
f41043
     operating_system->architecture = NULL;
f41043
     operating_system->cpe = NULL;
f41043
+    operating_system->variant = NULL;
f41043
     operating_system->uptime = 0;
f41043
 }
f41043
 
f41043
@@ -56,6 +57,7 @@ sr_operating_system_free(struct sr_operating_system *operating_system)
f41043
     free(operating_system->version);
f41043
     free(operating_system->architecture);
f41043
     free(operating_system->cpe);
f41043
+    free(operating_system->variant);
f41043
     free(operating_system);
f41043
 }
f41043
 
f41043
@@ -92,6 +94,13 @@ sr_operating_system_to_json(struct sr_operating_system *operating_system)
f41043
         sr_strbuf_append_str(strbuf, "\n");
f41043
     }
f41043
 
f41043
+    if (operating_system->variant)
f41043
+    {
f41043
+        sr_strbuf_append_str(strbuf, ",   \"variant\": ");
f41043
+        sr_json_append_escaped(strbuf, operating_system->variant);
f41043
+        sr_strbuf_append_str(strbuf, "\n");
f41043
+    }
f41043
+
f41043
     if (operating_system->uptime > 0)
f41043
     {
f41043
         sr_strbuf_append_strf(strbuf,
f41043
@@ -122,6 +131,9 @@ sr_operating_system_from_json(struct sr_json_value *root, char **error_message)
f41043
         JSON_READ_STRING(root, "architecture", &result->architecture) &&
f41043
         JSON_READ_UINT64(root, "uptime", &result->uptime);
f41043
 
f41043
+    /* variant is optional - failure is not fatal */
f41043
+    JSON_READ_STRING(root, "variant", &result->variant);
f41043
+
f41043
     if (!success)
f41043
     {
f41043
         sr_operating_system_free(result);
f41043
@@ -194,6 +206,10 @@ os_release_callback(char *key, char *value, void *data)
f41043
     {
f41043
         operating_system->cpe = value;
f41043
     }
f41043
+    else if (0 == strcmp(key, "VARIANT_ID"))
f41043
+    {
f41043
+        operating_system->variant = value;
f41043
+    }
f41043
     else
f41043
     {
f41043
         free(value);
f41043
diff --git a/tests/operating_system.at b/tests/operating_system.at
f41043
index 0db2b9d..044d4bd 100644
f41043
--- a/tests/operating_system.at
f41043
+++ b/tests/operating_system.at
f41043
@@ -46,12 +46,14 @@ AT_TESTFUN([sr_operating_system_parse_etc_os_release],
f41043
 [[
f41043
 #include "operating_system.h"
f41043
 #include "utils.h"
f41043
+#include <string.h>
f41043
 #include <stdio.h>
f41043
 #include <assert.h>
f41043
 
f41043
 void check(const char *etc_os_release,
f41043
            const char *expected_name,
f41043
-           const char *expected_version)
f41043
+           const char *expected_version,
f41043
+           const char *expected_variant)
f41043
 {
f41043
     struct sr_operating_system *os = sr_operating_system_new();
f41043
     bool success = sr_operating_system_parse_etc_os_release(
f41043
@@ -60,6 +62,20 @@ void check(const char *etc_os_release,
f41043
     assert(success);
f41043
     assert(0 == strcmp(os->name, expected_name));
f41043
     assert(0 == strcmp(os->version, expected_version));
f41043
+
f41043
+    if (   (    (expected_variant != NULL && os->variant == NULL)
f41043
+             || (expected_variant == NULL && os->variant != NULL)
f41043
+           )
f41043
+        || (    (expected_variant != NULL && os->variant != NULL)
f41043
+             &&  0 != strcmp(os->version, expected_version)
f41043
+            )
f41043
+        )
f41043
+    {
f41043
+        fprintf(stderr, "Expected: '%s'\n", expected_variant);
f41043
+        fprintf(stderr, "Got     : '%s'\n", os->variant);
f41043
+        abort();
f41043
+    }
f41043
+
f41043
     sr_operating_system_free(os);
f41043
 }
f41043
 
f41043
@@ -102,9 +118,28 @@ main(void)
f41043
 "REDHAT_SUPPORT_PRODUCT=\"Red Hat Enterprise Linux\"\n"
f41043
 "REDHAT_SUPPORT_PRODUCT_VERSION=7.0\n";
f41043
 
f41043
-    check(f19, "fedora", "19");
f41043
-    check(raw, "fedora", "rawhide");
f41043
-    check(el7, "rhel", "7.0");
f41043
+    char *f23 =
f41043
+"NAME=Fedora\n"
f41043
+"VERSION=\"23 (Workstation Edition)\"\n"
f41043
+"ID=fedora\n"
f41043
+"VERSION_ID=23\n"
f41043
+"PRETTY_NAME=\"Fedora 23 (Workstation Edition)\"\n"
f41043
+"ANSI_COLOR=\"0;34\"\n"
f41043
+"CPE_NAME=\"cpe:/o:fedoraproject:fedora:23\"\n"
f41043
+"HOME_URL=\"https://fedoraproject.org/\"\n"
f41043
+"BUG_REPORT_URL=\"https://bugzilla.redhat.com/\"\n"
f41043
+"REDHAT_BUGZILLA_PRODUCT=\"Fedora\"\n"
f41043
+"REDHAT_BUGZILLA_PRODUCT_VERSION=23\n"
f41043
+"REDHAT_SUPPORT_PRODUCT=\"Fedora\"\n"
f41043
+"REDHAT_SUPPORT_PRODUCT_VERSION=23\n"
f41043
+"PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy\n"
f41043
+"VARIANT=\"Workstation Edition\"\n"
f41043
+"VARIANT_ID=workstation\n";
f41043
+
f41043
+    check(f19, "fedora", "19", NULL);
f41043
+    check(raw, "fedora", "rawhide", NULL);
f41043
+    check(el7, "rhel", "7.0", NULL);
f41043
+    check(f23, "fedora", "23", "workstation");
f41043
 
f41043
     return 0;
f41043
 }
f41043
-- 
f41043
1.8.3.1
f41043