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
|
/*
* Copyright (c) 2007, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
/* pack/unpack functions for key data */
#ifndef SATSOLVER_REPOPACK_H
#define SATSOLVER_REPOPACK_H
static inline unsigned char *
data_read_id(unsigned char *dp, Id *idp)
{
Id x = 0;
unsigned char c;
for (;;)
{
c = *dp++;
if (!(c & 0x80))
{
*idp = (x << 7) ^ c;
return dp;
}
x = (x << 7) ^ c ^ 128;
}
}
static inline unsigned char *
data_read_ideof(unsigned char *dp, Id *idp, int *eof)
{
Id x = 0;
unsigned char c;
for (;;)
{
c = *dp++;
if (!(c & 0x80))
{
if (c & 0x40)
{
c ^= 0x40;
*eof = 0;
}
else
*eof = 1;
*idp = (x << 6) ^ c;
return dp;
}
x = (x << 7) ^ c ^ 128;
}
}
static inline unsigned char *
data_read_u32(unsigned char *dp, unsigned int *nump)
{
*nump = (dp[0] << 24) | (dp[1] << 16) | (dp[2] << 8) | dp[3];
return dp + 4;
}
static inline unsigned char *
data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
{
kv->eof = 1;
if (!dp)
return 0;
switch (key->type)
{
case REPOKEY_TYPE_VOID:
return dp;
case REPOKEY_TYPE_CONSTANT:
kv->num = key->size;
return dp;
case REPOKEY_TYPE_CONSTANTID:
kv->id = key->size;
return dp;
case REPOKEY_TYPE_STR:
kv->str = (const char *)dp;
return dp + strlen(kv->str) + 1;
case REPOKEY_TYPE_ID:
case REPOKEY_TYPE_DIR:
return data_read_id(dp, &kv->id);
case REPOKEY_TYPE_NUM:
return data_read_id(dp, &kv->num);
case REPOKEY_TYPE_U32:
return data_read_u32(dp, (unsigned int *)&kv->num);
case REPOKEY_TYPE_MD5:
kv->str = (const char *)dp;
return dp + SIZEOF_MD5;
case REPOKEY_TYPE_SHA1:
kv->str = (const char *)dp;
return dp + SIZEOF_SHA1;
case REPOKEY_TYPE_SHA256:
kv->str = (const char *)dp;
return dp + SIZEOF_SHA256;
case REPOKEY_TYPE_IDARRAY:
return data_read_ideof(dp, &kv->id, &kv->eof);
case REPOKEY_TYPE_DIRSTRARRAY:
dp = data_read_ideof(dp, &kv->id, &kv->eof);
kv->str = (const char *)dp;
return dp + strlen(kv->str) + 1;
case REPOKEY_TYPE_DIRNUMNUMARRAY:
dp = data_read_id(dp, &kv->id);
dp = data_read_id(dp, &kv->num);
return data_read_ideof(dp, &kv->num2, &kv->eof);
case REPOKEY_TYPE_FIXARRAY:
dp = data_read_id(dp, &kv->num);
return data_read_id(dp, &kv->id);
case REPOKEY_TYPE_FLEXARRAY:
return data_read_id(dp, &kv->num);
default:
return 0;
}
}
static inline unsigned char *
data_skip(unsigned char *dp, int type)
{
unsigned char x;
switch (type)
{
case REPOKEY_TYPE_VOID:
case REPOKEY_TYPE_CONSTANT:
case REPOKEY_TYPE_CONSTANTID:
return dp;
case REPOKEY_TYPE_ID:
case REPOKEY_TYPE_NUM:
case REPOKEY_TYPE_DIR:
while ((*dp & 0x80) != 0)
dp++;
return dp + 1;
case REPOKEY_TYPE_U32:
return dp + 4;
case REPOKEY_TYPE_MD5:
return dp + SIZEOF_MD5;
case REPOKEY_TYPE_SHA1:
return dp + SIZEOF_SHA1;
case REPOKEY_TYPE_SHA256:
return dp + SIZEOF_SHA256;
case REPOKEY_TYPE_IDARRAY:
case REPOKEY_TYPE_REL_IDARRAY:
while ((*dp & 0xc0) != 0)
dp++;
return dp + 1;
case REPOKEY_TYPE_STR:
while ((*dp) != 0)
dp++;
return dp + 1;
case REPOKEY_TYPE_DIRSTRARRAY:
for (;;)
{
while ((*dp & 0x80) != 0)
dp++;
x = *dp++;
while ((*dp) != 0)
dp++;
dp++;
if (!(x & 0x40))
return dp;
}
case REPOKEY_TYPE_DIRNUMNUMARRAY:
for (;;)
{
while ((*dp & 0x80) != 0)
dp++;
dp++;
while ((*dp & 0x80) != 0)
dp++;
dp++;
while ((*dp & 0x80) != 0)
dp++;
if (!(*dp & 0x40))
return dp + 1;
dp++;
}
default:
return 0;
}
}
static inline unsigned char *
data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
{
Id id;
int eof;
switch (type)
{
case REPOKEY_TYPE_VOID:
case REPOKEY_TYPE_CONSTANT:
case REPOKEY_TYPE_CONSTANTID:
return dp;
case REPOKEY_TYPE_NUM:
while ((*dp & 0x80) != 0)
dp++;
return dp + 1;
case REPOKEY_TYPE_U32:
return dp + 4;
case REPOKEY_TYPE_MD5:
return dp + SIZEOF_MD5;
case REPOKEY_TYPE_SHA1:
return dp + SIZEOF_SHA1;
case REPOKEY_TYPE_SHA256:
return dp + SIZEOF_SHA256;
case REPOKEY_TYPE_ID:
dp = data_read_id(dp, &id);
if (id >= maxid)
return 0;
return dp;
case REPOKEY_TYPE_DIR:
dp = data_read_id(dp, &id);
if (id >= maxdir)
return 0;
return dp;
case REPOKEY_TYPE_IDARRAY:
for (;;)
{
dp = data_read_ideof(dp, &id, &eof);
if (id >= maxid)
return 0;
if (eof)
return dp;
}
case REPOKEY_TYPE_STR:
while ((*dp) != 0)
dp++;
return dp + 1;
case REPOKEY_TYPE_DIRSTRARRAY:
for (;;)
{
dp = data_read_ideof(dp, &id, &eof);
if (id >= maxdir)
return 0;
while ((*dp) != 0)
dp++;
dp++;
if (eof)
return dp;
}
case REPOKEY_TYPE_DIRNUMNUMARRAY:
for (;;)
{
dp = data_read_id(dp, &id);
if (id >= maxdir)
return 0;
while ((*dp & 0x80) != 0)
dp++;
dp++;
while ((*dp & 0x80) != 0)
dp++;
if (!(*dp & 0x40))
return dp + 1;
dp++;
}
default:
return 0;
}
}
unsigned char *data_skip_key(Repodata *data, unsigned char *dp, Repokey *key);
#endif /* SATSOLVER_REPOPACK */
|