A
download brec.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 178
Project Info
BinkleyTerm XE(btxe)
Server: SourceForge
Type: cvs
...e\b\btxe\btxe\btnt\sources\
   Addr.cpp
   Addr.h
   aglcrc.cpp
   aglcrc.h
   asyn_lnx.cpp
   asyn_os2.cpp
   asyn_w32.cpp
   async.h
   asyos2v1.h
   b_banner.cpp
   b_bbs.cpp
   b_faxrcv.cpp
   b_flofil.cpp
   b_frproc.cpp
   b_help.cpp
   b_initva.cpp
   b_logs.cpp
   b_passwo.cpp
   b_proto.cpp
   b_rspfil.cpp
   b_sbinit.cpp
   b_script.cpp
   b_search.cpp
   b_sessio.cpp
   b_spawn.cpp
   b_term.cpp
   b_termov.cpp
   b_today.cpp
   b_wazoo.cpp
   b_whack.cpp
   b_wzsend.cpp
   banner.cpp
   banner.h
   BasicString.h
   bbs_ctra.cpp
   bbs_data.cpp
   bbs_incl.h
   bbs_io.cpp
   bink.h
   bink_asm.cpp
   binkdlg.cpp
   binkpipe.h
   box.h
   brec.cpp
   bsend.cpp
   bt.cpp
   btconfig.cpp
   btutil.cpp
   buffer.h
   cache.cpp
   cache.h
   callback.cpp
   callerid.cpp
   callwin.cpp
   callwin.h
   capi.cpp
   cfosline.cpp
   chat.cpp
   com.h
   com_dos.h
   com_lnx.h
   com_os2.h
   com_w32.h
   common.cpp
   cpuload.cpp
   css.cpp
   css.h
   data.cpp
   debug.cpp
   debug.h
   defines.h
   dosfuncs.cpp
   emsi.cpp
   emxmxcom.cpp
   evtparse.cpp
   evtsetup.cpp
   exceptio.cpp
   exceptio.h
   Exceptions.cpp
   Exceptions.h
   externs.h
   faxproto.h
   fcfgread.cpp
   fidomail.h
   file_all.cpp
   file_dos.cpp
   file_io.h
   file_lnx.cpp
   file_os2.cpp
   file_w32.cpp
   foffsets.h
   fossil.cpp
   freepoll.cpp
   ftsc.cpp
   gethcomm.h
   heap.cpp
   history.cpp
   history.h
   hydra.cpp
   hydra.h
   includes.cpp
   includes.h
   janus.cpp
   janus.h
   keybd.h
   keyfncs.h
   keymap.cpp
   langload.cpp
   language.h
   lngmagic.h
   m7rec.cpp
   m7send.cpp
   mailer.cpp
   mailovly.cpp
   mailroot.cpp
   maxcomm.h
   maxmcp.cpp
   maxmcp.h
   maxprm.cpp
   mdm_proc.cpp
   misc.cpp
   msgs.h
   Node.cpp
   Node.h
   NodeList.cpp
   NodeList.h
   nodeproc.cpp
   os2_pm.cpp
   outbound.cpp
   pipe.cpp
   pktmsgs.cpp
   pktmsgs.h
   protcomm.cpp
   prototyp.h
   recvbark.cpp
   recvsync.cpp
   sbuf.cpp
   sbuf.h
   sched.cpp
   sched.h
   script2.cpp
   SelfTest.cpp
   SelfTest.h
   sendbark.cpp
   sendsync.cpp
   squish.cpp
   squish.h
   srif.cpp
   statetbl.cpp
   stats.cpp
   stdafx.cpp
   stdafx.h
   timer.cpp
   timer.h
   times.cpp
   types.h
   v7debug.cpp
   version.cpp
   version7.cpp
   version7.h
   vfos_dos.cpp
   vfos_lnx.cpp
   vfos_os2.cpp
   vfos_qnx.cpp
   vfos_w32.cpp
   vfossil.h
   video.h
   vt100.cpp
   vt100.h
   xfer.h
   xmrec.cpp
   xmsend.cpp
   xstring.h
   yoohoo.cpp
   zmodem.cpp
   zmodem.h

/*---------------------------------------------------------------------------*
 *
 *                               BinkleyTerm
 *
 *              (C) Copyright 1987-96, Bit Bucket Software Co.
 *     For license and contact information see /doc/orig_260/license.260.
 *
 *           This version was modified by the BinkleyTerm XE Team.
 *        For contact information see /doc/team.lst and /doc/join.us.
 *  For a complete list of changes see /doc/xe_user.doc and /doc/xe_hist.doc.
 *
 * Filename    : $Source: /cvsroot/btxe/btnt/sources/brec.cpp,v $
 * Revision    : $Revision: 1.1 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/01 15:18:11 $
 * State       : $State: Exp $
 * Orig. Author: Bob Hartman
 *
 * Description : BinkleyTerm Batch Receiver State Machine
 *
 *---------------------------------------------------------------------------*/

/* Include this file before any other includes or defines! */

#include "includes.h"

static long batch_no_sealink;

int BRInit (XMARGSP);
int BREnd (XMARGSP);
int BRTestSL (XMARGSP);
int BRCheckSL (XMARGSP);
int BRCheckFNm (XMARGSP);
int BRCheckFile (XMARGSP);
int BRFindType (XMARGSP);

typedef struct
{
    char *state_name;
    int (*state_func) (XMARGSP);
}
BSTATES, *BSTATEP;

BSTATES Batch_Receiver[] =
    {
        {"BRInit", BRInit},
        {"BREnd", BREnd},
        {"BR0", BRTestSL},
        {"BR1", BRCheckSL},
        {"BR2", BRCheckFNm},
        {"BR3", BRCheckFile},
        {"BR4", BRFindType},
    };

int
BRInit (XMARGSP args)
{
    XON_DISABLE ();
    args->filename = (char*)calloc (1, 13);

    if (!args->filename)
        return (SYSTEM_ERR);

    batch_no_sealink = QueryNodeFlag (no_sealink, NOSEA, &remote_addr);
    return ((int) args->control);
}

int
BREnd (XMARGSP args)
{
    if (args->filename)
        free (args->filename);
    args->filename = NULL;
    return ((int) args->control);
}

int
BRTestSL (XMARGSP args)
{
    if (!batch_no_sealink)
        SENDBYTE (WANTCRC);

    args->T1 = timerset (10 * PER_SECOND);
    args->T2 = timerset (2 * PER_MINUTE);

    return (BR1);
}

int
BRCheckSL (XMARGSP args)
{
    long BR1Timer;

    BR1Timer = timerset (2 * PER_SECOND);
    while (!timeup (BR1Timer))
    {
        if (timeup (args->T2) || batch_no_sealink)
        {
            args->result = Modem7_Receive_File (args->filename);
            return (BR2);
        }

        if ((args->CHR = PEEKBYTE ()) >= 0)
        {
            return (BR4);
        }

        if (timeup (args->T1))
        {
            args->result = Modem7_Receive_File (args->filename);
            return (BR2);
        }
        else
        {
            if (!ComIsOnline(hcModem))
                return (CARRIER_ERR);
            else
                time_release ();
        }
    }

    SENDBYTE (WANTCRC);
    return (BR1);
}

int
BRCheckFNm (XMARGSP args)
{
    char buff1[20];
    char *p;
    int i;

    memset (buff1, 0, 19);

    if (args->result == EOT_RECEIVED)  /* Was it the last file */
    {
        return (SUCCESS);
    }
    else if (args->result == SUCCESS)  /* Did we get a valid filename */
    {
        /* First set up the filename buffer */
        p = buff1;
        for (i = 0; i < 8; ++p, i++)
        {
            if (args->filename[i] != ' ')
            {
                *p = args->filename[i];
            }
            else
                break;
        }

        *p = '.';
        ++p;
        *p = '\0';
        for (i = 8; i < 11; ++p, i++)
        {
            if (args->filename[i] != ' ')
            {
                *p = args->filename[i];
            }
            else
                break;
        }
        *p = '\0';

        /* Rename .REQ files */

        i = strlen (buff1) - 4;
        if ((i > 0) && (stricmp (&buff1[i], ".req") == 0))
        {
            buff1[i] = '\0';
            status_line (MSG_TXT (M_REC_REQ_AS), buff1, buff1, TaskNumber);
            sprintf (&buff1[i], ".r%02x", TaskNumber);
        }

        strcpy (args->filename, buff1);

        args->result = Internal_Xmodem_Receive_File (args->path, args->filename);
        return (BR3);
    }
    else                          /* Otherwise, we have to exit */
        return (args->result);
}

int
BRCheckFile (XMARGSP args)
{
    /* Was the file transfer good */
    if ((args->result == SUCCESS) || (args->result == SUCCESS_EOT))
    {
        return (BR0);
    }
    else
    {
        return (args->result);
    }
}

int
BRFindType (XMARGSP args)
{
    switch (args->CHR)
    {
    case SOH:
    case SYN:
        args->result = Internal_Batch_Xmodem_Receive_File (args->path, args->filename);
        return (BR3);

    case EOT:
        TIMED_READ (0);
        SENDBYTE (ACK);
        return (SUCCESS);

        /*  NUL is a special case of "noise." We want to reset our timer if we
         *  see one.
         */

    case NUL:
        args->T1 = timerset (20 * PER_SECOND);

        /*  Fall-through after resetting timer */

    default:
        break;
    }

    TIMED_READ (0);
    return (BR1);
}

int
Batch_Receive (char *where)
{
    XMARGS batch;
    int res;

    batch.result = 0;
    batch.path = where;
    res = state_machine ((STATEP) Batch_Receiver, &batch, 2);
    status_line (">Batch_Receive(%s) returns %d", where == NULL ? "(null)" : where, res);
    return (res == SUCCESS ? FILE_RECV_OK : CANNOT_RECV);
}

/* $Id: brec.cpp,v 1.1 2005/01/01 15:18:11 vildanov Exp $ */

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us