📄 httpc.asm
字号:
no_nbsp:
cmp al,13
jne no_lb
jmp byte_done
no_lb:
cmp al,10
jne no_lf
jmp byte_done
no_lf:
mov ebx,[pagey]
imul ebx,[pagexs]
add ebx,[pagex]
add ebx,0x20000
and eax,0xff
cmp eax,31
jbe byte_done
cmp [lastletter],al
jne letter_ok
cmp al,' '
je byte_done
letter_ok:
mov [ebx],al
mov dl,[text_type]
mov [ebx+0x10000],dl
mov [pageyinc],0
mov [lastletter],al
inc [pagex]
mov ebx,[pagex]
cmp ebx,[pagexs]
jb byte_done
mov [pagex],0
inc [pagey]
jmp byte_done
no_print:
; HTML -COMMAND
mov ax,[esi+0x10000] ; b> bold
cmp ax,'b>'
jne no_bold_start
mov [text_type],2
no_bold_start:
mov eax,[esi+0x10000] ; /b bold end
cmp eax,'</b>'
jne no_bold_end
mov [text_type],1
add esi,2
no_bold_end:
mov ax,[esi+0x10000] ; <a
cmp ax,'a '
jne no_link_start
mov [text_type],128
add esi,2
no_link_start:
mov ax,[esi+0x10000] ; /a
cmp ax,'/a'
jne no_link_end2
mov [text_type],1
add esi,0
no_link_end2:
mov ax,[esi+0x10000]
cmp ax,'br'
jne no_br
call linefeed
inc esi
no_br:
mov ax,[esi+0x10000]
cmp ax,'td'
jne no_td
call linefeed
inc esi
no_td:
mov eax,[esi+0x10000]
cmp eax,'tabl'
jne no_table
call linefeed
add esi,3
no_table:
byte_done:
inc esi
cmp esi,[pos]
jbe newbyte
mov [display_from],0
call display_page
popa
ret
;****************************************************************************
; Function
; linefeed
;
; Description
;
;
;****************************************************************************
linefeed:
cmp [pageyinc],2
jge nolf
mov [pagex],0
inc [pagey]
inc [pageyinc]
nolf:
ret
;****************************************************************************
; Function
; display_page
;
; Description
; Renders the text decoded by draw_page
;
;****************************************************************************
display_page:
pusha
mov eax,0
mov ebx,0
newpxy:
push eax
push ebx
mov eax,13 ; background for letter
mov ebx,[esp+4]
imul ebx,6
add ebx,[dpx]
shl ebx,16
add ebx,6
mov ecx,[esp+0]
imul ecx,10
add ecx,[dpy]
shl ecx,16
add ecx,10
mov edx,0xffffff
int 0x40
mov eax,4
mov ebx,[esp+4]
imul ebx,6
add ebx,[dpx]
shl ebx,16
mov bx,[esp+0]
imul bx,10
add bx,word [dpy]
mov esi,[esp]
imul esi,[pagexs]
add esi,[esp+4]
mov edx,[display_from]
imul edx,[pagexs]
add edx,0x20000
add edx,esi
movzx ecx,byte [edx+0x10000]
cmp ecx,1
jne noecx1
mov ecx,0x000000
noecx1:
movzx ecx,byte [edx+0x10000]
cmp ecx,2
jne noecx2
mov ecx,0xff0000
noecx2:
cmp ecx,128
jne noecx128
mov ecx,0x0000ff
noecx128:
mov esi,1
int 0x40
pop ebx
pop eax
inc eax
cmp eax,[pagexs]
jb newpxy
mov eax,0
inc ebx
cmp ebx,30
jb newpxy
popa
ret
;****************************************************************************
; Function
; socket_commands
;
; Description
; opens or closes the socket
;
;****************************************************************************
socket_commands:
cmp ah,22 ; open socket
jnz tst3
; Clear all page memory
mov edi,0x10000
mov ecx,0x30000
mov al,0
cld
rep stosb
; Parse the entered url
call parse_url
; Get a free port number
mov ecx, 1000 ; local port starting at 1000
getlp1:
inc ecx
push ecx
mov eax, 53
mov ebx, 9
int 0x40
pop ecx
cmp eax, 0 ; is this local port in use?
jz getlp1 ; yes - so try next
mov eax,53
mov ebx,5
mov edx,80
mov esi,dword [server_ip]
mov edi,1
int 0x40
mov [socket], eax
mov [pos],0
mov [pagex],0
mov [pagey],0
mov [pagexs],80
mov [command_on_off],0
ret
tst3:
cmp ah,24 ; close socket
jnz no_24
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
call draw_page
ret
no_24:
ret
;****************************************************************************
; Function
; parse_url
;
; Description
; parses the full url typed in by the user into a web address ( that
; can be turned into an IP address by DNS ) and the page to display
; DNS will be used to translate the web address into an IP address, if
; needed.
; url is at document_user and will be space terminated.
; web address goes to webAddr and is space terminated.
; ip address goes to server_ip
; page goes to document and is space terminated.
;
; Supported formats:
; <protocol://>address<page>
; <protocol> is optional, removed and ignored - only http supported
; <address> is required. It can be an ip address or web address
; <page> is optional and must start with a leading / character
;
;****************************************************************************
parse_url:
; First, reset destination variables
cld
mov al, ' '
mov edi, document
mov ecx,URLMAXLEN
rep stosb
mov edi, webAddr
mov ecx,URLMAXLEN
rep stosb
mov al, '/'
mov [document], al
mov esi, document_user
; remove any leading protocol text
mov ecx, URLMAXLEN
mov ax, '//'
pu_000:
cmp [esi], byte ' ' ; end of text?
je pu_002 ; yep, so not found
cmp word [esi], ax
je pu_001 ; Found it, so esi+2 is start
inc esi
loop pu_000
pu_002:
; not found, so reset esi to start
mov esi, document_user -2
pu_001:
add esi, 2
mov ebx, esi ; save address of start of web address
mov edi, document_user + URLMAXLEN ; end of string
; look for page delimiter - it's a '/' character
pu_003:
cmp [esi], byte ' ' ; end of text?
je pu_004 ; yep, so none found
cmp esi, edi ; end of string?
je pu_004 ; yep, so none found
cmp [esi], byte '/' ; delimiter?
je pu_005 ; yep - process it
inc esi
jmp pu_003
pu_005:
; copy page to document address
; esi = delimiter
push esi
inc esi
mov ecx, edi ; end of document_user
mov edi, document
cld
pu_006:
movsb
cmp esi, ecx
je pu_007 ; end of string?
cmp [esi], byte ' ' ; end of text
je pu_007
jmp pu_006
pu_007:
pop esi ; point esi to '/' delimiter
pu_004:
; copy web address to webAddr
; start in ebx, end in esi-1
mov ecx, esi
mov esi, ebx
mov edi, webAddr
cld
pu_008:
movsb
cmp esi, ecx
je pu_009
jmp pu_008
pu_009:
; For debugging, display resulting strings
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, document_user
call debug_print_string
mov esi, webAddr
call debug_print_string
mov esi, document
call debug_print_string
end if
; Look up the ip address, or was it specified?
mov al, [webAddr]
cmp al, '0'
jb pu_010 ; Resolve address
cmp al, '9'
ja pu_010 ; Resolve address
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str2 ; print gotip
call debug_print_string
end if
; Convert address
mov esi,webAddr-1
mov edi,server_ip
xor eax,eax
ip1:
inc esi
cmp [esi],byte '0'
jb ip2
cmp [esi],byte '9'
jg ip2
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip1
ip2:
mov [edi],al
xor eax,eax
inc edi
cmp edi,server_ip+3
jbe ip1
jmp pu_011
pu_010:
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str1 ; print resolving
call debug_print_string
end if
; Resolve Address
call translateData ; Convert domain & DNS IP address
call resolveDomain ; get ip address
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str3
call debug_print_string
end if
pu_011:
; Done
ret
;***************************************************************************
; Function
; translateData
;
; Description
; Coverts the domain name and DNS IP address typed in by the user into
; a format suitable for the IP layer.
;
; The ename, in query, is converted and stored in dnsMsg
;
;***************************************************************************
translateData:
; first, get the IP address of the DNS server
; Then, build up the request string.
; Build the request string
mov eax, 0x00010100
mov [dnsMsg], eax
mov eax, 0x00000100
mov [dnsMsg+4], eax
mov eax, 0x00000000
mov [dnsMsg+8], eax
; domain name goes in at dnsMsg+12
mov esi, dnsMsg + 12 ; location of label length
mov edi, dnsMsg + 13 ; label start
mov edx, webAddr
mov ecx, 12 ; total string length so far
td002:
mov [esi], byte 0
inc ecx
td0021:
mov al, [edx]
cmp al, ' '
je td001 ; we have finished the string translation
cmp al, '.' ; we have finished the label
je td004
inc byte [esi]
inc ecx
mov [edi], al
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -