/* 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; } }
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); }