#ifndef _NAP_NAP_H
#define _NAP_NAP_H

/* Copyright (c) 2000  Kevin Sullivan <nite@gis.net>
 *
 * Please refer to the COPYRIGHT file for more information.
 */

#include <dirent.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include "sscr.h"

extern int cloaked;  /* whether we are cloaked */
extern int lpbrk;

struct phead_s 
{
  unsigned short len;
  unsigned short op;
};
typedef struct phead_s phead_t;

/* the info structure contains certain global values that are set on
   the command line, prompted from the user, or read from the
   configuration file at startup. Some of these values can later be updated
   with user commands. */

struct info_s 
{
  char *name;            /* argv[0], the filename by which nap was invoked */
  char *user;            /* our Napster login name */
  char *pass;            /* our Napster password */
  char *email;           /* our Napster email address */
  char *up;              /* list of upload directories, separated by ";" */
  char *down;            /* a single download directory */
  char *incomplete;      /* a directory to hold incomplete files */
  char *serverlist;      /* ';'-separated list of servers to connect to */
  char *logallfile;      /* name of general log file (or NULL) */
  char *logfile;         /* name of transfer log file (or NULL) */
  char *dataport;        /* port or range of ports to use for client-to-client
			    connections */
  int autorestart;       /* auto reconnect when connection to server lost? */

  int port;              /* the actual dataport we are currently using
                            - not really a command line option, but a
                            state variable */

  char *shared_filename; /* name of shared library file */
  int daemon;            /* if !=0, run without user interface. When 1,
			    output to stdout, when 2, suppress output */
  int nxterm;            /* option --nxterm */
  int build;             /* 0=don't build, 1=build library, 2=build and exit */
  int create;            /* create new account? This is reset to 0 after acct created */
  int reconnect;         /* keep reconnecting until connection established? */
  int noserver;          /* start up without connecting to server */
  int notop;             /* if set, display no title */
  int bandwidthdown;     /* bandwidth limit for total downloads */
  int bandwidthup;       /* bandwidth limit for total uploads */
  int bandwidthdownconn; /* bandwidth limit for individual downloads */
  int bandwidthupconn;   /* bandwidth limit for individual uploads */
  int transparent;       /* let the terminal background shine through? */
  int sflag;             /* were -s options given on the command line? */
};
typedef struct info_s info_t;

void doquit(void);
void tresize(int);
void sigint(int);
void noop(int);
void dochecks(void);
char *quote(char *s);
char *home_file(const char *fn);
char *itoa(int n);
char *strip(char *);
char *nap_getline(FILE *f);
int readcfg(char *);
int msprintf(char **, const char *, ...)
#ifdef __GNUC__
     /* allow gcc to verify the format string */
        __attribute__ ((format (printf, 2, 3)))
#endif
;
int strcnt(char *, char);
void phelp(char *);
void dopts(int, char **);
int setup_configdir(void);
int move_file(const char *oldpath, const char *newpath);
char *next_server(char *serverlist);
int connection(void);
int main(int argc, char *argv[]);

int resolve(const char *host, struct in_addr *inp);
const char *getpeerip(int fd);
unsigned long int swapl(unsigned long int x);
int connect_t(int fd, struct sockaddr *serv_addr, int addlen, int t);
int conn(char *);
int login(int, char *, char *, int, int, char *);
int makeact(int, char *, char *, int, int, char *);
char *glistn(char *);
void checkhotlist(int, char *);
int checknv(int fd, int timeout, const char **errmsg, char **serial);

int savechans(chans_t *cl, char *fn);
int loadchans(int s, char *fn);
chans_t *findchan(chans_t *, char *);
chans_t *findquery(chans_t *, char *);

int sendpack(int, int, const char *, ...)
#if defined(__GNUC__) && 0 /* disabled: "erroneous" warnings on NULL fmt */
     /* allow gcc to verify the format string */
        __attribute__ ((format (printf, 3, 4)))
#endif
;
int ssock(int, const char *, ...)
#ifdef __GNUC__
     /* allow gcc to verify the format string */
        __attribute__ ((format (printf, 2, 3)))
#endif
;
int setkeepalive(int sock);
int recvpack(int, char **, phead_t **);
int recvpack_t(int s, char **buf, phead_t **hdr, int t);
int rsock(int, char **);

#endif /* not _NAP_NAP_H */
