From dc003af096388098867a0da65381866c084e4ef4 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 4 Nov 2013 21:40:13 +0000 Subject: [PATCH] liza 0.9c git-svn-id: svn://kolibrios.org@4164 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/liza/letter_attr.c | 61 ++++++++++++++++ programs/cmm/liza/liza.c | 10 ++- programs/cmm/liza/login.c | 119 ++++++++++++++------------------ programs/cmm/liza/mail_box.c | 100 ++++++--------------------- programs/cmm/liza/settings.c | 2 +- 5 files changed, 142 insertions(+), 150 deletions(-) create mode 100644 programs/cmm/liza/letter_attr.c diff --git a/programs/cmm/liza/letter_attr.c b/programs/cmm/liza/letter_attr.c new file mode 100644 index 0000000000..b699430ab6 --- /dev/null +++ b/programs/cmm/liza/letter_attr.c @@ -0,0 +1,61 @@ +char from[256]; +char to[256]; +char date[256]; +char subj[256]; +dword mdata; + +struct letter_attr +{ + char adress[sizeof(to)]; + char subject[sizeof(subj)]; + byte direction; + int size; + void CreateArray(); + void SetSizes(); + void SetAtrFromCurr(int N); + int GetSize(int N); + char GetDirection(int N); + dword GetSubject(int N); + dword GetAdress(int N); +}; +letter_attr atr; +dword mails_db; + +void letter_attr::CreateArray() +{ + free(mails_db); + mails_db = malloc( mail_list.count * sizeof(atr) ); +} + +void letter_attr::SetSizes() +{ + int i; + for (i=1; i < mail_list.count; i++) + { + ESDWORD[sizeof(atr)*i+#mails_db+#atr.size-#atr] = GetLetterSize_(i); + ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr] = ' '; + ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr+1] = '\0'; + } +} + +void letter_attr::SetAtrFromCurr(int N) +{ + byte mail_direction=0; + if (strstri(#to, #email_text)) + { + mail_direction = 1; + strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #from); + } + if (strstri(#from, #email_text)) + { + mail_direction = 2; + strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #to); + } + ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr] = mail_direction; + strcpy(sizeof(atr)*N+#mails_db+#atr.subject-#atr, #subj); +} + +int letter_attr::GetSize(int N) { return ESDWORD[sizeof(atr)*N+#mails_db+#atr.size-#atr]; } +char letter_attr::GetDirection(int N) { return ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr]; } +dword letter_attr::GetSubject(int N) { return sizeof(atr)*N+#mails_db+#atr.subject-#atr; } +dword letter_attr::GetAdress(int N) { return sizeof(atr)*N+#mails_db+#atr.adress-#atr; } \ No newline at end of file diff --git a/programs/cmm/liza/liza.c b/programs/cmm/liza/liza.c index 33b2214f03..9a83aab709 100644 --- a/programs/cmm/liza/liza.c +++ b/programs/cmm/liza/liza.c @@ -37,8 +37,7 @@ enum { SEND_NSTAT, GET_ANSWER_NSTAT, SEND_RETR, - GET_ANSWER_RETR, - FAILED + GET_ANSWER_RETR }; //WindowDefinitions @@ -75,8 +74,12 @@ int ticks; char immbuffer[BUFFERSIZE]; +llist mail_list; +llist letter_view; + #include "settings.c" #include "login.c" +#include "letter_attr.c" #include "mail_box.c" #include "parselist.c" @@ -114,7 +117,8 @@ void OpenMailDat() ReadFile(0, 512, #read_data, "/sys/network/mail.dat"); if (!read_data) { - strcpy(#email_text, "example@mail.com"); + strcpy(#email_text, "testliza@ya.ru"); //temporarily, for testing + strcpy(#pass_text, "kolibri"); } else { diff --git a/programs/cmm/liza/login.c b/programs/cmm/liza/login.c index e3d7ffac18..655ecfab79 100644 --- a/programs/cmm/liza/login.c +++ b/programs/cmm/liza/login.c @@ -12,13 +12,19 @@ unsigned char pass_text[32]; edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10}; edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1}; +void StopConnect(dword message) +{ + if (message) notify(message); + aim = STOP; +} + void LoginBoxLoop() { int key, id; char socket_char; - SetLoginStatus(NULL,NULL); + SetLoginStatus(NULL); goto _LB_DRAW; loop() @@ -27,7 +33,7 @@ void LoginBoxLoop() switch(EAX & 0xFF) { case evMouse: - IF (GetProcessSlot(Form.ID)-GetActiveProcess()!=0) break; + if (!CheckActiveProcess(Form.ID)) break; edit_box_mouse stdcall (#login_box); edit_box_mouse stdcall (#pass_box); break; @@ -35,12 +41,11 @@ void LoginBoxLoop() case evButton: id = GetButtonID(); if (id==1) SaveAndExit(); - if (id==11) OptionsLoop(); + if (id==11) SettingsDialog(); if (id==12) { if (!aim) aim=RESOLVE; else aim=NULL; GetSettings(); - SetLoginStatus(NULL, NULL); DrawLoginScreen(); } break; @@ -57,12 +62,10 @@ void LoginBoxLoop() edit_box_draw stdcall(#pass_box); break; } - if (key==13) + if (key==13) && (!aim) { - if (aim) break; aim=RESOLVE; GetSettings(); - SetLoginStatus(NULL, NULL); DrawLoginScreen(); } EAX=key<<8; @@ -76,128 +79,110 @@ void LoginBoxLoop() break; default: - if (!aim) { SetLoginStatus(NULL, NULL); break; } - if (!email_text) { notify("Enter email!"); aim=NULL; } - if (!pass_text) { notify("Enter password!"); aim=NULL; } - if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; } + if (!aim) break; + if (!email_text) StopConnect("Enter email!"); + if (!pass_text) StopConnect("Enter password!"); + if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com"); if (aim == RESOLVE) { - SetLoginStatus(1, "Resolving server address..."); - sockaddr.sin_family = AF_INET4; AX = POP_server_port; $xchg al, ah sockaddr.sin_port = AX; sockaddr.sin_addr = GetIPfromAdress(#POP_server_path); - if (!sockaddr.sin_addr) { SetLoginStatus(12, "Can't obtain server IP."); aim = FAILED; break;} - - aim = OPEN_CONNECTION; + if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;} + aim = OPEN_CONNECTION; + break; } if (aim == OPEN_CONNECTION) { - SetLoginStatus(1, "Connecting to server..."); - socketnum = Socket(AF_INET4, SOCK_STREAM, 0); - if (socketnum == 0xffffffff) { SetLoginStatus(13, "Cannot open socket."); aim = FAILED; break;} + if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;} Connect(socketnum, #sockaddr, 16); - SetLoginStatus(55, "Connection established. Waiting for answer..."); - aim = GET_ANSWER_CONNECT; + aim = GET_ANSWER_CONNECT; + break; } if (aim == GET_ANSWER_CONNECT) { ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); - if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(61, "Connection failed"); aim = FAILED; break;} + if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;} immbuffer[ticks]='\0'; if (immbuffer[ticks-2]=='\n') { - debug(#immbuffer); if (strstr(#immbuffer,"+OK")) - { - SetLoginStatus(60, "Verifying username..."); aim = SEND_USER; - } else - { - //aim=NULL; //may don't need retry? - SetLoginStatus(55, "Failed to connect to server. Retry..."); - } - } - else - { - SetLoginStatus(103, "Connection failed"); + StopConnect("Failed to connect to server. Retry..."); } } if (aim == SEND_USER) { request_len = GetRequest("USER", #login); - Send(socketnum, #request, request_len, 0); - if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;} - SetLoginStatus(70, "Login verifying..."); - debug("Send USER, awaiting answer..."); + if (Send(socketnum, #request, request_len, 0) == 0xffffffff) + { + SetLoginStatus("Failed to send USER. Retry..."); + break; + } aim = GET_ANSWER_USER; } if (aim == GET_ANSWER_USER) { ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); - if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus(81, "Connection failed"); break;} + if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;} immbuffer[ticks]='\0'; if (immbuffer[ticks-2]=='\n') { - debug("GOT::"); - debug(#immbuffer); if (strstr(#immbuffer,"+OK")) - { aim = SEND_PASS; SetLoginStatus(80, "Verifying password...");} + aim = SEND_PASS; else - { notify("Wrong username"); aim=NULL;} + { + debug(#immbuffer); + StopConnect("Wrong username"); + } } else { - SetLoginStatus(103, "Connection failed"); + StopConnect("Connection failed"); } } if (aim == SEND_PASS) { - debug("\n Send PASS, awaiting answer..."); request_len = GetRequest("PASS", #pass_text); - Send(socketnum, #request, request_len, 0); - if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;} + if (Send(socketnum, #request, request_len, 0) == 0xffffffff) + { + SetLoginStatus("Failed to send PASS. Retry..."); + break; + } aim = GET_ANSWER_PASS; } if (aim == GET_ANSWER_PASS) { ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); - if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(101, "Server disconnected"); break;} + if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;} immbuffer[ticks]='\0'; if (immbuffer[ticks-2]=='\n') { - debug("GOT::"); - debug(#immbuffer); - if (strstr(#immbuffer,"+OK")) - { - SetLoginStatus(100, "Entering mailbox..."); - aim=SEND_NSTAT; - MailBoxLoop(); - } + if (strstr(#immbuffer,"+OK")) MailBoxLoop(); else { - notify("Wrong password"); - aim=NULL; + StopConnect("Wrong password or POP3 disabled"); + debug(#immbuffer); } } else { - SetLoginStatus(103, "Connection failed"); + StopConnect("Connection failed"); } } @@ -207,6 +192,7 @@ void LoginBoxLoop() } + void DrawLoginScreen() { panel_x = Form.cwidth - PANEL_W /2; @@ -237,7 +223,7 @@ void DrawLoginScreen() } else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop"); - SetLoginStatus(cur_st_percent, cur_st_text); + SetLoginStatus(cur_st_text); } @@ -271,24 +257,21 @@ void GetServerPathAndLogin() void GetSettings() { - GetServerPathAndLogin(); //get + GetServerPathAndLogin(); if (checked[CUSTOM]) { - if (!strcmp(#POP_server_path, "pop.gmail.com")) POP_server_port = 995; - else POP_server_port = DEFAULT_POP_PORT; + POP_server_port = DEFAULT_POP_PORT; } if (checked[MANUAL]) { strcpy(#POP_server_path, #POP_server1); POP_server_port = atoi(#POP_server_port1); } - debug(#POP_server_path); - debug(itoa(POP_server_port)); + if (!strcmp(#POP_server_path, "pop.gmail.com")) StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption"); } -void SetLoginStatus(dword percent1, text1) +void SetLoginStatus(dword text1) { - DrawProgressBar(10, Form.cheight-22, PANEL_W, 12, sc.work, sc.work_graph, 0x54B1D6, sc.work_text, percent1, text1); - cur_st_percent = percent1; + if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1); cur_st_text = text1; } \ No newline at end of file diff --git a/programs/cmm/liza/mail_box.c b/programs/cmm/liza/mail_box.c index 9ff15ac76c..48c68c74ab 100644 --- a/programs/cmm/liza/mail_box.c +++ b/programs/cmm/liza/mail_box.c @@ -3,33 +3,10 @@ #define LIST_INFO_H 59 int status_bar_h = 15; -llist mail_list; -llist letter_view; scroll_bar scroll1 = { 17,200,210, LIST_INFO_H-3,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll2 = { 17,200,210, LIST_INFO_H,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; -char from[256]; -char to[256]; -char date[256]; -char subj[256]; -dword mdata; -struct letter_attr -{ - char adress[sizeof(to)]; - char subject[sizeof(subj)]; - byte direction; - int size; - void CreateArray(); - void SetSizes(); - void SetAtrFromCurr(int N); - int GetSize(int N); - char GetDirection(int N); - dword GetSubject(int N); - dword GetAdress(int N); -}; -letter_attr atr; -dword mails_db; char *listbuffer; char *listpointer; @@ -63,6 +40,7 @@ void MailBoxLoop() mail_list.ClearList(); SetMailBoxStatus( NULL , NULL); cur_charset = 0; + aim=SEND_NSTAT; goto _MB_DRAW; @@ -72,7 +50,7 @@ void MailBoxLoop() switch(EAX & 0xFF) { case evMouse: - IF (GetProcessSlot(Form.ID)-GetActiveProcess()!=0) break; + IF (!CheckActiveProcess(Form.ID)) break; m.get(); if (!m.lkm) panels_drag=0; @@ -110,6 +88,8 @@ void MailBoxLoop() { if (letter_view.MouseScroll(m.vert)) DrawLetter(); } + //if (!m.lkm) && (menu.ProcessMouse(mm.x, mm.y)) && + //if (!m.lkm) && if (menu.ProcessMouse(mm.x, mm.y)) DrawMenuList(); break; case evButton: @@ -182,7 +162,7 @@ void MailBoxLoop() default: if (aim == SEND_NSTAT) { - debug("Counting mail, awaiting answer..."); + SetLoginStatus("Counting mail, awaiting answer..."); request_len = GetRequest("STAT", NULL); Send(socketnum, #request, request_len, 0); if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;} @@ -196,7 +176,6 @@ void MailBoxLoop() if (immbuffer[ticks-2]=='\n') { - debug("GOT::"); debug(#immbuffer); if (strstr(#immbuffer,"+OK")) { @@ -211,8 +190,7 @@ void MailBoxLoop() } else { - notify("Sorry, can't recieve your mail"); - aim=NULL; //aim = SEND_NLIST; + StopConnect("Sorry, can't recieve your mail"); } } } @@ -252,37 +230,40 @@ void MailBoxLoop() DrawMailBox(); debug("Send RETR, awaiting answer..."); request_len = GetRequest("RETR", itoa(mail_list.current+1)); - Send(socketnum, #request, request_len, 0); - if (EAX == 0xffffffff) { notify("Error while trying to get letter from server"); aim=NULL; break;} - - free(mailbuffer); + if (Send(socketnum, #request, request_len, 0) == 0xffffffff) + { + StopConnect("Error while trying to get letter from server"); + break; + } letter_size = atr.GetSize(mail_list.current+1) + 1024; - mailbuffer = malloc(letter_size); - if (!mailbuffer) {debug("alloc error!"); aim=NULL; break;} + free(mailbuffer); + if (!mailbuffer = malloc(letter_size)) + { + debug("alloc error!"); + aim=NULL; + break; + } mailpointer = mailbuffer; aim = GET_ANSWER_RETR; - debugi(letter_size); } if (aim == GET_ANSWER_RETR) { + aim=NULL; + break; ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT); - debugi(ticks); if (ticks == 0xffffffff) break; - //debugi(EAX); mailpointer = mailpointer + ticks; - //*mailpointer='\0'; - //debug(mailbuffer); - if (!aim) continue; + if (!aim) break; if (letter_size + mailbuffer - mailpointer - 2 < 0) { debug("Resizing buffer"); letter_size += 4096; mailbuffer = realloc(mailbuffer, letter_size); - if (!mailbuffer) {debug("Realloc error!"); aim=NULL; break;} + if (!mailbuffer) { StopConnect("Realloc error!"); break;} } if (letter_size>9000) @@ -481,42 +462,5 @@ int GetLetterSize_(int number){ } -void letter_attr::CreateArray() -{ - free(mails_db); - mails_db = malloc( mail_list.count * sizeof(atr) ); -} -void letter_attr::SetSizes() -{ - int i; - for (i=1; i < mail_list.count; i++) - { - ESDWORD[sizeof(atr)*i+#mails_db+#atr.size-#atr] = GetLetterSize_(i); - ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr] = ' '; - ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr+1] = '\0'; - } -} - -void letter_attr::SetAtrFromCurr(int N) -{ - byte mail_direction=0; - if (strstri(#to, #email_text)) - { - mail_direction = 1; - strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #from); - } - if (strstri(#from, #email_text)) - { - mail_direction = 2; - strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #to); - } - ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr] = mail_direction; - strcpy(sizeof(atr)*N+#mails_db+#atr.subject-#atr, #subj); -} - -int letter_attr::GetSize(int N) { return ESDWORD[sizeof(atr)*N+#mails_db+#atr.size-#atr]; } -char letter_attr::GetDirection(int N) { return ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr]; } -dword letter_attr::GetSubject(int N) { return sizeof(atr)*N+#mails_db+#atr.subject-#atr; } -dword letter_attr::GetAdress(int N) { return sizeof(atr)*N+#mails_db+#atr.adress-#atr; } diff --git a/programs/cmm/liza/settings.c b/programs/cmm/liza/settings.c index 9058942a4e..20b0443995 100644 --- a/programs/cmm/liza/settings.c +++ b/programs/cmm/liza/settings.c @@ -18,7 +18,7 @@ edit_box SMTP_server_box = {210,190,140,0xffffff,0x94AECE,0xffc90E,0xfffff edit_box SMTP_server_port_box = {210,190,165,0xffffff,0x94AECE,0xffc90E,0xffffff,0,5,#SMTP_server_port1,#mouse_opt,0b1000000000000000}; -void OptionsLoop() +void SettingsDialog() { int key, id;