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

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