2 * Copyright (C) 2005-2009 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.
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,
39 static void s_emoji_add_to_tail(
40 mod_chxj_config* conf,
43 static char* s_load_emoji_no_tag(
49 static char* s_load_emoji_imode_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
51 static char* s_load_emoji_ezweb_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
53 static char* s_load_emoji_jphone_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
55 static char s_hexstring_to_byte(char* s);
65 mod_chxj_config* conf)
70 conf->emoji_tail = NULL;
72 if ((rtn = s_set_emoji_data(doc, p, conf,qs_get_root(doc))) != NULL)
85 mod_chxj_config* conf,
91 for (child = qs_get_child_node(doc,node);
93 child = qs_get_next_node(doc,child)) {
95 char* name = qs_get_node_name(doc,child);
97 if ((*name == 'e' || *name == 'E') && strcasecmp(name, "emoji") == 0) {
98 if ((rtn = s_load_emoji_emoji_tag(doc, p, conf, child)))
106 s_load_emoji_emoji_tag(
109 mod_chxj_config* conf,
115 for (child = qs_get_child_node(doc, node);
117 child = qs_get_next_node(doc, child)) {
119 char* name = qs_get_node_name(doc, child);
121 if ((*name == 's' || *name == 'S') && strcasecmp(name, "set") == 0) {
122 if ((rtn = s_load_emoji_set_tag(doc, p, conf, child)) != NULL)
132 s_load_emoji_set_tag(
135 mod_chxj_config* conf,
142 em = apr_palloc(p, sizeof(emoji_t));
143 em->imode = apr_palloc(p, sizeof(imode_emoji_t));
144 em->ezweb = apr_palloc(p, sizeof(ezweb_emoji_t));
145 em->jphone = apr_palloc(p, sizeof(jphone_emoji_t));
147 for (child = qs_get_child_node(doc, node);
149 child = qs_get_next_node(doc, child)) {
151 char* name = qs_get_node_name(doc, child);
156 if (strcasecmp(name, "no") == 0) {
157 if ((rtn = s_load_emoji_no_tag(doc, p, em, child)) != NULL)
164 if (strcasecmp(name, "imode") == 0) {
165 if ((rtn = s_load_emoji_imode_tag(doc, p, em, child)) != NULL)
172 if (strcasecmp(name, "ezweb") == 0) {
173 if ((rtn = s_load_emoji_ezweb_tag(doc, p, em, child)) != NULL)
180 if (strcasecmp(name, "jphone") == 0) {
181 if ((rtn = s_load_emoji_jphone_tag(doc, p, em, child)) != NULL)
191 s_emoji_add_to_tail(conf, em);
207 Node* child = qs_get_child_node(doc,node);
208 char* name = qs_get_node_name(doc, child);
209 char* value = qs_get_node_value(doc, child);
211 if ((*name == 't' || *name == 'T') && strcasecmp(name, "text") == 0) {
214 for (ii=0; ii<len; ii++) {
215 if (value[ii] < '0' || value[ii] > '9')
216 return apr_psprintf(p, "invalid data <no> tag [%s]", value);
218 em->no = atoi(value);
225 s_load_emoji_imode_tag(
233 em->imode->hex1byte = 0;
234 em->imode->hex2byte = 0;
235 em->imode->string = NULL;
236 em->imode->description = NULL;
238 for (child = qs_get_child_node(doc, node);
240 child = qs_get_next_node(doc, child)) {
242 char* name = qs_get_node_name(doc, child);
247 if (strcasecmp(name, "hex1") == 0) {
248 Node* hex1node = qs_get_child_node(doc, child);
251 char* cname = qs_get_node_name(doc, hex1node);
252 char* cvalue = qs_get_node_value(doc, hex1node);
254 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
255 em->imode->hex1byte = s_hexstring_to_byte(cvalue);
258 em->imode->hex1byte = 0;
262 if ((*name == 'h' || *name == 'H') && strcasecmp(name, "hex2") == 0) {
263 Node* hex2node = qs_get_child_node(doc, child);
265 char* cname = qs_get_node_name(doc, hex2node);
266 char* cvalue = qs_get_node_value(doc, hex2node);
268 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
269 em->imode->hex2byte = s_hexstring_to_byte(cvalue);
272 em->imode->hex2byte = 0;
279 if (strcasecmp(name, "string") == 0) {
280 Node* string_node = qs_get_child_node(doc, child);
283 char* cname = qs_get_node_name(doc, string_node);
284 char* cvalue = qs_get_node_value(doc, string_node);
286 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
287 em->imode->string = apr_pstrdup(p, cvalue);
290 em->imode->string = apr_palloc(p, 1);
291 em->imode->string[0] = 0;
298 if (strcasecmp(name, "description") == 0) {
299 Node* description_node = qs_get_child_node(doc, child);
301 if (description_node) {
302 char* cname = qs_get_node_name(doc, description_node);
303 char* cvalue = qs_get_node_value(doc, description_node);
305 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
306 em->imode->description = apr_pstrdup(p, cvalue);
309 em->imode->description = apr_palloc(p, 1);
310 em->imode->description[0] = 0;
325 s_load_emoji_ezweb_tag(
334 em->ezweb->typeA = NULL;
335 em->ezweb->typeB = NULL;
336 em->ezweb->typeC = NULL;
337 em->ezweb->typeD = NULL;
339 for (child = qs_get_child_node(doc, node);
341 child = qs_get_next_node(doc, child)) {
343 char* name = qs_get_node_name(doc, child);
345 if ((*name == 'a' || *name == 'A') && strcasecmp(name, "A") == 0) {
347 Node* typeAnode = qs_get_child_node(doc, child);
351 char* cname = qs_get_node_name(doc, typeAnode);
352 char* cvalue = qs_get_node_value(doc, typeAnode);
354 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
355 em->ezweb->typeA = apr_pstrdup(p,cvalue);
358 em->ezweb->typeA = apr_palloc(p, 1);
359 em->ezweb->typeA[0] = 0;
364 if ((*name == 'b' || *name == 'B') && strcasecmp(name, "B") == 0) {
366 Node* typeBnode = qs_get_child_node(doc, child);
370 char* cname = qs_get_node_name(doc, typeBnode);
371 char* cvalue = qs_get_node_value(doc, typeBnode);
373 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
374 em->ezweb->typeB = apr_pstrdup(p,cvalue);
378 em->ezweb->typeB = apr_palloc(p, 1);
379 em->ezweb->typeB[0] = 0;
383 if ((*name == 'c' || *name == 'C') && strcasecmp(name, "C") == 0) {
385 Node* typeCnode = qs_get_child_node(doc, child);
389 char* cname = qs_get_node_name(doc, typeCnode);
390 char* cvalue = qs_get_node_value(doc, typeCnode);
392 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
393 em->ezweb->typeC = apr_pstrdup(p,cvalue);
396 em->ezweb->typeC = apr_palloc(p, 1);
397 em->ezweb->typeC[0] = 0;
401 if ((*name == 'd' || *name == 'D') && strcasecmp(name, "D") == 0) {
403 Node* typeDnode = qs_get_child_node(doc, child);
407 char* cname = qs_get_node_name(doc, typeDnode);
408 char* cvalue = qs_get_node_value(doc, typeDnode);
410 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
411 em->ezweb->typeD = apr_pstrdup(p,cvalue);
415 em->ezweb->typeD = apr_palloc(p, 1);
416 em->ezweb->typeD[0] = 0;
426 s_load_emoji_jphone_tag(
435 em->jphone->string = NULL;
437 for (child = qs_get_child_node(doc, node);
439 child = qs_get_next_node(doc, child)) {
441 char* name = qs_get_node_name(doc, child);
443 if ((*name == 's' || *name == 'S') && strcasecmp(name, "string") == 0) {
445 Node* stringnode = qs_get_child_node(doc, child);
449 char* cname = qs_get_node_name(doc, stringnode);
450 char* cvalue = qs_get_node_value(doc, stringnode);
452 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0) {
457 tmp = apr_palloc(p, strlen(cvalue)+1);
458 memset(tmp, 0, strlen(cvalue)+1);
460 for (jj=0,ii=0; ii< strlen(cvalue); ii++) {
461 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_LT, strlen(ESCAPE_CHAR_LT)) == 0) {
464 ii += (strlen(ESCAPE_CHAR_LT) - 1);
467 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_GT, strlen(ESCAPE_CHAR_GT)) == 0) {
470 ii += (strlen(ESCAPE_CHAR_GT) - 1);
473 tmp[jj] = cvalue[ii];
477 em->jphone->string = apr_pstrdup(p,tmp);
481 em->jphone->string = apr_palloc(p, 1);
482 em->jphone->string[0] = 0;
494 mod_chxj_config* conf,
499 if (conf->emoji == NULL) {
501 conf->emoji_tail = emoji;
505 conf->emoji_tail->next = emoji;
506 conf->emoji_tail = emoji;
512 s_hexstring_to_byte(char* s)
520 for (ii=0; ii<len; ii++) {
532 one_byte |= (0xFF & (((s[ii] - '0') & 0xFF) << ((1-ii)*4)));
536 one_byte |= (0xFF & ((0x0A & 0xFF) << ((1-ii)*4)));
540 one_byte |= (0xFF & ((0x0B & 0xFF) << ((1-ii)*4)));
544 one_byte |= (0xFF & ((0x0C & 0xFF) << ((1-ii)*4)));
548 one_byte |= (0xFF & ((0x0d & 0xFF) << ((1-ii)*4)));
552 one_byte |= (0xFF & ((0x0e & 0xFF) << ((1-ii)*4)));
556 one_byte |= (0xFF & ((0x0f & 0xFF) << ((1-ii)*4)));