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);
190 static MagickWand* s_fixup_size(MagickWand* ,
193 query_string_param_t *qsp);
195 static MagickWand* s_fixup_color(MagickWand* magick_wand,
198 img_conv_mode_t mode);
199 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
200 request_rec* r, device_table* spec);
201 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
202 request_rec* r, device_table* spec);
204 static MagickWand* s_add_copyright(MagickWand* magick_wand,
208 static char* s_create_blob_data(request_rec* r,
210 query_string_param_t* qsp,
214 static int s_img_conv_format_from_file(
216 mod_chxj_config* conf,
217 const char* user_agent,
218 query_string_param_t* qsp,
224 chxj_img_conv_format_handler(request_rec* r)
226 mod_chxj_config* conf;
227 query_string_param_t* qsp;
230 chxjconvrule_entry* entryp;
232 DBG(r, "start chxj_img_conv_format_handler()");
234 if ((*r->handler != 'c' && *r->handler != 'C')
235 || (strcasecmp(r->handler, "chxj-picture")
236 && strcasecmp(r->handler, "chxj-qrcode"))) {
237 DBG(r, "end chxj_img_conv_format_handler()");
241 qsp = s_get_query_string_param(r);
242 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
244 DBG(r, "end chxj_img_conv_format_handler() conf is null");
248 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF)
252 /*------------------------------------------------------------------------*/
253 /* get UserAgent from http header */
254 /*------------------------------------------------------------------------*/
255 /*--------------------------------------------------------------------------*/
256 /* User-Agent to spec */
257 /*--------------------------------------------------------------------------*/
258 if (qsp->user_agent) {
259 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
262 entryp = chxj_apply_convrule(r, conf->convrules);
263 if (entryp && entryp->user_agent) {
264 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
267 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
273 if (qsp->ua_flag == UA_IGN)
274 spec = &v_ignore_spec;
276 spec = chxj_specified_device(r, user_agent);
278 DBG1(r,"found device_name=[%s]", spec->device_name);
279 DBG1(r,"User-Agent=[%s]", user_agent);
281 if (spec->width == 0 || spec->heigh == 0)
284 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
290 * It converts it from ImageData corresponding to each model.
293 * @param src [i] It is former image binary data.
294 * @param len [i/o] It is length of former image binary data.
297 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
299 mod_chxj_config* conf;
300 query_string_param_t* qsp;
305 chxjconvrule_entry* entryp;
307 DBG(r, "start chxj_exchange_image()");
309 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
311 DBG(r, "end chxj_exchnage_image() already convert.");
316 qsp = s_get_query_string_param(r);
317 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
319 DBG(r, "end chxj_exchange_image()");
323 /*--------------------------------------------------------------------------*/
324 /* User-Agent to spec */
325 /*--------------------------------------------------------------------------*/
326 if (qsp->user_agent) {
327 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
330 entryp = chxj_apply_convrule(r, conf->convrules);
331 if (entryp && entryp->user_agent) {
332 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
335 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
339 if (qsp->ua_flag == UA_IGN)
340 spec = &v_ignore_spec;
342 spec = chxj_specified_device(r, user_agent);
344 DBG1(r,"found device_name=[%s]", spec->device_name);
345 DBG1(r, "User-Agent=[%s]", user_agent);
347 if (spec->width == 0 || spec->heigh == 0)
350 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
354 DBG(r, "end chxj_exchange_image()");
360 s_img_conv_format_from_file(
362 mod_chxj_config* conf,
363 const char* user_agent,
364 query_string_param_t* qsp,
369 apr_finfo_t cache_st;
372 /*--------------------------------------------------------------------------*/
373 /* Create Workfile Name */
374 /*--------------------------------------------------------------------------*/
375 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
376 DBG1(r,"workfile=[%s]", tmpfile);
378 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
379 if (rv != APR_SUCCESS)
380 return HTTP_NOT_FOUND;
383 DBG1(r,"found [%s]", r->filename);
384 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
385 DBG1(r,"found [%s]", r->filename);
387 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
388 /*------------------------------------------------------------------------*/
389 /* It tries to make the cash file when it doesn't exist or there is */
390 /* change time later since the making time of the cash file. */
391 /*------------------------------------------------------------------------*/
392 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
397 DBG1(r,"color=[%d]", spec->color);
398 if (! r->header_only) {
399 rv = s_send_cache_file(spec, qsp,r, tmpfile);
404 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
408 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
410 DBG(r,"end chxj_img_conv_format");
417 s_create_cache_file(request_rec* r,
421 query_string_param_t *qsp)
425 apr_size_t writebyte;
427 img_conv_mode_t mode = qsp->mode;
429 char* writedata = NULL;
430 char* readdata = NULL;
435 MagickWand* magick_wand;
437 if ((*r->handler == 'c' || *r->handler == 'C')
438 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
439 /*------------------------------------------------------------------------*/
440 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
441 /*------------------------------------------------------------------------*/
447 memset(&doc, 0, sizeof(Doc));
448 memset(&qrcode, 0, sizeof(qr_code_t));
450 doc.parse_mode = PARSE_MODE_CHTML;
454 qs_init_malloc(&doc);
456 root = qs_parse_file(&doc, r->filename);
458 chxj_qrcode_node_to_qrcode(&qrcode, root);
460 qs_all_free(&doc,QX_LOGMARK);
462 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
464 ERR(r, "qrcode create failed.");
469 /*------------------------------------------------------------------------*/
470 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
471 /*------------------------------------------------------------------------*/
472 rv = apr_file_open(&fin,
474 APR_READ|APR_BINARY ,
477 if (rv != APR_SUCCESS) {
478 DBG1(r,"file open failed.[%s]", r->filename);
479 return HTTP_NOT_FOUND;
482 readdata = apr_palloc(r->pool, st->size);
483 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
484 if (rv != APR_SUCCESS || readbyte != st->size) {
485 DBG1(r,"file read failed.[%s]", r->filename);
488 return HTTP_NOT_FOUND;
491 DBG(r,"start img convert");
494 magick_wand = NewMagickWand();
495 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
497 return HTTP_NOT_FOUND;
501 * The size of the image is changed.
503 DBG(r,"call s_fixup_size()");
505 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
506 return HTTP_NOT_FOUND;
509 * The colors of the image is changed.
511 DBG(r,"call s_fixup_color()");
513 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
514 return HTTP_NOT_FOUND;
517 * DEPTH of the image is changed.
519 DBG(r,"call s_fixup_depth()");
521 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
522 return HTTP_NOT_FOUND;
526 DBG(r,"start convert and compression");
528 if (spec->available_jpeg) {
529 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
531 return HTTP_NOT_FOUND;
534 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
536 return HTTP_NOT_FOUND;
539 if (MagickStripImage(magick_wand) == MagickFalse) {
541 return HTTP_NOT_FOUND;
544 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
545 return HTTP_NOT_FOUND;
547 r->content_type = apr_psprintf(r->pool, "image/jpeg");
548 DBG(r,"convert to jpg");
551 if (spec->available_png) {
553 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
555 return HTTP_NOT_FOUND;
558 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
560 return HTTP_NOT_FOUND;
563 if (MagickStripImage(magick_wand) == MagickFalse) {
565 return HTTP_NOT_FOUND;
568 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
569 return HTTP_NOT_FOUND;
571 r->content_type = apr_psprintf(r->pool, "image/png");
572 DBG(r, "convert to png");
575 if (spec->available_gif) {
577 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
579 return HTTP_NOT_FOUND;
582 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
584 return HTTP_NOT_FOUND;
587 if (MagickStripImage(magick_wand) == MagickFalse) {
589 return HTTP_NOT_FOUND;
592 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
593 return HTTP_NOT_FOUND;
595 r->content_type = apr_psprintf(r->pool, "image/gif");
597 DBG(r,"convert to gif");
600 if (spec->available_bmp2 || spec->available_bmp4) {
602 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
604 return HTTP_NOT_FOUND;
607 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
609 return HTTP_NOT_FOUND;
612 if (MagickStripImage(magick_wand) == MagickFalse) {
614 return HTTP_NOT_FOUND;
617 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
618 return HTTP_NOT_FOUND;
620 r->content_type = apr_psprintf(r->pool, "image/bmp");
622 DBG(r, "convert to bmp(unsupported)");
626 * Add Comment (Copyright and so on.)
628 DBG(r, "call s_add_copyright()");
630 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
631 return HTTP_NOT_FOUND;
633 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
636 DestroyMagickWand(magick_wand);
637 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
639 return HTTP_INTERNAL_SERVER_ERROR;
642 DBG(r, "end convert and compression");
645 rv = apr_file_open(&fout, tmpfile,
646 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
648 if (rv != APR_SUCCESS) {
649 DestroyMagickWand(magick_wand);
650 ERR1(r,"file open error.[%s]", tmpfile);
651 return HTTP_INTERNAL_SERVER_ERROR;
654 rv = apr_file_write(fout, (void*)writedata, &writebyte);
655 if (rv != APR_SUCCESS) {
656 DestroyMagickWand(magick_wand);
657 apr_file_close(fout);
658 return HTTP_INTERNAL_SERVER_ERROR;
662 * CRC is added for AU for EzGET.
664 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
665 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
667 crc = s_add_crc(writedata, writebyte);
669 rv = apr_file_putc((crc >> 8) & 0xff, fout);
670 if (rv != APR_SUCCESS) {
671 DestroyMagickWand(magick_wand);
672 return HTTP_INTERNAL_SERVER_ERROR;
675 rv = apr_file_putc( crc & 0xff, fout);
676 if (rv != APR_SUCCESS) {
677 DestroyMagickWand(magick_wand);
678 return HTTP_INTERNAL_SERVER_ERROR;
682 DestroyMagickWand(magick_wand);
684 rv = apr_file_close(fout);
685 if (rv != APR_SUCCESS) {
686 DBG1(r,"file write error.[%s]", tmpfile);
687 return HTTP_INTERNAL_SERVER_ERROR;
695 s_create_blob_data(request_rec* r,
697 query_string_param_t *qsp,
701 apr_size_t writebyte;
703 img_conv_mode_t mode = qsp->mode;
705 char* writedata = NULL;
708 MagickWand* magick_wand;
710 magick_wand = NewMagickWand();
712 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
718 * The size of the image is changed.
720 DBG(r, "call s_fixup_size()");
722 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
726 * The colors of the image is changed.
728 DBG(r, "call s_fixup_color()");
730 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
734 * DEPTH of the image is changed.
737 DBG(r,"call s_fixup_depth()");
739 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
744 DBG(r,"start convert and compression");
746 if (spec->available_jpeg) {
747 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
752 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
757 if (MagickStripImage(magick_wand) == MagickFalse) {
762 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
765 r->content_type = apr_psprintf(r->pool, "image/jpeg");
767 DBG(r, "convert to jpg");
770 if (spec->available_png) {
771 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
776 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
781 if (MagickStripImage(magick_wand) == MagickFalse) {
786 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
789 r->content_type = apr_psprintf(r->pool, "image/png");
791 DBG(r,"convert to png");
794 if (spec->available_gif) {
796 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
801 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
806 if (MagickStripImage(magick_wand) == MagickFalse) {
811 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
814 r->content_type = apr_psprintf(r->pool, "image/gif");
816 DBG(r,"convert to gif");
819 if (spec->available_bmp2 || spec->available_bmp4) {
820 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
825 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
830 if (MagickStripImage(magick_wand) == MagickFalse) {
835 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
838 r->content_type = apr_psprintf(r->pool, "image/bmp");
840 DBG(r,"convert to bmp(unsupported)");
842 /*--------------------------------------------------------------------------*/
843 /* Add Comment (Copyright and so on.) */
844 /*--------------------------------------------------------------------------*/
845 DBG(r,"call s_add_copyright()");
847 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
850 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
853 DestroyMagickWand(magick_wand);
854 DBG(r,"convert failure to Jpeg ");
858 DBG(r,"end convert and compression");
862 dst = apr_palloc(r->pool, writebyte+2);
864 memcpy(dst, writedata, writebyte);
865 /*--------------------------------------------------------------------------*/
866 /* CRC is added for AU for EzGET. */
867 /*--------------------------------------------------------------------------*/
868 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
869 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
870 crc = s_add_crc(writedata, writebyte);
871 dst[writebyte + 0] = (crc >> 8) & 0xff;
872 dst[writebyte + 1] = (crc ) & 0xff;
876 DestroyMagickWand(magick_wand);
883 s_fixup_size(MagickWand* magick_wand,
886 query_string_param_t *qsp)
888 img_conv_mode_t mode = qsp->mode;
896 oldw = MagickGetImageWidth(magick_wand);
897 oldh = MagickGetImageHeight(magick_wand);
899 DBG1(r,"detect width=[%d]", oldw);
900 DBG1(r,"detect heigh=[%d]", oldh);
905 DBG1(r,"detect spec width=[%d]", spec->width);
906 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
908 c_width = spec->width;
909 c_heigh = spec->heigh;
912 case IMG_CONV_MODE_THUMBNAIL:
914 DBG(r,"**** detect thumbnail mode ****");
916 if (neww > c_width) {
917 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
918 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
920 if (newh > c_heigh) {
921 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
922 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
925 neww = (int)((double)(neww / 3) * 0.8);
926 newh = (int)((double)(newh / 3) * 0.8);
929 case IMG_CONV_MODE_WALLPAPER:
930 case IMG_CONV_MODE_EZGET:
932 DBG(r,"**** detect wallpaper mode ****");
934 if (spec->wp_width && spec->wp_heigh) {
935 c_width = spec->wp_width;
936 c_heigh = spec->wp_heigh;
939 DBG(r,"calc new width and height");
941 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
942 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
944 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
949 DBG(r,"**** detect normal mode ****");
951 if (qsp->ua_flag != UA_IGN) {
952 if (neww > c_width) {
953 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
954 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
957 if (newh > c_heigh) {
958 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
959 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
965 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
966 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
968 MagickResetIterator(magick_wand);
970 while (MagickNextImage(magick_wand) != MagickFalse) {
972 case IMG_CONV_MODE_WALLPAPER:
973 case IMG_CONV_MODE_EZGET:
975 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
980 if (MagickCropImage(magick_wand,
981 (unsigned long)c_width,
982 (unsigned long)c_heigh,
983 (long)((neww - c_width) / 2),
984 (long)((newh - c_heigh) / 2)) == MagickFalse) {
990 case IMG_CONV_MODE_NORMAL:
992 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
996 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
1001 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1002 EXIT_MAGICK_ERROR();
1008 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1009 EXIT_MAGICK_ERROR();
1013 if (MagickSetImageResolution(magick_wand,
1014 (double)spec->dpi_width,
1015 (double)spec->dpi_heigh) == MagickFalse) {
1016 EXIT_MAGICK_ERROR();
1020 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1021 EXIT_MAGICK_ERROR();
1030 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t mode)
1032 DBG(r,"start chxj_fixup_clor()");
1034 if (spec->color >= 256) {
1036 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1038 if (MagickQuantizeImage(magick_wand,
1043 0) == MagickFalse) {
1044 EXIT_MAGICK_ERROR();
1048 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1052 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1054 if (MagickQuantizeImage(magick_wand,
1059 0) == MagickFalse) {
1060 EXIT_MAGICK_ERROR();
1064 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1068 DBG(r,"end chxj_fixup_clor()");
1076 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1078 if (spec->color == 15680000) {
1079 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1080 EXIT_MAGICK_ERROR();
1085 if (spec->color == 262144) {
1086 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1087 EXIT_MAGICK_ERROR();
1092 if (spec->color == 65536) {
1093 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1094 EXIT_MAGICK_ERROR();
1099 if (spec->color == 4096) {
1100 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1101 EXIT_MAGICK_ERROR();
1106 if (spec->color == 256) {
1107 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1108 EXIT_MAGICK_ERROR();
1113 if (spec->color == 4) {
1114 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1115 EXIT_MAGICK_ERROR();
1120 if (spec->color == 2) {
1121 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1122 EXIT_MAGICK_ERROR();
1132 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1134 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1136 if (conf->image_copyright) {
1138 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1140 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1141 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1142 if (MagickCommentImage(magick_wand,
1143 apr_psprintf(r->pool,
1145 conf->image_copyright)) == MagickFalse)
1149 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1150 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1151 if (MagickCommentImage(magick_wand,
1152 apr_psprintf(r->pool,
1153 "kddi_copyright=on,%s",
1154 conf->image_copyright)) == MagickFalse)
1158 if (MagickCommentImage(magick_wand,
1159 apr_psprintf(r->pool,
1161 conf->image_copyright)) == MagickFalse)
1166 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1172 EXIT_MAGICK_ERROR();
1177 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1179 MagickBooleanType status;
1180 unsigned long quality = 70;
1181 apr_size_t writebyte = 0;
1183 apr_size_t prev_size = 0;
1184 int revers_flag = 0;
1186 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1187 prev_size = writebyte;
1190 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1191 EXIT_MAGICK_ERROR();
1195 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1196 if (writebyte >= prev_size || revers_flag) {
1197 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1200 if (quality > 100) {
1201 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1202 EXIT_MAGICK_ERROR();
1207 prev_size = writebyte;
1211 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1213 if (spec->cache == 0)
1216 if (writebyte <= spec->cache)
1221 if (quality == 0 || quality > 100)
1229 && writebyte > spec->cache) {
1230 unsigned long now_color = spec->color;
1231 unsigned long depth = 0;
1234 case 2: depth = 1; break;
1235 case 4: now_color = 2; depth = 1; break;
1236 case 8: now_color = 4; depth = 2; break;
1237 case 16: now_color = 8; depth = 3; break;
1238 case 256: now_color = 16; depth = 4; break;
1239 case 4096: now_color = 256; depth = 8; break;
1240 case 65536: now_color = 4096; depth = 12; break;
1241 case 262144: now_color = 65536; depth = 16; break;
1242 case 15680000: now_color = 262144; depth = 18; break;
1248 if (now_color <= 2) break;
1250 if (now_color >= 8) {
1251 status = MagickQuantizeImage(magick_wand,
1259 status = MagickQuantizeImage(magick_wand,
1265 MagickSetImageType(magick_wand, GrayscaleType);
1267 if (status == MagickFalse) {
1268 EXIT_MAGICK_ERROR();
1272 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1273 EXIT_MAGICK_ERROR();
1277 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1279 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, writebyte);
1281 /* Once per request */
1284 while(now_color > 2);
1291 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1296 apr_size_t sendbyte;
1297 char* contentLength;
1299 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1300 if (rv != APR_SUCCESS)
1301 return HTTP_NOT_FOUND;
1303 DBG1(r, "mode:[%d]", query_string->mode);
1304 DBG1(r, "name:[%s]", query_string->name);
1305 DBG1(r, "offset:[%ld]", query_string->offset);
1306 DBG1(r, "count:[%ld]", query_string->count);
1308 if (spec->available_jpeg) {
1309 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1312 if (spec->available_png) {
1313 r->content_type = apr_psprintf(r->pool, "image/png");
1316 if (spec->available_gif) {
1317 r->content_type = apr_psprintf(r->pool, "image/gif");
1320 if (spec->available_bmp2 || spec->available_bmp4) {
1321 r->content_type = apr_psprintf(r->pool, "image/bmp");
1324 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1325 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1326 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1328 DBG1(r,"Content-Length:[%d]", (int)st.size);
1330 rv = apr_file_open(&fout, tmpfile,
1331 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1332 if (rv != APR_SUCCESS) {
1333 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1334 return HTTP_NOT_FOUND;
1337 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1338 apr_file_close(fout);
1340 DBG1(r, "send file data[%d]byte", sendbyte);
1343 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1344 char* name = apr_pstrdup(r->pool, basename(r->filename));
1345 name[strlen(name)-4] = 0;
1346 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1348 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1349 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1352 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1353 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1354 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1357 if (strcasecmp(r->content_type, "image/png") == 0) {
1358 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1359 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1362 if (strcasecmp(r->content_type, "image/gif") == 0) {
1363 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1364 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1368 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1369 if (query_string->count == -1 && query_string->offset == -1) {
1370 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1371 ap_rprintf(r, HDML_SUCCESS_PAGE);
1375 if (query_string->count == -2 && query_string->offset == -1) {
1376 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1377 ap_rprintf(r, HDML_FAIL_PAGE);
1381 ap_set_content_type(r, "application/x-up-download");
1382 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1383 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1385 DBG1(r, "Content-Length:[%d]", (int)st.size);
1387 rv = apr_file_open(&fout, tmpfile,
1388 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1390 if (rv != APR_SUCCESS) {
1391 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1392 return HTTP_NOT_FOUND;
1395 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1396 apr_file_close(fout);
1398 DBG1(r, "send file data[%d]byte", sendbyte);
1406 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1410 char* contentLength;
1412 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1413 if (rv != APR_SUCCESS)
1414 return HTTP_NOT_FOUND;
1416 DBG1(r, "mode:[%d]", query_string->mode);
1417 DBG1(r, "name:[%s]", query_string->name);
1418 DBG1(r, "offset:[%ld]", query_string->offset);
1419 DBG1(r, "count:[%ld]", query_string->count);
1421 if (spec->available_jpeg) {
1422 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1425 if (spec->available_png) {
1426 r->content_type = apr_psprintf(r->pool, "image/png");
1429 if (spec->available_gif) {
1430 r->content_type = apr_psprintf(r->pool, "image/gif");
1433 if (spec->available_bmp2 || spec->available_bmp4) {
1434 r->content_type = apr_psprintf(r->pool, "image/bmp");
1437 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1438 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1439 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1441 DBG1(r,"Content-Length:[%d]", (int)st.size);
1444 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1445 char* name = apr_pstrdup(r->pool, basename(r->filename));
1446 name[strlen(name)-4] = 0;
1447 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1449 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1452 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1453 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1456 if (strcasecmp(r->content_type, "image/png") == 0) {
1457 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1460 if (strcasecmp(r->content_type, "image/gif") == 0) {
1461 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1465 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1466 if (query_string->count == -1 && query_string->offset == -1) {
1467 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1470 if (query_string->count == -2 && query_string->offset == -1) {
1471 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1474 ap_set_content_type(r, "application/x-up-download");
1475 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1476 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1478 DBG1(r, "Content-Length:[%d]", (int)st.size);
1490 mod_chxj_config* conf,
1491 const char* user_agent,
1492 query_string_param_t *qsp)
1497 char* w = apr_palloc(r->pool, 256);
1501 switch (qsp->mode) {
1502 case IMG_CONV_MODE_THUMBNAIL:
1503 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1504 DBG1(r, "mode=thumbnail [%s]", fname);
1506 case IMG_CONV_MODE_WALLPAPER:
1507 case IMG_CONV_MODE_EZGET:
1508 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1509 DBG1(r, "mode=WallPaper [%s]", fname);
1511 case IMG_CONV_MODE_NORMAL:
1514 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1517 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1520 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1522 DBG1(r,"mode=normal [%s]", fname);
1525 if (qsp->ua_flag == UA_IGN) {
1526 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1529 len = strlen(fname);
1531 for (ii=0; ii<len; ii++) {
1532 if (fname[ii] == '/'
1536 || fname[ii] == ')') {
1540 w[jj++] = fname[ii];
1544 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1547 static unsigned short
1548 s_add_crc(const char* writedata, apr_size_t writebyte)
1550 unsigned short crc = 0xffff;
1554 for(ii=0;ii<writebyte;ii++) {
1556 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1562 chxj_trans_name(request_rec *r)
1569 mod_chxj_config* conf;
1577 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1583 int do_ext_check = TRUE;
1584 int next_ok = FALSE;
1586 DBG(r, "start chxj_trans_name()");
1588 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1591 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1595 if (conf->image != CHXJ_IMG_ON) {
1596 DBG(r, "end chxj_trans_name() conf not found");
1601 DBG1(r,"Match URI[%s]", r->uri);
1604 if (r->filename == NULL)
1605 r->filename = apr_pstrdup(r->pool, r->uri);
1608 if ((idx = strchr(r->filename, ':')) != NULL)
1609 filename_sv = idx+1;
1611 filename_sv = r->filename;
1613 DBG1(r,"r->filename[%s]", filename_sv);
1615 ccp = ap_document_root(r);
1617 return HTTP_INTERNAL_SERVER_ERROR;
1619 docroot = apr_pstrdup(r->pool, ccp);
1620 len = strlen(docroot);
1622 if (docroot[len-1] == '/')
1623 docroot[len-1] = '\0';
1627 && *filename_sv == *r->server->path
1628 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1629 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1631 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1633 DBG1(r,"URI[%s]", filename_sv);
1635 do_ext_check = TRUE;
1636 for (ii=0; ii<7-1; ii++) {
1637 char* pos = strrchr(filename_sv, '.');
1639 if (strcasecmp(pos, ext[ii]) == 0) {
1640 do_ext_check = FALSE;
1641 fname = apr_psprintf(r->pool, "%s", filename_sv);
1648 for (ii=0; ii<7; ii++) {
1649 if (strlen(ext[ii]) == 0) {
1650 fname = apr_psprintf(r->pool, "%s", filename_sv);
1653 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1655 DBG1(r,"search [%s]", fname);
1657 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1658 if (rv == APR_SUCCESS) {
1659 if (st.filetype != APR_DIR)
1666 if (fname == NULL) {
1667 DBG1(r,"NotFound [%s]", r->filename);
1670 for (ii=0; ii<7-1; ii++) {
1671 char* pos = strrchr(fname, '.');
1673 if (strcasecmp(pos, ext[ii]) == 0) {
1681 DBG1(r,"NotFound [%s]", r->filename);
1685 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1686 DBG1(r,"Found [%s]", fname);
1688 r->filename = apr_psprintf(r->pool, "%s", fname);
1690 if (strcasecmp("qrc", ext[ii]) == 0)
1691 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1693 r->handler = apr_psprintf(r->pool, "chxj-picture");
1695 DBG(r, "end chxj_trans_name()");
1702 * It converts it from QUERYSTRING.
1706 static query_string_param_t*
1707 s_get_query_string_param(request_rec *r)
1715 query_string_param_t* param;
1717 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1718 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1719 param->mode = IMG_CONV_MODE_NORMAL;
1720 param->user_agent = NULL;
1721 param->ua_flag = UA_USE;
1728 if (s == NULL) return param;
1731 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1734 name = apr_strtok(pair, "=", &vstate);
1735 value = apr_strtok(NULL, "=", &vstate);
1740 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1745 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1746 param->mode = IMG_CONV_MODE_THUMBNAIL;
1751 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1752 param->mode = IMG_CONV_MODE_WALLPAPER;
1757 if (strcasecmp(value, "EZGET") == 0)
1758 param->mode = IMG_CONV_MODE_EZGET;
1768 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1769 ap_unescape_url(value);
1771 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1772 param->ua_flag = UA_IGN;
1774 param->user_agent = apr_pstrdup(r->pool, value);
1780 if (value && strcasecmp(name, "name") == 0)
1781 param->name = apr_pstrdup(r->pool, value);
1786 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1787 param->offset = chxj_atoi(value);
1793 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1794 param->count = chxj_atoi(value);
1799 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1800 param->width = chxj_atoi(value);
1805 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1806 param->height = chxj_atoi(value);
1814 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1815 param->mode = IMG_CONV_MODE_WALLPAPER;