Joe Orton wrote:
On Wed, Jun 23, 2004 at 04:10:58PM +0200, jean-frederic clere wrote:
Why take a convset if this can only convert to EBCDIC? You know that the
tree is in UTF-8 so there is no other variable for the caller to
control.
The convset I have used is ap_hdrs_from_ascii. (APR_DEFAULT_CHARSET,
"ISO8859-1") that is fixed.
It's broken then - the XML parser returns UTF-8.
It looks like the code will silently corrupt any part of the DOM tree
which can't be entirely converted to EBCDIC, since it ignores the
_conv_buffer return values, which doesn't seem acceptable to me.
Ok, I have prepared the attached patch should I apply it?
joe
Index: apr_xml.c
===================================================================
RCS file: /home/cvs/apr-util/xml/apr_xml.c,v
retrieving revision 1.32
diff -u -r1.32 apr_xml.c
--- apr_xml.c 23 Jun 2004 14:36:41 -0000 1.32
+++ apr_xml.c 6 Jul 2004 08:38:12 -0000
@@ -896,29 +896,49 @@
apr_xml_elem *ec;
apr_text *t;
apr_size_t inbytes_left, outbytes_left;
+ apr_status_t status;
inbytes_left = outbytes_left = strlen(e->name);
- apr_xlate_conv_buffer(convset, e->name, &inbytes_left, (char *) e->name,
&outbytes_left);
+ status = apr_xlate_conv_buffer(convset, e->name, &inbytes_left, (char *)
e->name, &outbytes_left);
+ if (status) {
+ return status;
+ }
for (t = e->first_cdata.first; t != NULL; t = t->next) {
inbytes_left = outbytes_left = strlen(t->text);
- apr_xlate_conv_buffer(convset, t->text, &inbytes_left, (char *)
t->text, &outbytes_left);
+ status = apr_xlate_conv_buffer(convset, t->text, &inbytes_left, (char
*) t->text, &outbytes_left);
+ if (status) {
+ return status;
+ }
}
for (t = e->following_cdata.first; t != NULL; t = t->next) {
inbytes_left = outbytes_left = strlen(t->text);
- apr_xlate_conv_buffer(convset, t->text, &inbytes_left, (char *)
t->text, &outbytes_left);
+ status = apr_xlate_conv_buffer(convset, t->text, &inbytes_left, (char
*) t->text, &outbytes_left);
+ if (status) {
+ return status;
+ }
}
for (a = e->attr; a != NULL; a = a->next) {
inbytes_left = outbytes_left = strlen(a->name);
- apr_xlate_conv_buffer(convset, a->name, &inbytes_left, (char *)
a->name, &outbytes_left);
+ status = apr_xlate_conv_buffer(convset, a->name, &inbytes_left, (char
*) a->name, &outbytes_left);
+ if (status) {
+ return status;
+ }
inbytes_left = outbytes_left = strlen(a->value);
- apr_xlate_conv_buffer(convset, a->value, &inbytes_left, (char *)
a->value, &outbytes_left);
+ status = apr_xlate_conv_buffer(convset, a->value, &inbytes_left, (char
*) a->value, &outbytes_left);
+ if (status) {
+ return status;
+ }
}
- for (ec = e->first_child; ec != NULL; ec = ec->next)
- apr_xml_parser_convert_elem(ec, convset);
+ for (ec = e->first_child; ec != NULL; ec = ec->next) {
+ status = apr_xml_parser_convert_elem(ec, convset);
+ if (status) {
+ return status;
+ }
+ }
return APR_SUCCESS;
}
@@ -927,6 +947,7 @@
apr_xml_doc *pdoc,
apr_xlate_t *convset)
{
+ apr_status_t status;
/* Don't convert the namespaces: they are constant! */
if (pdoc->namespaces != NULL) {
int i;
@@ -941,12 +962,14 @@
if ( ptr == NULL)
return APR_ENOMEM;
inbytes_left = outbytes_left = strlen(ptr);
- apr_xlate_conv_buffer(convset, ptr, &inbytes_left, ptr,
&outbytes_left);
+ status = apr_xlate_conv_buffer(convset, ptr, &inbytes_left, ptr,
&outbytes_left);
+ if (status) {
+ return status;
+ }
apr_xml_insert_uri(namespaces, ptr);
}
pdoc->namespaces = namespaces;
}
- apr_xml_parser_convert_elem(pdoc->root, convset);
- return APR_SUCCESS;
+ return apr_xml_parser_convert_elem(pdoc->root, convset);
}
#endif