From bf1811e1f560ea1bc2af5bf08012119ce15f3a6e Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Tue, 26 Jan 2021 08:40:56 +0000 Subject: [PATCH] - Moved header files from kos to clayer. - Fixed function names in libhttp. - Fixed example dynamic.c - Added macro fixing bug http_receive git-svn-id: svn://kolibrios.org@8549 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/bin/lib/libhttp.a | Bin 3070 -> 3080 bytes programs/develop/ktcc/trunk/lib/http/Makefile | 11 +++++++ programs/develop/ktcc/trunk/lib/http/get.asm | 2 +- programs/develop/ktcc/trunk/lib/http/head.asm | 2 +- programs/develop/ktcc/trunk/lib/http/make.bat | 9 ------ programs/develop/ktcc/trunk/lib/http/post.asm | 2 +- .../develop/ktcc/trunk/lib/http/receive.asm | 2 +- programs/develop/ktcc/trunk/lib/http/send.asm | 2 +- .../trunk/libc/include/{kos => clayer}/gb.h | 0 .../trunk/libc/include/{kos => clayer}/http.h | 28 +++++++++++------- .../libc/include/{kos => clayer}/inputbox.h | 0 programs/develop/ktcc/trunk/samples/dynamic.c | 15 ++++++---- .../develop/ktcc/trunk/samples/graphics.c | 2 +- 13 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 programs/develop/ktcc/trunk/lib/http/Makefile delete mode 100644 programs/develop/ktcc/trunk/lib/http/make.bat rename programs/develop/ktcc/trunk/libc/include/{kos => clayer}/gb.h (100%) rename programs/develop/ktcc/trunk/libc/include/{kos => clayer}/http.h (86%) rename programs/develop/ktcc/trunk/libc/include/{kos => clayer}/inputbox.h (100%) diff --git a/programs/develop/ktcc/trunk/bin/lib/libhttp.a b/programs/develop/ktcc/trunk/bin/lib/libhttp.a index b4f1bf4bf9f462910ef662e7ff3cb2a9bc706358..79abba8e76712da203f60595a3a74fd49652032d 100644 GIT binary patch delta 600 zcmew--XSqT!q-3n0U&H-QbEDo3?`qz#lXP82E-E>7?^;Vr4PtuVPN23VqoCn$|xx* zh@Y4s!3tqi$jRX{+04WQXyoJ#OimNOP3HhBPfsnGJdyD(qsioaCS_&(8Wj{wOe`lG za%nPNoP3{2WpW)``{Z8cUPi~s(oE`%fs^-hs{1Siy3zoMVSo|J;EIpW$xMom*UQ(3 z_==EK#)igVt7cBV&$3|hE=G~b(^ykXxC-)%OWP&4Zc%D- zYGzp~+$w_hm>GbbduMVu$2uNx&_ay>2Cwa8FU|#w7L#9dk`lzxT#z8<_$NL=qTbNd!qUvp*uug>(>0GU)!Ff#)S0*M4J1_lN;AZ}w|U}|DuU;$#* zUknWFK+O3sJ+*`(BQ-IF!6Bohq(Cn}DT|>Xzqo{C8YACJVA_OjclJo7~STF!>JS z0!IDGwM@!#aGzi`YT`bpNz8(iJGiJ&;dfCV)JL-xQ!zCYP{5+`_|-a0@i3;0ED01sFD_5Vza_h0Ww5 mj@dvgGFgsY8Xh=doC_F@Cx7Q8B5)>GaS3kj;1Xwq1q}dRc7;;_ 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 /// ===========================================================