home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
OUTBOUND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-31
|
11KB
|
380 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was originally written by Bob Hartman */
/* */
/* */
/* Outbound Manipulating */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <process.h>
#include <stdlib.h>
#include <dos.h>
#ifdef OS_2
#define INCL_DOSPROCESS
#endif
#ifdef __TURBOC__
#include <alloc.h>
#else
#include <malloc.h>
#endif
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
#include "defines.h"
static int add_request (char *, char *, char *, char *);
static int add_send (char *, char *, char *);
static int kill_node (char *);
int Overlay_Do_Get (p, x)
SAVEP p;
int x;
{
REGIONP r;
char node[51];
char file[13];
char password[9];
char flavor[2];
char sure[2];
if (p != NULL)
{
r = p->region;
/* First fill it all with blanks */
sb_fill (r, ' ', colors.popup);
/* Now draw the box */
sb_box (r, boxtype, colors.popup);
sb_move (r, 0, 1);
sb_puts (r, (unsigned char *) msgtxt[M_GET_FILE]);
/* Now do the fields */
sb_move (r, 1,2);
sb_puts (r, msgtxt[M_ADDRESS_TO_GET_FROM]);
if (!sb_input_chars (r, 1, 23, node, 36))
{
sb_move (r, 2, 2);
sb_puts (r, msgtxt[M_FILE_TO_RECEIVE]);
if (!sb_input_chars (r, 2, 23, file, 12))
{
sb_move (r, 3, 2);
sb_puts (r, msgtxt[M_PASSWORD_TO_USE]);
(void) sb_input_chars (r, 3, 23, password, 8);
sb_move (r, 4, 2);
sb_puts (r, "Crash, Hold, Direct, Normal (C/H/D/N)?");
(void) sb_input_chars (r, 4, 41, flavor, 1);
sb_move (r, 5, 2);
sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
(void) sb_input_chars (r, 5, 23, sure, 1);
if (sure[0] == toupper (msgtxt[M_YES][0]))
x = add_request (node, file, password, flavor);
}
}
}
/* Return value is never checked, just use x so lint and -W3 don't get mad */
return (x);
}
int Overlay_Do_Send (p, x)
SAVEP p;
int x;
{
REGIONP r;
char node[51];
char file[51];
char flavor[2];
char sure[2];
if (p != NULL)
{
r = p->region;
/* First fill it all with blanks */
sb_fill (r, ' ', colors.popup);
/* Now draw the box */
sb_box (r, boxtype, colors.popup);
sb_move (r, 0, 1);
sb_puts (r, (unsigned char *) msgtxt[M_SEND_FILE]);
/* Now do the fields */
sb_move (r, 1,2);
sb_puts (r, msgtxt[M_ADDRESS_TO_SEND_TO]);
if (!sb_input_chars (r, 1, 22, node, 47))
{
sb_move (r, 2, 2);
sb_puts (r, msgtxt[M_FILE_TO_SEND]);
if (!sb_input_chars (r, 2, 22, file, 47))
{
sb_move (r, 3, 2);
sb_puts (r, "Crash, Hold, Direct, Normal (C/H/D/N)?");
(void) sb_input_chars (r, 3, 41, flavor, 1);
sb_move (r, 4, 2);
sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
(void) sb_input_chars (r, 4, 22, sure, 1);
if (sure[0] == toupper (msgtxt[M_YES][0]))
x = add_send (node, file, flavor);
}
}
}
/* Return value is never checked, just use x so lint and -W3 don't get mad */
return (x);
}
int Overlay_Do_Kill (p, x)
SAVEP p;
int x;
{
REGIONP r;
char node[51];
char sure[2];
if (p != NULL)
{
r = p->region;
/* First fill it all with blanks */
sb_fill (r, ' ', colors.popup);
/* Now draw the box */
sb_box (r, boxtype, colors.popup);
sb_move (r, 0, 1);
sb_puts (r, (unsigned char *) msgtxt[M_KILL_MAIL]);
/* Now do the fields */
sb_move (r, 1,2);
sb_puts (r, msgtxt[M_ADDRESS_TO_KILL]);
if (!sb_input_chars (r, 1, 19, node, 50))
{
sb_move (r, 2, 2);
sb_puts (r, msgtxt[M_KILL_ALL_MAIL]);
sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
(void) sb_input_chars (r, 2, 38, sure, 1);
if (sure[0] == toupper (msgtxt[M_YES][0]))
x = kill_node (node);
}
}
/* Return value is never checked, just use x so lint and -W3 don't get mad */
return (x);
}
int kill_node (node)
char *node;
{
ADDR addr;
char *HoldName;
char *p;
char fname[100];
#ifdef OS_2
struct FILEINFO fileinfo;
#else
struct find_t fileinfo;
#endif
if (find_address (node, &addr))
{
if (flag_file (TEST_AND_SET, &addr, 0))
{
return (-1);
}
HoldName = HoldAreaNameMunge(&addr);
(void) sprintf (fname, "%s%s.*", HoldName, Hex_Addr_Str (&addr));
#ifndef OS_2
if (!_dos_findfirst (fname, 0, &fileinfo))
#else
if (!dir_findfirst (fname, 0, &fileinfo))
#endif
{
do
{
/* Don't delete the .bsy flags yet */
if ((p = strchr (fileinfo.name, '.')) != NULL)
{
if (strcmp (p, ".BSY") == 0)
continue;
}
sprintf (fname, "%s%s", HoldName, fileinfo.name);
unlink (fname);
#ifndef OS_2
} while (!_dos_findnext (&fileinfo));
#else
} while (!dir_findnext (&fileinfo));
#endif
}
flag_file (CLEAR_FLAG, &addr, 0);
return (0);
}
else
{
return (-1);
}
}
int add_request (node, file, password, flavor)
char *node;
char *file;
char *password;
char *flavor;
{
ADDR addr;
char *HoldName;
char fname[100];
FILE *f;
if (find_address (node, &addr))
{
HoldName = HoldAreaNameMunge(&addr);
/* Now see if we should send anything back to him */
sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&addr));
if ((f = fopen (fname, "r+")) == NULL) /* CML changed APPEND to READ -- added logic to correctly add line with CR-LF before it */
{
if ((f = fopen (fname, "w")) == NULL)
return (-2);
}
else
{
if (!fseek(f,-1L,SEEK_END)) /* CML: check the last char */
{
if (fgetc(f) != '\n')
{
fseek(f,0L,SEEK_END); /* seek before changing from read to write */
fputc('\n',f);
}
}
else
fseek(f,0L,SEEK_END);
}
// sprintf (fname, "%s", Full_Addr_Str (&(alias[0])));
// fprintf (f, ";GET generated by node %s using %s\r\n", fname, ANNOUNCE); /* CML - commented out */
fprintf (f, "%s", file);
if (password[0] != '\0')
fprintf (f, " !%s", password);
fprintf (f, "\n");
fclose (f);
add_send (node, "", flavor);
return (0);
}
else
{
return (-1);
}
}
int add_send (node, file, flavor)
char *node;
char *file;
char *flavor;
{
ADDR addr;
char *HoldName;
char fname[100];
FILE *f;
if ((flavor[0] != 'C') && (flavor[0] != 'H') && (flavor[0] != 'N') && (flavor[0] != 'D'))
return (-3);
if (flavor[0] == 'N')
flavor[0] = 'F';
if (find_address (node, &addr))
{
HoldName = HoldAreaNameMunge(&addr);
(void) sprintf (fname, "%s%s.%sLO", HoldName, Hex_Addr_Str (&addr), flavor);
if ((f = fopen (fname, "r+")) == NULL) /* CML changed APPEND to READ -- added logic to correctly add line with CR-LF before it */
{
if ((f = fopen (fname, "w")) == NULL)
return (-2);
}
else
{
if (!fseek(f,-1L,SEEK_END)) /* CML: check the last char */
{
if (fgetc(f) != '\n')
{
fseek(f,0L,SEEK_END); /* seek before changing from read to write */
fputc('\n',f);
}
}
else
fseek(f,0L,SEEK_END);
}
if (file[0] != '\0')
{
// sprintf (fname, "%s", Full_Addr_Str (&(alias[0])));
// fprintf (f, ";SEND generated by node %s using %s\r\n", fname, ANNOUNCE); /* CML - cut that out */
fprintf (f, "%s\n", file);
}
fclose (f);
}
else
{
return (-1);
}
}