home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Application Message Handling
- * server extension version
- *
- * 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 "ctsxcfg.h"
- #include "ctaxit.h" /* CBRKmode and CERRmode defines */
- #include <dos.h>
-
-
- #ifdef DEBUG
- #ifdef LOCAL
- #undef LOCAL
- #define LOCAL /* */
- #endif
- #endif
-
- #define SMB_ID ( (((UTEXT *) smb) + SMBid) )
- #define SMB_CMD ( (((UTEXT *) smb) + SMBcmd) )
- #define SMB_ECLASS ( (((UTEXT *) smb) + SMBeclass) )
- #define SMB_CMDX ( (((UTEXT *) smb) + SMBcmdx) )
- #define SMB_CTSIG ( (((UTEXT *) smb) + SMBctsig) )
- #define SMB_DATA ( (((UTEXT *) smb) + SMBdata) )
- #define SMB_WCT ( (((UTEXT *) smb) + SMBwct) )
- #define SMB_BCT ( (UCOUNT *) (((UTEXT *) smb) + SMBbct) )
- #define SMB_BLKID ( (((UTEXT *) smb) + SMBblkid) )
- #define SMB_DATSZ ( (UCOUNT *) (((UTEXT *) smb) + SMBdatsz) )
-
-
- LOCAL NCB ncb; /* netbios control block */
- LOCAL COUNT lsn = 0; /* nbios ses num (-1 if local user) */
- LOCAL COUNT connected = 0; /* set to 1 in getmids */
- LOCAL MESSAGE *ctlmsg; /* ptr to message buffer */
- LOCAL UCOUNT rspn_e; /* save response recv err */
- LOCAL UCOUNT msgsiz;
- LOCAL UCOUNT (far *fnulf)() = 0L;
- LOCAL TEXT fnbuffer[256];
-
- extern COUNT uerr_cod;
- extern TEXT ct_buf[];
- extern UCOUNT cts_apxsiz;
-
- extern UCOUNT far get_redir_entry(UCOUNT, UTEXT far *, UTEXT far *,
- UCOUNT far *, UCOUNT far *, UCOUNT far *);
-
- 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);
- }
-
-
-
- TEXT *getmids(apsize, pmsg)
- UCOUNT apsize;
- MESSAGE *pmsg;
- {
- SMB *smb;
- UCOUNT e;
- union REGS r;
-
- uerr_cod = 0;
- msgsiz = apsize; /* local copy of msg len */
-
- /*
- * check for network redirector installed
- */
- r.x.ax = 0xb800;
- int86(0x2f, &r, &r);
- if (!r.h.al || !(8 & r.x.bx)) {
- uerr_cod = ASKY_ERR;
- return (NULL);
- }
-
- /* find connection to server */
-
- if (e = find_server()) {
- uerr_cod = ASKY_ERR;
- return (NULL);
- }
-
- /* alloc message buffer */
-
- if (NULL == (smb = (SMB *) mballc(1, SMBdata + apsize))) {
- uerr_cod = ASPC_ERR;
- return (NULL);
- }
-
-
- /*
- * unix version requires 'application id' in mpntr. Not needed for
- * this version so just set it to 0.
- */
-
- pmsg->mpntr = 0;
-
- ctlmsg = (MESSAGE *) SMB_DATA; /* save pointer to msg for disconnect */
-
-
- connected = 1;
-
- /*
- * 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 ( SMB_DATA );
- }
-
- 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;
- SMB *smb;
- union REGS r;
- struct SREGS sr;
- TEXT *bfp;
-
- smb = (SMB *) (msgadr - SMBdata);
-
- cpybuf(msgadr, pmsg, sizeof(MESSAGE));
-
- /* if TST_MSGSIZ (login), add machine name to
- * message (will be stripped off by ctsmsgx
- */
-
- if (pmsg->mfunc == TST_MSGSIZ)
- {
- ((MESSAGE *) msgadr)->mdlen += 16;
- bfp = msgadr + sizeof(MESSAGE) + pmsg->mdlen;
- r.x.dx = (UCOUNT) (ULONG) bfp; /* data area after MESSAGE */
- sr.ds = (UCOUNT) ( ((ULONG) bfp) >> 16 );
- r.x.ax = 0x5e00;
- intdosx(&r, &r, &sr); /* get machine name */
- }
-
- msz = sizeof(MESSAGE) + ((MESSAGE *) msgadr)->mdlen;
-
- cpybuf(SMB_ID, "\xffSMB", 4);
- *SMB_CMD = 0xff;
- *SMB_CMDX = 0xdd;
- *SMB_ECLASS = 0;
- cpybuf(SMB_CTSIG, SRV_SMBNAME, 8);
- *SMB_WCT = 0;
- *SMB_BCT = msz + 3;
- *SMB_BLKID = VBLOCKID;
- *SMB_DATSZ = msz;
-
-
- if (lsn != -1) {
- e = nb_send(&ncb, 0, fnulf, lsn, (UTEXT *) smb, msz + SMBdata);
- #ifdef DEBUG
- /*printf("Sent %d, err = %d\n", msz, e);*/
- #endif
- }
- else {
- r.h.ah = SRV_MUXID;
- r.h.al = I2Frequest;
- r.x.di = (UCOUNT) smb;
- sr.ds = (UCOUNT) ( ((ULONG) (SMB far *) smb) >> 16 );
- int86x(0x2f, &r, &r, &sr);
- e = r.h.al;
- }
- if (e)
- return (uerr_cod = ARQS_ERR);
-
- if (lsn != -1) {
- rspn_e = nb_recv(&ncb, 0,fnulf,lsn, (UTEXT *) smb, msgsiz + SMBdata);
- #ifdef DEBUG
- /*printf("Rcv'd %d, err = %d\n", ncb.buflen, e);*/
- #endif
- if (!rspn_e && *SMB_ECLASS)
- return(uerr_cod = ARQS_ERR);
- }
- else
- rspn_e = 0;
-
- return (NO_ERROR);
- }
-
- COUNT ctrspn(msgadr,pmsg)
- PFAST TEXT **msgadr;
- MESSAGE *pmsg;
- {
- /* the actual receive is in ctrqst */
- if (rspn_e)
- return(uerr_cod = ARSP_ERR);
- 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
- * this does a virtual hangup by sending a message that only ctsmsg sees.
- * uses the main message buffer since appx is done with it
- */
-
- disconnect()
- {
-
- if (connected) {
- connected = 0;
- ctlmsg->mfunc = TST_SMSG;
- ctlmsg->mdlen = 0;
- if (!ctrqst(ctlmsg,ctlmsg)) {
- ctrspn(&ctlmsg,ctlmsg);
- }
- }
- }
-
- find_server()
- {
- UCOUNT e, i;
- union REGS r;
- TEXT netname[128];
- TEXT devname[128];
- TEXT *s;
- UCOUNT tid, maxsz;
-
- TEXT *strrchr();
-
- /* check to see if server on same machine */
- r.h.ah = SRV_MUXID;
- r.h.al = I2Ftestres; /* a 0 */
- int86(0x2f, &r, &r);
-
- if (r.h.al) {
- lsn = -1; /* lsn of -1 means server is on same machine */
- return (0);
- }
-
- /* server not on same machine, find an established connect to it */
-
- for (i=0; ;i++) {
- e = get_redir_entry(i, (TEXT far *) netname,
- (TEXT far *) devname,
- (UCOUNT far *) &tid,
- (UCOUNT far *) &maxsz,
- (UCOUNT far *) &lsn);
- if (e)
- return -1;
- s = strrchr(netname, '\\');
- if (s != NULL && !strcmp(s+1, SRV_SMBNAME_NOPAD))
- return 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;
- r.x.ax = 0x0400; /* execute netbios w/ retry */
- int86x(0x2a, &r, &r, &sr);
- return ((UCOUNT) r.h.al);
- }
-
- /* end of ctamsgx.c */
-