]> Nishi Git Mirror - libw3.git/commitdiff
pop3
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Sat, 27 Jan 2024 05:01:09 +0000 (05:01 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Sat, 27 Jan 2024 05:01:09 +0000 (05:01 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@107 d27a3e52-49c5-7645-884c-6793ebffc270

Example/pop3-list/pop3-list.c
Library/Core.c
Library/DNS.c
Library/POP3.c
Library/Util.c
Library/W3POP3.h

index 636c5b230fcc3c601ce3c8a9fab4e4ff409c55a2..c44bc95541a118c4e5ab4120bef15e75039a2c80 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
-void list_handler(struct W3* w3, char* data, size_t size) {
-}
+void list_handler(struct W3* w3, char* data, size_t size) {}
 
 int main(int argc, char** argv) {
-       if(argc < 4){
+       if(argc < 4) {
                return 1;
        }
        W3_Library_Init();
index 21f2d409d7ae61f5b4ae24d506618d1278296292..ae94ffc79d01111ea1789ad153af434ea7b682ef 100644 (file)
@@ -71,7 +71,7 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port) {
                if(strcmp(protocol, "http") == 0) {
 #ifdef SSL_SUPPORT
                } else if(strcmp(protocol, "https") == 0) {
-               } else if(strcmp(protocol, "pop3s") == 0){
+               } else if(strcmp(protocol, "pop3s") == 0) {
 #endif
                } else if(strcmp(protocol, "gopher") == 0) {
                } else if(strcmp(protocol, "pop3") == 0) {
@@ -112,7 +112,7 @@ void W3_Set_Path(struct W3* w3, const char* path) {
 void W3_Send_Request(struct W3* w3) {
        if(strcmp(w3->protocol, "http") == 0
 #ifdef SSL_SUPPORT
-               || strcmp(w3->protocol, "https") == 0
+          || strcmp(w3->protocol, "https") == 0
 #endif
        ) {
                __W3_HTTP_Request(w3);
@@ -120,9 +120,9 @@ void W3_Send_Request(struct W3* w3) {
                __W3_Gopher_Request(w3);
        } else if(strcmp(w3->protocol, "pop3") == 0
 #ifdef SSL_SUPPORT
-               || strcmp(w3->protocol, "pop3s") == 0
+                 || strcmp(w3->protocol, "pop3s") == 0
 #endif
-       ){
+       ) {
                __W3_POP3_Request(w3);
        } else if(strcmp(w3->protocol, "file") == 0) {
                __W3_File_Request(w3);
index c04a5e2978de41235d293f851b120671ff9fb8f4..4efabfbc0092f86337213d7ffc5a8edb168750f6 100644 (file)
@@ -7,8 +7,8 @@
 #include <string.h>
 
 #ifdef __MINGW32__
-#include <winsock2.h>
 #include <windows.h>
+#include <winsock2.h>
 #include <ws2tcpip.h>
 #else
 #include <netdb.h>
index 4595355aab647b164ebd9cef581df1e9b604ea66..cb521bc0b38bb25c03107a099aaa85de847c3890 100644 (file)
@@ -4,16 +4,18 @@
 #include "W3Core.h"
 #include "W3Util.h"
 
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdbool.h>
+
+extern int strcasecmp(const char* s1, const char* s2);
 
 void __W3_POP3_Request(struct W3* w3) {
-       if(__W3_Get_Prop(w3, "POP3_USERNAME") == NULL || __W3_Get_Prop(w3, "POP3_PASSWORD") == NULL){
+       if(__W3_Get_Prop(w3, "POP3_USERNAME") == NULL || __W3_Get_Prop(w3, "POP3_PASSWORD") == NULL) {
                __W3_Debug("LibW3-POP3", "Set the username/password");
                void* funcptr = __W3_Get_Event(w3, "error");
-               if(funcptr != NULL){
-                       void(*func)(struct W3*, const char*) = (void(*)(struct W3*, const char*))funcptr;
+               if(funcptr != NULL) {
+                       void (*func)(struct W3*, const char*) = (void (*)(struct W3*, const char*))funcptr;
                        func(w3, "did-not-auth");
                }
                return;
@@ -21,76 +23,86 @@ void __W3_POP3_Request(struct W3* w3) {
        char* buf = malloc(w3->readsize);
        int phase = 0;
        int login = 0;
+       char* message = malloc(1);
+       message[0] = 0;
+       char* cbuf = malloc(2);
+       cbuf[1] = 0;
        while(true) {
                int len = __W3_Auto_Read(w3, buf, w3->readsize);
                if(len <= 0) break;
                int i;
-               for(i = 0; i < len; i++){
-                       write(1, buf + i, 1);
+               for(i = 0; i < len; i++) {
                        char c = buf[i];
                        if(c == '\r') continue;
-                       if(c == '\n'){
-                               if(login == 0){
+                       if(c == '\n') {
+                               if(login == 0) {
                                        char* str = __W3_Concat3("USER ", __W3_Get_Prop(w3, "POP3_USERNAME"), "\r\n");
                                        __W3_Auto_Write(w3, str, strlen(str));
                                        free(str);
                                        login = 1;
-                               }else if(login == 1){
+                               } else if(login == 1) {
                                        char* str = __W3_Concat3("PASS ", __W3_Get_Prop(w3, "POP3_PASSWORD"), "\r\n");
                                        __W3_Auto_Write(w3, str, strlen(str));
                                        free(str);
                                        login = 2;
-                               }else{
-                                       if(phase == 3){
+                               } else {
+                                       if(phase == 3) {
                                                /* OK */
-                                               if(login == 2){
+                                               if(login == 2) {
                                                        /* Login success */
                                                        login = 3;
                                                        void* funcptr = __W3_Get_Event(w3, "login");
-                                                       if(funcptr != NULL){
-                                                               void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+                                                       if(funcptr != NULL) {
+                                                               void (*func)(struct W3*, int) = (void (*)(struct W3*, int))funcptr;
                                                                func(w3, 512);
                                                        }
                                                        __W3_Debug("LibW3-POP3", "Login successful");
-                                               }else{
+                                               } else {
                                                }
-                                       }else if(phase == 4){
+                                       } else if(phase == 4) {
                                                /* ERR */
-                                               if(login == 2){
+                                               if(login == 2) {
                                                        /* Login failed */
                                                        void* funcptr = __W3_Get_Event(w3, "error");
-                                                       if(funcptr != NULL){
-                                                               void(*func)(struct W3*, const char*) = (void(*)(struct W3*, const char*))funcptr;
+                                                       if(funcptr != NULL) {
+                                                               void (*func)(struct W3*, const char*) = (void (*)(struct W3*, const char*))funcptr;
                                                                func(w3, "login-fail");
                                                        }
                                                        login = 0;
                                                        return;
-                                               }else{
+                                               } else {
                                                }
                                        }
                                }
+                               free(message);
+                               message = malloc(1);
+                               message[0] = 0;
                                phase = 0;
                                continue;
+                       } else if(phase == 3 || phase == 4) {
+                               cbuf[0] = buf[i];
+                               char* tmp = message;
+                               message = __W3_Concat(tmp, cbuf);
+                               free(tmp);
                        }
-                       if(phase == 0){
-                               if(c == '+'){
+                       if(phase == 0) {
+                               if(c == '+') {
                                        phase = 1;
-                               }else if(c == '-'){
+                               } else if(c == '-') {
                                        phase = 2;
                                }
-                       }else if(phase == 1){
+                       } else if(phase == 1) {
                                if(c == ' ') phase += 2;
                        }
                }
        }
+       free(message);
+       free(cbuf);
        free(buf);
 }
 
-void W3_POP3_Set_Username(struct W3* w3, const char* username){
-       __W3_Add_Prop(w3, "POP3_USERNAME", username);
-}
+void W3_POP3_Set_Username(struct W3* w3, const char* username) { __W3_Add_Prop(w3, "POP3_USERNAME", username); }
 
+void W3_POP3_Set_Password(struct W3* w3, const char* password) { __W3_Add_Prop(w3, "POP3_PASSWORD", password); }
 
-void W3_POP3_Set_Password(struct W3* w3, const char* password){
-       __W3_Add_Prop(w3, "POP3_PASSWORD", password);
-}
+void W3_POP3_Send_Request(struct W3* w3) {}
index 59ecea876b5c79f3f8340278ad8e7097e5a93651..9c461a40d336113d8d251d96eb7c7db8e67da929 100644 (file)
@@ -119,15 +119,13 @@ bool __W3_Have_Prop(struct W3* w3, const char* name) {
        return false;
 }
 
-
-char* __W3_Get_Prop(struct W3* w3, const char* name){
+char* __W3_Get_Prop(struct W3* w3, const char* name) {
        if(w3->props == NULL) return NULL;
        int i;
        for(i = 0; w3->props[i] != NULL; i += 2) {
                if(strcmp(w3->props[i], name) == 0) return w3->props[i + 1];
        }
        return NULL;
-
 }
 
 void __W3_Add_Prop(struct W3* w3, const char* name, const char* value) {
index 1682123e383467471889a22b6205eb11cb9bb898..464d524f0a4e04f945693c044f446b9dfd408033 100644 (file)
@@ -11,6 +11,7 @@ extern "C" {
 void __W3_POP3_Request(struct W3* w3);
 void W3_POP3_Set_Username(struct W3* w3, const char* username);
 void W3_POP3_Set_Password(struct W3* w3, const char* password);
+void W3_POP3_Send_Request(struct W3* w3);
 
 #ifdef __cplusplus
 }