Libgourou

Libgourou Git Source Tree

Root/src/loan_token.cpp

1/*
2 Copyright 2022 Grégory Soutadé
3
4 This file is part of libgourou.
5
6 libgourou is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 libgourou is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with libgourou. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "libgourou_common.h"
21#include "loan_token.h"
22
23namespace gourou
24{
25 LoanToken::LoanToken(pugi::xml_document& doc)
26 {
27pugi::xml_node node = doc.select_node("/envelope/loanToken").node();
28
29if (!node)
30 EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken element in document");
31
32node = doc.select_node("/envelope/loanToken/loan").node();
33
34if (node)
35 properties["id"] = node.first_child().value();
36else
37{
38 node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/loan").node();
39
40 if (node)
41properties["id"] = node.first_child().value();
42 else
43 {
44node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/loan").node();
45if (node)
46 properties["id"] = node.first_child().value();
47else
48 EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/loan element in document");
49 }
50}
51
52node = doc.select_node("/envelope/loanToken/operatorURL").node();
53
54if (!node)
55 EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/operatorURL element in document");
56
57properties["operatorURL"] = node.first_child().value();
58
59node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/until").node();
60
61if (node)
62 properties["validity"] = node.first_child().value();
63else
64{
65 node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/until").node();
66
67 if (node)
68properties["validity"] = node.first_child().value();
69 else
70EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/operatorURL element in document");
71}
72 }
73
74 std::string LoanToken::getProperty(const std::string& property, const std::string& _default)
75 {
76if (properties.find(property) == properties.end())
77{
78 if (_default == "")
79EXCEPTION(GOUROU_INVALID_PROPERTY, "Invalid property " << property);
80
81 return _default;
82}
83
84return properties[property];
85 }
86
87 std::string LoanToken::operator[](const std::string& property)
88 {
89return getProperty(property);
90 }
91}

Archive Download this file