]> git.sur5r.net Git - openldap/commitdiff
move uuid normalized to string to liblutil
authorPierangelo Masarati <ando@openldap.org>
Fri, 17 Aug 2007 12:42:52 +0000 (12:42 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 17 Aug 2007 12:42:52 +0000 (12:42 +0000)
include/lutil.h
libraries/libldap/ldap_sync.c
libraries/liblutil/uuid.c
servers/slapd/syncrepl.c

index 49ea7951938dbc163b0e516b1b3b9d6d7ae0fc5d..9e40663201d3133e00fff5c2e5e9c24d4883828d 100644 (file)
@@ -219,6 +219,13 @@ lutil_pair( ber_socket_t sd[2] );
 LDAP_LUTIL_F( size_t )
 lutil_uuidstr( char *buf, size_t len );
 
+LDAP_LUTIL_F( int )
+lutil_uuidstr_from_normalized(
+       char            *uuid,
+       size_t          uuidlen,
+       char            *buf,
+       size_t          buflen );
+
 /* csn.c */
 /* use this macro to allocate buffer for lutil_csnstr */
 #define LDAP_LUTIL_CSNSTR_BUFSIZE      64
index 8db70ada2801960d0d22142adfc2adf6b1835805..8eb8933e200c277e70b45101f602be80537bf30d 100644 (file)
 #include "ldap-int.h"
 
 #ifdef LDAP_SYNC_TRACE
-/*
- * used for debug purposes
- */
-static char *
-print_UUID( char *buf, size_t len, unsigned char *UUID )
-{
-       snprintf( buf, len,
-               "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
-               "%02x%02x-%02x%02x%02x%02x%02x%02x",
-               UUID[0],
-               UUID[1],
-               UUID[2],
-               UUID[3],
-               UUID[4],
-               UUID[5],
-               UUID[6],
-               UUID[7],
-               UUID[8],
-               UUID[9],
-               UUID[10],
-               UUID[11],
-               UUID[12],
-               UUID[13],
-               UUID[14],
-               UUID[15] );
-       return buf;
-}
-
 static const char *
 ldap_sync_state2str( int state )
 {
@@ -600,8 +572,9 @@ ldap_sync_search_intermediate( ldap_sync_t *ls, LDAPMessage *res, int *refreshDo
                        for ( i = 0; syncUUIDs[ i ].bv_val != NULL; i++ ) {
                                char    buf[ BUFSIZ ];
                                fprintf( stderr, "\t\t%s\n", 
-                                       print_UUID( buf, sizeof( buf ),
-                                               (unsigned char *)syncUUIDs[ i ].bv_val ) );
+                                       lutil_uuidstr_from_normalized(
+                                               syncUUIDs[ i ].bv_val, syncUUIDs[ i ].bv_len,
+                                               buf, sizeof( buf ) ) );
                        }
                }
 #endif /* LDAP_SYNC_TRACE */
index 7b9f13e3faf014ea1b67a9204249a2500dc21215..dce2ee923da18681b78e70b5bc03ae26cdbac816 100644 (file)
@@ -380,6 +380,47 @@ lutil_uuidstr( char *buf, size_t len )
 #endif
 }
 
+int
+lutil_uuidstr_from_normalized(
+       char            *uuid,
+       size_t          uuidlen,
+       char            *buf,
+       size_t          buflen )
+{
+       unsigned char nibble;
+       int i, d = 0;
+
+       assert( uuid != NULL );
+       assert( buf != NULL );
+
+       if ( uuidlen != 16 ) return -1;
+       if ( buflen < 36 ) return -1;
+
+       for ( i = 0; i < 16; i++ ) {
+               if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
+                       buf[(i<<1)+d] = '-';
+                       d += 1;
+               }
+
+               nibble = (uuid[i] >> 4) & 0xF;
+               if ( nibble < 10 ) {
+                       buf[(i<<1)+d] = nibble + '0';
+               } else {
+                       buf[(i<<1)+d] = nibble - 10 + 'a';
+               }
+
+               nibble = (uuid[i]) & 0xF;
+               if ( nibble < 10 ) {
+                       buf[(i<<1)+d+1] = nibble + '0';
+               } else {
+                       buf[(i<<1)+d+1] = nibble - 10 + 'a';
+               }
+       }
+
+       if ( buflen > 36 ) buf[36] = '\0';
+       return 0;
+}
+
 #ifdef TEST
 int
 main(int argc, char **argv)
index fee5cfd0ba8f3cdfcb4da08423d9a01b7922e816..b1be2447aa57a7c17488ec674aed47a903eb76b4 100644 (file)
@@ -3032,6 +3032,7 @@ slap_uuidstr_from_normalized(
        struct berval* normalized,
        void *ctx )
 {
+#if 0
        struct berval *new;
        unsigned char nibble;
        int i, d = 0;
@@ -3079,6 +3080,49 @@ slap_uuidstr_from_normalized(
        }
 
        new->bv_val[new->bv_len] = '\0';
+       return new;
+#endif
+
+       struct berval   *new;
+       int             rc = 0;
+
+       if ( normalized == NULL ) return NULL;
+       if ( normalized->bv_len != 16 ) return NULL;
+
+       if ( uuidstr ) {
+               new = uuidstr;
+
+       } else {
+               new = (struct berval *)slap_sl_malloc( sizeof(struct berval), ctx );
+               if ( new == NULL ) {
+                       return NULL;
+               }
+       }
+
+       new->bv_len = 36;
+
+       if ( ( new->bv_val = slap_sl_malloc( new->bv_len + 1, ctx ) ) == NULL ) {
+               rc = 1;
+               goto done;
+       }
+
+       rc = lutil_uuidstr_from_normalized( normalized->bv_val,
+               normalized->bv_len, new->bv_val, new->bv_len + 1 );
+
+done:;
+       if ( rc != 0 ) {
+               if ( new != NULL ) {
+                       if ( new->bv_val != NULL ) {
+                               slap_sl_free( new->bv_val, ctx );
+                       }
+
+                       if ( new != uuidstr ) {
+                               slap_sl_free( new, ctx );
+                       }
+               }
+               new = NULL;
+       }
+
        return new;
 }