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
|
/*
* Copyright © 2008 Per Øyvind Karlsen <peroyvind@mandriva.org>
*
* $Id$
*/
#define RPM_NULL_TYPE 0
#define RPM_CHAR_TYPE RPM_UINT8_TYPE
#define RPM_INT8_TYPE RPM_UINT8_TYPE
#define RPM_INT16_TYPE RPM_UINT16_TYPE
#define RPM_INT32_TYPE RPM_UINT32_TYPE
#define WITH_DB
#include <rpm/rpmevr.h>
#include <rpm/rpmio.h>
#include <rpm/pkgio.h>
#include <rpm/rpmcb.h>
#include <rpm/rpmts.h>
#include <rpm/rpmmacro.h>
enum hMagic {
HEADER_MAGIC_NO = 0,
HEADER_MAGIC_YES = 1
};
typedef uint32_t * hTAG_t;
typedef uint32_t * hTYP_t;
typedef const void * hPTR_t;
typedef uint32_t * hCNT_t;
typedef uint32_t int_32;
typedef uint16_t uint_16;
typedef uint8_t byte;
typedef union hRET_s {
const void * ptr;
const char ** argv;
const char * str;
uint32_t * ui32p;
uint16_t * ui16p;
uint32_t * i32p;
uint16_t * i16p;
uint8_t * i8p;
} * hRET_t;
static inline int headerGetEntry(Header h, int_32 tag, hTYP_t type, void ** p, hCNT_t c){
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
int rc;
/* Always ensure to initialize */
*(void **)p = NULL;
he->tag = tag;
rc = headerGet(h, he, tag);
if (rc) {
if (type) *type = he->t;
if (p) *(void **) p = he->p.ptr;
if (c) *c = he->c;
}
return rc;
}
static int headerAddEntry(Header h, int_32 tag, int_32 type, const void * p, int_32 c) {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = tag;
he->t = type;
he->p.str = p;
he->c = c;
return headerPut(h, he, 0);
}
static int headerRemoveEntry(Header h, int_32 tag) {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = tag;
return headerDel(h, he, 0);
}
int headerModifyEntry(Header h, int_32 tag, int_32 type, const void * p, int_32 c) {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = tag;
he->t = type;
he->p.str = p;
he->c = c;
return headerMod(h, he, 0);
}
static int headerNextIterator(HeaderIterator hi, hTAG_t tag, hTYP_t type, hPTR_t * p, hCNT_t c) {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = (rpmTag)tag;
return headerNext(hi, he, 0);
}
static HeaderIterator headerFreeIterator(HeaderIterator hi) {
return headerFini(hi);
}
static HeaderIterator headerInitIterator(Header h){
return headerInit(h);
}
void * headerFreeData(const void * data, rpmTagType type) {
if (data)
free((void *)data);
return NULL;
}
static int headerWrite(void * _fd, Header h, enum hMagic magicp) {
const char item[] = "Header";
const char * msg = NULL;
rpmRC rc = rpmpkgWrite(item, _fd, h, &msg);
if (rc != RPMRC_OK) {
rpmlog(RPMLOG_ERR, "%s: %s: %s\n", "headerWrite", item, msg);
rc = RPMRC_FAIL;
}
msg = _free(msg);
return rc;
}
static inline Header headerRead(void * _fd, enum hMagic magicp) {
const char item[] = "Header";
Header h = NULL;
const char * msg = NULL;
rpmRC rc = rpmpkgRead(item, _fd, &h, &msg);
switch (rc) {
default:
rpmlog(RPMLOG_ERR, "%s: %s: %s\n", "headerRead", item, msg);
case RPMRC_NOTFOUND:
h = NULL;
case RPMRC_OK:
break;
}
msg = _free(msg);
return h;
}
int rpmMachineScore(int type, const char * name) {
char * platform = rpmExpand(name, "-%{_real_vendor}-%{_target_os}%{?_gnu}", NULL);
int score = rpmPlatformScore(platform, NULL, 0);
_free(platform);
return score;
}
|