Subversion Repositories Kolibri OS

Rev

Rev 5043 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #include <menuet/os.h>
  2. #include "http_msg.h"
  3. //#include "http.h"
  4.  
  5. #define NULL 0
  6.  
  7. #define __stdcall __attribute__((stdcall))
  8.  
  9. extern int dll_load();
  10. extern int mem_Free();
  11. extern int mem_Alloc();
  12. extern int mem_ReAlloc();
  13.  
  14. int (* __stdcall http_init)(void);
  15. // On the next line, we should tell the C compiler that this procedure actually returns a pointer. (to the http_msg struct)
  16. unsigned int (* __stdcall http_get) (char * url, unsigned int identifier, unsigned int flags, char * add_head); //yay, it's NOT uint, but hey, C is stubborn, and I'm dumb
  17. int (* __stdcall http_receive) (unsigned int identifier);
  18. void (* __stdcall http_free) (unsigned int identifier);
  19. char * (* __stdcall http_find_header_field) (struct http_msg *http_ahoy, char *field_name);
  20. char * (* __stdcall http_unescape_url) (char * url_asciiz);
  21. char * (* __stdcall http_post) (char *url, unsigned int identifier, unsigned int flags, char *headers, char *content_type, int content_length);
  22. int (* __stdcall http_send) (struct http_msg *handle, char *data, unsigned int length);
  23. void (* __stdcall http_disconnect) (struct http_msg *handle);
  24.  
  25. int HTTP_YAY(){
  26.         asm volatile ("pusha\n\
  27.                            movl $mem_Alloc, %eax\n\
  28.                            movl $mem_Free, %ebx\n\
  29.                            movl $mem_ReAlloc, %ecx\n\
  30.                            movl $dll_load, %edx\n\
  31.                            movl http_init, %esi\n\
  32.                            call *%esi\n\
  33.                            popa");
  34. }
  35.  
  36. int kol_exit(){
  37.   __menuet__debug_out("kol_exit()..Exiting..\n");
  38.   __menuet__sys_exit();
  39. }
  40.  
  41. void HTTP_INIT()
  42. {
  43. const IMP_ENTRY *imp;
  44.  
  45. imp = __kolibri__cofflib_load("/sys/lib/http.obj");
  46. if (imp == NULL)
  47.         kol_exit();
  48.  
  49. http_init = ( __stdcall  int(*)())
  50.                 __kolibri__cofflib_getproc (imp, "lib_init");
  51. if (http_init == NULL)
  52.   {
  53.   __menuet__debug_out("http_init() is NULL. Exiting.\n");
  54.   kol_exit();
  55.   }
  56.  else
  57.    __menuet__debug_out("\nhttp_init() initialised properly.\n");
  58.  
  59.  
  60. http_get = ( __stdcall  unsigned int (*)(char*, char*))
  61.                 __kolibri__cofflib_getproc  (imp, "get");
  62. if (http_get == NULL)
  63.   {
  64.     __menuet__debug_out("http_get() is NULL. Exiting.\n");
  65.     kol_exit();
  66.   }
  67. http_free = ( __stdcall  void (*)(unsigned int))
  68.                 __kolibri__cofflib_getproc  (imp, "free");
  69. if (http_free == NULL)
  70.   {
  71.     __menuet__debug_out("http_free() is NULL. Exiting.\n");
  72.     kol_exit();
  73.   }    
  74. http_receive = ( __stdcall  int (*)(unsigned int))
  75.                 __kolibri__cofflib_getproc  (imp, "receive");
  76.  
  77. if (http_receive == NULL)
  78.   {
  79.     __menuet__debug_out("http_receive() is NULL. Exiting.\n");
  80.     kol_exit();
  81.   }
  82.  
  83. http_find_header_field = ( __stdcall  char *(*)(struct http_msg*, char *))
  84.                 __kolibri__cofflib_getproc  (imp, "find_header_field");
  85. if (http_find_header_field == NULL)
  86.   {
  87.     __menuet__debug_out("http_find_header_field() is NULL. Exiting.\n");
  88.     kol_exit();
  89.   }
  90.  
  91. http_unescape_url = ( __stdcall  char *(*)(char *))
  92.   __kolibri__cofflib_getproc  (imp, "unescape");
  93.  
  94. if(http_unescape_url == NULL)
  95.   {
  96.     __menuet__debug_out("http_unescape_url() is NULL. Exiting.\n");
  97.     kol_exit();
  98.   }
  99.  
  100.  http_post = ( __stdcall  char *(*)(char *, char *, char *, int))
  101.   __kolibri__cofflib_getproc  (imp, "post");
  102.  
  103.  if(http_post == NULL)
  104.    {
  105.      __menuet__debug_out("http_post() is NULL. Exiting.\n");
  106.      kol_exit();
  107.   }
  108.  
  109.  
  110.  http_send = ( __stdcall  int (*)(struct http_msg *, char *, unsigned int))
  111.   __kolibri__cofflib_getproc  (imp, "send");
  112.  
  113.  if(http_send == NULL)
  114.    {
  115.      __menuet__debug_out("http_send() is NULL. Exiting.\n");
  116.      kol_exit();
  117.   }
  118.  
  119.  
  120.  http_disconnect = ( __stdcall  void (*)(struct http_msg *))
  121.   __kolibri__cofflib_getproc  (imp, "disconnect");
  122.  
  123.  if(http_disconnect == NULL)
  124.    {
  125.      __menuet__debug_out("http_disconnect() is NULL. Exiting.\n");
  126.      kol_exit();
  127.   }
  128.  
  129.  
  130.  
  131. __menuet__debug_out("HTTP init...\n");
  132. HTTP_YAY();
  133.  
  134. __menuet__debug_out("ok...\n");
  135. }
  136.