/*
 *	Name:				xferqlib.c
 *
 * Description:	Interface to saslib controller
 *
 * Copyright:		1992-1993 by David Jones.
 *
 * Distribution:
 *		This program is free software; you can redistribute it and/or modify
 *		it under the terms of the GNU General Public License as published by
 *		the Free Software Foundation; either version 2 of the License, or
 *		(at your option) any later version.
 *
 *		This program is distributed in the hope that it will be useful,
 *		but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *		GNU General Public License for more details.
 *
 *		You should have received a copy of the GNU General Public License
 *		along with this program; if not, write to:
 *
 *				The Free Software Foundation		David Jones
 *				675 Mass Ave							6730 Tooney Drive
 *				Cambridge, MA							Orleans, Ontario
 *				02139										K1C 6R4
 *				USA										Canada
 *
 *	Usenet:	gnu@prep.ai.mit.edu					aa457@freenet.carleton.ca
 *	Fidonet:												1:163/109.8
 *
 *		$Log: $
 *
 */

#include <exec/types.h>
#include <proto/exec.h>
#include "xferq.h"
#include "xferqint.h"
#include "omnilib.h"
#include "xferq_pragmas.h"
#include "xferq_rev.h"

/* These are filled in by saslib */
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct Library *LibBase;

/* We must open these */
struct Library *UtilityBase;
struct Library *XferqBase;

extern LONG RexxUsers;
extern BOOL ConfigRead;
BOOL DeathKiss;

struct InitTab InitTab = {
	sizeof(struct OmniBase),
	&FuncTable,
	NULL,
	LIBInit
};

struct Library *__saveds LibInit(void)
/*
 *	Does:	Prepares the library for use.
 */
{

	UtilityBase = OpenLibrary("utility.library", 0);
	if (!UtilityBase) {
		return NULL;
	}
	XferqBase = LibBase;
	DeathKiss = FALSE;
	ConfigRead = FALSE;
	if (!InitMemory()) {
		return NULL;
	}
	InitErrors();
	InitAddress();
	InitQueue();
	InitRexx();
	InitSeq();
	return XferqBase;
}


struct Library *__saveds LibOpen(void)
/*
 *	Does:	This function is called to perform pre-use initialization.
 */
{

	if (!ConfigRead) {
		ReadConfig();
	}
	return XferqBase;
}


void __saveds LibClose(void)
/*
 *	Does:	This function is called to perform post-use cleanup.
 */
{
struct ENode *en;

	en = FindENode(FALSE);
	if (en) {
		if (!(en->flags & EN_ISREXX)) {
			LibFlushQueue(NULL);
			DropENode(en);
		}
	}
	return;
}


ULONG __saveds LibExpunge(void)
/*
 *	Does:	This function is called to perform pre-expunge cleanup.
 */
{

	if (!DeathKiss && (RexxUsers || AnyDirty())) {
		return FALSE;
	}
	/* DropQueue();
	DropSessions(); */
	
	/* Return memory LAST!!! */
	DropMemory();
	
	CloseLibrary(UtilityBase);
	return TRUE;
}
	

void LIBWPL1(void)
{
}

void LIBWPL2(void)
{
}
