Commit 6e5e4496d7a87f014e6d281639d60222aa45d42a

Authored by Silvan Calarco
1 parent 8836c8f87b
Exists in master

headerGetStringArrayEntry: add missing terminator

Showing 1 changed file with 3 additions and 1 deletions Inline Diff

1 /* 1 /*
2 * distromatic - tool for RPM based repositories 2 * distromatic - tool for RPM based repositories
3 * 3 *
4 * Copyright (C) 2004-2020 by Silvan Calarco <silvan.calarco@mambasoft.it> 4 * Copyright (C) 2004-2020 by Silvan Calarco <silvan.calarco@mambasoft.it>
5 * Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com> 5 * Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it under 7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of version 2 of the GNU General Public License as published by the 8 * the terms of version 2 of the GNU General Public License as published by the
9 * Free Software Foundation. 9 * Free Software Foundation.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY, to the extent permitted by law; without even the implied 12 * ANY WARRANTY, to the extent permitted by law; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details. 14 * See the GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License along with 16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21 #if HAVE_STRING_H 21 #if HAVE_STRING_H
22 # if !STDC_HEADERS && HAVE_MEMORY_H 22 # if !STDC_HEADERS && HAVE_MEMORY_H
23 # include <memory.h> 23 # include <memory.h>
24 # endif 24 # endif
25 # include <string.h> 25 # include <string.h>
26 #endif 26 #endif
27 #if HAVE_STRINGS_H 27 #if HAVE_STRINGS_H
28 # include <strings.h> 28 # include <strings.h>
29 #endif 29 #endif
30 30
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <fcntl.h> 32 #include <fcntl.h>
33 #include <zlib.h> 33 #include <zlib.h>
34 #include <libiberty/libiberty.h> 34 #include <libiberty/libiberty.h>
35 35
36 #include "functions.h" 36 #include "functions.h"
37 #include "rpmfunctions.h" 37 #include "rpmfunctions.h"
38 38
39 /* 39 /*
40 * static int getPackageInfo( 40 * static int getPackageInfo(
41 * Header h, char **name, char **version, char **release, 41 * Header h, char **name, char **version, char **release,
42 * char **summary); */ 42 * char **summary); */
43 43
44 struct EVR_s { 44 struct EVR_s {
45 char *data; 45 char *data;
46 uint32_t e; 46 uint32_t e;
47 char *v; 47 char *v;
48 char *r; 48 char *r;
49 } EVR; 49 } EVR;
50 50
51 void rpmEVRsplit(const char* ver, struct EVR_s *evr) { 51 void rpmEVRsplit(const char* ver, struct EVR_s *evr) {
52 evr->e = 0; 52 evr->e = 0;
53 evr->v = NULL; 53 evr->v = NULL;
54 evr->r = NULL; 54 evr->r = NULL;
55 evr->data = strdup(ver); 55 evr->data = strdup(ver);
56 for (int i = 0; i < strlen(ver); i++) { 56 for (int i = 0; i < strlen(ver); i++) {
57 if (evr->data[i] == ':') { 57 if (evr->data[i] == ':') {
58 evr->e = strtoul(ver, NULL, 10); 58 evr->e = strtoul(ver, NULL, 10);
59 evr->data[i] = '\0'; 59 evr->data[i] = '\0';
60 evr->v = &evr->data[i+1]; 60 evr->v = &evr->data[i+1];
61 } else if (evr->data[i] == '-') { 61 } else if (evr->data[i] == '-') {
62 evr->data[i] = '\0'; 62 evr->data[i] = '\0';
63 evr->r = &evr->data[i+1]; 63 evr->r = &evr->data[i+1];
64 if (evr->v == NULL) evr->v = evr->data; 64 if (evr->v == NULL) evr->v = evr->data;
65 } 65 }
66 } 66 }
67 if (evr->v == NULL) evr->v = evr->data; 67 if (evr->v == NULL) evr->v = evr->data;
68 } 68 }
69 69
70 unsigned int checkVersionWithFlags(const char* cmp1, uint_32 flags, const char* cmp2) { 70 unsigned int checkVersionWithFlags(const char* cmp1, uint_32 flags, const char* cmp2) {
71 int vercmp = 0; 71 int vercmp = 0;
72 struct EVR_s evr1, evr2; 72 struct EVR_s evr1, evr2;
73 73
74 rpmEVRsplit(cmp1, &evr1); 74 rpmEVRsplit(cmp1, &evr1);
75 rpmEVRsplit(cmp2, &evr2); 75 rpmEVRsplit(cmp2, &evr2);
76 76
77 if (evr1.e == evr2.e) vercmp = 0; 77 if (evr1.e == evr2.e) vercmp = 0;
78 else if (evr1.e > evr2.e) vercmp = 1; 78 else if (evr1.e > evr2.e) vercmp = 1;
79 else vercmp = -1; 79 else vercmp = -1;
80 80
81 if (vercmp == 0) vercmp = rpmvercmp(evr1.v, evr2.v); 81 if (vercmp == 0) vercmp = rpmvercmp(evr1.v, evr2.v);
82 if (vercmp == 0 && evr1.r && evr2.r) vercmp = rpmvercmp(evr1.r, evr2.r); 82 if (vercmp == 0 && evr1.r && evr2.r) vercmp = rpmvercmp(evr1.r, evr2.r);
83 83
84 free(evr1.data); 84 free(evr1.data);
85 free(evr2.data); 85 free(evr2.data);
86 86
87 if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1; 87 if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1;
88 else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1; 88 else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1;
89 else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1; 89 else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1;
90 90
91 return 0; 91 return 0;
92 } 92 }
93 93
94 /* 94 /*
95 * get header from a file descriptor of a YUM compressed header file */ 95 * get header from a file descriptor of a YUM compressed header file */
96 int 96 int
97 getHeader(rpmts* ts, char *headerFile, Header * h) 97 getHeader(rpmts* ts, char *headerFile, Header * h)
98 { 98 {
99 char buffer[HEADERS_BUFFER_SIZE]; 99 char buffer[HEADERS_BUFFER_SIZE];
100 int len; 100 int len;
101 101
102 /* check if file is a compressed header or a RPM/SRPM */ 102 /* check if file is a compressed header or a RPM/SRPM */
103 if (!strcmp(&headerFile[strlen(headerFile) - 4], ".hdr")) { 103 if (!strcmp(&headerFile[strlen(headerFile) - 4], ".hdr")) {
104 gzFile gzIn; 104 gzFile gzIn;
105 gzIn = gzopen(headerFile, "r"); 105 gzIn = gzopen(headerFile, "r");
106 106
107 if (gzIn == NULL) { 107 if (gzIn == NULL) {
108 return 1; 108 return 1;
109 } /* can't gzopen file */ 109 } /* can't gzopen file */
110 110
111 len = gzread(gzIn, buffer, HEADERS_BUFFER_SIZE); 111 len = gzread(gzIn, buffer, HEADERS_BUFFER_SIZE);
112 gzclose(gzIn); 112 gzclose(gzIn);
113 113
114 /* header file is bigger than buffer */ 114 /* header file is bigger than buffer */
115 if (len >= HEADERS_BUFFER_SIZE) { 115 if (len >= HEADERS_BUFFER_SIZE) {
116 return 2; 116 return 2;
117 } 117 }
118 118
119 *h = headerLoad(buffer); 119 *h = headerLoad(buffer);
120 } else { 120 } else {
121 FD_t fd; 121 FD_t fd;
122 122
123 fd = Fopen(headerFile, "r"); 123 fd = Fopen(headerFile, "r");
124 124
125 if (fd == NULL || Ferror(fd)) { 125 if (fd == NULL || Ferror(fd)) {
126 return 1; 126 return 1;
127 } 127 }
128 int rc; 128 int rc;
129 129
130 #if RPM_VERSION >= 0x040100 130 #if RPM_VERSION >= 0x040100
131 rc = rpmReadPackageFile(*ts, fd, headerFile, h); 131 rc = rpmReadPackageFile(*ts, fd, headerFile, h);
132 Fclose(fd); 132 Fclose(fd);
133 #else 133 #else
134 rc = rpmReadPackageHeader(fd, h, NULL, NULL, NULL); 134 rc = rpmReadPackageHeader(fd, h, NULL, NULL, NULL);
135 fdClose(fd); 135 fdClose(fd);
136 #endif 136 #endif
137 #if RPM_VERSION >= 0x040100 137 #if RPM_VERSION >= 0x040100
138 if (rc != RPMRC_OK && rc != RPMRC_NOTTRUSTED && rc != RPMRC_NOKEY) { 138 if (rc != RPMRC_OK && rc != RPMRC_NOTTRUSTED && rc != RPMRC_NOKEY) {
139 #else 139 #else
140 if (rc != 0) { 140 if (rc != 0) {
141 #endif 141 #endif
142 return 1; 142 return 1;
143 } 143 }
144 } 144 }
145 145
146 return 0; 146 return 0;
147 } 147 }
148 148
149 char * 149 char *
150 headerGetStringEntry(Header h, const int tag) 150 headerGetStringEntry(Header h, const int tag)
151 { 151 {
152 char *st = NULL; 152 char *st = NULL;
153 153
154 #if RPM_VERSION_MAJOR >= 0x050000 154 #if RPM_VERSION_MAJOR >= 0x050000
155 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 155 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
156 156
157 he->tag = tag; 157 he->tag = tag;
158 if (headerGet(h, he, 0) && he->t == RPM_STRING_TYPE && he->c == 1) 158 if (headerGet(h, he, 0) && he->t == RPM_STRING_TYPE && he->c == 1)
159 st = strdup(he->p.str); 159 st = strdup(he->p.str);
160 else 160 else
161 st = NULL; 161 st = NULL;
162 he->p.ptr = _free(he->p.ptr); 162 he->p.ptr = _free(he->p.ptr);
163 #else 163 #else
164 st = headerGetAsString(h, tag); 164 st = headerGetAsString(h, tag);
165 #endif 165 #endif
166 return st; 166 return st;
167 } 167 }
168 168
169 char ** 169 char **
170 headerGetStringArrayEntry(Header h, const int tag, int* count) 170 headerGetStringArrayEntry(Header h, const int tag, int* count)
171 { 171 {
172 char **st = NULL; 172 char **st = NULL;
173 173
174 #if RPM_VERSION_MAJOR >= 0x050000 174 #if RPM_VERSION_MAJOR >= 0x050000
175 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 175 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
176 176
177 he->tag = tag; 177 he->tag = tag;
178 if (headerGet(h, he, 0) && he->t == RPM_STRING_ARRAY_TYPE && he->c >= 1) { 178 if (headerGet(h, he, 0) && he->t == RPM_STRING_ARRAY_TYPE && he->c >= 1) {
179 *count = he->c; 179 *count = he->c;
180 st = dupnargv(he->p.ptr, he->c); 180 st = dupnargv(he->p.ptr, he->c);
181 } else { 181 } else {
182 *count = 0; 182 *count = 0;
183 } 183 }
184 he->p.ptr = _free(he->p.ptr); 184 he->p.ptr = _free(he->p.ptr);
185 #else 185 #else
186 rpmtd td = rpmtdNew(); 186 rpmtd td = rpmtdNew();
187 int i = 0; 187 int i = 0;
188 *count = 0; 188 *count = 0;
189 if (headerGet(h, tag, td, HEADERGET_MINMEM) && rpmtdType(td) == RPM_STRING_ARRAY_TYPE && rpmtdCount(td) >= 1) { 189 if (headerGet(h, tag, td, HEADERGET_MINMEM) && rpmtdType(td) == RPM_STRING_ARRAY_TYPE && rpmtdCount(td) >= 1) {
190 *count = rpmtdCount(td); 190 *count = rpmtdCount(td);
191 if (*count > 0) { 191 if (*count > 0) {
192 st = malloc(sizeof(char*) * *count); 192 st = malloc(sizeof(char*) * (*count + 1));
193 const char* str; 193 const char* str;
194 rpmtdInit(td); 194 rpmtdInit(td);
195 while ((str = rpmtdNextString(td))) { 195 while ((str = rpmtdNextString(td))) {
196 st[i] = strdup(str); 196 st[i] = strdup(str);
197 i++; 197 i++;
198 } 198 }
199 // Terminator
200 st[i] = NULL;
199 rpmtdFree(td); 201 rpmtdFree(td);
200 } 202 }
201 } 203 }
202 #endif 204 #endif
203 return st; 205 return st;
204 } 206 }
205 207
206 long long headerGetUIntEntry(Header h, const int tag) { 208 long long headerGetUIntEntry(Header h, const int tag) {
207 209
208 unsigned long long ret = -1; 210 unsigned long long ret = -1;
209 211
210 #if RPM_VERSION_MAJOR >= 0x050000 212 #if RPM_VERSION_MAJOR >= 0x050000
211 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 213 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
212 214
213 he->tag = tag; 215 he->tag = tag;
214 if (headerGet(h, he, 0) && he->c == 1) { 216 if (headerGet(h, he, 0) && he->c == 1) {
215 switch (he->t) { 217 switch (he->t) {
216 case RPM_UINT8_TYPE: 218 case RPM_UINT8_TYPE:
217 ret = *he->p.ui8p; 219 ret = *he->p.ui8p;
218 break; 220 break;
219 case RPM_UINT16_TYPE: 221 case RPM_UINT16_TYPE:
220 ret = *he->p.ui16p; 222 ret = *he->p.ui16p;
221 break; 223 break;
222 case RPM_UINT32_TYPE: 224 case RPM_UINT32_TYPE:
223 ret = *he->p.ui32p; 225 ret = *he->p.ui32p;
224 break; 226 break;
225 case RPM_UINT64_TYPE: 227 case RPM_UINT64_TYPE:
226 ret = *he->p.ui64p; 228 ret = *he->p.ui64p;
227 break; 229 break;
228 default: 230 default:
229 ret = -1; 231 ret = -1;
230 break; 232 break;
231 } 233 }
232 } 234 }
233 he->p.ptr = _free(he->p.ptr); 235 he->p.ptr = _free(he->p.ptr);
234 #else 236 #else
235 ret = headerGetNumber(h, tag); 237 ret = headerGetNumber(h, tag);
236 #endif 238 #endif
237 return ret; 239 return ret;
238 } 240 }
239 241
240 uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count) { 242 uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
241 uint_32 *ret = NULL; 243 uint_32 *ret = NULL;
242 244
243 #if RPM_VERSION_MAJOR >= 0x050000 245 #if RPM_VERSION_MAJOR >= 0x050000
244 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 246 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
245 he->tag = tag; 247 he->tag = tag;
246 if (headerGet(h, he, 0) && he->c >= 1) { 248 if (headerGet(h, he, 0) && he->c >= 1) {
247 *count = he->c; 249 *count = he->c;
248 switch (he->t) { 250 switch (he->t) {
249 case RPM_UINT8_TYPE: 251 case RPM_UINT8_TYPE:
250 ret = memndup(he->p.ui8p, *count); 252 ret = memndup(he->p.ui8p, *count);
251 break; 253 break;
252 case RPM_UINT16_TYPE: 254 case RPM_UINT16_TYPE:
253 ret = memndup(he->p.ui16p, *count * 2); 255 ret = memndup(he->p.ui16p, *count * 2);
254 break; 256 break;
255 case RPM_UINT32_TYPE: 257 case RPM_UINT32_TYPE:
256 ret = memndup(he->p.ui32p, *count * 4); 258 ret = memndup(he->p.ui32p, *count * 4);
257 break; 259 break;
258 case RPM_UINT64_TYPE: 260 case RPM_UINT64_TYPE:
259 ret = memndup(he->p.ui64p, *count * 8); 261 ret = memndup(he->p.ui64p, *count * 8);
260 break; 262 break;
261 default: 263 default:
262 ret = NULL; 264 ret = NULL;
263 break; 265 break;
264 } 266 }
265 } 267 }
266 he->p.ptr = _free(he->p.ptr); 268 he->p.ptr = _free(he->p.ptr);
267 #else 269 #else
268 rpmtd td = rpmtdNew(); 270 rpmtd td = rpmtdNew();
269 int i = 0; 271 int i = 0;
270 if (headerGet(h, tag, td, HEADERGET_MINMEM)) { 272 if (headerGet(h, tag, td, HEADERGET_MINMEM)) {
271 *count = rpmtdCount(td); 273 *count = rpmtdCount(td);
272 ret = malloc(sizeof(uint_32) * *count); 274 ret = malloc(sizeof(uint_32) * *count);
273 rpmtdInit(td); 275 rpmtdInit(td);
274 while (rpmtdNext(td) >= 0) { 276 while (rpmtdNext(td) >= 0) {
275 switch (td->type) { 277 switch (td->type) {
276 case RPM_INT8_TYPE: 278 case RPM_INT8_TYPE:
277 ret[i] = (uint_32)*rpmtdGetChar(td); 279 ret[i] = (uint_32)*rpmtdGetChar(td);
278 break; 280 break;
279 case RPM_INT16_TYPE: 281 case RPM_INT16_TYPE:
280 ret[i] = (uint_32)*rpmtdGetUint16(td); 282 ret[i] = (uint_32)*rpmtdGetUint16(td);
281 break; 283 break;
282 case RPM_INT32_TYPE: 284 case RPM_INT32_TYPE:
283 ret[i] = (uint_32)*rpmtdGetUint32(td); 285 ret[i] = (uint_32)*rpmtdGetUint32(td);
284 break; 286 break;
285 case RPM_INT64_TYPE: 287 case RPM_INT64_TYPE:
286 fprintf(stderr,"headerGetUIntArrayEntry: uint_64 type converted to uint_32"); 288 fprintf(stderr,"headerGetUIntArrayEntry: uint_64 type converted to uint_32");
287 ret[i] = (uint_32)*rpmtdGetUint64(td); 289 ret[i] = (uint_32)*rpmtdGetUint64(td);
288 break; 290 break;
289 default: 291 default:
290 break; 292 break;
291 } 293 }
292 i++; 294 i++;
293 } 295 }
294 rpmtdFree(td); 296 rpmtdFree(td);
295 } else { 297 } else {
296 *count = 0; 298 *count = 0;
297 } 299 }
298 #endif 300 #endif
299 return ret; 301 return ret;
300 } 302 }
301 303
302 int 304 int
303 getPackageRequires(Header h, char ***requirename, uint_32 **requireflags, 305 getPackageRequires(Header h, char ***requirename, uint_32 **requireflags,
304 char ***requireversion, int *requirecount) 306 char ***requireversion, int *requirecount)
305 { 307 {
306 *requirename = headerGetStringArrayEntry(h, RPMTAG_REQUIRENAME, requirecount); 308 *requirename = headerGetStringArrayEntry(h, RPMTAG_REQUIRENAME, requirecount);
307 *requireflags = headerGetUIntArrayEntry(h, RPMTAG_REQUIREFLAGS, requirecount); 309 *requireflags = headerGetUIntArrayEntry(h, RPMTAG_REQUIREFLAGS, requirecount);
308 *requireversion = headerGetStringArrayEntry(h, RPMTAG_REQUIREVERSION, requirecount); 310 *requireversion = headerGetStringArrayEntry(h, RPMTAG_REQUIREVERSION, requirecount);
309 311
310 return 0; 312 return 0;
311 } 313 }
312 314
313 int 315 int
314 getPackageProvides(Header h, char ***providename, uint_32 **provideflags, 316 getPackageProvides(Header h, char ***providename, uint_32 **provideflags,
315 char ***provideversion, int *providecount) 317 char ***provideversion, int *providecount)
316 { 318 {
317 *providename = headerGetStringArrayEntry(h, RPMTAG_PROVIDENAME, providecount); 319 *providename = headerGetStringArrayEntry(h, RPMTAG_PROVIDENAME, providecount);
318 *provideflags = headerGetUIntArrayEntry(h, RPMTAG_PROVIDEFLAGS, providecount); 320 *provideflags = headerGetUIntArrayEntry(h, RPMTAG_PROVIDEFLAGS, providecount);
319 *provideversion = headerGetStringArrayEntry(h, RPMTAG_PROVIDEVERSION, providecount); 321 *provideversion = headerGetStringArrayEntry(h, RPMTAG_PROVIDEVERSION, providecount);
320 322
321 return 0; 323 return 0;
322 } 324 }
323 325
324 int 326 int
325 getPackageObsoletes(Header h, char ***obsoletename, uint_32 **obsoleteflags, 327 getPackageObsoletes(Header h, char ***obsoletename, uint_32 **obsoleteflags,
326 char ***obsoleteversion, int *obsoletecount) 328 char ***obsoleteversion, int *obsoletecount)
327 { 329 {
328 *obsoletename = headerGetStringArrayEntry(h, RPMTAG_OBSOLETENAME, obsoletecount); 330 *obsoletename = headerGetStringArrayEntry(h, RPMTAG_OBSOLETENAME, obsoletecount);
329 *obsoleteflags = headerGetUIntArrayEntry(h, RPMTAG_OBSOLETEFLAGS, obsoletecount); 331 *obsoleteflags = headerGetUIntArrayEntry(h, RPMTAG_OBSOLETEFLAGS, obsoletecount);
330 *obsoleteversion = headerGetStringArrayEntry(h, RPMTAG_OBSOLETEVERSION, obsoletecount); 332 *obsoleteversion = headerGetStringArrayEntry(h, RPMTAG_OBSOLETEVERSION, obsoletecount);
331 333
332 return 0; 334 return 0;
333 } 335 }
334 336
335 int 337 int
336 getPackageFiles(Header h, uint_32 **dirindexes, 338 getPackageFiles(Header h, uint_32 **dirindexes,
337 char ***dirnames, int *dirnamescount, 339 char ***dirnames, int *dirnamescount,
338 char ***basenames, int *filenamescount, 340 char ***basenames, int *filenamescount,
339 char ***usernames, char ***groupnames, 341 char ***usernames, char ***groupnames,
340 int_16 **fileflags) 342 int_16 **fileflags)
341 { 343 {
342 int count; 344 int count;
343 345
344 /* note: I assume that basenamecount == dirindexescount */ 346 /* note: I assume that basenamecount == dirindexescount */
345 *dirindexes = headerGetUIntArrayEntry(h, RPMTAG_DIRINDEXES, &count); 347 *dirindexes = headerGetUIntArrayEntry(h, RPMTAG_DIRINDEXES, &count);
346 *dirnames = headerGetStringArrayEntry(h, RPMTAG_DIRNAMES, dirnamescount); 348 *dirnames = headerGetStringArrayEntry(h, RPMTAG_DIRNAMES, dirnamescount);
347 *basenames = headerGetStringArrayEntry(h, RPMTAG_BASENAMES, filenamescount); 349 *basenames = headerGetStringArrayEntry(h, RPMTAG_BASENAMES, filenamescount);
348 *usernames = headerGetStringArrayEntry(h, RPMTAG_FILEUSERNAME, &count); 350 *usernames = headerGetStringArrayEntry(h, RPMTAG_FILEUSERNAME, &count);
349 *groupnames = headerGetStringArrayEntry(h, RPMTAG_FILEGROUPNAME, &count); 351 *groupnames = headerGetStringArrayEntry(h, RPMTAG_FILEGROUPNAME, &count);
350 *fileflags = headerGetUIntArrayEntry(h, RPMTAG_FILEMODES, &count); 352 *fileflags = headerGetUIntArrayEntry(h, RPMTAG_FILEMODES, &count);
351 353
352 return 0; 354 return 0;
353 } 355 }
354 356
355 int rpmnamecmp(char *filename1, char *filename2, int checkver) { 357 int rpmnamecmp(char *filename1, char *filename2, int checkver) {
356 int end1=0, end2=0, f, i; 358 int end1=0, end2=0, f, i;
357 char c1,c2; 359 char c1,c2;
358 360
359 f=0; 361 f=0;
360 362
361 /* find name end position assuming a "name-version-release" scheme */ 363 /* find name end position assuming a "name-version-release" scheme */
362 for (i = strlen(filename1)-1; (i > 0) && (f < 2); i--) { 364 for (i = strlen(filename1)-1; (i > 0) && (f < 2); i--) {
363 if (filename1[i] == '-') { 365 if (filename1[i] == '-') {
364 f++; 366 f++;
365 end1=i-1; 367 end1=i-1;
366 } 368 }
367 } 369 }
368 370
369 f=0; 371 f=0;
370 for (i = strlen(filename2)-1; (i > 0) && (f < 2); i--) { 372 for (i = strlen(filename2)-1; (i > 0) && (f < 2); i--) {
371 if (filename2[i] == '-') { 373 if (filename2[i] == '-') {
372 f++; 374 f++;
373 end2=i-1; 375 end2=i-1;
374 } 376 }
375 } 377 }
376 378
377 /* make comparison, case insensitive */ 379 /* make comparison, case insensitive */
378 for (i=0; (i <= end1) && (i <= end2); i++) { 380 for (i=0; (i <= end1) && (i <= end2); i++) {
379 c1=filename1[i]; 381 c1=filename1[i];
380 c2=filename2[i]; 382 c2=filename2[i];
381 if ((c1 >= 'A') && (c1 <= 'Z')) c1=c1+'a'-'A'; 383 if ((c1 >= 'A') && (c1 <= 'Z')) c1=c1+'a'-'A';
382 if ((c2 >= 'A') && (c2 <= 'Z')) c2=c2+'a'-'A'; 384 if ((c2 >= 'A') && (c2 <= 'Z')) c2=c2+'a'-'A';
383 if (c1 < c2) return -1; 385 if (c1 < c2) return -1;
384 else if (c1 > c2) return 1; 386 else if (c1 > c2) return 1;
385 } 387 }
386 388
387 if (end1 < end2) return -1; 389 if (end1 < end2) return -1;
388 else if (end1 > end2) return 1; 390 else if (end1 > end2) return 1;
389 391
390 /* same name, sort by version */ 392 /* same name, sort by version */
391 if (checkver) 393 if (checkver)
392 i=rpmvercmp(&filename2[i+1],&filename1[i+1]) * -1; 394 i=rpmvercmp(&filename2[i+1],&filename1[i+1]) * -1;
393 else 395 else
394 i=0; 396 i=0;
395 397
396 return i; 398 return i;
397 } 399 }
398 400
399 int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2) { 401 int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2) {
400 return rpmnamecmp((char*)(*f1)->d_name,(char*)(*f2)->d_name,1); 402 return rpmnamecmp((char*)(*f1)->d_name,(char*)(*f2)->d_name,1);
401 } 403 }
402 404
403 char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release) { 405 char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release) {
404 406
405 if (strcmp(release,"")) { 407 if (strcmp(release,"")) {
406 if (epoch) 408 if (epoch)
407 snprintf(s,bufsize,"%ld:%s-%s",epoch,version,release); 409 snprintf(s,bufsize,"%ld:%s-%s",epoch,version,release);
408 else 410 else
409 snprintf(s,bufsize,"%s-%s",version,release); 411 snprintf(s,bufsize,"%s-%s",version,release);
410 } else { 412 } else {
411 if (epoch) 413 if (epoch)
412 snprintf(s,bufsize,"%ld:%s",epoch,version); 414 snprintf(s,bufsize,"%ld:%s",epoch,version);
413 else 415 else
414 snprintf(s,bufsize,"%s",version); 416 snprintf(s,bufsize,"%s",version);
415 } 417 }
416 return s; 418 return s;
417 } 419 }
418 420
419 void rpminit() { 421 void rpminit() {
420 #if RPM_VERSION >= 0x040100 422 #if RPM_VERSION >= 0x040100
421 rpmReadConfigFiles(NULL, NULL); 423 rpmReadConfigFiles(NULL, NULL);
422 // ts = rpmtsCreate(); 424 // ts = rpmtsCreate();
423 // rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1); 425 // rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
424 #endif 426 #endif
425 } 427 }
426 428