]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-4.1-branch.patch
- fixed (finally?) GConf scripts, rel 0.6
[packages/rpm.git] / rpm-4.1-branch.patch
CommitLineData
a5c251d8
AM
1Index: CHANGES
2===================================================================
3RCS file: rpm/CHANGES,v
4retrieving revision 1.1130.2.23
5retrieving revision 1.1130.2.27
6diff -u -u -r1.1130.2.23 -r1.1130.2.27
7--- rpm/CHANGES 17 Sep 2002 15:18:23 -0000 1.1130.2.23
8+++ rpm/CHANGES 6 Nov 2002 17:28:19 -0000 1.1130.2.27
9@@ -286,6 +286,13 @@
10 - fix: register SIGCHLD handler before forking (#73134).
11 - better diagnostics on failed header parsing.
12 - lclint clean.
13+ - rpm-4.1 release.
14+ - fix: make sure that psm->child pid is set before SIGCHLD is handled.
15+ - fix: use size_t consistently, avoid segfault on ia64.
16+ - use %%{_lib} for libraries.
17+ - fix: permit build with --disable-nls (#76258).
18+ - backport db-4.1.17 changes.
19+ - add _noDirTokens macro for 6x builds.
20
21 4.0.3 -> 4.0.4:
22 - solaris: translate i86pc to i386 (#57182).
23Index: autogen.sh
24===================================================================
25RCS file: rpm/autogen.sh,v
26retrieving revision 2.39
27retrieving revision 2.39.2.1
28diff -u -u -r2.39 -r2.39.2.1
29--- rpm/autogen.sh 8 Aug 2002 22:20:26 -0000 2.39
30+++ rpm/autogen.sh 25 Oct 2002 17:31:37 -0000 2.39.2.1
31@@ -4,13 +4,13 @@
32 export LDFLAGS
33
34 LTV="libtoolize (GNU libtool) 1.4.2"
35-ACV="autoconf (GNU Autoconf) 2.53"
36+ACV="autoconf (GNU Autoconf) 2.54"
37 AMV="automake (GNU automake) 1.6.3"
38 USAGE="
39 This script documents the versions of the tools I'm using to build rpm:
40 libtool-1.4.2
41- autoconf-2.53
42- automake-1.6.2
43+ autoconf-2.54
44+ automake-1.6.3
45 Simply edit this script to change the libtool/autoconf/automake versions
46 checked if you need to, as rpm should build (and has built) with all
47 recent versions of libtool/autoconf/automake.
48Index: configure.ac
49===================================================================
50RCS file: rpm/configure.ac,v
51retrieving revision 2.6.2.2
52retrieving revision 2.6.2.3
53diff -u -u -r2.6.2.2 -r2.6.2.3
54--- rpm/configure.ac 22 Aug 2002 19:18:56 -0000 2.6.2.2
55+++ rpm/configure.ac 9 Oct 2002 19:05:38 -0000 2.6.2.3
b9e2d653
AM
56@@ -437,10 +437,12 @@
57 if test $withval = no ; then
58 dnl ------------------ without internal db
59
60-AC_CHECK_HEADERS(db3/db.h)
61+AC_CHECK_HEADERS(db.h)
62
63 dnl Check for Berkeley db3 API.
64 AC_CHECK_FUNC(db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"],
65+ AC_CHECK_LIB(db-4.1, db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"; libdb3="-ldb-4.1"],
66+ AC_CHECK_LIB(db-4.0, db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"; libdb3="-ldb-4.0"],
67 AC_CHECK_LIB(db-3.2, db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"; libdb3="-ldb-3.2"],
68 AC_CHECK_LIB(db-3.1, db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"; libdb3="-ldb-3.1"],
69 AC_CHECK_LIB(db-3.0, db_create, [DBLIBSRCS="$DBLIBSRCS db3.c"; libdb3="-ldb-3.0"],
70@@ -449,6 +451,8 @@
71 )
72 )
73 )
74+ )
75+ )
76 )
77
78 if test X"$DBLIBSRCS" = X; then
a5c251d8
AM
79@@ -1094,6 +1094,7 @@
80 dnl Determine the canonical arch-vendor-os for the build machine
81 case "${build_cpu}" in
82 *86) RPMCANONARCH=i386 ;;
83+x86_64*) RPMCANONARCH=x86_64 ;;
84 alpha*) RPMCANONARCH=alpha ;;
85 sparc*) RPMCANONARCH=sparc ;;
86 ia64*) RPMCANONARCH=ia64 ;;
87Index: installplatform
88===================================================================
89RCS file: rpm/installplatform,v
90retrieving revision 2.34
91retrieving revision 2.34.2.2
92diff -u -u -r2.34 -r2.34.2.2
93--- rpm/installplatform 30 Jul 2002 17:07:39 -0000 2.34
94+++ rpm/installplatform 11 Oct 2002 17:23:27 -0000 2.34.2.2
95@@ -34,6 +34,7 @@
96 alpha*) SUBSTS='s_alpha_alpha_ s_alpha_alphaev5_ s_alpha_alphaev56_ s_alpha_alphapca56_ s_alpha_alphaev6_ s_alpha_alphaev67_' ;;
97 sparc*) SUBSTS='s_sparc\(64\|v9\)_sparc_ s_sparc64_sparcv9_;s_sparc\([^v]\|$\)_sparcv9\1_ s_sparcv9_sparc64_;s_sparc\([^6]\|$\)_sparc64\1_' ;;
98 powerpc*|ppc*) SUBSTS='s_ppc64_ppc_ s_ppc\([^6]\|$\)_ppc64\1_' ;;
99+ s390*) SUBSTS='s_s390x_s390_ s_s390\([^x]\|$\)_s390x\1_' ;;
100 *) SUBSTS=y___ ;;
101 esac
102
103@@ -60,6 +61,12 @@
104 sparc-linux) MULTILIBNO=1 ;;
105 sparcv9-linux) MULTILIBNO=1 ;;
106 sparc64-linux) ARCH_INSTALL_POST=${pkglibdir}/brp-sparc64-linux; LIB=lib64; MULTILIBNO=2 ;;
107+ s390-linux) MULTILIBNO=1 ;;
108+ s390x-linux) LIB=lib64; MULTILIBNO=2 ;;
109+ ppc-linux) MULTILIBNO=1 ;;
110+ ppc64-linux) LIB=lib64; MULTILIBNO=2 ;;
111+ i?86-linux|athlon-linux) MULTILIBNO=1 ;;
112+ x86_64-linux) LIB=lib64; MULTILIBNO=2 ;;
113 esac
114
115 if [ -n "$MULTILIBNO" ]; then
116Index: rpmqv.c
117===================================================================
118RCS file: rpm/rpmqv.c,v
119retrieving revision 1.98
120retrieving revision 1.98.2.2
121diff -u -u -r1.98 -r1.98.2.2
122--- rpm/rpmqv.c 6 Aug 2002 01:41:46 -0000 1.98
123+++ rpm/rpmqv.c 6 Nov 2002 17:28:19 -0000 1.98.2.2
124@@ -271,6 +271,7 @@
125 freeSpecVec = freeSpec;
126 /*@=type@*/
127
128+#if defined(ENABLE_NLS)
129 /* set up the correct locale */
130 (void) setlocale(LC_ALL, "" );
131
132@@ -279,6 +280,7 @@
133 #endif
134 bindtextdomain(PACKAGE, LOCALEDIR);
135 textdomain(PACKAGE);
136+#endif
137
138 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
139
140@@ -614,6 +616,8 @@
141 (void) close(p[1]);
142 }
143
144+ _noDirTokens = rpmExpandNumeric("%{?_noDirTokens}");
145+
146 ts = rpmtsCreate();
147 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
148 switch (bigMode) {
149Index: beecrypt/base64.c
150===================================================================
151RCS file: rpm/beecrypt/base64.c,v
152retrieving revision 1.20
153retrieving revision 1.20.2.1
154diff -u -u -r1.20 -r1.20.2.1
155--- rpm/beecrypt/base64.c 2 Jul 2002 23:54:35 -0000 1.20
156+++ rpm/beecrypt/base64.c 9 Oct 2002 19:05:39 -0000 1.20.2.1
157@@ -246,7 +246,7 @@
158
159 /*@-boundswrite@*/
160 /*@-internalglobs -modfilesys @*/
161-char * b64encode (const void * data, int ns)
162+char * b64encode (const void * data, size_t ns)
163 {
164 static char b64enc[] =
165 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
166@@ -275,7 +275,7 @@
167
168 lc = 0;
169 if (te)
170- while (ns) {
171+ while (ns > 0) {
172
173 if (_debug)
174 fprintf(stderr, "%7u %02x %02x %02x -> %02x %02x %02x %02x\n",
175@@ -335,7 +335,7 @@
176 #define CRC24_POLY 0x1864cfbL
177
178 /*@-boundsread@*/
179-char * b64crc (const unsigned char * data, int ns)
180+char * b64crc (const unsigned char * data, size_t ns)
181 {
182 const unsigned char *s = data;
183 uint32 crc = CRC24_INIT;
184@@ -367,7 +367,7 @@
185
186 /*@-internalglobs -modfilesys @*/
187 /*@-boundswrite@*/
188-int b64decode (const char * s, void ** datap, int *lenp)
189+int b64decode (const char * s, void ** datap, size_t *lenp)
190 {
191 unsigned char b64dec[256];
192 const unsigned char *t;
193Index: beecrypt/base64.h
194===================================================================
195RCS file: rpm/beecrypt/base64.h,v
196retrieving revision 1.14
197retrieving revision 1.14.2.2
198diff -u -u -r1.14 -r1.14.2.2
199--- rpm/beecrypt/base64.h 13 May 2002 22:45:31 -0000 1.14
200+++ rpm/beecrypt/base64.h 6 Nov 2002 17:28:19 -0000 1.14.2.2
201@@ -68,17 +68,17 @@
202 * @return (malloc'd) base64 string
203 */
204 BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/
205-char * b64encode (const void * data, int ns)
206+char * b64encode (const void * data, size_t ns)
207 /*@*/;
208
209 /**
210 * Encode crc of binary input data into 5 bytes of base64 output.
211 * @param data binary data
212- * @param ns crc of data
213+ * @param ns no. bytes of binary data
214 * @return (malloc'd) base64 string
215 */
216 BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/
217-char * b64crc (const unsigned char * data, int ns)
218+char * b64crc (const unsigned char * data, size_t ns)
219 /*@*/;
220
221 /**
222@@ -89,7 +89,7 @@
223 * @return 0 on success, 1: s == NULL, 2: bad length, 3: bad char
224 */
225 BEECRYPTAPI /*@unused@*/
226-int b64decode (const char * s, /*@out@*/ void ** datap, /*@out@*/ int *lenp)
227+int b64decode (const char * s, /*@out@*/ void ** datap, /*@out@*/ size_t *lenp)
228 /*@modifies *datap, *lenp @*/;
229
230 /**
231Index: db3/configure
232===================================================================
233RCS file: rpm/db3/configure,v
234retrieving revision 1.20
235retrieving revision 1.20.2.1
236diff -u -u -r1.20 -r1.20.2.1
237--- rpm/db3/configure 30 Jul 2002 16:39:09 -0000 1.20
238+++ rpm/db3/configure 6 Nov 2002 17:28:20 -0000 1.20.2.1
239@@ -4,10 +4,6 @@
240
241 rm -f config.cache
242
243-# XXX hacks to get db-3.3.4 to configure properly
244-#ln -sf ../dist $db_dist/../db/dist
245-#ln -sf ../dist $db_dist
246-
247 # XXX edit CFLAGS= ... out of invocation args ???
248 ARGS="`echo $* | sed -e 's% [^ ]*CFLAGS=[^ ]*%%' -e 's% -[^-][^ ]*%%g' -e 's%--cache-file=.*$%%'`"
249
250@@ -15,18 +11,15 @@
251 --enable-shared --enable-static --enable-rpc \
252 --with-uniquename=_rpmdb --srcdir=$db_dist
253
254-# XXX hack to get db-3.3.4 to configure properly
255-#rm -f $db_dist/../db/dist $db_dist/dist
256-
257 mv Makefile Makefile.orig
258-cat Makefile.orig | sed -e 's/ -g$/ -g -O2/' -e '/^install:/c\
259+cat Makefile.orig | sed -e '/^install[:-]/c\
260 .PHONY: listobjs\
261 listobjs:\
262 @echo $(OBJS) $(C_OBJS) \
263 \
264 distdir install check:\
265 \
266-db3_install: all install_setip' > Makefile
267+db4_install: all install_setip' > Makefile
268
269 mv db.h db.h.orig
270 cat db.h.orig | sed \
271@@ -36,7 +29,7 @@
272 /*@=incondefs@*/' \
273 -e '/^#define db_create/i\
274 /*@-declundef -noparams -fcnuse@*/' \
275- -e '/^#define db_xa_switch/a\
276+ -e '/^int txn_commit __P((/a\
277 /*@=declundef =noparams =fcnuse =fielduse =enummemuse =typeuse @*/' > db.h
278
279 # Generate manifest for rpmdb.
280Index: lib/formats.c
281===================================================================
282RCS file: rpm/lib/formats.c,v
283retrieving revision 2.71.2.1
284retrieving revision 2.71.2.2
285diff -u -u -r2.71.2.1 -r2.71.2.2
286--- rpm/lib/formats.c 19 Aug 2002 22:21:20 -0000 2.71.2.1
287+++ rpm/lib/formats.c 9 Oct 2002 19:05:39 -0000 2.71.2.2
288@@ -145,7 +145,8 @@
289 char * t;
290 char * val;
291 int atype;
292- int lc, ns, nt;
293+ size_t ns, nt;
294+ int lc;
295
296 switch (type) {
297 case RPM_BIN_TYPE:
298@@ -238,7 +239,7 @@
299 const char * enc;
300 char * t;
301 int lc;
302- int nt = ((element + 2) / 3) * 4;
303+ size_t nt = ((element + 2) / 3) * 4;
304
305 /*@-boundswrite@*/
306 /*@-globs@*/
307Index: lib/package.c
308===================================================================
309RCS file: rpm/lib/package.c,v
310retrieving revision 2.112.2.10
311retrieving revision 2.112.2.11
312diff -u -u -r2.112.2.10 -r2.112.2.11
313--- rpm/lib/package.c 17 Sep 2002 15:18:23 -0000 2.112.2.10
314+++ rpm/lib/package.c 9 Oct 2002 19:05:39 -0000 2.112.2.11
315@@ -360,7 +360,7 @@
316 if (uc > 0 && pvlen != uc) {
317 (void) snprintf(buf, sizeof(buf),
318 _("blob size(%d): BAD, 8 + 16 * il(%d) + dl(%d)\n"),
319- uc, il, dl);
320+ (int)uc, (int)il, (int)dl);
321 goto exit;
322 }
323
324@@ -652,7 +652,7 @@
325 memset(block, 0, sizeof(block));
326 if ((xx = timedRead(fd, (char *)block, sizeof(block))) != sizeof(block)) {
327 (void) snprintf(buf, sizeof(buf),
328- _("hdr size(%d): BAD, read returned %d\n"), sizeof(block), xx);
329+ _("hdr size(%d): BAD, read returned %d\n"), (int)sizeof(block), xx);
330 goto exit;
331 }
332 if (memcmp(block, header_magic, sizeof(header_magic))) {
333Index: lib/poptALL.c
334===================================================================
335RCS file: rpm/lib/poptALL.c,v
336retrieving revision 2.10.2.2
337retrieving revision 2.10.2.3
338diff -u -u -r2.10.2.2 -r2.10.2.3
339--- rpm/lib/poptALL.c 27 Aug 2002 20:42:17 -0000 2.10.2.2
340+++ rpm/lib/poptALL.c 25 Oct 2002 17:31:37 -0000 2.10.2.3
341@@ -332,9 +332,12 @@
342 }
343 /*@=globs =mods@*/
344
345-#if !defined(__LCLINT__)
346+#if defined(ENABLE_NLS)
347 (void) setlocale(LC_ALL, "" );
348
349+#ifdef __LCLINT__
350+#define LOCALEDIR "/usr/share/locale"
351+#endif
352 (void) bindtextdomain(PACKAGE, LOCALEDIR);
353 (void) textdomain(PACKAGE);
354 #endif
355Index: lib/psm.c
356===================================================================
357RCS file: rpm/lib/psm.c,v
358retrieving revision 2.126.2.7
359retrieving revision 2.126.2.9
360diff -u -u -r2.126.2.7 -r2.126.2.9
361--- rpm/lib/psm.c 17 Sep 2002 15:18:23 -0000 2.126.2.7
362+++ rpm/lib/psm.c 9 Oct 2002 19:05:39 -0000 2.126.2.9
363@@ -695,15 +695,19 @@
364 (void) sigaddset(&caught, signum);
365 switch (signum) {
366 case SIGCHLD:
367- { int status = 0;
368- pid_t reaped = waitpid(0, &status, WNOHANG);
369- int i;
370-
371- if (psmtbl.psms)
372- for (i = 0; i < psmtbl.npsms; i++) {
373- rpmpsm psm = psmtbl.psms[i];
374- if (psm->child != reaped)
375- /*@innercontinue@*/ continue;
376+ while (1) {
377+ int status = 0;
378+ pid_t reaped = waitpid(0, &status, WNOHANG);
379+ int i;
380+
381+ if (reaped <= 0)
382+ /*@innerbreak@*/ break;
383+
384+ if (psmtbl.psms)
385+ for (i = 0; i < psmtbl.npsms; i++) {
386+ rpmpsm psm = psmtbl.psms[i];
387+ if (psm->child != reaped)
388+ /*@innercontinue@*/ continue;
389
390 #if _PSM_DEBUG
391 /*@-modfilesys@*/
392@@ -712,11 +716,12 @@
393 /*@=modfilesys@*/
394 #endif
395
396- psm->reaped = reaped;
397- psm->status = status;
398- /*@innerbreak@*/ break;
399+ psm->reaped = reaped;
400+ psm->status = status;
401+ /*@innerbreak@*/ break;
402+ }
403 }
404- } /*@switchbreak@*/ break;
405+ /*@switchbreak@*/ break;
406 default:
407 /*@switchbreak@*/ break;
408 }
409@@ -782,26 +787,6 @@
410 }
411
412 /**
413- * Fork a new process.
414- * @param psm package state machine data
415- * @return fork(2) pid
416- */
417-static pid_t psmFork(rpmpsm psm)
418- /*@globals fileSystem, internalState @*/
419- /*@modifies fileSystem, internalState @*/
420-{
421- pid_t pid;
422-
423- if ((pid = fork()) != 0) {
424-/*@-modfilesys@*/
425-if (_psm_debug)
426-fprintf(stderr, " Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, pid);
427-/*@=modfilesys@*/
428- }
429- return pid;
430-}
431-
432-/**
433 * Register a child reaper, then fork a child.
434 * @param psm package state machine data
435 * @return fork(2) pid
436@@ -835,7 +820,6 @@
437 }
438 empty = psmtbl.npsms++;
439 }
440- psm->reaped = 0;
441 if (psmtbl.psms) /* XXX can't happen */
442 psmtbl.psms[empty] = rpmpsmLink(psm, "psmRegister");
443 /*@-modfilesys@*/
444@@ -844,15 +828,24 @@
445 /*@=modfilesys@*/
446
447 (void) enableSignal(SIGCHLD);
448+
449+ psm->reaped = 0;
450+ if ((psm->child = fork()) != 0) {
451+/*@-modfilesys@*/
452+if (_psm_debug)
453+fprintf(stderr, " Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
454+/*@=modfilesys@*/
455+ }
456+
457 (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
458
459- return psmFork(psm);
460+ return psm->child;
461 }
462
463 /**
464 * Unregister a child reaper.
465 */
466-static int psmUnregister(rpmpsm psm, pid_t child)
467+static int psmWaitUnregister(rpmpsm psm, pid_t child)
468 /*@globals psmtbl, fileSystem, internalState @*/
469 /*@modifies psmtbl, fileSystem, internalState @*/
470 {
471@@ -862,6 +855,19 @@
472 (void) sigfillset(&newMask); /* block all signals */
473 (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
474
475+ /*@-infloops@*/
476+ while (psm->reaped != psm->child) {
477+ (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
478+ sleep(1); /* XXX sleep guarantees loop traversal. */
479+ (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
480+ }
481+ /*@=infloops@*/
482+
483+/*@-modfilesys@*/
484+if (_psm_debug)
485+fprintf(stderr, " Wait: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
486+/*@=modfilesys@*/
487+
488 if (psmtbl.psms)
489 for (i = 0; i < psmtbl.npsms; i++) {
490 if (psmtbl.psms[i] == NULL)
491@@ -893,25 +899,6 @@
492 }
493
494 /**
495- * Return reaped pid safely (i.e. with signals blocked).
496- * @param psm package state machine data
497- * @return
498- */
499-static inline pid_t psmGetReaped(rpmpsm psm)
500- /*@globals fileSystem @*/
501- /*@modifies fileSystem @*/
502-{
503- sigset_t newMask, oldMask;
504- pid_t reaped;
505-
506- (void) sigfillset(&newMask); /* block all signals */
507- (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
508- reaped = psm->reaped;
509- (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
510- return reaped;
511-}
512-
513-/**
514 * Wait for child process to be reaped.
515 * @param psm package state machine data
516 * @return
517@@ -921,15 +908,7 @@
518 /*@modifies psm, fileSystem, internalState @*/
519 {
520 if (psm->reaper) {
521- /*@-infloops@*/
522- while (psmGetReaped(psm) == 0)
523- (void) pause();
524- /*@=infloops@*/
525-/*@-modfilesys@*/
526-if (_psm_debug)
527-fprintf(stderr, " Wait: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, psm->child);
528-/*@=modfilesys@*/
529- (void) psmUnregister(psm, psm->child);
530+ (void) psmWaitUnregister(psm, psm->child);
531 } else {
532 do {
533 psm->reaped = waitpid(psm->child, &psm->status, 0);
534@@ -997,7 +976,6 @@
535 FD_t out;
536 rpmRC rc = RPMRC_OK;
537 const char *n, *v, *r;
538- pid_t pid;
539
540 if (progArgv == NULL && script == NULL)
541 return rc;
542@@ -1119,8 +1097,7 @@
543 if (out == NULL) return RPMRC_FAIL; /* XXX can't happen */
544
545 /*@-branchstate@*/
546- pid = psmRegisterFork(psm);
547- psm->child = pid;
548+ (void) psmRegisterFork(psm);
549 if (psm->child == 0) {
550 const char * rootDir;
551 int pipes[2];
552Index: lib/query.c
553===================================================================
554RCS file: rpm/lib/query.c,v
555retrieving revision 2.138.2.8
556retrieving revision 2.138.2.9
557diff -u -u -r2.138.2.8 -r2.138.2.9
558--- rpm/lib/query.c 17 Sep 2002 15:18:23 -0000 2.138.2.8
559+++ rpm/lib/query.c 9 Oct 2002 19:05:39 -0000 2.138.2.9
560@@ -266,7 +266,7 @@
561 /*@=boundswrite@*/
562
563 if (qva->qva_flags & QUERY_FOR_DUMPFILES) {
564- sprintf(te, "%s %d %d %s 0%o ", fn, fsize, fmtime, fmd5, fmode);
565+ sprintf(te, "%s %d %d %s 0%o ", fn, (int)fsize, fmtime, fmd5, fmode);
566 te += strlen(te);
567
568 if (fuser && fgroup) {
569Index: lib/rpmcli.h
570===================================================================
571RCS file: rpm/lib/rpmcli.h,v
572retrieving revision 2.47.2.2
573retrieving revision 2.47.2.3
574diff -u -u -r2.47.2.2 -r2.47.2.3
575--- rpm/lib/rpmcli.h 17 Sep 2002 15:18:24 -0000 2.47.2.2
576+++ rpm/lib/rpmcli.h 9 Oct 2002 19:05:39 -0000 2.47.2.3
577@@ -557,7 +557,7 @@
578 * @param argv array of package file names (NULL terminated)
579 * @return 0 on success
580 */
581-int rpmErase(rpmts ts, const struct rpmInstallArguments_s * ia,
582+int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
583 /*@null@*/ const char ** argv)
584 /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
585 /*@modifies ts, ia, rpmGlobalMacroContext,
586Index: lib/rpmds.h
587===================================================================
588RCS file: rpm/lib/rpmds.h,v
589retrieving revision 2.36
590retrieving revision 2.36.2.1
591diff -u -u -r2.36 -r2.36.2.1
592--- rpm/lib/rpmds.h 3 Aug 2002 22:31:39 -0000 2.36
593+++ rpm/lib/rpmds.h 6 Nov 2002 17:28:20 -0000 2.36.2.1
594@@ -232,6 +232,7 @@
595 /**
596 * Set "Don't promote Epoch:" flag.
597 * @param ds dependency set
598+ * @param nopromote Should an unspecified Epoch: be treated as Epoch: 0?
599 * @return previous "Don't promote Epoch:" flag
600 */
601 int rpmdsSetNoPromote(/*@null@*/ rpmds ds, int nopromote)
602Index: lib/rpminstall.c
603===================================================================
604RCS file: rpm/lib/rpminstall.c,v
605retrieving revision 1.118.2.5
606retrieving revision 1.118.2.6
607diff -u -u -r1.118.2.5 -r1.118.2.6
608--- rpm/lib/rpminstall.c 31 Aug 2002 22:30:22 -0000 1.118.2.5
609+++ rpm/lib/rpminstall.c 9 Oct 2002 19:05:39 -0000 1.118.2.6
610@@ -723,8 +723,7 @@
611 }
612 /*@=bounds@*/
613
614-int rpmErase(rpmts ts,
615- const struct rpmInstallArguments_s * ia,
616+int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
617 const char ** argv)
618 {
619 int count;
620Index: lib/signature.c
621===================================================================
622RCS file: rpm/lib/signature.c,v
623retrieving revision 2.139.2.7
624retrieving revision 2.139.2.8
625diff -u -u -r2.139.2.7 -r2.139.2.8
626--- rpm/lib/signature.c 17 Sep 2002 15:18:24 -0000 2.139.2.7
627+++ rpm/lib/signature.c 9 Oct 2002 19:05:39 -0000 2.139.2.8
628@@ -178,7 +178,7 @@
629 memset(block, 0, sizeof(block));
630 if ((xx = timedRead(fd, (char *)block, sizeof(block))) != sizeof(block)) {
631 (void) snprintf(buf, sizeof(buf),
632- _("sigh size(%d): BAD, read returned %d\n"), sizeof(block), xx);
633+ _("sigh size(%d): BAD, read returned %d\n"), (int)sizeof(block), xx);
634 goto exit;
635 }
636 if (memcmp(block, header_magic, sizeof(header_magic))) {
637@@ -215,7 +215,7 @@
638 dataStart = (unsigned char *) (pe + il);
639 if ((xx = timedRead(fd, (char *)pe, nb)) != nb) {
640 (void) snprintf(buf, sizeof(buf),
641- _("sigh blob(%d): BAD, read returned %d\n"), nb, xx);
642+ _("sigh blob(%d): BAD, read returned %d\n"), (int)nb, xx);
643 goto exit;
644 }
645
646@@ -985,11 +985,11 @@
647 if (size != dig->nbytes) {
648 res = RPMRC_FAIL;
649 t = stpcpy(t, rpmSigString(res));
650- sprintf(t, " Expected(%d) != (%d)\n", size, dig->nbytes);
651+ sprintf(t, " Expected(%d) != (%d)\n", (int)size, (int)dig->nbytes);
652 } else {
653 res = RPMRC_OK;
654 t = stpcpy(t, rpmSigString(res));
655- sprintf(t, " (%d)", dig->nbytes);
656+ sprintf(t, " (%d)", (int)dig->nbytes);
657 }
658
659 exit:
660Index: lib/transaction.c
661===================================================================
662RCS file: rpm/lib/transaction.c,v
663retrieving revision 1.274.2.6
664retrieving revision 1.274.2.7
665diff -u -u -r1.274.2.6 -r1.274.2.7
666--- rpm/lib/transaction.c 31 Aug 2002 22:30:22 -0000 1.274.2.6
667+++ rpm/lib/transaction.c 25 Oct 2002 17:31:38 -0000 1.274.2.7
668@@ -1018,7 +1018,7 @@
669 * - count files.
670 */
671
672-rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elments\n"), rpmtsNElements(ts));
673+rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elements\n"), rpmtsNElements(ts));
674 ps = rpmtsProblems(ts);
675 /* The ordering doesn't matter here */
676 pi = rpmtsiInit(ts);
677Index: python/_rpmdb.c
678===================================================================
679RCS file: rpm/python/_rpmdb.c,v
680retrieving revision 1.4
681retrieving revision 1.4.2.1
682diff -u -u -r1.4 -r1.4.2.1
683--- rpm/python/_rpmdb.c 7 Jun 2002 13:12:34 -0000 1.4
684+++ rpm/python/_rpmdb.c 6 Nov 2002 16:47:02 -0000 1.4.2.1
685@@ -90,9 +90,9 @@
686 /* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
687 #define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
688
689-#define PY_BSDDB_VERSION "3.3.1"
690+#define PY_BSDDB_VERSION "3.4.2"
691
692-static char *rcs_id = "$Id$";
693+static char *rcs_id = "$Id$";
694
695
696 #ifdef WITH_THREAD
697@@ -410,6 +410,7 @@
698 switch (err) {
699 case 0: /* successful, no error */ break;
700
701+#if (DBVER < 41)
702 case DB_INCOMPLETE:
703 #if INCOMPLETE_IS_WARNING
704 strcpy(errTxt, db_strerror(err));
705@@ -429,6 +430,7 @@
706 errObj = DBIncompleteError;
707 #endif
708 break;
709+#endif
710
711 case DB_KEYEMPTY: errObj = DBKeyEmptyError; break;
712 case DB_KEYEXIST: errObj = DBKeyExistError; break;
713@@ -1023,12 +1025,29 @@
714 secondaryDB->associateCallback = callback;
715 secondaryDB->primaryDBType = _DB_get_type(self);
716
717-
718+ /* PyEval_InitThreads is called here due to a quirk in python 1.5
719+ * - 2.2.1 (at least) according to Russell Williamson <merel@wt.net>:
720+ * The global interepreter lock is not initialized until the first
721+ * thread is created using thread.start_new_thread() or fork() is
722+ * called. that would cause the ALLOW_THREADS here to segfault due
723+ * to a null pointer reference if no threads or child processes
724+ * have been created. This works around that and is a no-op if
725+ * threads have already been initialized.
726+ * (see pybsddb-users mailing list post on 2002-08-07)
727+ */
728+ PyEval_InitThreads();
729 MYDB_BEGIN_ALLOW_THREADS;
730+#if (DBVER >= 41)
731+ err = self->db->associate(self->db, NULL,
732+ secondaryDB->db,
733+ _db_associateCallback,
734+ flags);
735+#else
736 err = self->db->associate(self->db,
737 secondaryDB->db,
738 _db_associateCallback,
739 flags);
740+#endif
741 MYDB_END_ALLOW_THREADS;
742
743 if (err) {
744@@ -1498,7 +1517,11 @@
745 }
746
747 MYDB_BEGIN_ALLOW_THREADS;
748+#if (DBVER >= 41)
749+ err = self->db->open(self->db, NULL, filename, dbname, type, flags, mode);
750+#else
751 err = self->db->open(self->db, filename, dbname, type, flags, mode);
752+#endif
753 MYDB_END_ALLOW_THREADS;
754 if (makeDBError(err)) {
755 self->db = NULL;
756@@ -1851,7 +1874,9 @@
757 MAKE_HASH_ENTRY(nkeys);
758 MAKE_HASH_ENTRY(ndata);
759 MAKE_HASH_ENTRY(pagesize);
760+#if (DBVER < 41)
761 MAKE_HASH_ENTRY(nelem);
762+#endif
763 MAKE_HASH_ENTRY(ffactor);
764 MAKE_HASH_ENTRY(buckets);
765 MAKE_HASH_ENTRY(free);
766@@ -1896,7 +1921,7 @@
767 MAKE_QUEUE_ENTRY(re_len);
768 MAKE_QUEUE_ENTRY(re_pad);
769 MAKE_QUEUE_ENTRY(pgfree);
770-#if (DBVER >= 31) && (DBVER < 40)
771+#if (DBVER == 31)
772 MAKE_QUEUE_ENTRY(start);
773 #endif
774 MAKE_QUEUE_ENTRY(first_recno);
775@@ -2334,8 +2359,6 @@
776 if (!PyArg_ParseTuple(args, ":close"))
777 return NULL;
778
779- CHECK_CURSOR_NOT_CLOSED(self);
780-
781 if (self->dbc != NULL) {
782 MYDB_BEGIN_ALLOW_THREADS;
783 err = self->dbc->c_close(self->dbc);
784@@ -2424,7 +2447,7 @@
785 static PyObject*
786 DBC_get(DBCursorObject* self, PyObject* args, PyObject *kwargs)
787 {
788- int err, flags;
789+ int err, flags=0;
790 PyObject* keyobj = NULL;
791 PyObject* dataobj = NULL;
792 PyObject* retval = NULL;
793@@ -3309,7 +3332,7 @@
794 int err;
795 DB_LOCK_STAT* sp;
796 PyObject* d = NULL;
797- u_int32_t flags;
798+ u_int32_t flags = 0;
799
800 if (!PyArg_ParseTuple(args, "|i:lock_stat", &flags))
801 return NULL;
802@@ -3337,7 +3360,9 @@
803
804 #define MAKE_ENTRY(name) _addIntToDict(d, #name, sp->st_##name)
805
806+#if (DBVER < 41)
807 MAKE_ENTRY(lastid);
808+#endif
809 MAKE_ENTRY(nmodes);
810 #if (DBVER >= 32)
811 MAKE_ENTRY(maxlocks);
812@@ -3421,7 +3446,7 @@
813 int err;
814 DB_TXN_STAT* sp;
815 PyObject* d = NULL;
816- u_int32_t flags;
817+ u_int32_t flags=0;
818
819 if (!PyArg_ParseTuple(args, "|i:txn_stat", &flags))
820 return NULL;
821@@ -4116,7 +4141,9 @@
822 ADD_INT(d, DB_APPEND);
823 ADD_INT(d, DB_BEFORE);
824 ADD_INT(d, DB_CACHED_COUNTS);
825+#if (DBVER < 41)
826 ADD_INT(d, DB_CHECKPOINT);
827+#endif
828 #if (DBVER >= 33)
829 ADD_INT(d, DB_COMMIT);
830 #endif
831@@ -4124,7 +4151,9 @@
832 #if (DBVER >= 32)
833 ADD_INT(d, DB_CONSUME_WAIT);
834 #endif
835+#if (DBVER < 41)
836 ADD_INT(d, DB_CURLSN);
837+#endif
838 ADD_INT(d, DB_CURRENT);
839 #if (DBVER >= 33)
840 ADD_INT(d, DB_FAST_STAT);
841@@ -4164,7 +4193,9 @@
842 ADD_INT(d, DB_DONOTINDEX);
843 #endif
844
845+#if (DBVER < 41)
846 ADD_INT(d, DB_INCOMPLETE);
847+#endif
848 ADD_INT(d, DB_KEYEMPTY);
849 ADD_INT(d, DB_KEYEXIST);
850 ADD_INT(d, DB_LOCK_DEADLOCK);
851Index: python/header-py.c
852===================================================================
853RCS file: rpm/python/header-py.c,v
854retrieving revision 1.20
855retrieving revision 1.20.2.1
856diff -u -u -r1.20 -r1.20.2.1
857--- rpm/python/header-py.c 7 Aug 2002 23:19:10 -0000 1.20
858+++ rpm/python/header-py.c 15 Oct 2002 19:03:22 -0000 1.20.2.1
859@@ -336,6 +336,11 @@
860 return rpmVersionCompare(a->h, b->h);
861 }
862
863+static long hdr_hash(hdrObject *h)
864+{
865+ return h;
866+}
867+
868 /** \ingroup python
869 */
870 /*@unchecked@*/ /*@observer@*/
871@@ -594,7 +599,7 @@
872 0, /* tp_as_number */
873 0, /* tp_as_sequence */
874 &hdr_as_mapping, /* tp_as_mapping */
875- 0, /* tp_hash */
876+ hdr_hash, /* tp_hash */
877 0, /* tp_call */
878 0, /* tp_str */
879 0, /* tp_getattro */
880Index: python/rpmdb/__init__.py
881===================================================================
882RCS file: rpm/python/rpmdb/__init__.py,v
883retrieving revision 1.2
884retrieving revision 1.2.2.1
885diff -u -u -r1.2 -r1.2.2.1
886--- rpm/python/rpmdb/__init__.py 3 Jun 2002 20:44:08 -0000 1.2
887+++ rpm/python/rpmdb/__init__.py 6 Nov 2002 16:47:02 -0000 1.2.2.1
888@@ -152,7 +152,7 @@
889 flags = _checkflag(flag)
890 d = _db.DB()
891 d.set_flags(hflags)
892- if cachesize is not None: d.set_cachesize(cachesize)
893+ if cachesize is not None: d.set_cachesize(0, cachesize)
894 if pgsize is not None: d.set_pagesize(pgsize)
895 if lorder is not None: d.set_lorder(lorder)
896 if ffactor is not None: d.set_h_ffactor(ffactor)
897@@ -168,7 +168,7 @@
898
899 flags = _checkflag(flag)
900 d = _db.DB()
901- if cachesize is not None: d.set_cachesize(cachesize)
902+ if cachesize is not None: d.set_cachesize(0, cachesize)
903 if pgsize is not None: d.set_pagesize(pgsize)
904 if lorder is not None: d.set_lorder(lorder)
905 d.set_flags(btflags)
906@@ -186,7 +186,7 @@
907
908 flags = _checkflag(flag)
909 d = _db.DB()
910- if cachesize is not None: d.set_cachesize(cachesize)
911+ if cachesize is not None: d.set_cachesize(0, cachesize)
912 if pgsize is not None: d.set_pagesize(pgsize)
913 if lorder is not None: d.set_lorder(lorder)
914 d.set_flags(rnflags)
915Index: python/rpmdb/dbshelve.py
916===================================================================
917RCS file: rpm/python/rpmdb/dbshelve.py,v
918retrieving revision 1.2
919retrieving revision 1.2.2.1
920diff -u -u -r1.2 -r1.2.2.1
921--- rpm/python/rpmdb/dbshelve.py 5 Jun 2002 20:28:03 -0000 1.2
922+++ rpm/python/rpmdb/dbshelve.py 6 Nov 2002 16:47:02 -0000 1.2.2.1
923@@ -53,7 +53,7 @@
924 if type(flags) == type(''):
925 sflag = flags
926 if sflag == 'r':
927- flags = db.DB_READONLY
928+ flags = db.DB_RDONLY
929 elif sflag == 'rw':
930 flags = 0
931 elif sflag == 'w':
932Index: python/rpmdb/dbtables.py
933===================================================================
934RCS file: rpm/python/rpmdb/dbtables.py,v
935retrieving revision 1.1
936retrieving revision 1.1.2.1
937diff -u -u -r1.1 -r1.1.2.1
938--- rpm/python/rpmdb/dbtables.py 3 Jun 2002 20:44:08 -0000 1.1
939+++ rpm/python/rpmdb/dbtables.py 6 Nov 2002 16:47:02 -0000 1.1.2.1
940@@ -1,6 +1,7 @@
941 #-----------------------------------------------------------------------
942 #
943 # Copyright (C) 2000, 2001 by Autonomous Zone Industries
944+# Copyright (C) 2002 Gregory P. Smith
945 #
946 # License: This is free software. You may use this software for any
947 # purpose including modification/redistribution, so long as
948@@ -54,6 +55,13 @@
949 def __call__(self, s):
950 return s[:len(self.prefix)] == self.prefix
951
952+class PostfixCond(Cond):
953+ """Acts as a condition function for matching a string postfix"""
954+ def __init__(self, postfix):
955+ self.postfix = postfix
956+ def __call__(self, s):
957+ return s[-len(self.postfix):] == self.postfix
958+
959 class LikeCond(Cond):
960 """
961 Acts as a function that will match using an SQL 'LIKE' style
962@@ -523,17 +531,10 @@
963 # if no condition was specified or the condition
964 # succeeds, add row to our match list.
965 if not condition or condition(data) :
966- # only create new entries in matcing_rowids on
967- # the first pass, otherwise reject the
968- # rowid as it must not have matched
969- # the previous passes
970- if column_num == 0 :
971- if not matching_rowids.has_key(rowid) :
972- matching_rowids[rowid] = {}
973- if savethiscolumndata :
974- matching_rowids[rowid][column] = data
975- else :
976- rejected_rowids[rowid] = rowid
977+ if not matching_rowids.has_key(rowid) :
978+ matching_rowids[rowid] = {}
979+ if savethiscolumndata :
980+ matching_rowids[rowid][column] = data
981 else :
982 if matching_rowids.has_key(rowid) :
983 del matching_rowids[rowid]
984Index: python/rpmdb/dbutils.py
985===================================================================
986RCS file: rpm/python/rpmdb/dbutils.py,v
987retrieving revision 1.1
988retrieving revision 1.1.2.1
989diff -u -u -r1.1 -r1.1.2.1
990--- rpm/python/rpmdb/dbutils.py 3 Jun 2002 20:44:08 -0000 1.1
991+++ rpm/python/rpmdb/dbutils.py 6 Nov 2002 16:47:02 -0000 1.1.2.1
992@@ -1,11 +1,5 @@
993 #------------------------------------------------------------------------
994 #
995-# In my performance tests, using this (as in dbtest.py test4) is
996-# slightly slower than simply compiling _db.c with MYDB_THREAD
997-# undefined to prevent multithreading support in the C module.
998-# Using NoDeadlockDb also prevent deadlocks from mutliple processes
999-# accessing the same database.
1000-#
1001 # Copyright (C) 2000 Autonomous Zone Industries
1002 #
1003 # License: This is free software. You may use this software for any
1004@@ -18,7 +12,7 @@
1005 # Author: Gregory P. Smith <greg@electricrain.com>
1006 #
1007 # Note: I don't know how useful this is in reality since when a
1008-# DBDeadlockError happens the current transaction is supposed to be
1009+# DBLockDeadlockError happens the current transaction is supposed to be
1010 # aborted. If it doesn't then when the operation is attempted again
1011 # the deadlock is still happening...
1012 # --Robin
1013@@ -36,33 +30,45 @@
1014
1015 import _rpmdb as _db
1016
1017-_deadlock_MinSleepTime = 1.0/64 # always sleep at least N seconds between retrys
1018-_deadlock_MaxSleepTime = 1.0 # never sleep more than N seconds between retrys
1019+_deadlock_MinSleepTime = 1.0/64 # always sleep at least N seconds between retrys
1020+_deadlock_MaxSleepTime = 3.14159 # never sleep more than N seconds between retrys
1021
1022+_deadlock_VerboseFile = None # Assign a file object to this for a "sleeping"
1023+ # message to be written to it each retry
1024
1025 def DeadlockWrap(function, *_args, **_kwargs):
1026 """DeadlockWrap(function, *_args, **_kwargs) - automatically retries
1027 function in case of a database deadlock.
1028
1029- This is a DeadlockWrapper method which DB calls can be made using to
1030- preform infinite retrys with sleeps in between when a DBLockDeadlockError
1031- exception is raised in a database call:
1032+ This is a function intended to be used to wrap database calls such
1033+ that they perform retrys with exponentially backing off sleeps in
1034+ between when a DBLockDeadlockError exception is raised.
1035+
1036+ A 'max_retries' parameter may optionally be passed to prevent it
1037+ from retrying forever (in which case the exception will be reraised).
1038
1039 d = DB(...)
1040 d.open(...)
1041 DeadlockWrap(d.put, "foo", data="bar") # set key "foo" to "bar"
1042 """
1043 sleeptime = _deadlock_MinSleepTime
1044- while (1) :
1045+ max_retries = _kwargs.get('max_retries', -1)
1046+ if _kwargs.has_key('max_retries'):
1047+ del _kwargs['max_retries']
1048+ while 1:
1049 try:
1050 return apply(function, _args, _kwargs)
1051 except _db.DBLockDeadlockError:
1052- print 'DeadlockWrap sleeping ', sleeptime
1053+ if _deadlock_VerboseFile:
1054+ _deadlock_VerboseFile.write('dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime)
1055 _sleep(sleeptime)
1056 # exponential backoff in the sleep time
1057 sleeptime = sleeptime * 2
1058 if sleeptime > _deadlock_MaxSleepTime :
1059 sleeptime = _deadlock_MaxSleepTime
1060+ max_retries = max_retries - 1
1061+ if max_retries == -1:
1062+ raise
1063
1064
1065 #------------------------------------------------------------------------
1066Index: python/test/test_dbshelve.py
1067===================================================================
1068RCS file: rpm/python/test/test_dbshelve.py,v
1069retrieving revision 1.1
1070retrieving revision 1.1.2.1
1071diff -u -u -r1.1 -r1.1.2.1
1072--- rpm/python/test/test_dbshelve.py 3 Jun 2002 20:44:08 -0000 1.1
1073+++ rpm/python/test/test_dbshelve.py 6 Nov 2002 16:47:02 -0000 1.1.2.1
1074@@ -210,7 +210,7 @@
1075
1076
1077 class HashShelveTestCase(BasicShelveTestCase):
1078- dbtype = db.DB_BTREE
1079+ dbtype = db.DB_HASH
1080 dbflags = db.DB_CREATE
1081
1082
1083@@ -220,7 +220,7 @@
1084
1085
1086 class ThreadHashShelveTestCase(BasicShelveTestCase):
1087- dbtype = db.DB_BTREE
1088+ dbtype = db.DB_HASH
1089 dbflags = db.DB_CREATE | db.DB_THREAD
1090
1091
1092@@ -261,7 +261,7 @@
1093
1094 class EnvHashShelveTestCase(BasicEnvShelveTestCase):
1095 envflags = 0
1096- dbtype = db.DB_BTREE
1097+ dbtype = db.DB_HASH
1098 dbflags = db.DB_CREATE
1099
1100
1101@@ -273,7 +273,7 @@
1102
1103 class EnvThreadHashShelveTestCase(BasicEnvShelveTestCase):
1104 envflags = db.DB_THREAD
1105- dbtype = db.DB_BTREE
1106+ dbtype = db.DB_HASH
1107 dbflags = db.DB_CREATE | db.DB_THREAD
1108
1109
1110Index: python/test/test_dbtables.py
1111===================================================================
1112RCS file: rpm/python/test/test_dbtables.py,v
1113retrieving revision 1.1
1114retrieving revision 1.1.2.1
1115diff -u -u -r1.1 -r1.1.2.1
1116--- rpm/python/test/test_dbtables.py 3 Jun 2002 20:44:08 -0000 1.1
1117+++ rpm/python/test/test_dbtables.py 6 Nov 2002 16:47:02 -0000 1.1.2.1
1118@@ -5,6 +5,7 @@
1119 #-----------------------------------------------------------------------
1120 #
1121 # Copyright (C) 2000, 2001 by Autonomous Zone Industries
1122+# Copyright (C) 2002 Gregory P. Smith
1123 #
1124 # March 20, 2000
1125 #
1126@@ -157,6 +158,40 @@
1127 conditions={'c': lambda c: c == 'meep'})
1128 assert len(values) == 1
1129 assert values[0]['b'] == "bad"
1130+
1131+
1132+ def test04_MultiCondSelect(self):
1133+ tabname = "test04_MultiCondSelect"
1134+ try:
1135+ self.tdb.Drop(tabname)
1136+ except dbtables.TableDBError:
1137+ pass
1138+ self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e'])
1139+
1140+ try:
1141+ self.tdb.Insert(tabname, {'a': "", 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1), 'f': "Zero"})
1142+ assert 0
1143+ except dbtables.TableDBError:
1144+ pass
1145+
1146+ self.tdb.Insert(tabname, {'a': "A", 'b': "B", 'c': "C", 'd': "D", 'e': "E"})
1147+ self.tdb.Insert(tabname, {'a': "-A", 'b': "-B", 'c': "-C", 'd': "-D", 'e': "-E"})
1148+ self.tdb.Insert(tabname, {'a': "A-", 'b': "B-", 'c': "C-", 'd': "D-", 'e': "E-"})
1149+
1150+ if verbose:
1151+ self.tdb._db_print()
1152+
1153+ # This select should return 0 rows. it is designed to test
1154+ # the bug identified and fixed in sourceforge bug # 590449
1155+ # (Big Thanks to "Rob Tillotson (n9mtb)" for tracking this down
1156+ # and supplying a fix!! This one caused many headaches to say
1157+ # the least...)
1158+ values = self.tdb.Select(tabname, ['b', 'a', 'd'],
1159+ conditions={'e': dbtables.ExactCond('E'),
1160+ 'a': dbtables.ExactCond('A'),
1161+ 'd': dbtables.PrefixCond('-')
1162+ } )
1163+ assert len(values) == 0, values
1164
1165
1166 def test_CreateOrExtend(self):
1167Index: python/test/test_thread.py
1168===================================================================
1169RCS file: rpm/python/test/test_thread.py,v
1170retrieving revision 1.1
1171retrieving revision 1.1.2.1
1172diff -u -u -r1.1 -r1.1.2.1
1173--- rpm/python/test/test_thread.py 3 Jun 2002 20:44:08 -0000 1.1
1174+++ rpm/python/test/test_thread.py 6 Nov 2002 16:47:02 -0000 1.1.2.1
1175@@ -18,7 +18,7 @@
1176 import unittest
1177 from test_all import verbose
1178
1179-from rpmdb import db
1180+from rpmdb import db, dbutils
1181
1182
1183 #----------------------------------------------------------------------
1184@@ -31,6 +31,9 @@
1185
1186
1187 def setUp(self):
1188+ if verbose:
1189+ dbutils._deadlock_VerboseFile = sys.stdout
1190+
1191 homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
1192 self.homeDir = homeDir
1193 try: os.mkdir(homeDir)
1194@@ -109,7 +112,7 @@
1195
1196 for x in range(start, stop):
1197 key = '%04d' % x
1198- d.put(key, self.makeData(key))
1199+ dbutils.DeadlockWrap(d.put, key, self.makeData(key), max_retries=12)
1200 if verbose and x % 100 == 0:
1201 print "%s: records %d - %d finished" % (name, start, x)
1202
1203@@ -212,7 +215,7 @@
1204 # create a bunch of records
1205 for x in xrange(start, stop):
1206 key = '%04d' % x
1207- d.put(key, self.makeData(key))
1208+ dbutils.DeadlockWrap(d.put, key, self.makeData(key), max_retries=12)
1209
1210 if verbose and x % 100 == 0:
1211 print "%s: records %d - %d finished" % (name, start, x)
1212@@ -221,12 +224,12 @@
1213 if random() <= 0.05:
1214 for y in xrange(start, x):
1215 key = '%04d' % x
1216- data = d.get(key)
1217+ data = dbutils.DeadlockWrap(d.get, key, max_retries=12)
1218 assert data == self.makeData(key)
1219
1220 # flush them
1221 try:
1222- d.sync()
1223+ dbutils.DeadlockWrap(d.sync, max_retries=12)
1224 except db.DBIncompleteError, val:
1225 if verbose:
1226 print "could not complete sync()..."
1227@@ -234,12 +237,12 @@
1228 # read them back, deleting a few
1229 for x in xrange(start, stop):
1230 key = '%04d' % x
1231- data = d.get(key)
1232+ data = dbutils.DeadlockWrap(d.get, key, max_retries=12)
1233 if verbose and x % 100 == 0:
1234 print "%s: fetched record (%s, %s)" % (name, key, data)
1235- assert data == self.makeData(key)
1236+ assert data == self.makeData(key), (key, data, self.makeData(key))
1237 if random() <= 0.10:
1238- d.delete(key)
1239+ dbutils.DeadlockWrap(d.delete, key, max_retries=12)
1240 if verbose:
1241 print "%s: deleted record %s" % (name, key)
1242
1243@@ -273,7 +276,7 @@
1244
1245
1246 class HashSimpleThreaded(SimpleThreadedBase):
1247- dbtype = db.DB_BTREE
1248+ dbtype = db.DB_HASH
1249
1250
1251 #----------------------------------------------------------------------
1252Index: rpmdb/db3.c
1253===================================================================
1254RCS file: rpm/rpmdb/db3.c,v
1255retrieving revision 1.45
1256retrieving revision 1.45.2.1
1257diff -u -u -r1.45 -r1.45.2.1
1258--- rpm/rpmdb/db3.c 13 Aug 2002 20:42:39 -0000 1.45
1259+++ rpm/rpmdb/db3.c 6 Nov 2002 17:29:34 -0000 1.45.2.1
1260@@ -266,11 +266,22 @@
1261
1262 { int xx;
1263 /*@-noeffectuncon@*/ /* FIX: annotate db3 methods */
1264+
1265+ /* 4.1: dbenv->set_app_dispatch(???) */
1266+ /* 4.1: dbenv->set_alloc(???) */
1267+ /* 4.1: dbenv->set_data_dir(???) */
1268+ /* 4.1: dbenv->set_encrypt(???) */
1269+
1270 dbenv->set_errcall(dbenv, rpmdb->db_errcall);
1271 dbenv->set_errfile(dbenv, rpmdb->db_errfile);
1272 dbenv->set_errpfx(dbenv, rpmdb->db_errpfx);
1273 /*@=noeffectuncon@*/
1274+
1275+ /* 4.1: dbenv->set_feedback(???) */
1276+ /* 4.1: dbenv->set_flags(???) */
1277+
1278 /* dbenv->set_paniccall(???) */
1279+
1280 xx = dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT,
1281 (dbi->dbi_verbose & DB_VERB_CHKPOINT));
1282 xx = dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK,
1283@@ -279,16 +290,35 @@
1284 (dbi->dbi_verbose & DB_VERB_RECOVERY));
1285 xx = dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR,
1286 (dbi->dbi_verbose & DB_VERB_WAITSFOR));
1287- /* dbenv->set_lg_max(???) */
1288+
1289 /* dbenv->set_lk_conflicts(???) */
1290 /* dbenv->set_lk_detect(???) */
1291- /* dbenv->set_lk_max(???) */
1292- xx = dbenv->set_mp_mmapsize(dbenv, dbi->dbi_mp_mmapsize);
1293- xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug);
1294- xx = dbenv->set_cachesize(dbenv, 0, dbi->dbi_mp_size, 0);
1295- xx = cvtdberr(dbi, "dbenv->set_cachesize", xx, _debug);
1296+ /* 4.1: dbenv->set_lk_max_lockers(???) */
1297+ /* 4.1: dbenv->set_lk_max_locks(???) */
1298+ /* 4.1: dbenv->set_lk_max_objects(???) */
1299+
1300+ /* 4.1: dbenv->set_lg_bsize(???) */
1301+ /* 4.1: dbenv->set_lg_dir(???) */
1302+ /* 4.1: dbenv->set_lg_max(???) */
1303+ /* 4.1: dbenv->set_lg_regionmax(???) */
1304+
1305+ if (dbi->dbi_mmapsize) {
1306+ xx = dbenv->set_mp_mmapsize(dbenv, dbi->dbi_mmapsize);
1307+ xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug);
1308+ }
1309+ if (dbi->dbi_cachesize) {
1310+ xx = dbenv->set_cachesize(dbenv, 0, dbi->dbi_cachesize, 0);
1311+ xx = cvtdberr(dbi, "dbenv->set_cachesize", xx, _debug);
1312+ }
1313+
1314+ /* 4.1 dbenv->set_timeout(???) */
1315 /* dbenv->set_tx_max(???) */
1316+ /* 4.1: dbenv->set_tx_timestamp(???) */
1317 /* dbenv->set_tx_recover(???) */
1318+
1319+ /* dbenv->set_rep_transport(???) */
1320+ /* dbenv->set_rep_limit(???) */
1321+
1322 if (dbi->dbi_no_fsync) {
1323 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR != 0) || (DB_VERSION_MAJOR == 4)
1324 xx = db_env_set_func_fsync(db3_fsync_disable);
1325@@ -366,7 +396,11 @@
1326 if (db != NULL)
1327 rc = db->sync(db, flags);
1328 /* XXX DB_INCOMPLETE is returned occaisionally with multiple access. */
1329+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1)
1330+ _printit = _debug;
1331+#else
1332 _printit = (rc == DB_INCOMPLETE ? 0 : _debug);
1333+#endif
1334 rc = cvtdberr(dbi, "db->sync", rc, _printit);
1335 return rc;
1336 }
1337@@ -599,10 +633,17 @@
1338 {
1339 DB * db = dbi->dbi_db;
1340 DB * secondary = dbisecondary->dbi_db;
1341+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1)
1342+ DB_TXN * txnid = NULL;
1343+#endif
1344 int rc;
1345
1346 /*@-moduncon@*/ /* FIX: annotate db3 methods */
1347+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1)
1348+ rc = db->associate(db, txnid, secondary, callback, flags);
1349+#else
1350 rc = db->associate(db, secondary, callback, flags);
1351+#endif
1352 /*@=moduncon@*/
1353 rc = cvtdberr(dbi, "db->associate", rc, _debug);
1354 return rc;
1355@@ -789,6 +830,9 @@
1356
1357 DB * db = NULL;
1358 DB_ENV * dbenv = NULL;
1359+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1)
1360+ DB_TXN * txnid = NULL;
1361+#endif
1362 u_int32_t oflags;
1363 int _printit;
1364
1365@@ -981,18 +1025,7 @@
1366 /*@=moduncon@*/
1367 rc = cvtdberr(dbi, "db_create", rc, _debug);
1368 if (rc == 0 && db != NULL) {
1369- if (rc == 0 && dbi->dbi_lorder) {
1370- rc = db->set_lorder(db, dbi->dbi_lorder);
1371- rc = cvtdberr(dbi, "db->set_lorder", rc, _debug);
1372- }
1373- if (rc == 0 && dbi->dbi_cachesize) {
1374- rc = db->set_cachesize(db, 0, dbi->dbi_cachesize, 0);
1375- rc = cvtdberr(dbi, "db->set_cachesize", rc, _debug);
1376- }
1377- if (rc == 0 && dbi->dbi_pagesize) {
1378- rc = db->set_pagesize(db, dbi->dbi_pagesize);
1379- rc = cvtdberr(dbi, "db->set_pagesize", rc, _debug);
1380- }
1381+
1382 /* XXX 3.3.4 change. */
1383 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3) || (DB_VERSION_MAJOR == 4)
1384 if (rc == 0 &&
1385@@ -1008,6 +1041,27 @@
1386 rc = cvtdberr(dbi, "db->set_malloc", rc, _debug);
1387 }
1388 #endif
1389+
1390+/* 4.1: db->set_cache_priority(???) */
1391+ if (rc == 0 && !dbi->dbi_use_dbenv && dbi->dbi_cachesize) {
1392+ rc = db->set_cachesize(db, 0, dbi->dbi_cachesize, 0);
1393+ rc = cvtdberr(dbi, "db->set_cachesize", rc, _debug);
1394+ }
1395+/* 4.1: db->set_encrypt(???) */
1396+/* 4.1: db->set_errcall(dbenv, rpmdb->db_errcall); */
1397+/* 4.1: db->set_errfile(dbenv, rpmdb->db_errfile); */
1398+/* 4.1: db->set_errpfx(dbenv, rpmdb->db_errpfx); */
1399+ /* 4.1: db->set_feedback(???) */
1400+
1401+ if (rc == 0 && dbi->dbi_lorder) {
1402+ rc = db->set_lorder(db, dbi->dbi_lorder);
1403+ rc = cvtdberr(dbi, "db->set_lorder", rc, _debug);
1404+ }
1405+ if (rc == 0 && dbi->dbi_pagesize) {
1406+ rc = db->set_pagesize(db, dbi->dbi_pagesize);
1407+ rc = cvtdberr(dbi, "db->set_pagesize", rc, _debug);
1408+ }
1409+ /* 4.1: db->set_paniccall(???) */
1410 if (rc == 0 && oflags & DB_CREATE) {
1411 switch(dbi->dbi_type) {
1412 default:
1413@@ -1042,6 +1096,7 @@
1414 #endif
1415 break;
1416 case DB_BTREE:
1417+/* 4.1: db->set_append_recno(???) */
1418 if (dbi->dbi_bt_flags) {
1419 rc = db->set_flags(db, dbi->dbi_bt_flags);
1420 rc = cvtdberr(dbi, "db->set_bt_flags", rc, _debug);
1421@@ -1073,6 +1128,7 @@
1422 break;
1423 case DB_RECNO:
1424 if (dbi->dbi_re_delim) {
1425+/* 4.1: db->set_append_recno(???) */
1426 rc = db->set_re_delim(db, dbi->dbi_re_delim);
1427 rc = cvtdberr(dbi, "db->set_re_selim", rc, _debug);
1428 if (rc) break;
1429@@ -1124,8 +1180,13 @@
1430 ? dbfullpath : dbfile;
1431 #endif
1432
1433+#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 1)
1434+ rc = db->open(db, txnid, dbpath, dbsubfile,
1435+ dbi->dbi_type, oflags, dbi->dbi_perms);
1436+#else
1437 rc = db->open(db, dbpath, dbsubfile,
1438 dbi->dbi_type, oflags, dbi->dbi_perms);
1439+#endif
1440
1441 if (rc == 0 && dbi->dbi_type == DB_UNKNOWN) {
1442 #if (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 3 && DB_VERSION_PATCH == 11) \
1443Index: rpmdb/dbconfig.c
1444===================================================================
1445RCS file: rpm/rpmdb/dbconfig.c,v
1446retrieving revision 1.33
1447retrieving revision 1.33.2.1
1448diff -u -u -r1.33 -r1.33.2.1
1449--- rpm/rpmdb/dbconfig.c 3 Aug 2002 22:31:39 -0000 1.33
1450+++ rpm/rpmdb/dbconfig.c 6 Nov 2002 17:29:34 -0000 1.33.2.1
1451@@ -190,9 +190,11 @@
1452 { "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
1453 NULL, NULL },
1454
1455- { "mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mp_mmapsize, 0,
1456+ { "mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
1457 NULL, NULL },
1458- { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_mp_size, 0,
1459+ { "mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
1460+ NULL, NULL },
1461+ { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
1462 NULL, NULL },
1463 { "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
1464 NULL, NULL },
1465@@ -259,7 +261,7 @@
1466 /** @todo Set a reasonable "last gasp" default db config. */
1467 /*@observer@*/ /*@unchecked@*/
1468 static const char *db3_config_default =
1469- "db3:hash:mpool:cdb:usecursors:verbose:mp_mmapsize=8Mb:mp_size=512Kb:pagesize=512:perms=0644";
1470+ "db3:hash:mpool:cdb:usecursors:verbose:mp_mmapsize=8Mb:cachesize=512Kb:pagesize=512:perms=0644";
1471
1472 /*@-bounds@*/
1473 dbiIndex db3New(rpmdb rpmdb, rpmTag rpmtag)
1474@@ -432,8 +434,8 @@
1475 if (!dbi->dbi_use_dbenv) { /* db3 dbenv is always used now. */
1476 dbi->dbi_use_dbenv = 1;
1477 dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
1478- dbi->dbi_mp_mmapsize = 16 * 1024 * 1024;
1479- dbi->dbi_mp_size = 1 * 1024 * 1024;
1480+ dbi->dbi_mmapsize = 16 * 1024 * 1024;
1481+ dbi->dbi_cachesize = 1 * 1024 * 1024;
1482 }
1483
1484 if ((dbi->dbi_bt_flags | dbi->dbi_h_flags) & DB_DUP)
1485Index: rpmdb/header.c
1486===================================================================
1487RCS file: rpm/rpmdb/header.c,v
1488retrieving revision 1.17.2.11
1489retrieving revision 1.17.2.12
1490diff -u -u -r1.17.2.11 -r1.17.2.12
1491--- rpm/rpmdb/header.c 17 Sep 2002 15:19:45 -0000 1.17.2.11
1492+++ rpm/rpmdb/header.c 6 Nov 2002 17:29:34 -0000 1.17.2.12
1493@@ -2825,6 +2825,7 @@
1494 }
1495
1496 /*@-branchstate@*/
1497+ if (data)
1498 switch (type) {
1499 case RPM_STRING_ARRAY_TYPE:
1500 strarray = (const char **)data;
1501Index: rpmdb/header.h
1502===================================================================
1503RCS file: rpm/rpmdb/header.h,v
1504retrieving revision 1.6
1505retrieving revision 1.6.2.1
1506diff -u -u -r1.6 -r1.6.2.1
1507--- rpm/rpmdb/header.h 13 Jul 2002 19:10:02 -0000 1.6
1508+++ rpm/rpmdb/header.h 6 Nov 2002 17:29:34 -0000 1.6.2.1
1509@@ -78,7 +78,7 @@
1510 /* RPM - Copyright (C) 1995-2001 Red Hat Software */
1511
1512 #include <stdio.h>
1513-#include <rpmio.h>
1514+#include "rpmio.h"
1515
1516 #ifdef __cplusplus
1517 extern "C" {
1518@@ -717,7 +717,7 @@
1519 }
1520
1521 #if !defined(__HEADER_PROTOTYPES__)
1522-#include <hdrinline.h>
1523+#include "hdrinline.h"
1524 #endif
1525
1526 #ifdef __cplusplus
1527Index: rpmdb/rpmdb.h
1528===================================================================
1529RCS file: rpm/rpmdb/rpmdb.h,v
1530retrieving revision 1.46.2.2
1531retrieving revision 1.46.2.3
1532diff -u -u -r1.46.2.2 -r1.46.2.3
1533--- rpm/rpmdb/rpmdb.h 17 Sep 2002 15:19:46 -0000 1.46.2.2
1534+++ rpm/rpmdb/rpmdb.h 6 Nov 2002 17:29:34 -0000 1.46.2.3
1535@@ -8,8 +8,8 @@
1536 */
1537
1538 #include <assert.h>
1539-#include <rpmlib.h>
1540-#include <db.h>
1541+#include "rpmlib.h"
1542+#include "db.h"
1543
1544 /*@-exportlocal@*/
1545 /*@unchecked@*/
1546@@ -321,8 +321,8 @@
1547 int dbi_region_init;
1548 int dbi_tas_spins;
1549 /* mpool sub-system parameters */
1550- int dbi_mp_mmapsize; /*!< (10Mb) */
1551- int dbi_mp_size; /*!< (128Kb) */
1552+ int dbi_mmapsize; /*!< (10Mb) */
1553+ int dbi_cachesize; /*!< (128Kb) */
1554 /* lock sub-system parameters */
1555 unsigned int dbi_lk_max;
1556 unsigned int dbi_lk_detect;
1557@@ -340,7 +340,6 @@
1558 /*@modifies fileSystem @*/;
1559 #endif
1560 /* dbinfo parameters */
1561- int dbi_cachesize; /*!< */
1562 int dbi_pagesize; /*!< (fs blksize) */
1563 /*@unused@*/ /*@null@*/
1564 void * (*dbi_malloc) (size_t nbytes)
1565Index: rpmio/rpmlog.c
1566===================================================================
1567RCS file: rpm/rpmio/rpmlog.c,v
1568retrieving revision 2.27
1569retrieving revision 2.27.2.1
1570diff -u -u -r2.27 -r2.27.2.1
1571--- rpm/rpmio/rpmlog.c 2 Jul 2002 23:54:38 -0000 2.27
1572+++ rpm/rpmio/rpmlog.c 20 Sep 2002 16:33:49 -0000 2.27.2.1
1573@@ -179,6 +179,7 @@
1574 else /* glibc 2.0 */
1575 msgnb *= 2;
1576 msgbuf = xrealloc(msgbuf, msgnb);
1577+ va_end(apc);
1578 }
1579 msgbuf[msgnb - 1] = '\0';
1580 msg = msgbuf;
1581Index: rpmio/rpmrpc.c
1582===================================================================
1583RCS file: rpm/rpmio/rpmrpc.c,v
1584retrieving revision 2.27.2.2
1585retrieving revision 2.27.2.3
1586diff -u -u -r2.27.2.2 -r2.27.2.3
1587--- rpm/rpmio/rpmrpc.c 17 Sep 2002 15:19:46 -0000 2.27.2.2
1588+++ rpm/rpmio/rpmrpc.c 9 Oct 2002 19:06:24 -0000 2.27.2.3
1589@@ -1023,7 +1023,7 @@
1590 (unsigned)st->st_dev,
1591 (unsigned)st->st_ino,
1592 st->st_mode,
1593- st->st_nlink,
1594+ (unsigned)st->st_nlink,
1595 st->st_uid,
1596 st->st_gid,
1597 (unsigned)st->st_rdev,
1598Index: tools/sections.c
1599===================================================================
1600RCS file: rpm/tools/sections.c,v
1601retrieving revision 1.1.2.2
1602retrieving revision 1.1.2.4
1603diff -u -u -r1.1.2.2 -r1.1.2.4
1604--- rpm/tools/sections.c 22 Aug 2002 19:19:47 -0000 1.1.2.2
1605+++ rpm/tools/sections.c 9 Oct 2002 19:06:24 -0000 1.1.2.4
1606@@ -24,38 +24,168 @@
1607 } UnstripInfo32;
1608
1609 typedef struct {
1610- Elf32_Off orig_e_shoff;
1611- Elf32_Off n_sections;
1612+ Elf64_Off orig_e_shoff;
1613+ Elf64_Off n_sections;
1614 UnstripInfoSection64 sections[1];
1615 } UnstripInfo64;
1616
1617+static uint32_t
1618+elf_32_to_file (uint32_t x, int file_is_little_endian)
1619+{
1620+ volatile uint32_t out;
1621+ unsigned char *outbytes;
1622+
1623+ outbytes = (unsigned char *)&out;
1624+ if (file_is_little_endian)
1625+ {
1626+ outbytes[0] = (x >> 0) & 0xff;
1627+ outbytes[1] = (x >> 8) & 0xff;
1628+ outbytes[2] = (x >> 16) & 0xff;
1629+ outbytes[3] = (x >> 24) & 0xff;
1630+ }
1631+ else /* big endian */
1632+ {
1633+ outbytes[0] = (x >> 24) & 0xff;
1634+ outbytes[1] = (x >> 16) & 0xff;
1635+ outbytes[2] = (x >> 8) & 0xff;
1636+ outbytes[3] = (x >> 0) & 0xff;
1637+ }
1638+
1639+ return out;
1640+}
1641+
1642+static uint64_t
1643+elf_64_to_file (uint64_t x, int file_is_little_endian)
1644+{
1645+ volatile uint64_t out;
1646+ unsigned char *outbytes;
1647+ int i;
1648+
1649+ outbytes = (unsigned char *)&out;
1650+ if (file_is_little_endian)
1651+ {
1652+ for (i = 0; i < 8; i++)
1653+ outbytes[i] = (x >> (8*i)) & 0xff;
1654+ }
1655+ else /* big endian */
1656+ {
1657+ for (i = 0; i < 8; i++)
1658+ outbytes[7-i] = (x >> (8*i)) & 0xff;
1659+ }
1660+
1661+ return out;
1662+}
1663
1664 static Elf32_Word
1665 word32_to_file (Elf32_Word x, Elf *elf)
1666 {
1667- /* FIXME: implement */
1668- return x;
1669+ Elf32_Ehdr *ehdr = elf32_getehdr (elf);
1670+ return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1671 }
1672
1673 static Elf32_Off
1674 off32_to_file (Elf32_Off x, Elf *elf)
1675 {
1676- /* FIXME: implement */
1677- return x;
1678+ Elf32_Ehdr *ehdr = elf32_getehdr (elf);
1679+ return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1680+}
1681+
1682+static Elf64_Word
1683+word64_to_file (Elf64_Word x, Elf *elf)
1684+{
1685+ Elf64_Ehdr *ehdr = elf64_getehdr (elf);
1686+ return elf_32_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1687+}
1688+
1689+static Elf64_Off
1690+off64_to_file (Elf64_Off x, Elf *elf)
1691+{
1692+ Elf64_Ehdr *ehdr = elf64_getehdr (elf);
1693+ return elf_64_to_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1694+}
1695+
1696+static uint32_t
1697+elf_32_from_file (uint32_t x, int file_is_little_endian)
1698+{
1699+ unsigned char *inbytes;
1700+
1701+ inbytes = (unsigned char *)&x;
1702+ if (file_is_little_endian)
1703+ {
1704+ return
1705+ (inbytes[0] << 0) |
1706+ (inbytes[1] << 8) |
1707+ (inbytes[2] << 16) |
1708+ (inbytes[3] << 24);
1709+ }
1710+ else /* big endian */
1711+ {
1712+ return
1713+ (inbytes[0] << 24) |
1714+ (inbytes[1] << 16) |
1715+ (inbytes[2] << 8) |
1716+ (inbytes[3] << 0);
1717+ }
1718+}
1719+
1720+static uint64_t
1721+elf_64_from_file (uint64_t x, int file_is_little_endian)
1722+{
1723+ unsigned char *inbytes;
1724+
1725+ inbytes = (unsigned char *)&x;
1726+ if (file_is_little_endian)
1727+ {
1728+ return
1729+ ((uint64_t)inbytes[0] << 0) |
1730+ ((uint64_t)inbytes[1] << 8) |
1731+ ((uint64_t)inbytes[2] << 16) |
1732+ ((uint64_t)inbytes[3] << 24) |
1733+ ((uint64_t)inbytes[4] << 32) |
1734+ ((uint64_t)inbytes[5] << 40) |
1735+ ((uint64_t)inbytes[6] << 48) |
1736+ ((uint64_t)inbytes[7] << 56);
1737+ }
1738+ else /* big endian */
1739+ {
1740+ return
1741+ ((uint64_t)inbytes[0] << 56) |
1742+ ((uint64_t)inbytes[1] << 48) |
1743+ ((uint64_t)inbytes[2] << 40) |
1744+ ((uint64_t)inbytes[3] << 32) |
1745+ ((uint64_t)inbytes[4] << 24) |
1746+ ((uint64_t)inbytes[5] << 16) |
1747+ ((uint64_t)inbytes[6] << 8) |
1748+ ((uint64_t)inbytes[7] << 0);
1749+ }
1750 }
1751
1752 static Elf32_Word
1753 word32_from_file (Elf32_Word x, Elf *elf)
1754 {
1755- /* FIXME: implement */
1756- return x;
1757+ Elf32_Ehdr *ehdr = elf32_getehdr (elf);
1758+ return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1759 }
1760
1761 static Elf32_Off
1762 off32_from_file (Elf32_Off x, Elf *elf)
1763 {
1764- /* FIXME: implement */
1765- return x;
1766+ Elf32_Ehdr *ehdr = elf32_getehdr (elf);
1767+ return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1768+}
1769+
1770+static Elf64_Word
1771+word64_from_file (Elf64_Word x, Elf *elf)
1772+{
1773+ Elf64_Ehdr *ehdr = elf64_getehdr (elf);
1774+ return elf_32_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1775+}
1776+
1777+static Elf64_Off
1778+off64_from_file (Elf64_Off x, Elf *elf)
1779+{
1780+ Elf64_Ehdr *ehdr = elf64_getehdr (elf);
1781+ return elf_64_from_file (x, ehdr->e_ident[EI_DATA] & ELFDATA2LSB);
1782 }
1783
1784 static void
1785@@ -93,7 +223,29 @@
1786 Elf *elf,
1787 Elf_Data *data)
1788 {
1789+ UnstripInfo64 *info64;
1790+ int i;
1791+
1792 data->d_align = 8;
1793+
1794+ data->d_size =
1795+ /* orig_e_shoff */ sizeof (Elf64_Off) +
1796+ /* n_sections */ sizeof (Elf64_Off) +
1797+ /* sections */ info->n_sections * sizeof (UnstripInfoSection64);
1798+
1799+ data->d_buf = calloc (1, data->d_size);
1800+
1801+ info64 = (UnstripInfo64 *) data->d_buf;
1802+
1803+ info64->orig_e_shoff = off64_to_file (info->orig_e_shoff, elf);
1804+ info64->n_sections = off64_to_file (info->n_sections, elf);
1805+
1806+ for (i = 0; i < info->n_sections; i++)
1807+ {
1808+ info64->sections[i].debug_section = word64_to_file (info->sections[i].debug_section, elf);
1809+ info64->sections[i].name = word64_to_file (info->sections[i].name, elf);
1810+ info64->sections[i].orig_offset = off64_to_file (info->sections[i].orig_offset, elf);
1811+ }
1812 }
1813
1814 void
1815@@ -101,14 +253,21 @@
1816 Elf *elf,
1817 Elf_Data *data)
1818 {
1819+ GElf_Ehdr ehdr;
1820+
1821 data->d_type = ELF_T_BYTE;
1822 data->d_off = 0;
1823
1824- /* FIXME: use right version */
1825- unstrip_info_to_data32 (info, elf, data);
1826+ gelf_getehdr (elf, &ehdr);
1827+ if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
1828+ unstrip_info_to_data32 (info, elf, data);
1829+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
1830+ unstrip_info_to_data64 (info, elf, data);
1831+ else
1832+ fprintf (stderr, "Warning. unsupported elf class\n");
1833 }
1834
1835-void
1836+static void
1837 unstrip_info_from_data32 (UnstripInfo *info,
1838 Elf *elf,
1839 Elf_Data *data)
1840@@ -130,23 +289,49 @@
1841 }
1842 }
1843
1844+static void
1845+unstrip_info_from_data64 (UnstripInfo *info,
1846+ Elf *elf,
1847+ Elf_Data *data)
1848+{
1849+ UnstripInfo64 *info64;
1850+ int i;
1851+
1852+ info64 = (UnstripInfo64 *) data->d_buf;
1853+
1854+ info->orig_e_shoff = off64_from_file (info64->orig_e_shoff, elf);
1855+ info->n_sections = off64_from_file (info64->n_sections, elf);
1856+
1857+ info->sections = calloc (info->n_sections, sizeof (UnstripInfoSection));
1858+ for (i = 0; i < info->n_sections; i++)
1859+ {
1860+ info->sections[i].debug_section = word64_from_file (info64->sections[i].debug_section, elf);
1861+ info->sections[i].name = word64_from_file (info64->sections[i].name, elf);
1862+ info->sections[i].orig_offset = off64_from_file (info64->sections[i].orig_offset, elf);
1863+ }
1864+}
1865+
1866 UnstripInfo *
1867 unstrip_info_from_data (Elf *elf,
1868 Elf_Data *data)
1869 {
1870+ GElf_Ehdr ehdr;
1871+
1872 UnstripInfo *info;
1873
1874 info = malloc (sizeof (UnstripInfo));
1875
1876- /* FIXME: use right version */
1877- unstrip_info_from_data32 (info,
1878- elf,
1879- data);
1880+ gelf_getehdr (elf, &ehdr);
1881+ if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
1882+ unstrip_info_from_data32 (info, elf, data);
1883+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
1884+ unstrip_info_from_data64 (info, elf, data);
1885+ else
1886+ fprintf (stderr, "Warning. unsupported elf class\n");
1887
1888 return info;
1889 }
1890
1891-
1892 static void
1893 debug_link_to_data32 (DebugLink *debuglink,
1894 Elf *elf,
1895@@ -166,23 +351,53 @@
1896 data->d_buf = calloc (1, data->d_size);
1897
1898 strcpy (data->d_buf, debuglink->filename);
1899- p = data->d_buf + namelen_aligned;
1900+ p = ((char *)data->d_buf) + namelen_aligned;
1901
1902 *(Elf32_Word *)p = word32_to_file (debuglink->checksum, elf);
1903- p += sizeof (Elf32_Word);
1904+}
1905+
1906+static void
1907+debug_link_to_data64 (DebugLink *debuglink,
1908+ Elf *elf,
1909+ Elf_Data *data)
1910+{
1911+ size_t namelen_aligned;
1912+ char *p;
1913+
1914+ data->d_align = 4;
1915+
1916+ namelen_aligned = align_up (strlen(debuglink->filename) + 1, 4);
1917+
1918+ data->d_size =
1919+ /* name */ namelen_aligned +
1920+ /* checksum */ sizeof (Elf64_Word);
1921+
1922+ data->d_buf = calloc (1, data->d_size);
1923+
1924+ strcpy (data->d_buf, debuglink->filename);
1925+ p = ((char *)data->d_buf) + namelen_aligned;
1926+
1927+ *(Elf64_Word *)p = word64_to_file (debuglink->checksum, elf);
1928 }
1929
1930 void
1931 debug_link_to_data (DebugLink *debuglink, Elf *elf, Elf_Data *data)
1932 {
1933+ GElf_Ehdr ehdr;
1934+
1935 data->d_type = ELF_T_BYTE;
1936 data->d_off = 0;
1937
1938- /* FIXME: use right version */
1939- debug_link_to_data32 (debuglink, elf, data);
1940+ gelf_getehdr (elf, &ehdr);
1941+ if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
1942+ debug_link_to_data32 (debuglink, elf, data);
1943+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
1944+ debug_link_to_data64 (debuglink, elf, data);
1945+ else
1946+ fprintf (stderr, "Warning. unsupported elf class\n");
1947 }
1948
1949-void
1950+static void
1951 debug_link_from_data32 (DebugLink *debuglink,
1952 Elf *elf,
1953 Elf_Data *data)
1954@@ -194,24 +409,44 @@
1955
1956 namelen_aligned = align_up (strlen (debuglink->filename) + 1, 4);
1957
1958- p = data->d_buf + namelen_aligned;
1959+ p = ((char *)data->d_buf) + namelen_aligned;
1960
1961 debuglink->checksum = word32_from_file (*(Elf32_Word *)p, elf);
1962- p += sizeof (Elf32_Word);
1963+}
1964+
1965+static void
1966+debug_link_from_data64 (DebugLink *debuglink,
1967+ Elf *elf,
1968+ Elf_Data *data)
1969+{
1970+ size_t namelen_aligned;
1971+ char *p;
1972+
1973+ debuglink->filename = strdup (data->d_buf);
1974+
1975+ namelen_aligned = align_up (strlen (debuglink->filename) + 1, 4);
1976+
1977+ p = ((char *)data->d_buf) + namelen_aligned;
1978+
1979+ debuglink->checksum = word64_from_file (*(Elf64_Word *)p, elf);
1980 }
1981
1982
1983 DebugLink *
1984 debug_link_from_data (Elf *elf, Elf_Data *data)
1985 {
1986+ GElf_Ehdr ehdr;
1987 DebugLink *debuglink;
1988
1989 debuglink = malloc (sizeof (DebugLink));
1990
1991- /* FIXME: use right version */
1992- debug_link_from_data32 (debuglink,
1993- elf,
1994- data);
1995+ gelf_getehdr (elf, &ehdr);
1996+ if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
1997+ debug_link_from_data32 (debuglink, elf, data);
1998+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
1999+ debug_link_from_data64 (debuglink, elf, data);
2000+ else
2001+ fprintf (stderr, "Warning. unsupported elf class\n");
2002
2003 return debuglink;
2004 }
2005Index: tools/striptofile.c
2006===================================================================
2007RCS file: rpm/tools/striptofile.c,v
2008retrieving revision 1.1.2.2
2009retrieving revision 1.1.2.4
2010diff -u -u -r1.1.2.2 -r1.1.2.4
2011--- rpm/tools/striptofile.c 22 Aug 2002 19:19:47 -0000 1.1.2.2
2012+++ rpm/tools/striptofile.c 9 Oct 2002 19:06:24 -0000 1.1.2.4
2013@@ -15,7 +15,8 @@
2014 int keep_all_section_headers = 1;
2015 int add_unstrip_info = 0;
2016
2017-void
2018+#if defined(NhUNUSED)
2019+static void
2020 copy_to_file(Elf *elf, Elf *out_elf)
2021 {
2022 GElf_Ehdr ehdr;
2023@@ -67,8 +68,9 @@
2024 }
2025 }
2026 }
2027+#endif
2028
2029-void
2030+static void
2031 strip_to_file(Elf *elf, Elf *out_elf, DebugLink *debuglink)
2032 {
2033 GElf_Ehdr ehdr;
2034@@ -82,7 +84,8 @@
2035 int keep_section;
2036 int changed_offsets;
2037 GElf_Off last_offset;
2038- int i, debuglink_name;
2039+ int i;
2040+ int debuglink_name = 0;
2041
2042 elf_flagelf (out_elf, ELF_C_SET, ELF_F_LAYOUT);
2043
2044@@ -201,7 +204,7 @@
2045 /* Update section header stringtab ref */
2046 gelf_getehdr (out_elf, &out_ehdr);
2047 out_ehdr.e_shstrndx = section_map[out_ehdr.e_shstrndx];
2048- out_ehdr.e_shoff = align_up (last_offset, 4);
2049+ out_ehdr.e_shoff = align_up (last_offset, 8);
2050 gelf_update_ehdr(out_elf, &out_ehdr);
2051
2052 /* Update section header links */
2053@@ -220,7 +223,7 @@
2054 }
2055 }
2056
2057-void
2058+static void
2059 copy_debuginfo_to_file(Elf *elf, Elf *out_elf)
2060 {
2061 GElf_Ehdr ehdr;
2062@@ -231,7 +234,7 @@
2063 unsigned char *section_strtab;
2064 int keep_section;
2065 UnstripInfo *info;
2066- int unstripinfo_name;
2067+ int unstripinfo_name = 0;
2068
2069 info = malloc (sizeof (UnstripInfo));
2070
2071@@ -402,6 +405,7 @@
2072 Elf *elf, *out_elf;
2073 int fd, out;
2074 const char *origname;
2075+ char *origname_base;
2076 char *debugname, *strippedname;
2077 DebugLink *debuglink;
2078 poptContext optCon; /* context for parsing command-line options */
2079@@ -433,14 +437,13 @@
2080
2081 origname = args[0];
2082
2083- if (output_dir) {
2084- const char * bn = strrchr(origname, '/');
2085- if ((bn = strrchr(origname, '/')) != NULL)
2086- bn++;
2087- else
2088- bn = origname;
2089- debugname = strconcat (output_dir, "/", bn, ".debug", NULL);
2090- } else
2091+ if (output_dir)
2092+ {
2093+ origname_base = path_basename (origname);
2094+ debugname = strconcat (output_dir, "/", origname_base, ".debug", NULL);
2095+ free (origname_base);
2096+ }
2097+ else
2098 debugname = strconcat (origname, ".debug", NULL);
2099
2100 strippedname = strconcat (origname, ".XXXXXX", NULL);
2101Index: tools/unstripfile.c
2102===================================================================
2103RCS file: rpm/tools/unstripfile.c,v
2104retrieving revision 1.1.2.2
2105retrieving revision 1.1.2.3
2106diff -u -u -r1.1.2.2 -r1.1.2.3
2107--- rpm/tools/unstripfile.c 22 Aug 2002 19:19:47 -0000 1.1.2.2
2108+++ rpm/tools/unstripfile.c 9 Oct 2002 19:06:24 -0000 1.1.2.3
2109@@ -9,7 +9,7 @@
2110
2111 #include "debug.h"
2112
2113-DebugLink *
2114+static DebugLink *
2115 read_debuglink (Elf *elf)
2116 {
2117 GElf_Ehdr ehdr;
2118@@ -47,7 +47,7 @@
2119 return NULL;
2120 }
2121
2122-Elf_Scn *
2123+static Elf_Scn *
2124 find_section (Elf *elf, const unsigned char *name, const unsigned char *strtab)
2125 {
2126 Elf_Scn *section;
2127@@ -69,7 +69,7 @@
2128 return section;
2129 }
2130
2131-size_t
2132+static size_t
2133 find_in_strtab (char *name, char *strtab, size_t strtab_len)
2134 {
2135 int name_len, i;
2136@@ -82,7 +82,7 @@
2137 return 0;
2138 }
2139
2140-void
2141+static void
2142 unstrip_file (Elf *elf, Elf *debug_elf, Elf *out_elf)
2143 {
2144 UnstripInfo *info;
2145Index: tools/utils.c
2146===================================================================
2147RCS file: rpm/tools/utils.c,v
2148retrieving revision 1.1.2.3
2149retrieving revision 1.1.2.4
2150diff -u -u -r1.1.2.3 -r1.1.2.4
2151--- rpm/tools/utils.c 4 Sep 2002 18:13:35 -0000 1.1.2.3
2152+++ rpm/tools/utils.c 9 Oct 2002 19:06:24 -0000 1.1.2.4
2153@@ -6,7 +6,7 @@
2154
2155 #include "debug.h"
2156
2157-char *
2158+static char *
2159 my_stpcpy (char *dest,
2160 const char *src)
2161 {
2162@@ -146,7 +146,7 @@
2163 0x2d02ef8d
2164 };
2165
2166-unsigned int crc32 (unsigned int crc, unsigned char *buf, size_t len)
2167+static unsigned int crc32 (unsigned int crc, unsigned char *buf, size_t len)
2168 {
2169 unsigned char *end;
2170
2171Index: xmlspec/Makefile
2172===================================================================
2173RCS file: rpm/xmlspec/Makefile,v
2174retrieving revision 1.5.2.2
2175retrieving revision 1.5.2.3
2176diff -u -u -r1.5.2.2 -r1.5.2.3
2177--- rpm/xmlspec/Makefile 28 Aug 2002 10:53:03 -0000 1.5.2.2
2178+++ rpm/xmlspec/Makefile 10 Oct 2002 22:47:59 -0000 1.5.2.3
2179@@ -7,7 +7,9 @@
2180 CFLAGS = -O2 -Wall -Wpointer-arith -Wno-char-subscripts
2181 INCDIR = -I. -I.. -I../build -I../lib -I../misc -I../popt -I../rpmdb -I../rpmio
2182 RPMDIR = ..
2183-DESTDIR = /usr/local
2184+
2185+prefix = /usr
2186+DESTDIR =
2187
2188 XMLBUILD = rpmxmlbuild
2189 XMLBUILD_SRC = rpmxmlbuild.c
2190@@ -21,6 +23,7 @@
2191 LIBS = $(XMLLIB) $(RPMDIR)/build/.libs/librpmbuild.a \
2192 $(RPMDIR)/lib/.libs/librpm.a $(RPMDIR)/rpmdb/.libs/librpmdb.a \
2193 $(RPMDIR)/rpmio/.libs/librpmio.a $(RPMDIR)/popt/.libs/libpopt.a \
2194+ $(RPMDIR)/libelf/lib/.libs/libelf.a \
2195 -lz -lexpat -lbz2
2196 LIBDIR = -L. -L$(RPMDIR)/.libs -L/usr/lib
2197
2198@@ -33,9 +36,9 @@
2199 $(STRIP) $(XMLBUILD)
2200
2201 install:
2202- @(cp $(XMLBUILD) $(DESTDIR)/bin)
2203- @(cp $(XMLLIB) $(DESTDIR)/lib)
2204- @(cp $(XMLLIB_H) $(DESTDIR)/include)
2205+ @(install -m 755 $(XMLBUILD) $(DESTDIR)$(prefix)/bin)
2206+ @(install -m 644 $(XMLLIB) $(DESTDIR)$(prefix)/lib)
2207+ @(install -m 644 $(XMLLIB_H) $(DESTDIR)$(prefix)/include/rpm)
2208
2209 $(XMLLIB): $(XMLLIB_OBJ)
2210 $(AR) $(ARFLAGS) $(XMLLIB) $(XMLLIB_OBJ)
2211Index: xmlspec/XMLAttrs.cpp
2212===================================================================
2213RCS file: xmlspec/XMLAttrs.cpp
2214diff -N xmlspec/XMLAttrs.cpp
2215--- /dev/null 1 Jan 1970 00:00:00 -0000
2216+++ rpm/xmlspec/XMLAttrs.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
2217@@ -0,0 +1,168 @@
2218+// standard C++ includes
2219+#include <string>
2220+
2221+// standard includes
2222+#include <string.h>
2223+
2224+// our includes
2225+#include "XMLAttrs.h"
2226+#include "XMLMisc.h"
2227+#include "XMLSpec.h"
2228+
2229+using namespace std;
2230+
2231+XMLAttr::XMLAttr(const char* szName,
2232+ const char* szValue)
2233+ : XMLBase()
2234+{
2235+ if (szName)
2236+ m_sName.assign(szName);
2237+ if (szValue)
2238+ m_sValue.assign(szValue);
2239+}
2240+
2241+XMLAttr::XMLAttr(const XMLAttr& rAttr)
2242+ : XMLBase()
2243+{
2244+ m_sName.assign(rAttr.m_sName);
2245+ m_sValue.assign(rAttr.m_sValue);
2246+}
2247+
2248+XMLAttr::~XMLAttr()
2249+{
2250+}
2251+
2252+XMLAttr XMLAttr::operator=(XMLAttr attr)
2253+{
2254+ m_sName.assign(attr.m_sName);
2255+ m_sValue.assign(attr.m_sValue);
2256+}
2257+
2258+XMLAttrs::XMLAttrs(const char** szAttrs)
2259+ : XMLBase()
2260+{
2261+ for (int i = 0; szAttrs && szAttrs[i]; i += 2) {
2262+ XMLAttr attr(szAttrs[i], szAttrs[i+1]);
2263+ m_vAttrs.push_back(attr);
2264+ }
2265+}
2266+
2267+XMLAttrs::XMLAttrs(const XMLAttrs& rAttrs)
2268+ : XMLBase()
2269+{
2270+ m_vAttrs = rAttrs.m_vAttrs;
2271+}
2272+
2273+XMLAttrs::~XMLAttrs()
2274+{
2275+}
2276+
2277+bool validateAttr(structValidAttrs& rAttr,
2278+ const char* szValue)
2279+{
2280+ switch (rAttr.m_nType) {
2281+ case XATTRTYPE_STRING:
2282+ return findStr(rAttr.m_szaMatches, szValue) != -1 ? true : false;
2283+ break;
2284+ case XATTRTYPE_INTEGER:
2285+ return isInteger(szValue);
2286+ break;
2287+ case XATTRTYPE_BOOL:
2288+ return isBool(szValue);
2289+ break;
2290+ case XATTRTYPE_DATE:
2291+ return isDate(szValue);
2292+ break;
2293+ case XATTRTYPE_MAIL:
2294+ return isEmail(szValue);
2295+ break;
2296+ case XATTRTYPE_NONE:
2297+ default:
2298+ return true;
2299+ break;
2300+ }
2301+ return false;
2302+}
2303+
2304+static char* szaTypeDesc[] = { "string",
2305+ "integer",
2306+ "bool [Values: true|false]",
2307+ "date [Format: DDD MMM DD YYYY]",
2308+ "e-mail" };
2309+
2310+bool XMLAttrs::validate(structValidAttrs* paValids,
2311+ XMLBase* pError)
2312+{
2313+ // nothing found at present
2314+ for (unsigned int i = 0; paValids[i].m_nValue != XATTR_END; i++)
2315+ paValids[i].m_bFound = false;
2316+
2317+ // test everything we have
2318+ for (unsigned int i = 0; i < num(); i++) {
2319+ bool bInvalid = true;
2320+ for (unsigned int j = 0; paValids[j].m_nValue != XATTR_END; j++) {
2321+ if (strcasecmp(paValids[j].m_szName, get(i).getName()) == 0) {
2322+ paValids[j].m_bFound = true;
2323+ if (!validateAttr(paValids[j], get(i).asString())) {
2324+ char szTmp[1024];
2325+ sprintf(szTmp, "Attribute value '%s' is not a valid %s.",
2326+ get(i).asString(), szaTypeDesc[paValids[j].m_nType]);
2327+ pError->setError(szTmp);
2328+ return false;
2329+ }
2330+ else
2331+ bInvalid = false;
2332+ break;
2333+ }
2334+ }
2335+ if (bInvalid) {
2336+ char szTmp[1024];
2337+ sprintf(szTmp, "Unknown attribute '%s'", get(i).getName());
2338+ pError->setWarning(szTmp);
2339+ }
2340+ }
2341+
2342+ // see if we have mandator tags that are not there
2343+ for (unsigned int i = 0; paValids[i].m_nValue != XATTR_END; i++) {
2344+ if (paValids[i].m_bMandatory && !paValids[i].m_bFound) {
2345+ char szTmp[1024];
2346+ sprintf(szTmp, "Mandatory attribute '%s' not found",
2347+ paValids[i].m_szName);
2348+ pError->setError(szTmp);
2349+ return false;
2350+ }
2351+ }
2352+
2353+ // if we got this far, everything is ok
2354+ return true;
2355+}
2356+
2357+unsigned int getPos(const char* szName,
2358+ XMLAttrs* pAttrs)
2359+{
2360+ if (szName) {
2361+ for (unsigned int i = 0; i < pAttrs->num(); i++) {
2362+ if (strcasecmp(szName, pAttrs->get(i).getName()) == 0)
2363+ return i;
2364+ }
2365+ }
2366+ return XATTR_END;
2367+}
2368+
2369+const char* XMLAttrs::asString(const char* szName)
2370+{
2371+ unsigned int nPos = getPos(szName, this);
2372+ return (nPos == XATTR_END) ? NULL : get(nPos).asString();
2373+}
2374+
2375+unsigned int XMLAttrs::asInteger(const char* szName)
2376+{
2377+ unsigned int nPos = getPos(szName, this);
2378+ return (nPos == XATTR_END) ? 0 : get(nPos).asInteger();
2379+}
2380+
2381+bool XMLAttrs::asBool(const char* szName)
2382+{
2383+ unsigned int nPos = getPos(szName, this);
2384+ return (nPos == XATTR_END) ? true : get(nPos).asBool();
2385+}
2386Index: xmlspec/XMLAttrs.h
2387===================================================================
2388RCS file: xmlspec/XMLAttrs.h
2389diff -N xmlspec/XMLAttrs.h
2390--- /dev/null 1 Jan 1970 00:00:00 -0000
2391+++ rpm/xmlspec/XMLAttrs.h 28 Aug 2002 10:52:43 -0000 1.2.2.1
2392@@ -0,0 +1,255 @@
2393+#ifndef _H_XMLATTRS_
2394+#define _H_XMLATTRS_
2395+
2396+// standard C++ includes
2397+#include <string>
2398+#include <vector>
2399+
2400+// standard C includes
2401+#include <string.h>
2402+
2403+// our includes
2404+#include "XMLBase.h"
2405+
2406+using namespace std;
2407+
2408+// definition for the end of the attributes
2409+#define XATTR_END 0xFFFF
2410+#define XATTR_NUM_VALSTR 5
2411+
2412+enum eAttrType
2413+{
2414+ XATTRTYPE_STRING = 0,
2415+ XATTRTYPE_INTEGER,
2416+ XATTRTYPE_BOOL,
2417+ XATTRTYPE_DATE,
2418+ XATTRTYPE_MAIL,
2419+ XATTRTYPE_NONE = XATTR_END
2420+};
2421+
2422+struct structValidAttrs
2423+{
2424+ unsigned int m_nValue;
2425+ bool m_bMandatory;
2426+ bool m_bFound;
2427+ char* m_szName;
2428+ unsigned int m_nType;
2429+ char* m_szaMatches[XATTR_NUM_VALSTR+1];
2430+};
2431+
2432+// forward class definitions
2433+class XMLSpec;
2434+
2435+class XMLAttr : public XMLBase
2436+{
2437+//
2438+// contructors/destructor
2439+//
2440+public:
2441+ /**
2442+ * Default constructor
2443+ * .
2444+ * @param szName The name of the attribute
2445+ * @param szValue The attribute value
2446+ * @return none
2447+ **/
2448+ XMLAttr(const char* szName,
2449+ const char* szValue);
2450+
2451+ /**
2452+ * Copy constructor
2453+ * .
2454+ * @param rAttr Reference to the attribute to copy
2455+ * @return none
2456+ **/
2457+ XMLAttr(const XMLAttr& rAttr);
2458+
2459+ /**
2460+ * Destructor
2461+ * .
2462+ * @param none
2463+ * @return none
2464+ **/
2465+ ~XMLAttr();
2466+
2467+//
2468+// operators
2469+//
2470+public:
2471+ /**
2472+ * Assignment operator
2473+ * .
2474+ * @param attr The attribute to copy
2475+ * @return the assigned obkect
2476+ **/
2477+ XMLAttr operator=(XMLAttr attr);
2478+
2479+//
2480+// get/set functions
2481+//
2482+public:
2483+ /**
2484+ * Returns the attribute name
2485+ * .
2486+ * @param none
2487+ * @return string containing the attribute name
2488+ **/
2489+ const char* getName()
2490+ {
2491+ return m_sName.c_str();
2492+ }
2493+
2494+ /**
2495+ * Returns the attribute value (as string)
2496+ * .
2497+ * @param none
2498+ * @return string containing the attribute value
2499+ **/
2500+ const char* asString()
2501+ {
2502+ return m_sValue.c_str();
2503+ }
2504+
2505+ /**
2506+ * Returns the attribute value (as integer)
2507+ * .
2508+ * @param none
2509+ * @return the attribute as an integer
2510+ **/
2511+ unsigned int asInteger()
2512+ {
2513+ return atoi(m_sValue.c_str());
2514+ }
2515+
2516+ /**
2517+ * Returns the attribute value as a boolean
2518+ * .
2519+ * @param none
2520+ * @return true if set, false otherwise
2521+ **/
2522+ bool asBool()
2523+ {
2524+ bool isSet = true;
2525+ if (strcasecmp(m_sValue.c_str(), "no") == 0 ||
2526+ strcasecmp(m_sValue.c_str(), "0") == 0 ||
2527+ strcasecmp(m_sValue.c_str(), "false") == 0)
2528+ isSet = false;
2529+ return isSet;
2530+ }
2531+
2532+//
2533+// member variables
2534+//
2535+public:
2536+ string m_sName;
2537+ string m_sValue;
2538+};
2539+
2540+class XMLAttrs : public XMLBase
2541+{
2542+//
2543+// constructors/destructor
2544+//
2545+public:
2546+ /**
2547+ * The default attribute constructor
2548+ * .
2549+ * @param szAttrs Pointer to an array of attributes, terminated by NULL
2550+ * @return none
2551+ **/
2552+ XMLAttrs(const char** szAttrs);
2553+
2554+ /**
2555+ * Copy constructor
2556+ * .
2557+ * @param rAttrs The attribute object to copy
2558+ * @return none
2559+ **/
2560+ XMLAttrs(const XMLAttrs& rAttrs);
2561+
2562+ /**
2563+ * The default destructor
2564+ * .
2565+ * @param none
2566+ * @return none
2567+ **/
2568+ ~XMLAttrs();
2569+
2570+//
2571+// member functions
2572+//
2573+public:
2574+ /**
2575+ * Validates an attribute object against the valid attributes. This
2576+ * checks for mandatory attributes (error) as well as unexpected
2577+ * attributes. (warnings)
2578+ * .
2579+ * @param paValids Pointer to the array of valid attributes
2580+ * @param pError The class in which we will set the errors
2581+ * and/or warnings.
2582+ * @return true on valid attributes, false otherwise
2583+ **/
2584+ bool validate(structValidAttrs* paValids,
2585+ XMLBase* pError);
2586+
2587+//
2588+// member variables get/set functions
2589+//
2590+public:
2591+ /**
2592+ * Gets the number of attributes contained in this object
2593+ * .
2594+ * @param none
2595+ * @returns The number of attributes
2596+ **/
2597+ unsigned int num()
2598+ {
2599+ return m_vAttrs.size();
2600+ }
2601+
2602+ /**
2603+ * Returns a specific attribute by number
2604+ * .
2605+ * @param nNum The number of the attribute to return
2606+ * @return The attribute or NULL if it doesn't exist
2607+ **/
2608+ XMLAttr& get(unsigned int nNum)
2609+ {
2610+ return m_vAttrs[nNum];
2611+ }
2612+
2613+ /**
2614+ * Returns the attribute as specified by the name
2615+ * .
2616+ * @param szName The name of the attribute whose value we are
2617+ * to return
2618+ * @return The attribute as a string
2619+ **/
2620+ const char* asString(const char* szName);
2621+
2622+ /**
2623+ * Returns the attribute as specified by the name
2624+ * .
2625+ * @param szName The name of the attribute whose value we are
2626+ * to return
2627+ * @return The attribute as an integer
2628+ **/
2629+ unsigned int asInteger(const char* szName);
2630+
2631+ /**
2632+ * Returns the attribute as specified by the name
2633+ * .
2634+ * @param szName The name of the attribute whose value we are
2635+ * to return
2636+ * @return The attribute as a bool
2637+ **/
2638+ bool asBool(const char* szName);
2639+
2640+//
2641+// protected data members
2642+//
2643+protected:
2644+ vector<XMLAttr> m_vAttrs;
2645+};
2646+
2647+#endif
2648Index: xmlspec/XMLBase.h
2649===================================================================
2650RCS file: xmlspec/XMLBase.h
2651diff -N xmlspec/XMLBase.h
2652--- /dev/null 1 Jan 1970 00:00:00 -0000
2653+++ rpm/xmlspec/XMLBase.h 28 Aug 2002 10:52:43 -0000 1.1.1.1.2.1
2654@@ -0,0 +1,134 @@
2655+#ifndef _H_XMLBASE_
2656+#define _H_XMLBASE_
2657+
2658+// standard C++ includes
2659+#include <string>
2660+
2661+// standard include
2662+#include <stdio.h>
2663+
2664+using namespace std;
2665+
2666+class XMLBase
2667+{
2668+//
2669+// constructors/destructor methods
2670+//
2671+public:
2672+ /**
2673+ * Default class constructor
2674+ * .
2675+ * param none
2676+ * @return none
2677+ **/
2678+ XMLBase()
2679+ {
2680+ m_bHasError = false;
2681+ m_bHasWarning = false;
2682+ }
2683+
2684+ /**
2685+ * Default class destructor
2686+ * .
2687+ * param none
2688+ * @return none
2689+ **/
2690+ ~XMLBase()
2691+ {
2692+ }
2693+
2694+//
2695+// member variable get and set functions
2696+//
2697+public:
2698+ /**
2699+ * Tests if the object has an error set.
2700+ * .
2701+ * @param none
2702+ * @return true if we have an error, false otherwise
2703+ **/
2704+ bool hasError()
2705+ {
2706+ return m_bHasError;
2707+ }
2708+
2709+ /**
2710+ * Sets the error message that can be retrieved from this
2711+ * object instance
2712+ * .
2713+ * @param szError The error string
2714+ * @return none
2715+ **/
2716+ void setError(const char* szError = NULL)
2717+ {
2718+ if (szError) {
2719+ m_bHasError = true;
2720+ m_sError.assign(szError);
2721+ }
2722+ else
2723+ m_bHasError = false;
2724+ }
2725+
2726+ /**
2727+ * Returns the currently set error value
2728+ * .
2729+ * @param none
2730+ * @return pointer to the error string
2731+ **/
2732+ const char* getError()
2733+ {
2734+ m_bHasError = false;
2735+ return m_sError.c_str();
2736+ }
2737+
2738+ /**
2739+ * Tests if the object has a warning set.
2740+ * .
2741+ * @param none
2742+ * @return true if we have a warning, false otherwise
2743+ **/
2744+ bool hasWarning()
2745+ {
2746+ return m_bHasWarning;
2747+ }
2748+
2749+ /**
2750+ * Sets the warning message that can be retrieved from this
2751+ * object instance
2752+ * .
2753+ * @param szWarning The warning string
2754+ * @return none
2755+ **/
2756+ void setWarning(const char* szWarning = NULL)
2757+ {
2758+ if (szWarning) {
2759+ m_bHasWarning = true;
2760+ m_sWarning.assign(szWarning);
2761+ }
2762+ else
2763+ m_bHasWarning = false;
2764+ }
2765+
2766+ /**
2767+ * Returns the currently set warning value
2768+ * .
2769+ * @param none
2770+ * @return pointer to the warning string
2771+ **/
2772+ const char* getWarning()
2773+ {
2774+ m_bHasWarning = false;
2775+ return m_sWarning.c_str();
2776+ }
2777+
2778+//
2779+// protected internal variables
2780+//
2781+protected:
2782+ bool m_bHasError;
2783+ string m_sError;
2784+ bool m_bHasWarning;
2785+ string m_sWarning;
2786+};
2787+
2788+#endif
2789Index: xmlspec/XMLChangelog.cpp
2790===================================================================
2791RCS file: xmlspec/XMLChangelog.cpp
2792diff -N xmlspec/XMLChangelog.cpp
2793--- /dev/null 1 Jan 1970 00:00:00 -0000
2794+++ rpm/xmlspec/XMLChangelog.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
2795@@ -0,0 +1,237 @@
2796+// standard C++ includes
2797+#include <string>
2798+
2799+// our includes
2800+#include "XMLChangelog.h"
2801+#include "XMLMisc.h"
2802+#include "XMLRPMWrap.h"
2803+#include "XMLSpec.h"
2804+
2805+using namespace std;
2806+
2807+bool XMLChangelogEntry::parseCreate(XMLAttrs* pAttrs,
2808+ const char* szChange,
2809+ XMLSpec* pSpec)
2810+{
2811+ if (!pSpec)
2812+ return false;
2813+ XMLChangelogEntry change(szChange);
2814+ pSpec->getChangelog().lastDate().addEntry(change);
2815+ return true;
2816+}
2817+
2818+bool XMLChangelogEntry::structCreate(const char* szEntries,
2819+ XMLSpec* pXSpec)
2820+{
2821+ if (!pXSpec || !szEntries)
2822+ return false;
2823+ char* szIn = (char*)szEntries;
2824+ char* szOut = NULL;
2825+ int nLen = -1;
2826+ string sChange;
2827+ while (nLen != 0) {
2828+ szOut = splitStr(szIn, '\n', nLen);
2829+ if (strncmp(szIn, "- ", 2) == 0) {
2830+ szIn += 2;
2831+ nLen -= 2;
2832+ if (sChange.length()) {
2833+ XMLChangelogEntry change(sChange.c_str());
2834+ pXSpec->getChangelog().lastDate().addEntry(change);
2835+ }
2836+ sChange.assign("");
2837+ }
2838+ sChange.append(szIn, nLen);
2839+ szIn = szOut;
2840+ }
2841+ if (sChange.length()) {
2842+ XMLChangelogEntry change(sChange.c_str());
2843+ pXSpec->getChangelog().lastDate().addEntry(change);
2844+ }
2845+ return true;
2846+}
2847+
2848+XMLChangelogEntry::XMLChangelogEntry(const char* szChange)
2849+ : XMLBase()
2850+{
2851+ m_sChange.assign(szChange);
2852+}
2853+
2854+XMLChangelogEntry::XMLChangelogEntry(const XMLChangelogEntry& rEntry)
2855+ : XMLBase()
2856+{
2857+ m_sChange.assign(rEntry.m_sChange);
2858+}
2859+
2860+XMLChangelogEntry::~XMLChangelogEntry()
2861+{
2862+}
2863+
2864+void XMLChangelogEntry::toSpecFile(ostream& rOut)
2865+{
2866+ rOut << endl << "- " << getChange();
2867+}
2868+
2869+void XMLChangelogEntry::toXMLFile(ostream& rOut)
2870+{
2871+ rOut << endl << "\t\t\t<change>" << getChange() << "</change>";
2872+}
2873+
2874+// attribute structure for XMLChangelogDate
2875+structValidAttrs g_paChangelogDateAttrs[] =
2876+{
2877+ {0x0000, true, false, "date", XATTRTYPE_DATE, {NULL}},
2878+ {0x0001, true, false, "author", XATTRTYPE_STRING, {"*", NULL}},
2879+ {0x0002, false, false, "author-email", XATTRTYPE_MAIL, {NULL}},
2880+ {0x0003, false, false, "version", XATTRTYPE_STRING, {"*", NULL}},
2881+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
2882+};
2883+
2884+bool XMLChangelogDate::parseCreate(XMLAttrs* pAttrs,
2885+ XMLSpec* pSpec)
2886+{
2887+ // validate our attributes
2888+ if (!pAttrs->validate(g_paChangelogDateAttrs, (XMLBase*)pSpec))
2889+ return false;
2890+
2891+ XMLChangelogDate date(pAttrs->asString("date"),
2892+ pAttrs->asString("author"),
2893+ pAttrs->asString("author-email"),
2894+ pAttrs->asString("version"));
2895+ pSpec->getChangelog().addDate(date);
2896+ return true;
2897+}
2898+
2899+bool XMLChangelogDate::structCreate(const char* szDate,
2900+ const char* szName,
2901+ const char* szEntries,
2902+ XMLSpec* pXSpec)
2903+{
2904+ if (!szDate || !szName || !szEntries || ! pXSpec)
2905+ return false;
2906+ time_t tTime = (time_t)(atol(szDate)) - timezone;
2907+ struct tm *sTime = gmtime(&tTime);
2908+ sTime->tm_year += 1900;
2909+ char szTmp[32];
2910+ sprintf(szTmp,"%s %s %d %d", g_szaDays[sTime->tm_wday],
2911+ g_szaMonths[sTime->tm_mon],
2912+ sTime->tm_mday, sTime->tm_year);
2913+ XMLChangelogDate date(szTmp, szName, NULL, NULL);
2914+ pXSpec->getChangelog().addDate(date);
2915+ XMLChangelogEntry::structCreate(szEntries, pXSpec);
2916+ return true;
2917+}
2918+
2919+XMLChangelogDate::XMLChangelogDate(const char* szDate,
2920+ const char* szAuthor,
2921+ const char* szEmail,
2922+ const char* szVersion)
2923+ : XMLBase()
2924+{
2925+ if (szDate)
2926+ m_sDate.assign(szDate);
2927+ if (szAuthor)
2928+ m_sAuthor.assign(szAuthor);
2929+ if (szEmail)
2930+ m_sEmail.assign(szEmail);
2931+ if (szVersion)
2932+ m_sVersion.assign(szVersion);
2933+}
2934+
2935+XMLChangelogDate::XMLChangelogDate(const XMLChangelogDate& rDate)
2936+ : XMLBase()
2937+{
2938+ m_sDate.assign(rDate.m_sDate);
2939+ m_sAuthor.assign(rDate.m_sAuthor);
2940+ m_sEmail.assign(rDate.m_sEmail);
2941+ m_sVersion.assign(rDate.m_sVersion);
2942+ m_vEntries = rDate.m_vEntries;
2943+}
2944+
2945+XMLChangelogDate::~XMLChangelogDate()
2946+{
2947+}
2948+
2949+void XMLChangelogDate::toSpecFile(ostream& rOut)
2950+{
2951+ rOut << endl << "* " << getDate() << " " << getAuthor();
2952+ if (hasEmail())
2953+ rOut << " <" << getEmail() << ">";
2954+ if (hasVersion())
2955+ rOut << " " << getVersion();
2956+ for (unsigned int i = 0; i < numEntries(); i++)
2957+ getEntry(i).toSpecFile(rOut);
2958+ rOut << endl;
2959+}
2960+
2961+void XMLChangelogDate::toXMLFile(ostream& rOut)
2962+{
2963+ rOut << endl << "\t\t<changes date=\"" << getDate() << "\"";
2964+ rOut << endl << "\t\t author=\"" << getAuthor() << "\"";
2965+ if (hasEmail())
2966+ rOut << endl << "\t\t author-email=\"" << getEmail() << "\"";
2967+ if (hasVersion())
2968+ rOut << endl << "\t\t version=\"" << getVersion() << "\"";
2969+ rOut << ">";
2970+ for (unsigned int i = 0; i < numEntries(); i++)
2971+ getEntry(i).toXMLFile(rOut);
2972+ rOut << endl << "\t\t</changes>";
2973+}
2974+
2975+bool XMLChangelog::structCreate(Spec pSpec,
2976+ XMLSpec* pXSpec)
2977+{
2978+ if (!pXSpec || !pSpec || !pSpec->packages || !pSpec->packages->header)
2979+ return false;
2980+ // FIXME: it looks like RPM only stores the tomost date in the
2981+ // spec file so we are only allowed to get that one instead of an
2982+ // array of time_t's
2983+ string sDates;
2984+ t_StrVector svChanges;
2985+ t_StrVector svNames;
2986+ getRPMHeader(pSpec->packages->header, RPMTAG_CHANGELOGTIME, sDates);
2987+ getRPMHeaderArray(pSpec->packages->header, RPMTAG_CHANGELOGNAME, svNames);
2988+ getRPMHeaderArray(pSpec->packages->header, RPMTAG_CHANGELOGTEXT, svChanges);
2989+ for (unsigned int i = 0; i < svNames.size(); i++)
2990+ XMLChangelogDate::structCreate(sDates.c_str(), svNames[i].c_str(),
2991+ svChanges[i].c_str(), pXSpec);
2992+ return true;
2993+}
2994+
2995+XMLChangelog::XMLChangelog()
2996+ : XMLBase()
2997+{
2998+}
2999+
3000+XMLChangelog::XMLChangelog(const XMLChangelog& rChangelog)
3001+ : XMLBase()
3002+{
3003+ m_vDates = rChangelog.m_vDates;
3004+}
3005+
3006+XMLChangelog::~XMLChangelog()
3007+{
3008+}
3009+
3010+void XMLChangelog::toSpecFile(ostream& rOut)
3011+{
3012+ if (numDates()) {
3013+ rOut << endl << "%changelog";
3014+ for (unsigned int i = 0; i < numDates(); i++)
3015+ getDate(i).toSpecFile(rOut);
3016+ rOut << endl;
3017+ }
3018+}
3019+
3020+void XMLChangelog::toXMLFile(ostream& rOut)
3021+{
3022+ if (numDates()) {
3023+ rOut << endl << "\t<changelog>";
3024+ for (unsigned int i = 0; i < numDates(); i++)
3025+ getDate(i).toXMLFile(rOut);
3026+ rOut << endl << "\t</changelog>";
3027+ }
3028+}
3029+
3030+void XMLChangelog::toRPMStruct(Spec spec)
3031+{
3032+}
3033Index: xmlspec/XMLChangelog.h
3034===================================================================
3035RCS file: xmlspec/XMLChangelog.h
3036diff -N xmlspec/XMLChangelog.h
3037--- /dev/null 1 Jan 1970 00:00:00 -0000
3038+++ rpm/xmlspec/XMLChangelog.h 28 Aug 2002 10:52:43 -0000 1.3.2.1
3039@@ -0,0 +1,458 @@
3040+#ifndef _H_XMLCHANGELOG_
3041+#define _H_XMLCHANGELOG_
3042+
3043+// standard C++ includes
3044+#include <iostream>
3045+#include <string>
3046+#include <vector>
3047+
3048+// standard includes
3049+#include <stdio.h>
3050+
3051+// our includes
3052+#include "XMLAttrs.h"
3053+#include "XMLBase.h"
3054+
3055+// rpm includes
3056+#include <rpmbuild.h>
3057+
3058+// forward class definitions
3059+class XMLSpec;
3060+class XMLChangelog;
3061+
3062+using namespace std;
3063+
3064+class XMLChangelogEntry : public XMLBase
3065+{
3066+//
3067+// factory functions
3068+//
3069+public:
3070+ /**
3071+ * Adds a changelog entry
3072+ * .
3073+ * @param pAttrs The XML attributes
3074+ * @param szEntry The entry to create
3075+ * @param pSpec Pointer to our spec
3076+ * @return true on success, false othersise
3077+ */
3078+ static bool parseCreate(XMLAttrs* pAttrs,
3079+ const char* szEntry,
3080+ XMLSpec* pSpec);
3081+
3082+
3083+ /**
3084+ * Creates changelog entries from the data provided to us by RPM
3085+ * @param szEntries The netries we are to evaluate
3086+ * @param pXSpec pointer to the XML spec we are working with
3087+ * @return true on success,. false otherwise
3088+ **/
3089+ static bool structCreate(const char* szEntries,
3090+ XMLSpec* pXSpec);
3091+
3092+//
3093+// constructors/destructor
3094+//
3095+public:
3096+ /**
3097+ * Default contructor
3098+ * .
3099+ * @param szChange The change entry
3100+ * @return none
3101+ **/
3102+ XMLChangelogEntry(const char* szChange);
3103+
3104+ /**
3105+ * Copy constructor
3106+ * .
3107+ * @param rEntry Reference to the entry to copy
3108+ * @return none
3109+ **/
3110+ XMLChangelogEntry(const XMLChangelogEntry& rEntry);
3111+
3112+ /**
3113+ * Destructor
3114+ * .
3115+ * @param none
3116+ * @return none
3117+ **/
3118+ ~XMLChangelogEntry();
3119+
3120+//
3121+// member functions
3122+//
3123+public:
3124+ /**
3125+ * Outputs the object into a spec file
3126+ * .
3127+ * @param rOut Reference to our output stream
3128+ * @return none
3129+ **/
3130+ void toSpecFile(ostream& rOut);
3131+
3132+ /**
3133+ * Outputs the object into an XML spec file
3134+ * .
3135+ * @param rOut Reference to our output stream
3136+ * @return none
3137+ **/
3138+ void toXMLFile(ostream& rOut);
3139+
3140+//
3141+// member variable get/set functions
3142+//
3143+public:
3144+ /**
3145+ * Returns the enrty
3146+ * .
3147+ * @param none
3148+ * @return string containing the entry
3149+ **/
3150+ const char* getChange()
3151+ {
3152+ return m_sChange.c_str();
3153+ }
3154+
3155+//
3156+// member variables
3157+//
3158+public:
3159+ string m_sChange;
3160+};
3161+
3162+class XMLChangelogDate : public XMLBase
3163+{
3164+//
3165+// factory functions
3166+//
3167+public:
3168+ /**
3169+ * Creates a XMLChangelogDate object
3170+ * .
3171+ * @param pAttrs The XML attributes
3172+ * @param pSpec The spec to add this object to
3173+ * @return true on success, false otherwise
3174+ **/
3175+ static bool parseCreate(XMLAttrs* pAttrs,
3176+ XMLSpec* pSpec);
3177+
3178+ /**
3179+ * Creates an XMLChangelogDate object from the information provided to
3180+ * us by RPM
3181+ * .
3182+ * @param szDate The date to generate this for
3183+ * @param szEntries The entries to add to this date
3184+ * @param pXSpec The XML spec we are working with
3185+ * @return true on success, false otherwise
3186+ **/
3187+ static bool structCreate(const char* szDate,
3188+ const char* szName,
3189+ const char* szEntries,
3190+ XMLSpec* pXSpec);
3191+
3192+//
3193+// constructors/destructor
3194+//
3195+public:
3196+ /**
3197+ * Default contructor
3198+ * .
3199+ * @param szDate The date
3200+ * @param szAuthor The author
3201+ * @param szEmail The author's email
3202+ * @param szVersion The version in which this change was made
3203+ * @return none
3204+ **/
3205+ XMLChangelogDate(const char* szDate,
3206+ const char* szAuthor,
3207+ const char* szEmail,
3208+ const char* szVersion);
3209+
3210+ /**
3211+ * Copy contructor
3212+ * .
3213+ * @param rDate Reference to the date object to copy
3214+ * @return none
3215+ **/
3216+ XMLChangelogDate(const XMLChangelogDate& rDate);
3217+
3218+ /**
3219+ * Destructor
3220+ * .
3221+ * @param none
3222+ * @return none
3223+ **/
3224+ ~XMLChangelogDate();
3225+
3226+//
3227+// public member functions
3228+//
3229+public:
3230+ /**
3231+ * Outputs the object into a spec file
3232+ * .
3233+ * @param rOut Reference to our output stream
3234+ * @return none
3235+ **/
3236+ void toSpecFile(ostream& rOut);
3237+
3238+ /**
3239+ * Outputs the object into an XML spec file
3240+ * .
3241+ * @param rOut Reference to our output stream
3242+ * @return none
3243+ **/
3244+ void toXMLFile(ostream& rOut);
3245+
3246+//
3247+// member variables get/set functions
3248+//
3249+public:
3250+ /**
3251+ * Returns the date for the group of entries
3252+ * .
3253+ * @param none
3254+ * @return string representation of the date
3255+ **/
3256+ const char* getDate()
3257+ {
3258+ return m_sDate.c_str();
3259+ }
3260+
3261+ /**
3262+ * Checks for an author
3263+ * .
3264+ * @param none
3265+ * @return true if we have an author, false otherwise
3266+ **/
3267+ bool hasAuthor()
3268+ {
3269+ return m_sAuthor.length() ? true : false;
3270+ }
3271+
3272+ /**
3273+ * Returns the author's name
3274+ * .
3275+ * @param none
3276+ * @return string containing the author's name
3277+ **/
3278+ const char* getAuthor()
3279+ {
3280+ return m_sAuthor.c_str();
3281+ }
3282+
3283+ /**
3284+ * Checks if we have an email address for the author
3285+ * .
3286+ * @param none
3287+ * @return true if we hava an email, false otherwise
3288+ **/
3289+ bool hasEmail()
3290+ {
3291+ return m_sEmail.length() ? true : false;
3292+ }
3293+
3294+ /**
3295+ * Returns the author's email addresse
3296+ * .
3297+ * @param none
3298+ * @return a string containing the author's email address
3299+ **/
3300+ const char* getEmail()
3301+ {
3302+ return m_sEmail.c_str();
3303+ }
3304+
3305+ /**
3306+ * Checks if we have a change version
3307+ * .
3308+ * @param none
3309+ * @return true if we have a version, false otherwise
3310+ **/
3311+ bool hasVersion()
3312+ {
3313+ return m_sVersion.length() ? true : false;
3314+ }
3315+
3316+ /**
3317+ * Gets the change version
3318+ * .
3319+ * @param none
3320+ * @return string containing the version
3321+ **/
3322+ const char* getVersion()
3323+ {
3324+ return m_sVersion.c_str();
3325+ }
3326+
3327+ /**
3328+ * Returns the number of entries for this date
3329+ * .
3330+ * @param none
3331+ * @return the number of entries
3332+ **/
3333+ unsigned int numEntries()
3334+ {
3335+ return m_vEntries.size();
3336+ }
3337+
3338+ /**
3339+ * Returns a specific entry
3340+ * .
3341+ * @param nNum The number of the entry to return
3342+ * @return the enrty
3343+ **/
3344+ XMLChangelogEntry& getEntry(unsigned int nNum)
3345+ {
3346+ return m_vEntries[nNum];
3347+ }
3348+
3349+ /**
3350+ * Adds an entry for this date
3351+ * .
3352+ * @param szEntry The entry to add
3353+ * @return none
3354+ **/
3355+ void addEntry(XMLChangelogEntry& rEntry)
3356+ {
3357+ m_vEntries.push_back(rEntry);
3358+ }
3359+
3360+//
3361+// member variables
3362+//
3363+protected:
3364+ string m_sDate;
3365+ string m_sAuthor;
3366+ string m_sEmail;
3367+ string m_sVersion;
3368+ vector<XMLChangelogEntry> m_vEntries;
3369+};
3370+
3371+class XMLChangelog : public XMLBase
3372+{
3373+//
3374+// static factory functions
3375+//
3376+public:
3377+ /**
3378+ * Creates changelog objects from an RPM Spec structure
3379+ * .
3380+ * @param pSpec Pointer to the RPM spec
3381+ * @param pXSpec pointer to the XMLSpec object to populate
3382+ * @return true on success, false otherwise
3383+ **/
3384+ static bool structCreate(Spec pSpec,
3385+ XMLSpec* pXSpec);
3386+
3387+//
3388+// constructors/destructor
3389+//
3390+public:
3391+ /**
3392+ * Default constructor
3393+ * .
3394+ * @param none
3395+ * @return none
3396+ **/
3397+ XMLChangelog();
3398+
3399+ /**
3400+ * Copy constructor
3401+ * .
3402+ * @param rChangelog The object to copy
3403+ * @return none
3404+ **/
3405+ XMLChangelog(const XMLChangelog& rChangelog);
3406+
3407+ /**
3408+ * Destructor
3409+ * .
3410+ * @param none
3411+ * @return none
3412+ **/
3413+ ~XMLChangelog();
3414+
3415+//
3416+// public member functions
3417+//
3418+public:
3419+ /**
3420+ * Converts the object into a spec file
3421+ * .
3422+ * @param rOut Reference to the output stream
3423+ * @return none
3424+ **/
3425+ void toSpecFile(ostream& rOut);
3426+
3427+ /**
3428+ * Converts the object into an xML spec
3429+ * .
3430+ * @param rOut Reference to the output stream
3431+ * @return none
3432+ **/
3433+ void toXMLFile(ostream& rOut);
3434+
3435+ /**
3436+ * Converts the object into an RPM structure
3437+ * .
3438+ * @param spec RPM structure
3439+ * @return none
3440+ **/
3441+ void toRPMStruct(Spec spec);
3442+//
3443+// variable get/set functions
3444+//
3445+public:
3446+ /**
3447+ * Adds a date to the changelog
3448+ * .
3449+ * @param rDate The date to add
3450+ * @return none
3451+ **/
3452+ void addDate(XMLChangelogDate& rDate)
3453+ {
3454+ m_vDates.push_back(rDate);
3455+ }
3456+
3457+ /**
3458+ * Returns the number of dates in the changelog
3459+ * .
3460+ * @param none
3461+ * @return the number of dates
3462+ **/
3463+ unsigned int numDates()
3464+ {
3465+ return m_vDates.size();
3466+ }
3467+
3468+ /**
3469+ * Gets a specific date
3470+ * .
3471+ * @param nNum The entry number
3472+ * @return The requated date
3473+ **/
3474+ XMLChangelogDate& getDate(unsigned int nNum)
3475+ {
3476+ return m_vDates[nNum];
3477+ }
3478+
3479+ /**
3480+ * Gets the last date we have added
3481+ * .
3482+ * @param none
3483+ * @return the last date
3484+ **/
3485+ XMLChangelogDate& lastDate()
3486+ {
3487+ return m_vDates[numDates()-1];
3488+ }
3489+
3490+//
3491+// member variables
3492+//
3493+protected:
3494+ vector<XMLChangelogDate> m_vDates;
3495+};
3496+
3497+#endif
3498Index: xmlspec/XMLFiles.cpp
3499===================================================================
3500RCS file: xmlspec/XMLFiles.cpp
3501diff -N xmlspec/XMLFiles.cpp
3502--- /dev/null 1 Jan 1970 00:00:00 -0000
3503+++ rpm/xmlspec/XMLFiles.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
3504@@ -0,0 +1,200 @@
3505+// standard includes
3506+#include <stdio.h>
3507+
3508+// our includes
3509+#include "XMLAttrs.h"
3510+#include "XMLFiles.h"
3511+#include "XMLPackage.h"
3512+#include "XMLSpec.h"
3513+
3514+// rpm includes
3515+#include <rpmlib.h>
3516+#include <stringbuf.h>
3517+
3518+using namespace std;
3519+
3520+// attribute structure for XMLFile
3521+structValidAttrs g_paFileAttrs[] =
3522+{
3523+ {0x0000, false, false, "mode", XATTRTYPE_INTEGER, {NULL}},
3524+ {0x0001, false, false, "group", XATTRTYPE_STRING, {"*", NULL}},
3525+ {0x0002, false, false, "user", XATTRTYPE_STRING, {"*", NULL}},
3526+ {0x0003, false, false, "config", XATTRTYPE_STRING, {"noreplace",
3527+ "*", NULL}},
3528+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
3529+};
3530+
3531+bool XMLFile::parseCreate(XMLAttrs* pAttrs,
3532+ const char* szPath,
3533+ XMLSpec* pSpec)
3534+{
3535+ // validate the attributes
3536+ if (!pSpec || !pAttrs->validate(g_paFileAttrs, (XMLBase*)pSpec))
3537+ return false;
3538+
3539+ // create and return
3540+ XMLFile file(pAttrs->asString("mode"), pAttrs->asString("user"),
3541+ pAttrs->asString("group"), pAttrs->asString("config"), szPath);
3542+ pSpec->lastPackage().getFiles().addFile(file);
3543+ return true;
3544+}
3545+
3546+XMLFile::XMLFile(const char* szMode,
3547+ const char* szOwner,
3548+ const char* szGroup,
3549+ const char* szConfig,
3550+ const char* szPath)
3551+ : XMLBase()
3552+{
3553+ if (szMode)
3554+ m_sMode.assign(szMode);
3555+ if (szOwner)
3556+ m_sOwner.assign(szOwner);
3557+ if (szGroup)
3558+ m_sGroup.assign(szGroup);
3559+ if (szConfig)
3560+ m_sConfig.assign(szConfig);
3561+ if (szPath)
3562+ m_sPath.assign(szPath);
3563+}
3564+
3565+XMLFile::XMLFile(const XMLFile& rFile)
3566+ : XMLBase()
3567+{
3568+ setMode(rFile.m_sMode.c_str());
3569+ setOwner(rFile.m_sOwner.c_str());
3570+ setGroup(rFile.m_sGroup.c_str());
3571+ setConfig(rFile.m_sConfig.c_str());
3572+ setPath(rFile.m_sPath.c_str());
3573+}
3574+
3575+XMLFile::~XMLFile()
3576+{
3577+}
3578+
3579+XMLFile XMLFile::operator=(XMLFile file)
3580+{
3581+ setMode(file.m_sMode.c_str());
3582+ setOwner(file.m_sOwner.c_str());
3583+ setGroup(file.m_sGroup.c_str());
3584+ setConfig(file.m_sConfig.c_str());
3585+ setPath(file.m_sPath.c_str());
3586+}
3587+
3588+void XMLFile::toSpecFile(ostream& rOut)
3589+{
3590+ if (hasMode() || hasOwner() || hasGroup()) {
3591+ rOut << "%attr(";
3592+ rOut << (hasMode() ? getMode() : "-");
3593+ rOut << "," << (hasOwner() ? getOwner() : "-");
3594+ rOut << "," << (hasGroup() ? getGroup() : "-");
3595+ rOut << ") ";
3596+ }
3597+ if (hasConfig()) {
3598+ rOut << "%config(" << getConfig() << ") ";
3599+ }
3600+ rOut << getPath() << endl;
3601+}
3602+
3603+void XMLFile::toXMLFile(ostream& rOut)
3604+{
3605+ rOut << endl << "\t\t\t<file";
3606+ if (hasMode())
3607+ rOut << " mode=\"" << getMode() << "\"";
3608+ if (hasOwner())
3609+ rOut << " user=\"" << getOwner() << "\"";
3610+ if (hasGroup())
3611+ rOut << " group=\"" << getGroup() << "\"";
3612+ if (hasConfig())
3613+ rOut << " config=\"" << getConfig() << "\"";
3614+ rOut << ">";
3615+ rOut << getPath() << "</file>";
3616+}
3617+
3618+// attribute structure for XMLFiles
3619+structValidAttrs g_paFilesAttrs[] =
3620+{
3621+ {0x0000, false, false, "mode", XATTRTYPE_INTEGER, {NULL}},
3622+ {0x0001, false, false, "group", XATTRTYPE_STRING, {"*", NULL}},
3623+ {0x0002, false, false, "user", XATTRTYPE_STRING, {"*", NULL}},
3624+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
3625+};
3626+
3627+bool XMLFiles::parseCreate(XMLAttrs* pAttrs,
3628+ XMLSpec* pSpec)
3629+{
3630+ if (!pSpec || !pAttrs->validate(g_paFilesAttrs, (XMLBase*)pSpec))
3631+ return false;
3632+ pSpec->lastPackage().getFiles().setDefMode(pAttrs->asString("mode"));
3633+ pSpec->lastPackage().getFiles().setDefOwner(pAttrs->asString("user"));
3634+ pSpec->lastPackage().getFiles().setDefGroup(pAttrs->asString("group"));
3635+ return true;
3636+}
3637+
3638+bool XMLFiles::structCreate(PackageStruct* pPackage,
3639+ Spec pSpec,
3640+ XMLSpec* pXSpec)
3641+{
3642+ if (!pXSpec || !pSpec || !pPackage || !pPackage->fileList)
3643+ return false;
3644+ return true;
3645+}
3646+
3647+XMLFiles::XMLFiles()
3648+ : XMLBase()
3649+{
3650+}
3651+
3652+XMLFiles::XMLFiles(const XMLFiles& rFiles)
3653+ : XMLBase()
3654+{
3655+ setDefMode(rFiles.m_sMode.c_str());
3656+ setDefOwner(rFiles.m_sOwner.c_str());
3657+ setDefGroup(rFiles.m_sGroup.c_str());
3658+ m_vFiles = rFiles.m_vFiles;
3659+}
3660+
3661+XMLFiles::~XMLFiles()
3662+{
3663+}
3664+
3665+XMLFiles XMLFiles::operator=(XMLFiles files)
3666+{
3667+ setDefMode(files.m_sMode.c_str());
3668+ setDefOwner(files.m_sOwner.c_str());
3669+ setDefGroup(files.m_sGroup.c_str());
3670+ m_vFiles = files.m_vFiles;
3671+ return *this;
3672+}
3673+
3674+void XMLFiles::toSpecFile(ostream& rOut)
3675+{
3676+ if (numFiles()) {
3677+ if (hasDefMode() || hasDefOwner() || hasDefGroup()) {
3678+ rOut << "%defattr(";
3679+ rOut << (hasDefMode() ? getDefMode() : "-");
3680+ rOut << "," << (hasDefOwner() ? getDefOwner() : "-");
3681+ rOut << "," << (hasDefGroup() ? getDefGroup() : "-");
3682+ rOut << ")" << endl;
3683+ }
3684+ for (unsigned int i = 0; i < numFiles(); i++)
3685+ getFile(i).toSpecFile(rOut);
3686+ }
3687+}
3688+
3689+void XMLFiles::toXMLFile(ostream& rOut)
3690+{
3691+ if (numFiles()) {
3692+ rOut << endl << "\t\t<files";
3693+ if (hasDefMode())
3694+ rOut << " mode=\"" << getDefMode() << "\"";
3695+ if (hasDefOwner())
3696+ rOut << " user=\"" << getDefOwner() << "\"";
3697+ if (hasDefGroup())
3698+ rOut << " group=\"" << getDefGroup() << "\"";
3699+ rOut << ">";
3700+ for (unsigned int i = 0; i < numFiles(); i++)
3701+ getFile(i).toXMLFile(rOut);
3702+ rOut << endl << "\t\t</files>";
3703+ }
3704+}
3705Index: xmlspec/XMLFiles.h
3706===================================================================
3707RCS file: xmlspec/XMLFiles.h
3708diff -N xmlspec/XMLFiles.h
3709--- /dev/null 1 Jan 1970 00:00:00 -0000
3710+++ rpm/xmlspec/XMLFiles.h 28 Aug 2002 10:52:43 -0000 1.3.2.1
3711@@ -0,0 +1,526 @@
3712+#ifndef _H_XMLFILES_
3713+#define _H_XMLFILES_
3714+
3715+// standard C++ includes
3716+#include <iostream>
3717+#include <string>
3718+#include <vector>
3719+
3720+// standard includes
3721+#include <stdio.h>
3722+
3723+// our includes
3724+#include "XMLAttrs.h"
3725+#include "XMLBase.h"
3726+
3727+// rpm includes
3728+#include <rpmbuild.h>
3729+
3730+// forward class definitions
3731+class XMLPackage;
3732+class XMLFiles;
3733+class XMLSpec;
3734+
3735+using namespace std;
3736+
3737+// <file ...>
3738+class XMLFile : public XMLBase
3739+{
3740+//
3741+// object creation static functions
3742+//
3743+public:
3744+ /**
3745+ * Creates a file object and add it to the correct XMLFiles
3746+ * container.
3747+ * .
3748+ * @param pAttrs The attributes in the XML tag
3749+ * @param szPath The file path
3750+ * @param pSpec The spec to which these files belong
3751+ * @return true on success, false otherwise
3752+ **/
3753+ static bool parseCreate(XMLAttrs* pAttrs,
3754+ const char* szPath,
3755+ XMLSpec* pSpec);
3756+
3757+//
3758+// constructors/destructor
3759+//
3760+public:
3761+ /**
3762+ * Default contructor
3763+ * .
3764+ * @param szMode The file's mode (NULL if default)
3765+ * @param szOwner The file's owner (NULL if default)
3766+ * @param szGroup The file's group (NULL if default)
3767+ * @param szConfig The configuration parameter
3768+ * @param szPath The file path
3769+ * @return none
3770+ **/
3771+ XMLFile(const char* szMode,
3772+ const char* szUser,
3773+ const char* szGroup,
3774+ const char* szConfig,
3775+ const char* szPath);
3776+
3777+ /**
3778+ * Copy constructire
3779+ * .
3780+ * @param rFile Reference to the object to copy
3781+ * @return none
3782+ **/
3783+ XMLFile(const XMLFile& rFile);
3784+
3785+ /**
3786+ * Default destructor
3787+ * .
3788+ * @param none
3789+ * @return none
3790+ **/
3791+ ~XMLFile();
3792+
3793+//
3794+// operators
3795+//
3796+public:
3797+ /**
3798+ * Assignment operator
3799+ * .
3800+ * @param file The file that we wish to copy
3801+ * @return a copy of the original
3802+ **/
3803+ XMLFile operator=(XMLFile file);
3804+
3805+//
3806+// member functions
3807+//
3808+public:
3809+ /**
3810+ * Outputs the obkect to an RPM spec file
3811+ * .
3812+ * @param rOut Reference to the output stream
3813+ * @return none
3814+ **/
3815+ void toSpecFile(ostream& rOut);
3816+
3817+ /**
3818+ * Outputs the object to an XML spec file
3819+ * .
3820+ * @param rOut Reference to the output stream
3821+ * @return none
3822+ **/
3823+ void toXMLFile(ostream& rOut);
3824+
3825+//
3826+// member variable get/set functions
3827+//
3828+public:
3829+ /**
3830+ * Returns the file path
3831+ * .
3832+ * @param none
3833+ * @return string containing the path
3834+ **/
3835+ const char* getPath()
3836+ {
3837+ return m_sPath.c_str();
3838+ }
3839+
3840+ /**
3841+ * Sets the file path
3842+ * .
3843+ * @param szPath The path to set
3844+ * @return none
3845+ **/
3846+ void setPath(const char* szPath)
3847+ {
3848+ if (szPath)
3849+ m_sPath.assign(szPath);
3850+ }
3851+
3852+ /**
3853+ * Checks for a file mode
3854+ * .
3855+ * @param none
3856+ * @return true if we have one, false otherwise
3857+ **/
3858+ bool hasMode()
3859+ {
3860+ return m_sMode.length() ? true : false;
3861+ }
3862+
3863+ /**
3864+ * Returns the file mode
3865+ * .
3866+ * @param none
3867+ * @return the mode string
3868+ **/
3869+ const char* getMode()
3870+ {
3871+ return m_sMode.c_str();
3872+ }
3873+
3874+ /**
3875+ * Sets the file mode
3876+ * .
3877+ * @param szMode The mode to set
3878+ * @return none
3879+ **/
3880+ void setMode(const char* szMode)
3881+ {
3882+ if (szMode)
3883+ m_sMode.assign(szMode);
3884+ }
3885+
3886+ /**
3887+ * Checks if we have a file owner
3888+ * .
3889+ * @param none
3890+ * @return true if we have an owner, false otherwise
3891+ **/
3892+ bool hasOwner()
3893+ {
3894+ return m_sOwner.length() ? true : false;
3895+ }
3896+
3897+ /**
3898+ * Returns the file owner
3899+ * .
3900+ * @param none
3901+ * @return the owner as a string
3902+ **/
3903+ const char* getOwner()
3904+ {
3905+ return m_sOwner.c_str();
3906+ }
3907+
3908+ /**
3909+ * Sets the file owner
3910+ * .
3911+ * @param szOwner The file owner
3912+ * @return none
3913+ **/
3914+ void setOwner(const char* szOwner)
3915+ {
3916+ if (szOwner)
3917+ m_sOwner.assign(szOwner);
3918+ }
3919+
3920+ /**
3921+ * Checks for a file group
3922+ * .
3923+ * @param none
3924+ * @return true if we have a group, false otherwise
3925+ **/
3926+ bool hasGroup()
3927+ {
3928+ return m_sGroup.length() ? true : false;
3929+ }
3930+
3931+ /**
3932+ * Returns the file group
3933+ * .
3934+ * @param none
3935+ * @return string containing the group
3936+ **/
3937+ const char* getGroup()
3938+ {
3939+ return m_sGroup.c_str();
3940+ }
3941+
3942+ /**
3943+ * Sets the file group
3944+ * .
3945+ * @param szGroup The group to set
3946+ * @return none
3947+ **/
3948+ void setGroup(const char* szGroup)
3949+ {
3950+ if (szGroup)
3951+ m_sGroup.assign(szGroup);
3952+ }
3953+
3954+ /**
3955+ * Checks for config directives
3956+ * .
3957+ * @param none
3958+ * @return true if we have one, false otherwise
3959+ **/
3960+ bool hasConfig()
3961+ {
3962+ return m_sConfig.length() ? true : false;
3963+ }
3964+
3965+ /**
3966+ * Returns the config attribute
3967+ * .
3968+ * @param none
3969+ * @return the sttribute string
3970+ **/
3971+ const char* getConfig()
3972+ {
3973+ return m_sConfig.c_str();
3974+ }
3975+
3976+ /**
3977+ * Sets the config attribute
3978+ * .
3979+ * @param szConfig The configuration
3980+ * @return none
3981+ **/
3982+ void setConfig(const char* szConfig)
3983+ {
3984+ if (szConfig)
3985+ m_sConfig.assign(szConfig);
3986+ }
3987+
3988+//
3989+// member variables
3990+//
3991+protected:
3992+ string m_sPath;
3993+ string m_sMode;
3994+ string m_sOwner;
3995+ string m_sGroup;
3996+ string m_sConfig;
3997+};
3998+
3999+// <files ...>
4000+class XMLFiles : public XMLBase
4001+{
4002+//
4003+// object creation static functions
4004+//
4005+public:
4006+ /**
4007+ * Creates an object as parsed from an XML spec
4008+ * .
4009+ * @param pAttrs XML atrtributes to use
4010+ * @param pSpec The spec to which we are adding this object to
4011+ * @return true on success, false otherwise
4012+ **/
4013+ static bool parseCreate(XMLAttrs* pAttrs,
4014+ XMLSpec* pSpec);
4015+
4016+ /**
4017+ * Creates file objects from an RPM Spec structure
4018+ * .
4019+ * @param pPackage Pointer to the package
4020+ * @param pSpec Pointer to the RPM spec
4021+ * @param pXSpec pointer to the XMLSpec object to populate
4022+ * @return true on success, false otherwise
4023+ **/
4024+ static bool structCreate(PackageStruct* pPackage,
4025+ Spec pSpec,
4026+ XMLSpec* pXSpec);
4027+
4028+//
4029+// constructors/destructor
4030+//
4031+public:
4032+ /**
4033+ * Default constructor
4034+ * .
4035+ * @param none
4036+ * @return none
4037+ **/
4038+ XMLFiles();
4039+
4040+ /**
4041+ * Copy constructor
4042+ * .
4043+ * @param rFiles Reference to the object to copy
4044+ * @return none
4045+ **/
4046+ XMLFiles(const XMLFiles& rFiles);
4047+
4048+ /**
4049+ * Destructor
4050+ * .
4051+ * @param none
4052+ * @return none
4053+ **/
4054+ ~XMLFiles();
4055+
4056+//
4057+// member functions
4058+//
4059+public:
4060+ /**
4061+ * Converts the object into an RPM spec
4062+ * .
4063+ * @param rOut Output stream
4064+ * @return none
4065+ **/
4066+ void toSpecFile(ostream& rOut);
4067+
4068+ /**
4069+ * Converts the object into an XML spec
4070+ * .
4071+ * @param rOut Output stream
4072+ * @return none
4073+ **/
4074+ void toXMLFile(ostream& rOut);
4075+
4076+//
4077+// operators
4078+//
4079+public:
4080+ /**
4081+ * Assignment operator
4082+ * .
4083+ * @param files XMLFiles object to copy
4084+ * @return copied object
4085+ **/
4086+ XMLFiles operator=(XMLFiles files);
4087+
4088+//
4089+// member variable get/set functions
4090+//
4091+public:
4092+ /**
4093+ * Adds a file to our file list
4094+ * .
4095+ * @param rFile File to add
4096+ * @return none
4097+ **/
4098+ void addFile(XMLFile& rFile)
4099+ {
4100+ m_vFiles.push_back(rFile);
4101+ }
4102+
4103+ /**
4104+ * Returns the number of files in our list
4105+ * .
4106+ * @param none
4107+ * @return none
4108+ **/
4109+ unsigned int numFiles()
4110+ {
4111+ return m_vFiles.size();
4112+ }
4113+
4114+ /**
4115+ * Returns a specific file
4116+ * .
4117+ * @param nNum Number of the file to return
4118+ * @return the file object
4119+ **/
4120+ XMLFile& getFile(unsigned int nNum)
4121+ {
4122+ return m_vFiles[nNum];
4123+ }
4124+
4125+ /**
4126+ * Checks for a default mode
4127+ * .
4128+ * @param none
4129+ * @return true if we have a default mode, false otherwise
4130+ **/
4131+ bool hasDefMode()
4132+ {
4133+ return m_sMode.length() ? true : false;
4134+ }
4135+
4136+ /**
4137+ * Sets the default mode
4138+ * .
4139+ * @param szMode The mode value
4140+ * @return none
4141+ **/
4142+ void setDefMode(const char* szMode)
4143+ {
4144+ if (szMode)
4145+ m_sMode.assign(szMode);
4146+ }
4147+
4148+ /**
4149+ * Returns the default mode
4150+ * .
4151+ * @param none
4152+ * @return string containing the mode
4153+ **/
4154+ const char* getDefMode()
4155+ {
4156+ return m_sMode.c_str();
4157+ }
4158+
4159+ /**
4160+ * Check if we have a default owner
4161+ * .
4162+ * @param none
4163+ * @return true if we have an owner, false otherwise
4164+ **/
4165+ bool hasDefOwner()
4166+ {
4167+ return m_sOwner.length() ? true : false;
4168+ }
4169+
4170+ /**
4171+ * Sets the default owner
4172+ * .
4173+ * @param szOwner The owner
4174+ * @return none
4175+ **/
4176+ void setDefOwner(const char* szOwner)
4177+ {
4178+ if (szOwner)
4179+ m_sOwner.assign(szOwner);
4180+ }
4181+
4182+ /**
4183+ * Returns the default owner
4184+ * .
4185+ * @param none
4186+ * @return the owner string
4187+ **/
4188+ const char* getDefOwner()
4189+ {
4190+ return m_sOwner.c_str();
4191+ }
4192+
4193+ /**
4194+ * Checks if we have a default group
4195+ * .
4196+ * @param none
4197+ * @return true if we have an owner, false otherwise
4198+ **/
4199+ bool hasDefGroup()
4200+ {
4201+ return m_sGroup.length() ? true : false;
4202+ }
4203+
4204+ /**
4205+ * Sets the default group
4206+ * .
4207+ * @param szGroup The group to set
4208+ * @return none
4209+ **/
4210+ void setDefGroup(const char* szGroup)
4211+ {
4212+ if (szGroup)
4213+ m_sGroup.assign(szGroup);
4214+ }
4215+
4216+ /**
4217+ * Gets the default group
4218+ * .
4219+ * @param none
4220+ * @return string representation of the group
4221+ **/
4222+ const char* getDefGroup()
4223+ {
4224+ return m_sGroup.c_str();
4225+ }
4226+
4227+//
4228+// member variables
4229+//
4230+protected:
4231+ string m_sMode;
4232+ string m_sOwner;
4233+ string m_sGroup;
4234+ vector<XMLFile> m_vFiles;
4235+};
4236+
4237+#endif
4238Index: xmlspec/XMLMacro.cpp
4239===================================================================
4240RCS file: xmlspec/XMLMacro.cpp
4241diff -N xmlspec/XMLMacro.cpp
4242--- /dev/null 1 Jan 1970 00:00:00 -0000
4243+++ rpm/xmlspec/XMLMacro.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
4244@@ -0,0 +1,61 @@
4245+// our includes
4246+#include "XMLMacro.h"
4247+#include "XMLSpec.h"
4248+
4249+using namespace std;
4250+
4251+// attribute structure for XMLMacro
4252+structValidAttrs g_paMacroAttrs[] =
4253+{
4254+ {0x0000, true, false, "name", XATTRTYPE_STRING, {"*", NULL}},
4255+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
4256+};
4257+
4258+bool XMLMacro::parseCreate(XMLAttrs* pAttrs,
4259+ const char* szMacro,
4260+ XMLSpec* pSpec)
4261+{
4262+ if (!pSpec || !szMacro || !pAttrs->validate(g_paMacroAttrs, (XMLBase*)pAttrs))
4263+ return false;
4264+ XMLMacro macro(pAttrs->asString("name"), szMacro);
4265+ pSpec->addXMacro(macro);
4266+ return true;
4267+}
4268+
4269+XMLMacro::XMLMacro(const char* szName,
4270+ const char* szMacro)
4271+ : XMLBase()
4272+{
4273+ if (szName)
4274+ m_sName.assign(szName);
4275+ if (szMacro)
4276+ m_sValue.assign(szMacro);
4277+}
4278+
4279+XMLMacro::XMLMacro(const XMLMacro& rMacro)
4280+ : XMLBase()
4281+{
4282+ m_sName.assign(rMacro.m_sName);
4283+ m_sValue.assign(rMacro.m_sValue);
4284+}
4285+
4286+XMLMacro::~XMLMacro()
4287+{
4288+}
4289+
4290+XMLMacro XMLMacro::operator=(XMLMacro macro)
4291+{
4292+ m_sName.assign(macro.m_sName);
4293+ m_sValue.assign(macro.m_sValue);
4294+}
4295+
4296+void XMLMacro::toSpecFile(ostream& rOut)
4297+{
4298+ rOut << "%define " << getName() << " " << getValue() << endl;
4299+}
4300+
4301+void XMLMacro::toXMLFile(ostream& rOut)
4302+{
4303+ rOut << endl << "\t<macro name=\"" << getName() << "\">";
4304+ rOut << getValue() << "</macro>";
4305+}
4306Index: xmlspec/XMLMacro.h
4307===================================================================
4308RCS file: xmlspec/XMLMacro.h
4309diff -N xmlspec/XMLMacro.h
4310--- /dev/null 1 Jan 1970 00:00:00 -0000
4311+++ rpm/xmlspec/XMLMacro.h 28 Aug 2002 10:52:43 -0000 1.1.1.1.2.1
4312@@ -0,0 +1,131 @@
4313+#ifndef _H_XMLMACRO_
4314+#define _H_XMLMACRO_
4315+
4316+// standard C++ includes
4317+#include <iostream>
4318+#include <string>
4319+
4320+// our includes
4321+#include "XMLAttrs.h"
4322+
4323+// forward class definitions
4324+class XMLSpec;
4325+
4326+using namespace std;
4327+
4328+//<macro ...>
4329+class XMLMacro : public XMLBase
4330+{
4331+//
4332+// factory functions
4333+//
4334+public:
4335+ /**
4336+ * Creates an XMLMacro object
4337+ * .
4338+ * @param pAttrs XML tag attributes
4339+ * @param szMacro The macro contents
4340+ * @param pSpec the spec to add the macro to
4341+ * @return true on success, false otherwise
4342+ **/
4343+ static bool parseCreate(XMLAttrs* pAttrs,
4344+ const char* szMacro,
4345+ XMLSpec* pSpec);
4346+
4347+//
4348+// constructors/destructor
4349+//
4350+public:
4351+ /**
4352+ * Default constructor
4353+ * .
4354+ * @param szName The name of the macro
4355+ * @param szMacro The expanded macro
4356+ * @return none
4357+ **/
4358+ XMLMacro(const char* szName,
4359+ const char* szMacro);
4360+
4361+ /**
4362+ * Copy constructor
4363+ * .
4364+ * @param rMacro the macro to copy
4365+ * @return none
4366+ **/
4367+ XMLMacro(const XMLMacro& rMacro);
4368+
4369+ /**
4370+ * Destructor
4371+ * .
4372+ * @param none
4373+ * @return none
4374+ **/
4375+ ~XMLMacro();
4376+
4377+//
4378+// operators
4379+//
4380+public:
4381+ /**
4382+ * Assignment operator
4383+ * .
4384+ * @param macro The macro to copy
4385+ * @return our copied object
4386+ **/
4387+ XMLMacro operator=(XMLMacro macro);
4388+
4389+//
4390+// member functions
4391+//
4392+public:
4393+ /**
4394+ * Outputs the macro into an RPM spec
4395+ * .
4396+ * @param rOut Output stream
4397+ * @return none
4398+ **/
4399+ void toSpecFile(ostream& rOut);
4400+
4401+ /**
4402+ * Outputs the macro into an XML spec
4403+ * .
4404+ * @param rOut Output stream
4405+ * @return none
4406+ **/
4407+ void toXMLFile(ostream& rOut);
4408+
4409+//
4410+// member get/set functions
4411+//
4412+public:
4413+ /**
4414+ * Gets the macro name
4415+ * .
4416+ * @param none
4417+ * @return string containing the macro name
4418+ **/
4419+ const char* getName()
4420+ {
4421+ return m_sName.c_str();
4422+ }
4423+
4424+ /**
4425+ * Gets tha macro value
4426+ * .
4427+ * @param none
4428+ * @return string contatining the macro value
4429+ **/
4430+ const char* getValue()
4431+ {
4432+ return m_sValue.c_str();
4433+ }
4434+
4435+//
4436+// member variables
4437+//
4438+protected:
4439+ string m_sName;
4440+ string m_sValue;
4441+};
4442+
4443+#endif
4444Index: xmlspec/XMLMirror.cpp
4445===================================================================
4446RCS file: xmlspec/XMLMirror.cpp
4447diff -N xmlspec/XMLMirror.cpp
4448--- /dev/null 1 Jan 1970 00:00:00 -0000
4449+++ rpm/xmlspec/XMLMirror.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
4450@@ -0,0 +1,78 @@
4451+// our includes
4452+#include "XMLMirror.h"
4453+#include "XMLSpec.h"
4454+
4455+using namespace std;
4456+
4457+// attribute structure for XMLMirror
4458+structValidAttrs g_paMirrorAttrs[] =
4459+{
4460+ {0x0000, true, false, "path", XATTRTYPE_STRING, {"*", NULL}},
4461+ {0x0001, false, false, "description", XATTRTYPE_STRING, {"*", NULL}},
4462+ {0x0002, false, false, "country", XATTRTYPE_STRING, {"*", NULL}},
4463+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
4464+};
4465+
4466+bool XMLMirror::parseCreate(XMLAttrs* pAttrs,
4467+ XMLSpec* pSpec,
4468+ bool bPatch)
4469+{
4470+ // validate the attributes
4471+ if (!pAttrs->validate(g_paMirrorAttrs, (XMLBase*)pSpec))
4472+ return false;
4473+
4474+ XMLMirror mirror(pAttrs->asString("path"),
4475+ pAttrs->asString("description"),
4476+ pAttrs->asString("country"));
4477+ if (bPatch && pSpec->numPatches())
4478+ pSpec->lastPatch().addMirror(mirror);
4479+ else if (!bPatch && pSpec->numSources())
4480+ pSpec->lastSource().addMirror(mirror);
4481+ return true;
4482+}
4483+
4484+XMLMirror::XMLMirror(const char* szPath,
4485+ const char* szDescription,
4486+ const char* szCountry) : XMLBase()
4487+{
4488+ if (szPath)
4489+ m_sPath.assign(szPath);
4490+ if (szDescription)
4491+ m_sDescription.assign(szDescription);
4492+ if (szCountry)
4493+ m_sCountry.assign(szCountry);
4494+}
4495+
4496+XMLMirror::XMLMirror(const XMLMirror& rMirror)
4497+ : XMLBase()
4498+{
4499+ m_sPath.assign(rMirror.m_sPath);
4500+ m_sDescription.assign(rMirror.m_sDescription);
4501+ m_sCountry.assign(rMirror.m_sCountry);
4502+}
4503+
4504+XMLMirror::~XMLMirror()
4505+{
4506+}
4507+
4508+XMLMirror XMLMirror::operator=(XMLMirror mirror)
4509+{
4510+ m_sPath.assign(mirror.m_sPath);
4511+ m_sDescription.assign(mirror.m_sDescription);
4512+ m_sCountry.assign(mirror.m_sCountry);
4513+}
4514+
4515+void XMLMirror::toSpecFile(ostream& rOut)
4516+{
4517+ rOut << endl << "# mirror: " << getPath();
4518+}
4519+
4520+void XMLMirror::toXMLFile(ostream& rOut)
4521+{
4522+ rOut << endl << "\t\t<mirror path=\"" << getPath() << "\"";
4523+ if (hasDescription())
4524+ rOut << endl << "\t\t description=\"" << getDescription() << "\"";
4525+ if (hasCountry())
4526+ rOut << endl << "\t\t country=\"" << getCountry() << "\"";
4527+ rOut << " />";
4528+}
4529Index: xmlspec/XMLMirror.h
4530===================================================================
4531RCS file: xmlspec/XMLMirror.h
4532diff -N xmlspec/XMLMirror.h
4533--- /dev/null 1 Jan 1970 00:00:00 -0000
4534+++ rpm/xmlspec/XMLMirror.h 28 Aug 2002 10:52:43 -0000 1.1.1.1.2.1
4535@@ -0,0 +1,181 @@
4536+#ifndef _H_XMLMIRROR_
4537+#define _H_XMLMIRROR_
4538+
4539+// standard C++ includes
4540+#include <string>
4541+#include <vector>
4542+#include <iostream>
4543+
4544+// our includes
4545+#include "XMLAttrs.h"
4546+#include "XMLBase.h"
4547+
4548+// forward declaration
4549+class XMLSpec;
4550+
4551+using namespace std;
4552+
4553+// <mirror ...>
4554+class XMLMirror : public XMLBase
4555+{
4556+//
4557+// static object creation functions
4558+//
4559+public:
4560+ /**
4561+ * static function for creation of an XMLMirror object
4562+ * .
4563+ * @param pAttrs Pointer to our attribute structure
4564+ * @param pSpec Pointer to our spec that is to ultimately
4565+ * contain the object
4566+ * @param bPatch true if we are handling the mirror for a patch
4567+ * @return true on success, false otherwise
4568+ **/
4569+ static bool parseCreate(XMLAttrs* pAttrs,
4570+ XMLSpec* pSpec,
4571+ bool bPatch = false);
4572+
4573+//
4574+// constructors/destructor
4575+//
4576+public:
4577+ /**
4578+ * Default constructor for the XMLMirror object
4579+ * .
4580+ * @param szPath Full path for the mirror
4581+ * @param szDescription Full mirror description
4582+ * @param szCoutry Country code for the mirror
4583+ * @return none
4584+ **/
4585+ XMLMirror(const char* szPath,
4586+ const char* szDescription,
4587+ const char* szCountry);
4588+
4589+ /**
4590+ * Copy contructor
4591+ * .
4592+ * @param rMirror Reference to the object to copy
4593+ * @return none
4594+ **/
4595+ XMLMirror(const XMLMirror& rMirror);
4596+
4597+ /**
4598+ * Destructor for an XMLMirror object
4599+ * .
4600+ * @param none
4601+ * @return none
4602+ **/
4603+ ~XMLMirror();
4604+
4605+//
4606+// operators
4607+//
4608+public:
4609+ /**
4610+ * Assignment operator
4611+ * .
4612+ * @param mirror The mirror to get the values from
4613+ * @return The modified object
4614+ **/
4615+ XMLMirror operator=(XMLMirror mirror);
4616+
4617+//
4618+// public member functions
4619+//
4620+public:
4621+ /**
4622+ * Converts an XMLMirror object to a RPM spec file
4623+ * .
4624+ * @param rOut File stream
4625+ * @return none
4626+ **/
4627+ void toSpecFile(ostream& rOut);
4628+
4629+ /**
4630+ * Converts an XMLMirror object to an XML spec file
4631+ * .
4632+ * @param rOut File stream
4633+ * @return none
4634+ **/
4635+ void toXMLFile(ostream& rOut);
4636+
4637+//
4638+// member variable get/set functions
4639+//
4640+public:
4641+ /**
4642+ * Checks if we have a path
4643+ * .
4644+ * @param none
4645+ * @return true if we have a path, false otherise
4646+ **/
4647+ bool hasPath()
4648+ {
4649+ return m_sPath.length() ? true : false;
4650+ }
4651+
4652+ /**
4653+ * Returns the path
4654+ * .
4655+ * @param none
4656+ * @return The path strinbg
4657+ **/
4658+ const char* getPath()
4659+ {
4660+ return m_sPath.c_str();
4661+ }
4662+
4663+ /**
4664+ * Checks if we have a description set
4665+ * .
4666+ * @param none
4667+ * @return true is we have a description, false otherwise
4668+ **/
4669+ bool hasDescription()
4670+ {
4671+ return m_sDescription.length() ? true : false;
4672+ }
4673+
4674+ /**
4675+ * Returns the description
4676+ * .
4677+ * @param none
4678+ * @return the description string
4679+ **/
4680+ const char* getDescription()
4681+ {
4682+ return m_sDescription.c_str();
4683+ }
4684+
4685+ /**
4686+ * Checks if we have a country set
4687+ * .
4688+ * @param none
4689+ * @return true if we have a country, false otherwise
4690+ **/
4691+ bool hasCountry()
4692+ {
4693+ return m_sCountry.length() ? true : false;
4694+ }
4695+
4696+ /**
4697+ * Gets the country
4698+ * .
4699+ * @param none
4700+ * @return The country string
4701+ **/
4702+ const char* getCountry()
4703+ {
4704+ return m_sCountry.c_str();
4705+ }
4706+
4707+//
4708+// member variables
4709+//
4710+protected:
4711+ string m_sPath;
4712+ string m_sDescription;
4713+ string m_sCountry;
4714+};
4715+
4716+#endif
4717Index: xmlspec/XMLMisc.cpp
4718===================================================================
4719RCS file: xmlspec/XMLMisc.cpp
4720diff -N xmlspec/XMLMisc.cpp
4721--- /dev/null 1 Jan 1970 00:00:00 -0000
4722+++ rpm/xmlspec/XMLMisc.cpp 28 Aug 2002 10:52:43 -0000 1.1.2.1
4723@@ -0,0 +1,96 @@
4724+// standard c includes
4725+#include <stdio.h>
4726+#include <stdlib.h>
4727+#include <string.h>
4728+
4729+using namespace std;
4730+
4731+char* g_szaDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL };
4732+char* g_szaMonths[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
4733+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL };
4734+int g_naLengths[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
4735+char* g_szaBools[] = { "no", "yes", "false", "true", "0", "1", NULL };
4736+
4737+char* splitStr(const char* szInput,
4738+ char cTerm,
4739+ int& nLen)
4740+{
4741+ nLen = 0;
4742+ while (szInput[nLen] != cTerm && szInput[nLen] != '\0') {
4743+ nLen++;
4744+ }
4745+ char* szTemp = ((char*)szInput)+nLen;
4746+ while (*szTemp == cTerm && *szTemp != '\0')
4747+ szTemp++;
4748+ return szTemp;
4749+}
4750+
4751+int findStr(char* szaMatches[],
4752+ const char* szValue,
4753+ int nLen = -1)
4754+{
4755+ for (unsigned int i = 0; szaMatches[i] != NULL; i++) {
4756+ if (strcmp(szaMatches[i], "*") == 0)
4757+ return i;
4758+ else if (nLen == -1) {
4759+ if (strcasecmp(szaMatches[i], szValue) == 0)
4760+ return i;
4761+ }
4762+ else if (strncasecmp(szaMatches[i], szValue, nLen) == 0)
4763+ return i;
4764+ }
4765+ return -1;
4766+}
4767+
4768+bool isInteger(const char* szValue,
4769+ int nLen = -1)
4770+{
4771+ if (nLen == -1)
4772+ nLen = strlen(szValue);
4773+ for (unsigned int i = 0; i < strlen(szValue); i++) {
4774+ if (szValue[i] < '0' || szValue[i] > '9')
4775+ return false;
4776+ }
4777+ return true;
4778+}
4779+
4780+bool isBool(const char* szValue,
4781+ int nLen = -1)
4782+{
4783+ return findStr(g_szaBools, szValue, nLen) != -1 ? true : false;
4784+}
4785+
4786+bool isDate(const char* szValue)
4787+{
4788+ int nLen, nPos;
4789+ char* szTemp = splitStr(szValue, ' ', nLen);
4790+ if ((nPos = findStr(g_szaDays, szValue, nLen)) != -1) {
4791+ if ((nPos = findStr(g_szaMonths, szTemp, nLen)) != -1) {
4792+ szTemp = splitStr(szTemp, ' ', nLen);
4793+ char* szBuffer = new char[nLen+1];
4794+ sprintf(szBuffer, "%s", szTemp);
4795+ szBuffer[nLen] = '\0';
4796+ if (atoi(szBuffer) <= g_naLengths[nPos]) {
4797+ delete[] szBuffer;
4798+ szTemp = splitStr(szTemp, ' ', nLen);
4799+ return isInteger(szTemp, nLen);
4800+ }
4801+ delete[] szBuffer;
4802+ }
4803+ }
4804+ return false;
4805+}
4806+
4807+bool isEmail(const char* szValue)
4808+{
4809+ bool bFound = false;
4810+ for (unsigned int j = 0; j < strlen(szValue); j++) {
4811+ if (szValue[j] == '@') {
4812+ if (bFound)
4813+ return false;
4814+ else
4815+ bFound = true;
4816+ }
4817+ }
4818+ return bFound;
4819+}
4820Index: xmlspec/XMLMisc.h
4821===================================================================
4822RCS file: xmlspec/XMLMisc.h
4823diff -N xmlspec/XMLMisc.h
4824--- /dev/null 1 Jan 1970 00:00:00 -0000
4825+++ rpm/xmlspec/XMLMisc.h 28 Aug 2002 10:52:43 -0000 1.1.2.1
4826@@ -0,0 +1,66 @@
4827+#ifndef _H_XMLMISC_
4828+#define _H_XMLMISC_
4829+
4830+extern char* g_szaDays[];
4831+extern char* g_szaMonths[];
4832+
4833+/**
4834+ * Splits the input string according to the terminator, returning
4835+ * the length and the new search position
4836+ * .
4837+ * @param szInput The input string
4838+ * @param cTerm The terminating character
4839+ * @param nLen the length buffer
4840+ * @return The next string position
4841+ **/
4842+extern char* splitStr(const char* szInput,
4843+ char cTerm,
4844+ int& nLen);
4845+
4846+/**
4847+ * Finds a string in an array of potential matches
4848+ * .
4849+ * @param szaMatches The potential matches
4850+ * @param szValue The value to search for
4851+ * @return The position on success, -1 if not found
4852+ **/
4853+extern int findStr(char* szaMatches[],
4854+ const char* szValue,
4855+ int nLen = -1);
4856+
4857+/**
4858+ * Checks if a string contains an integer
4859+ * .
4860+ * @param szValue The string to check
4861+ * @param nLen The length to check, -1 to end of string
4862+ * @return true if the string is an integer, false otherwise
4863+ **/
4864+extern bool isInteger(const char* szValue,
4865+ int nLen = -1);
4866+
4867+/**
4868+ * Checks if a string contains a boolean value
4869+ * .
4870+ * @param szValue The value to check
4871+ * @return true if we have a boolean, false otherwise
4872+ **/
4873+extern bool isBool(const char* szValue,
4874+ int nLen = -1);
4875+
4876+/**
4877+ * Checks if a string is in a valid date format
4878+ * .
4879+ * @param szValue The string to check
4880+ * @return true is this is a date, false otherwise
4881+ **/
4882+extern bool isDate(const char* szValue);
4883+
4884+/**
4885+ * Checks if a string contains a valid e-mail address
4886+ * .
4887+ * @param szValue the string to check
4888+ * @return true if this is an email address, false otherwise
4889+ **/
4890+extern bool isEmail(const char* szValue);
4891+
4892+#endif
4893Index: xmlspec/XMLPackage.cpp
4894===================================================================
4895RCS file: xmlspec/XMLPackage.cpp
4896diff -N xmlspec/XMLPackage.cpp
4897--- /dev/null 1 Jan 1970 00:00:00 -0000
4898+++ rpm/xmlspec/XMLPackage.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
4899@@ -0,0 +1,327 @@
4900+// standard C++ includes
4901+#include <string>
4902+
4903+// our includes
4904+#include "XMLPackage.h"
4905+#include "XMLRPMWrap.h"
4906+#include "XMLSpec.h"
4907+
4908+// rpm includes
4909+#include <rpmlib.h>
4910+
4911+// attribute structure for XMLPackage
4912+structValidAttrs g_paPackageAttrs[] =
4913+{
4914+ {0x0000, false, false, "name", XATTRTYPE_STRING, {"*", NULL}},
4915+ {0x0001, true, false, "group", XATTRTYPE_STRING, {"*", NULL}},
4916+ {0x0002, false, false, "autoreq", XATTRTYPE_BOOL, {NULL}},
4917+ {0x0003, false, false, "autoprov", XATTRTYPE_BOOL, {NULL}},
4918+ {0x0004, false, false, "autoreqprov", XATTRTYPE_BOOL, {NULL}},
4919+ {0x0005, false, false, "sub", XATTRTYPE_BOOL, {NULL}},
4920+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
4921+};
4922+
4923+bool XMLPackage::parseCreate(XMLAttrs* pAttrs,
4924+ XMLSpec* pSpec)
4925+{
4926+ // validate the attributes
4927+ if (!pAttrs->validate(g_paPackageAttrs, (XMLBase*)pSpec))
4928+ return false;
4929+
4930+ // setup the name attribute
4931+ string sName;
4932+ if (pAttrs->asString("name"))
4933+ sName.assign(pAttrs->asString("name"));
4934+
4935+ // if we have a name, cool, now test if the package already exists
4936+ if (sName.length()) {
4937+ XMLPackage package(sName.c_str(), pAttrs->asString("group"),
4938+ pAttrs->asBool("autoreq") || pAttrs->asBool("autoreqprov"),
4939+ pAttrs->asBool("autoprov") || pAttrs->asBool("autoreqprov"),
4940+ pAttrs->asBool("sub"));
4941+ pSpec->addPackage(package);
4942+ }
4943+
4944+ // already something existing with %{name} ?
4945+ else {
4946+ XMLPackage package(NULL, pAttrs->asString("group"),
4947+ pAttrs->asBool("autoreq") || pAttrs->asBool("autoreqprov"),
4948+ pAttrs->asBool("autoprov") || pAttrs->asBool("autoreqprov"),
4949+ pAttrs->asBool("sub"));
4950+ pSpec->addPackage(package);
4951+ }
4952+ return true;
4953+}
4954+
4955+bool XMLPackage::structCreate(PackageStruct* pPackage,
4956+ Spec pSpec,
4957+ XMLSpec* pXSpec)
4958+{
4959+ if (!pXSpec || !pSpec || !pPackage || !pPackage->header)
4960+ return false;
4961+
4962+ string sGroup, sName;
4963+ if (!getRPMHeader(pPackage->header, RPMTAG_GROUP, sGroup))
4964+ return false;
4965+ getRPMHeader(pPackage->header, RPMTAG_NAME, sName);
4966+ bool bSub = false;
4967+ if (sName.compare(pXSpec->getName()) == 0) {
4968+ bSub = true;
4969+ }
4970+
4971+ XMLPackage package(bSub ? NULL : sName.c_str(), sGroup.c_str(),
4972+ pPackage->autoReq ? true : false,
4973+ pPackage->autoProv ? true : false,
4974+ bSub);
4975+ t_StrVector svText;
4976+ t_StrVector svLang;
4977+ getRPMHeaderArray(pPackage->header, RPMTAG_HEADERI18NTABLE, svLang);
4978+ if (getRPMHeaderArray(pPackage->header, RPMTAG_SUMMARY, svText)) {
4979+ for (unsigned int i = 0; i < svText.size(); i++)
4980+ package.addSummary(svText[i].c_str(), svLang[i].c_str());
4981+ }
4982+ if (getRPMHeaderArray(pPackage->header, RPMTAG_DESCRIPTION, svText)) {
4983+ for (unsigned int i = 0; i < svText.size(); i++)
4984+ package.addDescription(svText[i].c_str(), svLang[i].c_str());
4985+ }
4986+ pXSpec->addPackage(package);
4987+
4988+ XMLPackageContainer::structCreate(pPackage, pSpec, pXSpec);
4989+ XMLFiles::structCreate(pPackage, pSpec, pXSpec);
4990+
4991+ // do the next package and return
4992+ XMLPackage::structCreate(pPackage->next, pSpec, pXSpec);
4993+ return true;
4994+}
4995+
4996+// attribute structure for summaries
4997+structValidAttrs g_paDescriptionAttrs[] =
4998+{
4999+ {0x0000, false, false, "lang", XATTRTYPE_STRING, {"*", NULL}},
5000+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
5001+};
5002+
5003+bool XMLPackage::addDescription(XMLAttrs* pAttrs,
5004+ const char* szDescription,
5005+ XMLSpec* pSpec)
5006+{
5007+ if (pSpec && pAttrs->validate(g_paDescriptionAttrs, (XMLBase*)pSpec)) {
5008+ pSpec->lastPackage().addDescription(szDescription, pAttrs->asString("lang"));
5009+ return true;
5010+ }
5011+ else
5012+ return false;
5013+}
5014+
5015+// attribute structure for summaries
5016+structValidAttrs g_paSummaryAttrs[] =
5017+{
5018+ {0x0000, false, false, "lang", XATTRTYPE_STRING, {"*", NULL}},
5019+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
5020+};
5021+
5022+bool XMLPackage::addSummary(XMLAttrs* pAttrs,
5023+ const char* szSummary,
5024+ XMLSpec* pSpec)
5025+{
5026+ if (pSpec && pAttrs->validate(g_paSummaryAttrs, (XMLBase*)pSpec)) {
5027+ pSpec->lastPackage().addSummary(szSummary, pAttrs->asString("lang"));
5028+ return true;
5029+ }
5030+ else
5031+ return false;
5032+}
5033+
5034+XMLPackage::XMLPackage(const char* szName,
5035+ const char* szGroup,
5036+ bool bAutoReq,
5037+ bool bAutoProv,
5038+ bool bSub)
5039+ : XMLBase()
5040+{
5041+ setName(szName);
5042+ setGroup(szGroup);
5043+ setSubPackage(bSub);
5044+ setAutoRequires(bAutoReq);
5045+ setAutoProvides(bAutoProv);
5046+}
5047+
5048+XMLPackage::XMLPackage(const XMLPackage& rPackage)
5049+ : XMLBase()
5050+{
5051+ setName(rPackage.m_sName.c_str());
5052+ setGroup(rPackage.m_sGroup.c_str());
5053+ setSubPackage(rPackage.m_bSub);
5054+ setAutoRequires(rPackage.m_bAutoReq);
5055+ setAutoProvides(rPackage.m_bAutoProv);
5056+ m_vSummaries = rPackage.m_vSummaries;
5057+ m_vDescriptions = rPackage.m_vDescriptions;
5058+ m_Requires = rPackage.m_Requires;
5059+ m_BuildRequires = rPackage.m_BuildRequires;
5060+ m_Provides = rPackage.m_Provides;
5061+ m_Obsoletes = rPackage.m_Obsoletes;
5062+ m_Post = rPackage.m_Post;
5063+ m_PostUn = rPackage.m_PostUn;
5064+ m_Pre = rPackage.m_Pre;
5065+ m_PreUn = rPackage.m_PreUn;
5066+ m_Verify = rPackage.m_Verify;
5067+ m_Files = rPackage.m_Files;
5068+}
5069+
5070+XMLPackage::~XMLPackage()
5071+{
5072+}
5073+
5074+void XMLPackage::toSpecFile(ostream& rOut)
5075+{
5076+ // top package bit
5077+ if (hasName()) {
5078+ rOut << endl << "%package";
5079+ rOut << (!isSubPackage() ? " -n " : " ") << getName() << endl;
5080+ }
5081+ else
5082+ rOut << endl << endl;
5083+
5084+ for (unsigned int i = 0; i < numSummaries(); i++) {
5085+ rOut << "summary";
5086+ if (getSummary(i).hasLang())
5087+ rOut << "(" << getSummary(i).getLang() << "):";
5088+ else
5089+ rOut << ": ";
5090+ rOut << " " << getSummary(i).getText() << endl;
5091+ }
5092+ if (hasGroup())
5093+ rOut << "group: " << getGroup() << endl;
5094+ if (!hasAutoRequires() && !hasAutoProvides())
5095+ rOut << "autoreqprov: no" << endl;
5096+ else {
5097+ if (!hasAutoRequires())
5098+ rOut << "autoreq: no" << endl;
5099+ if (!hasAutoProvides())
5100+ rOut << "autoprov: no" << endl;
5101+ }
5102+
5103+ getProvides().toSpecFile(rOut, "provides");
5104+ getObsoletes().toSpecFile(rOut, "obsoletes");
5105+ getRequires().toSpecFile(rOut, "requires");
5106+ getBuildRequires().toSpecFile(rOut, "buildrequires");
5107+
5108+ // add the description
5109+ for (unsigned int i = 0; i < numDescriptions(); i++) {
5110+ rOut << "%description ";
5111+ if (getDescription(i).hasLang())
5112+ rOut << "-l " << getDescription(i).getLang() << " ";
5113+ if (hasName()) {
5114+ rOut << (!isSubPackage() ? "-n " : "");
5115+ rOut << getName();
5116+ }
5117+ rOut << endl << getDescription(i).getText() << endl;
5118+ }
5119+}
5120+
5121+void toSectionSpecFile(ostream& rOut,
5122+ const char* szSection,
5123+ XMLPackage* pPkg)
5124+{
5125+ rOut << endl << "%" << szSection;
5126+ if (pPkg->hasName())
5127+ rOut << (!pPkg->isSubPackage() ? " -n " : " ") << pPkg->getName();
5128+ rOut << endl;
5129+}
5130+
5131+void XMLPackage::toScriptsSpecFile(ostream& rOut)
5132+{
5133+ if (getPre().numScripts()) {
5134+ toSectionSpecFile(rOut, "pre", this);
5135+ getPre().toSpecFile(rOut, "pre");
5136+ }
5137+
5138+ if (getPost().numScripts()) {
5139+ toSectionSpecFile(rOut, "post", this);
5140+ getPost().toSpecFile(rOut, "post");
5141+ }
5142+
5143+ if (getPreUn().numScripts()) {
5144+ toSectionSpecFile(rOut, "preun", this);
5145+ getPreUn().toSpecFile(rOut, "preun");
5146+ }
5147+
5148+ if (getPostUn().numScripts()) {
5149+ toSectionSpecFile(rOut, "postun", this);
5150+ getPostUn().toSpecFile(rOut, "postun");
5151+ }
5152+
5153+ if (getVerify().numScripts()) {
5154+ toSectionSpecFile(rOut, "verifyscript", this);
5155+ getVerify().toSpecFile(rOut, "verifyscript");
5156+ }
5157+}
5158+
5159+void XMLPackage::toFilesSpecFile(ostream& rOut)
5160+{
5161+ rOut << endl << "%files";
5162+ if (hasName())
5163+ rOut << (!isSubPackage() ? " -n " : " ") << getName();
5164+ rOut << endl;
5165+ getFiles().toSpecFile(rOut);
5166+}
5167+
5168+void XMLPackage::toXMLFile(ostream& rOut)
5169+{
5170+ rOut << endl << "\t<package";
5171+ if (hasName()) {
5172+ rOut << " name=\"" << getName() << "\"";
5173+ if (!isSubPackage())
5174+ rOut << " sub=\"no\"";
5175+ }
5176+ if (hasGroup())
5177+ rOut << " group=\"" << getGroup() << "\"";
5178+ if (!hasAutoRequires() && !hasAutoProvides())
5179+ rOut << " autoreqprov=\"no\"";
5180+ else {
5181+ if (!hasAutoRequires())
5182+ rOut << " autoreq=\"no\"";
5183+ if (!hasAutoProvides())
5184+ rOut << " autoprov=\"no\"";
5185+ }
5186+ rOut << ">";
5187+
5188+ for (unsigned int i = 0; i < numSummaries(); i++) {
5189+ rOut << endl << "\t\t<summary";
5190+ if (getSummary(i).hasLang())
5191+ rOut << " lang=\"" << getSummary(i).getLang() << "\"";
5192+ rOut << ">" << getSummary(i).getText() << "</summary>";
5193+ }
5194+ for (unsigned int i = 0; i < numDescriptions(); i++) {
5195+ rOut << endl << "\t\t<description";
5196+ if (getDescription(i).hasLang())
5197+ rOut << " lang=\"" << getDescription(i).getLang() << "\"";
5198+ rOut << ">" << getDescription(i).getText() << "</description>";
5199+ }
5200+
5201+ getProvides().toXMLFile(rOut, "provides");
5202+ getObsoletes().toXMLFile(rOut, "obsoletes");
5203+ getRequires().toXMLFile(rOut, "requires");
5204+ getBuildRequires().toXMLFile(rOut, "buildrequires");
5205+
5206+ getPre().toXMLFile(rOut, "pre");
5207+ getPost().toXMLFile(rOut, "post");
5208+ getPreUn().toXMLFile(rOut, "preun");
5209+ getPostUn().toXMLFile(rOut, "postun");
5210+ getVerify().toXMLFile(rOut, "verify");
5211+
5212+ getFiles().toXMLFile(rOut);
5213+
5214+ rOut << endl << "\t</package>";
5215+}
5216+
5217+void XMLPackage::toRPMStruct(Spec spec)
5218+{
5219+ //Package pkg = newPackage(spec);
5220+ //if (!hasName() && pkg == spec->packages)
5221+ // fillOutMainPackage(pkg->header);
5222+ //else if (pkg != spec->packages)
5223+ // headerCopyTags(spec->packages->header,
5224+ // pkg->header,
5225+ // (int_32 *)copyTagsDuringParse);
5226+}
5227Index: xmlspec/XMLPackage.h
5228===================================================================
5229RCS file: xmlspec/XMLPackage.h
5230diff -N xmlspec/XMLPackage.h
5231--- /dev/null 1 Jan 1970 00:00:00 -0000
5232+++ rpm/xmlspec/XMLPackage.h 28 Aug 2002 10:52:43 -0000 1.3.2.1
5233@@ -0,0 +1,507 @@
5234+#ifndef _H_XMLPACKAGE_
5235+#define _H_XMLPACKAGE_
5236+
5237+// standard C++ includes
5238+#include <iostream>
5239+#include <string>
5240+#include <vector>
5241+
5242+// standard includes
5243+#include <stdio.h>
5244+
5245+// our includes
5246+#include "XMLAttrs.h"
5247+#include "XMLBase.h"
5248+#include "XMLFiles.h"
5249+#include "XMLRequires.h"
5250+#include "XMLScript.h"
5251+#include "XMLText.h"
5252+
5253+// rpm includes
5254+#include <rpmbuild.h>
5255+
5256+// forward class declarations
5257+class XMLSpec;
5258+
5259+using namespace std;
5260+
5261+class XMLPackage : public XMLBase
5262+{
5263+//
5264+// factory functions
5265+//
5266+public:
5267+ /**
5268+ * Creates an object as parsed from an XML spec
5269+ * .
5270+ * @param pAttrs XML atrtributes to use
5271+ * @param pSpec The spec to which we are adding this object to
5272+ * @return true on success, false otherwise
5273+ **/
5274+ static bool parseCreate(XMLAttrs* pAttrs,
5275+ XMLSpec* pSpec);
5276+
5277+ /**
5278+ * Creates package objects from an RPM Spec structure
5279+ * .
5280+ * @param pPackage Pointer to the start package
5281+ * @param pSpec pointer to the RPM spec
5282+ * @param pXSpec Pointer to the spec object to populate
5283+ * @return true on success, false otherwise
5284+ **/
5285+ static bool structCreate(PackageStruct* pPackage,
5286+ Spec pSpec,
5287+ XMLSpec* pXSpec);
5288+
5289+ /**
5290+ * Adds a description for the last package
5291+ * .
5292+ * @param pAttrs The attributes
5293+ * @param szDescription the description
5294+ * @param pSpec The spec containing the package
5295+ * @return true on success, false otherwise
5296+ **/
5297+ static bool addDescription(XMLAttrs* pAttrs,
5298+ const char* szDescription,
5299+ XMLSpec* pSpec);
5300+
5301+ /**
5302+ * Adds the summary for the last added package
5303+ * .
5304+ * @param pAttrs The attributes
5305+ * @param szSummary The summary to set
5306+ * @param pSpec The spec contraining the package
5307+ * @return trus on success, false otherwise
5308+ **/
5309+ static bool addSummary(XMLAttrs* pAttrs,
5310+ const char* szSummary,
5311+ XMLSpec* pSpec);
5312+
5313+//
5314+// constructors/destructors
5315+//
5316+public:
5317+ /**
5318+ * Default constructor
5319+ * .
5320+ * @param szName The package name
5321+ * @param szGroup The group this package belongs to
5322+ * @param bAutoReq Auto Requires
5323+ * @param bAutoProv Auto Provides
5324+ * @param bSub true if this is a sub-package
5325+ * @return none
5326+ **/
5327+ XMLPackage(const char* szName,
5328+ const char* szGroup,
5329+ bool bAutoReq,
5330+ bool bAutoProv,
5331+ bool bSub);
5332+
5333+ /**
5334+ * Copy constructor
5335+ * .
5336+ * @param rPackage The package to copy from
5337+ * @return none
5338+ **/
5339+ XMLPackage(const XMLPackage& rPackage);
5340+
5341+ /**
5342+ * Destructor
5343+ * .
5344+ * @param none
5345+ * @return none
5346+ **/
5347+ ~XMLPackage();
5348+
5349+//
5350+// public member functions
5351+//
5352+public:
5353+ /**
5354+ * Converts the object to a spec file
5355+ * .
5356+ * @param rOut Output stream
5357+ * @return none
5358+ **/
5359+ void toSpecFile(ostream& rOut);
5360+
5361+ /**
5362+ * Converts the scripts part of the object to a spec
5363+ * .
5364+ * @param rOut Output stream
5365+ * @return none
5366+ **/
5367+ void toScriptsSpecFile(ostream& rOut);
5368+
5369+ /**
5370+ * Converts the files part of the object to a spec
5371+ * .
5372+ * @param rOut Output stream
5373+ * @return none
5374+ **/
5375+ void toFilesSpecFile(ostream& rOut);
5376+
5377+ /**
5378+ * Converts the object to an XML spec
5379+ * .
5380+ * @param rOut The output stream
5381+ * @return none
5382+ **/
5383+ void toXMLFile(ostream& rOut);
5384+
5385+ /**
5386+ * Converts the object to an RPM structure
5387+ * .
5388+ * @param Spec The main Spec object
5389+ * @param none
5390+ **/
5391+ void toRPMStruct(Spec spec);
5392+
5393+//
5394+// member variable get/set functions
5395+//
5396+public:
5397+ /**
5398+ * Checks of we have a package name
5399+ * .
5400+ * @param none
5401+ * @return true if we have a name, false otherwise
5402+ **/
5403+ bool hasName()
5404+ {
5405+ return m_sName.length() ? true : false;
5406+ }
5407+
5408+ /**
5409+ * Gets the package name
5410+ * .
5411+ * @param none
5412+ * @return string containing the package name
5413+ **/
5414+ const char* getName()
5415+ {
5416+ return m_sName.c_str();
5417+ }
5418+
5419+ /**
5420+ * Sets the package name
5421+ * .
5422+ * @param szName The name to set
5423+ * @return none
5424+ **/
5425+ void setName(const char* szName)
5426+ {
5427+ if (szName)
5428+ m_sName.assign(szName);
5429+ }
5430+
5431+ /**
5432+ * Checks if we have a group
5433+ * .
5434+ * @param none
5435+ * @return true if we have a group, false otherwise
5436+ **/
5437+ bool hasGroup()
5438+ {
5439+ return m_sGroup.length() ? true : false;
5440+ }
5441+
5442+ /**
5443+ * Returns the group
5444+ * .
5445+ * @param none
5446+ * @return string containing the group
5447+ **/
5448+ const char* getGroup()
5449+ {
5450+ return m_sGroup.c_str();
5451+ }
5452+
5453+ /**
5454+ * Sets the group
5455+ * .
5456+ * @param szGroup The group to set
5457+ * @return none
5458+ **/
5459+ void setGroup(const char* szGroup)
5460+ {
5461+ if (szGroup)
5462+ m_sGroup.assign(szGroup);
5463+ }
5464+
5465+ /**
5466+ * Tests if we are a sub-package
5467+ * .
5468+ * @param none
5469+ * @return true if this is a sub-package
5470+ **/
5471+ bool isSubPackage()
5472+ {
5473+ return m_bSub;
5474+ }
5475+
5476+ /**
5477+ * Sets the sub-package status
5478+ * .
5479+ * @param bSub The sub-package status
5480+ * @return none
5481+ **/
5482+ void setSubPackage(bool bSub)
5483+ {
5484+ m_bSub = bSub;
5485+ }
5486+
5487+ /**
5488+ * Tests for auto requires
5489+ * .
5490+ * @param none
5491+ * @return true if we have auto requires, false otherwise
5492+ **/
5493+ bool hasAutoRequires()
5494+ {
5495+ return m_bAutoReq;
5496+ }
5497+
5498+ /**
5499+ * Sets the auto requires state
5500+ * .
5501+ * @param bAutoReq The auto requires state
5502+ * @return none
5503+ **/
5504+ void setAutoRequires(bool bAutoReq)
5505+ {
5506+ m_bAutoReq = bAutoReq;
5507+ }
5508+
5509+ /**
5510+ * Tests for auto requires
5511+ * .
5512+ * @param none
5513+ * @return true if we have auto requires, false otherwise
5514+ **/
5515+ bool hasAutoProvides()
5516+ {
5517+ return m_bAutoProv;
5518+ }
5519+
5520+ /**
5521+ * Sets the auto provides status
5522+ * .
5523+ * @param bAutoProv The auto provides status
5524+ * @return none
5525+ **/
5526+ void setAutoProvides(bool bAutoProv)
5527+ {
5528+ m_bAutoProv = bAutoProv;
5529+ }
5530+
5531+ /**
5532+ * Gets the number of summaries
5533+ * .
5534+ * @param none
5535+ * @return the number of summaries
5536+ **/
5537+ unsigned int numSummaries()
5538+ {
5539+ return m_vSummaries.size();
5540+ }
5541+
5542+ /**
5543+ * Gets a summary
5544+ * .
5545+ * @param nNum The number to get
5546+ * @return the summary
5547+ **/
5548+ XMLText& getSummary(unsigned int nNum)
5549+ {
5550+ return m_vSummaries[nNum];
5551+ }
5552+
5553+ /**
5554+ * Adds a summary
5555+ * .
5556+ * @param szSummary the summary
5557+ * @param szLang the language
5558+ * @return none
5559+ **/
5560+ void addSummary(const char* szSummary,
5561+ const char* szLang = NULL)
5562+ {
5563+ if (szSummary && strlen(szSummary)) {
5564+ XMLText summary(szSummary, szLang);
5565+ m_vSummaries.push_back(summary);
5566+ }
5567+ }
5568+
5569+ /**
5570+ * Gets the number of descriptions
5571+ * .
5572+ * @param none
5573+ * @return the number in our list
5574+ **/
5575+ unsigned int numDescriptions()
5576+ {
5577+ return m_vDescriptions.size();
5578+ }
5579+
5580+ /**
5581+ * Get a description
5582+ * .
5583+ * @param nNum The description to get
5584+ * @return Reference to XMLText object
5585+ **/
5586+ XMLText& getDescription(unsigned int nNum)
5587+ {
5588+ return m_vDescriptions[nNum];
5589+ }
5590+
5591+ /**
5592+ * Adds a description
5593+ * .
5594+ * @param szDescription The description string
5595+ * @param szLang The language
5596+ * @return nonew
5597+ **/
5598+ void addDescription(const char* szDescription,
5599+ const char* szLang = NULL)
5600+ {
5601+ if (szDescription && strlen(szDescription)) {
5602+ XMLText description(szDescription, szLang);
5603+ m_vDescriptions.push_back(description);
5604+ }
5605+ }
5606+
5607+ /**
5608+ * Gets the provides
5609+ * .
5610+ * @param none
5611+ * @return reference to the provides
5612+ **/
5613+ XMLPackageContainer& getProvides()
5614+ {
5615+ return m_Provides;
5616+ }
5617+
5618+ /**
5619+ * Gets the package requires
5620+ * .
5621+ * @param none
5622+ * @return reference to the requires
5623+ **/
5624+ XMLPackageContainer& getRequires()
5625+ {
5626+ return m_Requires;
5627+ }
5628+
5629+ /**
5630+ * Get the buildrequires
5631+ * .
5632+ * @param none
5633+ * @return reference to the buildrequires
5634+ **/
5635+ XMLPackageContainer& getBuildRequires()
5636+ {
5637+ return m_BuildRequires;
5638+ }
5639+
5640+ /**
5641+ * Gets the obsoletes
5642+ * .
5643+ * @param none
5644+ * @return reference to the obsoletes
5645+ **/
5646+ XMLPackageContainer& getObsoletes()
5647+ {
5648+ return m_Obsoletes;
5649+ }
5650+
5651+ /**
5652+ * Gets the files
5653+ * .
5654+ * @param none
5655+ * @return reference to the files
5656+ **/
5657+ XMLFiles& getFiles()
5658+ {
5659+ return m_Files;
5660+ }
5661+
5662+ /**
5663+ * Gets the pre section
5664+ * .
5665+ * @param none
5666+ * @return reference to the pre section
5667+ **/
5668+ XMLPackageScripts& getPre()
5669+ {
5670+ return m_Pre;
5671+ }
5672+
5673+ /**
5674+ * Gets the post section
5675+ * .
5676+ * @param none
5677+ * @return reference to the post section
5678+ **/
5679+ XMLPackageScripts& getPost()
5680+ {
5681+ return m_Post;
5682+ }
5683+
5684+ /**
5685+ * Gets the preun section
5686+ * .
5687+ * @param none
5688+ * @return reference to the preun section
5689+ **/
5690+ XMLPackageScripts& getPreUn()
5691+ {
5692+ return m_PreUn;
5693+ }
5694+
5695+ /**
5696+ * Gets the postun section
5697+ * .
5698+ * @param none
5699+ * @return reference to the postun section
5700+ **/
5701+ XMLPackageScripts& getPostUn()
5702+ {
5703+ return m_PostUn;
5704+ }
5705+
5706+ /**
5707+ * Gets the verify section
5708+ * .
5709+ * @param none
5710+ * @return reference to the verify section
5711+ **/
5712+ XMLPackageScripts& getVerify()
5713+ {
5714+ return m_Verify;
5715+ }
5716+
5717+//
5718+// member variables
5719+//
5720+protected:
5721+ string m_sName;
5722+ string m_sGroup;
5723+ bool m_bSub;
5724+ bool m_bAutoReq;
5725+ bool m_bAutoProv;
5726+ vector<XMLText> m_vSummaries;
5727+ vector<XMLText> m_vDescriptions;
5728+ XMLPackageContainer m_Requires;
5729+ XMLPackageContainer m_BuildRequires;
5730+ XMLPackageContainer m_Provides;
5731+ XMLPackageContainer m_Obsoletes;
5732+ XMLPackageScripts m_Pre;
5733+ XMLPackageScripts m_PreUn;
5734+ XMLPackageScripts m_Post;
5735+ XMLPackageScripts m_PostUn;
5736+ XMLPackageScripts m_Verify;
5737+ XMLFiles m_Files;
5738+};
5739+
5740+#endif
5741Index: xmlspec/XMLParser.cpp
5742===================================================================
5743RCS file: xmlspec/XMLParser.cpp
5744diff -N xmlspec/XMLParser.cpp
5745--- /dev/null 1 Jan 1970 00:00:00 -0000
5746+++ rpm/xmlspec/XMLParser.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
5747@@ -0,0 +1,982 @@
5748+// standard library includes
5749+#include <stdarg.h>
5750+#include <stdio.h>
5751+#include <stdlib.h>
5752+
5753+// standard C++ includes
5754+#include <fstream>
5755+#include <string>
5756+
5757+// 3rd party library includes
5758+#include <expat.h>
5759+
5760+// our includes
5761+#include "XMLSpec.h"
5762+
5763+// this is the maximum tree dept we will require as
5764+// well as the number of scructures a specific tag can
5765+// occur in
5766+#define XML_MAX_TREE_DEPTH 5
5767+#define XML_MAX_PRE_TAGS 10
5768+
5769+using namespace std;
5770+
5771+// these define the error values
5772+enum eXMLErr
5773+{
5774+ XMLERR_WARNING = 0x0000,
5775+ XMLERR_ERROR,
5776+ XMLERR_FATAL
5777+};
5778+
5779+// this defines the structure that we are using in the callback
5780+// containing all the parse-specific data we might need.
5781+struct structCBData
5782+{
5783+ XML_Parser* m_pParser;
5784+ string m_sFilename;
5785+ int m_nWarnings;
5786+ int m_nErrors;
5787+ int m_nDepth;
5788+ unsigned int m_pnTree[XML_MAX_TREE_DEPTH];
5789+ string m_sData;
5790+ XMLSpec* m_pSpec;
5791+ XMLAttrs* m_pAttrs;
5792+};
5793+
5794+// enumeration of all XML tags that are recognised
5795+enum enumXMLTAGValid
5796+{
5797+ XTAG_NO = 0x0000,
5798+ XTAG_WRONGSTRUCT,
5799+ XTAG_SPEC,
5800+ XTAG_EXCLUDEARCH,
5801+ XTAG_EXCLUDEOS,
5802+ XTAG_EXCLUSIVEARCH,
5803+ XTAG_EXCLUSIVEOS,
5804+ XTAG_SOURCE,
5805+ XTAG_PATCH,
5806+ XTAG_NOSOURCE,
5807+ XTAG_MIRROR,
5808+ XTAG_PACKAGE,
5809+ XTAG_SUMMARY,
5810+ XTAG_DESC,
5811+ XTAG_REQS,
5812+ XTAG_BREQS,
5813+ XTAG_PROVS,
5814+ XTAG_OBSOLS,
5815+ XTAG_FILES,
5816+ XTAG_FILE,
5817+ XTAG_MACRO,
5818+ XTAG_PREP,
5819+ XTAG_SETUP,
5820+ XTAG_BUILD,
5821+ XTAG_INSTALL,
5822+ XTAG_CLEAN,
5823+ XTAG_PRE,
5824+ XTAG_POST,
5825+ XTAG_PREUN,
5826+ XTAG_POSTUN,
5827+ XTAG_VERIFY,
5828+ XTAG_SCRIPT,
5829+ XTAG_CHANGELOG,
5830+ XTAG_CHANGES,
5831+ XTAG_CHANGE,
5832+ XTAG_ANY = 0xFFFF // this always needs to be the last entry
5833+};
5834+
5835+// this is a structure to match tags to their values
5836+struct structXMLMatch
5837+{
5838+ unsigned int m_nVal;
5839+ int m_pnDepth[XML_MAX_TREE_DEPTH+1];
5840+ unsigned int m_pnFollows[XML_MAX_PRE_TAGS+1];
5841+ char* m_szName;
5842+};
5843+
5844+// this allows for the matching of all tags
5845+structXMLMatch g_pMatches[] =
5846+{
5847+ {
5848+ XTAG_SPEC, { 0, -1, -1}, {
5849+ XTAG_ANY,
5850+ XTAG_NO
5851+ },
5852+ "spec"
5853+ },
5854+ {
5855+ XTAG_PACKAGE, { 1, 3, -1}, {
5856+ XTAG_SPEC,
5857+ XTAG_REQS,
5858+ XTAG_BREQS,
5859+ XTAG_PROVS,
5860+ XTAG_OBSOLS,
5861+ XTAG_NO
5862+ },
5863+ "package"
5864+ },
5865+ {
5866+ XTAG_SOURCE, { 1, -1, -1}, {
5867+ XTAG_SPEC,
5868+ XTAG_NO
5869+ },
5870+ "source"
5871+ },
5872+ {
5873+ XTAG_PATCH, { 1, 2, -1}, {
5874+ XTAG_SPEC,
5875+ XTAG_PREP,
5876+ XTAG_NO
5877+ },
5878+ "patch"
5879+ },
5880+ {
5881+ XTAG_NOSOURCE, { 1, -1, -1}, {
5882+ XTAG_SPEC,
5883+ XTAG_NO
5884+ },
5885+ "nosource"
5886+ },
5887+ {
5888+ XTAG_MIRROR, { 2, -1, -1}, {
5889+ XTAG_SOURCE,
5890+ XTAG_NO
5891+ },
5892+ "mirror"
5893+ },
5894+ {
5895+ XTAG_SUMMARY, { 2, -1, -1}, {
5896+ XTAG_PACKAGE,
5897+ XTAG_NO
5898+ },
5899+ "summary"
5900+ },
5901+ {
5902+ XTAG_DESC, { 2, -1, -1}, {
5903+ XTAG_PACKAGE,
5904+ XTAG_NO
5905+ },
5906+ "description"
5907+ },
5908+ {
5909+ XTAG_REQS, { 2, -1, -1}, {
5910+ XTAG_PACKAGE,
5911+ XTAG_NO
5912+ },
5913+ "requires"
5914+ },
5915+ {
5916+ XTAG_BREQS, { 2, -1, -1}, {
5917+ XTAG_PACKAGE,
5918+ XTAG_NO
5919+ },
5920+ "buildrequires"
5921+ },
5922+ {
5923+ XTAG_PROVS, { 2, -1, -1}, {
5924+ XTAG_PACKAGE,
5925+ XTAG_NO
5926+ },
5927+ "provides"
5928+ },
5929+ {
5930+ XTAG_OBSOLS, { 2, -1, -1}, {
5931+ XTAG_PACKAGE,
5932+ XTAG_NO
5933+ },
5934+ "obsoletes"
5935+ },
5936+ {
5937+ XTAG_FILES, { 2, -1, -1}, {
5938+ XTAG_PACKAGE,
5939+ XTAG_NO
5940+ },
5941+ "files"
5942+ },
5943+ {
5944+ XTAG_FILE, { 3, -1, -1}, {
5945+ XTAG_FILES,
5946+ XTAG_NO
5947+ },
5948+ "file"
5949+ },
5950+ {
5951+ XTAG_MACRO, { 1, -1, -1}, {
5952+ XTAG_SPEC,
5953+ XTAG_NO
5954+ },
5955+ "macro"
5956+ },
5957+ {
5958+ XTAG_PREP, { 1, -1, -1}, {
5959+ XTAG_SPEC,
5960+ XTAG_NO
5961+ },
5962+ "prep"
5963+ },
5964+ {
5965+ XTAG_SETUP, { 2, -1, -1}, {
5966+ XTAG_PREP,
5967+ XTAG_NO
5968+ },
5969+ "setup"
5970+ },
5971+ {
5972+ XTAG_BUILD, { 1, -1, -1}, {
5973+ XTAG_SPEC,
5974+ XTAG_NO
5975+ },
5976+ "build"
5977+ },
5978+ {
5979+ XTAG_INSTALL, { 1, -1, -1}, {
5980+ XTAG_SPEC,
5981+ XTAG_NO
5982+ },
5983+ "install"
5984+ },
5985+ {
5986+ XTAG_CLEAN, { 1, -1, -1}, {
5987+ XTAG_SPEC,
5988+ XTAG_NO
5989+ },
5990+ "clean"
5991+ },
5992+ {
5993+ XTAG_PRE, { 2, -1, -1}, {
5994+ XTAG_PACKAGE,
5995+ XTAG_NO
5996+ },
5997+ "pre"
5998+ },
5999+ {
6000+ XTAG_POST, { 2, -1, -1}, {
6001+ XTAG_PACKAGE,
6002+ XTAG_NO
6003+ },
6004+ "post"
6005+ },
6006+ {
6007+ XTAG_PREUN, { 2, -1, -1}, {
6008+ XTAG_PACKAGE,
6009+ XTAG_NO
6010+ },
6011+ "preun"
6012+ },
6013+ {
6014+ XTAG_POSTUN, { 2, -1, -1}, {
6015+ XTAG_PACKAGE,
6016+ XTAG_NO
6017+ },
6018+ "postun"
6019+ },
6020+ {
6021+ XTAG_VERIFY, { 2, -1, -1}, {
6022+ XTAG_PACKAGE,
6023+ XTAG_NO
6024+ },
6025+ "verify"
6026+ },
6027+ {
6028+ XTAG_SCRIPT, { 2, 3, -1}, {
6029+ XTAG_PREP,
6030+ XTAG_BUILD,
6031+ XTAG_INSTALL,
6032+ XTAG_CLEAN,
6033+ XTAG_PRE,
6034+ XTAG_POST,
6035+ XTAG_PREUN,
6036+ XTAG_POSTUN,
6037+ XTAG_VERIFY,
6038+ XTAG_NO
6039+ },
6040+ "script"
6041+ },
6042+ {
6043+ XTAG_CHANGELOG, { 1, -1, -1}, {
6044+ XTAG_SPEC,
6045+ XTAG_NO
6046+ },
6047+ "changelog"
6048+ },
6049+ {
6050+ XTAG_CHANGES, { 2, -1, -1}, {
6051+ XTAG_CHANGELOG,
6052+ XTAG_NO
6053+ },
6054+ "changes"
6055+ },
6056+ {
6057+ XTAG_CHANGE, { 3, -1, -1}, {
6058+ XTAG_CHANGES,
6059+ XTAG_NO
6060+ },
6061+ "change"
6062+ },
6063+ // this always needs to be the last entry
6064+ {
6065+ XTAG_NO, {-1, -1, -1}, {
6066+ XTAG_NO
6067+ },
6068+ "none"
6069+ }
6070+};
6071+
6072+const char* treeToString(unsigned int* pnTree,
6073+ int nDepth)
6074+{
6075+ // internal string storage
6076+ string sTree;
6077+
6078+ // build the tree to the specified depth
6079+ for (int i = 0; i < nDepth; i++) {
6080+ int j = 0;
6081+ while (g_pMatches[j].m_nVal != pnTree[i])
6082+ j++;
6083+ sTree += string("<") + string(g_pMatches[j].m_szName) + string(">");
6084+ }
6085+
6086+ // return the tree string
6087+ return sTree.c_str();
6088+}
6089+
6090+unsigned int getTagValue(const char* szElement,
6091+ int nDepth,
6092+ unsigned int nPrev)
6093+{
6094+ // first convert the tag to a tag value
6095+ unsigned int nTagVal = XTAG_NO;
6096+
6097+ // loop through all matches to see if we have a valid
6098+ // tag here
6099+ int i = 0;
6100+ do {
6101+ // test if we have a match
6102+ if (strcasecmp(g_pMatches[i].m_szName, szElement) == 0) {
6103+ // look for a match on the tree depth
6104+ int j = 0;
6105+ nTagVal = XTAG_WRONGSTRUCT;
6106+ while (g_pMatches[i].m_pnDepth[j] != -1) {
6107+ if (g_pMatches[i].m_pnDepth[j++] == nDepth) {
6108+ j = 0;
6109+ do {
6110+ if (g_pMatches[i].m_pnFollows[j] == nPrev) {
6111+ nTagVal = g_pMatches[i].m_nVal;
6112+ break;
6113+ }
6114+ } while (g_pMatches[i].m_pnFollows[++j] != XTAG_NO);
6115+ break;
6116+ }
6117+ }
6118+ // break out
6119+ break;
6120+ }
6121+ } while (g_pMatches[++i].m_nVal != XTAG_NO);
6122+
6123+ // return
6124+ return nTagVal;
6125+}
6126+
6127+void createError(int nErrType,
6128+ structCBData* pData,
6129+ const char* szFormat, ...)
6130+{
6131+ // one more error/warning
6132+ nErrType == XMLERR_WARNING ? pData->m_nWarnings++ : pData->m_nErrors++;
6133+
6134+ // setup internal variables
6135+ FILE* fOut = stderr;
6136+ switch (nErrType) {
6137+ case XMLERR_WARNING:
6138+ fOut = stdout;
6139+ fprintf(fOut, "%s(%d): warning: ", pData->m_sFilename.c_str(),
6140+ XML_GetCurrentLineNumber(*(pData->m_pParser)));
6141+ break;
6142+ case XMLERR_ERROR:
6143+ fprintf(fOut, "%s(%d): error: ", pData->m_sFilename.c_str(),
6144+ XML_GetCurrentLineNumber(*(pData->m_pParser)));
6145+ break;
6146+ case XMLERR_FATAL:
6147+ fprintf(fOut, "%s(%d): fatal: ", pData->m_sFilename.c_str(),
6148+ XML_GetCurrentLineNumber(*(pData->m_pParser)));
6149+ break;
6150+ default:
6151+ return;
6152+ }
6153+
6154+ // create the argument list and print
6155+ va_list vaArgList;
6156+ va_start(vaArgList, szFormat);
6157+ vfprintf(fOut, szFormat, vaArgList);
6158+ fprintf(fOut, "\n");
6159+}
6160+
6161+void startDepth0(structCBData* pData)
6162+{
6163+ // this indicates a spec start
6164+ if (pData->m_pnTree[0] == XTAG_SPEC) {
6165+ // if we have a spec already, we are in trouble
6166+ if (pData->m_pSpec)
6167+ createError(XMLERR_ERROR, pData, "Extra 'spec' tag found.");
6168+ else if (!(pData->m_pSpec = XMLSpec::parseCreate(pData->m_pAttrs,
6169+ pData->m_sFilename.c_str())))
6170+ createError(XMLERR_ERROR, pData,
6171+ "Failed to parse 'spec' tag (%s).",
6172+ pData->m_pAttrs->getError());
6173+ else if (pData->m_pAttrs->hasWarning())
6174+ createError(XMLERR_WARNING, pData, pData->m_pAttrs->getWarning());
6175+ }
6176+}
6177+
6178+void startDepth1(structCBData* pData)
6179+{
6180+ // make sure we have a spec
6181+ if (!pData->m_pSpec) {
6182+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6183+ return;
6184+ }
6185+
6186+ // hanlde tag
6187+ switch (pData->m_pnTree[1]) {
6188+ case XTAG_PACKAGE:
6189+ if (!XMLPackage::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6190+ createError(XMLERR_ERROR, pData,
6191+ "Failed to parse 'package' tag or package already exists (%s).",
6192+ pData->m_pSpec->getError());
6193+ else if (pData->m_pSpec->hasWarning())
6194+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6195+ break;
6196+ case XTAG_SOURCE:
6197+ if (!XMLSource::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6198+ createError(XMLERR_ERROR, pData,
6199+ "Failed to parse 'source' tag (%s).",
6200+ pData->m_pSpec->getError());
6201+ else if (pData->m_pSpec->hasWarning())
6202+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6203+ break;
6204+ case XTAG_PATCH:
6205+ if (!XMLPatch::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6206+ createError(XMLERR_ERROR, pData,
6207+ "Failed to parse 'patch' tag (%s).",
6208+ pData->m_pSpec->getError());
6209+ else if (pData->m_pSpec->hasWarning())
6210+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6211+ break;
6212+ case XTAG_NOSOURCE:
6213+ if (!XMLNoSource::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6214+ createError(XMLERR_ERROR, pData,
6215+ "Failed to parse 'nosource' tag (%s).",
6216+ pData->m_pSpec->getError());
6217+ else if (pData->m_pSpec->hasWarning())
6218+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6219+ break;
6220+ case XTAG_CHANGELOG:
6221+ case XTAG_PREP:
6222+ case XTAG_BUILD:
6223+ case XTAG_INSTALL:
6224+ case XTAG_CLEAN:
6225+ default:
6226+ break;
6227+ }
6228+}
6229+
6230+void startDepth2(structCBData* pData)
6231+{
6232+ // make sure we have a spec
6233+ if (!pData->m_pSpec) {
6234+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6235+ return;
6236+ }
6237+
6238+ // handle tag
6239+ switch (pData->m_pnTree[2]) {
6240+ case XTAG_MIRROR:
6241+ switch (pData->m_pnTree[1]) {
6242+ case XTAG_SOURCE:
6243+ if (!XMLMirror::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6244+ createError(XMLERR_ERROR, pData,
6245+ "Failed to parse 'mirror' tag (%s).",
6246+ pData->m_pSpec->getError());
6247+ else if (pData->m_pSpec->hasWarning())
6248+ createError(XMLERR_WARNING, pData,
6249+ pData->m_pSpec->getWarning());
6250+ break;
6251+ case XTAG_PATCH:
6252+ if (!XMLMirror::parseCreate(pData->m_pAttrs, pData->m_pSpec, true))
6253+ createError(XMLERR_ERROR, pData,
6254+ "Failed to parse 'mirror' tag (%s).",
6255+ pData->m_pSpec->getError());
6256+ else if (pData->m_pSpec->hasWarning())
6257+ createError(XMLERR_WARNING, pData,
6258+ pData->m_pSpec->getWarning());
6259+ break;
6260+ }
6261+ break;
6262+ case XTAG_FILES:
6263+ if (!XMLFiles::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6264+ createError(XMLERR_ERROR, pData,
6265+ "Failed to parse 'change' tag (%s).",
6266+ pData->m_pSpec->getError());
6267+ else if (pData->m_pSpec->hasWarning())
6268+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6269+ break;
6270+ case XTAG_CHANGES:
6271+ if (!XMLChangelogDate::parseCreate(pData->m_pAttrs, pData->m_pSpec))
6272+ createError(XMLERR_ERROR, pData,
6273+ "Failed to parse 'change' tag (%s).",
6274+ pData->m_pSpec->getError());
6275+ else if (pData->m_pSpec->hasWarning())
6276+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6277+ break;
6278+ case XTAG_PRE:
6279+ if (!XMLPackageScripts::createPreScripts(pData->m_pAttrs, pData->m_pSpec))
6280+ createError(XMLERR_ERROR, pData,
6281+ "Failed to parse 'pre' tag (%s).",
6282+ pData->m_pSpec->getError());
6283+ else if (pData->m_pSpec->hasWarning())
6284+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6285+ break;
6286+ case XTAG_POST:
6287+ if (!XMLPackageScripts::createPostScripts(pData->m_pAttrs, pData->m_pSpec))
6288+ createError(XMLERR_ERROR, pData,
6289+ "Failed to parse 'pre' tag (%s).",
6290+ pData->m_pSpec->getError());
6291+ else if (pData->m_pSpec->hasWarning())
6292+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6293+ break;
6294+ case XTAG_PREUN:
6295+ if (!XMLPackageScripts::createPreUnScripts(pData->m_pAttrs, pData->m_pSpec))
6296+ createError(XMLERR_ERROR, pData,
6297+ "Failed to parse 'pre' tag (%s).",
6298+ pData->m_pSpec->getError());
6299+ else if (pData->m_pSpec->hasWarning())
6300+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6301+ break;
6302+ case XTAG_POSTUN:
6303+ if (!XMLPackageScripts::createPostUnScripts(pData->m_pAttrs, pData->m_pSpec))
6304+ createError(XMLERR_ERROR, pData,
6305+ "Failed to parse 'pre' tag (%s).",
6306+ pData->m_pSpec->getError());
6307+ else if (pData->m_pSpec->hasWarning())
6308+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6309+ break;
6310+ case XTAG_VERIFY:
6311+ if (!XMLPackageScripts::createVerifyScripts(pData->m_pAttrs, pData->m_pSpec))
6312+ createError(XMLERR_ERROR, pData,
6313+ "Failed to parse 'pre' tag (%s).",
6314+ pData->m_pSpec->getError());
6315+ else if (pData->m_pSpec->hasWarning())
6316+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6317+ break;
6318+ case XTAG_REQS:
6319+ case XTAG_BREQS:
6320+ case XTAG_PROVS:
6321+ case XTAG_OBSOLS:
6322+ default:
6323+ break;
6324+ }
6325+}
6326+
6327+void startDepth3(structCBData* pData)
6328+{
6329+ // make sure we have a spec
6330+ if (!pData->m_pSpec) {
6331+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6332+ return;
6333+ }
6334+
6335+ // handle tag
6336+ switch (pData->m_pnTree[3]) {
6337+ case XTAG_PACKAGE:
6338+ switch (pData->m_pnTree[2]) {
6339+ case XTAG_REQS:
6340+ if (!XMLPackageContainer::addRequire(pData->m_pAttrs,
6341+ pData->m_pSpec))
6342+ createError(XMLERR_ERROR, pData,
6343+ "Failed to parse 'package' tag (%s).",
6344+ pData->m_pSpec->getError());
6345+ else if (pData->m_pSpec->hasWarning())
6346+ createError(XMLERR_WARNING, pData,
6347+ pData->m_pSpec->getWarning());
6348+ break;
6349+ case XTAG_BREQS:
6350+ if (!XMLPackageContainer::addBuildRequire(pData->m_pAttrs,
6351+ pData->m_pSpec))
6352+ createError(XMLERR_ERROR, pData,
6353+ "Failed to parse 'package' tag (%s).",
6354+ pData->m_pSpec->getError());
6355+ else if (pData->m_pSpec->hasWarning())
6356+ createError(XMLERR_WARNING, pData,
6357+ pData->m_pSpec->getWarning());
6358+ break;
6359+ case XTAG_PROVS:
6360+ if (!XMLPackageContainer::addProvide(pData->m_pAttrs,
6361+ pData->m_pSpec))
6362+ createError(XMLERR_ERROR, pData,
6363+ "Failed to parse 'package' tag (%s).",
6364+ pData->m_pSpec->getError());
6365+ else if (pData->m_pSpec->hasWarning())
6366+ createError(XMLERR_WARNING, pData,
6367+ pData->m_pSpec->getWarning());
6368+ break;
6369+ case XTAG_OBSOLS:
6370+ if (!XMLPackageContainer::addObsolete(pData->m_pAttrs,
6371+ pData->m_pSpec))
6372+ createError(XMLERR_ERROR, pData,
6373+ "Failed to parse 'package' tag (%s).",
6374+ pData->m_pSpec->getError());
6375+ else if (pData->m_pSpec->hasWarning())
6376+ createError(XMLERR_WARNING, pData,
6377+ pData->m_pSpec->getWarning());
6378+ break;
6379+ default:
6380+ break;
6381+ }
6382+ break;
6383+ default:
6384+ break;
6385+ }
6386+}
6387+
6388+void startElementCB(void* pCBData,
6389+ const char* szElement,
6390+ const char** szAttr)
6391+{
6392+ // get the data structure we are working with and
6393+ structCBData* pData = (structCBData*)pCBData;
6394+
6395+ // validate and get the tag we are working with
6396+ unsigned int nTag = getTagValue(szElement,
6397+ pData->m_nDepth,
6398+ pData->m_nDepth ? pData->m_pnTree[pData->m_nDepth-1] : XTAG_ANY);
6399+
6400+ if (nTag == XTAG_NO || nTag == XTAG_WRONGSTRUCT)
6401+ return createError(XMLERR_WARNING, pData, "Unexpected tag '%s' in structure '%s'.",
6402+ szElement,
6403+ treeToString(pData->m_pnTree, pData->m_nDepth++));
6404+ pData->m_pnTree[pData->m_nDepth] = nTag;
6405+ pData->m_sData.assign("");
6406+
6407+ if (pData->m_pAttrs)
6408+ delete pData->m_pAttrs;
6409+ pData->m_pAttrs = new XMLAttrs(szAttr);
6410+
6411+ switch (pData->m_nDepth++) {
6412+ case 0:
6413+ startDepth0(pData);
6414+ break;
6415+ case 1:
6416+ startDepth1(pData);
6417+ break;
6418+ case 2:
6419+ startDepth2(pData);
6420+ break;
6421+ case 3:
6422+ startDepth3(pData);
6423+ break;
6424+ default:
6425+ break;
6426+ }
6427+}
6428+
6429+void endDepth1(structCBData* pData)
6430+{
6431+ // make sure we have a spec
6432+ if (!pData->m_pSpec) {
6433+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6434+ return;
6435+ }
6436+
6437+ // handle tag
6438+ switch (pData->m_pnTree[1]) {
6439+ case XTAG_MACRO:
6440+ if (!XMLMacro::parseCreate(pData->m_pAttrs,
6441+ pData->m_sData.c_str(),
6442+ pData->m_pSpec))
6443+ createError(XMLERR_ERROR, pData,
6444+ "Failed to add macro entry (%s).",
6445+ pData->m_pAttrs->getError());
6446+ else if (pData->m_pSpec->hasWarning())
6447+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6448+ break;
6449+ default:
6450+ break;
6451+ }
6452+}
6453+
6454+void endDepth2(structCBData* pData)
6455+{
6456+ // make sure we have a spec
6457+ if (!pData->m_pSpec) {
6458+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6459+ return;
6460+ }
6461+
6462+ // do the tag
6463+ switch (pData->m_pnTree[2]) {
6464+ case XTAG_SUMMARY:
6465+ if (!XMLPackage::addSummary(pData->m_pAttrs, pData->m_sData.c_str(),
6466+ pData->m_pSpec))
6467+ createError(XMLERR_ERROR, pData,
6468+ "Failed to add 'summary'.");
6469+ break;
6470+ case XTAG_DESC:
6471+ if (!XMLPackage::addDescription(pData->m_pAttrs, pData->m_sData.c_str(),
6472+ pData->m_pSpec))
6473+ createError(XMLERR_ERROR, pData,
6474+ "Failed to add 'description'.");
6475+ break;
6476+ case XTAG_SCRIPT:
6477+ switch (pData->m_pnTree[1]) {
6478+ case XTAG_PREP:
6479+ if (!XMLScripts::addPrepScript(pData->m_pAttrs,
6480+ pData->m_sData.c_str(),
6481+ pData->m_pSpec))
6482+ createError(XMLERR_ERROR, pData,
6483+ "Failed to add shell entry.");
6484+ break;
6485+ case XTAG_BUILD:
6486+ if (!XMLScripts::addBuildScript(pData->m_pAttrs,
6487+ pData->m_sData.c_str(),
6488+ pData->m_pSpec))
6489+ createError(XMLERR_ERROR, pData,
6490+ "Failed to add shell entry.");
6491+ break;
6492+ case XTAG_INSTALL:
6493+ if (!XMLScripts::addInstallScript(pData->m_pAttrs,
6494+ pData->m_sData.c_str(),
6495+ pData->m_pSpec))
6496+ createError(XMLERR_ERROR, pData,
6497+ "Failed to add shell entry.");
6498+ break;
6499+ case XTAG_CLEAN:
6500+ if (!XMLScripts::addCleanScript(pData->m_pAttrs,
6501+ pData->m_sData.c_str(),
6502+ pData->m_pSpec))
6503+ createError(XMLERR_ERROR, pData,
6504+ "Failed to add shell entry.");
6505+ break;
6506+ default:
6507+ break;
6508+ }
6509+ break;
6510+ default:
6511+ break;
6512+ }
6513+}
6514+
6515+void endDepth3(structCBData* pData)
6516+{
6517+ // make sure we have a spec
6518+ if (!pData->m_pSpec) {
6519+ createError(XMLERR_ERROR, pData, "Spec has not been defined.");
6520+ return;
6521+ }
6522+
6523+ // handle tag
6524+ switch (pData->m_pnTree[3]) {
6525+ case XTAG_CHANGE:
6526+ if (!XMLChangelogEntry::parseCreate(pData->m_pAttrs,
6527+ pData->m_sData.c_str(),
6528+ pData->m_pSpec))
6529+ createError(XMLERR_ERROR, pData,
6530+ "Failed to add changelog entry.");
6531+ else if (pData->m_pSpec->hasWarning())
6532+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6533+ break;
6534+ case XTAG_FILE:
6535+ if (!XMLFile::parseCreate(pData->m_pAttrs,
6536+ pData->m_sData.c_str(),
6537+ pData->m_pSpec))
6538+ createError(XMLERR_ERROR, pData, "Failed to parse 'file' tag (%s).",
6539+ pData->m_pSpec->getError());
6540+ else if (pData->m_pSpec->hasWarning())
6541+ createError(XMLERR_WARNING, pData, pData->m_pSpec->getWarning());
6542+ break;
6543+ case XTAG_SCRIPT:
6544+ switch (pData->m_pnTree[2]) {
6545+ case XTAG_PRE:
6546+ if (!XMLPackageScripts::addPreScript(pData->m_pAttrs,
6547+ pData->m_sData.c_str(),
6548+ pData->m_pSpec))
6549+ createError(XMLERR_ERROR, pData,
6550+ "Failed to parse 'script' tag (%s).",
6551+ pData->m_pSpec->getError());
6552+ else if (pData->m_pSpec->hasWarning())
6553+ createError(XMLERR_WARNING, pData,
6554+ pData->m_pSpec->getWarning());
6555+ break;
6556+ case XTAG_POST:
6557+ if (!XMLPackageScripts::addPostScript(pData->m_pAttrs,
6558+ pData->m_sData.c_str(),
6559+ pData->m_pSpec))
6560+ createError(XMLERR_ERROR, pData,
6561+ "Failed to parse 'script' tag (%s).",
6562+ pData->m_pSpec->getError());
6563+ else if (pData->m_pSpec->hasWarning())
6564+ createError(XMLERR_WARNING, pData,
6565+ pData->m_pSpec->getWarning());
6566+ break;
6567+ case XTAG_PREUN:
6568+ if (!XMLPackageScripts::addPreUnScript(pData->m_pAttrs,
6569+ pData->m_sData.c_str(),
6570+ pData->m_pSpec))
6571+ createError(XMLERR_ERROR, pData,
6572+ "Failed to parse 'script' tag (%s).",
6573+ pData->m_pSpec->getError());
6574+ else if (pData->m_pSpec->hasWarning())
6575+ createError(XMLERR_WARNING, pData,
6576+ pData->m_pSpec->getWarning());
6577+ break;
6578+ case XTAG_POSTUN:
6579+ if (!XMLPackageScripts::addPostUnScript(pData->m_pAttrs,
6580+ pData->m_sData.c_str(),
6581+ pData->m_pSpec))
6582+ createError(XMLERR_ERROR, pData,
6583+ "Failed to parse 'script' tag (%s).",
6584+ pData->m_pSpec->getError());
6585+ else if (pData->m_pSpec->hasWarning())
6586+ createError(XMLERR_WARNING, pData,
6587+ pData->m_pSpec->getWarning());
6588+ break;
6589+ case XTAG_VERIFY:
6590+ if (!XMLPackageScripts::addVerifyScript(pData->m_pAttrs,
6591+ pData->m_sData.c_str(),
6592+ pData->m_pSpec))
6593+ createError(XMLERR_ERROR, pData,
6594+ "Failed to parse 'script' tag (%s).",
6595+ pData->m_pSpec->getError());
6596+ else if (pData->m_pSpec->hasWarning())
6597+ createError(XMLERR_WARNING, pData,
6598+ pData->m_pSpec->getWarning());
6599+ break;
6600+ default:
6601+ break;
6602+ }
6603+ break;
6604+ default:
6605+ break;
6606+ }
6607+}
6608+
6609+void endElementCB(void* pCBData,
6610+ const char* szElement)
6611+{
6612+ // get the data structure we are working with
6613+ structCBData* pData = (structCBData*)pCBData;
6614+ pData->m_nDepth--;
6615+
6616+ // validate and get the tag we are working with
6617+ unsigned int nTag = getTagValue(szElement,
6618+ pData->m_nDepth,
6619+ pData->m_nDepth ? pData->m_pnTree[pData->m_nDepth-1] : XTAG_ANY);
6620+ if (nTag == XTAG_NO || nTag == XTAG_WRONGSTRUCT)
6621+ return;
6622+
6623+ // handle the tree depth
6624+ switch (pData->m_nDepth) {
6625+ case 0:
6626+ break;
6627+ case 1:
6628+ endDepth1(pData);
6629+ break;
6630+ case 2:
6631+ endDepth2(pData);
6632+ break;
6633+ case 3:
6634+ endDepth3(pData);
6635+ break;
6636+ default:
6637+ break;
6638+ }
6639+
6640+ // clean up
6641+ pData->m_sData.assign("");
6642+}
6643+
6644+void characterCB(void* pCBData,
6645+ const char* szStr,
6646+ int nLen)
6647+{
6648+ // get the data structure we are working with
6649+ structCBData* pData = (structCBData*)pCBData;
6650+
6651+ // append the string to our internal data
6652+ if (nLen) {
6653+ char* szTmp = new char[nLen+1];
6654+ strncpy(szTmp, szStr, nLen);
6655+ szTmp[nLen] = '\0';
6656+ pData->m_sData.append(szTmp);
6657+ delete[] szTmp;
6658+ }
6659+}
6660+
6661+int parseXMLSpec(const char* szXMLFilename,
6662+ XMLSpec*& pSpec)
6663+{
6664+ // create and setup our parser for use
6665+ printf("Creating XML parser instance ... ");
6666+ XML_Parser parser = XML_ParserCreate(NULL);
6667+ if (!parser) {
6668+ printf("Failed.\n\tERROR: Couldn't allocate memory for parser\n\n");
6669+ return -1;
6670+ }
6671+ else
6672+ printf("Ok.\n");
6673+ XML_SetElementHandler(parser, startElementCB, endElementCB);
6674+ XML_SetCharacterDataHandler(parser, characterCB);
6675+ structCBData stData;
6676+ stData.m_pParser = &parser;
6677+ stData.m_sFilename.assign(szXMLFilename);
6678+ stData.m_nWarnings = 0;
6679+ stData.m_nErrors = 0;
6680+ stData.m_nDepth = 0;
6681+ stData.m_pSpec = NULL;
6682+ stData.m_pAttrs = NULL;
6683+ XML_SetUserData(parser, (void*)&stData);
6684+
6685+ // open the input and output files here
6686+ printf("Opening input XML spec ... ");
6687+ ifstream fIn(szXMLFilename);
6688+ if (!fIn.is_open()) {
6689+ printf("Failed.\n\tERROR: Could not open %s\n\n", szXMLFilename);
6690+ return -2;
6691+ }
6692+ else
6693+ printf("Ok.\n");
6694+
6695+ // parse our configuration (loop through file,
6696+ // doing a break if needed (fatal error))
6697+ printf("Parsing %s: \n", szXMLFilename);
6698+ char szBuff[1024+1];
6699+ unsigned int nLength = 0;
6700+ while (!fIn.eof()) {
6701+ fIn.get(szBuff, 1024, '\0');
6702+ unsigned int nRead = strlen(szBuff);
6703+ nLength += nRead;
6704+ if (!XML_Parse(parser, szBuff, nRead, fIn.eof() ? 1 : 0)) {
6705+ createError(XMLERR_FATAL, &stData, "XML parsing: %s",
6706+ XML_ErrorString(XML_GetErrorCode(parser)));
6707+ break;
6708+ }
6709+ }
6710+
6711+ // print the end results
6712+ printf("\t%d bytes parsed, %d errors(s), %d warnings(s)\n",
6713+ nLength, stData.m_nErrors, stData.m_nWarnings);
6714+ printf("Closing input XML spec ... ");
6715+ fIn.close();
6716+ printf("Ok.\n");
6717+
6718+ // clean up
6719+ if (stData.m_nErrors) {
6720+ if (stData.m_pSpec != NULL)
6721+ delete stData.m_pSpec;
6722+ pSpec = NULL;
6723+ }
6724+ else
6725+ pSpec = stData.m_pSpec;
6726+
6727+ // return number of errors
6728+ return stData.m_nErrors;
6729+}
6730Index: xmlspec/XMLParser.h
6731===================================================================
6732RCS file: xmlspec/XMLParser.h
6733diff -N xmlspec/XMLParser.h
6734--- /dev/null 1 Jan 1970 00:00:00 -0000
6735+++ rpm/xmlspec/XMLParser.h 28 Aug 2002 10:52:43 -0000 1.1.1.1.2.1
6736@@ -0,0 +1,19 @@
6737+#ifndef _H_XMLPARSER_
6738+#define _H_XMLPARSER_
6739+
6740+// our includes
6741+#include "XMLSpec.h"
6742+
6743+/**
6744+ * Parses an XML spec into the internal data structures as
6745+ * defined in the XML* classes.
6746+ * .
6747+ * @param szXMLFilename The Spec to read as parser input
6748+ * @param pSpec A reference to the spec data structure we
6749+ * are to fill.
6750+ * @return The number of parsing/other errors (0 == success)
6751+ **/
6752+extern int parseXMLSpec(const char* szXMLFilename,
6753+ XMLSpec*& pSpec);
6754+
6755+#endif
6756Index: xmlspec/XMLRPMWrap.cpp
6757===================================================================
6758RCS file: xmlspec/XMLRPMWrap.cpp
6759diff -N xmlspec/XMLRPMWrap.cpp
6760--- /dev/null 1 Jan 1970 00:00:00 -0000
6761+++ rpm/xmlspec/XMLRPMWrap.cpp 28 Aug 2002 10:52:43 -0000 1.1.2.1
6762@@ -0,0 +1,72 @@
6763+// standard c++ includes
6764+#include <string>
6765+#include <vector>
6766+
6767+// rpm includes
6768+#include <rpmlib.h>
6769+#include <rpmbuild.h>
6770+
6771+// type definitions
6772+typedef vector<string> t_StrVector;
6773+
6774+using namespace std;
6775+
6776+bool getRPMHeader(Header header,
6777+ int_32 nTag,
6778+ string& rResult)
6779+{
6780+ if (headerIsEntry(header, nTag)) {
6781+ int_32 nCount, nTagType;
6782+ void* pBuffer;
6783+ if (!headerGetEntry(header, nTag, &nTagType, &pBuffer, &nCount))
6784+ return false;
6785+ char szTemp[32];
6786+ switch (nTagType) {
6787+ case RPM_INT32_TYPE:
6788+ sprintf(szTemp, "%d", *((int_32*)pBuffer));
6789+ rResult.assign(szTemp);
6790+ default:
6791+ rResult.assign((char*)pBuffer);
6792+ break;
6793+ }
6794+ headerFreeData(pBuffer, (rpmTagType_e)nTagType);
6795+ return true;
6796+ }
6797+ else
6798+ return false;
6799+}
6800+
6801+bool getRPMHeaderArray(Header header,
6802+ int_32 nTag,
6803+ t_StrVector& rvResult)
6804+{
6805+ rvResult.clear();
6806+ if (headerIsEntry(header, nTag)) {
6807+ int_32 nCount, nTagType;
6808+ void* pBuffer;
6809+ if (!headerGetEntry(header, nTag, &nTagType, &pBuffer, &nCount))
6810+ return false;
6811+ if (nTagType == RPM_STRING_ARRAY_TYPE || nTagType == RPM_I18NSTRING_TYPE) {
6812+ for (int_32 i = 0; i < nCount; i++)
6813+ rvResult.push_back(((char**)pBuffer)[i]);
6814+ }
6815+ else
6816+ rvResult.push_back((char*)pBuffer);
6817+ headerFreeData(pBuffer, (rpmTagType_e)nTagType);
6818+ return true;
6819+ }
6820+ else
6821+ return false;
6822+}
6823+
6824+bool getRPMMacro(const char* szMacro,
6825+ string& rResult)
6826+{
6827+ char* szValue = rpmExpand(szMacro, NULL);
6828+ if (szValue) {
6829+ rResult.assign(szValue);
6830+ return true;
6831+ }
6832+ else
6833+ return false;
6834+}
6835Index: xmlspec/XMLRPMWrap.h
6836===================================================================
6837RCS file: xmlspec/XMLRPMWrap.h
6838diff -N xmlspec/XMLRPMWrap.h
6839--- /dev/null 1 Jan 1970 00:00:00 -0000
6840+++ rpm/xmlspec/XMLRPMWrap.h 28 Aug 2002 10:52:43 -0000 1.1.2.1
6841@@ -0,0 +1,49 @@
6842+#ifndef _H_XMLRPMWRAP_
6843+#define _H_XMLRPMWRAP_
6844+
6845+// standard C++ includes
6846+#include <string>
6847+#include <vector>
6848+
6849+// rpm includes
6850+#include <rpmlib.h>
6851+
6852+// type definitions
6853+typedef vector<string> t_StrVector;
6854+
6855+/**
6856+ * Gets an RPM header after checking that is does exist.
6857+ * .
6858+ * @param header The RPM header to interrogate
6859+ * @param nTag The header tag to extract
6860+ * @param rResult The string to populate with the result
6861+ * @return true on success, false otherwise
6862+ **/
6863+extern bool getRPMHeader(Header header,
6864+ int_32 nTag,
6865+ std::string& rResult);
6866+
6867+/**
6868+ * Gets an RPM header array into a vector after checking that it
6869+ * does indeed exist
6870+ * .
6871+ * @param header The RPM header to interrogate
6872+ * @param nTag The header tag to extract
6873+ * @param rvResult The vector<string> to populate with the result
6874+ * @return true on success, false otherwise
6875+ **/
6876+extern bool getRPMHeaderArray(Header header,
6877+ int_32 nTag,
6878+ t_StrVector& rvResult);
6879+
6880+/**
6881+ * Gets a specific RPM macro
6882+ * .
6883+ * @param szMacro The macro to get the value of
6884+ * @param rResult The string to populate with the result
6885+ * @return true on success, false otherwise
6886+ **/
6887+extern bool getRPMMacro(const char* szMacro,
6888+ std::string& rResult);
6889+
6890+#endif
6891Index: xmlspec/XMLRequires.cpp
6892===================================================================
6893RCS file: xmlspec/XMLRequires.cpp
6894diff -N xmlspec/XMLRequires.cpp
6895--- /dev/null 1 Jan 1970 00:00:00 -0000
6896+++ rpm/xmlspec/XMLRequires.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
6897@@ -0,0 +1,189 @@
6898+// our includes
6899+#include "XMLAttrs.h"
6900+#include "XMLPackage.h"
6901+#include "XMLRequires.h"
6902+#include "XMLRPMWrap.h"
6903+#include "XMLSpec.h"
6904+
6905+// rpm includes
6906+#include <rpmlib.h>
6907+
6908+using namespace std;
6909+
6910+// attribute structure for XMLPackageEntry
6911+structValidAttrs g_paEntryAttrs[] =
6912+{
6913+ {0x0000, true, false, "name", XATTRTYPE_STRING, {"*", NULL}},
6914+ {0x0001, false, false, "version", XATTRTYPE_STRING, {"*", NULL}},
6915+ {0x0002, false, false, "cmp", XATTRTYPE_STRING, {"*", NULL}},
6916+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
6917+};
6918+
6919+bool XMLPackageEntry::parseCreate(XMLAttrs* pAttrs,
6920+ XMLPackageContainer& rContainer)
6921+{
6922+ // validate the attributes
6923+ if (!pAttrs->validate(g_paEntryAttrs, (XMLBase*)pAttrs))
6924+ return false;
6925+
6926+ // create and return
6927+ XMLPackageEntry entry(pAttrs->asString("name"), pAttrs->asString("version"),
6928+ pAttrs->asString("cmp"));
6929+ rContainer.addEntry(entry);
6930+ return true;
6931+}
6932+
6933+XMLPackageEntry::XMLPackageEntry(const char* szName,
6934+ const char* szVersion,
6935+ const char* szCmp)
6936+ : XMLBase()
6937+{
6938+ if (szName)
6939+ m_sName.assign(szName);
6940+ if (szVersion)
6941+ m_sVersion.assign(szVersion);
6942+ m_sCmp.assign("=");
6943+ if (szCmp) {
6944+ if (strcasecmp(szCmp, "lt") == 0)
6945+ m_sCmp.assign("<");
6946+ else if (strcasecmp(szCmp, "le") == 0)
6947+ m_sCmp.assign("<=");
6948+ else if (strcasecmp(szCmp, "gt") == 0)
6949+ m_sCmp.assign(">");
6950+ else if (strcasecmp(szCmp, "ge") == 0)
6951+ m_sCmp.assign(">=");
6952+ }
6953+}
6954+
6955+XMLPackageEntry::XMLPackageEntry(const XMLPackageEntry& rEntry)
6956+ : XMLBase()
6957+{
6958+ m_sName.assign(rEntry.m_sName);
6959+ m_sVersion.assign(rEntry.m_sVersion);
6960+ m_sCmp.assign(rEntry.m_sCmp);
6961+}
6962+
6963+XMLPackageEntry::~XMLPackageEntry()
6964+{
6965+}
6966+
6967+XMLPackageEntry XMLPackageEntry::operator=(XMLPackageEntry entry)
6968+{
6969+ m_sName.assign(entry.m_sName);
6970+ m_sVersion.assign(entry.m_sVersion);
6971+ m_sCmp.assign(entry.m_sCmp);
6972+ return *this;
6973+}
6974+
6975+void XMLPackageEntry::toSpecFile(ostream& rOut)
6976+{
6977+ rOut << getName();
6978+ if (hasVersion()) {
6979+ rOut << " " << getCompare() << " " << getVersion();
6980+ }
6981+}
6982+
6983+void XMLPackageEntry::toXMLFile(ostream& rOut)
6984+{
6985+ rOut << endl << "\t\t\t<package name=\"" << getName() << "\"";
6986+ if (hasVersion()) {
6987+ if (m_sCmp.compare("=") == 0)
6988+ rOut << " cmp=\"eq\"";
6989+ else if (m_sCmp.compare("<") == 0)
6990+ rOut << " cmp=\"lt\"";
6991+ else if (m_sCmp.compare("<=") == 0)
6992+ rOut << " cmp=\"le\"";
6993+ else if (m_sCmp.compare(">") == 0)
6994+ rOut << " cmp=\"gt\"";
6995+ else if (m_sCmp.compare(">=") == 0)
6996+ rOut << " cmp=\"ge\"";
6997+ rOut << " version=\"" << getVersion() << "\"";
6998+ }
6999+ rOut << " />";
7000+}
7001+
7002+XMLPackageContainer::XMLPackageContainer()
7003+ : XMLBase()
7004+{
7005+}
7006+
7007+XMLPackageContainer::XMLPackageContainer(const XMLPackageContainer& rContainer)
7008+ : XMLBase()
7009+{
7010+ m_vPackages = rContainer.m_vPackages;
7011+}
7012+
7013+XMLPackageContainer::~XMLPackageContainer()
7014+{
7015+}
7016+
7017+XMLPackageContainer XMLPackageContainer::operator=(XMLPackageContainer container)
7018+{
7019+ m_vPackages = container.m_vPackages;
7020+ return *this;
7021+}
7022+
7023+void XMLPackageContainer::toSpecFile(ostream& rOut,
7024+ const char* szTag)
7025+{
7026+ if (numEntries()) {
7027+ rOut << szTag << ": ";
7028+ for (unsigned int i = 0; i < numEntries(); i++) {
7029+ rOut << (i ? ", " : "");
7030+ getEntry(i).toSpecFile(rOut);
7031+ }
7032+ rOut << endl;
7033+ }
7034+}
7035+
7036+void XMLPackageContainer::toXMLFile(ostream& rOut,
7037+ const char* szTag)
7038+{
7039+ if (numEntries()) {
7040+ rOut << endl << "\t\t<" << szTag << ">";
7041+ for (unsigned int i = 0; i < numEntries(); i++)
7042+ getEntry(i).toXMLFile(rOut);
7043+ rOut << endl << "\t\t</" << szTag << ">";
7044+ }
7045+}
7046+
7047+bool XMLPackageContainer::addRequire(XMLAttrs* pAttrs,
7048+ XMLSpec* pSpec)
7049+{
7050+ if (!pSpec)
7051+ return false;
7052+ return XMLPackageEntry::parseCreate(pAttrs, pSpec->lastPackage().getRequires());
7053+}
7054+
7055+bool XMLPackageContainer::addBuildRequire(XMLAttrs* pAttrs,
7056+ XMLSpec* pSpec)
7057+{
7058+ if (!pSpec)
7059+ return false;
7060+ return XMLPackageEntry::parseCreate(pAttrs, pSpec->lastPackage().getBuildRequires());
7061+}
7062+
7063+bool XMLPackageContainer::addProvide(XMLAttrs* pAttrs,
7064+ XMLSpec* pSpec)
7065+{
7066+ if (!pSpec)
7067+ return false;
7068+ return XMLPackageEntry::parseCreate(pAttrs, pSpec->lastPackage().getProvides());
7069+}
7070+
7071+bool XMLPackageContainer::addObsolete(XMLAttrs* pAttrs,
7072+ XMLSpec* pSpec)
7073+{
7074+ if (!pSpec)
7075+ return false;
7076+ return XMLPackageEntry::parseCreate(pAttrs, pSpec->lastPackage().getObsoletes());
7077+}
7078+
7079+bool XMLPackageContainer::structCreate(PackageStruct* pPackage,
7080+ Spec pSpec,
7081+ XMLSpec* pXSpec)
7082+{
7083+ if (!pXSpec || !pPackage || !pPackage->header)
7084+ return false;
7085+ return true;
7086+}
7087Index: xmlspec/XMLRequires.h
7088===================================================================
7089RCS file: xmlspec/XMLRequires.h
7090diff -N xmlspec/XMLRequires.h
7091--- /dev/null 1 Jan 1970 00:00:00 -0000
7092+++ rpm/xmlspec/XMLRequires.h 28 Aug 2002 10:52:43 -0000 1.2.2.1
7093@@ -0,0 +1,327 @@
7094+#ifndef _H_XMLREQUIRES_
7095+#define _H_XMLREQUIRES_
7096+
7097+// standard C++ includes
7098+#include <iostream>
7099+#include <string>
7100+#include <vector>
7101+
7102+// standard C includes
7103+#include <stdio.h>
7104+
7105+// our includes
7106+#include "XMLAttrs.h"
7107+#include "XMLBase.h"
7108+
7109+// forward definitions
7110+class XMLPackage;
7111+class XMLPackageContainer;
7112+class XMLSpec;
7113+
7114+using namespace std;
7115+
7116+//<package ...> (after requires, buildrequires, obsoletes, provides)
7117+class XMLPackageEntry : public XMLBase
7118+{
7119+//
7120+// factory functions
7121+//
7122+public:
7123+ /**
7124+ * Creates an object as parsed from an XML spec
7125+ * .
7126+ * @param pAttrs XML atrtributes to use
7127+ * @param rContainer The container to which to add the object
7128+ * @return true on success, false otherwise
7129+ **/
7130+ static bool parseCreate(XMLAttrs* pAttrs,
7131+ XMLPackageContainer& rContainer);
7132+
7133+//
7134+// constructors/destructor
7135+//
7136+public:
7137+ /**
7138+ * Default constructor
7139+ * .
7140+ * @param szName Name of the package
7141+ * @param szVersion version of the package
7142+ * @param szCmp the comparator (eq,lt,le,gt,ge)
7143+ * @return none
7144+ **/
7145+ XMLPackageEntry(const char* szName,
7146+ const char* szVersion,
7147+ const char* szCmp);
7148+
7149+ /**
7150+ * Copy constructor
7151+ * .
7152+ * @param rEntry reference to the entrry to copy
7153+ * @return none
7154+ **/
7155+ XMLPackageEntry(const XMLPackageEntry& rEntry);
7156+
7157+ /**
7158+ * Destructor
7159+ * .
7160+ * @param none
7161+ * @return none
7162+ **/
7163+ ~XMLPackageEntry();
7164+
7165+//
7166+// operators
7167+//
7168+public:
7169+ /**
7170+ * Assignment operator
7171+ * .
7172+ * @param entry The entry to assigne to
7173+ * @return thye modified object
7174+ **/
7175+ XMLPackageEntry operator=(XMLPackageEntry entry);
7176+//
7177+// member functions
7178+//
7179+public:
7180+ /**
7181+ * Converts the object into an RPM spec
7182+ * .
7183+ * @param rOut Output stream
7184+ * @return none
7185+ **/
7186+ void toSpecFile(ostream& rOut);
7187+
7188+ /**
7189+ * Converts the object into an XML spec
7190+ * .
7191+ * @param rOut output stream
7192+ * @return none
7193+ **/
7194+ void toXMLFile(ostream& rOut);
7195+
7196+//
7197+// member variable get/set functions
7198+//
7199+public:
7200+ /**
7201+ * Gets the name
7202+ * .
7203+ * @param none
7204+ * @return string containing the name
7205+ **/
7206+ const char* getName()
7207+ {
7208+ return m_sName.c_str();
7209+ }
7210+
7211+ /**
7212+ * Checks if we have a version
7213+ * .
7214+ * @param none
7215+ * @return true if available, false otherwise
7216+ **/
7217+ bool hasVersion()
7218+ {
7219+ return m_sVersion.length() ? true : false;
7220+ }
7221+
7222+ /**
7223+ * Gets the version
7224+ * .
7225+ * @param none
7226+ * @return string containing the version
7227+ **/
7228+ const char* getVersion()
7229+ {
7230+ return m_sVersion.c_str();
7231+ }
7232+
7233+ /**
7234+ * Gets the comparision string
7235+ * .
7236+ * @param none
7237+ * @return string with the comparator (=, <, <=, >, >=, <>)
7238+ **/
7239+ const char* getCompare()
7240+ {
7241+ return m_sCmp.c_str();
7242+ }
7243+
7244+//
7245+// member variables
7246+//
7247+protected:
7248+ string m_sName;
7249+ string m_sVersion;
7250+ string m_sCmp;
7251+};
7252+
7253+//<requires,obsoletes,buildrequires,provides ...>
7254+class XMLPackageContainer : public XMLBase
7255+{
7256+//
7257+// factory functions
7258+//
7259+public:
7260+ /**
7261+ * Adds a require
7262+ * .
7263+ * @param pAttrs XML attributes
7264+ * @param pSpecx pointer to the spec to add to
7265+ * @return true on success, false otherwise
7266+ **/
7267+ static bool addRequire(XMLAttrs* pAttrs,
7268+ XMLSpec* pSpec);
7269+
7270+ /**
7271+ * Adds a buildrequire
7272+ * .
7273+ * @param pAttrs XML attributes
7274+ * @param pSpecx pointer to the spec to add to
7275+ * @return true on success, false otherwise
7276+ **/
7277+ static bool addBuildRequire(XMLAttrs* pAttrs,
7278+ XMLSpec* pSpec);
7279+
7280+ /**
7281+ * Adds a provide
7282+ * .
7283+ * @param pAttrs XML attributes
7284+ * @param pSpecx pointer to the spec to add to
7285+ * @return true on success, false otherwise
7286+ **/
7287+ static bool addProvide(XMLAttrs* pAttrs,
7288+ XMLSpec* pSpec);
7289+
7290+ /**
7291+ * Adds an obsolete
7292+ * .
7293+ * @param pAttrs XML attributes
7294+ * @param pSpecx pointer to the spec to add to
7295+ * @return true on success, false otherwise
7296+ **/
7297+ static bool addObsolete(XMLAttrs* pAttrs,
7298+ XMLSpec* pSpec);
7299+
7300+ /**
7301+ * Adds requires/provides/obsoletes from RPM structures
7302+ * .
7303+ * @param pPackage pointer to the RPM package
7304+ * @param pSpec pointer to the RPM spec
7305+ * @param pXSpec pointer to the XML spec to populate
7306+ * @return true on success, false otherwise
7307+ **/
7308+ static bool structCreate(PackageStruct* pPackage,
7309+ Spec pSpec,
7310+ XMLSpec* pXSpec);
7311+
7312+//
7313+// constructors/destructor
7314+//
7315+public:
7316+ /**
7317+ * Default constructor
7318+ * .
7319+ * @param none
7320+ * @return none
7321+ **/
7322+ XMLPackageContainer();
7323+
7324+ /**
7325+ * Copy constructor
7326+ * .
7327+ * @param rContainer The container to copy
7328+ * @return none
7329+ **/
7330+ XMLPackageContainer(const XMLPackageContainer& rContainer);
7331+
7332+ /**
7333+ * Destructor
7334+ * .
7335+ * @param none
7336+ * @return none
7337+ **/
7338+ virtual ~XMLPackageContainer();
7339+
7340+//
7341+// operators
7342+//
7343+public:
7344+ /**
7345+ * Assignment operator
7346+ * .
7347+ * @param container The container to copy
7348+ * @return a copy of the object
7349+ **/
7350+ XMLPackageContainer operator=(XMLPackageContainer container);
7351+
7352+//
7353+// member functions
7354+//
7355+public:
7356+ /**
7357+ * Converts the object into an RPM spec
7358+ * .
7359+ * @param rOut Output stream
7360+ * @param szTag the tag for this object (eg. buildrequires)
7361+ * @return none
7362+ **/
7363+ virtual void toSpecFile(ostream& rOut,
7364+ const char* szTag);
7365+
7366+ /**
7367+ * Converts the object into an XML spec
7368+ * .
7369+ * @param rOut Output stream
7370+ * @para szTag the tag for this object (eg. buildrequires)
7371+ * @return none
7372+ **/
7373+ virtual void toXMLFile(ostream& rOut,
7374+ const char* szTag);
7375+
7376+//
7377+// member variable get/set functions
7378+//
7379+public:
7380+ /**
7381+ * Gets the number of entries
7382+ * .
7383+ * @param none
7384+ * @return the number of entries
7385+ **/
7386+ unsigned int numEntries()
7387+ {
7388+ return m_vPackages.size();
7389+ }
7390+
7391+ /**
7392+ * Gets a specific entry
7393+ * .
7394+ * @param nNum The number of the entry
7395+ * @return reference to the entry
7396+ **/
7397+ XMLPackageEntry& getEntry(unsigned int nNum)
7398+ {
7399+ return m_vPackages[nNum];
7400+ }
7401+
7402+ /**
7403+ * Adds an entry
7404+ * .
7405+ * @param rPackage the entry to add
7406+ * @return none
7407+ **/
7408+ void addEntry(XMLPackageEntry& rPackage)
7409+ {
7410+ m_vPackages.push_back(rPackage);
7411+ }
7412+
7413+//
7414+// member variables
7415+//
7416+protected:
7417+ vector<XMLPackageEntry> m_vPackages;
7418+};
7419+
7420+#endif
7421Index: xmlspec/XMLScript.cpp
7422===================================================================
7423RCS file: xmlspec/XMLScript.cpp
7424diff -N xmlspec/XMLScript.cpp
7425--- /dev/null 1 Jan 1970 00:00:00 -0000
7426+++ rpm/xmlspec/XMLScript.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
7427@@ -0,0 +1,285 @@
7428+// standard includes
7429+#include <stdio.h>
7430+
7431+// our includes
7432+#include "XMLPackage.h"
7433+#include "XMLScript.h"
7434+#include "XMLSpec.h"
7435+
7436+// attribute structure for XMLScript
7437+structValidAttrs g_paScriptAttrs[] =
7438+{
7439+ {0x0000, false, false, "dir", XATTRTYPE_STRING, {"*", NULL}},
7440+ {0x0001, false, false, "interpreter", XATTRTYPE_STRING, {"*", NULL}},
7441+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
7442+};
7443+
7444+bool XMLScript::parseCreate(XMLAttrs* pAttrs,
7445+ const char* szScript,
7446+ XMLScripts& rContainer)
7447+{
7448+ if (!pAttrs->validate(g_paScriptAttrs, (XMLBase*)pAttrs))
7449+ return false;
7450+ XMLScript script(szScript,
7451+ pAttrs->asString("interpreter"),
7452+ pAttrs->asString("dir"));
7453+ rContainer.add(script);
7454+ return true;
7455+}
7456+
7457+XMLScript::XMLScript(const char* szScript,
7458+ const char* szInterpreter,
7459+ const char* szDir)
7460+ : XMLBase()
7461+{
7462+ if (szScript)
7463+ m_sValue.assign(szScript);
7464+ if (szInterpreter)
7465+ m_sInterpreter.assign(szInterpreter);
7466+ if (szDir)
7467+ m_sDir.assign(szDir);
7468+}
7469+
7470+XMLScript::XMLScript(const XMLScript& rScript)
7471+ : XMLBase()
7472+{
7473+ m_sValue.assign(rScript.m_sValue);
7474+ m_sInterpreter.assign(rScript.m_sInterpreter);
7475+ m_sDir.assign(rScript.m_sDir);
7476+}
7477+
7478+XMLScript::~XMLScript()
7479+{
7480+}
7481+
7482+XMLScript XMLScript::operator=(XMLScript script)
7483+{
7484+ m_sValue.assign(script.m_sValue);
7485+ m_sInterpreter.assign(script.m_sInterpreter);
7486+ m_sDir.assign(script.m_sDir);
7487+}
7488+
7489+void XMLScript::toSpecFile(ostream& rOut)
7490+{
7491+ if (hasDirectory())
7492+ rOut << "cd " << getDirectory() << endl;
7493+ rOut << getValue() << endl;
7494+}
7495+
7496+void XMLScript::toXMLFile(ostream& rOut,
7497+ const char* szIndent)
7498+{
7499+ rOut << endl << szIndent << "\t\t<script";
7500+ if (hasDirectory())
7501+ rOut << " dir=\"" << getDirectory() << "\"";
7502+ rOut << ">" << getValue() << "</script>";
7503+}
7504+
7505+void XMLScript::toRPMStruct(StringBuf* pSB)
7506+{
7507+ if (hasDirectory()) {
7508+ char szBuff[getDirectoryLen()+3+1]; // 3 == strlen("cd ")
7509+ sprintf(szBuff, "cd %s", getDirectory());
7510+ appendStringBuf(*pSB, szBuff);
7511+ }
7512+ appendStringBuf(*pSB, getValue());
7513+}
7514+
7515+bool XMLScripts::addPrepScript(XMLAttrs* pAttrs,
7516+ const char* szScript,
7517+ XMLSpec* pSpec)
7518+{
7519+ // no spec or already set
7520+ if (!pSpec)
7521+ return false;
7522+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->getPrep());
7523+}
7524+
7525+bool XMLScripts::addBuildScript(XMLAttrs* pAttrs,
7526+ const char* szScript,
7527+ XMLSpec* pSpec)
7528+{
7529+ // no spec or already set
7530+ if (!pSpec)
7531+ return false;
7532+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->getBuild());
7533+}
7534+
7535+bool XMLScripts::addInstallScript(XMLAttrs* pAttrs,
7536+ const char* szScript,
7537+ XMLSpec* pSpec)
7538+{
7539+ // no spec or already set
7540+ if (!pSpec)
7541+ return false;
7542+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->getInstall());
7543+}
7544+
7545+bool XMLScripts::addCleanScript(XMLAttrs* pAttrs,
7546+ const char* szScript,
7547+ XMLSpec* pSpec)
7548+{
7549+ // no spec or already set
7550+ if (!pSpec)
7551+ return false;
7552+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->getClean());
7553+}
7554+
7555+XMLScripts::XMLScripts()
7556+ : XMLBase()
7557+{
7558+}
7559+
7560+XMLScripts::XMLScripts(const XMLScripts& rContainer)
7561+ : XMLBase()
7562+{
7563+ m_vScripts = rContainer.m_vScripts;
7564+}
7565+
7566+XMLScripts::~XMLScripts()
7567+{
7568+}
7569+
7570+void XMLScripts::toSpecFile(ostream& rOut,
7571+ const char* szTag)
7572+{
7573+ if (numScripts()) {
7574+ rOut << endl << "%" << szTag << endl;
7575+ for (unsigned int i = 0; i < numScripts(); i++)
7576+ getScript(i).toSpecFile(rOut);
7577+ }
7578+}
7579+
7580+void XMLScripts::toXMLFile(ostream& rOut,
7581+ const char* szTag)
7582+{
7583+ if (numScripts()) {
7584+ rOut << endl << "\t<" << szTag << ">";
7585+ for (unsigned int i = 0; i < numScripts(); i++)
7586+ getScript(i).toXMLFile(rOut, "");
7587+ rOut << endl << "\t</" << szTag << ">";
7588+ }
7589+}
7590+
7591+bool XMLPackageScripts::addPreScript(XMLAttrs* pAttrs,
7592+ const char* szScript,
7593+ XMLSpec* pSpec)
7594+{
7595+ if (!pSpec)
7596+ return false;
7597+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->lastPackage().getPre());
7598+}
7599+
7600+bool XMLPackageScripts::addPostScript(XMLAttrs* pAttrs,
7601+ const char* szScript,
7602+ XMLSpec* pSpec)
7603+{
7604+ if (!pSpec)
7605+ return false;
7606+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->lastPackage().getPost());
7607+}
7608+
7609+bool XMLPackageScripts::addPreUnScript(XMLAttrs* pAttrs,
7610+ const char* szScript,
7611+ XMLSpec* pSpec)
7612+{
7613+ if (!pSpec)
7614+ return false;
7615+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->lastPackage().getPreUn());
7616+}
7617+
7618+bool XMLPackageScripts::addPostUnScript(XMLAttrs* pAttrs,
7619+ const char* szScript,
7620+ XMLSpec* pSpec)
7621+{
7622+ if (!pSpec)
7623+ return false;
7624+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->lastPackage().getPostUn());
7625+}
7626+
7627+bool XMLPackageScripts::addVerifyScript(XMLAttrs* pAttrs,
7628+ const char* szScript,
7629+ XMLSpec* pSpec)
7630+{
7631+ if (!pSpec)
7632+ return false;
7633+ return XMLScript::parseCreate(pAttrs, szScript, pSpec->lastPackage().getVerify());
7634+}
7635+
7636+bool XMLPackageScripts::createPreScripts(XMLAttrs* pAttrs,
7637+ XMLSpec* pSpec)
7638+{
7639+ if (!pSpec)
7640+ return false;
7641+ pSpec->lastPackage().getPre().setInterpreter(pAttrs->asString("interpreter"));
7642+ return true;
7643+}
7644+
7645+bool XMLPackageScripts::createPostScripts(XMLAttrs* pAttrs,
7646+ XMLSpec* pSpec)
7647+{
7648+ if (!pSpec)
7649+ return false;
7650+ pSpec->lastPackage().getPost().setInterpreter(pAttrs->asString("interpreter"));
7651+ return true;
7652+}
7653+
7654+bool XMLPackageScripts::createPreUnScripts(XMLAttrs* pAttrs,
7655+ XMLSpec* pSpec)
7656+{
7657+ if (!pSpec)
7658+ return false;
7659+ pSpec->lastPackage().getPreUn().setInterpreter(pAttrs->asString("interpreter"));
7660+ return true;
7661+}
7662+
7663+bool XMLPackageScripts::createPostUnScripts(XMLAttrs* pAttrs,
7664+ XMLSpec* pSpec)
7665+{
7666+ if (!pSpec)
7667+ return false;
7668+ pSpec->lastPackage().getPostUn().setInterpreter(pAttrs->asString("interpreter"));
7669+ return true;
7670+}
7671+
7672+bool XMLPackageScripts::createVerifyScripts(XMLAttrs* pAttrs,
7673+ XMLSpec* pSpec)
7674+{
7675+ if (!pSpec)
7676+ return false;
7677+ pSpec->lastPackage().getVerify().setInterpreter(pAttrs->asString("interpreter"));
7678+ return true;
7679+}
7680+
7681+XMLPackageScripts::XMLPackageScripts()
7682+ : XMLScripts()
7683+{
7684+}
7685+
7686+XMLPackageScripts::XMLPackageScripts(const XMLPackageScripts& rContainer)
7687+ : XMLScripts(rContainer)
7688+{
7689+}
7690+
7691+XMLPackageScripts::~XMLPackageScripts()
7692+{
7693+}
7694+
7695+void XMLPackageScripts::toSpecFile(ostream& rOut,
7696+ const char* szTag)
7697+{
7698+ // NOTE: header not done here, but by "package"
7699+ for (unsigned int i = 0; i < numScripts(); i++)
7700+ getScript(i).toSpecFile(rOut);
7701+}
7702+
7703+void XMLPackageScripts::toXMLFile(ostream& rOut,
7704+ const char* szTag)
7705+{
7706+ if (numScripts()) {
7707+ rOut << endl << "\t\t<" << szTag << ">";
7708+ for (unsigned int i = 0; i < numScripts(); i++)
7709+ getScript(i).toXMLFile(rOut, "\t");
7710+ rOut << endl << "\t\t</" << szTag << ">";
7711+ }
7712+}
7713Index: xmlspec/XMLScript.h
7714===================================================================
7715RCS file: xmlspec/XMLScript.h
7716diff -N xmlspec/XMLScript.h
7717--- /dev/null 1 Jan 1970 00:00:00 -0000
7718+++ rpm/xmlspec/XMLScript.h 28 Aug 2002 10:52:43 -0000 1.2.2.1
7719@@ -0,0 +1,519 @@
7720+#ifndef _H_XMLSCRIPT_
7721+#define _H_XMLSCRIPT_
7722+
7723+// standard C++ includes
7724+#include <iostream>
7725+#include <string>
7726+#include <vector>
7727+
7728+// our includes
7729+#include "XMLAttrs.h"
7730+#include "XMLBase.h"
7731+
7732+// rpm includes
7733+#include <rpmbuild.h>
7734+
7735+// forward definitions
7736+class XMLPackage;
7737+class XMLSpec;
7738+class XMLScripts;
7739+
7740+using namespace std;
7741+
7742+class XMLScript : public XMLBase
7743+{
7744+//
7745+// factory methods
7746+//
7747+public:
7748+ /**
7749+ * Creates a script object and adds it to the container
7750+ * .
7751+ * @param pAttrs The XML attributes
7752+ * @param szScript The script value
7753+ * @param rContainer reference to the script container to add to
7754+ * @return true on success, false otherwise
7755+ **/
7756+ static bool parseCreate(XMLAttrs* pAttrs,
7757+ const char* szScript,
7758+ XMLScripts& rContainer);
7759+
7760+//
7761+// constructors/destructor
7762+//
7763+public:
7764+ /**
7765+ * Default constructor
7766+ * .
7767+ * @param szScript The script
7768+ * @param szInterpreter The interpreter to use for script execution
7769+ * @param szDir Directory to execute the script in
7770+ * @return none
7771+ **/
7772+ XMLScript(const char* szScript,
7773+ const char* szInterpreter,
7774+ const char* szDir);
7775+
7776+ /**
7777+ * Copy constructor
7778+ * .
7779+ * @param rScript Script to copy
7780+ * @return none
7781+ **/
7782+ XMLScript(const XMLScript& rScript);
7783+
7784+ /**
7785+ * Destructor
7786+ * .
7787+ * @param none
7788+ * @return none
7789+ **/
7790+ virtual ~XMLScript();
7791+
7792+//
7793+// operators
7794+//
7795+public:
7796+ /**
7797+ * Assignment operator
7798+ * .
7799+ * @param script the script to copy
7800+ * @return the copied object
7801+ **/
7802+ XMLScript operator=(XMLScript script);
7803+
7804+//
7805+// member functions
7806+//
7807+public:
7808+ /**
7809+ * Converts the object into an RPM spec file
7810+ * .
7811+ * @param rOut Output stream
7812+ * @return none
7813+ **/
7814+ void toSpecFile(ostream& rOut);
7815+
7816+ /**
7817+ * Converts the object into an XML spec
7818+ * .
7819+ * @param rOut Output stream
7820+ * @param szIndent Indent string
7821+ * @return none
7822+ **/
7823+ void toXMLFile(ostream& rOut,
7824+ const char* szIndent = "");
7825+
7826+ /**
7827+ * Converts the object into an RPM structure
7828+ * .
7829+ * @param pSB Pointer to the string buffer
7830+ * @return none
7831+ **/
7832+ virtual void toRPMStruct(StringBuf* pSB);
7833+
7834+//
7835+// member variable get/set functions
7836+//
7837+public:
7838+ /**
7839+ * Gets the script value
7840+ * .
7841+ * @param none
7842+ * @return string containing the script
7843+ **/
7844+ const char* getValue()
7845+ {
7846+ return m_sValue.c_str();
7847+ }
7848+
7849+ /**
7850+ * Checks if we have an interpreter
7851+ * .
7852+ * @param none
7853+ * @return true if we have an interpreter, false otherwise
7854+ **/
7855+ bool hasInterpreter()
7856+ {
7857+ return m_sInterpreter.length() ? true : false;
7858+ }
7859+
7860+ /**
7861+ * Gets the interpreter
7862+ * .
7863+ * @param none
7864+ * @return string contating the interpreter
7865+ **/
7866+ const char* getInterpreter()
7867+ {
7868+ return m_sInterpreter.c_str();
7869+ }
7870+
7871+ /**
7872+ * Checks if we have a direcory
7873+ * .
7874+ * @param none
7875+ * @return true if we have a directory, false otherwise
7876+ **/
7877+ bool hasDirectory()
7878+ {
7879+ return m_sDir.length() ? true : false;
7880+ }
7881+
7882+ /**
7883+ * Gets the directory
7884+ * .
7885+ * @param none
7886+ * @return string contating the directory
7887+ **/
7888+ const char* getDirectory()
7889+ {
7890+ return m_sDir.c_str();
7891+ }
7892+
7893+ /**
7894+ * Gets the length of the directory string
7895+ * .
7896+ * @param none
7897+ * @return length of the description string
7898+ **/
7899+ unsigned int getDirectoryLen()
7900+ {
7901+ return m_sDir.length();
7902+ }
7903+
7904+//
7905+// member variables
7906+//
7907+public:
7908+ string m_sValue;
7909+ string m_sInterpreter;
7910+ string m_sDir;
7911+};
7912+
7913+//<prep,build,install,clean ...>
7914+class XMLScripts : public XMLBase
7915+{
7916+//
7917+// factory functions
7918+//
7919+public:
7920+ static bool addPrepScript(XMLAttrs* pAttrs,
7921+ const char* szScript,
7922+ XMLSpec* pSpec);
7923+
7924+ static bool addBuildScript(XMLAttrs* pAttrs,
7925+ const char* szScript,
7926+ XMLSpec* pSpec);
7927+
7928+ static bool addInstallScript(XMLAttrs* pAttrs,
7929+ const char* szScript,
7930+ XMLSpec* pSpec);
7931+
7932+ static bool addCleanScript(XMLAttrs* pAttrs,
7933+ const char* szScript,
7934+ XMLSpec* pSpec);
7935+
7936+//
7937+// constructors/destructor
7938+//
7939+public:
7940+ /**
7941+ * Default constructor
7942+ * .
7943+ * @param none
7944+ * @return none
7945+ **/
7946+ XMLScripts();
7947+
7948+ /**
7949+ * Copy constructor
7950+ * .
7951+ * @param rContainer the object to copy
7952+ * @return none
7953+ **/
7954+ XMLScripts(const XMLScripts& rContainer);
7955+
7956+ /**
7957+ * Destructor
7958+ * .
7959+ * @param none
7960+ * @return none
7961+ **/
7962+ virtual ~XMLScripts();
7963+
7964+//
7965+// member functions
7966+//
7967+public:
7968+ /**
7969+ * Converts the object into an RPM spec file
7970+ * .
7971+ * @param rOut Output stream
7972+ * @param szTag The tag name
7973+ * @return none
7974+ **/
7975+ virtual void toSpecFile(ostream& rOut,
7976+ const char* szTag);
7977+
7978+ /**
7979+ * Converts the object into an XML spec
7980+ * .
7981+ * @param rOut Output stream
7982+ * @param szTag The tag name
7983+ * @return none
7984+ **/
7985+ void toXMLFile(ostream& rOut,
7986+ const char* szTag);
7987+
7988+//
7989+// member variable get/set functions
7990+//
7991+public:
7992+ /**
7993+ * Checks if we have an interpreter
7994+ * .
7995+ * @param none
7996+ * @return true if we have an interpreter, false otherwise
7997+ **/
7998+ bool hasInterpreter()
7999+ {
8000+ return m_sInterpreter.length() ? true : false;
8001+ }
8002+
8003+ /**
8004+ * Gets the interpreter
8005+ * .
8006+ * @param none
8007+ * @return string contatining the interpreter
8008+ **/
8009+ const char* getInterpreter()
8010+ {
8011+ return m_sInterpreter.c_str();
8012+ }
8013+
8014+ /**
8015+ * Sets the script interpreter
8016+ * .
8017+ * @param szInterpreter The interpreter
8018+ * @return none
8019+ **/
8020+ void setInterpreter(const char* szInterpreter)
8021+ {
8022+ if (szInterpreter)
8023+ m_sInterpreter.assign(szInterpreter);
8024+ }
8025+
8026+ /**
8027+ * Gets the number of script entries
8028+ * .
8029+ * @param none
8030+ * @return the number of scripts
8031+ **/
8032+ unsigned int numScripts()
8033+ {
8034+ return m_vScripts.size();
8035+ }
8036+
8037+ /**
8038+ * Gets a specific script entry
8039+ * .
8040+ * @param nNum The entry number
8041+ * @return Reference to the script entry
8042+ **/
8043+ XMLScript& getScript(unsigned int nNum)
8044+ {
8045+ return m_vScripts[nNum];
8046+ }
8047+
8048+ /**
8049+ * Adds an script entry
8050+ * .
8051+ * @param szScript the script to add
8052+ * @return none
8053+ **/
8054+ void add(XMLScript& rScript)
8055+ {
8056+ m_vScripts.push_back(rScript);
8057+ }
8058+
8059+//
8060+// member variables
8061+//
8062+protected:
8063+ string m_sInterpreter;
8064+ vector<XMLScript> m_vScripts;
8065+};
8066+
8067+//<post, postun, ...>
8068+class XMLPackageScripts : public XMLScripts
8069+{
8070+//
8071+// factory functions
8072+//
8073+public:
8074+ /**
8075+ * Adds a pre script
8076+ * .
8077+ * @param pAttrs The XML attributes
8078+ * @param szScript The script to add
8079+ * @param pSpec The spec to which we are adding
8080+ * @return true on success, false otherwise
8081+ **/
8082+ static bool addPreScript(XMLAttrs* pAttrs,
8083+ const char* szScript,
8084+ XMLSpec* pSpec);
8085+
8086+ /**
8087+ * Adds a post script
8088+ * .
8089+ * @param pAttrs The XML attributes
8090+ * @param szScript The script to add
8091+ * @param pSpec The spec to which we are adding
8092+ * @return true on success, false otherwise
8093+ **/
8094+ static bool addPostScript(XMLAttrs* pAttrs,
8095+ const char* szScript,
8096+ XMLSpec* pSpec);
8097+
8098+ /**
8099+ * Adds a preun script
8100+ * .
8101+ * @param pAttrs The XML attributes
8102+ * @param szScript The script to add
8103+ * @param pSpec The spec to which we are adding
8104+ * @return true on success, false otherwise
8105+ **/
8106+ static bool addPreUnScript(XMLAttrs* pAttrs,
8107+ const char* szScript,
8108+ XMLSpec* pSpec);
8109+
8110+ /**
8111+ * Adds a postun script
8112+ * .
8113+ * @param pAttrs The XML attributes
8114+ * @param szScript The script to add
8115+ * @param pSpec The spec to which we are adding
8116+ * @return true on success, false otherwise
8117+ **/
8118+ static bool addPostUnScript(XMLAttrs* pAttrs,
8119+ const char* szScript,
8120+ XMLSpec* pSpec);
8121+
8122+ /**
8123+ * Adds a verify script
8124+ * .
8125+ * @param pAttrs The XML attributes
8126+ * @param szScript The script to add
8127+ * @param pSpec The spec to which we are adding
8128+ * @return true on success, false otherwise
8129+ **/
8130+ static bool addVerifyScript(XMLAttrs* pAttrs,
8131+ const char* szScript,
8132+ XMLSpec* pSpec);
8133+
8134+ /**
8135+ * Initialises a pre script container
8136+ * .
8137+ * @param pAttrs The XML attributes
8138+ * @param pSpec The spec to which we are adding
8139+ * @return true on success, false otherwise
8140+ **/
8141+ static bool createPreScripts(XMLAttrs* pAttrs,
8142+ XMLSpec* pSpec);
8143+
8144+ /**
8145+ * Initialises a post script container
8146+ * .
8147+ * @param pAttrs The XML attributes
8148+ * @param pSpec The spec to which we are adding
8149+ * @return true on success, false otherwise
8150+ **/
8151+ static bool createPostScripts(XMLAttrs* pAttrs,
8152+ XMLSpec* pSpec);
8153+
8154+ /**
8155+ * Initialises a preun script container
8156+ * .
8157+ * @param pAttrs The XML attributes
8158+ * @param pSpec The spec to which we are adding
8159+ * @return true on success, false otherwise
8160+ **/
8161+ static bool createPreUnScripts(XMLAttrs* pAttrs,
8162+ XMLSpec* pSpec);
8163+
8164+ /**
8165+ * Initialises a postun script container
8166+ * .
8167+ * @param pAttrs The XML attributes
8168+ * @param pSpec The spec to which we are adding
8169+ * @return true on success, false otherwise
8170+ **/
8171+ static bool createPostUnScripts(XMLAttrs* pAttrs,
8172+ XMLSpec* pSpec);
8173+
8174+ /**
8175+ * Initialises a verify script container
8176+ * .
8177+ * @param pAttrs The XML attributes
8178+ * @param pSpec The spec to which we are adding
8179+ * @return true on success, false otherwise
8180+ **/
8181+ static bool createVerifyScripts(XMLAttrs* pAttrs,
8182+ XMLSpec* pSpec);
8183+
8184+//
8185+// constructors/destructors
8186+//
8187+public:
8188+ /**
8189+ * Default constructor
8190+ * .
8191+ * @param none
8192+ * @return none
8193+ **/
8194+ XMLPackageScripts();
8195+
8196+ /**
8197+ * Copy constructor
8198+ * .
8199+ * @param rScripts Reference to the object to copy
8200+ * @return none
8201+ **/
8202+ XMLPackageScripts(const XMLPackageScripts& rScripts);
8203+
8204+ /**
8205+ * Destructor
8206+ * .
8207+ * @param none
8208+ * @return none
8209+ **/
8210+ ~XMLPackageScripts();
8211+
8212+//
8213+// member functions
8214+//
8215+public:
8216+ /**
8217+ * Converts the object into an RPM spec
8218+ * .
8219+ * @param rOut Output stream
8220+ * @param szTag The tag name
8221+ * @return none
8222+ **/
8223+ virtual void toSpecFile(ostream& rOut,
8224+ const char* szTag);
8225+
8226+ /**
8227+ * Converts the object into an XML spec
8228+ * .
8229+ * @param rOut Output stream
8230+ * @param szTag The tag name
8231+ * @return none
8232+ **/
8233+ virtual void toXMLFile(ostream& rOut,
8234+ const char* szTag);
8235+
8236+};
8237+
8238+#endif
8239Index: xmlspec/XMLSource.cpp
8240===================================================================
8241RCS file: xmlspec/XMLSource.cpp
8242diff -N xmlspec/XMLSource.cpp
8243--- /dev/null 1 Jan 1970 00:00:00 -0000
8244+++ rpm/xmlspec/XMLSource.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
8245@@ -0,0 +1,339 @@
8246+// standard includes
8247+#include <stdio.h>
8248+
8249+// our includes
8250+#include "XMLSource.h"
8251+#include "XMLSpec.h"
8252+
8253+// rpm includes
8254+#include <rpmspec.h>
8255+
8256+using namespace std;
8257+
8258+bool XMLSource::structCreate(Source* pSource,
8259+ Spec pSpec,
8260+ XMLSpec* pXSpec)
8261+{
8262+ if (!pXSpec || !pSpec || !pSource)
8263+ return false;
8264+
8265+ // create our mirror
8266+ XMLMirror *pMirror = NULL;
8267+ if (pSource->source != pSource->fullSource) {
8268+ unsigned int nLen = pSource->source-pSource->fullSource;
8269+ char szPath[nLen+1];
8270+ strncpy(szPath, pSource->fullSource, nLen);
8271+ szPath[nLen] = '\0';
8272+ pMirror = new XMLMirror(szPath, NULL, NULL);
8273+ }
8274+
8275+ // generate the source, nosource, patch
8276+ XMLSource* pXSource = NULL;
8277+ XMLNoSource* pXNoSource = NULL;
8278+ XMLPatch* pXPatch = NULL;
8279+ switch (pSource->flags) {
8280+ case RPMBUILD_ISSOURCE:
8281+ pXSource = new XMLSource(pSource->source, pSource->num,
8282+ NULL, NULL, NULL);
8283+ pXSpec->addSource(*pXSource);
8284+ if (pMirror)
8285+ pXSpec->lastSource().addMirror(*pMirror);
8286+ delete pXSource;
8287+ break;
8288+ case RPMBUILD_ISNO:
8289+ pXNoSource = new XMLNoSource(pSource->source, pSource->num,
8290+ NULL, NULL, NULL);
8291+ pXSpec->addNoSource(*pXNoSource);
8292+ if (pMirror)
8293+ pXSpec->lastNoSource().addMirror(*pMirror);
8294+ delete pXNoSource;
8295+ break;
8296+ case RPMBUILD_ISPATCH:
8297+ pXPatch = new XMLPatch(pSource->source, pSource->num, NULL, NULL);
8298+ pXSpec->addPatch(*pXPatch);
8299+ if (pMirror)
8300+ pXSpec->lastPatch().addMirror(*pMirror);
8301+ delete pXPatch;
8302+ break;
8303+ default:
8304+ break;
8305+ }
8306+ if (pMirror)
8307+ delete pMirror;
8308+
8309+ // do the next source and return
8310+ XMLSource::structCreate(pSource->next, pSpec, pXSpec);
8311+ return true;
8312+}
8313+
8314+// attribute structure for XMLSource
8315+structValidAttrs g_paSourceAttrs[] =
8316+{
8317+ {0x0000, true, false, "name", XATTRTYPE_STRING, {"*", NULL}},
8318+ {0x0001, false, false, "num", XATTRTYPE_INTEGER, {NULL}},
8319+ {0x0002, false, false, "dir", XATTRTYPE_STRING, {"*", NULL}},
8320+ {0x0003, false, false, "size", XATTRTYPE_INTEGER, {NULL}},
8321+ {0x0004, false, false, "md5", XATTRTYPE_STRING, {"*", NULL}},
8322+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
8323+};
8324+
8325+bool XMLSource::parseCreate(XMLAttrs* pAttrs,
8326+ XMLSpec* pSpec)
8327+{
8328+ // validate the attributes
8329+ if (!pAttrs->validate(g_paSourceAttrs, (XMLBase*)pSpec))
8330+ return false;
8331+
8332+ XMLSource source(pAttrs->asString("name"), pAttrs->asInteger("num"),
8333+ pAttrs->asString("dir"), pAttrs->asString("size"),
8334+ pAttrs->asString("md5"));
8335+ pSpec->addSource(source);
8336+
8337+ return true;
8338+}
8339+
8340+XMLSource::XMLSource(const char* szName,
8341+ unsigned int nNum,
8342+ const char* szDir,
8343+ const char* szSize,
8344+ const char* szMD5)
8345+ : XMLBase()
8346+{
8347+ if (szName)
8348+ m_sName.assign(szName);
8349+ m_nNum = nNum;
8350+ if (szDir)
8351+ m_sDir.assign(szDir);
8352+ if (szSize)
8353+ m_sSize.assign(szSize);
8354+ if (szMD5)
8355+ m_sMD5.assign(szMD5);
8356+}
8357+
8358+XMLSource::XMLSource(const XMLSource& rSource)
8359+ : XMLBase()
8360+{
8361+ m_sName.assign(rSource.m_sName);
8362+ m_nNum = rSource.m_nNum;
8363+ m_sDir.assign(rSource.m_sDir);
8364+ m_sSize.assign(rSource.m_sSize);
8365+ m_sMD5.assign(rSource.m_sMD5);
8366+ m_vMirrors = rSource.m_vMirrors;
8367+}
8368+
8369+XMLSource::~XMLSource()
8370+{
8371+}
8372+
8373+XMLSource XMLSource::operator=(XMLSource source)
8374+{
8375+ m_sName.assign(source.m_sName);
8376+ m_nNum = source.m_nNum;
8377+ m_sDir.assign(source.m_sDir);
8378+ m_sSize.assign(source.m_sSize);
8379+ m_sMD5.assign(source.m_sMD5);
8380+ m_vMirrors = source.m_vMirrors;
8381+ return *this;
8382+}
8383+
8384+void XMLSource::toSpecFile(ostream& rOut)
8385+{
8386+ for (unsigned int i = 0; i < numMirrors(); i++)
8387+ getMirror(i).toSpecFile(rOut);
8388+
8389+ rOut << endl << "source";
8390+ rOut << getNum();
8391+ rOut << ": ";
8392+ if (numMirrors())
8393+ rOut << getMirror(0).getPath();
8394+ rOut << getName();
8395+}
8396+
8397+void XMLSource::toXMLFile(ostream& rOut)
8398+{
8399+ rOut << endl << "\t<source name=\"" << getName() << "\"";
8400+ rOut << endl << "\t num=\"";
8401+ rOut << getNum();
8402+ rOut << "\"";
8403+ if (hasSize())
8404+ rOut << endl << "\t size=\"" << getSize() << "\"";
8405+ if (hasMD5())
8406+ rOut << endl << "\t md5=\"" << getMD5() << "\"";
8407+ if (hasDir())
8408+ rOut << endl << "\t dir=\"" << getDir() << "\"";
8409+ rOut << ">";
8410+
8411+ for (unsigned int i = 0; i < numMirrors(); i++)
8412+ getMirror(i).toXMLFile(rOut);
8413+
8414+ rOut << endl << "\t</source>";
8415+}
8416+
8417+void XMLSource::toRPMStruct(Spec pRPMSpec)
8418+{
8419+ /*Source* pCurr = new Source;
8420+ unsigned int nNameLen = strlen(getName());
8421+ unsigned int nMirrorLen = 0;
8422+ if (pPrev)
8423+ pPrev->next = pCurr;
8424+ pCurr->next = NULL;
8425+ if (numMirrors())
8426+ nMirrorlen = strlen(getMirror(0).getPath());
8427+ pCurr->fullSource = new char[nNamelen+nMirrorLen+1];
8428+ pCurr->fullSources[0] = '\0';
8429+ if (numMirrors())
8430+ strcpy(pCurr->fullSource, getMirror(0).getPath());
8431+ strcat(pCurr->fullSource, getName());
8432+ pCurr->source = pCurr->fullSource+nMirrorLen;
8433+ pCurr->num = getNum();
8434+ pCurr->flags = RPMBUILD_ISSOURCE;
8435+ return pCurr;*/
8436+}
8437+
8438+bool XMLNoSource::parseCreate(XMLAttrs* pAttrs,
8439+ XMLSpec* pSpec)
8440+{
8441+ // validate the attributes
8442+ if (!pAttrs->validate(g_paSourceAttrs, (XMLBase*)pSpec))
8443+ return false;
8444+
8445+ XMLNoSource source(pAttrs->asString("name"), pAttrs->asInteger("num"),
8446+ pAttrs->asString("dir"), pAttrs->asString("size"),
8447+ pAttrs->asString("md5"));
8448+ pSpec->addNoSource(source);
8449+ return true;
8450+}
8451+
8452+XMLNoSource::XMLNoSource(const char* szName,
8453+ unsigned int nNum,
8454+ const char* szDir,
8455+ const char* szSize,
8456+ const char* szMD5)
8457+ : XMLSource(szName,
8458+ nNum,
8459+ szDir,
8460+ szSize,
8461+ szMD5)
8462+{
8463+}
8464+
8465+XMLNoSource::XMLNoSource(const XMLNoSource& rNoSource)
8466+ : XMLSource(rNoSource.m_sName.c_str(),
8467+ rNoSource.m_nNum,
8468+ rNoSource.m_sDir.c_str(),
8469+ rNoSource.m_sSize.c_str(),
8470+ rNoSource.m_sMD5.c_str())
8471+{
8472+}
8473+
8474+XMLNoSource::~XMLNoSource()
8475+{
8476+}
8477+
8478+void XMLNoSource::toSpecFile(ostream& rOut)
8479+{
8480+ for (unsigned int i = 0; i < numMirrors(); i++)
8481+ getMirror(i).toSpecFile(rOut);
8482+
8483+ rOut << endl << "nosource";
8484+ rOut << getNum();
8485+ rOut << ": " << getName();
8486+}
8487+
8488+void XMLNoSource::toXMLFile(ostream& rOut)
8489+{
8490+ for (unsigned int i = 0; i < numMirrors(); i++)
8491+ getMirror(i).toXMLFile(rOut);
8492+}
8493+
8494+void XMLNoSource::toRPMStruct(Spec pRPMSpec)
8495+{
8496+ //Source* pCurr = XMLSource::toRPMStruct(pPrev);
8497+ //pCurr->flags = RPMBUILD_ISNO;
8498+ //return pCurr;
8499+}
8500+
8501+// attribute structure for XMLPatch
8502+structValidAttrs g_paPatchAttrs[] =
8503+{
8504+ {0x0000, true, false, "name", XATTRTYPE_STRING, {"*", NULL}},
8505+ {0x0001, false, false, "num", XATTRTYPE_INTEGER, {NULL}},
8506+ {0x0002, false, false, "size", XATTRTYPE_INTEGER, {NULL}},
8507+ {0x0003, false, false, "md5", XATTRTYPE_STRING, {"*", NULL}},
8508+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
8509+};
8510+
8511+bool XMLPatch::parseCreate(XMLAttrs* pAttrs,
8512+ XMLSpec* pSpec)
8513+{
8514+ // validate the attributes
8515+ if (!pAttrs->validate(g_paPatchAttrs, (XMLBase*)pSpec))
8516+ return false;
8517+
8518+ XMLPatch patch(pAttrs->asString("name"), pAttrs->asInteger("num"),
8519+ pAttrs->asString("size"), pAttrs->asString("md5"));
8520+ pSpec->addPatch(patch);
8521+ return true;
8522+}
8523+
8524+XMLPatch::XMLPatch(const char* szName,
8525+ unsigned int nNum,
8526+ const char* szSize,
8527+ const char* szMD5)
8528+ : XMLSource(szName,
8529+ nNum,
8530+ NULL,
8531+ szSize,
8532+ szMD5)
8533+{
8534+}
8535+
8536+XMLPatch::XMLPatch(const XMLPatch& rPatch)
8537+ : XMLSource(rPatch.m_sName.c_str(),
8538+ rPatch.m_nNum,
8539+ NULL,
8540+ rPatch.m_sSize.c_str(),
8541+ rPatch.m_sMD5.c_str())
8542+{
8543+}
8544+
8545+XMLPatch::~XMLPatch()
8546+{
8547+}
8548+
8549+void XMLPatch::toSpecFile(ostream& rOut)
8550+{
8551+ for (unsigned int i = 0; i < numMirrors(); i++)
8552+ getMirror(i).toSpecFile(rOut);
8553+ rOut << endl << "patch";
8554+ rOut << getNum();
8555+ rOut << ": " << getName();
8556+}
8557+
8558+void XMLPatch::toXMLFile(ostream& rOut)
8559+{
8560+ rOut << endl << "\t<patch name=\"" << getName() << "\"";
8561+ rOut << endl << "\t num=\"";
8562+ rOut << getNum();
8563+ rOut << "\"";
8564+ if (hasSize())
8565+ rOut << endl << "\t size=\"" << getSize() << "\"";
8566+ if (hasMD5())
8567+ rOut << endl << "\t md5=\"" << getMD5() << "\"";
8568+ if (hasDir())
8569+ rOut << endl << "\t dir=\"" << getDir() << "\"";
8570+ rOut << ">";
8571+
8572+ for (unsigned int i = 0; i < numMirrors(); i++)
8573+ getMirror(i).toXMLFile(rOut);
8574+
8575+ rOut << endl << "\t</patch>";
8576+}
8577+
8578+void XMLPatch::toRPMStruct(Spec pRPMSpec)
8579+{
8580+
8581+ //Source* pCurr = XMLSource::toRPMStruct(pPrev);
8582+ //pCurr->flags = RPMBUILD_ISPATCH;
8583+ //return pCurr;
8584+}
8585Index: xmlspec/XMLSource.h
8586===================================================================
8587RCS file: xmlspec/XMLSource.h
8588diff -N xmlspec/XMLSource.h
8589--- /dev/null 1 Jan 1970 00:00:00 -0000
8590+++ rpm/xmlspec/XMLSource.h 28 Aug 2002 10:52:43 -0000 1.2.2.1
8591@@ -0,0 +1,454 @@
8592+#ifndef _H_XMLSOURCE_
8593+#define _H_XMLSOURCE_
8594+
8595+// standard C++ includes
8596+#include <string>
8597+#include <vector>
8598+#include <iostream>
8599+
8600+// standard includes
8601+#include <stdio.h>
8602+
8603+// our includes
8604+#include "XMLAttrs.h"
8605+#include "XMLBase.h"
8606+#include "XMLMirror.h"
8607+
8608+// rpm includes
8609+#include <rpmbuild.h>
8610+
8611+// forward declaration
8612+class XMLSpec;
8613+
8614+using namespace std;
8615+
8616+// <source ...>
8617+class XMLSource : public XMLBase
8618+{
8619+//
8620+// factory functions
8621+//
8622+public:
8623+ /**
8624+ * Static factory function for the creation of XMLSource, XMLPatch, ...
8625+ * objects from RPM Source* structure.
8626+ * .
8627+ * @param pSource Pointer to a list of sources
8628+ * @param pSpec pointer to the RPM spec
8629+ * @param pSpec pointer to our spec object
8630+ * @return true on success, false otherwise
8631+ **/
8632+ static bool structCreate(Source* pSource,
8633+ Spec pSpec,
8634+ XMLSpec* pXSpec);
8635+
8636+ /**
8637+ * Static factory function for the creation of an XMLSource
8638+ * object from details parsed from an XML spec.
8639+ * .
8640+ * @param pAttrs Pointer to an XML attribute object
8641+ * @param pspec Ponter to our spec object
8642+ * @param bPatch True if this source is a patch
8643+ * @return true on success, false otherwise
8644+ **/
8645+ static bool parseCreate(XMLAttrs* pAttrs,
8646+ XMLSpec* pSpec);
8647+
8648+//
8649+// constructors/destructor
8650+//
8651+public:
8652+ /**
8653+ * Default contructor
8654+ * .
8655+ * @param szName The name
8656+ * @param szNum The source number
8657+ * @param szDir The unpack directory
8658+ * @param szSize The size of the source archive
8659+ * @param szMD5 The MD5 sum of the archive
8660+ * @return none
8661+ **/
8662+ XMLSource(const char* szName,
8663+ unsigned int nNum,
8664+ const char* szDir,
8665+ const char* szSize,
8666+ const char* szMD5);
8667+
8668+ /**
8669+ * Copy contructor
8670+ * .
8671+ * @param rSource The source that we are to copy
8672+ * @return none
8673+ **/
8674+ XMLSource(const XMLSource& rSource);
8675+
8676+ /**
8677+ * Destructor
8678+ * .
8679+ * @param none
8680+ * @return none
8681+ **/
8682+ virtual ~XMLSource();
8683+
8684+//
8685+// operators
8686+//
8687+public:
8688+ /**
8689+ * Assignment operator
8690+ * .
8691+ * @param source The source to copy
8692+ * @return copied object
8693+ **/
8694+ XMLSource operator=(XMLSource source);
8695+
8696+//
8697+// Member functions
8698+//
8699+public:
8700+ /**
8701+ * Convert the object into an RPM spec file
8702+ * .
8703+ * @param rOut Output stream
8704+ * @return none
8705+ **/
8706+ virtual void toSpecFile(ostream& rOut);
8707+
8708+ /**
8709+ * Converts the object into an XML spec
8710+ * .
8711+ * @param rOut Output stream
8712+ * @return none
8713+ **/
8714+ virtual void toXMLFile(ostream& rOut);
8715+
8716+ /**
8717+ * Converts the object into an RPM structure
8718+ * .
8719+ * @param spec the RPM structure to use
8720+ * @return none
8721+ **/
8722+ virtual void toRPMStruct(Spec spec);
8723+
8724+//
8725+// member variable get/set functions
8726+//
8727+public:
8728+ /**
8729+ * Checks if we have a source name
8730+ * .
8731+ * @param none
8732+ * @return true if we have a name, false otherwise
8733+ **/
8734+ bool hasName()
8735+ {
8736+ return m_sName.length() ? true : false;
8737+ }
8738+
8739+ /**
8740+ * Get the source name
8741+ * .
8742+ * @param none
8743+ * @return string containing the name
8744+ **/
8745+ const char* getName()
8746+ {
8747+ return m_sName.c_str();
8748+ }
8749+
8750+ /**
8751+ * Get the length of the name
8752+ * .
8753+ * @param none
8754+ * @return the length of the name
8755+ **/
8756+ unsigned int getNameLen()
8757+ {
8758+ return m_sName.length();
8759+ }
8760+
8761+ /**
8762+ * Get the source number
8763+ * .
8764+ * @param none
8765+ * @return the number
8766+ **/
8767+ unsigned int getNum()
8768+ {
8769+ return m_nNum;
8770+ }
8771+
8772+ /**
8773+ * Checks to see if we have an unpack directory
8774+ * .
8775+ * @param none
8776+ * @return true if we have a specified directory, false otherwise
8777+ **/
8778+ bool hasDir()
8779+ {
8780+ return m_sDir.length() ? true : false;
8781+ }
8782+
8783+ /**
8784+ * Gets the directory that we are to unpack this source to
8785+ * .
8786+ * @param none
8787+ * @return string contating the directory
8788+ **/
8789+ const char* getDir()
8790+ {
8791+ return m_sDir.c_str();
8792+ }
8793+
8794+ /**
8795+ * Checks to see if we have a source size
8796+ * .
8797+ * @param none
8798+ * @return true if we have a size, false otherwise
8799+ **/
8800+ bool hasSize()
8801+ {
8802+ return m_sSize.length() ? true : false;
8803+ }
8804+
8805+ /**
8806+ * Gets the size of the source
8807+ * .
8808+ * @param none
8809+ * @return string contating the size
8810+ **/
8811+ const char* getSize()
8812+ {
8813+ return m_sSize.c_str();
8814+ }
8815+
8816+ /**
8817+ * Checks to see if this source has an MD5 sum
8818+ * .
8819+ * @param none
8820+ * @return true if we have an MD5, false oterwise
8821+ **/
8822+ bool hasMD5()
8823+ {
8824+ return m_sMD5.length() ? true : false;
8825+ }
8826+
8827+ /**
8828+ * Gets the MD5 sum for this source
8829+ * .
8830+ * @param none
8831+ * @return string contating the MD5
8832+ **/
8833+ const char* getMD5()
8834+ {
8835+ return m_sMD5.c_str();
8836+ }
8837+
8838+ /**
8839+ * Add a mirror for this source
8840+ * .
8841+ * @param rMirror The mirror to add
8842+ * @return none
8843+ **/
8844+ void addMirror(XMLMirror& rMirror)
8845+ {
8846+ m_vMirrors.push_back(rMirror);
8847+ }
8848+
8849+ /**
8850+ * Gets the number of mirrors for this source
8851+ * .
8852+ * @param none
8853+ * @return the number oif mirrors
8854+ **/
8855+ unsigned int numMirrors()
8856+ {
8857+ return m_vMirrors.size();
8858+ }
8859+
8860+ /**
8861+ * Gets a specific mirror by number
8862+ * .
8863+ * @param nNum The mirror to get
8864+ * @param the mirror
8865+ **/
8866+ XMLMirror& getMirror(unsigned int nNum)
8867+ {
8868+ return m_vMirrors[nNum];
8869+ }
8870+
8871+//
8872+// member variables
8873+//
8874+protected:
8875+ string m_sName;
8876+ unsigned int m_nNum;
8877+ string m_sDir;
8878+ string m_sSize;
8879+ string m_sMD5;
8880+ vector<XMLMirror> m_vMirrors;
8881+};
8882+
8883+// <nosource ...>
8884+class XMLNoSource : public XMLSource
8885+{
8886+//
8887+// factory methods
8888+//
8889+public:
8890+ /**
8891+ * Create an XMLNoSource object
8892+ * .
8893+ * @param pAttrs XML attributes
8894+ * @param pSpec The spec to add the object o
8895+ * @return true on success, false otherwise
8896+ **/
8897+ static bool parseCreate(XMLAttrs* pAttrs,
8898+ XMLSpec* pSpec);
8899+
8900+//
8901+// constructors/destructor
8902+//
8903+public:
8904+ /**
8905+ * Default constructor
8906+ * .
8907+ * @param szName The name
8908+ * @param nNum source number
8909+ * @param szDir Thje director to extract to
8910+ * @param szSize size of the archive
8911+ * @param szMD5 the MD5 sum of the archive
8912+ * @return none
8913+ **/
8914+ XMLNoSource(const char* szName,
8915+ unsigned int nNum,
8916+ const char* szDir,
8917+ const char* szSize,
8918+ const char* szMD5);
8919+
8920+ /**
8921+ * Copy constructor
8922+ * .
8923+ * @param rNoSource Reference to the object ot copy
8924+ * @return none
8925+ **/
8926+ XMLNoSource(const XMLNoSource& rNoSource);
8927+
8928+ /**
8929+ * Destructor
8930+ * .
8931+ * @param none
8932+ * @return none
8933+ **/
8934+ virtual ~XMLNoSource();
8935+
8936+//
8937+// public member functions
8938+//
8939+public:
8940+ /**
8941+ * Converts the object into an RPM spec file
8942+ * .
8943+ * @param rOut Output stream
8944+ * @param none
8945+ **/
8946+ virtual void toSpecFile(ostream& rOut);
8947+
8948+ /**
8949+ * Converts the object into an XML spec
8950+ * .
8951+ * @param rOut Output stream
8952+ * @return none
8953+ **/
8954+ virtual void toXMLFile(ostream& rOut);
8955+
8956+ /**
8957+ * Converts the object into an RPM structure
8958+ * .
8959+ * @param spec The RPM spec structure
8960+ * @return none
8961+ **/
8962+ virtual void toRPMStruct(Spec spec);
8963+};
8964+
8965+// <patch ...>
8966+class XMLPatch : public XMLSource
8967+{
8968+//
8969+// factory methods
8970+//
8971+public:
8972+ /**
8973+ * Create an XMLPatch object
8974+ * .
8975+ * @param pAttrs XML attributes
8976+ * @param pSpec The spec to add the object o
8977+ * @return true on success, false otherwise
8978+ **/
8979+ static bool parseCreate(XMLAttrs* pAttrs,
8980+ XMLSpec* pSpec);
8981+
8982+//
8983+// constructors/destructor
8984+//
8985+public:
8986+ /**
8987+ * Default constructor
8988+ * .
8989+ * @param szName archive name
8990+ * @param nNum source number
8991+ * @param szSize size of the archive
8992+ * @param szMD5 MD5 sum
8993+ * @return none
8994+ **/
8995+ XMLPatch(const char* szName,
8996+ unsigned int nNum,
8997+ const char* szSize,
8998+ const char* szMD5);
8999+
9000+ /**
9001+ * Copy constructor
9002+ * .
9003+ * @param rPatch Reference to the object to copy
9004+ * @return none
9005+ **/
9006+ XMLPatch(const XMLPatch& rPatch);
9007+
9008+ /**
9009+ * Destructor
9010+ * .
9011+ * @param none
9012+ * @return nonew
9013+ **/
9014+ virtual ~XMLPatch();
9015+
9016+//
9017+// member functions
9018+//
9019+public:
9020+ /**
9021+ * Converts the object into an RPM spec file
9022+ * .
9023+ * @param rOut Output stream
9024+ * @param none
9025+ **/
9026+ virtual void toSpecFile(ostream& rOut);
9027+
9028+ /**
9029+ * Converts the object into an XML spec
9030+ * .
9031+ * @param rOut Output stream
9032+ * @return none
9033+ **/
9034+ virtual void toXMLFile(ostream& rOut);
9035+
9036+ /**
9037+ * Converts the object into an RPM structure
9038+ * .
9039+ * @param spec The RPM spec structure
9040+ * @return none
9041+ **/
9042+ virtual void toRPMStruct(Spec spec);
9043+};
9044+
9045+#endif
9046Index: xmlspec/XMLSpec.cpp
9047===================================================================
9048RCS file: xmlspec/XMLSpec.cpp
9049diff -N xmlspec/XMLSpec.cpp
9050--- /dev/null 1 Jan 1970 00:00:00 -0000
9051+++ rpm/xmlspec/XMLSpec.cpp 28 Aug 2002 10:52:43 -0000 1.3.2.1
9052@@ -0,0 +1,252 @@
9053+// 3rd party includes
9054+#include <expat.h>
9055+
9056+// our includes
9057+#include "XMLAttrs.h"
9058+#include "XMLRPMWrap.h"
9059+#include "XMLSpec.h"
9060+
9061+// rpm includes
9062+#include <rpmlib.h>
9063+
9064+using namespace std;
9065+
9066+// attribute structure for XMLSpec
9067+structValidAttrs g_paSpecAttrs[] =
9068+{
9069+ {0x0000, true, false, "name", XATTRTYPE_STRING, {"*", NULL}},
9070+ {0x0001, true, false, "version", XATTRTYPE_STRING, {"*", NULL}},
9071+ {0x0002, true, false, "release", XATTRTYPE_STRING, {"*", NULL}},
9072+ {0x0003, false, false, "epoch", XATTRTYPE_INTEGER, {NULL}},
9073+ {0x0004, false, false, "distribution", XATTRTYPE_STRING, {"*", NULL}},
9074+ {0x0005, false, false, "vendor", XATTRTYPE_STRING, {"*", NULL}},
9075+ {0x0006, false, false, "packager", XATTRTYPE_STRING, {"*", NULL}},
9076+ {0x0007, false, false, "packager-email", XATTRTYPE_MAIL, {"*", NULL}},
9077+ {0x0008, false, false, "copyright", XATTRTYPE_STRING, {"*", NULL}},
9078+ {0x0009, false, false, "url", XATTRTYPE_STRING, {"*", NULL}},
9079+ {0x000A, false, false, "buildroot", XATTRTYPE_STRING, {"*", NULL}},
9080+ {XATTR_END, false, false, "end", XATTRTYPE_NONE, {NULL}}
9081+};
9082+
9083+XMLSpec* XMLSpec::parseCreate(XMLAttrs* pAttrs,
9084+ const char* szFilename)
9085+{
9086+ // verify the attributes
9087+ if (!pAttrs->validate(g_paSpecAttrs, (XMLBase*)pAttrs))
9088+ return NULL;
9089+
9090+ // create and return
9091+ return new XMLSpec(szFilename,
9092+ pAttrs->asString("name"),
9093+ pAttrs->asString("version"),
9094+ pAttrs->asString("release"),
9095+ pAttrs->asString("epoch"),
9096+ pAttrs->asString("distribution"),
9097+ pAttrs->asString("vendor"),
9098+ pAttrs->asString("packager"),
9099+ pAttrs->asString("packager-email"),
9100+ pAttrs->asString("copyright"),
9101+ pAttrs->asString("url"),
9102+ pAttrs->asString("buildroot"));
9103+}
9104+
9105+XMLSpec* XMLSpec::structCreate(Spec pSpec)
9106+{
9107+ if (!pSpec || !pSpec->packages || !pSpec->packages->header)
9108+ return NULL;
9109+
9110+ // create the spec with values from the RPM stuff
9111+ string sName, sVersion, sRelease, sEpoch, sDistro;
9112+ string sVendor, sPackager, sMail, sLicense, sURL;
9113+ if (!getRPMHeader(pSpec->packages->header, RPMTAG_NAME, sName) ||
9114+ !getRPMMacro("PACKAGE_VERSION", sVersion) ||
9115+ !getRPMMacro("PACKAGE_RELEASE", sRelease))
9116+ return NULL;
9117+ getRPMHeader(pSpec->packages->header, RPMTAG_EPOCH, sEpoch);
9118+ getRPMHeader(pSpec->packages->header, RPMTAG_DISTRIBUTION, sDistro);
9119+ getRPMHeader(pSpec->packages->header, RPMTAG_VENDOR, sVendor);
9120+ getRPMHeader(pSpec->packages->header, RPMTAG_PACKAGER, sPackager);
9121+ getRPMHeader(pSpec->packages->header, RPMTAG_LICENSE, sLicense);
9122+ getRPMHeader(pSpec->packages->header, RPMTAG_URL, sURL);
9123+ XMLSpec* pXSpec = new XMLSpec(pSpec->specFile, sName.c_str(), sVersion.c_str(),
9124+ sRelease.c_str(), sEpoch.c_str(), sDistro.c_str(),
9125+ sVendor.c_str(), sPackager.c_str(), sMail.c_str(),
9126+ sLicense.c_str(), sURL.c_str(), pSpec->buildRootURL);
9127+
9128+ // add sources, packages all kinds of funny stuff
9129+ XMLChangelog::structCreate(pSpec, pXSpec);
9130+ XMLSource::structCreate(pSpec->sources, pSpec, pXSpec);
9131+ XMLPackage::structCreate(pSpec->packages, pSpec, pXSpec);
9132+
9133+ // return the created spec
9134+ return pXSpec;
9135+}
9136+
9137+XMLSpec::XMLSpec(const char* szFilename,
9138+ const char* szName,
9139+ const char* szVersion,
9140+ const char* szRelease,
9141+ const char* szEpoch,
9142+ const char* szDistribution,
9143+ const char* szVendor,
9144+ const char* szPackager,
9145+ const char* szPkgrEmail,
9146+ const char* szCopyright,
9147+ const char* szURL,
9148+ const char* szBuildRoot) : XMLBase()
9149+{
9150+ if (szFilename)
9151+ m_sFilename.assign(szFilename);
9152+ if (szName)
9153+ m_sName.assign(szName);
9154+ if (szVersion)
9155+ m_sVersion.assign(szVersion);
9156+ if (szRelease)
9157+ m_sRelease.assign(szRelease);
9158+ if (szEpoch)
9159+ m_sEpoch.assign(szEpoch);
9160+ if (szDistribution)
9161+ m_sDistribution.assign(szDistribution);
9162+ if (szVendor)
9163+ m_sVendor.assign(szVendor);
9164+ if (szPackager)
9165+ m_sPackager.assign(szPackager);
9166+ if (szPkgrEmail)
9167+ m_sPkgrEmail.assign(szPkgrEmail);
9168+ if (szCopyright)
9169+ m_sCopyright.assign(szCopyright);
9170+ if (szURL)
9171+ m_sURL.assign(szURL);
9172+ if (szBuildRoot)
9173+ m_sBuildRoot.assign(szBuildRoot);
9174+}
9175+
9176+XMLSpec::~XMLSpec()
9177+{
9178+}
9179+
9180+void XMLSpec::toSpecFile(ostream& rOut)
9181+{
9182+ for (unsigned int i = 0; i < numXMacros(); i++)
9183+ getXMacro(i).toSpecFile(rOut);
9184+
9185+ rOut << "name: " << getName() << endl;
9186+ rOut << "version: " << getVersion() << endl;
9187+ rOut << "release: " << getRelease() << endl;
9188+ if (hasEpoch())
9189+ rOut << "epoch: " << getEpoch() << endl;
9190+ if (hasCopyright())
9191+ rOut << "copyright: " << getCopyright() << endl;
9192+ if (hasURL())
9193+ rOut << "url: " << getURL() << endl;
9194+ if (hasBuildRoot())
9195+ rOut << "buildroot: " << getBuildRoot() << endl;
9196+ if (hasDistribution())
9197+ rOut << "distribution: " << getDistribution() << endl;
9198+ if (hasVendor())
9199+ rOut << "vendor: " << getVendor() << endl;
9200+ if (hasPackager()) {
9201+ rOut << "packager: " << getPackager();
9202+ if (hasPkgrEmail())
9203+ rOut << " <" << getPkgrEmail() << ">";
9204+ rOut << endl;
9205+ }
9206+
9207+ for (unsigned int i = 0; i < numSources(); i++)
9208+ getSource(i).toSpecFile(rOut);
9209+ //for (unsigned int i = 0; i < numNoSources(); i++)
9210+ // getNoSource(i).toSpecFile(rOut);
9211+ for (unsigned int i = 0; i < numPatches(); i++)
9212+ getPatch(i).toSpecFile(rOut);
9213+ for (unsigned int i = 0; i < numPackages(); i++)
9214+ getPackage(i).toSpecFile(rOut);
9215+
9216+ getPrep().toSpecFile(rOut, "prep");
9217+ getBuild().toSpecFile(rOut, "build");
9218+ getInstall().toSpecFile(rOut, "install");
9219+ getClean().toSpecFile(rOut, "clean");
9220+
9221+ for (unsigned int i = 0; i < numPackages(); i++)
9222+ getPackage(i).toScriptsSpecFile(rOut);
9223+
9224+ for (unsigned int i = 0; i < numPackages(); i++)
9225+ getPackage(i).toFilesSpecFile(rOut);
9226+
9227+ getChangelog().toSpecFile(rOut);
9228+}
9229+
9230+void XMLSpec::toXMLFile(ostream& rOut)
9231+{
9232+ // spec start
9233+ rOut << "<?xml version=\"1.0\"?>";
9234+ rOut << endl << "<spec name=\"" << getName() << "\"";
9235+ rOut << endl << " version=\"" << getVersion() << "\"";
9236+ rOut << endl << " release=\"" << getRelease() << "\"";
9237+ if (hasEpoch())
9238+ rOut << endl << " epoch=\"" << getEpoch() << "\"";
9239+ if (hasCopyright())
9240+ rOut << endl << " copyright=\"" << getCopyright() << "\"";
9241+ if (hasURL())
9242+ rOut << endl << " url=\"" << getURL() << "\"";
9243+ if (hasBuildRoot())
9244+ rOut << endl << " buildroot=\"" << getBuildRoot() << "\"";
9245+ if (hasDistribution())
9246+ rOut << endl << " distribution=\"" << getDistribution() << "\"";
9247+ if (hasVendor())
9248+ rOut << endl << " vendor=\"" << getVendor() << "\"";
9249+ if (hasPackager()) {
9250+ rOut << endl << " packager=\"" << getPackager() << "\"";
9251+ if (hasPkgrEmail())
9252+ rOut << endl << " packager-email=\"" << getPkgrEmail() << "\"";
9253+ }
9254+ rOut << ">";
9255+
9256+ for (unsigned int i = 0; i < numXMacros(); i++)
9257+ getXMacro(i).toXMLFile(rOut);
9258+ for (unsigned int i = 0; i < numSources(); i++)
9259+ getSource(i).toXMLFile(rOut);
9260+ for (unsigned int i = 0; i < numNoSources(); i++)
9261+ getNoSource(i).toXMLFile(rOut);
9262+ for (unsigned int i = 0; i < numPatches(); i++)
9263+ getPatch(i).toXMLFile(rOut);
9264+ for (unsigned int i = 0; i < numPackages(); i++)
9265+ getPackage(i).toXMLFile(rOut);
9266+
9267+ getPrep().toXMLFile(rOut, "prep");
9268+ getBuild().toXMLFile(rOut, "build");
9269+ getInstall().toXMLFile(rOut, "install");
9270+ getClean().toXMLFile(rOut, "clean");
9271+
9272+ getChangelog().toXMLFile(rOut);
9273+
9274+ rOut << endl << "</spec>";
9275+}
9276+
9277+void XMLSpec::toRPMStruct(Spec* pRPMSpec)
9278+{
9279+ Spec spec = newSpec();
9280+ if (hasBuildRoot()) {
9281+ spec->gotBuildRootURL = 1;
9282+ spec->buildRootURL = strdup(getBuildRoot());
9283+ addMacro(spec->macros, "buildroot", NULL, getBuildRoot(), RMIL_SPEC);
9284+ }
9285+ addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
9286+ spec->timeCheck = rpmExpandNumeric("%{_timecheck}");
9287+
9288+ //getChangelog().toRPMStruct(spec);
9289+ /*for (unsigned int i = 0; i < numPackages(); i++)
9290+ getPackage(i).toRPMStruct(pRPMSpec);
9291+ for (unsigned int i = 0; i < numSources(); i++)
9292+ getSource(i).toRPMStruct(pRPMSpec);
9293+ for (unsigned int i = 0; i < numNoSources(); i++)
9294+ getNoSource(i).toRPMStruct(pRPMSpec);
9295+ for (unsigned int i = 0; i < numPatches(); i++)
9296+ getPatch(i).toRPMStruct(pRPMSpec);*/
9297+
9298+ //getPrep().toRPMStruct(spec);
9299+ //getBuild().toRPMStruct(spec);
9300+ //getInstall().toRPMStruct(spec);
9301+ //getClean().toRPMStruct(spec);
9302+
9303+ *pRPMSpec = spec;
9304+}
9305Index: xmlspec/XMLSpec.h
9306===================================================================
9307RCS file: xmlspec/XMLSpec.h
9308diff -N xmlspec/XMLSpec.h
9309--- /dev/null 1 Jan 1970 00:00:00 -0000
9310+++ rpm/xmlspec/XMLSpec.h 28 Aug 2002 10:52:43 -0000 1.2.2.1
9311@@ -0,0 +1,678 @@
9312+#ifndef _H_XMLSPEC_
9313+#define _H_XMLSPEC_
9314+
9315+// standard C++ includes
9316+#include <iostream>
9317+#include <string>
9318+#include <vector>
9319+
9320+// our includes
9321+#include "XMLAttrs.h"
9322+#include "XMLBase.h"
9323+#include "XMLChangelog.h"
9324+#include "XMLMacro.h"
9325+#include "XMLPackage.h"
9326+#include "XMLScript.h"
9327+#include "XMLSource.h"
9328+
9329+// rpm includes
9330+#include <rpmbuild.h>
9331+
9332+using namespace std;
9333+
9334+// <spec ...>
9335+class XMLSpec : public XMLBase
9336+{
9337+//
9338+// static object creation functions
9339+//
9340+public:
9341+ /**
9342+ * Creates an XMLSpec from values parsed
9343+ * .
9344+ * @param pAttrs The XML attributes
9345+ * @param szFilename The XML spec filename
9346+ * @return Pointer to the created spec
9347+ **/
9348+ static XMLSpec* parseCreate(XMLAttrs* pAttrs,
9349+ const char* szFilename);
9350+
9351+ /**
9352+ * Creates and XMLSpec from an RPM Spec structure
9353+ * .
9354+ * @param pSpec The RPM spec structure
9355+ * @return Pointer to the created spec
9356+ **/
9357+ static XMLSpec* structCreate(Spec pSpec);
9358+
9359+//
9360+// constructors/destructor
9361+//
9362+public:
9363+ /**
9364+ * Default constructor
9365+ * .
9366+ * @param szFilename Filename of the spec on disk
9367+ * @param szName spec name
9368+ * @param szVersion Spec version
9369+ * @param szRelease spec release
9370+ * @param szEpoch spec epoch
9371+ * @param szDistribution spec distribution
9372+ * @param szVendor spec vendor
9373+ * @param szPackage spec packager
9374+ * @param szPkgEmail email address for the packager
9375+ * @param szCopyright spec copyright/licence
9376+ * @param szURL main package url
9377+ * @param szBuildRoot buildroot
9378+ * @return none
9379+ **/
9380+ XMLSpec(const char* szFilename,
9381+ const char* szName,
9382+ const char* szVersion,
9383+ const char* szRelease,
9384+ const char* szEpoch,
9385+ const char* szDistribution,
9386+ const char* szVendor,
9387+ const char* szPackager,
9388+ const char* szPkgrEmail,
9389+ const char* szCopyright,
9390+ const char* szURL,
9391+ const char* szBuildRoot);
9392+
9393+ /**
9394+ * Destructor
9395+ * .
9396+ * @param none
9397+ * @return none
9398+ **/
9399+ ~XMLSpec();
9400+
9401+//
9402+// public member functions
9403+//
9404+public:
9405+ /**
9406+ * Converts the spec object to a normal RPM spec file
9407+ * .
9408+ * @param rOut Reference to the stream to write the information to
9409+ * @return none
9410+ **/
9411+ void toSpecFile(ostream& rOut);
9412+
9413+ /**
9414+ * Converts the spec object to an XML spec file
9415+ * .
9416+ * @param rOut Reference to the stream to write the information to
9417+ * @return none
9418+ **/
9419+ void toXMLFile(ostream& rOut);
9420+
9421+ /**
9422+ * Converts the spec object to an internal RPM structure
9423+ * .
9424+ * @param none
9425+ * @return the created RPM structure
9426+ **/
9427+ void toRPMStruct(Spec* pRPMSpec);
9428+
9429+//
9430+// member variable get/set functions
9431+//
9432+public:
9433+ /**
9434+ * Adds a package to the internal list
9435+ * .
9436+ * @param rPkg Reference to the package to add
9437+ * @return none
9438+ **/
9439+ void addPackage(XMLPackage& rPkg)
9440+ {
9441+ m_vPackages.push_back(rPkg);
9442+ }
9443+
9444+ /**
9445+ * Gets the number of packages
9446+ * .
9447+ * @param none
9448+ * @return the number of packages
9449+ **/
9450+ unsigned int numPackages()
9451+ {
9452+ return m_vPackages.size();
9453+ }
9454+
9455+ /**
9456+ * Gets a specific package
9457+ * .
9458+ * @param nNum The package number
9459+ * @return the required package
9460+ **/
9461+ XMLPackage& getPackage(unsigned int nNum)
9462+ {
9463+ return m_vPackages[nNum];
9464+ }
9465+
9466+ /**
9467+ * Gets the last package added
9468+ * .
9469+ * @param none
9470+ * @return the last package added
9471+ **/
9472+ XMLPackage& lastPackage()
9473+ {
9474+ return m_vPackages[numPackages()-1];
9475+ }
9476+
9477+ /**
9478+ * Adds a source to the internal list
9479+ * .
9480+ * @param rSource Reference to the source to add
9481+ * @return none
9482+ **/
9483+ void addSource(XMLSource& rSource)
9484+ {
9485+ m_vSources.push_back(rSource);
9486+ }
9487+
9488+ /**
9489+ * Gets the number of sources
9490+ * .
9491+ * @param none
9492+ * @return the number of sources
9493+ **/
9494+ unsigned int numSources()
9495+ {
9496+ return m_vSources.size();
9497+ }
9498+
9499+ /**
9500+ * Gets a specific source
9501+ * .
9502+ * @param nNum The source number
9503+ * @return the required source
9504+ **/
9505+ XMLSource& getSource(unsigned int nNum)
9506+ {
9507+ return m_vSources[nNum];
9508+ }
9509+
9510+ /**
9511+ * Gets the last source added
9512+ * .
9513+ * @param none
9514+ * @return the last source added
9515+ **/
9516+ XMLSource& lastSource()
9517+ {
9518+ return m_vSources[numSources()-1];
9519+ }
9520+
9521+ /**
9522+ * Adds a source to the internal list
9523+ * .
9524+ * @param rSource Reference to the source to add
9525+ * @return none
9526+ **/
9527+ void addNoSource(XMLNoSource& rSource)
9528+ {
9529+ m_vNoSources.push_back(rSource);
9530+ }
9531+
9532+ /**
9533+ * Gets the number of nosources
9534+ * .
9535+ * @param none
9536+ * @return the number of nsources
9537+ **/
9538+ unsigned int numNoSources()
9539+ {
9540+ return m_vNoSources.size();
9541+ }
9542+
9543+ /**
9544+ * Gets a specific nosource
9545+ * .
9546+ * @param nNum The nosource number
9547+ * @return the required nosource
9548+ **/
9549+ XMLNoSource& getNoSource(unsigned int nNum)
9550+ {
9551+ return m_vNoSources[nNum];
9552+ }
9553+
9554+ /**
9555+ * Gets the last nosource added
9556+ * .
9557+ * @param none
9558+ * @return the last nosource added
9559+ **/
9560+ XMLNoSource& lastNoSource()
9561+ {
9562+ return m_vNoSources[numNoSources()-1];
9563+ }
9564+
9565+ /**
9566+ * Adds a patch to the internal list
9567+ * .
9568+ * @param rSource Reference to the patch to add
9569+ * @return none
9570+ **/
9571+ void addPatch(XMLPatch& rSource)
9572+ {
9573+ m_vPatches.push_back(rSource);
9574+ }
9575+
9576+ /**
9577+ * Gets the number of patches
9578+ * .
9579+ * @param none
9580+ * @return the number of patches
9581+ **/
9582+ unsigned int numPatches()
9583+ {
9584+ return m_vPatches.size();
9585+ }
9586+
9587+ /**
9588+ * Gets a specific patch
9589+ * .
9590+ * @param nNum The patch number
9591+ * @return the required patch
9592+ **/
9593+ XMLPatch& getPatch(unsigned int nNum)
9594+ {
9595+ return m_vPatches[nNum];
9596+ }
9597+
9598+ /**
9599+ * Gets the last patch added
9600+ * .
9601+ * @param none
9602+ * @return the last patch added
9603+ **/
9604+ XMLPatch& lastPatch()
9605+ {
9606+ return m_vPatches[numPatches()-1];
9607+ }
9608+
9609+ /**
9610+ * Adds a macro to the internal list
9611+ * .
9612+ * @param rMacro Reference to the macro to add
9613+ * @return none
9614+ **/
9615+ void addXMacro(XMLMacro& rMacro)
9616+ {
9617+ m_vMacros.push_back(rMacro);
9618+ }
9619+
9620+ /**
9621+ * Gets the number of macros
9622+ * .
9623+ * @param none
9624+ * @return the number of macros
9625+ **/
9626+ unsigned int numXMacros()
9627+ {
9628+ return m_vMacros.size();
9629+ }
9630+
9631+ /**
9632+ * Gets a specific macro
9633+ * .
9634+ * @param nNum The macro number
9635+ * @return the required macro
9636+ **/
9637+ XMLMacro& getXMacro(unsigned int nNum)
9638+ {
9639+ return m_vMacros[nNum];
9640+ }
9641+
9642+ /**
9643+ * Checks if we have a filename
9644+ * .
9645+ * @param none
9646+ * @return true if available, false otherwise
9647+ **/
9648+ bool hasFilename()
9649+ {
9650+ return m_sFilename.length() ? true : false;
9651+ }
9652+
9653+ /**
9654+ * Gets the filename
9655+ * .
9656+ * @param none
9657+ * @return string containing the filename
9658+ **/
9659+ const char* getFilename()
9660+ {
9661+ return m_sFilename.c_str();
9662+ }
9663+
9664+ /**
9665+ * Checks if we have a name
9666+ * .
9667+ * @param none
9668+ * @return true if available, false otherwise
9669+ **/
9670+ bool hasName()
9671+ {
9672+ return m_sName.length() ? true : false;
9673+ }
9674+
9675+ /**
9676+ * Gets the name
9677+ * .
9678+ * @param none
9679+ * @return string containing the name
9680+ **/
9681+ const char* getName()
9682+ {
9683+ return m_sName.c_str();
9684+ }
9685+
9686+ /**
9687+ * Checks if we have a version
9688+ * .
9689+ * @param none
9690+ * @return true if available, false otherwise
9691+ **/
9692+ bool hasVersion()
9693+ {
9694+ return m_sVersion.length() ? true : false;
9695+ }
9696+
9697+ /**
9698+ * Gets the version
9699+ * .
9700+ * @param none
9701+ * @return string containing the version
9702+ **/
9703+ const char* getVersion()
9704+ {
9705+ return m_sVersion.c_str();
9706+ }
9707+
9708+ /**
9709+ * Checks if we have a release
9710+ * .
9711+ * @param none
9712+ * @return true if available, false otherwise
9713+ **/
9714+ bool hasRelease()
9715+ {
9716+ return m_sRelease.length() ? true : false;
9717+ }
9718+
9719+ /**
9720+ * Gets the release
9721+ * .
9722+ * @param none
9723+ * @return string containing the release
9724+ **/
9725+ const char* getRelease()
9726+ {
9727+ return m_sRelease.c_str();
9728+ }
9729+
9730+ /**
9731+ * Checks if we have a epoch
9732+ * .
9733+ * @param none
9734+ * @return true if available, false otherwise
9735+ **/
9736+ bool hasEpoch()
9737+ {
9738+ return m_sEpoch.length() ? true : false;
9739+ }
9740+
9741+ /**
9742+ * Gets the epoch
9743+ * .
9744+ * @param none
9745+ * @return string containing the epoch
9746+ **/
9747+ const char* getEpoch()
9748+ {
9749+ return m_sEpoch.c_str();
9750+ }
9751+
9752+ /**
9753+ * Checks if we have a distribution
9754+ * .
9755+ * @param none
9756+ * @return true if available, false otherwise
9757+ **/
9758+ bool hasDistribution()
9759+ {
9760+ return m_sDistribution.length() ? true : false;
9761+ }
9762+
9763+ /**
9764+ * Gets the distribution
9765+ * .
9766+ * @param none
9767+ * @return string containing the distribution
9768+ **/
9769+ const char* getDistribution()
9770+ {
9771+ return m_sDistribution.c_str();
9772+ }
9773+
9774+ /**
9775+ * Checks if we have a vendor
9776+ * .
9777+ * @param none
9778+ * @return true if available, false otherwise
9779+ **/
9780+ bool hasVendor()
9781+ {
9782+ return m_sVendor.length() ? true : false;
9783+ }
9784+
9785+ /**
9786+ * Gets the vendor
9787+ * .
9788+ * @param none
9789+ * @return string containing the vendor
9790+ **/
9791+ const char* getVendor()
9792+ {
9793+ return m_sVendor.c_str();
9794+ }
9795+
9796+ /**
9797+ * Checks if we have a packager
9798+ * .
9799+ * @param none
9800+ * @return true if available, false otherwise
9801+ **/
9802+ bool hasPackager()
9803+ {
9804+ return m_sPackager.length() ? true : false;
9805+ }
9806+
9807+ /**
9808+ * Gets the packager
9809+ * .
9810+ * @param none
9811+ * @return string containing the packager
9812+ **/
9813+ const char* getPackager()
9814+ {
9815+ return m_sPackager.c_str();
9816+ }
9817+
9818+ /**
9819+ * Checks if we have a packager email
9820+ * .
9821+ * @param none
9822+ * @return true if available, false otherwise
9823+ **/
9824+ bool hasPkgrEmail()
9825+ {
9826+ return m_sPkgrEmail.length() ? true : false;
9827+ }
9828+
9829+ /**
9830+ * Gets the packager's email address
9831+ * .
9832+ * @param none
9833+ * @return string containing the packager's email address
9834+ **/
9835+ const char* getPkgrEmail()
9836+ {
9837+ return m_sPkgrEmail.c_str();
9838+ }
9839+
9840+ /**
9841+ * Checks if we have a copyright
9842+ * .
9843+ * @param none
9844+ * @return true if available, false otherwise
9845+ **/
9846+ bool hasCopyright()
9847+ {
9848+ return m_sCopyright.length() ? true : false;
9849+ }
9850+
9851+ /**
9852+ * Gets the copyright
9853+ * .
9854+ * @param none
9855+ * @return string containing the copyright
9856+ **/
9857+ const char* getCopyright()
9858+ {
9859+ return m_sCopyright.c_str();
9860+ }
9861+
9862+ /**
9863+ * Checks if we have an URL
9864+ * .
9865+ * @param none
9866+ * @return true if available, false otherwise
9867+ **/
9868+ bool hasURL()
9869+ {
9870+ return m_sURL.length() ? true : false;
9871+ }
9872+
9873+ /**
9874+ * Gets the URL
9875+ * .
9876+ * @param none
9877+ * @return string containing the URL
9878+ **/
9879+ const char* getURL()
9880+ {
9881+ return m_sURL.c_str();
9882+ }
9883+
9884+ /**
9885+ * Checks if we have a BuildRoot
9886+ * .
9887+ * @param none
9888+ * @return true if available, false otherwise
9889+ **/
9890+ bool hasBuildRoot()
9891+ {
9892+ return m_sBuildRoot.length() ? true : false;
9893+ }
9894+
9895+ /**
9896+ * Gets the buildroot
9897+ * .
9898+ * @param none
9899+ * @return string containing the buildroor
9900+ **/
9901+ const char* getBuildRoot()
9902+ {
9903+ return m_sBuildRoot.c_str();
9904+ }
9905+
9906+ /**
9907+ * Gets the prep section
9908+ * .
9909+ * @param none
9910+ * @return reference to the prep section
9911+ **/
9912+ XMLScripts& getPrep()
9913+ {
9914+ return m_Prep;
9915+ }
9916+
9917+ /**
9918+ * Gets the build section
9919+ * .
9920+ * @param none
9921+ * @return reference to the build section
9922+ **/
9923+ XMLScripts& getBuild()
9924+ {
9925+ return m_Build;
9926+ }
9927+
9928+ /**
9929+ * Gets the install section
9930+ * .
9931+ * @param none
9932+ * @return reference to the install section
9933+ **/
9934+ XMLScripts& getInstall()
9935+ {
9936+ return m_Install;
9937+ }
9938+
9939+ /**
9940+ * Gets the clean section
9941+ * .
9942+ * @param none
9943+ * @return reference to the clean section
9944+ **/
9945+ XMLScripts& getClean()
9946+ {
9947+ return m_Clean;
9948+ }
9949+
9950+ /**
9951+ * Gets the changelog section
9952+ * .
9953+ * @param none
9954+ * @return reference to the changelog section
9955+ **/
9956+ XMLChangelog& getChangelog()
9957+ {
9958+ return m_Changelog;
9959+ }
9960+
9961+//
9962+// internal member variables
9963+//
9964+protected:
9965+ string m_sFilename;
9966+ string m_sName;
9967+ string m_sVersion;
9968+ string m_sRelease;
9969+ string m_sEpoch;
9970+ string m_sDistribution;
9971+ string m_sVendor;
9972+ string m_sPackager;
9973+ string m_sPkgrEmail;
9974+ string m_sCopyright;
9975+ string m_sURL;
9976+ string m_sBuildRoot;
9977+ vector<XMLPackage> m_vPackages;
9978+ vector<XMLSource> m_vSources;
9979+ vector<XMLNoSource> m_vNoSources;
9980+ vector<XMLPatch> m_vPatches;
9981+ vector<XMLMacro> m_vMacros;
9982+ XMLScripts m_Prep;
9983+ XMLScripts m_Build;
9984+ XMLScripts m_Install;
9985+ XMLScripts m_Clean;
9986+ XMLChangelog m_Changelog;
9987+};
9988+
9989+#endif
9990Index: xmlspec/XMLText.cpp
9991===================================================================
9992RCS file: xmlspec/XMLText.cpp
9993diff -N xmlspec/XMLText.cpp
9994--- /dev/null 1 Jan 1970 00:00:00 -0000
9995+++ rpm/xmlspec/XMLText.cpp 28 Aug 2002 10:52:43 -0000 1.1.2.1
9996@@ -0,0 +1,23 @@
9997+// our includes
9998+#include "XMLText.h"
9999+
10000+using namespace std;
10001+
10002+XMLText::XMLText(const char* szText,
10003+ const char* szLang)
10004+ : XMLBase()
10005+{
10006+ setText(szText);
10007+ setLang(szLang);
10008+}
10009+
10010+XMLText::XMLText(const XMLText& rText)
10011+ : XMLBase()
10012+{
10013+ setText(rText.m_sText.c_str());
10014+ setLang(rText.m_sLang.c_str());
10015+}
10016+
10017+XMLText::~XMLText()
10018+{
10019+}
10020Index: xmlspec/XMLText.h
10021===================================================================
10022RCS file: xmlspec/XMLText.h
10023diff -N xmlspec/XMLText.h
10024--- /dev/null 1 Jan 1970 00:00:00 -0000
10025+++ rpm/xmlspec/XMLText.h 28 Aug 2002 10:52:43 -0000 1.1.2.1
10026@@ -0,0 +1,119 @@
10027+#ifndef _H_XMLTEXT_
10028+#define _H_XMLTEXT_
10029+
10030+// standard c++ includes
10031+#include <string>
10032+
10033+// our includes
10034+#include "XMLBase.h"
10035+
10036+using namespace std;
10037+
10038+class XMLText : public XMLBase
10039+{
10040+//
10041+// constructors/destructor
10042+//
10043+public:
10044+ /**
10045+ * Default constructor
10046+ * .
10047+ * @param szText The text to add
10048+ * @param szLang The text's language
10049+ * @return none
10050+ **/
10051+ XMLText(const char* szText,
10052+ const char* szLang = NULL);
10053+
10054+ /**
10055+ * Copy constructor
10056+ * .
10057+ * @param rText reference to the text to copy
10058+ * @return none
10059+ **/
10060+ XMLText(const XMLText& rText);
10061+
10062+ /**
10063+ * Default destructor
10064+ * .
10065+ * @param none
10066+ * @return none
10067+ **/
10068+ ~XMLText();
10069+
10070+//
10071+// get/set methods for internal variables
10072+//
10073+public:
10074+ /**
10075+ * Sets the text
10076+ * .
10077+ * @param szText The text
10078+ * @return none
10079+ **/
10080+ void setText(const char* szText)
10081+ {
10082+ if (szText)
10083+ m_sText.assign(szText);
10084+ }
10085+
10086+ /**
10087+ * Gets the text
10088+ * .
10089+ * @param none
10090+ * @return string containing the text
10091+ **/
10092+ const char* getText()
10093+ {
10094+ return m_sText.c_str();
10095+ }
10096+
10097+ /**
10098+ * Tests if we have a language for this description
10099+ * .
10100+ * @param none
10101+ * @return true if we have a language, false otherwise
10102+ **/
10103+ bool hasLang()
10104+ {
10105+ return m_sLang.length() ? true : false;
10106+ }
10107+
10108+ /**
10109+ * Sets the language
10110+ * .
10111+ * @param szLang The language
10112+ * @return none
10113+ **/
10114+ void setLang(const char* szLang)
10115+ {
10116+ if (szLang) {
10117+ // FIXME: We need to get the actual default language as specified
10118+ // in one of the RPM headers (which I cannot find now) and
10119+ // substitute it here. (I know the value is "C", bu we should
10120+ // use the define.)
10121+ if (strcmp(szLang, "C") != 0)
10122+ m_sLang.assign(szLang);
10123+ }
10124+ }
10125+
10126+ /**
10127+ * Gets the language
10128+ * .
10129+ * @param none
10130+ * @return string containing the language
10131+ **/
10132+ const char* getLang()
10133+ {
10134+ return m_sLang.c_str();
10135+ }
10136+
10137+//
10138+// member variables
10139+//
10140+public:
10141+ string m_sText;
10142+ string m_sLang;
10143+};
10144+
10145+#endif
10146Index: xmlspec/example.spec.xml
10147===================================================================
10148RCS file: xmlspec/example.spec.xml
10149diff -N xmlspec/example.spec.xml
10150--- /dev/null 1 Jan 1970 00:00:00 -0000
10151+++ rpm/xmlspec/example.spec.xml 28 Aug 2002 10:52:43 -0000 1.3.2.1
10152@@ -0,0 +1,188 @@
10153+<?xml version="1.0"?>
10154+<!--
10155+ This is an example XML spec file to demonstrate the xml2spec
10156+ conversion program. By running "xml2spec example.spec.xml" it
10157+ will create an output spec in "normal" RPM spec format, ready
10158+ for comsumption by rpmbuild.
10159+-->
10160+<spec name="example"
10161+ version="1.0"
10162+ release="06"
10163+ copyright="GPL"
10164+ url="http://www.rpm.org/"
10165+ distribution="Any distribution"
10166+ vendor="rpm.org"
10167+ packager="Jaco Greeff"
10168+ packager-email="jaco@puxedo.org"
10169+ buildroot="%{tmppath}/lvr-%{name}-build">
10170+
10171+ <macro name="test">value is this</macro>
10172+
10173+ <source name="rpm-4.0.4.tar.bz2"
10174+ num="0"
10175+ size="4296845"
10176+ md5="bb80a5d06a48623ecbe3f2d41cac15f9">
10177+ <mirror path="ftp://ftp.rpm.org/"
10178+ description="Main RPM FTP site" />
10179+ <mirror path="http://www.puxedo.org/downloads/source/"
10180+ description="puxedo.org source distribution"
10181+ country="za" />
10182+ </source>
10183+ <source name="expat-1.95.2.tar.bz2"
10184+ num="1"
10185+ size="156575"
10186+ md5="919c78ddaf7f319b7e07792309ae2f22">
10187+ <mirror path="http://expat.sourceforge.net/"
10188+ description="SourceForge Mirror"
10189+ country="us" />
10190+ </source>
10191+
10192+ <patch name="example-1.0-1.patch.bz2"
10193+ num="0"
10194+ size="3276"
10195+ md5="467c78cbdf75619b7e0abc2309ae2f11" />
10196+
10197+ <nosource name="nosource-sample-0.98.bz2"
10198+ num="33" />
10199+
10200+ <package group="System/Libraries">
10201+ <buildrequires>
10202+ <package name="automake" />
10203+ <package name="autoconf" />
10204+ <package name="bash" />
10205+ <package name="binutils" />
10206+ <package name="gcc" />
10207+ <package name="glibc-devel" />
10208+ </buildrequires>
10209+ <requires>
10210+ <package name="gcc" cmp="ge" version="2.95" />
10211+ <package name="glibc" cmp="ge" version="2.2" />
10212+ <package name="libogg" />
10213+ </requires>
10214+ <provides>
10215+ <package name="%{name}" />
10216+ </provides>
10217+ <obsoletes>
10218+ <package name="old-example" />
10219+ </obsoletes>
10220+ <summary>This spec is just an example for some funny purpose.</summary>
10221+ <summary lang="af">Hierdie is net 'n toets vir i18n in die opsomming</summary>
10222+ <description>%{summary}</description>
10223+ <description lang="af">Nog 'n toets, hierdie keer in die beskrywing</description>
10224+ <post>
10225+ <script interpreter="/bin/sh">/sbin/ldconfig</script>
10226+ </post>
10227+ <postun>
10228+ <script>/sbin/ldconfig</script>
10229+ </postun>
10230+ <files>
10231+ <file user="root" group="root">/usr/lib/*.so*</file>
10232+ </files>
10233+ </package>
10234+
10235+ <package name="devel"
10236+ group="Development/Libraries">
10237+ <requires>
10238+ <package name="%{name}" />
10239+ <package name="libtool" />
10240+ <package name="m4" />
10241+ </requires>
10242+ <summary>The libvorbis-devel package contains development headers.</summary>
10243+ <description>%{summary}</description>
10244+ <pre>
10245+ <script>some pre stuff under devel</script>
10246+ <script dir="/here/while/we/are/at/it">That ^^^ changed directory</script>
10247+ </pre>
10248+ <files user="root"
10249+ group="root">
10250+ <file>/usr/include/*.h</file>
10251+ <file group="rpm">/usr/lib/*.la</file>
10252+ <file user="rpm">/usr/share/aclocal/*</file>
10253+ <file mode="777">/usr/share/m4/*</file>
10254+ <file user="user" group="group" mode="444">/usr/share/man/*</file>
10255+ </files>
10256+ </package>
10257+
10258+ <package name="toys" sub="no" group="Application/Toys">
10259+ <requires>
10260+ <package name="%{name}" />
10261+ </requires>
10262+ <obsoletes>
10263+ <package name="oldtoys" />
10264+ </obsoletes>
10265+ <summary>The toys package contains toys</summary>
10266+ <description>%{summary}</description>
10267+ <preun>
10268+ <script>some preun stuff under toys</script>
10269+ </preun>
10270+ <verify>
10271+ <script>Some verify stuff under toys</script>
10272+ </verify>
10273+ <files>
10274+ <file>/usr/doc/*</file>
10275+ </files>
10276+ </package>
10277+
10278+ <prep>
10279+ <script>rm -rf $RPM_BUILD_DIR/%{name}-%{version}rc3</script>
10280+ <script>rm -rf %{buildroot}</script>
10281+ <setup path="%{name}-%{version}rc3" />
10282+ </prep>
10283+
10284+ <build>
10285+ <script>./configure --prefix=/usr</script>
10286+ <script>make PROFILE=&apos;-Wall -W -pg -g -O2 -ffast-math -D_REENTRANT -fsigned-char -fno-inline -static' CFLAGS='-O2 -ffast-math -D_REENTRANT -fsigned-char -DUSE_MEMORY_H&apos;</script>
10287+ </build>
10288+
10289+ <install>
10290+ <script>make DESTDIR=%{buildroot} install</script>
10291+ </install>
10292+
10293+ <clean>
10294+ <script>rm -rf %{buildroot}</script>
10295+ <script>rm -rf $RPM_BUILD_DIR/%{name}-%{version}rc3</script>
10296+ </clean>
10297+
10298+ <changelog>
10299+ <changes date="Wed Jun 05 2002"
10300+ author="Jaco Greeff"
10301+ author-email="jaco@puxedo.org"
10302+ version="1.0-06">
10303+ <change>Changed spec to make sure the output spec file can be understood by RPM</change>
10304+ <change>Added languages (description/summary) and a test in Afrikaans</change>
10305+ </changes>
10306+ <changes date="Mon Jun 03 2002"
10307+ author="Jaco Greeff"
10308+ author-email="jaco@puxedo.org"
10309+ version="1.0-05">
10310+ <change>Changed file attributes to mode, user and group</change>
10311+ </changes>
10312+ <changes date="Thu May 30 2002"
10313+ author="Jaco Greeff"
10314+ author-email="jaco@puxedo.org"
10315+ version="1.0-04">
10316+ <change>Added attribute &quot;interpreter&quot; to script</change>
10317+ </changes>
10318+ <changes date="Sat May 25 2002"
10319+ author="Jaco Greeff"
10320+ author-email="jaco@puxedo.org"
10321+ version="1.0-03">
10322+ <change>Moved &lt;files&gt; into &lt;package&gt; structure</change>
10323+ <change>Added &lt;nosource&gt; tag as example</change>
10324+ <change>Changed &lt;shell&gt; to &lt;script&gt;</change>
10325+ </changes>
10326+ <changes date="Sun May 19 2002"
10327+ author="Jaco Greeff"
10328+ author-email="jaco@puxedo.org"
10329+ version="1.0-02">
10330+ <change>Changed the formatting of the XML file to fit in with new implementation</change>
10331+ <change>Commented the spec to allow others to understand it as well</change>
10332+ </changes>
10333+ <changes date="Wed May 15 2002"
10334+ author="Jaco Greeff"
10335+ author-email="jaco@puxedo.org"
10336+ version="1.0-01">
10337+ <change>Converted spec file to .spec.xml file for illustrative purposes</change>
10338+ </changes>
10339+ </changelog>
10340+</spec>
10341Index: xmlspec/spec2xml.cpp
10342===================================================================
10343RCS file: xmlspec/spec2xml.cpp
10344diff -N xmlspec/spec2xml.cpp
10345--- /dev/null 1 Jan 1970 00:00:00 -0000
10346+++ rpm/xmlspec/spec2xml.cpp 28 Aug 2002 10:52:43 -0000 1.1.2.1
10347@@ -0,0 +1,62 @@
10348+// standard C++ includes
10349+#include <fstream>
10350+
10351+// our includes
10352+#include "XMLSpec.h"
10353+
10354+// rpm includes
10355+#include <rpmbuild.h>
10356+
10357+// display some usage
10358+int usage()
10359+{
10360+ printf("Usage: spec2xml input [output]\n");
10361+ printf("Converts the input pkg.spec file to a pkg.spec.xml\n");
10362+ printf("file for use in an rpmbuild command.\n\n");
10363+ return 1;
10364+}
10365+
10366+// program entry point
10367+int main(int argc,
10368+ char** argv)
10369+{
10370+ printf("\nspec2xml, version 0.01\n");
10371+ if (argc != 2 && argc != 3) {
10372+ usage();
10373+ return 1;
10374+ }
10375+
10376+ Spec pSpec = NULL;
10377+ printf("Parsing RPM spec %s:\n", argv[1]);
10378+ if (!parseSpec(&pSpec, argv[1], "/", "/var/tmp", 0, NULL, NULL, 1, 0)) {
10379+ printf("\tOk, spec parsed.\n");
10380+ printf("Creating XML structures:\n");
10381+ XMLSpec* pXSpec = XMLSpec::structCreate(pSpec);
10382+ if (pXSpec) {
10383+ printf("\tOk, structures created.\n");
10384+ if (argc == 3) {
10385+ printf("Writing XML to %s ... ", argv[2]);
10386+ ofstream fOut(argv[2]);
10387+ if (fOut.is_open()) {
10388+ pXSpec->toXMLFile(fOut);
10389+ fOut.close();
10390+ printf("Ok.\n");
10391+ }
10392+ else {
10393+ delete pSpec;
10394+ printf("Failed.\n");
10395+ return 2;
10396+ }
10397+ }
10398+ else if (argc == 2) {
10399+ pXSpec->toXMLFile(cout);
10400+ }
10401+
10402+ delete pSpec;
10403+ return 0;
10404+ }
10405+ }
10406+
10407+ printf("\tFailed.\n");
10408+ return 3;
10409+}
10410Index: xmlspec/xml2rpm.c
10411===================================================================
10412RCS file: rpm/xmlspec/xml2rpm.c,v
10413retrieving revision 1.2.2.1
10414retrieving revision 1.2.2.2
10415diff -u -u -r1.2.2.1 -r1.2.2.2
10416--- rpm/xmlspec/xml2rpm.c 28 Aug 2002 10:52:43 -0000 1.2.2.1
10417+++ rpm/xmlspec/xml2rpm.c 10 Oct 2002 22:47:59 -0000 1.2.2.2
10418@@ -8,6 +8,10 @@
10419 #include "xml2rpm.h"
10420 #include "xmlstruct.h"
10421
10422+#ifdef XML_DEBUG
10423+#include "header_internal.h"
10424+#endif
10425+
10426 // This is where our packaged scripts start (or the largest number
10427 // of the sources)
10428 int g_nMaxSourceNum = 511;
10429@@ -304,8 +308,14 @@
10430 createRPMSource(pScript->m_szScript, g_nMaxSourceNum+1,
10431 pSpec, RPMBUILD_ISSOURCE);
10432 }
10433- if (pScript->m_szEntry)
10434- appendLineStringBuf(pSb, pScript->m_szEntry);
10435+ if (pScript->m_szEntry) {
10436+ // we do a newStrEx to make sure we expand all
10437+ // macros, as is done in the case of the files
10438+ // (done as part of the fileToStr call)
10439+ newStrEx(pScript->m_szEntry, (char**)(&szTmp));
10440+ appendLineStringBuf(pSb, szTmp);
10441+ freeStr(&(szTmp));
10442+ }
10443 pScript = pScript->m_pNext;
10444 }
10445 }
10446@@ -335,6 +345,32 @@
10447 pScripts->m_szInterpreter, 1);
10448 }
10449
10450+void handleProvObsConf(Header pHeader, t_structXMLRequire* pReqs, rpmsenseFlags fSense)
10451+{
10452+ t_structXMLRequire* pReq = NULL;
10453+ int nFlags = 0;
10454+ int i = 0;
10455+ int nIndex = 0;
10456+
10457+ pReq = pReqs;
10458+ while (pReq) {
10459+ if (pReq->m_szName) {
10460+ nFlags = 0;
10461+ if (pReq->m_szCompare && pReq->m_szVersion) {
10462+ for (i = 0; sReqComp[i].m_szCmp; i++) {
10463+ if (!strcasecmp(sReqComp[i].m_szCmp,
10464+ pReq->m_szCompare)) {
10465+ nFlags = (sReqComp[i].m_rpmCmp | RPMSENSE_ANY) & ~RPMSENSE_SENSEMASK;
10466+ }
10467+ }
10468+ }
10469+ addReqProv(NULL, pHeader, fSense | nFlags,
10470+ pReq->m_szName, pReq->m_szVersion, nIndex++);
10471+ }
10472+ pReq = pReq->m_pNext;
10473+ }
10474+}
10475+
10476 void convertXMLPackage(const t_structXMLPackage* pXMLPkg,
10477 const t_structXMLSpec* pXMLSpec,
10478 Spec pSpec)
10479@@ -364,6 +400,11 @@
10480 _free(szArch);
10481 _free(szOs);
10482
10483+ // do the provides, obsoletes, conflicts
10484+ handleProvObsConf(pPkg->header, pXMLPkg->m_pProvides, RPMSENSE_PROVIDES);
10485+ handleProvObsConf(pPkg->header, pXMLPkg->m_pObsoletes, RPMSENSE_OBSOLETES);
10486+ handleProvObsConf(pPkg->header, pXMLPkg->m_pConflicts, RPMSENSE_CONFLICTS);
10487+
10488 if (pXMLPkg->m_szName)
10489 headerAddOrAppendEntry(pPkg->header, RPMTAG_NAME,
10490 RPM_STRING_TYPE, pXMLPkg->m_szName, 1);
10491@@ -514,7 +555,7 @@
10492 pSpec->build = scriptsToStringBuf(pXMLSpec->m_pBuild, pSpec);
10493 pSpec->install = scriptsToStringBuf(pXMLSpec->m_pInstall, pSpec);
10494 pSpec->clean = scriptsToStringBuf(pXMLSpec->m_pClean, pSpec);
10495-
10496+
10497 convertXMLPackage(pXMLSpec->m_pPackages, pXMLSpec, pSpec);
10498
10499 initSourceHeader(pSpec);
10500Index: xmlspec/xml2spec.cpp
10501===================================================================
10502RCS file: xmlspec/xml2spec.cpp
10503diff -N xmlspec/xml2spec.cpp
10504--- /dev/null 1 Jan 1970 00:00:00 -0000
10505+++ rpm/xmlspec/xml2spec.cpp 28 Aug 2002 10:52:43 -0000 1.2.2.1
10506@@ -0,0 +1,52 @@
10507+// standard C++ includes
10508+#include <fstream>
10509+
10510+// our includes
10511+#include "XMLParser.h"
10512+#include "XMLSpec.h"
10513+
10514+// display some usage
10515+int usage()
10516+{
10517+ printf("Usage: xml2spec input [output]\n");
10518+ printf("Converts the input pkg.spec.xml file to a pkg.spec\n");
10519+ printf("file for use in an rpmbuild command.\n\n");
10520+ return 1;
10521+}
10522+
10523+// program entry point
10524+int main(int argc,
10525+ char** argv)
10526+{
10527+ printf("\nxml2spec, version 0.01\n");
10528+ if (argc != 2 && argc != 3) {
10529+ usage();
10530+ return 1;
10531+ }
10532+
10533+ XMLSpec* pSpec = NULL;
10534+ if (parseXMLSpec(argv[1], pSpec) == 0 && pSpec) {
10535+ if (argc == 3) {
10536+ printf("Writing spec to %s ... ", argv[2]);
10537+ ofstream fOut(argv[2]);
10538+ if (fOut.is_open()) {
10539+ pSpec->toSpecFile(fOut);
10540+ fOut.close();
10541+ printf("Ok.\n");
10542+ }
10543+ else {
10544+ delete pSpec;
10545+ printf("Failed.\n");
10546+ return 2;
10547+ }
10548+ }
10549+ else if (argc == 2) {
10550+ pSpec->toSpecFile(cout);
10551+ }
10552+
10553+ delete pSpec;
10554+ return 0;
10555+ }
10556+
10557+ return 3;
10558+}
10559Index: xmlspec/xmlparse.c
10560===================================================================
10561RCS file: rpm/xmlspec/xmlparse.c,v
10562retrieving revision 1.1.2.1
10563retrieving revision 1.1.2.2
10564diff -u -u -r1.1.2.1 -r1.1.2.2
10565--- rpm/xmlspec/xmlparse.c 28 Aug 2002 10:52:43 -0000 1.1.2.1
10566+++ rpm/xmlspec/xmlparse.c 10 Oct 2002 22:47:59 -0000 1.1.2.2
10567@@ -43,7 +43,15 @@
10568 addXMLMacro(pParse->m_pAttrs, &(pSpec->m_pMacros));
10569 break;
10570 case TAGVAL_SOURCE:
10571- addXMLSource(pParse->m_pAttrs, &(pSpec->m_pSources));
10572+ if (pSpec->m_pSources)
10573+ addXMLSource(pParse->m_pAttrs, &(pSpec->m_pSources));
10574+ else {
10575+ if ((addXMLSource(pParse->m_pAttrs, &(pSpec->m_pSources))) &&
10576+ (pSpec->m_pSources->m_szDirectory)) {
10577+ newStr(pSpec->m_pSources->m_szDirectory,
10578+ (char**)&(pSpec->m_szBuildSubdir));
10579+ }
10580+ }
10581 break;
10582 case TAGVAL_PATCH:
10583 addXMLSource(pParse->m_pAttrs, &(pSpec->m_pPatches));
10584@@ -178,6 +186,12 @@
10585 appendStringBuf(pSb, szTmp);
10586 appendStringBuf(pSb, pSource->m_szName);
10587 }
10588+ else if (!strcasecmp(szTmp, "tgz")) {
10589+ szTmp = NULL;
10590+ newStrEx("%{_gzipbin} -dc ", &szTmp);
10591+ appendStringBuf(pSb, szTmp);
10592+ appendStringBuf(pSb, pSource->m_szName);
10593+ }
10594 else if (!strcasecmp(szTmp, "zip")) {
10595 szTmp = NULL;
10596 newStrEx("%{_unzipbin} ", &szTmp);
10597@@ -265,8 +279,8 @@
10598 appendStringBuf(pSb, pSource->m_szName);
10599 }
10600 freeStr(&szTmp);
10601- szTmp = malloc(strlen(" > patch -p1234567890 -s ")+strlen(pSource->m_szName)+1);
10602- sprintf(szTmp, " | patch -p%d -s", nLevel);
10603+ szTmp = malloc(strlen(" > patch -pN1234567890 -s ")+strlen(pSource->m_szName)+1);
10604+ sprintf(szTmp, " | patch -Np%d -s", nLevel);
10605 appendStringBuf(pSb, szTmp);
10606 appendLineStringBuf(pSb, "");
10607 appendLineStringBuf(pSb, "STATUS=$?");
10608@@ -290,6 +304,9 @@
10609 case TAGVAL_SUMMARY:
10610 case TAGVAL_DESCRIPTION:
10611 case TAGVAL_REQUIRES:
10612+ case TAGVAL_PROVIDES:
10613+ case TAGVAL_OBSOLETES:
10614+ case TAGVAL_CONFLICTS:
10615 // we don't need to do anything
10616 break;
10617 default:
10618@@ -315,6 +332,18 @@
10619 pPkg = getLastXMLPackage(pSpec->m_pPackages);
10620 addXMLRequire(pParse->m_pAttrs, &(pPkg->m_pRequires));
10621 break;
10622+ case TAGVAL_PROVIDE:
10623+ pPkg = getLastXMLPackage(pSpec->m_pPackages);
10624+ addXMLRequire(pParse->m_pAttrs, &(pPkg->m_pProvides));
10625+ break;
10626+ case TAGVAL_OBSOLETE:
10627+ pPkg = getLastXMLPackage(pSpec->m_pPackages);
10628+ addXMLRequire(pParse->m_pAttrs, &(pPkg->m_pObsoletes));
10629+ break;
10630+ case TAGVAL_CONFLICT:
10631+ pPkg = getLastXMLPackage(pSpec->m_pPackages);
10632+ addXMLRequire(pParse->m_pAttrs, &(pPkg->m_pConflicts));
10633+ break;
10634 case TAGVAL_CHANGE:
10635 pChanges = getLastXMLChanges(pSpec->m_pChangelog);
10636 addXMLChange(pParse->m_pAttrs, &(pChanges->m_pChanges));
10637@@ -544,32 +573,26 @@
10638 int nLen)
10639 {
10640 t_structXMLParse* pParse = NULL;
10641+ char* szVal = NULL;
10642 char* szTmp = NULL;
10643- char* szTmpValue = NULL;
10644- char* szPos = NULL;
10645
10646 if ((pParse = (t_structXMLParse*)pData)) {
10647- szTmp = malloc(nLen+2);
10648- szTmp[nLen] = '\0';
10649- snprintf(szTmp, nLen+1, "%s", szValue);
10650- szPos = szTmp;
10651- while ((*szPos == ' ') ||
10652- (*szPos == '\t') ||
10653- (*szPos == '\r') ||
10654- (*szPos == '\n'))
10655- szPos++;
10656-
10657- if (strlen(szPos)) {
10658+ szVal = malloc(nLen+2);
10659+ szVal[nLen] = '\0';
10660+ snprintf(szVal, nLen+1, "%s", szValue);
10661+ if (strlen(szVal)) {
10662+ while ((szTmp = strchr(szVal, '\t')))
10663+ *szTmp = ' ';
10664 if (pParse->m_szValue) {
10665- szTmpValue = malloc(strlen(szPos)+strlen(pParse->m_szValue)+1);
10666- sprintf(szTmpValue, "%s%s", pParse->m_szValue, szPos);
10667- newStr(szTmpValue, &(pParse->m_szValue));
10668- free(szTmpValue);
10669+ szTmp = malloc(strlen(szVal)+strlen(pParse->m_szValue)+1);
10670+ sprintf(szTmp, "%s%s", pParse->m_szValue, szVal);
10671+ newStr(szTmp, &(pParse->m_szValue));
10672+ free(szTmp);
10673 }
10674 else
10675- newStr(szPos, &(pParse->m_szValue));
10676+ newStr(szVal, &(pParse->m_szValue));
10677 }
10678- free(szTmp);
10679+ free(szVal);
10680 }
10681 }
10682
10683Index: xmlspec/xmlstruct.c
10684===================================================================
10685RCS file: rpm/xmlspec/xmlstruct.c,v
10686retrieving revision 1.2.2.1
10687retrieving revision 1.2.2.2
10688diff -u -u -r1.2.2.1 -r1.2.2.2
10689--- rpm/xmlspec/xmlstruct.c 28 Aug 2002 10:52:43 -0000 1.2.2.1
10690+++ rpm/xmlspec/xmlstruct.c 10 Oct 2002 22:47:59 -0000 1.2.2.2
10691@@ -97,7 +97,7 @@
10692 {
10693 while (pAttr && (strcasecmp(szName, pAttr->m_szName) != 0))
10694 pAttr = pAttr->m_pNext;
10695-
10696+
10697 return pAttr;
10698 }
10699
10700@@ -236,7 +236,7 @@
10701 attrSetInt(pAttr, "size", &(pSource->m_nSize));
10702 attrSetStr(pAttr, "md5", &(pSource->m_szMD5));
10703 attrSetStr(pAttr, "directory", &(pSource->m_szDirectory));
10704- attrSetInt(pAttr, "number", &(pSource->m_nNum));
10705+ attrSetInt(pAttr, "id", &(pSource->m_nNum));
10706 } while ((pAttr = pAttr->m_pNext));
10707 }
10708
10709@@ -365,6 +365,8 @@
10710
10711 if ((pScript = malloc(sizeof(t_structXMLScript)))) {
10712 pScript->m_szInterpreter = NULL;
10713+ pScript->m_szArch = NULL;
10714+ pScript->m_szOS = NULL;
10715 pScript->m_szScript = NULL;
10716 pScript->m_szEntry = NULL;
10717 pScript->m_pNext = NULL;
10718@@ -373,6 +375,10 @@
10719 do {
10720 attrSetStr(pAttr, "interpreter",
10721 &(pScript->m_szInterpreter));
10722+ attrSetStr(pAttr, "arch",
10723+ &(pScript->m_szArch));
10724+ attrSetStr(pAttr, "os",
10725+ &(pScript->m_szOS));
10726 attrSetStr(pAttr, "script",
10727 &(pScript->m_szScript));
10728 } while ((pAttr = pAttr->m_pNext));
10729@@ -386,6 +392,8 @@
10730 {
10731 if (*ppScript) {
10732 freeStr(&((*ppScript)->m_szInterpreter));
10733+ freeStr(&((*ppScript)->m_szArch));
10734+ freeStr(&((*ppScript)->m_szOS));
10735 freeStr(&((*ppScript)->m_szScript));
10736 freeStr(&((*ppScript)->m_szEntry));
10737 freeXMLScript(&((*ppScript)->m_pNext));
10738@@ -485,6 +493,59 @@
10739 return 0;
10740 }
10741
10742+t_structI18NStr* newI18NStr(const t_structXMLAttr* pAttrs)
10743+{
10744+ t_structI18NStr* pStr = NULL;
10745+ t_structXMLAttr* pAttr = NULL;
10746+
10747+ if ((pStr = malloc(sizeof(t_structI18NStr)))) {
10748+ pStr->m_szLang = NULL;
10749+ pStr->m_szText = NULL;
10750+ pStr->m_pNext = NULL;
10751+
10752+ pAttr = (t_structXMLAttr*)pAttrs;
10753+ do {
10754+ attrSetStr(pAttr, "lang", &(pStr->m_szLang));
10755+ } while ((pAttr = pAttr->m_pNext));
10756+ }
10757+
10758+ return pStr;
10759+}
10760+
10761+int freeI18NStr(t_structI18NStr** ppStr)
10762+{
10763+ if (*ppStr) {
10764+ freeStr(&((*ppStr)->m_szLang));
10765+ freeStr(&((*ppStr)->m_szText));
10766+ freeI18NStr(&((*ppStr)->m_pNext));
10767+ free(*ppStr);
10768+ }
10769+ *ppStr = NULL;
10770+
10771+ return 0;
10772+}
10773+
10774+t_structI18NStr* addI18NStr(const t_structXMLAttr* pAttrs,
10775+ t_structI18NStr** ppStr)
10776+{
10777+ t_structI18NStr* pStr = NULL;
10778+
10779+ if ((pStr = getLastI18NStr(*ppStr)))
10780+ pStr = (pStr->m_pNext = newI18NStr(pAttrs));
10781+ else
10782+ pStr = (*ppStr = newI18NStr(pAttrs));
10783+
10784+ return pStr;
10785+}
10786+
10787+t_structI18NStr* getLastI18NStr(t_structI18NStr* pStr)
10788+{
10789+ while (pStr && (pStr->m_pNext))
10790+ pStr = pStr->m_pNext;
10791+
10792+ return pStr;
10793+}
10794+
10795 t_structXMLPackage* newXMLPackage(const t_structXMLAttr* pAttrs)
10796 {
10797 t_structXMLPackage* pPackage = NULL;
10798@@ -492,6 +553,7 @@
10799
10800 if ((pPackage = malloc(sizeof(t_structXMLPackage)))) {
10801 pPackage->m_szName = NULL;
10802+ pPackage->m_szVersion = NULL;
10803 pPackage->m_szGroup = NULL;
10804 pPackage->m_szSummary = NULL;
10805 pPackage->m_szDescription = NULL;
10806@@ -507,15 +569,21 @@
10807 pPackage->m_pRequires = NULL;
10808 pPackage->m_pSuggests = NULL;
10809 pPackage->m_pObsoletes = NULL;
10810+ pPackage->m_pConflicts = NULL;
10811 pPackage->m_pProvides = NULL;
10812 pPackage->m_pNext = NULL;
10813
10814 pAttr = (t_structXMLAttr*)pAttrs;
10815 do {
10816 attrSetStr(pAttr, "name", &(pPackage->m_szName));
10817+ attrSetStr(pAttr, "version", &(pPackage->m_szVersion));
10818 attrSetStr(pAttr, "group", &(pPackage->m_szGroup));
10819 attrSetBool(pAttr, "autorequire", &(pPackage->m_nAutoRequire));
10820+ attrSetBool(pAttr, "autoreq", &(pPackage->m_nAutoRequire));
10821 attrSetBool(pAttr, "autoprovide", &(pPackage->m_nAutoProvide));
10822+ attrSetBool(pAttr, "autoprov", &(pPackage->m_nAutoProvide));
10823+ attrSetBool(pAttr, "autoreqprov", &(pPackage->m_nAutoProvide));
10824+ attrSetBool(pAttr, "autoreqprov", &(pPackage->m_nAutoRequire));
10825 attrSetBool(pAttr, "autosuggest", &(pPackage->m_nAutoSuggest));
10826 } while ((pAttr = pAttr->m_pNext));
10827 }
10828@@ -527,6 +595,7 @@
10829 {
10830 if (*ppPackage) {
10831 freeStr(&((*ppPackage)->m_szName));
10832+ freeStr(&((*ppPackage)->m_szVersion));
10833 freeStr(&((*ppPackage)->m_szGroup));
10834 freeStr(&((*ppPackage)->m_szSummary));
10835 freeStr(&((*ppPackage)->m_szDescription));
10836@@ -539,6 +608,7 @@
10837 freeXMLRequire(&((*ppPackage)->m_pRequires));
10838 freeXMLRequire(&((*ppPackage)->m_pSuggests));
10839 freeXMLRequire(&((*ppPackage)->m_pObsoletes));
10840+ freeXMLRequire(&((*ppPackage)->m_pConflicts));
10841 freeXMLRequire(&((*ppPackage)->m_pProvides));
10842 freeXMLPackage(&((*ppPackage)->m_pNext));
10843 free(*ppPackage);
10844Index: xmlspec/xmlstruct.h
10845===================================================================
10846RCS file: rpm/xmlspec/xmlstruct.h,v
10847retrieving revision 1.1.2.1
10848retrieving revision 1.1.2.2
10849diff -u -u -r1.1.2.1 -r1.1.2.2
10850--- rpm/xmlspec/xmlstruct.h 28 Aug 2002 10:52:43 -0000 1.1.2.1
10851+++ rpm/xmlspec/xmlstruct.h 10 Oct 2002 22:47:59 -0000 1.1.2.2
10852@@ -52,6 +52,8 @@
10853 typedef struct structXMLScript
10854 {
10855 char* m_szInterpreter;
10856+ char* m_szArch;
10857+ char* m_szOS;
10858 char* m_szScript;
10859 char* m_szEntry;
10860 struct structXMLScript* m_pNext;
10861@@ -71,9 +73,17 @@
10862 char* m_szGID;
10863 } t_structXMLFiles;
10864
10865+typedef struct structI18NStr
10866+{
10867+ char* m_szLang;
10868+ char* m_szText;
10869+ struct structI18NStr* m_pNext;
10870+} t_structI18NStr;
10871+
10872 typedef struct structXMLPackage
10873 {
10874 char* m_szName;
10875+ char* m_szVersion;
10876 char* m_szGroup;
10877 char* m_szSummary;
10878 char* m_szDescription;
10879@@ -89,6 +99,7 @@
10880 struct structXMLRequire* m_pRequires;
10881 struct structXMLRequire* m_pSuggests;
10882 struct structXMLRequire* m_pObsoletes;
10883+ struct structXMLRequire* m_pConflicts;
10884 struct structXMLRequire* m_pProvides;
10885 struct structXMLPackage* m_pNext;
10886 } t_structXMLPackage;
10887@@ -200,6 +211,12 @@
10888
10889 t_structXMLFiles* newXMLFiles(const t_structXMLAttr* pAttrs);
10890 int freeXMLFiles(t_structXMLFiles** ppFiles);
10891+
10892+t_structI18NStr* newI18NStr(const t_structXMLAttr* pAttrs);
10893+int freeI18NStr(t_structI18NStr** ppStr);
10894+t_structI18NStr* addI18NStr(const t_structXMLAttr* pAttrs,
10895+ t_structI18NStr** ppStr);
10896+t_structI18NStr* getLastI18NStr(t_structI18NStr* pStr);
10897
10898 t_structXMLPackage* newXMLPackage(const t_structXMLAttr* pAttrs);
10899 int freeXMLPackage(t_structXMLPackage** ppPackage);
10900Index: xmlspec/xmlverify.c
10901===================================================================
10902RCS file: rpm/xmlspec/xmlverify.c,v
10903retrieving revision 1.1.2.1
10904retrieving revision 1.1.2.2
10905diff -u -u -r1.1.2.1 -r1.1.2.2
10906--- rpm/xmlspec/xmlverify.c 28 Aug 2002 10:52:43 -0000 1.1.2.1
10907+++ rpm/xmlspec/xmlverify.c 10 Oct 2002 22:47:59 -0000 1.1.2.2
10908@@ -58,7 +58,7 @@
10909 {"size", ATTRTYPE_NUMERIC, 0},
10910 {"md5", ATTRTYPE_MD5, 0},
10911 {"path", ATTRTYPE_ANY, 0},
10912- {"number", ATTRTYPE_NUMERIC, 0},
10913+ {"id", ATTRTYPE_NUMERIC, 0},
10914 {NULL, ATTRTYPE_ANY, 1}
10915 }
10916 },
10917@@ -89,7 +89,7 @@
10918 {"size", ATTRTYPE_NUMERIC, 0},
10919 {"md5", ATTRTYPE_MD5, 0},
10920 {"path", ATTRTYPE_ANY, 0},
10921- {"number", ATTRTYPE_NUMERIC, 0},
10922+ {"id", ATTRTYPE_NUMERIC, 0},
10923 {NULL, ATTRTYPE_ANY, 1}
10924 }
10925 },
10926@@ -165,6 +165,7 @@
10927 },
10928 {
10929 {"name", ATTRTYPE_ANY, 0},
10930+ {"version", ATTRTYPE_ANY, 0},
10931 {"group", ATTRTYPE_ANY, 1},
10932 {"autoreqprov", ATTRTYPE_BOOL, 0},
10933 {"autoprov", ATTRTYPE_BOOL, 0},
10934@@ -219,6 +220,7 @@
10935 },
10936 {
10937 {"name", ATTRTYPE_ANY, 1},
10938+ {"version", ATTRTYPE_ANY, 0},
10939 {NULL, ATTRTYPE_ANY, 1}
10940 }
10941 },
10942@@ -243,6 +245,34 @@
10943 },
10944 {
10945 {"name", ATTRTYPE_ANY, 1},
10946+ {"version", ATTRTYPE_ANY, 0},
10947+ {"cmp", ATTRTYPE_CMP, 0},
10948+ {NULL, ATTRTYPE_ANY, 1}
10949+ }
10950+ },
10951+ {
10952+ "conflicts", TAGVAL_CONFLICTS, 2,
10953+ {
10954+ TAGVAL_SPEC,
10955+ TAGVAL_PACKAGE,
10956+ TAGVAL_LAST
10957+ },
10958+ {
10959+ {NULL, ATTRTYPE_ANY, 1}
10960+ }
10961+ },
10962+ {
10963+ "conflict", TAGVAL_CONFLICT, 3,
10964+ {
10965+ TAGVAL_SPEC,
10966+ TAGVAL_PACKAGE,
10967+ TAGVAL_CONFLICTS,
10968+ TAGVAL_LAST
10969+ },
10970+ {
10971+ {"name", ATTRTYPE_ANY, 1},
10972+ {"version", ATTRTYPE_ANY, 0},
10973+ {"cmp", ATTRTYPE_CMP, 0},
10974 {NULL, ATTRTYPE_ANY, 1}
10975 }
10976 },
10977@@ -280,6 +310,7 @@
10978 TAGVAL_LAST
10979 },
10980 {
10981+ {"lang", ATTRTYPE_ANY, 0},
10982 {NULL, ATTRTYPE_ANY, 1}
10983 }
10984 },
10985@@ -291,6 +322,7 @@
10986 TAGVAL_LAST
10987 },
10988 {
10989+ {"lang", ATTRTYPE_ANY, 0},
10990 {NULL, ATTRTYPE_ANY, 1}
10991 }
10992 },
10993@@ -317,6 +349,8 @@
10994 },
10995 {
10996 {"interpreter", ATTRTYPE_ANY, 0},
10997+ {"arch", ATTRTYPE_ANY, 0},
10998+ {"os", ATTRTYPE_ANY, 0},
10999 {"script", ATTRTYPE_SCRIPT, 0},
11000 {NULL, ATTRTYPE_ANY, 1}
11001 }
11002@@ -344,6 +378,8 @@
11003 },
11004 {
11005 {"interpreter", ATTRTYPE_ANY, 0},
11006+ {"arch", ATTRTYPE_ANY, 0},
11007+ {"os", ATTRTYPE_ANY, 0},
11008 {"script", ATTRTYPE_SCRIPT, 0},
11009 {NULL, ATTRTYPE_ANY, 1}
11010 }
11011@@ -371,6 +407,8 @@
11012 },
11013 {
11014 {"interpreter", ATTRTYPE_ANY, 0},
11015+ {"arch", ATTRTYPE_ANY, 0},
11016+ {"os", ATTRTYPE_ANY, 0},
11017 {"script", ATTRTYPE_SCRIPT, 0},
11018 {NULL, ATTRTYPE_ANY, 1}
11019 }
11020@@ -398,11 +436,14 @@
11021 },
11022 {
11023 {"interpreter", ATTRTYPE_ANY, 0},
11024+ {"arch", ATTRTYPE_ANY, 0},
11025+ {"os", ATTRTYPE_ANY, 0},
11026 {"script", ATTRTYPE_SCRIPT, 0},
11027 {NULL, ATTRTYPE_ANY, 1}
11028 }
11029 },
11030- {"verify", TAGVAL_VERIFY, 2,
11031+ {
11032+ "verify", TAGVAL_VERIFY, 2,
11033 {
11034 TAGVAL_SPEC,
11035 TAGVAL_PACKAGE,
11036@@ -424,6 +465,8 @@
11037 },
11038 {
11039 {"interpreter", ATTRTYPE_ANY, 0},
11040+ {"arch", ATTRTYPE_ANY, 0},
11041+ {"os", ATTRTYPE_ANY, 0},
11042 {"script", ATTRTYPE_SCRIPT, 0},
11043 {NULL, ATTRTYPE_ANY, 1}
11044 }
11045@@ -463,6 +506,8 @@
11046 },
11047 {
11048 {"interpreter", ATTRTYPE_ANY, 0},
11049+ {"arch", ATTRTYPE_ANY, 0},
11050+ {"os", ATTRTYPE_ANY, 0},
11051 {"script", ATTRTYPE_SCRIPT, 0},
11052 {NULL, ATTRTYPE_ANY, 1}
11053 }
11054@@ -476,6 +521,8 @@
11055 },
11056 {
11057 {"source", ATTRTYPE_NUMERIC, 0},
11058+ {"arch", ATTRTYPE_ANY, 0},
11059+ {"os", ATTRTYPE_ANY, 0},
11060 {"path", ATTRTYPE_ANY, 0},
11061 {NULL, ATTRTYPE_ANY, 1}
11062 }
11063@@ -489,6 +536,8 @@
11064 },
11065 {
11066 {"patch", ATTRTYPE_NUMERIC, 0},
11067+ {"arch", ATTRTYPE_ANY, 0},
11068+ {"os", ATTRTYPE_ANY, 0},
11069 {"level", ATTRTYPE_NUMERIC, 0},
11070 {"path", ATTRTYPE_ANY, 0},
11071 {NULL, ATTRTYPE_ANY, 1}
11072@@ -515,6 +564,8 @@
11073 },
11074 {
11075 {"interpreter", ATTRTYPE_ANY, 0},
11076+ {"arch", ATTRTYPE_ANY, 0},
11077+ {"os", ATTRTYPE_ANY, 0},
11078 {"script", ATTRTYPE_SCRIPT, 0},
11079 {NULL, ATTRTYPE_ANY, 1}
11080 }
11081@@ -540,6 +591,8 @@
11082 },
11083 {
11084 {"interpreter", ATTRTYPE_ANY, 0},
11085+ {"arch", ATTRTYPE_ANY, 0},
11086+ {"os", ATTRTYPE_ANY, 0},
11087 {"script", ATTRTYPE_SCRIPT, 0},
11088 {NULL, ATTRTYPE_ANY, 1}
11089 }
11090@@ -565,6 +618,8 @@
11091 },
11092 {
11093 {"interpreter", ATTRTYPE_ANY, 0},
11094+ {"arch", ATTRTYPE_ANY, 0},
11095+ {"os", ATTRTYPE_ANY, 0},
11096 {"script", ATTRTYPE_SCRIPT, 0},
11097 {NULL, ATTRTYPE_ANY, 1}
11098 }
11099Index: xmlspec/xmlverify.h
11100===================================================================
11101RCS file: rpm/xmlspec/xmlverify.h,v
11102retrieving revision 1.1.2.1
11103retrieving revision 1.1.2.2
11104diff -u -u -r1.1.2.1 -r1.1.2.2
11105--- rpm/xmlspec/xmlverify.h 28 Aug 2002 10:52:43 -0000 1.1.2.1
11106+++ rpm/xmlspec/xmlverify.h 10 Oct 2002 22:47:59 -0000 1.1.2.2
11107@@ -22,6 +22,8 @@
11108 TAGVAL_REQUIRE,
11109 TAGVAL_OBSOLETES,
11110 TAGVAL_OBSOLETE,
11111+ TAGVAL_CONFLICTS,
11112+ TAGVAL_CONFLICT,
11113 TAGVAL_SUGGESTS,
11114 TAGVAL_SUGGEST,
11115 TAGVAL_SUMMARY,
This page took 1.819208 seconds and 4 git commands to generate.