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);
187 static unsigned short s_add_crc( const char* writedata,
188 apr_size_t witebyte);
189 static MagickWand* s_fixup_size(MagickWand* ,
192 query_string_param_t *qsp);
193 static MagickWand* s_fixup_color(MagickWand* magick_wand,
196 img_conv_mode_t mode);
197 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
198 request_rec* r, device_table* spec);
199 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
200 request_rec* r, device_table* spec);
201 static MagickWand* s_add_copyright(
202 MagickWand* magick_wand,
205 static char* s_create_blob_data(request_rec* r,
207 query_string_param_t *qsp,
211 static int s_img_conv_format_from_file(
213 mod_chxj_config* conf,
214 const char* user_agent,
215 query_string_param_t* qsp,
219 chxj_img_conv_format_handler(request_rec* r)
221 mod_chxj_config* conf;
222 query_string_param_t* qsp;
225 chxjconvrule_entry* entryp;
227 DBG(r, "start chxj_img_conv_format_handler()");
229 if ((*r->handler != 'c' && *r->handler != 'C')
230 || (strcasecmp(r->handler, "chxj-picture")
231 && strcasecmp(r->handler, "chxj-qrcode"))) {
232 DBG(r, "end chxj_img_conv_format_handler()");
236 qsp = s_get_query_string_param(r);
237 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
239 DBG(r, "end chxj_img_conv_format_handler() conf is null");
243 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF)
247 /*------------------------------------------------------------------------*/
248 /* get UserAgent from http header */
249 /*------------------------------------------------------------------------*/
250 /*--------------------------------------------------------------------------*/
251 /* User-Agent to spec */
252 /*--------------------------------------------------------------------------*/
253 if (qsp->user_agent) {
254 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
257 entryp = chxj_apply_convrule(r, conf->convrules);
258 if (entryp && entryp->user_agent) {
259 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
262 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
268 if (qsp->ua_flag == UA_IGN)
269 spec = &v_ignore_spec;
271 spec = chxj_specified_device(r, user_agent);
273 DBG1(r,"found device_name=[%s]", spec->device_name);
274 DBG1(r,"User-Agent=[%s]", user_agent);
276 if (spec->width == 0 || spec->heigh == 0)
279 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
285 * It converts it from ImageData corresponding to each model.
288 * @param src [i] It is former image binary data.
289 * @param len [i/o] It is length of former image binary data.
292 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
294 mod_chxj_config* conf;
295 query_string_param_t* qsp;
300 chxjconvrule_entry* entryp;
302 DBG(r, "start chxj_exchange_image()");
304 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
306 DBG(r, "end chxj_exchnage_image() already convert.");
311 qsp = s_get_query_string_param(r);
312 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
314 DBG(r, "end chxj_exchange_image()");
318 /*--------------------------------------------------------------------------*/
319 /* User-Agent to spec */
320 /*--------------------------------------------------------------------------*/
321 if (qsp->user_agent) {
322 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
325 entryp = chxj_apply_convrule(r, conf->convrules);
326 if (entryp && entryp->user_agent) {
327 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
330 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
334 if (qsp->ua_flag == UA_IGN)
335 spec = &v_ignore_spec;
337 spec = chxj_specified_device(r, user_agent);
339 DBG1(r,"found device_name=[%s]", spec->device_name);
340 DBG1(r, "User-Agent=[%s]", user_agent);
342 if (spec->width == 0 || spec->heigh == 0)
345 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
349 DBG(r, "end chxj_exchange_image()");
355 s_img_conv_format_from_file(
357 mod_chxj_config* conf,
358 const char* user_agent,
359 query_string_param_t* qsp,
364 apr_finfo_t cache_st;
367 /*--------------------------------------------------------------------------*/
368 /* Create Workfile Name */
369 /*--------------------------------------------------------------------------*/
370 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
371 DBG1(r,"workfile=[%s]", tmpfile);
373 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
374 if (rv != APR_SUCCESS)
375 return HTTP_NOT_FOUND;
378 DBG1(r,"found [%s]", r->filename);
379 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
380 DBG1(r,"found [%s]", r->filename);
382 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
383 /*------------------------------------------------------------------------*/
384 /* It tries to make the cash file when it doesn't exist or there is */
385 /* change time later since the making time of the cash file. */
386 /*------------------------------------------------------------------------*/
387 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
392 DBG1(r,"color=[%d]", spec->color);
393 if (! r->header_only) {
394 rv = s_send_cache_file(spec, qsp,r, tmpfile);
399 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
403 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
405 DBG(r,"end chxj_img_conv_format");
412 s_create_cache_file(request_rec* r,
416 query_string_param_t *qsp)
420 apr_size_t writebyte;
422 img_conv_mode_t mode = qsp->mode;
424 char* writedata = NULL;
425 char* readdata = NULL;
430 MagickWand* magick_wand;
432 if ((*r->handler == 'c' || *r->handler == 'C')
433 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
434 /*------------------------------------------------------------------------*/
435 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
436 /*------------------------------------------------------------------------*/
442 memset(&doc, 0, sizeof(Doc));
443 memset(&qrcode, 0, sizeof(qr_code_t));
445 doc.parse_mode = PARSE_MODE_CHTML;
449 qs_init_malloc(&doc);
451 root = qs_parse_file(&doc, r->filename);
453 chxj_qrcode_node_to_qrcode(&qrcode, root);
455 qs_all_free(&doc,QX_LOGMARK);
457 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
459 ERR(r, "qrcode create failed.");
464 /*------------------------------------------------------------------------*/
465 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
466 /*------------------------------------------------------------------------*/
467 rv = apr_file_open(&fin,
469 APR_READ|APR_BINARY ,
472 if (rv != APR_SUCCESS) {
473 DBG1(r,"file open failed.[%s]", r->filename);
474 return HTTP_NOT_FOUND;
477 readdata = apr_palloc(r->pool, st->size);
478 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
479 if (rv != APR_SUCCESS || readbyte != st->size) {
480 DBG1(r,"file read failed.[%s]", r->filename);
483 return HTTP_NOT_FOUND;
486 DBG(r,"start img convert");
489 magick_wand = NewMagickWand();
490 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
492 return HTTP_NOT_FOUND;
496 * The size of the image is changed.
498 DBG(r,"call s_fixup_size()");
500 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
501 return HTTP_NOT_FOUND;
504 * The colors of the image is changed.
506 DBG(r,"call s_fixup_color()");
508 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
509 return HTTP_NOT_FOUND;
512 * DEPTH of the image is changed.
514 DBG(r,"call s_fixup_depth()");
516 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
517 return HTTP_NOT_FOUND;
521 DBG(r,"start convert and compression");
523 if (spec->available_jpeg) {
524 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
526 return HTTP_NOT_FOUND;
529 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
531 return HTTP_NOT_FOUND;
534 if (MagickStripImage(magick_wand) == MagickFalse) {
536 return HTTP_NOT_FOUND;
539 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
540 return HTTP_NOT_FOUND;
542 r->content_type = apr_psprintf(r->pool, "image/jpeg");
543 DBG(r,"convert to jpg");
546 if (spec->available_png) {
548 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
550 return HTTP_NOT_FOUND;
553 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
555 return HTTP_NOT_FOUND;
558 if (MagickStripImage(magick_wand) == MagickFalse) {
560 return HTTP_NOT_FOUND;
563 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
564 return HTTP_NOT_FOUND;
566 r->content_type = apr_psprintf(r->pool, "image/png");
567 DBG(r, "convert to png");
570 if (spec->available_gif) {
572 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
574 return HTTP_NOT_FOUND;
577 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
579 return HTTP_NOT_FOUND;
582 if (MagickStripImage(magick_wand) == MagickFalse) {
584 return HTTP_NOT_FOUND;
587 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
588 return HTTP_NOT_FOUND;
590 r->content_type = apr_psprintf(r->pool, "image/gif");
592 DBG(r,"convert to gif");
595 if (spec->available_bmp2 || spec->available_bmp4) {
597 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
599 return HTTP_NOT_FOUND;
602 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
604 return HTTP_NOT_FOUND;
607 if (MagickStripImage(magick_wand) == MagickFalse) {
609 return HTTP_NOT_FOUND;
612 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
613 return HTTP_NOT_FOUND;
615 r->content_type = apr_psprintf(r->pool, "image/bmp");
617 DBG(r, "convert to bmp(unsupported)");
621 * Add Comment (Copyright and so on.)
623 DBG(r, "call s_add_copyright()");
625 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
626 return HTTP_NOT_FOUND;
628 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
631 DestroyMagickWand(magick_wand);
632 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
634 return HTTP_INTERNAL_SERVER_ERROR;
637 DBG(r, "end convert and compression");
640 rv = apr_file_open(&fout, tmpfile,
641 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
643 if (rv != APR_SUCCESS) {
644 DestroyMagickWand(magick_wand);
645 ERR1(r,"file open error.[%s]", tmpfile);
646 return HTTP_INTERNAL_SERVER_ERROR;
649 rv = apr_file_write(fout, (void*)writedata, &writebyte);
650 if (rv != APR_SUCCESS) {
651 DestroyMagickWand(magick_wand);
652 apr_file_close(fout);
653 return HTTP_INTERNAL_SERVER_ERROR;
657 * CRC is added for AU for EzGET.
659 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
660 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
662 crc = s_add_crc(writedata, writebyte);
664 rv = apr_file_putc((crc >> 8) & 0xff, fout);
665 if (rv != APR_SUCCESS) {
666 DestroyMagickWand(magick_wand);
667 return HTTP_INTERNAL_SERVER_ERROR;
670 rv = apr_file_putc( crc & 0xff, fout);
671 if (rv != APR_SUCCESS) {
672 DestroyMagickWand(magick_wand);
673 return HTTP_INTERNAL_SERVER_ERROR;
677 DestroyMagickWand(magick_wand);
679 rv = apr_file_close(fout);
680 if (rv != APR_SUCCESS) {
681 DBG1(r,"file write error.[%s]", tmpfile);
682 return HTTP_INTERNAL_SERVER_ERROR;
690 s_create_blob_data(request_rec* r,
692 query_string_param_t *qsp,
696 apr_size_t writebyte;
698 img_conv_mode_t mode = qsp->mode;
700 char* writedata = NULL;
703 MagickWand* magick_wand;
705 magick_wand = NewMagickWand();
707 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
713 * The size of the image is changed.
715 DBG(r, "call s_fixup_size()");
717 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
721 * The colors of the image is changed.
723 DBG(r, "call s_fixup_color()");
725 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
729 * DEPTH of the image is changed.
732 DBG(r,"call s_fixup_depth()");
734 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
739 DBG(r,"start convert and compression");
741 if (spec->available_jpeg) {
742 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
747 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
752 if (MagickStripImage(magick_wand) == MagickFalse) {
757 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
760 r->content_type = apr_psprintf(r->pool, "image/jpeg");
762 DBG(r, "convert to jpg");
765 if (spec->available_png) {
766 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
771 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
776 if (MagickStripImage(magick_wand) == MagickFalse) {
781 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
784 r->content_type = apr_psprintf(r->pool, "image/png");
786 DBG(r,"convert to png");
789 if (spec->available_gif) {
791 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
796 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
801 if (MagickStripImage(magick_wand) == MagickFalse) {
806 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
809 r->content_type = apr_psprintf(r->pool, "image/gif");
811 DBG(r,"convert to gif");
814 if (spec->available_bmp2 || spec->available_bmp4) {
815 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
820 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
825 if (MagickStripImage(magick_wand) == MagickFalse) {
830 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
833 r->content_type = apr_psprintf(r->pool, "image/bmp");
835 DBG(r,"convert to bmp(unsupported)");
837 /*--------------------------------------------------------------------------*/
838 /* Add Comment (Copyright and so on.) */
839 /*--------------------------------------------------------------------------*/
840 DBG(r,"call s_add_copyright()");
842 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
845 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
848 DestroyMagickWand(magick_wand);
849 DBG(r,"convert failure to Jpeg ");
853 DBG(r,"end convert and compression");
857 dst = apr_palloc(r->pool, writebyte+2);
859 memcpy(dst, writedata, writebyte);
860 /*--------------------------------------------------------------------------*/
861 /* CRC is added for AU for EzGET. */
862 /*--------------------------------------------------------------------------*/
863 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
864 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
865 crc = s_add_crc(writedata, writebyte);
866 dst[writebyte + 0] = (crc >> 8) & 0xff;
867 dst[writebyte + 1] = (crc ) & 0xff;
871 DestroyMagickWand(magick_wand);
878 s_fixup_size(MagickWand* magick_wand,
881 query_string_param_t *qsp)
883 img_conv_mode_t mode = qsp->mode;
891 oldw = MagickGetImageWidth(magick_wand);
892 oldh = MagickGetImageHeight(magick_wand);
894 DBG1(r,"detect width=[%d]", oldw);
895 DBG1(r,"detect heigh=[%d]", oldh);
900 DBG1(r,"detect spec width=[%d]", spec->width);
901 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
903 c_width = spec->width;
904 c_heigh = spec->heigh;
907 case IMG_CONV_MODE_THUMBNAIL:
909 DBG(r,"**** detect thumbnail mode ****");
911 if (neww > c_width) {
912 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
913 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
915 if (newh > c_heigh) {
916 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
917 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
920 neww = (int)((double)(neww / 3) * 0.8);
921 newh = (int)((double)(newh / 3) * 0.8);
924 case IMG_CONV_MODE_WALLPAPER:
925 case IMG_CONV_MODE_EZGET:
927 DBG(r,"**** detect wallpaper mode ****");
929 if (spec->wp_width && spec->wp_heigh) {
930 c_width = spec->wp_width;
931 c_heigh = spec->wp_heigh;
934 DBG(r,"calc new width and height");
936 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
937 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
939 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
944 DBG(r,"**** detect normal mode ****");
946 if (qsp->ua_flag != UA_IGN) {
947 if (neww > c_width) {
948 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
949 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
952 if (newh > c_heigh) {
953 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
954 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
960 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
961 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
963 MagickResetIterator(magick_wand);
965 while (MagickNextImage(magick_wand) != MagickFalse) {
967 case IMG_CONV_MODE_WALLPAPER:
968 case IMG_CONV_MODE_EZGET:
970 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
975 if (MagickCropImage(magick_wand,
976 (unsigned long)c_width,
977 (unsigned long)c_heigh,
978 (long)((neww - c_width) / 2),
979 (long)((newh - c_heigh) / 2)) == MagickFalse) {
985 case IMG_CONV_MODE_NORMAL:
987 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
991 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
996 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1003 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1004 EXIT_MAGICK_ERROR();
1008 if (MagickSetImageResolution(magick_wand,
1009 (double)spec->dpi_width,
1010 (double)spec->dpi_heigh) == MagickFalse) {
1011 EXIT_MAGICK_ERROR();
1015 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1016 EXIT_MAGICK_ERROR();
1025 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t mode)
1027 DBG(r,"start chxj_fixup_clor()");
1029 if (spec->color >= 256) {
1031 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1033 if (MagickQuantizeImage(magick_wand,
1038 0) == MagickFalse) {
1039 EXIT_MAGICK_ERROR();
1043 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1047 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1049 if (MagickQuantizeImage(magick_wand,
1054 0) == MagickFalse) {
1055 EXIT_MAGICK_ERROR();
1059 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1063 DBG(r,"end chxj_fixup_clor()");
1071 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1073 if (spec->color == 15680000) {
1074 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1075 EXIT_MAGICK_ERROR();
1080 if (spec->color == 262144) {
1081 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1082 EXIT_MAGICK_ERROR();
1087 if (spec->color == 65536) {
1088 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1089 EXIT_MAGICK_ERROR();
1094 if (spec->color == 4096) {
1095 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1096 EXIT_MAGICK_ERROR();
1101 if (spec->color == 256) {
1102 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1103 EXIT_MAGICK_ERROR();
1108 if (spec->color == 4) {
1109 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1110 EXIT_MAGICK_ERROR();
1115 if (spec->color == 2) {
1116 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1117 EXIT_MAGICK_ERROR();
1127 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1129 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1131 if (conf->image_copyright) {
1133 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1135 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1136 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1137 if (MagickCommentImage(magick_wand,
1138 apr_psprintf(r->pool,
1140 conf->image_copyright)) == MagickFalse)
1144 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1145 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1146 if (MagickCommentImage(magick_wand,
1147 apr_psprintf(r->pool,
1148 "kddi_copyright=on,%s",
1149 conf->image_copyright)) == MagickFalse)
1153 if (MagickCommentImage(magick_wand,
1154 apr_psprintf(r->pool,
1156 conf->image_copyright)) == MagickFalse)
1161 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1167 EXIT_MAGICK_ERROR();
1172 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1174 MagickBooleanType status;
1175 unsigned long quality = 70;
1176 apr_size_t writebyte = 0;
1178 apr_size_t prev_size = 0;
1179 int revers_flag = 0;
1181 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1182 prev_size = writebyte;
1185 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1186 EXIT_MAGICK_ERROR();
1190 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1191 if (writebyte >= prev_size || revers_flag) {
1192 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1195 if (quality > 100) {
1196 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1197 EXIT_MAGICK_ERROR();
1202 prev_size = writebyte;
1206 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1208 if (spec->cache == 0)
1211 if (writebyte <= spec->cache)
1216 if (quality == 0 || quality > 100)
1224 && writebyte > spec->cache) {
1225 unsigned long now_color = spec->color;
1226 unsigned long depth = 0;
1229 case 2: depth = 1; break;
1230 case 4: now_color = 2; depth = 1; break;
1231 case 8: now_color = 4; depth = 2; break;
1232 case 16: now_color = 8; depth = 3; break;
1233 case 256: now_color = 16; depth = 4; break;
1234 case 4096: now_color = 256; depth = 8; break;
1235 case 65536: now_color = 4096; depth = 12; break;
1236 case 262144: now_color = 65536; depth = 16; break;
1237 case 15680000: now_color = 262144; depth = 18; break;
1243 if (now_color <= 2) break;
1245 if (now_color >= 8) {
1246 status = MagickQuantizeImage(magick_wand,
1254 status = MagickQuantizeImage(magick_wand,
1260 MagickSetImageType(magick_wand, GrayscaleType);
1262 if (status == MagickFalse) {
1263 EXIT_MAGICK_ERROR();
1267 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1268 EXIT_MAGICK_ERROR();
1272 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1274 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, writebyte);
1276 /* Once per request */
1279 while(now_color > 2);
1286 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1291 apr_size_t sendbyte;
1292 char* contentLength;
1294 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1295 if (rv != APR_SUCCESS)
1296 return HTTP_NOT_FOUND;
1298 DBG1(r, "mode:[%d]", query_string->mode);
1299 DBG1(r, "name:[%s]", query_string->name);
1300 DBG1(r, "offset:[%ld]", query_string->offset);
1301 DBG1(r, "count:[%ld]", query_string->count);
1303 if (spec->available_jpeg) {
1304 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1307 if (spec->available_png) {
1308 r->content_type = apr_psprintf(r->pool, "image/png");
1311 if (spec->available_gif) {
1312 r->content_type = apr_psprintf(r->pool, "image/gif");
1315 if (spec->available_bmp2 || spec->available_bmp4) {
1316 r->content_type = apr_psprintf(r->pool, "image/bmp");
1319 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1320 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1321 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1323 DBG1(r,"Content-Length:[%d]", (int)st.size);
1325 rv = apr_file_open(&fout, tmpfile,
1326 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1327 if (rv != APR_SUCCESS) {
1328 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1329 return HTTP_NOT_FOUND;
1332 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1333 apr_file_close(fout);
1335 DBG1(r, "send file data[%d]byte", sendbyte);
1338 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1339 char* name = apr_pstrdup(r->pool, basename(r->filename));
1340 name[strlen(name)-4] = 0;
1341 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1343 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1344 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1347 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1348 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1349 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1352 if (strcasecmp(r->content_type, "image/png") == 0) {
1353 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1354 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1357 if (strcasecmp(r->content_type, "image/gif") == 0) {
1358 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1359 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1363 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1364 if (query_string->count == -1 && query_string->offset == -1) {
1365 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1366 ap_rprintf(r, HDML_SUCCESS_PAGE);
1370 if (query_string->count == -2 && query_string->offset == -1) {
1371 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1372 ap_rprintf(r, HDML_FAIL_PAGE);
1376 ap_set_content_type(r, "application/x-up-download");
1377 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1378 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1380 DBG1(r, "Content-Length:[%d]", (int)st.size);
1382 rv = apr_file_open(&fout, tmpfile,
1383 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1385 if (rv != APR_SUCCESS) {
1386 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1387 return HTTP_NOT_FOUND;
1390 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1391 apr_file_close(fout);
1393 DBG1(r, "send file data[%d]byte", sendbyte);
1401 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1405 char* contentLength;
1407 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1408 if (rv != APR_SUCCESS)
1409 return HTTP_NOT_FOUND;
1411 DBG1(r, "mode:[%d]", query_string->mode);
1412 DBG1(r, "name:[%s]", query_string->name);
1413 DBG1(r, "offset:[%ld]", query_string->offset);
1414 DBG1(r, "count:[%ld]", query_string->count);
1416 if (spec->available_jpeg) {
1417 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1420 if (spec->available_png) {
1421 r->content_type = apr_psprintf(r->pool, "image/png");
1424 if (spec->available_gif) {
1425 r->content_type = apr_psprintf(r->pool, "image/gif");
1428 if (spec->available_bmp2 || spec->available_bmp4) {
1429 r->content_type = apr_psprintf(r->pool, "image/bmp");
1432 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1433 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1434 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1436 DBG1(r,"Content-Length:[%d]", (int)st.size);
1439 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1440 char* name = apr_pstrdup(r->pool, basename(r->filename));
1441 name[strlen(name)-4] = 0;
1442 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1444 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1447 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1448 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1451 if (strcasecmp(r->content_type, "image/png") == 0) {
1452 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1455 if (strcasecmp(r->content_type, "image/gif") == 0) {
1456 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1460 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1461 if (query_string->count == -1 && query_string->offset == -1) {
1462 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1465 if (query_string->count == -2 && query_string->offset == -1) {
1466 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1469 ap_set_content_type(r, "application/x-up-download");
1470 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1471 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1473 DBG1(r, "Content-Length:[%d]", (int)st.size);
1485 mod_chxj_config* conf,
1486 const char* user_agent,
1487 query_string_param_t *qsp)
1492 char* w = apr_palloc(r->pool, 256);
1496 switch (qsp->mode) {
1497 case IMG_CONV_MODE_THUMBNAIL:
1498 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1499 DBG1(r, "mode=thumbnail [%s]", fname);
1501 case IMG_CONV_MODE_WALLPAPER:
1502 case IMG_CONV_MODE_EZGET:
1503 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1504 DBG1(r, "mode=WallPaper [%s]", fname);
1506 case IMG_CONV_MODE_NORMAL:
1509 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1512 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1515 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1517 DBG1(r,"mode=normal [%s]", fname);
1520 if (qsp->ua_flag == UA_IGN) {
1521 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1524 len = strlen(fname);
1526 for (ii=0; ii<len; ii++) {
1527 if (fname[ii] == '/'
1531 || fname[ii] == ')') {
1535 w[jj++] = fname[ii];
1539 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1542 static unsigned short
1543 s_add_crc(const char* writedata, apr_size_t writebyte)
1545 unsigned short crc = 0xffff;
1549 for(ii=0;ii<writebyte;ii++) {
1551 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1557 chxj_trans_name(request_rec *r)
1564 mod_chxj_config* conf;
1572 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1578 int do_ext_check = TRUE;
1579 int next_ok = FALSE;
1581 DBG(r, "start chxj_trans_name()");
1583 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1586 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1590 if (conf->image != CHXJ_IMG_ON) {
1591 DBG(r, "end chxj_trans_name() conf not found");
1596 DBG1(r,"Match URI[%s]", r->uri);
1599 if (r->filename == NULL)
1600 r->filename = apr_pstrdup(r->pool, r->uri);
1603 if ((idx = strchr(r->filename, ':')) != NULL)
1604 filename_sv = idx+1;
1606 filename_sv = r->filename;
1608 DBG1(r,"r->filename[%s]", filename_sv);
1610 ccp = ap_document_root(r);
1612 return HTTP_INTERNAL_SERVER_ERROR;
1614 docroot = apr_pstrdup(r->pool, ccp);
1615 len = strlen(docroot);
1617 if (docroot[len-1] == '/')
1618 docroot[len-1] = '\0';
1622 && *filename_sv == *r->server->path
1623 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1624 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1626 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1628 DBG1(r,"URI[%s]", filename_sv);
1630 do_ext_check = TRUE;
1631 for (ii=0; ii<7-1; ii++) {
1632 char* pos = strrchr(filename_sv, '.');
1634 if (strcasecmp(pos, ext[ii]) == 0) {
1635 do_ext_check = FALSE;
1636 fname = apr_psprintf(r->pool, "%s", filename_sv);
1643 for (ii=0; ii<7; ii++) {
1644 if (strlen(ext[ii]) == 0) {
1645 fname = apr_psprintf(r->pool, "%s", filename_sv);
1648 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1650 DBG1(r,"search [%s]", fname);
1652 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1653 if (rv == APR_SUCCESS) {
1654 if (st.filetype != APR_DIR)
1661 if (fname == NULL) {
1662 DBG1(r,"NotFound [%s]", r->filename);
1665 for (ii=0; ii<7-1; ii++) {
1666 char* pos = strrchr(fname, '.');
1668 if (strcasecmp(pos, ext[ii]) == 0) {
1676 DBG1(r,"NotFound [%s]", r->filename);
1680 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1681 DBG1(r,"Found [%s]", fname);
1683 r->filename = apr_psprintf(r->pool, "%s", fname);
1685 if (strcasecmp("qrc", ext[ii]) == 0)
1686 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1688 r->handler = apr_psprintf(r->pool, "chxj-picture");
1690 DBG(r, "end chxj_trans_name()");
1697 * It converts it from QUERYSTRING.
1701 static query_string_param_t*
1702 s_get_query_string_param(request_rec *r)
1710 query_string_param_t* param;
1712 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1713 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1714 param->mode = IMG_CONV_MODE_NORMAL;
1715 param->user_agent = NULL;
1716 param->ua_flag = UA_USE;
1723 if (s == NULL) return param;
1726 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1729 name = apr_strtok(pair, "=", &vstate);
1730 value = apr_strtok(NULL, "=", &vstate);
1735 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1740 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1741 param->mode = IMG_CONV_MODE_THUMBNAIL;
1746 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1747 param->mode = IMG_CONV_MODE_WALLPAPER;
1752 if (strcasecmp(value, "EZGET") == 0)
1753 param->mode = IMG_CONV_MODE_EZGET;
1763 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1764 ap_unescape_url(value);
1766 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1767 param->ua_flag = UA_IGN;
1769 param->user_agent = apr_pstrdup(r->pool, value);
1775 if (value && strcasecmp(name, "name") == 0)
1776 param->name = apr_pstrdup(r->pool, value);
1781 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1782 param->offset = chxj_atoi(value);
1788 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1789 param->count = chxj_atoi(value);
1794 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1795 param->width = chxj_atoi(value);
1800 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1801 param->height = chxj_atoi(value);
1809 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1810 param->mode = IMG_CONV_MODE_WALLPAPER;