diff --git a/kernel/branches/net/applications/telnet/telnet.asm b/kernel/branches/net/applications/telnet/telnet.asm index a36f948cdc..239270c2a1 100644 --- a/kernel/branches/net/applications/telnet/telnet.asm +++ b/kernel/branches/net/applications/telnet/telnet.asm @@ -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 "" +__DEBUG__ equ 0 +__DEBUG_LEVEL__ equ 1 +BUFFERSIZE equ 4096 + use32 ; standard header db 'MENUET01' ; signature @@ -8,21 +26,14 @@ use32 dd i_end ; initialized size dd mem ; required memory dd mem ; stack pointer - dd 0 ; parameters + dd s ; parameters dd 0 ; path -__DEBUG__ equ 0 -__DEBUG_LEVEL__ equ 1 - - -BUFFERSIZE equ 4096 -; useful includes include '../macros.inc' purge mov,add,sub include '../proc32.inc' include '../dll.inc' include '../debug-fdo.inc' - include '../network.inc' ; entry point @@ -40,10 +51,17 @@ start: push 25 push 80 call [con_init] -; main loop + +; Check for parameters + cmp byte [s], 0 + jne resolve + +main: + call [con_cls] +; Welcome user push str1 call [con_write_asciiz] -main: + ; write prompt push str2 call [con_write_asciiz] @@ -57,20 +75,29 @@ main: jz done cmp byte [esi], 10 jz done + +resolve: + ; delete terminating '\n' - push esi -@@: + mov esi, s + @@: lodsb - test al, al - jnz @b - mov byte [esi-2], al - pop esi + cmp al, 0x20 + ja @r + mov byte [esi-1], 0 + + call [con_cls] + push str3 + call [con_write_asciiz] + push s + call [con_write_asciiz] + ; resolve name push esp ; reserve stack place push esp ; fourth parameter push 0 ; third parameter push 0 ; second parameter - push esi ; first parameter + push s ; first parameter call [getaddrinfo] pop esi ; test for error @@ -78,7 +105,7 @@ main: jnz fail ; write results - push str3 + push str8 call [con_write_asciiz] ; mov edi, esi @@ -95,7 +122,7 @@ main: push esi call [freeaddrinfo] - push str4 + push str9 call [con_write_asciiz] mcall socket, AF_INET4, SOCK_STREAM, 0 @@ -119,6 +146,10 @@ mainloop: mcall 10 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 cmp eax, -1 je mainloop @@ -182,17 +213,27 @@ mainloop: jmp .print_loop -fail: - push str5 - jmp main fail2: 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 done: push 1 call [con_exit] exit: + + mcall close, [socketnum] mcall -1 @@ -203,17 +244,23 @@ thread: call [con_getch2] mov byte [send_data], al mcall send, [socketnum], send_data, 1 - jmp .loop + + call [con_get_flags] + test eax, 0x200 ; con window closed? + jz .loop + mcall -1 ; data 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 str3 db 'Connecting to: ',0 str4 db 10,0 -str5 db 'Name resolution failed.',10,10,0 -str6 db 'Could not open socket',10,10,0 -str7 db 'Got data!',10,10,0 +str5 db 10,'Name resolution failed.',10,0 +str6 db 10,'Could not open socket.',10,0 +str8 db ' (',0 +str9 db ')',10,0 +str10 db 'Push any key to continue.',0 sockaddr1: dw AF_INET4 @@ -243,7 +290,8 @@ import console, \ con_cls, 'con_cls',\ con_getch2, 'con_getch2',\ 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: @@ -252,7 +300,6 @@ socketnum dd ? buffer_ptr rb BUFFERSIZE+1 send_data rb 100 -s rb 256 -align 4 -rb 4096 ; stack +s rb 1024 + rb 4096 ; stack mem: