Beispiel #1
0
/* 
 * return 1 if the file is a valid xml info file, 0 if it's not,
 * -1 on error;  Only checking that the root is 'elf' and the md5's match.
 */
int xmlelf_is_valid_info( elf_t * elf , char * name )
{
   xmlDocPtr doc;
   unsigned char xmd5[16], /* md5 in info */
                 emd5[16]; /* md5 of file */

   if(!elf || !name)
      error_ret("null args",-1);

   if( access( name , R_OK | W_OK )< 0)
      return(0);

   if(!(doc = xmlParseFile("1.0"))){
      error_ret("can't get doc",NULL);
   }

   xmlNodePtr root = xmlDocGetRootElement(doc);

   if(! root || ! name || !xmlStrCmp(root->name,(const xmlChar*)"elf") ){
      xmlFreeDoc(doc);
      debug_print("bad root name\n");
      return(0);
   }

   if( xmlelf_get_md5( root , xmd5 ) < 0 ){
      xmlFreeDoc(doc);
      error_ret("can't get md5 from xml",-1);
   }

   MD5( elf->data , elf->size , emd5 );

   if( memcmp(xmd5 , emd5 , 16 ) ){
      xmlFreeDoc(doc);
      return(0);
   }
   xmlFreeDoc(doc);
   return(1);
}
Beispiel #2
0
/** 
 * xslDbgShellAddParam:
 * @arg: A string comprised of two words separated by
 *          one or more spaces which are in UTF-8 
 *
 * Add a libxslt parameter to be sent to libxslt later on
 *
 * Returns 1 on success,
 *         0 otherwise
*/
int
xslDbgShellAddParam(xmlChar * arg)
{
    int result = 0;
    parameterItemPtr paramItem = NULL;
    static const char *errorPrompt = I18N_NOOP("Failed to add parameter");
    xmlChar *opts[2];

    if (!arg) {
        xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam"));
    }else{
	if ((xmlStrLen(arg) > 1) && splitString(arg, 2, opts) == 2) {
	    int count;
	    for (count = 0; count < arrayListCount(optionsGetParamItemList()); count++){
		paramItem = (parameterItemPtr)arrayListGet(optionsGetParamItemList(), count);
		if (paramItem != NULL){
		    if (xmlStrCmp(opts[0], paramItem->name) == 0){
			/* parameter exist just update its value */
			if (paramItem->value)
			    xmlFree(paramItem->value);
			paramItem->value = xmlStrdup(opts[1]); 
			return 1;
		    }
		}
	    }
	    paramItem = optionsParamItemNew(opts[0], opts[1]);
	    result = arrayListAdd(optionsGetParamItemList(), paramItem);
	} else {
	    xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam"));
	}
    }
    if (!result)
        xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
    else {
	xsldbgGenericErrorFunc("\n");
    }
    return result;
}
Beispiel #3
0
int
xslDbgShellSetVariable(xsltTransformContextPtr styleCtxt, xmlChar * arg)
{
    int result = 0, showUsage = 0;
    xmlChar *name, *nameURI, *selectExpr, *opts[3];

    if (!styleCtxt) {
	
        xsldbgGenericErrorFunc(i18n("Error: Stylesheet is not valid.\n"));
        return result;
    }

    if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_PROCESS
        xsltGenericError(xsltGenericErrorContext,
                         "Error: NULL argument provided\n");
#endif
        return result;
    }

    if (xmlStrLen(arg) > 1) {
        if (splitString(arg, 2, opts) == 2) {
            nameURI = NULL;
	    /* ignore any "$" prefix as user probably didn't mean that 
	       "$" is part of variable name*/
	    if (*opts[0] =='$'){
	      opts[0] = opts[0] + 1;
	    }
            name = xmlSplitQName2(opts[0], &nameURI);
            if (name == NULL)
                name = xmlStrdup(opts[0]);
            selectExpr = xmlStrdup(opts[1]);
            if (name && selectExpr) {
                xsltStackElemPtr def = NULL;

                if (styleCtxt->varsBase) {
                    /* try finding varaible in stack */
                    xsltStackElemPtr item =
                        styleCtxt->varsTab[styleCtxt->varsBase];
                    while (item) {
                        if ((xmlStrCmp(name, item->name) == 0) &&
                            (item->nameURI == NULL
                             || (xmlStrCmp(name, item->nameURI) == 0))) {
                            def = item;
                            break;
                        }
                        item = item->next;
                    }
                }

                if (def == NULL)
                    def = (xsltStackElemPtr)
                        xmlHashLookup2(styleCtxt->globalVars,
                                       name, nameURI);
                if (def != NULL) {
                    if (def->select) {
                        /* we've found the variable so change it */
                        xmlFree((void*)def->select);
                        def->select = selectExpr;
                        if (def->comp->comp)
                            xmlXPathFreeCompExpr(def->comp->comp);
                        def->comp->comp = xmlXPathCompile(def->select);
                        if (def->value)
                            xmlXPathFreeObject(def->value);
                        def->value =
                            xmlXPathEval(def->select,
                                         styleCtxt->xpathCtxt);
                        result = 1;
                    } else {
                        xmlFree(selectExpr);
                        xsldbgGenericErrorFunc(i18n("Error: Cannot change a variable that does not use the select attribute.\n"));
                    }
                } else
                    xsldbgGenericErrorFunc(i18n("Error: Variable %1 was not found.\n").arg(xsldbgText(name)));
                xmlFree(name);
            } else
                xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
        } else {
            showUsage = 1;
        }

        if (showUsage == 1)
            xsldbgGenericErrorFunc(i18n("Error: Invalid arguments to command %1.\n").arg("set"));
    }
    return result;
}