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->str = (const char *)dp;
168 return dp + SIZEOF_MD5;
169 case REPOKEY_TYPE_SHA1:
170 kv->str = (const char *)dp;
171 return dp + SIZEOF_SHA1;
172 case REPOKEY_TYPE_SHA256:
173 kv->str = (const char *)dp;
174 return dp + SIZEOF_SHA256;
175 case REPOKEY_TYPE_BINARY:
176 dp = data_read_id(dp, (Id *)&kv->num);
177 kv->str = (const char *)dp;
179 case REPOKEY_TYPE_IDARRAY:
180 return data_read_ideof(dp, &kv->id, &kv->eof);
181 case REPOKEY_TYPE_DIRSTRARRAY:
182 dp = data_read_ideof(dp, &kv->id, &kv->eof);
183 kv->str = (const char *)dp;
184 return dp + strlen(kv->str) + 1;
185 case REPOKEY_TYPE_DIRNUMNUMARRAY:
186 dp = data_read_id(dp, &kv->id);
187 dp = data_read_id(dp, (Id *)&kv->num);
188 return data_read_ideof(dp, (Id *)&kv->num2, &kv->eof);
189 case REPOKEY_TYPE_FIXARRAY:
190 dp = data_read_id(dp, (Id *)&kv->num);
191 return data_read_id(dp, &kv->id);
192 case REPOKEY_TYPE_FLEXARRAY:
193 return data_read_id(dp, (Id *)&kv->num);
199 static inline unsigned char *
200 data_skip(unsigned char *dp, int type)
205 case REPOKEY_TYPE_VOID:
206 case REPOKEY_TYPE_CONSTANT:
207 case REPOKEY_TYPE_CONSTANTID:
208 case REPOKEY_TYPE_DELETED:
210 case REPOKEY_TYPE_ID:
211 case REPOKEY_TYPE_NUM:
212 case REPOKEY_TYPE_DIR:
213 while ((*dp & 0x80) != 0)
216 case REPOKEY_TYPE_U32:
218 case REPOKEY_TYPE_MD5:
219 return dp + SIZEOF_MD5;
220 case REPOKEY_TYPE_SHA1:
221 return dp + SIZEOF_SHA1;
222 case REPOKEY_TYPE_SHA256:
223 return dp + SIZEOF_SHA256;
224 case REPOKEY_TYPE_IDARRAY:
225 case REPOKEY_TYPE_REL_IDARRAY:
226 while ((*dp & 0xc0) != 0)
229 case REPOKEY_TYPE_STR:
233 case REPOKEY_TYPE_BINARY:
236 dp = data_read_id(dp, (Id *)&len);
239 case REPOKEY_TYPE_DIRSTRARRAY:
242 while ((*dp & 0x80) != 0)
251 case REPOKEY_TYPE_DIRNUMNUMARRAY:
254 while ((*dp & 0x80) != 0)
257 while ((*dp & 0x80) != 0)
260 while ((*dp & 0x80) != 0)
271 static inline unsigned char *
272 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
279 case REPOKEY_TYPE_VOID:
280 case REPOKEY_TYPE_CONSTANT:
281 case REPOKEY_TYPE_CONSTANTID:
282 case REPOKEY_TYPE_DELETED:
284 case REPOKEY_TYPE_NUM:
285 while ((*dp & 0x80) != 0)
288 case REPOKEY_TYPE_U32:
290 case REPOKEY_TYPE_MD5:
291 return dp + SIZEOF_MD5;
292 case REPOKEY_TYPE_SHA1:
293 return dp + SIZEOF_SHA1;
294 case REPOKEY_TYPE_SHA256:
295 return dp + SIZEOF_SHA256;
296 case REPOKEY_TYPE_ID:
297 dp = data_read_id(dp, &id);
301 case REPOKEY_TYPE_DIR:
302 dp = data_read_id(dp, &id);
306 case REPOKEY_TYPE_IDARRAY:
309 dp = data_read_ideof(dp, &id, &eof);
315 case REPOKEY_TYPE_STR:
319 case REPOKEY_TYPE_BINARY:
322 dp = data_read_id(dp, (Id *)&len);
325 case REPOKEY_TYPE_DIRSTRARRAY:
328 dp = data_read_ideof(dp, &id, &eof);
337 case REPOKEY_TYPE_DIRNUMNUMARRAY:
340 dp = data_read_id(dp, &id);
343 while ((*dp & 0x80) != 0)
346 while ((*dp & 0x80) != 0)
357 #endif /* LIBSOLV_REPOPACK */