2 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3 * Copyright (C) 2005 Atsushi Konno All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <qs_ignore_sp.h>
20 #include <qs_malloc.h>
21 #include <qs_parse_attr.h>
22 #include <qs_parse_file.h>
23 #include <qs_parse_string.h>
24 #include <qs_parse_tag.h>
25 #include "chxj_load_device_data.h"
26 #include "chxj_str_util.h"
29 static void s_set_devices_data(Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node) ;
30 static void s_set_user_agent_data(Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node) ;
31 static void s_set_device_data(Doc* doc, apr_pool_t* p, device_table_list_t* dtl, Node* node) ;
33 * load device_data.xml
36 chxj_load_device_data(Doc* doc, apr_pool_t *p, mod_chxj_config* conf)
39 s_set_devices_data(doc, p, conf,qs_get_root(doc));
47 s_set_devices_data(Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node)
51 for (child = qs_get_child_node(doc,node);
53 child = qs_get_next_node(doc,child)) {
54 char* name = qs_get_node_name(doc,child);
55 if (strcasecmp(name, "devices") == 0)
56 s_set_user_agent_data(doc, p, conf, child);
64 s_set_user_agent_data(Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node)
67 device_table_list_t* t;
69 for (child = qs_get_child_node(doc,node);
71 child = qs_get_next_node(doc,child)) {
72 char* name = qs_get_node_name(doc,child);
74 if (strcasecmp(name, "user_agent") == 0 ) {
76 device_table_list_t* dtl;
78 if (! conf->devices) {
79 conf->devices = apr_pcalloc(p, sizeof(device_table_list_t));
80 conf->devices->next = NULL;
81 conf->devices->pattern = NULL;
82 conf->devices->table = NULL;
83 conf->devices->tail = NULL;
87 for (t = conf->devices; t ; t = t->next) {
91 t->next = apr_pcalloc(p, sizeof(device_table_list_t));
93 t->next->pattern = NULL;
94 t->next->table = NULL;
99 for (attr = qs_get_attr(doc,child);
101 attr = qs_get_next_attr(doc,attr)) {
102 if (strcasecmp(qs_get_attr_name(doc,attr), "pattern") == 0) {
103 dtl->pattern = apr_pstrdup(p, qs_get_attr_value(doc,attr));
104 dtl->regexp = ap_pregcomp(p, dtl->pattern, AP_REG_EXTENDED);
107 s_set_device_data(doc, p, dtl, child);
113 s_set_device_data(Doc* doc, apr_pool_t* p, device_table_list_t* dtl, Node* node)
118 dt = apr_pcalloc(p, sizeof(device_table_t));
120 dt->device_id = NULL;
121 dt->device_name = NULL;
122 dt->html_spec_type = CHXJ_SPEC_Chtml_3_0;
128 dt->emoji_type = NULL;
133 for (child = qs_get_child_node(doc,node);
135 child = qs_get_next_node(doc,child)) {
136 char* name = qs_get_node_name(doc,child);
137 if (strcasecmp(name, "device") == 0) {
138 s_set_device_data(doc,p, dtl, child);
141 if (strcasecmp(name, "device_id") == 0) {
142 Node* ch = qs_get_child_node(doc, child);
143 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
144 dt->device_id = apr_pstrdup(p, qs_get_node_value(doc, ch));
148 if (strcasecmp(name, "device_name") == 0) {
149 Node* ch = qs_get_child_node(doc, child);
150 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
151 dt->device_name = apr_pstrdup(p, qs_get_node_value(doc, ch));
155 if (strcasecmp(name, "html_spec_type") == 0) {
156 Node* ch = qs_get_child_node(doc, child);
157 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
158 char* vv = qs_get_node_value(doc, ch);
159 if (strcasecmp(vv, "xhtml_mobile_1_0") == 0) {
160 dt->html_spec_type = CHXJ_SPEC_XHtml_Mobile_1_0;
163 if (strcasecmp(vv, "chtml_1_0") == 0) {
164 dt->html_spec_type = CHXJ_SPEC_Chtml_1_0;
167 if (strcasecmp(vv, "chtml_2_0") == 0) {
168 dt->html_spec_type = CHXJ_SPEC_Chtml_2_0;
171 if (strcasecmp(vv, "chtml_3_0") == 0) {
172 dt->html_spec_type = CHXJ_SPEC_Chtml_3_0;
175 if (strcasecmp(vv, "chtml_4_0") == 0) {
176 dt->html_spec_type = CHXJ_SPEC_Chtml_4_0;
179 if (strcasecmp(vv, "chtml_5_0") == 0) {
180 dt->html_spec_type = CHXJ_SPEC_Chtml_5_0;
183 if (strcasecmp(vv, "hdml") == 0) {
184 dt->html_spec_type = CHXJ_SPEC_Hdml;
187 if (strcasecmp(vv, "jhtml") == 0) {
188 dt->html_spec_type = CHXJ_SPEC_Jhtml;
193 if (strcasecmp(name, "width") == 0) {
194 Node* ch = qs_get_child_node(doc, child);
195 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
196 char *vv = qs_get_node_value(doc,ch);
198 for (ii=0; ii<strlen(vv); ii++) {
199 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
203 if (ii == strlen(vv))
204 dt->width = atoi(qs_get_node_value(doc,ch));
210 if (strcasecmp(name, "heigh") == 0) {
211 Node* ch = qs_get_child_node(doc, child);
212 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
213 char *vv = qs_get_node_value(doc,ch);
215 for (ii=0; ii<strlen(vv); ii++) {
216 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
221 if (ii == strlen(vv))
222 dt->heigh = atoi(qs_get_node_value(doc,ch));
228 if (strcasecmp(name, "gif") == 0) {
229 Node* ch = qs_get_child_node(doc, child);
230 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
231 char *vv = qs_get_node_value(doc,ch);
233 if (strcasecmp(vv, "true") == 0)
234 dt->available_gif = 1;
236 dt->available_gif = 0;
240 if (strcasecmp(name, "jpeg") == 0 || strcasecmp(name, "jpg") == 0) {
241 Node* ch = qs_get_child_node(doc, child);
242 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
243 char *vv = qs_get_node_value(doc,ch);
245 if (strcasecmp(vv, "true") == 0)
246 dt->available_jpeg = 1;
248 dt->available_jpeg = 0;
252 if (strcasecmp(name, "png") == 0) {
253 Node* ch = qs_get_child_node(doc, child);
254 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
255 char *vv = qs_get_node_value(doc,ch);
257 if (strcasecmp(vv, "true") == 0)
258 dt->available_png = 1;
260 dt->available_png = 0;
264 if (strcasecmp(name, "bmp2") == 0) {
265 Node* ch = qs_get_child_node(doc, child);
266 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
267 char *vv = qs_get_node_value(doc,ch);
268 if (strcasecmp(vv, "true") == 0)
270 dt->available_bmp2 = 1;
274 dt->available_bmp2 = 0;
279 if (strcasecmp(name, "bmp4") == 0)
281 Node* ch = qs_get_child_node(doc, child);
282 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
284 char *vv = qs_get_node_value(doc,ch);
285 if (strcasecmp(vv, "true") == 0)
287 dt->available_bmp4 = 1;
291 dt->available_bmp4 = 0;
296 if (strcasecmp(name, "color") == 0)
298 Node* ch = qs_get_child_node(doc, child);
299 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
301 char *vv = qs_get_node_value(doc,ch);
302 if (chxj_chk_numeric(vv) != 0)
308 dt->color = chxj_atoi(vv);
313 if (strcasecmp(name, "emoji_type") == 0)
315 Node* ch = qs_get_child_node(doc, child);
316 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
318 dt->emoji_type = apr_pstrdup(p, qs_get_node_value(doc, ch));
322 if (strcasecmp(name, "wp_width") == 0)
324 Node* ch = qs_get_child_node(doc, child);
325 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
327 char *vv = qs_get_node_value(doc,ch);
329 for (ii=0; ii<strlen(vv); ii++)
331 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
337 if (ii == strlen(vv))
339 dt->wp_width = atoi(qs_get_node_value(doc,ch));
348 if (strcasecmp(name, "wp_heigh") == 0)
350 Node* ch = qs_get_child_node(doc, child);
351 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
353 char *vv = qs_get_node_value(doc,ch);
355 for (ii=0; ii<strlen(vv); ii++)
357 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
363 if (ii == strlen(vv))
365 dt->wp_heigh = atoi(qs_get_node_value(doc,ch));
374 if (strcasecmp(name, "cache") == 0)
376 Node* ch = qs_get_child_node(doc, child);
377 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
379 char *vv = qs_get_node_value(doc,ch);
381 for (ii=0; ii<strlen(vv); ii++)
383 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
389 if (ii == strlen(vv))
391 dt->cache = atoi(qs_get_node_value(doc,ch));
400 if (strcasecmp(name, "dpi_width") == 0)
402 Node* ch = qs_get_child_node(doc, child);
403 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
405 char *vv = qs_get_node_value(doc,ch);
407 for (ii=0; ii<strlen(vv); ii++)
409 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
415 if (ii == strlen(vv))
417 dt->dpi_width = atoi(qs_get_node_value(doc,ch));
426 if (strcasecmp(name, "dpi_heigh") == 0)
428 Node* ch = qs_get_child_node(doc, child);
429 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
431 char *vv = qs_get_node_value(doc,ch);
433 for (ii=0; ii<strlen(vv); ii++)
435 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
441 if (ii == strlen(vv))
443 dt->dpi_heigh = atoi(qs_get_node_value(doc,ch));
453 if (dt->device_id != NULL)
455 if (dtl->table == NULL)
462 dtl->tail->next = dt;