Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4830 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
5534 hidnplayr 3
;; Copyright (C) KolibriOS team 2014-2015. All rights reserved.    ;;
4830 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  pasta.asm - Paste something to paste.kolibrios.org using POST  ;;
7
;;                                                                 ;;
8
;;          GNU GENERAL PUBLIC LICENSE                             ;;
9
;;             Version 2, June 1991                                ;;
10
;;                                                                 ;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
 
13
format binary as ""
14
use32
15
        org     0x0
16
 
17
        db      'MENUET01'      ; header
18
        dd      0x01            ; header version
19
        dd      START           ; entry point
20
        dd      IM_END          ; image size
21
        dd      I_END+0x1000    ; required memory
22
        dd      I_END+0x1000    ; esp
23
        dd      0
24
        dd      0               ; I_Path
25
 
26
 
27
include '../../../../macros.inc'
28
include '../../../../proc32.inc'
29
include '../../../../dll.inc'
30
include '../../http/http.inc'
31
 
32
virtual at 0
33
        http_msg http_msg
34
end virtual
35
 
36
 
37
START:
38
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
39
 
40
; load libraries
41
        stdcall dll.Load, @IMPORT
42
        test    eax, eax
43
        jnz     exit
44
 
5534 hidnplayr 45
        invoke  HTTP_get, sz_url, 0, 0, 0
4830 hidnplayr 46
        test    eax, eax
47
        jz      error
48
        mov     [identifier], eax
49
 
50
  .again:
5534 hidnplayr 51
        invoke  HTTP_receive, [identifier]
4830 hidnplayr 52
        test    eax, eax
53
        jnz     .again
54
 
55
        invoke  HTTP_find_header_field, [identifier], sz_set_cookie
56
        mov     edi, cookie
57
        test    eax, eax
58
        jz      .no_cookie
59
 
60
        mov     esi, eax
61
  .cookie_loop:
62
        lodsb
63
        stosb
64
        cmp     al, 13
65
        je      .cookie_end
66
        cmp     al, 10
67
        je      .cookie_end
68
        cmp     al, 0
69
        je      .cookie_end
70
        jmp     .cookie_loop
71
  .cookie_end:
72
        dec     edi
73
  .no_cookie:
74
        mov     ax, 0x0a0d
75
        stosw
76
        xor     al, al
77
        stosb
78
 
79
        invoke  HTTP_free, [identifier]
80
 
5534 hidnplayr 81
        invoke  HTTP_post, sz_url, 0, 0, sz_cookie, sz_ctype, sz_paste.length
4830 hidnplayr 82
        test    eax, eax
83
        jz      error
84
        mov     [identifier], eax
85
 
86
        mov     ecx, [eax + http_msg.socket]
87
        mcall   75, 6, , sz_paste, sz_paste.length, 0
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', \
148
        HTTP_free,      'free'
4830 hidnplayr 149
 
150
 
151
identifier      dd 0
152
 
153
IM_END:
154
 
155
notify_struct:
156
        dd 7            ; run application
157
        dd 0
158
  .msg  dd paste_url
159
        dd 0
160
        dd 0
161
        db '/sys/@notify', 0
162
 
163
sz_url          db 'http://paste.kolibrios.org/', 0
164
sz_set_cookie   db 'set-cookie', 0
165
sz_location     db 'location', 0
166
sz_ctype        db 'application/x-www-form-urlencoded', 0
167
sz_failed       db '"Paste failed!" -N', 0
168
 
169
sz_paste        db 'code=test+from+KolibriOS+2%0D%0A&language=text&webpage='
170
.length = $ - sz_paste
171
 
172
sz_cookie       db 'Cookie: '
173
cookie          db 0
174
                rb 1024
175
 
176
paste_url       rb 1024
177
 
178
I_END:
179