aboutsummaryrefslogtreecommitdiffstats
path: root/include/jsonhandler.h
blob: 18baad0384d3c58b1b0c6d476eb016f5b67d6c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Copyright (C) 2022 The Qt Company Ltd.
 *
 * SPDX-License-Identifier: GPL-3.0-only WITH Qt-GPL-exception-1.0
*/
#pragma once

#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <iostream>
#include <iomanip>
#include "utils.h"

// Very simple JSON reader/writer, takes a JSON string as input
// Specific to Qt license daemon only, doesn't work with JSONs in general
class JsonHandler  {

const std::vector<std::string> reservation {
    "reservation_id", "license_number", "email", "user_id",
    "hardware_id", "expiry_date", "license_key"
};

public:
    explicit JsonHandler(const std::string &jsonString);
    ~JsonHandler() {  }

    std::string get(const std::string &item);
    // Just in case type-specific are needed - here is some
    int getInt(const std::string &item);
    std::string getStr(const std::string &item);
    bool getBool(const std::string &item);

    void add(const std::string &item, const std::string &value);
    void add(const std::string &item, uint64_t value);
    void add(const std::string &item, bool value);

    std::string dump(uint8_t indent=0);

private:
    std::map<std::string, std::string> m_items;
    int preParse(const std::string &jsonString);

};