Example #1
0
int main( int argc, char **argv )
{
    rpmmi mi;
    Header h;
    int_32 type, count;
    char *name;
    rpmdb db;

    rpmReadConfigFiles( NULL, NULL );

    if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
	fprintf( stderr, "cannot open database!\n" );
	exit(EXIT_FAILURE);
    }

    mi = rpmmiInit(db, RPMDBI_PACKAGES, NULL, 0);
    while ((h = rpmmiNext(mi)) != NULL) {

	headerGetEntry( h, RPMTAG_NAME, &type, (void**)&name, &count );
	if( strcmp(name,argv[1]) == 0 )
	    headerDump( h, stdout, HEADER_DUMP_INLINE, rpmTagTable );

	/*
	 * Note that the header reference is "owned" by the iterator,
	 * so no headerFree() is necessary.
	 */

    }
    mi = rpmmiFree(mi);

    rpmdbClose( db );

    return 0;
}
Example #2
0
/* --- Object ctors/dtors */
static void
rpmmi_free(rpmmi mi)
{
if (_debug)
fprintf(stderr, "==> %s(%p)\n", __FUNCTION__, mi);
    mi = rpmmiFree(mi);
}
Example #3
0
/*@-mustmod@*/
static void rpmgiFini(void * _gi)
	/*@modifies _gi @*/
{
    rpmgi gi = _gi;
    int xx;

    gi->hdrPath = _free(gi->hdrPath);
    (void)headerFree(gi->h);
    gi->h = NULL;

    gi->argv = argvFree(gi->argv);

    if (gi->ftsp != NULL) {
	xx = Fts_close(gi->ftsp);
	gi->ftsp = NULL;
	gi->fts = NULL;
    }
    if (gi->fd != NULL) {
	xx = Fclose(gi->fd);
	gi->fd = NULL;
    }
    gi->tsi = rpmtsiFree(gi->tsi);
    gi->mi = rpmmiFree(gi->mi);
    (void)rpmtsFree(gi->ts); 
    gi->ts = NULL;
}
Example #4
0
/** \ingroup py_c
 */
static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
	/*@globals rpmGlobalMacroContext @*/
	/*@modifies s, rpmGlobalMacroContext @*/
{
    if (s) {
	s->mi = rpmmiFree(s->mi);
	PyObject_Del(s);
    }
}
Example #5
0
/**
 * Return rpmdb match iterator with filters (if any) set.
 * @param gi		generalized iterator
 * @returns		RPMRC_OK on success
 */
static rpmRC rpmgiInitFilter(rpmgi gi)
	/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
	/*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/
{
    rpmRC rpmrc = RPMRC_OK;
    ARGV_t av;
    int got = 0;

    gi->mi = rpmtsInitIterator(gi->ts, gi->tag, gi->keyp, gi->keylen);

if (_rpmgi_debug < 0)
fprintf(stderr, "*** gi %p key %p[%d]\tmi %p\n", gi, gi->keyp, (int)gi->keylen, gi->mi);

    if (gi->argv != NULL)
    for (av = (const char **) gi->argv; *av != NULL; av++) {
	if (gi->tag == RPMDBI_PACKAGES) {
	    int tag = RPMTAG_NAME;
	    const char * pat;
	    char * a, * ae;

	    pat = a = xstrdup(*av);
	    tag = RPMTAG_NAME;

	    /* Parse for "tag=pattern" args. */
	    if ((ae = strchr(a, '=')) != NULL) {
		*ae++ = '\0';
		if (*a != '\0') {	/* XXX HACK: permit '=foo' */
		    tag = tagValue(a);
#ifdef	DYING	/* XXX arbitrary tags always have a return value */
		    if (tag < 0) {
			rpmlog(RPMLOG_NOTICE, _("unknown tag: \"%s\"\n"), a);
			got = -1;
		    }
#endif
		}
		pat = ae;
		got++;
	    }
	    if (got) {
if (_rpmgi_debug  < 0)
fprintf(stderr, "\tav %p[%d]: \"%s\" -> %s ~= \"%s\"\n", gi->argv, (int)(av - gi->argv), *av, tagName(tag), pat);
		got = rpmmiAddPattern(gi->mi, tag, RPMMIRE_DEFAULT, pat);
	    }
	    a = _free(a);
	}

	if (got >= 0)
	    continue;

	gi->mi = rpmmiFree(gi->mi);	/* XXX odd side effect? */
	rpmrc = RPMRC_FAIL;
	break;
    }

    return rpmrc;
}
Example #6
0
/*@null@*/
static PyObject *
rpmmi_iternext(rpmmiObject * s)
	/*@globals rpmGlobalMacroContext @*/
	/*@modifies s, rpmGlobalMacroContext @*/
{
    Header h;

    if (s->mi == NULL || (h = rpmmiNext(s->mi)) == NULL) {
	s->mi = rpmmiFree(s->mi);
	return NULL;
    }
    return (PyObject *) hdr_Wrap(h);
}
Example #7
0
int getPackageStr(rpmts ts, const char *NVRA, rpmTag tag, char **value)
{
    int rc = -1;
    rpmmi mi = rpmmiInit(rpmtsGetRdb(ts), RPMTAG_NVRA, NVRA, 0);
    Header h;
    if ((h = rpmmiNext(mi)) != NULL) {
        HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
        he->tag = tag;
        rc = (headerGet(h, he, 0) != 1);
        if(rc==0)
            *value = strdup((char *)he->p.ptr);
    }
    (void)rpmmiFree(mi);
    return rc;
}
Example #8
0
int lookupProvider(rpmts ts, const char *req, char **provider)
{
    int rc = 0;
    rpmmi provmi = rpmmiInit(rpmtsGetRdb(ts), RPMTAG_PROVIDENAME, req, 0);
    if(provmi) {
        Header h;
        if ((h = rpmmiNext(provmi)) != NULL) {
            HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
            he->tag = RPMTAG_NAME;
            rc = (headerGet(h, he, 0) != 1);
            if(rc==0)
                *provider = strdup((char *)he->p.ptr);
        }
        (void)rpmmiFree(provmi);
    }
    else {
        rc = -1;
    }
    return rc;
}
Example #9
0
/* --- Object methods */
static JSBool
rpmts_add(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL);
    rpmts ts = ptr;
    char * pkgN = 0;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &pkgN)))
        goto exit;

    if (pkgN != NULL) {
	rpmmi mi;
	Header h;
	int upgrade = 0;
	int xx;

	switch (*pkgN) {
	case '-':	pkgN++;		upgrade = -1;	break;
	case '+':	pkgN++;		upgrade = 1;	break;
	default:			upgrade = 1;	break;
	}
	mi = rpmtsInitIterator(ts, RPMTAG_NVRA, pkgN, 0);
	while ((h = rpmmiNext(mi)) != NULL) {
	    xx = (upgrade >= 0)
	        ? rpmtsAddInstallElement(ts, h, (fnpyKey)pkgN, upgrade, NULL)
		: rpmtsAddEraseElement(ts, h, rpmmiInstance(mi));
	    break;
	}
	mi = rpmmiFree(mi);
    }

    ok = JS_TRUE;
exit:
    *rval = BOOLEAN_TO_JSVAL(ok);	/* XXX return error */
    return ok;
}
Example #10
0
int printDepList(rpmts *ts, int tscount)
{
    int rc = 0;

    if( tscount > 1 )
        fprintf(stderr, ">1 database specified with dependency list, using first only\n");

    /* Get list of names */
    rpmdb db = rpmtsGetRdb(ts[0]);
    ARGV_t names = NULL;
    rc = rpmdbMireApply(db, RPMTAG_NAME,
                RPMMIRE_STRCMP, NULL, &names);
    int nnames = argvCount(names);

    /* Get list of NVRAs */
    ARGV_t keys = NULL;
    rc = rpmdbMireApply(db, RPMTAG_NVRA,
                RPMMIRE_STRCMP, NULL, &keys);
    if (keys) {
        int i, j;
        HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
        int nkeys = argvCount(keys);
        for(i=0; i<nkeys; i++) {
            rpmmi mi = rpmmiInit(db, RPMTAG_NVRA, keys[i], 0);
            Header h;
            if ((h = rpmmiNext(mi)) != NULL) {
                /* Get name of package */
                he->tag = RPMTAG_NAME;
                rc = (headerGet(h, he, 0) != 1);
                char *name = strdup((char *)he->p.ptr);
                /* Get its requires */
                he->tag = RPMTAG_REQUIRENAME;
                if (rc = (headerGet(h, he, 0) != 1)) {
                    if (debugmode) {
                        printf("DEBUG: %s requires null\n", name);
                    }
                    rc = 0;
                    free(name);
                    (void)rpmmiFree(mi);
                    continue;
                }
                ARGV_t reqs = (ARGV_t)he->p.ptr;
                /* Get its requireflags */
                he->tag = RPMTAG_REQUIREFLAGS;
                rc = (headerGet(h, he, 0) != 1);
                rpmuint32_t *reqflags = (rpmuint32_t *)he->p.ui32p;
                for(j=0; j<he->c; j++) {
                    int k;
                    char *prov = NULL;
                    for(k=0; k<nnames; k++) {
                        if(strcmp(names[k], reqs[j]) == 0) {
                            prov = names[k];
                            break;
                        }
                    }
                    if(prov) {
                        if((int)reqflags[j] & 0x80000)
                            fprintf(outf, "%s|%s [REC]\n", name, prov);
                        else
                            fprintf(outf, "%s|%s\n", name, prov);
                    }
                    else {
                        rc = lookupProvider(ts[0], reqs[j], &prov);
                        if(rc==0 && prov) {
                            if((int)reqflags[j] & 0x80000)
                                fprintf(outf, "%s|%s [REC]\n", name, prov);
                            else
                                fprintf(outf, "%s|%s\n", name, prov);
                            free(prov);
                        }
                    }
                }
                free(name);
            }
            (void)rpmmiFree(mi);
        }
    }

    return rc;
}
Example #11
0
rpmRC rpmgiNext(/*@null@*/ rpmgi gi)
{
    char hnum[32];
    rpmRC rpmrc = RPMRC_NOTFOUND;
    int xx;

    if (gi == NULL)
	return rpmrc;

if (_rpmgi_debug)
fprintf(stderr, "--> %s(%p) tag %s\n", __FUNCTION__, gi, tagName(gi->tag));

    /* Free header from previous iteration. */
    (void)headerFree(gi->h);
    gi->h = NULL;
    gi->hdrPath = _free(gi->hdrPath);
    hnum[0] = '\0';

    if (++gi->i >= 0)
    switch (gi->tag) {
    default:
	if (!gi->active) {
nextkey:
	    rpmrc = rpmgiLoadNextKey(gi);
	    if (rpmrc != RPMRC_OK)
		goto enditer;
	    rpmrc = rpmgiInitFilter(gi);
	    if (rpmrc != RPMRC_OK || gi->mi == NULL) {
		gi->mi = rpmmiFree(gi->mi);	/* XXX unnecessary */
		gi->i++;
		goto nextkey;
	    }
	    rpmrc = RPMRC_NOTFOUND;	/* XXX hack */
	    gi->active = 1;
	}
	if (gi->mi != NULL) {	/* XXX unnecessary */
	    Header h = rpmmiNext(gi->mi);
	    if (h != NULL) {
		if (!(gi->flags & RPMGI_NOHEADER))
		    gi->h = headerLink(h);
		/* XXX use h->origin instead. */
		sprintf(hnum, "%u", (unsigned)rpmmiInstance(gi->mi));
		gi->hdrPath = rpmExpand("rpmdb h# ", hnum, NULL);
		rpmrc = RPMRC_OK;
		/* XXX header reference held by iterator, so no headerFree */
	    }
	}
	if (rpmrc != RPMRC_OK) {
	    gi->mi = rpmmiFree(gi->mi);
	    goto nextkey;
	}
	break;
    case RPMDBI_PACKAGES:
	if (!gi->active) {
	    rpmrc = rpmgiInitFilter(gi);
	    if (rpmrc != RPMRC_OK) {
		gi->mi = rpmmiFree(gi->mi);	/* XXX unnecessary */
		goto enditer;
	    }
	    rpmrc = RPMRC_NOTFOUND;	/* XXX hack */
	    gi->active = 1;
	}
	if (gi->mi != NULL) {	/* XXX unnecessary */
	    Header h = rpmmiNext(gi->mi);
	    if (h != NULL) {
		if (!(gi->flags & RPMGI_NOHEADER))
		    gi->h = headerLink(h);
		/* XXX use h->origin instead. */
		sprintf(hnum, "%u", (unsigned)rpmmiInstance(gi->mi));
		gi->hdrPath = rpmExpand("rpmdb h# ", hnum, NULL);
		rpmrc = RPMRC_OK;
		/* XXX header reference held by iterator, so no headerFree */
	    }
	}
	if (rpmrc != RPMRC_OK) {
	    gi->mi = rpmmiFree(gi->mi);
	    goto enditer;
	}
	break;
    case RPMDBI_REMOVED:
    case RPMDBI_ADDED:
    {	rpmte p;
	int teType = 0;
	const char * teTypeString = NULL;

	if (!gi->active) {
	    gi->tsi = rpmtsiInit(gi->ts);
	    gi->active = 1;
	}
	if ((p = rpmtsiNext(gi->tsi, teType)) != NULL) {
	    Header h = rpmteHeader(p);
	    if (h != NULL)
		if (!(gi->flags & RPMGI_NOHEADER)) {
		    gi->h = headerLink(h);
		switch(rpmteType(p)) {
		case TR_ADDED:	teTypeString = "+++";	/*@switchbreak@*/break;
		case TR_REMOVED: teTypeString = "---";	/*@switchbreak@*/break;
		}
		sprintf(hnum, "%u", (unsigned)gi->i);
		gi->hdrPath = rpmExpand("%s h# ", teTypeString, hnum, NULL);
		rpmrc = RPMRC_OK;
		(void)headerFree(h);
		h = NULL;
	    }
	}
	if (rpmrc != RPMRC_OK) {
	    gi->tsi = rpmtsiFree(gi->tsi);
	    goto enditer;
	}
    }	break;
    case RPMDBI_HDLIST:
	if (!gi->active) {
	    const char * path = rpmExpand("%{?_query_hdlist_path}", NULL);
	    if (path == NULL || *path == '\0') {
		path = _free(path);
		path = rpmExpand(_query_hdlist_path, NULL);
	    }
	    gi->fd = rpmgiOpen(path, "rm%{?_rpmgio}");
	    gi->active = 1;
	    path = _free(path);
	}
	if (gi->fd != NULL) {
	    Header h = NULL;
	    const char item[] = "Header";
	    const char * msg = NULL;
/*@+voidabstract@*/
	    rpmrc = rpmpkgRead(item, gi->fd, &h, &msg);
/*@=voidabstract@*/
	    switch(rpmrc) {
		default:
		    rpmlog(RPMLOG_ERR, "%s: %s: %s\n", "rpmpkgRead", item, msg);
		case RPMRC_NOTFOUND:
		    h = NULL;
		case RPMRC_OK:
		    break;
	    }
	    msg = _free(msg);
	    if (h != NULL) {
		if (!(gi->flags & RPMGI_NOHEADER))
		    gi->h = headerLink(h);
		sprintf(hnum, "%u", (unsigned)gi->i);
		gi->hdrPath = rpmExpand("hdlist h# ", hnum, NULL);
		rpmrc = RPMRC_OK;
		(void)headerFree(h);
		h = NULL;
	    }
	}
	if (rpmrc != RPMRC_OK) {
	    if (gi->fd != NULL) (void) Fclose(gi->fd);
	    gi->fd = NULL;
	    goto enditer;
	}
	break;
    case RPMDBI_ARGLIST:
	/* XXX gi->active initialize? */
if (_rpmgi_debug  < 0)
fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]);
	/* Read next header, lazily expanding manifests as found. */
	rpmrc = rpmgiLoadReadHeader(gi);

	if (rpmrc != RPMRC_OK)	/* XXX check this */
	    goto enditer;

	gi->hdrPath = xstrdup(gi->argv[gi->i]);
	break;
    case RPMDBI_FTSWALK:
	if (gi->argv == NULL || gi->argv[0] == NULL)		/* HACK */
	    goto enditer;

	if (!gi->active) {
	    gi->ftsp = Fts_open((char *const *)gi->argv, gi->ftsOpts, NULL);
	    /* XXX NULL with open(2)/malloc(3) errno set */
	    gi->active = 1;
	}

	/* Read next header, lazily walking file tree. */
	rpmrc = rpmgiWalkReadHeader(gi);

	if (rpmrc != RPMRC_OK) {
	    xx = Fts_close(gi->ftsp);
	    gi->ftsp = NULL;
	    goto enditer;
	}

	if (gi->fts != NULL)
	    gi->hdrPath = xstrdup(gi->fts->fts_path);
	break;
    }

    if ((gi->flags & RPMGI_TSADD) && gi->h != NULL) {
	/* XXX rpmgi hack: Save header in transaction element. */
	if (gi->flags & RPMGI_ERASING) {
	    uint32_t hdrNum = headerGetInstance(gi->h);
	    xx = rpmtsAddEraseElement(gi->ts, gi->h, hdrNum);
	} else
	    xx = rpmtsAddInstallElement(gi->ts, gi->h, (fnpyKey)gi->hdrPath, 2, NULL);
    }
    goto exit;

enditer:
    if (gi->flags & RPMGI_TSORDER) {
	rpmts ts = gi->ts;

	/* Block access to indices used for depsolving. */
	if (!(gi->flags & RPMGI_ERASING)) {
	    (void) rpmtsSetGoal(ts, TSM_INSTALL);
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMDBI_DEPCACHE);
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMTAG_BASENAMES);
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), -RPMTAG_PROVIDENAME);
	} else {
	    (void) rpmtsSetGoal(ts, TSM_ERASE);
	}

	/* XXX query/verify will need the glop added to a buffer instead. */
	xx = rpmcliInstallCheck(ts);
	xx = rpmcliInstallSuggests(ts);

	/* Permit access to indices used for depsolving. */
	if (!(gi->flags & RPMGI_ERASING)) {
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMTAG_PROVIDENAME);
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMTAG_BASENAMES);
	    xx = rpmdbBlockDBI(rpmtsGetRdb(ts), RPMDBI_DEPCACHE);
	}

	/* XXX Display dependency loops with rpm -qvT. */
	if (rpmIsVerbose())
	    (void) rpmtsSetDFlags(ts, (rpmtsDFlags(ts) | RPMDEPS_FLAG_DEPLOOPS));

	xx = (*gi->tsOrder) (ts);

	/* XXX hackery alert! */
	gi->tag = (!(gi->flags & RPMGI_ERASING) ? RPMDBI_ADDED : RPMDBI_REMOVED);
	gi->flags &= ~(RPMGI_TSADD|RPMGI_TSORDER);

    }

    (void)headerFree(gi->h);
    gi->h = NULL;
    gi->hdrPath = _free(gi->hdrPath);
    gi->i = -1;
    gi->active = 0;

exit:
if (_rpmgi_debug)
fprintf(stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, gi, rpmrc);
    return rpmrc;
}