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_IDARRAY:
94 return data_read_ideof(dp, &kv->id, &kv->eof);
95 case REPOKEY_TYPE_DIRSTRARRAY:
96 dp = data_read_ideof(dp, &kv->id, &kv->eof);
97 kv->str = (const char *)dp;
98 return dp + strlen(kv->str) + 1;
99 case REPOKEY_TYPE_DIRNUMNUMARRAY:
100 dp = data_read_id(dp, &kv->id);
101 dp = data_read_id(dp, &kv->num);
102 return data_read_ideof(dp, &kv->num2, &kv->eof);
108 static inline unsigned char *
109 data_skip(unsigned char *dp, int type)
114 case REPOKEY_TYPE_VOID:
115 case REPOKEY_TYPE_CONSTANT:
116 case REPOKEY_TYPE_CONSTANTID:
118 case REPOKEY_TYPE_ID:
119 case REPOKEY_TYPE_NUM:
120 case REPOKEY_TYPE_DIR:
121 while ((*dp & 0x80) != 0)
124 case REPOKEY_TYPE_U32:
126 case REPOKEY_TYPE_MD5:
127 return dp + SIZEOF_MD5;
128 case REPOKEY_TYPE_SHA1:
129 return dp + SIZEOF_SHA1;
130 case REPOKEY_TYPE_IDARRAY:
131 case REPOKEY_TYPE_REL_IDARRAY:
132 while ((*dp & 0xc0) != 0)
135 case REPOKEY_TYPE_STR:
139 case REPOKEY_TYPE_DIRSTRARRAY:
142 while ((*dp & 0x80) != 0)
151 case REPOKEY_TYPE_DIRNUMNUMARRAY:
154 while ((*dp & 0x80) != 0)
157 while ((*dp & 0x80) != 0)
160 while ((*dp & 0x80) != 0)
171 static inline unsigned char *
172 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
179 case REPOKEY_TYPE_VOID:
180 case REPOKEY_TYPE_CONSTANT:
181 case REPOKEY_TYPE_CONSTANTID:
183 case REPOKEY_TYPE_NUM:
184 while ((*dp & 0x80) != 0)
187 case REPOKEY_TYPE_U32:
189 case REPOKEY_TYPE_MD5:
190 return dp + SIZEOF_MD5;
191 case REPOKEY_TYPE_SHA1:
192 return dp + SIZEOF_SHA1;
193 case REPOKEY_TYPE_ID:
194 dp = data_read_id(dp, &id);
198 case REPOKEY_TYPE_DIR:
199 dp = data_read_id(dp, &id);
203 case REPOKEY_TYPE_IDARRAY:
206 dp = data_read_ideof(dp, &id, &eof);
212 case REPOKEY_TYPE_STR:
216 case REPOKEY_TYPE_DIRSTRARRAY:
219 dp = data_read_ideof(dp, &id, &eof);
228 case REPOKEY_TYPE_DIRNUMNUMARRAY:
231 dp = data_read_id(dp, &id);
234 while ((*dp & 0x80) != 0)
237 while ((*dp & 0x80) != 0)
248 #endif /* SATSOLVER_REPOPACK */