]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/ldapsync.c
Add pointer to an existing document since the netscape.com URLs are dead.
[openldap] / servers / slapd / ldapsync.c
index 652622d0c9f6faa6df18b479a2972fe31e6f4ff0..1d7bf3b2bf2e34d1347118e1e5ba1309f95b4669 100644 (file)
@@ -35,12 +35,13 @@ slap_compose_sync_cookie(
        Operation *op,
        struct berval *cookie,
        BerVarray csn,
-       int rid )
+       int rid,
+       int sid )
 {
        int len, numcsn = 0;
 
        if ( csn ) {
-               for (; !BER_BVISEMPTY( &csn[numcsn] ); numcsn++);
+               for (; !BER_BVISNULL( &csn[numcsn] ); numcsn++);
        }
 
        if ( numcsn == 0 || rid == -1 ) {
@@ -51,6 +52,9 @@ slap_compose_sync_cookie(
                } else {
                        len = snprintf( cookiestr, sizeof( cookiestr ),
                                        "rid=%03d", rid );
+                       if ( sid >= 0 ) {
+                               len += sprintf( cookiestr+len, ",sid=%03x", sid );
+                       }
                }
                ber_str2bv_x( cookiestr, len, 1, cookie, 
                        op ? op->o_tmpmemctx : NULL );
@@ -63,12 +67,19 @@ slap_compose_sync_cookie(
                        len += csn[i].bv_len + 1;
 
                len += STRLENOF("rid=123,csn=");
+               if ( sid >= 0 )
+                       len += STRLENOF("sid=xxx,");
+
                cookie->bv_val = slap_sl_malloc( len, op ? op->o_tmpmemctx : NULL );
 
-               len = sprintf( cookie->bv_val, "rid=%03d,csn=", rid );
+               len = sprintf( cookie->bv_val, "rid=%03d,", rid );
                ptr = cookie->bv_val + len;
+               if ( sid >= 0 ) {
+                       ptr += sprintf( ptr, "sid=%03x,", sid );
+               }
+               ptr = lutil_strcopy( ptr, "csn=" );
                for ( i=0; i<numcsn; i++) {
-                       ptr = lutil_strncopy( ptr, csn->bv_val, csn->bv_len );
+                       ptr = lutil_strncopy( ptr, csn[i].bv_val, csn[i].bv_len );
                        *ptr++ = ';';
                }
                ptr--;
@@ -160,6 +171,7 @@ slap_parse_sync_cookie(
                return -1;
 
        cookie->rid = -1;
+       cookie->sid = -1;
        cookie->ctxcsn = NULL;
        cookie->sids = NULL;
        cookie->numcsns = 0;
@@ -181,12 +193,24 @@ slap_parse_sync_cookie(
                        }
                        continue;
                }
+               if ( !strncmp( next, "sid=", STRLENOF("sid=") )) {
+                       rid_ptr = next;
+                       cookie->sid = strtoul( &rid_ptr[ STRLENOF( "sid=" ) ], &next, 16 );
+                       if ( next == rid_ptr || next > end || *next != ',' ) {
+                               return -1;
+                       }
+                       if ( *next == ',' ) {
+                               next++;
+                       }
+                       continue;
+               }
                if ( !strncmp( next, "csn=", STRLENOF("csn=") )) {
                        slap_syntax_validate_func *validate;
                        struct berval stamp;
 
-                       csn_str = next + STRLENOF("csn=");
+                       next += STRLENOF("csn=");
                        while ( next < end ) {
+                               csn_str = next;
                                /* FIXME use csnValidate when it gets implemented */
                                csn_ptr = strchr( csn_str, '#' );
                                if ( !csn_ptr || csn_ptr > end )
@@ -257,6 +281,7 @@ slap_init_sync_cookie_ctxcsn(
        cookie->ctxcsn = NULL;
        value_add_one( &cookie->ctxcsn, &ctxcsn );
        cookie->numcsns = 1;
+       cookie->sid = -1;
 
        return 0;
 }
@@ -286,6 +311,7 @@ slap_dup_sync_cookie(
        }
 
        new->rid = src->rid;
+       new->sid = src->sid;
        new->numcsns = src->numcsns;
 
        if ( src->numcsns ) {