Subversion Repositories Kolibri OS

Rev

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

  1. #include <menuet/os.h>
  2. #define NULL 0
  3. #define __stdcall __attribute__((stdcall))
  4.  
  5. extern int dll_load();
  6. extern int mem_Free();
  7. extern int mem_Alloc();
  8. extern int mem_ReAlloc();
  9.  
  10.  
  11.  
  12. int kol_exit(){
  13.         __menuet__sys_exit();
  14. }
  15.  
  16.  
  17.  
  18. struct http_msg {
  19. // internal used by library, dont mess with these.
  20. unsigned int socket;
  21. unsigned int flags;
  22. unsigned int write_ptr;
  23. unsigned int buffer_length;
  24. unsigned int chunk_ptr;
  25. unsigned int timestamp;
  26.  
  27. // available for use.
  28. unsigned int status;
  29. unsigned int header_length;
  30. char *content_ptr;
  31. unsigned int content_length;
  32. unsigned int content_received;
  33. char header; //unknown size (actually, it's size is defined in header_length)
  34. };
  35.  
  36.  
  37. int (* __stdcall http_init)();
  38. // On the next line, we should tell the C compiler that this procedure actually returns a pointer. (to the http_msg struct)
  39. unsigned int (* __stdcall http_get) (char * url, char * add_head); //yay, it's NOT uint, but hey, C is stubborn, and I'm dumb
  40. int (* __stdcall http_process) (unsigned int identifier);
  41. void (* __stdcall http_free) (unsigned int identifier);
  42.  
  43.  
  44. int HTTP_YAY(){
  45.         asm volatile ("pusha\n\
  46.                            movl $mem_Alloc, %eax\n\
  47.                            movl $mem_Free, %ebx\n\
  48.                            movl $mem_ReAlloc, %ecx\n\
  49.                            movl $dll_load, %edx\n\
  50.                            movl http_init, %esi\n\
  51.                            call *%esi\n\
  52.                            popa");
  53. }
  54.  
  55. ///===========================
  56.  
  57. void HTTP_INIT()
  58. {
  59. IMP_ENTRY *imp;
  60.  
  61. imp = __kolibri__cofflib_load("/sys/lib/http.obj");
  62. if (imp == NULL)
  63.         kol_exit();
  64.  
  65. http_init = ( __stdcall  int(*)())
  66.                 __kolibri__cofflib_getproc (imp, "lib_init");
  67. if (http_init == NULL)
  68.         kol_exit();
  69.  
  70. http_get = ( __stdcall  unsigned int (*)(char*))
  71.                 __kolibri__cofflib_getproc  (imp, "get");
  72. if (http_get == NULL)
  73.         kol_exit();
  74.  
  75. http_free = ( __stdcall  void (*)(unsigned int))
  76.                 __kolibri__cofflib_getproc  (imp, "free");
  77. if (http_free == NULL)
  78.         kol_exit();
  79.  
  80.        
  81. http_process = ( __stdcall  int (*)(unsigned int))
  82.                 __kolibri__cofflib_getproc  (imp, "process");
  83. if (http_process == NULL)
  84.         kol_exit();
  85.  
  86. __menuet__debug_out("HTTP init...\n");
  87. HTTP_YAY();
  88.  
  89. __menuet__debug_out("ok...\n");
  90.  
  91. }
  92.