open-license-manager
2014-04-14 3ba1ee60337c5e74027acb6f89a16e5ff3aa345c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * LicenseReader.h
 *
 *  Created on: Mar 30, 2014
 *      Author: devel
 */
 
#ifndef LICENSEREADER_H_
#define LICENSEREADER_H_
 
#include "api/datatypes.h"
#include "base/EventRegistry.h"
#include "os/os.hpp"
#define SI_SUPPORT_IOSTREAMS
#include "ini/SimpleIni.h"
#include <string>
#include <ctime>
namespace license {
 
using namespace std;
 
class FullLicenseInfo {
public:
    string source;
    string product;
    string license_signature;
    int license_version;
    time_t from_date;
    time_t to_date;
    bool has_expiry;
    unsigned int from_sw_version;
    unsigned int to_sw_version;
    bool has_versions;
    string client_signature;
    bool has_client_sig;
    string extra_data;
 
    static const time_t UNUSED_TIME = (time_t) 0;
    static const unsigned int UNUSED_SOFTWARE_VERSION = 0;
 
    FullLicenseInfo(const string& source, const string& product,
            const string& license_signature, int licenseVersion,
            time_t from_date = UNUSED_TIME,
            time_t to_date = UNUSED_TIME, //
            const string& client_signature = "", //
            unsigned int from_sw_version = UNUSED_SOFTWARE_VERSION,
            unsigned int to_sw_version = UNUSED_SOFTWARE_VERSION,
            const string& extra_data = "");
    string printForSign() const;
    void printAsIni(ostream & a_ostream) const;
 
    void toLicenseInfo(LicenseInfo* license) const;
    EventRegistry validate(int sw_version);
};
/**
 * This class it is responsible to read the licenses from the disk
 * (in future from network) examining all the possible LicenseLocation
 * positions.
 *
 * Each section of the ini file represents a product.
 * <pre>
 * [product]
 *  sw_version_from = (optional int)
 *  sw_version_to = (optional int)
 *  from_date = YYYY-MM-DD (optional)
 *  to_date  = YYYY-MM-DD (optional)
 *  client_signature = XXXXXXXX (optional string 16)
 *  license_signature = XXXXXXXXXX (mandatory, 1024)
 *  application_data = xxxxxxxxx (optional string 16)
 *    license_version = 100 (mandatory int)
 *  </pre>
 */
class LicenseReader {
private:
    time_t read_date(const char * productName, const char * ini_key,
            const CSimpleIniA& ini) const;
    const LicenseLocation licenseLocation;
    EventRegistry getLicenseDiskFiles(vector<string>& diskFiles);
    vector<string> filterExistingFiles(vector<string> licensePositions);
    vector<string> splitLicensePositions(string licensePositions);
    bool findLicenseWithExplicitLocation(vector<string>& diskFiles,
            EventRegistry& eventRegistry);
    bool findFileWithEnvironmentVariable(vector<string>& diskFiles,
            EventRegistry& eventRegistry);
 
public:
    LicenseReader(const LicenseLocation& licenseLocation);
    EventRegistry readLicenses(const string &product,
            vector<FullLicenseInfo>& licenseInfoOut);
    virtual ~LicenseReader();
};
}
#endif /* LICENSEREADER_H_ */