From: nishi Date: Tue, 13 Feb 2024 02:27:37 +0000 (+0000) Subject: gophers support X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ae92b9922fbb62773880b6768c54f0d96a5fa90a;p=libw3.git gophers support git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@205 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Library/Core.c b/Library/Core.c index 628b615..513c634 100644 --- a/Library/Core.c +++ b/Library/Core.c @@ -58,7 +58,9 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port) { bool ssl = false; if(strcmp(protocol, "https") == 0) { ssl = true; - }else if(strcmp(protocol, "gemini") == 0) { + } else if(strcmp(protocol, "gemini") == 0) { + ssl = true; + } else if(strcmp(protocol, "gophers") == 0) { ssl = true; } w3->props = NULL; @@ -82,6 +84,7 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port) { } else if(strcmp(protocol, "https") == 0) { } else if(strcmp(protocol, "pop3s") == 0) { } else if(strcmp(protocol, "gemini") == 0) { + } else if(strcmp(protocol, "gophers") == 0) { #endif } else if(strcmp(protocol, "gopher") == 0) { } else if(strcmp(protocol, "pop3") == 0) { @@ -134,7 +137,11 @@ void W3_Send_Request(struct W3* w3) { #endif ) { __W3_HTTP_Request(w3); - } else if(strcmp(w3->protocol, "gopher") == 0) { + } else if(strcmp(w3->protocol, "gopher") == 0 +#ifdef SSL_SUPPORT + || strcmp(w3->protocol, "gophers") == 0 +#endif + ) { __W3_Gopher_Request(w3); } else if(strcmp(w3->protocol, "pop3") == 0 #ifdef SSL_SUPPORT diff --git a/Library/Gemini.c b/Library/Gemini.c index 9a96db5..523d574 100644 --- a/Library/Gemini.c +++ b/Library/Gemini.c @@ -4,9 +4,9 @@ #include "W3Util.h" #include -#include -#include #include +#include +#include void __W3_Gemini_Request(struct W3* w3) { __W3_Debug("LibW3-Gemini", "Sending the request"); @@ -29,20 +29,20 @@ void __W3_Gemini_Request(struct W3* w3) { 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'){ + 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) == 20){ + } else if(buf[i] == '\r') { + if(!bcode) { + if(atoi(code) == 20) { 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) >= 30 && atoi(code) < 40){ + } else if(atoi(code) >= 30 && atoi(code) < 40) { void* funcptr = __W3_Get_Event(w3, "header"); if(funcptr != NULL) { void (*func)(struct W3*, char*, char*) = (void (*)(struct W3*, char*, char*))funcptr; @@ -50,7 +50,7 @@ void __W3_Gemini_Request(struct W3* w3) { } } } - }else if(!bcode){ + } else if(!bcode) { char* tmp = meta; char* cbuf = malloc(2); cbuf[0] = buf[i]; @@ -58,15 +58,15 @@ void __W3_Gemini_Request(struct W3* w3) { meta = __W3_Concat(tmp, cbuf); free(tmp); free(cbuf); - }else if(bcode){ - if(buf[i] == ' '){ + } 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{ + } else { char* tmp = code; char* cbuf = malloc(2); cbuf[0] = buf[i]; diff --git a/Library/URL.c b/Library/URL.c index a3f8ec6..459b1aa 100644 --- a/Library/URL.c +++ b/Library/URL.c @@ -58,7 +58,7 @@ struct W3URL* W3_Parse_URL(const char* _url) { r->port = 80; } else if(strcmp(r->protocol, "https") == 0) { r->port = 443; - } else if(strcmp(r->protocol, "gopher") == 0) { + } else if(strcmp(r->protocol, "gopher") == 0 || strcmp(r->protocol, "gophers") == 0) { r->port = 70; } else if(strcmp(r->protocol, "gemini") == 0) { r->port = 1965; diff --git a/W3Version.h.p b/W3Version.h.p index 723af1d..e235c3c 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.6" \ +#define LIBW3_VERSION "2.7" \ SUFFIX #ifdef __cplusplus