summaryrefslogtreecommitdiffstats
path: root/ldap/admin/src/vlvindex.c
blob: e1be972c597fa5855286366fb55814ae76fd29c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/** BEGIN COPYRIGHT BLOCK
 * Copyright 2001 Sun Microsystems, Inc.
 * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/
/*
 * vlvindex.c:  Creates a VLV index for a given search
 * 
 * Rob Weltman
 */

#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>

int main(int argc, char *argv[]) 
{
	int status;
	char *backendNames = NULL;
	char *attributes = NULL;
	char *tmparg = NULL;
	char **attrList = NULL;
	char **backendList = NULL;
	int nItem = 0;
	char *nextItem = NULL;
	int i=0;

    fprintf(stdout, "Content-type: text/html\n\n");

	if ( init_ds_env() )
		return 1;

    ds_send_status("Creating vlv index ...");

	/*
	 * Get var's value 
	 */
	backendNames = ds_get_cgi_var("backendID");
	if ( (NULL == backendNames) || (strlen(backendNames) < 1) ) {
		rpt_err( DS_UNDEFINED_VARIABLE, "backendID", NULL, NULL );
		return 1;
	}

	attributes = ds_get_cgi_var("vlvTags");
	if ( (NULL == attributes) || (strlen(attributes) < 1) ) {
		rpt_err( DS_UNDEFINED_VARIABLE, "vlvTags", NULL, NULL );
		return 1;
	}	

	tmparg = strdup( attributes );
	nItem = 0;
	for(i=0 ; i < strlen(attributes) ; i++) {
		if ( tmparg[i] == ';' ) nItem++;
	}
	/* Allocate for worst possible case */
	attrList = (char **)malloc(sizeof(*attrList)  * (nItem + 2) );
	nItem = 0;
	/* strtok() is not MT safe, but it is okay to call here because this is a command line */
	attrList[nItem++] = strtok( tmparg, ";" );
	do {
		nextItem = strtok( NULL, ";" );
		attrList[nItem++] = nextItem;
	} while( nextItem != NULL );	

	tmparg = strdup( backendNames );
	nItem = 0;
	for(i=0;i<strlen(tmparg); i++) {
		if (  tmparg[i] == ';' ) nItem++;
	}
	backendList = (char **)malloc(sizeof(*backendList) * nItem + 2);
	nItem = 0;
	backendList[nItem++] = strtok( tmparg, ";" );
	do {
		nextItem = strtok( NULL, ";" );
		backendList[nItem++] = nextItem;
	} while( nextItem != NULL );	

	status = ds_vlvindex(backendList, attrList);

	if ( !status ) {
		rpt_success("Success! The index has been created.");
		status = 0;
	} else {
		rpt_err( status, backendList[0], NULL,  NULL );
		status = 1;
	}

	return status;
}