static JSObject * rpmtsLoadNVRA(JSContext *cx, JSObject *obj) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; JSObject * NVRA = JS_NewArrayObject(cx, 0, NULL); ARGV_t keys = NULL; int nkeys; int xx; int i; if (ts->rdb == NULL) (void) rpmtsOpenDB(ts, O_RDONLY); xx = rpmdbMireApply(rpmtsGetRdb(ts), RPMTAG_NVRA, RPMMIRE_STRCMP, NULL, &keys); nkeys = argvCount(keys); if (keys) for (i = 0; i < nkeys; i++) { JSString * valstr = JS_NewStringCopyZ(cx, keys[i]); jsval id = STRING_TO_JSVAL(valstr); JS_SetElement(cx, NVRA, i, &id); } JS_DefineProperty(cx, obj, "NVRA", OBJECT_TO_JSVAL(NVRA), NULL, NULL, JSPROP_ENUMERATE); if (_debug) fprintf(stderr, "==> %s(%p,%p) ptr %p NVRA %p\n", __FUNCTION__, cx, obj, ptr, NVRA); return NVRA; }
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; }
static JSBool rpmts_dbkeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; jsval tagid = JSVAL_VOID; jsval v = JSVAL_VOID; rpmTag tag = RPMTAG_NVRA; rpmMireMode _mode = RPMMIRE_PCRE; const char * _pat = "^a.*$"; ARGV_t _av = NULL; JSBool ok = JS_FALSE; int xx; _METHOD_DEBUG_ENTRY(_debug); if (!(ok = JS_ConvertArguments(cx, argc, argv, "/vvu", &v, &tagid, &v, &_mode))) goto exit; if (!JSVAL_IS_VOID(tagid)) { /* XXX TODO: make sure both tag and key were specified. */ tag = JSVAL_IS_INT(tagid) ? (rpmTag) JSVAL_TO_INT(tagid) : tagValue(JS_GetStringBytes(JS_ValueToString(cx, tagid))); } if (JSVAL_IS_VOID(v)) _pat = "^.*$"; else if (JSVAL_IS_NULL(v)) _pat = NULL; else if (JSVAL_IS_STRING(v)) _pat = JS_GetStringBytes(JS_ValueToString(cx, v)); #ifdef NOTYET else if (JSVAL_IS_NUMBER(v)) { uint32_t _u = 0; if (!JS_ValueToECMAUint32(cx, v, &_u)) { *rval = JSVAL_VOID; goto exit; } } else ; #endif switch (_mode) { default: *rval = JSVAL_VOID; goto exit; break; case RPMMIRE_DEFAULT: case RPMMIRE_STRCMP: case RPMMIRE_REGEX: case RPMMIRE_GLOB: case RPMMIRE_PCRE: break; } if (rpmtsGetRdb(ts) == NULL) xx = rpmtsOpenDB(ts, O_RDONLY); if (rpmdbMireApply(rpmtsGetRdb(ts), tag, _mode, _pat, &_av)) *rval = JSVAL_VOID; else if (_av == NULL || _av[0] == NULL) *rval = JSVAL_NULL; else { int _ac = argvCount(_av); int i; JSObject * arr = JS_NewArrayObject(cx, 0, NULL); *rval = OBJECT_TO_JSVAL(arr); for (i = 0; i < _ac; i++) { v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _av[i])); ok = JS_SetElement(cx, arr, i, &v); } } exit: ok = JS_TRUE; _av = argvFree(_av); return ok; }
int processPackages(rpmts *ts, int tscount, const char *packagelistfn, int ignoremissing) { int rc = 0; int count = 0; int sz = 100; int i = 0; int missing = 0; FILE *f = fopen(packagelistfn, "r" ); if(f) { char line[255]; while(fgets(line, sizeof(line), f)) { int len = strlen(line) - 1; if(len > 0) // Trim trailing whitespace while(len > 0 && isspace(line[len])) line[len--] = '\0'; if(len > 0) { int found = 0; for(i=0; i<tscount; i++) { ARGV_t keys = NULL; rpmdb db = rpmtsGetRdb(ts[i]); rc = rpmdbMireApply(db, RPMTAG_NAME, RPMMIRE_STRCMP, line, &keys); if (keys) { int nkeys = argvCount(keys); if( nkeys == 1 ) { char *value = NULL; rc = getPackageStr(ts[i], keys[0], RPMTAG_PACKAGEORIGIN, &value); if(rc == 0) fprintf(outf, "%s\n", value); else fprintf(stderr, "Failed to get package origin for %s\n", line); found = 1; } else if( nkeys > 1 ) { int keyindex = 0; fprintf(stderr, "Multiple matches for %s:\n", line); for( keyindex=0; keyindex<nkeys; keyindex++) { char *value = NULL; rc = getPackageStr(ts[i], keys[keyindex], RPMTAG_PACKAGEORIGIN, &value); if(rc == 0) fprintf(stderr, " %s\n", value); else fprintf(stderr, " (%s)\n", keys[keyindex]); } } } if(found) break; } if( !found ) { if( ignoremissing ) { fprintf(stderr, "Unable to resolve package %s - ignoring\n", line); } else { fprintf(stderr, "Unable to resolve package %s\n", line); missing = 1; } } } count++; } fclose(f); if( missing ) { fprintf(stderr, "ERROR: some packages were missing\n"); rc = 1; } } else { perror(packagelistfn); rc = -1; } return rc; }