RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   26-Mar-2011 14:03:54
  Branch: rpm-5_4                          Handle: 2011032613035300

  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES
    rpm/rpmdb               hdrfmt.c
    rpm/rpmio               rpmuuid.c

  Log:
    - uuid: permit --qf '%{RPMTAG:uuid}' UUIDv1/UUIDv5 output display.
    - uuid: rework for single exit return.

  Summary:
    Revision    Changes     Path
    1.3501.2.77 +2  -0      rpm/CHANGES
    1.151.2.2   +80 -20     rpm/rpmdb/hdrfmt.c
    2.5.10.1    +15 -23     rpm/rpmio/rpmuuid.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.76 -r1.3501.2.77 CHANGES
  --- rpm/CHANGES       25 Mar 2011 16:22:41 -0000      1.3501.2.76
  +++ rpm/CHANGES       26 Mar 2011 13:03:53 -0000      1.3501.2.77
  @@ -1,4 +1,6 @@
   5.4.0 -> 5.4.1:
  +    - jbj: uuid: permit --qf '%{RPMTAG:uuid}' UUIDv1/UUIDv5 output display.
  +    - jbj: uuid: rework for single exit return.
       - devzero2000: permit in configure phase to enable the 
         --enable-rpm-lua-extensions-based-on-rpmlib used by OpenPKG today
         and, for rpm.vercmp, by rpm.org (ref 
https://blueprints.launchpad.net/rpm/+spec/rpm-split-vendor-config-in-autofu)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/hdrfmt.c
  ============================================================================
  $ cvs diff -u -r1.151.2.1 -r1.151.2.2 hdrfmt.c
  --- rpm/rpmdb/hdrfmt.c        25 Jan 2011 18:12:22 -0000      1.151.2.1
  +++ rpm/rpmdb/hdrfmt.c        26 Mar 2011 13:03:53 -0000      1.151.2.2
  @@ -1631,7 +1631,7 @@
       }
   
       he->p.ui8p[6] &= 0xf0;   /* preserve version, clear time_hi nibble */
  -    he->p.ui8p[8] &= 0x3f;   /* preserve reserved, clear clock */
  +    he->p.ui8p[8] &= 0xc0;   /* preserve variant, clear clock */
       he->p.ui8p[9] &= 0x00;
   
       he->p.ui8p[3] = (rpmuint8_t)(uuid_time >>  0);
  @@ -1780,6 +1780,7 @@
       const char * ns = NULL;
       const char * tagn = tagName(he->tag);
       const char * s = NULL;
  +char * t = (val ? val : alloca(40));
       int rc;
   
       /* XXX Substitute Pkgid & Hdrid strings for aliases. */
  @@ -1807,12 +1808,13 @@
       he->c = 128/8;
       he->p.ptr = xcalloc(1, he->c);
       he->freeData = 1;
  -    rc = rpmuuidMake((int)version, ns, s, val, (unsigned char *)he->p.ui8p);
  +    rc = rpmuuidMake((int)version, ns, s, t, (unsigned char *)he->p.ui8p);
       if (rc) {
        he->p.ptr = _free(he->p.ptr);
        he->freeData = 0;
       }
       s = _free(s);
  +
       return rc;
   }
   
  @@ -4706,22 +4708,91 @@
        /*@globals rpmGlobalMacroContext, h_errno, internalState @*/
        /*@modifies rpmGlobalMacroContext, internalState @*/
   {
  +    static const char hex[] = "0123456789abcdef";
  +    /* XXX use private tag container to avoid memory issues for now. */
  +    HE_t nhe = memset(alloca(sizeof(*nhe)), 0, sizeof(*nhe));
   /*@-nullassign@*/
       /*@unchecked@*/ /*@observer@*/
       static const char *avdefault[] = { "v5", NULL };
   /*@=nullassign@*/
  -    rpmuint32_t version = 0;
       int ix = (he->ix > 0 ? he->ix : 0);
       char * val = NULL;
  -    int i;
  +    struct timeval tv;
  +    char * t;
  +    char * te;
  +    uint32_t i;
   
   assert(ix == 0);
  +    val = xmalloc((128/4 + 4) + 1);
  +    *val = '\0';
  +
  +    nhe->tag = he->tag;
  +    nhe->t = he->t;
       switch(he->t) {
       default:
  +     val = _free(val);
        val = xstrdup(_("(invalid type :uuid)"));
        goto exit;
        /*@notreached@*/ break;
  +    case RPM_UINT64_TYPE:
  +     /* XXX Limit to tag time stamps with UUIDv1 direct conversion. */
  +     switch (he->tag) {
  +     default:
  +         val = _free(val);
  +         val = xstrdup(_("(invalid tag :uuid)"));
  +         goto exit;
  +         break;
  +     case RPMTAG_INSTALLTIME:
  +     case RPMTAG_BUILDTIME:
  +     case RPMTAG_ORIGINTIME:
  +     case RPMTAG_INSTALLTID:
  +     case RPMTAG_REMOVETID:
  +     case RPMTAG_ORIGINTID:
  +
  +         /* Convert tag time stamp to UUIDv1. */
  +         tv.tv_sec = (long) he->p.ui64p[0];
  +         tv.tv_usec = (long) (he->c > 1 ? he->p.ui64p[1] : 0);
  +         ix = tv2uuidv1(NULL, nhe, &tv);
  +
  +         /* Convert UUIDv1 to display string. */
  +         te = val;
  +         for (i = 0; i < nhe->c; i++) {
  +             *te++ = hex[ (int)((nhe->p.ui8p[i] >> 4) & 0x0f) ];
  +             *te++ = hex[ (int)((nhe->p.ui8p[i]     ) & 0x0f) ];
  +             if (i == 3 || i == 5 || i == 7 || i == 9)
  +                 *te++ = '-';
  +         }
  +         *te = '\0';
  +         goto exit;  /* XXX immediate exit for UUIDv1 */
  +         break;
  +     }
  +     break;
  +    case RPM_BIN_TYPE:
  +     /* XXX Limit to tag binary digests with djb formatting in UUIDv5. */
  +     switch (he->tag) {
  +     default:
  +         val = _free(val);
  +         val = xstrdup(_("(invalid tag :uuid)"));
  +         goto exit;
  +         break;
  +     case RPMTAG_PKGID:
  +     case RPMTAG_SOURCEPKGID:
  +         /* Convert RPMTAG_*PKGID from binary => hex. */
  +         t = te = xmalloc(2*he->c + 1);
  +         for (i = 0; i < he->c; i++) {
  +             *te++ = hex[ (int)((he->p.ui8p[i] >> 4) & 0x0f) ];
  +             *te++ = hex[ (int)((he->p.ui8p[i]     ) & 0x0f) ];
  +         }
  +         *te = '\0';
  +         nhe->t = RPM_STRING_TYPE;
  +         nhe->p.ptr = t;
  +         nhe->c = 1;
  +         break;
  +     }
  +     break;
       case RPM_STRING_TYPE:
  +     nhe->c = 1;
  +     nhe->p.ptr = xstrdup(he->p.str);
        break;
       }
   
  @@ -4729,7 +4800,7 @@
        av = avdefault;
   
       for (i = 0; av[i] != NULL; i++) {
  -     rpmuint32_t keyval = keyValue(keyUuids, nkeyUuids, av[i]);
  +     uint32_t keyval = keyValue(keyUuids, nkeyUuids, av[i]);
   
        switch (keyval) {
        default:
  @@ -4738,25 +4809,14 @@
        case UUID_KEYS_V3:
        case UUID_KEYS_V4:
        case UUID_KEYS_V5:
  -         version = keyval;
  -         /*@switchbreak@*/ break;
  +         ix = str2uuid(nhe, NULL, keyval, val);
  +         goto exit;  /* XXX exit after first found. */
  +         break;
        }
       }
   
  -    /* XXX use private tag container to avoid memory issues for now. */
  -    {        HE_t nhe = memset(alloca(sizeof(*nhe)), 0, sizeof(*nhe));
  -     int xx;
  -     nhe->tag = he->tag;
  -     nhe->t = he->t;
  -     nhe->p.str = xstrdup(he->p.str);
  -     nhe->c = he->c;
  -     val = xmalloc((128/4 + 4) + 1);
  -     *val = '\0';
  -     xx = str2uuid(nhe, NULL, version, val);
  -     nhe->p.ptr = _free(nhe->p.ptr);
  -    }
  -
   exit:
  +    nhe->p.ptr = _free(nhe->p.ptr);
       return val;
   }
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmuuid.c
  ============================================================================
  $ cvs diff -u -r2.5 -r2.5.10.1 rpmuuid.c
  --- rpm/rpmio/rpmuuid.c       11 May 2008 12:24:59 -0000      2.5
  +++ rpm/rpmio/rpmuuid.c       26 Mar 2011 13:03:53 -0000      2.5.10.1
  @@ -22,6 +22,7 @@
   
   int rpmuuidMake(int version, const char *ns, const char *data, char 
*buf_str, unsigned char *buf_bin)
   {
  +    int ec = 1;              /* assume error */
   #ifdef WITH_UUID
       uuid_rc_t rc;
       uuid_t *uuid = NULL;
  @@ -32,33 +33,33 @@
       /* sanity check version */
       if (!(version == 1 || (version >= 3 && version <= 5))) {
           rpmlog(RPMLOG_ERR, _("invalid UUID version number"));
  -        return 1;
  +     goto exit;
       }
       if ((version == 3 || version == 5) && (ns == NULL || data == NULL)) {
           rpmlog(RPMLOG_ERR, _("namespace or data required for requested UUID 
version\n"));
  -        return 1;
  +     goto exit;
       }
       if (buf_str == NULL && buf_bin == NULL) {
           rpmlog(RPMLOG_ERR, _("either string or binary result buffer 
required\n"));
  -        return 1;
  +     goto exit;
       }
   
       /* create UUID object */
       if ((rc = uuid_create(&uuid)) != UUID_RC_OK) {
           rpmlog(RPMLOG_ERR, _("failed to create UUID object: %s\n"), 
uuid_error(rc));
  -        return 1;
  +     goto exit;
       }
   
       /* create optional UUID namespace object */
       if (version == 3 || version == 5) {
           if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK) {
               rpmlog(RPMLOG_ERR, _("failed to create UUID namespace object: 
%s\n"), uuid_error(rc));
  -            return 1;
  +         goto exit;
           }
           if ((rc = uuid_load(uuid_ns, ns)) != UUID_RC_OK) {
               if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, ns, strlen(ns))) != 
UUID_RC_OK) {
                   rpmlog(RPMLOG_ERR, _("failed to import UUID namespace 
object: %s\n"), uuid_error(rc));
  -                return 1;
  +             goto exit;
               }
           }
       }
  @@ -73,11 +74,8 @@
       else if (version == 5)
           rc = uuid_make(uuid, UUID_MAKE_V5, uuid_ns, data);
       if (rc != UUID_RC_OK) {
  -        (void) uuid_destroy(uuid);
  -        if (uuid_ns != NULL)
  -            (void) uuid_destroy(uuid_ns);
           rpmlog(RPMLOG_ERR, _("failed to make UUID object: %s\n"), 
uuid_error(rc));
  -        return 1;
  +     goto exit;
       }
   
       /*  export UUID */
  @@ -85,37 +83,31 @@
           result_ptr = buf_str;
           result_len = UUID_LEN_STR+1;
           if ((rc = uuid_export(uuid, UUID_FMT_STR, &result_ptr, &result_len)) 
!= UUID_RC_OK) {
  -            (void) uuid_destroy(uuid);
  -            if (uuid_ns != NULL)
  -                (void) uuid_destroy(uuid_ns);
               rpmlog(RPMLOG_ERR, _("failed to export UUID object as string 
representation: %s\n"), uuid_error(rc));
  -            return 1;
  +         goto exit;
           }
       }
       if (buf_bin != NULL) {
           result_ptr = (char *)buf_bin;
           result_len = UUID_LEN_BIN;
           if ((rc = uuid_export(uuid, UUID_FMT_BIN, &result_ptr, &result_len)) 
!= UUID_RC_OK) {
  -            (void) uuid_destroy(uuid);
  -            if (uuid_ns != NULL)
  -                (void) uuid_destroy(uuid_ns);
               rpmlog(RPMLOG_ERR, _("failed to export UUID object as binary 
representation: %s\n"), uuid_error(rc));
  -            return 1;
  +         goto exit;
           }
       }
   
  +exit:
       /*  destroy UUID object(s)  */
  +    if (uuid != NULL)
       (void) uuid_destroy(uuid);
       if (uuid_ns != NULL)
           (void) uuid_destroy(uuid_ns);
   
  -    /* indicate success */
  -    return 0;
  +    ec = 0;  /* indicate success */
   #else
       rpmlog(RPMLOG_ERR, _("UUID generator not available!\n"));
  -
  -    /* indicate error */
  -    return 1;
   #endif
  +
  +    return ec;
   }
   
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to