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( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
22 static char* s_set_emoji_data( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
23 static char* s_load_emoji_emoji_tag( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
24 static void s_emoji_add_to_tail( mod_chxj_config* conf, emoji_t* emoji);
25 static char* s_load_emoji_no_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
26 static char* s_load_emoji_imode_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
27 static char* s_load_emoji_ezweb_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
28 static char* s_load_emoji_jphone_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
29 static char s_hexstring_to_byte(char* s);
39 mod_chxj_config* conf)
44 conf->emoji_tail = NULL;
46 if (rtn = s_set_emoji_data(doc, p, conf,qs_get_root(doc))
59 mod_chxj_config* conf,
65 for (child = qs_get_child_node(doc,node);
67 child = qs_get_next_node(doc,child)) {
69 char* name = qs_get_node_name(doc,child);
71 if ((*name == 'e' || *name == 'E') && strcasecmp(name, "emoji") == 0) {
72 if ((rtn = s_load_emoji_emoji_tag(doc, p, conf, child)))
80 s_load_emoji_emoji_tag(
83 mod_chxj_config* conf,
89 for (child = qs_get_child_node(doc, node);
91 child = qs_get_next_node(doc, child)) {
93 char* name = qs_get_node_name(doc, child);
95 if ((*name == 's' || *name == 'S') && strcasecmp(name, "set") == 0) {
96 if (rtn = s_load_emoji_set_tag(doc, p, conf, child))
106 s_load_emoji_set_tag(
109 mod_chxj_config* conf,
116 em = apr_palloc(p, sizeof(emoji_t));
117 em->imode = apr_palloc(p, sizeof(imode_emoji_t));
118 em->ezweb = apr_palloc(p, sizeof(ezweb_emoji_t));
119 em->jphone = apr_palloc(p, sizeof(jphone_emoji_t));
121 for (child = qs_get_child_node(doc, node);
123 child = qs_get_next_node(doc, child)) {
125 char* name = qs_get_node_name(doc, child);
130 if (strcasecmp(name, "no") == 0) {
131 if (rtn = s_load_emoji_no_tag(doc, p, em, child))
138 if (strcasecmp(name, "imode") == 0) {
139 if (rtn = s_load_emoji_imode_tag(doc, p, em, child))
146 if (strcasecmp(name, "ezweb") == 0) {
147 if (rtn = s_load_emoji_ezweb_tag(doc, p, em, child))
154 if (strcasecmp(name, "jphone") == 0) {
155 if (rtn = s_load_emoji_jphone_tag(doc, p, em, child))
165 s_emoji_add_to_tail(conf, em);
181 Node* child = qs_get_child_node(doc,node);
182 char* name = qs_get_node_name(doc, child);
183 char* value = qs_get_node_value(doc, child);
185 if ((*name == 't' || *name == 'T') && strcasecmp(name, "text") == 0) {
188 for (ii=0; ii<len; ii++) {
189 if (value[ii] < '0' || value[ii] > '9')
190 return apr_psprintf(p, "invalid data <no> tag [%s]", value);
192 em->no = atoi(value);
199 s_load_emoji_imode_tag(
208 em->imode->hex1byte = 0;
209 em->imode->hex2byte = 0;
210 em->imode->string = NULL;
211 em->imode->description = NULL;
213 for (child = qs_get_child_node(doc, node);
215 child = qs_get_next_node(doc, child))
217 char* name = qs_get_node_name(doc, child);
218 if (strcasecmp(name, "hex1") == 0)
220 Node* hex1node = qs_get_child_node(doc, child);
221 if (hex1node != NULL)
223 char* cname = qs_get_node_name(doc, hex1node);
224 char* cvalue = qs_get_node_value(doc, hex1node);
225 if (strcasecmp(cname, "text") == 0)
227 em->imode->hex1byte = s_hexstring_to_byte(cvalue);
232 em->imode->hex1byte = 0;
236 if (strcasecmp(name, "hex2") == 0)
238 Node* hex2node = qs_get_child_node(doc, child);
239 if (hex2node != NULL)
241 char* cname = qs_get_node_name(doc, hex2node);
242 char* cvalue = qs_get_node_value(doc, hex2node);
243 if (strcasecmp(cname, "text") == 0)
245 em->imode->hex2byte = s_hexstring_to_byte(cvalue);
250 em->imode->hex2byte = 0;
254 if (strcasecmp(name, "string") == 0)
256 Node* string_node = qs_get_child_node(doc, child);
257 if (string_node != NULL)
259 char* cname = qs_get_node_name(doc, string_node);
260 char* cvalue = qs_get_node_value(doc, string_node);
261 if (strcasecmp(cname, "text") == 0)
263 em->imode->string = apr_pstrdup(p, cvalue);
268 em->imode->string = apr_palloc(p, 1);
269 em->imode->string[0] = 0;
273 if (strcasecmp(name, "description") == 0)
275 Node* description_node = qs_get_child_node(doc, child);
276 if (description_node != NULL)
278 char* cname = qs_get_node_name(doc, description_node);
279 char* cvalue = qs_get_node_value(doc, description_node);
280 if (strcasecmp(cname, "text") == 0)
282 em->imode->description = apr_pstrdup(p, cvalue);
287 em->imode->description = apr_palloc(p, 1);
288 em->imode->description[0] = 0;
296 s_load_emoji_ezweb_tag(
305 em->ezweb->typeA = NULL;
306 em->ezweb->typeB = NULL;
307 em->ezweb->typeC = NULL;
308 em->ezweb->typeD = NULL;
310 for (child = qs_get_child_node(doc, node);
312 child = qs_get_next_node(doc, child))
314 char* name = qs_get_node_name(doc, child);
315 if (strcasecmp(name, "A") == 0)
317 Node* typeAnode = qs_get_child_node(doc, child);
319 if (typeAnode != NULL)
321 char* cname = qs_get_node_name(doc, typeAnode);
322 char* cvalue = qs_get_node_value(doc, typeAnode);
323 if (strcasecmp(cname, "text") == 0)
325 em->ezweb->typeA = apr_pstrdup(p,cvalue);
330 em->ezweb->typeA = apr_palloc(p, 1);
331 em->ezweb->typeA[0] = 0;
335 if (strcasecmp(name, "B") == 0)
337 Node* typeBnode = qs_get_child_node(doc, child);
339 if (typeBnode != NULL)
341 char* cname = qs_get_node_name(doc, typeBnode);
342 char* cvalue = qs_get_node_value(doc, typeBnode);
343 if (strcasecmp(cname, "text") == 0)
345 em->ezweb->typeB = apr_pstrdup(p,cvalue);
350 em->ezweb->typeB = apr_palloc(p, 1);
351 em->ezweb->typeB[0] = 0;
355 if (strcasecmp(name, "C") == 0)
357 Node* typeCnode = qs_get_child_node(doc, child);
359 if (typeCnode != NULL)
361 char* cname = qs_get_node_name(doc, typeCnode);
362 char* cvalue = qs_get_node_value(doc, typeCnode);
363 if (strcasecmp(cname, "text") == 0)
365 em->ezweb->typeC = apr_pstrdup(p,cvalue);
370 em->ezweb->typeC = apr_palloc(p, 1);
371 em->ezweb->typeC[0] = 0;
375 if (strcasecmp(name, "D") == 0)
377 Node* typeDnode = qs_get_child_node(doc, child);
379 if (typeDnode != NULL)
381 char* cname = qs_get_node_name(doc, typeDnode);
382 char* cvalue = qs_get_node_value(doc, typeDnode);
383 if (strcasecmp(cname, "text") == 0)
385 em->ezweb->typeD = apr_pstrdup(p,cvalue);
390 em->ezweb->typeD = apr_palloc(p, 1);
391 em->ezweb->typeD[0] = 0;
399 s_load_emoji_jphone_tag(
408 em->jphone->string = NULL;
410 for (child = qs_get_child_node(doc, node);
412 child = qs_get_next_node(doc, child))
414 char* name = qs_get_node_name(doc, child);
415 if (strcasecmp(name, "string") == 0)
417 Node* stringnode = qs_get_child_node(doc, child);
418 if (stringnode != NULL)
420 char* cname = qs_get_node_name(doc, stringnode);
421 char* cvalue = qs_get_node_value(doc, stringnode);
422 if (strcasecmp(cname, "text") == 0)
426 char* tmp = apr_palloc(p, strlen(cvalue)+1);
427 memset(tmp, 0, strlen(cvalue)+1);
429 for (jj=0,ii=0; ii< strlen(cvalue); ii++)
431 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_LT, strlen(ESCAPE_CHAR_LT)) == 0)
435 ii += (strlen(ESCAPE_CHAR_LT) - 1);
438 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_GT, strlen(ESCAPE_CHAR_GT)) == 0)
442 ii += (strlen(ESCAPE_CHAR_GT) - 1);
446 tmp[jj] = cvalue[ii];
450 em->jphone->string = apr_pstrdup(p,tmp);
455 em->jphone->string = apr_palloc(p, 1);
456 em->jphone->string[0] = 0;
465 mod_chxj_config* conf,
469 if (conf->emoji == NULL) {
471 conf->emoji_tail = emoji;
475 conf->emoji_tail->next = emoji;
476 conf->emoji_tail = emoji;
480 s_hexstring_to_byte(char* s)
487 for (ii=0; ii<len; ii++)
501 one_byte |= (0xFF & (((s[ii] - '0') & 0xFF) << ((1-ii)*4)));
505 one_byte |= (0xFF & ((0x0A & 0xFF) << ((1-ii)*4)));
509 one_byte |= (0xFF & ((0x0B & 0xFF) << ((1-ii)*4)));
513 one_byte |= (0xFF & ((0x0C & 0xFF) << ((1-ii)*4)));
517 one_byte |= (0xFF & ((0x0d & 0xFF) << ((1-ii)*4)));
521 one_byte |= (0xFF & ((0x0e & 0xFF) << ((1-ii)*4)));
525 one_byte |= (0xFF & ((0x0f & 0xFF) << ((1-ii)*4)));