From: Pierangelo Masarati Date: Fri, 17 Aug 2007 12:42:52 +0000 (+0000) Subject: move uuid normalized to string to liblutil X-Git-Tag: OPENLDAP_REL_ENG_2_4_MP~182 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=403704b7bc05f41845fa51b2c771bb0eede20f6a;p=openldap move uuid normalized to string to liblutil --- diff --git a/include/lutil.h b/include/lutil.h index 49ea795193..9e40663201 100644 --- a/include/lutil.h +++ b/include/lutil.h @@ -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 diff --git a/libraries/libldap/ldap_sync.c b/libraries/libldap/ldap_sync.c index 8db70ada28..8eb8933e20 100644 --- a/libraries/libldap/ldap_sync.c +++ b/libraries/libldap/ldap_sync.c @@ -29,34 +29,6 @@ #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 */ diff --git a/libraries/liblutil/uuid.c b/libraries/liblutil/uuid.c index 7b9f13e3fa..dce2ee923d 100644 --- a/libraries/liblutil/uuid.c +++ b/libraries/liblutil/uuid.c @@ -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) diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index fee5cfd0ba..b1be2447aa 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -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; }