|
|
BSD 4.3reno
/* parse.c - */
#ifndef lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/dsap/common/parse.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif
/*
* $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/dsap/common/parse.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
*
*
* $Log: parse.c,v $
* Revision 1.1.1.1 2018/04/24 16:12:56 root
* BSD 4.3reno
*
* Revision 7.1 90/07/09 14:34:54 mrose
* sync
*
* Revision 7.0 89/11/23 22:17:56 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 "quipu/config.h"
#include "quipu/util.h"
#include "quipu/entry.h"
#include "quipu/ds_error.h"
#include "quipu/malloc.h"
#ifdef TURBO_DISK
#include <gdbm.h>
#endif
#ifndef TURBO_DISK
#define PARSE_BUFFER 10000
static char parse_buffer [PARSE_BUFFER];
#endif
Entry database_root;
int local_master_size = 0;
int local_slave_size = 0;
int local_cache_size = 0;
#ifdef TURBO_DISK
extern char *parse_entry;
int dbmeof;
int dbmfirst = 1;
datum turbo_header_key = { "HEADER", sizeof("HEADER") };
#endif
extern time_t time ();
#ifdef TURBO_DISK
char *getline (db)
GDBM_FILE db;
{
static datum newkey, key, dat;
static char *line, *next, *save;
static int new_entry;
char *TidyString();
int save_heap;
save_heap = mem_heap;
GENERAL_HEAP;
if (dbmfirst) {
dbmfirst = 0;
key = gdbm_firstkey(db);
parse_entry = key.dptr;
new_entry = 1;
} else if (line == NULLCP || *line == '\0') {
newkey = gdbm_nextkey(db, key);
free(key.dptr);
key = newkey;
parse_entry = key.dptr;
new_entry = 1;
}
if (key.dptr == NULLCP) {
dbmeof = 1;
dbmfirst = 1;
mem_heap = save_heap;
return(NULLCP);
}
if (new_entry) {
/* gross, but we have to skip the header datum */
if (strcmp(key.dptr, turbo_header_key.dptr) == 0) {
newkey = gdbm_nextkey(db, key);
free(key.dptr);
key = newkey;
if (key.dptr == NULLCP) {
parse_entry = key.dptr;
dbmeof = 1;
dbmfirst = 1;
mem_heap = save_heap;
return(NULLCP);
}
}
new_entry = 0;
parse_entry = key.dptr;
dat = gdbm_fetch(db, key);
if ((line = dat.dptr) == NULLCP) {
parse_error("edb error - null dbm data");
return(NULLCP);
}
}
if (*line == '\n') {
line = NULLCP;
free(dat.dptr);
mem_heap = save_heap;
return("");
}
line = SkipSpace(line);
while (*line == '#') {
line = index(line, '\n') + 1;
if (*line == '\0') {
mem_heap = save_heap;
return(NULLCP);
}
line = SkipSpace(line);
}
next = index(line, '\n');
*next++ = '\0';
save = line;
line = next;
mem_heap = save_heap;
return(TidyString(save));
}
#else
char * getline (file)
FILE * file;
{
extern int parse_line;
char * ptr;
extern char * TidyString ();
while ( fgets (parse_buffer,PARSE_BUFFER,file) != NULLCP) {
parse_line++;
ptr = SkipSpace (parse_buffer);
if (*ptr != '#')
return (TidyString(ptr));
}
return (NULLCP);
}
#endif
Attr_Sequence get_attributes_aux (file)
#ifdef TURBO_DISK
GDBM_FILE file;
#else
FILE * file;
#endif
{
Attr_Sequence as = NULLATTR;
Attr_Sequence as_combine ();
char * ptr;
if ((ptr = getline (file)) == NULLCP)
return (NULLATTR);
while ( *ptr != 0 ) {
as = as_combine (as,ptr);
if ((ptr = getline (file)) == NULLCP)
break;
}
return (as);
}
Attr_Sequence get_attributes (file)
#ifdef TURBO_DISK
GDBM_FILE file;
#else
FILE * file;
#endif
{
extern int parse_status;
extern int parse_line;
parse_status = 0;
parse_line = 0;
return (get_attributes_aux (file));
}
Entry get_entry_aux (file,parent,dtype)
#ifdef TURBO_DISK
GDBM_FILE file;
#else
FILE * file;
#endif
Entry parent;
int dtype;
{
Entry eptr;
char * ptr;
extern RDN parse_rdn;
struct DSError err;
extern int print_parse_errors;
extern int parse_line;
int save;
extern PS opt;
char check = TRUE;
DATABASE_HEAP;
eptr = get_default_entry (parent);
eptr->e_data = dtype;
if ((ptr = getline (file)) == NULLCP) {
GENERAL_HEAP;
return (NULLENTRY);
}
while (*ptr == 0)
if ((ptr = getline (file)) == NULLCP) {
GENERAL_HEAP;
return (NULLENTRY);
}
if ((eptr->e_name = str2rdn (ptr)) == NULLRDN) {
parse_error ("invalid rdn %s",ptr);
check = FALSE;
}
parse_rdn = eptr->e_name;
eptr->e_attributes = get_attributes_aux (file);
if (check) {
save = parse_line;
parse_line = 0;
if (unravel_attribute (eptr,&err) != OK) {
parse_error ("Error in entry ending line %d...",(char *) save);
if (print_parse_errors)
ds_error (opt,&err);
}
if (check_schema (eptr,NULLATTR,&err) != OK) {
parse_error ("Schema error in entry ending line %d...",(char *) save);
if (print_parse_errors)
ds_error (opt,&err);
}
parse_line = save;
}
parse_rdn = NULLRDN;
GENERAL_HEAP;
switch (dtype) {
case E_TYPE_SLAVE:
local_slave_size++; break;
case E_DATA_MASTER:
local_master_size++; break;
case E_TYPE_CACHE_FROM_MASTER:
eptr->e_age = time ((time_t *)0);
local_cache_size++; break;
}
return (eptr);
}
Entry get_entry (file,parent,dtype)
#ifdef TURBO_DISK
GDBM_FILE file;
#else
FILE * file;
#endif
Entry parent;
int dtype;
{
extern int parse_status;
extern int parse_line;
parse_status = 0;
parse_line = 0;
return (get_entry_aux (file,parent,dtype));
}
Entry new_constructor (parent)
Entry parent;
{
Entry constructor;
constructor = get_default_entry (parent);
constructor->e_leaf = FALSE;
constructor->e_complete = FALSE;
constructor->e_data = E_TYPE_CONSTRUCTOR;
constructor->e_acl = acl_alloc ();
constructor->e_acl->ac_child = acl_dflt ();
constructor->e_acl->ac_entry = acl_dflt ();
constructor->e_acl->ac_default = acl_dflt ();
constructor->e_acl->ac_attributes = NULLACL_ATTR;
return (constructor);
}
Entry make_path (dn)
DN dn;
{
Entry ptr;
register RDN a_rdn, b_rdn;
if ((database_root == NULLENTRY) || (database_root->e_child == NULLENTRY)) {
database_root = new_constructor(NULLENTRY);
ptr = database_root;
for (; dn!= NULLDN; dn=dn->dn_parent) {
ptr->e_child = new_constructor(ptr);
ptr = ptr->e_child;
ptr->e_name = rdn_cpy (dn->dn_rdn);
}
return (ptr);
} else {
/* follow links as far as poss, then add new bits */
if (dn == NULLDN)
return (database_root);
ptr = database_root->e_child;
b_rdn = dn->dn_rdn;
a_rdn = ptr->e_name ;
for(;;) { /* return out */
while (rdn_cmp (a_rdn, b_rdn) != OK) {
if (ptr->e_sibling == NULLENTRY) {
ptr->e_sibling = new_constructor(ptr->e_parent);
ptr = ptr->e_sibling;
ptr->e_name = rdn_cpy (dn->dn_rdn);
for (dn=dn->dn_parent; dn!= NULLDN; dn=dn->dn_parent) {
ptr->e_child = new_constructor(ptr);
ptr = ptr->e_child;
ptr->e_name = rdn_cpy (dn->dn_rdn);
}
return (ptr);
}
ptr = ptr->e_sibling;
a_rdn = ptr->e_name ;
}
if ( dn->dn_parent == NULLDN)
return (ptr);
dn = dn->dn_parent;
b_rdn = dn->dn_rdn;
if ( ptr->e_child == NULLENTRY) {
for (; dn!= NULLDN; dn=dn->dn_parent) {
ptr->e_child = new_constructor(ptr);
ptr = ptr->e_child;
ptr->e_name = rdn_cpy (dn->dn_rdn);
}
return (ptr);
}
ptr = ptr->e_child;
a_rdn = ptr->e_name;
}
}
/* NOTREACHED */
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.