Rev 5770 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4832 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
7100 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2014-2017. All rights reserved. ;; |
4832 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
7100 | hidnplayr | 6 | ;; pasta.asm - Paste text to dpaste.com from a file or from ;; |
7 | ;; clipboard. ;; |
||
4832 | 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 param |
||
25 | dd 0 ; I_Path |
||
26 | |||
27 | |||
28 | include '../../macros.inc' |
||
29 | include '../../proc32.inc' |
||
30 | include '../../dll.inc' |
||
31 | include '../../develop/libraries/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 error |
||
45 | |||
46 | ; Got parameters? |
||
47 | cmp byte[param], 0 |
||
48 | je clipboard |
||
49 | |||
50 | ; Yep, try to read the file. |
||
51 | mcall 68, 12, 32768 |
||
52 | test eax, eax |
||
53 | jz error |
||
54 | mov [file_struct.buf], eax |
||
55 | mov [clipboard_data], eax |
||
56 | mcall 70, file_struct |
||
57 | cmp eax, 6 |
||
4833 | hidnplayr | 58 | jne error_free_clip |
4832 | hidnplayr | 59 | mov [clipboard_data_length], ebx |
60 | mov eax, [clipboard_data] |
||
61 | |||
62 | jmp escape |
||
63 | |||
64 | clipboard: |
||
65 | |||
66 | ; Get number of slots on the clipboard |
||
67 | mcall 54, 0 |
||
68 | cmp eax, -1 |
||
69 | je error |
||
70 | |||
71 | ; Get last item on clipboard |
||
72 | mov ecx, eax |
||
73 | dec ecx |
||
74 | inc ebx |
||
75 | mcall 54 |
||
76 | cmp eax, -1 |
||
77 | je error |
||
5770 | hidnplayr | 78 | cmp eax, 1 |
79 | je error |
||
4832 | hidnplayr | 80 | |
81 | ; Verify if we can work with it |
||
4833 | hidnplayr | 82 | mov [clipboard_data], eax |
4832 | hidnplayr | 83 | cmp dword[eax + 4], 0 ; text ? |
4833 | hidnplayr | 84 | jne error_free_clip |
85 | |||
86 | ; Save length in [clipboard_data_length] |
||
4832 | hidnplayr | 87 | mov ecx, dword[eax] |
4834 | hidnplayr | 88 | sub ecx, 12 |
4832 | hidnplayr | 89 | mov [clipboard_data_length], ecx |
90 | |||
4833 | hidnplayr | 91 | ; Skip clipboard containter params for escape proc |
4832 | hidnplayr | 92 | add eax, 12 |
93 | |||
94 | escape: |
||
95 | ; Escape all characters that need escaping |
||
96 | invoke HTTP_escape, eax |
||
97 | test eax, eax |
||
4833 | hidnplayr | 98 | jz error_free_clip |
4832 | hidnplayr | 99 | mov [clipboard_data_length], ebx |
100 | |||
101 | push eax |
||
102 | mcall 68, 13, [clipboard_data] |
||
103 | pop [clipboard_data] |
||
104 | |||
7100 | hidnplayr | 105 | ; Post to the server |
106 | mov ecx, [clipboard_data_length] |
||
107 | add ecx, sz_paste_head.length |
||
108 | invoke HTTP_post, sz_url, 0, FLAG_BLOCK, 0, sz_ctype, ecx |
||
4832 | hidnplayr | 109 | test eax, eax |
7100 | hidnplayr | 110 | jz error_free_clip_disconnect |
4832 | hidnplayr | 111 | mov [identifier], eax |
112 | |||
7100 | hidnplayr | 113 | ; Send the data to the server |
114 | invoke HTTP_send, [identifier], sz_paste_head, sz_paste_head.length |
||
115 | |||
116 | push [clipboard_data] |
||
117 | pop [send_ptr] |
||
4832 | hidnplayr | 118 | .again: |
7100 | hidnplayr | 119 | invoke HTTP_send, [identifier], [send_ptr], [clipboard_data_length] |
120 | cmp eax, -1 |
||
121 | je error_free_clip_disconnect |
||
4832 | hidnplayr | 122 | test eax, eax |
5770 | hidnplayr | 123 | jz error_free_clip_disconnect |
7100 | hidnplayr | 124 | add [send_ptr], eax |
125 | sub [clipboard_data_length], eax |
||
126 | ja .again |
||
4832 | hidnplayr | 127 | |
4833 | hidnplayr | 128 | ; Free the data |
129 | mcall 68, 13, [clipboard_data] |
||
130 | |||
4832 | hidnplayr | 131 | .again2: |
5541 | hidnplayr | 132 | invoke HTTP_receive, [identifier] |
4832 | hidnplayr | 133 | test eax, eax |
134 | jnz .again2 |
||
135 | |||
5770 | hidnplayr | 136 | invoke HTTP_disconnect, [identifier] |
137 | |||
4832 | hidnplayr | 138 | mov ebp, [identifier] |
7100 | hidnplayr | 139 | test [ebp + http_msg.flags], 0xffff0000 ; Test error bits |
140 | jnz error_free_http |
||
141 | test [ebp + http_msg.flags], FLAG_GOT_HEADER |
||
142 | jz error_free_http |
||
143 | cmp [ebp + http_msg.status], 201 ; created |
||
144 | jne error_http_code |
||
4832 | hidnplayr | 145 | |
146 | invoke HTTP_find_header_field, [identifier], sz_location |
||
147 | test eax, eax |
||
4833 | hidnplayr | 148 | jz error_free_http |
4832 | hidnplayr | 149 | |
7100 | hidnplayr | 150 | mov esi, eax |
151 | call notify |
||
4832 | hidnplayr | 152 | |
153 | mcall 54, 3 ; Delete last slot in the clipboard |
||
154 | |||
7100 | hidnplayr | 155 | mov dword[notify_msg-4], ecx |
156 | mov dword[notify_msg+0], 0 ; Text |
||
157 | mov dword[notify_msg+4], 1 ; cp0866 |
||
158 | mcall 54, 2, , notify_msg-4 ; Write URL to the clipboard |
||
4832 | hidnplayr | 159 | |
160 | invoke HTTP_free, [identifier] |
||
161 | mcall -1 |
||
162 | |||
7100 | hidnplayr | 163 | error_http_code: |
164 | lea esi, [ebp + http_msg.http_header] |
||
165 | call notify |
||
4833 | hidnplayr | 166 | error_free_http: |
167 | invoke HTTP_free, [identifier] |
||
168 | jmp error |
||
5770 | hidnplayr | 169 | error_free_clip_disconnect: |
170 | invoke HTTP_disconnect, [identifier] |
||
171 | invoke HTTP_free, [identifier] |
||
4833 | hidnplayr | 172 | error_free_clip: |
173 | mcall 68, 13, [clipboard_data] |
||
4832 | hidnplayr | 174 | error: |
175 | mov [notify_struct.msg], sz_failed |
||
176 | mcall 70, notify_struct |
||
177 | |||
178 | mcall -1 |
||
179 | |||
180 | |||
7100 | hidnplayr | 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 | |||
204 | ret |
||
205 | |||
206 | |||
4832 | hidnplayr | 207 | ;--------------------------------------------------------------------- |
208 | ; Data area |
||
209 | ;----------------------------------------------------------------------------- |
||
210 | align 4 |
||
211 | @IMPORT: |
||
212 | |||
213 | library lib_http, 'http.obj' |
||
214 | |||
215 | import lib_http, \ |
||
216 | HTTP_get, 'get', \ |
||
217 | HTTP_post, 'post', \ |
||
7100 | hidnplayr | 218 | HTTP_send, 'send', \ |
5541 | hidnplayr | 219 | HTTP_receive, 'receive', \ |
4832 | hidnplayr | 220 | HTTP_find_header_field, 'find_header_field', \ |
5541 | hidnplayr | 221 | HTTP_free, 'free', \ |
5770 | hidnplayr | 222 | HTTP_escape, 'escape', \ |
223 | HTTP_disconnect, 'disconnect' |
||
4832 | hidnplayr | 224 | |
225 | IM_END: |
||
226 | |||
227 | file_struct: |
||
228 | dd 0 ; read file |
||
229 | dd 0 ; offset |
||
230 | dd 0 ; reserved |
||
231 | dd 32768 ; max file size |
||
232 | .buf dd 0 ; buffer ptr |
||
233 | db 0 |
||
234 | dd param |
||
235 | |||
236 | notify_struct: |
||
237 | dd 7 ; run application |
||
238 | dd 0 |
||
7100 | hidnplayr | 239 | .msg dd notify_msg |
4832 | hidnplayr | 240 | dd 0 |
241 | dd 0 |
||
242 | db '/sys/@notify', 0 |
||
243 | |||
7100 | hidnplayr | 244 | sz_url db 'http://dpaste.com/api/v2/', 0 |
4832 | hidnplayr | 245 | sz_location db 'location', 0 |
246 | sz_ctype db 'application/x-www-form-urlencoded', 0 |
||
4834 | hidnplayr | 247 | sz_failed db '"Pasta!',10,'Paste failed!" -E', 0 |
4832 | hidnplayr | 248 | |
7100 | hidnplayr | 249 | sz_paste_head db 'content=' |
4832 | hidnplayr | 250 | .length = $ - sz_paste_head |
251 | |||
7100 | hidnplayr | 252 | notify_msg db '"Pasta!',10 |
253 | .text rb 1024 |
||
4832 | hidnplayr | 254 | |
255 | param rb 1024 |
||
256 | |||
257 | identifier dd 0 |
||
258 | clipboard_data dd 0 |
||
259 | clipboard_data_length dd 0 |
||
7100 | hidnplayr | 260 | send_ptr dd ? |
4832 | hidnplayr | 261 | |
262 | I_END: |
||
263 |