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.
19 #include "chxj_img_conv_format.h"
20 #include "chxj_specified_device.h"
21 #include "chxj_str_util.h"
22 #include "chxj_qr_code.h"
23 #include "chxj_apply_convrule.h"
24 #include "qs_parse_string.h"
26 #include "http_core.h"
28 #include <wand/magick_wand.h>
31 #define EXIT_MAGICK_ERROR() \
33 char *description; ExceptionType severity; \
34 description=MagickGetException(magick_wand,&severity); \
35 ap_log_rerror(APLOG_MARK,APLOG_DEBUG, 0, r,"%s %s %d %s\n",__FILE__,(__func__),__LINE__,description); \
36 description=(char *) MagickRelinquishMemory(description); \
37 DestroyMagickWand(magick_wand); \
40 typedef enum img_conv_mode_t {
41 IMG_CONV_MODE_NORMAL = 0,
42 IMG_CONV_MODE_THUMBNAIL,
43 IMG_CONV_MODE_WALLPAPER,
47 /*----------------------------------------------------------------------------*/
48 /* User-Agent use flag */
49 /*----------------------------------------------------------------------------*/
50 typedef enum _ua_use_flag_t {
51 UA_USE=0, /* User-Agent is used. */
52 UA_IGN, /* User-Agent is disregarded. */
55 /*----------------------------------------------------------------------------*/
56 /* Request parameter maintenance structure */
57 /*----------------------------------------------------------------------------*/
58 typedef struct _query_string_param_t {
61 ua_use_flag_t ua_flag;
63 char* name; /* for EZGET */
64 long offset; /* for EZGET */
65 long count; /* for EZGET */
68 } query_string_param_t;
70 /*----------------------------------------------------------------------------*/
71 /* Device_spec when User-Agent is disregarded */
72 /*----------------------------------------------------------------------------*/
73 static device_table v_ignore_spec = {
94 /*----------------------------------------------------------------------------*/
95 /* CRC calculation table for AU */
96 /*----------------------------------------------------------------------------*/
97 static unsigned short AU_CRC_TBL[256] = {
98 0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
99 0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
100 0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,
101 0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
102 0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,
103 0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
104 0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,
105 0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
106 0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,
107 0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
108 0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,
109 0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
110 0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,
111 0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
112 0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,
113 0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
114 0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,
115 0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
116 0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,
117 0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
118 0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,
119 0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
120 0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,
121 0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
122 0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,
123 0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
124 0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,
125 0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
126 0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,
127 0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
128 0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,
129 0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0
132 /*----------------------------------------------------------------------------*/
133 /* Download page for AU */
134 /*----------------------------------------------------------------------------*/
135 static const char* HDML_FIRST_PAGE =
136 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
138 " <ACTION TYPE=ACCEPT TASK=GOSUB DEST=\"device:data/dnld?url=%s&name=%s%s&size=%ld&disposition=%s&title=%s\">\r\n"
142 static const char* HDML_SUCCESS_PAGE =
143 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
145 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
146 " \x83\x5f\x83\x45\x83\x93\x83\x8d\x81\x5b\x83\x68\x82\xc9\x90\xac\x8c\xf7\x82\xb5\x82\xdc\x82\xb5\x82\xbd\r\n"
150 static const char* HDML_FAIL_PAGE =
151 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
153 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
154 " \x83\x5f\x83\x45\x83\x93\x83\x8d\x81\x5b\x83\x68\x82\xc9\x8e\xb8\x94\x73\x82\xb5\x82\xdc\x82\xb5\x82\xbd\r\n"
158 /*----------------------------------------------------------------------------*/
159 /* Prototype declaration */
160 /*----------------------------------------------------------------------------*/
161 static char* s_create_workfile( request_rec*, mod_chxj_config* ,
163 query_string_param_t*);
164 static apr_status_t s_create_cache_file(request_rec* r,
168 query_string_param_t *qsp);
169 static apr_status_t s_send_cache_file( device_table* spec,
170 query_string_param_t* query_string,
172 const char* tmpfile);
173 static apr_status_t s_header_only_cache_file(
175 query_string_param_t* query_string,
177 const char* tmpfile);
178 static query_string_param_t* s_get_query_string_param(request_rec *r);
179 static unsigned short s_add_crc( const char* writedata,
180 apr_size_t witebyte);
181 static MagickWand* s_fixup_size(MagickWand* ,
184 query_string_param_t *qsp);
185 static MagickWand* s_fixup_color(MagickWand* magick_wand,
188 img_conv_mode_t mode);
189 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
190 request_rec* r, device_table* spec);
191 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
192 request_rec* r, device_table* spec);
193 static MagickWand* s_add_copyright(
194 MagickWand* magick_wand,
197 static char* s_create_blob_data(request_rec* r,
199 query_string_param_t *qsp,
203 static int s_img_conv_format_from_file(
205 mod_chxj_config* conf,
206 const char* user_agent,
207 query_string_param_t* qsp,
211 chxj_img_conv_format_handler(request_rec* r)
213 mod_chxj_config* conf;
214 query_string_param_t* qsp;
217 chxjconvrule_entry* entryp;
219 DBG(r, "start chxj_img_conv_format_handler()");
221 if ((*r->handler != 'c' && *r->handler != 'C')
222 || (strcasecmp(r->handler, "chxj-picture")
223 && strcasecmp(r->handler, "chxj-qrcode"))) {
224 DBG(r, "end chxj_img_conv_format_handler()");
228 qsp = s_get_query_string_param(r);
229 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
231 DBG(r, "end chxj_img_conv_format_handler() conf is null");
235 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF)
239 /*------------------------------------------------------------------------*/
240 /* get UserAgent from http header */
241 /*------------------------------------------------------------------------*/
242 /*--------------------------------------------------------------------------*/
243 /* User-Agent to spec */
244 /*--------------------------------------------------------------------------*/
245 if (qsp->user_agent) {
246 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
249 entryp = chxj_apply_convrule(r, conf->convrules);
250 if (entryp && entryp->user_agent) {
251 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
254 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
260 if (qsp->ua_flag == UA_IGN)
261 spec = &v_ignore_spec;
263 spec = chxj_specified_device(r, user_agent);
265 DBG1(r,"found device_name=[%s]", spec->device_name);
266 DBG1(r,"User-Agent=[%s]", user_agent);
268 if (spec->width == 0 || spec->heigh == 0)
271 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
277 * It converts it from ImageData corresponding to each model.
280 * @param src [i] It is former image binary data.
281 * @param len [i/o] It is length of former image binary data.
284 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
286 mod_chxj_config* conf;
287 query_string_param_t* qsp;
292 chxjconvrule_entry* entryp;
294 DBG(r, "start chxj_exchange_image()");
296 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
298 DBG(r, "end chxj_exchnage_image() already convert.");
303 qsp = s_get_query_string_param(r);
304 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
306 DBG(r, "end chxj_exchange_image()");
310 /*--------------------------------------------------------------------------*/
311 /* User-Agent to spec */
312 /*--------------------------------------------------------------------------*/
313 if (qsp->user_agent) {
314 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
317 entryp = chxj_apply_convrule(r, conf->convrules);
318 if (entryp && entryp->user_agent) {
319 user_agent = (char*)apr_table_get(r->headers_in, "CHXJ_HTTP_USER_AGENT");
322 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
326 if (qsp->ua_flag == UA_IGN)
327 spec = &v_ignore_spec;
329 spec = chxj_specified_device(r, user_agent);
331 DBG1(r,"found device_name=[%s]", spec->device_name);
332 DBG1(r, "User-Agent=[%s]", user_agent);
334 if (spec->width == 0 || spec->heigh == 0)
337 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
341 DBG(r, "end chxj_exchange_image()");
347 s_img_conv_format_from_file(
349 mod_chxj_config* conf,
350 const char* user_agent,
351 query_string_param_t* qsp,
356 apr_finfo_t cache_st;
359 /*--------------------------------------------------------------------------*/
360 /* Create Workfile Name */
361 /*--------------------------------------------------------------------------*/
362 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
363 DBG1(r,"workfile=[%s]", tmpfile);
365 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
366 if (rv != APR_SUCCESS)
367 return HTTP_NOT_FOUND;
370 DBG1(r,"found [%s]", r->filename);
371 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
372 DBG1(r,"found [%s]", r->filename);
374 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
375 /*------------------------------------------------------------------------*/
376 /* It tries to make the cash file when it doesn't exist or there is */
377 /* change time later since the making time of the cash file. */
378 /*------------------------------------------------------------------------*/
379 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
384 DBG1(r,"color=[%d]", spec->color);
385 if (! r->header_only) {
386 rv = s_send_cache_file(spec, qsp,r, tmpfile);
391 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
395 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
397 DBG(r,"end chxj_img_conv_format");
404 s_create_cache_file(request_rec* r,
408 query_string_param_t *qsp)
412 apr_size_t writebyte;
414 img_conv_mode_t mode = qsp->mode;
416 char* writedata = NULL;
417 char* readdata = NULL;
422 MagickWand* magick_wand;
424 if ((*r->handler == 'c' || *r->handler == 'C')
425 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
426 /*------------------------------------------------------------------------*/
427 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
428 /*------------------------------------------------------------------------*/
434 memset(&doc, 0, sizeof(Doc));
435 memset(&qrcode, 0, sizeof(qr_code_t));
437 doc.parse_mode = PARSE_MODE_CHTML;
441 qs_init_malloc(&doc);
443 root = qs_parse_file(&doc, r->filename);
445 chxj_qrcode_node_to_qrcode(&qrcode, root);
447 qs_all_free(&doc,QX_LOGMARK);
449 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
451 ERR(r, "qrcode create failed.");
456 /*------------------------------------------------------------------------*/
457 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
458 /*------------------------------------------------------------------------*/
459 rv = apr_file_open(&fin,
461 APR_READ|APR_BINARY ,
464 if (rv != APR_SUCCESS) {
465 DBG1(r,"file open failed.[%s]", r->filename);
466 return HTTP_NOT_FOUND;
469 readdata = apr_palloc(r->pool, st->size);
470 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
471 if (rv != APR_SUCCESS || readbyte != st->size) {
472 DBG1(r,"file read failed.[%s]", r->filename);
475 return HTTP_NOT_FOUND;
478 DBG(r,"start img convert");
481 magick_wand = NewMagickWand();
482 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
484 return HTTP_NOT_FOUND;
488 * The size of the image is changed.
490 DBG(r,"call s_fixup_size()");
492 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
493 return HTTP_NOT_FOUND;
496 * The colors of the image is changed.
498 DBG(r,"call s_fixup_color()");
500 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
501 return HTTP_NOT_FOUND;
504 * DEPTH of the image is changed.
506 DBG(r,"call s_fixup_depth()");
508 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
509 return HTTP_NOT_FOUND;
513 DBG(r,"start convert and compression");
515 if (spec->available_jpeg) {
516 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
518 return HTTP_NOT_FOUND;
521 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
523 return HTTP_NOT_FOUND;
526 if (MagickStripImage(magick_wand) == MagickFalse) {
528 return HTTP_NOT_FOUND;
531 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
532 return HTTP_NOT_FOUND;
534 r->content_type = apr_psprintf(r->pool, "image/jpeg");
535 DBG(r,"convert to jpg");
538 if (spec->available_png) {
540 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
542 return HTTP_NOT_FOUND;
545 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
547 return HTTP_NOT_FOUND;
550 if (MagickStripImage(magick_wand) == MagickFalse) {
552 return HTTP_NOT_FOUND;
555 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
556 return HTTP_NOT_FOUND;
558 r->content_type = apr_psprintf(r->pool, "image/png");
559 DBG(r, "convert to png");
562 if (spec->available_gif) {
564 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
566 return HTTP_NOT_FOUND;
569 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
571 return HTTP_NOT_FOUND;
574 if (MagickStripImage(magick_wand) == MagickFalse) {
576 return HTTP_NOT_FOUND;
579 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
580 return HTTP_NOT_FOUND;
582 r->content_type = apr_psprintf(r->pool, "image/gif");
584 DBG(r,"convert to gif");
587 if (spec->available_bmp2 || spec->available_bmp4) {
589 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
591 return HTTP_NOT_FOUND;
594 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
596 return HTTP_NOT_FOUND;
599 if (MagickStripImage(magick_wand) == MagickFalse) {
601 return HTTP_NOT_FOUND;
604 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
605 return HTTP_NOT_FOUND;
607 r->content_type = apr_psprintf(r->pool, "image/bmp");
609 DBG(r, "convert to bmp(unsupported)");
613 * Add Comment (Copyright and so on.)
615 DBG(r, "call s_add_copyright()");
617 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
618 return HTTP_NOT_FOUND;
620 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
623 DestroyMagickWand(magick_wand);
624 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
626 return HTTP_INTERNAL_SERVER_ERROR;
629 DBG(r, "end convert and compression");
632 rv = apr_file_open(&fout, tmpfile,
633 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
635 if (rv != APR_SUCCESS) {
636 DestroyMagickWand(magick_wand);
637 ERR1(r,"file open error.[%s]", tmpfile);
638 return HTTP_INTERNAL_SERVER_ERROR;
641 rv = apr_file_write(fout, (void*)writedata, &writebyte);
642 if (rv != APR_SUCCESS) {
643 DestroyMagickWand(magick_wand);
644 apr_file_close(fout);
645 return HTTP_INTERNAL_SERVER_ERROR;
649 * CRC is added for AU for EzGET.
651 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
652 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
654 crc = s_add_crc(writedata, writebyte);
656 rv = apr_file_putc((crc >> 8) & 0xff, fout);
657 if (rv != APR_SUCCESS) {
658 DestroyMagickWand(magick_wand);
659 return HTTP_INTERNAL_SERVER_ERROR;
662 rv = apr_file_putc( crc & 0xff, fout);
663 if (rv != APR_SUCCESS) {
664 DestroyMagickWand(magick_wand);
665 return HTTP_INTERNAL_SERVER_ERROR;
669 DestroyMagickWand(magick_wand);
671 rv = apr_file_close(fout);
672 if (rv != APR_SUCCESS) {
673 DBG1(r,"file write error.[%s]", tmpfile);
674 return HTTP_INTERNAL_SERVER_ERROR;
682 s_create_blob_data(request_rec* r,
684 query_string_param_t *qsp,
688 apr_size_t writebyte;
690 img_conv_mode_t mode = qsp->mode;
692 char* writedata = NULL;
695 MagickWand* magick_wand;
697 magick_wand = NewMagickWand();
699 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
705 * The size of the image is changed.
707 DBG(r, "call s_fixup_size()");
709 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
713 * The colors of the image is changed.
715 DBG(r, "call s_fixup_color()");
717 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
721 * DEPTH of the image is changed.
724 DBG(r,"call s_fixup_depth()");
726 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
731 DBG(r,"start convert and compression");
733 if (spec->available_jpeg) {
734 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
739 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
744 if (MagickStripImage(magick_wand) == MagickFalse) {
749 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
752 r->content_type = apr_psprintf(r->pool, "image/jpeg");
754 DBG(r, "convert to jpg");
757 if (spec->available_png) {
758 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
763 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
768 if (MagickStripImage(magick_wand) == MagickFalse) {
773 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
776 r->content_type = apr_psprintf(r->pool, "image/png");
778 DBG(r,"convert to png");
781 if (spec->available_gif) {
783 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
788 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
793 if (MagickStripImage(magick_wand) == MagickFalse) {
798 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
801 r->content_type = apr_psprintf(r->pool, "image/gif");
803 DBG(r,"convert to gif");
806 if (spec->available_bmp2 || spec->available_bmp4) {
807 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
812 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
817 if (MagickStripImage(magick_wand) == MagickFalse) {
822 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
825 r->content_type = apr_psprintf(r->pool, "image/bmp");
827 DBG(r,"convert to bmp(unsupported)");
829 /*--------------------------------------------------------------------------*/
830 /* Add Comment (Copyright and so on.) */
831 /*--------------------------------------------------------------------------*/
832 DBG(r,"call s_add_copyright()");
834 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
837 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
840 DestroyMagickWand(magick_wand);
841 DBG(r,"convert failure to Jpeg ");
845 DBG(r,"end convert and compression");
849 dst = apr_palloc(r->pool, writebyte+2);
851 memcpy(dst, writedata, writebyte);
852 /*--------------------------------------------------------------------------*/
853 /* CRC is added for AU for EzGET. */
854 /*--------------------------------------------------------------------------*/
855 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
856 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
857 crc = s_add_crc(writedata, writebyte);
858 dst[writebyte + 0] = (crc >> 8) & 0xff;
859 dst[writebyte + 1] = (crc ) & 0xff;
863 DestroyMagickWand(magick_wand);
870 s_fixup_size(MagickWand* magick_wand,
873 query_string_param_t *qsp)
875 img_conv_mode_t mode = qsp->mode;
883 oldw = MagickGetImageWidth(magick_wand);
884 oldh = MagickGetImageHeight(magick_wand);
886 DBG1(r,"detect width=[%d]", oldw);
887 DBG1(r,"detect heigh=[%d]", oldh);
892 DBG1(r,"detect spec width=[%d]", spec->width);
893 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
895 c_width = spec->width;
896 c_heigh = spec->heigh;
899 case IMG_CONV_MODE_THUMBNAIL:
901 DBG(r,"**** detect thumbnail mode ****");
903 if (neww > c_width) {
904 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
905 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
907 if (newh > c_heigh) {
908 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
909 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
912 neww = (int)((double)(neww / 3) * 0.8);
913 newh = (int)((double)(newh / 3) * 0.8);
916 case IMG_CONV_MODE_WALLPAPER:
917 case IMG_CONV_MODE_EZGET:
919 DBG(r,"**** detect wallpaper mode ****");
921 if (spec->wp_width && spec->wp_heigh) {
922 c_width = spec->wp_width;
923 c_heigh = spec->wp_heigh;
926 DBG(r,"calc new width and height");
928 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
929 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
931 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
936 DBG(r,"**** detect normal mode ****");
938 if (qsp->ua_flag != UA_IGN) {
939 if (neww > c_width) {
940 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
941 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
944 if (newh > c_heigh) {
945 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
946 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
952 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
953 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
955 MagickResetIterator(magick_wand);
957 while (MagickNextImage(magick_wand) != MagickFalse) {
959 case IMG_CONV_MODE_WALLPAPER:
960 case IMG_CONV_MODE_EZGET:
962 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
967 if (MagickCropImage(magick_wand,
968 (unsigned long)c_width,
969 (unsigned long)c_heigh,
970 (long)((neww - c_width) / 2),
971 (long)((newh - c_heigh) / 2)) == MagickFalse) {
977 case IMG_CONV_MODE_NORMAL:
979 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
983 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
988 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
995 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1000 if (MagickSetImageResolution(magick_wand,
1001 (double)spec->dpi_width,
1002 (double)spec->dpi_heigh) == MagickFalse) {
1003 EXIT_MAGICK_ERROR();
1007 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1008 EXIT_MAGICK_ERROR();
1017 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t mode)
1019 DBG(r,"start chxj_fixup_clor()");
1021 if (spec->color >= 256) {
1023 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1025 if (MagickQuantizeImage(magick_wand,
1030 0) == MagickFalse) {
1031 EXIT_MAGICK_ERROR();
1035 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1039 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1041 if (MagickQuantizeImage(magick_wand,
1046 0) == MagickFalse) {
1047 EXIT_MAGICK_ERROR();
1051 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1055 DBG(r,"end chxj_fixup_clor()");
1063 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1065 if (spec->color == 15680000) {
1066 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1067 EXIT_MAGICK_ERROR();
1072 if (spec->color == 262144) {
1073 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1074 EXIT_MAGICK_ERROR();
1079 if (spec->color == 65536) {
1080 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1081 EXIT_MAGICK_ERROR();
1086 if (spec->color == 4096) {
1087 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1088 EXIT_MAGICK_ERROR();
1093 if (spec->color == 256) {
1094 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1095 EXIT_MAGICK_ERROR();
1100 if (spec->color == 4) {
1101 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1102 EXIT_MAGICK_ERROR();
1107 if (spec->color == 2) {
1108 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1109 EXIT_MAGICK_ERROR();
1119 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1121 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1123 if (conf->image_copyright) {
1125 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1127 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1128 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1129 if (MagickCommentImage(magick_wand,
1130 apr_psprintf(r->pool,
1132 conf->image_copyright)) == MagickFalse)
1136 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1137 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1138 if (MagickCommentImage(magick_wand,
1139 apr_psprintf(r->pool,
1140 "kddi_copyright=on,%s",
1141 conf->image_copyright)) == MagickFalse)
1145 if (MagickCommentImage(magick_wand,
1146 apr_psprintf(r->pool,
1148 conf->image_copyright)) == MagickFalse)
1153 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1159 EXIT_MAGICK_ERROR();
1164 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1166 MagickBooleanType status;
1167 unsigned long quality = 70;
1168 apr_size_t writebyte = 0;
1170 apr_size_t prev_size = 0;
1171 int revers_flag = 0;
1173 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1174 prev_size = writebyte;
1177 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1178 EXIT_MAGICK_ERROR();
1182 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1183 if (writebyte >= prev_size || revers_flag) {
1184 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1187 if (quality > 100) {
1188 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1189 EXIT_MAGICK_ERROR();
1194 prev_size = writebyte;
1198 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1200 if (spec->cache == 0)
1203 if (writebyte <= spec->cache)
1208 if (quality == 0 || quality > 100)
1216 && writebyte > spec->cache) {
1217 unsigned long now_color = spec->color;
1218 unsigned long depth = 0;
1221 case 2: depth = 1; break;
1222 case 4: now_color = 2; depth = 1; break;
1223 case 8: now_color = 4; depth = 2; break;
1224 case 16: now_color = 8; depth = 3; break;
1225 case 256: now_color = 16; depth = 4; break;
1226 case 4096: now_color = 256; depth = 8; break;
1227 case 65536: now_color = 4096; depth = 12; break;
1228 case 262144: now_color = 65536; depth = 16; break;
1229 case 15680000: now_color = 262144; depth = 18; break;
1235 if (now_color <= 2) break;
1237 if (now_color >= 8) {
1238 status = MagickQuantizeImage(magick_wand,
1246 status = MagickQuantizeImage(magick_wand,
1252 MagickSetImageType(magick_wand, GrayscaleType);
1254 if (status == MagickFalse) {
1255 EXIT_MAGICK_ERROR();
1259 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1260 EXIT_MAGICK_ERROR();
1264 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1266 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, writebyte);
1268 /* Once per request */
1271 while(now_color > 2);
1278 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1283 apr_size_t sendbyte;
1284 char* contentLength;
1286 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1287 if (rv != APR_SUCCESS)
1288 return HTTP_NOT_FOUND;
1290 DBG1(r, "mode:[%d]", query_string->mode);
1291 DBG1(r, "name:[%s]", query_string->name);
1292 DBG1(r, "offset:[%ld]", query_string->offset);
1293 DBG1(r, "count:[%ld]", query_string->count);
1295 if (spec->available_jpeg) {
1296 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1299 if (spec->available_png) {
1300 r->content_type = apr_psprintf(r->pool, "image/png");
1303 if (spec->available_gif) {
1304 r->content_type = apr_psprintf(r->pool, "image/gif");
1307 if (spec->available_bmp2 || spec->available_bmp4) {
1308 r->content_type = apr_psprintf(r->pool, "image/bmp");
1311 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1312 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1313 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1315 DBG1(r,"Content-Length:[%d]", (int)st.size);
1317 rv = apr_file_open(&fout, tmpfile,
1318 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1319 if (rv != APR_SUCCESS) {
1320 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1321 return HTTP_NOT_FOUND;
1324 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1325 apr_file_close(fout);
1327 DBG1(r, "send file data[%d]byte", sendbyte);
1330 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1331 char* name = apr_pstrdup(r->pool, basename(r->filename));
1332 name[strlen(name)-4] = 0;
1333 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1335 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1336 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1339 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1340 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1341 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1344 if (strcasecmp(r->content_type, "image/png") == 0) {
1345 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1346 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1349 if (strcasecmp(r->content_type, "image/gif") == 0) {
1350 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1351 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1355 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1356 if (query_string->count == -1 && query_string->offset == -1) {
1357 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1358 ap_rprintf(r, HDML_SUCCESS_PAGE);
1362 if (query_string->count == -2 && query_string->offset == -1) {
1363 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1364 ap_rprintf(r, HDML_FAIL_PAGE);
1368 ap_set_content_type(r, "application/x-up-download");
1369 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1370 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1372 DBG1(r, "Content-Length:[%d]", (int)st.size);
1374 rv = apr_file_open(&fout, tmpfile,
1375 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1377 if (rv != APR_SUCCESS) {
1378 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1379 return HTTP_NOT_FOUND;
1382 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1383 apr_file_close(fout);
1385 DBG1(r, "send file data[%d]byte", sendbyte);
1393 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1397 char* contentLength;
1399 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1400 if (rv != APR_SUCCESS)
1401 return HTTP_NOT_FOUND;
1403 DBG1(r, "mode:[%d]", query_string->mode);
1404 DBG1(r, "name:[%s]", query_string->name);
1405 DBG1(r, "offset:[%ld]", query_string->offset);
1406 DBG1(r, "count:[%ld]", query_string->count);
1408 if (spec->available_jpeg) {
1409 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1412 if (spec->available_png) {
1413 r->content_type = apr_psprintf(r->pool, "image/png");
1416 if (spec->available_gif) {
1417 r->content_type = apr_psprintf(r->pool, "image/gif");
1420 if (spec->available_bmp2 || spec->available_bmp4) {
1421 r->content_type = apr_psprintf(r->pool, "image/bmp");
1424 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1425 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1426 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1428 DBG1(r,"Content-Length:[%d]", (int)st.size);
1431 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1432 char* name = apr_pstrdup(r->pool, basename(r->filename));
1433 name[strlen(name)-4] = 0;
1434 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1436 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1439 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1440 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1443 if (strcasecmp(r->content_type, "image/png") == 0) {
1444 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1447 if (strcasecmp(r->content_type, "image/gif") == 0) {
1448 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1452 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1453 if (query_string->count == -1 && query_string->offset == -1) {
1454 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1457 if (query_string->count == -2 && query_string->offset == -1) {
1458 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1461 ap_set_content_type(r, "application/x-up-download");
1462 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1463 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1465 DBG1(r, "Content-Length:[%d]", (int)st.size);
1477 mod_chxj_config* conf,
1478 const char* user_agent,
1479 query_string_param_t *qsp)
1484 char* w = apr_palloc(r->pool, 256);
1488 switch (qsp->mode) {
1489 case IMG_CONV_MODE_THUMBNAIL:
1490 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1491 DBG1(r, "mode=thumbnail [%s]", fname);
1493 case IMG_CONV_MODE_WALLPAPER:
1494 case IMG_CONV_MODE_EZGET:
1495 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1496 DBG1(r, "mode=WallPaper [%s]", fname);
1498 case IMG_CONV_MODE_NORMAL:
1501 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1504 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1507 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1509 DBG1(r,"mode=normal [%s]", fname);
1512 if (qsp->ua_flag == UA_IGN) {
1513 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1516 len = strlen(fname);
1518 for (ii=0; ii<len; ii++) {
1519 if (fname[ii] == '/'
1523 || fname[ii] == ')') {
1527 w[jj++] = fname[ii];
1531 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1534 static unsigned short
1535 s_add_crc(const char* writedata, apr_size_t writebyte)
1537 unsigned short crc = 0xffff;
1541 for(ii=0;ii<writebyte;ii++) {
1543 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1549 chxj_trans_name(request_rec *r)
1556 mod_chxj_config* conf;
1564 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1570 int do_ext_check = TRUE;
1571 int next_ok = FALSE;
1573 DBG(r, "start chxj_trans_name()");
1575 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1578 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1582 if (conf->image != CHXJ_IMG_ON) {
1583 DBG(r, "end chxj_trans_name() conf not found");
1588 DBG1(r,"Match URI[%s]", r->uri);
1591 if (r->filename == NULL)
1592 r->filename = apr_pstrdup(r->pool, r->uri);
1595 if ((idx = strchr(r->filename, ':')) != NULL)
1596 filename_sv = idx+1;
1598 filename_sv = r->filename;
1600 DBG1(r,"r->filename[%s]", filename_sv);
1602 ccp = ap_document_root(r);
1604 return HTTP_INTERNAL_SERVER_ERROR;
1606 docroot = apr_pstrdup(r->pool, ccp);
1607 len = strlen(docroot);
1609 if (docroot[len-1] == '/')
1610 docroot[len-1] = '\0';
1614 && *filename_sv == *r->server->path
1615 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1616 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1618 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1620 DBG1(r,"URI[%s]", filename_sv);
1622 do_ext_check = TRUE;
1623 for (ii=0; ii<7-1; ii++) {
1624 char* pos = strrchr(filename_sv, '.');
1626 if (strcasecmp(pos, ext[ii]) == 0) {
1627 do_ext_check = FALSE;
1628 fname = apr_psprintf(r->pool, "%s", filename_sv);
1635 for (ii=0; ii<7; ii++) {
1636 if (strlen(ext[ii]) == 0) {
1637 fname = apr_psprintf(r->pool, "%s", filename_sv);
1640 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1642 DBG1(r,"search [%s]", fname);
1644 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1645 if (rv == APR_SUCCESS) {
1646 if (st.filetype != APR_DIR)
1653 if (fname == NULL) {
1654 DBG1(r,"NotFound [%s]", r->filename);
1657 for (ii=0; ii<7-1; ii++) {
1658 char* pos = strrchr(fname, '.');
1660 if (strcasecmp(pos, ext[ii]) == 0) {
1668 DBG1(r,"NotFound [%s]", r->filename);
1672 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1673 DBG1(r,"Found [%s]", fname);
1675 r->filename = apr_psprintf(r->pool, "%s", fname);
1677 if (strcasecmp("qrc", ext[ii]) == 0)
1678 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1680 r->handler = apr_psprintf(r->pool, "chxj-picture");
1682 DBG(r, "end chxj_trans_name()");
1689 * It converts it from QUERYSTRING.
1693 static query_string_param_t*
1694 s_get_query_string_param(request_rec *r)
1702 query_string_param_t* param;
1704 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1705 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1706 param->mode = IMG_CONV_MODE_NORMAL;
1707 param->user_agent = NULL;
1708 param->ua_flag = UA_USE;
1715 if (s == NULL) return param;
1718 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1721 name = apr_strtok(pair, "=", &vstate);
1722 value = apr_strtok(NULL, "=", &vstate);
1727 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1732 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1733 param->mode = IMG_CONV_MODE_THUMBNAIL;
1738 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1739 param->mode = IMG_CONV_MODE_WALLPAPER;
1744 if (strcasecmp(value, "EZGET") == 0)
1745 param->mode = IMG_CONV_MODE_EZGET;
1755 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1756 ap_unescape_url(value);
1758 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1759 param->ua_flag = UA_IGN;
1761 param->user_agent = apr_pstrdup(r->pool, value);
1767 if (value && strcasecmp(name, "name") == 0)
1768 param->name = apr_pstrdup(r->pool, value);
1773 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1774 param->offset = chxj_atoi(value);
1780 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1781 param->count = chxj_atoi(value);
1786 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1787 param->width = chxj_atoi(value);
1792 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1793 param->height = chxj_atoi(value);
1801 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1802 param->mode = IMG_CONV_MODE_WALLPAPER;