Subversion Repositories Kolibri OS

Rev

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

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