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 | ␊ |
23 | namespace gourou␊ |
24 | {␊ |
25 | LoanToken::LoanToken(pugi::xml_document& doc)␊ |
26 | {␊ |
27 | ␉pugi::xml_node node = doc.select_node("/envelope/loanToken").node();␊ |
28 | ␊ |
29 | ␉if (!node)␊ |
30 | ␉ EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken element in document");␊ |
31 | ␊ |
32 | ␉node = doc.select_node("/envelope/loanToken/loan").node();␊ |
33 | ␊ |
34 | ␉if (node)␊ |
35 | ␉ properties["id"] = node.first_child().value();␊ |
36 | ␉else␊ |
37 | ␉{␊ |
38 | ␉ node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/loan").node();␊ |
39 | ␊ |
40 | ␉ if (node)␊ |
41 | ␉␉properties["id"] = node.first_child().value();␊ |
42 | ␉ else␊ |
43 | ␉ {␊ |
44 | ␉␉node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/loan").node();␊ |
45 | ␉␉if (node)␊ |
46 | ␉␉ properties["id"] = node.first_child().value();␊ |
47 | ␉␉else␊ |
48 | ␉␉ EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/loan element in document");␊ |
49 | ␉ }␊ |
50 | ␉}␊ |
51 | ␊ |
52 | ␉node = doc.select_node("/envelope/loanToken/operatorURL").node();␊ |
53 | ␊ |
54 | ␉if (!node)␊ |
55 | ␉ EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/operatorURL element in document");␊ |
56 | ␊ |
57 | ␉properties["operatorURL"] = node.first_child().value();␊ |
58 | ␊ |
59 | ␉node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/until").node();␊ |
60 | ␊ |
61 | ␉if (node)␊ |
62 | ␉ properties["validity"] = node.first_child().value();␊ |
63 | ␉else␊ |
64 | ␉{␊ |
65 | ␉ node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/until").node();␊ |
66 | ␊ |
67 | ␉ if (node)␊ |
68 | ␉␉properties["validity"] = node.first_child().value();␊ |
69 | ␉ else␊ |
70 | ␉␉EXCEPTION(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 | {␊ |
76 | ␉if (properties.find(property) == properties.end())␊ |
77 | ␉{␊ |
78 | ␉ if (_default == "")␊ |
79 | ␉␉EXCEPTION(GOUROU_INVALID_PROPERTY, "Invalid property " << property);␊ |
80 | ␊ |
81 | ␉ return _default;␊ |
82 | ␉}␊ |
83 | ␊ |
84 | ␉return properties[property];␊ |
85 | }␊ |
86 | ␊ |
87 | std::string LoanToken::operator[](const std::string& property)␊ |
88 | {␊ |
89 | ␉return getProperty(property);␊ |
90 | }␊ |
91 | }␊ |