home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Application Message Handling
- * Net Bios
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
-
- #include "ctnbio.h"
- #include "ctnbcfg.h"
- #include "ctaxit.h" /* CBRKmode and CERRmode defines */
- #include <dos.h>
-
- /*
- * If REPOSTNAME is defined, then each login will have a name check delay
- * If not defined, then once NetBios name (CTxxxxxxxxxxxx) has been added,
- * it is never deleted (normal setting).
- #define REPOSTNAME
- *
- */
-
- /*
- * IF QUIET is defined, then Netbios connect errors will simply return
- * the appropriate c-tree error code. If not defined (normal setting),
- * then a netbios connection error will cause more specific diagnostics
- * to be reported directly to stdout.
- #define QUIET
- *
- */
-
- #ifdef DEBUG
- #ifdef LOCAL
- #undef LOCAL
- #define LOCAL /* */
- #endif
- #endif
-
- LOCAL NCB ncb; /* netbios control block for send & ctl */
- LOCAL NCB rncb; /* ncb for receive */
- LOCAL TEXT *mbuf[2]; /* 1 buf for send, 1 for recv */
- LOCAL COUNT lsn = 0;
- LOCAL COUNT namenum = 0;
- LOCAL TEXT usrname[] = USR_NETNAME;
- LOCAL UCOUNT msgsiz;
- LOCAL UCOUNT (far *fnulf)() = 0L;
-
- LOCAL TEXT fnbuffer[256];
-
- extern COUNT uerr_cod;
- extern TEXT ct_buf[];
- extern UCOUNT cts_apxsiz;
-
-
- TEXT *mballc();
-
- /* copies a file name, after modifying name to a fully specified form */
- COUNT fulnam(dp, tp,maxlen)
- PFAST TEXT *dp,*tp;
- COUNT maxlen;
- {
- strcpy(dp,tp);
- return(NO_ERROR);
- }
-
- #ifndef QUIET
- static applic(tp,e)
- TEXT *tp;
- UCOUNT e;
- {
- printf(
- "\n\n****************\nThis application cannot %s. Netbios error=%d.",tp,e);
- printf("\nPlease call your software supplier to report this message.");
- printf("\n****************\n\n");
- }
- #endif
-
-
- TEXT *getmids(apsize, pmsg)
- UCOUNT apsize;
- MESSAGE *pmsg;
- {
- NB_ASTS *nbas;
- TEXT *retval;
- UCOUNT e, i, t;
-
- uerr_cod = 0;
- msgsiz = apsize; /* local copy of msg len */
- if (e = nb_install_check()) {
- uerr_cod = ASKY_ERR;
- #ifndef QUIET
- applic("find Netbios",e);
- #endif
- return (NULL);
- }
- if (NULL == (nbas = (NB_ASTS *) mballc(1, sizeof(NB_ASTS)))) {
- uerr_cod = ASPC_ERR; /* cannot allocate memory */
- return (NULL);
- }
- e = nb_adapter_stat(&ncb, 0, fnulf, "*", nbas, sizeof(NB_ASTS));
- if (e && e != NERRmsgincompl) {
- mbfree(nbas);
- uerr_cod = AAID_ERR;
- #ifndef QUIET
- applic("complete adapter status check",e);
- #endif
- return (NULL);
- }
- for (i=0; i<12; i++)
- {
- t = nbas->nodename[i >> 1];
- if (i & 1)
- t >>= 4;
- t = (t & 15) + '0';
- if (t > '9')
- t += 7;
- usrname[i + USR_NODENDX] = t;
- }
- mbfree(nbas);
- e = nb_addname(&ncb, 0, fnulf, usrname);
- if (e && e != NERRdupname) {
- uerr_cod = AAID_ERR;
- #ifndef QUIET
- applic("add username",e);
- #endif
- return (NULL);
- }
- #ifdef REPOSTNAME
- if (!e)
- namenum = ncb.namenum;
- #endif
- e = nb_call(&ncb, 0, fnulf, SRV_NETNAME, usrname, NBRTO, NBSTO);
- if (e) {
- uerr_cod = (e == NERRcallrej ? AAID_ERR : AAID_ERR);
- #ifndef QUIET
- applic(
- "find the c-tree(R) server.\nAre you sure it is running?\nDouble check",e);
- #endif
- return (NULL);
- }
- lsn = ncb.lsn;
- if (NULL == (retval = mbuf[0] = mballc(1, apsize))
- || NULL == (mbuf[1] = mballc(1, apsize))) {
- disconnect();
- uerr_cod = ASPC_ERR;
- return (NULL);
- }
- /*
- * unix version requires 'application id' in mpntr. Not needed for
- * netbios version so just set it to 0.
- */
-
- pmsg->mpntr = 0;
-
- /*
- * set traps on abnormal program exits (control-c or critical error)
- * the trap routines will call STPUSR() just before returning to DOS
- * (or will prevent program termination, depending on mode)
- */
-
- set_abort_traps(CBRKmode, CERRmode);
-
- return (retval);
- }
-
- COUNT ridmids()
- {
- disconnect();
- return (0);
- }
-
- COUNT ctrqst(msgadr,pmsg)
- PFAST TEXT *msgadr; /* ptr to message area */
- MESSAGE *pmsg; /* ptr to message header */
- {
- UCOUNT msz;
- UCOUNT e;
-
- cpybuf(msgadr, pmsg, sizeof(MESSAGE));
-
- /* if TST_MSGSIZ (login), add machine name to
- * message (will be stripped off by ctsmsg)
- */
-
- if (pmsg->mfunc == TST_MSGSIZ)
- {
- ((MESSAGE *) msgadr)->mdlen += 16;
- cpybuf(msgadr + sizeof(MESSAGE) + pmsg->mdlen, usrname, 15);
- *(msgadr + sizeof(MESSAGE) + pmsg->mdlen + 15) = 0;
- }
-
- msz = sizeof(MESSAGE) + ((MESSAGE *) msgadr)->mdlen;
-
- /* start an asynch send so that receive can be started
- * quickly on slower machines
- */
-
- /* send the request */
- nb_send(&ncb, NCBanr, fnulf, lsn, msgadr, msz);
-
- /* get response */
- e = nb_recv(&rncb, 0, fnulf, lsn,
- msgadr == mbuf[0] ? mbuf[1] : mbuf[0], msgsiz);
-
- /* make sure send completes */
- while (0xff == ncb.doneflag)
- ;
-
-
- #ifdef DEBUG
- /*printf("Sent %d, err = %d\n", msz, e);*/
- #endif
-
- #ifndef QUIET
- if (e) {
- applic("send message",e);
- return (uerr_cod = ARQS_ERR);
- }
- #else
- if (e)
- return (uerr_cod = ARQS_ERR);
- #endif
- else
- return (NO_ERROR);
- }
-
- COUNT ctrspn(msgadr,pmsg)
- PFAST TEXT **msgadr;
- MESSAGE *pmsg;
- {
- UCOUNT e;
-
- e = rncb.err;
-
- /* swap buffers on the caller (which passed us ptr to ptr) */
- *msgadr = (*msgadr == mbuf[0]) ? mbuf[1] : mbuf[0];
-
- #ifdef DEBUG
- /*printf("Rcv'd %d, err = %d\n", ncb.buflen, e);*/
- #endif
-
- #ifndef QUIET
- if (e) {
- applic("receive message",e);
- return(uerr_cod = ARSP_ERR);
- }
- #else
- if (e)
- return(uerr_cod = ARSP_ERR);
- #endif
-
- /* update callers header buffer */
- cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
-
- return (NO_ERROR);
- }
-
-
- /* fdisconnect is called from asm language in ctaxit */
-
- void far fdisconnect()
- {
- disconnect();
- }
-
- /*
- * hangup. if user hasn't logically logged off, server will clean up anyway
- */
-
- disconnect()
- {
- if (lsn)
- nb_hangup(&ncb, 0, fnulf, lsn);
- lsn = 0;
- if (namenum)
- nb_delname(&ncb, 0, fnulf, usrname);
- namenum = 0;
- }
-
-
- /*
- * called from ctnbios.c
- */
-
- UCOUNT far do_nb(ncb)
- NCB far *ncb;
- {
- union REGS r;
- struct SREGS sr;
-
- ncb->lana = 0; /* always adapter 0 */
-
- sr.es = sr.ds = (UCOUNT) ( ((ULONG) (NCB far *) ncb) >> 16 );
- r.x.bx = (UCOUNT) ncb;
- int86x(0x5c, &r, &r, &sr);
- return ((UCOUNT) r.h.al);
- }
-
- /* end of ctamsg.c */
-