/*
** GrabHTTP.h
** Copyright (C) 1996-97 Serge Emond
**
** 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, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef GRABHTTP_H
#define GRABHTTP_H 1

// Version.Revision
#define SVER        "1.05"

/// General includes

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <proto/exec.h>
#include <exec/execbase.h>
#include <exec/lists.h>
#include <exec/nodes.h>
#include <exec/memory.h>
#include <proto/dos.h>
#include <dos/stdio.h>
#include <dos/dostags.h>
#include <proto/rexxsyslib.h>
#include <rexx/storage.h>
#include <proto/timer.h>
#include <proto/utility.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <libraries/gadtools.h>
#include <clib/gadtools_protos.h>
#include "BufIO.h"

#include <string.h>

///

/// Defines

#define VERSION     "$VER: GrabHTTP "SVER" "__AMIGADATE__" (c) Serge Emond"
#define DEFAULT_PORT    80

#define OPT_TEMP        "PORT,ACCEPT,WBUF/N"
#define OPT_PORT        0
#define OPT_ACCEPT      1
#define OPT_WBUF        2
#define OPT_CNT         3

#define RES_VAR         "GHRES"
#define DEF_PORTNAME    "GRABHTTP"  // Default Port Name
#define DEF_TZ_H        5           // Default timezone: EST+05 (minutes)
#define DEF_TZ_M        0
#define DEF_TZ          (DEF_TZ_H * 60 + DEF_TZ_M)
#define DEF_MIME        "*/*"       // Default MIME setting
#define DEF_MLST_PUDDLE 1024
#define DEF_MLST_THRESH 128

#define DEF_FONT        "topaz.font"
#define DEF_FONT_SIZE   8

#define DEF_WBUF        (16*1024)
#define MIN_WBUF        (2048)
///

/// Macros

#define IsBissextile(a) ((((a) % 100) == 0) && (((a) % 400) == 0)) || \
                        ((((a) % 4) == 0) && (((a) % 100) != 0))

#define UpdFeb(y,t) t[1] = (IsBissextile(y) ? 29 : 28)

///

/// Structure Definitions

struct Table {
    LONG Day, Month, Year, Hour, Mins, Secs;
};

struct Mem {
    void *p;        // Pointeur
    ULONG s;        // Size
};

struct MemNode {
    struct MinNode n;   // MinNode struct for a MinList.
    void *p;            // The pointer itself
    ULONG s;            // Size of the block
    UBYTE t;            // Type, see MEMNT_ definitions
};

struct MemLst {
    struct MinList l;   // This is a list header...
    void *pool;         // Memory pool for nodes and strings
};

struct Functions {
    STRPTR  cmd;                // ARexx Command Name
    STRPTR  temp;               // Options template
    void (*function)(STRPTR);   // Function, arg is ptr to arguments
};

struct TimeDate {
    ULONG   Year,
            Month,
            Day,
            Week,       // Semaine de l'année
            Week_Day,   // Jour de la semaine (0 = dimanche)
            Hour,
            Mins,
            Secs;
};

#define GADGET_SKIP 1
#define GADGET_ABORT 2

struct Wtexts {
    TEXT    *url, *file, *recd, *cps, *actual, *rem, *skip, *abort;
};

struct WinInfo {
    struct TextAttr *tattr;
    ULONG
            fnth, fntw,
            win_x, win_y, win_w, win_h,

            urlt_tl, filet_tl, recdt_tl, cpst_tl, actt_tl, remt_tl,

            urlt_l, url_x, url_y, url_l, file_y, urlt_x, filet_x,

            col1t_l, col2t_l, col1_x, col1_l, col2_x, col2_l, line1_y, line2_y,
            col2t_x, recdt_x, cpst_x, actt_x, remt_x,

            long_x, long_l, long1_y, long2_y,

            prog_x1, prog_x2, prog_y1, prog_y2, prog_l,

            but_y, but2_x, but_l;
};

// Stuff specific to one process

struct Specific {

    LONG sok;                   // Socket..
    BPTR ffh;                   // Output file file handle
    bfile *bfh;                 // Buffered file handle

    ULONG   totticks;           // Ticks elapsed
    ULONG   cps;                // Last CPS rating
    ULONG   size;               // Length of the file (Header)
    ULONG   recd;               // Bytes received

    struct MemLst memlst;       // List of memory allocated

    UBYTE Initialized;          // 0 if free, 1 if alloc

    struct Window *w;
    struct Wtexts *wtexts;
    struct WinInfo winfo;
    struct Screen *scr;
    struct Gadget *glist;
    struct MyGadgets {
        struct Gadget *url, *file, *recd, *cps, *actual, *rem, *stat, *user, *prog, *skip, *abort;
    } g;
    struct GadText {
        struct Mem url, file, recd, cps, actual, rem, stat, user, prog;
    } gtxt;
    LONG BarValue;
    void *vi;
};

// Stuff common to all processes
struct Common {

    struct RDArgs *rdargs;      // ReadArgs() stuff
    LONG opts[OPT_CNT];         // Args array

    struct timerequest *tr;     // IORequest struct for timer.device

    BPTR idir;                  // Lock of initial directory

    struct MsgPort *mp;         // Message Port
    struct Message *msg;        // Pointer to current message

    ULONG CurFct;               // Number of function called

    ULONG minspace;             // Minimal space left to download
    LONG timezone;              // How many minutes to ADD to obtain GMT

    struct Mem email;           // EMail address
    struct Mem auth;            // Auth information

    struct WinInfo wi;
    struct TextFont *txt_fnt;

    ULONG wbufsize;             // Size of write buffer
};

///

/// Flags

// Types for struct MemNode
#define MEMNT_BUF       1   // IOBuffer
#define MEMNT_URL       2   // Url's name should be only one of that type...
#define MEMNT_HEADER    3   // Header lines
#define MEMNT_OTHER     0   // ... other!

///

#endif

