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

  1. /*
  2.  *    System Dependent Application Message Handling
  3.  *    Net Bios
  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. #include "ctstdr.h"
  25. #include "ctoptn.h"
  26. #include "ctstrc.h"
  27. #include "cterrc.h"
  28. #include "ctcomm.h"
  29.  
  30. #include "ctnbio.h"
  31. #include "ctnbcfg.h"
  32. #include "ctaxit.h"            /* CBRKmode and CERRmode defines */
  33. #include <dos.h>
  34.  
  35. /*
  36.  * If REPOSTNAME is defined, then each login will have a name check delay
  37.  * If not defined, then once NetBios name (CTxxxxxxxxxxxx) has been added,
  38.  * it is never deleted (normal setting).
  39. #define REPOSTNAME
  40.  *
  41.  */
  42.  
  43. /*
  44.  * IF QUIET is defined, then Netbios connect errors will simply return
  45.  * the appropriate c-tree error code. If not defined (normal setting),
  46.  * then a netbios connection error will cause more specific diagnostics
  47.  * to be reported directly to stdout.
  48. #define QUIET
  49.  *
  50.  */
  51.  
  52. #ifdef DEBUG
  53.  #ifdef LOCAL
  54.   #undef LOCAL
  55.   #define LOCAL /* */
  56.  #endif
  57. #endif
  58.  
  59. LOCAL NCB ncb;                /* netbios control block for send & ctl */
  60. LOCAL NCB rncb;            /* ncb for receive */
  61. LOCAL TEXT *mbuf[2];        /* 1 buf for send, 1 for recv */
  62. LOCAL COUNT lsn = 0;
  63. LOCAL COUNT namenum = 0;
  64. LOCAL TEXT usrname[] = USR_NETNAME;
  65. LOCAL UCOUNT msgsiz;
  66. LOCAL UCOUNT (far *fnulf)() = 0L;
  67.  
  68. LOCAL TEXT   fnbuffer[256];
  69.  
  70. extern COUNT uerr_cod;
  71. extern TEXT  ct_buf[];
  72. extern UCOUNT cts_apxsiz;
  73.  
  74.  
  75. TEXT *mballc();
  76.  
  77. /* copies a file name, after modifying name to a fully specified form */
  78. COUNT fulnam(dp, tp,maxlen) 
  79. PFAST TEXT  *dp,*tp;
  80. COUNT            maxlen;
  81. {
  82.     strcpy(dp,tp);
  83.     return(NO_ERROR);
  84. }
  85.  
  86. #ifndef QUIET
  87. static applic(tp,e)
  88. TEXT *tp;
  89. UCOUNT e;
  90. {
  91.     printf(
  92. "\n\n****************\nThis application cannot %s. Netbios error=%d.",tp,e);
  93.     printf("\nPlease call your software supplier to report this message.");
  94.     printf("\n****************\n\n");
  95. }
  96. #endif
  97.  
  98.  
  99. TEXT *getmids(apsize, pmsg)
  100. UCOUNT          apsize;
  101. MESSAGE             *pmsg;
  102. {
  103.     NB_ASTS *nbas;
  104.     TEXT *retval;
  105.     UCOUNT e, i, t;
  106.  
  107.     uerr_cod = 0;
  108.     msgsiz = apsize;        /* local copy of msg len */
  109.     if (e = nb_install_check()) {
  110.         uerr_cod = ASKY_ERR;
  111. #ifndef QUIET
  112.         applic("find Netbios",e);
  113. #endif
  114.         return (NULL);
  115.     }
  116.     if (NULL == (nbas = (NB_ASTS *) mballc(1, sizeof(NB_ASTS)))) {
  117.         uerr_cod = ASPC_ERR;    /* cannot allocate memory */
  118.         return (NULL);
  119.     }
  120.     e = nb_adapter_stat(&ncb, 0, fnulf, "*", nbas, sizeof(NB_ASTS));
  121.     if (e && e != NERRmsgincompl) {
  122.         mbfree(nbas);
  123.         uerr_cod = AAID_ERR;
  124. #ifndef QUIET
  125.         applic("complete adapter status check",e);
  126. #endif
  127.         return (NULL);
  128.     }
  129.     for (i=0; i<12; i++)
  130.     {
  131.         t = nbas->nodename[i >> 1];
  132.         if (i & 1)
  133.             t >>= 4;
  134.         t = (t & 15) + '0';
  135.         if (t > '9')
  136.             t += 7;
  137.         usrname[i + USR_NODENDX] = t;
  138.     }
  139.     mbfree(nbas);
  140.     e = nb_addname(&ncb, 0, fnulf, usrname);
  141.     if (e && e != NERRdupname) {
  142.         uerr_cod = AAID_ERR;
  143. #ifndef QUIET
  144.         applic("add username",e);
  145. #endif
  146.         return (NULL);
  147.     }
  148. #ifdef REPOSTNAME
  149.     if (!e)
  150.         namenum = ncb.namenum;
  151. #endif
  152.     e = nb_call(&ncb, 0, fnulf, SRV_NETNAME, usrname, NBRTO, NBSTO);
  153.     if (e) {
  154.         uerr_cod = (e == NERRcallrej ? AAID_ERR : AAID_ERR);
  155. #ifndef QUIET
  156.         applic(
  157. "find the c-tree(R) server.\nAre you sure it is running?\nDouble check",e);
  158. #endif
  159.         return (NULL);
  160.     }
  161.     lsn = ncb.lsn;
  162.     if (NULL == (retval = mbuf[0] = mballc(1, apsize))
  163.             || NULL == (mbuf[1] = mballc(1, apsize))) {
  164.         disconnect();
  165.         uerr_cod = ASPC_ERR;
  166.         return (NULL);
  167.     }
  168.     /*
  169.      * unix version requires 'application id' in mpntr.  Not needed for
  170.      * netbios version so just set it to 0.
  171.      */
  172.  
  173.     pmsg->mpntr = 0;
  174.  
  175.     /*
  176.      * set traps on abnormal program exits (control-c or critical error)
  177.      * the trap routines will call STPUSR() just before returning to DOS
  178.      * (or will prevent program termination, depending on mode)
  179.      */
  180.  
  181.     set_abort_traps(CBRKmode, CERRmode);
  182.  
  183.     return (retval);        
  184. }
  185.  
  186. COUNT ridmids()
  187. {
  188.     disconnect();
  189.     return (0);
  190. }
  191.  
  192. COUNT ctrqst(msgadr,pmsg)
  193. PFAST TEXT  *msgadr;        /* ptr to message area */
  194. MESSAGE           *pmsg;    /* ptr to message header */
  195. {
  196.     UCOUNT msz;
  197.     UCOUNT e;
  198.  
  199.     cpybuf(msgadr, pmsg, sizeof(MESSAGE));
  200.  
  201.     /* if TST_MSGSIZ (login), add machine name to
  202.      * message (will be stripped off by ctsmsg)
  203.      */
  204.  
  205.     if (pmsg->mfunc == TST_MSGSIZ)
  206.     {
  207.         ((MESSAGE *) msgadr)->mdlen += 16;
  208.         cpybuf(msgadr + sizeof(MESSAGE) + pmsg->mdlen, usrname, 15);
  209.         *(msgadr + sizeof(MESSAGE) + pmsg->mdlen + 15) = 0;
  210.     }
  211.  
  212.     msz = sizeof(MESSAGE) + ((MESSAGE *) msgadr)->mdlen;
  213.  
  214.     /* start an asynch send so that receive can be started
  215.      * quickly on slower machines
  216.      */
  217.  
  218.     /* send the request */
  219.     nb_send(&ncb, NCBanr, fnulf, lsn, msgadr, msz);
  220.  
  221.     /* get response */
  222.     e = nb_recv(&rncb, 0, fnulf, lsn,
  223.         msgadr == mbuf[0] ? mbuf[1] : mbuf[0], msgsiz);
  224.  
  225.     /* make sure send completes */
  226.     while (0xff == ncb.doneflag)
  227.         ;
  228.     
  229.  
  230.     #ifdef DEBUG
  231.     /*printf("Sent %d, err = %d\n", msz, e);*/
  232.     #endif
  233.  
  234. #ifndef QUIET
  235.     if (e) {
  236.         applic("send message",e);
  237.         return (uerr_cod = ARQS_ERR);
  238.     }
  239. #else
  240.     if (e)
  241.         return (uerr_cod = ARQS_ERR);
  242. #endif
  243.     else
  244.         return (NO_ERROR);
  245. }
  246.  
  247. COUNT ctrspn(msgadr,pmsg)
  248. PFAST TEXT **msgadr;
  249. MESSAGE                *pmsg;
  250. {
  251.     UCOUNT e;
  252.  
  253.     e = rncb.err;
  254.  
  255.     /* swap buffers on the caller (which passed us ptr to ptr) */
  256.     *msgadr = (*msgadr == mbuf[0]) ? mbuf[1] : mbuf[0];
  257.  
  258.     #ifdef DEBUG
  259.     /*printf("Rcv'd %d, err = %d\n", ncb.buflen, e);*/
  260.     #endif
  261.  
  262. #ifndef QUIET
  263.     if (e) {
  264.         applic("receive message",e);
  265.         return(uerr_cod = ARSP_ERR);
  266.     }
  267. #else
  268.     if (e)
  269.         return(uerr_cod = ARSP_ERR);
  270. #endif
  271.  
  272.     /* update callers header buffer */
  273.     cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
  274.  
  275.     return (NO_ERROR);
  276. }
  277.  
  278.  
  279. /* fdisconnect is called from asm language in ctaxit */
  280.  
  281. void far fdisconnect()
  282. {
  283.     disconnect();
  284. }
  285.  
  286. /*
  287.  * hangup. if user hasn't logically logged off, server will clean up anyway
  288.  */
  289.  
  290. disconnect()
  291. {
  292.     if (lsn)
  293.         nb_hangup(&ncb, 0, fnulf, lsn);
  294.     lsn = 0;
  295.     if (namenum)
  296.         nb_delname(&ncb, 0, fnulf, usrname);
  297.     namenum = 0;
  298. }
  299.  
  300.  
  301. /*
  302.  * called from ctnbios.c
  303.  */
  304.  
  305. UCOUNT far do_nb(ncb)
  306. NCB          far *ncb;
  307. {
  308.     union REGS r;
  309.     struct SREGS sr;
  310.  
  311.     ncb->lana = 0;            /* always adapter 0 */
  312.  
  313.     sr.es = sr.ds = (UCOUNT) ( ((ULONG) (NCB far *) ncb) >> 16 );
  314.     r.x.bx = (UCOUNT) ncb;
  315.     int86x(0x5c, &r, &r, &sr);
  316.     return ((UCOUNT) r.h.al);
  317. }
  318.  
  319. /* end of ctamsg.c */
  320.