download b_wzsend.cpp
Language: C++
Copyright: Copyright 1987, Wynn Wagner III. The original Copyright 1987-96, Bit Bucket Software Co.
LOC: 290
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/*---------------------------------------------------------------------------*
 *
 *                               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/b_wzsend.cpp,v $
 * Revision    : $Revision: 1.1 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/01 15:18:11 $
 * State       : $State: Exp $
 * Orig. Author: Wynn Wagner III
 *
 * Description : BinkleyTerm WaZOO/EMSI Session Logic
 *
 * Note        :
 *   This module is based largely on a similar module in OPUS-CBCS V1.03b.
 *   The original work is (C) Copyright 1987, Wynn Wagner III. The original
 *   author has graciously allowed us to use his code in this work.
 *
 *---------------------------------------------------------------------------*/

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

#include "includes.h"

int WaZOO_callback (char *);
int WaZOO_time (long);

static void LOCALFUNC InitExtAgent (void);
static void LOCALFUNC DeinitExtAgent (void);
int EXTMAIL_callback (char *);

/*--------------------------------------------------------------------------*/
/* SEND WaZOO (send another WaZOO or EMSI-capable system its mail)          */
/*--------------------------------------------------------------------------*/

MISSION_ERR
send_WaZOO (short session)
{
    char *HoldName;
    char fname[PATHLEN];
    char fname2[PATHLEN];
    char s[PATHLEN];
    struct stat buf;
    ADDR saved_addr;
    ADDR* addrp = &called_addr;
    int akas;
    int c;
    int check_again;
    int i;
    int z;
    long DontPick;
    long OkToRequest;
    MISSION_ERR error = mission_ok;

    /* !!!TJW added: fsent = 0 */
    /* r.hoerner: thomas: this is unnecessary: b_sessio.c already initializes
     *                    fsent to 0 at the start of a session.
     *                    see note in ..\doc\fsent.doc */

    /*r. hoerner */
    DontPick = QueryNodeFlag (no_pickup, NOPICK, &called_addr);
    OkToRequest = !DontPick && requests_ok && pickup_ok;
    /* cfg-flag + --- event def ----  */

    session_method = session;

    switch (remote_pickup)
    {
    case -2:
        InitExtAgent ();            /* External Mail session */
        /* ExtMail is handled like WaZOO. Fall through to that case. */

    case -1:
        akas = 1;                   /* WaZOO Session */
        remote_akas[0] = called_addr;
        break;

    case 0:
        akas = 0;                   /* remote has nopickup flag */
        break;

    case 1:
        akas = 1;
        break;

    case 2:
        akas = num_rakas;
        break;

    default:
        akas = 0;
        break;
    }

    saved_addr = called_addr;


#ifdef HAVE_HYDRA
    if (session == HYDRA_SESSION)
    {
        hydra_init (hydra_options);
    }
#endif

    for (i = 0; i < akas; i++)
    {
        addrp = &remote_akas[i];
        HoldName = HoldAreaNameMunge (addrp);
        status_line (MSG_TXT (M_EMSI_PROC_NODE), Full_Addr_Str (addrp), HoldName);
        check_again = 0;

        /* -------------------------------------------------------------------- */
        /* TJW 960528 moved sending out of FREQ to beginning of send batch      */
        /* to make xHydra easier to implement                                   */
        /* -------------------------------------------------------------------- */
        /* Send our File requests to other system                               */
        /* -------------------------------------------------------------------- */
        if (OkToRequest)            /* if I may request            */
        {
            sprintf (fname, "%s%s.req", HoldName, Hex_Addr_Str (addrp));
            sprintf (fname2, "%s%s.rqf", HoldName, Hex_Addr_Str (addrp));
            if (!unix_stat (fname, &buf))  /* and if I have some requests */
            {                         /* but other side does not allow requests */
                if (!(remote_capabilities & WZ_FREQ))
                {                       /* then give up. It is useless */
                    status_line (MSG_TXT (M_FREQ_DECLINED));
                    break;
                }
                else
                {
                    status_line (MSG_TXT (M_OUT_REQUESTS));
                    cleanup_req (fname);  /* TJW 960819 remove size info in REQ */
                    ++made_request;
                    z = FILE_SKIPPED;

#ifdef HAVE_HYDRA
                    if (session == HYDRA_SESSION)
                    {
                        z = hydra (fname, NULL);
                    }
                    else
#endif /* HAVE_HYDRA */
                    {
                        z = Send_Zmodem (fname, NULL, zmodem_state++, DO_WAZOO);
                    }

                    if (z == CANNOT_SEND) /* comm problems. Abort */
                    {
                        status_line (">Net_Problems in %s-Session",
                                     session == HYDRA_SESSION ? "Hydra" : "Zmodem");
                        error = mission_error;
                        goto abort;
                    }

                    if (z == FILE_SENT_OK)
                        fsent++;
                    rename (fname, fname2);

                }                       /* remote allows requests */
            }                         /* REQ found */
        }                           /* OkToRequest   */
    }                             /* for all his akas  */

#ifdef HAVE_HYDRA
    if ((session == HYDRA_SESSION) && do_RH1hydra)
    {
        if (hydra (NULL, NULL) == CANNOT_SEND)  /* RH1hydra: End of first batch */
            error = mission_error;
        SyncHydraSession = 0;       /* no sync in first HYDRA batch */
    }
#endif /* HAVE_HYDRA */

    if (remote_pickup)            /* if remote has not "NPU" flag set */
        for (i = 0; i < akas; i++)
        {
            addrp = &remote_akas[i];
            HoldName = HoldAreaNameMunge (addrp);
            status_line (MSG_TXT (M_EMSI_PROC_NODE), Full_Addr_Str (addrp), HoldName);
            check_again = 0;

just_make_sure:

            /* ------------------------------------------------------------------ */
            /* Send all waiting ?UT files (mail packets)                          */
            /* ------------------------------------------------------------------ */
            *ext_flags = 'o';
            for (c = 0; c < NUM_FLAGS; c++)
            {
                if ((caller && !SendHoldIfCaller) && (ext_flags[c] == 'h'))  /* VRP 990824 */
                    continue;

                sprintf (fname, "%s%s.%cut", HoldName, Hex_Addr_Str (addrp),
                         ext_flags[c]);

                if (!unix_stat (fname, &buf))
                {
                    /* --- Build a dummy PKT file name --- */
                    invent_pkt_name (s);

                    status_line (MSG_TXT (M_PACKET_MSG));

                    z = FILE_SKIPPED;

                    /* Do this using the external mail agent if need be */
                    if (remote_pickup == -2)
                    {
                        z = EXTMAIL_callback (fname);
                    }
                    else
#ifdef HAVE_HYDRA
                        if (session == HYDRA_SESSION)
                        {
                            z = hydra (fname, s);
                        }
                        else
#endif /* HAVE_HYDRA */
                        {
                            z = Send_Zmodem (fname, s, zmodem_state++, DO_WAZOO);
                        }

                    if (z == CANNOT_SEND) /* comm problems: abort */
                    {
                        status_line (">Net_Problems in %s-Session",
                                     session == HYDRA_SESSION ? "Hydra" : "Zmodem");
                        error = mission_error;
                        goto abort;
                    }

                    if (z == FILE_SENT_OK)  /* else: skipped or not found   */
                    {
                        fsent++;
                        unlink (fname);     /* only delete SENT mail/files */
                    }

                    CLEAR_IOERR ();

                }                       /* mailpkt found  */
            }                         /* for each mail flag */

            /* ------------------------------------------------------------------ */
            /* Send files listed in ?LO files (attached files)                    */
            /* ------------------------------------------------------------------ */
            *ext_flags = 'f';
            called_addr = *addrp;

            if (!bttask)
                if (!(fsent && SyncHydraSession))
                {
                    if (!do_FLOfile (ext_flags, WaZOO_callback))
                    {
                        called_addr = saved_addr;
                        error = mission_error;
                        goto abort;
                    }
                }

            called_addr = saved_addr;
            if (fsent && !check_again)
            {
                check_again++;
                goto just_make_sure;
            }

        }                           /* for all of his akas */

    status_line (">WaZoo BATCH 2 ended");

    /* END of active SENDING loop                */
    /* This is as far as we go for external mail */

    if (remote_pickup == -2)
    {
        DeinitExtAgent ();
        goto success;
    }

#ifdef HAVE_HYDRA
    if ((session == HYDRA_SESSION) && !do_RH1hydra)
    {
        if (hydra (NULL, NULL) == CANNOT_SEND)  /* !do_RH1hydra: End of first batch */
            error = mission_error;
    }
#endif /* HAVE_HYDRA */

    if (!bttask)
        if (!(fsent && SyncHydraSession))
        {
            fsent += respond_to_file_requests (0, WaZOO_callback, WaZOO_time);
        }

abort:                         /* jump here in case of trouble and de-init your protocols! */

#ifdef HAVE_HYDRA
    if (session == HYDRA_SESSION)
    {
        if (hydra (NULL, NULL) == CANNOT_SEND)
            error = mission_error;
        hydra_deinit ();
    }
    else
#endif /* HAVE_HYDRA */
    {
        int zmodem;

        zmodem = fsent ? ZMODEM_ENDBATCH : ZMODEM_END;
        z = Send_Zmodem (NULL, NULL, zmodem, DO_WAZOO);
        zmodem_state = ZMODEM_INIT;
    }

success:

    if (error == mission_ok)
    {
        /* MR 970810 only tell "nothing to send" if session was ok */
        if (!fsent)                 /* TJW 960429 after idea of Andrew Clarke vvvvvvvvvvvv */
            status_line (MSG_TXT (M_NOTHING_TO_SEND), Full_Addr_Str (&called_addr));

        sent_mail = 1;              /* MR 970803 only set it after successful session */
        status_line (">WaZoo END, no problems");
    }
    else
        status_line (">WaZoo END, error(s)");

    return error;
}                               /* WaZOO */


/*
 * WaZOO_callback () -- send requested file using WaZOO/EMSI method.
 */

int
WaZOO_callback (char *reqs)
{
    if (remote_pickup == -2)
        return EXTMAIL_callback (reqs);

#ifdef HAVE_HYDRA
    if (session_method == HYDRA_SESSION)
        return (hydra (reqs, NULL));
#endif /* HAVE_HYDRA */

    return (Send_Zmodem (reqs, NULL, zmodem_state++, DO_WAZOO));
}


int
WaZOO_time (long filesize)
{
    long ltemp;

#ifdef HAVE_HYDRA
    if ((session_method == HYDRA_SESSION) && (remote_pickup != -2))
        ltemp = remaining (filesize, 95L);
    else
#endif /* HAVE_HYDRA */
        ltemp = remaining (filesize, 100L);

    return (ltemp < 20L) ? 20 : (int) ltemp;
}


static void LOCALFUNC
InitExtAgent ()
{
    status_line (MSG_TXT (M_START_EXTMAIL), Full_Addr_Str (&remote_addr));
    modem_busy ();
    vfossil_cursor (1);
    close_up (share);
}


int
EXTMAIL_callback (char *reqs)
{
    unsigned char *p = bufp->extmail._p;  /* TJW 960416 */
    unsigned char *q = bufp->extmail._q;  /* TJW 960416 */

    struct stat f;
    long ltime;

    ltime = (long) unix_time (NULL);

    /* VRP 990915: changed external session success flag check.
     * External session success is now determined by the presense of
     * esess_ok.%task% flag in the flag dir.
     *
     * Was: sprintf ((char *) q, "%s.%03x", ExtMailAgent, TaskNumber);
     */

    sprintf ((char *) q, "%sesess_ok.%03x", flag_dir, TaskNumber);

    /* VRP 990915 end */

    unlink ((char *) q);

    unix_stat (reqs, &f);

    sprintf ((char *) p, "%s %s %03x %s", ExtMailAgent,
             Full_Addr_Str (&remote_addr), TaskNumber, reqs);

    status_line (">run %s", (char *) p);

    b_spawn ((char *) p);

    if (!dexists ((char *) q))
    {
        status_line (">%s not found", (char *) q);  /* VRP 990915 */
        DeinitExtAgent ();
        return CANNOT_SEND;
    }

    status_line (">%s found", (char *) q);  /* VRP 990915 */
    hist.files_out++;
    hist.size_out += f.st_size;
    hist.time_out += (long) unix_time (NULL) - ltime;

    return FILE_SENT_OK;
}


static void LOCALFUNC
DeinitExtAgent ()
{
    come_back ();
    modem_init ();
    status_line (MSG_TXT (M_END_EXTMAIL), Full_Addr_Str (&remote_addr));
}

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

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