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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
* Perl interface to rpmlib
*
* $Id: rpm.xs,v 1.3 1999/07/14 22:06:21 gafton Exp $
*/
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <rpm/rpmio.h>
#include <rpm/dbindex.h>
#include <rpm/header.h>
#include <popt.h>
#include <rpm/rpmlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
typedef rpmTransactionSet_s * Transaction;
/*
* External functions
*/
extern double constant(char *name, int arg);
MODULE = rpm PACKAGE = rpm
PROTOTYPES: ENABLE
double
constant(name,arg)
char * name
int arg
Header *
Header(package)
const char * package
PREINIT:
FD_t file_desc = NULL;
int rc;
int isSource;
int had_error = 0;
CODE:
New(1,RETVAL,1,Header);
file_desc = fdOpen(package, O_RDONLY, 0);
if (file_desc != NULL && RETVAL != NULL) {
rc = rpmReadPackageHeader(file_desc, RETVAL, &isSource, NULL, NULL);
if (rc != 0) {
had_error++;
}
if (file_desc != NULL) {
fdClose(file_desc);
}
} else {
had_error++;
}
ST(0) = sv_newmortal();
if (had_error) {
ST(0) = &PL_sv_undef;
} else {
sv_setref_pv(ST(0), "HeaderPtr", (void*)RETVAL);
}
Transaction *
Transaction(header)
Header * header
MODULE = rpm PACKAGE = HeaderPtr PREFIX = Header
AV *
HeaderItemByValRef(header, item)
Header * header
int item
PREINIT:
int_32 count, type;
int rc;
void * value;
char ** src;
AV * array;
CODE:
rc = headerGetEntry(*header, item, &type, &value, &count);
array = newAV();
if (rc != 0) {
switch(type) {
case RPM_CHAR_TYPE:
while (count-- > 0) {
av_push(array, newSViv((char) (int) value));
value++;
}
break;
case RPM_INT8_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_8) (int) value));
value++;
}
break;
case RPM_INT16_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_16) (int) value));
value++;
}
break;
case RPM_INT32_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_32)value));
value++;
}
break;
case RPM_STRING_TYPE:
av_push(array, newSVpv((char *)value, 0));
break;
case RPM_BIN_TYPE:
/* XXX: this looks mostly unused - how do we deal with it? */
break;
case RPM_STRING_ARRAY_TYPE:
case RPM_I18NSTRING_TYPE:
src = (char **) value;
while (count--) {
av_push(array, newSVpv(*src++, 0));
}
free(value);
break;
}
}
RETVAL = array;
OUTPUT:
RETVAL
AV *
HeaderItemByNameRef(header, tag)
Header * header
const char * tag
PREINIT:
int_32 count, type, item = -1;
int rc, i;
void * value;
char ** src;
AV * array;
CODE:
/* walk first through the list of items and get the proper value */
for (i = 0; i < rpmTagTableSize; i++) {
if (strcasecmp(tag, rpmTagTable[i].name) == 0) {
item = rpmTagTable[i].val;
break;
}
}
rc = headerGetEntry(*header, item, &type, &value, &count);
array = newAV();
if (rc != 0) {
switch(type) {
case RPM_CHAR_TYPE:
while (count-- > 0) {
av_push(array, newSViv((char) (int) value));
value++;
}
break;
case RPM_INT8_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_8) (int) value));
value++;
}
break;
case RPM_INT16_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_16) (int) value));
value++;
}
break;
case RPM_INT32_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_32)value));
value++;
}
break;
case RPM_STRING_TYPE:
av_push(array, newSVpv((char *)value, 0));
break;
case RPM_BIN_TYPE:
/* XXX: this looks mostly unused - how do we deal with it? */
break;
case RPM_STRING_ARRAY_TYPE:
case RPM_I18NSTRING_TYPE:
src = (char **) value;
while (count--) {
av_push(array, newSVpv(*src++, 0));
}
free(value);
break;
}
}
RETVAL = array;
OUTPUT:
RETVAL
HV *
HeaderListRef(header)
Header * header
PREINIT:
HeaderIterator iterator;
int_32 tag, type, count;
void *value;
CODE:
RETVAL = newHV();
iterator = headerInitIterator(*header);
while (headerNextIterator(iterator, &tag, &type, &value, &count)) {
SV ** sv;
AV * array;
char ** src;
char * tagStr = tagName(tag);
array = newAV();
switch(type) {
case RPM_CHAR_TYPE:
while (count-- > 0) {
av_push(array, newSViv((char) (int) value));
value++;
}
break;
case RPM_INT8_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_8) (int) value));
value++;
}
break;
case RPM_INT16_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_16) (int) value));
value++;
}
break;
case RPM_INT32_TYPE:
while (count-- > 0) {
av_push(array, newSViv((int_32)value));
value++;
}
break;
case RPM_STRING_TYPE:
av_push(array, newSVpv((char *)value, 0));
break;
case RPM_BIN_TYPE:
/* XXX: this looks mostly unused - how do we deal with it? */
break;
case RPM_STRING_ARRAY_TYPE:
case RPM_I18NSTRING_TYPE:
/* we have to build an array first */
src = (char **) value;
while (count--) {
av_push(array, newSVpv(*src++, 0));
}
free(value);
break;
}
sv = hv_store(RETVAL, tagStr, strlen(tagStr), newRV_inc((SV*)array), 0);
}
headerFreeIterator(iterator);
OUTPUT:
RETVAL
AV *
HeaderTagsRef(header)
Header * header
PREINIT:
HeaderIterator iterator;
int_32 tag, type;
void *value;
CODE:
RETVAL = newAV();
iterator = headerInitIterator(*header);
while (headerNextIterator(iterator, &tag, &type, &value, NULL)) {
av_push(RETVAL, newSVpv(tagName(tag), 0));
if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE)
free(value);
}
headerFreeIterator(iterator);
OUTPUT:
RETVAL
MODULE = rpm PACKAGE = TransactionPtr PREFIX = Trans
int
TransAdd(trans, header)
Transaction * trans
Header * header
int
TransDepCheck(trans)
Transaction * trans
int
TransRun(trans)
Transaction * trans
Transaction *
TransOrder(trans)
Transaction *trans
int
TransDealloc(trans)
Transaction * trans
int
TransGetAttr(trans, name)
Transaction * trans
const char * name
int
TransSetAttr(trans, name, val)
Transaction * trans
const char * name
void * val
|