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(
207 em->imode->hex1byte = 0;
208 em->imode->hex2byte = 0;
209 em->imode->string = NULL;
210 em->imode->description = NULL;
212 for (child = qs_get_child_node(doc, node);
214 child = qs_get_next_node(doc, child)) {
216 char* name = qs_get_node_name(doc, child);
221 if (strcasecmp(name, "hex1") == 0) {
222 Node* hex1node = qs_get_child_node(doc, child);
225 char* cname = qs_get_node_name(doc, hex1node);
226 char* cvalue = qs_get_node_value(doc, hex1node);
228 if ((*cname == 't' || *cname == 'T') && strcasecmp(cname, "text") == 0)
229 em->imode->hex1byte = s_hexstring_to_byte(cvalue);
232 em->imode->hex1byte = 0;
236 if ((*name == 'h' || *name == 'H') && strcasecmp(name, "hex2") == 0) {
237 Node* hex2node = qs_get_child_node(doc, child);
238 if (hex2node != NULL) {
239 char* cname = qs_get_node_name(doc, hex2node);
240 char* cvalue = qs_get_node_value(doc, hex2node);
241 if (strcasecmp(cname, "text") == 0)
242 em->imode->hex2byte = s_hexstring_to_byte(cvalue);
246 em->imode->hex2byte = 0;
250 if (strcasecmp(name, "string") == 0)
252 Node* string_node = qs_get_child_node(doc, child);
253 if (string_node != NULL)
255 char* cname = qs_get_node_name(doc, string_node);
256 char* cvalue = qs_get_node_value(doc, string_node);
257 if (strcasecmp(cname, "text") == 0)
259 em->imode->string = apr_pstrdup(p, cvalue);
264 em->imode->string = apr_palloc(p, 1);
265 em->imode->string[0] = 0;
269 if (strcasecmp(name, "description") == 0)
271 Node* description_node = qs_get_child_node(doc, child);
272 if (description_node != NULL)
274 char* cname = qs_get_node_name(doc, description_node);
275 char* cvalue = qs_get_node_value(doc, description_node);
276 if (strcasecmp(cname, "text") == 0)
278 em->imode->description = apr_pstrdup(p, cvalue);
283 em->imode->description = apr_palloc(p, 1);
284 em->imode->description[0] = 0;
292 s_load_emoji_ezweb_tag(
301 em->ezweb->typeA = NULL;
302 em->ezweb->typeB = NULL;
303 em->ezweb->typeC = NULL;
304 em->ezweb->typeD = NULL;
306 for (child = qs_get_child_node(doc, node);
308 child = qs_get_next_node(doc, child))
310 char* name = qs_get_node_name(doc, child);
311 if (strcasecmp(name, "A") == 0)
313 Node* typeAnode = qs_get_child_node(doc, child);
315 if (typeAnode != NULL)
317 char* cname = qs_get_node_name(doc, typeAnode);
318 char* cvalue = qs_get_node_value(doc, typeAnode);
319 if (strcasecmp(cname, "text") == 0)
321 em->ezweb->typeA = apr_pstrdup(p,cvalue);
326 em->ezweb->typeA = apr_palloc(p, 1);
327 em->ezweb->typeA[0] = 0;
331 if (strcasecmp(name, "B") == 0)
333 Node* typeBnode = qs_get_child_node(doc, child);
335 if (typeBnode != NULL)
337 char* cname = qs_get_node_name(doc, typeBnode);
338 char* cvalue = qs_get_node_value(doc, typeBnode);
339 if (strcasecmp(cname, "text") == 0)
341 em->ezweb->typeB = apr_pstrdup(p,cvalue);
346 em->ezweb->typeB = apr_palloc(p, 1);
347 em->ezweb->typeB[0] = 0;
351 if (strcasecmp(name, "C") == 0)
353 Node* typeCnode = qs_get_child_node(doc, child);
355 if (typeCnode != NULL)
357 char* cname = qs_get_node_name(doc, typeCnode);
358 char* cvalue = qs_get_node_value(doc, typeCnode);
359 if (strcasecmp(cname, "text") == 0)
361 em->ezweb->typeC = apr_pstrdup(p,cvalue);
366 em->ezweb->typeC = apr_palloc(p, 1);
367 em->ezweb->typeC[0] = 0;
371 if (strcasecmp(name, "D") == 0)
373 Node* typeDnode = qs_get_child_node(doc, child);
375 if (typeDnode != NULL)
377 char* cname = qs_get_node_name(doc, typeDnode);
378 char* cvalue = qs_get_node_value(doc, typeDnode);
379 if (strcasecmp(cname, "text") == 0)
381 em->ezweb->typeD = apr_pstrdup(p,cvalue);
386 em->ezweb->typeD = apr_palloc(p, 1);
387 em->ezweb->typeD[0] = 0;
395 s_load_emoji_jphone_tag(
404 em->jphone->string = NULL;
406 for (child = qs_get_child_node(doc, node);
408 child = qs_get_next_node(doc, child))
410 char* name = qs_get_node_name(doc, child);
411 if (strcasecmp(name, "string") == 0)
413 Node* stringnode = qs_get_child_node(doc, child);
414 if (stringnode != NULL)
416 char* cname = qs_get_node_name(doc, stringnode);
417 char* cvalue = qs_get_node_value(doc, stringnode);
418 if (strcasecmp(cname, "text") == 0)
422 char* tmp = apr_palloc(p, strlen(cvalue)+1);
423 memset(tmp, 0, strlen(cvalue)+1);
425 for (jj=0,ii=0; ii< strlen(cvalue); ii++)
427 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_LT, strlen(ESCAPE_CHAR_LT)) == 0)
431 ii += (strlen(ESCAPE_CHAR_LT) - 1);
434 if (strncasecmp(&cvalue[ii] , ESCAPE_CHAR_GT, strlen(ESCAPE_CHAR_GT)) == 0)
438 ii += (strlen(ESCAPE_CHAR_GT) - 1);
442 tmp[jj] = cvalue[ii];
446 em->jphone->string = apr_pstrdup(p,tmp);
451 em->jphone->string = apr_palloc(p, 1);
452 em->jphone->string[0] = 0;
461 mod_chxj_config* conf,
465 if (conf->emoji == NULL) {
467 conf->emoji_tail = emoji;
471 conf->emoji_tail->next = emoji;
472 conf->emoji_tail = emoji;
476 s_hexstring_to_byte(char* s)
483 for (ii=0; ii<len; ii++)
497 one_byte |= (0xFF & (((s[ii] - '0') & 0xFF) << ((1-ii)*4)));
501 one_byte |= (0xFF & ((0x0A & 0xFF) << ((1-ii)*4)));
505 one_byte |= (0xFF & ((0x0B & 0xFF) << ((1-ii)*4)));
509 one_byte |= (0xFF & ((0x0C & 0xFF) << ((1-ii)*4)));
513 one_byte |= (0xFF & ((0x0d & 0xFF) << ((1-ii)*4)));
517 one_byte |= (0xFF & ((0x0e & 0xFF) << ((1-ii)*4)));
521 one_byte |= (0xFF & ((0x0f & 0xFF) << ((1-ii)*4)));