#ifndef __TYPEDEFS_H__
#include <shared/typedefs.h>
#endif

#ifndef __NODE4D_H__
#include <shared/node4d.h>
#endif

#ifndef __JBLIST_H__
#include <shared/jblist.h>
#endif

#ifndef __MYSTDLIB_H__
#include <shared/mystdlib.h>
#endif

#include <dos/dos.h>

/* Prototypes */

void SafeWrite(BPTR fh,uchar *str);
void WriteNode(BPTR fh,struct Node4D *n4d);
void WriteSwitch(BPTR fh,uchar *name,ulong set);
void WriteString(BPTR fh,uchar *name,uchar *str);

#define READCONFIG_NOT_FOUND  1
#define READCONFIG_INVALID    2
#define READCONFIG_NO_MEM     3

short ReadConfig(uchar *filename,struct Config *cfg,short *seconderr,ulong *cfgline,uchar *cfgerr);
short WriteConfig(struct Config *cfg,uchar *cfgerr);

void InitConfig(struct Config *cfg);
void FreeConfig(struct Config *cfg);

short CheckConfig(struct Config *cfg,uchar *cfgerr);
/* Should not be called in prefs */

/* Config data */

#define CFG_CHECKCRC               1
#define CFG_ALLOWREPLACE           2
#define CFG_USEFILEBASE            4
#define CFG_CHECKSEENBY            8   /* default on */
#define CFG_UNATTENDED            16
#define CFG_FILENOTE              32

struct Config
{
   uchar configchanged;
   uchar filename[200];

   ulong cfg_MaxWaitPickup;

   ulong cfg_RaidMaxLines;

   uchar cfg_Sysop[36];
   uchar cfg_Inbound[40];
   uchar cfg_Outbound[40];
   uchar cfg_Tickdir[40];
   uchar cfg_Filebase[40];
   uchar cfg_BadTick[40];
   uchar cfg_AutoAddDir[40];

   struct Node4D cfg_Fake4D;
   uchar cfg_FakePW[9];

   uchar cfg_Logfile[40];
   uword cfg_Loglevel;
   ulong cfg_LogBufferLines;
   ulong cfg_LogBufferSecs;

   uchar cfg_ImportCommand[200];
   uchar cfg_MagicCommand[200];
   uchar cfg_ReplaceCommand[200];

   uchar cfg_LhaExtract[80];
   uchar cfg_LhaAdd[80];
   uchar cfg_ZipExtract[80];
   uchar cfg_ZipAdd[80];

   uchar cfg_StatsFile[40];
   uchar cfg_RaidHelp[40];

   ulong cfg_Flags;

   struct jbList AkaList;
   struct jbList AreaList;
   struct jbList CNodeList;
   struct jbList AnnounceList;

   uchar cfg_GroupNames[30][80];
};

#define AREA_NOREPLACE        1
#define AREA_IGNORESEENBY     2
#define AREA_MANDATORY        4
#define AREA_DEFREADONLY      8
#define AREA_UNCONFIRMED     16

struct Area
{
   struct Area *Next;

   ulong Flags;

   struct Aka  *Aka;
   uchar Group;
   uchar Name[80];
   uchar Directory[80];
   uchar Description[80];
   uchar AreaCommand[100];
   uchar UserData[40];

   struct jbList TickNodes;

   /* Stats */

   ulong Files,NewFiles;
   ulong Bytes,NewBytes;

   ulong Last8DaysFiles[8];
   ulong Last8DaysBytes[8];

   struct DateStamp FirstTime;
   ulong LastDay;
};

#define TICKNODE_READONLY  1
#define TICKNODE_WRITEONLY 2

struct TickNode
{
   struct TickNode *Next;
   struct ConfigNode *ConfigNode;
   uword Flags;
};

struct Aka
{
   struct Aka *Next;
   struct Node4D Node;
};

#define NODE_PASSIVE        1
#define NODE_NOTIFY         4
#define NODE_AUTOADD        8
#define NODE_TINYSEENBY    16
#define NODE_NOTICFILES    32

#define PRI_NORMAL   0
#define PRI_HOLD     1
#define PRI_DIRECT   2
#define PRI_CRASH    3

#define PACKER_NONE  0
#define PACKER_ZIP   1
#define PACKER_LHA   2

#define PACKMODE_NOPACK        0
#define PACKMODE_PACKALL       1
#define PACKMODE_PACKTIC       2

struct ConfigNode
{
   struct ConfigNode *Next;
   struct Node4D Node;

   uchar TickPW[20];
   uchar RaidPW[40];

   uchar Pri;
   uchar Packer;
   uchar Packmode;

   uchar FullAccessGroups[30];
   uchar ReadOnlyGroups[30];
   uchar WriteOnlyGroups[30];

   uchar DefaultGroup;
   ulong Flags;

   uchar SysopName[36];

   /* Stats */

   ulong SentFiles,SentBytes;
   ulong GotFiles,GotBytes;
   ulong FirstDay;

   /* Only used when tossing, but it is easier to keep this here */

   int IsInSeenBy;
   uchar ArchiveName[200];
};

#define ANNOUNCE_PKT    1
#define ANNOUNCE_FILE   2

struct Announce
{
   struct Announce *Next;

   uword Method;

   struct Aka *Aka;

   uchar Groups[30];
   uchar Name[80];

   uchar Subject[72];
   uchar Origin[80];
   uchar AreaHeader[500];
   uchar AreaFooter[500];
   uchar Format[200];
   uchar Header[40];
   uchar Footer[40];

   /* Only used when tossing, but it is easier to keep this here */

   struct jbList LineList;
};
