openldap/servers/slapd/tools/ldif2index.c
Hallvard Furuseth 496f9b1476 Factor out ldif entry parsing so all ldif2* tools will read the same format.
Valid LDIF files are parsed the same way as before.
1999-08-06 03:01:23 +00:00

89 lines
1.8 KiB
C

/*
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/socket.h>
#include <ac/unistd.h>
#include "ldif2common.h"
#include "../back-ldbm/back-ldbm.h"
#include "ldif.h"
int
main( int argc, char **argv )
{
char *linep, *buf, *attr;
int lineno, elineno;
int lmax;
int indexmask, syntaxmask;
ID id;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;
struct berval *vals[2];
ldbm_ignore_nextid_file = 1;
slap_ldif_init( argc, argv, LDIF2INDEX, "ldbm", SLAP_TOOL_MODE );
attr = attr_normalize( argv[argc - 1] );
slap_startup(dbnum);
be = &backends[dbnum];
/* disable write sync'ing */
li = (struct ldbminfo *) be->be_private;
li->li_dbcachewsync = 0;
attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
if ( indexmask == 0 ) {
exit( EXIT_SUCCESS );
}
id = 0;
lineno = 0;
buf = NULL;
lmax = 0;
vals[0] = &bv;
vals[1] = NULL;
while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 0 ) ) {
char *type, *val, *s;
ber_len_t vlen;
s = buf;
elineno = 0;
while ( (linep = ldif_getline( &s )) != NULL ) {
elineno++;
if ( ldif_parse_line( linep, &type, &val,
&vlen ) != 0 ) {
Debug( LDAP_DEBUG_PARSE,
"bad line %d in entry ending at line %d ignored\n",
elineno, lineno, 0 );
continue;
}
if ( strcasecmp( type, attr ) == 0 ) {
bv.bv_val = val;
bv.bv_len = vlen;
index_change_values( be,
attr,
vals,
id,
__INDEX_ADD_OP);
}
}
}
slap_shutdown(dbnum);
slap_destroy();
return( EXIT_SUCCESS );
}