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
|
/** \ingroup rpmdb
* \file rpmdb/hdrNVR.c
*/
#include "system.h"
#include <rpm/rpmtypes.h>
#include <rpm/header.h>
#include <rpm/rpmstring.h>
#include "debug.h"
int headerNVR(Header h, const char **np, const char **vp, const char **rp)
{
rpmTagType type;
rpm_count_t count;
if (np) {
if (!(headerGetEntry(h, RPMTAG_NAME, &type, (rpm_data_t *) np, &count)
&& type == RPM_STRING_TYPE && count == 1))
*np = NULL;
}
if (vp) {
if (!(headerGetEntry(h, RPMTAG_VERSION, &type, (rpm_data_t *) vp, &count)
&& type == RPM_STRING_TYPE && count == 1))
*vp = NULL;
}
if (rp) {
if (!(headerGetEntry(h, RPMTAG_RELEASE, &type, (rpm_data_t *) rp, &count)
&& type == RPM_STRING_TYPE && count == 1))
*rp = NULL;
}
return 0;
}
int headerNEVRA(Header h, const char **np,
int32_t **ep, const char **vp, const char **rp,
const char **ap)
{
rpmTagType type;
rpm_count_t count;
headerNVR(h, np, vp, rp);
if (ap) {
if (!(headerGetEntry(h, RPMTAG_ARCH, &type, (rpm_data_t *) ap, &count)
&& type == RPM_STRING_TYPE && count == 1))
*ap = NULL;
}
if (ep) {
if (!(headerGetEntry(h, RPMTAG_EPOCH, &type, (rpm_data_t *) ep, &count)
&& type == RPM_INT32_TYPE && count == 1))
*ep = NULL;
}
return 0;
}
char * headerGetNEVR(Header h, const char ** np)
{
const char * n, * v, * r;
char * NVR, * t;
(void) headerNVR(h, &n, &v, &r);
NVR = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + sizeof("--"));
t = stpcpy(t, n);
t = stpcpy(t, "-");
t = stpcpy(t, v);
t = stpcpy(t, "-");
t = stpcpy(t, r);
if (np)
*np = n;
return NVR;
}
char * headerGetNEVRA(Header h, const char ** np)
{
const char * n, * v, * r, * a;
char * NVRA, * t;
int xx;
(void) headerNVR(h, &n, &v, &r);
xx = headerGetEntry(h, RPMTAG_ARCH, NULL, (rpm_data_t *) &a, NULL);
NVRA = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + strlen(a) + sizeof("--."));
t = stpcpy(t, n);
t = stpcpy(t, "-");
t = stpcpy(t, v);
t = stpcpy(t, "-");
t = stpcpy(t, r);
t = stpcpy(t, ".");
t = stpcpy(t, a);
if (np)
*np = n;
return NVRA;
}
char * headerGetEVR(Header h, const char ** np)
{
const char *n, *v, *r;
char *EVR;
int32_t *e;
(void) headerNEVRA(h, &n, &e, &v, &r, NULL);
if (e) {
rasprintf(&EVR, "%d:%s-%s", *e, v, r);
} else {
rasprintf(&EVR, "%s-%s", v, r);
}
if (np)
*np = n;
return EVR;
}
rpm_color_t headerGetColor(Header h)
{
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
rpm_color_t hcolor = 0;
rpm_color_t * fcolors;
rpm_count_t ncolors;
int i;
fcolors = NULL;
ncolors = 0;
if (hge(h, RPMTAG_FILECOLORS, NULL, (rpm_data_t *)&fcolors, &ncolors)
&& fcolors != NULL && ncolors > 0)
{
for (i = 0; i < ncolors; i++)
hcolor |= fcolors[i];
}
hcolor &= 0x0f;
return hcolor;
}
int headerIsSource(Header h)
{
return (!headerIsEntry(h, RPMTAG_SOURCERPM));
}
|