mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
Add CSN routine.
This commit is contained in:
parent
3da9378c3a
commit
268ee5ff4a
@ -13,11 +13,11 @@ NT_OBJS = ntservice.o slapdmsg.res
|
||||
UNIX_SRCS = detach.c
|
||||
UNIX_OBJS = detach.o
|
||||
|
||||
SRCS = base64.c debug.c entropy.c sasl.c signal.c hash.c \
|
||||
SRCS = base64.c csn.c debug.c entropy.c sasl.c signal.c hash.c \
|
||||
md5.c passwd.c sha1.c getpass.c lockf.c utils.c uuid.c sockpair.c \
|
||||
@LIBSRCS@ $(@PLAT@_SRCS)
|
||||
|
||||
OBJS = base64.o debug.o entropy.o sasl.o signal.o hash.o \
|
||||
OBJS = base64.o csn.o debug.o entropy.o sasl.o signal.o hash.o \
|
||||
md5.o passwd.o sha1.o getpass.o lockf.o utils.o uuid.o sockpair.o \
|
||||
@LIBOBJS@ $(@PLAT@_OBJS)
|
||||
|
||||
|
74
libraries/liblutil/csn.c
Normal file
74
libraries/liblutil/csn.c
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
||||
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
||||
*/
|
||||
/* Portions
|
||||
* Copyright 2000, John E. Schimmel, All rights reserved.
|
||||
* This software is not subject to any license of Mirapoint, Inc.
|
||||
*
|
||||
* This is free software; you can redistribute and use it
|
||||
* under the same terms as OpenLDAP itself.
|
||||
*/
|
||||
/* Adapted for incorporatation into OpenLDAP by Kurt Zeilenga */
|
||||
|
||||
/*
|
||||
* This file contains routines to generate a change sequence number. Every
|
||||
* add delete, and modification is given a unique identifier for use in
|
||||
* resolving conflicts during replication operations.
|
||||
*
|
||||
* These routines are based upon draft-ietf-ldup-model-03.txt, and will
|
||||
* need to be revisited once standardized.
|
||||
*
|
||||
* The format of a CSN string is: yyyymmddhh:mm:ssz#0xSSSS#d#0xssss
|
||||
* where SSSS is a counter of operations within a timeslice, d is an
|
||||
* offset into a list of replica records, and ssss is a counter of
|
||||
* modifications within this operation.
|
||||
*
|
||||
* Calls to this routine MUST be serialized with other calls
|
||||
* to gmtime().
|
||||
*/
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ac/time.h>
|
||||
|
||||
int
|
||||
lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
|
||||
{
|
||||
static time_t csntime;
|
||||
static unsigned int csnop;
|
||||
|
||||
time_t t;
|
||||
unsigned int op;
|
||||
struct tm *ltm;
|
||||
int n;
|
||||
|
||||
time( &t );
|
||||
if ( t > csntime ) {
|
||||
csntime = t;
|
||||
csnop = 0;
|
||||
}
|
||||
op = ++csnop;
|
||||
|
||||
ltm = gmtime( &t );
|
||||
n = snprintf( buf, len, "%4d%02d%02d%02d:%02d:%02dZ#0x%04x#%d#%04x",
|
||||
ltm->tm_year + 1900, ltm->tm_mon, ltm->tm_mday, ltm->tm_hour,
|
||||
ltm->tm_min, ltm->tm_sec, op, replica, mod );
|
||||
|
||||
return ( n < len ) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) {
|
||||
fprintf(stderr, "failed lutil_csnstr\n");
|
||||
}
|
||||
if ( ! lutil_csnstr( buf, sizeof(buf), 0, 0 ) ) {
|
||||
fprintf(stderr, "failed lutil_csnstr\n");
|
||||
}
|
||||
}
|
||||
#endif
|
@ -12,11 +12,11 @@
|
||||
/* Adapted for incorporatation into OpenLDAP by Kurt Zeilenga */
|
||||
|
||||
/*
|
||||
** Sorry this file is so scary, but it needs to run on a wide range of
|
||||
** platforms. The only exported routine is lutil_uuidstr() which is all
|
||||
** that LDAP cares about. It generates a new uuid and returns it in
|
||||
** in string form.
|
||||
*/
|
||||
* Sorry this file is so scary, but it needs to run on a wide range of
|
||||
* platforms. The only exported routine is lutil_uuidstr() which is all
|
||||
* that LDAP cares about. It generates a new uuid and returns it in
|
||||
* in string form.
|
||||
*/
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
Loading…
Reference in New Issue
Block a user