Subversion Repositories Kolibri OS

Rev

Rev 1645 | 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]
457
	cmp	[ecx],byte 0
458
	jnz	save_in_shared
31 halyavin 459
 
1646 mario79 460
	mcall	70,fileinfo
461
;dps	"saving "
1645 clevermous 462
;pregs
1646 mario79 463
;	jmp	close_end_exit
464
	pop	edi
465
	pop	esi
466
; if called from command line, then exit
467
	cmp	[params],byte 0
468
	jnz	exit
469
	ret
1645 clevermous 470
 
471
save_in_shared:
1646 mario79 472
	mov	esi,1	; SHM_OPEN+SHM_WRITE
473
	mcall	68,22
474
	test	eax,eax
1645 clevermous 475
	jz	save_in_shared_done
1646 mario79 476
 
477
	sub	edx,4
1645 clevermous 478
	jbe	save_in_shared_done
1646 mario79 479
 
480
	mov	ecx,[final_size]
481
	cmp	ecx,edx
1645 clevermous 482
	jb	@f
1646 mario79 483
 
484
	mov	ecx,edx
1645 clevermous 485
@@:
1646 mario79 486
	mov	[eax],ecx
487
	lea	edi,[eax+4]
488
	mov	esi,[final_buffer]
489
	mov	edx,ecx
490
	shr	ecx,2
1645 clevermous 491
	rep	movsd
1646 mario79 492
	mov	ecx,edx
493
	and	ecx,3
1645 clevermous 494
	rep	movsb
1646 mario79 495
 
1645 clevermous 496
save_in_shared_done:
497
	pop	edi
498
	pop	esi
499
	jmp	exit
500
 
1646 mario79 501
; this function cuts header, and removes chunk sizes if doc is chunked
502
; in: buf_ptr, pos; out: buf_ptr, pos.
1645 clevermous 503
 
504
parse_result:
1646 mario79 505
; close socket
506
	mcall	53,8,[socket]
1645 clevermous 507
 
1646 mario79 508
dps	"close	socket: "
509
dph	eax
1645 clevermous 510
newline
1646 mario79 511
	mov	edi,[buf_ptr]
512
	mov	edx,[pos]
513
	mov	[buf_size],edx
514
;	mcall	70,fileinfo_tmp
515
dps	"pos = "
516
dph	edx
1645 clevermous 517
newline
31 halyavin 518
 
1646 mario79 519
; first, find end of headers
1645 clevermous 520
.next_byte:
1646 mario79 521
	cmp	[edi],dword 0x0d0a0d0a	; мне лень читать стандарт, пусть будут оба варианта
522
	je	.end_of_headers
523
	cmp	[edi],dword 0x0a0d0a0d
524
	je	.end_of_headers
525
	inc	edi
526
	dec	edx
527
	jne	.next_byte
528
; no end of headers. it's an error. let client see all those headers.
1645 clevermous 529
	ret
1646 mario79 530
 
1645 clevermous 531
.end_of_headers:
1646 mario79 532
; here we look at headers and search content-length or transfer-encoding headers
533
;dps	"eoh "
1645 clevermous 534
;newline
1646 mario79 535
	sub	edi,[buf_ptr]
536
	add	edi,3
537
	mov	[body_pos],edi	; store position where document body starts
538
	mov	[is_chunked],0
539
; find content-length in headers
540
; not good method, but should work for 'Content-Length:'
541
	mov	esi,[buf_ptr]
542
	mov	edi,s_contentlength
543
	mov	ebx,[body_pos]
544
	xor	edx,edx	; 0
1645 clevermous 545
.cl_next:
1646 mario79 546
	mov	al,[esi]
547
	cmp	al,[edi + edx]
548
	jne	.cl_fail
549
	inc	edx
550
	cmp	edx,len_contentlength
551
	je	.cl_found
552
	jmp	.cl_incr
1645 clevermous 553
.cl_fail:
1646 mario79 554
	xor	edx,edx	; 0
1645 clevermous 555
.cl_incr:
1646 mario79 556
	inc	esi
557
	dec	ebx
558
	je	.cl_error
559
	jmp	.cl_next
1645 clevermous 560
.cl_error:
561
;pregs
562
;newline
1646 mario79 563
;dph	esi
1645 clevermous 564
;dps	" content-length not found "
1646 mario79 565
; find 'chunked'
566
; да, я копирую код, это ужасно, но мне хочется, чтобы поскорее заработало
567
; а там уж отрефакторю
568
	mov	esi,[buf_ptr]
569
	mov	edi,s_chunked
570
	mov	ebx,[body_pos]
571
	xor	edx,edx	; 0
31 halyavin 572
 
1645 clevermous 573
.ch_next:
1646 mario79 574
	mov	al,[esi]
575
	cmp	al,[edi + edx]
576
	jne	.ch_fail
577
	inc	edx
578
	cmp	edx,len_chunked
579
	je	.ch_found
580
	jmp	.ch_incr
581
 
1645 clevermous 582
.ch_fail:
1646 mario79 583
	xor	edx,edx	; 0
584
 
1645 clevermous 585
.ch_incr:
1646 mario79 586
	inc	esi
587
	dec	ebx
588
	je	.ch_error
589
	jmp	.ch_next
590
 
1645 clevermous 591
.ch_error:
1646 mario79 592
; if neither of the 2 headers is found, it's an error
593
;dps	"transfer-encoding: chunked not found "
594
	mov	eax,[pos]
595
	sub	eax,[body_pos]
596
	jmp	.write_final_size
31 halyavin 597
 
1645 clevermous 598
.ch_found:
1646 mario79 599
	mov	[is_chunked],1
600
	mov	eax,[body_pos]
601
	add	eax,[buf_ptr]
602
	sub	eax,2
603
	mov	[prev_chunk_end],eax
604
	jmp	parse_chunks
1645 clevermous 605
 
606
.cl_found:
1646 mario79 607
	call	read_number	; eax = number from *esi
608
	inc	eax	; bugfix :)
609
 
1645 clevermous 610
.write_final_size:
1646 mario79 611
	mov	[final_size],eax	; if this works, i will b very happy...
1645 clevermous 612
 
1646 mario79 613
	mov	ebx,[pos]	; we well check if it is right
614
	sub	ebx,[body_pos]
31 halyavin 615
 
1646 mario79 616
;dps	"check cl eax==ebx "
1645 clevermous 617
;pregs
31 halyavin 618
 
1646 mario79 619
; everything is ok, so we return
620
	mov	eax,[body_pos]
621
	mov	ebx,[buf_ptr]
622
	add	ebx,eax
623
	mov	[final_buffer],ebx
624
;	mov	ebx,[pos]
625
;	sub	ebx,eax
626
;	mov	[final_size],ebx
1645 clevermous 627
	ret
628
 
629
parse_chunks:
1646 mario79 630
;dps	"parse chunks"
1645 clevermous 631
;newline
632
	; we have to look through the data and remove sizes of chunks we see
633
	; 1. read size of next chunk
634
	; 2. if 0, it's end. if not, continue.
635
	; 3. make a good buffer and copy a chunk there
1646 mario79 636
	xor	eax,eax
637
	mov	[final_buffer],eax	; 0
638
	mov	[final_size],eax	; 0
1645 clevermous 639
 
640
.read_size:
1646 mario79 641
	mov	eax,[prev_chunk_end]
642
	mov	ebx,eax
643
	sub	ebx,[buf_ptr]
644
	mov	edx,eax
645
;dps	"rs "
1645 clevermous 646
;pregs
1646 mario79 647
	cmp	ebx,[pos]
648
	jae	chunks_end	; not good
1645 clevermous 649
 
1646 mario79 650
	call	read_hex	; in: eax=pointer to text. out:eax=hex number,ebx=end of text.
651
	cmp	eax,0
652
	jz	chunks_end
31 halyavin 653
 
1646 mario79 654
	add	ebx,1
655
	mov	edx,ebx	; edx = size of size of chunk
1645 clevermous 656
 
1646 mario79 657
	add	ebx,eax
658
	mov	[prev_chunk_end],ebx
1645 clevermous 659
 
1646 mario79 660
;dps	"sz "
1645 clevermous 661
;pregs
1646 mario79 662
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
663
; realloc final buffer
1645 clevermous 664
	push	eax
665
	push	edx
666
	push	dword [final_size]
1646 mario79 667
	add	[final_size],eax
668
	mcall	68,20,[final_size],[final_buffer]
669
	mov	[final_buffer],eax
670
;dps	"re "
1645 clevermous 671
;pregs
1646 mario79 672
	pop	edi
673
	pop	esi
674
	pop	ecx
675
;	add	[pos],ecx
676
	add	edi,[final_buffer]
677
;dps	"cp "
1645 clevermous 678
;pregs
1646 mario79 679
	rep	movsb
680
	jmp	.read_size
1645 clevermous 681
 
682
chunks_end:
1646 mario79 683
; free old buffer
684
dps	"chunks end"
1645 clevermous 685
newline
1646 mario79 686
	mcall	68,13,[buf_ptr]
687
; done!
1645 clevermous 688
	ret
1646 mario79 689
 
1645 clevermous 690
; reads content-length from [edi+ecx], result in eax
691
read_number:
1646 mario79 692
	push	ebx
693
	xor	eax,eax
694
	xor	ebx,ebx
31 halyavin 695
 
1645 clevermous 696
.next:
1646 mario79 697
	mov	bl,[esi]
698
;dph	ebx
699
	cmp	bl,'0'
700
	jb	.not_number
701
	cmp	bl,'9'
702
	ja	.not_number
703
	sub	bl,'0'
704
	shl	eax,1
705
	lea	eax,[eax + eax * 4]	; eax *= 10
706
	add	eax,ebx
707
 
1645 clevermous 708
.not_number:
1646 mario79 709
	cmp	bl,13
710
	jz	.done
711
	inc	esi
712
	jmp	.next
713
 
1645 clevermous 714
.done:
1646 mario79 715
	pop	ebx
1645 clevermous 716
;newline
1646 mario79 717
;dps	"strtoint eax "
1645 clevermous 718
;pregs
719
	ret
720
 
1646 mario79 721
; reads hex from eax,result in eax,end of text in ebx
1645 clevermous 722
read_hex:
1646 mario79 723
	add	eax,2
724
	mov	ebx,eax
725
	mov	eax,[ebx]
726
	mov	[deba],eax
1645 clevermous 727
;	pushf
1646 mario79 728
;	pushad
729
;	mov	edx,deba
730
;	call	debug_outstr
731
;	popad
732
;	popf
733
	xor	eax,eax
734
	xor	ecx,ecx
1645 clevermous 735
.next:
1646 mario79 736
	mov	cl,[ebx]
737
	inc	ebx
1645 clevermous 738
 
1646 mario79 739
	cmp	cl,0x0d
740
	jz	.done
741
;dph	ebx
742
	or	cl,0x20
743
	sub	cl,'0'
744
	jb	.bad
745
 
746
	cmp	cl,0x9
747
	jbe	.adding
748
 
749
	sub	cl,'a'-'0'-10
750
	cmp	cl,0x0a
751
	jb	.bad
752
 
753
	cmp	cl,0x0f
754
	ja	.bad
755
 
1645 clevermous 756
.adding:
1646 mario79 757
	shl	eax,4
758
	or	eax,ecx
759
;	jmp	.not_number
1645 clevermous 760
;.bad:
761
.bad:
1646 mario79 762
	jmp	.next
1645 clevermous 763
.done:
764
;newline
1646 mario79 765
;dps	"hextoint eax "
1645 clevermous 766
;pregs
767
	ret
31 halyavin 768
 
1645 clevermous 769
;****************************************************************************
770
;    Function
771
;       draw_page
772
;
773
;   Description
774
;       parses the web page data, storing displayable data at 0x20000
775
;       and attributes at 0x30000. It then calls display_page to render
776
;       the data
777
;
778
;****************************************************************************
779
draw_page:
780
	ret
31 halyavin 781
 
782
;****************************************************************************
783
;    Function
784
;       linefeed
785
;
786
;   Description
787
;
788
;
789
;****************************************************************************
790
linefeed:
1646 mario79 791
	ret
31 halyavin 792
 
793
;****************************************************************************
794
;    Function
795
;       display_page
796
;
797
;   Description
798
;       Renders the text decoded by draw_page
799
;
800
;****************************************************************************
801
display_page:
1646 mario79 802
	ret
31 halyavin 803
 
804
;****************************************************************************
805
;    Function
806
;       socket_commands
807
;
808
;   Description
809
;       opens or closes the socket
810
;
811
;****************************************************************************
812
socket_commands:
1646 mario79 813
	cmp	ah,22	; open socket
814
	jnz	tst3
31 halyavin 815
 
1646 mario79 816
dps	"opening socket"
817
newline
818
; Clear all page memory
819
	xor	eax,eax
820
	mov	[prev_chunk_end],eax	; 0
821
	cmp	[buf_ptr],eax	; 0
822
	jz	no_free
823
 
824
	mcall	68,13,[buf_ptr]	; free	buffer
825
 
1645 clevermous 826
no_free:
1646 mario79 827
	xor	eax,eax
828
	mov	[buf_size],eax	; 0
829
; Parse the entered url
830
	call	parse_url
831
; Get a free port number
832
	mov	ecx,1000	; local port starting at 1000
31 halyavin 833
 
834
getlp1:
1646 mario79 835
	inc	ecx
836
	push	ecx
837
	mcall	53,9
838
	pop	ecx
839
	cmp	eax,0	; is this local port in use?
840
	jz	getlp1	; yes - so try next
31 halyavin 841
 
1646 mario79 842
	mov	edx,80
843
	cmp	[proxyAddr],byte 0
844
	jz	sc000
845
	mov	edx,[proxyPort]
1645 clevermous 846
sc000:
1646 mario79 847
	mcall	53,5,,,[server_ip],1
848
	mov	[socket],eax
849
	mov	[pagexs],80
1645 clevermous 850
 
1646 mario79 851
	push	eax
852
	xor	eax,eax ; 0
853
	mov	[pos],eax
854
	mov	[pagex],eax
855
	mov	[pagey],eax
856
	mov	[command_on_off],eax
857
	mov	[is_body],eax
858
	pop	eax
859
	ret
31 halyavin 860
 
861
tst3:
1646 mario79 862
	cmp	ah,24	; close	socket
863
	jnz	no_24
31 halyavin 864
 
1646 mario79 865
	mcall	53,8,[socket]
866
	call	draw_page
31 halyavin 867
no_24:
1646 mario79 868
	ret
31 halyavin 869
 
870
;****************************************************************************
871
;    Function
872
;       parse_url
873
;
874
;   Description
875
;       parses the full url typed in by the user into a web address ( that
876
;       can be turned into an IP address by DNS ) and the page to display
877
;       DNS will be used to translate the web address into an IP address, if
878
;       needed.
879
;       url is at document_user and will be space terminated.
880
;       web address goes to webAddr and is space terminated.
881
;       ip address goes to server_ip
882
;       page goes to document and is space terminated.
883
;
884
;       Supported formats:
885
;       address
886
;        is optional, removed and ignored - only http supported
887
;       
is required. It can be an ip address or web address
888
;        is optional and must start with a leading / character
889
;
890
;****************************************************************************
891
parse_url:
1646 mario79 892
; First, reset destination variables
893
	cld
894
	mov	al,' '
895
	mov	edi,document
896
	mov	ecx,URLMAXLEN
897
	rep	stosb
898
	mov	edi,webAddr
899
	mov	ecx,URLMAXLEN
900
	rep	stosb
1645 clevermous 901
 
1646 mario79 902
	mov	al,'/'
903
	mov	[document],al
31 halyavin 904
 
1646 mario79 905
	mov	esi,document_user
906
; remove any leading protocol text
907
	mov	ecx,URLMAXLEN
908
	mov	ax,'//'
31 halyavin 909
 
910
pu_000:
1646 mario79 911
	cmp	[esi],byte ' '	; end of text?
912
	je	pu_002		; yep, so not found
913
	cmp	[esi],ax
914
	je	pu_001	; Found it, so esi+2 is start
915
	inc	esi
916
	loop	pu_000
31 halyavin 917
 
918
pu_002:
1646 mario79 919
; not found, so reset esi to start
920
	mov	esi,document_user-2
31 halyavin 921
 
922
pu_001:
1646 mario79 923
	add	esi,2
924
	mov	ebx,esi	; save address of start of web address
925
	mov	edi,document_user + URLMAXLEN	; end of string
926
; look for page delimiter - it's a '/' character
31 halyavin 927
pu_003:
1646 mario79 928
	cmp	[esi],byte ' '	; end of text?
929
	je	pu_004		; yep, so none found
930
	cmp	esi,edi		; end of string?
931
	je	pu_004		; yep, so none found
932
	cmp	[esi],byte '/'	; delimiter?
933
	je	pu_005		; yep - process it
934
	inc	esi
935
	jmp	pu_003
31 halyavin 936
 
937
pu_005:
1646 mario79 938
; copy page to document address
939
; esi = delimiter
940
	push	esi
941
	mov	ecx,edi		; end of document_user
942
	mov	edi,document
943
	cld
31 halyavin 944
 
945
pu_006:
1646 mario79 946
	movsb
947
	cmp	esi,ecx
948
	je	pu_007		; end of string?
949
	cmp	[esi],byte ' '	; end of text
950
;	je	pu_007		; дзен-ассемблер
951
;	jmp	pu_006		; не надо плодить сущности по напрасну
952
	jne	pu_006
31 halyavin 953
 
954
pu_007:
1646 mario79 955
	pop	esi	; point esi to '/' delimiter
31 halyavin 956
 
957
pu_004:
1646 mario79 958
; copy web address to webAddr
959
; start in ebx,end in esi-1
960
	mov	ecx,esi
961
	mov	esi,ebx
962
	mov	edi,webAddr
963
	cld
31 halyavin 964
 
965
pu_008:
1646 mario79 966
	movsb
967
	cmp	esi,ecx
968
;	je	pu_009		; дзен-ассемблер
969
;	jmp	pu_008		; не надо плодить сущности по напрасну
970
	jne	pu_008
31 halyavin 971
 
972
pu_009:
1646 mario79 973
; For debugging, display resulting strings
974
if	DEBUGGING_STATE = DEBUGGING_ENABLED
975
	mov	esi,document_user
976
	call	debug_print_string
977
	mov	esi,webAddr
978
	call	debug_print_string
979
	mov	esi,document
980
	call	debug_print_string
981
end	if
982
; Look up the ip address, or was it specified?
983
	mov	al,[proxyAddr]
984
	cmp	al,0
985
	jnz	pu_015
986
	mov	al,[webAddr]
1645 clevermous 987
pu_015:
1646 mario79 988
	cmp	al,'0'
989
	jb	pu_010	; Resolve address
990
	cmp	al,'9'
991
	ja	pu_010	; Resolve address
31 halyavin 992
 
1646 mario79 993
if	DEBUGGING_STATE = DEBUGGING_ENABLED
994
	mov	esi,str2	; print	gotip
995
	call	debug_print_string
996
end	if
997
; Convert address
998
; If proxy is given, get proxy address instead of server
999
	mov	esi,proxyAddr-1
1000
	cmp	byte [esi+1],0
1001
	jnz	pu_020
1002
	mov	esi,webAddr-1
31 halyavin 1003
 
1645 clevermous 1004
pu_020:
1646 mario79 1005
	mov	edi,server_ip
1006
	xor	eax,eax
1645 clevermous 1007
 
31 halyavin 1008
ip1:
1646 mario79 1009
	inc	esi
1010
	cmp	[esi],byte '0'
1011
	jb	ip2
1012
	cmp	[esi],byte '9'
1013
	jg	ip2
1014
	imul	eax,10
1015
	movzx	ebx,byte [esi]
1016
	sub	ebx,48
1017
	add	eax,ebx
1018
	jmp	ip1
1019
 
31 halyavin 1020
ip2:
1646 mario79 1021
	mov	[edi],al
1022
	xor	eax,eax
1023
	inc	edi
1024
	cmp	edi,server_ip+3
1025
	jbe	ip1
1026
	jmp	pu_011
31 halyavin 1027
 
1028
pu_010:
1646 mario79 1029
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1030
	mov	esi,str1	; print	resolving
1031
	call	debug_print_string
1032
end	if
1033
; Resolve Address
1034
	call	translateData	; Convert domain & DNS IP address
1035
	call	resolveDomain	; get ip address
31 halyavin 1036
 
1646 mario79 1037
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1038
	mov	esi,str3
1039
	call	debug_print_string
1040
end	if
31 halyavin 1041
 
1042
pu_011:
1646 mario79 1043
; Done
1044
	ret
31 halyavin 1045
 
1046
;***************************************************************************
1047
;   Function
1048
;      translateData
1049
;
1050
;   Description
1051
;      Coverts the domain name and DNS IP address typed in by the user into
1052
;      a format suitable for the IP layer.
1053
;
1054
;    The ename, in query, is converted and stored in dnsMsg
1055
;
1056
;***************************************************************************
1057
translateData:
1058
    ; first, get the IP address of the DNS server
1059
    ; Then, build up the request string.
1060
 
1061
    ; Build the request string
1646 mario79 1062
	mov	eax,0x00010100
1063
	mov	[dnsMsg],eax
1064
	mov	eax,0x00000100
1065
	mov	[dnsMsg+4],eax
1066
	mov	eax,0x00000000
1067
	mov	[dnsMsg+8],eax
1068
; domain name goes in at dnsMsg+12
1069
	mov	esi,dnsMsg +12	;location of label length
1070
	mov	edi,dnsMsg + 13	;label start
1071
	mov	edx,proxyAddr
1072
	cmp	byte [edx],0
1073
	jnz	td000
1074
	mov	edx,webAddr
31 halyavin 1075
 
1645 clevermous 1076
td000:
1646 mario79 1077
	mov	ecx,12	; total string length so far
31 halyavin 1078
 
1079
td002:
1646 mario79 1080
	mov	[esi],byte 0
1081
	inc	ecx
31 halyavin 1082
 
1083
td0021:
1646 mario79 1084
	mov	al,[edx]
1085
	cmp	al,' '
1086
	je	td001	; we have finished the string translation
31 halyavin 1087
 
1646 mario79 1088
	cmp	al,0
1089
	je	td001
31 halyavin 1090
 
1646 mario79 1091
	cmp	al,'.'	; we have finished the label
1092
	je	td004
31 halyavin 1093
 
1646 mario79 1094
	inc	byte [esi]
1095
	inc	ecx
1096
	mov	[edi],al
1097
	inc	edi
1098
	inc	edx
1099
	jmp	td0021
31 halyavin 1100
 
1646 mario79 1101
td004:
1102
	mov	esi,edi
1103
	inc	edi
1104
	inc	edx
1105
	jmp	td002
31 halyavin 1106
 
1646 mario79 1107
; write label len + label text
31 halyavin 1108
td001:
1646 mario79 1109
	mov	[edi],byte 0
1110
	inc	ecx
1111
	inc	edi
1112
	mov	[edi],dword 0x01000100
1113
	add	ecx,4
1114
	mov	[dnsMsgLen],ecx
1115
	ret
31 halyavin 1116
 
1117
;***************************************************************************
1118
;   Function
1119
;      resolveDomain
1120
;
1121
;   Description
1122
;       Sends a question to the dns server
1123
;       works out the IP address from the response from the DNS server
1124
;
1125
;***************************************************************************
1126
resolveDomain:
1646 mario79 1127
; Get a free port number
1128
	mov	ecx,1000	; local port starting at 1000
31 halyavin 1129
getlp:
1646 mario79 1130
	inc	ecx
1131
	push	ecx
1132
	mcall	53,9
1133
	pop	ecx
1134
	cmp	eax,0	; is this local port in use?
1135
	jz	getlp	; yes - so try next
31 halyavin 1136
 
1646 mario79 1137
; Get DNS IP
1138
	mcall	52,13
1139
	mov	esi,eax
1140
; First, open socket
1141
	mov	edx,53	; remote port - dns
1142
;	mov	esi,dword [dns_ip]
1143
	xor	ebx,ebx	; 0
1144
	mcall	53
1145
	mov	[socketNum],eax
1146
; write to socket ( request DNS lookup )
1147
	mcall	53,4,[socketNum],[dnsMsgLen],dnsMsg
1148
; Setup the DNS response buffer
1149
	mov	eax,dnsMsg
1150
	mov	[dnsMsgLen],eax
1151
; now, we wait for
1152
; UI redraw
1153
; UI close
1154
; or data from remote
31 halyavin 1155
 
1156
ctr001:
1646 mario79 1157
	mcall	10	; wait here for event
1158
	cmp	eax,1	; redraw request ?
1159
	je	ctr003
31 halyavin 1160
 
1646 mario79 1161
	cmp	eax,2	; key in buffer ?
1162
	je	ctr004
31 halyavin 1163
 
1646 mario79 1164
	cmp	eax,3	; button in buffer ?
1165
	je	ctr005
1166
; Any data in the UDP receive buffer?
1167
	mcall	53,2,[socketNum]
1168
	cmp	eax,0
1169
	je	ctr001
31 halyavin 1170
 
1646 mario79 1171
; we have data - this will be the response
31 halyavin 1172
ctr002:
1646 mario79 1173
	mcall	53,3,[socketNum]	; read byte - block (high byte)
1174
; Store the data in the response buffer
1175
	mov	eax,[dnsMsgLen]
1176
	mov	[eax],bl
1177
	inc	dword [dnsMsgLen]
31 halyavin 1178
 
1646 mario79 1179
	mcall	53,2,[socketNum]	; any more data?
1180
	cmp	eax,0
1181
	jne	ctr002	; yes, so get it
31 halyavin 1182
 
1646 mario79 1183
; close	socket
1184
	mcall	53,1,[socketNum]
1185
	mov	[socketNum],dword  0xFFFF
1186
; Now parse the message to get the host IP
1187
; Man, this is complicated. It's described in
1188
; RFC 1035
1189
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1190
	mov	esi,str4
1191
	call	debug_print_string
1192
end	if
31 halyavin 1193
 
1194
    ; 1) Validate that we have an answer with > 0 responses
1195
    ; 2) Find the answer record with TYPE 0001 ( host IP )
1196
    ; 3) Finally, copy the IP address to the display
1197
    ; Note: The response is in dnsMsg
1198
    ;       The end of the buffer is pointed to by [dnsMsgLen]
1199
 
1646 mario79 1200
; Clear the IP address text
1201
	mov	[server_ip],dword  0
1202
	mov	esi,dnsMsg
1203
; Is this a response to my question?
1204
	mov	al,[esi+2]
1205
	and	al,0x80
1206
	cmp	al,0x80
1207
	jne	ctr002a
1208
; Were there any errors?
1209
	mov	al,[esi+3]
1210
	and	al,0x0F
1211
	cmp	al,0x00
1212
	jne	ctr002a
1213
; Is there ( at least 1 ) answer?
1214
	mov	ax,[esi+6]
1215
	cmp	ax,0x00
1216
	je	ctr002a
1217
; Header valdated. Scan through and get my answer
1218
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1219
	pusha
1220
	mov	esi,str4
1221
	call	debug_print_string
1222
	popa
1223
end	if
1224
	add	esi,12	; Skip to the question field
1225
; Skip through the question field
1226
	call	skipName
1227
	add	esi,4	; skip past the questions qtype, qclass
31 halyavin 1228
 
1229
ctr002z:
1646 mario79 1230
; Now at the answer. There may be several answers,
1231
; find the right one ( TYPE = 0x0001 )
1232
	call	skipName
1233
	mov	ax,[esi]
1234
	cmp	ax,0x0100	; Is this the IP address answer?
1235
	jne	ctr002c
1236
; Yes! Point esi to the first byte of the IP address
1237
	add	esi,10
1238
	mov	eax,[esi]
1239
	mov	[server_ip],eax
1240
	ret
31 halyavin 1241
 
1646 mario79 1242
ctr002c:	; Skip through the answer, move to the next
1243
	add	esi,8
1244
	movzx	eax,byte [esi+1]
1245
	mov	ah,[esi]
1246
	add	esi,eax
1247
	add	esi,2
1248
; Have we reached the end of the msg?
1249
; This is an error condition, should not happen
1250
	cmp	esi,[dnsMsgLen]
1251
	jl	ctr002z	; Check next answer
1252
	jmp	ctr002a	; abort
31 halyavin 1253
 
1254
ctr002a:
1646 mario79 1255
	jmp	ctr001
31 halyavin 1256
 
1646 mario79 1257
ctr003:	; redraw
1258
	call	draw_window
1259
	jmp	ctr001
31 halyavin 1260
 
1646 mario79 1261
ctr004:	; key
1262
	mcall	2	; just read it and ignore
1263
	jmp	ctr001
31 halyavin 1264
 
1646 mario79 1265
ctr005:	; button
1266
	mcall	17	; get id
1267
	mov	dl,ah
31 halyavin 1268
 
1646 mario79 1269
	; close	socket
1270
	mcall	53,1,[socketNum]
1271
	cmp	dl,1
1272
	je	exit
31 halyavin 1273
 
1646 mario79 1274
	mov	[socketNum],dword  0xFFFF
1275
	mov	[server_ip],dword  0
1276
	ret
31 halyavin 1277
 
1278
;***************************************************************************
1279
;   Function
1280
;      skipName
1281
;
1282
;   Description
1283
;       Increment esi to the first byte past the name field
1284
;       Names may use compressed labels. Normally do.
1285
;       RFC 1035 page 30 gives details
1286
;
1287
;***************************************************************************
1288
skipName:
1646 mario79 1289
	mov	al,[esi]
1290
	cmp	al,0
1291
	je	sn_exit
1292
	and	al,0xc0
1293
	cmp	al,0xc0
1294
	je	sn001
31 halyavin 1295
 
1646 mario79 1296
	movzx	eax,byte [esi]
1297
	inc	eax
1298
	add	esi,eax
1299
	jmp	skipName
31 halyavin 1300
 
1301
sn001:
1646 mario79 1302
	add	esi,2	; A pointer is always at the end
1303
	ret
31 halyavin 1304
 
1305
sn_exit:
1646 mario79 1306
	inc	esi
1307
	ret
31 halyavin 1308
 
1645 clevermous 1309
;***************************************************************************
1310
;   Function
1311
;       load_settings
1312
;
1313
;   Description
1314
;       Load settings from configuration file network.ini
1315
;
1316
;***************************************************************************
1317
load_settings:
1646 mario79 1318
	stdcall	dll.Load,@IMPORT
1319
	test	eax,eax
1320
	jnz	ls001
1321
	invoke	ini.get_str,inifile,sec_proxy,key_proxy,proxyAddr,256,proxyAddr
1322
	invoke	ini.get_int,inifile,sec_proxy,key_proxyport,80
1323
	mov	[proxyPort],eax
1324
	invoke	ini.get_str,inifile,sec_proxy,key_user,	proxyUser,256,proxyUser
1325
	invoke	ini.get_str,inifile,sec_proxy,key_password,proxyPassword,256,proxyPassword
1645 clevermous 1326
ls001:
1646 mario79 1327
	ret
31 halyavin 1328
 
1645 clevermous 1329
;***************************************************************************
1330
;   Function
1331
;       append_proxy_auth_header
1332
;
1333
;   Description
1334
;       Append header to HTTP request for proxy authentification
1335
;
1336
;***************************************************************************
1337
append_proxy_auth_header:
1646 mario79 1338
	mov	esi,proxy_auth_basic
1339
	mov	ecx,proxy_auth_basic_end - proxy_auth_basic
1340
	rep	movsb
1341
; base64-encode string :
1342
	mov	esi,proxyUser
1343
 
1645 clevermous 1344
apah000:
1646 mario79 1345
	lodsb
1346
	test	al,al
1347
	jz	apah001
1348
	call	encode_base64_byte
1349
	jmp	apah000
1350
 
1645 clevermous 1351
apah001:
1646 mario79 1352
	mov	al,':'
1353
	call	encode_base64_byte
1354
	mov	esi,proxyPassword
1355
 
1645 clevermous 1356
apah002:
1646 mario79 1357
	lodsb
1358
	test	al,al
1359
	jz	apah003
1360
	call	encode_base64_byte
1361
	jmp	apah002
1362
 
1645 clevermous 1363
apah003:
1646 mario79 1364
	call	encode_base64_final
1365
	ret
31 halyavin 1366
 
1645 clevermous 1367
encode_base64_byte:
1646 mario79 1368
	inc	ecx
1369
	shl	edx,8
1370
	mov	dl,al
1371
	cmp	ecx,3
1372
	je	ebb001
1373
	ret
1374
 
1645 clevermous 1375
ebb001:
1646 mario79 1376
	shl	edx,8
1377
	inc	ecx
1378
 
1645 clevermous 1379
ebb002:
1646 mario79 1380
	rol	edx,6
1381
	xor	eax,eax
1382
	xchg	al,dl
1383
	mov	al,[base64_table+eax]
1384
	stosb
1385
	loop	ebb002
1386
	ret
1645 clevermous 1387
 
1388
encode_base64_final:
1646 mario79 1389
	mov	al,0
1390
	test	ecx,ecx
1391
	jz	ebf000
1392
	call	encode_base64_byte
1393
	test	ecx,ecx
1394
	jz	ebf001
1395
	call	encode_base64_byte
1396
	mov	byte [edi-2],'='
1397
 
1645 clevermous 1398
ebf001:
1646 mario79 1399
	mov	byte [edi-1],'='
1400
 
1645 clevermous 1401
ebf000:
1646 mario79 1402
	ret
1645 clevermous 1403
 
1646 mario79 1404
if	DEBUGGING_STATE = DEBUGGING_ENABLED
31 halyavin 1405
 
1406
;****************************************************************************
1407
;    Function
1408
;       debug_print_string
1409
;
1410
;   Description
1411
;       prints a string to the debug board, in quotes
1412
;
1413
;       esi holds ptr to msg to display, which is space or 0 terminated
1414
;
1415
;       Nothing preserved; I'm assuming a pusha/popa is done before calling
1416
;
1417
;****************************************************************************
1418
debug_print_string:
1646 mario79 1419
	push	esi
1420
	mov	cl,'"'
1421
	mcall	63,1
1422
	pop	esi
31 halyavin 1423
 
1424
dps_000:
1646 mario79 1425
	mov	cl,[esi]
1426
	cmp	cl,0
1427
	je	dps_exit
31 halyavin 1428
 
1646 mario79 1429
	cmp	cl,' '
1430
	je	dps_exit
1431
	jmp	dps_001
1432
 
31 halyavin 1433
dps_exit:
1646 mario79 1434
	mov	cl,'"'
1435
	mcall	63,1
1436
	mov	cl,13
1437
	mcall
1438
	mov	cl,10
1439
	mcall
1440
	ret
31 halyavin 1441
 
1442
dps_001:
1646 mario79 1443
	push	esi
1444
	mcall	63,1
1445
	pop	esi
1446
	inc	esi
1447
	jmp	dps_000
1448
end	if
31 halyavin 1449
 
1450
;****************************************************************************
1451
;    Function
1452
;       print_text
1453
;
1454
;   Description
1455
;       display the url (full path) text
1456
;
1457
;****************************************************************************
1458
print_text:
1646 mario79 1459
; Draw a bar to blank out previous text
1460
	mov	ebx,30*65536+URLMAXLEN*6	; 50 should really be [len] and 103 [xa]
1461
	mov	ecx,[ya]
1462
	shl	ecx,16
1463
	mov	cx,9
1464
	mcall	13,,,0xFFFFFF
1465
; write text
1466
	mov	ebx,30*65536
1467
	add	ebx,[ya]
1468
	xor	ecx,ecx
1469
	mcall	4,,,[addr],URLMAXLEN
1470
	ret
31 halyavin 1471
 
1472
;   *********************************************
1473
;   *******  WINDOW DEFINITIONS AND DRAW ********
1474
;   *********************************************
1475
 
1476
draw_window:
1646 mario79 1477
; function 12: tell os about windowdraw
1478
; 1 start of draw
1479
	mcall	12,1
1645 clevermous 1480
 
1646 mario79 1481
;	cmp	[params],byte 0
1482
;	jz	.noret
1645 clevermous 1483
 
1646 mario79 1484
; это несколько загадочно, но если не рисовать окошко совсем, прога не пашет.
1485
; DRAW	WINDOW
1486
; eax	function 0 : define and draw window
1487
;	xor	eax,eax
1488
; ebx	[x start] *65536 + [x size]
1489
;	xor	ebx,ebx
1490
; ecx	[y start] *65536 + [y size]
1491
;	xor	ecx,ecx
1492
; edx	color of work area RRGGBB,8->color gl
1493
; esi	color of bar and flags
1494
;	xor	esi,esi
1495
;	mcall	,,,0x14ffffff,,title
31 halyavin 1496
 
1646 mario79 1497
; function 12: tell os about windowdraw
1498
; 2, end of draw
1499
;	mcall	12,2
1500
;	ret
1645 clevermous 1501
 
1646 mario79 1502
;.noret:
1503
; DRAW	WINDOW
1504
; eax	function 0 : define and draw window
1505
	xor	eax,eax
1506
; ebx	[x start] *65536 + [x size]
1507
; ecx	[y start] *65536 + [y size]
1508
; edx	color of work area RRGGBB,8->color gl
1509
; esi	color of bar and flags
1510
	xor	esi,esi
1511
; edi	WINDOW	LABEL
1512
	mcall	,<50,600>,<350,200>,0x14ffffff,,title
1513
; eax	function 4: write text to window
1514
; ebx	[x start] *65536 + [y start]
1515
; ecx	color of text RRGGBB
1516
; edx	pointer to text beginning
1517
; esi	max lenght
1518
	xor	ecx,ecx
1519
	mcall	4,<30,38>,,document_user,URLMAXLEN
1645 clevermous 1520
 
1646 mario79 1521
;	xor	edx,edx
1522
;	mcall	38,<5,545>,<60,60>
1645 clevermous 1523
 
1646 mario79 1524
;	mov	ecx,[winys]
1525
;	shl	ecx,16
1526
;	add	ecx,[winys]
1527
;	sub	ecx,26*65536+26
1528
;	mcall	38,<5,545>
1645 clevermous 1529
 
1646 mario79 1530
; RELOAD
1531
; eax	function 8 : define and draw button
1532
; ebx	[x start] *65536 + [x size]
1533
; ecx	[y start] *65536 + [y size]
1534
; edx	button id
1535
; esi	button color RRGGBB
1536
	mcall	8,<388,50>,<34,14>,22,0x5588dd
1537
; URL
1538
	mcall	,<10,12>,<34,12>,10
1539
; STOP
1540
	mcall	,<443,50>,<34,14>,24
1541
; SAVE
1542
	mcall	,<498,50>,,26
1543
; BUTTON TEXT
1544
; eax	function 4 : write text to window
1545
; ebx	[x start] *65536 + [y start]
1546
; ecx	color	of	text	RRGGBB
1547
; edx	pointer	to	text	beginning
1548
; esi	text	length
1549
	mcall	4,<390,38>,0xffffff,button_text,30
1550
	call	display_page
31 halyavin 1551
 
1646 mario79 1552
; function 12: tell os about windowdraw
1553
; 2, end of draw
1554
	mcall	12,2
1555
	ret
1556
;-----------------------------------------------------------------------------
1557
; Data area
1558
;-----------------------------------------------------------------------------
1559
align	4
1645 clevermous 1560
@IMPORT:
31 halyavin 1561
 
1646 mario79 1562
library	libini,'libini.obj'
1645 clevermous 1563
 
1564
import	libini, \
1646 mario79 1565
	ini.get_str,'ini_get_str', \
1566
	ini.get_int,'ini_get_int'
1645 clevermous 1567
 
1646 mario79 1568
;---------------------------------------------------------------------
1569
fileinfo	dd 2,0,0
1570
final_size	dd 0
1571
final_buffer	dd 0
1572
		db '/rd/1/.download',0
1573
 
1574
body_pos	dd 0
1645 clevermous 1575
 
1646 mario79 1576
;fileinfo_tmp	dd 2,0,0
1577
buf_size	dd 0
1578
buf_ptr		dd 0
1579
;		db	'/rd/1/1',0
1645 clevermous 1580
 
1646 mario79 1581
deba		dd 0
1582
		db 0
1583
;---------------------------------------------------------------------
1584
if	DEBUGGING_STATE = DEBUGGING_ENABLED
1585
str1:		db "Resolving...",0
1586
str3:		db "Resolved",0
1587
str2:		db "GotIP",0
1588
str4:		db "GotResponse",0
1589
end	if
1590
;---------------------------------------------------------------------
1591
button_text	db ' RELOAD    STOP       SAVE    '
1592
dpx		dd 25	; x - start of html page in pixels in window
1593
dpy		dd 65	; for	y
1594
lastletter	db 0
1595
pageyinc	dd 0
1596
display_from	dd 20
1597
pos		dd 0x0
1598
pagex		dd 0x0
1599
pagey		dd 0x0
1600
pagexs		dd 80
1601
command_on_off	dd 0x0
1602
text_type	db 1
1603
com2		dd 0x0
1604
script		dd 0x0
1605
socket		dd 0x0
1645 clevermous 1606
 
1646 mario79 1607
addr		dd 0x0
1608
ya		dd 0x0
1609
len		dd 0x00
1645 clevermous 1610
 
1646 mario79 1611
title		db 'Downloader',0
1645 clevermous 1612
 
1646 mario79 1613
server_ip:	db 207,44,212,20
1614
;dns_ip:	db 194,145,128,1
1615
;---------------------------------------------------------------------
1616
;webAddr:
1617
;times URLMAXLEN db ' '
1618
;db	0
31 halyavin 1619
 
1646 mario79 1620
;document_user:	db 'Click on the button to the left to enter a URL',0
1621
;times URLMAXLEN+document_user-$ db 0
1645 clevermous 1622
 
1646 mario79 1623
;document:	db '/'
1624
;times URLMAXLEN-1 db ' '
1625
;---------------------------------------------------------------------
1626
s_contentlength	db 'Content-Length:'
1627
len_contentlength = 15
31 halyavin 1628
 
1646 mario79 1629
s_chunked	db 'Transfer-Encoding: chunked'
1630
len_chunked	= $ - s_chunked
31 halyavin 1631
 
1646 mario79 1632
is_body		dd 0	; 0 if headers, 1 if content
1633
is_chunked	dd 0
1634
prev_chunk_end	dd 0
1635
cur_chunk_size	dd 0
31 halyavin 1636
 
1646 mario79 1637
string0:	db 'GET '
31 halyavin 1638
 
1646 mario79 1639
stringh:        db ' HTTP/1.1',13,10,'Host: '
31 halyavin 1640
stringh_end:
1646 mario79 1641
proxy_auth_basic:	db 13,10,'Proxy-Authorization: Basic '
1645 clevermous 1642
proxy_auth_basic_end:
1646 mario79 1643
connclose:	db 13,10,'User-Agent: Kolibrios Downloader',13,10,'Connection: Close',13,10,13,10
1645 clevermous 1644
connclose_end:
31 halyavin 1645
 
1646 mario79 1646
base64_table	db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
1647
		db '0123456789+/'
1645 clevermous 1648
 
1646 mario79 1649
inifile		db '/sys/network/zeroconf.ini',0
1645 clevermous 1650
 
1651
sec_proxy:
1646 mario79 1652
key_proxy	db 'proxy',0
1653
key_proxyport	db 'port',0
1654
key_user	db 'user',0
1655
key_password	db 'password',0
1645 clevermous 1656
 
1657
 
1646 mario79 1658
proxyPort	dd 80
1645 clevermous 1659
 
1646 mario79 1660
shared_name	dd 0
1645 clevermous 1661
 
1646 mario79 1662
;yandex:	db 'menuetos.net'
1645 clevermous 1663
;yandex_end:
1664
 
1646 mario79 1665
status		dd 0x0
1666
prev_status	dd 0x0
31 halyavin 1667
 
1646 mario79 1668
onoff		dd 0x0
31 halyavin 1669
 
1646 mario79 1670
nextupdate:	dd 0
1671
winys:		dd 400
31 halyavin 1672
 
1646 mario79 1673
dnsMsgLen:	dd 0
1674
socketNum:	dd 0xFFFF
1675
;---------------------------------------------------------------------
1676
document_user:	db 'Click on the button to the left to enter a URL',0
1677
;---------------------------------------------------------------------
1678
IM_END:
1679
	rb URLMAXLEN-(IM_END - document_user)
1680
;---------------------------------------------------------------------
1681
align 4
1682
document:
1683
	rb URLMAXLEN
1684
;---------------------------------------------------------------------
1685
align 4
1686
webAddr:
1687
	rb URLMAXLEN+1
1688
;---------------------------------------------------------------------
1689
align 4
1690
primary_buf:
1691
	rb primary_buffer_size
1692
;---------------------------------------------------------------------
1693
align 4
1694
params:		; db 1024 dup(0)
1695
	rb 1024
1696
;---------------------------------------------------------------------
1697
align 4
1698
request:	; db 256 dup(0)
1699
	rb 256
1700
;---------------------------------------------------------------------
1701
align 4
1702
proxyAddr:	; db 256 dup(0)
1703
	rb 256
1704
;---------------------------------------------------------------------
1705
align 4
1706
proxyUser:	; db 256 dup(0)
1707
	rb 256
1708
;---------------------------------------------------------------------
1709
align 4
1710
proxyPassword:	; db 256 dup(0)
1711
	rb 256
1712
;---------------------------------------------------------------------
1713
align 4
31 halyavin 1714
dnsMsg:
1646 mario79 1715
	rb 4096
1716
;	rb 0x100000
1717
;---------------------------------------------------------------------
1718
align 4
1719
	rb 4096
1720
stacktop:
1721
;---------------------------------------------------------------------
31 halyavin 1722
I_END:
1646 mario79 1723
;---------------------------------------------------------------------