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_SHA256:
175 kv->num = 0; /* not stringified yet */
176 kv->str = (const char *)dp;
177 return dp + SIZEOF_SHA256;
178 case REPOKEY_TYPE_BINARY:
179 dp = data_read_id(dp, (Id *)&kv->num);
180 kv->str = (const char *)dp;
182 case REPOKEY_TYPE_IDARRAY:
183 return data_read_ideof(dp, &kv->id, &kv->eof);
184 case REPOKEY_TYPE_DIRSTRARRAY:
185 dp = data_read_ideof(dp, &kv->id, &kv->eof);
186 kv->num = 0; /* not stringified yet */
187 kv->str = (const char *)dp;
188 return dp + strlen(kv->str) + 1;
189 case REPOKEY_TYPE_DIRNUMNUMARRAY:
190 dp = data_read_id(dp, &kv->id);
191 dp = data_read_id(dp, (Id *)&kv->num);
192 return data_read_ideof(dp, (Id *)&kv->num2, &kv->eof);
193 case REPOKEY_TYPE_FIXARRAY:
194 dp = data_read_id(dp, (Id *)&kv->num);
195 return data_read_id(dp, &kv->id);
196 case REPOKEY_TYPE_FLEXARRAY:
197 return data_read_id(dp, (Id *)&kv->num);
203 static inline unsigned char *
204 data_skip(unsigned char *dp, int type)
209 case REPOKEY_TYPE_VOID:
210 case REPOKEY_TYPE_CONSTANT:
211 case REPOKEY_TYPE_CONSTANTID:
212 case REPOKEY_TYPE_DELETED:
214 case REPOKEY_TYPE_ID:
215 case REPOKEY_TYPE_NUM:
216 case REPOKEY_TYPE_DIR:
217 while ((*dp & 0x80) != 0)
220 case REPOKEY_TYPE_U32:
222 case REPOKEY_TYPE_MD5:
223 return dp + SIZEOF_MD5;
224 case REPOKEY_TYPE_SHA1:
225 return dp + SIZEOF_SHA1;
226 case REPOKEY_TYPE_SHA256:
227 return dp + SIZEOF_SHA256;
228 case REPOKEY_TYPE_IDARRAY:
229 case REPOKEY_TYPE_REL_IDARRAY:
230 while ((*dp & 0xc0) != 0)
233 case REPOKEY_TYPE_STR:
237 case REPOKEY_TYPE_BINARY:
240 dp = data_read_id(dp, (Id *)&len);
243 case REPOKEY_TYPE_DIRSTRARRAY:
246 while ((*dp & 0x80) != 0)
255 case REPOKEY_TYPE_DIRNUMNUMARRAY:
258 while ((*dp & 0x80) != 0)
261 while ((*dp & 0x80) != 0)
264 while ((*dp & 0x80) != 0)
275 static inline unsigned char *
276 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
283 case REPOKEY_TYPE_VOID:
284 case REPOKEY_TYPE_CONSTANT:
285 case REPOKEY_TYPE_CONSTANTID:
286 case REPOKEY_TYPE_DELETED:
288 case REPOKEY_TYPE_NUM:
289 while ((*dp & 0x80) != 0)
292 case REPOKEY_TYPE_U32:
294 case REPOKEY_TYPE_MD5:
295 return dp + SIZEOF_MD5;
296 case REPOKEY_TYPE_SHA1:
297 return dp + SIZEOF_SHA1;
298 case REPOKEY_TYPE_SHA256:
299 return dp + SIZEOF_SHA256;
300 case REPOKEY_TYPE_ID:
301 dp = data_read_id(dp, &id);
305 case REPOKEY_TYPE_DIR:
306 dp = data_read_id(dp, &id);
310 case REPOKEY_TYPE_IDARRAY:
313 dp = data_read_ideof(dp, &id, &eof);
319 case REPOKEY_TYPE_STR:
323 case REPOKEY_TYPE_BINARY:
326 dp = data_read_id(dp, (Id *)&len);
329 case REPOKEY_TYPE_DIRSTRARRAY:
332 dp = data_read_ideof(dp, &id, &eof);
341 case REPOKEY_TYPE_DIRNUMNUMARRAY:
344 dp = data_read_id(dp, &id);
347 while ((*dp & 0x80) != 0)
350 while ((*dp & 0x80) != 0)
361 #endif /* LIBSOLV_REPOPACK */