static void stats_set_entity_decode (long handle, const char *name, const char *value) { xmlParserCtxtPtr parser = xmlNewParserCtxt(); if (parser) { xmlChar *decoded = xmlStringDecodeEntities (parser, (const xmlChar *) value, XML_SUBSTITUTE_BOTH, 0, 0, 0); stats_set (handle, name, (void*)decoded); xmlFreeParserCtxt (parser); xmlFree (decoded); return; } stats_set (handle, name, value); }
void utl_xml_get_strn (gchar *name, gchar *sname, gint buffer_size, xmlNodePtr node) { xmlParserCtxtPtr context; xmlChar *key, *out; if ((xmlStrcmp (node->name, (const xmlChar *) name)) == 0) { key = xmlNodeGetContent (node->xmlChildrenNode); context = xmlCreateDocParserCtxt (key); out = (xmlChar*) xmlStringDecodeEntities (context, key, XML_SUBSTITUTE_REF, 0, 0, 0); xmlFreeParserCtxt (context); xmlFree (key); if (out != NULL) { g_strlcpy (sname, (gchar *) out, buffer_size); xmlFree (out); } } }
gchar *__get_node_content_string(xmlNode *node) { if(!node) return NULL; gchar *content = NULL; content = (gchar *)xmlNodeGetContent(node); if(content == NULL) return NULL; xmlParserCtxtPtr parser = xmlNewParserCtxt(); xmlChar *decoded = xmlStringDecodeEntities(parser, (const xmlChar *) content, XML_SUBSTITUTE_REF, 0, 0, 0); xmlFreeParserCtxt(parser); g_free(content); return (gchar*)decoded; }
gboolean _nodes2object(GObject *object, xmlNode *node, gboolean force) { g_assert(object); g_assert(node); xmlNode *cur = NULL; GObject *prop_object; gchar *nodeprop = NULL; xmlChar *decoded; xmlParserCtxtPtr parser; MidgardObject *mobject = NULL; MidgardObject *lobject = NULL; MidgardReflectionProperty *mrp = NULL; const gchar *linktype = NULL; if(MIDGARD_IS_OBJECT(object)) { mobject = MIDGARD_OBJECT(object); MidgardObjectClass *klass = MIDGARD_OBJECT_GET_CLASS(mobject); if(klass) mrp = midgard_reflection_property_new( MIDGARD_DBOBJECT_CLASS(klass)); } gpointer set_from_xml_func = MIDGARD_DBOBJECT_GET_CLASS(object)->dbpriv->set_from_xml_node; if(set_from_xml_func != NULL) { MIDGARD_DBOBJECT_GET_CLASS(object)->dbpriv->set_from_xml_node(MIDGARD_DBOBJECT(object), node); return TRUE; } for (cur = node; cur; cur = cur->next) { if (cur->type == XML_ELEMENT_NODE) { linktype = NULL; GParamSpec *pspec = g_object_class_find_property( G_OBJECT_GET_CLASS(G_OBJECT(object)), (const gchar *)cur->name); if(pspec) { GValue pval = {0, }; g_value_init(&pval, pspec->value_type); if(nodeprop) g_free(nodeprop); nodeprop = (gchar *)xmlNodeGetContent(cur); if(mrp) { if(midgard_reflection_property_is_link( mrp, pspec->name)){ linktype = midgard_reflection_property_get_link_name( mrp, pspec->name); } } /* moved out from mrp condition check to avoid nested indents */ if(linktype && midgard_is_guid( (const gchar *) nodeprop)){ /* Just set property quickly, if property holds a guid */ GType mtype = midgard_reflection_property_get_midgard_type(mrp, pspec->name); if (mtype == MGD_TYPE_GUID) { g_value_unset(&pval); g_object_set(mobject, (const gchar *)cur->name, nodeprop, NULL); continue; } /* we can use nodeprop directly */ lobject = midgard_schema_object_factory_get_object_by_guid ( MIDGARD_DBOBJECT (mobject)->dbpriv->mgd, (const gchar *) nodeprop); if(!lobject && !force){ g_object_unref(mrp); g_value_unset(&pval); midgard_set_error(MGD_OBJECT_CNC (mobject), MGD_GENERIC_ERROR, MGD_ERR_MISSED_DEPENDENCE, " Can not import %s. " "No '%s' object identified by '%s'", G_OBJECT_TYPE_NAME(object), linktype, nodeprop); g_clear_error(&MIDGARD_DBOBJECT (mobject)->dbpriv->mgd->err); return FALSE; } /* When force parameter is set we do not translate guids to ids */ if(force && !lobject && midgard_is_guid( (const gchar *) nodeprop)) { switch(pspec->value_type) { case G_TYPE_UINT: g_value_set_uint(&pval, 0); break; case G_TYPE_INT: g_value_set_int(&pval, 0); break; default: goto set_property_unchecked; break; } g_object_set_property( G_OBJECT(object), (const gchar *) cur->name, &pval); g_value_unset(&pval); continue; } GValue tval = {0, }; g_value_init(&tval, pspec->value_type); g_object_get_property(G_OBJECT(lobject), "id", &tval); if(G_VALUE_TYPE(&pval) == G_TYPE_INT) g_value_transform((const GValue *) &tval, &pval); else g_value_copy((const GValue*) &tval, &pval); g_object_set_property( G_OBJECT(object), (const gchar *) cur->name, &pval); g_value_unset(&pval); g_object_unref(lobject); g_value_unset(&tval); continue; } set_property_unchecked: switch (G_TYPE_FUNDAMENTAL (pspec->value_type)) { case G_TYPE_STRING: parser = xmlNewParserCtxt(); decoded = xmlStringDecodeEntities(parser, (const xmlChar *) nodeprop, XML_SUBSTITUTE_REF, 0, 0, 0); g_value_set_string(&pval, (gchar *)decoded); g_free(decoded); xmlFreeParserCtxt(parser); break; case G_TYPE_INT: if(nodeprop) g_value_set_int(&pval, (gint)atoi((gchar *)nodeprop)); break; case G_TYPE_UINT: if(nodeprop) g_value_set_uint(&pval, (guint)atoi((gchar *)nodeprop)); break; case G_TYPE_FLOAT: g_value_set_float(&pval, (gfloat)atof((gchar *)nodeprop)); break; case G_TYPE_BOOLEAN: g_value_set_boolean(&pval, (gboolean)atoi((gchar*)nodeprop)); break; case G_TYPE_OBJECT: g_object_get(G_OBJECT(object), (const gchar *) cur->name, &prop_object, NULL); if (prop_object) { _nodes2object(prop_object, cur->children, force); g_value_set_object(&pval, prop_object); } else { g_warning ("Failed to unserialize '%s' object property. Expected to be initialized by given '%s' instance", (const gchar *) cur->name, G_OBJECT_TYPE_NAME (object)); } break; default: /* do nothing */ break; } g_object_set_property( G_OBJECT(object), (const gchar *) cur->name, &pval); g_value_unset(&pval); } else { g_warning("Undefined property '%s' for '%s'", cur->name, G_OBJECT_TYPE_NAME(object)); } } } if(nodeprop) g_free(nodeprop); if(mrp) g_object_unref(mrp); return TRUE; }
/* This function replaces processingInstruction */ void mxslt_sax_processing_instruction(void * ctx, const xmlChar * target, const xmlChar * data) { xmlParserCtxtPtr ctxt=(xmlParserCtxtPtr)ctx; mxslt_doc_t * document=(mxslt_get_state()->document); mxslt_pi_style_t * style_pi; mxslt_pi_param_t * param_pi; mxslt_pi_base_t * base_pi; char * type = NULL, * tmp; xmlNodePtr pi; int status; /* WARNING: don't change this array! Look below! */ static const mxslt_attr_search_t xml_stylesheet[] = { { (xmlChar *)"href", mxslt_sizeof_str("href") }, { (xmlChar *)"media", mxslt_sizeof_str("media") }, { (xmlChar *)"type", mxslt_sizeof_str("type") } }; /* WARNING: don't change this array! Look below! */ static const mxslt_attr_search_t mxslt_param[] = { { (xmlChar *)"name", mxslt_sizeof_str("name") }, { (xmlChar *)"value", mxslt_sizeof_str("value") } }; /* WARNING: don't change this array! Look below! */ static const mxslt_attr_search_t mxslt_base[] = { { (xmlChar *)"value", mxslt_sizeof_str("value") } }; /* This array _must_ have the same number of elements * as the array xml_stylesheet */ char * xml_stylesheet_values[] = { NULL, NULL, NULL }; enum xml_stylesheet_types { t_href=0, t_media, t_type }; /* This array _must_ have the same number of elements * as the array mxslt_param */ char * mxslt_param_values[] = { NULL, NULL }; enum mxslt_param_types { t_name=0, t_select }; /* This array _must_ have the same number of elements * as the array mxslt_base */ char * mxslt_base_values[] = { NULL }; enum mxslt_base_types { t_value=0 }; mxslt_doc_debug_print(document, MXSLT_DBG_LIBXML, "processing instruction \"%s\", attributes |%s|\n", target, data); /* Ignore pi when we're parsing the stylesheet */ if(document->flags & MXSLT_STYLE) return; /* Create a new pi node */ pi=xmlNewPI(target, data); if(!pi) return; /* Check if target is a known pi */ switch(target[0]) { case 'x': if(!xmlStrEqual(target+1, (xmlChar *)"xml-stylesheet"+1)) break; /* Get href, type and media from attribute list */ status=mxslt_get_static_attr((char *)data, xml_stylesheet, xml_stylesheet_values, mxslt_sizeof_array(xml_stylesheet)); if(status != MXSLT_OK) { if(xml_stylesheet_values[0]) xfree(xml_stylesheet_values[0]); if(xml_stylesheet_values[1]) xfree(xml_stylesheet_values[1]); if(xml_stylesheet_values[2]) xfree(xml_stylesheet_values[2]); goto error; } if(xml_stylesheet_values[t_type] && xml_stylesheet_values[t_href]) { /* Decode type */ type=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_type], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); /* Skip blanks before type */ for(tmp=type; MXSLT_IS_BLANK(*tmp); tmp++) ; /* compare type string */ if(!strncmp(tmp, "text/xml", mxslt_sizeof_str("text/xml")) || !strncmp(tmp, "text/xsl", mxslt_sizeof_str("text/xsl"))) { /* trailing spaces are allowed */ for(tmp+=mxslt_sizeof_str("text/x?l"); MXSLT_IS_BLANK(*tmp); tmp++) ; /* Check there's nothing else beside them */ if(*tmp != '\0') { xmlFree(type); break; } /* Type is ok, add parameter to processing * instruction */ style_pi=(mxslt_pi_style_t *)xmalloc(sizeof(mxslt_pi_style_t)); style_pi->type=MXSLT_PI_STDST; style_pi->ctype=type; style_pi->href=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_href], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); if(xml_stylesheet_values[t_media]) style_pi->media=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_media], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); else style_pi->media=NULL; /* tie up xmlNode and style_pi */ XML_LINK_PI(document, pi, style_pi); } else { mxslt_error(document, "warning - <xml-stylesheet type=\"... unknown: '%s'!\n", type); xmlFree(type); } } else { if(!xml_stylesheet_values[t_href]) mxslt_error(document, "warning - <xml-stylesheet href=\"... is missing, skipping PI!\n"); if(!xml_stylesheet_values[t_type]) mxslt_error(document, "warning - <xml-stylesheet type=\"... is missing, skipping PI!\n"); } if(xml_stylesheet_values[t_media]) xfree(xml_stylesheet_values[t_media]); if(xml_stylesheet_values[t_href]) xfree(xml_stylesheet_values[t_href]); if(xml_stylesheet_values[t_type]) xfree(xml_stylesheet_values[t_type]); break; case 'm': if(target[1] != 'o' || target[2] != 'd' || target[3] != 'x' || target[4] != 's' || target[5] != 'l' || target[6] != 't' || target[7] != '-') break; switch(target[8]) { case 'b': if(!xmlStrEqual(target+8, (xmlChar *)"modxslt-base"+8)) { mxslt_error(document, "warning - unknown modxslt PI: %s in %s\n", target, document->localfile); break; } /* Read modxslt-base */ status=mxslt_get_static_attr((char *)data, mxslt_base, mxslt_base_values, mxslt_sizeof_array(mxslt_base)); if(status != MXSLT_OK) { if(mxslt_base_values[0]) xfree(mxslt_base_values[0]); goto error; } /* Verify we got the base */ if(!mxslt_base_values[0]) { mxslt_error(document, "warning - <modxslt-base ... base=\" is missing, skipping PI\n", target, document->localfile); break; } /* Remember the pi we found */ base_pi=(mxslt_pi_base_t *)(xmalloc(sizeof(mxslt_pi_base_t))); base_pi->type=MXSLT_PI_UBASE; base_pi->file=(char *)xmlCanonicPath((xmlChar *)mxslt_base_values[0]); base_pi->directory=xmlParserGetDirectory(mxslt_base_values[0]); xfree(mxslt_base_values[0]); /* Switch base in the current context */ if(ctxt->input->filename) xmlFree((char *)ctxt->input->filename); if(ctxt->directory) xmlFree(ctxt->directory); /* Remember those information */ ctxt->input->filename=(char *)xmlStrdup((xmlChar *)base_pi->file); ctxt->directory=(char *)xmlStrdup((xmlChar *)base_pi->directory); /* tie up xmlNode and style_pi */ XML_LINK_PI(document, pi, base_pi); break; case 'p': if(!xmlStrEqual(target+8, (xmlChar *)"modxslt-param"+8)) { mxslt_error(document, "warning - unknown modxslt PI: %s in %s\n", target, document->localfile); break; } status=mxslt_get_static_attr((char *)data, mxslt_param, mxslt_param_values, mxslt_sizeof_array(mxslt_param)); if(status != MXSLT_OK) { if(mxslt_param_values[0]) xfree(mxslt_param_values[0]); if(mxslt_param_values[1]) xfree(mxslt_param_values[1]); goto error; } if(mxslt_param_values[t_name]) { /* Allocate and create pi */ param_pi=(mxslt_pi_param_t *)xmalloc(sizeof(mxslt_pi_param_t)); param_pi->type=MXSLT_PI_PARAM; param_pi->param=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)mxslt_param_values[t_name], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); param_pi->value=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)mxslt_param_values[t_select], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); /* Link pi to list of pis */ XML_LINK_PI(document, pi, param_pi); } else { mxslt_error(document, "warning - modxslt-param specified without ``name'' attribute in `%s'\n", document->localfile); } /* Free memory up */ if(mxslt_param_values[t_select]) xfree(mxslt_param_values[t_select]); if(mxslt_param_values[t_name]) xfree(mxslt_param_values[t_name]); break; case 's': if(!xmlStrEqual(target+8, (xmlChar *)"modxslt-stylesheet"+8)) { mxslt_error(document, "warning - unknown modxslt PI: %s in %s\n", target, document->localfile); break; } status=mxslt_get_static_attr((char *)data, xml_stylesheet, xml_stylesheet_values, mxslt_sizeof_array(xml_stylesheet)); if(status != MXSLT_OK) { if(xml_stylesheet_values[0]) xfree(xml_stylesheet_values[0]); if(xml_stylesheet_values[1]) xfree(xml_stylesheet_values[1]); if(xml_stylesheet_values[2]) xfree(xml_stylesheet_values[2]); goto error; } if(xml_stylesheet_values[t_type]) { /* Decode type */ type=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_type], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); /* Skip blanks before type */ for(tmp=type; MXSLT_IS_BLANK(*tmp); tmp++) ; /* compare type string */ if(!strncmp(tmp, "text/xml", mxslt_sizeof_str("text/xml")) || !strncmp(tmp, "text/xsl", mxslt_sizeof_str("text/xsl"))) { /* trailing spaces are allowed */ for(tmp+=mxslt_sizeof_str("text/x?l"); MXSLT_IS_BLANK(*tmp); tmp++) ; /* Check there's nothing else beside them */ if(*tmp != '\0') { mxslt_error(document, "warning - <modxslt-stylesheet type=\"... trailing junk: '%s'!\n", type); xmlFree(type); break; } /* Type is ok, add parameter to processing * instruction */ style_pi=(mxslt_pi_style_t *)xmalloc(sizeof(mxslt_pi_style_t)); style_pi->type=MXSLT_PI_MODST; style_pi->ctype=type; if(xml_stylesheet_values[t_href]) style_pi->href=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_href], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); else style_pi->href=NULL; if(xml_stylesheet_values[t_media]) style_pi->media=(char *)xmlStringDecodeEntities(ctxt, (xmlChar *)xml_stylesheet_values[t_media], XML_SUBSTITUTE_REF|XML_SUBSTITUTE_PEREF, 0, 0, 0); else style_pi->media=NULL; /* Link to nodes chain */ XML_LINK_PI(document, pi, style_pi); } else { mxslt_error(document, "warning - <modxslt-stylesheet type=\"... unknown: '%s'!\n", type); xmlFree(type); } } if(xml_stylesheet_values[t_media]) xfree(xml_stylesheet_values[t_media]); if(xml_stylesheet_values[t_href]) xfree(xml_stylesheet_values[t_href]); if(xml_stylesheet_values[t_type]) xfree(xml_stylesheet_values[t_type]); break; default: mxslt_error(document, "warning - unknown modxslt PI: %s in %s\n", target, document->localfile); break; } break; } /* Taken from `processingInstruction' */ switch(ctxt->inSubset) { case 1: xmlAddChild((xmlNodePtr)ctxt->myDoc->intSubset, pi); return; case 2: xmlAddChild((xmlNodePtr)ctxt->myDoc->extSubset, pi); return; } if(!ctxt->myDoc->children || !ctxt->node) { xmlAddChild((xmlNodePtr)ctxt->myDoc, pi); return; } if(ctxt->node->type == XML_ELEMENT_NODE) xmlAddChild(ctxt->node, pi); else xmlAddSibling(ctxt->node, pi); return; error: mxslt_error(document, "warning - weird data while processing PI: %s in %s\n", target, document->localfile); xmlFreeNode(pi); return; }
int loadstatus() { xmlNodePtr root = NULL; xmlNodePtr node = NULL; xmlParserCtxtPtr parserctxt; int ret = 0; char* tmp; FILE* totest; totest = fopen(statname, "r"); if (totest != NULL) { fclose(totest); status = xmlParseFile(statname); } if (status != NULL) root = xmlDocGetRootElement(status); else status = xmlNewDoc(NULL); if (root != NULL) { parserctxt = xmlNewParserCtxt(); for (node = root->children; node; node = node->next) { if (xmlStrcmp(node->name, "abc") == 0) { if (node->children && (strlen(node->children->content) > 0)) { ABC = xmlStringDecodeEntities(parserctxt, node->children->content,XML_SUBSTITUTE_BOTH,0,0,0); } else ret = 1; } else if (xmlStrcmp(node->name, "current") == 0) { if (node->children && (strlen(node->children->content) > 0)) { tmp = xmlStringDecodeEntities(parserctxt, node->children->content,XML_SUBSTITUTE_BOTH,0,0,0); strcpy(password,tmp); curr_len = strlen(password); printf("INFO: Resuming cracking from password: '******'\n",password); xmlFree(tmp); } else ret = 1; } else if (xmlStrcmp(node->name, "good_password") == 0) { if (node->children && (strlen(node->children->content) > 0)) { tmp = xmlStringDecodeEntities(parserctxt, node->children->content,XML_SUBSTITUTE_BOTH,0,0,0); strcpy(password,tmp); curr_len = strlen(password); xmlMutexLock(finishedMutex); finished = 1; xmlMutexUnlock(finishedMutex); strcpy((char*) &password_good, (char*) &password); printf("GOOD: This archive was succesfully cracked\n"); printf(" The good password is: '%s'\n", password); xmlFree(tmp); ret = 1; } } } xmlFreeParserCtxt(parserctxt); } else { root = xmlNewNode(NULL, "rarcrack"); xmlDocSetRootElement(status, root); node = xmlNewTextChild(root, NULL, "abc", ABC); node = xmlNewTextChild(root, NULL, "current", getfirstpassword()); node = xmlNewTextChild(root, NULL, "good_password", ""); savestatus(); } return ret; }