2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* pack/unpack functions for key data */
10 #ifndef LIBSOLV_REPOPACK_H
11 #define LIBSOLV_REPOPACK_H
13 static inline unsigned char *
14 data_read_id(unsigned char *dp, Id *idp)
25 *idp = dp[0] << 7 ^ dp[1] ^ 0x4000;
30 *idp = dp[0] << 14 ^ dp[1] << 7 ^ dp[2] ^ 0x204000;
35 *idp = dp[0] << 21 ^ dp[1] << 14 ^ dp[2] << 7 ^ dp[3] ^ 0x10204000;
38 x = dp[0] << 28 ^ dp[1] << 21 ^ dp[2] << 14 ^ dp[3] << 7 ^ dp[4] ^ 0x10204000;
54 x = (x << 7) ^ (c ^ 128);
58 static inline unsigned char *
59 data_read_num64(unsigned char *dp, unsigned int *low, unsigned int *high)
61 unsigned long long int x;
72 *low = dp[0] << 7 ^ dp[1] ^ 0x4000;
77 *low = dp[0] << 14 ^ dp[1] << 7 ^ dp[2] ^ 0x204000;
82 *low = dp[0] << 21 ^ dp[1] << 14 ^ dp[2] << 7 ^ dp[3] ^ 0x10204000;
87 *low = dp[0] << 28 ^ dp[1] << 21 ^ dp[2] << 14 ^ dp[3] << 7 ^ dp[4] ^ 0x10204000;
88 *high = (dp[0] ^ 0x80) >> 4;
91 x = (unsigned long long)(dp[0] ^ 0x80) << 28 ^ (unsigned int)(dp[1] << 21 ^ dp[2] << 14 ^ dp[3] << 7 ^ dp[4] ^ 0x10204080);
103 x = (x << 7) ^ (c ^ 128);
107 static inline unsigned char *
108 data_read_ideof(unsigned char *dp, Id *idp, int *eof)
127 x = (x << 7) ^ c ^ 128;
131 static inline unsigned char *
132 data_read_u32(unsigned char *dp, unsigned int *nump)
134 *nump = (dp[0] << 24) | (dp[1] << 16) | (dp[2] << 8) | dp[3];
138 static inline unsigned char *
139 data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
146 case REPOKEY_TYPE_VOID:
148 case REPOKEY_TYPE_CONSTANT:
152 case REPOKEY_TYPE_CONSTANTID:
155 case REPOKEY_TYPE_STR:
156 kv->str = (const char *)dp;
157 return dp + strlen(kv->str) + 1;
158 case REPOKEY_TYPE_ID:
159 case REPOKEY_TYPE_DIR:
160 return data_read_id(dp, &kv->id);
161 case REPOKEY_TYPE_NUM:
162 return data_read_num64(dp, &kv->num, &kv->num2);
163 case REPOKEY_TYPE_U32:
165 return data_read_u32(dp, &kv->num);
166 case REPOKEY_TYPE_MD5:
167 kv->num = 0; /* not stringified yet */
168 kv->str = (const char *)dp;
169 return dp + SIZEOF_MD5;
170 case REPOKEY_TYPE_SHA1:
171 kv->num = 0; /* not stringified yet */
172 kv->str = (const char *)dp;
173 return dp + SIZEOF_SHA1;
174 case REPOKEY_TYPE_SHA224:
175 kv->num = 0; /* not stringified yet */
176 kv->str = (const char *)dp;
177 return dp + SIZEOF_SHA224;
178 case REPOKEY_TYPE_SHA256:
179 kv->num = 0; /* not stringified yet */
180 kv->str = (const char *)dp;
181 return dp + SIZEOF_SHA256;
182 case REPOKEY_TYPE_SHA384:
183 kv->num = 0; /* not stringified yet */
184 kv->str = (const char *)dp;
185 return dp + SIZEOF_SHA384;
186 case REPOKEY_TYPE_SHA512:
187 kv->num = 0; /* not stringified yet */
188 kv->str = (const char *)dp;
189 return dp + SIZEOF_SHA512;
190 case REPOKEY_TYPE_BINARY:
191 dp = data_read_id(dp, (Id *)&kv->num);
192 kv->str = (const char *)dp;
194 case REPOKEY_TYPE_IDARRAY:
195 return data_read_ideof(dp, &kv->id, &kv->eof);
196 case REPOKEY_TYPE_DIRSTRARRAY:
197 dp = data_read_ideof(dp, &kv->id, &kv->eof);
198 kv->num = 0; /* not stringified yet */
199 kv->str = (const char *)dp;
200 return dp + strlen(kv->str) + 1;
201 case REPOKEY_TYPE_DIRNUMNUMARRAY:
202 dp = data_read_id(dp, &kv->id);
203 dp = data_read_id(dp, (Id *)&kv->num);
204 return data_read_ideof(dp, (Id *)&kv->num2, &kv->eof);
205 case REPOKEY_TYPE_FIXARRAY:
206 dp = data_read_id(dp, (Id *)&kv->num);
207 return data_read_id(dp, &kv->id);
208 case REPOKEY_TYPE_FLEXARRAY:
209 return data_read_id(dp, (Id *)&kv->num);
215 static inline unsigned char *
216 data_skip(unsigned char *dp, int type)
221 case REPOKEY_TYPE_VOID:
222 case REPOKEY_TYPE_CONSTANT:
223 case REPOKEY_TYPE_CONSTANTID:
224 case REPOKEY_TYPE_DELETED:
226 case REPOKEY_TYPE_ID:
227 case REPOKEY_TYPE_NUM:
228 case REPOKEY_TYPE_DIR:
229 while ((*dp & 0x80) != 0)
232 case REPOKEY_TYPE_U32:
234 case REPOKEY_TYPE_MD5:
235 return dp + SIZEOF_MD5;
236 case REPOKEY_TYPE_SHA1:
237 return dp + SIZEOF_SHA1;
238 case REPOKEY_TYPE_SHA224:
239 return dp + SIZEOF_SHA224;
240 case REPOKEY_TYPE_SHA256:
241 return dp + SIZEOF_SHA256;
242 case REPOKEY_TYPE_SHA384:
243 return dp + SIZEOF_SHA384;
244 case REPOKEY_TYPE_SHA512:
245 return dp + SIZEOF_SHA512;
246 case REPOKEY_TYPE_IDARRAY:
247 case REPOKEY_TYPE_REL_IDARRAY:
248 while ((*dp & 0xc0) != 0)
251 case REPOKEY_TYPE_STR:
255 case REPOKEY_TYPE_BINARY:
258 dp = data_read_id(dp, (Id *)&len);
261 case REPOKEY_TYPE_DIRSTRARRAY:
264 while ((*dp & 0x80) != 0)
273 case REPOKEY_TYPE_DIRNUMNUMARRAY:
276 while ((*dp & 0x80) != 0)
279 while ((*dp & 0x80) != 0)
282 while ((*dp & 0x80) != 0)
293 static inline unsigned char *
294 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
301 case REPOKEY_TYPE_VOID:
302 case REPOKEY_TYPE_CONSTANT:
303 case REPOKEY_TYPE_CONSTANTID:
304 case REPOKEY_TYPE_DELETED:
306 case REPOKEY_TYPE_NUM:
307 while ((*dp & 0x80) != 0)
310 case REPOKEY_TYPE_U32:
312 case REPOKEY_TYPE_MD5:
313 return dp + SIZEOF_MD5;
314 case REPOKEY_TYPE_SHA1:
315 return dp + SIZEOF_SHA1;
316 case REPOKEY_TYPE_SHA224:
317 return dp + SIZEOF_SHA224;
318 case REPOKEY_TYPE_SHA256:
319 return dp + SIZEOF_SHA256;
320 case REPOKEY_TYPE_SHA384:
321 return dp + SIZEOF_SHA384;
322 case REPOKEY_TYPE_SHA512:
323 return dp + SIZEOF_SHA512;
324 case REPOKEY_TYPE_ID:
325 dp = data_read_id(dp, &id);
329 case REPOKEY_TYPE_DIR:
330 dp = data_read_id(dp, &id);
334 case REPOKEY_TYPE_IDARRAY:
337 dp = data_read_ideof(dp, &id, &eof);
343 case REPOKEY_TYPE_STR:
347 case REPOKEY_TYPE_BINARY:
350 dp = data_read_id(dp, (Id *)&len);
353 case REPOKEY_TYPE_DIRSTRARRAY:
356 dp = data_read_ideof(dp, &id, &eof);
365 case REPOKEY_TYPE_DIRNUMNUMARRAY:
368 dp = data_read_id(dp, &id);
371 while ((*dp & 0x80) != 0)
374 while ((*dp & 0x80) != 0)
385 #endif /* LIBSOLV_REPOPACK */