DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T e

⟦8777fafe3⟧ TextFile

    Length: 9541 (0x2545)
    Types: TextFile
    Names: »entry_load.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« 
        └─⟦de7628f85⟧ 
            └─⟦this⟧ »isode-6.0/quipu/entry_load.c« 

TextFile

/* entry_load.c - load bits of the database */

#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/entry_load.c,v 7.1 89/12/19 16:20:34 mrose Exp $";
#endif

/*
 * $Header: /f/osi/quipu/RCS/entry_load.c,v 7.1 89/12/19 16:20:34 mrose Exp $
 *
 *
 * $Log:	entry_load.c,v $
 * Revision 7.1  89/12/19  16:20:34  mrose
 * sync
 * 
 * Revision 7.0  89/11/23  22:17:39  mrose
 * Release 6.0
 * 
 */

/*
 *                                NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */

#include "config.h"
#include "quipu/util.h"
#include "quipu/entry.h"
#include "quipu/ds_error.h"
#include "tailor.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

extern char * treedir;
extern LLog * log_dsap;
extern int errno;
struct acl_info * acl_dflt ();

static char filename [LINESIZE];
static PS ps;

#define EDBLEN	3	/* length of string "EDB" */

fileexists (fname)
char * fname;
{
struct stat buf;

	if (stat (fname,&buf) != 0) {
		if (errno != ENOENT)
			DLOG (log_dsap,LLOG_DEBUG,("File %s will not stat - %d",fname,errno));
		return FALSE;
	}
	return TRUE;
}

static read_mapped_rdn (aps,name,file)
PS aps;
char * name;
char * file;
{
FILE * mapfp;
char *ptr, *newname, *getline();
extern int parse_line;
register int i;

	if ((mapfp = fopen (file,"r")) == (FILE *)NULL) {
		LLOG(log_dsap,LLOG_EXCEPTIONS,("Can read \"%s\" (%d)",file,errno));
		return FALSE;
	}

	parse_line = 0;
	while ( (ptr = getline(mapfp)) != NULLCP) {
		if ((newname = rindex(ptr,'#')) == NULLCP) {
			LLOG(log_dsap,LLOG_EXCEPTIONS,("Seperator missing in map file \"%s\", line %d",file,parse_line));
			(void) fclose (mapfp);			
			return FALSE;
		}
		*newname++ = 0;
		if (lexequ (name,ptr) == 0) {
			/* got it - replace in ps*/	
			i = strlen (name);
			aps->ps_ptr -= i;
			aps->ps_cnt += i;
			ps_print (aps,newname);
			(void) fclose (mapfp);			
			return TRUE;
		}
	}

	DLOG (log_dsap, LLOG_DEBUG,("%s not found in map file %s",name,file));
	(void) fclose (mapfp);			
	return FALSE;
}

static write_mapped_rdn (aps,name,file)
PS aps;
char * name;
char * file;
{
FILE * mapfp;
char mapname[LINESIZE];
char sname[LINESIZE];
char *mptr, *nptr;
register int i;

	if (strlen(name) < MAXFILENAMELEN) 
		return FALSE;

	/* Make unique name for it */
	mptr = mapname;
	if ((nptr = index (name,'=')) == NULLCP)
		return FALSE;

	for (i=0 ; (*nptr!=0) && (i < MAXFILENAMELEN-6) ; nptr++)
		if (isalpha(*nptr))
			*mptr++ = *nptr, i++;

	(void) strcpy (sname,name);
	(void) strcpy (mptr,"XXXXXX");
	i = strlen (name);
	nptr = (aps->ps_ptr -= i);
	aps->ps_cnt += i;
	ps_print (aps,mapname);
	*aps->ps_ptr = 0;

	if ((aps->ps_base = mktemp (aps->ps_base)) == NULLCP)
		return FALSE;

	DLOG(log_dsap,LLOG_DEBUG,("mapped name %s",aps->ps_base));

	if (mkdir (aps->ps_base,0700) != 0) {
		LLOG (log_dsap,LLOG_EXCEPTIONS,("map rdn mkdir failure \"%s\" (%d)",aps->ps_base,errno));
		return FALSE;
	}

	/* write it to map file */
	if (fileexists(file)) 
		mapfp = fopen (file,"a");
	else {
		int um;
		um = umask (0177);
		mapfp = fopen (file,"w");
		(void) umask (um);
	}

	if (mapfp == (FILE *)NULL) {
		LLOG(log_dsap,LLOG_EXCEPTIONS,("Can't write to \"%s\" (%d)",file,errno));
		return FALSE;
	}

	if (fprintf (mapfp,"%s#%s\n",sname,nptr) == EOF) {
		LLOG(log_dsap,LLOG_EXCEPTIONS,("Can't write to \"%s\" (%d)",file,errno));
		return FALSE;
	}

	if (fclose (mapfp) != 0) {
		LLOG(log_dsap,LLOG_EXCEPTIONS,("Can't close \"%s\" (%d)",file,errno));
		return FALSE;
	}

	return TRUE;
}

static rdn2filename (aps,rdn,make)
PS aps;
RDN rdn;
char make;
{
	char *start = aps->ps_ptr;
	char mapbuf [LINESIZE];	

	/* look for EDB.map file */
	*aps->ps_ptr = 0;
	(void) sprintf (mapbuf, "%sEDB.map",aps->ps_base);

	rdn_print (aps,rdn,DIROUT);
	*aps->ps_ptr = 0;

	if ((fileexists (mapbuf)) && (read_mapped_rdn (aps,start,mapbuf))) 
		return OK;
#ifdef SYS5
	else if ( strlen(start) > MAXFILENAMELEN ) 
		LLOG (log_dsap,LLOG_EXCEPTIONS,("Potential problem with \"%s\" (name too long)",start));
#endif

	if (fileexists(aps->ps_base))
		return OK;
	
	if (make) { 
		if (write_mapped_rdn (aps,start,mapbuf)) 
			return OK;
		if (mkdir (aps->ps_base,0700) != 0) {
			LLOG (log_dsap,LLOG_EXCEPTIONS,("dn2file mkdir failure \"%s\" (%d)",aps->ps_base,errno));
			return NOTOK;
		}
		return OK;
	}

	return NOTOK;
}

static dn2filename (aps,dn,make)
PS aps;
DN dn;
char make;
{
	if (treedir != NULLCP) {
		ps_print (aps,isodefile(treedir,0));
		if (make) {
			*aps->ps_ptr = 0;
			if ((! fileexists (aps->ps_base)) &&
				(mkdir (aps->ps_base,0700) != 0)) {
				LLOG (log_dsap,LLOG_EXCEPTIONS,("dn2file mkdir failure \"%s\" (%d)",aps->ps_base,errno));
				return NOTOK;
				}
		}
		if (*(aps->ps_ptr - 1) != '/')
			ps_print (aps,"/");
	} else
		ps_print (aps,"./");

	if (dn != NULLDN) {
		if (rdn2filename (aps,dn->dn_rdn,make) == NOTOK)
			return NOTOK;
		if (dn->dn_parent != NULLDN) {
			DN eptr;
			for (eptr = dn->dn_parent; eptr != NULLDN; eptr = eptr->dn_parent) {
				ps_print (aps,"/"); 
				if (rdn2filename (aps,eptr->dn_rdn,make) == NOTOK)
					return NOTOK;
			}
		}
	}

	return OK;

}

char * dn2edbfile (dn)
DN dn;
{
PS aps;
static char result [LINESIZE];

	if ((aps = ps_alloc (str_open)) == NULLPS) {
		LLOG (log_dsap, LLOG_EXCEPTIONS, ("dn2dir ps_alloc failed"));
		return NULLCP;
	}
	if (str_setup (aps,result,LINESIZE,1) == NOTOK) {
		LLOG (log_dsap, LLOG_EXCEPTIONS, ("dn2dir ps_alloc failed"));
		return NULLCP;
	}

	if (dn2filename (aps,dn,TRUE) != OK)
		return NULLCP;

	if (*(aps->ps_ptr - 1) != '/')
		ps_print (aps,"/EDB");
	else
		ps_print (aps,"EDB");
	*aps->ps_ptr = 0;

	ps_free (aps);

	return result;
}

static file_check (offset,entryptr)
register int offset;
register Entry entryptr;
{
	ps->ps_ptr = filename + offset;
	ps->ps_cnt = LINESIZE - offset;

	if (rdn2filename (ps,entryptr->e_name,FALSE) == OK) {
		if (*(ps->ps_ptr - 1) != '/')
			ps_print (ps,"/EDB");
		else
			ps_print (ps,"EDB");
		*ps->ps_ptr = 0;
		return (OK);
	}
	return (NOTOK);
}

static entry_load_kids (entryptr,offset)
register Entry entryptr;
register int offset;
{
register Entry ptr;

	ps->ps_ptr = filename + offset;
	ps->ps_cnt = LINESIZE - offset;
	*ps->ps_ptr = 0;

	for ( ptr = entryptr; ptr != NULLENTRY; ptr = ptr->e_sibling) {
		if ((ptr->e_master == NULLAV) && (ptr->e_slave == NULLAV)) {
			ptr->e_leaf = TRUE;
			continue;
		}

		if (file_check (offset,ptr) == OK) {
			if ((ptr->e_child = getentry_block (ptr,filename)) == NULLENTRY)
				return (NOTOK);

			ptr->e_leaf = FALSE;
			if (entry_load_kids (ptr->e_child,strlen(filename) - EDBLEN) == NOTOK)
				return (NOTOK);
		} else
			LLOG (log_dsap,LLOG_TRACE,("Sibling file %s/EDB NOT found", filename));
	}
	return (OK);

}


Entry subtree_load (parent,dn)
Entry parent;
DN dn;
{
Entry treetop, temp, old_entry, sibl, find_sibling();

	if ((parent != NULLENTRY) && (parent->e_child != NULLENTRY))
		if (parent->e_child->e_data != E_TYPE_CONSTRUCTOR)
			return (parent->e_child);

	if ((ps = ps_alloc (str_open)) == NULLPS) {
		LLOG (log_dsap, LLOG_EXCEPTIONS, ("file open ps_alloc failed"));
		return (NULLENTRY);
	}
	if (str_setup (ps,filename,LINESIZE,1) == NOTOK) {
		LLOG (log_dsap, LLOG_EXCEPTIONS, ("file open ps_alloc failed"));
		return (NULLENTRY);
	}

	(void) dn2filename (ps,dn,FALSE);
	if (*(ps->ps_ptr - 1) != '/')
		ps_print (ps,"/EDB");
	else
		ps_print (ps,"EDB");
	*ps->ps_ptr = 0;

	if ((parent != NULLENTRY) && (parent->e_child != NULLENTRY)) {
		/* yuk - already got an edb lower in the DIT ... */
		treetop = getentry_block (parent,filename);

		for (temp = treetop; temp != NULLENTRY; temp=temp->e_sibling) {
			temp->e_parent = parent;

			if ((old_entry = find_sibling (temp->e_name,parent->e_child)) != NULLENTRY) {
				temp->e_leaf = FALSE;
				temp->e_allchildrenpresent = old_entry->e_allchildrenpresent;
				temp->e_child = old_entry->e_child;
				for (sibl = temp->e_child; sibl != NULLENTRY; sibl=sibl->e_sibling)
					sibl->e_parent = temp;
				if (old_entry->e_edbversion != NULLCP)
					temp->e_edbversion = strdup (old_entry->e_edbversion);
			}

		}
		for (temp = parent->e_child; temp != NULLENTRY; temp=old_entry) {
			old_entry = temp->e_sibling;
			entry_free (temp);
		}

		parent->e_child = treetop;

		ps_free (ps);
		return (treetop);
	}

	if (dn == NULLDN) {
		parent = get_default_entry (NULLENTRY);
		parent->e_leaf = FALSE;
		parent->e_acl = acl_alloc();
		parent->e_acl->ac_child = acl_dflt ();
		parent->e_acl->ac_entry = acl_dflt ();
		parent->e_acl->ac_default = acl_dflt ();
		if ((treetop = getentry_block (parent,filename)) == NULLENTRY) 
			return (NULLENTRY);
	} else 
		treetop = getentry_block (parent,filename);

	parent->e_child = treetop;

	if (entry_load_kids (treetop,strlen (filename) - EDBLEN) == NOTOK)
		return (NULLENTRY);

	ps_free (ps);

	if (dn == NULLDN)
		return (parent); /* be wary of this when calling subtree load... */
				 /* if DN == NULL - you may want the child !!! */
	else
		return (treetop);
}

refresh_from_disk(dn)
DN	dn;
{
Entry parent;
Entry child;
Entry tmp;
extern Entry database_root;

	if ((parent = local_find_entry (dn,FALSE)) == NULLENTRY)
		return (NOTOK);

	child = parent->e_child;
	parent->e_child = NULLENTRY;

	if ((tmp = subtree_load (parent,dn)) == NULLENTRY)
		return (NOTOK);

	if (dn == NULLDN) {
		database_root = tmp;
		entry_free (parent);
	}
	directory_free (child);

	return (OK);
}