X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fgdome_xslt%2FC%2Fgdome_xslt%2Fgdome_xslt.c;h=232f14b12b7e4945965ae1775f50a78058efb6ca;hb=4167cea65ca58897d1a3dbb81ff95de5074700cc;hp=87d3d4324ae85c1d2c159068a6af94b9896b9b3c;hpb=d2ef4a0e438ed6acee836b3786e377b133c098af;p=helm.git diff --git a/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c index 87d3d4324..232f14b12 100644 --- a/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c +++ b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c @@ -27,7 +27,9 @@ */ #include -#include +#include +#include +#include #include #include #include @@ -152,3 +154,86 @@ int saveResultToFd (int fd, GdomeDocument* result, xsltStylesheetPtr 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; +} +