static JSBool rpmts_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; jsint tiny = JSVAL_TO_INT(id); _PROP_DEBUG_ENTRY(_debug < 0); /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: *vp = INT_TO_JSVAL(_debug); break; case _LENGTH: *vp = INT_TO_JSVAL(rpmtsNElements(ts)); break; case _VSFLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsVSFlags(ts)); break; case _TYPE: *vp = INT_TO_JSVAL((jsint)rpmtsType(ts)); break; case _ARBGOAL: *vp = INT_TO_JSVAL((jsint)rpmtsARBGoal(ts)); break; case _ROOTDIR: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, rpmtsRootDir(ts))); break; case _CURRDIR: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, rpmtsCurrDir(ts))); break; case _SELINUX: *vp = INT_TO_JSVAL((jsint)rpmtsSELinuxEnabled(ts)); break; case _CHROOTDONE: *vp = INT_TO_JSVAL((jsint)rpmtsChrootDone(ts)); break; case _TID: *vp = INT_TO_JSVAL((jsint)rpmtsGetTid(ts)); break; case _NELEMENTS: *vp = INT_TO_JSVAL((jsint)rpmtsNElements(ts)); break; case _PROBFILTER: *vp = INT_TO_JSVAL((jsint)rpmtsFilterFlags(ts)); break; case _FLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsFlags(ts)); break; case _DFLAGS: *vp = INT_TO_JSVAL((jsint)rpmtsDFlags(ts)); break; case _GOAL: *vp = INT_TO_JSVAL((jsint)rpmtsGoal(ts)); break; case _DBMODE: *vp = INT_TO_JSVAL((jsint)rpmtsDBMode(ts)); break; case _COLOR: *vp = INT_TO_JSVAL((jsint)rpmtsColor(ts)); break; case _PREFCOLOR: *vp = INT_TO_JSVAL((jsint)rpmtsPrefColor(ts)); break; default: if (JSVAL_IS_INT(id)) { int oc = JSVAL_TO_INT(id); JSObject *teo = NULL; rpmte te = NULL; /* XXX rpmteLink/rpmteUnlink are no-ops */ if ((te = rpmtsElement(ts, oc)) != NULL && (teo = JS_NewObject(cx, &rpmteClass, NULL, NULL)) != NULL && JS_SetPrivate(cx, teo, rpmteLink(te))) { *vp = OBJECT_TO_JSVAL(teo); } break; } #ifdef DYING if (JSVAL_IS_STRING(id)) { JSString * str = JS_ValueToString(cx, id); const char * name = JS_GetStringBytes(str); if (!strcmp(name, "NVRA")) { JSObject * NVRA = rpmtsLoadNVRA(cx, obj); *vp = OBJECT_TO_JSVAL(NVRA); } break; } #endif break; } return JS_TRUE; }
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; }