2 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright 2000, John E. Schimmel, All rights reserved.
7 * This software is not subject to any license of Mirapoint, Inc.
9 * This is free software; you can redistribute and use it
10 * under the same terms as OpenLDAP itself.
12 /* Adapted for incorporatation into OpenLDAP by Kurt Zeilenga */
15 * This file contains routines to generate a change sequence number. Every
16 * add delete, and modification is given a unique identifier for use in
17 * resolving conflicts during replication operations.
19 * These routines are based upon draft-ietf-ldup-model-03.txt, and will
20 * need to be revisited once standardized.
22 * The format of a CSN string is: yyyymmddhh:mm:ssz#0xSSSS#d#0xssss
23 * where SSSS is a counter of operations within a timeslice, d is an
24 * offset into a list of replica records, and ssss is a counter of
25 * modifications within this operation.
27 * Calls to this routine MUST be serialized with other calls
38 lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
40 static time_t csntime;
41 static unsigned int csnop;
56 n = snprintf( buf, len, "%4d%02d%02d%02d:%02d:%02dZ#0x%04x#%d#%04x",
57 ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour,
58 ltm->tm_min, ltm->tm_sec, op, replica, mod );
61 return ( (size_t) n < len ) ? n : 0;
66 main(int argc, char **argv)
68 char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
70 if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) {
71 fprintf(stderr, "failed lutil_csnstr\n");
73 if ( ! lutil_csnstr( buf, sizeof(buf), 0, 0 ) ) {
74 fprintf(stderr, "failed lutil_csnstr\n");