File:  [CSRG BSD Unix] / 43BSDReno / contrib / isode-beta / dsap / common / file_enc.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:56 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

#include "quipu/util.h"
#include "quipu/attrvalue.h"

extern LLog * log_dsap;

PE grab_filepe (av)
AttributeValue av;
{
FILE * fptr;
struct file_syntax * fs;
sntx_table *tbl, * get_syntax_table();
PE ret_pe, grab_pe();


	fs = (struct file_syntax *) av->av_struct;

	if (fs->fs_attr != NULLAttrV)
		return (grab_pe (fs->fs_attr));

	if (fs->fs_name == NULLCP) 
		return (NULLPE);	/* should never happen */

	if ((fptr = fopen (fs->fs_name,"r")) != NULL) {
		tbl = get_syntax_table (fs->fs_real_syntax);
		if (tbl->s_parse == NULLIFP) { /* treat as pure asn */
			PS fps;
			fps = ps_alloc (std_open);
			if ((std_setup (fps,fptr)) == NOTOK) {
				(void) fclose (fptr);
				ps_free (fps);
				return (NULLPE);
			}
			if ((ret_pe = ps2pe (fps)) == NULLPE)
				LLOG (log_dsap,LLOG_EXCEPTIONS,("invalid ASN if file %s",fs->fs_name));
			(void) fclose (fptr);
			ps_free (fps);
		} else {
			char buffer [LINESIZE];
			AttributeValue newav;
			extern char * TidyString ();
	
			(void) fread (buffer,LINESIZE,1,fptr);
			(void) fclose (fptr);
			if ((newav = str2AttrV (TidyString(buffer),fs->fs_real_syntax)) == NULLAttrV){
				LLOG (log_dsap,LLOG_EXCEPTIONS,("invalid format in file %s",fs->fs_name));
			}
			ret_pe = grab_pe (newav);
			AttrV_free (newav);
		}
	} else  {
		LLOG(log_dsap,LLOG_EXCEPTIONS,("Can't open %s",fs->fs_name));
		/* Return the PE containing NULL 
		/* a NULLPE will cause the encode to fail, thus make the
		/* operation fail.
		/* Real solution is to remove the attribute at the encode 
		/* stage - but that is tricky... 
		*/

		return (pe_alloc (PE_CLASS_UNIV, PE_FORM_PRIM, PE_PRIM_NULL));
	}
	return (ret_pe);

}


file_decode (x)
AttributeValue x;
{
struct file_syntax * fs;

	fs = (struct file_syntax *) smalloc (sizeof(struct file_syntax));
	fs->fs_ref = 1;
	fs->fs_real_syntax = x->av_syntax - AV_WRITE_FILE;
	fs->fs_name = NULLCP;
	fs->fs_mode = FS_DEFAULT;

	fs->fs_attr = AttrV_alloc ();
	fs->fs_attr->av_syntax = x->av_syntax - AV_WRITE_FILE;
	fs->fs_attr->av_struct = x->av_struct;
		
	x->av_syntax = AV_FILE;
	x->av_struct = (caddr_t)fs;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.