rpm
5.2.1
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, 0 }
33
};
34
35
/*@-globs -mods -incondefs@*/
36
int
headerMacrosLoad
(
Header
h)
37
/*@globals rpmGlobalMacroContext @*/
38
/*@modifies rpmGlobalMacroContext @*/
39
{
40
HE_t
he = 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_STRING_ARRAY_TYPE
:
88
case
RPM_I18NSTRING_TYPE
:
89
case
RPM_BIN_TYPE
:
90
default
:
91
/*@switchbreak@*/
break
;
92
}
93
94
if
(val) {
95
/*@-duplicatequals@*/
96
if
(val == numbuf)
97
sprintf(numbuf,
"%llu"
, (
unsigned
long
long
)ival);
98
/*@=duplicatequals@*/
99
addMacro
(NULL, tagm->
macroname
, NULL, val, -1);
100
}
101
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
102
}
103
return
0;
104
}
105
/*@=globs =mods =incondefs@*/
106
107
/*@-globs -mods -incondefs@*/
108
int
headerMacrosUnload
(
Header
h)
109
/*@globals rpmGlobalMacroContext @*/
110
/*@modifies rpmGlobalMacroContext @*/
111
{
112
HE_t
he = memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
113
struct
tagMacro
* tagm;
114
int
xx;
115
116
for
(tagm =
tagMacros
; tagm->
macroname
!= NULL; tagm++) {
117
he->
tag
= tagm->
tag
;
118
xx =
headerGet
(h, he, 0);
119
if
(!xx)
120
continue
;
121
switch
(he->
t
) {
122
case
RPM_UINT32_TYPE
:
123
delMacro
(NULL, tagm->
macroname
);
124
/*@switchbreak@*/
break
;
125
case
RPM_STRING_TYPE
:
126
delMacro
(NULL, tagm->
macroname
);
127
/*@switchbreak@*/
break
;
128
case
RPM_STRING_ARRAY_TYPE
:
129
case
RPM_I18NSTRING_TYPE
:
130
case
RPM_BIN_TYPE
:
131
case
RPM_UINT8_TYPE
:
132
case
RPM_UINT16_TYPE
:
133
case
RPM_UINT64_TYPE
:
134
default
:
135
/*@switchbreak@*/
break
;
136
}
137
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
138
}
139
140
/* XXX restore previous %{buildroot} (if any) */
141
{
const
char
*s =
rpmExpand
(
"%{?_builddir}"
, NULL);
142
if
(s && *s)
143
(void)
delMacro
(NULL,
"_builddir"
);
144
s =
_free
(s);
145
}
146
{
const
char
*s =
rpmExpand
(
"%{?buildroot}"
, NULL);
147
if
(s && *s)
148
(void)
delMacro
(NULL,
"buildroot"
);
149
s =
_free
(s);
150
}
151
152
return
0;
153
}
154
/*@=globs =mods =incondefs@*/
155
156
int
headerNEVRA
(
Header
h,
const
char
**np,
/*@unused@*/
const
char
**ep,
157
const
char
**vp,
const
char
**rp,
const
char
**ap)
158
{
159
HE_t
he = memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
160
161
/*@-onlytrans@*/
162
if
(np) {
163
he->
tag
=
RPMTAG_NAME
;
164
if
(
headerGet
(h, he, 0)
165
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
166
*np =
xstrdup
(he->
p
.
str
);
167
else
168
*np = NULL;
169
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
170
}
171
if
(vp) {
172
he->
tag
=
RPMTAG_VERSION
;
173
if
(
headerGet
(h, he, 0)
174
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
175
*vp =
xstrdup
(he->
p
.
str
);
176
else
177
*vp = NULL;
178
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
179
}
180
if
(rp) {
181
he->
tag
=
RPMTAG_RELEASE
;
182
if
(
headerGet
(h, he, 0)
183
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
184
*rp =
xstrdup
(he->
p
.
str
);
185
else
186
*rp = NULL;
187
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
188
}
189
if
(ap) {
190
#if !defined(RPM_VENDOR_OPENPKG)
/* no-architecture-expose */
191
/* do not expose the architecture as this is too less
192
information, as in OpenPKG the "platform" is described by the
193
architecture+operating-system combination. But as the whole
194
"platform" information is actually overkill, just revert to the
195
RPM 4 behaviour and do not expose any such information at all. */
196
he->
tag
=
RPMTAG_ARCH
;
197
/*@-observertrans -readonlytrans@*/
198
if
(!
headerIsEntry
(h, he->
tag
))
199
*ap =
xstrdup
(
"pubkey"
);
200
else
201
if
(!
headerIsEntry
(h,
RPMTAG_SOURCERPM
))
202
*ap =
xstrdup
(
"src"
);
203
/*@=observertrans =readonlytrans@*/
204
else
205
if
(
headerGet
(h, he, 0)
206
&& he->
t
==
RPM_STRING_TYPE
&& he->
c
== 1)
207
*ap =
xstrdup
(he->
p
.
str
);
208
else
209
#endif
210
*ap = NULL;
211
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
212
}
213
/*@=onlytrans@*/
214
return
0;
215
}
216
217
rpmuint32_t
hGetColor
(
Header
h)
218
{
219
HE_t
he = memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
220
rpmuint32_t
hcolor = 0;
221
int
xx;
222
223
he->
tag
=
RPMTAG_FILECOLORS
;
224
xx =
headerGet
(h, he, 0);
225
if
(xx && he->
p
.
ptr
!= NULL && he->
c
> 0) {
226
unsigned
i;
227
for
(i = 0; i < (unsigned) he->
c
; i++)
228
hcolor |= he->
p
.
ui32p
[i];
229
}
230
he->
p
.
ptr
=
_free
(he->
p
.
ptr
);
231
hcolor &= 0x0f;
232
233
return
hcolor;
234
}
235
236
void
headerMergeLegacySigs
(
Header
h,
const
Header
sigh)
237
{
238
HE_t
he = memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
239
HeaderIterator
hi;
240
int
xx;
241
242
if
(h == NULL || sigh == NULL)
243
return
;
244
245
for
(hi =
headerInit
(sigh);
246
headerNext
(hi, he, 0);
247
he->
p
.
ptr
=
_free
(he->
p
.
ptr
))
248
{
249
/* XXX Translate legacy signature tag values. */
250
switch
((
rpmSigTag
)he->
tag
) {
251
case
RPMSIGTAG_SIZE
:
252
he->
tag
=
RPMTAG_SIGSIZE
;
253
/*@switchbreak@*/
break
;
254
case
RPMSIGTAG_MD5
:
255
he->
tag
=
RPMTAG_SIGMD5
;
256
/*@switchbreak@*/
break
;
257
case
RPMSIGTAG_PAYLOADSIZE
:
258
he->
tag
=
RPMTAG_ARCHIVESIZE
;
259
/*@switchbreak@*/
break
;
260
case
RPMSIGTAG_SHA1
:
261
case
RPMSIGTAG_DSA
:
262
case
RPMSIGTAG_RSA
:
263
default
:
264
/* Skip all unknown tags that are not in the signature tag range. */
265
if
(!(he->
tag
>=
HEADER_SIGBASE
&& he->
tag
<
HEADER_TAGBASE
))
266
continue
;
267
/*@switchbreak@*/
break
;
268
}
269
assert(he->
p
.
ptr
!= NULL);
270
if
(!
headerIsEntry
(h, he->
tag
)) {
271
if
(
hdrchkType
(he->
t
))
272
continue
;
273
if
(
hdrchkData
(he->
c
))
274
continue
;
275
switch
(he->
t
) {
276
default
:
277
assert(0);
/* XXX keep gcc quiet */
278
/*@switchbreak@*/
break
;
279
case
RPM_UINT8_TYPE
:
280
case
RPM_UINT16_TYPE
:
281
case
RPM_UINT32_TYPE
:
282
case
RPM_UINT64_TYPE
:
283
if
(he->
c
!= 1)
284
continue
;
285
/*@switchbreak@*/
break
;
286
case
RPM_STRING_TYPE
:
287
case
RPM_BIN_TYPE
:
288
if
(he->
c
>= 16*1024)
289
continue
;
290
/*@switchbreak@*/
break
;
291
case
RPM_STRING_ARRAY_TYPE
:
292
case
RPM_I18NSTRING_TYPE
:
293
continue
;
294
/*@notreached@*/
/*@switchbreak@*/
break
;
295
}
296
xx =
headerPut
(h, he, 0);
297
assert(xx == 1);
298
}
299
}
300
hi =
headerFini
(hi);
301
}
302
303
Header
headerRegenSigHeader
(
const
Header
h,
int
noArchiveSize)
304
{
305
HE_t
he = memset(
alloca
(
sizeof
(*he)), 0,
sizeof
(*he));
306
Header
sigh =
headerNew
();
307
HeaderIterator
hi;
308
int
xx;
309
310
for
(hi =
headerInit
(h);
311
headerNext
(hi, he, 0);
312
he->
p
.
ptr
=
_free
(he->
p
.
ptr
))
313
{
314
/* XXX Translate legacy signature tag values. */
315
switch
(he->
tag
) {
316
case
RPMTAG_SIGSIZE
:
317
he->
tag
= (
rpmTag
)
RPMSIGTAG_SIZE
;
318
/*@switchbreak@*/
break
;
319
case
RPMTAG_SIGMD5
:
320
he->
tag
= (
rpmTag
)
RPMSIGTAG_MD5
;
321
/*@switchbreak@*/
break
;
322
case
RPMTAG_ARCHIVESIZE
:
323
/* XXX rpm-4.1 and later has archive size in signature header. */
324
if
(noArchiveSize)
325
continue
;
326
he->
tag
= (
rpmTag
)
RPMSIGTAG_PAYLOADSIZE
;
327
/*@switchbreak@*/
break
;
328
case
RPMTAG_SHA1HEADER
:
329
case
RPMTAG_DSAHEADER
:
330
case
RPMTAG_RSAHEADER
:
331
default
:
332
/* Skip all unknown tags that are not in the signature tag range. */
333
if
(!(he->
tag
>=
HEADER_SIGBASE
&& he->
tag
<
HEADER_TAGBASE
))
334
continue
;
335
/*@switchbreak@*/
break
;
336
}
337
assert(he->
p
.
ptr
!= NULL);
338
if
(!
headerIsEntry
(sigh, he->
tag
)) {
339
xx =
headerPut
(sigh, he, 0);
340
assert(xx == 1);
341
}
342
}
343
hi =
headerFini
(hi);
344
return
sigh;
345
}
Generated on Thu Sep 26 2013 19:13:39 for rpm by
1.8.3.1