From: nishi Date: Thu, 15 Feb 2024 03:03:09 +0000 (+0000) Subject: fixing nntp X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=43feb1f27b8045c6c80bbc2fb68ac7fbcf4aa047;p=libw3.git fixing nntp git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@222 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Example/nntp-list/nntp-list.c b/Example/nntp-list/nntp-list.c index b174463..dbb7c0a 100644 --- a/Example/nntp-list/nntp-list.c +++ b/Example/nntp-list/nntp-list.c @@ -1,11 +1,11 @@ /* * $Id$ * - * Lists the FTP files + * Lists the NNTP files */ #include -#include +#include #include #include /* It has some useful functions, you know */ @@ -20,12 +20,10 @@ struct W3URL* w3url; void resp_handler(struct W3* w3, int status, char* data) { - printf("%d\n%s\n", status, data); - if(status == 230) { + printf("%d %s\n", status, data); + if(status == 200) { W3_Set_Method(w3, "LIST"); - W3_FTP_Send_Request(w3); - } else if(status == 226) { - W3_FTP_Disconnect(w3); + W3_NNTP_Send_Request(w3); } } diff --git a/Library/FTP.c b/Library/FTP.c index 930c05b..ee88c90 100644 --- a/Library/FTP.c +++ b/Library/FTP.c @@ -163,6 +163,7 @@ void __W3_FTP_Request(struct W3* w3) { } void* funcptr = __W3_Get_Event(w3, "ftpresp"); if(funcptr != NULL) { + if(buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0; void (*func)(struct W3*, int, char*) = (void (*)(struct W3*, int, char*))funcptr; func(w3, status, buffer); } diff --git a/Library/NNTP.c b/Library/NNTP.c index 5304e5c..1468861 100644 --- a/Library/NNTP.c +++ b/Library/NNTP.c @@ -13,9 +13,88 @@ extern int strcasecmp(const char* s1, const char* s2); void __W3_NNTP_Request(struct W3* w3) { __W3_Debug("LibW3-NNTP", "Sending the request"); char* buf = malloc(w3->readsize); + char* cbuf = malloc(2); + char* line = malloc(1); + line[0] = 0; + cbuf[1] = 0; + int flag = 0; + w3->generic = &flag; + char* data = malloc(1); + data[0] = 0; while(true) { int len = __W3_Auto_Read(w3, buf, w3->readsize); if(len <= 0) break; + int i; + for(i = 0; i < len; i++){ + if(buf[i] == '\n'){ + int sendstatus = -1; + char* senddata = NULL; + bool freedata = false; + if(flag & 1){ + if(strcmp(line, ".") == 0){ + flag &= ~1; + int j; + for(j = 0; data[j] != 0; j++){ + if(data[j] == ' '){ + data[j] = 0; + sendstatus = atoi(data); + senddata = data + j + 1; + break; + } + } + freedata = true; + }else{ + char* tmp = data; + data = __W3_Concat3(tmp, strlen(data) != 0 ? "\n" : "", line); + free(tmp); + } + }else{ + int j; + for(j = 0; line[j] != 0; j++){ + if(line[j] == ' '){ + line[j] = 0; + sendstatus = atoi(line); + senddata = line + j + 1; + break; + } + } + } + if(sendstatus != -1){ + void* funcptr = __W3_Get_Event(w3, "nntpresp"); + if(funcptr != NULL) { + void (*func)(struct W3*, int, char*) = (void (*)(struct W3*, int, char*))funcptr; + func(w3, sendstatus, senddata); + } + } + if(freedata){ + free(data); + data = malloc(1); + data[0] = 0; + } + free(line); + line = malloc(1); + line[0] = 0; + }else if(buf[i] != '\r'){ + cbuf[0] = buf[i]; + char* tmp = line; + line = __W3_Concat(tmp, cbuf); + free(tmp); + } + } } + free(data); + free(line); + free(cbuf); free(buf); } + +void W3_NNTP_Send_Request(struct W3* w3){ + if(strcasecmp(w3->method, "LIST") == 0){ + (*(int*)w3->generic) |= 1; + __W3_Auto_Write(w3, "LIST\r\n", 6); + } +} + +void W3_NNTP_Disconnect(struct W3* w3){ +} + diff --git a/Library/W3NNTP.h b/Library/W3NNTP.h index 2d3bd53..d38e170 100644 --- a/Library/W3NNTP.h +++ b/Library/W3NNTP.h @@ -9,6 +9,8 @@ extern "C" { #include "W3Core.h" void __W3_NNTP_Request(struct W3* w3); +void W3_NNTP_Send_Request(struct W3* w3); +void W3_NNTP_Disconnect(struct W3* w3); #ifdef __cplusplus } diff --git a/W3Version.h.p b/W3Version.h.p index 2b9c580..3392348 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.12E" \ +#define LIBW3_VERSION "2.12F" \ SUFFIX #ifdef __cplusplus