Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  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 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.  
  45.         invoke  HTTP_get, sz_url, 0
  46.         test    eax, eax
  47.         jz      error
  48.         mov     [identifier], eax
  49.  
  50.   .again:
  51.         invoke  HTTP_process, [identifier]
  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.  
  81.         invoke  HTTP_post, sz_url, sz_cookie, sz_ctype, sz_paste.length
  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:
  90.         invoke  HTTP_process, [identifier]
  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_process,   'process', \
  146.         HTTP_free,      'free', \
  147.         HTTP_stop,      'stop', \
  148.         HTTP_post,      'post', \
  149.         HTTP_find_header_field, 'find_header_field'
  150.  
  151.  
  152. identifier      dd 0
  153.  
  154. IM_END:
  155.  
  156. notify_struct:
  157.         dd 7            ; run application
  158.         dd 0
  159.   .msg  dd paste_url
  160.         dd 0
  161.         dd 0
  162.         db '/sys/@notify', 0
  163.  
  164. sz_url          db 'http://paste.kolibrios.org/', 0
  165. sz_set_cookie   db 'set-cookie', 0
  166. sz_location     db 'location', 0
  167. sz_ctype        db 'application/x-www-form-urlencoded', 0
  168. sz_failed       db '"Paste failed!" -N', 0
  169.  
  170. sz_paste        db 'code=test+from+KolibriOS+2%0D%0A&language=text&webpage='
  171. .length = $ - sz_paste
  172.  
  173. sz_cookie       db 'Cookie: '
  174. cookie          db 0
  175.                 rb 1024
  176.  
  177. paste_url       rb 1024
  178.  
  179. I_END:
  180.  
  181.  
  182.  
  183.