home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 4.ddi / NETBIOS / CTAMSGX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  6.9 KB  |  319 lines

  1. /*
  2.  *    System Dependent Application Message Handling
  3.  *    server extension version
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1987, 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *    4006 West Broadway
  15.  *    Columbia, MO 65203
  16.  *
  17.  *
  18.  *    c-tree(R)    Version 4.3
  19.  *            Release C
  20.  *            February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24.  
  25. #include "ctstdr.h"
  26. #include "ctoptn.h"
  27. #include "ctstrc.h"
  28. #include "cterrc.h"
  29. #include "ctcomm.h"
  30.  
  31. #include "ctnbio.h"
  32.  
  33. #include "ctsxcfg.h"
  34. #include "ctaxit.h"            /* CBRKmode and CERRmode defines */
  35. #include <dos.h>
  36.  
  37.  
  38. #ifdef DEBUG
  39.  #ifdef LOCAL
  40.   #undef LOCAL
  41.   #define LOCAL /* */
  42.  #endif
  43. #endif
  44.  
  45. #define SMB_ID    (            (((UTEXT *) smb) + SMBid) )
  46. #define SMB_CMD   (            (((UTEXT *) smb) + SMBcmd) )
  47. #define SMB_ECLASS (           (((UTEXT *) smb) + SMBeclass) )
  48. #define SMB_CMDX  (            (((UTEXT *) smb) + SMBcmdx) )
  49. #define SMB_CTSIG (            (((UTEXT *) smb) + SMBctsig) )
  50. #define SMB_DATA  (            (((UTEXT *) smb) + SMBdata) )
  51. #define SMB_WCT   (            (((UTEXT *) smb) + SMBwct) )
  52. #define SMB_BCT   ( (UCOUNT *) (((UTEXT *) smb) + SMBbct) )
  53. #define SMB_BLKID (            (((UTEXT *) smb) + SMBblkid) )
  54. #define SMB_DATSZ ( (UCOUNT *) (((UTEXT *) smb) + SMBdatsz) )
  55.  
  56.  
  57. LOCAL NCB ncb;                /* netbios control block */
  58. LOCAL COUNT lsn = 0;            /* nbios ses num (-1 if local user) */
  59. LOCAL COUNT connected = 0;        /* set to 1 in getmids */
  60. LOCAL MESSAGE *ctlmsg;            /* ptr to message buffer */
  61. LOCAL UCOUNT rspn_e;            /* save response recv err */
  62. LOCAL UCOUNT msgsiz;
  63. LOCAL UCOUNT (far *fnulf)() = 0L;
  64. LOCAL TEXT   fnbuffer[256];
  65.  
  66. extern COUNT uerr_cod;
  67. extern TEXT  ct_buf[];
  68. extern UCOUNT cts_apxsiz;
  69.  
  70. extern UCOUNT far get_redir_entry(UCOUNT, UTEXT far *, UTEXT far *,
  71.                 UCOUNT far *, UCOUNT far *, UCOUNT far *);
  72.  
  73. TEXT *mballc();
  74.  
  75. /* copies a file name, after modifying name to a fully specified form */
  76. COUNT fulnam(dp, tp,maxlen) 
  77. PFAST TEXT  *dp,*tp;
  78. COUNT            maxlen;
  79. {
  80.     strcpy(dp,tp);
  81.     return(NO_ERROR);
  82. }
  83.  
  84.  
  85.  
  86. TEXT *getmids(apsize, pmsg)
  87. UCOUNT          apsize;
  88. MESSAGE             *pmsg;
  89. {
  90.     SMB *smb;
  91.     UCOUNT e;
  92.     union REGS r;
  93.  
  94.     uerr_cod = 0;
  95.     msgsiz = apsize;        /* local copy of msg len */
  96.  
  97.     /*
  98.      * check for network redirector installed
  99.      */
  100.     r.x.ax = 0xb800;
  101.     int86(0x2f, &r, &r);
  102.     if (!r.h.al || !(8 & r.x.bx)) {
  103.         uerr_cod = ASKY_ERR;
  104.         return (NULL);
  105.     }
  106.  
  107.     /* find connection to server */
  108.  
  109.     if (e = find_server()) {
  110.         uerr_cod = ASKY_ERR;
  111.         return (NULL);
  112.     }
  113.  
  114.     /* alloc message buffer */
  115.  
  116.     if (NULL == (smb = (SMB *) mballc(1, SMBdata + apsize))) {
  117.         uerr_cod = ASPC_ERR;
  118.         return (NULL);
  119.     }
  120.  
  121.  
  122.     /*
  123.      * unix version requires 'application id' in mpntr.  Not needed for
  124.      * this version so just set it to 0.
  125.      */
  126.  
  127.     pmsg->mpntr = 0;
  128.  
  129.     ctlmsg = (MESSAGE *) SMB_DATA;    /* save pointer to msg for disconnect */
  130.  
  131.  
  132.     connected = 1;
  133.  
  134.     /*
  135.      * set traps on abnormal program exits (control-c or critical error)
  136.      * the trap routines will call STPUSR() just before returning to DOS
  137.      * (or will prevent program termination, depending on mode)
  138.      */
  139.  
  140.     set_abort_traps(CBRKmode, CERRmode);
  141.  
  142.     return ( SMB_DATA );
  143. }
  144.  
  145. COUNT ridmids()
  146. {
  147.     disconnect();
  148.     return (0);
  149. }
  150.  
  151. COUNT ctrqst(msgadr,pmsg)
  152. PFAST TEXT  *msgadr;        /* ptr to message area */
  153. MESSAGE           *pmsg;    /* ptr to message header */
  154. {
  155.     UCOUNT msz;
  156.     UCOUNT e;
  157.     SMB *smb;
  158.     union REGS r;
  159.     struct SREGS sr;
  160.     TEXT *bfp;
  161.  
  162.     smb = (SMB *) (msgadr - SMBdata);
  163.  
  164.     cpybuf(msgadr, pmsg, sizeof(MESSAGE));
  165.  
  166.     /* if TST_MSGSIZ (login), add machine name to
  167.      * message (will be stripped off by ctsmsgx
  168.      */
  169.  
  170.     if (pmsg->mfunc == TST_MSGSIZ)
  171.     {
  172.         ((MESSAGE *) msgadr)->mdlen += 16;
  173.         bfp = msgadr + sizeof(MESSAGE) + pmsg->mdlen;
  174.         r.x.dx = (UCOUNT) (ULONG) bfp;    /* data area after MESSAGE */
  175.         sr.ds = (UCOUNT) ( ((ULONG) bfp) >> 16 );
  176.         r.x.ax = 0x5e00;
  177.         intdosx(&r, &r, &sr);        /* get machine name */
  178.     }
  179.  
  180.     msz = sizeof(MESSAGE) + ((MESSAGE *) msgadr)->mdlen;
  181.  
  182.     cpybuf(SMB_ID, "\xffSMB", 4);
  183.     *SMB_CMD = 0xff;
  184.     *SMB_CMDX = 0xdd;
  185.     *SMB_ECLASS = 0;
  186.     cpybuf(SMB_CTSIG, SRV_SMBNAME, 8);
  187.     *SMB_WCT = 0;
  188.     *SMB_BCT = msz + 3;
  189.     *SMB_BLKID = VBLOCKID;
  190.     *SMB_DATSZ = msz;
  191.  
  192.  
  193.     if (lsn != -1) {
  194.         e = nb_send(&ncb, 0, fnulf, lsn, (UTEXT *) smb, msz + SMBdata);
  195.         #ifdef DEBUG
  196.         /*printf("Sent %d, err = %d\n", msz, e);*/
  197.         #endif
  198.     }
  199.     else {
  200.         r.h.ah = SRV_MUXID;
  201.         r.h.al = I2Frequest;
  202.         r.x.di = (UCOUNT) smb;
  203.         sr.ds = (UCOUNT) ( ((ULONG) (SMB far *) smb) >> 16 );
  204.         int86x(0x2f, &r, &r, &sr);
  205.         e = r.h.al;
  206.     }
  207.     if (e)
  208.         return (uerr_cod = ARQS_ERR);
  209.  
  210.     if (lsn != -1) {
  211.         rspn_e = nb_recv(&ncb, 0,fnulf,lsn, (UTEXT *) smb, msgsiz + SMBdata);
  212.         #ifdef DEBUG
  213.         /*printf("Rcv'd %d, err = %d\n", ncb.buflen, e);*/
  214.         #endif
  215.         if (!rspn_e && *SMB_ECLASS)
  216.             return(uerr_cod = ARQS_ERR);
  217.     }
  218.     else
  219.         rspn_e = 0;
  220.  
  221.     return (NO_ERROR);
  222. }
  223.  
  224. COUNT ctrspn(msgadr,pmsg)
  225. PFAST TEXT **msgadr;
  226. MESSAGE                *pmsg;
  227. {
  228.     /* the actual receive is in ctrqst */
  229.     if (rspn_e)
  230.         return(uerr_cod = ARSP_ERR);
  231.     cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
  232.     return (NO_ERROR);
  233. }
  234.  
  235.  
  236. /* fdisconnect is called from asm language in ctaxit */
  237.  
  238. void far fdisconnect()
  239. {
  240.     disconnect();
  241. }
  242.  
  243. /*
  244.  * hangup. if user hasn't logically logged off, server will clean up anyway
  245.  * this does a virtual hangup by sending a message that only ctsmsg sees.
  246.  * uses the main message buffer since appx is done with it
  247.  */
  248.  
  249. disconnect()
  250. {
  251.  
  252.     if (connected) {
  253.         connected = 0;
  254.         ctlmsg->mfunc = TST_SMSG;
  255.         ctlmsg->mdlen = 0;
  256.         if (!ctrqst(ctlmsg,ctlmsg)) {
  257.             ctrspn(&ctlmsg,ctlmsg);
  258.         }
  259.     }
  260. }
  261.  
  262. find_server()
  263. {
  264.     UCOUNT e, i;
  265.     union REGS r;
  266.     TEXT netname[128];
  267.     TEXT devname[128];
  268.     TEXT *s;
  269.     UCOUNT tid, maxsz;
  270.  
  271.     TEXT *strrchr();
  272.  
  273.     /* check to see if server on same machine */
  274.     r.h.ah = SRV_MUXID;
  275.     r.h.al = I2Ftestres;        /* a 0 */
  276.     int86(0x2f, &r, &r);
  277.  
  278.     if (r.h.al) {
  279.         lsn = -1;    /* lsn of -1 means server is on same machine */
  280.         return (0);
  281.     }
  282.  
  283.     /* server not on same machine, find an established connect to it */
  284.  
  285.     for (i=0; ;i++) {
  286.         e = get_redir_entry(i, (TEXT far *) netname,
  287.                     (TEXT far *) devname,
  288.                     (UCOUNT far *) &tid,
  289.                     (UCOUNT far *) &maxsz,
  290.                     (UCOUNT far *) &lsn);
  291.         if (e)
  292.             return -1;
  293.         s = strrchr(netname, '\\');
  294.         if (s != NULL && !strcmp(s+1, SRV_SMBNAME_NOPAD))
  295.             return 0;
  296.     }
  297. }
  298.  
  299. /*
  300.  * called from ctnbios.c
  301.  */
  302.  
  303. UCOUNT far do_nb(ncb)
  304. NCB          far *ncb;
  305. {
  306.     union REGS r;
  307.     struct SREGS sr;
  308.  
  309.     ncb->lana = 0;            /* always adapter 0 */
  310.  
  311.     sr.es = sr.ds = (UCOUNT) ( ((ULONG) (NCB far *) ncb) >> 16 );
  312.     r.x.bx = (UCOUNT) ncb;
  313.     r.x.ax = 0x0400;    /* execute netbios w/ retry */
  314.     int86x(0x2a, &r, &r, &sr);
  315.     return ((UCOUNT) r.h.al);
  316. }
  317.  
  318. /* end of ctamsgx.c */
  319.