2 * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. 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(
32 mod_chxj_config *conf,
35 static void s_set_user_agent_data(
38 mod_chxj_config *conf,
41 static void s_set_device_data(
44 device_table_list *dtl,
49 * load device_data.xml
52 chxj_load_device_data(Doc *doc, apr_pool_t *p, mod_chxj_config *conf)
55 s_set_devices_data(doc, p, conf,qs_get_root(doc));
63 s_set_devices_data(Doc *doc, apr_pool_t *p, mod_chxj_config *conf, Node *node)
67 for (child = qs_get_child_node(doc,node);
69 child = qs_get_next_node(doc,child)) {
70 char *name = qs_get_node_name(doc,child);
71 if (STRCASEEQ('d','D',"devices",name)) {
72 s_set_user_agent_data(doc, p, conf, child);
81 s_set_user_agent_data(Doc *doc, apr_pool_t *p, mod_chxj_config *conf, Node *node)
86 for (child = qs_get_child_node(doc,node);
88 child = qs_get_next_node(doc,child)) {
89 char *name = qs_get_node_name(doc,child);
90 if (STRCASEEQ('u','U',"user_agent",name)) {
92 device_table_list *dtl;
94 if (! conf->devices) {
95 conf->devices = apr_pcalloc(p, sizeof(device_table_list));
96 conf->devices->next = NULL;
97 conf->devices->pattern = NULL;
98 conf->devices->table = NULL;
99 conf->devices->tail = NULL;
103 for (t = conf->devices; t ; t = t->next) {
107 t->next = apr_pcalloc(p, sizeof(device_table_list));
108 t->next->next = NULL;
109 t->next->pattern = NULL;
110 t->next->table = NULL;
111 t->next->tail = NULL;
115 for (attr = qs_get_attr(doc,child);
117 attr = qs_get_next_attr(doc,attr)) {
118 char *attr_name = qs_get_attr_name(doc,attr);
120 if (STRCASEEQ('p','P',"pattern",attr_name)) {
121 dtl->pattern = apr_pstrdup(p, qs_get_attr_value(doc,attr));
122 dtl->regexp = ap_pregcomp(p, (const char *)dtl->pattern, AP_REG_EXTENDED|AP_REG_ICASE);
125 s_set_device_data(doc, p, dtl, child);
132 s_set_device_data(Doc *doc, apr_pool_t *p, device_table_list *dtl, Node *node)
137 dt = apr_pcalloc(p, sizeof(device_table));
139 dt->device_id = NULL;
140 dt->device_name = NULL;
141 dt->html_spec_type = CHXJ_SPEC_Chtml_3_0;
147 dt->emoji_type = NULL;
152 for (child = qs_get_child_node(doc,node);
154 child = qs_get_next_node(doc,child)) {
155 char *name = qs_get_node_name(doc,child);
159 if (strcasecmp(name, "device") == 0) {
160 s_set_device_data(doc,p, dtl, child);
163 if (strcasecmp(name, "device_id") == 0) {
164 Node* ch = qs_get_child_node(doc, child);
165 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
166 dt->device_id = apr_pstrdup(p, qs_get_node_value(doc, ch));
170 if (strcasecmp(name, "device_name") == 0) {
171 Node* ch = qs_get_child_node(doc, child);
172 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
173 dt->device_name = apr_pstrdup(p, qs_get_node_value(doc, ch));
177 if (strcasecmp(name, "dpi_width") == 0) {
178 Node* ch = qs_get_child_node(doc, child);
179 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
180 char *vv = qs_get_node_value(doc,ch);
182 for (ii=0; ii<strlen(vv); ii++) {
183 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
187 if (ii == strlen(vv))
188 dt->dpi_width = atoi(qs_get_node_value(doc,ch));
194 if (strcasecmp(name, "dpi_heigh") == 0) {
195 Node* ch = qs_get_child_node(doc, child);
196 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
197 char *vv = qs_get_node_value(doc,ch);
199 for (ii=0; ii<strlen(vv); ii++) {
200 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
205 if (ii == strlen(vv))
206 dt->dpi_heigh = atoi(qs_get_node_value(doc,ch));
215 if (strcasecmp(name, "html_spec_type") == 0) {
216 Node *ch = qs_get_child_node(doc, child);
217 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
218 char *vv = qs_get_node_value(doc, ch);
219 if (STRCASEEQ('x','X',"xhtml_mobile_1_0",vv)) {
220 dt->html_spec_type = CHXJ_SPEC_XHtml_Mobile_1_0;
222 else if (STRCASEEQ('c','C',"chtml_1_0",vv)) {
223 dt->html_spec_type = CHXJ_SPEC_Chtml_1_0;
225 else if (STRCASEEQ('c','C',"chtml_2_0",vv)) {
226 dt->html_spec_type = CHXJ_SPEC_Chtml_2_0;
228 else if (STRCASEEQ('c','C',"chtml_3_0",vv)) {
229 dt->html_spec_type = CHXJ_SPEC_Chtml_3_0;
231 else if (STRCASEEQ('c','C',"chtml_4_0",vv)) {
232 dt->html_spec_type = CHXJ_SPEC_Chtml_4_0;
234 else if (STRCASEEQ('c','C',"chtml_5_0",vv)) {
235 dt->html_spec_type = CHXJ_SPEC_Chtml_5_0;
237 else if (STRCASEEQ('c','C',"chtml_6_0",vv)) {
238 dt->html_spec_type = CHXJ_SPEC_Chtml_6_0;
240 else if (STRCASEEQ('c','C',"chtml_7_0",vv)) {
241 dt->html_spec_type = CHXJ_SPEC_Chtml_7_0;
243 else if (STRCASEEQ('h','H',"hdml",vv)) {
244 dt->html_spec_type = CHXJ_SPEC_Hdml;
246 else if (STRCASEEQ('j','J',"jhtml",vv)) {
247 dt->html_spec_type = CHXJ_SPEC_Jhtml;
249 else if (STRCASEEQ('j','J',"jxhtml",vv)) {
250 dt->html_spec_type = CHXJ_SPEC_Jxhtml;
255 if (strcasecmp(name, "heigh") == 0) {
256 Node* ch = qs_get_child_node(doc, child);
257 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
258 char *vv = qs_get_node_value(doc,ch);
260 for (ii=0; ii<strlen(vv); ii++) {
261 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
266 if (ii == strlen(vv))
267 dt->heigh = atoi(qs_get_node_value(doc,ch));
276 if (strcasecmp(name, "width") == 0) {
277 Node *ch = qs_get_child_node(doc, child);
278 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
279 char *vv = qs_get_node_value(doc,ch);
281 for (ii=0; ii<strlen(vv); ii++) {
282 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
286 if (ii == strlen(vv))
287 dt->width = atoi(qs_get_node_value(doc,ch));
293 if (strcasecmp(name, "wp_width") == 0) {
294 Node *ch = qs_get_child_node(doc, child);
295 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
296 char *vv = qs_get_node_value(doc,ch);
298 for (ii=0; ii<strlen(vv); ii++) {
299 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
304 if (ii == strlen(vv))
305 dt->wp_width = atoi(qs_get_node_value(doc,ch));
311 if (strcasecmp(name, "wp_heigh") == 0) {
312 Node *ch = qs_get_child_node(doc, child);
313 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
314 char *vv = qs_get_node_value(doc,ch);
316 for (ii=0; ii<strlen(vv); ii++) {
317 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
322 if (ii == strlen(vv))
323 dt->wp_heigh = atoi(qs_get_node_value(doc,ch));
332 if (strcasecmp(name, "gif") == 0) {
333 Node *ch = qs_get_child_node(doc, child);
334 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
335 char *vv = qs_get_node_value(doc,ch);
337 if (strcasecmp(vv, "true") == 0)
338 dt->available_gif = 1;
340 dt->available_gif = 0;
347 if (strcasecmp(name, "jpeg") == 0 || strcasecmp(name, "jpg") == 0) {
348 Node *ch = qs_get_child_node(doc, child);
349 if (ch != NULL && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
350 char *vv = qs_get_node_value(doc,ch);
352 if (strcasecmp(vv, "true") == 0)
353 dt->available_jpeg = 1;
355 dt->available_jpeg = 0;
362 if (strcasecmp(name, "png") == 0) {
363 Node *ch = qs_get_child_node(doc, child);
364 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
365 char *vv = qs_get_node_value(doc,ch);
367 if (strcasecmp(vv, "true") == 0)
368 dt->available_png = 1;
370 dt->available_png = 0;
377 if (strcasecmp(name, "bmp2") == 0) {
378 Node *ch = qs_get_child_node(doc, child);
379 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
380 char *vv = qs_get_node_value(doc,ch);
382 if (strcasecmp(vv, "true") == 0)
383 dt->available_bmp2 = 1;
385 dt->available_bmp2 = 0;
389 if (strcasecmp(name, "bmp4") == 0) {
390 Node *ch = qs_get_child_node(doc, child);
391 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
392 char *vv = qs_get_node_value(doc,ch);
394 if (strcasecmp(vv, "true") == 0)
395 dt->available_bmp4 = 1;
397 dt->available_bmp4 = 0;
404 if (strcasecmp(name, "color") == 0) {
405 Node *ch = qs_get_child_node(doc, child);
406 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
407 char *vv = qs_get_node_value(doc,ch);
409 if (chxj_chk_numeric(vv) != 0)
412 dt->color = chxj_atoi(vv);
416 if (strcasecmp(name, "cache") == 0) {
417 Node *ch = qs_get_child_node(doc, child);
418 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0) {
419 char *vv = qs_get_node_value(doc,ch);
421 for (ii=0; ii<strlen(vv); ii++) {
422 if ((vv[ii] >= '1' && vv[ii] <= '9') || vv[ii] == '0')
427 if (ii == strlen(vv))
428 dt->cache = atoi(qs_get_node_value(doc,ch));
437 if (strcasecmp(name, "emoji_type") == 0) {
438 Node *ch = qs_get_child_node(doc, child);
439 if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0)
440 dt->emoji_type = apr_pstrdup(p, qs_get_node_value(doc, ch));
454 dtl->tail->next = dt;