forked from KolibriOS/kolibrios
- 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
This commit is contained in:
parent
e42e81743b
commit
bf1811e1f5
Binary file not shown.
11
programs/develop/ktcc/trunk/lib/http/Makefile
Normal file
11
programs/develop/ktcc/trunk/lib/http/Makefile
Normal file
@ -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
|
@ -2,7 +2,7 @@ format ELF
|
|||||||
|
|
||||||
include "__lib__.inc"
|
include "__lib__.inc"
|
||||||
|
|
||||||
fun equ get
|
fun equ http_get
|
||||||
fun_str equ 'get'
|
fun_str equ 'get'
|
||||||
|
|
||||||
section '.text'
|
section '.text'
|
||||||
|
@ -2,7 +2,7 @@ format ELF
|
|||||||
|
|
||||||
include "__lib__.inc"
|
include "__lib__.inc"
|
||||||
|
|
||||||
fun equ head
|
fun equ http_head
|
||||||
fun_str equ 'head'
|
fun_str equ 'head'
|
||||||
|
|
||||||
section '.text'
|
section '.text'
|
||||||
|
@ -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
|
|
@ -2,7 +2,7 @@ format ELF
|
|||||||
|
|
||||||
include "__lib__.inc"
|
include "__lib__.inc"
|
||||||
|
|
||||||
fun equ post
|
fun equ http_post
|
||||||
fun_str equ 'post'
|
fun_str equ 'post'
|
||||||
|
|
||||||
section '.text'
|
section '.text'
|
||||||
|
@ -2,7 +2,7 @@ format ELF
|
|||||||
|
|
||||||
include "__lib__.inc"
|
include "__lib__.inc"
|
||||||
|
|
||||||
fun equ receive
|
fun equ http_receive
|
||||||
fun_str equ 'receive'
|
fun_str equ 'receive'
|
||||||
|
|
||||||
section '.text'
|
section '.text'
|
||||||
|
@ -2,7 +2,7 @@ format ELF
|
|||||||
|
|
||||||
include "__lib__.inc"
|
include "__lib__.inc"
|
||||||
|
|
||||||
fun equ send
|
fun equ http_send
|
||||||
fun_str equ 'send'
|
fun_str equ 'send'
|
||||||
|
|
||||||
section '.text'
|
section '.text'
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
This is adapded thunk for console.obj sys library
|
This is adapded thunk for http.obj sys library
|
||||||
.h is equal to svn:\programs\develop\libraries\http\http_en.txt
|
.h is equal to svn:\\programs\develop\libraries\http\http_en.txt
|
||||||
|
|
||||||
Adapted for TCC's dynamic API by Magomed Kostoev, 2020
|
Adapted for TCC's dynamic API by Magomed Kostoev, 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __kos__http__h________
|
#ifndef _HTTP_H_
|
||||||
#define __kos__http__h________
|
#define _HTTP_H_
|
||||||
|
|
||||||
#define cdecl __attribute__ ((cdecl))
|
#define cdecl __attribute__ ((cdecl))
|
||||||
#define stdcall __attribute__ ((stdcall))
|
#define stdcall __attribute__ ((stdcall))
|
||||||
|
|
||||||
// Bitflags for http_msg.flags
|
// Bitflags for http_msg.flags
|
||||||
// status
|
// status
|
||||||
|
|
||||||
#define HTTP_FLAG_HTTP11 1 << 0
|
#define HTTP_FLAG_HTTP11 1 << 0
|
||||||
#define HTTP_FLAG_GOT_HEADER 1 << 1
|
#define HTTP_FLAG_GOT_HEADER 1 << 1
|
||||||
#define HTTP_FLAG_GOT_ALL_DATA 1 << 2
|
#define HTTP_FLAG_GOT_ALL_DATA 1 << 2
|
||||||
@ -65,7 +66,7 @@ typedef struct http_msg_s {
|
|||||||
void * content_ptr; // ptr to content
|
void * content_ptr; // ptr to content
|
||||||
unsigned content_length; // total length of HTTP content
|
unsigned content_length; // total length of HTTP content
|
||||||
unsigned content_received; // number of currently received content bytes
|
unsigned content_received; // number of currently received content bytes
|
||||||
char http_header[1];
|
char * http_header;
|
||||||
} http_msg;
|
} http_msg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -77,7 +78,7 @@ typedef struct http_msg_s {
|
|||||||
Initiates a HTTP connection, using 'GET' method.
|
Initiates a HTTP connection, using 'GET' method.
|
||||||
Returns NULL on error, identifier otherwise.
|
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
|
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.
|
Initiate a HTTP connection, using 'HEAD' method.
|
||||||
Returns NULL on error, identifier otherwise.
|
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
|
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.
|
using system function 75, 6.
|
||||||
Returns 0 on error, identifier otherwise
|
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);
|
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_length you'll find the length of the content.
|
||||||
In content_received, you'll find the number of content bytes already received.
|
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
|
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)
|
This procedure can be used to send data to the server (POST)
|
||||||
Returns number of bytes sent, -1 on error
|
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________
|
/*
|
||||||
|
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_
|
@ -1,14 +1,19 @@
|
|||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <kos/http.h>
|
#include <clayer/http.h>
|
||||||
#include <kos/inputbox.h>
|
#include <clayer/inputbox.h>
|
||||||
|
|
||||||
|
#define OK 200
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (con_init_console_dll()) return 1; // init fail
|
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_write_asciiz("Wait, I'll ask you... when I'll done to fetch one site...\n");
|
||||||
con_set_title("Dynamicaly linked app");
|
con_set_title("Dynamicaly linked app");
|
||||||
http_msg *h = get("http://example.com", 0, HTTP_FLAG_BLOCK, "");
|
|
||||||
if (!receive(h)) {
|
http_msg *h = http_get("http://kolibri.org/", 0, HTTP_FLAG_BLOCK, "");
|
||||||
con_printf("%s\n", h->content_ptr);
|
http_long_receive(h);
|
||||||
|
|
||||||
|
if (h->status == OK) {
|
||||||
|
con_write_string(h->content_ptr, h->content_length);
|
||||||
} else {
|
} else {
|
||||||
con_write_asciiz("Oops! Can't access to the page.\n");
|
con_write_asciiz("Oops! Can't access to the page.\n");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <kos32sys1.h>
|
#include <kos32sys1.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <kos/gb.h>
|
#include <clayer/gb.h>
|
||||||
|
|
||||||
/// ===========================================================
|
/// ===========================================================
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user