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 "chxj_url_encode.h"
25 #include "qs_parse_string.h"
27 #include "http_core.h"
29 #include <wand/magick_wand.h>
32 #define EXIT_MAGICK_ERROR() \
34 char *description; ExceptionType severity; \
35 description=MagickGetException(magick_wand,&severity); \
36 ap_log_rerror(APLOG_MARK,APLOG_DEBUG, 0, r,"%s %s %d %s\n",__FILE__,(__func__),__LINE__,description); \
37 description=(char *) MagickRelinquishMemory(description); \
38 DestroyMagickWand(magick_wand); \
41 typedef enum img_conv_mode_t {
42 IMG_CONV_MODE_NORMAL = 0,
43 IMG_CONV_MODE_THUMBNAIL,
44 IMG_CONV_MODE_WALLPAPER,
48 /*----------------------------------------------------------------------------*/
49 /* User-Agent use flag */
50 /*----------------------------------------------------------------------------*/
51 typedef enum _ua_use_flag_t {
52 UA_USE=0, /* User-Agent is used. */
53 UA_IGN, /* User-Agent is disregarded. */
56 /*----------------------------------------------------------------------------*/
57 /* Request parameter maintenance structure */
58 /*----------------------------------------------------------------------------*/
59 typedef struct query_string_param_t query_string_param_t;
61 struct query_string_param_t {
64 ua_use_flag_t ua_flag;
66 char* name; /* for EZGET */
67 long offset; /* for EZGET */
68 long count; /* for EZGET */
73 /*----------------------------------------------------------------------------*/
74 /* Device_spec when User-Agent is disregarded */
75 /*----------------------------------------------------------------------------*/
76 static device_table v_ignore_spec = {
97 /*----------------------------------------------------------------------------*/
98 /* CRC calculation table for AU */
99 /*----------------------------------------------------------------------------*/
100 static unsigned short AU_CRC_TBL[256] = {
101 0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
102 0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
103 0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,
104 0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
105 0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,
106 0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
107 0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,
108 0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
109 0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,
110 0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
111 0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,
112 0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
113 0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,
114 0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
115 0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,
116 0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
117 0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,
118 0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
119 0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,
120 0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
121 0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,
122 0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
123 0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,
124 0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
125 0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,
126 0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
127 0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,
128 0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
129 0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,
130 0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
131 0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,
132 0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0
135 /*----------------------------------------------------------------------------*/
136 /* Download page for AU */
137 /*----------------------------------------------------------------------------*/
138 static const char* HDML_FIRST_PAGE =
139 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
141 " <ACTION TYPE=ACCEPT TASK=GOSUB DEST=\"device:data/dnld?url=%s&name=%s%s&size=%ld&disposition=%s&title=%s\">\r\n"
145 static const char* HDML_SUCCESS_PAGE =
146 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
148 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
149 " \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"
153 static const char* HDML_FAIL_PAGE =
154 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
156 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
157 " \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"
161 /*----------------------------------------------------------------------------*/
162 /* Prototype declaration */
163 /*----------------------------------------------------------------------------*/
164 static char* s_create_workfile( request_rec*,
167 query_string_param_t*);
169 static apr_status_t s_create_cache_file(request_rec* r,
173 query_string_param_t* qsp);
175 static apr_status_t s_send_cache_file( device_table* spec,
176 query_string_param_t* query_string,
178 const char* tmpfile);
180 static apr_status_t s_header_only_cache_file(device_table* spec,
181 query_string_param_t* query_string,
183 const char* tmpfile);
185 static query_string_param_t* s_get_query_string_param(request_rec *r);
186 static unsigned short s_add_crc( const char* writedata,
187 apr_size_t witebyte);
188 static MagickWand* s_fixup_size(MagickWand* ,
191 query_string_param_t *qsp);
192 static MagickWand* s_fixup_color(MagickWand* magick_wand,
195 img_conv_mode_t mode);
196 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
197 request_rec* r, device_table* spec);
198 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
199 request_rec* r, device_table* spec);
200 static MagickWand* s_add_copyright(
201 MagickWand* magick_wand,
204 static char* s_create_blob_data(request_rec* r,
206 query_string_param_t *qsp,
210 static int s_img_conv_format_from_file(
212 mod_chxj_config* conf,
213 const char* user_agent,
214 query_string_param_t* qsp,
218 chxj_img_conv_format_handler(request_rec* r)
220 mod_chxj_config* conf;
221 query_string_param_t* qsp;
224 chxjconvrule_entry* entryp;
226 DBG(r, "start chxj_img_conv_format_handler()");
228 if ((*r->handler != 'c' && *r->handler != 'C')
229 || (strcasecmp(r->handler, "chxj-picture")
230 && strcasecmp(r->handler, "chxj-qrcode"))) {
231 DBG(r, "end chxj_img_conv_format_handler()");
235 qsp = s_get_query_string_param(r);
236 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
238 DBG(r, "end chxj_img_conv_format_handler() conf is null");
242 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF)
246 /*------------------------------------------------------------------------*/
247 /* get UserAgent from http header */
248 /*------------------------------------------------------------------------*/
249 /*--------------------------------------------------------------------------*/
250 /* User-Agent to spec */
251 /*--------------------------------------------------------------------------*/
252 if (qsp->user_agent) {
253 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
256 entryp = chxj_apply_convrule(r, conf->convrules);
257 if (entryp && entryp->user_agent) {
258 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
261 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
267 if (qsp->ua_flag == UA_IGN)
268 spec = &v_ignore_spec;
270 spec = chxj_specified_device(r, user_agent);
272 DBG1(r,"found device_name=[%s]", spec->device_name);
273 DBG1(r,"User-Agent=[%s]", user_agent);
275 if (spec->width == 0 || spec->heigh == 0)
278 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
284 * It converts it from ImageData corresponding to each model.
287 * @param src [i] It is former image binary data.
288 * @param len [i/o] It is length of former image binary data.
291 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
293 mod_chxj_config* conf;
294 query_string_param_t* qsp;
299 chxjconvrule_entry* entryp;
301 DBG(r, "start chxj_exchange_image()");
303 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
305 DBG(r, "end chxj_exchnage_image() already convert.");
310 qsp = s_get_query_string_param(r);
311 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
313 DBG(r, "end chxj_exchange_image()");
317 /*--------------------------------------------------------------------------*/
318 /* User-Agent to spec */
319 /*--------------------------------------------------------------------------*/
320 if (qsp->user_agent) {
321 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
324 entryp = chxj_apply_convrule(r, conf->convrules);
325 if (entryp && entryp->user_agent) {
326 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
329 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
333 if (qsp->ua_flag == UA_IGN)
334 spec = &v_ignore_spec;
336 spec = chxj_specified_device(r, user_agent);
338 DBG1(r,"found device_name=[%s]", spec->device_name);
339 DBG1(r, "User-Agent=[%s]", user_agent);
341 if (spec->width == 0 || spec->heigh == 0)
344 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
348 DBG(r, "end chxj_exchange_image()");
354 s_img_conv_format_from_file(
356 mod_chxj_config* conf,
357 const char* user_agent,
358 query_string_param_t* qsp,
363 apr_finfo_t cache_st;
366 /*--------------------------------------------------------------------------*/
367 /* Create Workfile Name */
368 /*--------------------------------------------------------------------------*/
369 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
370 DBG1(r,"workfile=[%s]", tmpfile);
372 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
373 if (rv != APR_SUCCESS)
374 return HTTP_NOT_FOUND;
377 DBG1(r,"found [%s]", r->filename);
378 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
379 DBG1(r,"found [%s]", r->filename);
381 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
382 /*------------------------------------------------------------------------*/
383 /* It tries to make the cash file when it doesn't exist or there is */
384 /* change time later since the making time of the cash file. */
385 /*------------------------------------------------------------------------*/
386 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
391 DBG1(r,"color=[%d]", spec->color);
392 if (! r->header_only) {
393 rv = s_send_cache_file(spec, qsp,r, tmpfile);
398 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
402 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
404 DBG(r,"end chxj_img_conv_format");
411 s_create_cache_file(request_rec* r,
415 query_string_param_t *qsp)
419 apr_size_t writebyte;
421 img_conv_mode_t mode = qsp->mode;
423 char* writedata = NULL;
424 char* readdata = NULL;
429 MagickWand* magick_wand;
431 if ((*r->handler == 'c' || *r->handler == 'C')
432 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
433 /*------------------------------------------------------------------------*/
434 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
435 /*------------------------------------------------------------------------*/
441 memset(&doc, 0, sizeof(Doc));
442 memset(&qrcode, 0, sizeof(qr_code_t));
444 doc.parse_mode = PARSE_MODE_CHTML;
448 qs_init_malloc(&doc);
450 root = qs_parse_file(&doc, r->filename);
452 chxj_qrcode_node_to_qrcode(&qrcode, root);
454 qs_all_free(&doc,QX_LOGMARK);
456 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
458 ERR(r, "qrcode create failed.");
463 /*------------------------------------------------------------------------*/
464 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
465 /*------------------------------------------------------------------------*/
466 rv = apr_file_open(&fin,
468 APR_READ|APR_BINARY ,
471 if (rv != APR_SUCCESS) {
472 DBG1(r,"file open failed.[%s]", r->filename);
473 return HTTP_NOT_FOUND;
476 readdata = apr_palloc(r->pool, st->size);
477 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
478 if (rv != APR_SUCCESS || readbyte != st->size) {
479 DBG1(r,"file read failed.[%s]", r->filename);
482 return HTTP_NOT_FOUND;
485 DBG(r,"start img convert");
488 magick_wand = NewMagickWand();
489 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
491 return HTTP_NOT_FOUND;
495 * The size of the image is changed.
497 DBG(r,"call s_fixup_size()");
499 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
500 return HTTP_NOT_FOUND;
503 * The colors of the image is changed.
505 DBG(r,"call s_fixup_color()");
507 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
508 return HTTP_NOT_FOUND;
511 * DEPTH of the image is changed.
513 DBG(r,"call s_fixup_depth()");
515 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
516 return HTTP_NOT_FOUND;
520 DBG(r,"start convert and compression");
522 if (spec->available_jpeg) {
523 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
525 return HTTP_NOT_FOUND;
528 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
530 return HTTP_NOT_FOUND;
533 if (MagickStripImage(magick_wand) == MagickFalse) {
535 return HTTP_NOT_FOUND;
538 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
539 return HTTP_NOT_FOUND;
541 r->content_type = apr_psprintf(r->pool, "image/jpeg");
542 DBG(r,"convert to jpg");
545 if (spec->available_png) {
547 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
549 return HTTP_NOT_FOUND;
552 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
554 return HTTP_NOT_FOUND;
557 if (MagickStripImage(magick_wand) == MagickFalse) {
559 return HTTP_NOT_FOUND;
562 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
563 return HTTP_NOT_FOUND;
565 r->content_type = apr_psprintf(r->pool, "image/png");
566 DBG(r, "convert to png");
569 if (spec->available_gif) {
571 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
573 return HTTP_NOT_FOUND;
576 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
578 return HTTP_NOT_FOUND;
581 if (MagickStripImage(magick_wand) == MagickFalse) {
583 return HTTP_NOT_FOUND;
586 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
587 return HTTP_NOT_FOUND;
589 r->content_type = apr_psprintf(r->pool, "image/gif");
591 DBG(r,"convert to gif");
594 if (spec->available_bmp2 || spec->available_bmp4) {
596 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
598 return HTTP_NOT_FOUND;
601 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
603 return HTTP_NOT_FOUND;
606 if (MagickStripImage(magick_wand) == MagickFalse) {
608 return HTTP_NOT_FOUND;
611 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
612 return HTTP_NOT_FOUND;
614 r->content_type = apr_psprintf(r->pool, "image/bmp");
616 DBG(r, "convert to bmp(unsupported)");
620 * Add Comment (Copyright and so on.)
622 DBG(r, "call s_add_copyright()");
624 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
625 return HTTP_NOT_FOUND;
627 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
630 DestroyMagickWand(magick_wand);
631 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
633 return HTTP_INTERNAL_SERVER_ERROR;
636 DBG(r, "end convert and compression");
639 rv = apr_file_open(&fout, tmpfile,
640 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
642 if (rv != APR_SUCCESS) {
643 DestroyMagickWand(magick_wand);
644 ERR1(r,"file open error.[%s]", tmpfile);
645 return HTTP_INTERNAL_SERVER_ERROR;
648 rv = apr_file_write(fout, (void*)writedata, &writebyte);
649 if (rv != APR_SUCCESS) {
650 DestroyMagickWand(magick_wand);
651 apr_file_close(fout);
652 return HTTP_INTERNAL_SERVER_ERROR;
656 * CRC is added for AU for EzGET.
658 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
659 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
661 crc = s_add_crc(writedata, writebyte);
663 rv = apr_file_putc((crc >> 8) & 0xff, fout);
664 if (rv != APR_SUCCESS) {
665 DestroyMagickWand(magick_wand);
666 return HTTP_INTERNAL_SERVER_ERROR;
669 rv = apr_file_putc( crc & 0xff, fout);
670 if (rv != APR_SUCCESS) {
671 DestroyMagickWand(magick_wand);
672 return HTTP_INTERNAL_SERVER_ERROR;
676 DestroyMagickWand(magick_wand);
678 rv = apr_file_close(fout);
679 if (rv != APR_SUCCESS) {
680 DBG1(r,"file write error.[%s]", tmpfile);
681 return HTTP_INTERNAL_SERVER_ERROR;
689 s_create_blob_data(request_rec* r,
691 query_string_param_t *qsp,
695 apr_size_t writebyte;
697 img_conv_mode_t mode = qsp->mode;
699 char* writedata = NULL;
702 MagickWand* magick_wand;
704 magick_wand = NewMagickWand();
706 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
712 * The size of the image is changed.
714 DBG(r, "call s_fixup_size()");
716 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
720 * The colors of the image is changed.
722 DBG(r, "call s_fixup_color()");
724 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
728 * DEPTH of the image is changed.
731 DBG(r,"call s_fixup_depth()");
733 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
738 DBG(r,"start convert and compression");
740 if (spec->available_jpeg) {
741 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
746 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
751 if (MagickStripImage(magick_wand) == MagickFalse) {
756 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
759 r->content_type = apr_psprintf(r->pool, "image/jpeg");
761 DBG(r, "convert to jpg");
764 if (spec->available_png) {
765 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
770 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
775 if (MagickStripImage(magick_wand) == MagickFalse) {
780 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
783 r->content_type = apr_psprintf(r->pool, "image/png");
785 DBG(r,"convert to png");
788 if (spec->available_gif) {
790 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
795 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
800 if (MagickStripImage(magick_wand) == MagickFalse) {
805 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
808 r->content_type = apr_psprintf(r->pool, "image/gif");
810 DBG(r,"convert to gif");
813 if (spec->available_bmp2 || spec->available_bmp4) {
814 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
819 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
824 if (MagickStripImage(magick_wand) == MagickFalse) {
829 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
832 r->content_type = apr_psprintf(r->pool, "image/bmp");
834 DBG(r,"convert to bmp(unsupported)");
836 /*--------------------------------------------------------------------------*/
837 /* Add Comment (Copyright and so on.) */
838 /*--------------------------------------------------------------------------*/
839 DBG(r,"call s_add_copyright()");
841 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
844 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
847 DestroyMagickWand(magick_wand);
848 DBG(r,"convert failure to Jpeg ");
852 DBG(r,"end convert and compression");
856 dst = apr_palloc(r->pool, writebyte+2);
858 memcpy(dst, writedata, writebyte);
859 /*--------------------------------------------------------------------------*/
860 /* CRC is added for AU for EzGET. */
861 /*--------------------------------------------------------------------------*/
862 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
863 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
864 crc = s_add_crc(writedata, writebyte);
865 dst[writebyte + 0] = (crc >> 8) & 0xff;
866 dst[writebyte + 1] = (crc ) & 0xff;
870 DestroyMagickWand(magick_wand);
877 s_fixup_size(MagickWand* magick_wand,
880 query_string_param_t *qsp)
882 img_conv_mode_t mode = qsp->mode;
890 oldw = MagickGetImageWidth(magick_wand);
891 oldh = MagickGetImageHeight(magick_wand);
893 DBG1(r,"detect width=[%d]", oldw);
894 DBG1(r,"detect heigh=[%d]", oldh);
899 DBG1(r,"detect spec width=[%d]", spec->width);
900 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
902 c_width = spec->width;
903 c_heigh = spec->heigh;
906 case IMG_CONV_MODE_THUMBNAIL:
908 DBG(r,"**** detect thumbnail mode ****");
910 if (neww > c_width) {
911 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
912 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
914 if (newh > c_heigh) {
915 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
916 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
919 neww = (int)((double)(neww / 3) * 0.8);
920 newh = (int)((double)(newh / 3) * 0.8);
923 case IMG_CONV_MODE_WALLPAPER:
924 case IMG_CONV_MODE_EZGET:
926 DBG(r,"**** detect wallpaper mode ****");
928 if (spec->wp_width && spec->wp_heigh) {
929 c_width = spec->wp_width;
930 c_heigh = spec->wp_heigh;
933 DBG(r,"calc new width and height");
935 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
936 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
938 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
943 DBG(r,"**** detect normal mode ****");
945 if (qsp->ua_flag != UA_IGN) {
946 if (neww > c_width) {
947 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
948 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
951 if (newh > c_heigh) {
952 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
953 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
959 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
960 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
962 MagickResetIterator(magick_wand);
964 while (MagickNextImage(magick_wand) != MagickFalse) {
966 case IMG_CONV_MODE_WALLPAPER:
967 case IMG_CONV_MODE_EZGET:
969 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
974 if (MagickCropImage(magick_wand,
975 (unsigned long)c_width,
976 (unsigned long)c_heigh,
977 (long)((neww - c_width) / 2),
978 (long)((newh - c_heigh) / 2)) == MagickFalse) {
984 case IMG_CONV_MODE_NORMAL:
986 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
990 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
995 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1002 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1003 EXIT_MAGICK_ERROR();
1007 if (MagickSetImageResolution(magick_wand,
1008 (double)spec->dpi_width,
1009 (double)spec->dpi_heigh) == MagickFalse) {
1010 EXIT_MAGICK_ERROR();
1014 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1015 EXIT_MAGICK_ERROR();
1024 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t mode)
1026 DBG(r,"start chxj_fixup_clor()");
1028 if (spec->color >= 256) {
1030 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1032 if (MagickQuantizeImage(magick_wand,
1037 0) == MagickFalse) {
1038 EXIT_MAGICK_ERROR();
1042 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1046 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1048 if (MagickQuantizeImage(magick_wand,
1053 0) == MagickFalse) {
1054 EXIT_MAGICK_ERROR();
1058 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1062 DBG(r,"end chxj_fixup_clor()");
1070 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1072 if (spec->color == 15680000) {
1073 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1074 EXIT_MAGICK_ERROR();
1079 if (spec->color == 262144) {
1080 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1081 EXIT_MAGICK_ERROR();
1086 if (spec->color == 65536) {
1087 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1088 EXIT_MAGICK_ERROR();
1093 if (spec->color == 4096) {
1094 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1095 EXIT_MAGICK_ERROR();
1100 if (spec->color == 256) {
1101 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1102 EXIT_MAGICK_ERROR();
1107 if (spec->color == 4) {
1108 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1109 EXIT_MAGICK_ERROR();
1114 if (spec->color == 2) {
1115 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1116 EXIT_MAGICK_ERROR();
1126 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1128 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1130 if (conf->image_copyright) {
1132 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1134 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1135 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1136 if (MagickCommentImage(magick_wand,
1137 apr_psprintf(r->pool,
1139 conf->image_copyright)) == MagickFalse)
1143 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1144 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1145 if (MagickCommentImage(magick_wand,
1146 apr_psprintf(r->pool,
1147 "kddi_copyright=on,%s",
1148 conf->image_copyright)) == MagickFalse)
1152 if (MagickCommentImage(magick_wand,
1153 apr_psprintf(r->pool,
1155 conf->image_copyright)) == MagickFalse)
1160 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1166 EXIT_MAGICK_ERROR();
1171 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1173 MagickBooleanType status;
1174 unsigned long quality = 70;
1175 apr_size_t writebyte = 0;
1177 apr_size_t prev_size = 0;
1178 int revers_flag = 0;
1180 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1181 prev_size = writebyte;
1184 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1185 EXIT_MAGICK_ERROR();
1189 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1190 if (writebyte >= prev_size || revers_flag) {
1191 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1194 if (quality > 100) {
1195 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1196 EXIT_MAGICK_ERROR();
1201 prev_size = writebyte;
1205 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1207 if (spec->cache == 0)
1210 if (writebyte <= spec->cache)
1215 if (quality == 0 || quality > 100)
1223 && writebyte > spec->cache) {
1224 unsigned long now_color = spec->color;
1225 unsigned long depth = 0;
1228 case 2: depth = 1; break;
1229 case 4: now_color = 2; depth = 1; break;
1230 case 8: now_color = 4; depth = 2; break;
1231 case 16: now_color = 8; depth = 3; break;
1232 case 256: now_color = 16; depth = 4; break;
1233 case 4096: now_color = 256; depth = 8; break;
1234 case 65536: now_color = 4096; depth = 12; break;
1235 case 262144: now_color = 65536; depth = 16; break;
1236 case 15680000: now_color = 262144; depth = 18; break;
1242 if (now_color <= 2) break;
1244 if (now_color >= 8) {
1245 status = MagickQuantizeImage(magick_wand,
1253 status = MagickQuantizeImage(magick_wand,
1259 MagickSetImageType(magick_wand, GrayscaleType);
1261 if (status == MagickFalse) {
1262 EXIT_MAGICK_ERROR();
1266 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1267 EXIT_MAGICK_ERROR();
1271 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1273 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, writebyte);
1275 /* Once per request */
1278 while(now_color > 2);
1285 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1290 apr_size_t sendbyte;
1291 char* contentLength;
1293 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1294 if (rv != APR_SUCCESS)
1295 return HTTP_NOT_FOUND;
1297 DBG1(r, "mode:[%d]", query_string->mode);
1298 DBG1(r, "name:[%s]", query_string->name);
1299 DBG1(r, "offset:[%ld]", query_string->offset);
1300 DBG1(r, "count:[%ld]", query_string->count);
1302 if (spec->available_jpeg) {
1303 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1306 if (spec->available_png) {
1307 r->content_type = apr_psprintf(r->pool, "image/png");
1310 if (spec->available_gif) {
1311 r->content_type = apr_psprintf(r->pool, "image/gif");
1314 if (spec->available_bmp2 || spec->available_bmp4) {
1315 r->content_type = apr_psprintf(r->pool, "image/bmp");
1318 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1319 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1320 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1322 DBG1(r,"Content-Length:[%d]", (int)st.size);
1324 rv = apr_file_open(&fout, tmpfile,
1325 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1326 if (rv != APR_SUCCESS) {
1327 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1328 return HTTP_NOT_FOUND;
1331 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1332 apr_file_close(fout);
1334 DBG1(r, "send file data[%d]byte", sendbyte);
1337 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1338 char* name = apr_pstrdup(r->pool, basename(r->filename));
1339 name[strlen(name)-4] = 0;
1340 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1342 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1343 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1346 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1347 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1348 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1351 if (strcasecmp(r->content_type, "image/png") == 0) {
1352 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1353 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1356 if (strcasecmp(r->content_type, "image/gif") == 0) {
1357 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1358 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1362 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1363 if (query_string->count == -1 && query_string->offset == -1) {
1364 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1365 ap_rprintf(r, HDML_SUCCESS_PAGE);
1369 if (query_string->count == -2 && query_string->offset == -1) {
1370 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1371 ap_rprintf(r, HDML_FAIL_PAGE);
1375 ap_set_content_type(r, "application/x-up-download");
1376 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1377 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1379 DBG1(r, "Content-Length:[%d]", (int)st.size);
1381 rv = apr_file_open(&fout, tmpfile,
1382 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1384 if (rv != APR_SUCCESS) {
1385 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1386 return HTTP_NOT_FOUND;
1389 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1390 apr_file_close(fout);
1392 DBG1(r, "send file data[%d]byte", sendbyte);
1400 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1404 char* contentLength;
1406 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1407 if (rv != APR_SUCCESS)
1408 return HTTP_NOT_FOUND;
1410 DBG1(r, "mode:[%d]", query_string->mode);
1411 DBG1(r, "name:[%s]", query_string->name);
1412 DBG1(r, "offset:[%ld]", query_string->offset);
1413 DBG1(r, "count:[%ld]", query_string->count);
1415 if (spec->available_jpeg) {
1416 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1419 if (spec->available_png) {
1420 r->content_type = apr_psprintf(r->pool, "image/png");
1423 if (spec->available_gif) {
1424 r->content_type = apr_psprintf(r->pool, "image/gif");
1427 if (spec->available_bmp2 || spec->available_bmp4) {
1428 r->content_type = apr_psprintf(r->pool, "image/bmp");
1431 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1432 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1433 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1435 DBG1(r,"Content-Length:[%d]", (int)st.size);
1438 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1439 char* name = apr_pstrdup(r->pool, basename(r->filename));
1440 name[strlen(name)-4] = 0;
1441 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1443 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1446 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1447 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1450 if (strcasecmp(r->content_type, "image/png") == 0) {
1451 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1454 if (strcasecmp(r->content_type, "image/gif") == 0) {
1455 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1459 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1460 if (query_string->count == -1 && query_string->offset == -1) {
1461 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1464 if (query_string->count == -2 && query_string->offset == -1) {
1465 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1468 ap_set_content_type(r, "application/x-up-download");
1469 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1470 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1472 DBG1(r, "Content-Length:[%d]", (int)st.size);
1484 mod_chxj_config* conf,
1485 const char* user_agent,
1486 query_string_param_t *qsp)
1491 char* w = apr_palloc(r->pool, 256);
1495 switch (qsp->mode) {
1496 case IMG_CONV_MODE_THUMBNAIL:
1497 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1498 DBG1(r, "mode=thumbnail [%s]", fname);
1500 case IMG_CONV_MODE_WALLPAPER:
1501 case IMG_CONV_MODE_EZGET:
1502 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1503 DBG1(r, "mode=WallPaper [%s]", fname);
1505 case IMG_CONV_MODE_NORMAL:
1508 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1511 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1514 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1516 DBG1(r,"mode=normal [%s]", fname);
1519 if (qsp->ua_flag == UA_IGN) {
1520 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1523 len = strlen(fname);
1525 for (ii=0; ii<len; ii++) {
1526 if (fname[ii] == '/'
1530 || fname[ii] == ')') {
1534 w[jj++] = fname[ii];
1538 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1541 static unsigned short
1542 s_add_crc(const char* writedata, apr_size_t writebyte)
1544 unsigned short crc = 0xffff;
1548 for(ii=0;ii<writebyte;ii++) {
1550 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1556 chxj_trans_name(request_rec *r)
1563 mod_chxj_config* conf;
1571 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1577 int do_ext_check = TRUE;
1578 int next_ok = FALSE;
1580 DBG(r, "start chxj_trans_name()");
1582 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1585 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1589 if (conf->image != CHXJ_IMG_ON) {
1590 DBG(r, "end chxj_trans_name() conf not found");
1595 DBG1(r,"Match URI[%s]", r->uri);
1598 if (r->filename == NULL)
1599 r->filename = apr_pstrdup(r->pool, r->uri);
1602 if ((idx = strchr(r->filename, ':')) != NULL)
1603 filename_sv = idx+1;
1605 filename_sv = r->filename;
1607 DBG1(r,"r->filename[%s]", filename_sv);
1609 ccp = ap_document_root(r);
1611 return HTTP_INTERNAL_SERVER_ERROR;
1613 docroot = apr_pstrdup(r->pool, ccp);
1614 len = strlen(docroot);
1616 if (docroot[len-1] == '/')
1617 docroot[len-1] = '\0';
1621 && *filename_sv == *r->server->path
1622 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1623 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1625 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1627 DBG1(r,"URI[%s]", filename_sv);
1629 do_ext_check = TRUE;
1630 for (ii=0; ii<7-1; ii++) {
1631 char* pos = strrchr(filename_sv, '.');
1633 if (strcasecmp(pos, ext[ii]) == 0) {
1634 do_ext_check = FALSE;
1635 fname = apr_psprintf(r->pool, "%s", filename_sv);
1642 for (ii=0; ii<7; ii++) {
1643 if (strlen(ext[ii]) == 0) {
1644 fname = apr_psprintf(r->pool, "%s", filename_sv);
1647 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1649 DBG1(r,"search [%s]", fname);
1651 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1652 if (rv == APR_SUCCESS) {
1653 if (st.filetype != APR_DIR)
1660 if (fname == NULL) {
1661 DBG1(r,"NotFound [%s]", r->filename);
1664 for (ii=0; ii<7-1; ii++) {
1665 char* pos = strrchr(fname, '.');
1667 if (strcasecmp(pos, ext[ii]) == 0) {
1675 DBG1(r,"NotFound [%s]", r->filename);
1679 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1680 DBG1(r,"Found [%s]", fname);
1682 r->filename = apr_psprintf(r->pool, "%s", fname);
1684 if (strcasecmp("qrc", ext[ii]) == 0)
1685 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1687 r->handler = apr_psprintf(r->pool, "chxj-picture");
1689 DBG(r, "end chxj_trans_name()");
1696 * It converts it from QUERYSTRING.
1700 static query_string_param_t*
1701 s_get_query_string_param(request_rec *r)
1709 query_string_param_t* param;
1711 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1712 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1713 param->mode = IMG_CONV_MODE_NORMAL;
1714 param->user_agent = NULL;
1715 param->ua_flag = UA_USE;
1722 if (s == NULL) return param;
1725 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1728 name = apr_strtok(pair, "=", &vstate);
1729 value = apr_strtok(NULL, "=", &vstate);
1734 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1739 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1740 param->mode = IMG_CONV_MODE_THUMBNAIL;
1745 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1746 param->mode = IMG_CONV_MODE_WALLPAPER;
1751 if (strcasecmp(value, "EZGET") == 0)
1752 param->mode = IMG_CONV_MODE_EZGET;
1762 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1763 ap_unescape_url(value);
1765 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1766 param->ua_flag = UA_IGN;
1768 param->user_agent = apr_pstrdup(r->pool, value);
1774 if (value && strcasecmp(name, "name") == 0)
1775 param->name = apr_pstrdup(r->pool, value);
1780 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1781 param->offset = chxj_atoi(value);
1787 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1788 param->count = chxj_atoi(value);
1793 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1794 param->width = chxj_atoi(value);
1799 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1800 param->height = chxj_atoi(value);
1808 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1809 param->mode = IMG_CONV_MODE_WALLPAPER;