4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 #include <libxml/parser.h>
23 #include <libxml/tree.h>
24 #include <libxml/uri.h>
29 static xmlDocPtr configxml = NULL;
31 static xmlNodePtr next(xmlNodePtr node, const char *type)
33 while (node && node->type != XML_ELEMENT_NODE && strcmp(type, node->name))
38 static xmlNodePtr first(const char *type)
42 root = xmlDocGetRootElement(configxml);
44 return next(root->children, type);
49 static xmlNodePtr element_based_localisation(const char *type)
56 lang = xmlNodeGetLang(resu);
60 resu = next(resu->next, type);
68 xmlFreeDoc(configxml);
76 configxml = xmlReadFile(_config_xml_, NULL, 0);
77 if (configxml == NULL) {
78 syslog(LOG_ERR, "xml parse of config file %s failed", _config_xml_);
84 /* elements based on localisation */
85 xmlNodePtr confixml_name()
87 return element_based_localisation(_name_);
90 xmlNodePtr confixml_description()
92 return element_based_localisation(_description_);
95 xmlNodePtr confixml_license()
97 return element_based_localisation(_license_);
100 /* elements based on path localisation */
101 xmlNodePtr confixml_author()
103 return first(_author_);
106 xmlNodePtr confixml_content()
108 return first(_content_);
111 /* element multiple */
113 xmlNodePtr confixml_first_feature()
115 return first(_feature_);
118 xmlNodePtr confixml_next_feature(xmlNodePtr node)
120 return next(node->next, _feature_);
123 xmlNodePtr confixml_first_preference()
125 return first(_preference_);
128 xmlNodePtr confixml_next_preference(xmlNodePtr node)
130 return next(node->next, _preference_);
133 xmlNodePtr confixml_first_icon()
135 return first(_icon_);
138 xmlNodePtr confixml_next_icon(xmlNodePtr node)
140 return next(node->next, _icon_);
143 /* best sized icon */
145 static int score_dim(xmlNodePtr ref, xmlNodePtr x, const char *dim, int request)
150 sref = xmlGetProp(ref, dim);
154 sx = xmlGetProp(x, dim);
178 sx = xmlGetProp(x, dim);
195 static int better_icon(xmlNodePtr ref, xmlNodePtr x, int width, int height)
197 int sw = score_dim(ref, x, _width_, width);
198 int sh = score_dim(ref, x, _height_, height);
202 xmlNodePtr confixml_icon(int width, int height)
204 xmlNodePtr resu, icon;
206 resu = confixml_first_icon();
207 icon = confixml_next_icon(resu);
209 if (better_icon(resu, icon, width, height))
211 icon = confixml_next_icon(icon);