00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 #include <ctype.h>
00065
00066 #include "xml_shared.h"
00067 #include "xml_definitions.h"
00068
00069 #include <string.h>
00070
00071 struct charset_t {
00072 char *charset;
00073 char *nro;
00074 unsigned int MIBenum;
00075 };
00076
00077 charset_t character_sets[] = {
00078 { "ISO", "8859-1", 4 },
00079 { "ISO", "8859-2", 5 },
00080 { "ISO", "8859-3", 6 },
00081 { "ISO", "8859-4", 7 },
00082 { "ISO", "8859-5", 8 },
00083 { "ISO", "8859-6", 9 },
00084 { "ISO", "8859-7", 10 },
00085 { "ISO", "8859-8", 11 },
00086 { "ISO", "8859-9", 12 },
00087 { "WINDOWS", "1250", 2250 },
00088 { "WINDOWS", "1251", 2251 },
00089 { "WINDOWS", "1252", 2252 },
00090 { "WINDOWS", "1253", 2253 },
00091 { "WINDOWS", "1254", 2254 },
00092 { "WINDOWS", "1255", 2255 },
00093 { "WINDOWS", "1256", 2256 },
00094 { "WINDOWS", "1257", 2257 },
00095 { "WINDOWS", "1258", 2258 },
00096 { "UTF", "8", 106 },
00097 { NULL }
00098 };
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 void set_charset(Octstr *document, Octstr *charset)
00112 {
00113 long gt = 0, enc = 0;
00114 Octstr *encoding = NULL, *text = NULL, *temp = NULL;
00115
00116 if (octstr_len(charset) == 0)
00117 return;
00118
00119 encoding = octstr_create(" encoding");
00120 enc = octstr_search(document, encoding, 0);
00121 gt = octstr_search_char(document, '>', 0);
00122
00123 if (enc < 0 || enc > gt) {
00124 gt++;
00125 text = octstr_copy(document, gt, octstr_len(document) - gt);
00126 if (charset_to_utf8(text, &temp, charset) >= 0) {
00127 octstr_delete(document, gt, octstr_len(document) - gt);
00128 octstr_append_data(document, octstr_get_cstr(temp),
00129 octstr_len(temp));
00130 }
00131
00132 octstr_destroy(temp);
00133 octstr_destroy(text);
00134 }
00135
00136 octstr_destroy(encoding);
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 Octstr *find_charset_encoding(Octstr *document)
00146 {
00147 long gt = 0, enc = 0;
00148 Octstr *encoding = NULL, *temp = NULL;
00149
00150 enc = octstr_search(document, octstr_imm(" encoding="), 0);
00151 gt = octstr_search(document, octstr_imm("?>"), 0);
00152
00153
00154 if (enc < 0 || enc + 10 > gt)
00155 return NULL;
00156
00157 temp = octstr_copy(document, enc + 10, gt - (enc + 10));
00158 octstr_strip_blanks(temp);
00159 encoding = octstr_copy(temp, 1, octstr_len(temp) - 2);
00160 octstr_destroy(temp);
00161
00162 return encoding;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 int only_blanks(const char *text)
00172 {
00173 int blank = 1;
00174 int j=0;
00175 int len = strlen(text);
00176
00177 while ((j<len) && blank) {
00178 blank = blank && isspace((int)text[j]);
00179 j++;
00180 }
00181
00182 return blank;
00183 }
00184
00185
00186
00187
00188
00189 int parse_charset(Octstr *os)
00190 {
00191 Octstr *charset = NULL;
00192 Octstr *number = NULL;
00193 int i, j, cut = 0, ret = 0;
00194
00195 gw_assert(os != NULL);
00196 charset = octstr_duplicate(os);
00197
00198
00199 octstr_convert_range(charset, 0, octstr_len(charset), toupper);
00200
00201
00202
00203
00204
00205 if ((cut = octstr_search_char(charset, '_', 0)) > 0) {
00206 number = octstr_copy(charset, cut + 1, (octstr_len(charset) - (cut + 1)));
00207 octstr_truncate(charset, cut);
00208 }
00209 else if ((cut = octstr_search_char(charset, '-', 0)) > 0) {
00210 number = octstr_copy(charset, cut + 1, (octstr_len(charset) - (cut + 1)));
00211 octstr_truncate(charset, cut);
00212 }
00213
00214
00215 for (i = 0; character_sets[i].charset != NULL; i++)
00216 if (octstr_str_compare(charset, character_sets[i].charset) == 0) {
00217 for (j = i; octstr_str_compare(charset,
00218 character_sets[j].charset) == 0; j++)
00219 if (octstr_str_compare(number, character_sets[j].nro) == 0) {
00220 ret = character_sets[j].MIBenum;
00221 break;
00222 }
00223 break;
00224 }
00225
00226
00227 if (character_sets[i].charset == NULL)
00228 ret = character_sets[i-1].MIBenum;
00229
00230 octstr_destroy(number);
00231 octstr_destroy(charset);
00232
00233 return ret;
00234 }
00235
00236
00237
00238
00239
00240
00241
00242 unsigned char element_check_content(xmlNodePtr node)
00243 {
00244 unsigned char status_bits = 0x00;
00245
00246 if ((node->children != NULL) &&
00247 !((node->children->next == NULL) &&
00248 (node->children->type == XML_TEXT_NODE) &&
00249 (only_blanks((char *)node->children->content))))
00250 status_bits = WBXML_CONTENT_BIT;
00251
00252 if (node->properties != NULL)
00253 status_bits = status_bits | WBXML_ATTR_BIT;
00254
00255 return status_bits;
00256 }
00257
00258
00259
00260
00261
00262 List *wml_charsets(void)
00263 {
00264 int i;
00265 List *result;
00266 Octstr *charset;
00267
00268 result = gwlist_create();
00269 for (i = 0; character_sets[i].charset != NULL; i++) {
00270 charset = octstr_create(character_sets[i].charset);
00271 octstr_append_char(charset, '-');
00272 octstr_append(charset, octstr_imm(character_sets[i].nro));
00273 gwlist_append(result, charset);
00274 }
00275
00276 return result;
00277 }
00278
00279
00280
00281
00282
00283
00284 simple_binary_t *simple_binary_create(void)
00285 {
00286 simple_binary_t *binary;
00287
00288 binary = gw_malloc(sizeof(simple_binary_t));
00289
00290 binary->wbxml_version = 0x00;
00291 binary->public_id = 0x00;
00292 binary->charset = 0x00;
00293 binary->binary = octstr_create("");
00294
00295 return binary;
00296 }
00297
00298 void simple_binary_destroy(simple_binary_t *binary)
00299 {
00300 if (binary == NULL)
00301 return;
00302
00303 octstr_destroy(binary->binary);
00304 gw_free(binary);
00305 }
00306
00307
00308
00309
00310
00311 void simple_binary_output(Octstr *os, simple_binary_t *binary)
00312 {
00313 gw_assert(octstr_len(os) == 0);
00314 octstr_format_append(os, "%c", binary->wbxml_version);
00315 octstr_format_append(os, "%c", binary->public_id);
00316 octstr_append_uintvar(os, binary->charset);
00317 octstr_format_append(os, "%c", 0x00);
00318 octstr_format_append(os, "%S", binary->binary);
00319 }
00320
00321 void parse_end(simple_binary_t **binary)
00322 {
00323 output_char(WBXML_END, binary);
00324 }
00325
00326 void output_char(int byte, simple_binary_t **binary)
00327 {
00328 octstr_append_char((**binary).binary, byte);
00329 }
00330
00331 void parse_octet_string(Octstr *os, simple_binary_t **binary)
00332 {
00333 output_octet_string(os, binary);
00334 }
00335
00336
00337
00338
00339 void parse_inline_string(Octstr *temp, simple_binary_t **binary)
00340 {
00341 Octstr *startos;
00342
00343 octstr_insert(temp, startos = octstr_format("%c", WBXML_STR_I), 0);
00344 octstr_destroy(startos);
00345 octstr_format_append(temp, "%c", WBXML_STR_END);
00346 parse_octet_string(temp, binary);
00347 }
00348
00349 void output_octet_string(Octstr *os, simple_binary_t **sibxml)
00350 {
00351 octstr_insert((*sibxml)->binary, os, octstr_len((*sibxml)->binary));
00352 }
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.