Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f71c7b9d
Commit
f71c7b9d
authored
Sep 23, 2007
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs in XML binary I/O functions. Heikki and Tom
parent
a8da5761
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
src/backend/utils/adt/xml.c
src/backend/utils/adt/xml.c
+30
-9
No files found.
src/backend/utils/adt/xml.c
View file @
f71c7b9d
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.4
6 2007/07/13 03:43:23
tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.4
7 2007/09/23 21:36:42
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -232,37 +232,51 @@ xml_recv(PG_FUNCTION_ARGS)
xmlDocPtr
doc
;
xmlChar
*
encoding
=
NULL
;
str
=
pq_getmsgtext
(
buf
,
buf
->
len
-
buf
->
cursor
,
&
nbytes
);
/*
* Read the data in raw format. We don't know yet what the encoding
* is, as that information is embedded in the xml declaration; so we
* have to parse that before converting to server encoding.
*/
nbytes
=
buf
->
len
-
buf
->
cursor
;
str
=
(
char
*
)
pq_getmsgbytes
(
buf
,
nbytes
);
result
=
palloc
(
nbytes
+
VARHDRSZ
);
/*
* We need a null-terminated string to pass to parse_xml_decl(). Rather
* than make a separate copy, make the temporary result one byte bigger
* than it needs to be.
*/
result
=
palloc
(
nbytes
+
1
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
nbytes
+
VARHDRSZ
);
memcpy
(
VARDATA
(
result
),
str
,
nbytes
);
str
=
VARDATA
(
result
);
str
[
nbytes
]
=
'\0'
;
parse_xml_decl
((
xmlChar
*
)
str
,
NULL
,
NULL
,
&
encoding
,
NULL
);
/*
* Parse the data to check if it is well-formed XML data. Assume
* that
ERROR occurred if parsing failed
.
* that
xml_parse will throw ERROR if not
.
*/
doc
=
xml_parse
(
result
,
xmloption
,
true
,
encoding
);
xmlFreeDoc
(
doc
);
/* Now that we know what we're dealing with, convert to server encoding */
newstr
=
(
char
*
)
pg_do_encoding_conversion
((
unsigned
char
*
)
str
,
nbytes
,
encoding
?
pg_char_to_encoding
((
char
*
)
encoding
)
:
PG_UTF8
,
GetDatabaseEncoding
());
pfree
(
str
);
if
(
newstr
!=
str
)
{
free
(
result
);
p
free
(
result
);
nbytes
=
strlen
(
newstr
);
result
=
palloc
(
nbytes
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
nbytes
+
VARHDRSZ
);
memcpy
(
VARDATA
(
result
),
newstr
,
nbytes
);
pfree
(
newstr
);
}
PG_RETURN_XML_P
(
result
);
...
...
@@ -277,11 +291,18 @@ Datum
xml_send
(
PG_FUNCTION_ARGS
)
{
xmltype
*
x
=
PG_GETARG_XML_P
(
0
);
char
*
outval
=
xml_out_internal
(
x
,
pg_get_client_encoding
())
;
char
*
outval
;
StringInfoData
buf
;
/*
* xml_out_internal doesn't convert the encoding, it just prints
* the right declaration. pq_sendtext will do the conversion.
*/
outval
=
xml_out_internal
(
x
,
pg_get_client_encoding
());
pq_begintypsend
(
&
buf
);
pq_sendstring
(
&
buf
,
outval
);
pq_sendtext
(
&
buf
,
outval
,
strlen
(
outval
));
pfree
(
outval
);
PG_RETURN_BYTEA_P
(
pq_endtypsend
(
&
buf
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment