55 volatile xsltStylesheetPtr stylesheet = NULL;
56 volatile xmlDocPtr doctree = NULL;
57 volatile xmlDocPtr restree = NULL;
58 volatile xsltSecurityPrefsPtr xslt_sec_prefs = NULL;
59 volatile xsltTransformContextPtr xslt_ctxt = NULL;
60 volatile int resstat = -1;
61 xmlChar *resstr = NULL;
64 if (fcinfo->nargs == 3)
67 params = parse_params(paramstr);
72 params = (
const char **)
palloc(
sizeof(
char *));
82 bool xslt_sec_prefs_error;
91 "error parsing XML document");
100 "error parsing stylesheet as XML document");
103 stylesheet = xsltParseStylesheetDoc(ssdoc);
105 if (stylesheet == NULL)
107 "failed to parse stylesheet");
109 xslt_ctxt = xsltNewTransformContext(stylesheet, doctree);
111 xslt_sec_prefs_error =
false;
112 if ((xslt_sec_prefs = xsltNewSecurityPrefs()) == NULL)
113 xslt_sec_prefs_error =
true;
115 if (xsltSetSecurityPrefs(xslt_sec_prefs, XSLT_SECPREF_READ_FILE,
116 xsltSecurityForbid) != 0)
117 xslt_sec_prefs_error =
true;
118 if (xsltSetSecurityPrefs(xslt_sec_prefs, XSLT_SECPREF_WRITE_FILE,
119 xsltSecurityForbid) != 0)
120 xslt_sec_prefs_error =
true;
121 if (xsltSetSecurityPrefs(xslt_sec_prefs, XSLT_SECPREF_CREATE_DIRECTORY,
122 xsltSecurityForbid) != 0)
123 xslt_sec_prefs_error =
true;
124 if (xsltSetSecurityPrefs(xslt_sec_prefs, XSLT_SECPREF_READ_NETWORK,
125 xsltSecurityForbid) != 0)
126 xslt_sec_prefs_error =
true;
127 if (xsltSetSecurityPrefs(xslt_sec_prefs, XSLT_SECPREF_WRITE_NETWORK,
128 xsltSecurityForbid) != 0)
129 xslt_sec_prefs_error =
true;
130 if (xsltSetCtxtSecurityPrefs(xslt_sec_prefs, xslt_ctxt) != 0)
131 xslt_sec_prefs_error =
true;
133 if (xslt_sec_prefs_error)
135 (
errmsg(
"could not set libxslt security preferences")));
137 restree = xsltApplyStylesheetUser(stylesheet, doctree, params,
138 NULL, NULL, xslt_ctxt);
142 "failed to apply stylesheet");
144 resstat = xsltSaveResultToString(&resstr, &reslen, restree, stylesheet);
150 if (xslt_ctxt != NULL)
151 xsltFreeTransformContext(xslt_ctxt);
152 if (xslt_sec_prefs != NULL)
153 xsltFreeSecurityPrefs(xslt_sec_prefs);
154 if (stylesheet != NULL)
155 xsltFreeStylesheet(stylesheet);
158 xsltCleanupGlobals();
167 xsltFreeTransformContext(xslt_ctxt);
168 xsltFreeSecurityPrefs(xslt_sec_prefs);
169 xsltFreeStylesheet(stylesheet);
171 xsltCleanupGlobals();
188 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
189 errmsg(
"xslt_process() is not available without libxslt")));
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_TEXT_P(x)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text_with_len(const char *s, int len)
struct PgXmlErrorContext PgXmlErrorContext
void xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg)
void pg_xml_done(PgXmlErrorContext *errcxt, bool isError)
@ PG_XML_STRICTNESS_LEGACY
PgXmlErrorContext * pgxml_parser_init(PgXmlStrictness strictness)