X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=php5-swig%2Fxml-template.swig;h=02314f0e81637b710b1adcebcff23ce52748a486;hb=f5af96eb727899f04c322640ee36028441c29ec9;hp=225f8bbd2e2d9a4c17df0d3937bef0721a15beff;hpb=c00c787ebcd86ec94285b708db96a20286e57ab0;p=xml-template diff --git a/php5-swig/xml-template.swig b/php5-swig/xml-template.swig index 225f8bb..02314f0 100644 --- a/php5-swig/xml-template.swig +++ b/php5-swig/xml-template.swig @@ -1,4 +1,5 @@ %module XML_Template_SWIG +%include struct XmlDocPtrWrapper { ~XmlDocPtrWrapper(); @@ -93,13 +94,31 @@ XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive delete root_directive; return XmlDocPtrWrapper(new XmlDocWrapper { ret }); } - -void output_to_fd(XmlDocPtrWrapper doc, int fd) + +namespace { + +int write_to_string(void *context, const char *buffer, int len) { - xmlOutputBufferPtr buf = xmlOutputBufferCreateFd(fd, NULL); - xmlSaveFileTo(buf, doc->ptr, NULL); + std::string *str = reinterpret_cast(context); + str->append(buffer, len); + return len; +} + +int close_string(void *context) +{ + return 0; } +} // namespace + +std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc) +{ + std::string ret; + xmlOutputBufferPtr buf = xmlOutputBufferCreateIO(write_to_string, close_string, &ret, NULL); + xmlSaveFileTo(buf, doc->ptr, NULL); + return ret; +} + %} %typemap(in) Directive* { @@ -107,5 +126,5 @@ void output_to_fd(XmlDocPtrWrapper doc, int fd) } XmlDocPtrWrapper XML_Template_process_file(const char *input_filename, Directive *root_directive, bool clean); -void output_to_fd(XmlDocPtrWrapper doc, int fd); +std::string XML_Template_convert_doc_to_string(XmlDocPtrWrapper doc);