dslinux/user/bitchx/dll/nap Changes Makefile.in README.nap md5.c md5.h nap.c nap.sh nap_file.c napfunc.c napother.c napsend.c napster.h test test.c to-do

stsp stsp at user.in-berlin.de
Sun Jul 2 15:18:36 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/bitchx/dll/nap
In directory antilope:/tmp/cvs-serv9280/dll/nap

Added Files:
	Changes Makefile.in README.nap md5.c md5.h nap.c nap.sh 
	nap_file.c napfunc.c napother.c napsend.c napster.h test 
	test.c to-do 
Log Message:
Adding pristine copy of BitchX so I can branch from it.


--- NEW FILE: to-do ---
[Nap] Recieved error for [609] booz_hound

"\home\mp3\incoming\VA-Promo_Only_Canadian_Modern_Rock_November_1999-
          KSI\10-silverchair-miss_you_love-ksi.mp3".
[Nap] Recieved error for [609] jaime_romain
"\home\mp3\Albums5\Rosie_ODonnell-A_Rosie_Christmas-1999-EGO\09-rosie
          _odonnell-last_christmas_ft._darren_hayes-ego.mp3".
[Nap] Recieved error for [609] booz_hound

"\home\mp3\incoming\Various_Artists-WBCN_Naked_Disc_2000-ALLiED\08-si
          lverchair-anthem_for_the_year_2000-allied.mp3".

remove person from send queue on receipt of 609

--- NEW FILE: md5.h ---
#ifndef MD5_H
#define MD5_H

#ifdef __alpha
typedef unsigned int uint32;
#else
typedef unsigned long uint32;
#endif

struct MD5Context {

uint32 buf[4];

uint32 bits[2];

unsigned char in[64];
};

void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf,
       unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
void MD5Transform(uint32 buf[4], uint32 const in[16]);

/*
 * This is needed to make RSAREF happy on some MS-DOS compilers.
 */
typedef struct MD5Context MD5_CTX;
#define md5_init MD5Init
#define md5_state_t MD5_CTX 
#define md5_append MD5Update
#define md5_finish MD5Final

#endif /* !MD5_H */


--- NEW FILE: Makefile.in ---
SHELL = @SHELL@

srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
topdir = @topdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = @oldincludedir@

local_dir = $(HOME)

# Where the BitchX binary will be installed.
# "make install" will compile and install the program.
INSTALL_IRC = @INSTALL_IRC@

# Where the BitchX library will be. Generally this is the place that
# you put the scripts, help pages and translation tables. It is
# very important that you set this correctly.
IRCLIB = @IRCLIB@

CC = @CC@
DEFS = @INCLUDES@
LIBS = @LIBS@

# Tcl library.
TCL_LIBS = @TCL_LIBS@

# These are for Tcl support.
TCL_OBJS = @TCL_OBJS@
# You don't have the following, so you'll want to leave this blank.
TCL_SRCS = @TCL_SRCS@

# Set this to -g if you want to be able to debug the client, otherwise
# use -O to have the compiler do some optimization instead.
CFLAGS = @CFLAGS@

# Set this to -s if you want the binary to be stripped.
LDFLAGS = @LDFLAGS@

# These are for the cd device player.
CD_SRCS = @CD_SRCS@
CD_OBJS = @CD_OBJS@

# This is the executable suffix for the target operating system.
EXEEXT = @EXEEXT@

# Extra files.
DEFAULT_CTOOLZ_DIR = @DEFAULT_CTOOLZ_DIR@
DEFAULT_MSGLOGFILE = @DEFAULT_MSGLOGFILE@
DEFAULT_BITCHX_HELP_FILE = @DEFAULT_BITCHX_HELP_FILE@
DEFAULT_SCRIPT_HELP_FILE = @DEFAULT_SCRIPT_HELP_FILE@
DEFAULT_BITCHX_KICK_FILE = @DEFAULT_BITCHX_KICK_FILE@
DEFAULT_BITCHX_QUIT_FILE = @DEFAULT_BITCHX_QUIT_FILE@
DEFAULT_BITCHX_IRCNAME_FILE = @DEFAULT_BITCHX_IRCNAME_FILE@

# Full path of the directory for BitchX help files.
HELPDIR = @HELPDIR@

# Full path of the directory for the BitchX scripts.
INSTALL_SCRIPT = @INSTALL_SCRIPT@

# Default setting for IRCPATH where BitchX will look for
# its script files if the environment variable is undefined.
# Usually, this should contain the same path as used for INSTALL_SCRIPT in
# the Makefile, but it can contain multiple path elements
# separated by colons. The path MUST lead to an existing directory,
# because the 'global' script is expected to be found there.
IRCPATH = @IRCPATH@

# Path for TRANSLATION variable.
TRANSLATION_PATH = @TRANSLATION_PATH@

# This command will be used to install the BitchX help files. If you don't
# want to install them, replace with the following:
# INSTALL_HELP_CMD = @echo The help files have not been installed.
INSTALL_HELP_CMD = @INSTALL_HELP_CMD@

# This is where the optional plugins will be copied to.
PLUGINDIR = @PLUGINDIR@

# Plugin flags.
SHLIB_LD = @SHLIB_LD@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_SUFFIX = @SHLIB_SUFFIX@

# This command will be used to install the BitchX files on Win32/OS2EMX
# systems.
WINNT_INSTALL = @WINNT_INSTALL@

# This program allows you to use screen/xterm's to put new BitchX windows
# on new screen/xterm windows.
INSTALL_WSERV = @INSTALL_WSERV@

# This program allows you to screen BitchX and reattach to it later.
INSTALL_SCRBX = @INSTALL_SCRBX@

# Set gzip and bzip2 options.
GZIP_ENV = @GZIP_ENV@
BZIP2 = @BZIP2@

# Standard programs.
RM = @RM@
LN = @LN_S@
CP = @CP@
MV = @MV@

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

VERSION = @VERSION@
_VERSION_ = @_VERSION_@

MAKE_BIN = @MAKE@
MAKE = $(MAKE_BIN) $(MFLAGS)
MFLAGS = \
	'local_dir=$(HOME)'			\
	'INSTALL_IRC=$(INSTALL_IRC)'		\
	'IRCLIB=$(IRCLIB)'			\
	'CC=$(CC)'				\
	'CFLAGS=$(CFLAGS)'			\
	'HELPDIR=$(HELPDIR)'			\
        'INSTALL_WSERV=$(INSTALL_WSERV)'	\
	'IRCPATH=$(IRCPATH)'			\
	'TRANSLATION_PATH=$(TRANSLATION_PATH)'	\
	'LDFLAGS=$(LDFLAGS)'			\
	'LIBS=$(LIBS)'				\
	'LN=$(LN)'				\
	'RM=$(RM)'				\
	'TCL_SRCS=$(TCL_SRCS)'			\
	'TCL_OBJS=$(TCL_OBJS)'			\
	'CD_PLAY=$(CD_PLAY)'			\
	'CD_SRCS=$(CD_SRCS)'			\
	'CD_OBJS=$(CD_OBJS)'			\
	'TCL_LIBS=$(TCL_LIBS)'			\
	'PLUGINDIR=$(PLUGINDIR)'		\
	'_VERSION_=$(_VERSION_)'		\
	'VERSION=$(VERSION)'			\
	'INSTALL_DATA=$(INSTALL_DATA)'		\
	'INSTALL_SCRIPT=$(INSTALL_SCRIPT)'	\
	'EXEEXT=$(EXEEXT)'			\
	'SHLIB_CFLAGS=$(SHLIB_CFLAGS)'		\
	'SHLIB_SUFFIX=$(SHLIB_SUFFIX)'

## Makefile starts here.

PLUGIN_NAME = nap

OBJS = nap.o napsend.o nap_file.o napfunc.o napother.o md5.o $(topdir)/source/compat.o

all: Makefile nap$(SHLIB_SUFFIX)

Makefile: Makefile.in
	cd $(topdir) \
	  && ./config.status

$(topdir)/source/compat.o: $(top_srcdir)/source/compat.c
	$(CC) $(DEFS) $(CFLAGS) \
		-c $(top_srcdir)/source/compat.c -o $(topdir)/source/compat.o

nap.o: $(srcdir)/nap.c
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/nap.c

napsend.o: $(srcdir)/napsend.c
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/napsend.c

nap_file.o: $(srcdir)/nap_file.c
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/nap_file.c

napfunc.o: $(srcdir)/napfunc.c
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/napfunc.c

napother.o: $(srcdir)/napother.c
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/napother.c

md5.o: $(srcdir)/md5.c $(srcdir)/md5.h
	$(CC) $(DEFS) $(CFLAGS) -c $(srcdir)/md5.c

nap$(SHLIB_SUFFIX): $(OBJS) 
	$(SHLIB_LD) $(OBJS) $(SHLIB_CFLAGS) -o nap$(SHLIB_SUFFIX)

clean:
	$(RM) *~ *.o *.so *.a *.dll *.def .#*

distclean: clean
	$(RM) Makefile

install:
	$(INSTALL) $(PLUGIN_NAME)$(SHLIB_SUFFIX) $(PLUGINDIR)

--- NEW FILE: md5.c ---
/*
 * This code implements the MD5 message-digest algorithm.
 * The algorithm is due to Ron Rivest.  This code was
 * written by Colin Plumb in 1993, no copyright is claimed.
 * This code is in the public domain; do with it what you wish.
 *
 * Equivalent code is available from RSA Data Security, Inc.
 * This code has been tested against that, and is equivalent,
 * except that you don't need to include two pages of legalese
 * with every copy.
 *
 * To compute the message digest of a chunk of bytes, declare an
 * MD5Context structure, pass it to MD5Init, call MD5Update as
 * needed on buffers full of bytes, and then call MD5Final, which
 * will fill a supplied 16-byte array with the digest.
 */
#include <string.h>

/* for memcpy() */
#include "md5.h"

#ifndef HIGHFIRST
#define byteReverse(buf, len)
/* Nothing */
#else
void byteReverse(unsigned char *buf, unsigned longs);

#ifndef ASM_MD5
/*
 * Note: this code is harmless on little-endian machines.
 */
void byteReverse(unsigned char *buf, unsigned longs)
{
    uint32 t;
    do {

t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |

    ((unsigned) buf[1] << 8 | buf[0]);

*(uint32 *) buf = t;

buf += 4;
    } while (--longs);
}
#endif
#endif

/*
 * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
 * initialization constants.
 */
void MD5Init(struct MD5Context *ctx)
{
    ctx->buf[0] = 0x67452301;
    ctx->buf[1] = 0xefcdab89;
    ctx->buf[2] = 0x98badcfe;
    ctx->buf[3] = 0x10325476;

    ctx->bits[0] = 0;
    ctx->bits[1] = 0;
}

/*
 * Update context to reflect the concatenation of another buffer full
 * of bytes.
 */
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
    uint32 t;

    /* Update bitcount */

    t = ctx->bits[0];
    if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)

ctx->bits[1]++;

/* Carry from low to high */
    ctx->bits[1] += len >> 29;

    t = (t >> 3) & 0x3f;
/* Bytes already in shsInfo->data */

    /* Handle any leading odd-sized chunks */

    if (t) {

unsigned char *p = (unsigned char *) ctx->in + t;


t = 64 - t;

if (len < t) {

    memcpy(p, buf, len);

    return;

}

memcpy(p, buf, t);

byteReverse(ctx->in, 16);

MD5Transform(ctx->buf, (uint32 *) ctx->in);

buf += t;

len -= t;
    }
    /* Process data in 64-byte chunks */

    while (len >= 64) {

memcpy(ctx->in, buf, 64);

byteReverse(ctx->in, 16);

MD5Transform(ctx->buf, (uint32 *) ctx->in);

buf += 64;

len -= 64;
    }

    /* Handle any remaining bytes of data. */

    memcpy(ctx->in, buf, len);
}

/*
 * Final wrapup - pad to 64-byte boundary with the bit pattern
 * 1 0* (64-bit count of bits processed, MSB-first)
 */
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
{
    unsigned count;
    unsigned char *p;

    /* Compute number of bytes mod 64 */
    count = (ctx->bits[0] >> 3) & 0x3F;

    /* Set the first char of padding to 0x80.  This is safe since there is
       always at least one byte free */
    p = ctx->in + count;
    *p++ = 0x80;

    /* Bytes of padding needed to make 64 bytes */
    count = 64 - 1 - count;

    /* Pad out to 56 mod 64 */
    if (count < 8) {

/* Two lots of padding:  Pad the first block to 64 bytes */

memset(p, 0, count);

byteReverse(ctx->in, 16);

MD5Transform(ctx->buf, (uint32 *) ctx->in);


/* Now fill the next block with 56 bytes */

memset(ctx->in, 0, 56);
    } else {

/* Pad block to 56 bytes */

memset(p, 0, count - 8);
    }
    byteReverse(ctx->in, 14);

    /* Append length in bits and transform */
    ((uint32 *) ctx->in)[14] = ctx->bits[0];
    ((uint32 *) ctx->in)[15] = ctx->bits[1];

    MD5Transform(ctx->buf, (uint32 *) ctx->in);
    byteReverse((unsigned char *) ctx->buf, 4);
    memcpy(digest, ctx->buf, 16);
    memset(ctx, 0, sizeof(ctx));
/* In case it's sensitive */
}

#ifndef ASM_MD5

/* The four core functions - F1 is optimized somewhat */

/* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))

/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )

/*
 * The core of the MD5 algorithm, this alters an existing MD5 hash to
 * reflect the addition of 16 longwords of new data.  MD5Update blocks
 * the data and converts bytes into longwords for this routine.
 */
void MD5Transform(uint32 buf[4], uint32 const in[16])
{
    register uint32 a, b, c, d;

    a = buf[0];
    b = buf[1];
    c = buf[2];
    d = buf[3];

    MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
    MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
    MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
    MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
    MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
    MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
    MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
    MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
    MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
    MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
    MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
    MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
    MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
    MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
    MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
    MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);

    MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
    MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
    MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
    MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
    MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
    MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
    MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
    MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
    MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
    MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
    MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
    MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
    MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
    MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
    MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
    MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);

    MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
    MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
    MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
    MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
    MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
    MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
    MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
    MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
    MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
    MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
    MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
    MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
    MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
    MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
    MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
    MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);

    MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
    MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
    MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
    MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
    MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
    MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
    MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
    MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
    MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
    MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
    MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
    MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
    MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
    MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
    MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
    MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);

    buf[0] += a;
    buf[1] += b;
    buf[2] += c;
    buf[3] += d;
}

#endif


--- NEW FILE: napother.c ---
#include "irc.h"
#include "struct.h"
#include "ircaux.h"
#include "misc.h"
#include "output.h"
#include "module.h"
#include "list.h"
#include "vars.h"
#include "modval.h"
#include "napster.h"

static IgnoreStruct *ignores = NULL;

int check_nignore(char *nick)
{
	if (ignores && find_in_list((List **)&ignores, nick, 0))
		return 1;
	return 0;
}

void ignore_user(IrcCommandDll *intp, char *command, char *args, char *subargs, char *help)
{
IgnoreStruct *new;
char *nick;
	if (command && !my_stricmp(command, "nignore"))
	{
		if (!args || !*args)
		{
			char buffer[NAP_BUFFER_SIZE+1];
			int cols =	get_dllint_var("napster_names_columns") ? 
					get_dllint_var("napster_names_columns") : 
					get_int_var(NAMES_COLUMNS_VAR);
			int count = 0;
			if (!cols)
				cols = 1;
			*buffer = 0;
			nap_say("%s", cparse("Ignore List:", NULL));
			for (new = ignores; new; new = new->next)
			{
				strcat(buffer, cparse(get_dllstring_var("napster_names_nickcolor"), "%s %d %d", new->nick, 0, 0));
				strcat(buffer, space);
				if (count++ >= (cols - 1))
				{
					nap_put("%s", buffer);
					*buffer = 0;
					count = 0;
				}
			}
			if (*buffer)
				nap_put("%s", buffer);
			return;
		}
		while ((nick = next_arg(args, &args)))
		{
			if (*nick == '-')
			{
				nick++;
				if (!*nick)
					continue;
				if ((new = (IgnoreStruct *)remove_from_list((List **)&ignores, nick)))
				{
					new_free(&new->nick);
					new_free(&new);
					nap_say("Removed %s from ignore list", nick);
				}
			}
			else
			{
				new = new_malloc(sizeof(IgnoreStruct));
				new->nick = m_strdup(nick);
				new->start = time(NULL);
				new->next = ignores;
				ignores = new;
				nap_say("Added %s to ignore list", new->nick);
			}
		}
		return;
	}
}


void nap_echo(IrcCommandDll *intp, char *command, char *args, char *subargs, char *help)
{
int (*func)(char *, ...);
	if (!args || !*args)
		return;

	func = nap_say;
	while (args && (*args == '-'))
	{
		args++;
		if (!*args)
			break;
		if (tolower(*args) == 'x')
		{
			func = nap_put;
			next_arg(args, &args);
		}
		else
		{
			args--;
			break;
		}
	}
	if (args)
		(func)("%s", args);
}

extern GetFile *napster_sendqueue;

int count_download(char *nick)
{
int count = 0;
GetFile *gf;
	for (gf = napster_sendqueue; gf; gf = gf->next)
		if (!my_stricmp(gf->nick, nick))
			count++;
	return count;
}

void compute_soundex (char *d, int dsize, const char *s)
{
    int n = 0;

    /* if it's not big enough to hold one soundex word, quit without
       doing anything */
    if (dsize < 4)
    {
	if (dsize > 0)
	    *d = 0;
	return;
    }
    dsize--; /* save room for the terminatin nul (\0) */

    while (*s && !isalpha(*s))
	s++;
    if (!*s)
    {
	*d = 0;
	return;
    }

    *d++ = toupper (*s);
    dsize--;
    s++;

    while (*s && dsize > 0)
    {
	switch (tolower (*s))
	{
	    case 'b':
	    case 'p':
	    case 'f':
	    case 'v':
		if (n < 3)
		{
		    *d++ = '1';
		    dsize--;
		    n++;
		}
		break;
	    case 'c':
	    case 's':
	    case 'k':
	    case 'g':
	    case 'j':
	    case 'q':
	    case 'x':
	    case 'z':
		if (n < 3)
		{
		    *d++ = '2';
		    dsize--;
		    n++;
		}
		break;
	    case 'd':
	    case 't':
		if (n < 3)
		{
		    *d++ = '3';
		    dsize--;
		    n++;
		}
		break;
	    case 'l':
		if (n < 3)
		{
		    *d++ = '4';
		    dsize--;
		    n++;
		}
		break;
	    case 'm':
	    case 'n':
		if (n < 3)
		{
		    *d++ = '5';
		    dsize--;
		    n++;
		}
		break;
	    case 'r':
		if (n < 3)
		{
		    *d++ = '6';
		    dsize--;
		    n++;
		}
		break;
	    default:
		if (!isalpha (*s))
		{
		    /* pad short words with 0's */
		    while (n < 3 && dsize > 0)
		    {
			*d++ = '0';
			dsize--;
			n++;
		    }
		    n = 0; /* reset */
		    /* skip forward until we find the next word */
		    s++;
		    while (*s && !isalpha (*s))
			s++;
		    if (!*s)
		    {
			*d = 0;
			return;
		    }
		    if (dsize > 0)
		    {
			*d++ = ',';
			dsize--;
			if (dsize > 0)
			{
			    *d++ = toupper (*s);
			    dsize--;
			}
		    }
		}
		/* else it's a vowel and we ignore it */
		break;
	}
	/* skip over duplicate letters */
	while (*(s+1) == *s)
	    s++;

	/* next letter */
	s++;
    }
    /* pad short words with 0's */
    while (n < 3 && dsize > 0)
    {
	*d++ = '0';
	dsize--;
	n++;
    }
    *d = 0;
}


--- NEW FILE: test.c ---

#include <stdio.h>
unsigned short len = 0;
unsigned char blah[3];

main()
{
int burp = 1;
	blah[2] = '\224';
	blah[3] = '\1';
	blah[0] = '\027';
	blah[1] = 0x0;
	memcpy(&len, blah, sizeof(len));
	printf("%d\n", len);
	memcpy(&len, blah+2, sizeof(len));
	printf("%d\n", len);
	printf("%d ", burp);	
	burp += 0xf0;
	printf("%d ", burp);	
	printf("and %d ", burp & ~0xf0);	
	printf("or %d \n", burp | 0xf0);	

}
--- NEW FILE: nap.sh ---
#!/bin/sh
# Make .def file:
export LIBPATH=/usr/local/cygwin-new/i586-pc-cygwin/lib
export LD=/usr/local/cygwin-new/bin/i586-pc-cygwin-ld
export NM=/usr/local/cygwin-new/bin/i586-pc-cygwin-nm
export DLLTOOL=/usr/local/cygwin-new/bin/i586-pc-cygwin-dlltool
export AS=/usr/local/cygwin-new/bin/i586-pc-cygwin-as
export GCC=/usr/local/cygwin-new/bin/i586-pc-cygwin-gcc
CP=cp
RM=rm

$GCC -I../../include -c nap.c
$GCC -I../../include -c md5.c
$GCC -I../../include -c nap_file.c
$GCC -I../../include -c napfunc.c
$GCC -I../../include -c napother.c
$GCC -I../../include -c napsend.c

echo EXPORTS > nap.def
$NM nap.o md5.o nap_file.o napfunc.o napother.o napsend.o ../init.o ../fixup.o | grep '^........ [T] _' | sed 's/[^_]*_//' >> nap.def

# Link DLL.
$LD --base-file nap.base --dll -o nap.dll nap.o md5.o nap_file.o napfunc.o napother.o napsend.o ../init.o ../fixup.o\
 $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry at 12
$DLLTOOL --as=$AS --dllname nap.dll --def nap.def --base-file\
 nap.base --output-exp nap.exp
$LD --base-file nap.base nap.exp --dll -o nap.dll nap.o md5.o nap_file.o napfunc.o napother.o napsend.o \
 ../init.o ../fixup.o $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry at 12
$DLLTOOL --as=$AS --dllname nap.dll --def nap.def --base-file\
 nap.base --output-exp nap.exp
$LD nap.exp --dll -o nap.dll nap.o  md5.o nap_file.o napfunc.o napother.o napsend.o ../init.o ../fixup.o\
 $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry at 12

# Build the napB.a lib to link to:
$DLLTOOL --as=$AS --dllname nap.dll --def nap.def --output-lib nap.a

$RM *.base *.exp *.def
$CP *.dll ..

--- NEW FILE: napster.h ---

#ifndef _napster_h
#define _napster_h

#include "modval.h"

typedef struct _Stats {
	int libraries;
	int gigs;
	int songs;
	unsigned long total_files;
	double total_filesize;
	unsigned long files_served;
	double filesize_served;
	unsigned long files_received;
	double filesize_received;
	double max_downloadspeed;
	double max_uploadspeed;
	time_t starttime;
	unsigned long shared_files;
	double shared_filesize;
} Stats;

extern Stats statistics;

typedef struct {
	char *username;
	char *password;
	int connection_speed;
} _N_AUTH;

typedef unsigned char _N_CMD;
                
typedef struct {
	int libraries;
	int gigs;
	int songs;
} _N_STATS;

#define cparse convert_output_format

typedef struct _nick_struct {
	struct _nick_struct *next;
	char	*nick;
  	int	speed;
	unsigned long shared;
} NickStruct;

typedef struct _AUDIO_HEADER {
	unsigned long filesize;
	int mpeg25;
	int ID;
	int layer;
	int error_protection;
	int bitrate_index;
	int sampling_frequency;
	int padding;
	int extension;
	int mode; /* 0 = STEREO 1 = Joint 2 = DUAL 3 = Mono */
	int mode_ext;
	int copyright;
	int original;
	int emphasis;
	int stereo;
	int jsbound;
	int sblimit;
	int true_layer;
	int framesize;
	int freq;
	unsigned long totalframes;
	unsigned long bitrate;
} AUDIO_HEADER;

typedef struct _files {
	struct _files	*next;
	char		*filename;
	char		*checksum;
	unsigned long	filesize;
	time_t		time;
	int		bitrate;
	int		freq;
	int		stereo;
	int		type;
} Files;

typedef struct _ignore_nick_struct {
	struct _ignore_nick_struct *next;
	char *nick;
	unsigned long start;
	unsigned long end;
} IgnoreStruct;

typedef struct _channel_struct {
	struct _channel_struct *next;
	char *channel;
	char *topic;
	int injoin;
	NickStruct *nicks;
} ChannelStruct;

typedef struct _file_struct {
	struct _file_struct *next;
	char *name;
	char *checksum;
	unsigned long filesize;
	unsigned int bitrate;
	unsigned int freq;
	unsigned int seconds;
	char *nick;
	unsigned long ip;
	int port;
	unsigned short speed;	
} FileStruct;

typedef struct _getfile_ {
	struct _getfile_ *next;	

	char	*nick;
	char	*ip;
	char	*checksum;
	char	*filename;
	char	*realfile;

	int	socket;
	int	port;
	int	write;
	int	count;
	unsigned long filesize;
	unsigned long received;
	unsigned long resume;
	time_t	starttime;
	time_t	addtime;
	int	speed;
	int	up;
} GetFile;

typedef struct _resume_file_ {
	struct _resume_file_ *next;
	char *checksum;
	unsigned long filesize;
	char *filename;
	FileStruct *results;
} ResumeFile;

enum nap_Commands {
	CMDR_ERROR		= 0,
	CMDS_UNKNOWN		= 1,
	CMDS_LOGIN		= 2, /* user pass dataport "version" speed */
	CMDR_EMAILADDR		= 3, /* email address */
	CMDR_BASTARD		= 4, /* unknown */
	CMDS_REGISTERINFO	= 6, /* userinfo */
	CMDS_CREATEUSER		= 7, /* create user account */
	CMDR_CREATED		= 8, /* account created */
	CMDR_CREATEERROR	= 9, /* username taken */
	CMDR_ILLEGALNICK	= 10, /* illegal nickname specified */
	
	CMDR_LOGINERROR		= 13, 

	CMDS_OPTIONS		= 14, /* NAME:%s ADDRESS:%s CITY:%s STATE:%s PHONE:%s AGE:%s INCOME:%s EDUCATION:%s   *login options */

	CMDR_MSTAT		= 15, 
	CMDR_REQUESTUSERSPEED	= 89,
	CMDR_SENDFILE		= 95,
	CMDS_ADDFILE		= 100,

	CMDS_REMOVEFILE		= 102, /* "\path\to\filename\" for removal */

	CMDR_GETQUEUE		= 108,
	CMDR_MOTD		= 109,
	CMDR_ANOTHERUSER	= 148,
	CMDS_SEARCH		= 200,
	CMDR_SEARCHRESULTS	= 201,
	CMDR_SEARCHRESULTSEND	= 202,

	/* if dataport is 0 we use 500 to request a transfer. 0 is a firewalled host */
	CMDS_REQUESTFILE	= 203,
	CMDR_FILEREADY		= 204,

	CMDS_SENDMSG		= 205,
	CMDR_GETERROR		= 206,

	CMDS_ADDHOTLIST		= 207,

	CMDS_ADDHOTLISTSEQ	= 208,
	CMDR_HOTLISTONLINE	= 209,
	CMDR_USEROFFLINE	= 210, 

	CMDS_BROWSE		= 211,
	CMDR_BROWSERESULT	= 212,
	CMDR_BROWSEENDRESULT	= 213,
	CMDR_STATS		= 214,

	CMDS_REQUESTRESUME	= 215, /* checksum filesize */
	CMDR_RESUMESUCCESS	= 216, /* nick ip port filename checksum size connection */
	CMDR_RESUMEEND		= 217, /* end resume for checksum filesize */

	CMDS_UPDATE_GET1	= 218, /* add 1 to download */
	CMDS_UPDATE_GET		= 219, /* sub 1 from download */
	CMDS_UPDATE_SEND1	= 220, /* add 1 for send */
    	CMDS_UPDATE_SEND	= 221, /* sub 1 from send */

	CMDR_HOTLISTSUCCESS	= 301,
	CMDR_HOTLISTERROR	= 302, /* not on hotlist */
	CMDS_HOTLISTREMOVE	= 303, /* nick */
	
	CMDS_JOIN		= 400,
	CMDS_PART		= 401,
	CMDS_SEND		= 402,
	CMDR_PUBLIC		= 403,
	CMDR_ERRORMSG		= 404,
	CMDR_JOIN		= 405,
	CMDR_JOINNEW		= 406,
	CMDR_PARTED		= 407,
	CMDR_NAMES		= 408,
	CMDR_ENDNAMES		= 409,
	CMDS_TOPIC		= 410, /* got/change topic */

	CMDS_REQUESTFILEFIRE	= 500,
	CMDR_FILEINFOFIRE	= 501, /* if firewalled then expect a 501 request send */

	CMDS_REQUESTINFO	= 600,
	CMDS_FILESIZE		= 601,
	CMDS_REQUESTSIZE	= 602,
	CMDS_WHOIS		= 603,
	CMDR_WHOIS		= 604,
	CMDR_WHOWAS		= 605,
	CMDS_SETUSERLEVEL	= 606, /* moderators/administrators/elite */
	CMDR_FILEREQUEST	= 607, /* nick \"filename\" */
	CMDS_FILEINFO		= 608, /* nick \"filename\" */
	CMDR_ACCEPTERROR	= 609, /* accept failed on request */

	CMDS_KILLUSER		= 610, /* return 404 permission denied */
	CMDS_NUKEUSER		= 611, /* return 404 */
	CMDS_BANUSER		= 612,
	CMDS_SETDATAPORT	= 613, 
	CMDS_UNBANUSER		= 614,
	CMDS_BANLIST		= 615,
	CMDR_BANLIST_IP		= 616,
	CMDS_LISTCHANNELS	= 617,
	CMDR_LISTCHANNELS	= 618,

	CMDS_SENDLIMIT		= 619, /* nick "filename" queuelimit */
	CMDR_SENDLIMIT		= 620, /* nick "filename" filesize queuelimit */

	CMDR_MOTDS		= 621, 
	CMDS_MUZZLE		= 622,
	CMDS_UNMUZZLE		= 623,
	CMDS_UNNUKEUSER		= 624, /* return 404 */
	CMDS_SETLINESPEED	= 625,
	CMDR_DATAPORTERROR	= 626,
	CMDS_OPSAY		= 627,
	CMDS_ANNOUNCE		= 628,
	CMDR_BANLIST_NICK	= 629,
	
	CMDS_CHANGESPEED	= 700,
	CMDS_CHANGEPASS		= 701,
	CMDS_CHANGEEMAIL	= 702,
	CMDS_CHANGEDATA		= 703,

	CMDS_PING		= 751, /* user */
	CMDS_PONG		= 752, /* <user> recieved from a ping*/
			       /* <user> can also be used to send a pong */
	/* 753 */
	
	CMDS_RELOADCONFIG	= 800, /* <config variable> */
	CMDS_SERVERVERSION	= 801, /* none */
	/* 802 missing */
	CMDS_SETCONFIG		= 810, /* <config string */
	/* 811 */
	CMDS_CLEARCHANNEL	= 820,  /* channelname */
	/* 821 822 823 826 827 */
	CMDS_SENDME		= 824,
	CMDR_NICK		= 825,
	CMDS_NAME		= 830, /* <channel> returns 825 with nick info, 830 is recieved on end of list */
	/* 831 */


	/* the following are open-nap specific */
	CMDS_SERVERLINK		= 10100, /* link server  <server> <port> [<remote server>] */
	CMDS_SERVERUNLINK	= 10101, /* unlink server <server> <reason> */
	CMDS_SERVERKILL		= 10110, /* kill server <server> <reason> */
	CMDS_SERVERREMOVE	= 10111,  /* remove it <server> <reason> */
	CMDS_ADDMIMEFILE	= 10300	 /* add a mime file type */
#if 0
%s %s "%s"
Proper Syntax: /setpassword <user> <password> [reason]
SETPASSWORD
#endif
};

/* 
 500 nick filename  -> "501 nick ip port filename md5 speed"
*/


typedef struct {
	unsigned short len;
	unsigned short command;
} _N_DATA;

typedef struct {
	int	cmd;
	int	(*func)(int, char *);
} _NAP_COMMANDS;

#define NAP_COMM(name) \
	int name (int cmd, char *args)

NAP_COMM(cmd_error);
NAP_COMM(cmd_unknown);
NAP_COMM(cmd_login);
NAP_COMM(cmd_email);
NAP_COMM(cmd_stats);
NAP_COMM(cmd_whois);
NAP_COMM(cmd_whowas);
NAP_COMM(cmd_joined);
NAP_COMM(cmd_topic);
NAP_COMM(cmd_names);
NAP_COMM(cmd_endnames);
NAP_COMM(cmd_parted);
NAP_COMM(cmd_public);
NAP_COMM(cmd_msg);
NAP_COMM(cmd_search);
NAP_COMM(cmd_endsearch);
NAP_COMM(cmd_browse);
NAP_COMM(cmd_endbrowse);
NAP_COMM(cmd_request);
NAP_COMM(cmd_getfile);
NAP_COMM(cmd_getfileinfo);
NAP_COMM(cmd_alreadyregistered);
NAP_COMM(cmd_registerinfo);
NAP_COMM(cmd_banlist);
NAP_COMM(cmd_offline);
NAP_COMM(cmd_filerequest);
NAP_COMM(cmd_dataport);
NAP_COMM(cmd_hotlist);
NAP_COMM(cmd_fileinfo);
NAP_COMM(cmd_hotlistsuccess);
NAP_COMM(cmd_hotlisterror);
NAP_COMM(cmd_channellist);
NAP_COMM(cmd_resumerequest);
NAP_COMM(cmd_resumerequestend);
NAP_COMM(cmd_send_limit_msg);
NAP_COMM(cmd_accepterror);

NAP_COMM(cmd_recname);
NAP_COMM(cmd_endname);
NAP_COMM(cmd_firewall_request);
NAP_COMM(cmd_ping);
NAP_COMM(cmd_bastard);
NAP_COMM(cmd_sendme);

BUILT_IN_DLL(load_napserv);
BUILT_IN_DLL(print_napster);
BUILT_IN_DLL(share_napster);
BUILT_IN_DLL(nclose);
BUILT_IN_DLL(nap_del);
BUILT_IN_DLL(nap_glist);
BUILT_IN_DLL(nap_request);
BUILT_IN_DLL(ignore_user);
BUILT_IN_DLL(nap_echo);

#define NAP_send(s, i) write(nap_socket, s, i);
SocketList *naplink_connect(char *, unsigned short);
void naplink_getserver(char *, unsigned short, int);

int nap_say(char *, ...);
int nap_put(char *, ...);
int send_ncommand(unsigned int, char *, ...);


void print_file(FileStruct *, int);
void naplink_handlelink(int);
int make_listen(int);
void set_napster_socket(int);
char *napster_status(void);
int build_napster_status(Window *);
int nap_finished_file(int, GetFile *);
int clean_queue(GetFile **, int);
void clear_filelist(FileStruct **);
void clear_files(Files **);
void nap_firewall_get(int);
char *mp3_time(unsigned long);
char *calc_md5(int, unsigned long);
int check_nignore(char *);

#if 0
#undef BUILT_IN_FUNCTION
#define BUILT_IN_FUNCTION(x, y) static char * x (char *fn, char * y)
#endif

BUILT_IN_FUNCTION(func_mp3_time);
BUILT_IN_FUNCTION(func_topic);
BUILT_IN_FUNCTION(func_onchan);
BUILT_IN_FUNCTION(func_onchannel);
BUILT_IN_FUNCTION(func_connected);
BUILT_IN_FUNCTION(func_hotlist);
BUILT_IN_FUNCTION(func_napchannel);
BUILT_IN_FUNCTION(func_raw);
BUILT_IN_FUNCTION(func_md5);

GetFile *find_in_getfile(GetFile **, int, char *, char *, char *, int, int);
int connectbynumber(char *, unsigned short *, int, int, int);

int count_download(char *);
void compute_soundex (char *, int, const char *);

char *base_name(char *);

extern FileStruct *file_search;
extern FileStruct *file_browse;
extern GetFile *napster_sendqueue;
extern char *nap_current_channel;
extern int nap_socket;
extern ChannelStruct *nchannels;
extern NickStruct *nap_hotlist;


#define NAP_DOWNLOAD	0x00
#define NAP_UPLOAD	0x01
#define NAP_QUEUED	0xf0
#define NAP_BUFFER_SIZE 2048

#endif

--- NEW FILE: napfunc.c ---
#define IN_MODULE
#include "irc.h"
#include "struct.h"
#include "dcc.h"
#include "ircaux.h"
#include "misc.h"
#include "output.h"
#include "lastlog.h"
#include "screen.h"
#include "status.h"
#include "window.h"
#include "vars.h"
#include "input.h"
#include "module.h"
#include "hook.h"
#include "list.h"
#include "modval.h"
#include "./napster.h"
#include "md5.h"

#define NEMPTY ""
#define EMPTY_STRING m_strdup(NEMPTY)
#define RETURN_EMPTY return EMPTY_STRING
#define RETURN_IF_EMPTY(x) if (empty( x )) RETURN_EMPTY
#define GET_INT_ARG(x, y) {RETURN_IF_EMPTY(y); x = atol(new_next_arg(y, &y));}
#define GET_STR_ARG(x, y) {RETURN_IF_EMPTY(y); x = new_next_arg(y, &y);RETURN_IF_EMPTY(x);}
#define RETURN_STR(x) return m_strdup(x ? x : EMPTY)
#define RETURN_INT(x) return m_strdup(ltoa(x))


/* 
 * given a "time in seconds" we convert this to a pretty time format 
 */

BUILT_IN_FUNCTION(func_mp3_time)
{
unsigned long t;
	t = my_atol(input);
	return m_strdup(mp3_time(t));
}

/*
 * return topic for the channel or empty
 */
 
BUILT_IN_FUNCTION(func_topic)
{
char *chan;
ChannelStruct *ch;
	GET_STR_ARG(chan, input);
	ch = (ChannelStruct *)find_in_list((List **)&nchannels, chan, 0);
	return ch ? m_strdup(ch->topic) : m_strdup("");
}

/*
 * are we on "channel"
 */
 
BUILT_IN_FUNCTION(func_onchan)
{
char *chan;
ChannelStruct *ch;
	GET_STR_ARG(chan, input);
	ch = (ChannelStruct *)find_in_list((List **)&nchannels, chan, 0);
	return ch ? m_strdup("1") : m_strdup("0");
}

/*
 * given a channel, returns the nicks on that channel.
 * given a channel and a "nick speed files" returns the nick else empty.
 */
BUILT_IN_FUNCTION(func_onchannel)
{
char *chan;
ChannelStruct *ch;
NickStruct *n;
char *nick = NULL;
	GET_STR_ARG(chan, input);
	if ((ch = (ChannelStruct *)find_in_list((List **)&nchannels, chan, 0)))
	{
		char *ret = NULL;
		char buffer[200];
		if (input && *input)
		{
			while ((nick = next_arg(input, &input)))
			{
				for (n = ch->nicks; n; n = n->next)
				{
					if (!my_stricmp(nick, n->nick))
					{
						sprintf(buffer, "%s %d %lu", n->nick, n->speed, n->shared);
						m_s3cat(&ret, " ", buffer);
					}			
				}
			}
		}
		else
		{
			for (n = ch->nicks; n; n = n->next)
				m_s3cat(&ret, " ", n->nick);
		}
		return ret ? ret : m_strdup("");
	}
	RETURN_EMPTY;
}

BUILT_IN_FUNCTION(func_connected)
{
	if (nap_socket > -1)
	{
		int len;
		struct sockaddr_in name;
		len = sizeof (name);
		if (getpeername(nap_socket, (struct sockaddr *)&name, &len))
			return m_strdup("-1");
		return m_sprintf("%s %d", inet_ntoa(name.sin_addr), ntohs(name.sin_port));
	}
	return m_strdup("");
}

BUILT_IN_FUNCTION(func_hotlist)
{
char *nick = NULL;
char *ret = NULL;
NickStruct *n;
	if (input && *input)
	{
		char buffer[200];
		while ((nick = next_arg(input, &input)))
		{
			for (n = nap_hotlist; n; n = n->next)
			{
				if (!my_stricmp(nick, n->nick))
				{
					sprintf(buffer, "%s %d %lu", n->nick, n->speed, n->shared);
					m_s3cat(&ret, " ", buffer);
				}
			}
		}
	}
	else
	{
		for (n = nap_hotlist; n; n = n->next)
			m_s3cat(&ret, " ", n->nick);

	}
	return ret ? ret : m_strdup("");
}

BUILT_IN_FUNCTION(func_raw)
{
int l;
_N_DATA n_data = {0, 0};
	GET_INT_ARG(l, input);
	n_data.command = l;
	if (input && *input)
		n_data.len = strlen(input);
	if (nap_socket < 0)
		return m_strdup("-1");
	write(nap_socket, &n_data, 4);
	if (n_data.len)
		return m_strdup(ltoa(write(nap_socket, input, n_data.len)));
	else
		return m_strdup("0");
}

BUILT_IN_FUNCTION(func_napchannel)
{
	return nap_current_channel ? m_strdup(nap_current_channel) : m_strdup(empty_string);
}

BUILT_IN_FUNCTION(func_md5)
{
int l;
unsigned long size = 0;
	GET_INT_ARG(l, input);
	if (input && *input)
		size = my_atol(input);
	return calc_md5(l, size);
}

--- NEW FILE: nap.c ---

#define NAP_VERSION "0.07"

/*
 *
 * This is the  Napster handler.
 * based on code donated by Drago.
 * Written by Colten Edwards. (C) Nov 99
 */
#include "irc.h"
#include "struct.h"
#include "dcc.h"
#include "ircaux.h"
#include "misc.h"
#include "output.h"
#include "lastlog.h"
#include "screen.h"
#include "status.h"
#include "window.h"
[...2332 lines suppressed...]
	add_module_proc(ALIAS_PROC, nap_name, "md5", NULL, 0, 0, func_md5, NULL);

	add_module_proc(VAR_PROC, nap_name, "napster_format", NULL, STR_TYPE_VAR, 0, set_numeric_string, NULL);
	add_module_proc(VAR_PROC, nap_name, "napster_dir", NULL, STR_TYPE_VAR, 0, NULL, NULL);

	add_completion_type("nload", 4, FILE_COMPLETION);
	add_completion_type("nreload", 4, FILE_COMPLETION);

	naphelp(NULL, NULL, NULL, NULL, NULL);
	sprintf(buffer, "$0+Napster %s by panasync - $2 $3", nap_version);
	fset_string_var(FORMAT_VERSION_FSET, buffer);
	loading_global = 1;
	snprintf(buffer, BIG_BUFFER_SIZE, "%s/Napster.sav", get_string_var(CTOOLZ_DIR_VAR));
	p  = expand_twiddle(buffer);
	load("LOAD", p, empty_string, NULL);
	new_free(&p);
	loading_global = 0;

	return 0;
}

--- NEW FILE: test ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: napsend.c ---

#define IN_MODULE
#include "irc.h"
#include "struct.h"
#include "dcc.h"
#include "ircaux.h"
#include "ctcp.h"
#include "cdcc.h"
#include "input.h"
#include "status.h"
#include "lastlog.h"
#include "screen.h"
#include "vars.h" 
#include "misc.h"
#include "output.h"
#include "module.h"
#include "hook.h"
#include "hash2.h"

[...1643 lines suppressed...]
		read(snum, buff, 4);
		s->func_read = nap_firewall_get;
	}
	else
		close_socketread(snum);
}

void naplink_handlelink(int snum)
{
struct  sockaddr_in     remaddr;
int sra = sizeof(struct sockaddr_in);
int sock = -1;
	if ((sock = accept(snum, (struct sockaddr *) &remaddr, &sra)) > -1)
	{
		add_socketread(sock, snum, 0, inet_ntoa(remaddr.sin_addr), naplink_handleconnect, NULL);
		add_sockettimeout(sock, 180, sendfile_timeout);
		write(sock, "\n", 1); 
	}
}


--- NEW FILE: Changes ---

02-01-00
	* added support for opennap server commands.
	* added support for opennap soundex searching. This means we can
          search for something which may be spelled incorrectly or where we 
	  don't know the exact spelling.  /nsound is the command. It is used
	  exactly like /nsearch
	* added support for opennap mime-type searching. When specifying a
	  type, all other params are ignored, except max_results.
		/nsearch -type video matrix
		
01-17-00 
	* gratitious change to napster windows client involving the md5
          checksum. Seems we need to send the filesize at the end of the
	  md5. "md5-filesize"
	* Added /nload -load which will load a ~/.BitchX/shared.dat. This
	  file is in the same format as the linux client.
	* Added /nload -save which will save/overwrite the shared.dat.
	* firewall get's are fixed.
	* removed SO_LINGER on a file send. why should we wait for the other
          end to catch up.

01-11-00 0.7
	* when a file get returns "FILE NOT SHARED" we need to use += on the
	  read
	* Changed the queued get to actually queue the file instead of
	  deleting the request.
	* Changed socket's to SO_LINGER. Maybe this'll fix firewall get's.

12-20-99 0.6c
	* md5 only calculated on 300k. do NOT include the id3v1 or id3v2 tag. 
	  Also it seems that MusicMatch uses id3v2 (lame piece of shit, why
	  make something so complicated as id3v2), So we have to skip the
	  id3v2 header while calculating it. Also noticed was that a file
	  had BOTH id3v1 and id3v2 headers. Like, give us a break. Use one 
	  or the other, not both.

12-19-99
	* void noticed that /nscan was not working. Turns out my
	  nap_current_channel and njoin routines were a little screwy. njoin
	  should not "remove" the channel from our internal list.
	* fudd helped me find a problem with file sends.. needed to be a
	  little less optimistic about when data is available for reading.
	* added /necho command. accepts a -x arg, which places text without
	  the prompt.
	* found another possible coredump problem in filesends.
	* added auto-reconfigure dataport.
	* colorized speed of connection in the names and scan list. Also
	  joins and parts. bright green is fastest, dark grey is unknown.
	
12-15-99
	* found/fixed firewall sends. IT should work as long as the other
	  end is okay. It does seem however that on occasion the other end
	  fails and odd errors will pop up.
	* found the send limit numerics.
	* found remove file numeric.
	* added support for data port misconfigurations.
	* modified tab_completion() so that tab key will work for nmsg.
	* fixed lost sockets.
	* fixed download coredump.
	* made certain /set's send the appropriate napster command.
	* merged all the admin commands into /nadmin
	* added several functions for scripting. 
		$mp3time(seconds) pretty prints the time.
		$nonchan(chan) returns if we are on the specified channel
		$nonchannel(chan [nick]) returns ALL nicks or just nick
		$napconnected() returns the server/port
		$ntopic(chan) topic for the channel
		$ncurrent() returns the current "client" channel
		$nhotlist([nick]) returns the whole hotlist or whether 
			nick is online
		$nraw(# string) will send "raw" commands to the server.
		$md5(# [size]) will md5 checksum a open file # using 300000
			as the default size or whatever you specify.
			@f = open(filename R)
			@md = md5(f)
			close(f)
	* started adding firewall download support. (does this even work ??)
	
12-13-99
	* Fixed more cores.
	* Found more numerics... Almost complete.
	* Found "resume" semantics..
	* Added "hooks" for scripting.
	* Whois info is updated with number of file sends/gets
	* Added channel save between connects. We now re-join any channels we
	  were in when the server dumps us.
	* Fudd found a problem when the filesend does not complete, but a
	  msg saying it did, appears	
	* Should compile for cygwin now as well.
	* new commands added. /nemail, /ndataport, /nlinespeed etc.
		?? should these be removed in favour of the /set's

12-12-99
	* Server connection errors detected earlier.
	* Server read error caught.
	* Hotlist fixes.


--- NEW FILE: nap_file.c ---

#include "irc.h"
#include "struct.h"
#include "dcc.h"
#include "ircaux.h"
#include "ctcp.h"
#include "cdcc.h"
#include "input.h"
#include "status.h"
#include "lastlog.h"
#include "screen.h"
#include "vars.h" 
#include "misc.h"
#include "output.h"
#include "module.h"
#include "hook.h"
#include "hash2.h"
#include "napster.h"
#include "bsdglob.h"
#include "modval.h"

#include <sys/stat.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif

GetFile *getfile_struct = NULL;
ResumeFile *resume_struct = NULL;


char *napster_status(void)
{
int upload = 0;
int download = 0;
GetFile *tmp;
char buffer[NAP_BUFFER_SIZE+1];
char tmpbuff[80];
double perc = 0.0;
	if (!get_dllint_var("napster_window"))
		return m_strdup(empty_string);
	sprintf(buffer, statistics.shared_files ? "%s [Sh:%lu/%3.2f%s] ": "%s ", 
		nap_current_channel ? nap_current_channel : empty_string, 
		statistics.shared_files, _GMKv(statistics.shared_filesize), 
		_GMKs(statistics.shared_filesize));
	for (tmp = getfile_struct; tmp; tmp = tmp->next, download++)
	{
		if (!tmp->filesize)
			continue;
                perc = (100.0 * (((double)(tmp->received + tmp->resume)) / (double)tmp->filesize));
		sprintf(tmpbuff, "%4.1f%%%%", perc);
		if (download)
			strcat(buffer, ",");
		else
			strcat(buffer, " [G:");
		strcat(buffer, tmpbuff);
	}
	if (download)
		strcat(buffer, "]");
	for (tmp = napster_sendqueue; tmp; tmp = tmp->next, upload++)
	{
		if (!tmp->filesize)
			continue;
                perc = (100.0 * (((double)(tmp->received + tmp->resume)) / (double)tmp->filesize));
		sprintf(tmpbuff, "%4.1f%%%%", perc);
		if (upload)
			strcat(buffer, ",");
		else
			strcat(buffer, " [S:");
		strcat(buffer, tmpbuff);
	}
	if (upload)
		strcat(buffer, "]");
	sprintf(tmpbuff, " [U:%d/D:%d]", upload, download);
	strcat(buffer, tmpbuff);
	return m_strdup(buffer);
}

BUILT_IN_DLL(nap_del)
{
int count = 0;
GetFile *tmp, *last = NULL;
int num;
char *t;
	if (!args && !*args)
		return;
	if (*args == '*')
	{
		if ((do_hook(MODULE_LIST, "NAP DEL ALL")))
			nap_say("%s", cparse("Removing ALL file send/upload", NULL));
		while (getfile_struct)
		{
			count++;
			tmp = getfile_struct;
			last = tmp->next;
			if ((do_hook(MODULE_LIST, "NAP DEL GET %s %s", tmp->nick, tmp->filename)))
				nap_say("%s", cparse("Removing $0 [$1-]", "%s %s", tmp->nick, base_name(tmp->filename)));
			nap_finished_file(tmp->socket, tmp);
			getfile_struct = last;
			send_ncommand(CMDS_UPDATE_GET, NULL);
		}
		while (napster_sendqueue)
		{
			count++;
			tmp = napster_sendqueue;
			last = tmp->next;
			if ((do_hook(MODULE_LIST, "NAP DEL SEND %s %s", tmp->nick, tmp->filename)))
				nap_say("%s", cparse("Removing $0 [$1-]", "%s %s", tmp->nick, base_name(tmp->filename)));
			nap_finished_file(tmp->socket, tmp);
			napster_sendqueue = last;
			send_ncommand(CMDS_UPDATE_SEND, NULL);
		}
		build_napster_status(NULL);
		return;
	}
	while ((t = next_arg(args, &args)))
	{	
		char *name = NULL;
		count = 1;
		if (!(num = my_atol(t)))
			name = t;
		for (tmp = getfile_struct; tmp; tmp = tmp->next, count++)
		{
			if ((count == num) || (name && !my_stricmp(name, tmp->nick)))
			{
				if (last)
					last->next = tmp->next;
				else	
					getfile_struct = tmp->next;
				if ((do_hook(MODULE_LIST, "NAP DEL GET %s %s", tmp->nick, tmp->filename)))
					nap_say("%s", cparse("Removing $0 [$1-]", "%s %s", tmp->nick, base_name(tmp->filename)));
				nap_finished_file(tmp->socket, tmp);
				build_napster_status(NULL);
				send_ncommand(CMDS_UPDATE_GET, NULL);
				return;
			}
			last = tmp;
		}
		last = NULL;
		for (tmp = napster_sendqueue; tmp; tmp = tmp->next, count++)
		{
			if ((count == num) || (name && !my_stricmp(name, tmp->nick)))
			{
				if (last)
					last->next = tmp->next;
				else	
					napster_sendqueue = tmp->next;
				if ((do_hook(MODULE_LIST, "NAP DEL SEND %s %s", tmp->nick, tmp->filename)))
					nap_say("%s", cparse("Removing $0 [$1-]", "%s %s", tmp->nick, base_name(tmp->filename)));
				nap_finished_file(tmp->socket, tmp);
				build_napster_status(NULL);
				send_ncommand(CMDS_UPDATE_SEND, NULL);
				return;
			}
			last = tmp;
		}
	}
}

BUILT_IN_DLL(nap_glist)
{
int count = 1;
GetFile *sg = getfile_struct;
time_t snow = now;
char	*dformat = "%W#$[3]0%n %Y$4%n $[14]1 $[-6]2$3 $5/$6 $7-";

	for(sg = getfile_struct; sg; sg = sg->next, count++)
	{
		char buff[80];
		char buff1[80];
		char buff2[80];
		char ack[4];
		double perc = 0.0;
		if (count == 1)
		{
			nap_put("%s", cparse("ÚÄÄÄÄÄ%GD%gownloads", NULL));
			nap_put("%s", cparse("%KÀÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ", NULL, NULL));
		}
		if (sg->starttime)
			sprintf(buff, "%2.3f", sg->received / 1024.0 / (snow - sg->starttime));
		else
			strcpy(buff, "N/A");
		if (sg->filesize)
			perc = (100.0 * (((double)(sg->received + sg->resume)) / (double)sg->filesize));
		sprintf(buff1, "%4.1f%%", perc);
		sprintf(buff2, "%4.2f", _GMKv(sg->filesize));
		*ack = 0;
		if (sg->up & NAP_QUEUED)
			strcpy(ack, "Q");
		strcat(ack, sg->starttime ? "D" : "W");
		nap_put("%s", cparse(dformat, "%d %s %s %s %s %s %s %s", 
			count, sg->nick, buff2, _GMKs(sg->filesize),
			ack, buff, buff1, base_name(sg->filename)));
	}
	for (sg = napster_sendqueue; sg; sg = sg->next, count++)
	{
		char buff[80];
		char buff1[80];
		char buff2[80];
		char ack[10];
		double perc = 0.0;
		if (count == 1)
		{
			nap_put("%s", cparse("ÚÄÄÄÄÄ%GU%gploads", NULL));
			nap_put("%s", cparse("%KÀÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄ%nÄ%WÄ%nÄ%KÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ", NULL, NULL));
		}
		if (sg->starttime)
			sprintf(buff, "%2.3f", sg->received / 1024.0 / (snow - sg->starttime));
		else
			strcpy(buff, "N/A");
		if (sg->filesize)
			perc = (100.0 * (((double)(sg->received + sg->resume)) / (double)sg->filesize));
		sprintf(buff1, "%4.1f%%", perc);
		sprintf(buff2, "%4.2f", _GMKv(sg->filesize));
		*ack = 0;
		if (sg->up & NAP_QUEUED)
			strcpy(ack, "Q");
		strcat(ack, sg->starttime ? "U" : "W");
		nap_put("%s", cparse(dformat, "%d %s %s %s %s %s %s %s", 
			count, sg->nick, buff2, _GMKs(sg->filesize), 
			ack, buff, buff1, base_name(sg->filename)));
	}
}

NAP_COMM(cmd_resumerequest)
{
char *nick, *file, *checksum;
int port;
unsigned long filesize;
unsigned long ip;
int speed;
int count = 0;
ResumeFile *sf;

	nick = next_arg(args, &args);
	ip = my_atol(next_arg(args, &args));
	port = my_atol(next_arg(args, &args));
	file = new_next_arg(args, &args);
	checksum = next_arg(args, &args);
	filesize = my_atol(next_arg(args, &args));
	speed = my_atol(next_arg(args, &args));

	for (sf = resume_struct; sf; sf = sf->next)
	{
		if (!strcmp(checksum, sf->checksum) && (filesize == sf->filesize))
		{
			FileStruct *new;
			new = new_malloc(sizeof(FileStruct));
			new->nick = m_strdup(nick);
			new->ip = ip;
			new->name = m_strdup(file);
			new->checksum = m_strdup(checksum);
			new->port = port;
			new->filesize = filesize;
			new->speed = speed;
			new->next = sf->results;
			sf->results = new;
			count++;
		}
	}
	if (!count)
		nap_say("error in resume request. no match");
	return 0;
}

NAP_COMM(cmd_resumerequestend)
{
char *checksum;
unsigned long filesize;
ResumeFile *sf;
	checksum = next_arg(args, &args);
	filesize = my_atol(next_arg(args, &args));
	for (sf = resume_struct; sf; sf = sf->next)
	{
		if (!strcmp(checksum, sf->checksum) && (filesize == sf->filesize))
		{
			FileStruct *new;
			int count = 1;
			for (new = sf->results; new; new = new->next)
				print_file(new, count++);
		}
	}
	return 0;
}

BUILT_IN_DLL(nap_request)
{
char *nick, *filen, *comm;

	if (!my_stricmp(command, "nrequest"))
	{
		nick = next_arg(args, &args);
		filen = new_next_arg(args, &args);
		if (nick && filen && *filen)
		{
			GetFile *new;
			do_hook(MODULE_LIST, "NAP REQUESTFILE %s %s", nick, filen);
			send_ncommand(CMDS_REQUESTFILE, "%s \"%s\"", nick, filen);
			new = new_malloc(sizeof(GetFile));
			new->nick = m_strdup(nick);
			new->filename = m_strdup(filen);
			new->next = getfile_struct;
			getfile_struct = new;
		}
	}
	else if (!my_stricmp(command, "nget") || !my_stricmp(command, "nresume"))
	{
		int	i = 0, count = 1, resume = 0;
		FileStruct *sf = NULL;
		ResumeFile *rf = NULL;

		resume = !my_stricmp(command, "nresume") ? 1 : 0;
		while (args && *args)
		{
			int req, browse;

			sf = NULL;
			req = browse = 0;
			count = 1;
			comm = next_arg(args, &args);
			if (!my_strnicmp(comm, "-request", 3))
			{
				req = 1;
				comm = next_arg(args, &args);
			}
			else if (!my_strnicmp(comm, "-browse", 3))
			{
				browse = 1;
				comm = next_arg(args, &args);
			}

			if (comm && *comm)
				i = strtoul(comm, NULL, 10);
			if (!req && !browse)
			{
				if (file_search)
					sf = file_search;
				else
					sf = file_browse;
			} 
			else if (req)
				sf = file_search;
			else
				sf = file_browse;

			if (sf && i)
			{
				for (; sf; sf = sf->next, count++)
				{
					if (i == count)
					{
						GetFile *new;
						if (resume)
						{
							for (rf = resume_struct; rf; rf= rf->next)
							{
								if (!strcmp(rf->checksum, sf->checksum) && (sf->filesize == rf->filesize))
								{
									nap_say("Already a Resume request for %s", base_name(sf->name));
									return;
								}
							}
							rf = new_malloc(sizeof(ResumeFile));
							rf->checksum = m_strdup(sf->checksum);
							rf->filename = m_strdup(sf->name);
							rf->filesize = sf->filesize;
							rf->next = resume_struct;
							resume_struct = rf;
							send_ncommand(CMDS_REQUESTRESUME, "%s %lu", rf->checksum, rf->filesize);
							do_hook(MODULE_LIST, "NAP RESUMEREQUEST %s %lu %s", sf->checksum, rf->filesize, rf->filename);
							return;
						}
						do_hook(MODULE_LIST, "NAP REQUESTFILE %s %s", sf->nick, sf->name);
						send_ncommand(CMDS_REQUESTFILE, "%s \"%s\"", sf->nick, sf->name);
						new = new_malloc(sizeof(GetFile));
						new->nick = m_strdup(sf->nick);
						new->filename = m_strdup(sf->name);
						new->filesize = sf->filesize;
						new->checksum = m_strdup(sf->checksum);
						new->next = getfile_struct;
						getfile_struct = new;
						return;
					}
				}
			} 
			else if (sf)
			{
				for (; sf; sf = sf->next)
					print_file(sf, count++);
				return;
			}
		}
		if (file_search)
		{
			for (sf = file_search; sf; sf = sf->next)
				print_file(sf, count++);
		} else if (file_browse)
			for (sf = file_browse; sf; sf = sf->next)
				print_file(sf, count++);
	}
}

GetFile *find_in_getfile(GetFile **fn, int remove, char *nick, char *check, char *file, int speed, int up)
{
GetFile *last, *tmp;
	last = NULL;
	if (!nick)
		return NULL;
	for (tmp = *fn; tmp; tmp = tmp->next)
	{
		if (!my_stricmp(tmp->nick, nick))
		{
			if (check && my_stricmp(tmp->checksum, check))
			{
				last = tmp;
				continue;
			}
			if (file && my_stricmp(tmp->filename, file))
			{
				last = tmp;
				continue;
			}
			if ((speed != -1) && (tmp->speed != speed))
			{
				last = tmp;
				continue;
			}
			if ((up != -1) && ((tmp->up & ~NAP_QUEUED) != up))
			{
				last = tmp;
				continue;
			}
			if (remove)
			{
				if (last)
					last->next = tmp->next;
				else
					*fn = tmp->next;
			}
			return tmp;
		}
		last = tmp;
	}
	return NULL;
}

void getfile_cleanup(int snum)
{
SocketList *s;
	if ((s = get_socket(snum)) && s->info)
	{
		GetFile *f = (GetFile *)s->info;
		if ((f = find_in_getfile(&getfile_struct, 1, f->nick, f->checksum, f->filename, -1, NAP_DOWNLOAD)))
		{
			new_free(&f->nick);
			new_free(&f->filename);
			new_free(&f->realfile);
			new_free(&f->ip);
			new_free(&f->checksum);
			if (f->write > 0)
				close(f->write);
			new_free(&f);
		}
		s->info = NULL;
	}
	close_socketread(snum);
	build_napster_status(NULL);
	return;
}

void nap_getfile(int snum)
{
char indata[2*NAP_BUFFER_SIZE+1];
SocketList *s;
int rc;
int count = sizeof(indata) - 1;
GetFile *gf;
unsigned long nbytes = 0;

	s = get_socket(snum);
	gf = (GetFile *)get_socketinfo(snum);
	if (gf && gf->count)
	{
		int flags = O_WRONLY;
		memset(&indata, 0, 200);
		if ((rc = read(snum, &indata, gf->count)) != gf->count)
			return;
		if (!isdigit(*indata) || !*(indata+1) || !isdigit(*(indata+1)))
		{
			rc += read(snum, &indata[gf->count], sizeof(indata)-1);
			indata[rc] = 0;
			nap_say("Request from %s is %s", gf->nick, indata);
			gf = find_in_getfile(&getfile_struct, 1, gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD);
			nap_finished_file(snum, gf);
			return;
		}
		gf->count = 0;
		set_non_blocking(snum);
		gf->starttime = time(NULL);
		if (!gf->resume)
			flags |= O_CREAT;
		if (!gf->realfile || ((gf->write = open(gf->realfile, flags, 0666)) == -1))
		{
			nap_say("Error opening output file %s: %s\n", base_name(gf->realfile), strerror(errno));
			gf = find_in_getfile(&getfile_struct, 1, gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD);
			nap_finished_file(snum, gf);
			return;
		}
		if (gf->resume)
			lseek(gf->write, gf->resume, SEEK_SET);	
		if (do_hook(MODULE_LIST, "NAP GETFILE %sING %s %lu %s",gf->resume ? "RESUM": "GETT", gf->nick, gf->filesize, gf->filename)) 
		{
			sprintf(indata, "%4.2g%s %4.2g%s", _GMKv(gf->resume), _GMKs(gf->resume), _GMKv(gf->filesize), _GMKs(gf->filesize));
			nap_say("%s", cparse(gf->resume ?"$0ing from $1 $2/$3 [$4-]":"$0ing from $1 $3 [$4-]", "%s %s %s %s", gf->resume?"Resum":"Gett", gf->nick, indata, base_name(gf->filename)));
		}
		add_sockettimeout(snum, 0, NULL);
		send_ncommand(CMDS_UPDATE_GET1, NULL);
		build_napster_status(NULL);
		return;
	} 
	else if (!gf)
	{
		s->is_write = 0;
		close_socketread(snum);
		send_ncommand(CMDS_UPDATE_GET, NULL);
		return;
	}
        if ((rc = ioctl(snum, FIONREAD, &nbytes) != -1))
	{
		if (nbytes)
		{
			count = (nbytes > count) ? count : nbytes;
			rc = read(snum, indata, count);
		} else
			rc = 0;
	}
	switch (rc)
	{
		case -1:
			nap_say("ERROR reading file [%s]", strerror(errno));
		case 0:
		{
			if (gf && (gf = find_in_getfile(&getfile_struct, 1, gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD)))
			{
				char speed1[80];
				double speed;
				speed = gf->received / 1024.0 / (now - gf->starttime);
				sprintf(speed1, "%4.2fK/s", speed);
				if ((gf->received + gf->resume) >= gf->filesize)
				{
					char rs[60];
					sprintf(rs, "%4.2g%s", _GMKv(gf->filesize), _GMKs(gf->filesize));
					if (rc != -1 && do_hook(MODULE_LIST, "NAP GETFILE FINISH %sING %s %s %lu %s", gf->resume ? "RESUM":"GETT", gf->nick, speed1, gf->received + gf->resume, gf->filename))
						nap_say("%s", cparse("Finished $2ing [$3-] from $0 $1", "%s %s %s %s %s", gf->nick, speed1, gf->resume ? "Resum":"Gett", rs, base_name(gf->filename)));
					if (speed > statistics.max_downloadspeed)
						statistics.max_downloadspeed = speed;
					statistics.files_received++;
					statistics.filesize_received += gf->received;
				}
				else if (do_hook(MODULE_LIST, "NAP GETFILE ERROR %sING %s %s %lu %lu %s", gf->resume? "RESUM":"GETT", gf->nick, speed1, gf->filesize, gf->received + gf->resume, gf->filename))
				{
					char fs[60];
					char rs[60];
					sprintf(fs, "%4.2g%s", _GMKv(gf->filesize), _GMKs(gf->filesize));
					sprintf(rs, "%4.2g%s", _GMKv(gf->received), _GMKs(gf->received));
					nap_say("%s", cparse("Error $2ing [$3-] from $0 $1", "%s %s %s %s %s %s", gf->nick, speed1, gf->resume ? "Resum":"Gett", fs, rs, base_name(gf->filename)));
				}
			}
			send_ncommand(CMDS_UPDATE_GET, NULL);
			nap_finished_file(snum, gf);
			build_napster_status(NULL);
			return;
		}
		default:
			break;
	}
	write(gf->write, indata, rc);
	gf->received += rc;
	if ((gf->received+gf->resume) >= gf->filesize)
	{
		if ((gf = find_in_getfile(&getfile_struct, 1, 
			gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD)))
		{
			char speed1[80];
			double speed;
			speed = gf->received / 1024.0 / (now - gf->starttime);
			sprintf(speed1, "%4.2fK/s", speed);
			if (speed > statistics.max_downloadspeed)
				statistics.max_downloadspeed = speed;
			if (do_hook(MODULE_LIST, "NAP GETFILE FINISH %sING %s %s %lu %s", gf->resume ? "RESUM":"GETT", gf->nick, speed1, gf->filesize, gf->filename))
			{
				char rs[60];
				sprintf(rs, "%4.2g%s", _GMKv(gf->filesize), _GMKs(gf->filesize));
				nap_say("%s", cparse("Finished $2ing [$3-] from $0 at $1", "%s %s %s %s %s", gf->nick, speed1, gf->resume?"Resum":"Gett", rs, base_name(gf->filename)));
			}
			statistics.files_received++;
			statistics.filesize_received += gf->received;
		}
		send_ncommand(CMDS_UPDATE_GET, NULL);
		nap_finished_file(snum, gf);
		build_napster_status(NULL);
	}
}

void nap_getfilestart(int snum)
{
SocketList *s;
int rc;
char c;
GetFile *gf;
	s = get_socket(snum);
	gf = (GetFile *)get_socketinfo(snum);
	if (gf)
	{
		set_blocking(snum);
		if ((rc = read(snum, &c, 1)) != 1)
			return;
		s->func_read = nap_getfile;
		return;
	}
	close_socketread(snum);
}


void nap_firewall_get(int snum)
{
char indata[2*NAP_BUFFER_SIZE+1];
int rc;
	memset(indata, 0, sizeof(indata));
	alarm(15);
	rc = recv(snum, indata, sizeof(indata)-1, 0);
	alarm(0);
	switch(rc)
	{
		case -1:
			close_socketread(snum);
			nap_say("ERROR in nap_firewall_get %s", strerror(errno));
		case 0:
			break;
		default:
		{
			char *args, *nick, *filename;
			unsigned long filesize;
			GetFile *gf;
			SocketList *s;

			s = get_socket(snum);
			if (!strncmp(indata, "FILE NOT", 8) || !strncmp(indata, "INVALID DATA", 10))
			{
				close_socketread(snum);
				return;
			}
			args = &indata[0];
			if (!(nick = next_arg(args, &args)))
			{
				close_socketread(snum);
				return;
			}
			filename = new_next_arg(args, &args);
			filesize = my_atol(next_arg(args, &args));
			if (!filename || !*filename || !filesize)
			{
				close_socketread(snum);
				return;
			}
			if ((gf = find_in_getfile(&getfile_struct, 0, nick, NULL, filename, -1, NAP_DOWNLOAD)))
			{
				int flags = O_WRONLY;
#ifndef NO_STRUCT_LINGER
				int len;
				struct linger	lin;
				len = sizeof(lin);
				lin.l_onoff = lin.l_linger = 1;
#endif

				gf->count = 0;
				set_non_blocking(snum);
				gf->starttime = time(NULL);
				gf->socket = snum;
				gf->filesize = filesize;
				if (!gf->resume)
					flags |= O_CREAT;
				if (!gf->realfile || ((gf->write = open(gf->realfile, flags, 0666)) == -1))
				{
					nap_say("Error opening output file %s: %s\n", base_name(gf->realfile), strerror(errno));
					gf = find_in_getfile(&getfile_struct, 1, gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD);
					nap_finished_file(snum, gf);
					return;
				}
				if (gf->resume)
					lseek(gf->write, gf->resume, SEEK_SET);	
				sprintf(indata, "%lu", gf->resume);
				write(snum, indata, strlen(indata));
				if (do_hook(MODULE_LIST, "NAP GETFILE %sING %s %lu %s",gf->resume ? "RESUM": "GETT", gf->nick, gf->filesize, gf->filename)) 
				{
					sprintf(indata, "%4.2g%s %4.2g%s", _GMKv(gf->resume), _GMKs(gf->resume), _GMKv(gf->filesize), _GMKs(gf->filesize));
					nap_say("%s", cparse("$0ing from $1 $3 [$4-]", "%s %s %s %s", gf->resume?"Resum":"Gett", gf->nick, indata, base_name(gf->filename)));
				}
				add_sockettimeout(snum, 0, NULL);
				send_ncommand(CMDS_UPDATE_GET1, NULL);
				build_napster_status(NULL);
				s->func_read = nap_getfile;
				set_socketinfo(snum, gf);
#ifndef NO_STRUCT_LINGER
				setsockopt(snum, SOL_SOCKET, SO_LINGER, (char *)&lin, len);
#endif
			}
		}
	}
}

NAP_COMM(cmd_getfileinfo)
{
char *nick;
GetFile *gf;
char indata[2*NAP_BUFFER_SIZE+1];
int count;
	nick = next_arg(args, &args);
	count = my_atol(args);
	if ((gf = find_in_getfile(&getfile_struct, 0, nick, NULL, NULL, count, NAP_DOWNLOAD)))
	{
		sprintf(indata, "%lu", gf->filesize);
		gf->count = strlen(indata);
		write(gf->socket, "GET", 3);
	        snprintf(indata, sizeof(indata), "%s \"%s\" %lu", get_dllstring_var("napster_user"), gf->filename, gf->resume);
		write(gf->socket, indata, strlen(indata));
		add_socketread(gf->socket, gf->port, gf->write, gf->nick, nap_getfilestart, NULL);
		set_socketinfo(gf->socket, gf);
		add_sockettimeout(gf->socket, 180, getfile_cleanup);
	}
	return 0;	
}

NAP_COMM(cmd_getfile)
{
/*
gato242 3068149784 6699 "d:\mp3\Hackers_-_07_-_Orbital_-_Halcyon_&_On_&_On.mp3"
8b451240c17fec98ea4f63e26bd42c60 7
*/
unsigned short port;
int getfd = -1;
int speed;
char *nick, *file, *checksum, *ip, *dir = NULL;
char *realfile = NULL;
char indata[2*NAP_BUFFER_SIZE+1];
struct sockaddr_in socka;
GetFile *gf = NULL;
struct stat st;
                
	nick = next_arg(args, &args);
	ip = next_arg(args, &args);
	port = my_atol(next_arg(args, &args));
	file = new_next_arg(args, &args);
	checksum = next_arg(args, &args);
	speed = my_atol(args);

	if (!(gf = find_in_getfile(&getfile_struct, 1, nick, checksum, file, -1, NAP_DOWNLOAD)))
	{
		nap_say("%s", "request not in getfile");
		return 0;
	}
	gf->ip = m_strdup(ip);	
	gf->checksum = m_strdup(checksum);
	gf->speed = atol(args);
	gf->port = port;

	if (!(dir = get_dllstring_var("napster_download_dir")))
		if (!(dir = get_string_var(DCC_DLDIR_VAR)))
			dir = "~";
	snprintf(indata, sizeof(indata), "%s/%s", dir, base_name(file));

	realfile = expand_twiddle(indata);

	gf->realfile = realfile;
	if (!(stat(realfile, &st)) && get_dllint_var("napster_resume_download"))
		gf->resume = st.st_size;

	gf->write = -1;

	if (!port) 
	{
		/* this is a firewalled host. make a listen socket instead */
		send_ncommand(CMDS_REQUESTFILEFIRE, "%s \"%s\"", nick, file);
		nap_say("Attempting to get from a firewalled host");
	}
	else
	{
#ifndef NO_STRUCT_LINGER
		int len;
		struct linger	lin;
		len = sizeof(lin);
		lin.l_onoff = lin.l_linger = 1;
#endif
		
		getfd = socket(AF_INET, SOCK_STREAM, 0);
		socka.sin_addr.s_addr = strtoul(ip, NULL, 10);
		socka.sin_family = AF_INET;
		socka.sin_port = htons(port);
		alarm(get_int_var(CONNECT_TIMEOUT_VAR));
		if (connect(getfd, (struct sockaddr *)&socka, sizeof(struct sockaddr)) != 0) 
		{
			nap_say("ERROR connecting [%s]", strerror(errno));
			send_ncommand(CMDR_DATAPORTERROR, gf->nick);
			new_free(&gf->nick);
			new_free(&gf->filename);
			new_free(&gf->ip);
			new_free(&gf->checksum);
			new_free(&gf->realfile);
			new_free(&gf);
			return 0;
		}
		alarm(0);
#ifndef NO_STRUCT_LINGER
		setsockopt(getfd, SOL_SOCKET, SO_LINGER, (char *)&lin, len);
#endif
		send_ncommand(CMDS_REQUESTINFO, nick);
	}

	gf->socket = getfd;
	gf->next = getfile_struct;
	gf->up = NAP_DOWNLOAD;
	getfile_struct = gf;
	return 0;
}

NAP_COMM(cmd_send_limit_msg)
{
char *nick, *filename, *limit, *filesize;
GetFile *gf;
	nick = next_arg(args, &args);
	filename = new_next_arg(args, &args);
	filesize = next_arg(args, &args);
	limit = args;
	if (!(gf = find_in_getfile(&getfile_struct, 1, nick, NULL, filename, -1, NAP_DOWNLOAD)))
	{
		nap_say("%s %s[%s]", "request not in getfile", nick, filename);
		return 0;
	}
/*	nap_finished_file(gf->socket, gf);*/
	gf->up &= NAP_QUEUED;
	if (do_hook(MODULE_LIST, "NAP QUEUE FULL %s %s %s %s", nick, filesize, limit, filename))
		nap_say("%s", cparse("$0 send queue[$1] is full.", "%s %s %s", nick, limit, filename));
	return 0;
	
}

--- NEW FILE: README.nap ---


Well here's my attempt at a "napster" client. Mine is a plugin for BitchX
and should work with 1.0c11 or 1.0c12. This source should be untar'd in the
BitchX/dll directory in order to find certain files that are required.
There will be a compile error in include/modval.h of 1.0c11 and 1.0c12, 
requiring you to edit the file and add a ( to the #define for strmopencat. 
This is what the line should look like.

#define strmopencat ((char * (*)())global[STRMOPENCAT])

After you have compiled BitchX with plugin support (./configure
--with-plugins) and have installed the client with either make install or
make install_local, you can then /loaddll nap  which loads the plugin into
the client. At this point, you have a bunch of new /set's and a few new
commands.

There is a /set napster_user and a /set napster_pass to set the username and
password you use with the server. You will need to set these to a unique
name and password. IF after you run set these 2 variables and /napster,
recieve an error msg about Invalid Password, it means the username is taken.

There is also a /napster command which actually connects you to the server.
The /napster command can also take a -create flag which tells the napster
server to create the account. /n<tab> will display a list of commands
(starting with the letter N) of which ALL the nap plugin commands are
included. /set napster will display ALL the set's.


We also have a list of functions specific to napster and a whole set of
hook's for use in a scripted environment. /on module "NAP *"  where the
first arg is NAP, second is a function are available for scripts to be
written.

[Functions]

	$md5(open_file_des [size]) 
		size defaults to 300000

	$napchannel() 
		returns current channel

	$nraw(num [args])
		sends a raw command to the server.
		returns -1 on error.
		returns 0 if no args for command.
		returns len of args.

	$nhotlist([nick|nick(s)])
		returns current hotlist with no args.
		returns hotlist info if nick is specified. 

	$nap_connected()
		returns empty or the server we are connected to.

	$nonchannel(channel [nick|nick(s)]);
		returns all nicks on the channel if no other arg specified.
		returns info on nicks specified.

	$nonchan(channel)
		are we on this channel?. 0 or 1

	$ntopic(channel)
		returns the topic for the specified channel.

	$mp3time(seconds)
		pretty prints the seconds.

[Commands]
n command args
	command can be one of raw, whois. raw is for sending raw server
	numerics and is meant for testing.
               
napster [-create] [user] [pass] [host] [port]
	This command will attempt to find the best server and connect you to
	it. with -create, it will attempt to create an account using the
	/set napster_user and /set napster_pass variables.

nbrowse nick
	Attempts to get the filelist that nick is offering.

nclose
	Close the current napster connection.

nconnect <server:port> | <server port>
	Attempt to connect to a known server.
	
ndel <*|#>
	Deletes the numbered download.

necho [-x] args
	Will display text using the internal window display routine. -x
	displays text without the "prompt"

ninfo [nick]
	Will display whois info about nick, or yourself if no nick
	specified.

nget [-request] [-browse] <#>
	Attempt to get the # file from the request or the browse list

nglist
	Display list of current uploads and downloads.

njoin [channelname]
	Join the channelname specified, or if none and we are on a
	channel(s), then switch current channels.

nlist
	Displays all the channel's available.

nload [-recurse][-share][-file [filename]][-save [filename]] dir | dir(s)
	-recurse is a toggle which turns on/off recursive directory
	searching. It can appear anywhere, and turns on/off recursion until 
	the end of the directory paths or until the next occurance.
	-share will add the files as they are found to the napster server
	database
	-file  will load a file called shared.dat(default) from your
	~/.BitchX or CTOOLZ_DIR. This file is in the same format as the
	linux napster save file. A filename can be specified in it's place
	-save  will attempt to save a file using the same as the information
	in -file

nmsg nick msg
	sends a msg to nick.



npart [channelname]
	Attempts to part or leave the [channelname] or if no channelname is
	specified it leaves the current channel.

nprint
	Prints a list of the mp3's in a nice format.. /set napster_format
	can be used to change this format. More documentation needed here.

nreconnect
	Attempts to re-connect to the current server.

nreload [-recurse] dir | dir(s)
	Removes the old list of mp3's and then scans the directories
	specified. See [nload].

nrequest nick filename
	If you know the exact filename on "nick" then you can directly
	request it without going through the browse.
	
nsave
	This saves ~/.BitchX/Napster.sav which is all your current set's.

nsay msg
	Say msg on the current channel.
	
nscan
	Display the nicks on the current channel.

nsound 
	same arg's are nsearch. The differance is that a soundex is
	performed and requested. This is an opennap feature.

nsearch [-maxresults #][-bitrate|-maxbitrate|-minbitrate #]
		(20,24,32,48,56,64,98,112,128,160,192,256,320)
		[-freq|-minfreq|-maxfreq #]
		(8000,11025,12000,16000,22050,24000,32000,44100,48000)
		[-linespeed|-minlinespeed|-maxlinespeed #] (0-11) 
		[-type video/zip/audio]
		pattern
	
	Search for "pattern" on your napster server.. You can then use /nget
	to receive files.
** NOTE napster servers have an error where more than 100 results will never
	be returned.

nshare
	After a /nload you might want to actually share the files with your
	friends.

ntopic [topic]
	Displays or attempts to set the current channel topic.

npass <nick password>
	Command to change your password.

nping <nick>
	Will ping a nick giving an indication of server response time.

nstats
	Display statistics gathered during the operation of napster plugin.

nignore <nick|-nick>
	This will ignore everything this particular nick might do to you.
	-nick will remove the ignore.

necho [-x] <args>
	output args to the napster window. -x is raw output.

nadmin <command> [args]
	This command is used for admins and elite etc. <command> is one of
	the following:

	annouce <args>
		This is a command for moderators and admins.

	kill <nick>
		This is a command for moderators and admins.

	muzzle <nick>
		This is a command for moderators and admins.

	muzzle <nick>
		This is a command for moderators and admins.

	nuke <nick>
		This is a command for moderators and admins.

	opsay <msg>
		This is a command for moderators and admins.

	setdataport <nick port>
		This is a command for moderators and admins.

	setlinespeed <nick #>
		This is a command for moderators and admins.

	setuserlevel <nick level>
		This is a command for moderators and admins.

	unban <nick>
		This is a command for moderators and admins.

	unnuke <nick>
		This is a command for moderators and admins.

	ban <nick>
		This is a command for moderators and admins.

	banlist
		Display current list of server bans.

	version
		grab the server version.

[following are opennap specific]
	connect <host> <port> [<remote server>]
		attempts to connect to the server on <port>

	disconnect <host> <reason>
		delink server from net.
		
	killserver <server> <reason>
		shutdown server
		
	removeserver <servername> <reason>
		remove server from table of allowed servers

	config <variable> [<value>]
		attempts to set a server variable

	reload
		reloads the default variables from the config file


The Following set's are available.

              napster_dataport [6699]
	Set's your dataport for filesends.

                   napster_dir
	Set's your base directory for /nload

          napster_download_dir ~
	Set's the location for your downloaded files.

                 napster_email blah at hrm.test
	Set's your email address for login

		napster_send_limit 5
	Set the max send's allowed.

		napster_max_send_nick
	Set the max sends to one nick allowed at one time. Should be smaller
	than "napster_send_limit"

                napster_format 
	Set's the output of the /nprint command.
		%%  will print a % sign.
		%b  bitrate
		%s  filesize
		%t  print mp3 time in minutes/seconds.
		%T  print raw time in seconds.
		%f  print base name of the file.
		%F  print raw filename
		%M  print md5 checksum
		%S  print mode of mp3.
		%H  print frequency
		%h  print raw frequency
		\n  start a newline
		\t  put a tab in the output.

                  napster_host server.napster.com
	Set's the napster server for lookups.

           napster_max_results 100
	Set's the MAX number of results for /nsearch. 

       napster_names_nickcolor %K[%w$[12]0%K]
	Set's the format for the nicks when you /njoin or /nscan a channel
	A double space in the format will be replaced with a "color" code
	based on the speed of the user.

               napster_numeric 
	Set's the numeric prompt

                  napster_pass 
	Set's the password you will use on the server.

                  napster_port 8875
	Set's the port for /set napster_server

                napster_prompt [Nap]
	Set's the prompt when outputting a napster line.

          napster_show_numeric OFF
	Set's display of numerics on/off

                 napster_speed 3
	Set's your connection speed. values are 0-11.

                  napster_user 
	Set's the username you will use on the server.

                napster_window OFF
	Set's a private window for napster

         napster_window_hidden OFF
	Set's the private window hidden.

                 napster_share ON
	Turn's on/off sharing of music. shared files will however stay in
	the database.

						panasync
						Colten Edwards




More information about the dslinux-commit mailing list