c_XSLTProcessor::c_XSLTProcessor(Class *cb) : ExtObjectData(cb), m_stylesheet(nullptr), m_doc(nullptr), m_secprefs(k_XSL_SECPREF_DEFAULT), m_registerPhpFunctions(0) { xsltSetGenericErrorFunc(nullptr, xslt_ext_error_handler); exsltRegisterAll(); }
void yaz_init_globals(void) { if (yaz_init_flag) return; #if YAZ_POSIX_THREADS pthread_mutex_lock(&yaz_init_mutex); #endif if (!yaz_init_flag) { yaz_log_init_globals(); #if HAVE_GCRYPT_H /* POSIX threads locking. In case gnutls_global_init do not override */ gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); #endif #if HAVE_GNUTLS_H gnutls_global_init(); #endif #if HAVE_GCRYPT_H /* most likely, GnuTLS has already initialized libgcrypt */ if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) { gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); } #endif #if YAZ_HAVE_EXSLT exsltRegisterAll(); #endif yaz_init_flag = 1; /* must be last, before unlocking */ } #if YAZ_POSIX_THREADS pthread_mutex_unlock(&yaz_init_mutex); #endif }
void moduleInit() override { xsltSetGenericErrorFunc(nullptr, xslt_ext_error_handler); exsltRegisterAll(); HHVM_RC_INT(XSL_SECPREF_NONE, k_XSL_SECPREF_NONE); HHVM_RC_INT(XSL_SECPREF_READ_FILE, k_XSL_SECPREF_READ_FILE); HHVM_RC_INT(XSL_SECPREF_WRITE_FILE, k_XSL_SECPREF_WRITE_FILE); HHVM_RC_INT(XSL_SECPREF_CREATE_DIRECTORY, k_XSL_SECPREF_CREATE_DIRECTORY); HHVM_RC_INT(XSL_SECPREF_READ_NETWORK, k_XSL_SECPREF_READ_NETWORK); HHVM_RC_INT(XSL_SECPREF_WRITE_NETWORK, k_XSL_SECPREF_WRITE_NETWORK); HHVM_RC_INT(XSL_SECPREF_DEFAULT, k_XSL_SECPREF_DEFAULT); HHVM_RC_INT_SAME(LIBXSLT_VERSION); HHVM_RC_STR_SAME(LIBXSLT_DOTTED_VERSION); HHVM_ME(XSLTProcessor, getParameter); HHVM_ME(XSLTProcessor, getSecurityPrefs); HHVM_ME(XSLTProcessor, importStylesheet); HHVM_ME(XSLTProcessor, removeParameter); HHVM_ME(XSLTProcessor, registerPHPFunctions); HHVM_ME(XSLTProcessor, setParameter); HHVM_ME(XSLTProcessor, setSecurityPrefs); HHVM_ME(XSLTProcessor, setProfiling); HHVM_ME(XSLTProcessor, transformToDoc); HHVM_ME(XSLTProcessor, transformToURI); HHVM_ME(XSLTProcessor, transformToXML); Native:: registerNativeDataInfo<XSLTProcessorData>(s_XSLTProcessorData.get()); loadSystemlib(); }
void Init_libxslt_ruby(void) { LIBXML_TEST_VERSION; cLibXSLT = rb_define_module("LibXSLT"); cXSLT = rb_define_module_under(cLibXSLT, "XSLT"); rb_define_const(cXSLT, "MAX_DEPTH", INT2NUM(xsltMaxDepth)); rb_define_const(cXSLT, "MAX_SORT", INT2NUM(XSLT_MAX_SORT)); rb_define_const(cXSLT, "ENGINE_VERSION", rb_str_new2(xsltEngineVersion)); rb_define_const(cXSLT, "LIBXSLT_VERSION", INT2NUM(xsltLibxsltVersion)); rb_define_const(cXSLT, "LIBXML_VERSION", INT2NUM(xsltLibxmlVersion)); rb_define_const(cXSLT, "XSLT_NAMESPACE", rb_str_new2((const char*)XSLT_NAMESPACE)); rb_define_const(cXSLT, "DEFAULT_VENDOR", rb_str_new2(XSLT_DEFAULT_VENDOR)); rb_define_const(cXSLT, "DEFAULT_VERSION", rb_str_new2(XSLT_DEFAULT_VERSION)); rb_define_const(cXSLT, "DEFAULT_URL", rb_str_new2(XSLT_DEFAULT_URL)); rb_define_const(cXSLT, "NAMESPACE_LIBXSLT", rb_str_new2((const char*)XSLT_LIBXSLT_NAMESPACE)); rb_define_const(cXSLT, "NAMESPACE_NORM_SAXON", rb_str_new2((const char*)XSLT_NORM_SAXON_NAMESPACE)); rb_define_const(cXSLT, "NAMESPACE_SAXON", rb_str_new2((const char*)XSLT_SAXON_NAMESPACE)); rb_define_const(cXSLT, "NAMESPACE_XT", rb_str_new2((const char*)XSLT_XT_NAMESPACE)); rb_define_const(cXSLT, "NAMESPACE_XALAN", rb_str_new2((const char*)XSLT_XALAN_NAMESPACE)); eXSLTError = rb_define_class_under(cLibXSLT, "XSLTError", rb_eRuntimeError); eXMLXSLTStylesheetRequireParsedDoc = rb_define_class_under(cLibXSLT, "ResultError", rb_eRuntimeError); ruby_init_xslt_stylesheet(); /* Now load exslt. */ exsltRegisterAll(); }
/* Called from within R. This is used when we are not running in stand-alone mode, but within a regular R session and want to use XSLT with the R extensions. We now call this when we load the Sxslt library regardless of which mode we are in. There is the possibility of duplication which we can take care of in the near future. XXX */ void R_registerXSLTModule(int *fromR) { exsltRegisterAll(); registerRModule(*fromR); if(fromR) R_alreadyInitialized = 1; }
/* * call-seq: * parse_stylesheet_doc(document) * * Parse a stylesheet from +document+. */ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj) { xmlDocPtr xml ; xsltStylesheetPtr ss ; Data_Get_Struct(xmldocobj, xmlDoc, xml); exsltRegisterAll(); ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */ return Data_Wrap_Struct(klass, NULL, dealloc, ss); }
/********************************************************************** print_xml_filename_to_filename_using_stylesheet Print the contents of an XML file to another file applying an XSLT stylesheet. Returns TRUE if successful, FALSE otherwise. **********************************************************************/ BOOLEAN_T print_xml_filename_to_filename_using_stylesheet( char* input_file_path, /* path to XML input file IN */ char* stylesheet_file_path, /* path to MEME XSL stylesheet IN */ char* output_file_path /* path to HTML output file IN */ ) { xsltStylesheetPtr stylesheet = NULL; xmlDocPtr input_doc = NULL; xmlDocPtr output_doc = NULL; const int PERFORM_ENTITY_SUBST = 1; xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST); xmlLoadExtDtdDefaultValue = 0; exsltRegisterAll(); stylesheet = xsltParseStylesheetFile((const xmlChar *) stylesheet_file_path); if (!stylesheet) { fprintf(stderr, "Unable to parse stylesheet %s.\n", stylesheet_file_path); return FALSE; } input_doc = xmlParseFile(input_file_path); if (!input_doc) { fprintf(stderr, "Unable to parse input file %s.\n", input_file_path); return FALSE; } output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL); if (!output_doc) { fprintf( stderr, "Unable to apply stylsheet %s to input from file %s.\n", stylesheet_file_path, input_file_path ); return FALSE; } int result = xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0); if (result == -1) { fprintf( stderr, "Unable to save result of applying stylesheet %s to %s.\n", stylesheet_file_path, output_file_path ); } xsltFreeStylesheet(stylesheet); xmlFreeDoc(output_doc); xmlFreeDoc(input_doc); xsltCleanupGlobals(); xmlCleanupParser(); return TRUE; } /* print_xml_file_html */
Xsltproc::Xsltproc() : mErrorRedirect(false) { exsltRegisterAll(); xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; mStylesheet = 0; mOutput = 0; mXml = 0; mParams = 0; mNParams = 0; }
void moduleInit() override { xsltSetGenericErrorFunc(nullptr, xslt_ext_error_handler); exsltRegisterAll(); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_NONE.get(), k_XSL_SECPREF_NONE ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_READ_FILE.get(), k_XSL_SECPREF_READ_FILE ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_WRITE_FILE.get(), k_XSL_SECPREF_WRITE_FILE ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_CREATE_DIRECTORY.get(), k_XSL_SECPREF_CREATE_DIRECTORY ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_READ_NETWORK.get(), k_XSL_SECPREF_READ_NETWORK ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_WRITE_NETWORK.get(), k_XSL_SECPREF_WRITE_NETWORK ); Native::registerConstant<KindOfInt64>( s_XSL_SECPREF_DEFAULT.get(), k_XSL_SECPREF_DEFAULT ); Native::registerConstant<KindOfInt64>( s_xslt_version.get(), LIBXSLT_VERSION ); Native::registerConstant<KindOfString>( s_xslt_dotted_version.get(), s_xslt_dotted_version_value.get() ); HHVM_ME(XSLTProcessor, getParameter); HHVM_ME(XSLTProcessor, getSecurityPrefs); HHVM_ME(XSLTProcessor, importStylesheet); HHVM_ME(XSLTProcessor, removeParameter); HHVM_ME(XSLTProcessor, registerPHPFunctions); HHVM_ME(XSLTProcessor, setParameter); HHVM_ME(XSLTProcessor, setSecurityPrefs); HHVM_ME(XSLTProcessor, setProfiling); HHVM_ME(XSLTProcessor, transformToDoc); HHVM_ME(XSLTProcessor, transformToURI); HHVM_ME(XSLTProcessor, transformToXML); Native:: registerNativeDataInfo<XSLTProcessorData>(s_XSLTProcessorData.get()); loadSystemlib(); }
/* * call-seq: * parse_stylesheet_doc(document) * * Parse a stylesheet from +document+. */ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj) { xmlDocPtr xml ; xsltStylesheetPtr ss ; Data_Get_Struct(xmldocobj, xmlDoc, xml); exsltRegisterAll(); xsltSetGenericErrorFunc(NULL, xslt_generic_error_handler); ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */ xsltSetGenericErrorFunc(NULL, NULL); return Data_Wrap_Struct(klass, NULL, dealloc, ss); }
void xslt::init::init_library() { xsltInit(); // set some defautls process_xincludes(true); set_allow_extension_functions_leak(false); // keep libxslt silent xsltSetGenericErrorFunc(0, xslt_error); xsltSetGenericDebugFunc(0, xslt_error); #ifdef HAVE_LIBEXSLT // load EXSLT exsltRegisterAll(); #endif }
void yelp_transform_start (YelpTransform *transform, xmlDocPtr document, gchar **params) { transform->inputDoc = document; transform->context = xsltNewTransformContext (transform->stylesheet, transform->inputDoc); if (!transform->context) { YelpError *error = yelp_error_new (_("Broken Transformation"), _("An unknown error occurred while attempting to " "transform the document.")); transform_set_error (transform, error); return; } transform->params = g_strdupv (params); transform->context->_private = transform; if (!exslt_registered) { exsltRegisterAll (); exslt_registered = TRUE; } xsltRegisterExtElement (transform->context, BAD_CAST "document", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_document); xsltRegisterExtElement (transform->context, BAD_CAST "cache", BAD_CAST YELP_NAMESPACE, (xsltTransformFunction) xslt_yelp_cache); xsltRegisterExtFunction (transform->context, BAD_CAST "input", BAD_CAST YELP_NAMESPACE, (xmlXPathFunction) xslt_yelp_input); transform->mutex = g_mutex_new (); g_mutex_lock (transform->mutex); transform->running = TRUE; transform->thread = g_thread_create ((GThreadFunc) transform_run, transform, FALSE, NULL); g_mutex_unlock (transform->mutex); }
int main(int argc, char* argv[]) { char* usage = "xsltpro_lite <xslt filename> <xml input filename> <output filename>\n"; if (argc != 4) { fprintf(stderr, "%s", usage); exit(0); } char* stylesheet_file_path = argv[1]; // Path to XSLT stylesheet char* input_file_path = argv[2]; // Path to XML input file IN char* output_file_path = argv[3]; // Path to XML input file IN xsltStylesheetPtr stylesheet = NULL; xmlDocPtr input_doc = NULL; xmlDocPtr output_doc = NULL; const int PERFORM_ENTITY_SUBST = 1; xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST); xmlLoadExtDtdDefaultValue = 0; exsltRegisterAll(); stylesheet = xsltParseStylesheetFile((xmlChar *) stylesheet_file_path); if (! stylesheet) { fprintf(stderr, "Couldn't parse stylesheet file %s\n", stylesheet_file_path); exit(1); } input_doc = xmlParseFile(input_file_path); if (! stylesheet) { fprintf(stderr, "Couldn't parse input file %s\n", input_file_path); exit(1); } output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL); if (! output_doc) { fprintf(stderr, "Couldn't apply stylesheet %s to input file %s\n", stylesheet_file_path, input_file_path); exit(1); } xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0); xmlFreeDoc(output_doc); xmlFreeDoc(input_doc); xsltFreeStylesheet(stylesheet); exit(0); };
static void yelp_transform_class_init (YelpTransformClass *klass) { exsltRegisterAll (); GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = yelp_transform_dispose; object_class->finalize = yelp_transform_finalize; object_class->get_property = yelp_transform_get_property; object_class->set_property = yelp_transform_set_property; signals[CHUNK_READY] = g_signal_new ("chunk-ready", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); signals[FINISHED] = g_signal_new ("finished", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[ERROR] = g_signal_new ("error", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); g_type_class_add_private (klass, sizeof (YelpTransformPrivate)); g_object_class_install_property (object_class, PROP_STYLESHEET, g_param_spec_string ("stylesheet", N_("XSLT Stylesheet"), N_("The location of the XSLT stylesheet"), NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); }
void cepgdata2xmltv::LoadXSLT() { if (pxsltStylesheet) return; xmlSetGenericErrorFunc(NULL,tvmGenericErrorFunc); xmlSubstituteEntitiesDefault (1); xmlLoadExtDtdDefaultValue = 1; xmlSetExternalEntityLoader(xmlMyExternalEntityLoader); exsltRegisterAll(); if ((sxmlDoc = xmlReadMemory (xsl, sizeof(xsl), NULL,NULL,0)) != NULL) { pxsltStylesheet=xsltParseStylesheetDoc(sxmlDoc); if (!pxsltStylesheet) { esyslog("can't parse stylesheet"); xmlFreeDoc (sxmlDoc); sxmlDoc=NULL; } } }
/********************************************************************** print_meme_file_html Print MEME results in HTML format. Format XML as HTML using a stylesheet and an XSLT **********************************************************************/ extern void print_meme_file_html( char* stylesheet_file_path, /* path to MEME XSL stylesheet IN */ char* input_file_path, /* path to XML input file IN */ char* output_file_path /* path to HTML output file IN */ ) { xsltStylesheetPtr stylesheet = NULL; xmlDocPtr input_doc = NULL; xmlDocPtr output_doc = NULL; const int PERFORM_ENTITY_SUBST = 1; xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST); xmlLoadExtDtdDefaultValue = 0; exsltRegisterAll(); stylesheet = xsltParseStylesheetFile((const xmlChar *) stylesheet_file_path); input_doc = xmlParseFile(input_file_path); output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL); xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0); xmlFreeDoc(output_doc); xmlFreeDoc(input_doc); xsltFreeStylesheet(stylesheet); } /* print_meme_file_html */
/* * call-seq: * parse_stylesheet_doc(document) * * Parse a stylesheet from +document+. */ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj) { xmlDocPtr xml, xml_cpy; VALUE errstr, exception; xsltStylesheetPtr ss ; Data_Get_Struct(xmldocobj, xmlDoc, xml); exsltRegisterAll(); errstr = rb_str_new(0, 0); xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler); xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */ ss = xsltParseStylesheetDoc(xml_cpy); xsltSetGenericErrorFunc(NULL, NULL); if (!ss) { xmlFreeDoc(xml_cpy); exception = rb_exc_new3(rb_eRuntimeError, errstr); rb_exc_raise(exception); } return Nokogiri_wrap_xslt_stylesheet(ss); }
/* A _configure function will be executed by the webserver * at the moment of 'first' initialisation. Here you do the * start of memory management. The processing of the configuration * parameters. */ ret_t cherokee_handler_xslt_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props) { cherokee_list_t *i; cherokee_handler_xslt_props_t *props; ret_t ret; if (*_props == NULL) { CHEROKEE_NEW_STRUCT (n, handler_xslt_props); cherokee_module_props_init_base (MODULE_PROPS(n), MODULE_PROPS_FREE(props_free)); /* Look at handler_xslt.h * This is an xslt of configuration. */ xmlInitMemory(); LIBXML_TEST_VERSION /* * Register the EXSLT extensions and the test module */ exsltRegisterAll(); xsltRegisterTestModule(); cherokee_buffer_init (&n->content_type); cherokee_buffer_init (&n->stylesheet); n->global = NULL; n->globalDoc = NULL; n->xinclude = false; n->xincludestyle = false; // n->sec = xsltNewSecurityPrefs(); // xsltSetDefaultSecurityPrefs(n->sec); n->defaultEntityLoader = xmlGetExternalEntityLoader(); // xmlSetExternalEntityLoader(xsltprocExternalEntityLoader); *_props = MODULE_PROPS(n); } props = PROP_XSLT(*_props); /* processing of the parameters, we only know about xslt_config * it might be a good thing to abort if we found a wrong key, understand * the consequences: your handler will prevent the server startup upon * a wrong configuration. * * You see the for each method is rather creative. Read more code * to see with what nice things Cherokee extended the C syntax. */ cherokee_config_node_foreach (i, conf) { cherokee_config_node_t *subconf = CONFIG_NODE(i); /* Cherokee has a nifty string equal function that allows * lazy programmers to do strcmp without the == 0. */ /*if (equal_buf_str (&subconf->key, "maxdepth")) { cherokee_atoi(subconf->val.buf, &props->xsltMaxDepth); } else if (equal_buf_str (&subconf->key, "maxparserdepth")) { cherokee_atoi(subconf->val.buf, &props->xsltParserMaxDepth); } else */ if (equal_buf_str (&subconf->key, "options")) { if (equal_buf_str (&subconf->val, "novalid")) { props->options |= XML_PARSE_NOENT | XML_PARSE_NOCDATA; } else if (equal_buf_str (&subconf->val, "nodtdattr")) { props->options |= XML_PARSE_NOENT | XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA; } else { PRINT_MSG ("ERROR: Handler xslt: Unknown value: '%s'\n", subconf->val.buf); return ret_error; } } else if (equal_buf_str (&subconf->key, "nodict")) { cherokee_boolean_t nodict; ret = cherokee_atob (subconf->val.buf, &nodict); if (ret != ret_ok) return ret; if (nodict) { props->options |= XML_PARSE_NODICT; } #ifdef LIBXML_CATALOG_ENABLED } else if (equal_buf_str (&subconf->key, "catalogs")) { cherokee_boolean_t catalogs; ret = cherokee_atob (subconf->val.buf, &catalogs); if (ret != ret_ok) return ret; if (catalogs) { const char *catalogs = getenv("SGML_CATALOG_FILES"); if (catalogs != NULL) { xmlLoadCatalogs(catalogs); } } #endif #ifdef LIBXML_XINCLUDE_ENABLED } else if (equal_buf_str (&subconf->key, "xinclude")) { ret = cherokee_atob (subconf->val.buf, &props->xinclude); } else if (equal_buf_str (&subconf->key, "xincludestyle")) { ret = cherokee_atob (subconf->val.buf, &props->xincludestyle); if (props->xincludestyle) { xsltSetXIncludeDefault(1); } #endif } else if (equal_buf_str (&subconf->key, "contenttype")) { cherokee_buffer_add(&props->content_type, subconf->val.buf, subconf->val.len); } else if (equal_buf_str (&subconf->key, "stylesheet")) { cherokee_buffer_add(&props->stylesheet, subconf->val.buf, subconf->val.len); } else { PRINT_MSG ("ERROR: Handler xslt: Unknown key: '%s'\n", subconf->key.buf); return ret_error; } }
TXsltIniter() { xmlInitMemory(); exsltRegisterAll(); }
static gboolean msp_plugin_transform (PlannerPlugin *plugin, const gchar *input_filename) { xsltStylesheet *stylesheet; xmlDoc *doc; xmlDoc *final_doc; gint fd; FILE *file; gchar *tmp_name, *uri; MrpProject *project; gchar *filename; /* libxml housekeeping */ xmlSubstituteEntitiesDefault (1); xmlLoadExtDtdDefaultValue = 1; exsltRegisterAll (); filename = mrp_paths_get_stylesheet_dir ("msp2planner.xsl"); stylesheet = xsltParseStylesheetFile (filename); g_free (filename); doc = xmlParseFile (input_filename); if (!doc) { xsltFreeStylesheet (stylesheet); return FALSE; } final_doc = xsltApplyStylesheet (stylesheet, doc, NULL); xmlFree (doc); if (!final_doc) { xsltFreeStylesheet (stylesheet); return FALSE; } filename = mrp_paths_get_dtd_dir ("mrproject-0.6.dtd"); if (!xml_validate (final_doc, filename)) { GtkWidget *dialog; xsltFreeStylesheet (stylesheet); xmlFree (final_doc); dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Couldn't import file.")); gtk_widget_show (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (filename); return FALSE; } g_free (filename); fd = g_file_open_tmp ("planner-msp-XXXXXX", &tmp_name, NULL); if (fd == -1) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); return FALSE; } file = fdopen (fd, "w"); if (file == NULL) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); close (fd); g_free (tmp_name); return FALSE; } if (xsltSaveResultToFile (file, final_doc, stylesheet) == -1) { xsltFreeStylesheet (stylesheet); xmlFree (final_doc); fclose (file); g_free (tmp_name); return FALSE; } xsltFreeStylesheet (stylesheet); xmlFree (final_doc); uri = g_filename_to_uri (tmp_name, NULL, NULL); if (uri) { planner_window_open_in_existing_or_new (plugin->main_window, uri, TRUE); project = planner_window_get_project (plugin->main_window) ; mrp_project_set_uri (project, NULL); } unlink (tmp_name); fclose (file); g_free (tmp_name); g_free (uri); return TRUE; }
void oscap_init(void) { xmlInitParser(); xsltInit(); exsltRegisterAll(); }
int main(void) { unsigned int i, repeat; unsigned int num_threads = 8; void *results[MAX_ARGC]; int ret; xmlInitParser(); /* * Register the EXSLT extensions and the test module */ exsltRegisterAll(); xsltRegisterTestModule(); /* * Register our own extension module */ registerFooModule(); /* * First pass each thread has its own version of the stylesheet * each of them will initialize and shutdown the extension */ printf("Pass 1\n"); for (repeat = 0;repeat < 500;repeat++) { memset(results, 0, sizeof(*results)*num_threads); memset(tid, 0xff, sizeof(*tid)*num_threads); for (i = 0; i < num_threads; i++) { ret = pthread_create(&tid[i], NULL, threadRoutine1, (void *) (unsigned long) i); if (ret != 0) { perror("pthread_create"); exit(1); } } for (i = 0; i < num_threads; i++) { ret = pthread_join(tid[i], &results[i]); if (ret != 0) { perror("pthread_join"); exit(1); } } } /* * Second pass all threads share the same stylesheet instance * look for transformation clashes */ printf("Pass 2\n"); for (repeat = 0;repeat < 500;repeat++) { xmlDocPtr style; xsltStylesheetPtr cur; style = xmlReadMemory(stylesheet, strlen(stylesheet), "doc.xsl", NULL, 0); if (style == NULL) { fprintf(stderr, "Main failed to parse stylesheet\n"); exit(1); } cur = xsltParseStylesheetDoc(style); if (cur == NULL) { fprintf(stderr, "Main failed to compile stylesheet\n"); exit(1); } memset(results, 0, sizeof(*results)*num_threads); memset(tid, 0xff, sizeof(*tid)*num_threads); for (i = 0; i < num_threads; i++) { ret = pthread_create(&tid[i], NULL, threadRoutine2, (void *) cur); if (ret != 0) { perror("pthread_create"); exit(1); } } for (i = 0; i < num_threads; i++) { ret = pthread_join(tid[i], &results[i]); if (ret != 0) { perror("pthread_join"); exit(1); } } xsltFreeStylesheet(cur); } xsltCleanupGlobals(); xmlCleanupParser(); xmlMemoryDump(); printf("Ok\n"); return (0); }
int main(int argc, char **argv) { int i; xsltStylesheetPtr cur = NULL; xmlDocPtr doc, style; if (argc <= 1) { usage(argv[0]); return (1); } xmlInitMemory(); LIBXML_TEST_VERSION defaultLoader = xmlGetExternalEntityLoader(); xmlLineNumbersDefault(1); if (novalid == 0) /* TODO XML_DETECT_IDS | XML_COMPLETE_ATTRS */ xmlLoadExtDtdDefaultValue = 6; else xmlLoadExtDtdDefaultValue = 0; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-")) break; if (argv[i][0] != '-') continue; #ifdef LIBXML_DEBUG_ENABLED if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) { debug++; } else #endif if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "-verbose")) || (!strcmp(argv[i], "--verbose"))) { xsltSetGenericDebugFunc(stderr, NULL); } else if ((!strcmp(argv[i], "-o")) || (!strcmp(argv[i], "-output")) || (!strcmp(argv[i], "--output"))) { i++; output = argv[i++]; } else if ((!strcmp(argv[i], "-V")) || (!strcmp(argv[i], "-version")) || (!strcmp(argv[i], "--version"))) { printf("Using libxml %s, libxslt %s and libexslt %s\n", xmlParserVersion, xsltEngineVersion, exsltLibraryVersion); printf ("xsltproc was compiled against libxml %d, libxslt %d and libexslt %d\n", LIBXML_VERSION, LIBXSLT_VERSION, LIBEXSLT_VERSION); printf("libxslt %d was compiled against libxml %d\n", xsltLibxsltVersion, xsltLibxmlVersion); printf("libexslt %d was compiled against libxml %d\n", exsltLibexsltVersion, exsltLibxmlVersion); } else if ((!strcmp(argv[i], "-repeat")) || (!strcmp(argv[i], "--repeat"))) { if (repeat == 0) repeat = 20; else repeat = 100; } else if ((!strcmp(argv[i], "-novalid")) || (!strcmp(argv[i], "--novalid"))) { novalid++; } else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) { noout++; #ifdef LIBXML_DOCB_ENABLED } else if ((!strcmp(argv[i], "-docbook")) || (!strcmp(argv[i], "--docbook"))) { docbook++; #endif #ifdef LIBXML_HTML_ENABLED } else if ((!strcmp(argv[i], "-html")) || (!strcmp(argv[i], "--html"))) { html++; #endif } else if ((!strcmp(argv[i], "-timing")) || (!strcmp(argv[i], "--timing"))) { timing++; } else if ((!strcmp(argv[i], "-profile")) || (!strcmp(argv[i], "--profile"))) { profile++; } else if ((!strcmp(argv[i], "-norman")) || (!strcmp(argv[i], "--norman"))) { profile++; } else if ((!strcmp(argv[i], "-warnnet")) || (!strcmp(argv[i], "--warnnet"))) { xmlSetExternalEntityLoader(xsltNoNetExternalEntityLoader); } else if ((!strcmp(argv[i], "-nonet")) || (!strcmp(argv[i], "--nonet"))) { xmlSetExternalEntityLoader(xsltNoNetExternalEntityLoader); nonet = 1; #ifdef LIBXML_CATALOG_ENABLED } else if ((!strcmp(argv[i], "-catalogs")) || (!strcmp(argv[i], "--catalogs"))) { const char *catalogs; catalogs = getenv("SGML_CATALOG_FILES"); if (catalogs == NULL) { fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n"); } else { xmlLoadCatalogs(catalogs); } #endif #ifdef LIBXML_XINCLUDE_ENABLED } else if ((!strcmp(argv[i], "-xinclude")) || (!strcmp(argv[i], "--xinclude"))) { xinclude++; xsltSetXIncludeDefault(1); #endif } else if ((!strcmp(argv[i], "-param")) || (!strcmp(argv[i], "--param"))) { i++; params[nbparams++] = argv[i++]; params[nbparams++] = argv[i]; if (nbparams >= 16) { fprintf(stderr, "too many params\n"); return (1); } } else if ((!strcmp(argv[i], "-maxdepth")) || (!strcmp(argv[i], "--maxdepth"))) { int value; i++; if (sscanf(argv[i], "%d", &value) == 1) { if (value > 0) xsltMaxDepth = value; } } else if (!strcmp(argv[i], "--r")) { startRAutomatically = 1; RstartupScript = strchr(argv[i],'='); continue; } else { fprintf(stderr, "Unknown option %s\n", argv[i]); usage(argv[0]); return (1); } } params[nbparams] = NULL; /* * Replace entities with their content. */ xmlSubstituteEntitiesDefault(1); /* * Register the EXSLT extensions */ exsltRegisterAll(); registerRModule(0); if(startRAutomatically) { extern int RXSLT_internalSource(const char *fileName); int rargs = 1; const char *rargv[] = { "Sxsltproc" }; Rf_initEmbeddedR(rargs, rargv); loadXSLPackage(); if(RstartupScript && RstartupScript[0]) RXSLT_internalSource(RstartupScript); } for (i = 1; i < argc; i++) { if ((!strcmp(argv[i], "-maxdepth")) || (!strcmp(argv[i], "--maxdepth"))) { i++; continue; } else if ((!strcmp(argv[i], "-o")) || (!strcmp(argv[i], "-output")) || (!strcmp(argv[i], "--output"))) { i++; continue; } if ((!strcmp(argv[i], "-param")) || (!strcmp(argv[i], "--param"))) { i += 2; continue; } else if(!strcmp(argv[i], "--r")) { continue; } if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { if (timing) gettimeofday(&begin, NULL); style = xmlParseFile((const char *) argv[i]); if (timing) { long msec; gettimeofday(&end, NULL); msec = end.tv_sec - begin.tv_sec; msec *= 1000; msec += (end.tv_usec - begin.tv_usec) / 1000; fprintf(stderr, "Parsing stylesheet %s took %ld ms\n", argv[i], msec); } if (style == NULL) { fprintf(stderr, "cannot parse %s\n", argv[i]); cur = NULL; } else { cur = xsltLoadStylesheetPI(style); if (cur != NULL) { /* it is an embedded stylesheet */ xsltProcess(style, cur, argv[i]); xsltFreeStylesheet(cur); exit(0); } cur = xsltParseStylesheetDoc(style); if (cur != NULL) { if (cur->indent == 1) xmlIndentTreeOutput = 1; else xmlIndentTreeOutput = 0; i++; } } break; } } /* * disable CDATA from being built in the document tree */ xmlDefaultSAXHandlerInit(); xmlDefaultSAXHandler.cdataBlock = NULL; if ((cur != NULL) && (cur->errors == 0)) { for (; i < argc; i++) { doc = NULL; if (timing) gettimeofday(&begin, NULL); #ifdef LIBXML_HTML_ENABLED if (html) doc = htmlParseFile(argv[i], NULL); else #endif #ifdef LIBXML_DOCB_ENABLED if (docbook) doc = docbParseFile(argv[i], NULL); else #endif doc = xmlParseFile(argv[i]); if (doc == NULL) { fprintf(stderr, "unable to parse %s\n", argv[i]); continue; } if (timing) { long msec; gettimeofday(&end, NULL); msec = end.tv_sec - begin.tv_sec; msec *= 1000; msec += (end.tv_usec - begin.tv_usec) / 1000; fprintf(stderr, "Parsing document %s took %ld ms\n", argv[i], msec); } xsltProcess(doc, cur, argv[i]); } xsltFreeStylesheet(cur); } #ifdef CAN_UNREGISTER_MODULES xsltUnregisterAllExtModules(); #endif xmlCleanupParser(); xmlMemoryDump(); return (0); }