Subversion Repositories Kolibri OS

Rev

Rev 2127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1646 mario79 1
; version: 0.5
2
; last update:  07/10/2010
3
; written by:   Marat Zakiyanov aka Mario79, aka Mario
4
; changes:      reducing the size of the binary code,
5
;               program uses far less memory while running
6
;               (>0x7000, the old version used >0x100000),
7
;               process only net event at start with parameter
8
;-----------------------------------------------------------
9
; version 0.3 -0.4
10
; written by:   CleverMouse
11
;
12
;-----------------------------------------------------------
1645 clevermous 13
; wget 0.2 by barsuk
14
; based on Menuet Httpc
31 halyavin 15
 
16
 
17
; Enabling debugging puts stuff to the debug board
1646 mario79 18
DEBUGGING_ENABLED	equ 1
19
DEBUGGING_DISABLED	equ 0
20
DEBUGGING_STATE		equ DEBUGGING_ENABLED
31 halyavin 21
 
22
use32
1646 mario79 23
	org	0x0
24
	db 'MENUET01'	; header
25
	dd 0x01		; header version
26
	dd START	; entry point
27
	dd IM_END	; image size
28
	dd I_END	;0x100000 ; required memory
29
	dd stacktop	; esp
30
	dd params	; I_PARAM
31
	dd 0x0		; I_Path
31 halyavin 32
 
1646 mario79 33
include	'lang.inc'
34
include	'../../../macros.inc'
35
include	"../../../proc32.inc"
36
include	"dll.inc"
37
include	"debug.inc"
31 halyavin 38
 
1646 mario79 39
URLMAXLEN	equ 256	; maximum length of url string
31 halyavin 40
 
1646 mario79 41
primary_buffer_size	equ 4096
1645 clevermous 42
 
31 halyavin 43
; Memory usage
1645 clevermous 44
; webpage headers at buf_headers
31 halyavin 45
 
1646 mario79 46
START:	; start of execution
47
;dps	<"Program started",13,10>
48
; prepare webAddr area
49
	mov	al,' '
50
	mov	edi,webAddr
51
	mov	ecx,URLMAXLEN
52
	cld
53
	rep	stosb
54
	xor	eax,eax
55
	stosb
56
; prepare document area
57
	mov	al,'/'
58
	mov	edi,document
59
	cld
60
	stosb
61
	mov	al,' '
62
	mov	ecx,URLMAXLEN-1
63
	rep	stosb
31 halyavin 64
 
1646 mario79 65
; create local heap
66
	mcall	68,11
31 halyavin 67
 
1646 mario79 68
	call	load_settings
69
	cmp	[params],byte 0
70
	jz	prepare_event	;red
71
 
72
	mcall	40,10000000b ; only net event!!!
73
 
74
; we have an url
75
	mov	edi,document_user
76
	mov	al,' '
77
	mov	ecx,URLMAXLEN
78
	rep	stosb
1645 clevermous 79
 
1646 mario79 80
	mov	esi,params
81
	mov	edi,document_user
82
 
1645 clevermous 83
.copy_param:
1646 mario79 84
	mov	al,[esi]
85
	cmp	al,0
86
	jz	.done
87
 
88
	cmp	al,' '
89
	jz	.done_inc
90
 
91
	mov	[edi],al
92
	inc	esi
93
	inc	edi
94
	jmp	.copy_param
95
 
1645 clevermous 96
.done_inc:
1646 mario79 97
; url is followed by shared memory name.
98
	inc	esi
1645 clevermous 99
.done:
1646 mario79 100
	mov	[shared_name],esi
31 halyavin 101
 
1646 mario79 102
	mov	ah,22	; strange way to tell that socket should be opened...
1645 clevermous 103
	call	socket_commands
31 halyavin 104
 
1646 mario79 105
	jmp	still
31 halyavin 106
 
1646 mario79 107
prepare_event:
108
; Report events
109
; Stack 8 + defaults
110
	mcall	40,10000111b
31 halyavin 111
 
1646 mario79 112
red:	; redraw
113
	call	draw_window
31 halyavin 114
 
1646 mario79 115
still:
116
	mcall	23,1	; wait here for event
117
	cmp	eax,1	; redraw request ?
118
	je	red
31 halyavin 119
 
1646 mario79 120
	cmp	eax,2	; key in buffer ?
121
	je	key
31 halyavin 122
 
1646 mario79 123
	cmp	eax,3	; button in buffer ?
124
	je	button
31 halyavin 125
 
1646 mario79 126
; Get the web page data from the remote server
127
	call	read_incoming_data
128
	mov	eax,[status]
129
	mov	[prev_status],eax
130
	mcall	53,6,[socket]
131
	mov	[status],eax
31 halyavin 132
 
1646 mario79 133
	cmp	[prev_status],4
134
	jge	no_send
31 halyavin 135
 
1646 mario79 136
	cmp	[status],4
137
	jne	no_send
31 halyavin 138
 
1646 mario79 139
	mov	[onoff],1
140
	call	send_request
31 halyavin 141
 
1646 mario79 142
no_send:
143
	call	print_status
31 halyavin 144
 
1646 mario79 145
	cmp	[prev_status],4
146
	jne	no_close
147
	cmp	[status],4	; connection closed by server
148
	jbe	no_close	; respond to connection close command
149
; draw page
150
	call	read_incoming_data
151
	mcall	53,8,[socket]
152
	call	draw_page
153
	mov	[onoff],0
31 halyavin 154
 
155
no_close:
1646 mario79 156
	jmp	still
31 halyavin 157
 
1646 mario79 158
key:	; key
159
	mcall	2	; just read it and ignore
160
	shr	eax,8
161
	cmp	eax,184
162
	jne	no_down
163
	cmp	[display_from],25
164
	jb	no_down
165
	sub	[display_from],25
166
	call	display_page
31 halyavin 167
 
168
no_down:
1646 mario79 169
	cmp	eax,183
170
	jne	no_up
171
	add	[display_from],25
172
	call	display_page
31 halyavin 173
 
174
no_up:
1646 mario79 175
	jmp	still
31 halyavin 176
 
1646 mario79 177
button:	; button
178
;dps	<"Button pressed",13,10>
179
	mcall	17	; get id
180
	cmp	ah,26
181
	je	save
182
	cmp	ah,1	; button id=1 ?
183
	jne	noclose
184
;	dps	"Closing socket before exit... "
31 halyavin 185
 
1645 clevermous 186
close_end_exit:
31 halyavin 187
 
1646 mario79 188
;dpd	eax
189
;dps	<13,10>
31 halyavin 190
 
191
exit:
1646 mario79 192
	or	eax,-1	; close this program
193
	mcall
31 halyavin 194
 
1645 clevermous 195
save:
1646 mario79 196
dps	"saving"
1645 clevermous 197
newline
1646 mario79 198
	mcall	70,fileinfo
1645 clevermous 199
;pregs
1646 mario79 200
	jmp	still
1645 clevermous 201
 
31 halyavin 202
noclose:
1646 mario79 203
	cmp	ah,31
204
	jne	noup
205
	sub	[display_from],20
206
	call	display_page
207
	jmp	still
31 halyavin 208
 
209
noup:
1646 mario79 210
	cmp	ah,32
211
	jne	nodown
212
	add	[display_from],20
213
	call	display_page
214
	jmp	still
31 halyavin 215
 
216
nodown:
1646 mario79 217
	cmp	ah,10	; Enter url
218
	jne	nourl
31 halyavin 219
 
1646 mario79 220
	mov	[addr],dword document_user
221
	mov	[ya],dword 38
222
	mov	[len],dword URLMAXLEN
31 halyavin 223
 
1646 mario79 224
	mov	ecx,URLMAXLEN
225
	mov	edi,[addr]
226
	mov	al,' '
227
	rep	stosb
31 halyavin 228
 
1646 mario79 229
	call	print_text
31 halyavin 230
 
1646 mario79 231
	mov	edi,[addr]
31 halyavin 232
 
233
f11:
1646 mario79 234
	mcall	10
235
	cmp	eax,2	; key?
236
	jz	fbu
237
	jmp	still
31 halyavin 238
 
239
fbu:
1646 mario79 240
	mcall	2	; get key
241
	shr	eax,8
242
	cmp	eax,8
243
	jnz	nobs
244
	cmp	edi,[addr]
245
	jz	f11
246
	sub	edi,1
247
	mov	[edi],byte ' '
248
	call	print_text
249
	jmp	f11
31 halyavin 250
 
251
nobs:
1646 mario79 252
	cmp	eax,10
253
	je	retkey
254
	cmp	eax,13
255
	je	retkey
31 halyavin 256
 
1646 mario79 257
	cmp	eax,31
258
	jbe	f11
31 halyavin 259
 
260
; Removed in v0.4
1646 mario79 261
;	cmp	eax,95
262
;	jb	keyok
263
;	sub	eax,32
31 halyavin 264
 
265
keyok:
1646 mario79 266
	mov	[edi],al
267
	call	print_text
268
	add	edi,1
269
	mov	esi,[addr]
270
	add	esi,URLMAXLEN
271
	cmp	esi,edi
272
	jnz	f11
273
	jmp	still
31 halyavin 274
 
275
retkey:
1646 mario79 276
	mov	ah,22	; start load
31 halyavin 277
 
278
nourl:
1646 mario79 279
	call	socket_commands	; opens or closes the connection
280
	jmp	still
31 halyavin 281
 
282
;****************************************************************************
283
;    Function
284
;       send_request
285
;
286
;   Description
287
;       Transmits the GET request to the server.
1645 clevermous 288
;       This is done as GET then URL then HTTP/1.1',13,10,13,10 in 3 packets
31 halyavin 289
;
290
;****************************************************************************
291
send_request:
1646 mario79 292
	pusha
293
	mov	esi,string0
294
	mov	edi,request
1645 clevermous 295
	movsd
1646 mario79 296
; If proxy is used, make absolute URI - prepend http://
297
	cmp	[proxyAddr],byte 0
298
	jz	.noproxy
299
	mov	dword [edi],'http'
300
	mov	[edi+4],byte ':'
301
	mov	[edi+5],word '//'
302
	add	edi,7
303
	mov	esi,webAddr
31 halyavin 304
 
1645 clevermous 305
.copy_host_loop:
306
	lodsb
1646 mario79 307
	cmp	al,' '
308
	jz	.noproxy
1645 clevermous 309
	stosb
1646 mario79 310
	jmp	.copy_host_loop
311
 
1645 clevermous 312
.noproxy:
1646 mario79 313
	xor	edx,edx ; 0
314
 
1645 clevermous 315
.next_edx:
1646 mario79 316
; Determine the length of the url to send in the GET request
317
	mov	al,[edx+document]
318
	cmp	al,' '
319
	je	.document_done
320
	mov	[edi],al
321
	inc	edi
322
	inc	edx
323
	jmp	.next_edx
324
 
1645 clevermous 325
.document_done:
1646 mario79 326
	mov	esi,stringh
327
	mov	ecx,stringh_end-stringh
328
	rep	movsb
329
	xor	edx,edx	; 0
31 halyavin 330
 
1646 mario79 331
.webaddr_next:
332
	mov	al,[webAddr + edx]
333
	cmp	al,' '
334
	je	.webaddr_done
335
	mov	[edi],al
336
	inc	edi
337
	inc	edx
338
	jmp	.webaddr_next
31 halyavin 339
 
1645 clevermous 340
.webaddr_done:
1646 mario79 341
	cmp	[proxyUser],byte 0
342
	jz	@f
343
	call	append_proxy_auth_header
1645 clevermous 344
@@:
1646 mario79 345
	mov	esi,connclose
346
	mov	ecx,connclose_end-connclose
347
	rep	movsb
1645 clevermous 348
 
349
	pusha
1646 mario79 350
	mov	eax,63
351
	mov	ebx,1
352
	mov	edx,request
1645 clevermous 353
@@:
1646 mario79 354
	mov	cl,[edx]
355
	cmp	edx,edi
356
	jz	@f
357
	mcall
358
	inc	edx
359
	jmp	@b
1645 clevermous 360
@@:
361
	popa
362
 
1646 mario79 363
	mov	edx,edi
364
	sub	edx,request
365
;;;;now write \r\nConnection: Close \r\n\r\n
366
	mcall	53,7,[socket],,request	;' HTTP/1.1 .. '
367
	popa
368
	ret
1645 clevermous 369
 
31 halyavin 370
;****************************************************************************
371
;    Function
372
;       print_status
373
;
374
;   Description
375
;       displays the socket/data received status information
376
;
377
;****************************************************************************
378
print_status:
1646 mario79 379
	pusha
380
	mcall	26,9
381
	cmp	eax,[nextupdate]
382
	jb	status_return
31 halyavin 383
 
1646 mario79 384
	add	eax,25
385
	mov	[nextupdate],eax
31 halyavin 386
 
1646 mario79 387
	mov	ecx,[winys]
388
	shl	ecx,16
389
	add	ecx,-18*65536+10
390
	mcall	13,<5,100>,,0xffffff
31 halyavin 391
 
1646 mario79 392
	mov	edx,12*65536-18
393
	add	edx,[winys]
394
	xor	esi,esi
395
	mcall	47,<3,0>,[status],,
31 halyavin 396
 
1646 mario79 397
	mov	edx,40*65536-18
398
	add	edx,[winys]
399
	mcall	,<6,0>,[pos]
31 halyavin 400
 
401
status_return:
1646 mario79 402
	popa
403
	ret
31 halyavin 404
 
405
;****************************************************************************
406
;    Function
407
;       read_incoming_data
408
;
409
;   Description
410
;       receive the web page from the server, storing it without processing
411
;
412
;****************************************************************************
413
read_incoming_data:
1646 mario79 414
	cmp	[onoff],1
415
	je	rid
416
	ret
31 halyavin 417
 
418
rid:
1645 clevermous 419
	push	esi
420
	push	edi
1646 mario79 421
dps	"rid"
1645 clevermous 422
newline
423
 
31 halyavin 424
newbyteread:
1645 clevermous 425
	;call	print_status
1646 mario79 426
	mcall	53,2,[socket]
427
	cmp	eax,0
428
	je	no_more_data
1645 clevermous 429
 
1646 mario79 430
	mcall	53,11,[socket],primary_buf,primary_buffer_size
1645 clevermous 431
 
1646 mario79 432
;dps	"part "
433
;dph	eax
1645 clevermous 434
;newline
1646 mario79 435
	mov	edi,[pos]
436
	add	[pos],eax
1645 clevermous 437
	push	eax
1646 mario79 438
	mcall	68,20,[pos],[buf_ptr]
439
	mov	[buf_ptr],eax
440
	add	edi,eax
441
	mov	esi,primary_buf
442
	pop	ecx	; number of recently read bytes
443
	lea	edx,[ecx - 3]
444
	rep	movsb
1645 clevermous 445
 
31 halyavin 446
no_more_data:
1646 mario79 447
	mcall	53,6,[socket]
448
	cmp	eax,4
449
	jne	no_more_data.finish
450
	jmp	newbyteread
31 halyavin 451
 
1645 clevermous 452
.finish:
1646 mario79 453
;dps	"finish	"
1645 clevermous 454
;pregs
455
	call	parse_result
1646 mario79 456
	mov	ecx,[shared_name]
2579 clevermous 457
	test	ecx, ecx
458
	jz	@f
1646 mario79 459
	cmp	[ecx],byte 0
460
	jnz	save_in_shared
2579 clevermous 461
@@:
31 halyavin 462
 
1646 mario79 463
	mcall	70,fileinfo
464
;dps	"saving "
1645 clevermous 465
;pregs
1646 mario79 466
;	jmp	close_end_exit
467
	pop	edi
468
	pop	esi
469
; if called from command line, then exit
470
	cmp	[params],byte 0
471
	jnz	exit
472
	ret
1645 clevermous 473
 
474
save_in_shared:
1646 mario79 475
	mov	esi,1	; SHM_OPEN+SHM_WRITE
476
	mcall	68,22
477
	test	eax,eax
1645 clevermous 478
	jz	save_in_shared_done
1646 mario79 479
 
480
	sub	edx,4
1645 clevermous 481
	jbe	save_in_shared_done
1646 mario79 482
 
483
	mov	ecx,[final_size]
484
	cmp	ecx,edx
1645 clevermous 485
	jb	@f
1646 mario79 486
 
487
	mov	ecx,edx
1645 clevermous 488
@@:
1646 mario79 489
	mov	[eax],ecx
490
	lea	edi,[eax+4]
491
	mov	esi,[final_buffer]
492
	mov	edx,ecx
493
	shr	ecx,2
1645 clevermous 494
	rep	movsd
1646 mario79 495
	mov	ecx,edx
496
	and	ecx,3
1645 clevermous 497
	rep	movsb
1646 mario79 498
 
1645 clevermous 499
save_in_shared_done:
500
	pop	edi
501
	pop	esi
502
	jmp	exit
503
 
1646 mario79 504
; this function cuts header, and removes chunk sizes if doc is chunked
505
; in: buf_ptr, pos; out: buf_ptr, pos.
1645 clevermous 506
 
507
parse_result:
1646 mario79 508
; close socket
509
	mcall	53,8,[socket]
1645 clevermous 510
 
1646 mario79 511
dps	"close	socket: "
512
dph	eax
1645 clevermous 513
newline
1646 mario79 514
	mov	edi,[buf_ptr]
515
	mov	edx,[pos]
516
	mov	[buf_size],edx
517
;	mcall	70,fileinfo_tmp
518
dps	"pos = "
519
dph	edx
1645 clevermous 520
newline
31 halyavin 521
 
1646 mario79 522
; first, find end of headers
1645 clevermous 523
.next_byte:
1646 mario79 524
	cmp	[edi],dword 0x0d0a0d0a	; мне лень читать стандарт, пусть будут оба варианта
525
	je	.end_of_headers
526
	cmp	[edi],dword 0x0a0d0a0d
527
	je	.end_of_headers
528
	inc	edi
529
	dec	edx
530
	jne	.next_byte
531
; no end of headers. it's an error. let client see all those headers.
1645 clevermous 532
	ret
1646 mario79 533
 
1645 clevermous 534
.end_of_headers:
1646 mario79 535
; here we look at headers and search content-length or transfer-encoding headers
536
;dps	"eoh "
1645 clevermous 537
;newline
1646 mario79 538
	sub	edi,[buf_ptr]
2126 clevermous 539
	add	edi,4
1646 mario79 540
	mov	[body_pos],edi	; store position where document body starts
541
	mov	[is_chunked],0
542
; find content-length in headers
543
; not good method, but should work for 'Content-Length:'
544
	mov	esi,[buf_ptr]
545
	mov	edi,s_contentlength
546
	mov	ebx,[body_pos]
547
	xor	edx,edx	; 0
1645 clevermous 548
.cl_next:
1646 mario79 549
	mov	al,[esi]
550
	cmp	al,[edi + edx]
551
	jne	.cl_fail
552
	inc	edx
553
	cmp	edx,len_contentlength
554
	je	.cl_found
555
	jmp	.cl_incr
1645 clevermous 556
.cl_fail:
1646 mario79 557
	xor	edx,edx	; 0
1645 clevermous 558
.cl_incr:
1646 mario79 559
	inc	esi
560
	dec	ebx
561
	je	.cl_error
562
	jmp	.cl_next
1645 clevermous 563
.cl_error:
564
;pregs
565
;newline
1646 mario79 566
;dph	esi
1645 clevermous 567
;dps	" content-length not found "
1646 mario79 568
; find 'chunked'
569
; да, я копирую код, это ужасно, но мне хочется, чтобы поскорее заработало
570
; а там уж отрефакторю
571
	mov	esi,[buf_ptr]
572
	mov	edi,s_chunked
573
	mov	ebx,[body_pos]
574
	xor	edx,edx	; 0
31 halyavin 575
 
1645 clevermous 576
.ch_next:
1646 mario79 577
	mov	al,[esi]
578
	cmp	al,[edi + edx]
579
	jne	.ch_fail
580
	inc	edx
581
	cmp	edx,len_chunked
582
	je	.ch_found
583
	jmp	.ch_incr
584
 
1645 clevermous 585
.ch_fail:
1646 mario79 586
	xor	edx,edx	; 0
587
 
1645 clevermous 588
.ch_incr:
1646 mario79 589
	inc	esi
590
	dec	ebx
591
	je	.ch_error
592
	jmp	.ch_next
593
 
1645 clevermous 594
.ch_error:
1646 mario79 595
; if neither of the 2 headers is found, it's an error
596
;dps	"transfer-encoding: chunked not found "
597
	mov	eax,[pos]
598
	sub	eax,[body_pos]
599
	jmp	.write_final_size
31 halyavin 600
 
1645 clevermous 601
.ch_found:
1646 mario79 602
	mov	[is_chunked],1
603
	mov	eax,[body_pos]
604
	add	eax,[buf_ptr]
605
	sub	eax,2
606
	mov	[prev_chunk_end],eax
607
	jmp	parse_chunks
1645 clevermous 608
 
609
.cl_found:
1646 mario79 610
	call	read_number	; eax = number from *esi
611
 
1645 clevermous 612
.write_final_size:
1646 mario79 613
	mov	[final_size],eax	; if this works, i will b very happy...
1645 clevermous 614
 
1646 mario79 615
	mov	ebx,[pos]	; we well check if it is right
616
	sub	ebx,[body_pos]
31 halyavin 617
 
1646 mario79 618
;dps	"check cl eax==ebx "
1645 clevermous 619
;pregs
31 halyavin 620
 
1646 mario79 621
; everything is ok, so we return
622
	mov	eax,[body_pos]
623
	mov	ebx,[buf_ptr]
624
	add	ebx,eax
625
	mov	[final_buffer],ebx
626
;	mov	ebx,[pos]
627
;	sub	ebx,eax
628
;	mov	[final_size],ebx
1645 clevermous 629
	ret
630
 
631
parse_chunks:
1646 mario79 632
;dps	"parse chunks"
1645 clevermous 633
;newline
634
	; we have to look through the data and remove sizes of chunks we see
635
	; 1. read size of next chunk
636
	; 2. if 0, it's end. if not, continue.
637
	; 3. make a good buffer and copy a chunk there
1646 mario79 638
	xor	eax,eax
639
	mov	[final_buffer],eax	; 0
640
	mov	[final_size],eax	; 0
1645 clevermous 641
 
642
.read_size:
1646 mario79 643
	mov	eax,[prev_chunk_end]
644
	mov	ebx,eax
645
	sub	ebx,[buf_ptr]
646
	mov	edx,eax
647
;dps	"rs "
1645 clevermous 648
;pregs
1646 mario79 649
	cmp	ebx,[pos]
650
	jae	chunks_end	; not good
1645 clevermous 651
 
1646 mario79 652
	call	read_hex	; in: eax=pointer to text. out:eax=hex number,ebx=end of text.
653
	cmp	eax,0
654
	jz	chunks_end
31 halyavin 655
 
1646 mario79 656
	add	ebx,1
657
	mov	edx,ebx	; edx = size of size of chunk
1645 clevermous 658
 
1646 mario79 659
	add	ebx,eax
660
	mov	[prev_chunk_end],ebx
1645 clevermous 661
 
1646 mario79 662
;dps	"sz "
1645 clevermous 663
;pregs
1646 mario79 664
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
665
; realloc final buffer
1645 clevermous 666
	push	eax
667
	push	edx
668
	push	dword [final_size]
1646 mario79 669
	add	[final_size],eax
670
	mcall	68,20,[final_size],[final_buffer]
671
	mov	[final_buffer],eax
672
;dps	"re "
1645 clevermous 673
;pregs
1646 mario79 674
	pop	edi
675
	pop	esi
676
	pop	ecx
677
;	add	[pos],ecx
678
	add	edi,[final_buffer]
679
;dps	"cp "
1645 clevermous 680
;pregs
1646 mario79 681
	rep	movsb
682
	jmp	.read_size
1645 clevermous 683
 
684
chunks_end:
1646 mario79 685
; free old buffer
686
dps	"chunks end"
1645 clevermous 687
newline
1646 mario79 688
	mcall	68,13,[buf_ptr]
689
; done!
1645 clevermous 690
	ret
1646 mario79 691
 
1645 clevermous 692
; reads content-length from [edi+ecx], result in eax
693
read_number:
1646 mario79 694
	push	ebx
695
	xor	eax,eax
696
	xor	ebx,ebx
31 halyavin 697
 
1645 clevermous 698
.next:
1646 mario79 699
	mov	bl,[esi]
700
;dph	ebx
701
	cmp	bl,'0'
702
	jb	.not_number
703
	cmp	bl,'9'
704
	ja	.not_number
705
	sub	bl,'0'
706
	shl	eax,1
707
	lea	eax,[eax + eax * 4]	; eax *= 10
708
	add	eax,ebx
709
 
1645 clevermous 710
.not_number:
1646 mario79 711
	cmp	bl,13
712
	jz	.done
713
	inc	esi
714
	jmp	.next
715
 
1645 clevermous 716
.done:
1646 mario79 717
	pop	ebx
1645 clevermous 718
;newline
1646 mario79 719
;dps	"strtoint eax "
1645 clevermous 720
;pregs
721
	ret
722
 
1646 mario79 723
; reads hex from eax,result in eax,end of text in ebx
1645 clevermous 724
read_hex:
1646 mario79 725
	add	eax,2
726
	mov	ebx,eax
727
	mov	eax,[ebx]
728
	mov	[deba],eax
1645 clevermous 729
;	pushf
1646 mario79 730
;	pushad
731
;	mov	edx,deba
732
;	call	debug_outstr
733
;	popad
734
;	popf
735
	xor	eax,eax
736
	xor	ecx,ecx
1645 clevermous 737
.next:
1646 mario79 738
	mov	cl,[ebx]
739
	inc	ebx
1645 clevermous 740
 
1646 mario79 741
	cmp	cl,0x0d
742
	jz	.done
743
;dph	ebx
744
	or	cl,0x20
745
	sub	cl,'0'
746
	jb	.bad
747
 
748
	cmp	cl,0x9
749
	jbe	.adding
750
 
751
	sub	cl,'a'-'0'-10
752
	cmp	cl,0x0a
753
	jb	.bad
754
 
755
	cmp	cl,0x0f
756
	ja	.bad
757
 
1645 clevermous 758
.adding:
1646 mario79 759
	shl	eax,4
760
	or	eax,ecx
761
;	jmp	.not_number
1645 clevermous 762
;.bad:
763
.bad:
1646 mario79 764
	jmp	.next
1645 clevermous 765
.done:
766
;newline
1646 mario79 767
;dps	"hextoint eax "
1645 clevermous 768
;pregs
769
	ret
31 halyavin 770
 
1645 clevermous 771
;****************************************************************************
772
;    Function
773
;       draw_page
774
;
775
;   Description
776
;       parses the web page data, storing displayable data at 0x20000
777
;       and attributes at 0x30000. It then calls display_page to render
778
;       the data
779
;
780
;****************************************************************************
781
draw_page:
782
	ret
31 halyavin 783
 
784
;****************************************************************************
785
;    Function
786
;       linefeed
787
;
788
;   Description
789
;
790
;
791
;****************************************************************************
792
linefeed:
1646 mario79 793
	ret
31 halyavin 794
 
795
;****************************************************************************
796
;    Function
797
;       display_page
798
;
799
;   Description
800
;       Renders the text decoded by draw_page
801
;
802
;****************************************************************************
803
display_page:
1646 mario79 804
	ret
31 halyavin 805
 
806
;****************************************************************************
807
;    Function
808
;       socket_commands
809
;
810
;   Description
811
;       opens or closes the socket
812
;
813
;****************************************************************************
814
socket_commands:
1646 mario79 815
	cmp	ah,22	; open socket
816
	jnz	tst3
31 halyavin 817
 
1646 mario79 818
dps	"opening socket"
819
newline
820
; Clear all page memory
821
	xor	eax,eax
822
	mov	[prev_chunk_end],eax	; 0
823
	cmp	[buf_ptr],eax	; 0
824
	jz	no_free
825
 
826
	mcall	68,13,[buf_ptr]	; free	buffer
827
 
1645 clevermous 828
no_free:
1646 mario79 829
	xor	eax,eax
830
	mov	[buf_size],eax	; 0
831
; Parse the entered url
832
	call	parse_url
833
; Get a free port number
834
	mov	ecx,1000	; local port starting at 1000
31 halyavin 835
 
836
getlp1:
1646 mario79 837
	inc	ecx
838
	push	ecx
839
	mcall	53,9
840
	pop	ecx
841
	cmp	eax,0	; is this local port in use?
842
	jz	getlp1	; yes - so try next
31 halyavin 843
 
1646 mario79 844
	mov	edx,80
845
	cmp	[proxyAddr],byte 0
846
	jz	sc000
847
	mov	edx,[proxyPort]
1645 clevermous 848
sc000:
1646 mario79 849
	mcall	53,5,,,[server_ip],1
850
	mov	[socket],eax
851
	mov	[pagexs],80
1645 clevermous 852
 
1646 mario79 853
	push	eax
854
	xor	eax,eax ; 0
855
	mov	[pos],eax
856
	mov	[pagex],eax
857
	mov	[pagey],eax
858
	mov	[command_on_off],eax
859
	mov	[is_body],eax
860
	pop	eax
861
	ret
31 halyavin 862
 
863
tst3:
1646 mario79 864
	cmp	ah,24	; close	socket
865
	jnz	no_24
31 halyavin 866
 
1646 mario79 867
	mcall	53,8,[socket]
868
	call	draw_page
31 halyavin 869
no_24:
1646 mario79 870
	ret
31 halyavin 871
 
872
;****************************************************************************
873
;    Function
874
;       parse_url
875
;
876
;   Description
877
;       parses the full url typed in by the user into a web address ( that
878
;       can be turned into an IP address by DNS ) and the page to display
879
;       DNS will be used to translate the web address into an IP address, if
880
;       needed.
881
;       url is at document_user and will be space terminated.
882
;       web address goes to webAddr and is space terminated.
883
;       ip address goes to server_ip
884
;       page goes to document and is space terminated.
885
;
886
;       Supported formats:
887
;       address
888
;        is optional, removed and ignored - only http supported
889
;       
is required. It can be an ip address or web address
890
;        is optional and must start with a leading / character
891
;
892
;****************************************************************************
893
parse_url:
1646 mario79 894
; First, reset destination variables
895
	cld
896
	mov	al,' '
897
	mov	edi,document
898
	mov	ecx,URLMAXLEN
899
	rep	stosb
900
	mov	edi,webAddr
901
	mov	ecx,URLMAXLEN
902
	rep	stosb
1645 clevermous 903
 
1646 mario79 904
	mov	al,'/'
905
	mov	[document],al
31 halyavin 906
 
1646 mario79 907
	mov	esi,document_user
908
; remove any leading protocol text
909
	mov	ecx,URLMAXLEN
910
	mov	ax,'//'
31 halyavin 911
 
912
pu_000:
1646 mario79 913
	cmp	[esi],byte ' '	; end of text?
914
	je	pu_002		; yep, so not found
915
	cmp	[esi],ax
916
	je	pu_001	; Found it, so esi+2 is start
917
	inc	esi
918
	loop	pu_000
31 halyavin 919
 
920
pu_002:
1646 mario79 921
; not found, so reset esi to start
922
	mov	esi,document_user-2
31 halyavin 923
 
924
pu_001:
1646 mario79 925
	add	esi,2
926
	mov	ebx,esi	; save address of start of web address
927
	mov	edi,document_user + URLMAXLEN	; end of string
928
; look for page delimiter - it's a '/' character
31 halyavin 929
pu_003:
1646 mario79 930
	cmp	[esi],byte ' '	; end of text?
931
	je	pu_004		; yep, so none found
932
	cmp	esi,edi		; end of string?
933
	je	pu_004		; yep, so none found
934
	cmp	[esi],byte '/'	; delimiter?
935
	je	pu_005		; yep - process it
936
	inc	esi
937
	jmp	pu_003
31 halyavin 938
 
939
pu_005:
1646 mario79 940
; copy page to document address
941
; esi = delimiter
942
	push	esi
943
	mov	ecx,edi		; end of document_user
944
	mov	edi,document
945
	cld
31 halyavin 946
 
947
pu_006:
1646 mario79 948
	movsb
949
	cmp	esi,ecx
950
	je	pu_007		; end of string?
951
	cmp	[esi],byte ' '	; end of text
952
;	je	pu_007		; дзен-ассемблер
953
;	jmp	pu_006		; не надо плодить сущности по напрасну
954
	jne	pu_006
31 halyavin 955
 
956
pu_007:
1646 mario79 957
	pop	esi	; point esi to '/' delimiter
31 halyavin 958
 
959
pu_004:
1646 mario79 960
; copy web address to webAddr
961
; start in ebx,end in esi-1
962
	mov	ecx,esi
963
	mov	esi,ebx
964
	mov	edi,webAddr
965
	cld
31 halyavin 966
 
967
pu_008:
1646 mario79 968
	movsb
969
	cmp	esi,ecx
970
;	je	pu_009		; дзен-ассемблер
971
;	jmp	pu_008		; не надо плодить сущности по напрасну
972
	jne	pu_008
31 halyavin 973
 
974
pu_009:
1646 mario79 975
; For debugging, display resulting strings
976
if	DEBUGGING_STATE = DEBUGGING_ENABLED
977
	mov	esi,document_user
978
	call	debug_print_string
979
	mov	esi,webAddr
980
	call	debug_print_string
981
	mov	esi,document
982
	call	debug_print_string
983
end	if
984
; Look up the ip address, or was it specified?
985
	mov	al,[proxyAddr]
986
	cmp	al,0
987
	jnz	pu_015
988
	mov	al,[webAddr]
1645 clevermous 989
pu_015:
1646 mario79 990
	cmp	al,'0'
991
	jb	pu_010	; Resolve address
992
	cmp	al,'9'
993
	ja	pu_010	; Resolve address
31 halyavin 994
 
1646 mario79 995
if	DEBUGGING_STATE = DEBUGGING_ENABLED
996
	mov	esi,str2	; print	gotip
997
	call	debug_print_string
998
end	if
999
; Convert address
1000
; If proxy is given, get proxy address instead of server
1001
	mov	esi,proxyAddr-1
1002
	cmp	byte [esi+1],0
1003
	jnz	pu_020
1004
	mov	esi,webAddr-1
31 halyavin 1005
 
1645 clevermous 1006
pu_020:
1646 mario79 1007
	mov	edi,server_ip
1008
	xor	eax,eax
1645 clevermous 1009
 
31 halyavin 1010
ip1:
1646 mario79 1011
	inc	esi
1012
	cmp	[esi],byte '0'
1013
	jb	ip2
1014
	cmp	[esi],byte '9'
1015
	jg	ip2
1016
	imul	eax,10
1017
	movzx	ebx,byte [esi]
1018
	sub	ebx,48
1019
	add	eax,ebx
1020
	jmp	ip1
1021
 
31 halyavin 1022
ip2:
1646 mario79 1023
	mov	[edi],al
1024
	xor	eax,eax
1025
	inc	edi
1026
	cmp	edi,server_ip+3
1027
	jbe	ip1
1028
	jmp	pu_011
31 halyavin 1029
 
1030
pu_010:
1646 mario79 1031
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1032
	mov	esi,str1	; print	resolving
1033
	call	debug_print_string
1034
end	if
1035
; Resolve Address
1036
	call	translateData	; Convert domain & DNS IP address
1037
	call	resolveDomain	; get ip address
31 halyavin 1038
 
1646 mario79 1039
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1040
	mov	esi,str3
1041
	call	debug_print_string
1042
end	if
31 halyavin 1043
 
1044
pu_011:
1646 mario79 1045
; Done
1046
	ret
31 halyavin 1047
 
1048
;***************************************************************************
1049
;   Function
1050
;      translateData
1051
;
1052
;   Description
1053
;      Coverts the domain name and DNS IP address typed in by the user into
1054
;      a format suitable for the IP layer.
1055
;
1056
;    The ename, in query, is converted and stored in dnsMsg
1057
;
1058
;***************************************************************************
1059
translateData:
1060
    ; first, get the IP address of the DNS server
1061
    ; Then, build up the request string.
1062
 
1063
    ; Build the request string
1646 mario79 1064
	mov	eax,0x00010100
1065
	mov	[dnsMsg],eax
1066
	mov	eax,0x00000100
1067
	mov	[dnsMsg+4],eax
1068
	mov	eax,0x00000000
1069
	mov	[dnsMsg+8],eax
1070
; domain name goes in at dnsMsg+12
1071
	mov	esi,dnsMsg +12	;location of label length
1072
	mov	edi,dnsMsg + 13	;label start
1073
	mov	edx,proxyAddr
1074
	cmp	byte [edx],0
1075
	jnz	td000
1076
	mov	edx,webAddr
31 halyavin 1077
 
1645 clevermous 1078
td000:
1646 mario79 1079
	mov	ecx,12	; total string length so far
31 halyavin 1080
 
1081
td002:
1646 mario79 1082
	mov	[esi],byte 0
1083
	inc	ecx
31 halyavin 1084
 
1085
td0021:
1646 mario79 1086
	mov	al,[edx]
1087
	cmp	al,' '
1088
	je	td001	; we have finished the string translation
31 halyavin 1089
 
1646 mario79 1090
	cmp	al,0
1091
	je	td001
31 halyavin 1092
 
1646 mario79 1093
	cmp	al,'.'	; we have finished the label
1094
	je	td004
31 halyavin 1095
 
1646 mario79 1096
	inc	byte [esi]
1097
	inc	ecx
1098
	mov	[edi],al
1099
	inc	edi
1100
	inc	edx
1101
	jmp	td0021
31 halyavin 1102
 
1646 mario79 1103
td004:
1104
	mov	esi,edi
1105
	inc	edi
1106
	inc	edx
1107
	jmp	td002
31 halyavin 1108
 
1646 mario79 1109
; write label len + label text
31 halyavin 1110
td001:
1646 mario79 1111
	mov	[edi],byte 0
1112
	inc	ecx
1113
	inc	edi
1114
	mov	[edi],dword 0x01000100
1115
	add	ecx,4
1116
	mov	[dnsMsgLen],ecx
1117
	ret
31 halyavin 1118
 
1119
;***************************************************************************
1120
;   Function
1121
;      resolveDomain
1122
;
1123
;   Description
1124
;       Sends a question to the dns server
1125
;       works out the IP address from the response from the DNS server
1126
;
1127
;***************************************************************************
1128
resolveDomain:
1646 mario79 1129
; Get a free port number
1130
	mov	ecx,1000	; local port starting at 1000
31 halyavin 1131
getlp:
1646 mario79 1132
	inc	ecx
1133
	push	ecx
1134
	mcall	53,9
1135
	pop	ecx
1136
	cmp	eax,0	; is this local port in use?
1137
	jz	getlp	; yes - so try next
31 halyavin 1138
 
1646 mario79 1139
; Get DNS IP
1140
	mcall	52,13
1141
	mov	esi,eax
1142
; First, open socket
1143
	mov	edx,53	; remote port - dns
1144
;	mov	esi,dword [dns_ip]
1145
	xor	ebx,ebx	; 0
1146
	mcall	53
1147
	mov	[socketNum],eax
1148
; write to socket ( request DNS lookup )
1149
	mcall	53,4,[socketNum],[dnsMsgLen],dnsMsg
1150
; Setup the DNS response buffer
1151
	mov	eax,dnsMsg
1152
	mov	[dnsMsgLen],eax
1153
; now, we wait for
1154
; UI redraw
1155
; UI close
1156
; or data from remote
31 halyavin 1157
 
1158
ctr001:
1646 mario79 1159
	mcall	10	; wait here for event
1160
	cmp	eax,1	; redraw request ?
1161
	je	ctr003
31 halyavin 1162
 
1646 mario79 1163
	cmp	eax,2	; key in buffer ?
1164
	je	ctr004
31 halyavin 1165
 
1646 mario79 1166
	cmp	eax,3	; button in buffer ?
1167
	je	ctr005
1168
; Any data in the UDP receive buffer?
1169
	mcall	53,2,[socketNum]
1170
	cmp	eax,0
1171
	je	ctr001
31 halyavin 1172
 
1646 mario79 1173
; we have data - this will be the response
31 halyavin 1174
ctr002:
1646 mario79 1175
	mcall	53,3,[socketNum]	; read byte - block (high byte)
1176
; Store the data in the response buffer
1177
	mov	eax,[dnsMsgLen]
1178
	mov	[eax],bl
1179
	inc	dword [dnsMsgLen]
31 halyavin 1180
 
1646 mario79 1181
	mcall	53,2,[socketNum]	; any more data?
1182
	cmp	eax,0
1183
	jne	ctr002	; yes, so get it
31 halyavin 1184
 
1646 mario79 1185
; close	socket
1186
	mcall	53,1,[socketNum]
1187
	mov	[socketNum],dword  0xFFFF
1188
; Now parse the message to get the host IP
1189
; Man, this is complicated. It's described in
1190
; RFC 1035
1191
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1192
	mov	esi,str4
1193
	call	debug_print_string
1194
end	if
31 halyavin 1195
 
1196
    ; 1) Validate that we have an answer with > 0 responses
1197
    ; 2) Find the answer record with TYPE 0001 ( host IP )
1198
    ; 3) Finally, copy the IP address to the display
1199
    ; Note: The response is in dnsMsg
1200
    ;       The end of the buffer is pointed to by [dnsMsgLen]
1201
 
1646 mario79 1202
; Clear the IP address text
1203
	mov	[server_ip],dword  0
1204
	mov	esi,dnsMsg
1205
; Is this a response to my question?
1206
	mov	al,[esi+2]
1207
	and	al,0x80
1208
	cmp	al,0x80
1209
	jne	ctr002a
1210
; Were there any errors?
1211
	mov	al,[esi+3]
1212
	and	al,0x0F
1213
	cmp	al,0x00
1214
	jne	ctr002a
1215
; Is there ( at least 1 ) answer?
1216
	mov	ax,[esi+6]
1217
	cmp	ax,0x00
1218
	je	ctr002a
1219
; Header valdated. Scan through and get my answer
1220
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1221
	pusha
1222
	mov	esi,str4
1223
	call	debug_print_string
1224
	popa
1225
end	if
1226
	add	esi,12	; Skip to the question field
1227
; Skip through the question field
1228
	call	skipName
1229
	add	esi,4	; skip past the questions qtype, qclass
31 halyavin 1230
 
1231
ctr002z:
1646 mario79 1232
; Now at the answer. There may be several answers,
1233
; find the right one ( TYPE = 0x0001 )
1234
	call	skipName
1235
	mov	ax,[esi]
1236
	cmp	ax,0x0100	; Is this the IP address answer?
1237
	jne	ctr002c
1238
; Yes! Point esi to the first byte of the IP address
1239
	add	esi,10
1240
	mov	eax,[esi]
1241
	mov	[server_ip],eax
1242
	ret
31 halyavin 1243
 
1646 mario79 1244
ctr002c:	; Skip through the answer, move to the next
1245
	add	esi,8
1246
	movzx	eax,byte [esi+1]
1247
	mov	ah,[esi]
1248
	add	esi,eax
1249
	add	esi,2
1250
; Have we reached the end of the msg?
1251
; This is an error condition, should not happen
1252
	cmp	esi,[dnsMsgLen]
1253
	jl	ctr002z	; Check next answer
1254
	jmp	ctr002a	; abort
31 halyavin 1255
 
1256
ctr002a:
1646 mario79 1257
	jmp	ctr001
31 halyavin 1258
 
1646 mario79 1259
ctr003:	; redraw
1260
	call	draw_window
1261
	jmp	ctr001
31 halyavin 1262
 
1646 mario79 1263
ctr004:	; key
1264
	mcall	2	; just read it and ignore
1265
	jmp	ctr001
31 halyavin 1266
 
1646 mario79 1267
ctr005:	; button
1268
	mcall	17	; get id
1269
	mov	dl,ah
31 halyavin 1270
 
1646 mario79 1271
	; close	socket
1272
	mcall	53,1,[socketNum]
1273
	cmp	dl,1
1274
	je	exit
31 halyavin 1275
 
1646 mario79 1276
	mov	[socketNum],dword  0xFFFF
1277
	mov	[server_ip],dword  0
1278
	ret
31 halyavin 1279
 
1280
;***************************************************************************
1281
;   Function
1282
;      skipName
1283
;
1284
;   Description
1285
;       Increment esi to the first byte past the name field
1286
;       Names may use compressed labels. Normally do.
1287
;       RFC 1035 page 30 gives details
1288
;
1289
;***************************************************************************
1290
skipName:
1646 mario79 1291
	mov	al,[esi]
1292
	cmp	al,0
1293
	je	sn_exit
1294
	and	al,0xc0
1295
	cmp	al,0xc0
1296
	je	sn001
31 halyavin 1297
 
1646 mario79 1298
	movzx	eax,byte [esi]
1299
	inc	eax
1300
	add	esi,eax
1301
	jmp	skipName
31 halyavin 1302
 
1303
sn001:
1646 mario79 1304
	add	esi,2	; A pointer is always at the end
1305
	ret
31 halyavin 1306
 
1307
sn_exit:
1646 mario79 1308
	inc	esi
1309
	ret
31 halyavin 1310
 
1645 clevermous 1311
;***************************************************************************
1312
;   Function
1313
;       load_settings
1314
;
1315
;   Description
1316
;       Load settings from configuration file network.ini
1317
;
1318
;***************************************************************************
1319
load_settings:
1646 mario79 1320
	stdcall	dll.Load,@IMPORT
1321
	test	eax,eax
1322
	jnz	ls001
1323
	invoke	ini.get_str,inifile,sec_proxy,key_proxy,proxyAddr,256,proxyAddr
1324
	invoke	ini.get_int,inifile,sec_proxy,key_proxyport,80
1325
	mov	[proxyPort],eax
1326
	invoke	ini.get_str,inifile,sec_proxy,key_user,	proxyUser,256,proxyUser
1327
	invoke	ini.get_str,inifile,sec_proxy,key_password,proxyPassword,256,proxyPassword
1645 clevermous 1328
ls001:
1646 mario79 1329
	ret
31 halyavin 1330
 
1645 clevermous 1331
;***************************************************************************
1332
;   Function
1333
;       append_proxy_auth_header
1334
;
1335
;   Description
1336
;       Append header to HTTP request for proxy authentification
1337
;
1338
;***************************************************************************
1339
append_proxy_auth_header:
1646 mario79 1340
	mov	esi,proxy_auth_basic
1341
	mov	ecx,proxy_auth_basic_end - proxy_auth_basic
1342
	rep	movsb
1343
; base64-encode string :
1344
	mov	esi,proxyUser
1345
 
1645 clevermous 1346
apah000:
1646 mario79 1347
	lodsb
1348
	test	al,al
1349
	jz	apah001
1350
	call	encode_base64_byte
1351
	jmp	apah000
1352
 
1645 clevermous 1353
apah001:
1646 mario79 1354
	mov	al,':'
1355
	call	encode_base64_byte
1356
	mov	esi,proxyPassword
1357
 
1645 clevermous 1358
apah002:
1646 mario79 1359
	lodsb
1360
	test	al,al
1361
	jz	apah003
1362
	call	encode_base64_byte
1363
	jmp	apah002
1364
 
1645 clevermous 1365
apah003:
1646 mario79 1366
	call	encode_base64_final
1367
	ret
31 halyavin 1368
 
1645 clevermous 1369
encode_base64_byte:
1646 mario79 1370
	inc	ecx
1371
	shl	edx,8
1372
	mov	dl,al
1373
	cmp	ecx,3
1374
	je	ebb001
1375
	ret
1376
 
1645 clevermous 1377
ebb001:
1646 mario79 1378
	shl	edx,8
1379
	inc	ecx
1380
 
1645 clevermous 1381
ebb002:
1646 mario79 1382
	rol	edx,6
1383
	xor	eax,eax
1384
	xchg	al,dl
1385
	mov	al,[base64_table+eax]
1386
	stosb
1387
	loop	ebb002
1388
	ret
1645 clevermous 1389
 
1390
encode_base64_final:
1646 mario79 1391
	mov	al,0
1392
	test	ecx,ecx
1393
	jz	ebf000
1394
	call	encode_base64_byte
1395
	test	ecx,ecx
1396
	jz	ebf001
1397
	call	encode_base64_byte
1398
	mov	byte [edi-2],'='
1399
 
1645 clevermous 1400
ebf001:
1646 mario79 1401
	mov	byte [edi-1],'='
1402
 
1645 clevermous 1403
ebf000:
1646 mario79 1404
	ret
1645 clevermous 1405
 
1646 mario79 1406
if	DEBUGGING_STATE = DEBUGGING_ENABLED
31 halyavin 1407
 
1408
;****************************************************************************
1409
;    Function
1410
;       debug_print_string
1411
;
1412
;   Description
1413
;       prints a string to the debug board, in quotes
1414
;
1415
;       esi holds ptr to msg to display, which is space or 0 terminated
1416
;
1417
;       Nothing preserved; I'm assuming a pusha/popa is done before calling
1418
;
1419
;****************************************************************************
1420
debug_print_string:
1646 mario79 1421
	push	esi
1422
	mov	cl,'"'
1423
	mcall	63,1
1424
	pop	esi
31 halyavin 1425
 
1426
dps_000:
1646 mario79 1427
	mov	cl,[esi]
1428
	cmp	cl,0
1429
	je	dps_exit
31 halyavin 1430
 
1646 mario79 1431
	cmp	cl,' '
1432
	je	dps_exit
1433
	jmp	dps_001
1434
 
31 halyavin 1435
dps_exit:
1646 mario79 1436
	mov	cl,'"'
1437
	mcall	63,1
1438
	mov	cl,13
1439
	mcall
1440
	mov	cl,10
1441
	mcall
1442
	ret
31 halyavin 1443
 
1444
dps_001:
1646 mario79 1445
	push	esi
1446
	mcall	63,1
1447
	pop	esi
1448
	inc	esi
1449
	jmp	dps_000
1450
end	if
31 halyavin 1451
 
1452
;****************************************************************************
1453
;    Function
1454
;       print_text
1455
;
1456
;   Description
1457
;       display the url (full path) text
1458
;
1459
;****************************************************************************
1460
print_text:
1646 mario79 1461
; Draw a bar to blank out previous text
1462
	mov	ebx,30*65536+URLMAXLEN*6	; 50 should really be [len] and 103 [xa]
1463
	mov	ecx,[ya]
1464
	shl	ecx,16
1465
	mov	cx,9
1466
	mcall	13,,,0xFFFFFF
1467
; write text
1468
	mov	ebx,30*65536
1469
	add	ebx,[ya]
1470
	xor	ecx,ecx
1471
	mcall	4,,,[addr],URLMAXLEN
1472
	ret
31 halyavin 1473
 
1474
;   *********************************************
1475
;   *******  WINDOW DEFINITIONS AND DRAW ********
1476
;   *********************************************
1477
 
1478
draw_window:
1646 mario79 1479
; function 12: tell os about windowdraw
1480
; 1 start of draw
1481
	mcall	12,1
1645 clevermous 1482
 
1646 mario79 1483
;	cmp	[params],byte 0
1484
;	jz	.noret
1645 clevermous 1485
 
1646 mario79 1486
; это несколько загадочно, но если не рисовать окошко совсем, прога не пашет.
1487
; DRAW	WINDOW
1488
; eax	function 0 : define and draw window
1489
;	xor	eax,eax
1490
; ebx	[x start] *65536 + [x size]
1491
;	xor	ebx,ebx
1492
; ecx	[y start] *65536 + [y size]
1493
;	xor	ecx,ecx
1494
; edx	color of work area RRGGBB,8->color gl
1495
; esi	color of bar and flags
1496
;	xor	esi,esi
1497
;	mcall	,,,0x14ffffff,,title
31 halyavin 1498
 
1646 mario79 1499
; function 12: tell os about windowdraw
1500
; 2, end of draw
1501
;	mcall	12,2
1502
;	ret
1645 clevermous 1503
 
1646 mario79 1504
;.noret:
1505
; DRAW	WINDOW
1506
; eax	function 0 : define and draw window
1507
	xor	eax,eax
1508
; ebx	[x start] *65536 + [x size]
1509
; ecx	[y start] *65536 + [y size]
1510
; edx	color of work area RRGGBB,8->color gl
1511
; esi	color of bar and flags
1512
	xor	esi,esi
1513
; edi	WINDOW	LABEL
1514
	mcall	,<50,600>,<350,200>,0x14ffffff,,title
1515
; eax	function 4: write text to window
1516
; ebx	[x start] *65536 + [y start]
1517
; ecx	color of text RRGGBB
1518
; edx	pointer to text beginning
1519
; esi	max lenght
1520
	xor	ecx,ecx
1521
	mcall	4,<30,38>,,document_user,URLMAXLEN
1645 clevermous 1522
 
1646 mario79 1523
;	xor	edx,edx
1524
;	mcall	38,<5,545>,<60,60>
1645 clevermous 1525
 
1646 mario79 1526
;	mov	ecx,[winys]
1527
;	shl	ecx,16
1528
;	add	ecx,[winys]
1529
;	sub	ecx,26*65536+26
1530
;	mcall	38,<5,545>
1645 clevermous 1531
 
1646 mario79 1532
; RELOAD
1533
; eax	function 8 : define and draw button
1534
; ebx	[x start] *65536 + [x size]
1535
; ecx	[y start] *65536 + [y size]
1536
; edx	button id
1537
; esi	button color RRGGBB
1538
	mcall	8,<388,50>,<34,14>,22,0x5588dd
1539
; URL
1540
	mcall	,<10,12>,<34,12>,10
1541
; STOP
1542
	mcall	,<443,50>,<34,14>,24
1543
; SAVE
1544
	mcall	,<498,50>,,26
1545
; BUTTON TEXT
1546
; eax	function 4 : write text to window
1547
; ebx	[x start] *65536 + [y start]
1548
; ecx	color	of	text	RRGGBB
1549
; edx	pointer	to	text	beginning
1550
; esi	text	length
1551
	mcall	4,<390,38>,0xffffff,button_text,30
1552
	call	display_page
31 halyavin 1553
 
1646 mario79 1554
; function 12: tell os about windowdraw
1555
; 2, end of draw
1556
	mcall	12,2
1557
	ret
1558
;-----------------------------------------------------------------------------
1559
; Data area
1560
;-----------------------------------------------------------------------------
1561
align	4
1645 clevermous 1562
@IMPORT:
31 halyavin 1563
 
1646 mario79 1564
library	libini,'libini.obj'
1645 clevermous 1565
 
1566
import	libini, \
1646 mario79 1567
	ini.get_str,'ini_get_str', \
1568
	ini.get_int,'ini_get_int'
1645 clevermous 1569
 
1646 mario79 1570
;---------------------------------------------------------------------
1571
fileinfo	dd 2,0,0
1572
final_size	dd 0
1573
final_buffer	dd 0
1574
		db '/rd/1/.download',0
1575
 
1576
body_pos	dd 0
1645 clevermous 1577
 
1646 mario79 1578
;fileinfo_tmp	dd 2,0,0
1579
buf_size	dd 0
1580
buf_ptr		dd 0
1581
;		db	'/rd/1/1',0
1645 clevermous 1582
 
1646 mario79 1583
deba		dd 0
1584
		db 0
1585
;---------------------------------------------------------------------
1586
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1587
str1:		db "Resolving...",0
1588
str3:		db "Resolved",0
1589
str2:		db "GotIP",0
1590
str4:		db "GotResponse",0
1591
end	if
1592
;---------------------------------------------------------------------
2097 leency 1593
button_text	db ' RELOAD    STOP     SAVE      '
1646 mario79 1594
dpx		dd 25	; x - start of html page in pixels in window
1595
dpy		dd 65	; for	y
1596
lastletter	db 0
1597
pageyinc	dd 0
1598
display_from	dd 20
1599
pos		dd 0x0
1600
pagex		dd 0x0
1601
pagey		dd 0x0
1602
pagexs		dd 80
1603
command_on_off	dd 0x0
1604
text_type	db 1
1605
com2		dd 0x0
1606
script		dd 0x0
1607
socket		dd 0x0
1645 clevermous 1608
 
1646 mario79 1609
addr		dd 0x0
1610
ya		dd 0x0
1611
len		dd 0x00
1645 clevermous 1612
 
1646 mario79 1613
title		db 'Downloader',0
1645 clevermous 1614
 
1646 mario79 1615
server_ip:	db 207,44,212,20
1616
;dns_ip:	db 194,145,128,1
1617
;---------------------------------------------------------------------
1618
;webAddr:
1619
;times URLMAXLEN db ' '
1620
;db	0
31 halyavin 1621
 
1646 mario79 1622
;document_user:	db 'Click on the button to the left to enter a URL',0
1623
;times URLMAXLEN+document_user-$ db 0
1645 clevermous 1624
 
1646 mario79 1625
;document:	db '/'
1626
;times URLMAXLEN-1 db ' '
1627
;---------------------------------------------------------------------
1628
s_contentlength	db 'Content-Length:'
1629
len_contentlength = 15
31 halyavin 1630
 
1646 mario79 1631
s_chunked	db 'Transfer-Encoding: chunked'
1632
len_chunked	= $ - s_chunked
31 halyavin 1633
 
1646 mario79 1634
is_body		dd 0	; 0 if headers, 1 if content
1635
is_chunked	dd 0
1636
prev_chunk_end	dd 0
1637
cur_chunk_size	dd 0
31 halyavin 1638
 
1646 mario79 1639
string0:	db 'GET '
31 halyavin 1640
 
1646 mario79 1641
stringh:        db ' HTTP/1.1',13,10,'Host: '
31 halyavin 1642
stringh_end:
1646 mario79 1643
proxy_auth_basic:	db 13,10,'Proxy-Authorization: Basic '
1645 clevermous 1644
proxy_auth_basic_end:
1646 mario79 1645
connclose:	db 13,10,'User-Agent: Kolibrios Downloader',13,10,'Connection: Close',13,10,13,10
1645 clevermous 1646
connclose_end:
31 halyavin 1647
 
1646 mario79 1648
base64_table	db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
1649
		db '0123456789+/'
1645 clevermous 1650
 
1646 mario79 1651
inifile		db '/sys/network/zeroconf.ini',0
1645 clevermous 1652
 
1653
sec_proxy:
1646 mario79 1654
key_proxy	db 'proxy',0
1655
key_proxyport	db 'port',0
1656
key_user	db 'user',0
1657
key_password	db 'password',0
1645 clevermous 1658
 
1659
 
1646 mario79 1660
proxyPort	dd 80
1645 clevermous 1661
 
1646 mario79 1662
shared_name	dd 0
1645 clevermous 1663
 
1646 mario79 1664
;yandex:	db 'menuetos.net'
1645 clevermous 1665
;yandex_end:
1666
 
1646 mario79 1667
status		dd 0x0
1668
prev_status	dd 0x0
31 halyavin 1669
 
1646 mario79 1670
onoff		dd 0x0
31 halyavin 1671
 
1646 mario79 1672
nextupdate:	dd 0
1673
winys:		dd 400
31 halyavin 1674
 
1646 mario79 1675
dnsMsgLen:	dd 0
1676
socketNum:	dd 0xFFFF
1677
;---------------------------------------------------------------------
1678
document_user:	db 'Click on the button to the left to enter a URL',0
1679
;---------------------------------------------------------------------
1680
IM_END:
1681
	rb URLMAXLEN-(IM_END - document_user)
1682
;---------------------------------------------------------------------
1683
align 4
1684
document:
1685
	rb URLMAXLEN
1686
;---------------------------------------------------------------------
1687
align 4
1688
webAddr:
1689
	rb URLMAXLEN+1
1690
;---------------------------------------------------------------------
1691
align 4
1692
primary_buf:
1693
	rb primary_buffer_size
1694
;---------------------------------------------------------------------
1695
align 4
1696
params:		; db 1024 dup(0)
1697
	rb 1024
1698
;---------------------------------------------------------------------
1699
align 4
1700
request:	; db 256 dup(0)
1701
	rb 256
1702
;---------------------------------------------------------------------
1703
align 4
1704
proxyAddr:	; db 256 dup(0)
1705
	rb 256
1706
;---------------------------------------------------------------------
1707
align 4
1708
proxyUser:	; db 256 dup(0)
1709
	rb 256
1710
;---------------------------------------------------------------------
1711
align 4
1712
proxyPassword:	; db 256 dup(0)
1713
	rb 256
1714
;---------------------------------------------------------------------
1715
align 4
31 halyavin 1716
dnsMsg:
1646 mario79 1717
	rb 4096
1718
;	rb 0x100000
1719
;---------------------------------------------------------------------
1720
align 4
1721
	rb 4096
1722
stacktop:
1723
;---------------------------------------------------------------------
31 halyavin 1724
I_END:
1646 mario79 1725
;---------------------------------------------------------------------