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_load_emoji_data.h"
21 static char* s_load_emoji_set_tag(
24 mod_chxj_config* conf,
27 static char* s_set_emoji_data(
30 mod_chxj_config* conf,
33 static char* s_load_emoji_emoji_tag(
36 mod_chxj_config* conf,
40 s_emoji_add_to_tail( mod_chxj_config* conf, emoji_t* emoji);
42 static char* s_load_emoji_no_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
43 static char* s_load_emoji_imode_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
44 static char* s_load_emoji_ezweb_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
45 static char* s_load_emoji_jphone_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
46 static char s_hexstring_to_byte(char* s);
56 mod_chxj_config* conf)
61 conf->emoji_tail = NULL;
63 if ((rtn = s_set_emoji_data(doc, p, conf,qs_get_root(doc))) != NULL)
76 mod_chxj_config* conf,
82 for (child = qs_get_child_node(doc,node);
84 child = qs_get_next_node(doc,child)) {
86 char* name = qs_get_node_name(doc,child);
88 if ((*name == 'e' || *name == 'E') && strcasecmp(name, "emoji") == 0) {
89 if ((rtn = s_load_emoji_emoji_tag(doc, p, conf, child)))
97 s_load_emoji_emoji_tag(
100 mod_chxj_config* conf,
106 for (child = qs_get_child_node(doc, node);
108 child = qs_get_next_node(doc, child)) {
110 char* name = qs_get_node_name(doc, child);
112 if ((*name == 's' || *name == 'S') && strcasecmp(name, "set") == 0) {
113 if ((rtn = s_load_emoji_set_tag(doc, p, conf, child)) != NULL)
123 s_load_emoji_set_tag(
126 mod_chxj_config* conf,
133 em = apr_palloc(p, sizeof(emoji_t));
134 em->imode = apr_palloc(p, sizeof(imode_emoji_t));
135 em->ezweb = apr_palloc(p, sizeof(ezweb_emoji_t));
136 em->jphone = apr_palloc(p, sizeof(jphone_emoji_t));
138 for (child = qs_get_child_node(doc, node);
140 child = qs_get_next_node(doc, child)) {
142 char* name = qs_get_node_name(doc, child);
147 if (strcasecmp(name, "no") == 0) {
148 if ((rtn = s_load_emoji_no_tag(doc, p, em, child)) != NULL)
155 if (strcasecmp(name, "imode") == 0) {
156 if ((rtn = s_load_emoji_imode_tag(doc, p, em, child)) != NULL)
163 if (strcasecmp(name, "ezweb") == 0) {
164 if ((rtn = s_load_emoji_ezweb_tag(doc, p, em, child)) != NULL)
171 if (strcasecmp(name, "jphone") == 0) {
172 if ((rtn = s_load_emoji_jphone_tag(doc, p, em, child)) != NULL)
182 s_emoji_add_to_tail(conf, em);
198 Node* child = qs_get_child_node(doc,node);
199 char* name = qs_get_node_name(doc, child);
200 char* value = qs_get_node_value(doc, child);
202 if ((*name == 't' || *name == 'T') && strcasecmp(name, "text") == 0) {
205 for (ii=0; ii<len; ii++) {
206 if (value[ii] < '0' || value[ii] > '9')
207 return apr_psprintf(p, "invalid data <no> tag [%s]", value);
209 em->no = atoi(value);
216 s_load_emoji_imode_tag(
224 em->imode->hex1byte = 0;
225 em->imode->hex2byte = 0;
226 em->imode->string = NULL;
227 em->imode->description = NULL;
229 for (child = qs_get_child_node(doc, node);
231 child = qs_get_next_node(doc, child)) {
233 char* name = qs_get_node_name(doc, child);
238 if (strcasecmp(name, "hex1") == 0) {
239 Node* hex1node = qs_get_child_node(doc, child);
242 char* cname = qs_get_node_name(doc, hex1node);
243 char* cvalue = qs_get_node_value(doc, hex1node);
245 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
246 em->imode->hex1byte = s_hexstring_to_byte(cvalue);
249 em->imode->hex1byte = 0;
253 if ((*name == 'h' || *name == 'H') && strcasecmp(name, "hex2") == 0) {
254 Node* hex2node = qs_get_child_node(doc, child);
256 char* cname = qs_get_node_name(doc, hex2node);
257 char* cvalue = qs_get_node_value(doc, hex2node);
259 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
260 em->imode->hex2byte = s_hexstring_to_byte(cvalue);
263 em->imode->hex2byte = 0;
270 if (strcasecmp(name, "string") == 0) {
271 Node* string_node = qs_get_child_node(doc, child);
274 char* cname = qs_get_node_name(doc, string_node);
275 char* cvalue = qs_get_node_value(doc, string_node);
277 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
278 em->imode->string = apr_pstrdup(p, cvalue);
281 em->imode->string = apr_palloc(p, 1);
282 em->imode->string[0] = 0;
289 if (strcasecmp(name, "description") == 0) {
290 Node* description_node = qs_get_child_node(doc, child);
292 if (description_node) {
293 char* cname = qs_get_node_name(doc, description_node);
294 char* cvalue = qs_get_node_value(doc, description_node);
296 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
297 em->imode->description = apr_pstrdup(p, cvalue);
300 em->imode->description = apr_palloc(p, 1);
301 em->imode->description[0] = 0;
316 s_load_emoji_ezweb_tag(
325 em->ezweb->typeA = NULL;
326 em->ezweb->typeB = NULL;
327 em->ezweb->typeC = NULL;
328 em->ezweb->typeD = NULL;
330 for (child = qs_get_child_node(doc, node);
332 child = qs_get_next_node(doc, child)) {
334 char* name = qs_get_node_name(doc, child);
336 if ((*name == 'a' || *name == 'A') && strcasecmp(name, "A") == 0) {
338 Node* typeAnode = qs_get_child_node(doc, child);
342 char* cname = qs_get_node_name(doc, typeAnode);
343 char* cvalue = qs_get_node_value(doc, typeAnode);
345 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
346 em->ezweb->typeA = apr_pstrdup(p,cvalue);
349 em->ezweb->typeA = apr_palloc(p, 1);
350 em->ezweb->typeA[0] = 0;
355 if ((*name == 'b' || *name == 'B') && strcasecmp(name, "B") == 0) {
357 Node* typeBnode = qs_get_child_node(doc, child);
361 char* cname = qs_get_node_name(doc, typeBnode);
362 char* cvalue = qs_get_node_value(doc, typeBnode);
364 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
365 em->ezweb->typeB = apr_pstrdup(p,cvalue);
369 em->ezweb->typeB = apr_palloc(p, 1);
370 em->ezweb->typeB[0] = 0;
374 if ((*name == 'c' || *name == 'C') && strcasecmp(name, "C") == 0) {
376 Node* typeCnode = qs_get_child_node(doc, child);
380 char* cname = qs_get_node_name(doc, typeCnode);
381 char* cvalue = qs_get_node_value(doc, typeCnode);
383 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
384 em->ezweb->typeC = apr_pstrdup(p,cvalue);
387 em->ezweb->typeC = apr_palloc(p, 1);
388 em->ezweb->typeC[0] = 0;
392 if ((*name == 'd' || *name == 'D') && strcasecmp(name, "D") == 0) {
394 Node* typeDnode = qs_get_child_node(doc, child);
398 char* cname = qs_get_node_name(doc, typeDnode);
399 char* cvalue = qs_get_node_value(doc, typeDnode);
401 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
402 em->ezweb->typeD = apr_pstrdup(p,cvalue);
406 em->ezweb->typeD = apr_palloc(p, 1);
407 em->ezweb->typeD[0] = 0;
417 s_load_emoji_jphone_tag(
426 em->jphone->string = NULL;
428 for (child = qs_get_child_node(doc, node);
430 child = qs_get_next_node(doc, child)) {
432 char* name = qs_get_node_name(doc, child);
434 if ((*name == 's' || *name == 'S') && strcasecmp(name, "string") == 0) {
436 Node* stringnode = qs_get_child_node(doc, child);
440 char* cname = qs_get_node_name(doc, stringnode);
441 char* cvalue = qs_get_node_value(doc, stringnode);
443 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0) {
448 tmp = apr_palloc(p, strlen(cvalue)+1);
449 memset(tmp, 0, strlen(cvalue)+1);
451 for (jj=0,ii=0; ii< strlen(cvalue); ii++) {
452 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_LT, strlen(ESCAPE_CHAR_LT)) == 0) {
455 ii += (strlen(ESCAPE_CHAR_LT) - 1);
458 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_GT, strlen(ESCAPE_CHAR_GT)) == 0) {
461 ii += (strlen(ESCAPE_CHAR_GT) - 1);
464 tmp[jj] = cvalue[ii];
468 em->jphone->string = apr_pstrdup(p,tmp);
472 em->jphone->string = apr_palloc(p, 1);
473 em->jphone->string[0] = 0;
485 mod_chxj_config* conf,
490 if (conf->emoji == NULL) {
492 conf->emoji_tail = emoji;
496 conf->emoji_tail->next = emoji;
497 conf->emoji_tail = emoji;
503 s_hexstring_to_byte(char* s)
511 for (ii=0; ii<len; ii++) {
523 one_byte |= (0xFF & (((s[ii] - '0') & 0xFF) << ((1-ii)*4)));
527 one_byte |= (0xFF & ((0x0A & 0xFF) << ((1-ii)*4)));
531 one_byte |= (0xFF & ((0x0B & 0xFF) << ((1-ii)*4)));
535 one_byte |= (0xFF & ((0x0C & 0xFF) << ((1-ii)*4)));
539 one_byte |= (0xFF & ((0x0d & 0xFF) << ((1-ii)*4)));
543 one_byte |= (0xFF & ((0x0e & 0xFF) << ((1-ii)*4)));
547 one_byte |= (0xFF & ((0x0f & 0xFF) << ((1-ii)*4)));