Rev 5770 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5770 | Rev 7100 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2014-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2014-2017. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; pasta.asm - Paste text to paste.kolibrios.org from a file or ;; |
6 | ;; pasta.asm - Paste text to dpaste.com from a file or from ;; |
7 | ;; from clipboard. ;; |
7 | ;; clipboard. ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; GNU GENERAL PUBLIC LICENSE ;; |
9 | ;; GNU GENERAL PUBLIC LICENSE ;; |
10 | ;; Version 2, June 1991 ;; |
10 | ;; Version 2, June 1991 ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 100... | Line 100... | ||
100 | 100 | ||
101 | push eax |
101 | push eax |
102 | mcall 68, 13, [clipboard_data] |
102 | mcall 68, 13, [clipboard_data] |
Line 103... | Line 103... | ||
103 | pop [clipboard_data] |
103 | pop [clipboard_data] |
- | 104 | ||
- | 105 | ; Post to the server |
|
104 | 106 | mov ecx, [clipboard_data_length] |
|
105 | ; Connect to the server |
107 | add ecx, sz_paste_head.length |
106 | invoke HTTP_get, sz_url, 0, FLAG_BLOCK or FLAG_KEEPALIVE, 0 |
108 | invoke HTTP_post, sz_url, 0, FLAG_BLOCK, 0, sz_ctype, ecx |
107 | test eax, eax |
109 | test eax, eax |
Line 108... | Line -... | ||
108 | jz error_free_clip |
- | |
109 | mov [identifier], eax |
- | |
110 | 110 | jz error_free_clip_disconnect |
|
111 | .again: |
- | |
112 | invoke HTTP_receive, [identifier] |
- | |
113 | test eax, eax |
111 | mov [identifier], eax |
114 | jnz .again |
- | |
115 | - | ||
116 | invoke HTTP_find_header_field, [identifier], sz_set_cookie |
- | |
117 | mov edi, cookie |
- | |
118 | test eax, eax |
- | |
119 | jz .no_cookie |
- | |
120 | - | ||
121 | mov esi, eax |
- | |
122 | .cookie_loop: |
- | |
123 | lodsb |
- | |
124 | stosb |
- | |
125 | cmp al, 13 |
- | |
126 | je .cookie_end |
- | |
127 | cmp al, 10 |
- | |
128 | je .cookie_end |
- | |
129 | cmp al, 0 |
- | |
130 | je .cookie_end |
- | |
131 | jmp .cookie_loop |
- | |
132 | .cookie_end: |
- | |
133 | dec edi |
- | |
134 | .no_cookie: |
- | |
135 | mov ax, 0x0a0d |
- | |
Line 136... | Line 112... | ||
136 | stosw |
112 | |
137 | xor al, al |
113 | ; Send the data to the server |
- | 114 | invoke HTTP_send, [identifier], sz_paste_head, sz_paste_head.length |
|
138 | stosb |
115 | |
- | 116 | push [clipboard_data] |
|
- | 117 | pop [send_ptr] |
|
139 | 118 | .again: |
|
140 | mov ecx, [clipboard_data_length] |
119 | invoke HTTP_send, [identifier], [send_ptr], [clipboard_data_length] |
141 | add ecx, sz_paste_head.length + sz_paste_tail.length |
- | |
142 | invoke HTTP_post, sz_url, [identifier], FLAG_BLOCK, sz_cookie, sz_ctype, ecx |
- | |
143 | test eax, eax |
120 | cmp eax, -1 |
144 | jz error_free_clip_disconnect |
- | |
145 | 121 | je error_free_clip_disconnect |
|
146 | ; Send the data to the server |
122 | test eax, eax |
Line 147... | Line 123... | ||
147 | mov ecx, [eax + http_msg.socket] |
123 | jz error_free_clip_disconnect |
148 | mcall 75, 6, , sz_paste_head, sz_paste_head.length, 0 |
124 | add [send_ptr], eax |
Line 149... | Line 125... | ||
149 | mcall 75, 6, , [clipboard_data], [clipboard_data_length], 0 |
125 | sub [clipboard_data_length], eax |
Line 158... | Line 134... | ||
158 | jnz .again2 |
134 | jnz .again2 |
Line 159... | Line 135... | ||
159 | 135 | ||
Line 160... | Line 136... | ||
160 | invoke HTTP_disconnect, [identifier] |
136 | invoke HTTP_disconnect, [identifier] |
- | 137 | ||
- | 138 | mov ebp, [identifier] |
|
- | 139 | test [ebp + http_msg.flags], 0xffff0000 ; Test error bits |
|
- | 140 | jnz error_free_http |
|
161 | 141 | test [ebp + http_msg.flags], FLAG_GOT_HEADER |
|
162 | mov ebp, [identifier] |
142 | jz error_free_http |
Line 163... | Line 143... | ||
163 | cmp [ebp + http_msg.status], 302 ; found |
143 | cmp [ebp + http_msg.status], 201 ; created |
164 | jne error_free_http |
144 | jne error_http_code |
165 | 145 | ||
Line 166... | Line -... | ||
166 | invoke HTTP_find_header_field, [identifier], sz_location |
- | |
167 | test eax, eax |
- | |
168 | jz error_free_http |
- | |
169 | 146 | invoke HTTP_find_header_field, [identifier], sz_location |
|
170 | push eax |
- | |
171 | mov esi, sz_failed |
- | |
172 | mov edi, paste_url |
- | |
173 | mov ecx, 2 |
- | |
174 | rep movsd |
- | |
175 | pop esi |
- | |
176 | .url_loop: |
- | |
177 | lodsb |
- | |
178 | stosb |
- | |
179 | cmp al, 13 |
- | |
180 | je .url_end |
- | |
181 | cmp al, 10 |
- | |
182 | je .url_end |
- | |
183 | cmp al, 0 |
- | |
184 | je .url_end |
- | |
185 | jmp .url_loop |
- | |
186 | .url_end: |
- | |
187 | dec edi |
- | |
188 | lea ecx, [edi - paste_url + 4] |
- | |
189 | mov eax, '" -t' |
- | |
190 | stosd |
147 | test eax, eax |
Line 191... | Line 148... | ||
191 | mov ax, 'O' |
148 | jz error_free_http |
Line 192... | Line 149... | ||
192 | stosw |
149 | |
193 | mov [notify_struct.msg], paste_url |
150 | mov esi, eax |
194 | mcall 70, notify_struct |
151 | call notify |
195 | 152 | ||
Line 196... | Line 153... | ||
196 | mcall 54, 3 ; Delete last slot in the clipboard |
153 | mcall 54, 3 ; Delete last slot in the clipboard |
197 | 154 | ||
Line -... | Line 155... | ||
- | 155 | mov dword[notify_msg-4], ecx |
|
- | 156 | mov dword[notify_msg+0], 0 ; Text |
|
- | 157 | mov dword[notify_msg+4], 1 ; cp0866 |
|
198 | mov dword[paste_url-4], ecx |
158 | mcall 54, 2, , notify_msg-4 ; Write URL to the clipboard |
199 | mov dword[paste_url+0], 0 ; Text |
159 | |
200 | mov dword[paste_url+4], 1 ; cp0866 |
160 | invoke HTTP_free, [identifier] |
201 | mcall 54, 2, , paste_url-4 ; Write URL to the clipboard |
161 | mcall -1 |
202 | 162 | ||
Line 216... | Line 176... | ||
216 | mcall 70, notify_struct |
176 | mcall 70, notify_struct |
Line 217... | Line 177... | ||
217 | 177 | ||
Line -... | Line 178... | ||
- | 178 | mcall -1 |
|
- | 179 | ||
- | 180 | ||
- | 181 | notify: |
|
- | 182 | ||
- | 183 | mov edi, notify_msg.text |
|
- | 184 | .msg_loop: |
|
- | 185 | lodsb |
|
- | 186 | stosb |
|
- | 187 | cmp al, 13 |
|
- | 188 | je .msg_end |
|
- | 189 | cmp al, 10 |
|
- | 190 | je .msg_end |
|
- | 191 | cmp al, 0 |
|
- | 192 | je .msg_end |
|
- | 193 | jmp .msg_loop |
|
- | 194 | .msg_end: |
|
- | 195 | dec edi |
|
- | 196 | lea ecx, [edi - notify_msg + 4] |
|
- | 197 | mov eax, '" -t' |
|
- | 198 | stosd |
|
- | 199 | mov ax, 'O' |
|
- | 200 | stosw |
|
- | 201 | mov [notify_struct.msg], notify_msg |
|
- | 202 | mcall 70, notify_struct |
|
- | 203 | ||
218 | mcall -1 |
204 | ret |
219 | 205 | ||
220 | 206 | ||
221 | ;--------------------------------------------------------------------- |
207 | ;--------------------------------------------------------------------- |
222 | ; Data area |
208 | ; Data area |
Line 227... | Line 213... | ||
227 | library lib_http, 'http.obj' |
213 | library lib_http, 'http.obj' |
Line 228... | Line 214... | ||
228 | 214 | ||
229 | import lib_http, \ |
215 | import lib_http, \ |
230 | HTTP_get, 'get', \ |
216 | HTTP_get, 'get', \ |
- | 217 | HTTP_post, 'post', \ |
|
231 | HTTP_post, 'post', \ |
218 | HTTP_send, 'send', \ |
232 | HTTP_receive, 'receive', \ |
219 | HTTP_receive, 'receive', \ |
233 | HTTP_find_header_field, 'find_header_field', \ |
220 | HTTP_find_header_field, 'find_header_field', \ |
234 | HTTP_free, 'free', \ |
221 | HTTP_free, 'free', \ |
235 | HTTP_escape, 'escape', \ |
222 | HTTP_escape, 'escape', \ |
Line 247... | Line 234... | ||
247 | dd param |
234 | dd param |
Line 248... | Line 235... | ||
248 | 235 | ||
249 | notify_struct: |
236 | notify_struct: |
250 | dd 7 ; run application |
237 | dd 7 ; run application |
251 | dd 0 |
238 | dd 0 |
252 | .msg dd paste_url |
239 | .msg dd notify_msg |
253 | dd 0 |
240 | dd 0 |
254 | dd 0 |
241 | dd 0 |
Line 255... | Line 242... | ||
255 | db '/sys/@notify', 0 |
242 | db '/sys/@notify', 0 |
256 | - | ||
257 | sz_url db 'http://paste.kolibrios.org/', 0 |
243 | |
258 | sz_set_cookie db 'set-cookie', 0 |
244 | sz_url db 'http://dpaste.com/api/v2/', 0 |
259 | sz_location db 'location', 0 |
245 | sz_location db 'location', 0 |
Line 260... | Line 246... | ||
260 | sz_ctype db 'application/x-www-form-urlencoded', 0 |
246 | sz_ctype db 'application/x-www-form-urlencoded', 0 |
261 | sz_failed db '"Pasta!',10,'Paste failed!" -E', 0 |
247 | sz_failed db '"Pasta!',10,'Paste failed!" -E', 0 |
262 | - | ||
263 | sz_paste_head db 'code=' |
- | |
Line 264... | Line 248... | ||
264 | .length = $ - sz_paste_head |
248 | |
265 | sz_paste_tail db '%0D%0A&language=text&webpage=' |
- | |
266 | .length = $ - sz_paste_tail |
249 | sz_paste_head db 'content=' |
Line 267... | Line -... | ||
267 | - | ||
268 | sz_cookie db 'Cookie: ' |
250 | .length = $ - sz_paste_head |
Line 269... | Line 251... | ||
269 | cookie db 0 |
251 | |
270 | rb 1024 |
252 | notify_msg db '"Pasta!',10 |
271 | 253 | .text rb 1024 |
|
- | 254 | ||
Line 272... | Line 255... | ||
272 | paste_url rb 1024 |
255 | param rb 1024 |