/** * xmlSchematronPushInclude: * @ctxt: the schema parser context * @doc: the included document * @cur: the current include node * * Add an included document */ static void xmlSchematronPushInclude(xmlSchematronParserCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr cur) { if (ctxt->includes == NULL) { ctxt->maxIncludes = 10; ctxt->includes = (xmlNodePtr *) xmlMalloc(ctxt->maxIncludes * 2 * sizeof(xmlNodePtr)); if (ctxt->includes == NULL) { xmlSchematronPErrMemory(NULL, "allocating parser includes", NULL); return; } ctxt->nbIncludes = 0; } else if (ctxt->nbIncludes + 2 >= ctxt->maxIncludes) { xmlNodePtr *tmp; tmp = (xmlNodePtr *) xmlRealloc(ctxt->includes, ctxt->maxIncludes * 4 * sizeof(xmlNodePtr)); if (tmp == NULL) { xmlSchematronPErrMemory(NULL, "allocating parser includes", NULL); return; } ctxt->includes = tmp; ctxt->maxIncludes *= 2; } ctxt->includes[2 * ctxt->nbIncludes] = cur; ctxt->includes[2 * ctxt->nbIncludes + 1] = (xmlNodePtr) doc; ctxt->nbIncludes++; }
/** * xmlCopyEntity: * @ent: An entity * * Build a copy of an entity * * Returns the new xmlEntitiesPtr or NULL in case of error. */ static xmlEntityPtr xmlCopyEntity(xmlEntityPtr ent) { xmlEntityPtr cur; cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); if (cur == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlCopyEntity: out of memory !\n"); return(NULL); } memset(cur, 0, sizeof(xmlEntity)); cur->type = XML_ENTITY_DECL; cur->etype = ent->etype; if (ent->name != NULL) cur->name = xmlStrdup(ent->name); if (ent->ExternalID != NULL) cur->ExternalID = xmlStrdup(ent->ExternalID); if (ent->SystemID != NULL) cur->SystemID = xmlStrdup(ent->SystemID); if (ent->content != NULL) cur->content = xmlStrdup(ent->content); if (ent->orig != NULL) cur->orig = xmlStrdup(ent->orig); if (ent->URI != NULL) cur->URI = xmlStrdup(ent->URI); return(cur); }
/** * xmlSchematronAddPattern: * @ctxt: the schema parsing context * @schema: a schema structure * @node: the node hosting the pattern * @id: the id or name of the pattern * * Add a pattern to a schematron * * Returns the new pointer or NULL in case of error */ static xmlSchematronPatternPtr xmlSchematronAddPattern(xmlSchematronParserCtxtPtr ctxt, xmlSchematronPtr schema, xmlNodePtr node, xmlChar *name) { xmlSchematronPatternPtr ret; if ((ctxt == NULL) || (schema == NULL) || (node == NULL) || (name == NULL)) return(NULL); ret = (xmlSchematronPatternPtr) xmlMalloc(sizeof(xmlSchematronPattern)); if (ret == NULL) { xmlSchematronPErrMemory(ctxt, "allocating schema pattern", node); return (NULL); } memset(ret, 0, sizeof(xmlSchematronPattern)); ret->name = name; ret->next = NULL; if (schema->patterns == NULL) { schema->patterns = ret; } else { xmlSchematronPatternPtr prev = schema->patterns; while (prev->next != NULL) prev = prev->next; prev->next = ret; } return (ret); }
/** * htmlNodeDumpFormat: * @buf: the HTML buffer output * @doc: the document * @cur: the current node * @format: should formatting spaces been added * * Dump an HTML node, recursive behaviour,children are printed too. * * Returns the number of byte written or -1 in case of error */ static int htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int format) { unsigned int use; int ret; xmlOutputBufferPtr outbuf; if (cur == NULL) { return (-1); } if (buf == NULL) { return (-1); } outbuf = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); if (outbuf == NULL) { htmlSaveErrMemory("allocating HTML output buffer"); return (-1); } memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer)); outbuf->buffer = buf; outbuf->encoder = NULL; outbuf->writecallback = NULL; outbuf->closecallback = NULL; outbuf->context = NULL; outbuf->written = 0; use = buf->use; htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format); xmlFree(outbuf); ret = buf->use - use; return (ret); }
xmlChar *xml_convert_input(const char *in, const char *encoding) { xmlChar *out; int ret; int size; int out_size; int temp; xmlCharEncodingHandlerPtr handler; handler = xmlFindCharEncodingHandler(encoding); assert(handler != NULL); size = (int)strlen(in) + 1; out_size = size * 2 - 1; out = (unsigned char *)xmlMalloc((size_t) out_size); if (out != NULL) { temp = size - 1; ret = handler->input(out, &out_size, (const xmlChar *)in, &temp); if ((ret < 0) || (temp - size + 1)) { xmlFree(out); out = 0; } else { out = (unsigned char *)xmlRealloc(out, out_size + 1); out[out_size] = 0; /*null terminating out */ } } return out; }
/** * xmlSecEncCtxCreate: * @keysMngr: the pointer to keys manager. * * Creates <enc:EncryptedData/> element processing context. * The caller is responsible for destroying returned object by calling * #xmlSecEncCtxDestroy function. * * Returns: pointer to newly allocated context object or NULL if an error * occurs. */ xmlSecEncCtxPtr xmlSecEncCtxCreate(xmlSecKeysMngrPtr keysMngr) { xmlSecEncCtxPtr encCtx; int ret; encCtx = (xmlSecEncCtxPtr) xmlMalloc(sizeof(xmlSecEncCtx)); if(encCtx == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, NULL, XMLSEC_ERRORS_R_MALLOC_FAILED, "sizeof(xmlSecEncCtx)=%d", (int)sizeof(xmlSecEncCtx)); return(NULL); } ret = xmlSecEncCtxInitialize(encCtx, keysMngr); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecEncCtxInitialize", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); xmlSecEncCtxDestroy(encCtx); return(NULL); } return(encCtx); }
static void xz_error(xz_statep state, int err, const char *msg) { /* free previously allocated message and clear */ if (state->msg != NULL) { if (state->err != LZMA_MEM_ERROR) xmlFree(state->msg); state->msg = NULL; } /* set error code, and if no message, then done */ state->err = err; if (msg == NULL) return; /* for an out of memory error, save as static string */ if (err == LZMA_MEM_ERROR) { state->msg = (char *) msg; return; } /* construct error message with path */ if ((state->msg = xmlMalloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { state->err = LZMA_MEM_ERROR; state->msg = (char *) "out of memory"; return; } strcpy(state->msg, state->path); strcat(state->msg, ": "); strcat(state->msg, msg); return; }
/** * xmlBufCreate: * * routine to create an XML buffer. * returns the new structure. */ xmlBufPtr xmlBufCreate(void) { xmlBufPtr ret; ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); if (ret == NULL) { xmlBufMemoryError(NULL, "creating buffer"); return(NULL); } ret->compat_use = 0; ret->use = 0; ret->error = 0; ret->buffer = NULL; ret->size = xmlDefaultBufferSize; ret->compat_size = xmlDefaultBufferSize; ret->alloc = xmlBufferAllocScheme; ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); if (ret->content == NULL) { xmlBufMemoryError(ret, "creating buffer"); xmlFree(ret); return(NULL); } ret->content[0] = 0; ret->contentIO = NULL; return(ret); }
/* Problem: * - xmlSetGlobalState may need to either ``copy'' memory * from one place to another or ``change a pointer''. * * - changing a pointer requires: * an ** where to save the old pointer * a new * to set instead of the old one * - copying memory requires * a memory area where to save the old state * a new memory area to copy over the current state * * In either cases, the SetGlobalState must be transparent * to the user * */ int xmlSetGlobalState(xmlGlobalStatePtr new_state, xmlGlobalStatePtr * old_state) { xmlGlobalStatePtr global; int retval=1; /* Get a pointer to the current * memory area */ global=xmlGetGlobalState(); /* If the user wants to * save the current state somewhere */ if(old_state) { *old_state=(xmlGlobalStatePtr)xmlMalloc(sizeof(xmlGlobalState)); if(*old_state) memcpy(*old_state, global, sizeof(xmlGlobalState)); else retval=0; } /* If the user provides a new_state state * and the copy was succesfull */ if(new_state && (!old_state || *old_state)) { memcpy(global, new_state, sizeof(xmlGlobalState)); xmlFree(new_state); } /* Return status */ return retval; }
/** * xmlSchematronNewMemParserCtxt: * @buffer: a pointer to a char array containing the schemas * @size: the size of the array * * Create an XML Schematrons parse context for that memory buffer expected * to contain an XML Schematrons file. * * Returns the parser context or NULL in case of error */ xmlSchematronParserCtxtPtr xmlSchematronNewMemParserCtxt(const char *buffer, int size) { xmlSchematronParserCtxtPtr ret; if ((buffer == NULL) || (size <= 0)) return (NULL); ret = (xmlSchematronParserCtxtPtr) xmlMalloc(sizeof(xmlSchematronParserCtxt)); if (ret == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser context", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchematronParserCtxt)); ret->buffer = buffer; ret->size = size; ret->dict = xmlDictCreate(); ret->xctxt = xmlXPathNewContext(NULL); if (ret->xctxt == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context", NULL); xmlSchematronFreeParserCtxt(ret); return (NULL); } return (ret); }
/** * xmlSchematronNewDocParserCtxt: * @doc: a preparsed document tree * * Create an XML Schematrons parse context for that document. * NB. The document may be modified during the parsing process. * * Returns the parser context or NULL in case of error */ xmlSchematronParserCtxtPtr xmlSchematronNewDocParserCtxt(xmlDocPtr doc) { xmlSchematronParserCtxtPtr ret; if (doc == NULL) return (NULL); ret = (xmlSchematronParserCtxtPtr) xmlMalloc(sizeof(xmlSchematronParserCtxt)); if (ret == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser context", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchematronParserCtxt)); ret->doc = doc; ret->dict = xmlDictCreate(); /* The application has responsibility for the document */ ret->preserve = 1; ret->xctxt = xmlXPathNewContext(doc); if (ret->xctxt == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context", NULL); xmlSchematronFreeParserCtxt(ret); return (NULL); } return (ret); }
/** * exsltFuncInit: * @ctxt: an XSLT transformation context * @URI: the namespace URI for the extension * * Initializes the EXSLT - Functions module. * Called at transformation-time; merges all * functions declared in the import tree taking * import precedence into account, i.e. overriding * functions with lower import precedence. * * Returns the data for this transformation */ static exsltFuncData * exsltFuncInit (xsltTransformContextPtr ctxt, const xmlChar *URI) { exsltFuncData *ret; xsltStylesheetPtr tmp; exsltFuncImportRegData ch; xmlHashTablePtr hash; ret = (exsltFuncData *) xmlMalloc (sizeof(exsltFuncData)); if (ret == NULL) { xsltGenericError(xsltGenericErrorContext, "exsltFuncInit: not enough memory\n"); return(NULL); } memset(ret, 0, sizeof(exsltFuncData)); ret->result = NULL; ret->error = 0; ch.hash = (xmlHashTablePtr) xsltStyleGetExtData(ctxt->style, URI); ret->funcs = ch.hash; xmlHashScanFull(ch.hash, (xmlHashScannerFull) exsltFuncRegisterFunc, ctxt); tmp = ctxt->style; ch.ctxt = ctxt; while ((tmp=xsltNextImport(tmp))!=NULL) { hash = xsltGetExtInfo(tmp, URI); if (hash != NULL) { xmlHashScanFull(hash, (xmlHashScannerFull) exsltFuncRegisterImportFunc, &ch); } } return(ret); }
/** * xmlSchematronNewParserCtxt: * @URL: the location of the schema * * Create an XML Schematrons parse context for that file/resource expected * to contain an XML Schematrons file. * * Returns the parser context or NULL in case of error */ xmlSchematronParserCtxtPtr xmlSchematronNewParserCtxt(const char *URL) { xmlSchematronParserCtxtPtr ret; if (URL == NULL) return (NULL); ret = (xmlSchematronParserCtxtPtr) xmlMalloc(sizeof(xmlSchematronParserCtxt)); if (ret == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser context", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchematronParserCtxt)); ret->type = XML_STRON_CTXT_PARSER; ret->dict = xmlDictCreate(); ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); ret->includes = NULL; ret->xctxt = xmlXPathNewContext(NULL); if (ret->xctxt == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context", NULL); xmlSchematronFreeParserCtxt(ret); return (NULL); } ret->xctxt->flags = XML_XPATH_CHECKNS; return (ret); }
/* * call-seq: * parser.parse -> (true|false) * * Parse the input XML, generating callbacks to the object * registered via the +callbacks+ attributesibute. */ static VALUE rxml_sax_parser_parse(VALUE self) { int status; VALUE context = rb_ivar_get(self, CONTEXT_ATTR); xmlParserCtxtPtr ctxt; Data_Get_Struct(context, xmlParserCtxt, ctxt); ctxt->sax2 = 1; ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR); if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(rxml_sax_handler)); if (ctxt->sax == NULL) rb_fatal("Not enough memory."); memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler)); status = xmlParseDocument(ctxt); /* Now check the parsing result*/ if (status == -1 || !ctxt->wellFormed) { if (ctxt->myDoc) xmlFreeDoc(ctxt->myDoc); rxml_raise(&ctxt->lastError); } return Qtrue; }
/** * xmlSchematronNewValidCtxt: * @schema: a precompiled XML Schematrons * @options: a set of xmlSchematronValidOptions * * Create an XML Schematrons validation context based on the given schema. * * Returns the validation context or NULL in case of error */ xmlSchematronValidCtxtPtr xmlSchematronNewValidCtxt(xmlSchematronPtr schema, int options) { int i; xmlSchematronValidCtxtPtr ret; ret = (xmlSchematronValidCtxtPtr) xmlMalloc(sizeof(xmlSchematronValidCtxt)); if (ret == NULL) { xmlSchematronVErrMemory(NULL, "allocating validation context", NULL); return (NULL); } memset(ret, 0, sizeof(xmlSchematronValidCtxt)); ret->type = XML_STRON_CTXT_VALIDATOR; ret->schema = schema; ret->xctxt = xmlXPathNewContext(NULL); ret->flags = options; if (ret->xctxt == NULL) { xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context", NULL); xmlSchematronFreeValidCtxt(ret); return (NULL); } for (i = 0;i < schema->nbNamespaces;i++) { if ((schema->namespaces[2 * i] == NULL) || (schema->namespaces[2 * i + 1] == NULL)) break; xmlXPathRegisterNs(ret->xctxt, schema->namespaces[2 * i + 1], schema->namespaces[2 * i]); } return (ret); }
/** * xmlNewPatParserContext: * @pattern: the pattern context * @dict: the inherited dictionnary or NULL * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * * Create a new XML pattern parser context * * Returns the newly allocated xmlPatParserContextPtr or NULL in case of error */ static xmlPatParserContextPtr xmlNewPatParserContext(const xmlChar *pattern, xmlDictPtr dict, const xmlChar **namespaces) { xmlPatParserContextPtr cur; if (pattern == NULL) return(NULL); cur = (xmlPatParserContextPtr) xmlMalloc(sizeof(xmlPatParserContext)); if (cur == NULL) { ERROR(NULL, NULL, NULL, "xmlNewPatParserContext : malloc failed\n"); return(NULL); } memset(cur, 0, sizeof(xmlPatParserContext)); cur->dict = dict; cur->cur = pattern; cur->base = pattern; if (namespaces != NULL) { int i; for (i = 0;namespaces[2 * i] != NULL;i++); cur->nb_namespaces = i; } else { cur->nb_namespaces = 0; } cur->namespaces = namespaces; return(cur); }
/** * xmlModuleOpen: * @name: the module name * @options: a set of xmlModuleOption * * Opens a module/shared library given its name or path * TODO: options are not yet implemented. * * Returns a handle for the module or NULL in case of error */ xmlModulePtr xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED) { xmlModulePtr module; module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule)); if (module == NULL) { xmlModuleErrMemory(NULL, "creating module"); return (NULL); } memset(module, 0, sizeof(xmlModule)); module->handle = xmlModulePlatformOpen(name); if (module->handle == NULL) { xmlFree(module); __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, name, NULL, 0, 0, "failed to open %s\n", name); return(NULL); } module->name = xmlStrdup((const xmlChar *) name); return (module); }
/** * @arg xpath XPath expression to evaluate * @doc document over which to evaluate * @arg pctxt can be NULL * @return list of matching nodes. The caller will have to free it using xmlXPathFreeNodeSet(). */ xmlNodeSetPtr find_node_set(const char *xpath, const xmlDocPtr doc, xmlXPathParserContextPtr *pctxt) { xmlXPathContextPtr ctxt = xmlXPathNewContext(doc); if(!ctxt) { g_printerr(G_STRLOC ": Failed to allocate XPathContext!\n"); return NULL; } if(xmlXPathRegisterNs(ctxt, (xmlChar *) FREEDICT_EDITOR_NAMESPACE_PREFIX, (xmlChar *) FREEDICT_EDITOR_NAMESPACE)) { g_printerr("Warning: Unable to register XSLT-Namespace prefix \"%s\"" " for URI \"%s\"\n", FREEDICT_EDITOR_NAMESPACE_PREFIX, FREEDICT_EDITOR_NAMESPACE); } if(xmlXPathRegisterFuncNS(ctxt, (xmlChar *) "unbalanced-braces", (xmlChar *) FREEDICT_EDITOR_NAMESPACE, freedict_xpath_extension_unbalanced_braces)) g_printerr("Warning: Unable to register XPath extension function " "\"unbalanced-braces\" for URI \"%s\"\n", FREEDICT_EDITOR_NAMESPACE); xmlXPathParserContextPtr pctxt2; if(!pctxt) pctxt = &pctxt2; xmlXPathObjectPtr xpobj = my_xmlXPathEvalExpression((xmlChar *) xpath, ctxt, pctxt); if(!xpobj) { g_printerr(G_STRLOC ": No XPathObject!\n"); xmlXPathFreeContext(ctxt); return NULL; } if(!(xpobj->nodesetval)) { g_printerr(G_STRLOC ": No nodeset!\n"); xmlXPathFreeObject(xpobj); xmlXPathFreeContext(ctxt); return NULL; } if(!(xpobj->nodesetval->nodeNr)) { //g_printerr("0 nodes!\n"); xmlXPathFreeObject(xpobj); xmlXPathFreeContext(ctxt); return NULL; } xmlXPathFreeContext(ctxt); xmlNodeSetPtr nodes = xmlMalloc(sizeof(xmlNodeSet)); // XXX copying is slow... memcpy(nodes, xpobj->nodesetval, sizeof(xmlNodeSet)); // I don't understand the naming of this function. According to the // documentation, it frees xpobj, but not its nodelist, if it // contained one. So it should be called xmlXPathFreeObjectButNotNodeSetList(). xmlXPathFreeNodeSetList(xpobj); return nodes; }
xmlGlobalStatePtr xmlNewGlobalState(void) { xmlGlobalStatePtr retval; retval=(xmlGlobalStatePtr)(xmlMalloc(sizeof(xmlGlobalState))); xmlInitializeGlobalState(retval); return retval; }
/* * xmlCreateEntity: * * internal routine doing the entity node strutures allocations */ static xmlEntityPtr xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type, const xmlChar *ExternalID, const xmlChar *SystemID, const xmlChar *content) { xmlEntityPtr ret; ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); if (ret == NULL) { xmlEntitiesErrMemory("xmlCreateEntity: malloc failed"); return(NULL); } memset(ret, 0, sizeof(xmlEntity)); ret->type = XML_ENTITY_DECL; ret->checked = 0; /* * fill the structure. */ ret->etype = (xmlEntityType) type; if (dict == NULL) { ret->name = xmlStrdup(name); if (ExternalID != NULL) ret->ExternalID = xmlStrdup(ExternalID); if (SystemID != NULL) ret->SystemID = xmlStrdup(SystemID); } else { ret->name = xmlDictLookup(dict, name, -1); if (ExternalID != NULL) ret->ExternalID = xmlDictLookup(dict, ExternalID, -1); if (SystemID != NULL) ret->SystemID = xmlDictLookup(dict, SystemID, -1); } if (content != NULL) { ret->length = xmlStrlen(content); if ((dict != NULL) && (ret->length < 5)) ret->content = (xmlChar *) xmlDictLookup(dict, content, ret->length); else 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; return(ret); }
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)); }
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)); }
/* * xmlDictAddQString: * @dict: the dictionary * @prefix: the prefix of the userdata * @plen: the prefix length * @name: the name of the userdata * @len: the length of the name * * Add the QName to the array[s] * * Returns the pointer of the local string, or NULL in case of error. */ static const xmlChar * xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, unsigned int plen, const xmlChar *name, unsigned int namelen) { xmlDictStringsPtr pool; const xmlChar *ret; size_t size = 0; /* + sizeof(_xmlDictStrings) == 1024 */ size_t limit = 0; if (prefix == NULL) return(xmlDictAddString(dict, name, namelen)); #ifdef DICT_DEBUG_PATTERNS fprintf(stderr, "="); #endif pool = dict->strings; while (pool != NULL) { if (pool->end - pool->free > namelen + plen + 1) goto found_pool; if (pool->size > size) size = pool->size; limit += pool->size; pool = pool->next; } /* * Not found, need to allocate */ if (pool == NULL) { if ((dict->limit > 0) && (limit > dict->limit)) { return(NULL); } if (size == 0) size = 1000; else size *= 4; /* exponential growth */ if (size < 4 * (namelen + plen + 1)) size = 4 * (namelen + plen + 1); /* just in case ! */ pool = (xmlDictStringsPtr) xmlMalloc(sizeof(xmlDictStrings) + size); if (pool == NULL) return(NULL); pool->size = size; pool->nbStrings = 0; pool->free = &pool->array[0]; pool->end = &pool->array[size]; pool->next = dict->strings; dict->strings = pool; #ifdef DICT_DEBUG_PATTERNS fprintf(stderr, "+"); #endif } found_pool: ret = pool->free; memcpy(pool->free, prefix, plen); pool->free += plen; *(pool->free++) = ':'; memcpy(pool->free, name, namelen); pool->free += namelen; *(pool->free++) = 0; pool->nbStrings++; return(ret); }
xmlNodeSetPtr ermXmlGetChildNodeSet(xmlNodePtr parent, const char* childName) { int i; xmlNodeSetPtr nodeSet = NULL; // return value xmlNodePtr cur = NULL; //TRACE("entry: parent [%p] [%s]", parent, parent ? parent->name : NULL); //TRACE("entry: node [%s]", childName); // allocate space for nodeset nodeSet = xmlMalloc( sizeof(xmlNodeSet) ); if (nodeSet == NULL) { return NULL; } nodeSet->nodeNr = 0; nodeSet->nodeMax = 10; nodeSet->nodeTab = xmlMalloc(10 * sizeof(xmlNode)); if (nodeSet->nodeTab == NULL) { return NULL; } if (parent && childName && childName[0] != '\0') { cur = parent->children; while (cur != NULL) { if ( xmlStrcmp(cur->name, (const xmlChar*)childName) == 0 ) { //TRACE("Found child node %s", childName); // extend space for nodeset if (nodeSet->nodeNr >= nodeSet->nodeMax) { i = 2 * nodeSet->nodeMax; nodeSet->nodeMax = i; nodeSet->nodeTab = xmlRealloc(nodeSet->nodeTab, i * sizeof(xmlNode)); if (nodeSet->nodeTab == NULL) { return NULL; } } // add node to nodeset nodeSet->nodeTab[ nodeSet->nodeNr ] = cur; nodeSet->nodeNr++; } cur = cur->next; } } return nodeSet; }
/** * ConvertInput: * @in: string in a given encoding * @encoding: the encoding used * * Converts @in into UTF-8 for processing with libxml2 APIs * * Returns the converted UTF-8 string, or NULL in case of error. */ xmlChar* cpXmlCmdOutput::ConvertInput( const xmlChar* in, const xmlChar* encoding ) { xmlChar *out; int ret; int size; int out_size; int temp; xmlCharEncodingHandlerPtr handler; if ( in == 0 ) return 0; handler = xmlFindCharEncodingHandler( (const char *)encoding ); if ( !handler ) { printf( "ConvertInput: no encoding handler found for '%s'\n", encoding != 0 ? (const char *)encoding : "" ); return 0; } size = (int) strlen( (const char*) in ) + 1; out_size = size * 2 - 1; out = (xmlChar *) xmlMalloc( (size_t) out_size ); if ( out != 0 ) { temp = size - 1; ret = handler->input( out, &out_size, in, &temp ); if ( ( ret < 0 ) || ( temp - size + 1 ) ) { if ( ret < 0 ) { printf( "ConvertInput: conversion wasn't successful.\n" ); } else { printf ( "ConvertInput: conversion wasn't successful. converted: %i octets.\n", temp ); } xmlFree( out ); out = 0; } else { out = (xmlChar *) xmlRealloc( out, out_size + 1 ); out[out_size] = 0; //null termination } } else { printf( "ConvertInput: no mem\n" ); } return out; }
/** * xmlHashUpdateEntry3: * @table: the hash table * @name: the name of the userdata * @name2: a second name of the userdata * @name3: a third name of the userdata * @userdata: a pointer to the userdata * @f: the deallocator function for replaced item (if any) * * Add the @userdata to the hash @table. This can later be retrieved * by using the tuple (@name, @name2, @name3). Existing entry for this tuple * will be removed and freed with @f if found. * * Returns 0 the addition succeeded and -1 in case of error. */ int xmlHashUpdateEntry3(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, const xmlChar *name3, void *userdata, xmlHashDeallocator f) { unsigned long key; xmlHashEntryPtr entry; xmlHashEntryPtr insert; if ((table == NULL) || name == NULL) return(-1); /* * Check for duplicate and insertion location. */ key = xmlHashComputeKey(table, name, name2, name3); if (table->table[key] == NULL) { insert = NULL; } else { for (insert = table->table[key]; insert->next != NULL; insert = insert->next) { if ((xmlStrEqual(insert->name, name)) && (xmlStrEqual(insert->name2, name2)) && (xmlStrEqual(insert->name3, name3))) { if (f) f(insert->payload, insert->name); insert->payload = userdata; return(0); } } if ((xmlStrEqual(insert->name, name)) && (xmlStrEqual(insert->name2, name2)) && (xmlStrEqual(insert->name3, name3))) { if (f) f(insert->payload, insert->name); insert->payload = userdata; return(0); } } entry = xmlMalloc(sizeof(xmlHashEntry)); if (entry == NULL) return(-1); entry->name = xmlStrdup(name); entry->name2 = xmlStrdup(name2); entry->name3 = xmlStrdup(name3); entry->payload = userdata; entry->next = NULL; table->nbElems++; if (insert == NULL) { table->table[key] = entry; } else { insert->next = entry; } return(0); }
/** * xmlSchematronAddRule: * @ctxt: the schema parsing context * @schema: a schema structure * @node: the node hosting the rule * @context: the associated context string * @report: the associated report string * * Add a rule to a schematron * * Returns the new pointer or NULL in case of error */ static xmlSchematronRulePtr xmlSchematronAddRule(xmlSchematronParserCtxtPtr ctxt, xmlSchematronPtr schema, xmlSchematronPatternPtr pat, xmlNodePtr node, xmlChar *context, xmlChar *report) { xmlSchematronRulePtr ret; xmlPatternPtr pattern; if ((ctxt == NULL) || (schema == NULL) || (node == NULL) || (context == NULL)) return(NULL); /* * Try first to compile the pattern */ pattern = xmlPatterncompile(context, ctxt->dict, XML_PATTERN_XPATH, ctxt->namespaces); if (pattern == NULL) { xmlSchematronPErr(ctxt, node, XML_SCHEMAP_NOROOT, "Failed to compile context expression %s", context, NULL); } ret = (xmlSchematronRulePtr) xmlMalloc(sizeof(xmlSchematronRule)); if (ret == NULL) { xmlSchematronPErrMemory(ctxt, "allocating schema rule", node); return (NULL); } memset(ret, 0, sizeof(xmlSchematronRule)); ret->node = node; ret->context = context; ret->pattern = pattern; ret->report = report; ret->next = NULL; if (schema->rules == NULL) { schema->rules = ret; } else { xmlSchematronRulePtr prev = schema->rules; while (prev->next != NULL) prev = prev->next; prev->next = ret; } ret->patnext = NULL; if (pat->rules == NULL) { pat->rules = ret; } else { xmlSchematronRulePtr prev = pat->rules; while (prev->patnext != NULL) prev = prev->patnext; prev->patnext = ret; } return (ret); }
static void _build_entity(const xmlChar *name, int len, xmlChar **entity, int *entity_len) { *entity_len = len + 2; *entity = xmlMalloc(*entity_len + 1); (*entity)[0] = '&'; memcpy(*entity+1, name, len); (*entity)[len+1] = ';'; (*entity)[*entity_len] = '\0'; }
/** * xmlHashCreate: * @size: the size of the hash table * * Create a new xmlHashTablePtr. * * Returns the newly created object, or NULL if an error occured. */ xmlHashTablePtr xmlHashCreate(int size) { xmlHashTablePtr table; if (size <= 0) size = 256; table = xmlMalloc(sizeof(xmlHashTable)); if (table) { table->size = size; table->nbElems = 0; table->table = xmlMalloc(size * sizeof(xmlHashEntryPtr)); if (table->table) { memset(table->table, 0, size * sizeof(xmlHashEntryPtr)); return(table); } xmlFree(table); } return(NULL); }
/** * xmlHashAddEntry3: * @table: the hash table * @name: the name of the userdata * @name2: a second name of the userdata * @name3: a third name of the userdata * @userdata: a pointer to the userdata * * Add the @userdata to the hash @table. This can later be retrieved * by using the tuple (@name, @name2, @name3). Duplicate entries generate * errors. * * Returns 0 the addition succeeded and -1 in case of error. */ int xmlHashAddEntry3(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, const xmlChar *name3, void *userdata) { unsigned long key, len = 0; xmlHashEntryPtr entry; xmlHashEntryPtr insert; if ((table == NULL) || name == NULL) return(-1); /* * Check for duplicate and insertion location. */ key = xmlHashComputeKey(table, name, name2, name3); if (table->table[key] == NULL) { insert = NULL; } else { for (insert = table->table[key]; insert->next != NULL; insert = insert->next) { if ((xmlStrEqual(insert->name, name)) && (xmlStrEqual(insert->name2, name2)) && (xmlStrEqual(insert->name3, name3))) return(-1); len++; } if ((xmlStrEqual(insert->name, name)) && (xmlStrEqual(insert->name2, name2)) && (xmlStrEqual(insert->name3, name3))) return(-1); } entry = xmlMalloc(sizeof(xmlHashEntry)); if (entry == NULL) return(-1); entry->name = xmlStrdup(name); entry->name2 = xmlStrdup(name2); entry->name3 = xmlStrdup(name3); entry->payload = userdata; entry->next = NULL; if (insert == NULL) { table->table[key] = entry; } else { insert->next = entry; } table->nbElems++; if (len > MAX_HASH_LEN) xmlHashGrow(table, MAX_HASH_LEN * table->size); return(0); }