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)); }
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); }
/** * lineNoItemAdd: * @breakPointHash: is valid * @breakPtr: is valid * * Returns 1 if able to add @breakPtr to @breakPointHash, * 0 otherwise */ int lineNoItemAdd(xmlHashTablePtr breakPointHash, breakPointPtr breakPtr) { int result = 0; if (breakPointHash && breakPtr) { if (xmlHashAddEntry(breakPointHash, breakPtr->url, breakPtr) == 0) result = 1; } return result; }
static void cache_copy(void* data, void* dest, xmlChar* name) { schema_cache* This = (schema_cache*) dest; cache_entry* entry = (cache_entry*) data; if (xmlHashLookup(This->cache, name) == NULL) { cache_entry_add_ref(entry); xmlHashAddEntry(This->cache, name, entry); } }
static xar_file_t xar_link_lookup(xar_t x, dev_t dev, ino_t ino, xar_file_t f) { char key[32]; xar_file_t ret; memset(key, 0, sizeof(key)); snprintf(key, sizeof(key)-1, "%08" DEV_HEXSTRING "%08" INO_HEXSTRING, DEV_CAST dev, INO_CAST ino); ret = xmlHashLookup(XAR(x)->ino_hash, BAD_CAST(key)); if( ret == NULL ) { xmlHashAddEntry(XAR(x)->ino_hash, BAD_CAST(key), XAR_FILE(f)); return NULL; } return ret; }
/* * 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) { xmlDictPtr dict = NULL; xmlEntitiesTablePtr table = NULL; xmlEntityPtr ret; if (name == NULL) return(NULL); if (dtd == NULL) return(NULL); if (dtd->doc != NULL) dict = dtd->doc->dict; 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 = xmlHashCreateDict(0, dict); table = dtd->entities; break; case XML_INTERNAL_PARAMETER_ENTITY: case XML_EXTERNAL_PARAMETER_ENTITY: if (dtd->pentities == NULL) dtd->pentities = xmlHashCreateDict(0, dict); table = dtd->pentities; break; case XML_INTERNAL_PREDEFINED_ENTITY: return(NULL); } if (table == NULL) return(NULL); ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content); if (ret == NULL) return(NULL); ret->doc = dtd->doc; if (xmlHashAddEntry(table, name, ret)) { /* * entity was already defined at another level. */ xmlFreeEntity(ret); return(NULL); } return(ret); }
boxdir * boxtree_add_folder(const char * path, const char * id, jobj * folder) { boxdir * aDir; boxfile * aFile, * part; list_iter it, pit; jobj * obj, *item; char * type; aDir = boxdir_create(); aDir->id = strdup(id); if(options.verbose) syslog(LOG_DEBUG, "Adding %s", path); obj = jobj_get(folder, "entries"); it = list_get_iter(obj->children); for(; it; it = list_iter_next(it)) { item = list_iter_getval(it); aFile = obj_to_file(item); type = jobj_getval(item, "type"); if(!strcmp(type,"folder")) list_append(aDir->folders, aFile); else { if(options.splitfiles && ends_with(aFile->name, PART_SUFFIX)) list_insert_sorted_comp(aDir->pieces, aFile, filename_compare); else list_append(aDir->files, aFile); } free(type); } if(options.splitfiles) { it = list_get_iter(aDir->files); pit = list_get_iter(aDir->pieces); for(; pit; pit = list_iter_next(pit)) { part = (boxfile*)list_iter_getval(pit); find_file_for_part(part->name, &it); if(it) { aFile = (boxfile*)list_iter_getval(it); aFile->size+=part->size; } else { syslog(LOG_WARNING, "Stale file part %s found", part->name ); it = list_get_iter(aDir->files); } } } xmlHashAddEntry(allDirs, path, aDir); return aDir; }
/*********************************** * Function Name: Xml_Register_Modset * Desription : This functions Register Modset entry to Hash Table * Input : pModsetName - Modset Name * funptr - Call back function pointer * Output : Success or Failure * Return Value : None ***************************************/ t_int32 Xml_Register_Modset (t_char8 * pModsetName, t_void * funptr) { int val; XML_DebugArg ("pModsetName =", pModsetName); if (hTable == NULL) { XML_Debug ("Xml Module Hash Table does not exist"); return -1; } val = xmlHashAddEntry (hTable, pModsetName, funptr); if (val != 0) { XML_DebugArg (pModsetName, "is already exist in Hash"); return -1; } return 0; }
/* * This is called by annotation_callback() in xmlschemas.c when an * annotation is encountered while reading the schema. */ xmlNotifyValidatedElement* schema_annotation_callback(void *handle, xmlNodePtr node) { xmlChar* content = xmlNodeGetContent(node); char* key; if (node->ns == NULL || !xmlStrEqual(BAD_CAST "myNamespace", node->ns->href) || !xmlStrEqual(BAD_CAST "path", node->name)) return NULL; printf("\noooooooooooo %s: %p \"%s\"\n", __FUNCTION__, handle, content); /* dump_doc(node->doc, node); */ walk_doc_tree(node, 0); printf("\n"); key = xmlMalloc(20); sprintf(key, "%p", handle); xmlHashAddEntry(Handle2Path, (xmlChar*)key, content); return &instance_annotation_callback; }
static void cache_add_entry(schema_cache *cache, const xmlChar *uri, cache_entry *entry) { int i; /* meaning no entry found with this name */ if (xmlHashRemoveEntry(cache->cache, uri, cache_free)) { if (cache->count == cache->allocated) { cache->allocated *= 2; cache->uris = heap_realloc(cache->uris, cache->allocated*sizeof(xmlChar*)); } i = cache->count++; } else i = cache_free_uri(cache, uri); cache->uris[i] = heap_strdupxmlChar(uri); xmlHashAddEntry(cache->cache, uri, entry); }
/*********************************************************************** * Function Name: CNTRLXMLRegisterModsets * Desription : This functions Register Modset entry to Hash Table * Input : pModsetName - Modset Name * funptr - Call back function pointer * Output : Success or Failure * Return Value : None ***********************************************************************/ t_int32 CNTRLXMLRegisterModsets (t_char8 * pModsetName, t_void * strPtr) { int val; XML_DebugArg ("pModsetName = ", pModsetName); if (pModSetTable == NULL) { XML_Error ("Xml Module Hash Table does not exist"); return CNTRLXML_FAILURE; } val = xmlHashAddEntry (pModSetTable, pModsetName, strPtr); if (val != 0) { XML_DebugArg (pModsetName, "is already exist in Hash"); return CNTRLXML_FAILURE; } return CNTRLXML_SUCCESS; }
// Move a dir to another path in the tree, // recursively updating all the child entries in allDirs void boxtree_movedir(const char * from, const char * to) { boxdir * aDir = xmlHashLookup(allDirs, from); list_iter it; char * newfrom, * newto, *name; if(!aDir) { syslog(LOG_ERR, "no such directory %s", from); return; } for (it=list_get_iter(aDir->folders); it; it = list_iter_next(it)) { name = ((boxfile*)list_iter_getval(it))->name; newfrom = pathappend(from, name); newto = pathappend(to, name); boxtree_movedir(newfrom, newto); free(newfrom); free(newto); } //LOCKDIR(aDir); xmlHashRemoveEntry(allDirs, from, NULL); xmlHashAddEntry(allDirs, to, aDir); //UNLOCKDIR(aDir); }
/** * 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); }
static struct hash_val_t *findncreate_arr_by_idx(ourfa_hash_t *h, enum ourfa_elm_type_t type, const char *key, const char *arr_idx, unsigned do_not_create, unsigned *last_idx_res ) { int i; unsigned last_idx; struct hash_val_t *hval; unsigned idx_list[20]; int idx_list_cnt; if (do_not_create) assert(type == 0); if (h == NULL || key == NULL) return NULL; if (arr_idx == NULL || arr_idx[0]=='\0') arr_idx="0"; idx_list_cnt = ourfa_hash_parse_idx_list(h, arr_idx, &idx_list[0], sizeof(idx_list)/sizeof(idx_list[0])); if (idx_list_cnt <= 0) return NULL; hval = xmlHashLookup(h, (const xmlChar *)key); if (hval == NULL) { if (do_not_create) return NULL; else { /* Create new array */ if (idx_list_cnt == 1) { hval = hash_val_new(type, idx_list[0]); } else hval = hash_val_new(OURFA_ELM_ARRAY, idx_list[0]); if (hval == NULL) return NULL; if (xmlHashAddEntry(h, (const xmlChar *)key, hval) != 0) { hash_val_free(hval); return NULL; } } } assert(hval != NULL); /* create interrim arrays */ for (i=0; i<idx_list_cnt-1; i++) { unsigned cur_idx; cur_idx = idx_list[i]; if (hval->type != OURFA_ELM_ARRAY) { if (do_not_create) return NULL; /* Replace old value */ hash_val_clear(hval); assert(hval->data == NULL); assert(hval->data_pool_size == 0); hval->type=OURFA_ELM_ARRAY; } /* Increase data pool */ if (hval->data_pool_size <= cur_idx) { if (do_not_create) return NULL; if (increase_pool_size(hval, cur_idx-hval->data_pool_size+1)) return NULL; } /* Init interim elements */ if (hval->elm_cnt <= cur_idx) { unsigned j; if (do_not_create) return NULL; for (j=hval->elm_cnt; j <= cur_idx; j++) ((struct hash_val_t **)hval->data)[j] = NULL; hval->elm_cnt = cur_idx+1; } assert(hval->data_pool_size > cur_idx); if ( ((struct hash_val_t **)hval->data)[cur_idx] == NULL) { if (do_not_create) return NULL; ((struct hash_val_t **)hval->data)[cur_idx] = hash_val_new( i == idx_list_cnt-2 ? type : OURFA_ELM_ARRAY, idx_list[i+1]+1); } hval = ((struct hash_val_t **)hval->data)[cur_idx]; if (hval == NULL) return NULL; } /* Init last array */ last_idx = idx_list[idx_list_cnt-1]; /* Increase data pool */ if (hval->data_pool_size <= last_idx) { if (do_not_create) return NULL; if (increase_pool_size(hval, last_idx-hval->data_pool_size+1)) return NULL; } if (last_idx_res != NULL) *last_idx_res = last_idx; return hval; }
int32_t xar_attrcopy_to_heap(xar_t x, xar_file_t f, xar_prop_t p, read_callback rcb, void *context) { int modulecount = (sizeof(xar_datamods)/sizeof(struct datamod)); void *modulecontext[modulecount]; int r, off, i; size_t bsize, rsize; int64_t readsize=0, writesize=0, inc = 0; void *inbuf; char *tmpstr = NULL; const char *opt, *csum; off_t orig_heap_offset = XAR(x)->heap_offset; xar_file_t tmpf = NULL; xar_prop_t tmpp = NULL; memset(modulecontext, 0, sizeof(void*)*modulecount); opt = xar_opt_get(x, XAR_OPT_RSIZE); if( !opt ) { bsize = 4096; } else { bsize = strtol(opt, NULL, 0); if( ((bsize == LONG_MAX) || (bsize == LONG_MIN)) && (errno == ERANGE) ) { bsize = 4096; } } r = 1; while(r != 0) { inbuf = malloc(bsize); if( !inbuf ) return -1; r = rcb(x, f, inbuf, bsize, context); if( r < 0 ) { free(inbuf); return -1; } readsize+=r; inc += r; rsize = r; /* filter the data through the in modules */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_in ) { xar_datamods[i].th_in(x, f, p, &inbuf, &rsize, &(modulecontext[i])); } } /* filter the data through the out modules */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_out ) xar_datamods[i].th_out(x, f, p, inbuf, rsize, &(modulecontext[i])); } off = 0; if( rsize != 0 ) { do { r = write(XAR(x)->heap_fd, inbuf+off, rsize-off); if( (r < 0) && (errno != EINTR) ) return -1; off += r; writesize += r; } while( off < rsize ); } XAR(x)->heap_offset += off; free(inbuf); } /* If size is 0, don't bother having anything in the heap */ if( readsize == 0 ) { XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_done ) xar_datamods[i].th_done(x, f, p, &(modulecontext[i])); } return 0; } /* finish up anything that still needs doing */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_done ) xar_datamods[i].th_done(x, f, p, &(modulecontext[i])); } XAR(x)->heap_len += writesize; tmpp = xar_prop_pget(p, "archived-checksum"); if( tmpp ) csum = xar_prop_getvalue(tmpp); tmpf = xmlHashLookup(XAR(x)->csum_hash, BAD_CAST(csum)); if( tmpf ) { const char *attr = xar_prop_getkey(p); opt = xar_opt_get(x, XAR_OPT_LINKSAME); if( opt && (strcmp(attr, "data") == 0) ) { const char *id = xar_attr_pget(tmpf, NULL, "id"); xar_prop_pset(f, NULL, "type", "hardlink"); tmpp = xar_prop_pfirst(f); if( tmpp ) tmpp = xar_prop_find(tmpp, "type"); if( tmpp ) xar_attr_pset(f, tmpp, "link", id); xar_prop_pset(tmpf, NULL, "type", "hardlink"); tmpp = xar_prop_pfirst(tmpf); if( tmpp ) tmpp = xar_prop_find(tmpp, "type"); if( tmpp ) xar_attr_pset(tmpf, tmpp, "link", "original"); tmpp = xar_prop_pfirst(f); if( tmpp ) tmpp = xar_prop_find(tmpp, "data"); xar_prop_punset(f, tmpp); XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); XAR(x)->heap_len -= writesize; return 0; } opt = xar_opt_get(x, XAR_OPT_COALESCE); if( opt ) { long long tmpoff; const char *offstr = NULL; tmpp = xar_prop_pfirst(tmpf); if( tmpp ) { const char *key; key = xar_prop_getkey(p); tmpp = xar_prop_find(tmpp, key); } if( tmpp ) tmpp = xar_prop_pget(tmpp, "offset"); if( tmpp ) offstr = xar_prop_getvalue(tmpp); if( offstr ) { tmpoff = strtoll(offstr, NULL, 10); XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); orig_heap_offset = tmpoff; XAR(x)->heap_len -= writesize; } } } else { xmlHashAddEntry(XAR(x)->csum_hash, BAD_CAST(csum), XAR_FILE(f)); } asprintf(&tmpstr, "%"PRIu64, readsize); xar_prop_pset(f, p, "size", tmpstr); free(tmpstr); asprintf(&tmpstr, "%"PRIu64, (uint64_t)orig_heap_offset); xar_prop_pset(f, p, "offset", tmpstr); free(tmpstr); tmpstr = (char *)xar_opt_get(x, XAR_OPT_COMPRESSION); if( tmpstr && (strcmp(tmpstr, XAR_OPT_VAL_NONE) == 0) ) { xar_prop_pset(f, p, "encoding", NULL); tmpp = xar_prop_pget(p, "encoding"); if( tmpp ) xar_attr_pset(f, tmpp, "style", "application/octet-stream"); } asprintf(&tmpstr, "%"PRIu64, writesize); xar_prop_pset(f, p, "length", tmpstr); free(tmpstr); return 0; }
/** * xsltInitCtxtKey: * @ctxt: an XSLT transformation context * @idoc: the document information (holds key values) * @keyDef: the key definition * * Computes the key tables this key and for the current input document. * * Returns: 0 on success, -1 on error */ int xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr idoc, xsltKeyDefPtr keyDef) { int i, len, k; xmlNodeSetPtr matchList = NULL, keylist; xmlXPathObjectPtr matchRes = NULL, useRes = NULL; xmlChar *str = NULL; xsltKeyTablePtr table; xmlNodePtr oldInst, cur; xmlNodePtr oldContextNode; xsltDocumentPtr oldDocInfo; int oldXPPos, oldXPSize; xmlDocPtr oldXPDoc; int oldXPNsNr; xmlNsPtr *oldXPNamespaces; xmlXPathContextPtr xpctxt; #ifdef KEY_INIT_DEBUG fprintf(stderr, "xsltInitCtxtKey %s : %d\n", keyDef->name, ctxt->keyInitLevel); #endif if ((keyDef->comp == NULL) || (keyDef->usecomp == NULL)) return(-1); /* * Detect recursive keys */ if (ctxt->keyInitLevel > ctxt->nbKeys) { #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS, xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: key definition of %s is recursive\n", keyDef->name)); #endif xsltTransformError(ctxt, NULL, keyDef->inst, "Key definition for %s is recursive\n", keyDef->name); ctxt->state = XSLT_STATE_STOPPED; return(-1); } ctxt->keyInitLevel++; xpctxt = ctxt->xpathCtxt; idoc->nbKeysComputed++; /* * Save context state. */ oldInst = ctxt->inst; oldDocInfo = ctxt->document; oldContextNode = ctxt->node; oldXPDoc = xpctxt->doc; oldXPPos = xpctxt->proximityPosition; oldXPSize = xpctxt->contextSize; oldXPNsNr = xpctxt->nsNr; oldXPNamespaces = xpctxt->namespaces; /* * Set up contexts. */ ctxt->document = idoc; ctxt->node = (xmlNodePtr) idoc->doc; ctxt->inst = keyDef->inst; xpctxt->doc = idoc->doc; xpctxt->node = (xmlNodePtr) idoc->doc; /* TODO : clarify the use of namespaces in keys evaluation */ xpctxt->namespaces = keyDef->nsList; xpctxt->nsNr = keyDef->nsNr; /* * Evaluate the 'match' expression of the xsl:key. * TODO: The 'match' is a *pattern*. */ matchRes = xmlXPathCompiledEval(keyDef->comp, xpctxt); if (matchRes == NULL) { #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluation failed\n", keyDef->match)); #endif xsltTransformError(ctxt, NULL, keyDef->inst, "Failed to evaluate the 'match' expression.\n"); ctxt->state = XSLT_STATE_STOPPED; goto error; } else { if (matchRes->type == XPATH_NODESET) { matchList = matchRes->nodesetval; #ifdef WITH_XSLT_DEBUG_KEYS if (matchList != NULL) XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluates to %d nodes\n", keyDef->match, matchList->nodeNr)); #endif } else { /* * Is not a node set, but must be. */ #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s is not a node set\n", keyDef->match)); #endif xsltTransformError(ctxt, NULL, keyDef->inst, "The 'match' expression did not evaluate to a node set.\n"); ctxt->state = XSLT_STATE_STOPPED; goto error; } } if ((matchList == NULL) || (matchList->nodeNr <= 0)) goto exit; /** * Multiple key definitions for the same name are allowed, so * we must check if the key is already present for this doc */ table = (xsltKeyTablePtr) idoc->keys; while (table != NULL) { if (xmlStrEqual(table->name, keyDef->name) && (((keyDef->nameURI == NULL) && (table->nameURI == NULL)) || ((keyDef->nameURI != NULL) && (table->nameURI != NULL) && (xmlStrEqual(table->nameURI, keyDef->nameURI))))) break; table = table->next; } /** * If the key was not previously defined, create it now and * chain it to the list of keys for the doc */ if (table == NULL) { table = xsltNewKeyTable(keyDef->name, keyDef->nameURI); if (table == NULL) goto error; table->next = idoc->keys; idoc->keys = table; } /* * SPEC XSLT 1.0 (XSLT 2.0 does not clarify the context size!) * "...the use attribute of the xsl:key element is evaluated with x as " the current node and with a node list containing just x as the * current node list" */ xpctxt->contextSize = 1; xpctxt->proximityPosition = 1; for (i = 0; i < matchList->nodeNr; i++) { cur = matchList->nodeTab[i]; if (! IS_XSLT_REAL_NODE(cur)) continue; xpctxt->node = cur; /* * Process the 'use' of the xsl:key. * SPEC XSLT 1.0: * "The use attribute is an expression specifying the values of * the key; the expression is evaluated once for each node that * matches the pattern." */ if (useRes != NULL) xmlXPathFreeObject(useRes); useRes = xmlXPathCompiledEval(keyDef->usecomp, xpctxt); if (useRes == NULL) { xsltTransformError(ctxt, NULL, keyDef->inst, "Failed to evaluate the 'use' expression.\n"); ctxt->state = XSLT_STATE_STOPPED; break; } if (useRes->type == XPATH_NODESET) { if ((useRes->nodesetval != NULL) && (useRes->nodesetval->nodeNr != 0)) { len = useRes->nodesetval->nodeNr; str = xmlXPathCastNodeToString(useRes->nodesetval->nodeTab[0]); } else { continue; } } else { len = 1; if (useRes->type == XPATH_STRING) { /* * Consume the string value. */ str = useRes->stringval; useRes->stringval = NULL; } else { str = xmlXPathCastToString(useRes); } } /* * Process all strings. */ k = 0; while (1) { if (str == NULL) goto next_string; #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsl:key : node associated to ('%s', '%s')\n", keyDef->name, str)); #endif keylist = xmlHashLookup(table->keys, str); if (keylist == NULL) { keylist = xmlXPathNodeSetCreate(cur); if (keylist == NULL) goto error; xmlHashAddEntry(table->keys, str, keylist); } else { /* * TODO: How do we know if this function failed? */ xmlXPathNodeSetAdd(keylist, cur); } switch (cur->type) { case XML_ELEMENT_NODE: case XML_TEXT_NODE: case XML_CDATA_SECTION_NODE: case XML_PI_NODE: case XML_COMMENT_NODE: cur->psvi = keyDef; break; case XML_ATTRIBUTE_NODE: ((xmlAttrPtr) cur)->psvi = keyDef; break; case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: ((xmlDocPtr) cur)->psvi = keyDef; break; default: break; } xmlFree(str); str = NULL; next_string: k++; if (k >= len) break; str = xmlXPathCastNodeToString(useRes->nodesetval->nodeTab[k]); } } exit: error: ctxt->keyInitLevel--; /* * Restore context state. */ xpctxt->doc = oldXPDoc; xpctxt->nsNr = oldXPNsNr; xpctxt->namespaces = oldXPNamespaces; xpctxt->proximityPosition = oldXPPos; xpctxt->contextSize = oldXPSize; ctxt->node = oldContextNode; ctxt->document = oldDocInfo; ctxt->inst = oldInst; if (str) xmlFree(str); if (useRes != NULL) xmlXPathFreeObject(useRes); if (matchRes != NULL) xmlXPathFreeObject(matchRes); return(0); }
PyObject *keysdata_KeyDataIdCreate(PyObject *self, PyObject *args) { PyObject *initialize_obj, *duplicate_obj, *finalize_obj, *generate_obj; PyObject *getType_obj, *getSize_obj, *getIdentifier_obj; PyObject *xmlRead_obj, *xmlWrite_obj, *binRead_obj, *binWrite_obj; PyObject *debugDump_obj, *debugXmlDump_obj; xmlSecSize klassSize; xmlSecSize objSize; const xmlChar *name; xmlSecKeyDataUsage usage; const xmlChar *href; const xmlChar *dataNodeName; const xmlChar *dataNodeNs; /* new KeyDataId */ struct _xmlSecKeyDataKlass *dataId; if (CheckArgs(args, "IISISSSccccccccccccc:keyDataIdCreate")) { if (!PyArg_ParseTuple(args, (char *) "iisisssOOOOOOOOOOOOO:keyDataIdCreate", &klassSize, &objSize, &name, &usage, &href, &dataNodeName, &dataNodeNs, &initialize_obj, &duplicate_obj, &finalize_obj, &generate_obj, &getType_obj, &getSize_obj, &getIdentifier_obj, &xmlRead_obj, &xmlWrite_obj, &binRead_obj, &binWrite_obj, &debugDump_obj, &debugXmlDump_obj)) return NULL; } else return NULL; if (KeyDataInitMethods == NULL && initialize_obj != Py_None) KeyDataInitMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataDuplicateMethods == NULL && duplicate_obj != Py_None) KeyDataDuplicateMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataFinalizeMethods == NULL && finalize_obj != Py_None) KeyDataFinalizeMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataGenerateMethods == NULL && generate_obj != Py_None) KeyDataGenerateMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataGetTypeMethods == NULL && getType_obj != Py_None) KeyDataGetTypeMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataGetSizeMethods == NULL && getSize_obj != Py_None) KeyDataGetSizeMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataGetIdentifierMethods == NULL && getIdentifier_obj != Py_None) KeyDataGetIdentifierMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataXmlReadMethods == NULL && xmlRead_obj != Py_None) KeyDataXmlReadMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataXmlWriteMethods == NULL && xmlWrite_obj != Py_None) KeyDataXmlWriteMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataBinReadMethods == NULL && binRead_obj != Py_None) KeyDataBinReadMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataBinWriteMethods == NULL && binWrite_obj != Py_None) KeyDataBinWriteMethods = xmlHashCreate(HASH_TABLE_SIZE); if (KeyDataDebugDumpMethods == NULL && (debugDump_obj != Py_None || debugXmlDump_obj != Py_None)) KeyDataDebugDumpMethods = xmlHashCreate(HASH_TABLE_SIZE * 2); if (initialize_obj != Py_None) xmlHashAddEntry(KeyDataInitMethods, name, initialize_obj); if (duplicate_obj != Py_None) xmlHashAddEntry(KeyDataDuplicateMethods, name, duplicate_obj); if (finalize_obj != Py_None) xmlHashAddEntry(KeyDataFinalizeMethods, name, finalize_obj); if (generate_obj != Py_None) xmlHashAddEntry(KeyDataGenerateMethods, name, generate_obj); if (getType_obj != Py_None) xmlHashAddEntry(KeyDataGetTypeMethods, name, getType_obj); if (getSize_obj != Py_None) xmlHashAddEntry(KeyDataGetSizeMethods, name, getSize_obj); if (getIdentifier_obj != Py_None) xmlHashAddEntry(KeyDataGetIdentifierMethods, name, getIdentifier_obj); if (xmlRead_obj != Py_None) xmlHashAddEntry(KeyDataXmlReadMethods, name, xmlRead_obj); if (xmlWrite_obj != Py_None) xmlHashAddEntry(KeyDataXmlWriteMethods, name, xmlWrite_obj); if (binRead_obj != Py_None) xmlHashAddEntry(KeyDataBinReadMethods, name, binRead_obj); if (binWrite_obj != Py_None) xmlHashAddEntry(KeyDataBinWriteMethods, name, binWrite_obj); if (debugDump_obj != Py_None) xmlHashAddEntry(KeyDataDebugDumpMethods, name, debugDump_obj); if (debugXmlDump_obj != Py_None) xmlHashAddEntry(KeyDataDebugDumpMethods, name, debugXmlDump_obj); dataId = xmlMalloc(sizeof(xmlSecKeyDataKlass)); /* FIXME dataId->klassSize = klassSize; dataId->objSize = objSize; */ dataId->klassSize = sizeof(xmlSecKeyDataKlass); dataId->objSize = sizeof(xmlSecKeyData); dataId->name = name; dataId->usage = usage; dataId->href = href; dataId->dataNodeName = dataNodeName; dataId->dataNodeNs = dataNodeNs; if (initialize_obj != Py_None) dataId->initialize = (xmlSecKeyDataInitMethod)xmlsec_KeyDataInitMethod; else dataId->initialize = NULL; if (duplicate_obj != Py_None) dataId->duplicate = (xmlSecKeyDataDuplicateMethod)xmlsec_KeyDataDuplicateMethod; else dataId->duplicate = NULL; if (finalize_obj != Py_None) dataId->finalize = (xmlSecKeyDataFinalizeMethod)xmlsec_KeyDataFinalizeMethod; else dataId->finalize = NULL; if (generate_obj != Py_None) dataId->generate = (xmlSecKeyDataGenerateMethod)xmlsec_KeyDataGenerateMethod; else dataId->generate = NULL; if (getType_obj != Py_None) dataId->getType = (xmlSecKeyDataGetTypeMethod)xmlsec_KeyDataGetTypeMethod; else dataId->getType = NULL; if (getSize_obj != Py_None) dataId->getSize = (xmlSecKeyDataGetSizeMethod)xmlsec_KeyDataGetSizeMethod; else dataId->getSize = NULL; if (getIdentifier_obj != Py_None) dataId->getIdentifier = (xmlSecKeyDataGetIdentifierMethod)xmlsec_KeyDataGetIdentifierMethod; else dataId->getIdentifier = NULL; if (xmlRead_obj != Py_None) dataId->xmlRead = (xmlSecKeyDataXmlReadMethod)xmlsec_KeyDataXmlReadMethod; else dataId->xmlRead = NULL; if (xmlWrite_obj != Py_None) dataId->xmlWrite = (xmlSecKeyDataXmlWriteMethod)xmlsec_KeyDataXmlWriteMethod; else dataId->xmlWrite = NULL; if (binRead_obj != Py_None) dataId->binRead = (xmlSecKeyDataBinReadMethod)xmlsec_KeyDataBinReadMethod; else dataId->binRead = NULL; if (binWrite_obj != Py_None) dataId->binWrite = (xmlSecKeyDataBinWriteMethod)xmlsec_KeyDataBinWriteMethod; else dataId->binWrite = NULL; if (debugDump_obj != Py_None) dataId->debugDump = (xmlSecKeyDataDebugDumpMethod)xmlsec_KeyDataDebugDumpMethod; else dataId->debugDump = NULL; if (debugXmlDump_obj != Py_None) dataId->debugXmlDump = (xmlSecKeyDataDebugDumpMethod)xmlsec_KeyDataDebugDumpMethod; else dataId->debugXmlDump = NULL; Py_XINCREF(initialize_obj); Py_XINCREF(duplicate_obj); Py_XINCREF(finalize_obj); Py_XINCREF(generate_obj); Py_XINCREF(getType_obj); Py_XINCREF(getSize_obj); Py_XINCREF(getIdentifier_obj); Py_XINCREF(xmlRead_obj); Py_XINCREF(xmlWrite_obj); Py_XINCREF(binRead_obj); Py_XINCREF(binWrite_obj); Py_XINCREF(debugDump_obj); Py_XINCREF(debugXmlDump_obj); return (wrap_xmlSecKeyDataId(dataId)); }
int32_t xar_attrcopy_to_heap(xar_t x, xar_file_t f, xar_prop_t p, read_callback rcb, void *context) { int modulecount = (sizeof(xar_datamods)/sizeof(struct datamod)); void *modulecontext[modulecount]; int r, i; size_t bsize, rsize; int64_t readsize=0, writesize=0, inc = 0, this_write=0; void *inbuf; char *tmpstr = NULL; const char *opt = NULL, *csum = NULL; off_t orig_heap_offset = XAR(x)->heap_offset; xar_file_t tmpf = NULL; xar_prop_t tmpp = NULL; memset(modulecontext, 0, sizeof(void*)*modulecount); bsize = xar_io_get_rsize(x); r = 1; // (Apple) allocate once inbuf = malloc(bsize); if( !inbuf ) return -1; while(r != 0) { r = rcb(x, f, inbuf, bsize, context); if( r < 0 ) { free(inbuf); return -1; } readsize+=r; inc += r; rsize = r; /* filter the data through the in modules */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_in ) { xar_datamods[i].th_in(x, f, p, &inbuf, &rsize, &(modulecontext[i])); } } /* filter the data through the out modules */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_out ) xar_datamods[i].th_out(x, f, p, inbuf, rsize, &(modulecontext[i])); } size_t written = 0; if( rsize != 0 ) { while(written < rsize) { this_write = xar_write_fd(XAR(x)->heap_fd, inbuf, rsize); if( this_write < 0 ) { xar_err_new(x); xar_err_set_string(x, "write(2) error when writing to heap"); xar_err_set_errno(x, errno); xar_err_callback(x, XAR_SEVERITY_FATAL, XAR_ERR_ARCHIVE_CREATION); free(inbuf); return -1; } written += this_write; } } XAR(x)->heap_offset += written; writesize += written; } free(inbuf); /* If size is 0, don't bother having anything in the heap */ if( readsize == 0 ) { XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_done ) xar_datamods[i].th_done(x, f, p, &(modulecontext[i])); } return 0; } /* finish up anything that still needs doing */ for( i = 0; i < modulecount; i++) { if( xar_datamods[i].th_done ) xar_datamods[i].th_done(x, f, p, &(modulecontext[i])); } XAR(x)->heap_len += writesize; tmpp = xar_prop_pget(p, "archived-checksum"); if( tmpp ) csum = xar_prop_getvalue(tmpp); if( csum ) tmpf = xmlHashLookup(XAR(x)->csum_hash, BAD_CAST(csum)); if( tmpf ) { const char *attr = xar_prop_getkey(p); opt = xar_opt_get(x, XAR_OPT_LINKSAME); if( opt && (strcmp(attr, "data") == 0) ) { const char *id = xar_attr_pget(tmpf, NULL, "id"); xar_prop_pset(f, NULL, "type", "hardlink"); tmpp = xar_prop_pfirst(f); if( tmpp ) tmpp = xar_prop_find(tmpp, "type"); if( tmpp ) xar_attr_pset(f, tmpp, "link", id); xar_prop_pset(tmpf, NULL, "type", "hardlink"); tmpp = xar_prop_pfirst(tmpf); if( tmpp ) tmpp = xar_prop_find(tmpp, "type"); if( tmpp ) xar_attr_pset(tmpf, tmpp, "link", "original"); tmpp = xar_prop_pfirst(f); if( tmpp ) tmpp = xar_prop_find(tmpp, "data"); xar_prop_punset(f, tmpp); XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); XAR(x)->heap_len -= writesize; return 0; } opt = xar_opt_get(x, XAR_OPT_COALESCE); if( opt ) { long long tmpoff; const char *offstr = NULL; tmpp = xar_prop_pfirst(tmpf); if( tmpp ) { const char *key; key = xar_prop_getkey(p); tmpp = xar_prop_find(tmpp, key); } if( tmpp ) tmpp = xar_prop_pget(tmpp, "offset"); if( tmpp ) offstr = xar_prop_getvalue(tmpp); if( offstr ) { tmpoff = strtoll(offstr, NULL, 10); XAR(x)->heap_offset = orig_heap_offset; lseek(XAR(x)->heap_fd, -writesize, SEEK_CUR); orig_heap_offset = tmpoff; XAR(x)->heap_len -= writesize; } } } else if( csum ) { xmlHashAddEntry(XAR(x)->csum_hash, BAD_CAST(csum), XAR_FILE(f)); } else { xar_err_new(x); xar_err_set_file(x, f); xar_err_set_string(x, "No archived-checksum"); xar_err_callback(x, XAR_SEVERITY_WARNING, XAR_ERR_ARCHIVE_CREATION); } asprintf(&tmpstr, "%"PRIu64, readsize); xar_prop_pset(f, p, "size", tmpstr); free(tmpstr); asprintf(&tmpstr, "%"PRIu64, (uint64_t)orig_heap_offset); xar_prop_pset(f, p, "offset", tmpstr); free(tmpstr); tmpstr = (char *)xar_opt_get(x, XAR_OPT_COMPRESSION); if( tmpstr && (strcmp(tmpstr, XAR_OPT_VAL_NONE) == 0) ) { xar_prop_pset(f, p, "encoding", NULL); tmpp = xar_prop_pget(p, "encoding"); if( tmpp ) xar_attr_pset(f, tmpp, "style", "application/octet-stream"); } asprintf(&tmpstr, "%"PRIu64, writesize); xar_prop_pset(f, p, "length", tmpstr); free(tmpstr); return 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 *sprefix; xmlNsPtr sNs; xmlChar *rprefix; xmlNsPtr rNs; sprefix = xsltGetNsProp(node, (const xmlChar *)"stylesheet-prefix", XSLT_NAMESPACE); if (sprefix == NULL) { xsltPrintErrorContext(NULL, style, node); xsltGenericError(xsltGenericErrorContext, "namespace-alias: stylesheet-prefix attribute missing\n"); return; } rprefix = xsltGetNsProp(node, (const xmlChar *)"result-prefix", XSLT_NAMESPACE); if (rprefix == NULL) { xsltPrintErrorContext(NULL, style, node); xsltGenericError(xsltGenericErrorContext, "namespace-alias: result-prefix attribute missing\n"); goto error; } if (xmlStrEqual(sprefix, (const xmlChar *)"#default")) { sNs = xmlSearchNs(node->doc, node, NULL); } else { sNs = xmlSearchNs(node->doc, node, sprefix); } if ((sNs == NULL) || (sNs->href == NULL)) { xsltPrintErrorContext(NULL, style, node); xsltGenericError(xsltGenericErrorContext, "namespace-alias: prefix %s not bound to any namespace\n", sprefix); goto error; } if (xmlStrEqual(rprefix, (const xmlChar *)"#default")) { rNs = xmlSearchNs(node->doc, node, NULL); } else { rNs = xmlSearchNs(node->doc, node, rprefix); } if ((rNs == NULL) || (rNs->href == NULL)) { xsltPrintErrorContext(NULL, style, node); xsltGenericError(xsltGenericErrorContext, "namespace-alias: prefix %s not bound to any namespace\n", rprefix); goto error; } if (style->nsAliases == NULL) style->nsAliases = xmlHashCreate(10); if (style->nsAliases == NULL) { xsltPrintErrorContext(NULL, style, node); xsltGenericError(xsltGenericErrorContext, "namespace-alias: cannot create hash table\n"); goto error; } xmlHashAddEntry((xmlHashTablePtr) style->nsAliases, sNs->href, (void *) rNs->href); error: if (sprefix != NULL) xmlFree(sprefix); if (rprefix != NULL) xmlFree(rprefix); }
static HRESULT WINAPI schema_cache_add(IXMLDOMSchemaCollection2* iface, BSTR uri, VARIANT var) { schema_cache* This = impl_from_IXMLDOMSchemaCollection2(iface); xmlChar* name = xmlChar_from_wchar(uri); TRACE("(%p)->(%s, var(vt %x))\n", This, debugstr_w(uri), V_VT(&var)); switch (V_VT(&var)) { case VT_NULL: { xmlHashRemoveEntry(This->cache, name, cache_free); } break; case VT_BSTR: { xmlChar* url = xmlChar_from_wchar(V_BSTR(&var)); cache_entry* entry = cache_entry_from_url((char const*)url); heap_free(url); if (entry) { cache_entry_add_ref(entry); } else { heap_free(name); return E_FAIL; } xmlHashRemoveEntry(This->cache, name, cache_free); xmlHashAddEntry(This->cache, name, entry); } break; case VT_DISPATCH: { xmlDocPtr doc = NULL; cache_entry* entry; SCHEMA_TYPE type; IXMLDOMNode* domnode = NULL; IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IXMLDOMNode, (void**)&domnode); if (domnode) doc = xmlNodePtr_from_domnode(domnode, XML_DOCUMENT_NODE)->doc; if (!doc) { IXMLDOMNode_Release(domnode); heap_free(name); return E_INVALIDARG; } type = schema_type_from_xmlDocPtr(doc); if (type == SCHEMA_TYPE_XSD) { entry = cache_entry_from_xsd_doc(doc); } else if (type == SCHEMA_TYPE_XDR) { entry = cache_entry_from_xdr_doc(doc); } else { WARN("invalid schema!\n"); entry = NULL; } IXMLDOMNode_Release(domnode); if (entry) { cache_entry_add_ref(entry); } else { heap_free(name); return E_FAIL; } xmlHashRemoveEntry(This->cache, name, cache_free); xmlHashAddEntry(This->cache, name, entry); } break; default: { heap_free(name); return E_INVALIDARG; } } heap_free(name); return S_OK; }
/* * setup_session * * Create a new session for the given handler */ void setup_session(struct handler_args* hargs, xmlHashTablePtr sessions, struct qz_config* conf){ struct session * this_session; // session_id is a number here, a string in the session struct, // and the encrypted contents of the session key, same value for each. uint64_t session_id; this_session = calloc(1, sizeof(struct session)); // Assign a random number that has no zero octets // as the session identifier, then test it. session_id = qzrandom64ch(this_session->session_id); // There is a risk of session id collisions that // is larger than might be hoped from the // birthday paradox. // With around 200 users, the chance of a hash key // collission is around 10^-15. This is on the order // of random bit errors and cosmic ray bit flipping. // With around 6000 users, the chance goes up to // around 10^-6, or once in a million. // Or it could be the NSA is messing with your PRNG, // or it could be your PRNG is setup wrong. // In any case, it is bad and wrong to continue. struct session* test_for_session; test_for_session = xmlHashLookup(sessions, this_session->session_id); if (test_for_session != NULL){ fprintf(hargs->log, "%f %d %s:%d collision in session identifiers - %s\n", gettime(), hargs->request_id, __func__, __LINE__, "terminating application now"); FCGX_FPrintF(hargs->err, "collision in session identifiers - ending program now\n"); exit(49); } if (pthread_mutex_init( &(this_session->session_lock), NULL) != 0){ fprintf(hargs->log, "%f %d %s:%d mutex_init failed\n", gettime(), hargs->request_id, __func__, __LINE__); fflush(hargs->log); free(this_session); return; } make_etag(hargs->session_key, conf->tagger_socket_path, session_id); snprintf(this_session->tagger_socket_path, MAXPATHLEN, "%s", conf->tagger_socket_path); this_session->zero = 0; this_session->is_logged_in = false; this_session->logged_in_time = 0; this_session->logged_out_time = 0; this_session->last_activity_time = time(NULL); this_session->conn = NULL; // 197 is just an arbritrary value. // It is prime, hashes should be a prime size. // These should be in the config file. XXXXXXXXXXXXX this_session->opentables = xmlHashCreate(197); this_session->pgtype_datum = xmlHashCreate(197); this_session->form_tags = xmlHashCreate(197); this_session->form_sets = xmlHashCreate(197); this_session->integrity_token = conf->integrity_token; // index on session_id for crypto etag xmlHashAddEntry(sessions, this_session->session_id, this_session); // cookie path is /qz/ or whatever is used as the base path char* uri_parts[] = {hargs->uri_parts[0],"",NULL}; char* path = build_path(uri_parts); make_cookie(hargs, "session_key", hargs->session_key, path, NULL, 0, false, true); free(path); hargs->session = this_session; fprintf(hargs->log, "%f %d %s:%d setup_session complete\n", gettime(), hargs->request_id, __func__, __LINE__); return; }
/* * 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, EMBED_ERRTXT("xmlAddEntity: out of memory\n")); // TODO: Handle OOM - cannot be distinguished from NULL result of function return(NULL); } memset(ret, 0, sizeof(xmlEntity)); ret->type = XML_ENTITY_DECL; /* * fill the structure. */ // TODO: Multiple xmlStrdup() calls! Avoid memory leaks in OOM!!! 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); }
/** * read file and print element paths */ int parse_xml_file(const char *filename) { int ret, prev_depth = 0; xmlTextReaderPtr reader; for (reader = xmlReaderForFile(filename, NULL, 0);;) { int depth; const xmlChar *name; xmlReaderTypes type; if (!reader) { fprintf(stderr, "couldn't read file '%s'\n", filename); exit(EXIT_BAD_FILE); } ret = xmlTextReaderRead(reader); if (ret <= 0) break; type = xmlTextReaderNodeType(reader); depth = xmlTextReaderDepth(reader); name = xmlTextReaderConstName(reader); if (type != XML_READER_TYPE_ELEMENT) continue; while (curXPath && depth <= prev_depth) { xmlChar *slash = BAD_CAST strrchr((char*) curXPath, '/'); if (slash) *slash = '\0'; prev_depth--; } prev_depth = depth; if (depth > 0) curXPath = xmlStrcat(curXPath, BAD_CAST "/"); curXPath = xmlStrcat(curXPath, name); if (elOps.show_attr) { int have_attr; fprintf(stdout, "%s\n", curXPath); for (have_attr = xmlTextReaderMoveToFirstAttribute(reader); have_attr; have_attr = xmlTextReaderMoveToNextAttribute(reader)) { const xmlChar *aname = xmlTextReaderConstName(reader); fprintf(stdout, "%s/@%s\n", curXPath, aname); } } else if (elOps.show_attr_and_val) { fprintf(stdout, "%s", curXPath); if (xmlTextReaderHasAttributes(reader)) { int have_attr, first = 1; fprintf(stdout, "["); for (have_attr = xmlTextReaderMoveToFirstAttribute(reader); have_attr; have_attr = xmlTextReaderMoveToNextAttribute(reader)) { const xmlChar *aname = xmlTextReaderConstName(reader), *avalue = xmlTextReaderConstValue(reader); char quote; if (!first) fprintf(stdout, " and "); first = 0; quote = xmlStrchr(avalue, '\'')? '"' : '\''; fprintf(stdout, "@%s=%c%s%c", aname, quote, avalue, quote); } fprintf(stdout, "]"); } fprintf(stdout, "\n"); } else if (elOps.sort_uniq) { if ((elOps.check_depth == 0) || (elOps.check_depth != 0 && depth < elOps.check_depth)) { xmlHashAddEntry(uniq, curXPath, (void*) 1); } } else fprintf(stdout, "%s\n", curXPath); } return ret == -1? EXIT_LIB_ERROR : ret; }
/* * 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) { xmlDictPtr dict = NULL; xmlEntitiesTablePtr table = NULL; xmlEntityPtr ret; if (name == NULL) return(NULL); if (dtd == NULL) return(NULL); if (dtd->doc != NULL) dict = dtd->doc->dict; 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 = xmlHashCreateDict(0, dict); table = dtd->entities; break; case XML_INTERNAL_PARAMETER_ENTITY: case XML_EXTERNAL_PARAMETER_ENTITY: if (dtd->pentities == NULL) dtd->pentities = xmlHashCreateDict(0, dict); table = dtd->pentities; break; case XML_INTERNAL_PREDEFINED_ENTITY: return(NULL); } if (table == NULL) return(NULL); ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); if (ret == NULL) { xmlEntitiesErrMemory("xmlAddEntity:: malloc failed"); return(NULL); } memset(ret, 0, sizeof(xmlEntity)); ret->type = XML_ENTITY_DECL; /* * 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; ret->doc = dtd->doc; if (xmlHashAddEntry(table, name, ret)) { /* * entity was already defined at another level. */ xmlFreeEntity(ret); return(NULL); } return(ret); }
/** * xsltInitCtxtKey: * @ctxt: an XSLT transformation context * @doc: an XSLT document * @keyd: the key definition * * Computes the key tables this key and for the current input document. */ int xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc, xsltKeyDefPtr keyd) { int i; xmlNodeSetPtr nodelist = NULL, keylist; xmlXPathObjectPtr res = NULL; xmlChar *str, **list; xsltKeyTablePtr table; int oldPos, oldSize; xmlNodePtr oldInst; xmlNodePtr oldNode; xsltDocumentPtr oldDoc; xmlDocPtr oldXDoc; int oldNsNr; xmlNsPtr *oldNamespaces; doc->nbKeysComputed++; /* * Evaluate the nodelist */ oldXDoc= ctxt->xpathCtxt->doc; oldPos = ctxt->xpathCtxt->proximityPosition; oldSize = ctxt->xpathCtxt->contextSize; oldNsNr = ctxt->xpathCtxt->nsNr; oldNamespaces = ctxt->xpathCtxt->namespaces; oldInst = ctxt->inst; oldDoc = ctxt->document; oldNode = ctxt->node; if (keyd->comp == NULL) goto error; if (keyd->usecomp == NULL) goto error; ctxt->document = doc; ctxt->xpathCtxt->doc = doc->doc; ctxt->xpathCtxt->node = (xmlNodePtr) doc->doc; ctxt->node = (xmlNodePtr) doc->doc; /* TODO : clarify the use of namespaces in keys evaluation */ ctxt->xpathCtxt->namespaces = keyd->nsList; ctxt->xpathCtxt->nsNr = keyd->nsNr; ctxt->inst = keyd->inst; res = xmlXPathCompiledEval(keyd->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldSize; ctxt->xpathCtxt->proximityPosition = oldPos; ctxt->inst = oldInst; if (res != NULL) { if (res->type == XPATH_NODESET) { nodelist = res->nodesetval; #ifdef WITH_XSLT_DEBUG_KEYS if (nodelist != NULL) XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluates to %d nodes\n", keyd->match, nodelist->nodeNr)); #endif } else { #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s is not a node set\n", keyd->match)); #endif goto error; } } else { #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluation failed\n", keyd->match)); #endif ctxt->state = XSLT_STATE_STOPPED; goto error; } /* * for each node in the list evaluate the key and insert the node */ if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) goto error; /** * Multiple key definitions for the same name are allowed, so * we must check if the key is already present for this doc */ table = (xsltKeyTablePtr) doc->keys; while (table != NULL) { if (xmlStrEqual(table->name, keyd->name) && (((keyd->nameURI == NULL) && (table->nameURI == NULL)) || ((keyd->nameURI != NULL) && (table->nameURI != NULL) && (xmlStrEqual(table->nameURI, keyd->nameURI))))) break; table = table->next; } /** * If the key was not previously defined, create it now and * chain it to the list of keys for the doc */ if (table == NULL) { table = xsltNewKeyTable(keyd->name, keyd->nameURI); if (table == NULL) goto error; table->next = doc->keys; doc->keys = table; } for (i = 0;i < nodelist->nodeNr;i++) { if (IS_XSLT_REAL_NODE(nodelist->nodeTab[i])) { ctxt->node = nodelist->nodeTab[i]; list = xsltEvalXPathKeys(ctxt, keyd->usecomp, keyd); if (list != NULL) { int ix = 0; str = list[ix++]; while (str != NULL) { #ifdef WITH_XSLT_DEBUG_KEYS XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsl:key : node associated to(%s,%s)\n", keyd->name, str)); #endif keylist = xmlHashLookup(table->keys, str); if (keylist == NULL) { keylist = xmlXPathNodeSetCreate(nodelist->nodeTab[i]); xmlHashAddEntry(table->keys, str, keylist); } else { xmlXPathNodeSetAdd(keylist, nodelist->nodeTab[i]); } switch (nodelist->nodeTab[i]->type) { case XML_ELEMENT_NODE: case XML_TEXT_NODE: case XML_CDATA_SECTION_NODE: case XML_PI_NODE: case XML_COMMENT_NODE: nodelist->nodeTab[i]->psvi = keyd; break; case XML_ATTRIBUTE_NODE: { xmlAttrPtr attr = (xmlAttrPtr) nodelist->nodeTab[i]; attr->psvi = keyd; break; } case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: { xmlDocPtr kdoc = (xmlDocPtr) nodelist->nodeTab[i]; kdoc->psvi = keyd; break; } default: break; } xmlFree(str); str = list[ix++]; } xmlFree(list); #ifdef WITH_XSLT_DEBUG_KEYS } else { XSLT_TRACE(ctxt,XSLT_TRACE_KEYS,xsltGenericDebug(xsltGenericDebugContext, "xsl:key : use %s failed to return strings\n", keyd->use)); #endif } } } error: ctxt->document = oldDoc; ctxt->xpathCtxt->doc = oldXDoc; ctxt->xpathCtxt->nsNr = oldNsNr; ctxt->xpathCtxt->namespaces = oldNamespaces; ctxt->node = oldNode; if (res != NULL) xmlXPathFreeObject(res); return(0); }