
/*      Get and Resume Elite EDition source code


Get and Resume Elite EDition (GREED)
Copyright (C) 1999  Anoakie Turner

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., 675 Mass Ave, Cambridge, MA 02139, USA.

For more information on the GPL, please go to:
http://www.gnu.org/copyleft/gpl.html


        Contact:  Anoakie Turner
                  Anoakie.Turner@asu.edu

                  13240 N. 94th Pl.
                  Scottsdale, AZ 85260
*/


/*
**  To compile, use gcc -O2 -Wall -o greed greed.c
**
**
**  To compile under any non linux OS, use:
**  gcc -O2 -Wall -lsocket -lxnet -o greed greed.c
*/

#ifndef GREED_MAIN_H
#define GREED_MAIN_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#ifdef USE_GTK
#include <gtk/gtk.h>
#include "gui.h"
#include "gui_utils.h"
#endif
#ifdef __riscos__
#include <sys/select.h>
#define usleep sleep
#endif

#define HTTP 1
#define FTP 2
#define CURRENT_VERSION "GREED/0.82+ BETA 1 sb4!"
#define GGR "http://www.public.asu.edu/~arturner/greed.tar.gz"
#define BASE64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"


typedef int bool;


extern long ROLLBACK;
extern int TIMEOUT_SEC;
extern int MINSPEED;
extern long FTP_WAIT_TIME;
extern int OUTPUT_LEVEL;
extern int REFERRER;
extern int WAIT_RETRY;
extern bool STDOUT;
extern bool NOSIZE;
extern int DEBUG;
extern int CALL_ME;
extern char *CALL_ADDR;
extern char *PROXY;
extern char *PROXYPORT;
extern char *DEFAULT_DIR;
extern int dlstat;
extern long dldots;
extern struct sockaddr_in address;
extern unsigned int dport;
extern time_t start, end;
extern fd_set testfds;
extern char REF[1024];


typedef struct URLstruct
{	char *name;
	char *server;
	char *file;
	char *filename;
	char *user;
	char *pass;
	char *left;
	char *size;
	char *total;
	char *cport;
	char *b64pass;
	unsigned int port;
	int protocol;
	int sockfd;
	int recurse;
	struct hostent *host;
	struct servent *serv;
	long lleft;
	long lsize;
	long ltotal;
	FILE *fp;
	bool done, resume, retry;
#ifdef USE_GTK
	GtkLabel *label;
	GtkProgressBar *bar;
	pid_t pid;
#endif
} *URLp, URLst;


typedef struct NODE
{	struct URLstruct URL;
	struct NODE *next;
} NODE;
extern NODE *list;
extern NODE *curr;


#ifdef USE_GTK
extern int filedes[2];
extern FILE *out, *in;


void RemoveURL (char *U);
extern int RECURSE;
#endif

void Download(URLp URL);
void DownloadLoop(URLp URL);
void Switches(int i, char *argv[]);
bool ReadHTTPHeader(URLp URL);
int  ReadSock (int sockfd, char* buffer, char* stopstr);
int  ReadPASVPort(char *buffer);
bool ReadFTPListing(URLp URL);
bool Parse(URLp URL);
bool Connect(URLp URL);
void SendFTPConnectData(URLp URL);
void SendHTTPConnectData(URLp URL);
char *ReadString(char *str1, int *ind, char stopchar, int stopint);
char *ReadString2(char *str1, char stopchar);
char *Base64Encode(char *str1);
void Proxy(int NEWRC);
void CreateNewRC(FILE* fp);
void unescape_url (char *url);
char x2c (char *what);
NODE *InsertURL (char *U, int);
void PrintList ();

#endif /* GREED_MAIN_H */
