OSDN Git Service

* Added features:
[modchxj/mod_chxj.git] / src / chxj_specified_device.c
1 /*
2  * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #include "mod_chxj.h"
18
19 static device_table  UNKNOWN_DEVICE      = {
20   .next               = NULL,
21   .device_id          = "",
22   .device_name        = "UNKNOWN",
23   .html_spec_type     = CHXJ_SPEC_UNKNOWN,
24   .width              = 640,
25   .heigh              = 480,
26   /*--------------------------------------------------------------------------*/
27   /* Walll Paper Size                                                         */
28   /*--------------------------------------------------------------------------*/
29   .wp_width           = 640,
30   .wp_heigh           = 480,
31   /*--------------------------------------------------------------------------*/
32   /* Cache Size                                                               */
33   /*--------------------------------------------------------------------------*/
34   .cache              = 10000000,
35   /*--------------------------------------------------------------------------*/
36   /* Correspondence image format                                              */
37   /* 1: It is possible to display it.                                         */
38   /* 0: It is not possible to display it.                                     */
39   /*--------------------------------------------------------------------------*/
40   .available_gif      = 1,
41   .available_jpeg     = 1,
42   .available_png      = 1,
43   .available_bmp2     = 1,
44   .available_bmp4     = 1,
45   .dpi_width          = 96,
46   .dpi_heigh          = 96,
47   /*--------------------------------------------------------------------------*/
48   /* Color number type                                                        */
49   /* 2       : 2        Colors                                                */
50   /* 4       : 4        Colors                                                */
51   /* 256     : 256      Colors                                                */
52   /* 4096    : 4096     Colors                                                */
53   /* 65536   : 65536    Colors                                                */
54   /* 262144  : 262144   Colors                                                */
55   /* 15680000: 15680000 over colors                                           */
56   /*--------------------------------------------------------------------------*/
57   .color              = 15680000,
58   .emoji_type         = NULL,
59 };
60
61 /**
62  * The device is specified from UserAgent. 
63  * @param r Request_rec is appointed.
64  * @param userAgent UserAgent is appointed here,
65  * @return The style which corresponds is returned.
66  */
67 device_table *
68 chxj_specified_device(request_rec *r, const char *user_agent) 
69 {
70   ap_regmatch_t        match[10];
71   device_table         *returnType = &UNKNOWN_DEVICE;
72   device_table_list    *dtl;
73   device_table         *dt;
74   mod_chxj_config      *conf; 
75   char                 *device_id;
76
77   if (! user_agent) 
78     return returnType;
79             
80
81   DBG(r, "start chxj_specified_device()");
82
83   conf = ap_get_module_config(r->per_dir_config, &chxj_module);
84   if (! conf->devices) {
85     DBG(r, "device_data.xml load failure");
86     return returnType;
87   }
88
89   for (dtl = conf->devices; dtl; dtl = dtl->next) {
90     if (! dtl->pattern) {
91       DBG(r, "pattern is null");
92       continue;
93     }
94
95     DBG(r, "pattern is [%s]", dtl->pattern);
96     if (! dtl->regexp) {
97       DBG(r,"compile failed.");
98       return returnType;
99     }
100
101     if (ap_regexec((const ap_regex_t *)dtl->regexp, user_agent, (apr_size_t)dtl->regexp->re_nsub + 1, match, 0) == 0) {
102       device_id = ap_pregsub(r->pool, "$1", user_agent, dtl->regexp->re_nsub + 1, match);
103       DBG(r, "device_id:[%s]", device_id);
104       for (dt = dtl->table; dt; dt = dt->next) {
105         if (strcasecmp(device_id, dt->device_id) == 0) {
106           DBG(r, "device_name:[%s]", dt->device_name);
107           returnType = dt;
108           break;
109         }
110       }
111
112       if (! dt) {
113         for (dt = dtl->table; dt; dt = dt->next) {
114           if (dt->next == NULL)
115             break;
116         }
117
118         if (dt)
119           returnType = dt;
120       }
121     }
122
123     if (returnType != &UNKNOWN_DEVICE) {
124       DBG(r,"end chxj_specified_device()");
125       return returnType;
126     }
127   }
128
129   DBG(r,"end chxj_specified_device()");
130
131   return returnType;
132 }
133 /*
134  * vim:ts=2 et
135  */