-.PHONY: clean
+# $Id$:
+.PHONY: clean install
./fetch: ./fetch.c
- $(CC) -o $@ $< ../Library/libw3.so
+ $(CC) -o $@ -I ../Library -L ../Library $< -lw3
clean:
rm -f fetch *.o *.so *.core
+
+install: ./fetch
+ mkdir -p $(PREFIX)/bin
+ cp ./fetch $(PREFIX)/bin/w3-fetch
*
*/
+#include <W3Core.h>
+
#include <stdio.h>
+#include <stdbool.h>
int main(int argc, char** argv){
if(argc < 2){
fprintf(stderr, "Usage: %s URL\n", argv[0]);
return 1;
}
+ W3_Library_Init();
+ struct W3* w3 = W3_Create(false, 80);
}
/* $Id$ */
#include "W3Core.h"
+
+#include "W3Util.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+
+#ifdef SSL_SUPPORT
+#include <openssl/ssl.h>
+#endif
+
+int W3_Library_Init(void){
+ __W3_Debug("LibW3", "Initializing");
+#ifdef SSL_SUPPORT
+ if(SSL_library_init() >= 0){
+ __W3_Debug("LibW3-SSL", "Initialized");
+ }else{
+ return 1;
+ }
+#endif
+#ifdef SSL_SUPPORT
+ __W3_Debug("LibW3", "This is LibW3, version " LIBW3_VERSION ", using " OPENSSL_VERSION_TEXT);
+#else
+ __W3_Debug("LibW3", "This is LibW3, version " LIBW3_VERSION ", without SSL support");
+#endif
+ return 0;
+}
+
+struct W3* W3_Create(bool ssl, int port){
+ __W3_Debug("Create", "Creating a struct");
+ struct W3* w3 = malloc(sizeof(*w3));
+ return w3;
+}
--- /dev/null
+/* $Id$ */
+#include "W3DNS.h"
# $Id$
-.PHONY: clean
+.PHONY: clean install
-./libw3.so: ./Core.o
- $(CC) $(LDFLAGS) -shared -o $@ $^
+./libw3.so: ./Core.o ./Util.o
+ $(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBS)
./%.o: ./%.c W3%.h
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *.o *.so *.core
+
+install: ./libw3.so
+ mkdir -p $(PREFIX)/lib
+ cp ./libw3.so $(PREFIX)/lib/
+ mkdir -p $(PREFIX)/include/W3
+ cp *.h $(PREFIX)/include/W3/
--- /dev/null
+/* $Id$ */
+#include "W3Util.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define __DEBUG_LEN 12
+
+void __W3_Debug(const char* title, const char* message){
+#ifdef __DEBUG__
+ char* periods = malloc(__DEBUG_LEN - strlen(title) + 1);
+ periods[__DEBUG_LEN - strlen(title)] = 0;
+ memset(periods, '.', __DEBUG_LEN - strlen(title));
+ fprintf(stderr, "%s%s %s\n", title, periods, message);
+#endif
+}
#ifndef __W3CORE_H__
#define __W3CORE_H__
+#include <stdbool.h>
+
+#define LIBW3_VERSION "1.0"
+
+struct W3 {
+ int sock; /* Socket */
+#ifdef SSL_SUPPORT
+ void* ssl; /* Actually SSL*, NULL if no SSL */
+ void* ssl_ctx; /* Actually SSL_CTX* */
+#endif
+};
+
+int W3_Library_Init(void); /* Initialize the Library */
+struct W3* W3_Create(bool ssl, int port); /* Create the struct */
+
#endif
--- /dev/null
+/* $Id$ */
+#ifndef __W3DNS_H__
+#define __W3DNS_H__
+
+int __W3_DNS_Connect(const char* hostname);
+
+#endif
--- /dev/null
+/* $Id$ */
+#ifndef __W3UTIL_H__
+#define __W3UTIL_H__
+
+void __W3_Debug(const char* title, const char* message);
+
+#endif
CFLAGS := -g -std=c99 -fPIC
LDFLAGS :=
LIBS :=
+PREFIX := /usr/local
ifdef SSL
+CFLAGS += -DSSL_SUPPORT
LIBS += -lssl -lcrypto
-SSL=SSL=YES
endif
-.PHONY: all clean
+ifdef DEBUG
+CFLAGS += -D__DEBUG__
+endif
+
+.PHONY: all clean ./Library/libw3.so ./Example/fetch
all: ./Library/libw3.so ./Example/fetch
./Library/libw3.so:
- $(MAKE) -C ./Library $(SSL) CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)"
+ $(MAKE) -C ./Library CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)"
./Example/fetch:
$(MAKE) -C ./Example CC=$(CC) fetch
clean:
$(MAKE) -C ./Library clean
$(MAKE) -C ./Example clean
+
+install:
+ $(MAKE) -C ./Library install PREFIX=$(PREFIX)
+ $(MAKE) -C ./Example install PREFIX=$(PREFIX)