diff options
-rw-r--r-- | URPM.xs | 241 |
1 files changed, 105 insertions, 136 deletions
@@ -288,9 +288,9 @@ typedef int (*callback_list_str)(char *s, int slen, const char *name, const uint static int callback_list_str_xpush(char *s, int slen, const char *name, uint32_t flags, const char *evr, __attribute__((unused)) void *param) { dSP; - if (s) { + if (s) mXPUSHs(newSVpv(s, slen)); - } else { + else { char buff[4096]; int len = print_list_entry(buff, sizeof(buff)-1, name, flags, evr); if (len >= 0) @@ -303,9 +303,9 @@ callback_list_str_xpush(char *s, int slen, const char *name, uint32_t flags, con static int callback_list_str_xpush_requires(char *s, int slen, const char *name, const uint32_t flags, const char *evr, __attribute__((unused)) void *param) { dSP; - if (s) { + if (s) mXPUSHs(newSVpv(s, slen)); - } else if (is_not_old_suggests(flags)) { + else if (is_not_old_suggests(flags)) { char buff[4096]; int len = print_list_entry(buff, sizeof(buff)-1, name, flags, evr); if (len >= 0) @@ -318,9 +318,9 @@ callback_list_str_xpush_requires(char *s, int slen, const char *name, const uint static int callback_list_str_xpush_old_suggests(char *s, int slen, const char *name, uint32_t flags, const char *evr, __attribute__((unused)) void *param) { dSP; - if (s) { + if (s) mXPUSHs(newSVpv(s, slen)); - } else if (is_old_suggests(flags)) { + else if (is_old_suggests(flags)) { char buff[4096]; int len = print_list_entry(buff, sizeof(buff)-1, name, flags, evr); if (len >= 0) @@ -543,9 +543,9 @@ return_list_tag(URPM__Package pkg, int32_t tag_name) { if (headerGet(pkg->h, tag_name, &td, HEADERGET_DEFAULT)) { void *list = td.data; int32_t count = rpmtdCount(&td); - if (tag_name == RPMTAG_ARCH) { + if (tag_name == RPMTAG_ARCH) mXPUSHs(newSVpv(headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? (char *) list : "src", 0)); - } else + else switch (rpmtdType(&td)) { case RPM_NULL_TYPE: break; @@ -1021,13 +1021,13 @@ open_archive(char *filename, int *empty_archive) { } else { /* this is an archive, prepare for reading with uncompress defined inside */ rfd = Fopen(filename, "r.fdio"); - if (strcmp(buf.uncompress, "gzip")) { + if (strcmp(buf.uncompress, "gzip")) rfd = Fdopen(rfd, "r.gzip"); - } else if (strcmp(buf.uncompress, "bzip")) { + else if (strcmp(buf.uncompress, "bzip")) rfd = Fdopen(rfd, "r.bzip2"); - } else if (strcmp(buf.uncompress, "xz") || strcmp(buf.uncompress, "lzma")) { + else if (strcmp(buf.uncompress, "xz") || strcmp(buf.uncompress, "lzma")) rfd = Fdopen(rfd, "r.xz"); - } else { + else { free(rfd); rfd = NULL; } @@ -1068,9 +1068,9 @@ parse_line(AV *depslist, HV *provides, HV *obsoletes, URPM__Package pkg, char *b char *tag, *data; int data_len; - if (buff[0] == 0) { + if (buff[0] == 0) return 1; - } else if ((tag = buff)[0] == '@' && (data = strchr(tag+1, '@')) != NULL) { + else if ((tag = buff)[0] == '@' && (data = strchr(tag+1, '@')) != NULL) { *tag++ = *data++ = 0; data_len = 1+strlen(data); if (!strcmp(tag, "info")) { @@ -1085,21 +1085,21 @@ parse_line(AV *depslist, HV *provides, HV *obsoletes, URPM__Package pkg, char *b av_push(depslist, sv_pkg); } memset(pkg, 0, sizeof(struct s_Package)); - } else if (!strcmp(tag, "filesize")) { + } else if (!strcmp(tag, "filesize")) pkg->filesize = atoi(data); - } else if (!strcmp(tag, "requires")) { - free(pkg->requires); pkg->requires = memcpy(malloc(data_len), data, data_len); - } else if (!strcmp(tag, "suggests")) { - free(pkg->suggests); pkg->suggests = memcpy(malloc(data_len), data, data_len); - } else if (!strcmp(tag, "obsoletes")) { - free(pkg->obsoletes); pkg->obsoletes = memcpy(malloc(data_len), data, data_len); - } else if (!strcmp(tag, "conflicts")) { - free(pkg->conflicts); pkg->conflicts = memcpy(malloc(data_len), data, data_len); - } else if (!strcmp(tag, "provides")) { - free(pkg->provides); pkg->provides = memcpy(malloc(data_len), data, data_len); - } else if (!strcmp(tag, "summary")) { - free(pkg->summary); pkg->summary = memcpy(malloc(data_len), data, data_len); - } + else if (!strcmp(tag, "requires")) + free(pkg->requires), pkg->requires = memcpy(malloc(data_len), data, data_len); + else if (!strcmp(tag, "suggests")) + free(pkg->suggests), pkg->suggests = memcpy(malloc(data_len), data, data_len); + else if (!strcmp(tag, "obsoletes")) + free(pkg->obsoletes), pkg->obsoletes = memcpy(malloc(data_len), data, data_len); + else if (!strcmp(tag, "conflicts")) + free(pkg->conflicts), pkg->conflicts = memcpy(malloc(data_len), data, data_len); + else if (!strcmp(tag, "provides")) + free(pkg->provides), pkg->provides = memcpy(malloc(data_len), data, data_len); + else if (!strcmp(tag, "summary")) + free(pkg->summary), pkg->summary = memcpy(malloc(data_len), data, data_len); + return 1; } else { fprintf(stderr, "bad line <%s>\n", buff); @@ -1509,9 +1509,8 @@ void Pkg_sourcerpm(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_SOURCERPM), 0)); - } void Pkg_packager(pkg) @@ -1524,19 +1523,17 @@ void Pkg_buildhost(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_BUILDHOST), 0)); - } int Pkg_buildtime(pkg) URPM::Package pkg CODE: - if (pkg->h) { + if (pkg->h) RETVAL = get_int(pkg->h, RPMTAG_BUILDTIME); - } else { + else RETVAL = 0; - } OUTPUT: RETVAL @@ -1544,11 +1541,10 @@ int Pkg_installtid(pkg) URPM::Package pkg CODE: - if (pkg->h) { + if (pkg->h) RETVAL = get_int(pkg->h, RPMTAG_INSTALLTID); - } else { + else RETVAL = 0; - } OUTPUT: RETVAL @@ -1556,49 +1552,43 @@ void Pkg_url(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_URL), 0)); - } void Pkg_license(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_LICENSE), 0)); - } void Pkg_distribution(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_DISTRIBUTION), 0)); - } void Pkg_vendor(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_VENDOR), 0)); - } void Pkg_os(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_OS), 0)); - } void Pkg_payload_format(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->h) mXPUSHs(newSVpv(get_name(pkg->h, RPMTAG_PAYLOADFORMAT), 0)); - } void Pkg_fullname(pkg) @@ -1651,9 +1641,8 @@ Pkg_epoch(pkg) if ((eos = strchr(s+1, '@')) != NULL) *eos = 0; /* mark end of string to enable searching backwards */ RETVAL = atoi(s+1); if (eos != NULL) *eos = '@'; - } else { + } else RETVAL = 0; - } } else if (pkg->h) { RETVAL = get_int(pkg->h, RPMTAG_EPOCH); } else RETVAL = 0; @@ -1686,9 +1675,8 @@ Pkg_compare_pkg(lpkg, rpkg) if ((leos = strchr(s+1, '@')) != NULL) *leos = 0; /* mark end of string to enable searching backwards */ lepoch = atoi(s+1); if (leos != NULL) *leos = '@'; - } else { + } else lepoch = 0; - } get_fullname_parts(lpkg, NULL, &lversion, &lrelease, &larch, &leos); /* temporarily mark end of each substring */ lrelease[-1] = 0; @@ -1706,9 +1694,8 @@ Pkg_compare_pkg(lpkg, rpkg) if ((reos = strchr(s+1, '@')) != NULL) *reos = 0; /* mark end of string to enable searching backwards */ repoch = atoi(s+1); if (reos != NULL) *reos = '@'; - } else { + } else repoch = 0; - } get_fullname_parts(rpkg, NULL, &rversion, &rrelease, &rarch, &reos); /* temporarily mark end of each substring */ rrelease[-1] = 0; @@ -1792,16 +1779,15 @@ Pkg_compare(pkg, evr) if ((_eos = strchr(s+1, '@')) != NULL) *_eos = 0; /* mark end of string to enable searching backwards */ _epoch = atoi(s+1); if (_eos != NULL) *_eos = '@'; - } else { + } else _epoch = 0; - } get_fullname_parts(pkg, NULL, &_version, &_release, &_eos, NULL); /* temporarily mark end of each substring */ _release[-1] = 0; _eos[-1] = 0; - } else if (pkg->h) { + } else if (pkg->h) _epoch = get_int(pkg->h, RPMTAG_EPOCH); - } else croak("undefined package"); + else croak("undefined package"); if (!compare) { char *epoch, *version, *release; @@ -1858,12 +1844,11 @@ Pkg_size(pkg) if ((eos = strchr(s+1, '@')) != NULL) *eos = 0; /* mark end of string to enable searching backwards */ RETVAL = atoi(s+1); if (eos != NULL) *eos = '@'; - } else { + } else RETVAL = 0; - } - } else if (pkg->h) { + } else if (pkg->h) RETVAL = get_int(pkg->h, RPMTAG_SIZE); - } else RETVAL = 0; + else RETVAL = 0; OUTPUT: RETVAL @@ -1871,11 +1856,11 @@ int Pkg_filesize(pkg) URPM::Package pkg CODE: - if (pkg->filesize) { + if (pkg->filesize) RETVAL = pkg->filesize; - } else if (pkg->h) { + else if (pkg->h) RETVAL = get_filesize(pkg->h); - } else RETVAL = 0; + else RETVAL = 0; OUTPUT: RETVAL @@ -1890,9 +1875,8 @@ Pkg_group(pkg) char *eos = strchr(s+1, '@'); mXPUSHs(newSVpv_utf8(s+1, eos != NULL ? eos-s-1 : 0)); } - } else if (pkg->h) { + } else if (pkg->h) mXPUSHs(newSVpv_utf8(get_name(pkg->h, RPMTAG_GROUP), 0)); - } void Pkg_filename(pkg) @@ -1953,9 +1937,8 @@ Pkg_set_id(pkg, id=-1) URPM::Package pkg int id PPCODE: - if ((pkg->flag & FLAG_ID) <= FLAG_ID_MAX) { + if ((pkg->flag & FLAG_ID) <= FLAG_ID_MAX) mXPUSHs(newSViv(pkg->flag & FLAG_ID)); - } pkg->flag &= ~FLAG_ID; pkg->flag |= id >= 0 && id <= FLAG_ID_MAX ? id : FLAG_ID_INVALID; @@ -2333,19 +2316,18 @@ Pkg_update_header(pkg, filename, ...) int keep_all_tags = 0; CODE: /* compability mode with older interface of parse_hdlist */ - if (items == 3) { + if (items == 3) packing = SvIV(ST(2)); - } else if (items > 3) { + else if (items > 3) { int i; for (i = 2; i < items-1; i+=2) { STRLEN len; char *s = SvPV(ST(i), len); - if (len == 7 && !memcmp(s, "packing", 7)) { + if (len == 7 && !memcmp(s, "packing", 7)) packing = SvTRUE(ST(i + 1)); - } else if (len == 13 && !memcmp(s, "keep_all_tags", 13)) { + else if (len == 13 && !memcmp(s, "keep_all_tags", 13)) keep_all_tags = SvTRUE(ST(i+1)); - } } } RETVAL = update_header(filename, pkg, !packing && keep_all_tags, RPMVSF_DEFAULT); @@ -2930,26 +2912,25 @@ Trans_add(trans, pkg, ...) int update = 0; rpmRelocation *relocations = NULL; /* compability mode with older interface of add */ - if (items == 3) { + if (items == 3) update = SvIV(ST(2)); - } else if (items > 3) { + else if (items > 3) { int i; for (i = 2; i < items-1; i+=2) { STRLEN len; char *s = SvPV(ST(i), len); - if (len == 6 && !memcmp(s, "update", 6)) { + if (len == 6 && !memcmp(s, "update", 6)) update = SvIV(ST(i+1)); - } else if (len == 11 && !memcmp(s, "excludepath", 11)) { + else if (len == 11 && !memcmp(s, "excludepath", 11)) { if (SvROK(ST(i+1)) && SvTYPE(SvRV(ST(i+1))) == SVt_PVAV) { AV *excludepath = (AV*)SvRV(ST(i+1)); I32 j = 1 + av_len(excludepath); relocations = calloc(j + 1, sizeof(rpmRelocation)); while (--j >= 0) { SV **e = av_fetch(excludepath, j, 0); - if (e != NULL && *e != NULL) { + if (e != NULL && *e != NULL) relocations[j].oldPath = SvPV_nolen(*e); - } } } } @@ -2977,13 +2958,11 @@ Trans_remove(trans, name) *boa = 0; if ((bor = strrchr(name, '-'))) { *bor = 0; - if (!strrchr(name, '-')) { + if (!strrchr(name, '-')) *boa = '.'; boa = NULL; - } *bor = '-'; bor = NULL; - } else { + } else *boa = '.'; boa = NULL; - } } mi = rpmtsInitIterator(trans->ts, RPMDBI_LABEL, name, 0); while ((h = rpmdbNextIterator(mi))) { @@ -3041,30 +3020,28 @@ Trans_check(trans, ...) STRLEN len; char *s = SvPV(ST(i), len); - if (len == 17 && !memcmp(s, "translate_message", 17)) { + if (len == 17 && !memcmp(s, "translate_message", 17)) translate_message = SvIV(ST(i+1)); - } } if (rpmtsCheck(trans->ts)) { - if (gimme == G_SCALAR) { + if (gimme == G_SCALAR) mXPUSHs(newSViv(0)); - } else if (gimme == G_ARRAY) { + else if (gimme == G_ARRAY) mXPUSHs(newSVpv("error while checking dependencies", 0)); - } } else { rpmps ps = rpmtsProblems(trans->ts); if (rpmpsNumProblems(ps) > 0) { - if (gimme == G_SCALAR) { + if (gimme == G_SCALAR) mXPUSHs(newSViv(0)); - } else if (gimme == G_ARRAY) { + else if (gimme == G_ARRAY) { /* now translation is handled by rpmlib, but only for version 4.2 and above */ PUTBACK; return_problems(ps, 1, 0); SPAGAIN; } - } else if (gimme == G_SCALAR) { + } else if (gimme == G_SCALAR) mXPUSHs(newSViv(1)); - } + ps = rpmpsFree(ps); } @@ -3075,15 +3052,13 @@ Trans_order(trans) I32 gimme = GIMME_V; PPCODE: if (rpmtsOrder(trans->ts) == 0) { - if (gimme == G_SCALAR) { + if (gimme == G_SCALAR) mXPUSHs(newSViv(1)); - } } else { - if (gimme == G_SCALAR) { + if (gimme == G_SCALAR) mXPUSHs(newSViv(0)); - } else if (gimme == G_ARRAY) { + else if (gimme == G_ARRAY) mXPUSHs(newSVpv("error while ordering dependencies", 0)); - } } int @@ -3319,9 +3294,8 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) STRLEN len; char *s = SvPV(ST(i), len); - if (len == 8 && !memcmp(s, "callback", 8)) { - if (SvROK(ST(i+1))) callback = ST(i+1); - } + if (len == 8 && !memcmp(s, "callback", 8) && SvROK(ST(i+1))) + callback = ST(i+1); } } @@ -3403,25 +3377,24 @@ Urpm_parse_hdlist__XS(urpm, filename, ...) SV *callback = NULL; /* compability mode with older interface of parse_hdlist */ - if (items == 3) { + if (items == 3) packing = SvTRUE(ST(2)); - } else if (items > 3) { + else if (items > 3) { int i; for (i = 2; i < items-1; i+=2) { STRLEN len; char *s = SvPV(ST(i), len); - if (len == 7 && !memcmp(s, "packing", 7)) { + if (len == 7 && !memcmp(s, "packing", 7)) packing = SvTRUE(ST(i+1)); - } else if (len == 8 && !memcmp(s, "callback", 8)) { - if (SvROK(ST(i+1))) callback = ST(i+1); - } + else if (len == 8 && !memcmp(s, "callback", 8) && SvROK(ST(i+1))) + callback = ST(i+1); } } PUTBACK; do { - header=headerRead(fd, HEADER_MAGIC_YES); + header = headerRead(fd, HEADER_MAGIC_YES); if (header != NULL) { struct s_Package pkg, *_pkg; SV *sv_pkg; @@ -3445,9 +3418,8 @@ Urpm_parse_hdlist__XS(urpm, filename, ...) int ok = Fclose(fd) == 0; - if (!empty_archive) { + if (!empty_archive) ok = av_len(depslist) >= start_id; - } SPAGAIN; if (ok) { mXPUSHs(newSViv(start_id)); @@ -3483,21 +3455,21 @@ Urpm_parse_rpm(urpm, filename, ...) rpmVSFlags vsflags = RPMVSF_DEFAULT; /* compability mode with older interface of parse_hdlist */ - if (items == 3) { + if (items == 3) packing = SvTRUE(ST(2)); - } else if (items > 3) { + else if (items > 3) { int i; for (i = 2; i < items-1; i+=2) { STRLEN len; char *s = SvPV(ST(i), len); - if (len == 7 && !memcmp(s, "packing", 7)) { + if (len == 7 && !memcmp(s, "packing", 7)) packing = SvTRUE(ST(i + 1)); - } else if (len == 13 && !memcmp(s, "keep_all_tags", 13)) { + else if (len == 13 && !memcmp(s, "keep_all_tags", 13)) keep_all_tags = SvTRUE(ST(i+1)); - } else if (len == 8 && !memcmp(s, "callback", 8)) { - if (SvROK(ST(i+1))) callback = ST(i+1); - } else if (len == 5) { + else if (len == 8 && !memcmp(s, "callback", 8) && SvROK(ST(i+1))) + callback = ST(i+1); + else if (len == 5) { if (!memcmp(s, "nopgp", 5)) { if (SvIV(ST(i+1))) vsflags |= (RPMVSF_NOSHA1 | RPMVSF_NOSHA1HEADER); } @@ -3571,18 +3543,17 @@ Urpm_verify_rpm(filename, ...) } } fd = Fopen(filename, "r"); - if (fd == NULL) { + if (fd == NULL) RETVAL = 0; - } else { + else { read_config_files(0); ts = rpmtsCreate(); rpmtsSetRootDir(ts, "/"); rpmtsOpenDB(ts, O_RDONLY); - if (rpmVerifySignatures(&qva, ts, fd, filename)) { + if (rpmVerifySignatures(&qva, ts, fd, filename)) RETVAL = 0; - } else { + else RETVAL = 1; - } Fclose(fd); (void)rpmtsFree(ts); } @@ -3604,16 +3575,15 @@ Urpm_get_gpg_fingerprint(filename) CODE: memset (fingerprint, 0, sizeof (fingerprint)); - if ((rc = pgpReadPkts(filename, (uint8_t ** ) &pkt, &pktlen)) <= 0) { + if ((rc = pgpReadPkts(filename, (uint8_t ** ) &pkt, &pktlen)) <= 0) pktlen = 0; - } else if (rc != PGPARMOR_PUBKEY) { + else if (rc != PGPARMOR_PUBKEY) pktlen = 0; - } else { + else { unsigned int i; pgpPubkeyFingerprint (pkt, pktlen, fingerprint); - for (i = 0; i < sizeof (pgpKeyID_t); i++) { + for (i = 0; i < sizeof (pgpKeyID_t); i++) sprintf(&fingerprint_str[i*2], "%02x", fingerprint[i]); - } } _free(pkt); RETVAL = fingerprint_str; @@ -3633,9 +3603,9 @@ Urpm_verify_signature(filename, prefix="/") Header h; CODE: fd = Fopen(filename, "r"); - if (fd == NULL) { + if (fd == NULL) RETVAL = "NOT OK (could not read file)"; - } else { + else { read_config_files(0); ts = rpmtsCreate(); rpmtsSetRootDir(ts, prefix); @@ -3694,15 +3664,14 @@ Urpm_import_pubkey_file(db, filename) #endif rpmtsClean(ts); - if ((rc = pgpReadPkts(filename, (uint8_t ** ) &pkt, &pktlen)) <= 0) { + if ((rc = pgpReadPkts(filename, (uint8_t ** ) &pkt, &pktlen)) <= 0) RETVAL = 0; - } else if (rc != PGPARMOR_PUBKEY) { + else if (rc != PGPARMOR_PUBKEY) RETVAL = 0; - } else if (rpmtsImportPubkey(ts, pkt, pktlen) != RPMRC_OK) { + else if (rpmtsImportPubkey(ts, pkt, pktlen) != RPMRC_OK) RETVAL = 0; - } else { + else RETVAL = 1; - } pkt = _free(pkt); (void)rpmtsFree(ts); OUTPUT: |