home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. CD ROM (Annual Premium Edition)
/
premium.zip
/
premium
/
IBMOS2_2
/
MAILMIND.ZIP
/
NETFMIND.ASM
< prev
next >
Wrap
Assembly Source File
|
1992-03-11
|
18KB
|
521 lines
TITLE NETFMIND.ASM -- TSR to check for mail with file read for names
;Thomas A. Marciniak, M.D. = ytm@nihccpc1.bitnet
;Division of Cancer Prevention & Control, NCI
;Revision history:
;1.00 ytm 02/19/92 first release
;Program notes:
;This program uses the Tesseract TSR assembler object modules.
;Three command line parameters are supported: The first is the path of
;the mail directories (default L:\); the second is the path of
;the ini file (default NETFMIND.INI); and the third is the delay between
;each user check in ticks (default 1100 = 1 minute). The ini file must
;be similar in format to the MBXS mailbox file: the first line will be ignored
;and subsequent lines have the directory numbers and user names as follows:
;004425070950 - This first line is skipped!
;0 Admin:NCIDCPC1:NIH
;82 John Doe:NCIDCPC1:NIH
;A leading ';' indicates a remark. The domain and organization are not
;needed. The name must be a workstation netbios name. If that is different
;than the 3+Mail name (as it is in DCPC), the MBXS file can not be used--
;you must make a similar file with the workstation netbios names.
PAGE 60,80
LOCALS
.MODEL tiny
INCLUDE NETBIOS.INC
;equates
DELAY EQU 110 ;1100 = 1 minute
USER_NUM EQU 4 ;NETBIOS number for send message
MAXARRAY EQU 4096 ;maximum size for user ids
BUFSIZE EQU 128 ;ini file read buffer size
VIDEO_SEG EQU 0b800h ;for test purposes only
;macro to display a variable on the screen for test purposes
PUTVAR MACRO var, start, len
IFDEF TEST
push si
push ax
push cx
mov si, OFFSET var
mov ax, start
mov cl, len
call PutMsg
pop cx
pop ax
pop si
ENDIF
ENDM
;structure
FBUF STRUC
caRes DB 21 DUP (?)
cAttr DB ?
iTime DW ?
iDate DW ?
lSize DD ?
caName DB 13 DUP (?)
FBUF ENDS
;external refererences
EXTRN TSDOINIT:NEAR
EXTRN TSCHECKRESIDENT:NEAR
EXTRN TSSETSTACK:NEAR
.CODE
;globals
igCount DW DELAY ;delay counter
igDelay DW DELAY ;delay value
igDo DW 0 ;do background flag
igUser DW OFFSET cgaUser ;offset of current pos in user array
cgaMailPath DB 'L:\', 20 DUP (0) ;mail directory path
sgMail DW OFFSET cgaMailPath + 3 ;offset of variable part of mail path
cgaMsg DB 'M',0 ;message to be sent
igTSR DW 0 ;ID number
cgaTSR DB 'NETFMIND' ;Identification string
gNcb NCB_STRUC <> ;netbios control block
gFFBlk FBUF <> ;find_first buffer
;TesSeRact Entry Points
PUBLIC TSRUSERPROC, TSRTIMERPROC, TSRBACKCHECK, TSRMAIN, TSRBACKPROC
PUBLIC TSRCLEANUP, TESSBEEP
;NULL procedures
TSRUSERPROC:
TSRMAIN:
TSRCLEANUP:
TESSBEEP:
ret
IFDEF TEST
;put a message to screen - call with string pointed to by si,
;displacement in ax, count in cl
PUBLIC PutMsg
PutMsg PROC NEAR
ASSUME cs:_TEXT, ds:_TEXT
push es
push di
shl ax, 1
mov di, ax
mov ax, VIDEO_SEG
mov es, ax ;video seg pointer
@@PutMsgC:
mov al, BYTE PTR [si]
mov BYTE PTR es:[di], al
inc si
inc di
inc di
dec cl
jnz SHORT @@PutMsgC
pop di
pop es
PutMsg ENDP
ENDIF
TSRBACKCHECK PROC NEAR
ASSUME cs:_TEXT, ds:_TEXT
mov ax, [igDo]
ret
TSRBACKCHECK ENDP
TSRBACKPROC PROC NEAR
ASSUME cs:_TEXT, ds:_TEXT
push bx ;save registers
push cx
push dx
push es
push di
push si
mov [igDo], 0 ;reset do flag
mov ax, [igDelay] ;reset delay count
mov [igCount], ax
mov si, [igUser] ;check User.MailDir
cmp BYTE PTR [si], 0 ;if null, reset user pointer to
jne SHORT @@SetMailPath ; cgaUser
mov si, OFFSET cgaUser
mov [igUser], si
@@SetMailPath: ;copy User.MailDir to mail path
mov di, [sgMail]
jmp SHORT @@CheckDirEnd
@@SetDirC: ;transfer byte & increment pointers
mov al, BYTE PTR [si]
mov BYTE PTR [di], al
inc si
inc di
@@CheckDirEnd:
cmp BYTE PTR [si], 0 ;check for terminating 0
jne SHORT @@SetDirC ;loop if not done
inc si ;skip 0
push si ;save user ptr
mov BYTE PTR [di], '\' ;finish mail path search template
inc di
mov BYTE PTR [di], '*'
inc di
mov BYTE PTR [di], '.'
inc di
mov BYTE PTR [di], '*'
inc di
mov BYTE PTR [di], 0
mov ah, 2fh ;get & save old DTA
int 21h
push ds ;save data segment
push es ;save old DTA address
push bx
mov dx, OFFSET gFFBlk ;set DTA to gFFBlk
mov ah, 1ah
int 21h
mov dx, OFFSET cgaMailPath ;set up search
xor cx, cx ;normal attribute
mov ah, 4eh ;find first
int 21h
pop dx ;retrieve old DTA address
pop ds
push ax ;save find first result
mov ah, 1ah ;restore old DTA
int 21h
pop ax ;retrieve find first result
pop ds ;retrieve data seg
pop si ;retrieve user ptr
or ax, ax ;check find first result
jz SHORT @@SendMsg ;if 0, send message
jmp SHORT @@CheckEndU ;else, skip over user id
@@IncU:
inc si
@@CheckEndU:
cmp BYTE PTR [si], 0
jne SHORT @@IncU
push si ;save user ptr
jmp SHORT @@Exit ; & exit
@@SendMsg: ;send a message
mov bx, ds ;zero gNcb
mov es, bx
mov di, OFFSET gNcb
mov cx, 32 ;Ncb length in words
xor ax, ax
cld
rep stosw
mov di, OFFSET gNcb.NCB_CALLNAME ;move to NCB_CALLNAME
jmp SHORT @@ChkInitials
@@PutCallNameC:
mov al, BYTE PTR [si]
mov BYTE PTR [di], al
inc di
inc si
@@ChkInitials:
cmp BYTE PTR [si], 0
jne SHORT @@PutCallNameC
push si ;save user ptr
jmp SHORT @@ChkNameEnd
@@BlankC:
mov BYTE PTR [di], ' ' ;blank fill CALLNAME
inc di
@@ChkNameEnd:
cmp di, OFFSET gNcb.NCB_NAME - 1
jb SHORT @@BlankC
mov BYTE PTR [gNcb.NCB_COMMAND], SEND_DATAGRAM ;setup rest of gNcb
mov BYTE PTR [gNcb.NCB_NUM], USER_NUM
mov WORD PTR [gNcb.NCB_LENGTH], 1
mov WORD PTR [gNcb.NCB_BUF_OFF], OFFSET cgaMsg
mov WORD PTR [gNcb.NCB_BUF_SEG], ds
mov BYTE PTR [gNcb.NCB_CMD_CPLT], 0ffh ;0ffh = not completed
mov ax, ds
mov es, ax
mov bx, OFFSET gNcb
mov ax, 100h
IFNDEF TEST
int 05ch ;NETBIOS call
ENDIF
@@Exit:
pop ax ;retrieve user ptr
inc ax ;skip 0
mov [igUser], ax ;and resave
pop si ;restore registers
pop di
pop es
pop dx
pop cx
pop bx
ret
TSRBACKPROC ENDP
TSRTIMERPROC PROC NEAR
ASSUME cs:_TEXT, ds:_TEXT
cmp [igCount], 0
je SHORT @@SetDo
dec [igCount]
jmp SHORT @@Exit
@@SetDo:
mov [igDo], 1
@@Exit:
ret
TSRTIMERPROC ENDP
;TSR stack
PUBLIC TsrStack
PUBLIC TopStack
TsrStack DB 256 dup (0) ;stack to use
TopStack EQU this byte
;User array
cgaUser DB MAXARRAY dup (0) ;maximum size for user array
PUBLIC TESSINITSTART ;required entry point
TESSINITSTART:
ASSUME cs:_TEXT, ds:_TEXT
mov dx, OFFSET caVersion
mov ah, 09
int 21h ;display the logo
mov si, OFFSET cgaTSR
mov di, OFFSET igTSR
call TSCHECKRESIDENT
or ax, ax
jz SHORT @@GetParams
mov dx, OFFSET caBefore ;already installed
@@Terminate:
mov ah, 09
int 21h ;display message
mov ax, 4c01h
int 21h ;and exit with error code
@@GetParams:
call GetParameters ;get command line parameters
call GetIni ;read ini file
jc SHORT @@Terminate
@@GoTsr:
IFDEF TEST
mov dx, OFFSET caTSRFailed
jmp SHORT @@Terminate
ENDIF
push di ;save user top
mov di, OFFSET TopStack ;set TSR stack
dec di
dec di
mov si, di
call TSSETSTACK
mov dx, OFFSET caInstalled
mov ah, 09
int 21h
pop dx ;retrieve top of user for TSR
mov bx, 1060h ;no pop graphics, background & timer
xor ax, ax ;no hotkey!
dec ax ;no hotkey is -1
call TSDOINIT
mov dx, OFFSET caTSRFailed
jmp SHORT @@Terminate
;read the ini file, return with no carry and di pointing to top of user
;if successful, carry set and dx pointing to error message if unsuccessful
GetIni:
mov dx, OFFSET caBuf
mov ax, 3d00h ;open file
int 21h
jnc SHORT @@ReadIni
mov dx, OFFSET caNoIni
ret
@@ReadIni:
mov bx, ax ;file handle in BX
mov cx, BUFSIZE ;bytes to read
mov si, OFFSET caBuf ;pointer for @@GetC
mov di, OFFSET cgaUser ;user pointer in DI
mov BYTE PTR [si], 0 ;force 1st read
call @@SkipLine ;skip 1st line
jc SHORT @@ExitErr
@@ReadLoop:
call @@GetC ;get a character
jc SHORT @@ExitErr
jz SHORT @@Exit ;exit if 0
cmp al, ';' ;skip line if ;
jne SHORT @@SaveLoc
@@SkipL:
call @@SkipLine
jc SHORT @@ExitErr
jmp SHORT @@ReadLoop
@@SaveLoc:
mov [iUserLoc], di ;save current user loc
@@Chk1: ;check the 1st parameter = user dir
cmp al, ' ' ;stop getting at first blank
je SHORT @@End1
cmp al, 0dh ;if CR, restore old user loc
je SHORT @@SkipUser
mov BYTE PTR [di], al
inc di
call @@GetC
jc SHORT @@ExitErr
jz SHORT @@Exit
jmp SHORT @@Chk1
@@SkipUser: ;skip this user
mov di, [iUserLoc]
jmp SHORT @@ReadLoop
@@End1:
mov BYTE PTR [di], 0 ;write delimiting 0
inc di
@@Get2: ;get 2nd parameter = user id
call @@GetC
jc SHORT @@ExitErr
jz SHORT @@Exit
cmp al, ':' ;skip rest of line if :
je SHORT @@SkipDomain
cmp al, 0dh ;finish if CR
je SHORT @@End2
mov BYTE PTR [di], al
inc di
jmp SHORT @@Get2
@@SkipDomain: ;skip domain (line after :)
call @@SkipLine
jc SHORT @@ExitErr
jz SHORT @@Exit
@@End2:
mov BYTE PTR [di], 0 ;add terminating 0
inc di
jmp SHORT @@ReadLoop
@@Exit:
mov BYTE PTR [di], 0 ;force two nulls at end
inc di
mov BYTE PTR [di], 0
inc di
mov ah, 3Eh ;close file
int 21h
@@ExitErr:
mov dx, OFFSET caReadErr
ret
;get a character in al, return 0 with zero set if EOF
;skip linefeeds
;error exit with carry if read error
;before the first call, the following registers must have be initialized:
;bx to file handle, cx to BUFSIZE, dx and si to OFFSET caBuf
;update si, buffer source pointer
@@GetC:
cmp BYTE PTR [si], 0
jne SHORT @@CheckEOF
mov ah, 3fh ;read file
int 21h
jnc SHORT @@SetSentinel
ret ;exit on carry
@@SetSentinel:
add cx, dx ;add buffer offset to byte count
mov si, cx
mov BYTE PTR [si], 0 ;set sentinel
mov si, dx ;reset source ptr to buffer start
@@CheckEOF:
mov al, BYTE PTR [si] ;get byte
or al, al
jz SHORT @@ExitGetC ;exit if 0
inc si ;increment source ptr if not 0
cmp al, 0ah ;skip line feeds
je SHORT @@GetC
cmp al, 1ah ;check for CTLZ
jne SHORT @@ExitGetC
mov al, 0 ;convert CTLZ to 0
@@ExitGetC:
or al, al ;affect zero and reset carry flags
ret
;skip the rest of the line
@@SkipLine:
call @@GetC
jc SHORT @@ExitSkip
jz SHORT @@ExitSkip
cmp al, 0dh
jne SHORT @@SkipLine
@@ExitSkip:
ret
;get the command line parameters in globals (no register returns)
GetParameters:
mov si, 80h ;OFFSET of command line
cmp BYTE PTR [si], 0 ;check for end
je SHORT @@Done ;no command line
inc si ;skip count
inc si ;skip blank
mov di, OFFSET cgaMailPath - 1
jmp SHORT @@CheckPathEnd
@@SetPathC:
inc di ;increment pointers
inc si
mov BYTE PTR [di], al ;save character
@@CheckPathEnd:
mov al, BYTE PTR [si] ;get a character
cmp al, 13 ;check for end
je SHORT @@CheckSlash
cmp al, ' '
jne SHORT @@SetPathC ;loop if not end
@@CheckSlash:
cmp BYTE PTR [di], '\'
je SHORT @@EndPath
inc di
mov BYTE PTR [di], '\'
@@EndPath:
inc di
mov [sgMail], di ;set sgMail (start of name)
cmp al, 13 ;check for end
jne SHORT @@GetIni
@@Done:
ret ;exit for SHORT jumps
@@GetIni:
inc si ;skip blank
mov di, OFFSET caBuf
jmp SHORT @@CheckIniEnd
@@SetIniC:
mov BYTE PTR [di], al ;save character
inc di ;increment pointers
inc si
@@CheckIniEnd:
mov al, BYTE PTR [si] ;get a character
cmp al, 13 ;check for end
je SHORT @@EndIni
cmp al, ' '
jne SHORT @@SetIniC ;loop if not end
@@EndIni:
mov BYTE PTR [di], 0 ;set terminating 0
cmp al, 13 ;check for end
je SHORT @@Done
inc si ;skip blank
xor ax, ax ;clear accumulator
jmp SHORT @@CheckDelayEnd
@@SetDelayC:
mov bx, ax ;multiply ax by 10
shl ax, 1
shl ax, 1
shl ax, 1
add ax, bx
add ax, bx
mov bl, BYTE PTR [si]
mov bh, 0
add ax, bx ;add character
sub ax, '0' ;subtract ASCII offset
inc si
@@CheckDelayEnd:
cmp BYTE PTR [si], 13 ;check for end
jne SHORT @@SetDelayC ;loop if not end
@@EndDelay:
mov [igDelay], ax ;save delay count
ret
;read buffer
caBuf DB 'NETFMIND.INI', (BUFSIZE - 12) DUP (0)
DB 0 ;buffer sentinel
iUserLoc DW OFFSET cgaUser ;temp loc for user
;messages
caBefore LABEL BYTE
DB 'already installed',7,13,10,'$'
caNoIni LABEL BYTE
DB 'INI file not found',7,13,10,'$'
caReadErr LABEL BYTE
DB 'error reading INI file',7,13,10,'$'
caTSRFailed LABEL BYTE
DB 'tsr failed',7,13,10,'$'
caVersion LABEL BYTE
DB 13,10,'NETFMIND.COM v1.00 - ','$'
caInstalled LABEL BYTE
DB 'installed',13,10,'$'
_TEXT ENDS
END