home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d026 / 25.ddi / NET / WNETCONS.AS_ / WNETCONS.AS
Encoding:
Text File  |  1991-10-17  |  8.1 KB  |  299 lines

  1. page        60, 132
  2. title        Windows Network Device Redirecting Functions
  3. ;===============================================================================
  4. ;        Filename    WNETCONS.ASM
  5. ;        Copyright    (C) 1989 by Research Machines
  6. ;        Copyright    (C) 1989-1990 Microsoft Corporation
  7. ;===============================================================================
  8. ; REVISIONS:    24/02/1989    Initial version
  9. ;        16/03/1989    Change to STANDARD procedures (save si, di, ds)
  10. ;        23/03/1989    Change to segment name / file name
  11. ;        23/03/1989    Update to spec 0.58
  12. ;        28/03/1989    Change clLocal & clRemote to offsets
  13. ;        31/03/1989    Tidied up comments
  14. ;        ever since    made it work
  15. ;===============================================================================
  16.  
  17.         memM    equ    1                ; Middle memory model
  18.         ?WIN    =    1                ; Windows prolog/epilog
  19.         ?PLM    =    1                ; Pascal calling convention
  20.  
  21.         .xlist
  22. include     cmacros.inc
  23. include     windows.inc
  24. include     msdos.inc
  25. include     wnet.inc
  26. include     wnetcaps.inc
  27. include     wnetcons.inc
  28.         .list
  29.  
  30.         .sall
  31.  
  32. externFP    MSNetMakeAssignListEntry            ; In file MSNET.ASM
  33. externFP    MSNetCancelAssignListEntry            ; In file MSNET.ASM
  34. externFP    MSNetGetAssignListEntry             ; In file MSNET.ASM
  35.  
  36. externFP    lstrlen
  37. externFP    lstrcpy
  38. externFP    lstrcmpi
  39.  
  40.  
  41. ;===============================================================================
  42. ; ============= DATA SEGMENT ===================================================
  43. ;===============================================================================
  44.  
  45. sBegin        DATA
  46.  
  47. sEnd        DATA
  48.  
  49. ;===============================================================================
  50. ; ============= CODE SEGMENT ===================================================
  51. ;===============================================================================
  52.  
  53. createSeg    _CONS, CONSCODE, BYTE, PUBLIC, CODE
  54. sBegin        CONSCODE
  55.         assumes CS, CONSCODE
  56.         assumes DS, DATA
  57.  
  58. ;===============================================================================
  59. ; ============= EXPORTED FUNTIONS ==============================================
  60. ;===============================================================================
  61.  
  62. ;===============================================================================
  63. subttl        WNetAddConnection
  64. page
  65. ;===============================================================================
  66. ;
  67. ; DESCRIPTION . Add an entry to the assign list.
  68. ; ENTRY .......
  69. ; EXIT ........
  70. ; COMMENT .....
  71. ;
  72. ;===============================================================================
  73.  
  74. cProc        WNetAddConnection, <FAR, PUBLIC>, <si>
  75.  
  76.         parmD    lpszNetPath
  77.         parmD    lpszPassword
  78.         parmD    lpszLocalName
  79.  
  80.         localW    nSizeNetPath                ; Length of remote name
  81.  
  82.         localV    RemoteName, <size aleRemoteName>
  83.  
  84. cBegin
  85.         lea    si,RemoteName
  86.  
  87. ;---------------------------------------------------------------
  88. ; Form the destination string. This has the following format:
  89. ; <machine-name><pathname><0><password><0>
  90. ; Check first that this does not exceed 128 bytes.
  91. ;---------------------------------------------------------------
  92.  
  93. WNACCheckSize:    Arg    lpszNetPath                ; Length of NetPath
  94.         cCall    lstrlen                 ;
  95.         inc    ax                    ; Plus NULL
  96.         mov    ( nSizeNetPath ), ax            ; Save
  97.  
  98.         Arg    lpszPassword                ; Length of Password
  99.         cCall    lstrlen                 ;
  100.         inc    ax                    ; Plus NULL
  101.  
  102.         add    ax, ( nSizeNetPath )            ; Plus length of NetPath
  103.         cmp    ax, size aleRemoteName            ; More than 128 bytes?
  104.         jbe    WNACFormString                ;
  105.  
  106.         mov    ax, WN_BAD_NETNAME            ; Set return code
  107.         jmp    WNACExit                ; Exit with FreeLocal
  108.  
  109. ;---------------------------------------------------------------
  110. ; Now we are sure that the destination string fits, create it in
  111. ; the heap.
  112. ;---------------------------------------------------------------
  113.  
  114. WNACFormString: Arg    RegPairSSSI                ; Copy <machine-name><pathname><0>
  115.         Arg    lpszNetPath                ;
  116.         cCall    LStrcpy                 ;
  117.  
  118.         mov    bx, si
  119.         add    bx, ( nSizeNetPath )            ; Adjust bx past first part
  120.  
  121.         Arg    RegPairSSBX                ; Copy <password><0>
  122.         Arg    lpszPassword                ;
  123.         cCall    LStrcpy                 ;
  124.  
  125. ;---------------------------------------------------------------
  126. ; Finally, make the assign list entry. This is the easy bit.
  127. ;---------------------------------------------------------------
  128.  
  129.         mov    ax, 0                    ; UserValue = 0
  130.  
  131.         Arg    lpszLocalName                ;
  132.         Arg    RegPairSSSI                ;
  133.         Arg    ax                    ;
  134.         cCall    MSNetMakeAssignListEntry        ;
  135.  
  136. ;---------------------------------------------------------------
  137. ; Return to the caller
  138. ;---------------------------------------------------------------
  139.  
  140. WNACExit:
  141. cEnd
  142.  
  143. ;===============================================================================
  144. subttl        WNetCancelConnection
  145. page
  146. ;===============================================================================
  147. ;
  148. ; DESCRIPTION . Remove an entry from the assign list.
  149. ; ENTRY .......
  150. ; EXIT ........
  151. ; COMMENT .....
  152. ;
  153. ;===============================================================================
  154.  
  155. cProc        WNetCancelConnection, <FAR, PUBLIC>
  156.  
  157.         parmD    lpszName
  158.         parmW    fForce                    ; IGNORED
  159.  
  160. cBegin
  161. ;---------------------------------------------------------------
  162. ; Cancel the assign list entry using DosCancelAssignListEntry.
  163. ;---------------------------------------------------------------
  164.  
  165.         Arg    lpszName                ;
  166.         cCall    MSNetCancelAssignListEntry        ;
  167.  
  168.         cmp    ax, WN_SUCCESS                ;
  169.         je    WNCCExit                ;
  170.  
  171.         mov    ax, WN_NOT_CONNECTED            ; Set return code
  172.  
  173. ;---------------------------------------------------------------
  174. ; Return to the caller
  175. ;---------------------------------------------------------------
  176.  
  177. WNCCExit:
  178. cEnd
  179.  
  180. ;===============================================================================
  181. subttl        WNetGetConnection
  182. page
  183. ;===============================================================================
  184. ;
  185. ; DESCRIPTION . Return a list of assign list entries.
  186. ; ENTRY .......
  187. ; EXIT ........
  188. ; COMMENT .....
  189. ;
  190. ;===============================================================================
  191.  
  192. cProc        WNetGetConnection, <FAR, PUBLIC>, <si,di>
  193.  
  194.     parmD    lpLocal
  195.     parmD    lpRemote
  196.     parmD    lpcbBuffer
  197.  
  198.     localV    szFind,16
  199.     localV    szLocal,16
  200.     localV    szRemote,128
  201.     localW    iEntry
  202.     localW    iStatus
  203.  
  204. cBegin
  205.     cCall    lstrlen,<lpLocal>    ; check for length too long
  206.     cmp    ax, 16
  207.     jle    @F
  208.     jmp    wngc_badname
  209.  
  210. @@:
  211.     push    ax            ; save length
  212.     lea    si,szFind
  213.     cCall    lstrcpy,<RegPairSSSI,lpLocal>
  214.     pop    ax            ; restore
  215.     cmp    ax,2                ; HACK: Is this a Drive?
  216.     je    wngc_nocolon            ; Yup, leave the colon on
  217.     add    si,ax                ; Nope, this is an LPT port
  218.     dec    si                ; Strip off the trailing colon
  219.     cmp    byte ptr ss:[si],':'
  220.     jnz    wngc_nocolon
  221.     mov    byte ptr ss:[si],0
  222. wngc_nocolon:
  223.     mov    ax,ss
  224.     mov    ds,ax
  225.     mov    es,ax
  226.     lea    si,szLocal
  227.     lea    di,szRemote
  228.     mov    iEntry,0
  229.  
  230.     RegPtr    szLoc,ss,si
  231.     RegPtr  szRem,ss,di
  232.  
  233. wngc_loop:
  234.     mov    ax,5F02h
  235.     mov    bx,iEntry
  236.     inc    iEntry
  237.     push    bp
  238.     call    dos3call
  239.     pop    bp
  240.     jc    wngc_notfound
  241.  
  242.     mov    iStatus, WN_SUCCESS
  243.     test    bh,1        ; is the device valid
  244.     jz    @F
  245.     mov    iStatus, WN_DEVICE_ERROR
  246. @@:
  247.  
  248.     push    es        ; Save ES
  249.  
  250.     lea    bx,szFind
  251.     cCall    lstrcmpi,<szLoc,RegPairSSBX>
  252.  
  253.     pop    es        ; Restore ES
  254.  
  255.     or    ax,ax
  256.     jnz    wngc_loop
  257.  
  258.     cCall    lstrlen,<szRem>
  259.     inc    ax        ; account for NULL
  260.  
  261.     les    bx,lpcbBuffer    ; get size of caller's buffer
  262.     cmp    ax,es:[bx]    ; is it smaller than we need?
  263.     ja    wngc_too_small    ; go deal with that mess
  264.     mov    es:[bx],ax    ; else tell him how much we used
  265.     mov    cx,ax
  266.     mov    ax,iStatus    ; indicate success or drive error
  267.     jmp    short wngc_copy
  268.  
  269. wngc_badname:
  270.     mov    ax,WN_BAD_NETNAME
  271.     jmp    short wngc_exit
  272.  
  273. wngc_notfound:
  274.     mov    ax,WN_NOT_CONNECTED
  275.     jmp    short wngc_exit
  276.  
  277. wngc_too_small:
  278.     mov    cx,es:[bx]      
  279.         mov     es:[bx],ax      ; indicate the required buffer size
  280.     mov    ax,WN_MORE_DATA    ; indicate buffer is too small
  281.         jcxz    wngc_exit       ; check for null length buffer.
  282.  
  283. wngc_copy:
  284.     dec    cx        ; account for null
  285.     les    di,lpRemote    ; point to user's destination
  286.     lea    si,szRemote
  287.     rep    movsb        ; blast the string
  288.     mov    byte ptr es:[di],0     ; null terminate in all cases
  289.  
  290. wngc_exit:
  291. cEnd
  292.  
  293. ;===============================================================================
  294. ; ============= END OF WNETCONS ================================================
  295. ;===============================================================================
  296.  
  297. sEnd        CONSCODE
  298.         end
  299.