home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / MAILMIND.ZOO / NETFMIND.ASM < prev    next >
Assembly Source File  |  1992-03-11  |  18KB  |  521 lines

  1.  TITLE NETFMIND.ASM --  TSR to check for mail with file read for names
  2. ;Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
  3. ;Division of Cancer Prevention & Control, NCI
  4.  
  5. ;Revision history:
  6. ;1.00  ytm  02/19/92  first release
  7.  
  8. ;Program notes:
  9. ;This program uses the Tesseract TSR assembler object modules.
  10. ;Three command line parameters are supported:  The first is the path of
  11. ;the mail directories (default L:\);  the second is the path of
  12. ;the ini file (default NETFMIND.INI);  and the third is the delay between
  13. ;each user check in ticks (default 1100 = 1 minute).  The ini file must
  14. ;be similar in format to the MBXS mailbox file: the first line will be ignored
  15. ;and subsequent lines have the directory numbers and user names as follows:
  16. ;004425070950 - This first line is skipped!
  17. ;0 Admin:NCIDCPC1:NIH
  18. ;82 John Doe:NCIDCPC1:NIH
  19. ;A leading ';' indicates a remark.  The domain and organization are not
  20. ;needed.  The name must be a workstation netbios name.  If that is different
  21. ;than the 3+Mail name (as it is in DCPC), the MBXS file can not be used--
  22. ;you must make a similar file with the workstation netbios names.
  23.  
  24.  PAGE 60,80
  25.  LOCALS
  26. .MODEL tiny
  27.  
  28.  INCLUDE NETBIOS.INC
  29.  
  30. ;equates
  31. DELAY         EQU 110                   ;1100 = 1 minute
  32. USER_NUM      EQU 4                     ;NETBIOS number for send message
  33. MAXARRAY      EQU 4096                  ;maximum size for user ids
  34. BUFSIZE       EQU 128                   ;ini file read buffer size
  35. VIDEO_SEG     EQU 0b800h                ;for test purposes only
  36.  
  37. ;macro to display a variable on the screen for test purposes
  38. PUTVAR  MACRO var, start, len
  39. IFDEF TEST
  40.         push    si
  41.         push    ax
  42.         push    cx
  43.         mov     si, OFFSET var
  44.         mov     ax, start
  45.         mov     cl, len
  46.         call    PutMsg
  47.         pop     cx
  48.         pop     ax
  49.         pop     si
  50. ENDIF
  51. ENDM
  52.  
  53. ;structure
  54. FBUF STRUC
  55. caRes    DB  21 DUP (?)
  56. cAttr    DB  ?
  57. iTime    DW  ?
  58. iDate    DW  ?
  59. lSize    DD  ?
  60. caName   DB  13 DUP (?)
  61. FBUF ENDS
  62.  
  63. ;external refererences
  64. EXTRN TSDOINIT:NEAR
  65. EXTRN TSCHECKRESIDENT:NEAR
  66. EXTRN TSSETSTACK:NEAR
  67.  
  68. .CODE
  69.  
  70. ;globals
  71. igCount      DW DELAY                   ;delay counter
  72. igDelay      DW DELAY                   ;delay value
  73. igDo         DW 0                       ;do background flag
  74. igUser       DW OFFSET cgaUser          ;offset of current pos in user array
  75. cgaMailPath  DB 'L:\', 20 DUP (0)       ;mail directory path
  76. sgMail       DW OFFSET cgaMailPath + 3  ;offset of variable part of mail path
  77. cgaMsg       DB 'M',0                   ;message to be sent
  78. igTSR        DW 0                       ;ID number
  79. cgaTSR       DB 'NETFMIND'              ;Identification string
  80. gNcb         NCB_STRUC <>               ;netbios control block
  81. gFFBlk       FBUF <>                    ;find_first buffer
  82.  
  83. ;TesSeRact Entry Points
  84. PUBLIC  TSRUSERPROC, TSRTIMERPROC, TSRBACKCHECK, TSRMAIN, TSRBACKPROC
  85. PUBLIC  TSRCLEANUP, TESSBEEP
  86.  
  87. ;NULL procedures
  88. TSRUSERPROC:
  89. TSRMAIN:
  90. TSRCLEANUP:
  91. TESSBEEP:
  92.         ret
  93.  
  94. IFDEF TEST
  95. ;put a message to screen - call with string pointed to by si,
  96. ;displacement in ax, count in cl
  97. PUBLIC PutMsg
  98. PutMsg PROC NEAR
  99.         ASSUME cs:_TEXT, ds:_TEXT
  100.         push    es
  101.         push    di
  102.         shl     ax, 1
  103.         mov     di, ax
  104.     mov    ax, VIDEO_SEG
  105.     mov    es, ax                  ;video seg pointer
  106. @@PutMsgC:
  107.         mov     al, BYTE PTR [si]
  108.         mov     BYTE PTR es:[di], al
  109.         inc     si
  110.         inc     di
  111.         inc     di
  112.         dec     cl
  113.         jnz     SHORT @@PutMsgC
  114.         pop     di
  115.         pop     es
  116. PutMsg ENDP
  117. ENDIF
  118.  
  119. TSRBACKCHECK PROC NEAR
  120.         ASSUME cs:_TEXT, ds:_TEXT
  121.         mov     ax, [igDo]
  122.         ret
  123. TSRBACKCHECK ENDP
  124.  
  125. TSRBACKPROC PROC NEAR
  126.         ASSUME cs:_TEXT, ds:_TEXT
  127.         push    bx                      ;save registers
  128.         push    cx
  129.         push    dx
  130.         push    es
  131.         push    di
  132.         push    si
  133.         mov  [igDo], 0                  ;reset do flag
  134.         mov  ax, [igDelay]              ;reset delay count
  135.         mov  [igCount], ax
  136.         mov  si, [igUser]               ;check User.MailDir
  137.         cmp     BYTE PTR [si], 0        ;if null, reset user pointer to
  138.         jne     SHORT @@SetMailPath     ;  cgaUser
  139.         mov     si, OFFSET cgaUser
  140.         mov     [igUser], si
  141. @@SetMailPath:                          ;copy User.MailDir to mail path
  142.         mov     di, [sgMail]
  143.         jmp     SHORT @@CheckDirEnd
  144. @@SetDirC:                              ;transfer byte & increment pointers
  145.         mov     al, BYTE PTR [si]
  146.         mov     BYTE PTR [di], al
  147.         inc     si
  148.         inc     di
  149. @@CheckDirEnd:
  150.         cmp     BYTE PTR [si], 0        ;check for terminating 0
  151.         jne     SHORT @@SetDirC         ;loop if not done
  152.         inc     si                      ;skip 0
  153.         push    si                      ;save user ptr
  154.         mov     BYTE PTR [di], '\'      ;finish mail path search template
  155.         inc     di
  156.         mov     BYTE PTR [di], '*'
  157.         inc     di
  158.         mov     BYTE PTR [di], '.'
  159.         inc     di
  160.         mov     BYTE PTR [di], '*'
  161.         inc     di
  162.         mov     BYTE PTR [di], 0
  163.         mov     ah, 2fh                 ;get & save old DTA
  164.         int     21h
  165.         push    ds                      ;save data segment
  166.         push    es                      ;save old DTA address
  167.         push    bx
  168.         mov     dx, OFFSET gFFBlk       ;set DTA to gFFBlk
  169.         mov     ah, 1ah
  170.         int     21h
  171.         mov     dx, OFFSET cgaMailPath  ;set up search
  172.         xor     cx, cx                  ;normal attribute
  173.         mov     ah, 4eh                 ;find first
  174.         int     21h
  175.         pop     dx                      ;retrieve old DTA address
  176.         pop     ds
  177.         push    ax                      ;save find first result
  178.         mov     ah, 1ah                 ;restore old DTA
  179.         int     21h
  180.         pop     ax                      ;retrieve find first result
  181.         pop     ds                      ;retrieve data seg
  182.         pop     si                      ;retrieve user ptr
  183.         or      ax, ax                  ;check find first result
  184.         jz      SHORT @@SendMsg         ;if 0, send message
  185.         jmp     SHORT @@CheckEndU       ;else, skip over user id
  186. @@IncU:
  187.         inc     si
  188. @@CheckEndU:
  189.         cmp     BYTE PTR [si], 0
  190.         jne     SHORT @@IncU
  191.         push    si                      ;save user ptr
  192.         jmp     SHORT @@Exit            ; & exit
  193. @@SendMsg:                              ;send a message
  194.         mov     bx, ds                  ;zero gNcb
  195.         mov     es, bx
  196.         mov     di, OFFSET gNcb
  197.         mov     cx, 32                  ;Ncb length in words
  198.         xor     ax, ax
  199.         cld
  200.         rep     stosw
  201.         mov     di, OFFSET gNcb.NCB_CALLNAME ;move to NCB_CALLNAME
  202.         jmp     SHORT @@ChkInitials
  203. @@PutCallNameC:
  204.         mov     al, BYTE PTR [si]
  205.         mov     BYTE PTR [di], al
  206.         inc     di
  207.         inc     si
  208. @@ChkInitials:
  209.         cmp     BYTE PTR [si], 0
  210.         jne     SHORT @@PutCallNameC
  211.         push    si                      ;save user ptr
  212.         jmp     SHORT @@ChkNameEnd
  213. @@BlankC:
  214.         mov     BYTE PTR [di], ' '      ;blank fill CALLNAME
  215.         inc     di
  216. @@ChkNameEnd:
  217.         cmp     di, OFFSET gNcb.NCB_NAME - 1
  218.         jb      SHORT @@BlankC
  219.         mov     BYTE PTR [gNcb.NCB_COMMAND], SEND_DATAGRAM ;setup rest of gNcb
  220.         mov     BYTE PTR [gNcb.NCB_NUM], USER_NUM
  221.         mov     WORD PTR [gNcb.NCB_LENGTH], 1
  222.         mov     WORD PTR [gNcb.NCB_BUF_OFF], OFFSET cgaMsg
  223.         mov     WORD PTR [gNcb.NCB_BUF_SEG], ds
  224.         mov     BYTE PTR [gNcb.NCB_CMD_CPLT], 0ffh ;0ffh = not completed
  225.         mov     ax, ds
  226.         mov     es, ax
  227.         mov     bx, OFFSET gNcb
  228.         mov     ax, 100h
  229. IFNDEF TEST
  230.         int     05ch                    ;NETBIOS call
  231. ENDIF
  232. @@Exit:
  233.         pop     ax                      ;retrieve user ptr
  234.         inc     ax                      ;skip 0
  235.         mov     [igUser], ax            ;and resave
  236.         pop     si                      ;restore registers
  237.         pop     di
  238.         pop     es
  239.         pop     dx
  240.         pop     cx
  241.         pop     bx
  242.         ret  
  243. TSRBACKPROC ENDP
  244.  
  245. TSRTIMERPROC PROC NEAR
  246.         ASSUME cs:_TEXT, ds:_TEXT
  247.         cmp     [igCount], 0
  248.         je      SHORT @@SetDo
  249.         dec     [igCount]
  250.         jmp     SHORT @@Exit
  251. @@SetDo:
  252.         mov     [igDo], 1
  253. @@Exit:
  254.         ret  
  255. TSRTIMERPROC ENDP
  256.  
  257. ;TSR stack
  258. PUBLIC TsrStack
  259. PUBLIC TopStack
  260. TsrStack  DB 256 dup (0)                ;stack to use
  261. TopStack  EQU this byte
  262.  
  263. ;User array
  264. cgaUser   DB MAXARRAY dup (0)           ;maximum size for user array
  265.  
  266. PUBLIC TESSINITSTART                    ;required entry point
  267. TESSINITSTART:
  268.         ASSUME cs:_TEXT, ds:_TEXT
  269.         mov     dx, OFFSET caVersion
  270.         mov     ah, 09
  271.         int     21h                     ;display the logo
  272.         mov     si, OFFSET cgaTSR
  273.         mov     di, OFFSET igTSR
  274.         call    TSCHECKRESIDENT
  275.         or      ax, ax
  276.         jz      SHORT @@GetParams
  277.         mov     dx, OFFSET caBefore     ;already installed
  278. @@Terminate:
  279.         mov     ah, 09
  280.         int     21h                     ;display message
  281.         mov     ax, 4c01h
  282.         int     21h                     ;and exit with error code
  283. @@GetParams:
  284.         call    GetParameters           ;get command line parameters
  285.         call    GetIni                  ;read ini file
  286.         jc      SHORT @@Terminate
  287. @@GoTsr:
  288. IFDEF TEST
  289.         mov     dx, OFFSET caTSRFailed
  290.         jmp     SHORT @@Terminate
  291. ENDIF
  292.         push    di                      ;save user top
  293.         mov     di, OFFSET TopStack     ;set TSR stack
  294.         dec     di
  295.         dec     di
  296.         mov     si, di
  297.         call    TSSETSTACK
  298.         mov     dx, OFFSET caInstalled
  299.         mov     ah, 09
  300.         int     21h
  301.         pop     dx                      ;retrieve top of user for TSR
  302.         mov     bx, 1060h               ;no pop graphics, background & timer
  303.         xor     ax, ax                  ;no hotkey!
  304.         dec     ax                      ;no hotkey is -1
  305.         call    TSDOINIT
  306.         mov     dx, OFFSET caTSRFailed
  307.         jmp     SHORT @@Terminate
  308.  
  309. ;read the ini file, return with no carry and di pointing to top of user
  310. ;if successful, carry set and dx pointing to error message if unsuccessful
  311. GetIni:
  312.         mov     dx, OFFSET caBuf
  313.         mov     ax, 3d00h               ;open file
  314.         int     21h
  315.         jnc     SHORT @@ReadIni
  316.         mov     dx, OFFSET caNoIni
  317.         ret
  318. @@ReadIni:
  319.         mov     bx, ax                  ;file handle in BX
  320.         mov     cx, BUFSIZE             ;bytes to read
  321.         mov     si, OFFSET caBuf        ;pointer for @@GetC
  322.         mov     di, OFFSET cgaUser      ;user pointer in DI
  323.         mov     BYTE PTR [si], 0        ;force 1st read
  324.         call    @@SkipLine              ;skip 1st line
  325.         jc      SHORT @@ExitErr
  326. @@ReadLoop:
  327.         call    @@GetC                  ;get a character
  328.         jc      SHORT @@ExitErr
  329.         jz      SHORT @@Exit            ;exit if 0
  330.         cmp     al, ';'                 ;skip line if ;
  331.         jne     SHORT @@SaveLoc
  332. @@SkipL:
  333.         call    @@SkipLine
  334.         jc      SHORT @@ExitErr
  335.         jmp     SHORT @@ReadLoop
  336. @@SaveLoc:
  337.         mov     [iUserLoc], di          ;save current user loc
  338. @@Chk1:                                 ;check the 1st parameter = user dir
  339.         cmp     al, ' '                 ;stop getting at first blank
  340.         je      SHORT @@End1
  341.         cmp     al, 0dh                 ;if CR, restore old user loc
  342.         je      SHORT @@SkipUser
  343.         mov     BYTE PTR [di], al
  344.         inc     di
  345.         call    @@GetC
  346.         jc      SHORT @@ExitErr
  347.         jz      SHORT @@Exit
  348.         jmp     SHORT @@Chk1
  349. @@SkipUser:                             ;skip this user
  350.         mov     di, [iUserLoc]
  351.         jmp     SHORT @@ReadLoop
  352. @@End1:
  353.         mov     BYTE PTR [di], 0        ;write delimiting 0
  354.         inc     di
  355. @@Get2:                                 ;get 2nd parameter = user id
  356.         call    @@GetC
  357.         jc      SHORT @@ExitErr
  358.         jz      SHORT @@Exit
  359.         cmp     al, ':'                 ;skip rest of line if :
  360.         je      SHORT @@SkipDomain
  361.         cmp     al, 0dh                 ;finish if CR
  362.         je      SHORT @@End2
  363.         mov     BYTE PTR [di], al
  364.         inc     di
  365.         jmp     SHORT @@Get2
  366. @@SkipDomain:                           ;skip domain (line after :)
  367.         call    @@SkipLine
  368.         jc      SHORT @@ExitErr
  369.         jz      SHORT @@Exit
  370. @@End2:
  371.         mov     BYTE PTR [di], 0        ;add terminating 0
  372.         inc     di
  373.         jmp     SHORT @@ReadLoop
  374. @@Exit:
  375.         mov     BYTE PTR [di], 0        ;force two nulls at end
  376.         inc     di
  377.         mov     BYTE PTR [di], 0
  378.         inc     di
  379.         mov  ah, 3Eh                    ;close file
  380.         int  21h
  381. @@ExitErr:
  382.         mov     dx, OFFSET caReadErr
  383.         ret
  384.  
  385. ;get a character in al, return 0 with zero set if EOF
  386. ;skip linefeeds
  387. ;error exit with carry if read error
  388. ;before the first call, the following registers must have be initialized:
  389. ;bx to file handle, cx to BUFSIZE, dx and si to OFFSET caBuf
  390. ;update si, buffer source pointer
  391. @@GetC:
  392.         cmp     BYTE PTR [si], 0
  393.         jne     SHORT @@CheckEOF
  394.         mov     ah, 3fh                 ;read file
  395.         int     21h
  396.         jnc     SHORT @@SetSentinel
  397.         ret                             ;exit on carry
  398. @@SetSentinel:
  399.         add     cx, dx                  ;add buffer offset to byte count
  400.         mov     si, cx
  401.         mov     BYTE PTR [si], 0        ;set sentinel
  402.         mov     si, dx                  ;reset source ptr to buffer start
  403. @@CheckEOF:
  404.         mov     al, BYTE PTR [si]       ;get byte
  405.         or      al, al                  
  406.         jz      SHORT @@ExitGetC        ;exit if 0
  407.         inc     si                      ;increment source ptr if not 0
  408.         cmp     al, 0ah                 ;skip line feeds
  409.         je      SHORT @@GetC
  410.         cmp     al, 1ah                 ;check for CTLZ
  411.         jne     SHORT @@ExitGetC         
  412.         mov     al, 0                   ;convert CTLZ to 0
  413. @@ExitGetC:
  414.         or      al, al                  ;affect zero and reset carry flags
  415.         ret
  416.         
  417. ;skip the rest of the line
  418. @@SkipLine:
  419.         call    @@GetC
  420.         jc      SHORT @@ExitSkip
  421.         jz      SHORT @@ExitSkip
  422.         cmp     al, 0dh
  423.         jne     SHORT @@SkipLine
  424. @@ExitSkip:
  425.         ret
  426.  
  427. ;get the command line parameters in globals (no register returns)
  428. GetParameters:
  429.         mov     si, 80h                 ;OFFSET of command line
  430.         cmp     BYTE PTR [si], 0        ;check for end
  431.         je      SHORT @@Done            ;no command line
  432.         inc     si                      ;skip count
  433.         inc     si                      ;skip blank
  434.         mov     di, OFFSET cgaMailPath - 1
  435.         jmp     SHORT @@CheckPathEnd
  436. @@SetPathC:
  437.         inc     di                      ;increment pointers
  438.         inc     si
  439.         mov     BYTE PTR [di], al       ;save character
  440. @@CheckPathEnd:
  441.         mov     al, BYTE PTR [si]       ;get a character
  442.         cmp     al, 13                  ;check for end
  443.         je      SHORT @@CheckSlash
  444.         cmp     al, ' '
  445.         jne     SHORT @@SetPathC        ;loop if not end
  446. @@CheckSlash:
  447.         cmp     BYTE PTR [di], '\'
  448.         je      SHORT @@EndPath
  449.         inc     di
  450.         mov     BYTE PTR [di], '\'
  451. @@EndPath:
  452.         inc     di
  453.         mov     [sgMail], di            ;set sgMail (start of name)
  454.         cmp     al, 13                  ;check for end
  455.         jne     SHORT @@GetIni
  456. @@Done:
  457.         ret                             ;exit for SHORT jumps
  458. @@GetIni:
  459.         inc     si                      ;skip blank
  460.         mov     di, OFFSET caBuf
  461.         jmp     SHORT @@CheckIniEnd
  462. @@SetIniC:
  463.         mov     BYTE PTR [di], al       ;save character
  464.         inc     di                      ;increment pointers
  465.         inc     si
  466. @@CheckIniEnd:
  467.         mov     al, BYTE PTR [si]       ;get a character
  468.         cmp     al, 13                  ;check for end
  469.         je      SHORT @@EndIni
  470.         cmp     al, ' '
  471.         jne     SHORT @@SetIniC         ;loop if not end
  472. @@EndIni:
  473.         mov     BYTE PTR [di], 0        ;set terminating 0
  474.         cmp     al, 13                  ;check for end
  475.         je      SHORT @@Done
  476.         inc     si                      ;skip blank
  477.         xor     ax, ax                  ;clear accumulator
  478.         jmp     SHORT @@CheckDelayEnd
  479. @@SetDelayC:
  480.         mov     bx, ax                  ;multiply ax by 10
  481.         shl     ax, 1
  482.         shl     ax, 1
  483.         shl     ax, 1
  484.         add     ax, bx
  485.         add     ax, bx
  486.         mov     bl, BYTE PTR [si]
  487.         mov     bh, 0
  488.         add     ax, bx                  ;add character
  489.         sub     ax, '0'                 ;subtract ASCII offset
  490.         inc     si
  491. @@CheckDelayEnd:
  492.         cmp     BYTE PTR [si], 13       ;check for end
  493.         jne     SHORT @@SetDelayC       ;loop if not end
  494. @@EndDelay:
  495.         mov     [igDelay], ax           ;save delay count
  496.         ret
  497.  
  498. ;read buffer
  499. caBuf   DB      'NETFMIND.INI', (BUFSIZE - 12) DUP (0)
  500.         DB      0                       ;buffer sentinel
  501. iUserLoc DW     OFFSET cgaUser          ;temp loc for user
  502.  
  503. ;messages
  504. caBefore        LABEL   BYTE
  505.         DB      'already installed',7,13,10,'$'
  506. caNoIni         LABEL   BYTE
  507.         DB      'INI file not found',7,13,10,'$'
  508. caReadErr       LABEL   BYTE
  509.         DB      'error reading INI file',7,13,10,'$'
  510. caTSRFailed     LABEL   BYTE
  511.         DB      'tsr failed',7,13,10,'$'
  512. caVersion       LABEL   BYTE
  513.         DB      13,10,'NETFMIND.COM v1.00 - ','$'
  514. caInstalled     LABEL   BYTE
  515.         DB      'installed',13,10,'$'
  516.  
  517. _TEXT ENDS
  518.  
  519.         END
  520.  
  521.