rpm
5.4.10
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
rpmdb
hdrNVR.c
Go to the documentation of this file.
1
5
#include "system.h"
6
7
#include <
rpmiotypes.h
>
8
#include <
rpmmacro.h
>
9
10
#define _RPMTAG_INTERNAL
11
#include "
header_internal.h
"
/* XXX hdrchkType(), hdrchkData() */
12
13
#include "
debug.h
"
14
19
/*@observer@*/
/*@unchecked@*/
20
static
struct
tagMacro
{
21
/*@observer@*/
/*@null@*/
22
const
char
*
macroname
;
23
rpmTag
tag
;
24
}
tagMacros
[] = {
25
{
"name"
,
RPMTAG_NAME
},
26
{
"version"
,
RPMTAG_VERSION
},
27
{
"release"
,
RPMTAG_RELEASE
},
28
{
"distepoch"
,
RPMTAG_DISTEPOCH
},
29
{
"epoch"
,
RPMTAG_EPOCH
},
30
{
"arch"
,
RPMTAG_ARCH
},
31
{
"os"
,
RPMTAG_OS
},
32
{ NULL, (
rpmTag
) 0 }
33
};
34
35
/*@-globs -mods -incondefs@*/
36
int
headerMacrosLoad
(
Header
h)
37
/*@globals rpmGlobalMacroContext @*/
38
/*@modifies rpmGlobalMacroContext @*/
39
{
40
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
41
struct
tagMacro
* tagm;
42
char
numbuf[64];
43
const
char
* val;
44
rpmuint64_t
ival;
45
int
xx;
46
47
numbuf[0] =
'\0'
;
48
/* XXX pre-expand %{buildroot} (if any) */
49
{
const
char
*s =
rpmExpand
(
"%{?buildroot}"
, NULL);
50
if
(s && *s)
51
(void)
addMacro
(NULL,
"..buildroot"
, NULL, s, -1);
52
s =
_free
(s);
53
}
54
{
const
char
*s =
rpmExpand
(
"%{?_builddir}"
, NULL);
55
if
(s && *s)
56
(void)
addMacro
(NULL,
".._builddir"
, NULL, s, -1);
57
s =
_free
(s);
58
}
59
60
for
(tagm =
tagMacros
; tagm->
macroname
!= NULL; tagm++) {
61
he->
tag
= tagm->
tag
;
62
xx =
headerGet
(h, he, 0);
63
if
(!xx)
64
continue
;
65
val = NULL;
66
ival = 0;
67
switch
(he->
t
) {
68
case
RPM_UINT8_TYPE
:
69
ival = (
rpmuint64_t
)he->
p
.
ui8p
[0];
70
val = numbuf;
71
/*@switchbreak@*/
break
;
72
case
RPM_UINT16_TYPE
:
73
ival = (
rpmuint64_t
)he->
p
.
ui16p
[0];
74
val = numbuf;
75
/*@switchbreak@*/
break
;
76
case
RPM_UINT32_TYPE
:
77
ival = (
rpmuint64_t
)he->
p
.
ui32p
[0];
78
val = numbuf;
79
/*@switchbreak@*/
break
;
80
case
RPM_UINT64_TYPE
:
81
ival = he->
p
.
ui64p
[0];
82
val = numbuf;
83
/*@switchbreak@*/
break
;
84
case
RPM_STRING_TYPE
:
85
val = he->
p
.
str
;
86
/*@switchbreak@*/
break
;
87
case
RPM_I18NSTRING_TYPE
:
88
#
if
!defined(
SUPPORT_I18NSTRING_TYPE
)
89
assert(0);
90
#endif
91
case
RPM_STRING_ARRAY_TYPE
:
92
case
RPM_BIN_TYPE
:
93
default
:
94
/*@switchbreak@*/
break
;
95
}
96
97
if
(val) {
98
/*@-duplicatequals@*/
99
if
(val == numbuf)
100
sprintf(numbuf,
"%llu"
, (
unsigned
long
long
)ival);
101
/*@=duplicatequals@*/
102
addMacro
(NULL, tagm->
macroname
, NULL, val, -1);
103
}
104
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
105
}
106
return
0;
107
}
108
/*@=globs =mods =incondefs@*/
109
110
/*@-globs -mods -incondefs@*/
111
int
headerMacrosUnload
(
Header
h)
112
/*@globals rpmGlobalMacroContext @*/
113
/*@modifies rpmGlobalMacroContext @*/
114
{
115
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
116
struct
tagMacro
* tagm;
117
int
xx;
118
119
for
(tagm =
tagMacros
; tagm->
macroname
!= NULL; tagm++) {
120
he->
tag
= tagm->
tag
;
121
xx =
headerGet
(h, he, 0);
122
if
(!xx)
123
continue
;
124
switch
(he->
t
) {
125
case
RPM_UINT32_TYPE
:
126
delMacro
(NULL, tagm->
macroname
);
127
/*@switchbreak@*/
break
;
128
case
RPM_STRING_TYPE
:
129
delMacro
(NULL, tagm->
macroname
);
130
/*@switchbreak@*/
break
;
131
case
RPM_I18NSTRING_TYPE
:
132
#if !defined(SUPPORT_I18NSTRING_TYPE)
133
assert(0);
134
#endif
135
case
RPM_STRING_ARRAY_TYPE
:
136
case
RPM_BIN_TYPE
:
137
case
RPM_UINT8_TYPE
:
138
case
RPM_UINT16_TYPE
:
139
case
RPM_UINT64_TYPE
:
140
default
:
141
/*@switchbreak@*/
break
;
142
}
143
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
144
}
145
146
/* XXX restore previous %{buildroot} (if any) */
147
{
const
char
*s =
rpmExpand
(
"%{?_builddir}"
, NULL);
148
if
(s && *s)
149
(void)
delMacro
(NULL,
"_builddir"
);
150
s =
_free
(s);
151
}
152
{
const
char
*s =
rpmExpand
(
"%{?buildroot}"
, NULL);
153
if
(s && *s)
154
(void)
delMacro
(NULL,
"buildroot"
);
155
s =
_free
(s);
156
}
157
158
return
0;
159
}
160
/*@=globs =mods =incondefs@*/
161
162
int
headerNEVRA
(
Header
h,
const
char
**np,
/*@unused@*/
const
char
**ep,
163
const
char
**vp,
const
char
**rp,
const
char
**ap)
164
{
165
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
166
167
/*@-onlytrans@*/
168
if
(np) {
169
he->
tag
=
RPMTAG_NAME
;
170
if
(
headerGet
(h, he, 0)
171
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
172
*np =
xstrdup
(he->
p
.
str
);
173
else
174
*np = NULL;
175
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
176
}
177
if
(vp) {
178
he->
tag
=
RPMTAG_VERSION
;
179
if
(
headerGet
(h, he, 0)
180
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
181
*vp =
xstrdup
(he->
p
.
str
);
182
else
183
*vp = NULL;
184
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
185
}
186
if
(rp) {
187
he->
tag
=
RPMTAG_RELEASE
;
188
if
(
headerGet
(h, he, 0)
189
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
190
*rp =
xstrdup
(he->
p
.
str
);
191
else
192
*rp = NULL;
193
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
194
}
195
if
(ap) {
196
#if !defined(RPM_VENDOR_OPENPKG)
/* no-architecture-expose */
197
/* do not expose the architecture as this is too less
198
information, as in OpenPKG the "platform" is described by the
199
architecture+operating-system combination. But as the whole
200
"platform" information is actually overkill, just revert to the
201
RPM 4 behaviour and do not expose any such information at all. */
202
he->
tag
=
RPMTAG_ARCH
;
203
/*@-observertrans -readonlytrans@*/
204
if
(!
headerIsEntry
(h, he->
tag
))
205
*ap =
xstrdup
(
"pubkey"
);
206
else
207
if
(!
headerIsEntry
(h,
RPMTAG_SOURCERPM
))
208
*ap =
xstrdup
(
"src"
);
209
/*@=observertrans =readonlytrans@*/
210
else
211
if
(
headerGet
(h, he, 0)
212
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
213
*ap =
xstrdup
(he->
p
.
str
);
214
else
215
#endif
216
*ap = NULL;
217
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
218
}
219
/*@=onlytrans@*/
220
return
0;
221
}
222
223
rpmuint32_t
hGetColor
(
Header
h)
224
{
225
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
226
rpmuint32_t
hcolor = 0;
227
int
xx;
228
229
he->
tag
=
RPMTAG_FILECOLORS
;
230
xx =
headerGet
(h, he, 0);
231
if
(xx && he->
p
.
ptr
!= NULL && he->
c
> 0) {
232
unsigned
i;
233
for
(i = 0; i < (unsigned) he->
c
; i++)
234
hcolor |= he->
p
.
ui32p
[i];
235
}
236
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
237
hcolor &= 0x0f;
238
239
return
hcolor;
240
}
241
242
void
headerMergeLegacySigs
(
Header
h,
const
Header
sigh)
243
{
244
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
245
HeaderIterator
hi;
246
int
xx;
247
248
if
(h == NULL || sigh == NULL)
249
return
;
250
251
for
(hi =
headerInit
(sigh);
252
headerNext
(hi, he, 0);
253
he->
p
.
ptr
=
_free
(he->
p
.
ptr
))
254
{
255
/* XXX Translate legacy signature tag values. */
256
switch
((
rpmSigTag
)he->
tag
) {
257
case
RPMSIGTAG_SIZE
:
258
he->
tag
=
RPMTAG_SIGSIZE
;
259
/*@switchbreak@*/
break
;
260
case
RPMSIGTAG_MD5
:
261
he->
tag
=
RPMTAG_SIGMD5
;
262
/*@switchbreak@*/
break
;
263
case
RPMSIGTAG_PAYLOADSIZE
:
264
he->
tag
=
RPMTAG_ARCHIVESIZE
;
265
/*@switchbreak@*/
break
;
266
case
RPMSIGTAG_SHA1
:
267
case
RPMSIGTAG_DSA
:
268
case
RPMSIGTAG_RSA
:
269
default
:
270
/* Skip all unknown tags that are not in the signature tag range. */
271
if
(!(he->
tag
>=
HEADER_SIGBASE
&& he->
tag
<
HEADER_TAGBASE
))
272
continue
;
273
/*@switchbreak@*/
break
;
274
}
275
assert(he->
p
.
ptr
!= NULL);
276
if
(!
headerIsEntry
(h, he->
tag
)) {
277
if
(
hdrchkType
(he->
t
))
278
continue
;
279
if
(
hdrchkData
(he->
c
))
280
continue
;
281
switch
(he->
t
) {
282
default
:
283
assert(0);
/* XXX keep gcc quiet */
284
/*@switchbreak@*/
break
;
285
case
RPM_UINT8_TYPE
:
286
case
RPM_UINT16_TYPE
:
287
case
RPM_UINT32_TYPE
:
288
case
RPM_UINT64_TYPE
:
289
if
(he->
c
!= 1)
290
continue
;
291
/*@switchbreak@*/
break
;
292
case
RPM_STRING_TYPE
:
293
case
RPM_BIN_TYPE
:
294
if
(he->
c
>= 16*1024)
295
continue
;
296
/*@switchbreak@*/
break
;
297
case
RPM_I18NSTRING_TYPE
:
298
#if !defined(SUPPORT_I18NSTRING_TYPE)
299
assert(0);
300
#endif
301
case
RPM_STRING_ARRAY_TYPE
:
302
continue
;
303
/*@notreached@*/
/*@switchbreak@*/
break
;
304
}
305
xx =
headerPut
(h, he, 0);
306
assert(xx == 1);
307
}
308
}
309
hi =
headerFini
(hi);
310
}
311
312
Header
headerRegenSigHeader
(
const
Header
h,
int
noArchiveSize)
313
{
314
HE_t
he = (
HE_t
) memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
315
Header
sigh =
headerNew
();
316
HeaderIterator
hi;
317
int
xx;
318
319
for
(hi =
headerInit
(h);
320
headerNext
(hi, he, 0);
321
he->
p
.
ptr
=
_free
(he->
p
.
ptr
))
322
{
323
/* XXX Translate legacy signature tag values. */
324
switch
(he->
tag
) {
325
case
RPMTAG_SIGSIZE
:
326
he->
tag
= (
rpmTag
)
RPMSIGTAG_SIZE
;
327
/*@switchbreak@*/
break
;
328
case
RPMTAG_SIGMD5
:
329
he->
tag
= (
rpmTag
)
RPMSIGTAG_MD5
;
330
/*@switchbreak@*/
break
;
331
case
RPMTAG_ARCHIVESIZE
:
332
/* XXX rpm-4.1 and later has archive size in signature header. */
333
if
(noArchiveSize)
334
continue
;
335
he->
tag
= (
rpmTag
)
RPMSIGTAG_PAYLOADSIZE
;
336
/*@switchbreak@*/
break
;
337
case
RPMTAG_SHA1HEADER
:
338
case
RPMTAG_DSAHEADER
:
339
case
RPMTAG_RSAHEADER
:
340
default
:
341
/* Skip all unknown tags that are not in the signature tag range. */
342
if
(!(he->
tag
>=
HEADER_SIGBASE
&& he->
tag
<
HEADER_TAGBASE
))
343
continue
;
344
/*@switchbreak@*/
break
;
345
}
346
assert(he->
p
.
ptr
!= NULL);
347
if
(!
headerIsEntry
(sigh, he->
tag
)) {
348
xx =
headerPut
(sigh, he, 0);
349
assert(xx == 1);
350
}
351
}
352
hi =
headerFini
(hi);
353
return
sigh;
354
}
Generated on Mon Nov 5 2012 15:32:19 for rpm by
1.8.1.2