2 * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. 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.
17 #include "chxj_tag_util.h"
18 #include "chxj_url_encode.h"
19 #include "chxj_str_util.h"
23 * The value of the VALUE attribute that the object tag node maintains is
26 * @param doc [i] The pointer to the Doc structure to be scanned is
28 * @param node [i] The tag node to be scanned is specified.
29 * @param pool [i] To use POOL.
30 * @return The value of the VALUE attribute that the object tag node maintains
31 * is returned. NULL is returned when not found.
34 qs_get_value_attr(Doc *doc, Node *node, apr_pool_t *pool)
38 /*--------------------------------------------------------------------------*/
39 /* The object tag node is scanned. */
40 /*--------------------------------------------------------------------------*/
41 for (attr = qs_get_attr(doc,node);
43 attr = qs_get_next_attr(doc,attr)) {
44 char *name = qs_get_attr_name(doc,attr);
45 char *value = qs_get_attr_value(doc,attr);
46 if (STRCASEEQ('v','V',"value",name)) {
47 /*----------------------------------------------------------------------*/
48 /* The VALUE attribute was found. */
49 /*----------------------------------------------------------------------*/
50 return apr_pstrdup(pool, value);
53 /*--------------------------------------------------------------------------*/
55 /*--------------------------------------------------------------------------*/
61 * The value of the checked tag is acquired.
63 * @param doc [i] The pointer to the Doc structure to be scanned is
65 * @param tag [i] The tag node to be scanned is specified.
66 * @param pool [i] To use POOL(unused).
67 * @return The value of the checked tag is returned. NULL is returned when
71 qs_get_checked_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
74 /*--------------------------------------------------------------------------*/
75 /* The object tag node is scanned. */
76 /*--------------------------------------------------------------------------*/
77 for (attr = qs_get_attr(doc,tag);
79 attr = qs_get_next_attr(doc,attr)) {
80 char *name = qs_get_attr_name(doc,attr);
81 if (STRCASEEQ('c','C',"checked",name)) {
82 /*----------------------------------------------------------------------*/
83 /* The VALUE attribute was found. */
84 /*----------------------------------------------------------------------*/
88 /*------------------------------------------------------------------------*/
90 /*------------------------------------------------------------------------*/
96 * The value of the type attribute is acquired.
98 * @param doc [i] The pointer to the Doc structure to be scanned is
100 * @param tag [i] The tag node to be scanned is specified.
101 * @param r [i] To use POOL, the pointer to request_rec is specified.
102 * @return The value of the type attribute is returned. NULL is returned when
106 qs_get_type_attr(Doc *doc, Node *tag, apr_pool_t *pool)
109 /*--------------------------------------------------------------------------*/
110 /* The object tag node is scanned. */
111 /*--------------------------------------------------------------------------*/
112 for (attr = qs_get_attr(doc,tag);
114 attr = qs_get_next_attr(doc,attr)) {
115 char *name = qs_get_attr_name(doc,attr);
116 char *value = qs_get_attr_value(doc,attr);
117 if (STRCASEEQ('t','T',"type",name)) {
118 /*----------------------------------------------------------------------*/
119 /* The VALUE attribute was found. */
120 /*----------------------------------------------------------------------*/
121 return apr_pstrdup(pool, value);
124 /*--------------------------------------------------------------------------*/
126 /*--------------------------------------------------------------------------*/
132 * The character string area in 0 bytes is allocated.
134 * @param pool [i] To use POOL.
135 * @return The allocated 0 byte character string is returned.
138 qs_alloc_zero_byte_string(apr_pool_t *pool)
145 tgt = apr_palloc(pool, 1);
153 * A consecutive head and the last WHITESPACE are removed.
155 * @param p [i] To use POOL
156 * @param s [i] The character string that should be removed is specified.
157 * @return The character string that has been removed is returned.
160 qs_trim_string(apr_pool_t *p, char *s)
166 if (! s) return apr_pstrdup(p, "");
168 ss = apr_pstrdup(p, s);
171 for (ii = 0;is_white_space(*ss) && ii < len; ss++, ii++);
174 for(;is_white_space(ss[ii-1]) && ii > 0; ii--);
183 * The value of child TEXT of tag that maintains the SELECTED attribute is
186 * @param Doc [i] The pointer to the Doc structure to be scanned is
188 * @param node [i] The tag node to be scanned is specified.
189 * @param pool [i] To use POOL.
190 * @reutrn The value of child TEXT of tag that maintains the SELECTED
191 * attribute is returned. NULL is returned when not found.
194 qs_get_selected_value_text(Doc *doc, Node *node, apr_pool_t *pool)
200 for (child = qs_get_child_node(doc,node);
202 child = qs_get_next_node(doc,child)) {
203 char *name = qs_get_node_name(doc,child);
204 /*------------------------------------------------------------------------*/
206 /*------------------------------------------------------------------------*/
207 if (STRCASEEQ('o','O',"option",name)) {
209 for (attr = qs_get_attr(doc,child);
211 attr = qs_get_next_attr(doc,attr)) {
212 char *name2 = qs_get_attr_name(doc,attr);
213 if (STRCASEEQ('s','S',"selected",name2)) {
214 /*------------------------------------------------------------------*/
215 /* SELECTED Value Found */
216 /*------------------------------------------------------------------*/
217 selchild = qs_get_child_node(doc, child);
220 return apr_pstrdup(pool, "");
222 return qs_get_node_value(doc, selchild);
227 if ((result = qs_get_selected_value_text(doc, child, pool)) != NULL) {
232 /*--------------------------------------------------------------------------*/
234 /*--------------------------------------------------------------------------*/
240 * The value of tag that maintains the SELECTED attribute is acquired.
242 * @param doc [i] The pointer to the Doc structure to be scanned is
244 * @param node [i] The SELECT tag node is specified.
245 * @param pool [i] To use POOL.
246 * @return The value of tag that maintains the SELECTED attribute is
247 * returned. NULL is returned when not found.
250 qs_get_selected_value(Doc *doc, Node *node, apr_pool_t *pool)
255 for (child = qs_get_child_node(doc,node);
257 child = qs_get_next_node(doc,child)) {
258 char *name = qs_get_node_name(doc,child);
259 /*------------------------------------------------------------------------*/
261 /*------------------------------------------------------------------------*/
262 if (STRCASEEQ('o','O',"option",name)) {
264 for (attr = qs_get_attr(doc,child);
266 attr = qs_get_next_attr(doc,attr)) {
267 char *name2 = qs_get_attr_name(doc,attr);
268 if (STRCASEEQ('s','S',"selected",name2)) {
269 /*------------------------------------------------------------------*/
270 /* SELECTED Value Found */
271 /*------------------------------------------------------------------*/
272 return qs_get_value_attr(doc, child, doc->buf.pool);
277 if ((result = qs_get_selected_value(doc, child, pool)) != NULL) {
282 /*--------------------------------------------------------------------------*/
284 /*--------------------------------------------------------------------------*/
290 * The value of the NAME attribute is acquired.
292 * @param doc [i] The pointer to the Doc structure at the output
293 * destination is specified.
294 * @param tag [i] The tag node to want to acquire the SIZE attribute
296 * @param pool [i] To use POOL.
297 * @return The value of the NAME attribute is returned. NULL is
298 * returned when not is.
301 qs_get_name_attr(Doc *doc, Node *tag, apr_pool_t *pool)
304 for (attr = qs_get_attr(doc,tag);
306 attr = qs_get_next_attr(doc,attr)) {
307 char *name = qs_get_attr_name(doc,attr);
308 char *value = qs_get_attr_value(doc,attr);
309 if (STRCASEEQ('n','N',"name",name)) {
310 return apr_pstrdup(pool, (value ? value : ""));
318 * The value of the SIZE attribute is acquired.
320 * @param doc [i] The pointer to the Doc structure at the output
321 * destination is specified.
322 * @param tag [i] The tag node to want to acquire the SIZE attribute
324 * @param pool [i] To use POOL.
325 * @return The value of the SIZE attribute is returned. NULL is
326 * returned when not is.
329 qs_get_size_attr(Doc *doc, Node *tag, apr_pool_t *pool)
332 for (attr = qs_get_attr(doc,tag);
334 attr = qs_get_next_attr(doc,attr)) {
335 char *name = qs_get_attr_name(doc,attr);
336 char *value = qs_get_attr_value(doc,attr);
337 if (STRCASEEQ('s','S',"size",name)) {
338 return apr_pstrdup(pool, (value ? value : ""));
346 * The value of the ACCESSKEY attribute is acquired.
348 * @param doc [i] The pointer to the Doc structure at the output
349 * destination is specified.
350 * @param tag [i] The tag node to want to acquire the ACCESSKEY attribute
352 * @param pool [i] To use POOL.
353 * @return The value of the ACCESSKEY attribute is returned. NULL is
354 * returned when not is.
357 qs_get_accesskey_attr(Doc *doc, Node *tag, apr_pool_t *pool)
360 for (attr = qs_get_attr(doc,tag);
362 attr = qs_get_next_attr(doc,attr)) {
363 char *name = qs_get_attr_name(doc,attr);
364 char *value = qs_get_attr_value(doc,attr);
365 if (STRCASEEQ('a','A',"accesskey",name)) {
366 return apr_pstrdup(pool, value);
374 * The value of the ISTYLE attribute is acquired.
376 * @param doc [i] The pointer to the Doc structure at the output
377 * destination is specified.
378 * @param tag [i] The tag node to want to acquire the ISTYLE attribute
380 * @param pool [i] To use POOL.
381 * @return The value of the ISTYLE attribute is returned. NULL is
382 * returned when not is.
385 qs_get_istyle_attr(Doc *doc, Node *tag, apr_pool_t *pool)
388 for (attr = qs_get_attr(doc,tag);
390 attr = qs_get_next_attr(doc,attr)) {
391 char *name = qs_get_attr_name(doc,attr);
392 char *value = qs_get_attr_value(doc,attr);
393 if (STRCASEEQ('i','I',"istyle",name)) {
394 return apr_pstrdup(pool, value);
402 * The value of the MAXLENGTH attribute is acquired from the tag node of the
405 * @param doc [i] The pointer to the Doc structure at the output
406 * destination is specified.
407 * @param tag [i] The tag node to want to acquire the MAXLENGTH attribute
409 * @param pool [i] To use POOL.
410 * @return The value of the MAXLENGTH attribute is returned. NULL is
411 * returned when not is.
414 qs_get_maxlength_attr(Doc *doc, Node *tag, apr_pool_t *pool)
417 for (attr = qs_get_attr(doc,tag);
419 attr = qs_get_next_attr(doc,attr)) {
420 char *name = qs_get_attr_name(doc,attr);
421 char *value = qs_get_attr_value(doc,attr);
422 if (STRCASEEQ('m','M',"maxlength",name)) {
423 return apr_pstrdup(pool, value);
431 * It is scanned whether the CHECKBOX tag of the object is CHECKED.
433 * @param doc [i] The pointer to the Doc structure at the output
434 * destination is specified.
435 * @param tag [i] The tag node to want to acquire the CHECKBOX attribute
437 * @param pool [i] To use POOL.
438 * @return 1 is returned when it is CHECKED and, additionally, 0 is returned.
441 qs_is_checked_checkbox_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
444 for (attr = qs_get_attr(doc,tag);
446 attr = qs_get_next_attr(doc,attr)) {
447 char *name = qs_get_attr_name(doc,attr);
448 if (STRCASEEQ('c','C',"checked",name)) {
457 chxj_chxjif_is_mine(device_table *spec, Doc *doc, Node *tag)
459 request_rec *r = doc->r;
462 for (attr = qs_get_attr(doc,tag);
464 attr = qs_get_next_attr(doc,attr)) {
465 char *name = qs_get_attr_name(doc,attr);
466 char *value = qs_get_attr_value(doc,attr);
467 if ((*name == 'l' || *name == 'L') && strcasecmp(name, "lang") == 0) {
469 DBG(r, "lang found [%s] spec [%d]", value, spec->html_spec_type);
471 if (STRCASEEQ('x','X',"xhtml",value)) {
472 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0) {
473 /* Yes , it is mine */
477 else if (STRCASEEQ('h','H',"hdml",value)) {
478 if (spec->html_spec_type == CHXJ_SPEC_Hdml) {
479 /* Yes , it is mine */
483 else if (STRCASEEQ('j','J',"jhtml",value)) {
484 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
485 /* Yes , it is mine */
489 else if (STRCASEEQ('j','J',"jxhtml",value)) {
490 if (spec->html_spec_type == CHXJ_SPEC_Jxhtml) {
491 /* Yes , it is mine */
495 else if (STRCASEEQ('c','C',"chtml",value)) {
496 switch (spec->html_spec_type) {
497 case CHXJ_SPEC_Chtml_1_0:
498 case CHXJ_SPEC_Chtml_2_0:
499 case CHXJ_SPEC_Chtml_3_0:
500 case CHXJ_SPEC_Chtml_4_0:
501 case CHXJ_SPEC_Chtml_5_0:
502 case CHXJ_SPEC_Chtml_6_0:
503 case CHXJ_SPEC_Chtml_7_0:
509 else if (STRCASEEQ('c','C',"cxhtml",value)) {
510 switch (spec->html_spec_type) {
511 case CHXJ_SPEC_Chtml_6_0:
512 case CHXJ_SPEC_Chtml_7_0:
521 /* No, it is not mine. */
527 * The value of the DESTLANG attribute is acquired from the tag node of the
530 * @param doc [i] The pointer to the Doc structure at the output
531 * destination is specified.
532 * @param tag [i] The tag node to want to acquire the DESTLANG attribute
534 * @param pool [i] To use POOL.
535 * @return The value of the DESTLANG attribute is returned. NULL is
536 * returned when not is.
539 qs_get_destlang_attr(Doc *doc, Node *tag, apr_pool_t *pool)
542 for (attr = qs_get_attr(doc,tag);
544 attr = qs_get_next_attr(doc,attr)) {
545 char *name = qs_get_attr_name(doc,attr);
546 char *value = qs_get_attr_value(doc,attr);
547 if (STRCASEEQ('d','D',"destlang",name)) {
548 return apr_pstrdup(pool, value);
557 * The value of the PARSE attribute is acquired.
559 * @param doc [i] The pointer to the Doc structure to be scanned is
561 * @param tag [i] The tag node to be scanned is specified.
562 * @param pool [i] To use POOL.
563 * @return The value of the PARSE attribute is returned. NULL is returned when
567 qs_get_parse_attr(Doc *doc, Node *tag, apr_pool_t *pool)
570 /*--------------------------------------------------------------------------*/
571 /* The object tag node is scanned. */
572 /*--------------------------------------------------------------------------*/
573 for (attr = qs_get_attr(doc,tag);
575 attr = qs_get_next_attr(doc,attr)) {
576 char *name = qs_get_attr_name(doc,attr);
577 char *value = qs_get_attr_value(doc,attr);
578 if (STRCASEEQ('p','P',"parse",name)) {
579 /*----------------------------------------------------------------------*/
580 /* The VALUE attribute was found. */
581 /*----------------------------------------------------------------------*/
582 return apr_pstrdup(pool, value);
586 /*--------------------------------------------------------------------------*/
588 /*--------------------------------------------------------------------------*/
594 chxj_form_action_to_hidden_tag(request_rec *r, apr_pool_t *pool, const char *str, int xmlFlag, int post, char **new_query_string, int docomo)
596 char *s = apr_pstrdup(pool, str);
597 *new_query_string = NULL;
599 if (chxj_starts_with(s, "http://") || chxj_starts_with(s, "https://")) {
601 apr_uri_parse(pool, s, &url);
602 if (url.hostname && strcasecmp(url.hostname, r->hostname) != 0) {
614 char *pair = apr_strtok(s, "&", &pstat);
617 char *key = apr_strtok(pair, "=", &pstat2);
620 val = apr_strtok(NULL, "=", &pstat2);
624 if (post && strcasecmp(key, "guid") == 0 && docomo) {
625 *new_query_string = apr_psprintf(pool, "%s=%s", key, val);
628 if (! post || strcasecmp(key, "_chxj_cc") == 0 || strcasecmp(key, "_chxj_nc") == 0) {
629 tmp = apr_psprintf(pool, "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>", key, chxj_url_decode(pool, val), (xmlFlag == 1) ? " /" : "");
632 tmp = apr_psprintf(pool, "<input type=\"hidden\" name=\"_chxj_qs_%s\" value=\"%s\"%s>", key, chxj_url_decode(pool, val), (xmlFlag == 1) ? " /" : "");
635 result = apr_pstrcat(pool, result, tmp, NULL);