ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

imports.c
Go to the documentation of this file.
00001 /*
00002  * imports.c: Implementation of the XSLT imports
00003  *
00004  * Reference:
00005  *   http://www.w3.org/TR/1999/REC-xslt-19991116
00006  *
00007  * See Copyright for the status of this software.
00008  *
00009  * daniel@veillard.com
00010  */
00011 
00012 #define IN_LIBXSLT
00013 #include "libxslt.h"
00014 
00015 #include <string.h>
00016 
00017 #ifdef HAVE_SYS_TYPES_H
00018 #include <sys/types.h>
00019 #endif
00020 #ifdef HAVE_MATH_H
00021 #include <math.h>
00022 #endif
00023 #ifdef HAVE_FLOAT_H
00024 #include <float.h>
00025 #endif
00026 #ifdef HAVE_IEEEFP_H
00027 #include <ieeefp.h>
00028 #endif
00029 #ifdef HAVE_NAN_H
00030 #include <nan.h>
00031 #endif
00032 #ifdef HAVE_CTYPE_H
00033 #include <ctype.h>
00034 #endif
00035 
00036 #include <libxml/xmlmemory.h>
00037 #include <libxml/tree.h>
00038 #include <libxml/hash.h>
00039 #include <libxml/xmlerror.h>
00040 #include <libxml/uri.h>
00041 #include "xslt.h"
00042 #include "xsltInternals.h"
00043 #include "xsltutils.h"
00044 #include "preproc.h"
00045 #include "imports.h"
00046 #include "documents.h"
00047 #include "security.h"
00048 #include "pattern.h"
00049 
00050 
00051 /************************************************************************
00052  *                                  *
00053  *          Module interfaces               *
00054  *                                  *
00055  ************************************************************************/
00065 static void xsltFixImportedCompSteps(xsltStylesheetPtr master, 
00066             xsltStylesheetPtr style) {
00067     xsltStylesheetPtr res;
00068     xmlHashScan(style->templatesHash,
00069                 (xmlHashScanner) xsltNormalizeCompSteps, master);
00070     master->extrasNr += style->extrasNr;
00071     for (res = style->imports; res != NULL; res = res->next) {
00072         xsltFixImportedCompSteps(master, res);
00073     }
00074 }
00075 
00086 int
00087 xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
00088     int ret = -1;
00089     xmlDocPtr import = NULL;
00090     xmlChar *base = NULL;
00091     xmlChar *uriRef = NULL;
00092     xmlChar *URI = NULL;
00093     xsltStylesheetPtr res;
00094     xsltSecurityPrefsPtr sec;
00095 
00096     if ((cur == NULL) || (style == NULL))
00097     return (ret);
00098 
00099     uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
00100     if (uriRef == NULL) {
00101     xsltTransformError(NULL, style, cur,
00102         "xsl:import : missing href attribute\n");
00103     goto error;
00104     }
00105 
00106     base = xmlNodeGetBase(style->doc, cur);
00107     URI = xmlBuildURI(uriRef, base);
00108     if (URI == NULL) {
00109     xsltTransformError(NULL, style, cur,
00110         "xsl:import : invalid URI reference %s\n", uriRef);
00111     goto error;
00112     }
00113 
00114     res = style;
00115     while (res != NULL) {
00116         if (res->doc == NULL)
00117         break;
00118     if (xmlStrEqual(res->doc->URL, URI)) {
00119         xsltTransformError(NULL, style, cur,
00120            "xsl:import : recursion detected on imported URL %s\n", URI);
00121         goto error;
00122     }
00123     res = res->parent;
00124     }
00125 
00126     /*
00127      * Security framework check
00128      */
00129     sec = xsltGetDefaultSecurityPrefs();
00130     if (sec != NULL) {
00131     int secres;
00132 
00133     secres = xsltCheckRead(sec, NULL, URI);
00134     if (secres == 0) {
00135         xsltTransformError(NULL, NULL, NULL,
00136          "xsl:import: read rights for %s denied\n",
00137                  URI);
00138         goto error;
00139     }
00140     }
00141 
00142     import = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS,
00143                                   (void *) style, XSLT_LOAD_STYLESHEET);
00144     if (import == NULL) {
00145     xsltTransformError(NULL, style, cur,
00146         "xsl:import : unable to load %s\n", URI);
00147     goto error;
00148     }
00149 
00150     res = xsltParseStylesheetImportedDoc(import, style);
00151     if (res != NULL) {
00152     res->next = style->imports;
00153     style->imports = res;
00154     if (style->parent == NULL) {
00155         xsltFixImportedCompSteps(style, res);
00156     }
00157     ret = 0;
00158     } else {
00159     xmlFreeDoc(import);
00160     }
00161 
00162 error:
00163     if (uriRef != NULL)
00164     xmlFree(uriRef);
00165     if (base != NULL)
00166     xmlFree(base);
00167     if (URI != NULL)
00168     xmlFree(URI);
00169 
00170     return (ret);
00171 }
00172 
00183 int
00184 xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur) {
00185     int ret = -1;
00186     xmlDocPtr oldDoc;
00187     xmlChar *base = NULL;
00188     xmlChar *uriRef = NULL;
00189     xmlChar *URI = NULL;
00190     xsltStylesheetPtr result;
00191     xsltDocumentPtr include;
00192     xsltDocumentPtr docptr;
00193     int oldNopreproc;
00194 
00195     if ((cur == NULL) || (style == NULL))
00196     return (ret);
00197 
00198     uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
00199     if (uriRef == NULL) {
00200     xsltTransformError(NULL, style, cur,
00201         "xsl:include : missing href attribute\n");
00202     goto error;
00203     }
00204 
00205     base = xmlNodeGetBase(style->doc, cur);
00206     URI = xmlBuildURI(uriRef, base);
00207     if (URI == NULL) {
00208     xsltTransformError(NULL, style, cur,
00209         "xsl:include : invalid URI reference %s\n", uriRef);
00210     goto error;
00211     }
00212 
00213     /*
00214      * in order to detect recursion, we check all previously included
00215      * stylesheets.
00216      */
00217     docptr = style->includes;
00218     while (docptr != NULL) {
00219         if (xmlStrEqual(docptr->doc->URL, URI)) {
00220         xsltTransformError(NULL, style, cur,
00221             "xsl:include : recursion detected on included URL %s\n", URI);
00222         goto error;
00223     }
00224     docptr = docptr->includes;
00225     }
00226 
00227     include = xsltLoadStyleDocument(style, URI);
00228     if (include == NULL) {
00229     xsltTransformError(NULL, style, cur,
00230         "xsl:include : unable to load %s\n", URI);
00231     goto error;
00232     }
00233 #ifdef XSLT_REFACTORED    
00234     if (IS_XSLT_ELEM_FAST(cur) && (cur->psvi != NULL)) {
00235     ((xsltStyleItemIncludePtr) cur->psvi)->include = include;
00236     } else {
00237     xsltTransformError(NULL, style, cur,
00238         "Internal error: (xsltParseStylesheetInclude) "
00239         "The xsl:include element was not compiled.\n", URI);
00240     style->errors++;
00241     }
00242 #endif
00243     oldDoc = style->doc;
00244     style->doc = include->doc;
00245     /* chain to stylesheet for recursion checking */
00246     include->includes = style->includes;
00247     style->includes = include;
00248     oldNopreproc = style->nopreproc;
00249     style->nopreproc = include->preproc;
00250     /*
00251     * TODO: This will change some values of the
00252     *  including stylesheet with every included module
00253     *  (e.g. excluded-result-prefixes)
00254     *  We need to strictly seperate such stylesheet-owned values.
00255     */
00256     result = xsltParseStylesheetProcess(style, include->doc);
00257     style->nopreproc = oldNopreproc;
00258     include->preproc = 1;
00259     style->includes = include->includes;
00260     style->doc = oldDoc;
00261     if (result == NULL) {
00262     ret = -1;
00263     goto error;
00264     }
00265     ret = 0;
00266 
00267 error:
00268     if (uriRef != NULL)
00269     xmlFree(uriRef);
00270     if (base != NULL)
00271     xmlFree(base);
00272     if (URI != NULL)
00273     xmlFree(URI);
00274 
00275     return (ret);
00276 }
00277 
00287 xsltStylesheetPtr
00288 xsltNextImport(xsltStylesheetPtr cur) {
00289     if (cur == NULL)
00290     return(NULL);
00291     if (cur->imports != NULL)
00292     return(cur->imports);
00293     if (cur->next != NULL)
00294     return(cur->next) ;
00295     do {
00296     cur = cur->parent;
00297     if (cur == NULL) break;
00298     if (cur->next != NULL) return(cur->next);
00299     } while (cur != NULL);
00300     return(cur);
00301 }
00302 
00312 int
00313 xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt) {
00314     xsltStylesheetPtr style;
00315 
00316     if (ctxt == NULL)
00317     return(0);
00318     style = ctxt->style;
00319     while (style != NULL) {
00320     if (style->stripSpaces != NULL)
00321         return(1);
00322     style = xsltNextImport(style);
00323     }
00324     return(0);
00325 }
00326 
00339 int
00340 xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node) {
00341     xsltStylesheetPtr style;
00342     const xmlChar *val;
00343 
00344     if ((ctxt == NULL) || (node == NULL))
00345     return(0);
00346     style = ctxt->style;
00347     while (style != NULL) {
00348     if (node->ns != NULL) {
00349         val = (const xmlChar *)
00350           xmlHashLookup2(style->stripSpaces, node->name, node->ns->href);
00351             if (val == NULL) {
00352                 val = (const xmlChar *)
00353                     xmlHashLookup2(style->stripSpaces, BAD_CAST "*",
00354                                    node->ns->href);
00355             }
00356     } else {
00357         val = (const xmlChar *)
00358           xmlHashLookup2(style->stripSpaces, node->name, NULL);
00359     }
00360     if (val != NULL) {
00361         if (xmlStrEqual(val, (xmlChar *) "strip"))
00362         return(1);
00363         if (xmlStrEqual(val, (xmlChar *) "preserve"))
00364         return(0);
00365     }
00366     if (style->stripAll == 1)
00367         return(1);
00368     if (style->stripAll == -1)
00369         return(0);
00370 
00371     style = xsltNextImport(style);
00372     }
00373     return(0);
00374 }
00375 
00393 xsltTemplatePtr
00394 xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name,
00395              const xmlChar *nameURI) {
00396     xsltTemplatePtr cur;
00397     xsltStylesheetPtr style;
00398 
00399     if ((ctxt == NULL) || (name == NULL))
00400     return(NULL);
00401     style = ctxt->style;
00402     while (style != NULL) {
00403     cur = style->templates;
00404     while (cur != NULL) {
00405         if (xmlStrEqual(name, cur->name)) {
00406         if (((nameURI == NULL) && (cur->nameURI == NULL)) ||
00407             ((nameURI != NULL) && (cur->nameURI != NULL) &&
00408              (xmlStrEqual(nameURI, cur->nameURI)))) {
00409             return(cur);
00410         }
00411         }
00412         cur = cur->next;
00413     }
00414 
00415     style = xsltNextImport(style);
00416     }
00417     return(NULL);
00418 }
00419 

Generated on Sun May 27 2012 04:19:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.