Subversion Repositories Kolibri OS

Rev

Rev 661 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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