return 1;
}
W3_Library_Init();
- struct W3* w3 = W3_Create("http", argv[1], 80);
+ struct W3* w3 = W3_Create("file", argv[1], 80);
if(w3 != NULL){
W3_Set_Method(w3, argv[3] == NULL ? "GET" : argv[3]);
W3_Set_Path(w3, argv[2]);
#include "W3DNS.h"
#include "W3Util.h"
+
#include "W3HTTP.h"
+#include "W3File.h"
#include <stdio.h>
#include <string.h>
w3->path = NULL;
w3->events = NULL;
w3->headers = NULL;
- w3->protocol = __W3_Strdup(protocol);
- w3->hostname = __W3_Strdup(hostname);
w3->size = 0;
w3->data = NULL;
- if(ssl) __W3_Debug("Protocol", "Enabled SSL");
- w3->sock = __W3_DNS_Connect(hostname, ssl, port
+ w3->protocol = __W3_Strdup(protocol);
+ if(strcmp(protocol, "file") != 0){
+ w3->hostname = __W3_Strdup(hostname);
+ if(ssl) __W3_Debug("Protocol", "Enabled SSL");
+ w3->sock = __W3_DNS_Connect(hostname, ssl, port
#ifdef SSL_SUPPORT
- ,
- &w3->ssl,
- &w3->ssl_ctx
+ ,
+ &w3->ssl,
+ &w3->ssl_ctx
#endif
- );
- if(w3->sock == -1){
- W3_Free(w3);
- w3 = NULL;
+ );
+ if(w3->sock == -1){
+ W3_Free(w3);
+ w3 = NULL;
+ }
}
return w3;
}
void W3_Send_Request(struct W3* w3){
if(strcmp(w3->protocol, "http") == 0 || strcmp(w3->protocol, "https") == 0){
__W3_HTTP_Request(w3);
+ }else if(strcmp(w3->protocol, "file") == 0){
+ __W3_File_Request(w3);
}
}
--- /dev/null
+/* $Id$ */
+#include "W3File.h"
+
+#include "W3Core.h"
+#include "W3Util.h"
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+void __W3_File_Request(struct W3* w3){
+ __W3_Debug("LibW3-File", "Sending the request");
+ FILE* f = fopen(w3->path, "r");
+ if(f == NULL){
+ void* funcptr = __W3_Get_Event(w3, "status");
+ if(funcptr != NULL){
+ void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+ func(w3, LIBW3_FILE_NOT_FOUND);
+ }
+ }else{
+ void* funcptr = __W3_Get_Event(w3, "status");
+ if(funcptr != NULL){
+ void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+ func(w3, LIBW3_FILE_FOUND);
+ }
+ char* buf = malloc(512);
+ while(true){
+ int len = fread(buf, 1, 512, f);
+ void* funcptr = __W3_Get_Event(w3, "data");
+ if(funcptr != NULL){
+ void(*func)(struct W3*, char*, size_t) = (void(*)(struct W3*, char*, size_t))funcptr;
+ func(w3, buf, len);
+ }
+ if(feof(f)) break;
+ }
+ free(buf);
+ }
+}
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
void __W3_HTTP_Request(struct W3* w3){
__W3_Debug("LibW3-HTTP", "Sending the request");
char* headerbuf = malloc(1);
headerbuf[0] = 0;
int phase = 0;
- while(1){
+ while(true){
int l = __W3_Auto_Read(w3, buf, 512);
if(l <= 0) break;
int i;
# $Id$
.PHONY: clean install
-OBJS = ./Core.o ./Util.o ./DNS.o ./HTTP.o
+OBJS = ./Core.o ./Util.o ./DNS.o ./HTTP.o ./File.o
ifeq ($(WINDOWS),YES)
./w3.dll: $(OBJS)
--- /dev/null
+/* $Id$ */
+#ifndef __W3FILE_H__
+#define __W3FILE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "W3Core.h"
+void __W3_File_Request(struct W3* w3);
+
+#define LIBW3_FILE_FOUND 0
+#define LIBW3_FILE_NOT_FOUND 1
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
extern "C" {
#endif
-#define LIBW3_VERSION "1.1" \
+#define LIBW3_VERSION "1.2" \
SUFFIX
#ifdef __cplusplus