RPM Community Forums

Mailing List Message of <rpm-devel>

Re: [CVS] RPM: rpm/ CHANGES rpm/lib/ poptQV.c

From: Jeff Johnson <n3npq@mac.com>
Date: Sun 25 Jan 2009 - 01:49:10 CET
Message-id: <232F030D-E048-4475-9CEC-1FEB36F8ACBD@mac.com>
This patch likely needs some background ...

Over the last year, its increasingly apparent (to me anyways)
that WYSIWIG metadata markup for packages is the only way forward
for software packaging.

So there are 6+ forms of half-baked markup (so far) that need to be
accommodated through --queryformat aka headerSprintf() "templates"
applied to *.rpm packages.

Up till now, the "templates" for the markup have been carried
in /usr/lib/rpm/rpmpopt-X.Y.Y, which has been adequate for proof-of- 
concept
development work.

But RPM (imho) needs to commit to some backing store for markup  
"templates"
in order to, say, share the --yum:primary.xml markup between
"rpm --query" and rpmrepo (my current narrow focus).

So this patch achieves the brutally simple basics of loading
a "template" from backing store, where the "template" follows
C newline escaping conventions, with no "# this is a comment" lines  
permitted.

I'm currently assuming this path
	/usr/lib/rpm/qf/
as a prefix for loading "templates". I already know that the backing  
store (and
the rather crude cut-n-paste in this patch) is going to change
a lot before I'm done.

Hint: For starters, all I/O in RPM typically uses Fopen(3), not open(2).
Are you prepared for a network URI connection to be attempted during
rpm(8) CLI argument processing? I am ...

hth

73 de Jeff

On Jan 24, 2009, at 7:29 PM, Jeff Johnson wrote:

>  RPM Package Manager, CVS Repository
>  http://rpm5.org/cvs/
>   
> ____________________________________________________________________________
>
>  Server: rpm5.org                         Name:   Jeff Johnson
>  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
>  Module: rpm                              Date:   25-Jan-2009 01:29:49
>  Branch: HEAD                             Handle: 2009012500294801
>
>  Modified files:
>    rpm                     CHANGES
>    rpm/lib                 poptQV.c
>
>  Log:
>    - jbj: rude & crude backing store for --queryformat templates.
>
>  Summary:
>    Revision    Changes     Path
>    1.2754      +1  -0      rpm/CHANGES
>    2.58        +96 -0      rpm/lib/poptQV.c
>   
> ____________________________________________________________________________
>
>  patch -p0 <<'@@ .'
>  Index: rpm/CHANGES
>   
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
>  $ cvs diff -u -r1.2753 -r1.2754 CHANGES
>  --- rpm/CHANGES	23 Jan 2009 23:12:51 -0000	1.2753
>  +++ rpm/CHANGES	25 Jan 2009 00:29:48 -0000	1.2754
>  @@ -1,5 +1,6 @@
>
>   5.2a2 -> 5.2a3:
>  +    - jbj: rude & crude backing store for --queryformat templates.
>       - proyvind: xzdio: accept compression level 0 - 9 (new '0' =  
> former '1' etc.).
>       - proyvind: don't wipe out $DOCDIR when using %doc as it will  
> wipe out any
>   	files that would happen to be installed during %install.
>  @@ .
>  patch -p0 <<'@@ .'
>  Index: rpm/lib/poptQV.c
>   
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
>  $ cvs diff -u -r2.57 -r2.58 poptQV.c
>  --- rpm/lib/poptQV.c	21 Jan 2009 22:24:18 -0000	2.57
>  +++ rpm/lib/poptQV.c	25 Jan 2009 00:29:49 -0000	2.58
>  @@ -195,6 +195,79 @@
>      POPT_TABLEEND
>   };
>
>  +/**
>  + * Read a file into a buffer.
>  + * @param con		context
>  + * @param fn		file name
>  + * @retval *bp		file contents
>  + * @retval *nbp		no. of bytes in file contents
>  + * return		0 on success
>  + */
>  +static int poptSlurp(/*@unused@*/ poptContext con, const char * fn,
>  +		char ** bp, off_t * nbp)
>  +	/*@globals errno, fileSystem, internalState @*/
>  +	/*@modifies *bp, *nbp, errno, fileSystem, internalState @*/
>  +{
>  +    int fdno;
>  +    char * b = NULL;
>  +    off_t nb = 0;
>  +    char * s, * t, * se;
>  +    int rc = POPT_ERROR_ERRNO;	/* assume failure */
>  +
>  +    fdno = open(fn, O_RDONLY);
>  +    if (fdno < 0)
>  +	goto exit;
>  +
>  +    if ((nb = lseek(fdno, 0, SEEK_END)) == (off_t)-1
>  +     || lseek(fdno, 0, SEEK_SET) == (off_t)-1
>  +     || (b = calloc(sizeof(*b), (size_t)nb + 1)) == NULL
>  +     || read(fdno, (char *)b, (size_t)nb) != (ssize_t)nb)
>  +    {
>  +	int oerrno = errno;
>  +	(void) close(fdno);
>  +	errno = oerrno;
>  +	goto exit;
>  +    }
>  +    if (close(fdno) == -1)
>  +	goto exit;
>  +    if (b == NULL || nb <= 0) {
>  +	rc = POPT_ERROR_BADCONFIG;
>  +	goto exit;
>  +    }
>  +    rc = 0;
>  +
>  +   /* Trim out escaped newlines. */
>  +    for (t = b, s = b, se = b + nb; *s && s < se; s++) {
>  +	switch (*s) {
>  +	case '\\':
>  +	    if (s[1] == '\n') {
>  +		s++;
>  +		continue;
>  +	    }
>  +	    /*@fallthrough@*/
>  +	default:
>  +	    *t++ = *s;
>  +	    /*@switchbreak@*/ break;
>  +	}
>  +    }
>  +    *t++ = '\0';
>  +    nb = (off_t)(t - b);
>  +
>  +exit:
>  +    if (rc == 0) {
>  +	*bp = b;
>  +	*nbp = nb;
>  +    } else {
>  +	if (b)
>  +	    free(b);
>  +	*bp = NULL;
>  +	*nbp = 0;
>  +    }
>  +/*@-compdef -nullstate @*/	/* XXX cannot annotate char **  
> correctly */
>  +    return rc;
>  +/*@=compdef =nullstate @*/
>  +}
>  +
>   /* ========== Query specific popt args */
>
>   static void queryArgCallback(poptContext con,
>  @@ -218,6 +291,26 @@
>       case POPT_QUERYFORMAT:
>   	if (arg) {
>   	    char * qf = (char *)qva->qva_queryFormat;
>  +	    char * b = NULL;
>  +	    off_t nb = 0;
>  +
>  +	    /* Read queryformat from file. */
>  +	    if (arg[0] == '/') {
>  +		const char * fn = arg;
>  +		int rc;
>  +
>  +		if ((rc = poptSlurp(con, fn, &b, &nb)) != 0)
>  +		    goto _qfexit;
>  +		if (b == NULL || nb <= 0)
>  +		    goto _qfexit;
>  +		/* XXX trim trailing newline(s). */
>  +		nb--;		/* XXX skip final NUL */
>  +		while (nb > 0 && b[nb-1] == '\n')
>  +		    b[--nb] = '\0';
>  +		arg = b;
>  +	    }
>  +
>  +	    /* Append to existing queryformat. */
>   	    if (qf) {
>   		size_t len = strlen(qf) + strlen(arg) + 1;
>   		qf = xrealloc(qf, len);
>  @@ -227,6 +320,9 @@
>   		strcpy(qf, arg);
>   	    }
>   	    qva->qva_queryFormat = qf;
>  +
>  +	_qfexit:
>  +	    b = _free(b);
>   	}
>   	break;
>
>  @@ .
> ______________________________________________________________________
> RPM Package Manager                                    http://rpm5.org
> CVS Sources Repository                                rpm-cvs@rpm5.org



  • application/pkcs7-signature attachment: smime.p7s
Received on Sun Jan 25 01:49:15 2009
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.