1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#include "rpmcli.h"
#include "rpmlib.h"
#include "misc.h"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
const char *CLASS = "RPM2";
MODULE = RPM2 PACKAGE = RPM2
int
rpmvercmp(one, two)
char* one
char* two
void
_init_rpm()
CODE:
rpmReadConfigFiles(NULL, NULL);
void
_close_rpm_db(db)
rpmdb db
CODE:
rpmdbClose(db);
rpmdb
_open_rpm_db(path,for_write)
char *path
int for_write
PREINIT:
rpmdb db;
CODE:
if (rpmdbOpen(path, &db, for_write ? O_RDWR | O_CREAT : O_RDONLY, 0644)) {
croak("rpmdbOpen failed");
RETVAL = NULL;
}
RETVAL = db;
OUTPUT:
RETVAL
rpmdbMatchIterator
_init_iterator(db, rpmtag, key, len)
rpmdb db
int rpmtag
char *key
size_t len
CODE:
RETVAL = rpmdbInitIterator(db, rpmtag, key && *key ? key : NULL, len);
OUTPUT:
RETVAL
void
_destroy_iterator(i)
rpmdbMatchIterator i
CODE:
rpmdbFreeIterator(i);
Header
_iterator_next(i)
rpmdbMatchIterator i
PREINIT:
Header ret;
CODE:
ret = rpmdbNextIterator(i);
if (ret)
headerLink(ret);
RETVAL = ret;
OUTPUT:
RETVAL
void
_read_package_info(fp)
FILE *fp
PREINIT:
Header ret;
Header sigs;
rpmRC rc;
FD_t fd;
PPCODE:
fd = fdDup(fileno(fp));
rc = rpmReadPackageInfo(fd, &sigs, &ret);
Fclose(fd);
if (rc == RPMRC_OK) {
SV *h_sv, *s_sv;
EXTEND(SP, 2);
h_sv = sv_newmortal();
s_sv = sv_newmortal();
sv_setref_pv(h_sv, "Header", (void *)ret);
sv_setref_pv(s_sv, "Header", (void *)sigs);
PUSHs(h_sv);
PUSHs(s_sv);
}
else {
croak("error reading package");
}
void
_free_header(h)
Header h
CODE:
headerFree(h);
void
_header_tag(h, tag)
Header h
int tag
PREINIT:
void *ret = NULL;
int type;
int n;
int ok;
PPCODE:
ok = headerGetEntry(h, tag, &type, &ret, &n);
if (!ok) {
/* nop, empty stack */
}
else {
switch(type)
{
case RPM_STRING_ARRAY_TYPE:
{
int i;
char **s;
EXTEND(SP, n);
s = (char **)ret;
for (i = 0; i < n; i++) {
PUSHs(sv_2mortal(newSVpv(s[i], 0)));
}
}
break;
case RPM_STRING_TYPE:
PUSHs(sv_2mortal(newSVpv((char *)ret, 0)));
break;
case RPM_CHAR_TYPE:
case RPM_INT8_TYPE:
case RPM_INT16_TYPE:
case RPM_INT32_TYPE:
{
int i;
int *r;
EXTEND(SP, n);
r = (int *)ret;
for (i = 0; i < n; i++) {
PUSHs(sv_2mortal(newSViv(r[i])));
}
}
break;
default:
croak("unknown rpm tag type %d", type);
}
}
headerFreeData(ret, type);
int
_header_is_source(h)
Header h
CODE:
RETVAL = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
OUTPUT:
RETVAL
void
_populate_header_tags(href)
SV *href
PREINIT:
int i = 0;
HV *h;
CODE:
h = (HV *)SvRV(href);
for (i = 0; i < rpmTagTableSize; i++) {
hv_store(h, rpmTagTable[i].name, strlen(rpmTagTable[i].name), newSViv(rpmTagTable[i].val), 0);
}
|