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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#include "rpmlib.h"
#include "rpmcli.h"
#ifdef RPM2_RPM41
#include "rpmts.h"
#endif
#include "header.h"
#include "rpmdb.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
_add_macro(name, val)
char * name
char * val
CODE:
addMacro(NULL, name, NULL, val, RMIL_DEFAULT);
void
_delete_macro(name)
char * name
CODE:
delMacro(NULL, name);
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:
#ifdef RPM2_RPM41
rpmts ts;
#endif
Header ret;
Header sigs;
rpmRC rc;
FD_t fd;
PPCODE:
#ifdef RPM2_RPM41
ts = rpmtsCreate();
#endif
/* XXX Determine type of signature verification when reading
vsflags |= _RPMTS_VSF_NOLEGACY;
vsflags |= _RPMTS_VSF_NODIGESTS;
vsflags |= _RPMTS_VSF_NOSIGNATURES;
xx = rpmtsSetVerifySigFlags(ts, vsflags);
*/
fd = fdDup(fileno(fp));
#ifdef RPM2_RPM41
rc = rpmReadPackageFile(ts, fd, "filename or other identifier", &ret);
#else
rc = rpmReadPackageInfo(fd, NULL, &ret);
#endif
Fclose(fd);
if (rc == RPMRC_OK) {
SV *h_sv;
EXTEND(SP, 1);
h_sv = sv_newmortal();
sv_setref_pv(h_sv, "Header", (void *)ret);
PUSHs(h_sv);
}
else {
croak("error reading package");
}
#ifdef RPM2_RPM41
ts = rpmtsFree(ts);
#endif
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_compare(h1, h2)
Header h1
Header h2
CODE:
RETVAL = rpmVersionCompare(h1, h2);
OUTPUT:
RETVAL
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);
}
|