Subversion Repositories Kolibri OS

Rev

Rev 5539 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4830 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
7008 hidnplayr 3
;; Copyright (C) KolibriOS team 2014-2017. All rights reserved.    ;;
4830 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
7008 hidnplayr 6
;;  post.asm - HTTP library example:                               ;;
7
;;   Paste something to paste.kolibrios.org using HTTP POST method.;;
4830 hidnplayr 8
;;                                                                 ;;
9
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;             Version 2, June 1991                                ;;
11
;;                                                                 ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
format binary as ""
15
use32
16
        org     0x0
17
 
18
        db      'MENUET01'      ; header
19
        dd      0x01            ; header version
20
        dd      START           ; entry point
21
        dd      IM_END          ; image size
22
        dd      I_END+0x1000    ; required memory
23
        dd      I_END+0x1000    ; esp
24
        dd      0
25
        dd      0               ; I_Path
26
 
27
 
28
include '../../../../macros.inc'
29
include '../../../../proc32.inc'
30
include '../../../../dll.inc'
31
include '../../http/http.inc'
32
 
33
virtual at 0
34
        http_msg http_msg
35
end virtual
36
 
37
 
38
START:
39
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
40
 
41
; load libraries
42
        stdcall dll.Load, @IMPORT
43
        test    eax, eax
44
        jnz     exit
45
 
5534 hidnplayr 46
        invoke  HTTP_get, sz_url, 0, 0, 0
4830 hidnplayr 47
        test    eax, eax
48
        jz      error
49
        mov     [identifier], eax
50
 
51
  .again:
5534 hidnplayr 52
        invoke  HTTP_receive, [identifier]
4830 hidnplayr 53
        test    eax, eax
54
        jnz     .again
55
 
56
        invoke  HTTP_find_header_field, [identifier], sz_set_cookie
57
        mov     edi, cookie
58
        test    eax, eax
59
        jz      .no_cookie
60
 
61
        mov     esi, eax
62
  .cookie_loop:
63
        lodsb
64
        stosb
65
        cmp     al, 13
66
        je      .cookie_end
67
        cmp     al, 10
68
        je      .cookie_end
69
        cmp     al, 0
70
        je      .cookie_end
71
        jmp     .cookie_loop
72
  .cookie_end:
73
        dec     edi
74
  .no_cookie:
75
        mov     ax, 0x0a0d
76
        stosw
77
        xor     al, al
78
        stosb
79
 
80
        invoke  HTTP_free, [identifier]
81
 
5534 hidnplayr 82
        invoke  HTTP_post, sz_url, 0, 0, sz_cookie, sz_ctype, sz_paste.length
4830 hidnplayr 83
        test    eax, eax
84
        jz      error
85
        mov     [identifier], eax
86
 
7008 hidnplayr 87
        invoke  HTTP_send, eax, sz_paste, sz_paste.length
4830 hidnplayr 88
 
89
  .again2:
5534 hidnplayr 90
        invoke  HTTP_receive, [identifier]
4830 hidnplayr 91
        test    eax, eax
92
        jnz     .again2
93
 
94
        mov     ebp, [identifier]
95
        cmp     [ebp + http_msg.status], 302    ; found
96
        jne     error
97
 
98
        invoke  HTTP_find_header_field, [identifier], sz_location
99
        test    eax, eax
100
        jz      error
101
        mov     esi, eax
102
        mov     edi, paste_url
103
        mov     al, '"'
104
        stosb
105
  .url_loop:
106
        lodsb
107
        stosb
108
        cmp     al, 13
109
        je      .url_end
110
        cmp     al, 10
111
        je      .url_end
112
        cmp     al, 0
113
        je      .url_end
114
        jmp     .url_loop
115
  .url_end:
116
        dec     edi
117
        mov     eax, '" -N'
118
        stosd
119
        xor     al, al
120
        stosb
121
 
122
        mov     [notify_struct.msg], paste_url
123
        mcall   70, notify_struct
124
 
125
        invoke  HTTP_free, [identifier]
126
        jmp     exit
127
 
128
error:
129
        mov     [notify_struct.msg], sz_failed
130
        mcall   70, notify_struct
131
exit:
132
        mcall   -1
133
 
134
 
135
;---------------------------------------------------------------------
136
; Data area
137
;-----------------------------------------------------------------------------
138
align   4
139
@IMPORT:
140
 
141
library lib_http,       'http.obj'
142
 
143
import  lib_http, \
144
        HTTP_get,       'get', \
145
        HTTP_post,      'post', \
5534 hidnplayr 146
        HTTP_receive,   'receive', \
147
        HTTP_find_header_field, 'find_header_field', \
7008 hidnplayr 148
        HTTP_send,      'send', \
5534 hidnplayr 149
        HTTP_free,      'free'
4830 hidnplayr 150
 
151
 
152
identifier      dd 0
153
 
154
IM_END:
155
 
156
notify_struct:
157
        dd 7            ; run application
158
        dd 0
159
  .msg  dd paste_url
160
        dd 0
161
        dd 0
162
        db '/sys/@notify', 0
163
 
164
sz_url          db 'http://paste.kolibrios.org/', 0
165
sz_set_cookie   db 'set-cookie', 0
166
sz_location     db 'location', 0
167
sz_ctype        db 'application/x-www-form-urlencoded', 0
168
sz_failed       db '"Paste failed!" -N', 0
169
 
170
sz_paste        db 'code=test+from+KolibriOS+2%0D%0A&language=text&webpage='
171
.length = $ - sz_paste
172
 
173
sz_cookie       db 'Cookie: '
174
cookie          db 0
175
                rb 1024
176
 
177
paste_url       rb 1024
178
 
179
I_END:
180