"hyc" == Howard Chu hyc@symas.com writes:
hyc> The entryCSNs used for replication now record timestamps with microsecond hyc> resolution, instead of just seconds.
Would this be suitable to adjust CSNs of the form 2002120818:17:48Z#0x008d#0#0000?
*** servers/slapd/schema_init.c~ Wed Oct 17 21:35:12 2007 --- servers/slapd/schema_init.c Thu Nov 8 14:08:11 2007 *************** *** 3454,3459 **** --- 3454,3548 ---- return LDAP_SUCCESS; }
+ /* Normalize a CSN in OpenLDAP ? format */ + static int + csnNormalize_stoneage( + slap_mask_t usage, + Syntax *syntax, + MatchingRule *mr, + struct berval *val, + struct berval *normalized, + void *ctx ) + { + struct berval gt, cnt, sid, mod; + char *ptr; + int i; + + assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 ); + assert( !BER_BVISEMPTY( val ) ); + + gt = *val; + + ptr = ber_bvchr( >, '#' ); + if ( ptr == NULL || ptr - gt.bv_val == gt.bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + gt.bv_len = ptr - gt.bv_val; + assert( gt.bv_len == STRLENOF( "YYYYmmddHH:MM:SSZ" ) ); + assert( gt.bv_val[10] == ':' ); + assert( gt.bv_val[13] == ':' ); + + cnt.bv_val = ptr + 1; + cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val ); + + ptr = ber_bvchr( &cnt, '#' ); + if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + cnt.bv_len = ptr - cnt.bv_val; + assert( cnt.bv_len == STRLENOF( "0x0000" ) ); + assert( strncmp(cnt.bv_val, "0x", 2) == 0 ); + + sid.bv_val = ptr + 1; + sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val ); + + ptr = ber_bvchr( &sid, '#' ); + if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) { + return LDAP_INVALID_SYNTAX; + } + + sid.bv_len = ptr - sid.bv_val; + assert( sid.bv_len == STRLENOF( "0" ) ); + + mod.bv_val = ptr + 1; + mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val ); + assert( mod.bv_len == STRLENOF( "0000" ) ); + + normalized->bv_len = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ); + normalized->bv_val = ber_memalloc_x( normalized->bv_len + 1, ctx ); + + ptr = normalized->bv_val; + + ptr = lutil_strncopy( ptr, gt.bv_val, 10); + ptr = lutil_strncopy( ptr, gt.bv_val + 11, 2); + ptr = lutil_strncopy( ptr, gt.bv_val + 14, 2); + + ptr = lutil_strcopy( ptr, ".000000Z#" ); + + *ptr++ = '0'; + *ptr++ = '0'; + ptr = lutil_strncopy( ptr, cnt.bv_val + 2, cnt.bv_len - 2); + *ptr++ = '#'; + *ptr++ = '0'; + *ptr++ = '0'; + for ( i = 0; i < sid.bv_len; i++ ) { + *ptr++ = TOLOWER( sid.bv_val[ i ] ); + } + *ptr++ = '#'; + *ptr++ = '0'; + *ptr++ = '0'; + for ( i = 0; i < mod.bv_len; i++ ) { + *ptr++ = TOLOWER( mod.bv_val[ i ] ); + } + *ptr = '\0'; + + assert( ptr - normalized->bv_val == normalized->bv_len ); + + return LDAP_SUCCESS; + } + /* Normalize a CSN */ static int csnNormalize( *************** *** 3483,3488 **** --- 3572,3583 ---- return csnNormalize23( usage, syntax, mr, val, normalized, ctx ); }
+ if ( val->bv_len == STRLENOF( "YYYYmmddHH:MM:SSZ#0xSSSS#I#ssss" ) ) { + /* Openldap <= ? */ + + return csnNormalize_stoneage( usage, syntax, mr, val, normalized, ctx ); + } + assert( val->bv_len == STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) );
ptr = ber_bvchr( val, '#' );