Numerous minor fixes to nap plugin

This commit is contained in:
Kevin Easton
2017-11-25 00:53:43 +11:00
parent 862137d975
commit 21ed1a01a3
3 changed files with 34 additions and 36 deletions

View File

@@ -273,11 +273,9 @@ int connectbynumber(char *hostn, unsigned short *portnum, int service, int proto
/* Inet domain client */ /* Inet domain client */
else if (service == SERVICE_CLIENT) else if (service == SERVICE_CLIENT)
{ {
struct sockaddr_foobar server; struct sockaddr_foobar server = { 0 };
struct hostent *hp; struct hostent *hp;
memset(&server, 0, sizeof(struct sockaddr_in));
if (isdigit(hostn[strlen(hostn)-1])) if (isdigit(hostn[strlen(hostn)-1]))
inet_aton(hostn, (struct in_addr *)&server.sf_addr); inet_aton(hostn, (struct in_addr *)&server.sf_addr);
else else
@@ -313,15 +311,15 @@ int connectbynumber(char *hostn, unsigned short *portnum, int service, int proto
return fd; return fd;
} }
char *numeric_banner(int curr) char *numeric_banner(int curr)
{ {
static char thing[4]; static char thing[4];
if (!get_dllint_var("napster_show_numeric")) if (!get_dllint_var("napster_show_numeric"))
return (nap_ansi?nap_ansi:empty_string); return nap_ansi ? nap_ansi : empty_string;
sprintf(thing, "%3.3u", curr);
return (thing); snprintf(thing, sizeof thing, "%3.3d", curr);
return thing;
} }
static void set_numeric_string(Window *win, char *value, int unused) static void set_numeric_string(Window *win, char *value, int unused)
@@ -1015,10 +1013,12 @@ char *chan;
if (!(chan = next_arg(args, &args))) if (!(chan = next_arg(args, &args)))
return 0; return 0;
ch = (ChannelStruct *)find_in_list((List **)&nchannels, chan, 0); ch = (ChannelStruct *)find_in_list((List **)&nchannels, chan, 0);
if (!ch)
return 0;
ch->injoin = 0; ch->injoin = 0;
if (do_hook(MODULE_LIST, "NAP ENDNAMES %s", chan)) if (do_hook(MODULE_LIST, "NAP ENDNAMES %s", chan))
{ {
if (ch)
name_print(ch->nicks, 0); name_print(ch->nicks, 0);
} }
malloc_strcpy(&nap_current_channel, chan); malloc_strcpy(&nap_current_channel, chan);
@@ -1746,7 +1746,7 @@ char *type = NULL;
} }
else if (strstr(cmd, "line")) else if (strstr(cmd, "line"))
{ {
if (value < 0 || value > 10) if (value > 10)
{ {
nap_say("%s", cparse("Allowed linespeed 0-10", NULL)); nap_say("%s", cparse("Allowed linespeed 0-10", NULL));
return; return;

View File

@@ -482,12 +482,11 @@ unsigned long nbytes = 0;
if (gf && gf->count) if (gf && gf->count)
{ {
int flags = O_WRONLY; int flags = O_WRONLY;
memset(&indata, 0, 200);
if ((rc = read(snum, &indata, gf->count)) != gf->count) if ((rc = read(snum, &indata, gf->count)) != gf->count)
return; return;
if (!isdigit(*indata) || !*(indata+1) || !isdigit(*(indata+1))) if (!isdigit(*indata) || !*(indata+1) || !isdigit(*(indata+1)))
{ {
rc += read(snum, &indata[gf->count], sizeof(indata)-1); rc += read(snum, &indata[gf->count], sizeof indata - gf->count);
indata[rc] = 0; indata[rc] = 0;
nap_say("Request from %s is %s", gf->nick, indata); 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); gf = find_in_getfile(&getfile_struct, 1, gf->nick, gf->checksum, gf->filename, -1, NAP_DOWNLOAD);
@@ -525,7 +524,8 @@ unsigned long nbytes = 0;
send_ncommand(CMDS_UPDATE_GET, NULL); send_ncommand(CMDS_UPDATE_GET, NULL);
return; return;
} }
if ((rc = ioctl(snum, FIONREAD, &nbytes) != -1)) rc = ioctl(snum, FIONREAD, &nbytes);
if (rc != -1)
{ {
if (nbytes) if (nbytes)
{ {

View File

@@ -65,7 +65,7 @@ char *mime_type[] = { "x-wav", "x-aiff", "x-midi", "x-mod", "x-mp3", /* 0-4 */
char *audio[] = {".wav", ".aiff", ".mid", ".mod", ".mp3", ""}; char *audio[] = {".wav", ".aiff", ".mid", ".mod", ".mp3", ""};
char *image[] = {".jpg", ".gif", ""}; char *image[] = {".jpg", ".gif", ""};
char *video[] = {".mpg", ".dat", ""}; char *video[] = {".mpg", ".dat", ""};
char *application[] = {".tar.gz" ".tar.Z", ".Z", ".gz", ".arc", ".bz2", ".zip", ""}; char *application[] = {".tar.gz", ".tar.Z", ".Z", ".gz", ".arc", ".bz2", ".zip", ""};
char *find_mime_type(char *fn) char *find_mime_type(char *fn)
{ {
@@ -259,7 +259,7 @@ char *make_mp3_string(FILE *fp, Files *f, char *fs, char *dirbuff)
*s++ = *fs; *s++ = *fs;
break; break;
case 'b': case 'b':
sprintf(s, "%*u", prec, f->bitrate); sprintf(s, "%*d", prec, f->bitrate);
break; break;
case 's': case 's':
if (!prec) prec = 3; if (!prec) prec = 3;
@@ -287,7 +287,7 @@ char *make_mp3_string(FILE *fp, Files *f, char *fs, char *dirbuff)
sprintf(s, "%*.*f", prec, fl, ((double)f->freq) / ((double)1000.0)); sprintf(s, "%*.*f", prec, fl, ((double)f->freq) / ((double)1000.0));
break; break;
case 'h': case 'h':
sprintf(s, "%*u", prec, f->freq); sprintf(s, "%*d", prec, f->freq);
break; break;
default: default:
*s++ = *fs; *s++ = *fs;
@@ -364,7 +364,7 @@ char *fs = NULL;
*dir = 0; *dir = 0;
for (new = fserv_files; new; new = new->next) for (new = fserv_files; new; new = new->next)
{ {
if (!pattern || (pattern && wild_match(pattern, new->filename))) if (!pattern || wild_match(pattern, new->filename))
{ {
char *p; char *p;
p = base_name(new->filename); p = base_name(new->filename);
@@ -681,7 +681,7 @@ long get_bitrate(int fdes, time_t *mp3_time, int *freq_rate, unsigned long *file
lseek(fdes, 0, SEEK_SET); lseek(fdes, 0, SEEK_SET);
*id3 = 0; *id3 = 0;
rc = read(fdes, buff, 128); rc = read(fdes, buff, 128);
if (!strncmp(buff, "ID3", 3)) if (rc == 128 && !strncmp(buff, "ID3", 3))
{ {
struct id3v2 { struct id3v2 {
char tag[3]; char tag[3];
@@ -725,8 +725,6 @@ md5_state_t state;
char buffer[BIG_BUFFER_SIZE+1]; char buffer[BIG_BUFFER_SIZE+1];
struct stat st; struct stat st;
unsigned long size = DEFAULT_MD5_SIZE; unsigned long size = DEFAULT_MD5_SIZE;
int di = 0;
int rc;
#if !defined(WINNT) && !defined(__EMX__) #if !defined(WINNT) && !defined(__EMX__)
char *m; char *m;
@@ -750,7 +748,9 @@ int rc;
#if defined(WINNT) || defined(__EMX__) #if defined(WINNT) || defined(__EMX__)
while (size) while (size)
{ {
int rc;
unsigned char md5_buff[8 * NAP_BUFFER_SIZE+1]; unsigned char md5_buff[8 * NAP_BUFFER_SIZE+1];
rc = (size >= (8 * NAP_BUFFER_SIZE)) ? 8 * NAP_BUFFER_SIZE : size; rc = (size >= (8 * NAP_BUFFER_SIZE)) ? 8 * NAP_BUFFER_SIZE : size;
rc = read(r, md5_buff, rc); rc = read(r, md5_buff, rc);
md5_append(&state, (unsigned char *)md5_buff, rc); md5_append(&state, (unsigned char *)md5_buff, rc);
@@ -768,11 +768,13 @@ int rc;
md5_finish(digest, &state); md5_finish(digest, &state);
munmap(m, size); munmap(m, size);
#endif #endif
memset(buffer, 0, 200); snprintf(buffer, sizeof buffer,
for (di = 0, rc = 0; di < 16; ++di, rc += 2) "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x-%ld",
snprintf(&buffer[rc], BIG_BUFFER_SIZE, "%02x", digest[di]); digest[0], digest[1], digest[2], digest[3],
strcat(buffer, "-"); digest[4], digest[5], digest[6], digest[7],
strcat(buffer, ltoa(st.st_size)); digest[8], digest[9], digest[10], digest[11],
digest[12], digest[13], digest[14], digest[15],
(long)st.st_size);
} }
return m_strdup(buffer); return m_strdup(buffer);
} }
@@ -859,7 +861,7 @@ unsigned int scan_mp3_dir(char *path, int recurse, int reload, int share, int se
count++; count++;
if (share && (nap_socket != -1)) if (share && (nap_socket != -1))
{ {
sprintf(buffer, "\"%s\" %s %lu %u %u %ld", new->filename, sprintf(buffer, "\"%s\" %s %lu %d %d %ld", new->filename,
new->checksum, new->filesize, new->bitrate, new->freq, new->checksum, new->filesize, new->bitrate, new->freq,
(long)new->time); (long)new->time);
send_ncommand(CMDS_ADDFILE, convertnap_dos(buffer)); send_ncommand(CMDS_ADDFILE, convertnap_dos(buffer));
@@ -969,7 +971,7 @@ Files *new;
{ {
for (new = fserv_files; new; new = new->next) for (new = fserv_files; new; new = new->next)
{ {
fprintf(fp, "\"%s\" %s %lu %u %u %ld\n", fprintf(fp, "\"%s\" %s %lu %d %d %ld\n",
new->filename, new->checksum, new->filesize, new->filename, new->checksum, new->filesize,
new->bitrate, new->freq, (long)new->time); new->bitrate, new->freq, (long)new->time);
count++; count++;
@@ -1119,7 +1121,7 @@ Files *new;
if (new->freq && new->bitrate) if (new->freq && new->bitrate)
{ {
sprintf(buffer, "\"%s\" %s %lu %u %u %ld", name, sprintf(buffer, "\"%s\" %s %lu %d %d %ld", name,
new->checksum, new->filesize, new->bitrate, new->freq, new->checksum, new->filesize, new->bitrate, new->freq,
(long)new->time); (long)new->time);
cmd = CMDS_ADDFILE; cmd = CMDS_ADDFILE;
@@ -1537,7 +1539,6 @@ void nap_firewall_start(int snum)
void napfile_read(int snum) void napfile_read(int snum)
{ {
GetFile *gf; GetFile *gf;
char buffer[NAP_BUFFER_SIZE+1];
int rc; int rc;
SocketList *s = get_socket(snum); SocketList *s = get_socket(snum);
@@ -1574,7 +1575,6 @@ void napfile_read(int snum)
|| !(gf = find_in_getfile(&napster_sendqueue, 0, nick, NULL, fbuff, -1, NAP_UPLOAD)) || !(gf = find_in_getfile(&napster_sendqueue, 0, nick, NULL, fbuff, -1, NAP_UPLOAD))
|| (gf->write == -1)) || (gf->write == -1))
{ {
memset(buff, 0, 80);
if (!gf) if (!gf)
sprintf(buff, "0INVALID REQUEST"); sprintf(buff, "0INVALID REQUEST");
else else
@@ -1583,7 +1583,7 @@ void napfile_read(int snum)
if ((gf = find_in_getfile(&napster_sendqueue, 1, nick, NULL, fbuff, -1, NAP_UPLOAD))) if ((gf = find_in_getfile(&napster_sendqueue, 1, nick, NULL, fbuff, -1, NAP_UPLOAD)))
gf->socket = snum; gf->socket = snum;
} }
write(snum, buff, strlen(buffer)); write(snum, buff, strlen(buff));
nap_finished_file(snum, gf); nap_finished_file(snum, gf);
return; return;
} }
@@ -1597,7 +1597,6 @@ void napfile_read(int snum)
gf->socket = snum; gf->socket = snum;
lseek(gf->write, SEEK_SET, gf->resume); lseek(gf->write, SEEK_SET, gf->resume);
set_socketinfo(snum, gf); set_socketinfo(snum, gf);
memset(buff, 0, 80);
sprintf(buff, "%lu", gf->filesize); sprintf(buff, "%lu", gf->filesize);
write(snum, buff, strlen(buff)); write(snum, buff, strlen(buff));
s->func_write = s->func_read; s->func_write = s->func_read;
@@ -1617,11 +1616,10 @@ void napfile_read(int snum)
void naplink_handleconnect(int snum) void naplink_handleconnect(int snum)
{ {
char buff[2*NAP_BUFFER_SIZE+1]; char buff[2*NAP_BUFFER_SIZE+1] = { 0 };
SocketList *s; SocketList *s;
int rc; int rc;
memset(buff, 0, sizeof(buff) - 1);
switch ((rc = recv(snum, buff, 4, MSG_PEEK))) switch ((rc = recv(snum, buff, 4, MSG_PEEK)))
{ {