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"
21 * The value of the VALUE attribute that the object tag node maintains is
24 * @param doc [i] The pointer to the Doc structure to be scanned is
26 * @param node [i] The tag node to be scanned is specified.
27 * @param r [i] To use POOL, the pointer to request_rec is specified.
28 * @return The value of the VALUE attribute that the object tag node maintains
29 * is returned. NULL is returned when not found.
32 qs_get_value_attr(Doc *doc, Node *node, request_rec *r)
36 /*--------------------------------------------------------------------------*/
37 /* The object tag node is scanned. */
38 /*--------------------------------------------------------------------------*/
39 for (attr = qs_get_attr(doc,node);
41 attr = qs_get_next_attr(doc,attr)) {
45 name = qs_get_attr_name(doc,attr);
46 value = qs_get_attr_value(doc,attr);
48 if ((*name == 'v' || *name == 'V') && strcasecmp(name, "value") == 0)
49 /*----------------------------------------------------------------------*/
50 /* The VALUE attribute was found. */
51 /*----------------------------------------------------------------------*/
52 return apr_pstrdup(r->pool, value);
55 /*--------------------------------------------------------------------------*/
57 /*--------------------------------------------------------------------------*/
63 * The value of the checked tag is acquired.
65 * @param doc [i] The pointer to the Doc structure to be scanned is
67 * @param tag [i] The tag node to be scanned is specified.
68 * @param r [i] To use POOL, the pointer to request_rec is specified.
69 * @return The value of the checked tag is returned. NULL is returned when
73 qs_get_checked_attr(Doc *doc, Node *tag, request_rec *r)
78 /*--------------------------------------------------------------------------*/
79 /* The object tag node is scanned. */
80 /*--------------------------------------------------------------------------*/
81 for (attr = qs_get_attr(doc,tag);
83 attr = qs_get_next_attr(doc,attr)) {
84 char *name = qs_get_attr_name(doc,attr);
85 if ((*name == 'c' || *name == 'C') && strcasecmp(name, "checked") == 0) {
86 /*----------------------------------------------------------------------*/
87 /* The VALUE attribute was found. */
88 /*----------------------------------------------------------------------*/
92 /*------------------------------------------------------------------------*/
94 /*------------------------------------------------------------------------*/
100 * The value of the type attribute is acquired.
102 * @param doc [i] The pointer to the Doc structure to be scanned is
104 * @param tag [i] The tag node to be scanned is specified.
105 * @param r [i] To use POOL, the pointer to request_rec is specified.
106 * @return The value of the type attribute is returned. NULL is returned when
110 qs_get_type_attr(Doc *doc, Node *tag, request_rec *r)
114 /*--------------------------------------------------------------------------*/
115 /* The object tag node is scanned. */
116 /*--------------------------------------------------------------------------*/
117 for (attr = qs_get_attr(doc,tag);
119 attr = qs_get_next_attr(doc,attr)) {
120 char *name = qs_get_attr_name(doc,attr);
121 char *value = qs_get_attr_value(doc,attr);
123 if ((*name == 't' || *name == 'T') && strcasecmp(name, "type") == 0)
124 /*----------------------------------------------------------------------*/
125 /* The VALUE attribute was found. */
126 /*----------------------------------------------------------------------*/
127 return apr_pstrdup(r->pool, value);
129 /*--------------------------------------------------------------------------*/
131 /*--------------------------------------------------------------------------*/
137 * The character string area in 0 bytes is allocated.
139 * @param r [i] To use POOL, the pointer to request_rec is specified.
140 * @return The allocated 0 byte character string is returned.
143 qs_alloc_zero_byte_string(request_rec *r)
145 char *tgt = apr_palloc(r->pool, 1);
153 * A consecutive head and the last WHITESPACE are removed.
155 * @param p [i] To use POOL, the pointer to request_rec is specified.
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)
162 char *ss = apr_pstrdup(p, s);
167 for (ii = 0;is_white_space(*ss) && ii < len; ss++, ii++);
170 for(;is_white_space(ss[ii-1]) && ii > 0; ii--);
179 * The value of child TEXT of tag that maintains the SELECTED attribute is
182 * @param Doc [i] The pointer to the Doc structure to be scanned is
184 * @param node [i] The tag node to be scanned is specified.
185 * @param r [i] To use POOL, the pointer to request_rec is specified.
186 * @reutrn The value of child TEXT of tag that maintains the SELECTED
187 * attribute is returned. NULL is returned when not found.
190 qs_get_selected_value_text(Doc *doc, Node *node, request_rec *r)
196 for (child = qs_get_child_node(doc,node);
198 child = qs_get_next_node(doc,child)) {
199 char *name = qs_get_node_name(doc,child);
201 /*------------------------------------------------------------------------*/
203 /*------------------------------------------------------------------------*/
204 if ((*name == 'o' || *name == 'O') && strcasecmp(name, "option") == 0) {
207 for (attr = qs_get_attr(doc,child);
209 attr = qs_get_next_attr(doc,attr)) {
210 char *name = qs_get_attr_name(doc,attr);
211 DBG(r, "qs_get_selected_value name::[%s]" , name);
213 if ((*name == 's'|| *name == 'S') && strcasecmp(name, "selected") == 0) {
214 /*------------------------------------------------------------------*/
215 /* SELECTED Value Found */
216 /*------------------------------------------------------------------*/
217 selchild = qs_get_child_node(doc, child);
219 DBG(r,"found selected tag but null node" );
222 return qs_get_node_value(doc, selchild);
227 if ((result = qs_get_selected_value_text(doc, child, r)) != NULL)
231 /*--------------------------------------------------------------------------*/
233 /*--------------------------------------------------------------------------*/
239 * The value of tag that maintains the SELECTED attribute is acquired.
241 * @param doc [i] The pointer to the Doc structure to be scanned is
243 * @param node [i] The SELECT tag node is specified.
244 * @param r [i] To use POOL, the pointer to request_rec is specified.
245 * @return The value of tag that maintains the SELECTED attribute is
246 * returned. NULL is returned when not found.
249 qs_get_selected_value(Doc *doc, Node *node, request_rec *r)
254 for (child = qs_get_child_node(doc,node);
256 child = qs_get_next_node(doc,child)) {
257 char *name = qs_get_node_name(doc,child);
259 /*------------------------------------------------------------------------*/
261 /*------------------------------------------------------------------------*/
262 if ((*name == 'o' || *name == 'O') && strcasecmp(name, "option") == 0) {
265 for (attr = qs_get_attr(doc,child);
267 attr = qs_get_next_attr(doc,attr)) {
269 char *name = qs_get_attr_name(doc,attr);
271 DBG(r, "qs_get_selected_value name::[%s]" , name);
273 if ((*name == 's' || *name == 'S') && strcasecmp(name, "selected") == 0)
274 /*------------------------------------------------------------------*/
275 /* SELECTED Value Found */
276 /*------------------------------------------------------------------*/
277 return qs_get_value_attr(doc, child, r);
281 if ((result = qs_get_selected_value(doc, child, r)) != NULL)
285 /*--------------------------------------------------------------------------*/
287 /*--------------------------------------------------------------------------*/
293 * The value of the SIZE attribute is acquired.
295 * @param doc [i] The pointer to the Doc structure at the output
296 * destination is specified.
297 * @param tag [i] The tag node to want to acquire the SIZE attribute
299 * @param r [i] To use POOL, the pointer to request_rec is specified.
300 * @return The value of the SIZE attribute is returned. NULL is
301 * returned when not is.
304 qs_get_name_attr(Doc *doc, Node *tag, request_rec *r)
308 for (attr = qs_get_attr(doc,tag);
310 attr = qs_get_next_attr(doc,attr)) {
311 char *name = qs_get_attr_name(doc,attr);
312 char *value = qs_get_attr_value(doc,attr);
314 if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0)
315 return apr_pstrdup(r->pool, value);
323 * The value of the SIZE attribute is acquired.
325 * @param doc [i] The pointer to the Doc structure at the output
326 * destination is specified.
327 * @param tag [i] The tag node to want to acquire the SIZE attribute
329 * @param r [i] To use POOL, the pointer to request_rec is specified.
330 * @return The value of the SIZE attribute is returned. NULL is
331 * returned when not is.
334 qs_get_size_attr(Doc *doc, Node *tag, request_rec *r)
338 for (attr = qs_get_attr(doc,tag);
340 attr = qs_get_next_attr(doc,attr)) {
341 char *name = qs_get_attr_name(doc,attr);
342 char *value = qs_get_attr_value(doc,attr);
344 if ((*name == 's' || *name == 'S') && strcasecmp(name, "size") == 0)
345 return apr_pstrdup(r->pool, value);
353 * The value of the ACCESSKEY attribute is acquired.
355 * @param doc [i] The pointer to the Doc structure at the output
356 * destination is specified.
357 * @param tag [i] The tag node to want to acquire the ACCESSKEY attribute
359 * @param r [i] To use POOL, the pointer to request_rec is specified.
360 * @return The value of the ACCESSKEY attribute is returned. NULL is
361 * returned when not is.
364 qs_get_accesskey_attr(Doc *doc, Node *tag, request_rec *r)
368 for (attr = qs_get_attr(doc,tag);
370 attr = qs_get_next_attr(doc,attr)) {
372 char *name = qs_get_attr_name(doc,attr);
373 char *value = qs_get_attr_value(doc,attr);
374 if ((*name == 'a' || *name == 'A') && strcasecmp(name, "accesskey") == 0)
375 return apr_pstrdup(r->pool, value);
383 * The value of the ISTYLE attribute is acquired.
385 * @param doc [i] The pointer to the Doc structure at the output
386 * destination is specified.
387 * @param tag [i] The tag node to want to acquire the ISTYLE attribute
389 * @param r [i] To use POOL, the pointer to request_rec is specified.
390 * @return The value of the ISTYLE attribute is returned. NULL is
391 * returned when not is.
394 qs_get_istyle_attr(Doc *doc, Node *tag, request_rec *r)
398 for (attr = qs_get_attr(doc,tag);
400 attr = qs_get_next_attr(doc,attr)) {
402 char *name = qs_get_attr_name(doc,attr);
403 char *value = qs_get_attr_value(doc,attr);
405 if ((*name == 'i' || *name == 'I') && strcasecmp(name, "istyle") == 0)
406 return apr_pstrdup(r->pool, value);
414 * The value of the MAXLENGTH attribute is acquired from the tag node of the
417 * @param doc [i] The pointer to the Doc structure at the output
418 * destination is specified.
419 * @param tag [i] The tag node to want to acquire the MAXLENGTH attribute
421 * @param r [i] To use POOL, the pointer to request_rec is specified.
422 * @return The value of the MAXLENGTH attribute is returned. NULL is
423 * returned when not is.
426 qs_get_maxlength_attr(Doc *doc, Node *tag, request_rec *r)
430 for (attr = qs_get_attr(doc,tag);
432 attr = qs_get_next_attr(doc,attr)) {
434 char *name = qs_get_attr_name(doc,attr);
435 char *value = qs_get_attr_value(doc,attr);
437 if ((*name == 'm' || *name == 'M') && strcasecmp(name, "maxlength") == 0)
438 return apr_pstrdup(r->pool, value);
446 * It is scanned whether the CHECKBOX tag of the object is CHECKED.
448 * @param doc [i] The pointer to the Doc structure at the output
449 * destination is specified.
450 * @param tag [i] The tag node to want to acquire the CHECKBOX attribute
452 * @param r [i] To use POOL, the pointer to request_rec is specified.
453 * @return 1 is returned when it is CHECKED and, additionally, 0 is returned.
456 qs_is_checked_checkbox_attr(Doc* doc, Node* tag, request_rec* UNUSED(r))
460 for (attr = qs_get_attr(doc,tag);
462 attr = qs_get_next_attr(doc,attr)) {
463 char *name = qs_get_attr_name(doc,attr);
465 if ((*name == 'c' || *name == 'C') && strcasecmp(name, "checked") == 0)
474 chxj_chxjif_is_mine(device_table *spec, Doc *doc, Node *tag)
476 request_rec *r = doc->r;
479 for (attr = qs_get_attr(doc,tag);
481 attr = qs_get_next_attr(doc,attr)) {
482 char *name = qs_get_attr_name(doc,attr);
483 char *value = qs_get_attr_value(doc,attr);
485 if ((*name == 'l' || *name == 'L') && strcasecmp(name, "lang") == 0) {
487 DBG(r, "lang found [%s] spec [%d]", value, spec->html_spec_type);
489 if ((*value == 'x' || *value == 'X') && strcasecmp(value, "xhtml") == 0) {
490 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0) {
491 /* Yes , it is mine */
496 if ((*value == 'h' || *value == 'H') && strcasecmp(value, "hdml") == 0) {
497 if (spec->html_spec_type == CHXJ_SPEC_Hdml) {
498 /* Yes , it is mine */
503 if ((*value == 'j' || *value == 'J') && strcasecmp(value, "jhtml") == 0) {
504 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
505 /* Yes , it is mine */
510 if ((*value == 'c' || *value == 'C') && strcasecmp(value, "chtml") == 0) {
511 switch (spec->html_spec_type) {
512 case CHXJ_SPEC_Chtml_1_0:
513 case CHXJ_SPEC_Chtml_2_0:
514 case CHXJ_SPEC_Chtml_3_0:
515 case CHXJ_SPEC_Chtml_4_0:
516 case CHXJ_SPEC_Chtml_5_0:
517 case CHXJ_SPEC_Chtml_6_0:
518 case CHXJ_SPEC_Chtml_7_0:
527 /* No, it is not mine. */
533 * The value of the DESTLANG attribute is acquired from the tag node of the
536 * @param doc [i] The pointer to the Doc structure at the output
537 * destination is specified.
538 * @param tag [i] The tag node to want to acquire the DESTLANG attribute
540 * @param r [i] To use POOL, the pointer to request_rec is specified.
541 * @return The value of the DESTLANG attribute is returned. NULL is
542 * returned when not is.
545 qs_get_destlang_attr(Doc *doc, Node *tag, request_rec *r)
549 for (attr = qs_get_attr(doc,tag);
551 attr = qs_get_next_attr(doc,attr)) {
553 char *name = qs_get_attr_name(doc,attr);
554 char *value = qs_get_attr_value(doc,attr);
556 if ((*name == 'd' || *name == 'D') && strcasecmp(name, "destlang") == 0)
557 return apr_pstrdup(r->pool, value);
565 * The value of the PARSE attribute is acquired.
567 * @param doc [i] The pointer to the Doc structure to be scanned is
569 * @param tag [i] The tag node to be scanned is specified.
570 * @param r [i] To use POOL, the pointer to request_rec is specified.
571 * @return The value of the PARSE attribute is returned. NULL is returned when
575 qs_get_parse_attr(Doc *doc, Node *tag, request_rec *r)
579 /*--------------------------------------------------------------------------*/
580 /* The object tag node is scanned. */
581 /*--------------------------------------------------------------------------*/
582 for (attr = qs_get_attr(doc,tag);
584 attr = qs_get_next_attr(doc,attr)) {
585 char *name = qs_get_attr_name(doc,attr);
586 char *value = qs_get_attr_value(doc,attr);
588 if ((*name == 'p' || *name == 'P') && strcasecmp(name, "parse") == 0) {
589 /*----------------------------------------------------------------------*/
590 /* The VALUE attribute was found. */
591 /*----------------------------------------------------------------------*/
592 return apr_pstrdup(r->pool, value);
596 /*--------------------------------------------------------------------------*/
598 /*--------------------------------------------------------------------------*/