Subversion Repositories Kolibri OS

Rev

Rev 1373 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1373 Rev 1514
Line 1... Line 1...
1
use32
1
use32
2
 
-
 
3
	org 0x0
2
    org 0x0
Line 4... Line 3...
4
 
3
 
-
 
4
    db 'MENUET01'
-
 
5
    dd 0x1
-
 
6
    dd START
-
 
7
    dd I_END
5
	db 'MENUET01'
8
    dd IM_END
-
 
9
    dd IM_END
Line 6... Line 10...
6
	dd 1, START, I_END, IM_END+0x1000, IM_END+0x1000, 0, 0
10
    dd 0, 0
7
 
11
 
8
include '../proc32.inc'
-
 
9
include '../macros.inc'
12
include '../proc32.inc'
-
 
13
include '../macros.inc'
10
include '../dll.inc'
14
include '../libio.inc'
Line 11... Line 15...
11
include '../libio.inc'
15
include '../dll.inc'
Line 12... Line 16...
12
include '../../../../../programs/develop/libraries/box_lib/trunk/box_lib.mac'
16
include 'editbox_ex.mac'
13
 
17
 
14
include '../network.inc'
18
include '../network.inc'
Line 15... Line 19...
15
 
19
 
16
 
20
 
Line 17... Line 21...
17
filebuffer_size equ 4*4096 ; 16kb   (dont try to change it yet..)
21
filebuffer_size equ 4*4096 ; 16kb   (dont try to change it yet..)
18
TIMEOUT 	equ 500
22
TIMEOUT 	equ 100
19
buffer_len	equ 1500
23
buffer_len	equ 1500
20
 
24
 
21
AF_INET4	equ 2
25
AF_INET4	equ 2
Line 22... Line 26...
22
IP_PROTO_UDP	equ 17
26
IP_PROTO_UDP	equ 17
23
 
27
 
24
opcode_rrq	equ 1 shl 8
28
opcode_rrq	equ 1
25
opcode_wrq	equ 2 shl 8
29
opcode_wrq	equ 2
Line 49... Line 53...
49
;  ---------------------
53
;  ---------------------
Line 50... Line 54...
50
 
54
 
51
; error packet
55
; error packet
52
;
56
;
53
;  2 bytes  2 bytes        string    1 byte
57
;  2 bytes  2 bytes        string    1 byte
54
;  -----------------------------------------
58
;  ----------------------------------------
55
; | Opcode |  ErrorCode |   ErrMsg   |   0  |
59
; | Opcode |  ErrorCode |   ErrMsg   |   0  |
Line 56... Line 60...
56
;  -----------------------------------------
60
;  ----------------------------------------
Line 57... Line 61...
57
 
61
 
Line 58... Line 62...
58
 
62
 
59
START:
63
START:
60
 
64
 
Line 183... Line 187...
183
 
187
 
Line 184... Line 188...
184
	mcall	38,10*65536+380, 130*65536+130,0x00000000
188
	mcall	38,10*65536+380, 130*65536+130,0x00000000
Line 185... Line 189...
185
 
189
 
Line 186... Line 190...
186
	mcall	4,350*65536+137, 0x80000000, str_kb_s
190
	mcall	4,350*65536+137, 0x80000000, str_kb_s
Line 187... Line 191...
187
 
191
 
Line 188... Line 192...
188
;        mcall   47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000
192
	mcall	47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000
Line 189... Line 193...
189
 
193
 
Line 207... Line 211...
207
	push	esp	; reserve stack place
211
	push	esp	; reserve stack place
Line 208... Line 212...
208
 
212
 
209
	push	esp	; fourth parameter
213
	push	esp	; fourth parameter
210
	push	0	; third parameter
214
	push	0	; third parameter
211
	push	0	; second parameter
215
	push	0	; second parameter
212
	push	SRV	; first parameter
216
	push	dword SRV     ; first parameter
Line 213... Line 217...
213
	call	[getaddrinfo]
217
	call	[getaddrinfo]
Line 214... Line 218...
214
 
218
 
215
	pop	esi	; now we will have pointer to result in esi
219
	pop	esi
216
 
220
 
Line 217... Line 221...
217
; test for error
221
; test for error
218
	test	eax, eax
222
	test	eax, eax
219
	jnz	still
223
	jnz	still
Line 220... Line -...
220
 
-
 
221
	mov	esi, [esi + addrinfo.ai_addr]
-
 
222
	mov	esi, [esi + sockaddr_in.sin_addr]
-
 
223
	mov	dword [IP], esi
-
 
224
 
-
 
225
	stdcall mem.Alloc, buffer_len
-
 
226
	test	eax, eax
-
 
227
	jz	stop_transfer
-
 
228
	mov	[packetbuff], eax
-
 
229
 
-
 
230
	invoke	file_open, local_addr, O_READ + O_WRITE + O_CREATE
-
 
231
	cmp	eax, 32
224
 
232
	jb	stop_transfer
225
	mov	esi, [esi]
233
 
226
	mov	esi, [esi + sockaddr_in.sin_addr]
Line 234... Line 227...
234
	mov	[fh], eax
227
	mov	dword [IP], esi
Line 242... Line 235...
242
	mcall	connect, [socketnum], sockaddr, sockaddr_len	; socket_connect
235
	mcall	connect, [socketnum], sockaddr, sockaddr_len	     ; socket_connect
243
	cmp	eax, -1
236
	cmp	eax, -1
244
	je	still
237
	je	still
Line 245... Line 238...
245
 
238
 
246
	mov	word [I_END], opcode_rrq
239
	mov	word [I_END], opcode_rrq
247
	cmp	[option_group2],op3		; method = get?
240
	cmp	[option_group2],op3
248
	jz	@f
241
	je	@f
249
	mov	word [I_END], opcode_wrq
242
	mov	word [I_END], opcode_wrq
Line 250... Line 243...
250
       @@:
243
      @@:
251
 
244
 
252
	xor	al , al
245
	xor	al , al
253
	mov	edi, remote_addr
246
	mov	edi, remote_addr
254
	mov	ecx, 250
247
	mov	ecx, 250
255
	repnz	scasb
248
	repnz	scasb
256
	sub	edi, remote_addr
249
	sub	edi, remote_addr-1
257
	mov	ecx, edi
250
	mov	ecx, edi
258
	mov	edi, I_END+2
251
	mov	edi, I_END+2
Line 281... Line 274...
281
 
274
 
282
	sub	edi, I_END
275
	sub	edi, I_END
283
	mov	esi, edi
276
	mov	esi, edi
Line -... Line 277...
-
 
277
	mcall	send, [socketnum], I_END
-
 
278
 
284
	mcall	send, [socketnum], I_END
279
	mcall	40, 10000101b
Line 285... Line -...
285
 
-
 
286
	mov	[last_ack], 0
-
 
Line 287... Line -...
287
 
-
 
288
;        mcall   26, 9
-
 
Line 289... Line -...
289
;        mov     [last_time], eax
-
 
Line 290... Line -...
290
 
-
 
291
	mov	[status], str_transfering
-
 
Line 292... Line -...
292
	call	draw_window
-
 
Line 293... Line 280...
293
 
280
 
Line 294... Line 281...
294
	mcall	40, 10000101b
281
	mov	[last_ack], 0
Line 295... Line 282...
295
 
282
 
296
	cmp	[option_group2],op3		; method = get?
283
 
Line 297... Line 284...
297
	jnz	send_data_loop
284
 
298
 
-
 
299
	invoke	file_truncate, [fh]
285
 
-
 
286
 
Line 300... Line 287...
300
 
287
 
Line 301... Line -...
301
receive_data_loop:
-
 
302
 
288
receive_data_loop:
303
	mcall	23, TIMEOUT
289
 
Line 304... Line 290...
304
 
290
	mcall	23, TIMEOUT
305
	dec	eax
-
 
306
	jz	.redraw
-
 
307
 
-
 
308
	dec	eax
291
 
309
	dec	eax
292
	dec	eax
310
	jz	.btn
-
 
311
 
293
	jz	.red
Line 312... Line -...
312
	mcall	recv, [socketnum], [packetbuff], buffer_len ; receive data
-
 
313
 
-
 
314
	mov	esi, [packetbuff]
-
 
315
	cmp	word[esi], opcode_data
-
 
316
	jne	.error
294
 
317
 
-
 
318
	mov	bx, [last_ack]
-
 
319
	inc	bx
-
 
320
	rol	bx, 8
-
 
321
 
295
	dec	eax
Line 322... Line 296...
322
	cmp	word [esi + 2], bx
296
	jz	.key
323
	jne	.packet_got_lost
-
 
324
 
-
 
325
	inc	[last_ack]
-
 
326
 
-
 
327
 
-
 
328
	; now, we need to store the data
-
 
329
 
-
 
330
	add	esi, 4
-
 
331
	sub	eax, 4
-
 
332
	mov	ecx, eax
297
 
Line 333... Line -...
333
	invoke	file_write, [fh], esi ,ecx
-
 
334
 
-
 
335
	cmp	ecx, 512      ; full data packet?
-
 
336
	jge	.continue
-
 
337
 
-
 
338
	; last packet, or something else
298
 
Line 339... Line -...
339
 
-
 
Line 340... Line -...
340
	mov	[status], str_success
-
 
341
 
-
 
342
.kill_xfer:
-
 
343
 
-
 
344
	invoke	file_close, [fh]
-
 
345
	mcall	close, [socketnum]
-
 
346
	jmp	stop_transfer
299
	mcall	recv, [socketnum], buffer, buffer_len, 0  ; receive data
347
 
-
 
348
.error:
-
 
Line 349... Line 300...
349
 
300
 
350
	cmp	word[esi], opcode_error
-
 
351
	je	.decode_error
-
 
352
 
-
 
353
	jmp	.continue
301
	cmp	word[buffer], opcode_data
Line 354... Line 302...
354
 
302
	jne	.error
Line -... Line 303...
-
 
303
 
Line 355... Line -...
355
.packet_got_lost:
-
 
356
 
-
 
357
 
-
 
358
.continue:
-
 
359
 
-
 
360
;        mcall   26, 9
-
 
361
;        mov     ebx, [last_time]
304
	mov	bx, [last_ack]
-
 
305
	cmp	word [buffer + 2], bx
362
;        mov     [last_time], eax
306
	jne	.packet_got_lost
Line 363... Line 307...
363
;        xor     edx, edx
307
	inc	[last_ack]
364
;        sub     eax, ebx
308
 
365
;        xchg    eax, ecx
309
	cmp	eax, 4+512
-
 
310
	je	.continue
-
 
311
 
366
;        div     ecx
312
; last packet, or something else
-
 
313
.error:
-
 
314
 
-
 
315
.packet_got_lost:
Line 367... Line -...
367
;        mov     [kbps], eax
-
 
368
;        mcall   47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x40000000, 0x00ffffff
-
 
Line 369... Line -...
369
 
-
 
Line 370... Line 316...
370
	mov	word [buffer], opcode_ack		 ; send ack
316
 
Line 371... Line 317...
371
	mov	ax, [last_ack]
317
 
Line -... Line 318...
-
 
318
 
-
 
319
.continue:
-
 
320
 
372
	rol	ax, 8
321
	mov	word[buffer], opcode_ack		; send ack
Line -... Line 322...
-
 
322
	mcall	send, [socketnum], buffer, 4, 0
373
	mov	word [buffer+2], ax
323
 
-
 
324
	jmp	receive_data_loop
-
 
325
 
Line 374... Line 326...
374
	mcall	send, [socketnum], buffer, 4, 0
326
.red:
-
 
327
 
Line 375... Line -...
375
 
-
 
376
	jmp	receive_data_loop
328
	call	draw_window
377
 
-
 
Line 378... Line 329...
378
 
329
 
379
.btn:
330
	jmp	receive_data_loop
-
 
331
 
-
 
332
 
-
 
333
.key:
-
 
334
	mcall	2
-
 
335
	cmp	ah, 2
-
 
336
	jz	exit
380
	mcall	17
337
 
-
 
338
	; close socket ?
-
 
339
 
-
 
340
	jmp	receive_data_loop
-
 
341
 
-
 
342
 
-
 
343
 
-
 
344
 
-
 
345
 
-
 
346
 
-
 
347
;--------------------------------
-
 
348
 
-
 
349
 
-
 
350
send_:
-
 
351
 
-
 
352
	invoke	file_open, local_addr, O_READ
-
 
353
	or	eax, eax
Line 381... Line -...
381
 
-
 
382
	jmp	.kill_xfer
354
	jz	.exit
Line 383... Line -...
383
 
-
 
384
.redraw:
-
 
Line 385... Line 355...
385
	call	draw_window
355
	mov	[fh], eax
-
 
356
 
386
	jmp	receive_data_loop
357
	stdcall mem.Alloc, filebuffer_size
Line 387... Line 358...
387
 
358
	or	eax, eax
388
 
359
	jz	.exit
Line 389... Line 360...
389
.decode_error:
360
	mov	[fb], eax
390
	movzx	esi, word[esi + 2]
-
 
391
	cmp	esi, 7
361
 
392
	cmovg	esi, [zero]
-
 
393
 
-
 
394
	mov	esi, dword [4*esi + error_crosslist]
-
 
395
	mov	[status], esi
-
 
396
 
-
 
397
	jmp	.kill_xfer
-
 
Line 398... Line 362...
398
 
362
	mov	[last_ack], 0
399
 
-
 
Line 400... Line 363...
400
 
363
	mov	[fo], 0
401
;--------------------------------
364
 
Line 402... Line 365...
402
 
365
.read_chunk:
403
 
-
 
404
send_data_loop:
366
 
405
 
367
	invoke	file_seek, [fh], [fo], SEEK_END
406
	mov	word[buffer], opcode_data
368
	cmp	eax, -1
407
 
369
	je	.exit
408
.read_chunk:
370
	invoke	file_read, [fh], [fb], filebuffer_size
409
 
-
 
410
	inc	[last_ack]
371
	cmp	eax, -1
Line 411... Line -...
411
 
-
 
Line 412... Line 372...
412
	mov	ax, [last_ack]
372
	je	.exit
413
	xchg	al, ah
-
 
414
	mov	word[buffer+2], ax
-
 
415
 
-
 
416
	invoke	file_read, [fh], buffer + 4, 512
-
 
417
	cmp	eax, -1
-
 
Line -... Line 373...
-
 
373
	add	[fo], filebuffer_size
Line 418... Line 374...
418
	je	.kill_xfer
374
	cmp	eax, filebuffer_size
419
 
-
 
Line 420... Line -...
420
	add	eax, 4
-
 
421
	mov	[packetsize], eax
-
 
422
 
-
 
423
.send_packet:
-
 
Line -... Line 375...
-
 
375
	je	.packet
-
 
376
 
-
 
377
	; ijhidfhfdsndsfqk
-
 
378
 
Line 424... Line -...
424
	mcall	send, [socketnum], buffer, [packetsize], 0	 ; send data
-
 
425
 
-
 
426
.loop:
379
.packet:
Line -... Line 380...
-
 
380
 
Line 427... Line 381...
427
	mcall	23, TIMEOUT
381
	movzx	esi, [last_ack]
428
 
382
	and	esi, 0x000000001f   ; last five bits    BUFFER SIZE MUST BE 16 kb for this to work !!!
429
	dec	eax
383
	shl	esi, 9		    ; = * 512
430
	jz	.red
-
 
Line 431... Line -...
431
 
-
 
432
	dec	eax
-
 
Line 433... Line -...
433
	dec	eax
-
 
Line 434... Line 384...
434
	jz	.btn
384
	add	esi, [fb]
435
 
385
	mov	edi, buffer
Line 498... Line 448...
498
kbps	       dd 0
448
kbps	       dd 0
499
done	       dd 0
449
done	       dd 0
Line 500... Line 450...
500
 
450
 
501
sockaddr:
451
sockaddr:
502
	dw AF_INET4
452
	dw AF_INET4
503
	dw 69 shl 8
453
	dw 69
504
IP	db 192,168,1,115
454
IP	db 192,168,1,115
Line 505... Line 455...
505
sockaddr_len = $ - sockaddr
455
sockaddr_len = $ - sockaddr
506
 
456
 
Line 507... Line 457...
507
align 16
457
align 16
508
@IMPORT:
458
@IMPORT:
509
 
459
 
Line 510... Line 460...
510
library box_lib , 'box_lib.obj',\
460
library box_lib , 'box_lib.obj'
511
	io_lib	, 'libio.obj',\
461
library io_lib	, 'libio.obj'
512
	network , 'network.obj'
462
library network , 'network.obj'
513
 
463
 
Line 542... Line 492...
542
	inet_ntoa	, 'inet_ntoa'		,\
492
	inet_ntoa		, 'inet_ntoa'		,\
543
	getaddrinfo	, 'getaddrinfo' 	,\
493
	getaddrinfo		, 'getaddrinfo' 	,\
544
	freeaddrinfo	, 'freeaddrinfo'
494
	freeaddrinfo		, 'freeaddrinfo'
Line 545... Line -...
545
 
-
 
546
 
495
 
547
 
496
 
548
edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,ed_focus,  13,13
497
edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,ed_focus,  11,11
549
edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,ed_figure_only, 5,5
498
edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,ed_figure_only, 10,10
Line 550... Line 499...
550
edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,ed_figure_only, 13,13
499
edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,ed_figure_only, 27,27
551
edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,ed_figure_only, 3, 3
500
edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,ed_figure_only, 3,3
Line 552... Line 501...
552
 
501
 
553
op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii
502
op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii
Line 554... Line 503...
554
op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet
503
op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet
555
 
504
 
556
op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get
-
 
557
op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put
505
op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get
558
 
506
op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put
Line 559... Line 507...
559
option_group1	dd op1
507
 
560
option_group2	dd op3
508
option_group1	dd op1
Line 570... Line 518...
570
str_method	db 'Method:',0
518
str_method	db 'Method:',0
571
str_blocksize	db 'Blocksize:',0
519
str_blocksize	db 'Blocksize:',0
572
str_kb_s	db 'kb/s',0
520
str_kb_s	db 'kb/s',0
573
str_complete	db '% complete',0
521
str_complete	db '% complete',0
574
str_transfer	db 'Transfer',0
522
str_transfer	db 'Transfer',0
575
str_waiting	db 'Welcome!',0
-
 
576
str_transfering db 'Transfering...',0
-
 
577
 
-
 
578
str_success	db 'Tranfser completed sucessfully',0
-
 
579
str_fail	db 'Transfer failed!',0
-
 
Line 580... Line 523...
580
 
523
 
581
str_error:
524
str_error:
582
._0 db 'Not defined, see error message (if any).',0
525
._0 db 'Not defined, see error message (if any).',0
583
._1 db 'File not found.',0
526
._1 db 'File not found.',0
Line 587... Line 530...
587
._5 db 'Unknown transfer ID.',0
530
._5 db 'Unknown transfer ID.',0
588
._6 db 'File already exists.',0
531
._6 db 'File already exists.',0
589
._7 db 'No such user.',0
532
._7 db 'No such user.',0
Line 590... Line -...
590
 
-
 
591
 
-
 
592
error_crosslist:
-
 
593
dd	str_error._0
-
 
594
dd	str_error._1
-
 
595
dd	str_error._2
-
 
596
dd	str_error._3
-
 
597
dd	str_error._4
-
 
598
dd	str_error._5
-
 
599
dd	str_error._6
-
 
600
dd	str_error._7
-
 
601
 
-
 
602
 
533
 
603
 
534
 
604
netascii db 'NetASCII'
535
netascii db 'NetASCII'
605
octet	 db 'Octet'
536
octet	 db 'Octet'
Line 606... Line 537...
606
get	 db 'GET'
537
get	 db 'GET'
Line 607... Line 538...
607
put	 db 'PUT'
538
put	 db 'PUT'
Line 608... Line 539...
608
 
539
 
609
BLK	 db "512",0,0,0
-
 
610
 
540
BLK	 db "512",0,0,0
611
last_ack dw ?
-
 
612
 
-
 
613
fh	 dd ?	; file handle
-
 
614
 
541
 
615
last_time dd ?
-
 
Line 616... Line 542...
616
 
542
last_ack dw ?
617
packetbuff	dd	?
543
 
Line 618... Line 544...
618
packetsize	dd	?
544
fh	 dd ?	; file handle
619
status		dd	str_waiting
545
fo	 dd ?	; file offset
Line 620... Line 546...
620
zero		dd	0
546
fb	 dd ?	; file buffer
621
 
547
 
Line 622... Line 548...
622
SRV db "192.168.1.115",0
548
SRV db "192.168.1.115",0
623
times (SRV + 256 - $) db 0
-
 
624
 
549
rb (SRV + 256 - $)
625
remote_addr db "3.png",0
550
 
Line 626... Line 551...
626
times (remote_addr + 256 - $) db 0
551
remote_addr db "IMG00",0
627
 
552
rb (remote_addr + 256 - $)