#include #include #include #include #include #include #include #include #include #include #include #include static void structured_error_callback(void *ctx, xmlErrorPtr xerror) { printf("SEC: %p\n", ctx); } static void structuredErrorFunc(void *userData, xmlErrorPtr xerror) { printf("SEF: %p\n", userData); } xmlSAXHandler sax_handler = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XML_SAX2_MAGIC, 0, 0, 0, 0 }; int main(int argc, char *argv[]) { char a[] = "true"; if (argc != 4) { printf("usage: %s XML SET_ERR_FUNC SET_CONTEXT_ERR_FUNC\n", argv[0]); exit(1); } xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(argv[1], strlen(argv[1])); if (!strcmp(argv[2], a)) { printf("Setting xmlSetStructuredErrorFunc()\n"); xmlSetStructuredErrorFunc((void *)0xbadf00d, structuredErrorFunc); } ctxt->sax2 = 1; ctxt->userData = (void*)0xdeadbeef; if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(sax_handler)); if (ctxt->sax == NULL) { printf("ENOMEM\n"); exit(1); } memcpy(ctxt->sax, &sax_handler, sizeof(sax_handler)); if (!strcmp(argv[3], a)) { printf("Setting ctxt->sax->serror\n"); ctxt->sax->serror = (xmlStructuredErrorFunc) structured_error_callback; } xmlParseDocument(ctxt); if (ctxt->myDoc) xmlFreeDoc(ctxt->myDoc); xmlFreeParserCtxt(ctxt); exit(0); }