diff --git a/programs/develop/ktcc/trunk/bin/lib/libhttp.a b/programs/develop/ktcc/trunk/bin/lib/libhttp.a index b4f1bf4bf9..79abba8e76 100644 Binary files a/programs/develop/ktcc/trunk/bin/lib/libhttp.a and b/programs/develop/ktcc/trunk/bin/lib/libhttp.a differ diff --git a/programs/develop/ktcc/trunk/lib/http/Makefile b/programs/develop/ktcc/trunk/lib/http/Makefile new file mode 100644 index 0000000000..3b3ba744b2 --- /dev/null +++ b/programs/develop/ktcc/trunk/lib/http/Makefile @@ -0,0 +1,11 @@ +FASM = fasm + +OBJS = get.o head.o __lib__.o post.o receive.o send.o + +%.o : %.asm + $(FASM) $< + +all: $(OBJS) + ar -rsc libhttp.a *.o + mv -f libhttp.a ../../bin/lib + rm -f *.o diff --git a/programs/develop/ktcc/trunk/lib/http/get.asm b/programs/develop/ktcc/trunk/lib/http/get.asm index 2ebfd3d670..d2a1132553 100644 --- a/programs/develop/ktcc/trunk/lib/http/get.asm +++ b/programs/develop/ktcc/trunk/lib/http/get.asm @@ -2,7 +2,7 @@ format ELF include "__lib__.inc" -fun equ get +fun equ http_get fun_str equ 'get' section '.text' diff --git a/programs/develop/ktcc/trunk/lib/http/head.asm b/programs/develop/ktcc/trunk/lib/http/head.asm index 138a86b201..5b7ac8b942 100644 --- a/programs/develop/ktcc/trunk/lib/http/head.asm +++ b/programs/develop/ktcc/trunk/lib/http/head.asm @@ -2,7 +2,7 @@ format ELF include "__lib__.inc" -fun equ head +fun equ http_head fun_str equ 'head' section '.text' diff --git a/programs/develop/ktcc/trunk/lib/http/make.bat b/programs/develop/ktcc/trunk/lib/http/make.bat deleted file mode 100644 index 482cda55c3..0000000000 --- a/programs/develop/ktcc/trunk/lib/http/make.bat +++ /dev/null @@ -1,9 +0,0 @@ -fasm __lib__.asm -fasm get.asm -fasm head.asm -fasm post.asm -fasm receive.asm -fasm send.asm -kos32-ar -ru libhttp.a *.o -del *.o -pause \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/lib/http/post.asm b/programs/develop/ktcc/trunk/lib/http/post.asm index e9d9c51f65..cedf139378 100644 --- a/programs/develop/ktcc/trunk/lib/http/post.asm +++ b/programs/develop/ktcc/trunk/lib/http/post.asm @@ -2,7 +2,7 @@ format ELF include "__lib__.inc" -fun equ post +fun equ http_post fun_str equ 'post' section '.text' diff --git a/programs/develop/ktcc/trunk/lib/http/receive.asm b/programs/develop/ktcc/trunk/lib/http/receive.asm index 4044fd7058..5bc616828c 100644 --- a/programs/develop/ktcc/trunk/lib/http/receive.asm +++ b/programs/develop/ktcc/trunk/lib/http/receive.asm @@ -2,7 +2,7 @@ format ELF include "__lib__.inc" -fun equ receive +fun equ http_receive fun_str equ 'receive' section '.text' diff --git a/programs/develop/ktcc/trunk/lib/http/send.asm b/programs/develop/ktcc/trunk/lib/http/send.asm index fea2ef2a8d..3adfe2bb80 100644 --- a/programs/develop/ktcc/trunk/lib/http/send.asm +++ b/programs/develop/ktcc/trunk/lib/http/send.asm @@ -2,7 +2,7 @@ format ELF include "__lib__.inc" -fun equ send +fun equ http_send fun_str equ 'send' section '.text' diff --git a/programs/develop/ktcc/trunk/libc/include/kos/gb.h b/programs/develop/ktcc/trunk/libc/include/clayer/gb.h similarity index 100% rename from programs/develop/ktcc/trunk/libc/include/kos/gb.h rename to programs/develop/ktcc/trunk/libc/include/clayer/gb.h diff --git a/programs/develop/ktcc/trunk/libc/include/kos/http.h b/programs/develop/ktcc/trunk/libc/include/clayer/http.h similarity index 86% rename from programs/develop/ktcc/trunk/libc/include/kos/http.h rename to programs/develop/ktcc/trunk/libc/include/clayer/http.h index 79261197e9..e8452a61ae 100644 --- a/programs/develop/ktcc/trunk/libc/include/kos/http.h +++ b/programs/develop/ktcc/trunk/libc/include/clayer/http.h @@ -1,18 +1,19 @@ /* - This is adapded thunk for console.obj sys library - .h is equal to svn:\programs\develop\libraries\http\http_en.txt + This is adapded thunk for http.obj sys library + .h is equal to svn:\\programs\develop\libraries\http\http_en.txt Adapted for TCC's dynamic API by Magomed Kostoev, 2020 */ -#ifndef __kos__http__h________ -#define __kos__http__h________ +#ifndef _HTTP_H_ +#define _HTTP_H_ #define cdecl __attribute__ ((cdecl)) #define stdcall __attribute__ ((stdcall)) // Bitflags for http_msg.flags // status + #define HTTP_FLAG_HTTP11 1 << 0 #define HTTP_FLAG_GOT_HEADER 1 << 1 #define HTTP_FLAG_GOT_ALL_DATA 1 << 2 @@ -65,7 +66,7 @@ typedef struct http_msg_s { void * content_ptr; // ptr to content unsigned content_length; // total length of HTTP content unsigned content_received; // number of currently received content bytes - char http_header[1]; + char * http_header; } http_msg; /* @@ -77,7 +78,7 @@ typedef struct http_msg_s { Initiates a HTTP connection, using 'GET' method. Returns NULL on error, identifier otherwise. */ -extern http_msg * stdcall (*get)(const char *url, http_msg *identifier, unsigned flags, const char *add_header); +extern http_msg * stdcall (*http_get)(const char *url, http_msg *identifier, unsigned flags, const char *add_header); /* url = pointer to ASCIIZ URL @@ -88,7 +89,7 @@ extern http_msg * stdcall (*get)(const char *url, http_msg *identifier, unsigned Initiate a HTTP connection, using 'HEAD' method. Returns NULL on error, identifier otherwise. */ -extern http_msg * stdcall (*head)(const char *url, http_msg *identifier, unsigned flags, const char *add_header); +extern http_msg * stdcall (*http_head)(const char *url, http_msg *identifier, unsigned flags, const char *add_header); /* url = pointer to ASCIIZ URL @@ -103,7 +104,7 @@ extern http_msg * stdcall (*head)(const char *url, http_msg *identifier, unsigne using system function 75, 6. Returns 0 on error, identifier otherwise */ -extern http_msg * stdcall (*post)(const char *url, http_msg *identifier, unsigned flags, const char *add_header, +extern http_msg * stdcall (*http_post)(const char *url, http_msg *identifier, unsigned flags, const char *add_header, const char *content_type, unsigned content_length); /* @@ -125,7 +126,7 @@ extern http_msg * stdcall (*post)(const char *url, http_msg *identifier, unsigne In content_length you'll find the length of the content. In content_received, you'll find the number of content bytes already received. */ -extern int stdcall (*receive)(http_msg *identifier); +extern int stdcall (*http_receive)(http_msg *identifier); /* identifier = identifier which one of the previous functions returned @@ -134,6 +135,11 @@ extern int stdcall (*receive)(http_msg *identifier); This procedure can be used to send data to the server (POST) Returns number of bytes sent, -1 on error */ -extern int stdcall (*send)(http_msg *identifier, void *dataptr, unsigned datalength); +extern int stdcall (*http_send)(http_msg *identifier, void *dataptr, unsigned datalength); -#endif // __kos__http__h________ \ No newline at end of file +/* + Sometimes the http_receive function receives incomplete data. If you have the same problem then a macro can help you: +*/ +#define http_long_receive(x) while(http_receive(x)){}; + +#endif // _HTTP_H_ diff --git a/programs/develop/ktcc/trunk/libc/include/kos/inputbox.h b/programs/develop/ktcc/trunk/libc/include/clayer/inputbox.h similarity index 100% rename from programs/develop/ktcc/trunk/libc/include/kos/inputbox.h rename to programs/develop/ktcc/trunk/libc/include/clayer/inputbox.h diff --git a/programs/develop/ktcc/trunk/samples/dynamic.c b/programs/develop/ktcc/trunk/samples/dynamic.c index 2915dc907e..45766b3f5e 100644 --- a/programs/develop/ktcc/trunk/samples/dynamic.c +++ b/programs/develop/ktcc/trunk/samples/dynamic.c @@ -1,14 +1,19 @@ #include -#include -#include +#include +#include + +#define OK 200 int main() { if (con_init_console_dll()) return 1; // init fail con_write_asciiz("Wait, I'll ask you... when I'll done to fetch one site...\n"); con_set_title("Dynamicaly linked app"); - http_msg *h = get("http://example.com", 0, HTTP_FLAG_BLOCK, ""); - if (!receive(h)) { - con_printf("%s\n", h->content_ptr); + + http_msg *h = http_get("http://kolibri.org/", 0, HTTP_FLAG_BLOCK, ""); + http_long_receive(h); + + if (h->status == OK) { + con_write_string(h->content_ptr, h->content_length); } else { con_write_asciiz("Oops! Can't access to the page.\n"); } diff --git a/programs/develop/ktcc/trunk/samples/graphics.c b/programs/develop/ktcc/trunk/samples/graphics.c index 142affb585..6e52d8600c 100644 --- a/programs/develop/ktcc/trunk/samples/graphics.c +++ b/programs/develop/ktcc/trunk/samples/graphics.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include /// ===========================================================