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 SATSOLVER_REPOPACK_H
11 #define SATSOLVER_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_ideof(unsigned char *dp, Id *idp, int *eof)
50 x = (x << 7) ^ c ^ 128;
54 static inline unsigned char *
55 data_read_u32(unsigned char *dp, unsigned int *nump)
57 *nump = (dp[0] << 24) | (dp[1] << 16) | (dp[2] << 8) | dp[3];
61 static inline unsigned char *
62 data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
69 case REPOKEY_TYPE_VOID:
71 case REPOKEY_TYPE_CONSTANT:
74 case REPOKEY_TYPE_CONSTANTID:
77 case REPOKEY_TYPE_STR:
78 kv->str = (const char *)dp;
79 return dp + strlen(kv->str) + 1;
81 case REPOKEY_TYPE_DIR:
82 return data_read_id(dp, &kv->id);
83 case REPOKEY_TYPE_NUM:
84 return data_read_id(dp, &kv->num);
85 case REPOKEY_TYPE_U32:
86 return data_read_u32(dp, (unsigned int *)&kv->num);
87 case REPOKEY_TYPE_MD5:
88 kv->str = (const char *)dp;
89 return dp + SIZEOF_MD5;
90 case REPOKEY_TYPE_SHA1:
91 kv->str = (const char *)dp;
92 return dp + SIZEOF_SHA1;
93 case REPOKEY_TYPE_SHA256:
94 kv->str = (const char *)dp;
95 return dp + SIZEOF_SHA256;
96 case REPOKEY_TYPE_IDARRAY:
97 return data_read_ideof(dp, &kv->id, &kv->eof);
98 case REPOKEY_TYPE_DIRSTRARRAY:
99 dp = data_read_ideof(dp, &kv->id, &kv->eof);
100 kv->str = (const char *)dp;
101 return dp + strlen(kv->str) + 1;
102 case REPOKEY_TYPE_DIRNUMNUMARRAY:
103 dp = data_read_id(dp, &kv->id);
104 dp = data_read_id(dp, &kv->num);
105 return data_read_ideof(dp, &kv->num2, &kv->eof);
106 case REPOKEY_TYPE_COUNTED:
107 dp = data_read_id(dp, &kv->num);
108 return data_read_id(dp, &kv->id);
114 static inline unsigned char *
115 data_skip(unsigned char *dp, int type)
120 case REPOKEY_TYPE_VOID:
121 case REPOKEY_TYPE_CONSTANT:
122 case REPOKEY_TYPE_CONSTANTID:
124 case REPOKEY_TYPE_ID:
125 case REPOKEY_TYPE_NUM:
126 case REPOKEY_TYPE_DIR:
127 while ((*dp & 0x80) != 0)
130 case REPOKEY_TYPE_U32:
132 case REPOKEY_TYPE_MD5:
133 return dp + SIZEOF_MD5;
134 case REPOKEY_TYPE_SHA1:
135 return dp + SIZEOF_SHA1;
136 case REPOKEY_TYPE_SHA256:
137 return dp + SIZEOF_SHA256;
138 case REPOKEY_TYPE_IDARRAY:
139 case REPOKEY_TYPE_REL_IDARRAY:
140 while ((*dp & 0xc0) != 0)
143 case REPOKEY_TYPE_STR:
147 case REPOKEY_TYPE_DIRSTRARRAY:
150 while ((*dp & 0x80) != 0)
159 case REPOKEY_TYPE_DIRNUMNUMARRAY:
162 while ((*dp & 0x80) != 0)
165 while ((*dp & 0x80) != 0)
168 while ((*dp & 0x80) != 0)
174 case REPOKEY_TYPE_COUNTED:
175 while ((*dp & 0x80) != 0)
178 while ((*dp & 0x80) != 0)
186 static inline unsigned char *
187 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
194 case REPOKEY_TYPE_VOID:
195 case REPOKEY_TYPE_CONSTANT:
196 case REPOKEY_TYPE_CONSTANTID:
198 case REPOKEY_TYPE_NUM:
199 while ((*dp & 0x80) != 0)
202 case REPOKEY_TYPE_U32:
204 case REPOKEY_TYPE_MD5:
205 return dp + SIZEOF_MD5;
206 case REPOKEY_TYPE_SHA1:
207 return dp + SIZEOF_SHA1;
208 case REPOKEY_TYPE_SHA256:
209 return dp + SIZEOF_SHA256;
210 case REPOKEY_TYPE_ID:
211 dp = data_read_id(dp, &id);
215 case REPOKEY_TYPE_DIR:
216 dp = data_read_id(dp, &id);
220 case REPOKEY_TYPE_IDARRAY:
223 dp = data_read_ideof(dp, &id, &eof);
229 case REPOKEY_TYPE_STR:
233 case REPOKEY_TYPE_DIRSTRARRAY:
236 dp = data_read_ideof(dp, &id, &eof);
245 case REPOKEY_TYPE_DIRNUMNUMARRAY:
248 dp = data_read_id(dp, &id);
251 while ((*dp & 0x80) != 0)
254 while ((*dp & 0x80) != 0)
260 case REPOKEY_TYPE_COUNTED:
261 while ((*dp & 0x80) != 0)
264 while ((*dp & 0x80) != 0)
272 unsigned char * data_skip_recursive(Repodata *data, unsigned char *dp,
275 #endif /* SATSOLVER_REPOPACK */