Lines 1-277
Link Here
|
1 |
--- src/wbxml_encoder.c.orig 2006-07-11 21:47:45.000000000 +1000 |
|
|
2 |
+++ src/wbxml_encoder.c 2008-06-15 08:45:31.000000000 +1000 |
3 |
@@ -136,6 +136,7 @@ |
4 |
const WBXMLTagEntry *current_tag; /**< Current Tag (See The Warning For This Field !) */ |
5 |
const WBXMLTreeNode *current_text_parent; /**< Text parent of current Node (See The Warning For This Field !) */ |
6 |
const WBXMLAttrEntry *current_attr; /**< Current Attribute */ |
7 |
+ WBXMLTreeNode *current_node; |
8 |
WB_UTINY tagCodePage; /**< Current Tag Code Page */ |
9 |
WB_UTINY attrCodePage; /**< Current Attribute Code Page */ |
10 |
WB_BOOL ignore_empty_text; /**< Do we ignore empty text nodes (ie: ignorable whitespaces)? */ |
11 |
@@ -153,6 +154,7 @@ |
12 |
WB_BOOL use_strtbl; /**< Do we use String Table when generating WBXML output ? (default: YES) */ |
13 |
#endif /* WBXML_ENCODER_USE_STRTBL */ |
14 |
WB_BOOL xml_encode_header; /**< Do we generate XML Header ? */ |
15 |
+ WB_BOOL produce_anonymous; |
16 |
WBXMLVersion wbxml_version; /**< WBXML Version to use (when generating WBXML output) */ |
17 |
WBXMLCharsetMIBEnum output_charset; /**< Output charset encoding */ |
18 |
WB_BOOL flow_mode; /**< Is Flow Mode encoding activated ? */ |
19 |
@@ -269,6 +271,7 @@ |
20 |
static WBXMLError wbxml_encode_entity(WBXMLEncoder *encoder, WB_ULONG value); |
21 |
#endif /* 0 */ |
22 |
static WBXMLError wbxml_encode_opaque(WBXMLEncoder *encoder, WBXMLBuffer *buff); |
23 |
+static WBXMLError wbxml_encode_opaque_data(WBXMLEncoder *encoder, WB_UTINY *data, WB_ULONG data_len); |
24 |
#if defined( WBXML_ENCODER_USE_STRTBL ) |
25 |
static WBXMLError wbxml_encode_tableref(WBXMLEncoder *encoder, WB_ULONG offset); |
26 |
#endif /* WBXML_ENCODER_USE_STRTBL */ |
27 |
@@ -292,7 +295,9 @@ |
28 |
#if defined( WBXML_SUPPORT_DRMREL ) |
29 |
static WBXMLError wbxml_encode_drmrel_content(WBXMLEncoder *encoder, WB_UTINY *buffer); |
30 |
#endif /* WBXML_SUPPORT_DRMREL */ |
31 |
- |
32 |
+#if defined( WBXML_SUPPORT_OTA_SETTINGS ) |
33 |
+static WBXMLError wbxml_encode_ota_nokia_icon(WBXMLEncoder *encoder, WB_UTINY *buffer); |
34 |
+#endif |
35 |
#if defined( WBXML_ENCODER_USE_STRTBL ) |
36 |
/* WBXML String Table Functions */ |
37 |
static WBXMLStringTableElement *wbxml_strtbl_element_create(WBXMLBuffer *string, WB_BOOL is_stat); |
38 |
@@ -383,6 +388,7 @@ |
39 |
encoder->current_tag = NULL; |
40 |
encoder->current_text_parent = NULL; |
41 |
encoder->current_attr = NULL; |
42 |
+ encoder->current_node = NULL; |
43 |
|
44 |
encoder->tagCodePage = 0; |
45 |
encoder->attrCodePage = 0; |
46 |
@@ -400,6 +406,7 @@ |
47 |
encoder->cdata = NULL; |
48 |
|
49 |
encoder->xml_encode_header = TRUE; |
50 |
+ encoder->produce_anonymous = FALSE; |
51 |
|
52 |
/* Default Version: WBXML 1.3 */ |
53 |
encoder->wbxml_version = WBXML_VERSION_13; |
54 |
@@ -450,6 +457,7 @@ |
55 |
|
56 |
encoder->current_tag = NULL; |
57 |
encoder->current_attr = NULL; |
58 |
+ encoder->current_node = NULL; |
59 |
|
60 |
encoder->tagCodePage = 0; |
61 |
encoder->attrCodePage = 0; |
62 |
@@ -507,7 +515,13 @@ |
63 |
encoder->use_strtbl = use_strtbl; |
64 |
#endif /* WBXML_ENCODER_USE_STRTBL */ |
65 |
} |
66 |
- |
67 |
+WBXML_DECLARE(void) wbxml_encoder_set_produce_anonymous(WBXMLEncoder *encoder, WB_BOOL set_anonymous) |
68 |
+{ |
69 |
+ if (encoder == NULL) |
70 |
+ return; |
71 |
+ |
72 |
+ encoder->produce_anonymous = set_anonymous; |
73 |
+} |
74 |
|
75 |
WBXML_DECLARE(void) wbxml_encoder_set_wbxml_version(WBXMLEncoder *encoder, WBXMLVersion version) |
76 |
{ |
77 |
@@ -637,6 +651,9 @@ |
78 |
|
79 |
WBXML_DECLARE(WBXMLError) wbxml_encoder_encode_node(WBXMLEncoder *encoder, WBXMLTreeNode *node) |
80 |
{ |
81 |
+ if (encoder->flow_mode == FALSE) { |
82 |
+ WBXML_WARNING((WBXML_ENCODER, "You should NOT call wbxml_encoder_encode_node() if you are not in Flow Mode encoding ! (use wbxml_encoder_set_flow_mode(encoder, TRUE))")); |
83 |
+ } |
84 |
return wbxml_encoder_encode_node_with_elt_end(encoder, node, TRUE); |
85 |
} |
86 |
|
87 |
@@ -649,10 +666,6 @@ |
88 |
if ((encoder == NULL) || (node == NULL)) |
89 |
return WBXML_ERROR_BAD_PARAMETER; |
90 |
|
91 |
- if (encoder->flow_mode == FALSE) { |
92 |
- WBXML_WARNING((WBXML_ENCODER, "You should NOT call wbxml_encoder_encode_node() if you are not in Flow Mode encoding ! (use wbxml_encoder_set_flow_mode(encoder, TRUE))")); |
93 |
- } |
94 |
- |
95 |
/* Check that language table has been set */ |
96 |
if (encoder->lang == NULL) |
97 |
return WBXML_ERROR_BAD_PARAMETER; |
98 |
@@ -965,6 +978,7 @@ |
99 |
static WBXMLError parse_node(WBXMLEncoder *encoder, WBXMLTreeNode *node, WB_BOOL enc_end) |
100 |
{ |
101 |
WBXMLError ret = WBXML_OK; |
102 |
+ encoder->current_node = node; |
103 |
|
104 |
/* Parse this node */ |
105 |
switch (node->type) { |
106 |
@@ -1078,6 +1092,7 @@ |
107 |
|
108 |
/* Reset Current Tag */ |
109 |
encoder->current_tag = NULL; |
110 |
+ encoder->current_node = NULL; |
111 |
|
112 |
/* Parse next node */ |
113 |
if (node->next != NULL) |
114 |
@@ -1464,7 +1479,7 @@ |
115 |
|
116 |
/* Encode Public ID */ |
117 |
/* If WBXML Public Id is '0x01' (unknown), or we forced it, add the XML Public ID in the String Table */ |
118 |
- if (encoder->textual_publicid || (public_id == WBXML_PUBLIC_ID_UNKNOWN)) |
119 |
+ if ((encoder->textual_publicid || (public_id == WBXML_PUBLIC_ID_UNKNOWN)) && !encoder->produce_anonymous) |
120 |
{ |
121 |
if (encoder->lang->publicID->xmlPublicID != NULL) |
122 |
{ |
123 |
@@ -1500,7 +1515,7 @@ |
124 |
else { |
125 |
#endif /* WBXML_ENCODER_USE_STRTBL */ |
126 |
/* Length of String Table is length of XML Public ID */ |
127 |
- strstbl_len = wbxml_buffer_len(pid); |
128 |
+ strstbl_len = wbxml_buffer_len(pid) + 1; |
129 |
|
130 |
/* There is only the XML Public ID in String Table */ |
131 |
public_id_index = 0; |
132 |
@@ -1548,7 +1563,8 @@ |
133 |
/* The append includes terminating NULL char */ |
134 |
if (!wbxml_buffer_append(header, pid)) |
135 |
return WBXML_ERROR_ENCODER_APPEND_DATA; |
136 |
- |
137 |
+ if (!wbxml_buffer_append_char(header, WBXML_STR_END)) |
138 |
+ return WBXML_ERROR_ENCODER_APPEND_DATA; |
139 |
/* Clean up */ |
140 |
wbxml_buffer_destroy(pid); |
141 |
} |
142 |
@@ -1870,7 +1886,7 @@ |
143 |
* Encoder Language Specific Attribute Values |
144 |
*/ |
145 |
|
146 |
- if (ctx == WBXML_VALUE_ELEMENT_CTX_ATTR) { |
147 |
+ if ((ctx == WBXML_VALUE_ELEMENT_CTX_ATTR) && (encoder->current_attr != NULL)) { |
148 |
switch (encoder->lang->langID) { |
149 |
#if defined( WBXML_SUPPORT_SI ) |
150 |
case WBXML_LANG_SI10: |
151 |
@@ -1892,7 +1908,16 @@ |
152 |
} |
153 |
break; |
154 |
#endif /* WBXML_SUPPORT_EMN */ |
155 |
- |
156 |
+#if defined( WBXML_SUPPORT_OTA_SETTINGS ) |
157 |
+ case WBXML_LANG_OTA_SETTINGS: |
158 |
+ if ((encoder->current_attr->wbxmlCodePage == 0x00) && |
159 |
+ (encoder->current_attr->wbxmlToken == 0x11)) |
160 |
+ { |
161 |
+ if ((ret = wbxml_encode_ota_nokia_icon(encoder, buffer)) != WBXML_NOT_ENCODED) |
162 |
+ return ret; |
163 |
+ } |
164 |
+ break; |
165 |
+#endif /* WBXML_SUPPORT_OTA_SETTINGS */ |
166 |
default: |
167 |
break; |
168 |
} |
169 |
@@ -1936,7 +1961,8 @@ |
170 |
#if defined( WBXML_SUPPORT_SYNCML ) |
171 |
/* If this is a SyncML document ? */ |
172 |
if ((encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML10) || |
173 |
- (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML11)) |
174 |
+ (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML11) || |
175 |
+ (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML12)) |
176 |
{ |
177 |
/** @todo We must check too if we are in a <Type> */ |
178 |
|
179 |
@@ -2219,6 +2245,11 @@ |
180 |
* @param list The Value Element list |
181 |
* @return WBXML_OK if encoding is OK, an error code otherwise |
182 |
*/ |
183 |
+static WBXMLError wbxml_encode_opaque(WBXMLEncoder *encoder, WBXMLBuffer *buff) |
184 |
+{ |
185 |
+ return wbxml_encode_opaque_data(encoder, wbxml_buffer_get_cstr(buff), wbxml_buffer_len(buff)); |
186 |
+} |
187 |
+ |
188 |
static WBXMLError wbxml_encode_value_element_list(WBXMLEncoder *encoder, WBXMLList *list) |
189 |
{ |
190 |
WBXMLValueElement *elt = NULL; |
191 |
@@ -2438,18 +2469,18 @@ |
192 |
* @note opaque = OPAQUE length *byte |
193 |
* length = mb_u_int32 |
194 |
*/ |
195 |
-static WBXMLError wbxml_encode_opaque(WBXMLEncoder *encoder, WBXMLBuffer *buff) |
196 |
+static WBXMLError wbxml_encode_opaque_data(WBXMLEncoder *encoder, WB_UTINY *data, WB_ULONG data_len) |
197 |
{ |
198 |
/* Add WBXML_OPAQUE */ |
199 |
if (!wbxml_buffer_append_char(encoder->output, WBXML_OPAQUE)) |
200 |
return WBXML_ERROR_ENCODER_APPEND_DATA; |
201 |
|
202 |
/* Add Length */ |
203 |
- if (!wbxml_buffer_append_mb_uint_32(encoder->output, wbxml_buffer_len(buff))) |
204 |
+ if (!wbxml_buffer_append_mb_uint_32(encoder->output, data_len)) |
205 |
return WBXML_ERROR_ENCODER_APPEND_DATA; |
206 |
|
207 |
/* Add Buffer */ |
208 |
- if (!wbxml_buffer_append(encoder->output, buff)) |
209 |
+ if (!wbxml_buffer_append_data(encoder->output, data, data_len)) |
210 |
return WBXML_ERROR_ENCODER_APPEND_DATA; |
211 |
|
212 |
return WBXML_OK; |
213 |
@@ -3146,8 +3177,54 @@ |
214 |
} |
215 |
|
216 |
#endif /* WBXML_SUPPORT_DRMREL */ |
217 |
+#if defined( WBXML_SUPPORT_OTA_SETTINGS ) |
218 |
+static WBXMLError wbxml_encode_ota_nokia_icon(WBXMLEncoder *encoder, WB_UTINY *buffer) |
219 |
+{ |
220 |
+ WBXMLError ret = WBXML_NOT_ENCODED; |
221 |
+ |
222 |
+ /* Is a VALUE attribute ? */ |
223 |
+ if ((encoder->current_tag != NULL) && |
224 |
+ (encoder->current_attr->wbxmlCodePage == 0x00) && |
225 |
+ (encoder->current_attr->wbxmlToken == 0x11) && |
226 |
+ (encoder->current_node && encoder->current_node->attrs)) |
227 |
+ { |
228 |
+ WBXMLList *attrs = encoder->current_node->attrs; |
229 |
+ WB_ULONG index = 0; |
230 |
+ WB_ULONG nb_attrs = wbxml_list_len(attrs); |
231 |
+ WB_BOOL found = FALSE; |
232 |
+ |
233 |
+ /* Search for a NAME="ICON" attribute */ |
234 |
+ while (!found && (index < nb_attrs)) { |
235 |
+ WBXMLAttribute *attr = (WBXMLAttribute*)wbxml_list_get(attrs, index); |
236 |
+ |
237 |
+ if ((WBXML_STRCMP("NAME", wbxml_attribute_get_xml_name(attr)) == 0) && |
238 |
+ (WBXML_STRCMP("ICON", wbxml_attribute_get_xml_value(attr)) == 0)) |
239 |
+ { |
240 |
+ WB_UTINY *data = NULL; |
241 |
+ WB_LONG data_len = 0; |
242 |
|
243 |
+ /* Decode Base64 */ |
244 |
+ if ((data_len = wbxml_base64_decode(buffer, &data)) < 0) |
245 |
+ return WBXML_NOT_ENCODED; |
246 |
+ |
247 |
+ /* Encode opaque */ |
248 |
+ if ((ret = wbxml_encode_opaque_data(encoder, data, data_len)) != WBXML_OK) |
249 |
+ return ret; |
250 |
+ |
251 |
+ /* Free Data */ |
252 |
+ wbxml_free(data); |
253 |
+ |
254 |
+ found = TRUE; |
255 |
+ } |
256 |
+ |
257 |
+ index++; |
258 |
+ } |
259 |
+ } |
260 |
+ |
261 |
+ return ret; |
262 |
+} |
263 |
|
264 |
+#endif /* WBXML_SUPPORT_OTA_SETTINGS */ |
265 |
#if defined( WBXML_ENCODER_USE_STRTBL ) |
266 |
|
267 |
/**************************** |
268 |
@@ -4019,7 +4096,8 @@ |
269 |
#if defined( WBXML_SUPPORT_SYNCML ) |
270 |
/* Change text in <Type> from "application/vnd.syncml-devinf+wbxml" to "application/vnd.syncml-devinf+xml" */ |
271 |
if (((encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML10) || |
272 |
- (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML11)) && |
273 |
+ (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML11) || |
274 |
+ (encoder->lang->langID == WBXML_LANG_SYNCML_SYNCML12)) && |
275 |
(encoder->current_tag != NULL) && |
276 |
(encoder->current_tag->wbxmlCodePage == 0x01 ) && |
277 |
(encoder->current_tag->wbxmlToken == 0x13 ) && |