OpenCPN Partial API docs
Loading...
Searching...
No Matches
catalog_parser.cpp
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Copyright (C) 2019 Alec Leamas *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 ***************************************************************************
23 */
24
25#include <cstring>
26#include <fstream>
27#include <iterator>
28#include <sstream>
29
30#include <wx/log.h>
31
32#if defined(__MINGW32__) && defined(Yield)
33#undef Yield // from win.h, conflicts with mingw headers
34#endif
35
36#include "catalog_parser.h"
37#include "ocpn_utils.h"
38#include "catalog_handler.h"
39#include "pugixml.hpp"
40
41
42bool ParseCatalog(const std::string xml, CatalogCtx* ctx) {
43 bool ok = true;
44 PluginMetadata* plugin = 0;
45
46 pugi::xml_document doc;
47 doc.load_string(xml.c_str());
48
49 pugi::xml_node elements = doc.child("plugins");
50 for (pugi::xml_node element = elements.first_child(); element;
51 element = element.next_sibling()) {
52 if (!strcmp(element.name(), "version") && ctx->version == "") {
53 ctx->version = ocpn::trim(element.first_child().value());
54 } else if (strcmp(element.name(), "date") == 0 && ctx->date == "") {
55 ctx->date = ocpn::trim(element.first_child().value());
56 } else if (strcmp(element.name(), "meta-url") == 0) {
57 ctx->meta_url = ocpn::trim(element.first_child().value());
58 } else if (!strcmp(element.name(), "plugin")) {
59 if (ctx->meta_url != "") {
60 ctx->meta_urls.push_back(ctx->meta_url);
61 ctx->meta_url = "";
62 } else {
63 if (plugin) ctx->plugins.push_back(*plugin);
64 plugin = new PluginMetadata;
65 }
66
67 for (pugi::xml_node plugin_element = element.first_child();
68 plugin_element; plugin_element = plugin_element.next_sibling()) {
69 if (strcmp(plugin_element.name(), "meta-url") == 0) {
70 auto url = ocpn::trim(plugin_element.first_child().value());
71 ctx->meta_url = url;
72 } else if (strcmp(plugin_element.name(), "name") == 0) {
73 plugin->name = ocpn::trim(plugin_element.first_child().value());
74 } else if (strcmp(plugin_element.name(), "version") == 0) {
75 plugin->version = ocpn::trim(plugin_element.first_child().value());
76 } else if (strcmp(plugin_element.name(), "release") == 0) {
77 plugin->release = ocpn::trim(plugin_element.first_child().value());
78 } else if (strcmp(plugin_element.name(), "summary") == 0) {
79 plugin->summary = ocpn::trim(plugin_element.first_child().value());
80 } else if (strcmp(plugin_element.name(), "api_version") == 0) {
81 plugin->api_version =
82 ocpn::trim(plugin_element.first_child().value());
83 } else if (strcmp(plugin_element.name(), "author") == 0) {
84 plugin->author = ocpn::trim(plugin_element.first_child().value());
85 } else if (strcmp(plugin_element.name(), "description") == 0) {
86 plugin->description =
87 ocpn::trim(plugin_element.first_child().value());
88 } else if (strcmp(plugin_element.name(), "git-commit") == 0) {
89 plugin->git_commit = ocpn::trim(plugin_element.first_child().value());
90 } else if (strcmp(plugin_element.name(), "git-date") == 0) {
91 plugin->git_date = ocpn::trim(plugin_element.first_child().value());
92 } else if (strcmp(plugin_element.name(), "source") == 0) {
93 plugin->source = ocpn::trim(plugin_element.first_child().value());
94 } else if (strcmp(plugin_element.name(), "tarball-url") == 0) {
95 plugin->tarball_url =
96 ocpn::trim(plugin_element.first_child().value());
97 } else if (strcmp(plugin_element.name(), "info-url") == 0) {
98 plugin->info_url = ocpn::trim(plugin_element.first_child().value());
99 } else if (strcmp(plugin_element.name(), "target") == 0) {
100 plugin->target = ocpn::trim(plugin_element.first_child().value());
101 } else if (strcmp(plugin_element.name(), "build-gtk") == 0) {
102 plugin->build_gtk = ocpn::trim(plugin_element.first_child().value());
103 } else if (strcmp(plugin_element.name(), "target-version") == 0) {
104 plugin->target_version =
105 ocpn::trim(plugin_element.first_child().value());
106 } else if (strcmp(plugin_element.name(), "target-arch") == 0) {
107 plugin->target_arch =
108 ocpn::trim(plugin_element.first_child().value());
109 } else if (strcmp(plugin_element.name(), "tarball-checksum") == 0) {
110 plugin->checksum = ocpn::trim(plugin_element.first_child().value());
111 } else if (strcmp(plugin_element.name(), "open-source") == 0) {
112 plugin->openSource =
113 ocpn::trim(plugin_element.first_child().value()) == "yes";
114 }
115 }
116 }
117 }
118
119 // capture last plugin
120 if (plugin)
121 ctx->plugins.push_back(*plugin);
122 else {
123 if (ctx->meta_url != "") {
124 ctx->meta_urls.push_back(ctx->meta_url);
125 ctx->meta_url = "";
126 }
127 }
128
129 return true;
130}
The result from parsing the xml catalog i.
Plugin metadata, reflects the xml format directly.