diff options
author | jbj <devnull@localhost> | 2004-06-15 20:16:22 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2004-06-15 20:16:22 +0000 |
commit | bb7ba371839408a7da6a14624cb29201598f05b2 (patch) | |
tree | ab0f01e5e735e553181d5c43304f83ca1f31e75f /tools | |
parent | dfc183d5a79725a1bc23858313adb5a7003f756c (diff) | |
download | rpm-bb7ba371839408a7da6a14624cb29201598f05b2.tar.gz rpm-bb7ba371839408a7da6a14624cb29201598f05b2.tar.bz2 rpm-bb7ba371839408a7da6a14624cb29201598f05b2.zip |
Generate header from xml parse.
CVS patchset: 7339
CVS date: 2004/06/15 20:16:22
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 5 | ||||
-rw-r--r-- | tools/rpmtool.c | 36 | ||||
-rw-r--r-- | tools/rpmxml.c | 250 | ||||
-rw-r--r-- | tools/rpmxp.h | 3 |
4 files changed, 273 insertions, 21 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index dc029b20f..2f19956cc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -70,7 +70,8 @@ rpmtool_SOURCES = rpmtool.c rpmxp.c #rpmtool_LDFLAGS = $(staticLDFLAGS) rpmtool_LDADD = $(LDADD) -lxml2 -rpmxml_SOURCES = rpmxml.c rpmxp.c -rpmxml_LDADD = -lxml2 +rpmxml_SOURCES = rpmxml.c # rpmxp.c +#rpmxml_LDFLAGS = $(staticLDFLAGS) +rpmxml_LDADD = $(LDADD) -lxml2 $(PROGRAMS): $(LDADD) diff --git a/tools/rpmtool.c b/tools/rpmtool.c index 5149c8948..90b35997e 100644 --- a/tools/rpmtool.c +++ b/tools/rpmtool.c @@ -48,24 +48,24 @@ static const char * rpmaviNext(rpmavi avi) /*@observer@*/ /*@unchecked@*/ static const struct headerTagTableEntry_s rpmSTagTbl[] = { - { "RPMTAG_HEADERIMAGE", HEADER_IMAGE, }, - { "RPMTAG_HEADERSIGNATURES", HEADER_SIGNATURES, }, - { "RPMTAG_HEADERIMMUTABLE", HEADER_IMMUTABLE, }, - { "RPMTAG_HEADERREGIONS", HEADER_REGIONS, }, - { "RPMTAG_SIGSIZE", 999+1, }, - { "RPMTAG_SIGLEMD5_1", 999+2, }, - { "RPMTAG_SIGPGP", 999+3, }, - { "RPMTAG_SIGLEMD5_2", 999+4, }, - { "RPMTAG_SIGMD5", 999+5, }, - { "RPMTAG_SIGGPG", 999+6, }, - { "RPMTAG_SIGPGP5", 999+7, }, - { "RPMTAG_SIGPAYLOADSIZE", 999+8, }, - { "RPMTAG_BADSHA1_1", HEADER_SIGBASE+8, }, - { "RPMTAG_BADSHA1_2", HEADER_SIGBASE+9, }, - { "RPMTAG_PUBKEYS", HEADER_SIGBASE+10, }, - { "RPMTAG_DSAHEADER", HEADER_SIGBASE+11, }, - { "RPMTAG_RSAHEADER", HEADER_SIGBASE+12, }, - { "RPMTAG_SHA1HEADER", HEADER_SIGBASE+13, }, + { "RPMTAG_HEADERIMAGE", HEADER_IMAGE, RPM_BIN_TYPE }, + { "RPMTAG_HEADERSIGNATURES", HEADER_SIGNATURES, RPM_BIN_TYPE }, + { "RPMTAG_HEADERIMMUTABLE", HEADER_IMMUTABLE, RPM_BIN_TYPE }, + { "RPMTAG_HEADERREGIONS", HEADER_REGIONS, RPM_BIN_TYPE }, + { "RPMTAG_SIGSIZE", 999+1, RPM_INT32_TYPE }, + { "RPMTAG_SIGLEMD5_1", 999+2, RPM_BIN_TYPE }, + { "RPMTAG_SIGPGP", 999+3, RPM_BIN_TYPE }, + { "RPMTAG_SIGLEMD5_2", 999+4, RPM_BIN_TYPE }, + { "RPMTAG_SIGMD5", 999+5, RPM_BIN_TYPE }, + { "RPMTAG_SIGGPG", 999+6, RPM_BIN_TYPE }, + { "RPMTAG_SIGPGP5", 999+7, RPM_BIN_TYPE }, + { "RPMTAG_SIGPAYLOADSIZE", 999+8, RPM_INT32_TYPE }, + { "RPMTAG_BADSHA1_1", HEADER_SIGBASE+8, RPM_STRING_TYPE }, + { "RPMTAG_BADSHA1_2", HEADER_SIGBASE+9, RPM_STRING_TYPE }, + { "RPMTAG_PUBKEYS", HEADER_SIGBASE+10, RPM_STRING_ARRAY_TYPE }, + { "RPMTAG_DSAHEADER", HEADER_SIGBASE+11, RPM_BIN_TYPE }, + { "RPMTAG_RSAHEADER", HEADER_SIGBASE+12, RPM_BIN_TYPE }, + { "RPMTAG_SHA1HEADER", HEADER_SIGBASE+13, RPM_STRING_TYPE }, { NULL, 0 } }; diff --git a/tools/rpmxml.c b/tools/rpmxml.c index 8ef1109c1..9c16582e7 100644 --- a/tools/rpmxml.c +++ b/tools/rpmxml.c @@ -1,7 +1,255 @@ #include "system.h" -#include <rpmxp.h> +#include <rpmlib.h> +#define _RPMXP_INTERNAL +#include "rpmxp.h" #include "debug.h" +int _rpmxp_debug = 0; + +const char * rpmxpDTD = "\ +<?xml version=\"1.0\"?>\n\ +<!DOCTYPE rpmHeader [\n\ +<!ELEMENT rpmHeader (rpmTag+)>\n\ +<!ELEMENT rpmTag (string+|integer+|base64+)>\n\ +<!ATTLIST rpmTag name CDATA #REQUIRED>\n\ +<!ELEMENT string (#PCDATA)>\n\ +<!ELEMENT integer (#PCDATA)>\n\ +<!ELEMENT base64 (#PCDATA)>\n\ +]>\n\ +"; + +rpmxp rpmxpFree(rpmxp xp) +{ + if (xp != NULL) { + if (xp->value) { + xmlFree(xp->value); + xp->value = NULL; + } + if (xp->name) { + xmlFree(xp->name); + xp->name = NULL; + } + if (xp->reader != NULL) { + xmlFreeTextReader(xp->reader); + xp->reader = NULL; + } + free(xp); + xp = NULL; + } + return xp; +} + +rpmxp rpmxpNew(const char * fn) +{ + rpmxp xp = calloc(1, sizeof(*xp)); + + if (xp == NULL) + return NULL; + if (fn) { + int xx; + xp->reader = xmlNewTextReaderFilename(fn); + if (xp->reader == NULL) + return rpmxpFree(xp); + xx = xmlTextReaderSetParserProp(xp->reader, XML_PARSER_VALIDATE, 1); + xx = xmlTextReaderSetParserProp(xp->reader, XML_PARSER_SUBST_ENTITIES, 1); + } + xp->name = NULL; + xp->value = NULL; + xp->depth = 0; + xp->nodeType = 0; + xp->isEmptyElement = 0; + xp->n = 2; + return xp; +} + +/** + * Return tag table entry from name lookup. + * @todo bsearch on sorted name table. + * @param tbl tag table + * @param name tag name to find + * @return tag value, 0 on not found + */ +static headerTagTableEntry myTagByName(headerTagTableEntry tbl, const char * name) +{ + int x = (strncmp(name, "RPMTAG_", (sizeof("RPMTAG_")-1)) + ? (sizeof("RPMTAG_")-1) : 0); + + for (; tbl->name != NULL; tbl++) { + if (!xstrcasecmp(tbl->name+x, name)) + return tbl; + } + return NULL; +} + +int rpmxpRead(rpmxp xp) +{ + return xmlTextReaderRead(xp->reader); +} + +int rpmxpProcess(rpmxp xp) +{ + int rc = 0; + + xp->name = xmlTextReaderName(xp->reader); + xp->value = xmlTextReaderValue(xp->reader); + xp->depth = xmlTextReaderDepth(xp->reader); + xp->nodeType = xmlTextReaderNodeType(xp->reader); + xp->isEmptyElement = xmlTextReaderIsEmptyElement(xp->reader); + + if (xp->name == NULL) + xp->name = xmlStrdup(BAD_CAST "--"); + +if (_rpmxp_debug) +printf("%d %d %s %d\n", xp->depth, xp->nodeType, xp->name, xp->isEmptyElement); + switch (xp->nodeType) { + case XML_READER_TYPE_ELEMENT: + printf("%*s<%s", (xp->n * xp->depth), "", xp->name); + while (xmlTextReaderMoveToNextAttribute(xp->reader) != 0) { + xmlChar * attrN = xmlTextReaderName(xp->reader); + xmlChar * attrV = xmlTextReaderValue(xp->reader); + printf(" %s", attrN); + if (attrV) { + printf("=\"%s\"", attrV); + if (!strcmp(xp->name, "rpmTag") && !strcmp(attrN, "name")) { + /* XXX rpmSTagTable gonna be needed. */ + xp->tte = myTagByName(rpmTagTable, attrV); + } + xmlFree(attrV); + } + xmlFree(attrN); + } + if (xp->isEmptyElement) { + printf("/>\n"); + if (xp->h && xp->tte) { + headerTagTableEntry tte = xp->tte; + if (!strcmp(xp->name, "string")) { + const char * nstr = ""; + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &nstr, 1); + } else + if (!strcmp(xp->name, "integer")) { + int i = 0; + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &i, 1); + } + } + } else { + printf(">"); + if (xp->depth < 2) + printf("\n"); + } + if (!strcmp(xp->name, "rpmHeader")) { + xp->h = headerNew(); + } + break; + case XML_READER_TYPE_END_ELEMENT: + if (xp->depth < 2) + printf("%*s", (xp->n * xp->depth), ""); + printf("</%s>\n", xp->name); + if (!strcmp(xp->name, "rpmHeader")) { + if (xp->h) { + FD_t fdo = Fopen("time.xmlhdr", "w.ufdio"); + if (fdo != NULL) { + headerWrite(fdo, xp->h, HEADER_MAGIC_YES); + Fclose(fdo); + } + } + xp->h = headerFree(xp->h); + } else + if (!strcmp(xp->name, "rpmTag")) { + xp->tte = NULL; + } + break; + case XML_READER_TYPE_TEXT: + printf("%s", xp->value); + if (xp->h && xp->tte) { + headerTagTableEntry tte = xp->tte; + switch (tte->type) { + case RPM_NULL_TYPE: + { + } break; + case RPM_CHAR_TYPE: + { char c = xp->value[0]; + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &c, 1); + } break; + case RPM_INT8_TYPE: + { int_8 i = strtol(xp->value, NULL, 0); + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &i, 1); + } break; + case RPM_INT16_TYPE: + { int_16 i = strtol(xp->value, NULL, 0); + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &i, 1); + } break; + case RPM_INT32_TYPE: + { int_32 i = strtol(xp->value, NULL, 0); + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &i, 1); + } break; + case RPM_STRING_TYPE: + { const char * s = xp->value; + (void) headerAddEntry(xp->h, tte->val, tte->type, s, 1); + } break; + case RPM_STRING_ARRAY_TYPE: + { const char * s = xp->value; + (void) headerAddOrAppendEntry(xp->h, tte->val, tte->type, &s, 1); + } break; + case RPM_I18NSTRING_TYPE: + { const char * s = xp->value; + (void) headerAddI18NString(xp->h, tte->val, s, "C"); + } break; + default: + break; + } + } + break; + case XML_READER_TYPE_DOCUMENT_TYPE: + break; + case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: + break; + + case XML_READER_TYPE_NONE: + case XML_READER_TYPE_ATTRIBUTE: + case XML_READER_TYPE_CDATA: + case XML_READER_TYPE_ENTITY_REFERENCE: + case XML_READER_TYPE_ENTITY: + case XML_READER_TYPE_PROCESSING_INSTRUCTION: + case XML_READER_TYPE_COMMENT: + case XML_READER_TYPE_DOCUMENT: + case XML_READER_TYPE_DOCUMENT_FRAGMENT: + case XML_READER_TYPE_NOTATION: + case XML_READER_TYPE_WHITESPACE: + case XML_READER_TYPE_END_ENTITY: + case XML_READER_TYPE_XML_DECLARATION: + default: + printf("%d %d %s %d\n", xp->depth, xp->nodeType, + xp->name, xp->isEmptyElement); + if (xp->value) + printf(" %s", xp->value); + if (xp->depth < 2) + printf("\n"); + rc = -1; + break; + } + + + if (xp->value != NULL) { + xmlFree(xp->value); + xp->value = NULL; + } + if (xp->name != NULL) { + xmlFree(xp->name); + xp->name = NULL; + } + return rc; +} + +int rpmxpParseFile(rpmxp xp) +{ + int ret = -1; + + if (xp != NULL) + while ((ret = rpmxpRead(xp)) == 1) + rpmxpProcess(xp); + return ret; +} + int main(int argc, char ** argv) { const char * fn = "time.xml"; diff --git a/tools/rpmxp.h b/tools/rpmxp.h index ad72768de..1102ebbdc 100644 --- a/tools/rpmxp.h +++ b/tools/rpmxp.h @@ -37,6 +37,9 @@ struct rpmxp_s { int nodeType; int isEmptyElement; + Header h; + headerTagTableEntry tte; + int n; }; #endif |