}
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);
}
#include "W3DNS.h"
#include "W3Util.h"
+#include "W3HTTP.h"
#include <stdio.h>
#include <string.h>
){
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
);
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);
+}
--- /dev/null
+/* $Id$ */
+#include "W3HTTP.h"
+
+#include "W3Core.h"
+#include "W3Util.h"
+
+void __W3_HTTP_Request(struct W3* w3){
+ __W3_Debug("LibW3-HTTP", "Sending the request");
+}
# $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
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;
+}
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* */
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
--- /dev/null
+/* $Id$ */
+#ifndef __W3HTTP_H__
+#define __W3HTTP_H__
+
+#include "W3Core.h"
+void __W3_HTTP_Request(struct W3* w3);
+
+#endif
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