OSDN Git Service

Merge branch 'branch_0.13.0'
[modchxj/mod_chxj.git] / src / chxj_add_device_env.c
1 /*
2  * Copyright (C) 2005-2011 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 #include "chxj_add_device_env.h"
19 #include "chxj_str_util.h"
20
21 void
22 chxj_add_device_env(request_rec *r, device_table *spec)
23 {
24   DBG(r, "REQ[%X] start chxj_add_device_env()", (unsigned int)(apr_size_t)r);
25   switch(spec->html_spec_type) {
26   case CHXJ_SPEC_Chtml_1_0:
27   case CHXJ_SPEC_Chtml_2_0:
28   case CHXJ_SPEC_Chtml_3_0:
29   case CHXJ_SPEC_Chtml_4_0:
30   case CHXJ_SPEC_Chtml_5_0:
31   case CHXJ_SPEC_Chtml_6_0:
32   case CHXJ_SPEC_Chtml_7_0:
33     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER, "1");
34     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER_STRING, "docomo");
35     break;
36   case CHXJ_SPEC_XHtml_Mobile_1_0:
37   case CHXJ_SPEC_Hdml:
38     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER, "2");
39     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER_STRING, "au");
40     break;
41   case CHXJ_SPEC_Jhtml:
42   case CHXJ_SPEC_Jxhtml:
43     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER, "3");
44     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER_STRING, "SoftBank");
45     break;
46   default:
47     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER, "0");
48     apr_table_setn(r->headers_in, HTTP_X_CHXJ_PROVIDER_STRING, "unknown");
49     break;
50   }
51
52   apr_table_setn(r->headers_in, HTTP_X_CHXJ_DEVICEID, apr_pstrdup(r->pool, spec->device_id));
53   apr_table_setn(r->headers_in, HTTP_X_CHXJ_DEVICENAME, apr_pstrdup(r->pool, spec->device_name));
54
55   switch(spec->html_spec_type) {
56   case CHXJ_SPEC_Chtml_1_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML1.0"); break;
57   case CHXJ_SPEC_Chtml_2_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML2.0"); break;
58   case CHXJ_SPEC_Chtml_3_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML3.0"); break;
59   case CHXJ_SPEC_Chtml_4_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML4.0"); break;
60   case CHXJ_SPEC_Chtml_5_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML5.0"); break;
61   case CHXJ_SPEC_Chtml_6_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML6.0"); break;
62   case CHXJ_SPEC_Chtml_7_0:        apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "CHTML7.0"); break;
63   case CHXJ_SPEC_XHtml_Mobile_1_0: apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "XHTML");    break;
64   case CHXJ_SPEC_Hdml:             apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "HDML");     break;
65   case CHXJ_SPEC_Jhtml:            apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "JHTML");    break;
66   case CHXJ_SPEC_Jxhtml:           apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "JXHTML");   break;
67   default:                         apr_table_setn(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE, "UNKNOWN");  break;
68   }
69
70   apr_table_setn(r->headers_in, HTTP_X_CHXJ_WIDTH,    apr_psprintf(r->pool, "%d", spec->width));
71   apr_table_setn(r->headers_in, HTTP_X_CHXJ_HEIGHT,   apr_psprintf(r->pool, "%d", spec->heigh));
72   apr_table_setn(r->headers_in, HTTP_X_CHXJ_GIF,      (spec->available_gif  == 0) ? "false" : "true");
73   apr_table_setn(r->headers_in, HTTP_X_CHXJ_JPEG,     (spec->available_jpeg == 0) ? "false" : "true");
74   apr_table_setn(r->headers_in, HTTP_X_CHXJ_PNG,      (spec->available_png  == 0) ? "false" : "true");
75   apr_table_setn(r->headers_in, HTTP_X_CHXJ_BMP2,     (spec->available_bmp2 == 0) ? "false" : "true");
76   apr_table_setn(r->headers_in, HTTP_X_CHXJ_BMP4,     (spec->available_bmp4 == 0) ? "false" : "true");
77   apr_table_setn(r->headers_in, HTTP_X_CHXJ_COLOR,    apr_psprintf(r->pool, "%d", spec->color));
78   apr_table_setn(r->headers_in, HTTP_X_CHXJ_WP_WIDTH, apr_psprintf(r->pool, "%d", spec->wp_width));
79   apr_table_setn(r->headers_in, HTTP_X_CHXJ_WP_HEIGHT,apr_psprintf(r->pool, "%d", spec->wp_heigh));
80   apr_table_setn(r->headers_in, HTTP_X_CHXJ_CACHE,    apr_psprintf(r->pool, "%d", spec->cache));
81   apr_table_setn(r->headers_in, HTTP_X_CHXJ_DPI_WIDTH,    apr_psprintf(r->pool, "%d", spec->dpi_width));
82   apr_table_setn(r->headers_in, HTTP_X_CHXJ_DPI_HEIGHT,   apr_psprintf(r->pool, "%d", spec->dpi_heigh));
83   apr_table_setn(r->headers_in, HTTP_X_CHXJ_EMOJI_TYPE,   (spec->emoji_type) ? spec->emoji_type : "");
84
85   apr_table_setn(r->headers_in, HTTP_X_CHXJ_VERSION,  apr_pstrdup(r->pool, PACKAGE_VERSION));
86   
87   mod_chxj_config*    dconf;
88   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
89   if (dconf->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_TSV ){
90     if (spec->device_id     != NULL &&
91         dconf->device_hash  != NULL){
92       char *key = apr_psprintf(r->pool,"%d.%s",spec->provider,spec->device_id);
93       apr_table_t *ht = apr_hash_get(dconf->device_hash,key,APR_HASH_KEY_STRING);
94   
95       if(ht != NULL){
96         int i;
97         for ( i=0; i< dconf->device_keys->nelts; i++){
98           const char *k = ((const char**)dconf->device_keys->elts)[i];
99           char *val = (char *)apr_table_get(ht,k);
100           if(val != NULL){
101             char *info_key = apr_psprintf(r->pool,"%s-%s",HTTP_X_CHXJ_INFO,k);
102             apr_table_setn(r->headers_in, info_key, val);
103           }
104         }
105       }
106     }
107   }
108
109   DBG(r, "REQ[%X] end chxj_add_device_env()", (unsigned int)(apr_size_t)r);
110 }
111
112 device_table *
113 chxj_get_device_env(request_rec *r)
114 {
115   device_table *spec;
116   char *tmp;
117   DBG(r, "REQ[%X] start chxj_get_device_env()", (unsigned int)(apr_size_t)r);
118
119   spec = apr_palloc(r->pool, sizeof(device_table));
120   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_HTMLSPECTYPE);
121   if (! tmp) {
122     DBG(r, "REQ[%X] end chxj_get_device_env()", (unsigned int)(apr_size_t)r);
123     return NULL;
124   }
125   if (STRCASEEQ('c','C', "CHTML1.0", tmp)) {
126     spec->html_spec_type = CHXJ_SPEC_Chtml_1_0;
127   }
128   else if (STRCASEEQ('c','C', "CHTML2.0", tmp)) {
129     spec->html_spec_type = CHXJ_SPEC_Chtml_2_0;
130   }
131   else if (STRCASEEQ('c','C', "CHTML3.0", tmp)) {
132     spec->html_spec_type = CHXJ_SPEC_Chtml_3_0;
133   }
134   else if (STRCASEEQ('c','C', "CHTML4.0", tmp)) {
135     spec->html_spec_type = CHXJ_SPEC_Chtml_4_0;
136   }
137   else if (STRCASEEQ('c','C', "CHTML5.0", tmp)) {
138     spec->html_spec_type = CHXJ_SPEC_Chtml_5_0;
139   }
140   else if (STRCASEEQ('c','C', "CHTML6.0", tmp)) {
141     spec->html_spec_type = CHXJ_SPEC_Chtml_6_0;
142   }
143   else if (STRCASEEQ('c','C', "CHTML7.0", tmp)) {
144     spec->html_spec_type = CHXJ_SPEC_Chtml_7_0;
145   }
146   else if (STRCASEEQ('x','X', "XHTML", tmp)) {
147     spec->html_spec_type = CHXJ_SPEC_XHtml_Mobile_1_0;
148   }
149   else if (STRCASEEQ('h','H', "HDML", tmp)) {
150     spec->html_spec_type = CHXJ_SPEC_Hdml;
151   }
152   else if (STRCASEEQ('j','j', "JHTML", tmp)) {
153     spec->html_spec_type = CHXJ_SPEC_Jhtml;
154   }
155   else if (STRCASEEQ('j','j', "JXHTML", tmp)) {
156     spec->html_spec_type = CHXJ_SPEC_Jxhtml;
157   }
158   else {
159     spec->html_spec_type = CHXJ_SPEC_UNKNOWN;
160   }
161   
162   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_DEVICEID);
163   if (tmp) {
164     spec->device_id = apr_pstrdup(r->pool, tmp);
165   }
166   else {
167     spec->device_id = apr_pstrdup(r->pool, "");
168   }
169
170   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_DEVICENAME);
171   if (tmp) {
172     spec->device_name = apr_pstrdup(r->pool, tmp);
173   }
174   else {
175     spec->device_name = apr_pstrdup(r->pool, "UNKNOWN");
176   }
177
178   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_WIDTH);
179   if (tmp) {
180     spec->width = chxj_atoi(tmp); 
181   }
182   else {
183     spec->width = 640;
184   }
185
186   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_HEIGHT);
187   if (tmp) {
188     spec->heigh = chxj_atoi(tmp); 
189   }
190   else {
191     spec->heigh = 480; 
192   }
193
194   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_GIF);
195   if (STRCASEEQ('t','T',"true",tmp)) {
196     spec->available_gif = 1;
197   }
198   else {
199     spec->available_gif = 0;
200   }
201
202   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_JPEG);
203   if (STRCASEEQ('t','T',"true",tmp)) {
204     spec->available_jpeg = 1;
205   }
206   else {
207     spec->available_jpeg = 0;
208   }
209
210   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_PNG);
211   if (STRCASEEQ('t','T',"true",tmp)) {
212     spec->available_png = 1;
213   }
214   else {
215     spec->available_png = 0;
216   }
217
218   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_BMP2);
219   if (STRCASEEQ('t','T',"true",tmp)) {
220     spec->available_bmp2 = 1;
221   }
222   else {
223     spec->available_bmp2 = 0;
224   }
225
226   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_BMP4);
227   if (STRCASEEQ('t','T',"true",tmp)) {
228     spec->available_bmp4 = 1;
229   }
230   else {
231     spec->available_bmp4 = 0;
232   }
233
234   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_COLOR);
235   if (tmp) {
236     spec->color = chxj_atoi(tmp); 
237   }
238   else {
239     spec->color = 15680000; 
240   }
241
242   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_WP_WIDTH);
243   if (tmp) {
244     spec->wp_width = chxj_atoi(tmp); 
245   }
246   else {
247     spec->wp_width = 640; 
248   }
249
250   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_WP_HEIGHT);
251   if (tmp) {
252     spec->wp_heigh = chxj_atoi(tmp); 
253   }
254   else {
255     spec->wp_heigh = 480; 
256   }
257
258   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_CACHE);
259   if (tmp) {
260     spec->cache = chxj_atoi(tmp); 
261   }
262   else {
263     spec->cache = 10000000; 
264   }
265
266   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_DPI_WIDTH);
267   if (tmp) {
268     spec->dpi_width = chxj_atoi(tmp); 
269   }
270   else {
271     spec->dpi_width = 96;
272   }
273
274   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_DPI_HEIGHT);
275   if (tmp) {
276     spec->dpi_heigh = chxj_atoi(tmp); 
277   }
278   else {
279     spec->dpi_heigh = 96;
280   }
281
282   tmp = (char *)apr_table_get(r->headers_in, HTTP_X_CHXJ_EMOJI_TYPE);
283   if (tmp) {
284     spec->emoji_type = apr_pstrdup(r->pool, tmp);
285   }
286   else {
287     spec->emoji_type = apr_pstrdup(r->pool, "");
288   }
289
290   DBG(r, "REQ[%X] end chxj_get_device_env()", (unsigned int)(apr_size_t)r);
291   return spec;
292 }