]> Nishi Git Mirror - libw3.git/commitdiff
fixing nntp
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 15 Feb 2024 03:03:09 +0000 (03:03 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 15 Feb 2024 03:03:09 +0000 (03:03 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@222 d27a3e52-49c5-7645-884c-6793ebffc270

Example/nntp-list/nntp-list.c
Library/FTP.c
Library/NNTP.c
Library/W3NNTP.h
W3Version.h.p

index b174463b0b89de74f8f44dccbc98ec4028f7ca1b..dbb7c0a5d6ad8f82b60787703564e271f5520053 100644 (file)
@@ -1,11 +1,11 @@
 /*
  * $Id$
  *
- * Lists the FTP files
+ * Lists the NNTP files
  */
 
 #include <W3Core.h>
-#include <W3FTP.h>
+#include <W3NNTP.h>
 
 #include <W3URL.h>
 #include <W3Util.h> /* It has some useful functions, you know */
 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);
        }
 }
 
index 930c05b4f33229e376f21e51a9a319f9f7466f28..ee88c9019ab2a80511d6402b8cca977589e04c20 100644 (file)
@@ -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);
                                        }
index 5304e5c44407095002da794375d0214936df8424..1468861ccade97830d971ee4ed81be954006648d 100644 (file)
@@ -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){
+}
+
index 2d3bd53e5d23816a0e9e56ac71794054c8075b57..d38e170b6c16804d3398e8306aecb69726269af9 100644 (file)
@@ -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
 }
index 2b9c5803601c41765157351d0cbb790a47761c9a..339234884a4e688e324326172fc8349cbabc27eb 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "2.12E" \
+#define LIBW3_VERSION "2.12F" \
 SUFFIX
 
 #ifdef __cplusplus