Rev 4833 | Rev 5541 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4832 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2014. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; pasta.asm - Paste text to paste.kolibrios.org from a file or ;; |
||
7 | ;; from clipboard. ;; |
||
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 |
||
78 | |||
79 | ; Verify if we can work with it |
||
4833 | hidnplayr | 80 | mov [clipboard_data], eax |
4832 | hidnplayr | 81 | cmp dword[eax + 4], 0 ; text ? |
4833 | hidnplayr | 82 | jne error_free_clip |
83 | |||
84 | ; Save length in [clipboard_data_length] |
||
4832 | hidnplayr | 85 | mov ecx, dword[eax] |
4834 | hidnplayr | 86 | sub ecx, 12 |
4832 | hidnplayr | 87 | mov [clipboard_data_length], ecx |
88 | |||
4833 | hidnplayr | 89 | ; Skip clipboard containter params for escape proc |
4832 | hidnplayr | 90 | add eax, 12 |
91 | |||
92 | escape: |
||
93 | ; Escape all characters that need escaping |
||
94 | invoke HTTP_escape, eax |
||
95 | test eax, eax |
||
4833 | hidnplayr | 96 | jz error_free_clip |
4832 | hidnplayr | 97 | mov [clipboard_data_length], ebx |
98 | |||
99 | push eax |
||
100 | mcall 68, 13, [clipboard_data] |
||
101 | pop [clipboard_data] |
||
102 | |||
103 | ; Connect to the server |
||
104 | invoke HTTP_get, sz_url, 0 |
||
105 | test eax, eax |
||
4833 | hidnplayr | 106 | jz error_free_clip |
4832 | hidnplayr | 107 | mov [identifier], eax |
108 | |||
109 | .again: |
||
110 | invoke HTTP_process, [identifier] |
||
111 | test eax, eax |
||
112 | jnz .again |
||
113 | |||
114 | invoke HTTP_find_header_field, [identifier], sz_set_cookie |
||
115 | mov edi, cookie |
||
116 | test eax, eax |
||
117 | jz .no_cookie |
||
118 | |||
119 | mov esi, eax |
||
120 | .cookie_loop: |
||
121 | lodsb |
||
122 | stosb |
||
123 | cmp al, 13 |
||
124 | je .cookie_end |
||
125 | cmp al, 10 |
||
126 | je .cookie_end |
||
127 | cmp al, 0 |
||
128 | je .cookie_end |
||
129 | jmp .cookie_loop |
||
130 | .cookie_end: |
||
131 | dec edi |
||
132 | .no_cookie: |
||
133 | mov ax, 0x0a0d |
||
134 | stosw |
||
135 | xor al, al |
||
136 | stosb |
||
137 | |||
138 | invoke HTTP_free, [identifier] |
||
139 | |||
140 | mov ecx, [clipboard_data_length] |
||
141 | add ecx, sz_paste_head.length + sz_paste_tail.length |
||
142 | invoke HTTP_post, sz_url, sz_cookie, sz_ctype, ecx |
||
143 | test eax, eax |
||
4833 | hidnplayr | 144 | jz error_free_clip |
4832 | hidnplayr | 145 | mov [identifier], eax |
146 | |||
4833 | hidnplayr | 147 | ; Send the data to the server |
4832 | hidnplayr | 148 | mov ecx, [eax + http_msg.socket] |
149 | mcall 75, 6, , sz_paste_head, sz_paste_head.length, 0 |
||
150 | mcall 75, 6, , [clipboard_data], [clipboard_data_length], 0 |
||
151 | mcall 75, 6, , sz_paste_tail, sz_paste_tail.length, 0 |
||
152 | |||
4833 | hidnplayr | 153 | ; Free the data |
154 | mcall 68, 13, [clipboard_data] |
||
155 | |||
4832 | hidnplayr | 156 | .again2: |
157 | invoke HTTP_process, [identifier] |
||
158 | test eax, eax |
||
159 | jnz .again2 |
||
160 | |||
161 | mov ebp, [identifier] |
||
162 | cmp [ebp + http_msg.status], 302 ; found |
||
4833 | hidnplayr | 163 | jne error_free_http |
4832 | hidnplayr | 164 | |
165 | invoke HTTP_find_header_field, [identifier], sz_location |
||
166 | test eax, eax |
||
4833 | hidnplayr | 167 | jz error_free_http |
4832 | hidnplayr | 168 | |
169 | push eax |
||
170 | mov esi, sz_failed |
||
171 | mov edi, paste_url |
||
172 | mov ecx, 2 |
||
173 | rep movsd |
||
174 | pop esi |
||
175 | .url_loop: |
||
176 | lodsb |
||
177 | stosb |
||
178 | cmp al, 13 |
||
179 | je .url_end |
||
180 | cmp al, 10 |
||
181 | je .url_end |
||
182 | cmp al, 0 |
||
183 | je .url_end |
||
184 | jmp .url_loop |
||
185 | .url_end: |
||
186 | dec edi |
||
187 | lea ecx, [edi - paste_url + 4] |
||
188 | mov eax, '" -t' |
||
189 | stosd |
||
190 | mov ax, 'O' |
||
191 | stosw |
||
192 | mov [notify_struct.msg], paste_url |
||
193 | mcall 70, notify_struct |
||
194 | |||
195 | mcall 54, 3 ; Delete last slot in the clipboard |
||
196 | |||
197 | mov dword[paste_url-4], ecx |
||
198 | mov dword[paste_url+0], 0 ; Text |
||
199 | mov dword[paste_url+4], 1 ; cp0866 |
||
200 | mcall 54, 2, , paste_url-4 ; Write URL to the clipboard |
||
201 | |||
202 | invoke HTTP_free, [identifier] |
||
203 | mcall -1 |
||
204 | |||
4833 | hidnplayr | 205 | error_free_http: |
206 | invoke HTTP_free, [identifier] |
||
207 | jmp error |
||
208 | error_free_clip: |
||
209 | mcall 68, 13, [clipboard_data] |
||
4832 | hidnplayr | 210 | error: |
211 | mov [notify_struct.msg], sz_failed |
||
212 | mcall 70, notify_struct |
||
213 | |||
214 | mcall -1 |
||
215 | |||
216 | |||
217 | ;--------------------------------------------------------------------- |
||
218 | ; Data area |
||
219 | ;----------------------------------------------------------------------------- |
||
220 | align 4 |
||
221 | @IMPORT: |
||
222 | |||
223 | library lib_http, 'http.obj' |
||
224 | |||
225 | import lib_http, \ |
||
226 | HTTP_get, 'get', \ |
||
227 | HTTP_process, 'process', \ |
||
228 | HTTP_free, 'free', \ |
||
229 | HTTP_stop, 'stop', \ |
||
230 | HTTP_post, 'post', \ |
||
231 | HTTP_find_header_field, 'find_header_field', \ |
||
232 | HTTP_escape, 'escape' |
||
233 | |||
234 | IM_END: |
||
235 | |||
236 | file_struct: |
||
237 | dd 0 ; read file |
||
238 | dd 0 ; offset |
||
239 | dd 0 ; reserved |
||
240 | dd 32768 ; max file size |
||
241 | .buf dd 0 ; buffer ptr |
||
242 | db 0 |
||
243 | dd param |
||
244 | |||
245 | notify_struct: |
||
246 | dd 7 ; run application |
||
247 | dd 0 |
||
248 | .msg dd paste_url |
||
249 | dd 0 |
||
250 | dd 0 |
||
251 | db '/sys/@notify', 0 |
||
252 | |||
253 | sz_url db 'http://paste.kolibrios.org/', 0 |
||
254 | sz_set_cookie db 'set-cookie', 0 |
||
255 | sz_location db 'location', 0 |
||
256 | sz_ctype db 'application/x-www-form-urlencoded', 0 |
||
4834 | hidnplayr | 257 | sz_failed db '"Pasta!',10,'Paste failed!" -E', 0 |
4832 | hidnplayr | 258 | |
259 | sz_paste_head db 'code=' |
||
260 | .length = $ - sz_paste_head |
||
261 | sz_paste_tail db '%0D%0A&language=text&webpage=' |
||
262 | .length = $ - sz_paste_tail |
||
263 | |||
264 | sz_cookie db 'Cookie: ' |
||
265 | cookie db 0 |
||
266 | rb 1024 |
||
267 | |||
268 | paste_url rb 1024 |
||
269 | param rb 1024 |
||
270 | |||
271 | identifier dd 0 |
||
272 | clipboard_data dd 0 |
||
273 | clipboard_data_length dd 0 |
||
274 | |||
275 | I_END: |
||
276 |