*/
#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
#include <libgdome/gdome.h>
#include <libxslt/xsltconfig.h>
#include <libxslt/xslt.h>
return xsltSaveResultToFd(fd, result_libxml, style_libxslt);
}
+ /**********************************************/
+ /* Error and Debugging Callbacks Registration */
+ /**********************************************/
+
+ /* max size of a single message passed to callbacks */
+#define MAX_MSG_SIZE 1024
+#define TRUNCATED_MSG "... TRUNCATED ..."
+#define TRUNCATED_MSG_LEN strlen(TRUNCATED_MSG)
+
+ /* ERROR callbacks */
+
+ /* user provided error callback, needs a string input */
+static gdomeXsltMsgCallback errorUserCallback = NULL;
+
+ /* libxslt like error callback, ignore context, builds a string
+ * input for user provided error callback and invoke it */
+void gdomeXsltErrorCallback (void *ctx, const char *msg, ...) {
+ va_list args;
+ char buf[MAX_MSG_SIZE];
+
+ if (errorUserCallback == NULL)
+ return;
+
+ va_start(args, msg);
+ if (vsnprintf(buf, MAX_MSG_SIZE, msg, args) > MAX_MSG_SIZE - 1)
+ { /* message truncated; write TRUNCATED_MSG on it */
+ strncpy(buf+(strlen(buf) - TRUNCATED_MSG_LEN),
+ TRUNCATED_MSG, TRUNCATED_MSG_LEN);
+ }
+ va_end(args);
+
+ (*errorUserCallback) (buf);
+
+ return;
+}
+
+ /* set user provided error callback */
+void setErrorCallback (gdomeXsltMsgCallback callback)
+{
+ errorUserCallback = callback;
+ xsltSetGenericErrorFunc(NULL,
+ (callback == NULL ? NULL : gdomeXsltErrorCallback));
+
+ return;
+}
+
+ /* DEBUG callbacks */
+
+ /* user provided debug callback, needs a string input */
+static gdomeXsltMsgCallback debugUserCallback = NULL;
+
+ /* libxslt like debug callback, ignore context, builds a string
+ * input for user provided debug callback and invoke it */
+void gdomeXsltDebugCallback (void *ctx, const char *msg, ...) {
+ va_list args;
+ char buf[MAX_MSG_SIZE];
+
+ if (debugUserCallback == NULL)
+ return;
+
+ va_start(args, msg);
+ if (vsnprintf(buf, MAX_MSG_SIZE, msg, args) > MAX_MSG_SIZE - 1)
+ { /* message truncated; write TRUNCATED_MSG on it */
+ strncpy(buf+(strlen(buf) - TRUNCATED_MSG_LEN),
+ TRUNCATED_MSG, TRUNCATED_MSG_LEN);
+ }
+ va_end(args);
+
+ (*debugUserCallback) (buf);
+
+ return;
+}
+
+ /* set user provided debug callback */
+void setDebugCallback (gdomeXsltMsgCallback callback)
+{
+ debugUserCallback = callback;
+ xsltSetGenericDebugFunc(NULL,
+ (callback == NULL ? NULL : gdomeXsltDebugCallback));
+
+ return;
+}
+
extern "C" {
#endif /* __cplusplus */
+ /******************************/
+ /* XSLT stylesheet Processing */
+ /******************************/
+
xsltStylesheetPtr processStylesheet (GdomeDocument* style);
+
+ /*******************************/
+ /* XSLT stylesheet Application */
+ /*******************************/
+
GdomeDocument* applyStylesheet (GdomeDocument* source,
xsltStylesheetPtr style_libxslt,
const char** params);
+ /******************/
+ /* Results Output */
+ /******************/
+
int saveResultToFilename (const char* name,
GdomeDocument* result,
xsltStylesheetPtr style_libxslt,
int saveResultToFd (int fd,
GdomeDocument* result,
xsltStylesheetPtr style_libxslt);
+
+ /**********************************************/
+ /* Error and Debugging Callbacks Registration */
+ /**********************************************/
+
+typedef void(*gdomeXsltMsgCallback)(const char *);
+
+void setErrorCallback (gdomeXsltMsgCallback callback);
+void setDebugCallback (gdomeXsltMsgCallback callback);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
~stylesheet
;;
+let setErrorCallback = function
+ | None -> I_gdome_xslt.disableErrorCallback ()
+ | Some (callback: string -> unit) ->
+ Callback.register "error_callback" callback;
+ I_gdome_xslt.enableErrorCallback ()
+;;
+let setDebugCallback = function
+ | None -> I_gdome_xslt.disableDebugCallback ()
+ | Some (callback: string -> unit) ->
+ Callback.register "debug_callback" callback;
+ I_gdome_xslt.enableDebugCallback ()
+;;
+
stylesheet: I_gdome_xslt.processed_stylesheet ->
unit
+(** set error callback, that is a function invoked each time an error message is
+generated. If None is passed, libxslt default error callback is used *)
+val setErrorCallback: (string -> unit) option -> unit
+
+(** set debug callback, that is a function invoked each time a debugging message
+is generated. If None is passed, libxslt default error callback is used *)
+val setDebugCallback: (string -> unit) option -> unit
+
unit
= "ml_saveResultToChannel"
+external enableErrorCallback : unit -> unit = "ml_enableErrorCallback"
+external disableErrorCallback : unit -> unit = "ml_disableErrorCallback"
+external enableDebugCallback : unit -> unit = "ml_enableDebugCallback"
+external disableDebugCallback : unit -> unit = "ml_disableDebugCallback"
+
#include <caml/memory.h>
#include <caml/custom.h>
#include <caml/callback.h>
+#include <caml/mlvalues.h>
#include <libxslt/xsltconfig.h>
#include <libxslt/imports.h>
CAMLreturn0;
}
+ /* error callback handling */
+
+static void ml_gdomeXsltErrorCallback(const char *msg) {
+ callback(*caml_named_value("error_callback"), copy_string(msg));
+
+ return;
+}
+
+value ml_enableErrorCallback(value unit) {
+ CAMLparam1(unit);
+ setErrorCallback(ml_gdomeXsltErrorCallback);
+ CAMLreturn(Val_unit);
+}
+
+value ml_disableErrorCallback(value unit) {
+ CAMLparam1(unit);
+ setErrorCallback(NULL);
+ CAMLreturn(Val_unit);
+}
+
+ /* debug callback handling */
+
+static void ml_gdomeXsltDebugCallback(const char *msg) {
+ callback(*caml_named_value("debug_callback"), copy_string(msg));
+
+ return;
+}
+
+value ml_enableDebugCallback(value unit) {
+ CAMLparam1(unit);
+ setDebugCallback(ml_gdomeXsltDebugCallback);
+ CAMLreturn(Val_unit);
+}
+
+value ml_disableDebugCallback(value unit) {
+ CAMLparam1(unit);
+ setDebugCallback(NULL);
+ CAMLreturn(Val_unit);
+}
+
value ml_saveResultToChannel(value channel, value result, value stylesheet);
+value ml_enableErrorCallback(value unit);
+value ml_disableErrorCallback(value unit);
+value ml_enableDebugCallback(value unit);
+value ml_disableDebugCallback(value unit);
+