]> Nishi Git Mirror - libw3.git/commitdiff
dns
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 17 Jan 2024 01:15:18 +0000 (01:15 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 17 Jan 2024 01:15:18 +0000 (01:15 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@3 d27a3e52-49c5-7645-884c-6793ebffc270

Example/Makefile
Example/fetch.c
Library/Core.c
Library/DNS.c [new file with mode: 0644]
Library/Makefile
Library/Util.c [new file with mode: 0644]
Library/W3Core.h
Library/W3DNS.h [new file with mode: 0644]
Library/W3Util.h [new file with mode: 0644]
Makefile
config.mk

index 0b15da1151e7a9ae8f808f50855c28310ea2d6da..834103f8577244240645be9de5d8501dd536ebb2 100644 (file)
@@ -1,7 +1,12 @@
-.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
index bf4f8f76bdaf9a1aa38ca3f16e18a8b4b2063547..cef8fc5cbf380c44c913093a7c9bd3200c9c8dcd 100644 (file)
@@ -4,11 +4,16 @@
  *
  */
 
+#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);
 }
index 99b5b5a3f136bd773dd9a2359ee662a4b0a2febf..e1dcb8d73899d495aee6365dcd3556c066f2b0dc 100644 (file)
@@ -1,2 +1,34 @@
 /* $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;
+}
diff --git a/Library/DNS.c b/Library/DNS.c
new file mode 100644 (file)
index 0000000..8513ab3
--- /dev/null
@@ -0,0 +1,2 @@
+/* $Id$ */
+#include "W3DNS.h"
index 468ebaa7fdf34ab13e9d96f2cda9658ecc87f1a3..43d84dd543bd59a8bc67c8208d679e66baedac32 100644 (file)
@@ -1,11 +1,17 @@
 # $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/
diff --git a/Library/Util.c b/Library/Util.c
new file mode 100644 (file)
index 0000000..a1ebd9c
--- /dev/null
@@ -0,0 +1,17 @@
+/* $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
+}
index ff003c815c755a8f3d0f201a4ed3a785eed42325..221dfea4c6b4092ae83996f0af18a48e046a10e0 100644 (file)
@@ -2,4 +2,19 @@
 #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
diff --git a/Library/W3DNS.h b/Library/W3DNS.h
new file mode 100644 (file)
index 0000000..132413e
--- /dev/null
@@ -0,0 +1,7 @@
+/* $Id$ */
+#ifndef __W3DNS_H__
+#define __W3DNS_H__
+
+int __W3_DNS_Connect(const char* hostname);
+
+#endif
diff --git a/Library/W3Util.h b/Library/W3Util.h
new file mode 100644 (file)
index 0000000..94bef34
--- /dev/null
@@ -0,0 +1,7 @@
+/* $Id$ */
+#ifndef __W3UTIL_H__
+#define __W3UTIL_H__
+
+void __W3_Debug(const char* title, const char* message);
+
+#endif
index 37ff8bbbe3b22facad263c8c772332290acec15e..83ab44b899e4b76653aaa9073e970801c33319de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,18 +5,23 @@ CC := cc
 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
@@ -24,3 +29,7 @@ all: ./Library/libw3.so ./Example/fetch
 clean:
        $(MAKE) -C ./Library clean
        $(MAKE) -C ./Example clean
+
+install:
+       $(MAKE) -C ./Library install PREFIX=$(PREFIX)
+       $(MAKE) -C ./Example install PREFIX=$(PREFIX)
index c92f39f5bd378a647dc307a5d885f3edf7246595..4452ff45177521cc8eb79289895f719d086891b6 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -1 +1,2 @@
 SSL=YES
+DEBUG=YES