1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Copyright (C) KolibriOS team 2014-2017. All rights reserved. ;;
4 ;; Distributed under terms of the GNU General Public License ;;
6 ;; pasta.asm - Paste text to dpaste.com from a file or from ;;
9 ;; GNU GENERAL PUBLIC LICENSE ;;
10 ;; Version 2, June 1991 ;;
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
28 include '../../macros.inc'
29 include '../../proc32.inc'
30 include '../../dll.inc'
31 include '../../develop/libraries/http/http.inc'
39 mcall
68, 11 ; init heap so we can allocate memory dynamically
42 stdcall dll.Load
, @IMPORT
50 ; Yep, try to read the file.
54 mov [file_struct.buf
], eax
55 mov [clipboard_data
], eax
59 mov [clipboard_data_length
], ebx
60 mov eax, [clipboard_data
]
66 ; Get number of slots on the clipboard
71 ; Get last item on clipboard
81 ; Verify if we can work with it
82 mov [clipboard_data
], eax
83 cmp dword[eax + 4], 0 ; text ?
86 ; Save length in [clipboard_data_length]
89 mov [clipboard_data_length
], ecx
91 ; Skip clipboard containter params for escape proc
95 ; Escape all characters that need escaping
96 invoke HTTP_escape
, eax
99 mov [clipboard_data_length
], ebx
102 mcall
68, 13, [clipboard_data
]
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
110 jz error_free_clip_disconnect
111 mov [identifier
], eax
113 ; Send the data to the server
114 invoke HTTP_send
, [identifier
], sz_paste_head
, sz_paste_head.
length
116 push [clipboard_data
]
119 invoke HTTP_send
, [identifier
], [send_ptr
], [clipboard_data_length
]
121 je error_free_clip_disconnect
123 jz error_free_clip_disconnect
125 sub [clipboard_data_length
], eax
129 mcall
68, 13, [clipboard_data
]
132 invoke HTTP_receive
, [identifier
]
136 invoke HTTP_disconnect
, [identifier
]
138 mov ebp, [identifier
]
139 test [ebp + http_msg.flags
], 0xffff0000 ; Test error bits
141 test [ebp + http_msg.flags
], FLAG_GOT_HEADER
143 cmp [ebp + http_msg.status
], 201 ; created
146 invoke HTTP_find_header_field
, [identifier
], sz_location
153 mcall
54, 3 ; Delete last slot in the clipboard
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
160 invoke HTTP_free
, [identifier
]
164 lea esi, [ebp + http_msg.http_header
]
167 invoke HTTP_free
, [identifier
]
169 error_free_clip_disconnect:
170 invoke HTTP_disconnect
, [identifier
]
171 invoke HTTP_free
, [identifier
]
173 mcall
68, 13, [clipboard_data
]
175 mov [notify_struct.msg
], sz_failed
176 mcall
70, notify_struct
183 mov edi, notify_msg.text
196 lea ecx, [edi - notify_msg
+ 4]
201 mov [notify_struct.msg
], notify_msg
202 mcall
70, notify_struct
207 ;---------------------------------------------------------------------
209 ;-----------------------------------------------------------------------------
213 library lib_http
, 'http.obj'
219 HTTP_receive
, 'receive', \
220 HTTP_find_header_field
, 'find_header_field', \
222 HTTP_escape
, 'escape', \
223 HTTP_disconnect
, 'disconnect'
231 dd 32768 ; max file size
232 .buf
dd 0 ; buffer ptr
237 dd 7 ; run application
244 sz_url
db 'http://dpaste.com/api/v2/', 0
245 sz_location
db 'location', 0
246 sz_ctype
db 'application/x-www-form-urlencoded', 0
247 sz_failed
db '"Pasta!',10,'Paste failed!" -E', 0
249 sz_paste_head
db 'content='
250 .
length = $
- sz_paste_head
252 notify_msg
db '"Pasta!',10
259 clipboard_data_length
dd 0