Fix EN typos
- Corrections for en_US language. - Some whitespace sanitation. git-svn-id: svn://kolibrios.org@10061 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
4ad795c835
commit
2d3e0ac7f4
File diff suppressed because it is too large
Load Diff
@ -1,467 +1,467 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Copyright (C) KolibriOS team 2010-2017. All rights reserved. ;;
|
;; Copyright (C) KolibriOS team 2010-2024. All rights reserved. ;;
|
||||||
;; Distributed under terms of the GNU General Public License ;;
|
;; Distributed under terms of the GNU General Public License ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; ftpd.asm - FTP Daemon for KolibriOS ;;
|
;; ftpd.asm - FTP Daemon for KolibriOS ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Written by hidnplayr@kolibrios.org ;;
|
;; Written by hidnplayr@kolibrios.org ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; GNU GENERAL PUBLIC LICENSE ;;
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
||||||
;; Version 2, June 1991 ;;
|
;; Version 2, June 1991 ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
DEBUG = 0 ; if set to one, program will run in a single thread
|
DEBUG = 0 ; if set to one, program will run in a single thread
|
||||||
|
|
||||||
BUFFERSIZE = 8192
|
BUFFERSIZE = 8192
|
||||||
|
|
||||||
; using multiple's of 4
|
; using multiple's of 4
|
||||||
STATE_CONNECTED = 0*4
|
STATE_CONNECTED = 0*4
|
||||||
STATE_LOGIN = 1*4
|
STATE_LOGIN = 1*4
|
||||||
STATE_LOGIN_FAIL = 2*4 ; When an invalid username was given
|
STATE_LOGIN_FAIL = 2*4 ; When an invalid username was given
|
||||||
STATE_ACTIVE = 3*4
|
STATE_ACTIVE = 3*4
|
||||||
|
|
||||||
TYPE_UNDEF = 0
|
TYPE_UNDEF = 0
|
||||||
|
|
||||||
TYPE_ASCII = 00000100b
|
TYPE_ASCII = 00000100b
|
||||||
TYPE_EBDIC = 00001000b
|
TYPE_EBDIC = 00001000b
|
||||||
; subtypes for ascii & ebdic (np = default)
|
; subtypes for ascii & ebdic (np = default)
|
||||||
TYPE_NP = 00000001b ; non printable
|
TYPE_NP = 00000001b ; non printable
|
||||||
TYPE_TELNET = 00000010b
|
TYPE_TELNET = 00000010b
|
||||||
TYPE_ASA = 00000011b
|
TYPE_ASA = 00000011b
|
||||||
|
|
||||||
TYPE_IMAGE = 01000000b ; binary data
|
TYPE_IMAGE = 01000000b ; binary data
|
||||||
TYPE_LOCAL = 10000000b ; bits per byte must be specified
|
TYPE_LOCAL = 10000000b ; bits per byte must be specified
|
||||||
; lower 4 bits will hold this value
|
; lower 4 bits will hold this value
|
||||||
MODE_NOTREADY = 0
|
MODE_NOTREADY = 0
|
||||||
MODE_ACTIVE = 1
|
MODE_ACTIVE = 1
|
||||||
MODE_PASSIVE_WAIT = 2
|
MODE_PASSIVE_WAIT = 2
|
||||||
MODE_PASSIVE_OK = 3
|
MODE_PASSIVE_OK = 3
|
||||||
MODE_PASSIVE_FAILED = 4
|
MODE_PASSIVE_FAILED = 4
|
||||||
|
|
||||||
PERMISSION_EXEC = 1b ; LIST
|
PERMISSION_EXEC = 1b ; LIST
|
||||||
PERMISSION_READ = 10b
|
PERMISSION_READ = 10b
|
||||||
PERMISSION_WRITE = 100b
|
PERMISSION_WRITE = 100b
|
||||||
PERMISSION_DELETE = 1000b
|
PERMISSION_DELETE = 1000b
|
||||||
PERMISSION_CD = 10000b ; Change Directory
|
PERMISSION_CD = 10000b ; Change Directory
|
||||||
|
|
||||||
ABORT = 1 shl 31
|
ABORT = 1 shl 31
|
||||||
|
|
||||||
format binary as ""
|
format binary as ""
|
||||||
|
|
||||||
use32
|
use32
|
||||||
|
|
||||||
org 0x0
|
org 0x0
|
||||||
|
|
||||||
db 'MENUET01' ; signature
|
db 'MENUET01' ; signature
|
||||||
dd 1 ; header version
|
dd 1 ; header version
|
||||||
dd start ; entry point
|
dd start ; entry point
|
||||||
dd i_end ; initialized size
|
dd i_end ; initialized size
|
||||||
dd mem+0x1000 ; required memory
|
dd mem+0x1000 ; required memory
|
||||||
dd mem+0x1000 ; stack pointer
|
dd mem+0x1000 ; stack pointer
|
||||||
dd params ; parameters
|
dd params ; parameters
|
||||||
dd path ; path
|
dd path ; path
|
||||||
|
|
||||||
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 '../../struct.inc'
|
include '../../struct.inc'
|
||||||
include '../../develop/libraries/libs-dev/libio/libio.inc'
|
include '../../develop/libraries/libs-dev/libio/libio.inc'
|
||||||
|
|
||||||
include '../../network.inc'
|
include '../../network.inc'
|
||||||
|
|
||||||
macro sendFTP str {
|
macro sendFTP str {
|
||||||
local string, length
|
local string, length
|
||||||
xor edi, edi
|
xor edi, edi
|
||||||
mcall send, [ebp + thread_data.socketnum], string, length
|
mcall send, [ebp + thread_data.socketnum], string, length
|
||||||
invoke con_write_asciiz, string
|
invoke con_write_asciiz, string
|
||||||
|
|
||||||
iglobal
|
iglobal
|
||||||
string db str, 13, 10, 0
|
string db str, 13, 10, 0
|
||||||
length = $ - string - 1
|
length = $ - string - 1
|
||||||
\}
|
\}
|
||||||
}
|
}
|
||||||
|
|
||||||
include 'commands.inc'
|
include 'commands.inc'
|
||||||
|
|
||||||
start:
|
start:
|
||||||
mcall 68, 11 ; init heap
|
mcall 68, 11 ; init heap
|
||||||
mcall 40, EVM_STACK ; we only want network events
|
mcall 40, EVM_STACK ; we only want network events
|
||||||
|
|
||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz exit
|
jnz exit
|
||||||
|
|
||||||
; find path to main settings file (ftpd.ini)
|
; find path to main settings file (ftpd.ini)
|
||||||
mov edi, path ; Calculate the length of zero-terminated string
|
mov edi, path ; Calculate the length of zero-terminated string
|
||||||
xor al, al
|
xor al, al
|
||||||
mov ecx, 1024
|
mov ecx, 1024
|
||||||
repne scasb
|
repne scasb
|
||||||
dec edi
|
dec edi
|
||||||
mov esi, str_ini ; append it with '.ini', 0
|
mov esi, str_ini ; append it with '.ini', 0
|
||||||
movsd
|
movsd
|
||||||
movsb
|
movsb
|
||||||
|
|
||||||
; now create the second path (users.ini)
|
; now create the second path (users.ini)
|
||||||
std
|
std
|
||||||
mov al, '/'
|
mov al, '/'
|
||||||
repne scasb
|
repne scasb
|
||||||
lea ecx, [edi - path + 2]
|
lea ecx, [edi - path + 2]
|
||||||
cld
|
cld
|
||||||
mov esi, path
|
mov esi, path
|
||||||
mov edi, path2
|
mov edi, path2
|
||||||
rep movsb
|
rep movsb
|
||||||
mov esi, str_users
|
mov esi, str_users
|
||||||
movsd
|
movsd
|
||||||
movsd
|
movsd
|
||||||
movsw
|
movsw
|
||||||
|
|
||||||
; initialize console
|
; initialize console
|
||||||
invoke con_start, 1
|
invoke con_start, 1
|
||||||
invoke con_init, -1, -1, -1, -1, title
|
invoke con_init, -1, -1, -1, -1, title
|
||||||
|
|
||||||
; get settings from ini
|
; get settings from ini
|
||||||
invoke ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0
|
invoke ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0
|
||||||
mov esi, ini_buf
|
mov esi, ini_buf
|
||||||
mov cl, '.'
|
mov cl, '.'
|
||||||
call ip_to_dword
|
call ip_to_dword
|
||||||
mov [serverip], ebx
|
mov [serverip], ebx
|
||||||
|
|
||||||
invoke ini.get_int, path, str_ftpd, str_port, 21
|
invoke ini.get_int, path, str_ftpd, str_port, 21
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
mov [sockaddr1.port], ax
|
mov [sockaddr1.port], ax
|
||||||
|
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
invoke con_printf, str1, eax
|
invoke con_printf, str1, eax
|
||||||
add esp, 8
|
add esp, 8
|
||||||
|
|
||||||
; open listening socket
|
; open listening socket
|
||||||
mcall socket, AF_INET4, SOCK_STREAM, SO_NONBLOCK ; we dont want to block on accept
|
mcall socket, AF_INET4, SOCK_STREAM, SO_NONBLOCK ; we don't want to block on accept
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je sock_err
|
je sock_err
|
||||||
mov [socketnum], eax
|
mov [socketnum], eax
|
||||||
|
|
||||||
invoke con_write_asciiz, str2
|
invoke con_write_asciiz, str2
|
||||||
|
|
||||||
; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
|
; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
|
||||||
; cmp eax, -1
|
; cmp eax, -1
|
||||||
; je opt_err
|
; je opt_err
|
||||||
|
|
||||||
mcall bind, [socketnum], sockaddr1, sockaddr1.length
|
mcall bind, [socketnum], sockaddr1, sockaddr1.length
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je bind_err
|
je bind_err
|
||||||
|
|
||||||
invoke con_write_asciiz, str2
|
invoke con_write_asciiz, str2
|
||||||
|
|
||||||
invoke ini.get_int, path, str_ftpd, str_conn, 1 ; Backlog (max connections)
|
invoke ini.get_int, path, str_ftpd, str_conn, 1 ; Backlog (max connections)
|
||||||
mov edx, eax
|
mov edx, eax
|
||||||
|
|
||||||
invoke con_write_asciiz, str2
|
invoke con_write_asciiz, str2
|
||||||
|
|
||||||
mcall listen, [socketnum]
|
mcall listen, [socketnum]
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je listen_err
|
je listen_err
|
||||||
|
|
||||||
invoke con_write_asciiz, str2b
|
invoke con_write_asciiz, str2b
|
||||||
|
|
||||||
invoke ini.get_int, path, str_pasv, str_start, 2000
|
invoke ini.get_int, path, str_pasv, str_start, 2000
|
||||||
mov [pasv_start], ax
|
mov [pasv_start], ax
|
||||||
invoke ini.get_int, path, str_pasv, str_end, 5000
|
invoke ini.get_int, path, str_pasv, str_end, 5000
|
||||||
mov [pasv_end], ax
|
mov [pasv_end], ax
|
||||||
|
|
||||||
mov [alive], 1
|
mov [alive], 1
|
||||||
|
|
||||||
mainloop:
|
mainloop:
|
||||||
mcall 23, 100 ; Wait here for incoming connections on the base socket (socketnum)
|
mcall 23, 100 ; Wait here for incoming connections on the base socket (socketnum)
|
||||||
; One second timeout, we will use this to check if console is still working
|
; One second timeout, we will use this to check if console is still working
|
||||||
|
|
||||||
test eax, eax ; network event?
|
test eax, eax ; network event?
|
||||||
jz .checkconsole
|
jz .checkconsole
|
||||||
|
|
||||||
if DEBUG
|
if DEBUG
|
||||||
jmp threadstart
|
jmp threadstart
|
||||||
else
|
else
|
||||||
mcall 51, 1, threadstart, 0 ; Start a new thread for every incoming connection
|
mcall 51, 1, threadstart, 0 ; Start a new thread for every incoming connection
|
||||||
; NOTE: upon initialisation of the thread, stack will not be available!
|
; NOTE: upon initialisation of the thread, stack will not be available!
|
||||||
end if
|
end if
|
||||||
jmp mainloop
|
jmp mainloop
|
||||||
|
|
||||||
.checkconsole:
|
.checkconsole:
|
||||||
|
|
||||||
invoke con_get_flags ; Is console still running?
|
invoke con_get_flags ; Is console still running?
|
||||||
test eax, 0x0200
|
test eax, 0x0200
|
||||||
jz mainloop
|
jz mainloop
|
||||||
mcall close, [socketnum] ; kill the listening socket
|
mcall close, [socketnum] ; kill the listening socket
|
||||||
mov [alive], 0
|
mov [alive], 0
|
||||||
mcall -1 ; and exit
|
mcall -1 ; and exit
|
||||||
|
|
||||||
diff16 "threadstart", 0, $
|
diff16 "threadstart", 0, $
|
||||||
|
|
||||||
threadstart:
|
threadstart:
|
||||||
;;; mcall 68, 11 ; init heap
|
;;; mcall 68, 11 ; init heap
|
||||||
mcall 68, 12, sizeof.thread_data ; allocate the thread data struct
|
mcall 68, 12, sizeof.thread_data ; allocate the thread data struct
|
||||||
test eax, eax
|
test eax, eax
|
||||||
je exit
|
je exit
|
||||||
|
|
||||||
lea esp, [eax + thread_data.stack] ; init stack
|
lea esp, [eax + thread_data.stack] ; init stack
|
||||||
mov ebp, eax
|
mov ebp, eax
|
||||||
|
|
||||||
mcall 40, EVM_STACK ; we only want network events for this thread
|
mcall 40, EVM_STACK ; we only want network events for this thread
|
||||||
|
|
||||||
lea ebx, [ebp + thread_data.buffer] ; get information about the current process
|
lea ebx, [ebp + thread_data.buffer] ; get information about the current process
|
||||||
or ecx, -1
|
or ecx, -1
|
||||||
mcall 9
|
mcall 9
|
||||||
mov eax, dword [ebp + thread_data.buffer + 30] ; PID is at offset 30
|
mov eax, dword [ebp + thread_data.buffer + 30] ; PID is at offset 30
|
||||||
mov [ebp + thread_data.pid], eax
|
mov [ebp + thread_data.pid], eax
|
||||||
|
|
||||||
invoke con_set_flags, 0x03
|
invoke con_set_flags, 0x03
|
||||||
invoke con_printf, str8, [ebp + thread_data.pid] ; print on the console that we have created the new thread successfully
|
invoke con_printf, str8, [ebp + thread_data.pid] ; print on the console that we have created the new thread successfully
|
||||||
add esp, 8 ; balance stack
|
add esp, 8 ; balance stack
|
||||||
invoke con_set_flags, 0x07
|
invoke con_set_flags, 0x07
|
||||||
|
|
||||||
mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection..
|
mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection..
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je thread_exit
|
je thread_exit
|
||||||
mov [ebp + thread_data.socketnum], eax
|
mov [ebp + thread_data.socketnum], eax
|
||||||
|
|
||||||
if DEBUG
|
if DEBUG
|
||||||
mcall close, [socketnum] ; close the listening socket
|
mcall close, [socketnum] ; close the listening socket
|
||||||
end if
|
end if
|
||||||
|
|
||||||
mov [ebp + thread_data.state], STATE_CONNECTED
|
mov [ebp + thread_data.state], STATE_CONNECTED
|
||||||
mov [ebp + thread_data.permissions], 0
|
mov [ebp + thread_data.permissions], 0
|
||||||
mov [ebp + thread_data.mode], MODE_NOTREADY
|
mov [ebp + thread_data.mode], MODE_NOTREADY
|
||||||
lea eax, [ebp + thread_data.buffer]
|
lea eax, [ebp + thread_data.buffer]
|
||||||
mov [ebp + thread_data.buffer_ptr], eax
|
mov [ebp + thread_data.buffer_ptr], eax
|
||||||
mov [ebp + thread_data.passivesocknum], -1
|
mov [ebp + thread_data.passivesocknum], -1
|
||||||
|
|
||||||
sendFTP " 220 Welcome to KolibriOS FTP daemon" ; fix output code
|
sendFTP " 220 Welcome to KolibriOS FTP daemon" ; fix output code
|
||||||
|
|
||||||
diff16 "threadloop", 0, $
|
diff16 "threadloop", 0, $
|
||||||
threadloop:
|
threadloop:
|
||||||
;; Check if our socket is still connected
|
;; Check if our socket is still connected
|
||||||
; mcall send, [ebp + thread_data.socketnum], 0, 0 ; Try to send zero bytes, if socket is closed, this will return -1
|
; mcall send, [ebp + thread_data.socketnum], 0, 0 ; Try to send zero bytes, if socket is closed, this will return -1
|
||||||
; cmp eax, -1
|
; cmp eax, -1
|
||||||
; je thread_exit
|
; je thread_exit
|
||||||
|
|
||||||
cmp [alive], 0 ; Did main thread take a run for it?
|
cmp [alive], 0 ; Did main thread take a run for it?
|
||||||
je thread_exit
|
je thread_exit
|
||||||
|
|
||||||
mcall 23, 100 ; Wait for network event
|
mcall 23, 100 ; Wait for network event
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz threadloop
|
jz threadloop
|
||||||
|
|
||||||
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
|
cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT
|
||||||
jne .not_passive
|
jne .not_passive
|
||||||
mov ecx, [ebp + thread_data.passivesocknum]
|
mov ecx, [ebp + thread_data.passivesocknum]
|
||||||
lea edx, [ebp + thread_data.datasock]
|
lea edx, [ebp + thread_data.datasock]
|
||||||
mov esi, sizeof.thread_data.datasock
|
mov esi, sizeof.thread_data.datasock
|
||||||
mcall accept
|
mcall accept
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je .not_passive
|
je .not_passive
|
||||||
mov [ebp + thread_data.datasocketnum], eax
|
mov [ebp + thread_data.datasocketnum], eax
|
||||||
mov [ebp + thread_data.mode], MODE_PASSIVE_OK
|
mov [ebp + thread_data.mode], MODE_PASSIVE_OK
|
||||||
mcall close ; [ebp + thread_data.passivesocknum]
|
mcall close ; [ebp + thread_data.passivesocknum]
|
||||||
mov [ebp + thread_data.passivesocknum], -1
|
mov [ebp + thread_data.passivesocknum], -1
|
||||||
|
|
||||||
invoke con_write_asciiz, str_datasock
|
invoke con_write_asciiz, str_datasock
|
||||||
.not_passive:
|
.not_passive:
|
||||||
|
|
||||||
mov ecx, [ebp + thread_data.socketnum]
|
mov ecx, [ebp + thread_data.socketnum]
|
||||||
mov edx, [ebp + thread_data.buffer_ptr]
|
mov edx, [ebp + thread_data.buffer_ptr]
|
||||||
mov esi, sizeof.thread_data.buffer ;;; FIXME
|
mov esi, sizeof.thread_data.buffer ;;; FIXME
|
||||||
mov edi, MSG_DONTWAIT
|
mov edi, MSG_DONTWAIT
|
||||||
mcall recv
|
mcall recv
|
||||||
inc eax ; error? (-1)
|
inc eax ; error? (-1)
|
||||||
jz threadloop
|
jz threadloop
|
||||||
dec eax ; 0 bytes read?
|
dec eax ; 0 bytes read?
|
||||||
jz threadloop
|
jz threadloop
|
||||||
|
|
||||||
mov edi, [ebp + thread_data.buffer_ptr]
|
mov edi, [ebp + thread_data.buffer_ptr]
|
||||||
add [ebp + thread_data.buffer_ptr], eax
|
add [ebp + thread_data.buffer_ptr], eax
|
||||||
|
|
||||||
; Check if we received a newline character, if not, wait for more data
|
; Check if we received a newline character, if not, wait for more data
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
mov al, 10
|
mov al, 10
|
||||||
repne scasb
|
repne scasb
|
||||||
jne threadloop
|
jne threadloop
|
||||||
|
|
||||||
cmp word[edi-1], 0x0a0d
|
cmp word[edi-1], 0x0a0d
|
||||||
jne .got_command
|
jne .got_command
|
||||||
dec edi
|
dec edi
|
||||||
|
|
||||||
; We got a command!
|
; We got a command!
|
||||||
.got_command:
|
.got_command:
|
||||||
mov byte [edi], 0 ; append string with zero byte
|
mov byte [edi], 0 ; append string with zero byte
|
||||||
lea esi, [ebp + thread_data.buffer]
|
lea esi, [ebp + thread_data.buffer]
|
||||||
mov ecx, [ebp + thread_data.buffer_ptr]
|
mov ecx, [ebp + thread_data.buffer_ptr]
|
||||||
sub ecx, esi
|
sub ecx, esi
|
||||||
mov [ebp + thread_data.buffer_ptr], esi ; reset buffer ptr
|
mov [ebp + thread_data.buffer_ptr], esi ; reset buffer ptr
|
||||||
|
|
||||||
invoke con_set_flags, 0x02 ; print received data to console (in green color)
|
invoke con_set_flags, 0x02 ; print received data to console (in green color)
|
||||||
invoke con_write_asciiz, str_newline
|
invoke con_write_asciiz, str_newline
|
||||||
invoke con_write_asciiz, esi
|
invoke con_write_asciiz, esi
|
||||||
invoke con_set_flags, 0x07
|
invoke con_set_flags, 0x07
|
||||||
|
|
||||||
push threadloop
|
push threadloop
|
||||||
jmp parse_cmd
|
jmp parse_cmd
|
||||||
|
|
||||||
listen_err:
|
listen_err:
|
||||||
invoke con_set_flags, 0x0c ; print errors in red
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
invoke con_write_asciiz, str3
|
invoke con_write_asciiz, str3
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
bind_err:
|
bind_err:
|
||||||
invoke con_set_flags, 0x0c ; print errors in red
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
invoke con_write_asciiz, str4
|
invoke con_write_asciiz, str4
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
sock_err:
|
sock_err:
|
||||||
invoke con_set_flags, 0x0c ; print errors in red
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
invoke con_write_asciiz, str6
|
invoke con_write_asciiz, str6
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
done:
|
done:
|
||||||
invoke con_exit, 0
|
invoke con_exit, 0
|
||||||
exit:
|
exit:
|
||||||
mcall -1
|
mcall -1
|
||||||
|
|
||||||
|
|
||||||
thread_exit:
|
thread_exit:
|
||||||
invoke con_set_flags, 0x03 ; print thread info in blue
|
invoke con_set_flags, 0x03 ; print thread info in blue
|
||||||
invoke con_printf, str_bye, [ebp + thread_data.pid] ; print on the console that we are about to kill the thread
|
invoke con_printf, str_bye, [ebp + thread_data.pid] ; print on the console that we are about to kill the thread
|
||||||
add esp, 8 ; balance stack
|
add esp, 8 ; balance stack
|
||||||
mcall 68, 13, ebp ; free the memory
|
mcall 68, 13, ebp ; free the memory
|
||||||
mcall -1 ; and kill the thread
|
mcall -1 ; and kill the thread
|
||||||
|
|
||||||
|
|
||||||
; initialized data
|
; initialized data
|
||||||
|
|
||||||
title db 'FTP daemon', 0
|
title db 'FTP daemon', 0
|
||||||
str1 db 'Starting FTP daemon on port %u.', 0
|
str1 db 'Starting FTP daemon on port %u.', 0
|
||||||
str2 db '.', 0
|
str2 db '.', 0
|
||||||
str2b db ' OK!',10,0
|
str2b db ' OK!',10,0
|
||||||
str3 db 'Listen error',10,0
|
str3 db 'Listen error',10,0
|
||||||
str4 db 10,'ERROR: local port is already in use.',10,0
|
str4 db 10,'ERROR: local port is already in use.',10,0
|
||||||
;str5 db 'Setsockopt error.',10,10,0
|
;str5 db 'Setsockopt error.',10,10,0
|
||||||
str6 db 'ERROR: Could not open socket.',10,0
|
str6 db 'ERROR: Could not open socket.',10,0
|
||||||
str7 db 'Got data!',10,10,0
|
str7 db 'Got data!',10,10,0
|
||||||
str8 db 10,'Thread %d created',10,0
|
str8 db 10,'Thread %d created',10,0
|
||||||
str_bye db 10,'Thread %d killed',10,0
|
str_bye db 10,'Thread %d killed',10,0
|
||||||
|
|
||||||
str_logged_in db 'Login ok',10,0
|
str_logged_in db 'Login ok',10,0
|
||||||
str_pass_ok db 'Password ok',10,0
|
str_pass_ok db 'Password ok',10,0
|
||||||
str_pass_err db 'Password/Username incorrect',10,0
|
str_pass_err db 'Password/Username incorrect',10,0
|
||||||
str_pwd db 'Current directory is "%s"\n',0
|
str_pwd db 'Current directory is "%s"\n',0
|
||||||
str_err2 db 'ERROR: cannot open the directory.',10,0
|
str_err2 db 'ERROR: cannot open the directory.',10,0
|
||||||
str_datasock db 'Passive data socket connected.',10,0
|
str_datasock db 'Passive data socket connected.',10,0
|
||||||
str_datasock2 db 'Active data socket connected.',10,0
|
str_datasock2 db 'Active data socket connected.',10,0
|
||||||
str_alopen db 'Data connection already open.',10,0
|
str_alopen db 'Data connection already open.',10,0
|
||||||
str_notfound db 'ERROR: file not found.',10,0
|
str_notfound db 'ERROR: file not found.',10,0
|
||||||
str_sockerr db 'ERROR: socket error.',10,0
|
str_sockerr db 'ERROR: socket error.',10,0
|
||||||
|
|
||||||
str_newline db 10, 0
|
str_newline db 10, 0
|
||||||
str_mask db '*', 0
|
str_mask db '*', 0
|
||||||
str_infinity db 0xff, 0xff, 0xff, 0xff, 0
|
str_infinity db 0xff, 0xff, 0xff, 0xff, 0
|
||||||
|
|
||||||
months dd 'Jan '
|
months dd 'Jan '
|
||||||
dd 'Feb '
|
dd 'Feb '
|
||||||
dd 'Mar '
|
dd 'Mar '
|
||||||
dd 'Apr '
|
dd 'Apr '
|
||||||
dd 'May '
|
dd 'May '
|
||||||
dd 'Jun '
|
dd 'Jun '
|
||||||
dd 'Jul '
|
dd 'Jul '
|
||||||
dd 'Aug '
|
dd 'Aug '
|
||||||
dd 'Sep '
|
dd 'Sep '
|
||||||
dd 'Oct '
|
dd 'Oct '
|
||||||
dd 'Nov '
|
dd 'Nov '
|
||||||
dd 'Dec '
|
dd 'Dec '
|
||||||
|
|
||||||
str_users db 'users'
|
str_users db 'users'
|
||||||
str_ini db '.ini', 0
|
str_ini db '.ini', 0
|
||||||
str_port db 'port', 0
|
str_port db 'port', 0
|
||||||
str_ftpd db 'ftpd', 0
|
str_ftpd db 'ftpd', 0
|
||||||
str_conn db 'conn', 0
|
str_conn db 'conn', 0
|
||||||
str_ip db 'ip', 0
|
str_ip db 'ip', 0
|
||||||
str_pass db 'pass', 0
|
str_pass db 'pass', 0
|
||||||
str_home db 'home', 0
|
str_home db 'home', 0
|
||||||
str_mode db 'mode', 0
|
str_mode db 'mode', 0
|
||||||
str_pasv db 'pasv', 0
|
str_pasv db 'pasv', 0
|
||||||
str_start db 'start', 0
|
str_start db 'start', 0
|
||||||
str_end db 'end', 0
|
str_end db 'end', 0
|
||||||
|
|
||||||
|
|
||||||
sockaddr1:
|
sockaddr1:
|
||||||
dw AF_INET4
|
dw AF_INET4
|
||||||
.port dw 0
|
.port dw 0
|
||||||
.ip dd 0
|
.ip dd 0
|
||||||
rb 10
|
rb 10
|
||||||
.length = $ - sockaddr1
|
.length = $ - sockaddr1
|
||||||
|
|
||||||
; import
|
; import
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
@IMPORT:
|
@IMPORT:
|
||||||
|
|
||||||
diff16 "import", 0, $
|
diff16 "import", 0, $
|
||||||
|
|
||||||
library console, 'console.obj',\
|
library console, 'console.obj',\
|
||||||
libini, 'libini.obj', \
|
libini, 'libini.obj', \
|
||||||
libio, 'libio.obj'
|
libio, 'libio.obj'
|
||||||
|
|
||||||
import console,\
|
import console,\
|
||||||
con_start, 'START',\
|
con_start, 'START',\
|
||||||
con_init, 'con_init',\
|
con_init, 'con_init',\
|
||||||
con_write_asciiz, 'con_write_asciiz',\
|
con_write_asciiz, 'con_write_asciiz',\
|
||||||
con_exit, 'con_exit',\
|
con_exit, 'con_exit',\
|
||||||
con_gets, 'con_gets',\
|
con_gets, 'con_gets',\
|
||||||
con_cls, 'con_cls',\
|
con_cls, 'con_cls',\
|
||||||
con_printf, 'con_printf',\
|
con_printf, 'con_printf',\
|
||||||
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_set_flags, 'con_set_flags',\
|
con_set_flags, 'con_set_flags',\
|
||||||
con_get_flags, 'con_get_flags'
|
con_get_flags, 'con_get_flags'
|
||||||
|
|
||||||
import libini,\
|
import libini,\
|
||||||
ini.get_str, 'ini_get_str',\
|
ini.get_str, 'ini_get_str',\
|
||||||
ini.get_int, 'ini_get_int'
|
ini.get_int, 'ini_get_int'
|
||||||
|
|
||||||
import libio,\
|
import libio,\
|
||||||
file.size, 'file_size',\
|
file.size, 'file_size',\
|
||||||
file.open, 'file_open',\
|
file.open, 'file_open',\
|
||||||
file.read, 'file_read',\
|
file.read, 'file_read',\
|
||||||
file.write, 'file_write',\
|
file.write, 'file_write',\
|
||||||
file.close, 'file_close',\
|
file.close, 'file_close',\
|
||||||
file.find.first, 'file_find_first',\
|
file.find.first, 'file_find_first',\
|
||||||
file.find.next, 'file_find_next',\
|
file.find.next, 'file_find_next',\
|
||||||
file.find.close, 'file_find_close'
|
file.find.close, 'file_find_close'
|
||||||
|
|
||||||
|
|
||||||
IncludeIGlobals
|
IncludeIGlobals
|
||||||
|
|
||||||
|
|
||||||
i_end:
|
i_end:
|
||||||
|
|
||||||
diff16 "i_end", 0, $
|
diff16 "i_end", 0, $
|
||||||
|
|
||||||
; uninitialised data
|
; uninitialised data
|
||||||
|
|
||||||
socketnum dd ?
|
socketnum dd ?
|
||||||
path rb 1024
|
path rb 1024
|
||||||
path2 rb 1024
|
path2 rb 1024
|
||||||
params rb 1024
|
params rb 1024
|
||||||
serverip dd ?
|
serverip dd ?
|
||||||
pasv_start dw ?
|
pasv_start dw ?
|
||||||
pasv_end dw ?
|
pasv_end dw ?
|
||||||
pasv_port dw ?
|
pasv_port dw ?
|
||||||
|
|
||||||
ini_buf rb 3*4+3+1
|
ini_buf rb 3*4+3+1
|
||||||
|
|
||||||
alive db ?
|
alive db ?
|
||||||
|
|
||||||
mem:
|
mem:
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,385 +1,385 @@
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
||||||
;; Distributed under terms of the GNU General Public License ;;
|
;; Distributed under terms of the GNU General Public License ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; Written by hidnplayr@kolibrios.org ;;
|
;; Written by hidnplayr@kolibrios.org ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;; GNU GENERAL PUBLIC LICENSE ;;
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
||||||
;; Version 2, June 1991 ;;
|
;; Version 2, June 1991 ;;
|
||||||
;; ;;
|
;; ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
draw_window: ; Completely redraw the window, recalculate all coordinates and sizes
|
draw_window: ; Completely redraw the window, recalculate all coordinates and sizes
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
|
|
||||||
; get system colors
|
; get system colors
|
||||||
mcall 48, 3, colors, 40
|
mcall 48, 3, colors, 40
|
||||||
call set_edit_box_and_scrollbar_colors
|
call set_edit_box_and_scrollbar_colors
|
||||||
|
|
||||||
mcall 9, thread_info, -1 ; get information about this thread
|
mcall 9, thread_info, -1 ; get information about this thread
|
||||||
mov eax, [thread_info.box.width] ; window xsize
|
mov eax, [thread_info.box.width] ; window xsize
|
||||||
mov ebx, [thread_info.box.height] ; ysize
|
mov ebx, [thread_info.box.height] ; ysize
|
||||||
mov edx, [thread_info.client_box.width] ; work area xsize
|
mov edx, [thread_info.client_box.width] ; work area xsize
|
||||||
mov esi, [thread_info.client_box.height] ; ysize
|
mov esi, [thread_info.client_box.height] ; ysize
|
||||||
sub eax, edx
|
sub eax, edx
|
||||||
sub ebx, esi
|
sub ebx, esi
|
||||||
|
|
||||||
cmp edx, WIN_MIN_X
|
cmp edx, WIN_MIN_X
|
||||||
jae .x_ok
|
jae .x_ok
|
||||||
mov edx, WIN_MIN_X
|
mov edx, WIN_MIN_X
|
||||||
.x_ok:
|
.x_ok:
|
||||||
mov [xsize], edx
|
mov [xsize], edx
|
||||||
add edx, eax
|
add edx, eax
|
||||||
|
|
||||||
cmp esi, WIN_MIN_Y
|
cmp esi, WIN_MIN_Y
|
||||||
jae .y_ok
|
jae .y_ok
|
||||||
mov esi, WIN_MIN_Y
|
mov esi, WIN_MIN_Y
|
||||||
.y_ok:
|
.y_ok:
|
||||||
mov [ysize], esi
|
mov [ysize], esi
|
||||||
add esi, ebx
|
add esi, ebx
|
||||||
mcall 67, -1, -1 ; set the new sizes
|
mcall 67, -1, -1 ; set the new sizes
|
||||||
|
|
||||||
popa
|
popa
|
||||||
|
|
||||||
.dont_resize:
|
.dont_resize:
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
|
|
||||||
mcall 12, 1
|
mcall 12, 1
|
||||||
xor eax, eax ; draw window
|
xor eax, eax ; draw window
|
||||||
mov ebx, WIN_MIN_X+10
|
mov ebx, WIN_MIN_X+10
|
||||||
mov ecx, WIN_MIN_Y+30
|
mov ecx, WIN_MIN_Y+30
|
||||||
mov edx, [colors.work]
|
mov edx, [colors.work]
|
||||||
add edx, 0x33000000
|
add edx, 0x33000000
|
||||||
mov edi, str_programname
|
mov edi, str_programname
|
||||||
mcall
|
mcall
|
||||||
|
|
||||||
test [thread_info.wnd_state], 100b ; skip if window is rolled up
|
test [thread_info.wnd_state], 100b ; skip if window is rolled up
|
||||||
jne .exit
|
jne .exit
|
||||||
|
|
||||||
cmp [window_active], 0
|
cmp [window_active], 0
|
||||||
je .no_window
|
je .no_window
|
||||||
|
|
||||||
; calculate available space for textbox and coordinates for scrollbars
|
; calculate available space for textbox and coordinates for scrollbars
|
||||||
mov eax, [ysize]
|
mov eax, [ysize]
|
||||||
sub eax, TOP_Y + INPUTBOX_HEIGHT - 1
|
sub eax, TOP_Y + INPUTBOX_HEIGHT - 1
|
||||||
mov [scroll2.y_size], ax
|
mov [scroll2.y_size], ax
|
||||||
mov [scroll1.y_size], ax
|
mov [scroll1.y_size], ax
|
||||||
sub eax, 4
|
sub eax, 4
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov ecx, FONT_HEIGHT
|
mov ecx, FONT_HEIGHT
|
||||||
div ecx
|
div ecx
|
||||||
mov [textbox_height], eax
|
mov [textbox_height], eax
|
||||||
mov [scroll2.cur_area], eax
|
mov [scroll2.cur_area], eax
|
||||||
mov [scroll1.cur_area], eax
|
mov [scroll1.cur_area], eax
|
||||||
|
|
||||||
mov eax, [xsize]
|
mov eax, [xsize]
|
||||||
sub eax, SCROLLBAR_WIDTH
|
sub eax, SCROLLBAR_WIDTH
|
||||||
mov [scroll1.x_pos], ax
|
mov [scroll1.x_pos], ax
|
||||||
mov edi, [window_active]
|
mov edi, [window_active]
|
||||||
cmp [edi + window.type], WINDOWTYPE_CHANNEL
|
cmp [edi + window.type], WINDOWTYPE_CHANNEL
|
||||||
jne @f
|
jne @f
|
||||||
sub eax, USERLIST_WIDTH + SCROLLBAR_WIDTH + 2
|
sub eax, USERLIST_WIDTH + SCROLLBAR_WIDTH + 2
|
||||||
@@:
|
@@:
|
||||||
mov [scroll2.x_pos], ax
|
mov [scroll2.x_pos], ax
|
||||||
sub eax, 10
|
sub eax, 10
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov ecx, FONT_WIDTH
|
mov ecx, FONT_WIDTH
|
||||||
div ecx
|
div ecx
|
||||||
mov [textbox_width], eax
|
mov [textbox_width], eax
|
||||||
|
|
||||||
; recalculate text line breaks (because height/width might have changed..)
|
; recalculate text line breaks (because height/width might have changed..)
|
||||||
; meanwhile, recalculate line number of current line
|
; meanwhile, recalculate line number of current line
|
||||||
mov esi, [edi + window.text_print]
|
mov esi, [edi + window.text_print]
|
||||||
mov al, byte[esi]
|
mov al, byte[esi]
|
||||||
push eax
|
push eax
|
||||||
mov byte[esi], 0
|
mov byte[esi], 0
|
||||||
push esi
|
push esi
|
||||||
|
|
||||||
mov esi, [edi + window.text_start]
|
mov esi, [edi + window.text_start]
|
||||||
call text_insert_newlines
|
call text_insert_newlines
|
||||||
mov [edi + window.text_lines], edx
|
mov [edi + window.text_lines], edx
|
||||||
mov [edi + window.text_scanned], esi
|
mov [edi + window.text_scanned], esi
|
||||||
mov [edi + window.text_line_print], edx
|
mov [edi + window.text_line_print], edx
|
||||||
|
|
||||||
pop esi
|
pop esi
|
||||||
pop eax
|
pop eax
|
||||||
mov byte[esi], al
|
mov byte[esi], al
|
||||||
|
|
||||||
; and redraw the textbox (and scrollbar if needed)
|
; and redraw the textbox (and scrollbar if needed)
|
||||||
mov [scroll2.all_redraw], 1
|
mov [scroll2.all_redraw], 1
|
||||||
call draw_channel_text
|
call draw_channel_text
|
||||||
|
|
||||||
; Draw userlist if active window is a channel
|
; Draw userlist if active window is a channel
|
||||||
mov edi, [window_active]
|
mov edi, [window_active]
|
||||||
cmp [edi + window.type], WINDOWTYPE_CHANNEL
|
cmp [edi + window.type], WINDOWTYPE_CHANNEL
|
||||||
jne .not_channel
|
jne .not_channel
|
||||||
|
|
||||||
mov [scroll1.all_redraw], 1
|
mov [scroll1.all_redraw], 1
|
||||||
call draw_user_list
|
call draw_user_list
|
||||||
|
|
||||||
; draw a vertical separator line when there is no scrollbar
|
; draw a vertical separator line when there is no scrollbar
|
||||||
cmp [scroll2.all_redraw], 1
|
cmp [scroll2.all_redraw], 1
|
||||||
jne .not_channel
|
jne .not_channel
|
||||||
|
|
||||||
mov ebx, [xsize]
|
mov ebx, [xsize]
|
||||||
sub ebx, USERLIST_WIDTH + SCROLLBAR_WIDTH + 3
|
sub ebx, USERLIST_WIDTH + SCROLLBAR_WIDTH + 3
|
||||||
push bx
|
push bx
|
||||||
shl ebx, 16
|
shl ebx, 16
|
||||||
pop bx
|
pop bx
|
||||||
mov ecx, [ysize]
|
mov ecx, [ysize]
|
||||||
add ecx, TOP_Y shl 16 - (INPUTBOX_HEIGHT)
|
add ecx, TOP_Y shl 16 - (INPUTBOX_HEIGHT)
|
||||||
mov edx, [colors.work_graph]
|
mov edx, [colors.work_graph]
|
||||||
mcall 38
|
mcall 38
|
||||||
.not_channel:
|
.not_channel:
|
||||||
.no_window:
|
.no_window:
|
||||||
|
|
||||||
; draw editbox
|
; draw editbox
|
||||||
mov eax, [ysize]
|
mov eax, [ysize]
|
||||||
sub eax, INPUTBOX_HEIGHT
|
sub eax, INPUTBOX_HEIGHT
|
||||||
mov [edit1.top], eax
|
mov [edit1.top], eax
|
||||||
|
|
||||||
mov eax, [xsize]
|
mov eax, [xsize]
|
||||||
mov [edit1.width], eax
|
mov [edit1.width], eax
|
||||||
|
|
||||||
invoke edit_box_draw, edit1
|
invoke edit_box_draw, edit1
|
||||||
|
|
||||||
; draw tabs
|
; draw tabs
|
||||||
call draw_window_tabs
|
call draw_window_tabs
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
mcall 12, 2
|
mcall 12, 2
|
||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
draw_user_list:
|
draw_user_list:
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
|
|
||||||
; Do we need a scrollbar?
|
; Do we need a scrollbar?
|
||||||
mov ebx, [window_active]
|
mov ebx, [window_active]
|
||||||
mov eax, [ebx + window.users]
|
mov eax, [ebx + window.users]
|
||||||
mov [scroll1.max_area], eax
|
mov [scroll1.max_area], eax
|
||||||
cmp [scroll1.cur_area], eax
|
cmp [scroll1.cur_area], eax
|
||||||
jae .noscroll
|
jae .noscroll
|
||||||
|
|
||||||
; Is the current position greater then the max position?
|
; Is the current position greater then the max position?
|
||||||
cmp eax, [scroll1.position]
|
cmp eax, [scroll1.position]
|
||||||
ja @f
|
ja @f
|
||||||
mov [scroll1.position], eax
|
mov [scroll1.position], eax
|
||||||
@@:
|
@@:
|
||||||
; OK, draw the scrollbar
|
; OK, draw the scrollbar
|
||||||
invoke scrollbar_draw, scroll1
|
invoke scrollbar_draw, scroll1
|
||||||
|
|
||||||
; dont redraw scrollbar completely next time,
|
; don't redraw scrollbar completely next time,
|
||||||
; unless draw_window asks us to by setting [scroll1.all_redraw] back to 1
|
; unless draw_window asks us to by setting [scroll1.all_redraw] back to 1
|
||||||
mov [scroll1.all_redraw], 0
|
mov [scroll1.all_redraw], 0
|
||||||
jmp .scroll_done
|
jmp .scroll_done
|
||||||
|
|
||||||
.noscroll:
|
.noscroll:
|
||||||
mov [scroll1.position], 0
|
mov [scroll1.position], 0
|
||||||
.scroll_done:
|
.scroll_done:
|
||||||
|
|
||||||
; draw an invisible button, where the usernames will go
|
; draw an invisible button, where the usernames will go
|
||||||
mov ebx, [xsize]
|
mov ebx, [xsize]
|
||||||
sub ebx, USERLIST_WIDTH + SCROLLBAR_WIDTH
|
sub ebx, USERLIST_WIDTH + SCROLLBAR_WIDTH
|
||||||
shl ebx, 16
|
shl ebx, 16
|
||||||
push ebx
|
push ebx
|
||||||
mov bx, USERLIST_WIDTH
|
mov bx, USERLIST_WIDTH
|
||||||
mov ecx, [ysize]
|
mov ecx, [ysize]
|
||||||
add ecx, TEXT_Y shl 16 - (TEXT_Y + 16)
|
add ecx, TEXT_Y shl 16 - (TEXT_Y + 16)
|
||||||
push ecx ebx
|
push ecx ebx
|
||||||
mov edx, WINDOW_BTN_LIST + 1 shl 29 + 1 shl 30
|
mov edx, WINDOW_BTN_LIST + 1 shl 29 + 1 shl 30
|
||||||
mcall 8
|
mcall 8
|
||||||
|
|
||||||
; draw a filled rectangle to clear previously printed names
|
; draw a filled rectangle to clear previously printed names
|
||||||
pop ebx ecx
|
pop ebx ecx
|
||||||
mov edx, [colors.work]
|
mov edx, [colors.work]
|
||||||
mcall 13
|
mcall 13
|
||||||
|
|
||||||
; now, draw the names according to the scrollbar position and window size
|
; now, draw the names according to the scrollbar position and window size
|
||||||
mov eax, [scroll1.position]
|
mov eax, [scroll1.position]
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov ecx, MAX_NICK_LEN
|
mov ecx, MAX_NICK_LEN
|
||||||
mul ecx
|
mul ecx
|
||||||
mov edx, eax
|
mov edx, eax
|
||||||
mov eax, [window_active]
|
mov eax, [window_active]
|
||||||
mov ebp, [eax + window.selected]
|
mov ebp, [eax + window.selected]
|
||||||
add edx, [eax + window.data_ptr]
|
add edx, [eax + window.data_ptr]
|
||||||
sub ebp, [scroll1.position]
|
sub ebp, [scroll1.position]
|
||||||
add edx, window_data.names
|
add edx, window_data.names
|
||||||
|
|
||||||
pop ebx
|
pop ebx
|
||||||
mov bx, TEXT_Y
|
mov bx, TEXT_Y
|
||||||
mov ecx, [colors.work_text]
|
mov ecx, [colors.work_text]
|
||||||
or ecx, 0x90000000 ; 8x16 font, zero terminated string
|
or ecx, 0x90000000 ; 8x16 font, zero terminated string
|
||||||
mov eax, 4 ; draw text
|
mov eax, 4 ; draw text
|
||||||
|
|
||||||
mov edi, [textbox_height] ; how many names will fit on screen
|
mov edi, [textbox_height] ; how many names will fit on screen
|
||||||
.loop:
|
.loop:
|
||||||
cmp byte[edx], 0 ; end of list?
|
cmp byte[edx], 0 ; end of list?
|
||||||
je .done
|
je .done
|
||||||
|
|
||||||
dec ebp ; is this name selected?
|
dec ebp ; is this name selected?
|
||||||
jnz .nothighlight
|
jnz .nothighlight
|
||||||
; yes, highlight it
|
; yes, highlight it
|
||||||
pusha
|
pusha
|
||||||
mov cx, bx
|
mov cx, bx
|
||||||
mov bx, USERLIST_WIDTH
|
mov bx, USERLIST_WIDTH
|
||||||
shl ecx, 16
|
shl ecx, 16
|
||||||
mov cx, FONT_HEIGHT
|
mov cx, FONT_HEIGHT
|
||||||
mov edx, 0x00000055 ; blue!
|
mov edx, 0x00000055 ; blue!
|
||||||
mcall 13
|
mcall 13
|
||||||
popa
|
popa
|
||||||
|
|
||||||
mov ecx, 0x9000ffff ; cyan!
|
mov ecx, 0x9000ffff ; cyan!
|
||||||
mcall
|
mcall
|
||||||
|
|
||||||
mov ecx, [colors.work_text]
|
mov ecx, [colors.work_text]
|
||||||
or ecx, 0x90000000 ; 8x16 font, zero terminated string
|
or ecx, 0x90000000 ; 8x16 font, zero terminated string
|
||||||
jmp .next
|
jmp .next
|
||||||
|
|
||||||
.nothighlight:
|
.nothighlight:
|
||||||
mcall
|
mcall
|
||||||
|
|
||||||
.next:
|
.next:
|
||||||
add edx, MAX_NICK_LEN
|
add edx, MAX_NICK_LEN
|
||||||
add ebx, FONT_HEIGHT
|
add ebx, FONT_HEIGHT
|
||||||
dec edi
|
dec edi
|
||||||
jnz .loop
|
jnz .loop
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
popa
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
draw_window_tabs:
|
draw_window_tabs:
|
||||||
|
|
||||||
; Draw horizontal line
|
; Draw horizontal line
|
||||||
|
|
||||||
mov ebx, [xsize]
|
mov ebx, [xsize]
|
||||||
mov edx, [colors.work_graph]
|
mov edx, [colors.work_graph]
|
||||||
mov ecx, TOP_Y SHL 16 + TOP_Y
|
mov ecx, TOP_Y SHL 16 + TOP_Y
|
||||||
mcall 38
|
mcall 38
|
||||||
|
|
||||||
; Create the buttons
|
; Create the buttons
|
||||||
|
|
||||||
mov eax, 8
|
mov eax, 8
|
||||||
mov ebx, TAB_WIDTH
|
mov ebx, TAB_WIDTH
|
||||||
mov ecx, TOP_SPACE shl 16 + TAB_HEIGHT
|
mov ecx, TOP_SPACE shl 16 + TAB_HEIGHT
|
||||||
mov edx, WINDOW_BTN_START
|
mov edx, WINDOW_BTN_START
|
||||||
mov edi, windows
|
mov edi, windows
|
||||||
.more_btn:
|
.more_btn:
|
||||||
mov esi, [colors.work]
|
mov esi, [colors.work]
|
||||||
cmp [window_active], edi
|
cmp [window_active], edi
|
||||||
jne @f
|
jne @f
|
||||||
;not esi
|
;not esi
|
||||||
;and esi, 0x00ffffff
|
;and esi, 0x00ffffff
|
||||||
mov esi, [colors.work_light]
|
mov esi, [colors.work_light]
|
||||||
@@:
|
@@:
|
||||||
mcall
|
mcall
|
||||||
inc edx
|
inc edx
|
||||||
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
||||||
add edi, sizeof.window
|
add edi, sizeof.window
|
||||||
cmp [edi + window.data_ptr], 0
|
cmp [edi + window.data_ptr], 0
|
||||||
jne .more_btn
|
jne .more_btn
|
||||||
|
|
||||||
; Draw the close window button
|
; Draw the close window button
|
||||||
mov edi, [window_active]
|
mov edi, [window_active]
|
||||||
cmp [edi + window.type], WINDOWTYPE_SERVER ; dont let the user close server window
|
cmp [edi + window.type], WINDOWTYPE_SERVER ; don't let the user close server window
|
||||||
je @f
|
je @f
|
||||||
|
|
||||||
; mov eax, 8
|
; mov eax, 8
|
||||||
mov ebx, [xsize]
|
mov ebx, [xsize]
|
||||||
sub ebx, SCROLLBAR_WIDTH
|
sub ebx, SCROLLBAR_WIDTH
|
||||||
shl ebx, 16
|
shl ebx, 16
|
||||||
mov bx, SCROLLBAR_WIDTH
|
mov bx, SCROLLBAR_WIDTH
|
||||||
mov ecx, TOP_SPACE shl 16 + TAB_HEIGHT - 1
|
mov ecx, TOP_SPACE shl 16 + TAB_HEIGHT - 1
|
||||||
mov edx, WINDOW_BTN_CLOSE
|
mov edx, WINDOW_BTN_CLOSE
|
||||||
mov esi, 0x00aa0000 ; red !
|
mov esi, 0x00aa0000 ; red !
|
||||||
mcall
|
mcall
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
; write closing cross
|
; write closing cross
|
||||||
mov ebx, [xsize]
|
mov ebx, [xsize]
|
||||||
sub ebx, 9
|
sub ebx, 9
|
||||||
shl ebx, 16
|
shl ebx, 16
|
||||||
add ebx, TOP_SPACE+3
|
add ebx, TOP_SPACE+3
|
||||||
mov ecx, 0x80FFFfff
|
mov ecx, 0x80FFFfff
|
||||||
mov edx, closing_cross
|
mov edx, closing_cross
|
||||||
mcall 4
|
mcall 4
|
||||||
popa
|
popa
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
; Draw the windownames onto the buttons
|
; Draw the windownames onto the buttons
|
||||||
|
|
||||||
mov eax, 4
|
mov eax, 4
|
||||||
mov ebx, 5 shl 16 + TOP_SPACE + 4 ;;;;
|
mov ebx, 5 shl 16 + TOP_SPACE + 4 ;;;;
|
||||||
mov esi, MAX_WINDOWS
|
mov esi, MAX_WINDOWS
|
||||||
mov edi, windows
|
mov edi, windows
|
||||||
.more:
|
.more:
|
||||||
mov ecx, [colors.work_text]
|
mov ecx, [colors.work_text]
|
||||||
test [edi + window.flags], FLAG_UPDATED
|
test [edi + window.flags], FLAG_UPDATED
|
||||||
jz @f
|
jz @f
|
||||||
mov ecx, 0x00aa0000 ; RED!
|
mov ecx, 0x00aa0000 ; RED!
|
||||||
@@:
|
@@:
|
||||||
or ecx, 0x80000000 ; ASCIIZ string
|
or ecx, 0x80000000 ; ASCIIZ string
|
||||||
lea edx, [edi + window.name]
|
lea edx, [edi + window.name]
|
||||||
mcall
|
mcall
|
||||||
add edi, sizeof.window ; get ptr to next window
|
add edi, sizeof.window ; get ptr to next window
|
||||||
cmp [edi + window.data_ptr], 0
|
cmp [edi + window.data_ptr], 0
|
||||||
je .enough
|
je .enough
|
||||||
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
||||||
dec esi
|
dec esi
|
||||||
jnz .more
|
jnz .more
|
||||||
.enough:
|
.enough:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
highlight_updated_tabs:
|
highlight_updated_tabs:
|
||||||
mov eax, 4
|
mov eax, 4
|
||||||
mov ebx, 5 shl 16 + TOP_SPACE + 4 ;;;;
|
mov ebx, 5 shl 16 + TOP_SPACE + 4 ;;;;
|
||||||
mov ecx, 0x80aa0000
|
mov ecx, 0x80aa0000
|
||||||
mov esi, MAX_WINDOWS
|
mov esi, MAX_WINDOWS
|
||||||
mov edi, windows
|
mov edi, windows
|
||||||
.more_:
|
.more_:
|
||||||
test [edi + window.flags], FLAG_UPDATED
|
test [edi + window.flags], FLAG_UPDATED
|
||||||
jz .next
|
jz .next
|
||||||
lea edx, [edi + window.name]
|
lea edx, [edi + window.name]
|
||||||
mcall
|
mcall
|
||||||
.next:
|
.next:
|
||||||
add edi, sizeof.window ; get ptr to next window
|
add edi, sizeof.window ; get ptr to next window
|
||||||
cmp [edi + window.data_ptr], 0
|
cmp [edi + window.data_ptr], 0
|
||||||
je .enough_
|
je .enough_
|
||||||
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
add ebx, (TAB_WIDTH + TAB_SPACE) shl 16
|
||||||
dec esi
|
dec esi
|
||||||
jnz .more_
|
jnz .more_
|
||||||
.enough_:
|
.enough_:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
set_edit_box_and_scrollbar_colors:
|
set_edit_box_and_scrollbar_colors:
|
||||||
mov eax, [colors.work]
|
mov eax, [colors.work]
|
||||||
mov [scroll1.bg_color], eax
|
mov [scroll1.bg_color], eax
|
||||||
mov [scroll2.bg_color], eax
|
mov [scroll2.bg_color], eax
|
||||||
|
|
||||||
mov eax, [colors.work_button]
|
mov eax, [colors.work_button]
|
||||||
mov [scroll1.front_color], eax
|
mov [scroll1.front_color], eax
|
||||||
mov [scroll2.front_color], eax
|
mov [scroll2.front_color], eax
|
||||||
|
|
||||||
mov eax, [colors.work_text]
|
mov eax, [colors.work_text]
|
||||||
mov [scroll1.line_color], eax
|
mov [scroll1.line_color], eax
|
||||||
mov [scroll2.line_color], eax
|
mov [scroll2.line_color], eax
|
||||||
|
|
||||||
mov [scroll1.type], 0 ; 0 = simple, 1 = skinned
|
mov [scroll1.type], 0 ; 0 = simple, 1 = skinned
|
||||||
mov [scroll2.type], 0
|
mov [scroll2.type], 0
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
@ -96,7 +96,7 @@ user_parser:
|
|||||||
.ret:
|
.ret:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Text begins with a '/' lets try to find the command in the lookup table.
|
; Text begins with a '/' let's try to find the command in the lookup table.
|
||||||
.command:
|
.command:
|
||||||
mov eax, dword[user_command+1] ; skip '/'
|
mov eax, dword[user_command+1] ; skip '/'
|
||||||
or eax, 0x20202020 ; convert to lowercase
|
or eax, 0x20202020 ; convert to lowercase
|
||||||
@ -309,7 +309,7 @@ cmd_usr_nick:
|
|||||||
.fail:
|
.fail:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; We arent logged in yet, directly change user_nick field and print notification to user.
|
; We aren't logged in yet, directly change user_nick field and print notification to user.
|
||||||
.dontsend:
|
.dontsend:
|
||||||
mov ecx, MAX_NICK_LEN
|
mov ecx, MAX_NICK_LEN
|
||||||
mov esi, user_command+6
|
mov esi, user_command+6
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,9 @@ https://www.binarytides.com/whois-client-code-in-c-with-linux-sockets/
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/ksys.h>
|
#include <sys/ksys.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <clayer/network.h>
|
#include <clayer/network.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ char* str_copy(char*);
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc , char *argv[])
|
int main(int argc , char *argv[])
|
||||||
{
|
{
|
||||||
char *domain , *data = NULL;
|
char *domain , *data = NULL;
|
||||||
int f_flag=0;
|
int f_flag=0;
|
||||||
|
|
||||||
@ -106,11 +106,11 @@ int get_whois_data(char *domain , char **data)
|
|||||||
// Next line please
|
// Next line please
|
||||||
pch = strtok(NULL , "\n");
|
pch = strtok(NULL , "\n");
|
||||||
}
|
}
|
||||||
// Now we have the TLD whois server in wch , query again
|
// Now we have the TLD whois server in 'wch', query again
|
||||||
//This will provide minimal whois information along with the parent whois server of the specific domain :)
|
// This will provide minimal whois information along with the parent whois server of the specific domain :)
|
||||||
wch = strdup(wch);
|
wch = strdup(wch);
|
||||||
free(response);
|
free(response);
|
||||||
//This should not be necessary , but segmentation fault without this , why ?
|
// This should not be necessary, but segmentation fault without this, why ?
|
||||||
response = NULL;
|
response = NULL;
|
||||||
if(wch != NULL){
|
if(wch != NULL){
|
||||||
fprintf(out,"\nTLD Whois server is : %s" , wch);
|
fprintf(out,"\nTLD Whois server is : %s" , wch);
|
||||||
@ -122,9 +122,9 @@ int get_whois_data(char *domain , char **data)
|
|||||||
fprintf(out, "\nTLD whois server for %s not found\n" , ext);
|
fprintf(out, "\nTLD whois server for %s not found\n" , ext);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
response_2 = strdup(response);
|
response_2 = strdup(response);
|
||||||
|
|
||||||
// Again search for a whois server in this response. :)
|
// Again search for a whois server in this response. :)
|
||||||
pch = strtok(response , "\n");
|
pch = strtok(response , "\n");
|
||||||
while(pch != NULL){
|
while(pch != NULL){
|
||||||
@ -141,11 +141,11 @@ int get_whois_data(char *domain , char **data)
|
|||||||
If a registrar whois server is found then query it
|
If a registrar whois server is found then query it
|
||||||
*/
|
*/
|
||||||
if(wch){
|
if(wch){
|
||||||
// Now we have the registrar whois server , this has the direct full information of the particular domain
|
// Now we have the registrar whois server, this has the direct full information of the particular domain
|
||||||
// so lets query again
|
// so let's query again
|
||||||
|
|
||||||
fprintf(out, "\nRegistrar Whois server is : %s" , wch);
|
fprintf(out, "\nRegistrar Whois server is : %s" , wch);
|
||||||
|
|
||||||
if( whois_query(wch , domain , &response) == EXIT_FAILURE ){
|
if( whois_query(wch , domain , &response) == EXIT_FAILURE ){
|
||||||
fprintf(out, "Whois query failed");
|
fprintf(out, "Whois query failed");
|
||||||
}else{
|
}else{
|
||||||
@ -157,7 +157,7 @@ int get_whois_data(char *domain , char **data)
|
|||||||
*/
|
*/
|
||||||
else{
|
else{
|
||||||
fprintf(out, "%s" , response_2);
|
fprintf(out, "%s" , response_2);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,22 +170,22 @@ int whois_query(char *server , char *query , char **response)
|
|||||||
int sock , read_size , total_size = 0;
|
int sock , read_size , total_size = 0;
|
||||||
int WHOIS_PORT = 43;
|
int WHOIS_PORT = 43;
|
||||||
struct sockaddr dest;
|
struct sockaddr dest;
|
||||||
|
|
||||||
sock = socket(AF_INET4 , SOCK_STREAM , IPPROTO_TCP);
|
sock = socket(AF_INET4 , SOCK_STREAM , IPPROTO_TCP);
|
||||||
|
|
||||||
//Prepare connection structures :)
|
//Prepare connection structures :)
|
||||||
memset(&dest , 0 , sizeof(dest) );
|
memset(&dest , 0 , sizeof(dest) );
|
||||||
dest.sin_family = AF_INET;
|
dest.sin_family = AF_INET;
|
||||||
server = str_copy(server);
|
server = str_copy(server);
|
||||||
|
|
||||||
server[strcspn(server, "\r\n")] = '\0';
|
server[strcspn(server, "\r\n")] = '\0';
|
||||||
fprintf(out, "\nResolving: %s ...\n" , server);
|
fprintf(out, "\nResolving: %s ...\n" , server);
|
||||||
if(hostname_to_ip(server , ip) == EXIT_FAILURE ){
|
if(hostname_to_ip(server , ip) == EXIT_FAILURE ){
|
||||||
fprintf(out, "Failed\n");
|
fprintf(out, "Failed\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(out, "Found ip: %s \n" , ip);
|
fprintf(out, "Found ip: %s \n" , ip);
|
||||||
dest.sin_addr = inet_addr(ip);
|
dest.sin_addr = inet_addr(ip);
|
||||||
dest.sin_port = PORT(WHOIS_PORT);
|
dest.sin_port = PORT(WHOIS_PORT);
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ int whois_query(char *server , char *query , char **response)
|
|||||||
perror("send failed");
|
perror("send failed");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now receive the response
|
//Now receive the response
|
||||||
while((read_size = recv(sock, buffer, sizeof(buffer), 0))){
|
while((read_size = recv(sock, buffer, sizeof(buffer), 0))){
|
||||||
*response = realloc(*response , read_size + total_size);
|
*response = realloc(*response , read_size + total_size);
|
||||||
@ -214,9 +214,9 @@ int whois_query(char *server , char *query , char **response)
|
|||||||
memcpy(*response + total_size , buffer , read_size);
|
memcpy(*response + total_size , buffer , read_size);
|
||||||
total_size += read_size;
|
total_size += read_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(out, "Done\n");
|
fprintf(out, "Done\n");
|
||||||
|
|
||||||
*response = realloc(*response , total_size + 1);
|
*response = realloc(*response , total_size + 1);
|
||||||
*(*response + total_size) = '\0';
|
*(*response + total_size) = '\0';
|
||||||
close(sock);
|
close(sock);
|
||||||
@ -231,7 +231,7 @@ int hostname_to_ip(char *hostname , char *ip)
|
|||||||
char port_str[16]; sprintf(port_str, "%d", 80);
|
char port_str[16]; sprintf(port_str, "%d", 80);
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter
|
hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesn't matter
|
||||||
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
|
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
|
||||||
if (getaddrinfo(hostname, port_str, 0, &addr_info) != 0) {
|
if (getaddrinfo(hostname, port_str, 0, &addr_info) != 0) {
|
||||||
freeaddrinfo(addr_info);
|
freeaddrinfo(addr_info);
|
||||||
@ -248,48 +248,48 @@ char *str_replace(char *search , char *replace , char *subject)
|
|||||||
{
|
{
|
||||||
char *p = NULL , *old = NULL , *new_subject = NULL ;
|
char *p = NULL , *old = NULL , *new_subject = NULL ;
|
||||||
int c = 0 , search_size;
|
int c = 0 , search_size;
|
||||||
|
|
||||||
search_size = strlen(search);
|
search_size = strlen(search);
|
||||||
|
|
||||||
//Count how many occurences
|
//Count how many occurences
|
||||||
for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){
|
for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
//Final size
|
//Final size
|
||||||
c = ( strlen(replace) - search_size )*c + strlen(subject);
|
c = ( strlen(replace) - search_size )*c + strlen(subject);
|
||||||
|
|
||||||
//New subject with new size
|
//New subject with new size
|
||||||
new_subject = malloc( c );
|
new_subject = malloc( c );
|
||||||
|
|
||||||
//Set it to blank
|
//Set it to blank
|
||||||
strcpy(new_subject , "");
|
strcpy(new_subject , "");
|
||||||
|
|
||||||
//The start position
|
//The start position
|
||||||
old = subject;
|
old = subject;
|
||||||
|
|
||||||
for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){
|
for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){
|
||||||
//move ahead and copy some text from original subject , from a certain position
|
//move ahead and copy some text from original subject , from a certain position
|
||||||
strncpy(new_subject + strlen(new_subject) , old , p - old);
|
strncpy(new_subject + strlen(new_subject) , old , p - old);
|
||||||
|
|
||||||
//move ahead and copy the replacement text
|
//move ahead and copy the replacement text
|
||||||
strcpy(new_subject + strlen(new_subject) , replace);
|
strcpy(new_subject + strlen(new_subject) , replace);
|
||||||
|
|
||||||
//The new start position after this search match
|
//The new start position after this search match
|
||||||
old = p + search_size;
|
old = p + search_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copy the part after the last search match
|
//Copy the part after the last search match
|
||||||
strcpy(new_subject + strlen(new_subject) , old);
|
strcpy(new_subject + strlen(new_subject) , old);
|
||||||
|
|
||||||
return new_subject;
|
return new_subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* str_copy(char *source)
|
char* str_copy(char *source)
|
||||||
{
|
{
|
||||||
char *copy = malloc(strlen(source) + 1);
|
char *copy = malloc(strlen(source) + 1);
|
||||||
|
|
||||||
if(copy){
|
if(copy){
|
||||||
strcpy(copy, source);
|
strcpy(copy, source);
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user