]> Nishi Git Mirror - libw3.git/commitdiff
adding spartan support
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 28 Mar 2024 00:44:46 +0000 (00:44 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 28 Mar 2024 00:44:46 +0000 (00:44 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@265 d27a3e52-49c5-7645-884c-6793ebffc270

Library/Core.c
Library/Makefile
Library/Spartan.c [new file with mode: 0644]
Library/URL.c
Library/W3Spartan.h [new file with mode: 0644]
Library/protocol.mk
Makefile
W3Version.h.m4

index de4050548721a9930d257ba7dda4741d90891745..9793373d1bb9e4f215ef2b1421cc4f2ad80bfa89 100644 (file)
 #include "W3IRC.h"
 #endif
 
+#ifdef SPARTAN_SUPPORT
+#include "W3Spartan.h"
+#endif
+
 #include <ctype.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -156,6 +160,9 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port) {
 #endif
 #ifdef IRC_SUPPORT
                } else if(strcmp(protocol, "irc") == 0) {
+#endif
+#ifdef SPARTAN_SUPPORT
+               } else if(strcmp(protocol, "spartan") == 0) {
 #endif
                } else {
                        __W3_Debug("Protocol", "Not suppported");
@@ -259,6 +266,10 @@ void W3_Send_Request(struct W3* w3) {
        } else if(strcmp(w3->protocol, "file") == 0) {
                __W3_File_Request(w3);
 #endif
+#ifdef SPARTAN_SUPPORT
+       } else if(strcmp(w3->protocol, "spartan") == 0) {
+               __W3_Spartan_Request(w3);
+#endif
 #ifdef IRC_SUPPORT
        } else if(strcmp(w3->protocol, "irc") == 0
 #ifdef SSL_SUPPORT
index dda6b217e0594b62092833870b8debcd549f65f4..bae59aa05b0a9da2415470a53f4eb47c1053549f 100644 (file)
@@ -50,6 +50,10 @@ ifneq ($(IRC),NO)
 OBJS += ./IRC.o
 endif
 
+ifneq ($(Spartan),NO)
+OBJS += ./Spartan.o
+endif
+
 ifeq ($(WINDOWS),YES)
 ./w3.dll: $(OBJS)
        $(CC) $(LDFLAGS) -fstack-protector -L../openssl/lib/mingw/$(WINARCH) -L . -shared -Wl,--out-implib,./w3.lib -o $@ $^ $(LIBS)
diff --git a/Library/Spartan.c b/Library/Spartan.c
new file mode 100644 (file)
index 0000000..0c4c7c5
--- /dev/null
@@ -0,0 +1,99 @@
+/* $Id$ */
+#include "W3Spartan.h"
+
+#include "W3Util.h"
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void __W3_Spartan_Request(struct W3* w3) {
+       __W3_Debug("LibW3-", "Sending the request");
+       __W3_Auto_Write(w3, w3->hostname, strlen(w3->hostname));
+       char* portstr = malloc(10);
+       memset(portstr, 0, 10);
+       sprintf(portstr, ":%d", w3->port);
+       __W3_Auto_Write(w3, portstr, strlen(portstr));
+       __W3_Auto_Write(w3, " ", 1);
+       __W3_Auto_Write(w3, w3->path, strlen(w3->path));
+       __W3_Auto_Write(w3, " ", 1);
+       char* conlen = malloc(65);
+       sprintf(conlen, "%d", w3->size);
+       __W3_Auto_Write(w3, conlen, strlen(conlen));
+       free(conlen);
+       __W3_Auto_Write(w3, "\r\n", 2);
+       if(w3->data != NULL){
+               __W3_Auto_Write(w3, w3->data, w3->size);
+       }
+       char* buf = malloc(w3->readsize);
+       bool status = true;
+       char* code = malloc(1);
+       code[0] = 0;
+       char* meta = malloc(1);
+       meta[0] = 0;
+       bool bcode = true;
+       while(true) {
+               int len = __W3_Auto_Read(w3, buf, w3->readsize);
+               if(len <= 0) break;
+               int i = 0;
+               if(status) {
+                       for(i = 0; i < len; i++) {
+                               if(buf[i] == '\n') {
+                                       status = false;
+                                       break;
+                               } else if(buf[i] == '\r') {
+                                       if(!bcode) {
+                                               if(atoi(code) == 2) {
+                                                       void* funcptr = __W3_Get_Event(w3, "header");
+                                                       if(funcptr != NULL) {
+                                                               void (*func)(struct W3*, char*, char*) = (void (*)(struct W3*, char*, char*))funcptr;
+                                                               func(w3, "Content-Type", meta);
+                                                       }
+                                               } else if(atoi(code) == 3) {
+                                                       void* funcptr = __W3_Get_Event(w3, "header");
+                                                       if(funcptr != NULL) {
+                                                               void (*func)(struct W3*, char*, char*) = (void (*)(struct W3*, char*, char*))funcptr;
+                                                               func(w3, "Location", meta);
+                                                       }
+                                               }
+                                       }
+                               } else if(!bcode) {
+                                       char* tmp = meta;
+                                       char* cbuf = malloc(2);
+                                       cbuf[0] = buf[i];
+                                       cbuf[1] = 0;
+                                       meta = __W3_Concat(tmp, cbuf);
+                                       free(tmp);
+                                       free(cbuf);
+                               } else if(bcode) {
+                                       if(buf[i] == ' ') {
+                                               bcode = false;
+                                               void* funcptr = __W3_Get_Event(w3, "status");
+                                               if(funcptr != NULL) {
+                                                       void (*func)(struct W3*, int) = (void (*)(struct W3*, int))funcptr;
+                                                       func(w3, atoi(code));
+                                               }
+                                       } else {
+                                               char* tmp = code;
+                                               char* cbuf = malloc(2);
+                                               cbuf[0] = buf[i];
+                                               cbuf[1] = 0;
+                                               code = __W3_Concat(tmp, cbuf);
+                                               free(tmp);
+                                               free(cbuf);
+                                       }
+                               }
+                       }
+                       i++;
+               }
+               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 + i, len - i);
+               }
+       }
+       free(meta);
+       free(code);
+       free(buf);
+}
index c57d2dbb4df50f417ba55543b995d4fa88091e21..633c95e103efb88865ad8cd2c9e8996df711a4aa 100644 (file)
@@ -132,8 +132,10 @@ struct W3URL* W3_Parse_URL(const char* _url) {
                                        r->port = 119;
                                } else if(strcmp(r->protocol, "irc") == 0) {
                                        r->port = 6667;
-                               } else if(strcmp(r->protocol, "ircs") == 0) {
+                               }  else if(strcmp(r->protocol, "ircs") == 0) {
                                        r->port = 6697;
+                               }else if(strcmp(r->protocol, "spartan") == 0) {
+                                       r->port = 300;
                                }
                        }
                        r->host = __W3_Strdup(url + start + (atmark == 0 ? 0 : (atmark - 1)));
diff --git a/Library/W3Spartan.h b/Library/W3Spartan.h
new file mode 100644 (file)
index 0000000..6339a4c
--- /dev/null
@@ -0,0 +1,17 @@
+/* $Id$ */
+#ifndef __W3SPARTAN_H__
+#define __W3SPARTAN_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "W3Core.h"
+
+void __W3_Spartan_Request(struct W3* w3);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index d7ce21368d001f3c32595d9145926517804ad176..cd81faec4f4f3683e75f334c78bd530af2d77304 100644 (file)
@@ -9,3 +9,4 @@
 #FILE=NO
 #NNTP=NO
 #IRC=NO
+#SPARTAN=NO
index 0d350e34b8e1a312ea339ac71c25ba131d07e5ba..ae18a6863c932aa63a311ed7140e1919e0b5ce65 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,10 @@ ifneq ($(IRC),NO)
 FLAGS += -DIRC_SUPPORT
 endif
 
+ifneq ($(SPARTAN),NO)
+FLAGS += -DSPARTAN_SUPPORT
+endif
+
 CFLAGS += $(FLAGS)
 
 ifeq ($(WIN32),YES)
index 239edf61a9dd1115a70cddcb2c5edfe95c9dafb0..fc9644eb89dee86d69be735e97506538fee7d1dd 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "2.20G" \
+#define LIBW3_VERSION "2.21" \
 SUFFIX
 
 ifdef(`HTTP_SUPPORT', `#define LIBW3_HTTP_SUPPORT', `')
@@ -18,6 +18,7 @@ ifdef(`NEX_SUPPORT', `#define LIBW3_NEX_SUPPORT', `')
 ifdef(`FILE_SUPPORT', `#define LIBW3_FILE_SUPPORT', `')
 ifdef(`IRC_SUPPORT', `#define LIBW3_IRC_SUPPORT', `')
 ifdef(`NNTP_SUPPORT', `#define LIBW3_NNTP_SUPPORT', `')
+ifdef(`SPARTAN_SUPPORT', `#define LIBW3_SPARTAN_SUPPORT', `')
 
 #ifdef __cplusplus
 }