Telnet for net branch: better UI, all threads now automatically exit when console window is closed, application now accepts parameters.

git-svn-id: svn://kolibrios.org@2860 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-07-12 22:50:11 +00:00
parent bd062d9661
commit a6337bc8cd

View File

@ -1,5 +1,23 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2010-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; telnet.asm - Telnet client for KolibriOS ;;
;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format binary as "" format binary as ""
__DEBUG__ equ 0
__DEBUG_LEVEL__ equ 1
BUFFERSIZE equ 4096
use32 use32
; standard header ; standard header
db 'MENUET01' ; signature db 'MENUET01' ; signature
@ -8,21 +26,14 @@ use32
dd i_end ; initialized size dd i_end ; initialized size
dd mem ; required memory dd mem ; required memory
dd mem ; stack pointer dd mem ; stack pointer
dd 0 ; parameters dd s ; parameters
dd 0 ; path dd 0 ; path
__DEBUG__ equ 0
__DEBUG_LEVEL__ equ 1
BUFFERSIZE equ 4096
; useful includes
include '../macros.inc' include '../macros.inc'
purge mov,add,sub purge mov,add,sub
include '../proc32.inc' include '../proc32.inc'
include '../dll.inc' include '../dll.inc'
include '../debug-fdo.inc' include '../debug-fdo.inc'
include '../network.inc' include '../network.inc'
; entry point ; entry point
@ -40,10 +51,17 @@ start:
push 25 push 25
push 80 push 80
call [con_init] call [con_init]
; main loop
; Check for parameters
cmp byte [s], 0
jne resolve
main:
call [con_cls]
; Welcome user
push str1 push str1
call [con_write_asciiz] call [con_write_asciiz]
main:
; write prompt ; write prompt
push str2 push str2
call [con_write_asciiz] call [con_write_asciiz]
@ -57,20 +75,29 @@ main:
jz done jz done
cmp byte [esi], 10 cmp byte [esi], 10
jz done jz done
resolve:
; delete terminating '\n' ; delete terminating '\n'
push esi mov esi, s
@@: @@:
lodsb lodsb
test al, al cmp al, 0x20
jnz @b ja @r
mov byte [esi-2], al mov byte [esi-1], 0
pop esi
call [con_cls]
push str3
call [con_write_asciiz]
push s
call [con_write_asciiz]
; resolve name ; resolve name
push esp ; reserve stack place push esp ; reserve stack place
push esp ; fourth parameter push esp ; fourth parameter
push 0 ; third parameter push 0 ; third parameter
push 0 ; second parameter push 0 ; second parameter
push esi ; first parameter push s ; first parameter
call [getaddrinfo] call [getaddrinfo]
pop esi pop esi
; test for error ; test for error
@ -78,7 +105,7 @@ main:
jnz fail jnz fail
; write results ; write results
push str3 push str8
call [con_write_asciiz] call [con_write_asciiz]
; mov edi, esi ; mov edi, esi
@ -95,7 +122,7 @@ main:
push esi push esi
call [freeaddrinfo] call [freeaddrinfo]
push str4 push str9
call [con_write_asciiz] call [con_write_asciiz]
mcall socket, AF_INET4, SOCK_STREAM, 0 mcall socket, AF_INET4, SOCK_STREAM, 0
@ -119,6 +146,10 @@ mainloop:
mcall 10 mcall 10
DEBUGF 1, 'TELNET: EVENT %x !\n', eax DEBUGF 1, 'TELNET: EVENT %x !\n', eax
call [con_get_flags]
test eax, 0x200 ; con window closed?
jnz exit
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0 mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
cmp eax, -1 cmp eax, -1
je mainloop je mainloop
@ -182,17 +213,27 @@ mainloop:
jmp .print_loop jmp .print_loop
fail:
push str5
jmp main
fail2: fail2:
push str6 push str6
call [con_write_asciiz]
jmp fail.wait
fail:
push str5
call [con_write_asciiz]
.wait:
push str10
call [con_write_asciiz]
call [con_getch2]
jmp main jmp main
done: done:
push 1 push 1
call [con_exit] call [con_exit]
exit: exit:
mcall close, [socketnum]
mcall -1 mcall -1
@ -203,17 +244,23 @@ thread:
call [con_getch2] call [con_getch2]
mov byte [send_data], al mov byte [send_data], al
mcall send, [socketnum], send_data, 1 mcall send, [socketnum], send_data, 1
jmp .loop
call [con_get_flags]
test eax, 0x200 ; con window closed?
jz .loop
mcall -1
; data ; data
title db 'Telnet',0 title db 'Telnet',0
str1 db 'Telnet v0.1',10,' for KolibriOS # 1281 or later. ',10,10,'If you dont know where to connect to, try towel.blinkenlights.nl',10,10,0 str1 db 'Telnet for KolibriOS v0.11',10,10,'Please enter URL of telnet server (for example: towel.blinkenlights.nl)',10,10,0
str2 db '> ',0 str2 db '> ',0
str3 db 'Connecting to: ',0 str3 db 'Connecting to: ',0
str4 db 10,0 str4 db 10,0
str5 db 'Name resolution failed.',10,10,0 str5 db 10,'Name resolution failed.',10,0
str6 db 'Could not open socket',10,10,0 str6 db 10,'Could not open socket.',10,0
str7 db 'Got data!',10,10,0 str8 db ' (',0
str9 db ')',10,0
str10 db 'Push any key to continue.',0
sockaddr1: sockaddr1:
dw AF_INET4 dw AF_INET4
@ -243,7 +290,8 @@ import console, \
con_cls, 'con_cls',\ con_cls, 'con_cls',\
con_getch2, 'con_getch2',\ con_getch2, 'con_getch2',\
con_set_cursor_pos, 'con_set_cursor_pos',\ con_set_cursor_pos, 'con_set_cursor_pos',\
con_write_string, 'con_write_string' con_write_string, 'con_write_string',\
con_get_flags, 'con_get_flags'
i_end: i_end:
@ -252,7 +300,6 @@ socketnum dd ?
buffer_ptr rb BUFFERSIZE+1 buffer_ptr rb BUFFERSIZE+1
send_data rb 100 send_data rb 100
s rb 256 s rb 1024
align 4 rb 4096 ; stack
rb 4096 ; stack
mem: mem: