From: nishi Date: Wed, 17 Jan 2024 08:52:54 +0000 (+0000) Subject: http X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=eccaafbce4b077a018c4446902d348636d0dc2b4;p=libw3.git http git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@12 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Example/fetch.c b/Example/fetch.c index 6f664e8..40c033a 100644 --- a/Example/fetch.c +++ b/Example/fetch.c @@ -16,4 +16,8 @@ int main(int argc, char** argv){ } W3_Library_Init(); struct W3* w3 = W3_Create("http", argv[1], 80); + W3_Set_Method(w3, "GET"); + W3_Set_Path(w3, "/sunhttpd"); + W3_Send_Request(w3); + W3_Free(w3); } diff --git a/Library/Core.c b/Library/Core.c index c9beb0e..6ddcca0 100644 --- a/Library/Core.c +++ b/Library/Core.c @@ -3,6 +3,7 @@ #include "W3DNS.h" #include "W3Util.h" +#include "W3HTTP.h" #include #include @@ -38,6 +39,9 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){ ){ ssl = true; } + w3->method = NULL; + w3->path = NULL; + w3->protocol = __W3_Strdup(protocol); if(ssl) __W3_Debug("Protocol", "Enabled SSL"); w3->sock = __W3_DNS_Connect(hostname, ssl, port #ifdef SSL_SUPPORT @@ -48,3 +52,27 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){ ); return w3; } + +void W3_Set_Method(struct W3* w3, const char* method){ + if(w3->method != NULL) free(w3->method); + w3->method = __W3_Strdup(method); +} + +void W3_Set_Path(struct W3* w3, const char* path){ + if(w3->path != NULL) free(w3->path); + w3->path = __W3_Strdup(path); +} + +void W3_Send_Request(struct W3* w3){ + if(strcmp(w3->protocol, "http") == 0 || strcmp(w3->protocol, "https") == 0){ + __W3_HTTP_Request(w3); + } +} + +void W3_Free(struct W3* w3){ + __W3_Debug("LibW3", "Freeing"); + if(w3->method != NULL) free(w3->method); + if(w3->path != NULL) free(w3->path); + if(w3->protocol != NULL) free(w3->protocol); + free(w3); +} diff --git a/Library/HTTP.c b/Library/HTTP.c new file mode 100644 index 0000000..690e379 --- /dev/null +++ b/Library/HTTP.c @@ -0,0 +1,9 @@ +/* $Id$ */ +#include "W3HTTP.h" + +#include "W3Core.h" +#include "W3Util.h" + +void __W3_HTTP_Request(struct W3* w3){ + __W3_Debug("LibW3-HTTP", "Sending the request"); +} diff --git a/Library/Makefile b/Library/Makefile index 08147f6..07e0663 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -1,7 +1,7 @@ # $Id$ .PHONY: clean install -./libw3.so: ./Core.o ./Util.o ./DNS.o +./libw3.so: ./Core.o ./Util.o ./DNS.o ./HTTP.o $(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBS) ./%.o: ./%.c W3%.h diff --git a/Library/Util.c b/Library/Util.c index 906e279..8d87cd4 100644 --- a/Library/Util.c +++ b/Library/Util.c @@ -23,3 +23,16 @@ char* __W3_Concat(const char* str1, const char* str2){ str[strlen(str1) + strlen(str2)] = 0; return str; } + +char* __W3_Concat3(const char* str1, const char* str2, const char* str3){ + char* tmp = __W3_Concat(str1, str2); + char* str = __W3_Concat(tmp, str3); + free(tmp); + return str; +} + +char* __W3_Strdup(const char* str){ + char* result = malloc(strlen(str) + 1); + memcpy(result, str, strlen(str) + 1); + return result; +} diff --git a/Library/W3Core.h b/Library/W3Core.h index 3ed745f..a232ae4 100644 --- a/Library/W3Core.h +++ b/Library/W3Core.h @@ -8,6 +8,9 @@ struct W3 { int sock; /* Socket */ + char* protocol; /* As you can read from its name */ + char* method; /* Used in HTTP */ + char* path; /* As you can read from its name */ #ifdef SSL_SUPPORT void* ssl; /* Actually SSL*, NULL if no SSL */ void* ssl_ctx; /* Actually SSL_CTX* */ @@ -17,4 +20,9 @@ struct W3 { int W3_Library_Init(void); /* Initialize the Library */ struct W3* W3_Create(const char* protocol, const char* hostname, int port); /* Create the struct */ +void W3_Set_Method(struct W3* w3, const char* method); /* Set the method */ +void W3_Set_Path(struct W3* w3, const char* path); /* Set the path */ +void W3_Send_Request(struct W3* w3); /* Send the request */ +void W3_Free(struct W3* w3); /* Free the struct */ + #endif diff --git a/Library/W3HTTP.h b/Library/W3HTTP.h new file mode 100644 index 0000000..33e655a --- /dev/null +++ b/Library/W3HTTP.h @@ -0,0 +1,8 @@ +/* $Id$ */ +#ifndef __W3HTTP_H__ +#define __W3HTTP_H__ + +#include "W3Core.h" +void __W3_HTTP_Request(struct W3* w3); + +#endif diff --git a/Library/W3Util.h b/Library/W3Util.h index 9eefd88..1156655 100644 --- a/Library/W3Util.h +++ b/Library/W3Util.h @@ -4,5 +4,7 @@ void __W3_Debug(const char* title, const char* message); char* __W3_Concat(const char* str1, const char* str2); +char* __W3_Concat3(const char* str1, const char* str2, const char* str3); +char* __W3_Strdup(const char* str); #endif