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)
26 x = (x << 7) ^ (c ^ 128);
30 static inline unsigned char *
31 data_read_num64(unsigned char *dp, unsigned int *low, unsigned int *high)
34 unsigned long long int xx;
47 x = (x << 7) ^ (c ^ 128);
60 xx = (xx << 7) ^ (c ^ 128);
64 static inline unsigned char *
65 data_read_ideof(unsigned char *dp, Id *idp, int *eof)
84 x = (x << 7) ^ c ^ 128;
88 static inline unsigned char *
89 data_read_u32(unsigned char *dp, unsigned int *nump)
91 *nump = (dp[0] << 24) | (dp[1] << 16) | (dp[2] << 8) | dp[3];
95 static inline unsigned char *
96 data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
103 case REPOKEY_TYPE_VOID:
105 case REPOKEY_TYPE_CONSTANT:
109 case REPOKEY_TYPE_CONSTANTID:
112 case REPOKEY_TYPE_STR:
113 kv->str = (const char *)dp;
114 return dp + strlen(kv->str) + 1;
115 case REPOKEY_TYPE_ID:
116 case REPOKEY_TYPE_DIR:
117 return data_read_id(dp, &kv->id);
118 case REPOKEY_TYPE_NUM:
119 return data_read_num64(dp, &kv->num, &kv->num2);
120 case REPOKEY_TYPE_U32:
122 return data_read_u32(dp, &kv->num);
123 case REPOKEY_TYPE_MD5:
124 kv->str = (const char *)dp;
125 return dp + SIZEOF_MD5;
126 case REPOKEY_TYPE_SHA1:
127 kv->str = (const char *)dp;
128 return dp + SIZEOF_SHA1;
129 case REPOKEY_TYPE_SHA256:
130 kv->str = (const char *)dp;
131 return dp + SIZEOF_SHA256;
132 case REPOKEY_TYPE_BINARY:
133 dp = data_read_id(dp, (Id *)&kv->num);
134 kv->str = (const char *)dp;
136 case REPOKEY_TYPE_IDARRAY:
137 return data_read_ideof(dp, &kv->id, &kv->eof);
138 case REPOKEY_TYPE_DIRSTRARRAY:
139 dp = data_read_ideof(dp, &kv->id, &kv->eof);
140 kv->str = (const char *)dp;
141 return dp + strlen(kv->str) + 1;
142 case REPOKEY_TYPE_DIRNUMNUMARRAY:
143 dp = data_read_id(dp, &kv->id);
144 dp = data_read_id(dp, (Id *)&kv->num);
145 return data_read_ideof(dp, (Id *)&kv->num2, &kv->eof);
146 case REPOKEY_TYPE_FIXARRAY:
147 dp = data_read_id(dp, (Id *)&kv->num);
148 return data_read_id(dp, &kv->id);
149 case REPOKEY_TYPE_FLEXARRAY:
150 return data_read_id(dp, (Id *)&kv->num);
156 static inline unsigned char *
157 data_skip(unsigned char *dp, int type)
162 case REPOKEY_TYPE_VOID:
163 case REPOKEY_TYPE_CONSTANT:
164 case REPOKEY_TYPE_CONSTANTID:
165 case REPOKEY_TYPE_DELETED:
167 case REPOKEY_TYPE_ID:
168 case REPOKEY_TYPE_NUM:
169 case REPOKEY_TYPE_DIR:
170 while ((*dp & 0x80) != 0)
173 case REPOKEY_TYPE_U32:
175 case REPOKEY_TYPE_MD5:
176 return dp + SIZEOF_MD5;
177 case REPOKEY_TYPE_SHA1:
178 return dp + SIZEOF_SHA1;
179 case REPOKEY_TYPE_SHA256:
180 return dp + SIZEOF_SHA256;
181 case REPOKEY_TYPE_IDARRAY:
182 case REPOKEY_TYPE_REL_IDARRAY:
183 while ((*dp & 0xc0) != 0)
186 case REPOKEY_TYPE_STR:
190 case REPOKEY_TYPE_BINARY:
193 dp = data_read_id(dp, (Id *)&len);
196 case REPOKEY_TYPE_DIRSTRARRAY:
199 while ((*dp & 0x80) != 0)
208 case REPOKEY_TYPE_DIRNUMNUMARRAY:
211 while ((*dp & 0x80) != 0)
214 while ((*dp & 0x80) != 0)
217 while ((*dp & 0x80) != 0)
228 static inline unsigned char *
229 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
236 case REPOKEY_TYPE_VOID:
237 case REPOKEY_TYPE_CONSTANT:
238 case REPOKEY_TYPE_CONSTANTID:
239 case REPOKEY_TYPE_DELETED:
241 case REPOKEY_TYPE_NUM:
242 while ((*dp & 0x80) != 0)
245 case REPOKEY_TYPE_U32:
247 case REPOKEY_TYPE_MD5:
248 return dp + SIZEOF_MD5;
249 case REPOKEY_TYPE_SHA1:
250 return dp + SIZEOF_SHA1;
251 case REPOKEY_TYPE_SHA256:
252 return dp + SIZEOF_SHA256;
253 case REPOKEY_TYPE_ID:
254 dp = data_read_id(dp, &id);
258 case REPOKEY_TYPE_DIR:
259 dp = data_read_id(dp, &id);
263 case REPOKEY_TYPE_IDARRAY:
266 dp = data_read_ideof(dp, &id, &eof);
272 case REPOKEY_TYPE_STR:
276 case REPOKEY_TYPE_BINARY:
279 dp = data_read_id(dp, (Id *)&len);
282 case REPOKEY_TYPE_DIRSTRARRAY:
285 dp = data_read_ideof(dp, &id, &eof);
294 case REPOKEY_TYPE_DIRNUMNUMARRAY:
297 dp = data_read_id(dp, &id);
300 while ((*dp & 0x80) != 0)
303 while ((*dp & 0x80) != 0)
314 #endif /* LIBSOLV_REPOPACK */