Beispiel #1
0
PyObject *keysmngr_KeyStoreIdCreate(PyObject *self, PyObject *args) {
  PyObject *initialize_obj, *finalize_obj, *findKey_obj;
  xmlSecSize klassSize;
  xmlSecSize objSize;
  const xmlChar *name;    
  struct _xmlSecKeyStoreKlass *storeId;

  if (CheckArgs(args, "IISccc:keyStoreIdCreate")) {
    if(!PyArg_ParseTuple(args, (char *) "iisOOO:keyStoreIdCreate", &klassSize,
			 &objSize, &name, &initialize_obj, &finalize_obj,
			 &findKey_obj))
      return NULL;
  }
  else return NULL;
  
  if (KeyStoreInitializeMethods == NULL && initialize_obj != Py_None)
    KeyStoreInitializeMethods = xmlHashCreate(HASH_TABLE_SIZE);
  if (KeyStoreFinalizeMethods == NULL && finalize_obj != Py_None)
    KeyStoreFinalizeMethods = xmlHashCreate(HASH_TABLE_SIZE);
  if (KeyStoreFindKeyMethods == NULL && findKey_obj != Py_None)
    KeyStoreFindKeyMethods = xmlHashCreate(HASH_TABLE_SIZE);

  if (initialize_obj != Py_None)
    xmlHashAddEntry(KeyStoreInitializeMethods, name, initialize_obj);
  if (finalize_obj != Py_None)
    xmlHashAddEntry(KeyStoreFinalizeMethods,   name, finalize_obj);
  if (findKey_obj != Py_None)
    xmlHashAddEntry(KeyStoreFindKeyMethods,    name, findKey_obj);

  storeId = xmlMalloc(sizeof(xmlSecKeyStoreKlass));

  /* FIXME
    storeId->klassSize = klassSize;
    storeId->objSize = objSize;
  */
  storeId->klassSize = sizeof(xmlSecKeyStoreKlass);
  storeId->objSize = sizeof(xmlSecKeyStore);

  storeId->name = (xmlChar *)strdup((const char *)name);
  if (initialize_obj != Py_None)
    storeId->initialize = (xmlSecKeyStoreInitializeMethod)xmlsec_KeyStoreInitializeMethod;
  else
    storeId->initialize = NULL;
  if (finalize_obj != Py_None)
    storeId->finalize = (xmlSecKeyStoreFinalizeMethod)xmlsec_KeyStoreFinalizeMethod;
  else
    storeId->finalize = NULL;
  if (findKey_obj != Py_None)
    storeId->findKey = (xmlSecKeyStoreFindKeyMethod)xmlsec_KeyStoreFindKeyMethod;
  else
    storeId->findKey = NULL;

  Py_XINCREF(initialize_obj);
  Py_XINCREF(finalize_obj);
  Py_XINCREF(findKey_obj);

  return (wrap_xmlSecKeyStoreId(storeId));
}
Beispiel #2
0
PyObject *xmlsec_PtrListIdCreate(PyObject *self, PyObject *args) {
  PyObject *duplicateItem_obj, *destroyItem_obj;
  PyObject *debugDumpItem_obj, *debugXmlDumpItem_obj;
  const xmlChar *name;
  struct _xmlSecPtrListKlass *listId;

  if (CheckArgs(args, "Scccc:ptrListIdCreate")) {
    if(!PyArg_ParseTuple(args, (char *) "sOOOO:ptrListIdCreate", &name,
			 &duplicateItem_obj, &destroyItem_obj,
			 &debugDumpItem_obj, &debugXmlDumpItem_obj))
      return NULL;
  }
  else return NULL;
  
  if (PtrDuplicateItemMethods == NULL && duplicateItem_obj != Py_None)
    PtrDuplicateItemMethods = xmlHashCreate(HASH_TABLE_SIZE);
  if (PtrDestroyItemMethods == NULL && destroyItem_obj != Py_None)
    PtrDestroyItemMethods = xmlHashCreate(HASH_TABLE_SIZE);
  if (PtrDebugDumpItemMethods == NULL && debugDumpItem_obj != Py_None)
    PtrDebugDumpItemMethods = xmlHashCreate(HASH_TABLE_SIZE);
  if (PtrDebugXmlDumpItemMethods == NULL && debugXmlDumpItem_obj != Py_None)
    PtrDebugXmlDumpItemMethods = xmlHashCreate(HASH_TABLE_SIZE);

  if (duplicateItem_obj != Py_None)
    xmlHashAddEntry(PtrDuplicateItemMethods, name, duplicateItem_obj);
  if (destroyItem_obj != Py_None)
    xmlHashAddEntry(PtrDestroyItemMethods,   name, destroyItem_obj);
  if (debugDumpItem_obj != Py_None)
    xmlHashAddEntry(PtrDebugDumpItemMethods, name, debugDumpItem_obj);
  if (debugXmlDumpItem_obj != Py_None)
    xmlHashAddEntry(PtrDebugXmlDumpItemMethods, name, debugXmlDumpItem_obj);

  listId = xmlMalloc(sizeof(xmlSecPtrListKlass));
  listId->name = name;
  if (duplicateItem_obj != Py_None)
    listId->duplicateItem = xmlsec_PtrDuplicateItemMethod;
  else
    listId->duplicateItem = NULL;
  if (destroyItem_obj != Py_None)
    listId->destroyItem = xmlsec_PtrDestroyItemMethod;
  else
    listId->destroyItem = NULL;
  if (debugDumpItem_obj != Py_None)
    listId->debugDumpItem = xmlsec_PtrDebugDumpItemMethod;
  else
    listId->debugDumpItem = NULL;
  if (debugXmlDumpItem_obj != Py_None)
    listId->debugXmlDumpItem = xmlsec_PtrDebugXmlDumpItemMethod;
  else
    listId->debugXmlDumpItem = NULL;

  Py_XINCREF(duplicateItem_obj);
  Py_XINCREF(destroyItem_obj);
  Py_XINCREF(debugDumpItem_obj);
  Py_XINCREF(debugXmlDumpItem_obj);

  return (wrap_xmlSecPtrListId(listId));
}
Beispiel #3
0
/* }}} */
ContactList *cl_new(Account *ac, const char *ticket)/*{{{*/
{
	CL *cl;
	cl = (CL*)xmalloc(sizeof(CL));
	memset(cl, 0, sizeof(CL));
	cl->account = ac;
	cl->ticket = (char*)xmalloc(strlen(ticket)+1);
	strcpy(cl->ticket, ticket);
	cl->table = xmlHashCreate(30);
	cl->emailtable = xmlHashCreate(250);

	return cl;
}/*}}}*/
Beispiel #4
0
xmlHashTablePtr 
hash_icons_yrno_table_create(){
    xmlHashTablePtr hash;
    hash = xmlHashCreate(6);
#include "hash_icons.data"
    return hash;
}
Beispiel #5
0
PyObject *xmlSecKeysMngr_setattr(PyObject *self, PyObject *args) {
  PyObject *mngr_obj, *value_obj;
  xmlSecKeysMngrPtr mngr;
  const char *name;

  if (CheckArgs(args, "OS?:keysMngrSetAttr")) {
    if (!PyArg_ParseTuple(args, "OsO:keysMngrSetAttr",
			  &mngr_obj, &name, &value_obj))
      return NULL;
  }
  else return NULL;

  mngr = xmlSecKeysMngrPtr_get(mngr_obj);
    
  if (!strcmp(name, "keysStore"))
    mngr->keysStore = xmlSecKeyStorePtr_get(value_obj);
  else if (!strcmp(name, "storesList"))
    mngr->storesList = *(xmlSecPtrListPtr_get(value_obj));
  else if (!strcmp(name, "getKey")) {
    if (value_obj != Py_None) {
      if (GetKeyCallbacks == NULL)
	GetKeyCallbacks = xmlHashCreate(HASH_TABLE_SIZE);
      xmlHashAddEntry(GetKeyCallbacks,
		      mngr->keysStore->id->name, value_obj);
      Py_XINCREF(value_obj);
      mngr->getKey = xmlsec_GetKeyCallback;
    }
    else
      mngr->getKey = NULL;
  }

  Py_INCREF(Py_None);
  return (Py_None);
}
PyObject *xmlsec_NodeSetWalk(PyObject *self, PyObject *args) {
  PyObject *nset_obj, *walkFunc_obj, *data_obj;
  xmlSecNodeSetPtr nset;
  int ret;

  if (CheckArgs(args, "OC?:nodeSetWalk")) {
    if (!PyArg_ParseTuple(args, "OOO:nodeSetWalk", &nset_obj, &walkFunc_obj,
			  &data_obj))
      return NULL;
  }
  else return NULL;

  nset = xmlSecNodeSetPtr_get(nset_obj);

  if (NodeSetWalkCallbacks == NULL && walkFunc_obj != Py_None)
    NodeSetWalkCallbacks = xmlHashCreate(HASH_TABLE_SIZE);
  if (walkFunc_obj != Py_None)
    xmlHashAddEntry2(NodeSetWalkCallbacks, (const xmlChar *)nset->doc->name,
		     nset->doc->URL, walkFunc_obj);

  Py_XINCREF(walkFunc_obj);
  ret = xmlSecNodeSetWalk(nset, xmlsec_NodeSetWalkCallback,
			  PyCObject_AsVoidPtr(data_obj));

  return (wrap_int(ret));
}
Beispiel #7
0
xmlHashTablePtr
hash_description_yrno_table_create(){
    xmlHashTablePtr hash;
    hash = xmlHashCreate(6);
#include "hash_description.data"
    return hash;
}
Beispiel #8
0
static void
dlinit(void)

{
    int locked;

    /**
    ***     Initialize the package.
    ***     Should be call once per process.
    **/

    locked = !pthread_mutex_lock(&dlmutex);

    if (!(dlflags & INITED)) {
        dlflags &= ~THREADS;

        if (locked)
            dlflags |= THREADS;

        Qp0zInitEnv();
        dldir = xmlHashCreate(16);
        dlflags &= ~MULTIBUF;

        if (dlflags & THREADS)
            if (!pthread_key_create(&dlkey, dlthreadterm))
                dlflags |= MULTIBUF;

        atexit(dlterm);
        dlflags |= INITED;
    }

    if (locked)
        pthread_mutex_unlock(&dlmutex);
}
Beispiel #9
0
/**
 * xmlHashCopy:
 * @table: the hash table
 * @f:  the copier function for items in the hash
 *
 * Scan the hash @table and applied @f to each value.
 *
 * Returns the new table or NULL in case of error.
 */
xmlHashTablePtr
xmlHashCopy(xmlHashTablePtr table, xmlHashCopier f) {
    int i;
    xmlHashEntryPtr iter;
    xmlHashEntryPtr next;
    xmlHashTablePtr ret;

    if (table == NULL)
	return(NULL);
    if (f == NULL)
	return(NULL);

    ret = xmlHashCreate(table->size);
    if (table->table) {
	for(i = 0; i < table->size; i++) {
	    iter = table->table[i];
	    while (iter) {
		next = iter->next;
		xmlHashAddEntry3(ret, iter->name, iter->name2,
			         iter->name3, f(iter->payload, iter->name));
		iter = next;
	    }
	}
    }
    ret->nbElems = table->nbElems;
    return(ret);
}
Beispiel #10
0
bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding)
{
    RefPtr<Document> ownerDocument = sourceNode->document();

    setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->docLoader());
    xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get());
    if (!sheet) {
        setXSLTLoadCallBack(0, 0, 0);
        return false;
    }
    m_stylesheet->clearDocuments();

    xmlChar* origMethod = sheet->method;
    if (!origMethod && mimeType == "text/html")
        sheet->method = (xmlChar*)"html";

    bool success = false;
    bool shouldFreeSourceDoc = false;
    if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) {
        // The XML declaration would prevent parsing the result as a fragment, and it's not needed even for documents,
        // as the result of this function is always immediately parsed.
        sheet->omitXmlDeclaration = true;

        xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
        registerXSLTExtensions(transformContext);

        // <http://bugs.webkit.org/show_bug.cgi?id=16077>: XSLT processor <xsl:sort> algorithm only compares by code point.
        xsltSetCtxtSortFunc(transformContext, xsltUnicodeSortFunction);

        // This is a workaround for a bug in libxslt.
        // The bug has been fixed in version 1.1.13, so once we ship that this can be removed.
        if (!transformContext->globalVars)
           transformContext->globalVars = xmlHashCreate(20);

        const char** params = xsltParamArrayFromParameterMap(m_parameters);
        xsltQuoteUserParams(transformContext, params);
        xmlDocPtr resultDoc = xsltApplyStylesheetUser(sheet, sourceDoc, 0, 0, 0, transformContext);

        xsltFreeTransformContext(transformContext);
        freeXsltParamArray(params);

        if (shouldFreeSourceDoc)
            xmlFreeDoc(sourceDoc);

        if ((success = saveResultToString(resultDoc, sheet, resultString))) {
            mimeType = resultMIMEType(resultDoc, sheet);
            resultEncoding = (char*)resultDoc->encoding;
        }
        xmlFreeDoc(resultDoc);
    }

    sheet->method = origMethod;
    setXSLTLoadCallBack(0, 0, 0);
    xsltFreeStylesheet(sheet);
    m_stylesheet = 0;

    return success;
}
Beispiel #11
0
/**
 * lineNoItemNew:
 * 
 * Returns a new hash table for break points
 */
xmlHashTablePtr
lineNoItemNew(void)
{
    xmlHashTablePtr hash;

    hash = xmlHashCreate(4);

    return hash;
}
Beispiel #12
0
static VXdoc& _transform(Request& r, const String* stylesheet_source, 
						   VXdoc& vdoc, xsltStylesheetPtr stylesheet, const xmlChar** transform_params) 
{
	xmlDoc& xmldoc=vdoc.get_xmldoc();

	xsltTransformContext_auto_ptr transformContext(
		xsltNewTransformContext(stylesheet, &xmldoc));
	// make params literal
	if (transformContext->globalVars == NULL) // strangly not initialized by xsltNewTransformContext
		transformContext->globalVars = xmlHashCreate(20);
	xsltQuoteUserParams(transformContext.get(), (const char**)transform_params);
	// do transform
	xmlDoc *transformed=xsltApplyStylesheetUser(
		stylesheet,
		&xmldoc,
		0/*already quoted-inserted  transform_params*/,
		0/*const char* output*/,
		0/*FILE *profile*/,
		transformContext.get());
	if(!transformed || xmlHaveGenericErrors())
		throw XmlException(stylesheet_source, r);

	//gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE  type, fixing
	transformed->type=XML_DOCUMENT_NODE;
	// constructing result
	VXdoc& result=*new VXdoc(r.charsets, *transformed);
	/* grabbing options

		<xsl:output
		!method = "xml" | "html" | "text"
			X| qname-but-not-ncname 
		!version = nmtoken 
		!encoding = string 
		!omit-xml-declaration = "yes" | "no"
		!standalone = "yes" | "no"
		!doctype-public = string 
		!doctype-system = string 
		Xcdata-section-elements = qnames 
		!indent = "yes" | "no"
		!media-type = string /> 
	*/
	XDocOutputOptions& oo=result.output_options;

	oo.method=stylesheet->method?&r.transcode(stylesheet->method):0;
	oo.encoding=stylesheet->encoding?&r.transcode(stylesheet->encoding):0;
	oo.mediaType=stylesheet->mediaType?&r.transcode(stylesheet->mediaType):0;
	oo.indent=stylesheet->indent;
	oo.version=stylesheet->version?&r.transcode(stylesheet->version):0;
	oo.standalone=stylesheet->standalone;
	oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration;

	// return
	return result;
}
Beispiel #13
0
/***********************************
 * Function Name: InitXmlModHashTable
 * Desription	: This functions Initializes the HashTable for Modset
 * Input	: None
 * Output	: xmlHashTableptr
 * Return Value	: None
 ***************************************/
t_int32
InitXmlModHashTable (t_void)
{
  hTable = xmlHashCreate (MAX_HASH_SIZE);
  if (hTable == NULL)
  {
    XML_Debug ("A xml Modset Table is not created");
    return -1;
  }
  return 0;
}
Beispiel #14
0
/**********************************************************************
 * Function Name: PSPInitXmlModsetTable
 * Desription	: This functions Initializes the HashTable for Modset
 * Input	: None
 * Output	: xmlHashTableptr
 * Return Value	: None
 ***********************************************************************/
t_int32
PSPInitXmlModsetTable (t_void)
{
  pModSetTable = xmlHashCreate (MAX_HASH_SIZE);
  if (pModSetTable == NULL)
  {
    XML_Error ("xml Modset Table is not created");
    return CNTRLXML_FAILURE;
  }
  /*    XMLMain_RegisterAll(); *//*This will be called from xmlhtphdlr.c. */
  return CNTRLXML_SUCCESS;
}
Beispiel #15
0
HRESULT SchemaCache_create(IUnknown* pUnkOuter, void** ppObj)
{
    schema_cache* This = heap_alloc(sizeof(schema_cache));
    if (!This)
        return E_OUTOFMEMORY;

    This->lpVtbl = &schema_cache_vtbl;
    This->cache = xmlHashCreate(DEFAULT_HASHTABLE_SIZE);
    This->ref = 1;

    *ppObj = &This->lpVtbl;
    return S_OK;
}
Beispiel #16
0
PyObject *xmlSecTransformCtx_setattr(PyObject *self, PyObject *args) {
  PyObject *transformCtx_obj, *value_obj;
  xmlSecTransformCtxPtr transformCtx;
  const char *name;

  if (CheckArgs(args, "OS?:transformCtxSetAttr")) {
    if (!PyArg_ParseTuple(args, "OsO:transformCtxSetAttr",
			  &transformCtx_obj, &name, &value_obj))
      return NULL;
  }
  else return NULL;

  transformCtx = xmlSecTransformCtxPtr_get(transformCtx_obj);
    
  if (!strcmp(name, "flags"))
    transformCtx->flags = PyInt_AsLong(value_obj);
  else if (!strcmp(name, "flags2"))
    transformCtx->flags2 = PyInt_AsLong(value_obj);
  else if (!strcmp(name, "enabledUris"))
    transformCtx->enabledUris = PyInt_AsLong(value_obj);
  else if (!strcmp(name, "enabledTransforms"))
    transformCtx->enabledTransforms = *(xmlSecPtrListPtr_get(value_obj));
  else if (!strcmp(name, "preExecCallback"))
    if (value_obj != Py_None) {
      if (TransformCtxPreExecuteCallbacks == NULL)
	TransformCtxPreExecuteCallbacks = xmlHashCreate(HASH_TABLE_SIZE);
      xmlHashAddEntry2(TransformCtxPreExecuteCallbacks,
		       transformCtx->uri, transformCtx->xptrExpr, value_obj);
      Py_XINCREF(value_obj);
      transformCtx->preExecCallback = xmlsec_TransformCtxPreExecuteCallback;
    }
    else
      transformCtx->preExecCallback = NULL;
  else if (!strcmp(name, "result"))
    transformCtx->result = xmlSecBufferPtr_get(value_obj);
  else if (!strcmp(name, "status"))
    transformCtx->status = PyInt_AsLong(value_obj);
  else if (!strcmp(name, "uri"))
    transformCtx->uri = (xmlChar *)PyString_AsString(value_obj);
  else if (!strcmp(name, "xptrExpr"))
    transformCtx->xptrExpr = (xmlChar *)PyString_AsString(value_obj);
  else if (!strcmp(name, "first"))
    transformCtx->first = xmlSecTransformPtr_get(value_obj);
  else if (!strcmp(name, "last"))
    transformCtx->last = xmlSecTransformPtr_get(value_obj);

  Py_INCREF(Py_None);
  return (Py_None);
}
Beispiel #17
0
/**
 * xsltNewKeyTable:
 * @name:  the key name or NULL
 * @nameURI:  the name URI or NULL
 *
 * Create a new XSLT KeyTable
 *
 * Returns the newly allocated xsltKeyTablePtr or NULL in case of error
 */
static xsltKeyTablePtr
xsltNewKeyTable(const xmlChar *name, const xmlChar *nameURI) {
    xsltKeyTablePtr cur;

    cur = (xsltKeyTablePtr) xmlMalloc(sizeof(xsltKeyTable));
    if (cur == NULL) {
	xsltTransformError(NULL, NULL, NULL,
		"xsltNewKeyTable : malloc failed\n");
	return(NULL);
    }
    memset(cur, 0, sizeof(xsltKeyTable));
    if (name != NULL)
	cur->name = xmlStrdup(name);
    if (nameURI != NULL)
	cur->nameURI = xmlStrdup(nameURI);
    cur->keys = xmlHashCreate(0);
    return(cur);
}
Beispiel #18
0
/**
 * xsltResolveStylesheetAttributeSet:
 * @style:  the XSLT stylesheet
 *
 * resolve the references between attribute sets.
 */
void
xsltResolveStylesheetAttributeSet(xsltStylesheetPtr style) {
    xsltStylesheetPtr cur;

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
    xsltGenericDebug(xsltGenericDebugContext,
                     "Resolving attribute sets references\n");
#endif
    /*
     * First aggregate all the attribute sets definitions from the imports
     */
    cur = xsltNextImport(style);
    while (cur != NULL) {
        if (cur->attributeSets != NULL) {
            if (style->attributeSets == NULL) {
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
                xsltGenericDebug(xsltGenericDebugContext,
                                 "creating attribute set table\n");
#endif
                style->attributeSets = xmlHashCreate(10);
            }
            xmlHashScanFull(cur->attributeSets,
                            (xmlHashScannerFull) xsltMergeSASCallback, style);
            /*
             * the attribute lists have either been migrated to style
             * or freed directly in xsltMergeSASCallback()
             */
            xmlHashFree(cur->attributeSets, NULL);
            cur->attributeSets = NULL;
        }
        cur = xsltNextImport(cur);
    }

    /*
     * Then resolve all the references and computes the resulting sets
     */
    if (style->attributeSets != NULL) {
        xmlHashScanFull(style->attributeSets,
                        (xmlHashScannerFull) xsltResolveSASCallback, style);
    }
}
Beispiel #19
0
HRESULT SchemaCache_create(MSXML_VERSION version, void** obj)
{
    schema_cache* This = heap_alloc(sizeof(schema_cache));
    if (!This)
        return E_OUTOFMEMORY;

    TRACE("(%d %p)\n", version, obj);

    This->IXMLDOMSchemaCollection2_iface.lpVtbl = &XMLDOMSchemaCollection2Vtbl;
    This->cache = xmlHashCreate(DEFAULT_HASHTABLE_SIZE);
    This->allocated = 10;
    This->count = 0;
    This->uris = heap_alloc(This->allocated*sizeof(xmlChar*));
    This->ref = 1;
    This->version = version;
    This->validateOnLoad = VARIANT_TRUE;
    This->read_only = 0;
    init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMSchemaCollection2_iface, &schemacache_dispex);

    *obj = &This->IXMLDOMSchemaCollection2_iface;
    return S_OK;
}
Beispiel #20
0
HRESULT SchemaCache_create(const GUID *clsid, IUnknown* pUnkOuter, void** ppObj)
{
    schema_cache* This = heap_alloc(sizeof(schema_cache));
    if (!This)
        return E_OUTOFMEMORY;

    This->lpVtbl = &schema_cache_vtbl;
    This->cache = xmlHashCreate(DEFAULT_HASHTABLE_SIZE);
    This->ref = 1;

    if (IsEqualCLSID(clsid, &CLSID_XMLSchemaCache30))
        This->version = MSXML3;
    else if (IsEqualCLSID(clsid, &CLSID_DOMDocument40))
        This->version = MSXML4;
    else if (IsEqualCLSID(clsid, &CLSID_DOMDocument60))
        This->version = MSXML6;
    else
        This->version = MSXML_DEFAULT;

    *ppObj = &This->lpVtbl;
    return S_OK;
}
Beispiel #21
0
/**
 * xsltResolveStylesheetAttributeSet:
 * @style:  the XSLT stylesheet
 *
 * resolve the references between attribute sets.
 */
void
xsltResolveStylesheetAttributeSet(xsltStylesheetPtr style) {
    xsltStylesheetPtr cur;
    xsltAttrSetContext asctx;

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
    xsltGenericDebug(xsltGenericDebugContext,
	    "Resolving attribute sets references\n");
#endif
    asctx.topStyle = style;
    cur = style;
    while (cur != NULL) {
	if (cur->attributeSets != NULL) {
	    if (style->attributeSets == NULL) {
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
		xsltGenericDebug(xsltGenericDebugContext,
		    "creating attribute set table\n");
#endif
		style->attributeSets = xmlHashCreate(10);
	    }
            asctx.style = cur;
	    xmlHashScanFull(cur->attributeSets,
		(xmlHashScannerFull) xsltResolveSASCallback, &asctx);

            if (cur != style) {
                /*
                 * the attribute lists have either been migrated to style
                 * or freed directly in xsltResolveSASCallback()
                 */
                xmlHashFree(cur->attributeSets, NULL);
                cur->attributeSets = NULL;
            }
	}
	cur = xsltNextImport(cur);
    }
}
Beispiel #22
0
            .name = "textarea",
            .add_prompt = add_textarea
        },
        {
            .prompt_type = text_array,
            .name = "text_array",
            .add_prompt = add_text_array
        },
        {
            .prompt_type = none,
            .name = NULL,
            .add_prompt = NULL
        }    
     };
    
    prompt_type_hash = xmlHashCreate(31);
    int n;
    for(n=0; static_prompt_types[n].name != NULL; n++){
        xmlHashAddEntry( prompt_type_hash, static_prompt_types[n].name,
           (void*) &static_prompt_types[n]);
    }        

}


/*
 *  fetch_options
 *
 *
 *  options[] as in select options or radio button labels
 *  as a null termintated array of strings.
Beispiel #23
0
/**
 * xmlCreateEntitiesTable:
 *
 * create and initialize an empty entities hash table.
 * This really doesn't make sense and should be deprecated
 *
 * Returns the xmlEntitiesTablePtr just created or NULL in case of error.
 */
xmlEntitiesTablePtr
xmlCreateEntitiesTable(void) {
    return((xmlEntitiesTablePtr) xmlHashCreate(0));
}
Beispiel #24
0
void
xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
    const xmlChar *ncname;
    const xmlChar *prefix;
    xmlChar *value;
    xmlNodePtr child;
    xsltAttrElemPtr attrItems;

    if ((cur == NULL) || (style == NULL) || (cur->type != XML_ELEMENT_NODE))
        return;

    value = xmlGetNsProp(cur, (const xmlChar *)"name", NULL);
    if ((value == NULL) || (*value == 0)) {
        xsltGenericError(xsltGenericErrorContext,
                         "xsl:attribute-set : name is missing\n");
        if (value)
            xmlFree(value);
        return;
    }

    ncname = xsltSplitQName(style->dict, value, &prefix);
    xmlFree(value);
    value = NULL;

    if (style->attributeSets == NULL) {
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
        xsltGenericDebug(xsltGenericDebugContext,
                         "creating attribute set table\n");
#endif
        style->attributeSets = xmlHashCreate(10);
    }
    if (style->attributeSets == NULL)
        return;

    attrItems = xmlHashLookup2(style->attributeSets, ncname, prefix);

    /*
    * Parse the content. Only xsl:attribute elements are allowed.
    */
    child = cur->children;
    while (child != NULL) {
        /*
        * Report invalid nodes.
        */
        if ((child->type != XML_ELEMENT_NODE) ||
                (child->ns == NULL) ||
                (! IS_XSLT_ELEM(child)))
        {
            if (child->type == XML_ELEMENT_NODE)
                xsltTransformError(NULL, style, child,
                                   "xsl:attribute-set : unexpected child %s\n",
                                   child->name);
            else
                xsltTransformError(NULL, style, child,
                                   "xsl:attribute-set : child of unexpected type\n");
        } else if (!IS_XSLT_NAME(child, "attribute")) {
            xsltTransformError(NULL, style, child,
                               "xsl:attribute-set : unexpected child xsl:%s\n",
                               child->name);
        } else {
#ifdef XSLT_REFACTORED
            xsltAttrElemPtr nextAttr, curAttr;

            /*
            * Process xsl:attribute
            * ---------------------
            */

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
            xsltGenericDebug(xsltGenericDebugContext,
                             "add attribute to list %s\n", ncname);
#endif
            /*
            * The following was taken over from
            * xsltAddAttrElemList().
            */
            if (attrItems == NULL) {
                attrItems = xsltNewAttrElem(child);
            } else {
                curAttr = attrItems;
                while (curAttr != NULL) {
                    nextAttr = curAttr->next;
                    if (curAttr->attr == child) {
                        /*
                        * URGENT TODO: Can somebody explain
                        *  why attrItems is set to curAttr
                        *  here? Is this somehow related to
                        *  avoidance of recursions?
                        */
                        attrItems = curAttr;
                        goto next_child;
                    }
                    if (curAttr->next == NULL)
                        curAttr->next = xsltNewAttrElem(child);
                    curAttr = nextAttr;
                }
            }
            /*
            * Parse the xsl:attribute and its content.
            */
            xsltParseAnyXSLTElem(XSLT_CCTXT(style), child);
#else
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
            xsltGenericDebug(xsltGenericDebugContext,
                             "add attribute to list %s\n", ncname);
#endif
            /*
            * OLD behaviour:
            */
            attrItems = xsltAddAttrElemList(attrItems, child);
#endif
        }

#ifdef XSLT_REFACTORED
next_child:
#endif
        child = child->next;
    }

    /*
    * Process attribue "use-attribute-sets".
    */
    /* TODO check recursion */
    value = xmlGetNsProp(cur, (const xmlChar *)"use-attribute-sets",
                         NULL);
    if (value != NULL) {
        const xmlChar *curval, *endval;
        curval = value;
        while (*curval != 0) {
            while (IS_BLANK(*curval)) curval++;
            if (*curval == 0)
                break;
            endval = curval;
            while ((*endval != 0) && (!IS_BLANK(*endval))) endval++;
            curval = xmlDictLookup(style->dict, curval, endval - curval);
            if (curval) {
                const xmlChar *ncname2 = NULL;
                const xmlChar *prefix2 = NULL;
                xsltAttrElemPtr refAttrItems;

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
                xsltGenericDebug(xsltGenericDebugContext,
                                 "xsl:attribute-set : %s adds use %s\n", ncname, curval);
#endif
                ncname2 = xsltSplitQName(style->dict, curval, &prefix2);
                refAttrItems = xsltNewAttrElem(NULL);
                if (refAttrItems != NULL) {
                    refAttrItems->set = ncname2;
                    refAttrItems->ns = prefix2;
                    attrItems = xsltMergeAttrElemList(style,
                                                      attrItems, refAttrItems);
                    xsltFreeAttrElem(refAttrItems);
                }
            }
            curval = endval;
        }
        xmlFree(value);
        value = NULL;
    }

    /*
     * Update the value
     */
    /*
    * TODO: Why is this dummy entry needed.?
    */
    if (attrItems == NULL)
        attrItems = xsltNewAttrElem(NULL);
    xmlHashUpdateEntry2(style->attributeSets, ncname, prefix, attrItems, NULL);
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
    xsltGenericDebug(xsltGenericDebugContext,
                     "updated attribute list %s\n", ncname);
#endif
}
Beispiel #25
0
/**
 *  This is the main function for 'el' option
 */
int
elMain(int argc, char **argv)
{
    int errorno = 0;
    char* inp_file = "-";

    if (argc <= 1) elUsage(argc, argv, EXIT_BAD_ARGS);

    elInitOptions(&elOps);

    if (argc == 2)
        errorno = parse_xml_file("-");  
    else
    {
        if (!strcmp(argv[2], "--help") || !strcmp(argv[2], "-h") ||
            !strcmp(argv[2], "-?") || !strcmp(argv[2], "-Z"))
        {
            elUsage(argc, argv, EXIT_SUCCESS);
        }
        else if (!strcmp(argv[2], "-a"))
        {
            elOps.show_attr = 1;
            if (argc >= 4) inp_file = argv[3];
            errorno = parse_xml_file(inp_file);
        }
        else if (!strcmp(argv[2], "-v"))
        {
            elOps.show_attr_and_val = 1;
            if (argc >= 4) inp_file = argv[3];
            errorno = parse_xml_file(inp_file);
        }
        else if (!strcmp(argv[2], "-u"))
        {
            elOps.sort_uniq = 1;
            if (argc >= 4) inp_file = argv[3];
            uniq = xmlHashCreate(0);
            errorno = parse_xml_file(inp_file);
        }
        else if (!strncmp(argv[2], "-d", 2)) 
        { 
            elOps.check_depth = atoi(argv[2]+2); 
            /* printf("Checking depth (%d)\n", elOps.check_depth); */ 
            elOps.sort_uniq = 1; 
            if (argc >= 4) inp_file = argv[3];
            uniq = xmlHashCreate(0);
            errorno = parse_xml_file(inp_file); 
        }
        else if (argv[2][0] != '-')
        {
            errorno = parse_xml_file(argv[2]);
        }
        else
            elUsage(argc, argv, EXIT_BAD_ARGS);
    }

    if (uniq)
    {
        int i;
        ArrayDest lines;
        lines.array = xmlMalloc(sizeof(xmlChar*) * xmlHashSize(uniq));
        lines.offset = 0;
        xmlHashScan(uniq, hash_key_put, &lines);

        qsort(lines.array, lines.offset, sizeof(xmlChar*), compare_string_ptr);

        for (i = 0; i < lines.offset; i++)
        {
            printf("%s\n", lines.array[i]);
        }

        xmlFree(lines.array);
        xmlHashFree(uniq, NULL);
    }

    return errorno;
}
Beispiel #26
0
ourfa_hash_t *ourfa_hash_new(int size)
{
   return xmlHashCreate(size ? size : 10);
}
Beispiel #27
0
int
test (const char* base) {
    xmlDocPtr docPtr = NULL;
    char filename[100];
    xmlSchemaPtr wxschemas = NULL;

    Handle2Path = xmlHashCreate(0);

    /* Read the schema. */
    {
        /* There is no visitibility into parserCtxt. */
	xmlSchemaParserCtxtPtr parserCtxt;

        /* parserCtxt->ctxtType is xmlSchemaTypePtr */

        snprintf(filename, 100, "%s.xsd", base);
        printf("\n\n\n----------------------------------------------------------------\n\n\n");
        printf("\n----> Reading schema %s...\n", filename);

	parserCtxt = xmlSchemaNewParserCtxt(filename);
	xmlSchemaSetParserErrors(parserCtxt,
		(xmlSchemaValidityErrorFunc) fprintf,
		(xmlSchemaValidityWarningFunc) fprintf,
		stdout);
	xmlSchemaSetParserAnnotation(parserCtxt, schema_annotation_callback, NULL);
	wxschemas = xmlSchemaParse(parserCtxt);
	if (wxschemas == NULL)
        {
            printf("***** schema parsing failed!\n");
	}
	xmlSchemaFreeParserCtxt(parserCtxt);
        printf("\n<---- Schema read!\n\n");
    }

    /* Read the XML. */
    {
        snprintf(filename, 100, "%s.xml", base);
        if ((docPtr = xmlReadFile(filename, NULL, 0)) == NULL)
        {
            printf("failed to parse \"%s\".\n", filename);
            return -1;
        }
    }

    if (!SKIP) {
        /* There is no visibility into schemaCtxt. */
	xmlSchemaValidCtxtPtr schemaCtxt;
	int ret;

        printf("\n----------------------------------------------------------------\n");
        printf("\n----> Validating document %s...\n", filename);

        /* This sets up the schemaCtxt, including a pointer to wxschemas. */
	schemaCtxt = xmlSchemaNewValidCtxt(wxschemas);
	xmlSchemaSetValidErrors(schemaCtxt,
		(xmlSchemaValidityErrorFunc) fprintf,
		(xmlSchemaValidityWarningFunc) fprintf,
		stdout);
	ret = xmlSchemaValidateDoc(schemaCtxt, docPtr);	/* read me! */
	if (ret == 0)
        {
	    /* printf("%s validates\n", filename); */
	}
        else if (ret > 0)
        {
	    printf("%s fails to validate\n", filename);
	}
        else
        {
	    printf("%s validation generated an internal error\n",
		   filename);
	}
	xmlSchemaFreeValidCtxt(schemaCtxt);
        printf("\n<---- Document validated!\n");

    }

    /* Generate a doc and validate it. */
    {
	xmlDocPtr newDoc = xmlNewDoc(BAD_CAST "1.0");
	{
	    xmlSchemaValidCtxtPtr schemaCtxt;
	    int ret;

	    schemaCtxt = xmlSchemaNewValidCtxt(wxschemas);
	    xmlSchemaSetValidErrors(schemaCtxt,
				    (xmlSchemaValidityErrorFunc) fprintf,
				    (xmlSchemaValidityWarningFunc) fprintf,
				    stdout);
	    xmlSchemaSetGeneratorCallback(schemaCtxt, BAD_CAST "people", NULL, &generation_callback, newDoc);
	    ret = xmlSchemaValidateDoc(schemaCtxt, newDoc);
	    if (ret == 0) {
/* 		xmlDocSetRootElement(newDoc, vctxt->node); */
		dump_doc(newDoc, NULL);
	    } else if (ret > 0)
		printf("%s fails to validate\n", filename);
	    else
		printf("%s validation generated an internal error\n",
		       filename);
	    xmlSchemaFreeValidCtxt(schemaCtxt);
	    printf("\n<---- Schema read!\n\n");
	}

	{
	    xmlSchemaValidCtxtPtr schemaCtxt;
	    int ret;

	    schemaCtxt = xmlSchemaNewValidCtxt(wxschemas);
	    xmlSchemaSetValidErrors(schemaCtxt,
				    (xmlSchemaValidityErrorFunc) fprintf,
				    (xmlSchemaValidityWarningFunc) fprintf,
				    stdout);
	    ret = xmlSchemaValidateDoc(schemaCtxt, newDoc);
	    if (ret == 0)
		;
	    else if (ret > 0)
		printf("%s fails to validate\n", filename);
	    else
		printf("%s validation generated an internal error\n",
		       filename);
	    xmlSchemaFreeValidCtxt(schemaCtxt);
	    printf("\n<---- Schema read!\n\n");
	}

	xmlFreeDoc(newDoc);
    }

#if 0
    /* why can't I just start with doc->children? */
    tree_trunk = xmlDocGetRootElement(docPtr);
#endif

#if 0
    tree_trunk = docPtr->children;

    printf("\n\n\n----------------------------------------------------------------\n\n\n");
    printf("\nWalking doc tree...\n");
    walk_doc_tree(tree_trunk, 0);
    printf("\n");
#endif
    printf("\n\n\n----------------------------------------------------------------\n\n\n");
    printf("\nWalking schema tree...\n");
    walk_schema_tree(wxschemas);
    printf("\n");

    /*****************************************************************/
    /*****************************************************************/
    /*****************************************************************/
    /*****************************************************************/
    /* This will tell me, for example, how to decode sequences. */
    printf("\n\n\n----------------------------------------------------------------\n\n\n");
    xmlSchemaDump(stdout, wxschemas);
    /*****************************************************************/
    /*****************************************************************/
    /*****************************************************************/
    /*****************************************************************/

    xmlFreeDoc(docPtr);

    xmlCleanupParser();

    xmlHashFree(Handle2Path, NULL);

    return 0;
}
Beispiel #28
0
/**
 * xsltNamespaceAlias:
 * @style:  the XSLT stylesheet
 * @node:  the xsl:namespace-alias node
 *
 * Read the stylesheet-prefix and result-prefix attributes, register
 * them as well as the corresponding namespace.
 */
void
xsltNamespaceAlias(xsltStylesheetPtr style, xmlNodePtr node)
{
    xmlChar *resultPrefix = NULL;
    xmlChar *stylePrefix = NULL;
    xmlNsPtr literalNs = NULL;
    xmlNsPtr targetNs = NULL;

#ifdef XSLT_REFACTORED
    xsltNsAliasPtr alias;

    if ((style == NULL) || (node == NULL))
	return;

    /*
    * SPEC XSLT 1.0:
    *  "If a namespace URI is declared to be an alias for multiple
    *  different namespace URIs, then the declaration with the highest
    *  import precedence is used. It is an error if there is more than
    *  one such declaration. An XSLT processor may signal the error;
    *  if it does not signal the error, it must recover by choosing,
    *  from amongst the declarations with the highest import precedence,
    *  the one that occurs last in the stylesheet."
    *
    * SPEC TODO: Check for the errors mentioned above.
    */
    /*
    * NOTE that the XSLT 2.0 also *does* use the NULL namespace if
    *  "#default" is used and there's no default namespace is scope.
    *  I.e., this is *not* an error.
    *  Most XSLT 1.0 implementations work this way.
    *  The XSLT 1.0 spec has nothing to say on the subject.
    */
    /*
    * Attribute "stylesheet-prefix".
    */
    stylePrefix = xmlGetNsProp(node, (const xmlChar *)"stylesheet-prefix", NULL);
    if (stylePrefix == NULL) {
	xsltTransformError(NULL, style, node,
	    "The attribute 'stylesheet-prefix' is missing.\n");
	return;
    }
    if (xmlStrEqual(stylePrefix, (const xmlChar *)"#default"))
	literalNs = xmlSearchNs(node->doc, node, NULL);
    else {
	literalNs = xmlSearchNs(node->doc, node, stylePrefix);
	if (literalNs == NULL) {
	    xsltTransformError(NULL, style, node,
	        "Attribute 'stylesheet-prefix': There's no namespace "
		"declaration in scope for the prefix '%s'.\n",
		    stylePrefix);
	    goto error;
	}
    }
    /*
    * Attribute "result-prefix".
    */
    resultPrefix = xmlGetNsProp(node, (const xmlChar *)"result-prefix", NULL);
    if (resultPrefix == NULL) {
	xsltTransformError(NULL, style, node,
	    "The attribute 'result-prefix' is missing.\n");
	goto error;
    }
    if (xmlStrEqual(resultPrefix, (const xmlChar *)"#default"))
	targetNs = xmlSearchNs(node->doc, node, NULL);
    else {
	targetNs = xmlSearchNs(node->doc, node, resultPrefix);

        if (targetNs == NULL) {
	   xsltTransformError(NULL, style, node,
	        "Attribute 'result-prefix': There's no namespace "
		"declaration in scope for the prefix '%s'.\n",
		    stylePrefix);
	    goto error;
	}
    }
    /*
     *
     * Same alias for multiple different target namespace URIs:
     *  TODO: The one with the highest import precedence is used.
     *  Example:
     *  <xsl:namespace-alias stylesheet-prefix="foo"
     *                       result-prefix="bar"/>
     *
     *  <xsl:namespace-alias stylesheet-prefix="foo"
     *                       result-prefix="zar"/>
     *
     * Same target namespace URI for multiple different aliases:
     *  All alias-definitions will be used.
     *  Example:
     *  <xsl:namespace-alias stylesheet-prefix="bar"
     *                       result-prefix="foo"/>
     *
     *  <xsl:namespace-alias stylesheet-prefix="zar"
     *                       result-prefix="foo"/>
     * Cases using #default:
     *  <xsl:namespace-alias stylesheet-prefix="#default"
     *                       result-prefix="#default"/>
     *  TODO: Has this an effect at all?
     *
     *  <xsl:namespace-alias stylesheet-prefix="foo"
     *                       result-prefix="#default"/>
     *  From namespace to no namespace.
     *
     *  <xsl:namespace-alias stylesheet-prefix="#default"
     *                       result-prefix="foo"/>
     *  From no namespace to namespace.
     */


     /*
     * Store the ns-node in the alias-object.
    */
    alias = xsltNewNsAlias(XSLT_CCTXT(style));
    if (alias == NULL)
	return;
    alias->literalNs = literalNs;
    alias->targetNs = targetNs;
    XSLT_CCTXT(style)->hasNsAliases = 1;


#else /* XSLT_REFACTORED */
    const xmlChar *literalNsName;
    const xmlChar *targetNsName;


    if ((style == NULL) || (node == NULL))
	return;

    stylePrefix = xmlGetNsProp(node, (const xmlChar *)"stylesheet-prefix", NULL);
    if (stylePrefix == NULL) {
	xsltTransformError(NULL, style, node,
	    "namespace-alias: stylesheet-prefix attribute missing\n");
	return;
    }
    resultPrefix = xmlGetNsProp(node, (const xmlChar *)"result-prefix", NULL);
    if (resultPrefix == NULL) {
	xsltTransformError(NULL, style, node,
	    "namespace-alias: result-prefix attribute missing\n");
	goto error;
    }

    if (xmlStrEqual(stylePrefix, (const xmlChar *)"#default")) {
	literalNs = xmlSearchNs(node->doc, node, NULL);
	if (literalNs == NULL) {
	    literalNsName = NULL;
	} else
	    literalNsName = literalNs->href; /* Yes - set for nsAlias table */
    } else {
	literalNs = xmlSearchNs(node->doc, node, stylePrefix);

	if ((literalNs == NULL) || (literalNs->href == NULL)) {
	    xsltTransformError(NULL, style, node,
	        "namespace-alias: prefix %s not bound to any namespace\n",
					stylePrefix);
	    goto error;
	} else
	    literalNsName = literalNs->href;
    }

    /*
     * When "#default" is used for result, if a default namespace has not
     * been explicitly declared the special value UNDEFINED_DEFAULT_NS is
     * put into the nsAliases table
     */
    if (xmlStrEqual(resultPrefix, (const xmlChar *)"#default")) {
	targetNs = xmlSearchNs(node->doc, node, NULL);
	if (targetNs == NULL) {
	    targetNsName = UNDEFINED_DEFAULT_NS;
	} else
	    targetNsName = targetNs->href;
    } else {
	targetNs = xmlSearchNs(node->doc, node, resultPrefix);

        if ((targetNs == NULL) || (targetNs->href == NULL)) {
	    xsltTransformError(NULL, style, node,
	        "namespace-alias: prefix %s not bound to any namespace\n",
					resultPrefix);
	    goto error;
	} else
	    targetNsName = targetNs->href;
    }
    /*
     * Special case: if #default is used for
     *  the stylesheet-prefix (literal namespace) and there's no default
     *  namespace in scope, we'll use style->defaultAlias for this.
     */
    if (literalNsName == NULL) {
        if (targetNs != NULL) {
	    /*
	    * BUG TODO: Is it not sufficient to have only 1 field for
	    *  this, since subsequently alias declarations will
	    *  overwrite this.
	    *  Example:
	    *   <xsl:namespace-alias result-prefix="foo"
	    *                        stylesheet-prefix="#default"/>
	    *   <xsl:namespace-alias result-prefix="bar"
	    *                        stylesheet-prefix="#default"/>
	    *  The mapping for "foo" won't be visible anymore.
	    */
            style->defaultAlias = targetNs->href;
	}
    } else {
        if (style->nsAliases == NULL)
	    style->nsAliases = xmlHashCreate(10);
        if (style->nsAliases == NULL) {
	    xsltTransformError(NULL, style, node,
	        "namespace-alias: cannot create hash table\n");
	    goto error;
        }
	xmlHashAddEntry((xmlHashTablePtr) style->nsAliases,
	    literalNsName, (void *) targetNsName);
    }
#endif /* else of XSLT_REFACTORED */

error:
    if (stylePrefix != NULL)
	xmlFree(stylePrefix);
    if (resultPrefix != NULL)
	xmlFree(resultPrefix);
}
Beispiel #29
0
void
xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
    const xmlChar *ncname;
    const xmlChar *prefix;
    const xmlChar *nsUri = NULL;
    xmlChar *value;
    xmlNodePtr child;
    xsltAttrSetPtr set;

    if ((cur == NULL) || (style == NULL) || (cur->type != XML_ELEMENT_NODE))
	return;

    value = xmlGetNsProp(cur, (const xmlChar *)"name", NULL);
    if ((value == NULL) || (*value == 0)) {
	xsltGenericError(xsltGenericErrorContext,
	     "xsl:attribute-set : name is missing\n");
        if (value)
	    xmlFree(value);
	return;
    }

    if (xmlValidateQName(value, 0)) {
        xsltTransformError(NULL, style, cur,
            "xsl:attribute-set : The name '%s' is not a valid QName.\n",
            value);
        style->errors++;
        xmlFree(value);
        return;
    }

    ncname = xsltSplitQName(style->dict, value, &prefix);
    xmlFree(value);
    value = NULL;
    if (prefix != NULL) {
        xmlNsPtr ns = xmlSearchNs(style->doc, cur, prefix);
        if (ns == NULL) {
            xsltTransformError(NULL, style, cur,
                "xsl:attribute-set : No namespace found for QName '%s:%s'\n",
                prefix, ncname);
            style->errors++;
            return;
        }
        nsUri = ns->href;
    }

    if (style->attributeSets == NULL) {
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
	xsltGenericDebug(xsltGenericDebugContext,
	    "creating attribute set table\n");
#endif
	style->attributeSets = xmlHashCreate(10);
    }
    if (style->attributeSets == NULL)
	return;

    set = xmlHashLookup2(style->attributeSets, ncname, nsUri);
    if (set == NULL) {
        set = xsltNewAttrSet();
        if (set == NULL)
            return;
        xmlHashAddEntry2(style->attributeSets, ncname, nsUri, set);
    }

    /*
    * Parse the content. Only xsl:attribute elements are allowed.
    */
    child = cur->children;
    while (child != NULL) {
	/*
	* Report invalid nodes.
	*/
	if ((child->type != XML_ELEMENT_NODE) ||
	    (child->ns == NULL) ||
	    (! IS_XSLT_ELEM(child)))
	{
	    if (child->type == XML_ELEMENT_NODE)
		xsltTransformError(NULL, style, child,
			"xsl:attribute-set : unexpected child %s\n",
		                 child->name);
	    else
		xsltTransformError(NULL, style, child,
			"xsl:attribute-set : child of unexpected type\n");
	} else if (!IS_XSLT_NAME(child, "attribute")) {
	    xsltTransformError(NULL, style, child,
		"xsl:attribute-set : unexpected child xsl:%s\n",
		child->name);
	} else {
#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
	    xsltGenericDebug(xsltGenericDebugContext,
		"add attribute to list %s\n", ncname);
#endif
            if (child->psvi == NULL) {
                xsltTransformError(NULL, style, child,
                    "xsl:attribute-set : internal error, attribute %s not "
                    "compiled\n", child->name);
            }
            else {
	        set->attrs = xsltAddAttrElemList(set->attrs, child);
            }
	}

	child = child->next;
    }

    /*
    * Process attribute "use-attribute-sets".
    */
    value = xmlGetNsProp(cur, BAD_CAST "use-attribute-sets", NULL);
    if (value != NULL) {
	const xmlChar *curval, *endval;
	curval = value;
	while (*curval != 0) {
	    while (IS_BLANK(*curval)) curval++;
	    if (*curval == 0)
		break;
	    endval = curval;
	    while ((*endval != 0) && (!IS_BLANK(*endval))) endval++;
	    curval = xmlDictLookup(style->dict, curval, endval - curval);
	    if (curval) {
		const xmlChar *ncname2 = NULL;
		const xmlChar *prefix2 = NULL;
                const xmlChar *nsUri2 = NULL;

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
		xsltGenericDebug(xsltGenericDebugContext,
		    "xsl:attribute-set : %s adds use %s\n", ncname, curval);
#endif

                if (xmlValidateQName(curval, 0)) {
                    xsltTransformError(NULL, style, cur,
                        "xsl:attribute-set : The name '%s' in "
                        "use-attribute-sets is not a valid QName.\n", curval);
                    style->errors++;
                    xmlFree(value);
                    return;
                }

		ncname2 = xsltSplitQName(style->dict, curval, &prefix2);
                if (prefix2 != NULL) {
                    xmlNsPtr ns2 = xmlSearchNs(style->doc, cur, prefix2);
                    if (ns2 == NULL) {
                        xsltTransformError(NULL, style, cur,
                            "xsl:attribute-set : No namespace found for QName "
                            "'%s:%s' in use-attribute-sets\n",
                            prefix2, ncname2);
                        style->errors++;
                        xmlFree(value);
                        return;
                    }
                    nsUri2 = ns2->href;
                }
                set->useAttrSets = xsltAddUseAttrSetList(set->useAttrSets,
                                                         ncname2, nsUri2);
	    }
	    curval = endval;
	}
	xmlFree(value);
	value = NULL;
    }

#ifdef WITH_XSLT_DEBUG_ATTRIBUTES
    xsltGenericDebug(xsltGenericDebugContext,
	"updated attribute list %s\n", ncname);
#endif
}
/*
 * xmlAddEntity : register a new entity for an entities table.
 */
static xmlEntityPtr
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
	  const xmlChar *ExternalID, const xmlChar *SystemID,
	  const xmlChar *content) {
    xmlEntitiesTablePtr table = NULL;
    xmlEntityPtr ret;

    if (name == NULL)
	return(NULL);
    switch (type) {
        case XML_INTERNAL_GENERAL_ENTITY:
        case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
        case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
	    if (dtd->entities == NULL)
		dtd->entities = xmlHashCreate(0);
	    table = (xmlEntitiesTablePtr)dtd->entities;
	    break;
        case XML_INTERNAL_PARAMETER_ENTITY:
        case XML_EXTERNAL_PARAMETER_ENTITY:
	    if (dtd->pentities == NULL)
		dtd->pentities = xmlHashCreate(0);
	    table = (xmlEntitiesTablePtr)dtd->pentities;
	    break;
        case XML_INTERNAL_PREDEFINED_ENTITY:
	    return(NULL);
    }
    if (table == NULL)
	return(NULL);
    ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
    if (ret == NULL) {
	xmlGenericError(xmlGenericErrorContext,
		"xmlAddEntity: out of memory\n");
	return(NULL);
    }
    memset(ret, 0, sizeof(xmlEntity));
    ret->type = XML_ENTITY_DECL;

    /*
     * fill the structure.
     */
    ret->name = xmlStrdup(name);
    ret->etype = (xmlEntityType) type;
    if (ExternalID != NULL)
	ret->ExternalID = xmlStrdup(ExternalID);
    if (SystemID != NULL)
	ret->SystemID = xmlStrdup(SystemID);
    if (content != NULL) {
        ret->length = xmlStrlen(content);
	ret->content = xmlStrndup(content, ret->length);
     } else {
        ret->length = 0;
        ret->content = NULL;
    }
    ret->URI = NULL; /* to be computed by the layer knowing
			the defining entity */
    ret->orig = NULL;
    ret->owner = 0;

    if (xmlHashAddEntry(table, name, ret)) {
	/*
	 * entity was already defined at another level.
	 */
        xmlFreeEntity(ret);
	return(NULL);
    }
    return(ret);
}