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

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