summaryrefslogtreecommitdiffstats
path: root/call/yapp.c
diff options
context:
space:
mode:
authorTerry Dawson VK2KTJ <terry@animats.net>2001-09-12 13:18:43 +0000
committerTerry Dawson VK2KTJ <terry@animats.net>2001-09-12 13:18:43 +0000
commit0eb707fdcf1b87e71bb3a9eaa8472d0b05799a3d (patch)
treeb2db8371470b697e3ae8a19b1e78c7805046f2d2 /call/yapp.c
parent628edceba5f1485ef7c4ef30fba93b4c0c0dd955 (diff)
updated libtool, uniformly indented source, corrected small ax25mond Makefile bug
Diffstat (limited to 'call/yapp.c')
-rw-r--r--call/yapp.c844
1 files changed, 415 insertions, 429 deletions
diff --git a/call/yapp.c b/call/yapp.c
index 3deb6d1..35818ed 100644
--- a/call/yapp.c
+++ b/call/yapp.c
@@ -37,7 +37,7 @@
#include "call.h"
-#define TIMEOUT 300 /* 5 Minutes */
+#define TIMEOUT 300 /* 5 Minutes */
#define NUL 0x00
#define SOH 0x01
@@ -62,11 +62,11 @@
static int state;
static int total = 0;
-static int readlen = 0;
-static int outlen = 0;
+static int readlen = 0;
+static int outlen = 0;
static int outbufptr = 0;
static unsigned char outbuffer[512];
-static char yappc; /* Nonzero if using YAPP C */
+static char yappc; /* Nonzero if using YAPP C */
static void Write_Status(char *s)
{
@@ -77,27 +77,27 @@ static void Write_Status(char *s)
static void Send_RR(void)
{
char buffer[2];
-
+
buffer[0] = ACK;
buffer[1] = 0x01;
-
+
write(fd, buffer, 2);
}
static void Send_RF(void)
{
char buffer[2];
-
+
buffer[0] = ACK;
buffer[1] = 0x02;
-
+
write(fd, buffer, 2);
}
static void Send_RT(void)
{
char buffer[2];
-
+
buffer[0] = ACK;
buffer[1] = ACK;
@@ -107,35 +107,35 @@ static void Send_RT(void)
static void Send_AF(void)
{
char buffer[2];
-
+
buffer[0] = ACK;
buffer[1] = 0x03;
-
+
write(fd, buffer, 2);
}
static void Send_AT(void)
{
char buffer[2];
-
+
buffer[0] = ACK;
buffer[1] = 0x04;
-
+
write(fd, buffer, 2);
}
static void Send_NR(char *reason)
{
char buffer[257];
- int length;
-
+ int length;
+
if ((length = strlen(reason)) > 255)
length = 255;
-
+
buffer[0] = NAK;
buffer[1] = length;
memcpy(buffer + 2, reason, length);
-
+
write(fd, buffer, length + 2);
}
@@ -151,36 +151,36 @@ static void Send_RS(int length)
buffer[3] = 0;
len = sprintf(buffer + 4, "%d", length) + 5;
-
- buffer[len] = 'C';
+
+ buffer[len] = 'C';
buffer[len + 1] = 0;
- buffer[1] = len;
-
+ buffer[1] = len;
+
write(fd, buffer, len + 2);
-}
+}
static void Send_SI(void)
{
char buffer[2];
-
+
buffer[0] = ENQ;
buffer[1] = 0x01;
-
+
write(fd, buffer, 2);
}
static void Send_CN(char *reason)
{
char buffer[257];
- int length;
+ int length;
if ((length = strlen(reason)) > 255)
length = 255;
-
+
buffer[0] = CAN;
buffer[1] = length;
memcpy(buffer + 2, reason, length);
-
+
write(fd, buffer, length + 2);
}
@@ -188,24 +188,23 @@ static void Send_HD(char *filename, long length)
{
char buffer[257];
char size_buffer[10];
- int len_filename;
- int len_size;
- int len;
+ int len_filename;
+ int len_size;
+ int len;
struct stat sb;
-
+
sprintf(size_buffer, "%ld", length);
-
- len_filename = strlen(filename) + 1; /* Include the NUL */
- len_size = strlen(size_buffer) + 1; /* Include the NUL */
-
+
+ len_filename = strlen(filename) + 1; /* Include the NUL */
+ len_size = strlen(size_buffer) + 1; /* Include the NUL */
+
len = len_filename + len_size;
- if (!stat(filename, &sb))
- {
+ if (!stat(filename, &sb)) {
unix2yapp(sb.st_mtime, buffer + len + 2);
len += 9;
}
-
+
buffer[0] = SOH;
buffer[1] = len;
@@ -218,32 +217,33 @@ static void Send_HD(char *filename, long length)
static void Send_ET(void)
{
char buffer[2];
-
+
buffer[0] = EOT;
buffer[1] = 0x01;
-
+
write(fd, buffer, 2);
}
static void Send_DT(int length)
{
char buffer[2];
-
- if (length > 255) length = 0;
-
+
+ if (length > 255)
+ length = 0;
+
buffer[0] = STX;
- buffer[1] = length;
-
+ buffer[1] = length;
+
write(fd, buffer, 2);
}
static void Send_EF(void)
{
char buffer[2];
-
+
buffer[0] = ETX;
buffer[1] = 0x01;
-
+
write(fd, buffer, 2);
}
@@ -260,157 +260,147 @@ static unsigned char checksum(unsigned char *buf, int len)
static int yapp_download_data(int *filefd, unsigned char *buffer)
{
- int length,file_time;
+ int length, file_time;
char Message[50];
- if (buffer[0] == CAN || buffer[0] == NAK)
- {
+ if (buffer[0] == CAN || buffer[0] == NAK) {
Write_Status("RcdABORT");
- return(FALSE);
+ return (FALSE);
}
- switch (state)
- {
- case STATE_R:
- if (buffer[0] == ENQ && buffer[1] == 0x01)
- {
- Send_RR();
- Write_Status("RcvHeader");
- state = STATE_RH;
- break;
- }
+ switch (state) {
+ case STATE_R:
+ if (buffer[0] == ENQ && buffer[1] == 0x01) {
+ Send_RR();
+ Write_Status("RcvHeader");
+ state = STATE_RH;
+ break;
+ }
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_RH:
- if (buffer[0] == SOH)
- {
- /* Parse header: 3 fields == YAPP C */
- char *hptr, *hfield[3];
- if ((length = buffer[1]) == 0) length = 256;
- hptr = (char *)buffer + 2;
- while (length > 0)
- {
- int hlen;
- hlen = strlen(hptr) + 1;
- hfield[(int)yappc++] = hptr;
- hptr += hlen;
- length -= hlen;
- }
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
+
+ case STATE_RH:
+ if (buffer[0] == SOH) {
+ /* Parse header: 3 fields == YAPP C */
+ char *hptr, *hfield[3];
+ if ((length = buffer[1]) == 0)
+ length = 256;
+ hptr = (char *) buffer + 2;
+ while (length > 0) {
+ int hlen;
+ hlen = strlen(hptr) + 1;
+ hfield[(int) yappc++] = hptr;
+ hptr += hlen;
+ length -= hlen;
+ }
- if (yappc < 3)
- {
- yappc = 0;
- }
- else
- {
- file_time = yapp2unix(hfield[2]);
- yappc = 1;
- }
+ if (yappc < 3) {
+ yappc = 0;
+ } else {
+ file_time = yapp2unix(hfield[2]);
+ yappc = 1;
+ }
- if (*filefd == -1)
- {
- if ((*filefd = open(hfield[0], O_RDWR | O_APPEND | O_CREAT, 0666)) == -1)
- {
- printf("\n[Unable to open %s]\n", hfield[0]);
- Send_NR("Invalid filename");
- return(FALSE);
- }
+ if (*filefd == -1) {
+ if ((*filefd =
+ open(hfield[0],
+ O_RDWR | O_APPEND | O_CREAT,
+ 0666)) == -1) {
+ printf("\n[Unable to open %s]\n",
+ hfield[0]);
+ Send_NR("Invalid filename");
+ return (FALSE);
}
+ }
- printf("Receiving %s %s %s", hfield[0], hfield[1],
- yappc ? ctime((time_t *)&file_time) : " ");
+ printf("Receiving %s %s %s", hfield[0], hfield[1],
+ yappc ? ctime((time_t *) & file_time) :
+ " ");
- if (yappc)
- {
- struct stat sb;
+ if (yappc) {
+ struct stat sb;
- if (!fstat(*filefd, &sb) && sb.st_size)
- Send_RS(sb.st_size);
- else
- Send_RT();
- }
+ if (!fstat(*filefd, &sb) && sb.st_size)
+ Send_RS(sb.st_size);
else
- {
- Send_RF();
- }
-
- state = STATE_RD;
- break;
+ Send_RT();
+ } else {
+ Send_RF();
}
- if (buffer[0] == ENQ && buffer[1] == 0x01)
- {
- break;
- }
+ state = STATE_RD;
+ break;
+ }
- if (buffer[0] == EOT && buffer[1] == 0x01)
- {
- Send_AT();
- Write_Status("RcvEOT");
- return(FALSE);
- }
+ if (buffer[0] == ENQ && buffer[1] == 0x01) {
+ break;
+ }
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_RD:
- if (buffer[0] == STX)
- {
- if ((length = buffer[1]) == 0) length = 256;
- total += length;
- sprintf(Message, "RcvData %5d bytes received", total);
- Write_Status(Message);
-
- if (yappc)
- {
- int i;
- unsigned char checksum = 0;
-
- for (i = 0; i < length; i++)
- checksum += buffer[i + 2];
-
- if (checksum != buffer[length + 2])
- {
- Send_CN("Bad Checksum");
- Write_Status("SndABORT: Bad Checksum");
- return(FALSE);
- }
- }
+ if (buffer[0] == EOT && buffer[1] == 0x01) {
+ Send_AT();
+ Write_Status("RcvEOT");
+ return (FALSE);
+ }
- write(*filefd, buffer + 2, length);
- break;
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
+
+ case STATE_RD:
+ if (buffer[0] == STX) {
+ if ((length = buffer[1]) == 0)
+ length = 256;
+ total += length;
+ sprintf(Message, "RcvData %5d bytes received",
+ total);
+ Write_Status(Message);
+
+ if (yappc) {
+ int i;
+ unsigned char checksum = 0;
+
+ for (i = 0; i < length; i++)
+ checksum += buffer[i + 2];
+
+ if (checksum != buffer[length + 2]) {
+ Send_CN("Bad Checksum");
+ Write_Status
+ ("SndABORT: Bad Checksum");
+ return (FALSE);
+ }
}
- if (buffer[0] == ETX && buffer[1] == 0x01)
- {
- Send_AF();
- Write_Status("RcvEof");
- state = STATE_RH;
- close(*filefd);
- *filefd = -1;
- break;
- }
+ write(*filefd, buffer + 2, length);
+ break;
+ }
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
+ if (buffer[0] == ETX && buffer[1] == 0x01) {
+ Send_AF();
+ Write_Status("RcvEof");
+ state = STATE_RH;
+ close(*filefd);
+ *filefd = -1;
+ break;
+ }
+
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
}
-
- return(TRUE);
+
+ return (TRUE);
}
static void yapp_download(int filefd)
{
struct timeval timeval;
fd_set sock_read;
- int n;
- int buflen = 0;
- int length;
- int used;
+ int n;
+ int buflen = 0;
+ int length;
+ int used;
unsigned char buffer[1024];
Write_Status("RcvWait");
@@ -419,19 +409,17 @@ static void yapp_download(int filefd)
total = 0;
yappc = 0;
- while (TRUE)
- {
+ while (TRUE) {
FD_ZERO(&sock_read);
FD_SET(STDIN_FILENO, &sock_read);
FD_SET(fd, &sock_read);
-
+
timeval.tv_usec = 0;
- timeval.tv_sec = TIMEOUT;
-
+ timeval.tv_sec = TIMEOUT;
+
n = select(fd + 1, &sock_read, NULL, NULL, &timeval);
-
- if (n == -1)
- {
+
+ if (n == -1) {
if (!interrupted && errno == EAGAIN)
continue;
if (!interrupted)
@@ -440,57 +428,56 @@ static void yapp_download(int filefd)
Write_Status("SndABORT");
return;
}
-
- if (n == 0) /* Timeout */
- {
+
+ if (n == 0) { /* Timeout */
Send_CN("Timeout");
Write_Status("SndABORT");
return;
}
-
- if (FD_ISSET(STDIN_FILENO, &sock_read))
- {
+
+ if (FD_ISSET(STDIN_FILENO, &sock_read)) {
Send_CN("Cancelled by user");
Write_Status("SndABORT");
return;
}
-
- if (FD_ISSET(fd, &sock_read))
- {
- if ((length = read(fd, buffer + buflen, 511)) > 0)
- {
+
+ if (FD_ISSET(fd, &sock_read)) {
+ if ((length = read(fd, buffer + buflen, 511)) > 0) {
buflen += length;
-
- do
- {
+
+ do {
used = FALSE;
-
- switch (buffer[0])
- {
+
+ switch (buffer[0]) {
case ACK:
case ENQ:
case ETX:
case EOT:
- if (buflen >= 2)
- {
+ if (buflen >= 2) {
if (!yapp_download_data(&filefd, buffer))
return;
buflen -= 2;
- memcpy(buffer, buffer + 2, buflen);
+ memcpy(buffer,
+ buffer + 2,
+ buflen);
used = TRUE;
}
break;
default:
- if ((length = buffer[1]) == 0)
+ if ((length =
+ buffer[1]) == 0)
length = 256;
if (buffer[0] == STX)
- length += yappc;
- if (buflen >= (length + 2))
- {
+ length += yappc;
+ if (buflen >= (length + 2)) {
if (!yapp_download_data(&filefd, buffer))
return;
- buflen -= length + 2;
- memcpy(buffer, buffer + length + 2, buflen);
+ buflen -=
+ length + 2;
+ memcpy(buffer,
+ buffer +
+ length + 2,
+ buflen);
used = TRUE;
}
break;
@@ -501,124 +488,123 @@ static void yapp_download(int filefd)
}
}
}
-
-static int yapp_upload_data(int filefd, char *filename, int filelength, unsigned char *buffer)
+
+static int yapp_upload_data(int filefd, char *filename, int filelength,
+ unsigned char *buffer)
{
char Message[80];
-
- if (buffer[0] == CAN || buffer[0] == NAK)
- {
+
+ if (buffer[0] == CAN || buffer[0] == NAK) {
Write_Status("RcvABORT");
- return(FALSE);
+ return (FALSE);
}
- switch (state)
- {
- case STATE_S:
- if (buffer[0] == ACK && buffer[1] == 0x01)
- {
- Write_Status("SendHeader");
- Send_HD(filename, filelength);
- state = STATE_SH;
- break;
- }
-
- if (buffer[0] == ACK && buffer[1] == 0x02)
- {
- sprintf(Message, "SendData %5d bytes transmitted", total);
- Write_Status(Message);
- outlen = read(filefd, outbuffer, readlen);
- outbufptr = 0;
+ switch (state) {
+ case STATE_S:
+ if (buffer[0] == ACK && buffer[1] == 0x01) {
+ Write_Status("SendHeader");
+ Send_HD(filename, filelength);
+ state = STATE_SH;
+ break;
+ }
- if (outlen) Send_DT(outlen);
+ if (buffer[0] == ACK && buffer[1] == 0x02) {
+ sprintf(Message, "SendData %5d bytes transmitted",
+ total);
+ Write_Status(Message);
+ outlen = read(filefd, outbuffer, readlen);
+ outbufptr = 0;
- if (yappc)
- {
- outbuffer[outlen] = checksum(outbuffer, outlen);
- outlen++;
- }
+ if (outlen)
+ Send_DT(outlen);
- state = STATE_SD;
- break;
+ if (yappc) {
+ outbuffer[outlen] =
+ checksum(outbuffer, outlen);
+ outlen++;
}
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_SH:
+ state = STATE_SD;
+ break;
+ }
+
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
+
+ case STATE_SH:
/* Could get three replies here:
* ACK 02 : normal acknowledge.
* ACK ACK: yappc acknowledge.
* NAK ...: resume request.
*/
- if (buffer[0] == NAK && buffer[2] == 'R')
- {
- int len;
- off_t rpos;
-
- len = buffer[1];
- if (buffer[len] == 'C') yappc=1;
- rpos = atol((char *)buffer + 4);
- lseek(filefd, rpos, SEEK_SET);
- buffer[0] = ACK;
- buffer[1] = yappc ? ACK : 0x02;
- }
+ if (buffer[0] == NAK && buffer[2] == 'R') {
+ int len;
+ off_t rpos;
+
+ len = buffer[1];
+ if (buffer[len] == 'C')
+ yappc = 1;
+ rpos = atol((char *) buffer + 4);
+ lseek(filefd, rpos, SEEK_SET);
+ buffer[0] = ACK;
+ buffer[1] = yappc ? ACK : 0x02;
+ }
- if (buffer[0] == ACK &&
- (buffer[1] == 0x02 || buffer[1] == ACK))
- {
- if (buffer[1] == ACK) yappc = 1;
-
- sprintf(Message, "SendData %5d bytes transmitted", total);
- Write_Status(Message);
- outlen = read(filefd, outbuffer, readlen);
- outbufptr = 0;
- if (outlen) Send_DT(outlen);
- state = STATE_SD;
-
- if (yappc)
- {
- outbuffer[outlen] = checksum(outbuffer, outlen);
- outlen++;
- }
- break;
+ if (buffer[0] == ACK &&
+ (buffer[1] == 0x02 || buffer[1] == ACK)) {
+ if (buffer[1] == ACK)
+ yappc = 1;
+
+ sprintf(Message, "SendData %5d bytes transmitted",
+ total);
+ Write_Status(Message);
+ outlen = read(filefd, outbuffer, readlen);
+ outbufptr = 0;
+ if (outlen)
+ Send_DT(outlen);
+ state = STATE_SD;
+
+ if (yappc) {
+ outbuffer[outlen] =
+ checksum(outbuffer, outlen);
+ outlen++;
}
+ break;
+ }
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_SD:
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_SE:
- if (buffer[0] == ACK && buffer[1] == 0x03)
- {
- Write_Status("SendEOT");
- Send_ET();
- state = STATE_ST;
- break;
- }
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
-
- case STATE_ST:
- if (buffer[0] == ACK && buffer[1] == 0x04)
- {
- return(FALSE);
- }
+ case STATE_SD:
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
- Send_CN("Unknown code");
- Write_Status("SndABORT");
- return(FALSE);
+ case STATE_SE:
+ if (buffer[0] == ACK && buffer[1] == 0x03) {
+ Write_Status("SendEOT");
+ Send_ET();
+ state = STATE_ST;
+ break;
+ }
+
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
+
+ case STATE_ST:
+ if (buffer[0] == ACK && buffer[1] == 0x04) {
+ return (FALSE);
+ }
+
+ Send_CN("Unknown code");
+ Write_Status("SndABORT");
+ return (FALSE);
}
- return(TRUE);
+ return (TRUE);
}
static void yapp_upload(int filefd, char *filename, long filelength)
@@ -626,45 +612,42 @@ static void yapp_upload(int filefd, char *filename, long filelength)
struct timeval timeval;
fd_set sock_read;
fd_set sock_write;
- int n;
+ int n;
unsigned char buffer[1024];
- int buflen = 0;
- int length;
- int used;
- char Message[80];
+ int buflen = 0;
+ int length;
+ int used;
+ char Message[80];
Write_Status("SendInit");
readlen = (paclen - 2 > 253) ? 253 : paclen - 2;
- state = STATE_S;
- total = 0;
- yappc = 0;
+ state = STATE_S;
+ total = 0;
+ yappc = 0;
Send_SI();
- while (TRUE)
- {
+ while (TRUE) {
FD_ZERO(&sock_read);
FD_ZERO(&sock_write);
FD_SET(STDIN_FILENO, &sock_read);
FD_SET(fd, &sock_read);
- if (state == STATE_SD)
- {
+ if (state == STATE_SD) {
FD_SET(fd, &sock_write);
-
- n = select(fd + 1, &sock_read, &sock_write, NULL, NULL);
- }
- else
- {
+
+ n = select(fd + 1, &sock_read, &sock_write, NULL,
+ NULL);
+ } else {
timeval.tv_usec = 0;
- timeval.tv_sec = TIMEOUT;
+ timeval.tv_sec = TIMEOUT;
- n = select(fd + 1, &sock_read, NULL, NULL, &timeval);
+ n = select(fd + 1, &sock_read, NULL, NULL,
+ &timeval);
}
-
- if (n == -1)
- {
+
+ if (n == -1) {
if (!interrupted && errno == EAGAIN)
continue;
if (!interrupted)
@@ -673,93 +656,92 @@ static void yapp_upload(int filefd, char *filename, long filelength)
Send_CN("Internal error");
return;
}
-
- if (n == 0) /* Timeout, not STATE_SD */
- {
+
+ if (n == 0) { /* Timeout, not STATE_SD */
Write_Status("SndABORT");
Send_CN("Timeout");
return;
}
-
- if (FD_ISSET(STDIN_FILENO, &sock_read))
- {
+
+ if (FD_ISSET(STDIN_FILENO, &sock_read)) {
Write_Status("SndABORT");
Send_CN("Cancelled by user");
return;
}
- if (FD_ISSET(fd, &sock_write)) /* Writable, only STATE_SD */
- {
- if (outlen > 0)
- {
- if ((n = write(fd, outbuffer + outbufptr, outlen)) > 0)
- {
+ if (FD_ISSET(fd, &sock_write)) { /* Writable, only STATE_SD */
+ if (outlen > 0) {
+ if ((n =
+ write(fd, outbuffer + outbufptr,
+ outlen)) > 0) {
outbufptr += n;
- outlen -= n;
- total += n;
+ outlen -= n;
+ total += n;
}
}
-
- if (outlen == 0)
- {
+
+ if (outlen == 0) {
total -= yappc;
- if ((outlen = read(filefd, outbuffer, readlen)) > 0)
- {
- sprintf(Message, "SendData %5d bytes transmitted", total);
+ if ((outlen =
+ read(filefd, outbuffer,
+ readlen)) > 0) {
+ sprintf(Message,
+ "SendData %5d bytes transmitted",
+ total);
Write_Status(Message);
outbufptr = 0;
- Send_DT(outlen);
+ Send_DT(outlen);
- if (yappc)
- {
- outbuffer[outlen] = checksum(outbuffer, outlen);
+ if (yappc) {
+ outbuffer[outlen] =
+ checksum(outbuffer,
+ outlen);
outlen++;
}
- }
- else
- {
+ } else {
Write_Status("SendEof");
state = STATE_SE;
Send_EF();
}
}
}
-
- if (FD_ISSET(fd, &sock_read))
- {
- if ((length = read(fd, buffer + buflen, 511)) > 0)
- {
+
+ if (FD_ISSET(fd, &sock_read)) {
+ if ((length = read(fd, buffer + buflen, 511)) > 0) {
buflen += length;
-
- do
- {
+
+ do {
used = FALSE;
-
- switch (buffer[0])
- {
+
+ switch (buffer[0]) {
case ACK:
case ENQ:
case ETX:
case EOT:
- if (buflen >= 2)
- {
+ if (buflen >= 2) {
if (!yapp_upload_data(filefd, filename, filelength, buffer))
return;
buflen -= 2;
- memcpy(buffer, buffer + 2, buflen);
+ memcpy(buffer,
+ buffer + 2,
+ buflen);
used = TRUE;
}
break;
default:
- if ((length = buffer[1]) == 0)
+ if ((length =
+ buffer[1]) == 0)
length = 256;
- if (buflen >= (length + 2))
- {
+ if (buflen >= (length + 2)) {
if (!yapp_upload_data(filefd, filename, filelength, buffer))
return;
- buflen -= length + 2;
- memcpy(buffer, buffer + length + 2, buflen);
+ buflen -=
+ length + 2;
+ memcpy(buffer,
+ buffer +
+ length + 2,
+ buflen);
used = TRUE;
}
break;
@@ -770,71 +752,75 @@ static void yapp_upload(int filefd, char *filename, long filelength)
}
}
}
-
+
void cmd_yapp(char *buf, int bytes)
{
- int filefd;
+ int filefd;
long size = 0L;
char *t;
- if (bytes == 0) return;
-
- switch (buf[0])
- {
- case 'U':
- case 'u':
- if ((t = strchr(buf, '\n')) != NULL)
- *t = '\0';
- t = buf + 2;
- while (*t != '\0' && isspace(*t))
- t++;
- if (*t == '\0')
- {
- printf("\n[YAPP Upload requires a filename - eg ~yu hello.txt]\n");
- Send_NR("No filename");
- return;
- }
- if ((filefd = open(t, O_RDONLY)) == -1)
- {
- printf("\n[Unable to open upload file]\n");
- Send_NR("Invalid filename");
- return;
- }
- if (lseek(filefd, 0L, SEEK_END) != -1)
- size = lseek(filefd, 0L, SEEK_CUR);
- lseek(filefd, 0L, SEEK_SET);
- if (size != -1)
- printf("\n[Uploading %ld bytes from %s using YAPP]\n", size, t);
- else
- printf("\n[Uploading from %s using YAPP]\n", t);
- yapp_upload(filefd, t, size);
- close(filefd);
- printf("[Finished YAPP Upload, %d bytes Transmitted]\n", total);
- break;
-
- case 'D':
- case 'd':
- if ((t = strchr(buf, '\n')) != NULL)
- *t = '\0';
- t = buf + 2;
- while (*t != '\0' && isspace(*t))
- t++;
- if (*t == '\0') filefd=-1;
- else if ((filefd = open(t, O_RDWR | O_APPEND | O_CREAT, 0666)) == -1)
- {
- printf("\n[Unable to open %s]\n", buf + 2);
- Send_NR("Invalid filename");
- return;
- }
- printf("\n[Downloading using YAPP]\n");
- yapp_download(filefd);
- close(filefd);
- printf("[Finished YAPP Download, %d bytes received]\n", total);
- break;
-
- default:
- printf("\nUnknown '~y' escape. Type ~h for a list.\n");
- break;
+ if (bytes == 0)
+ return;
+
+ switch (buf[0]) {
+ case 'U':
+ case 'u':
+ if ((t = strchr(buf, '\n')) != NULL)
+ *t = '\0';
+ t = buf + 2;
+ while (*t != '\0' && isspace(*t))
+ t++;
+ if (*t == '\0') {
+ printf
+ ("\n[YAPP Upload requires a filename - eg ~yu hello.txt]\n");
+ Send_NR("No filename");
+ return;
+ }
+ if ((filefd = open(t, O_RDONLY)) == -1) {
+ printf("\n[Unable to open upload file]\n");
+ Send_NR("Invalid filename");
+ return;
+ }
+ if (lseek(filefd, 0L, SEEK_END) != -1)
+ size = lseek(filefd, 0L, SEEK_CUR);
+ lseek(filefd, 0L, SEEK_SET);
+ if (size != -1)
+ printf
+ ("\n[Uploading %ld bytes from %s using YAPP]\n",
+ size, t);
+ else
+ printf("\n[Uploading from %s using YAPP]\n", t);
+ yapp_upload(filefd, t, size);
+ close(filefd);
+ printf("[Finished YAPP Upload, %d bytes Transmitted]\n",
+ total);
+ break;
+
+ case 'D':
+ case 'd':
+ if ((t = strchr(buf, '\n')) != NULL)
+ *t = '\0';
+ t = buf + 2;
+ while (*t != '\0' && isspace(*t))
+ t++;
+ if (*t == '\0')
+ filefd = -1;
+ else if ((filefd =
+ open(t, O_RDWR | O_APPEND | O_CREAT,
+ 0666)) == -1) {
+ printf("\n[Unable to open %s]\n", buf + 2);
+ Send_NR("Invalid filename");
+ return;
+ }
+ printf("\n[Downloading using YAPP]\n");
+ yapp_download(filefd);
+ close(filefd);
+ printf("[Finished YAPP Download, %d bytes received]\n",
+ total);
+ break;
+
+ default:
+ printf("\nUnknown '~y' escape. Type ~h for a list.\n");
+ break;
}
}
-