Subversion Repositories Kolibri OS

Rev

Rev 3413 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3413 Rev 4139
Line 36... Line 36...
36
				id = GetButtonID(); 
36
				id = GetButtonID(); 
37
				if (id==1) SaveAndExit();
37
				if (id==1) SaveAndExit();
38
				if (id==11)	OptionsLoop();
38
				if (id==11)	OptionsLoop();
39
				if (id==12)
39
				if (id==12)
40
				{
40
				{
41
					if (!aim) aim=GET_PORT; else aim=NULL;
41
					if (!aim) aim=RESOLVE; else aim=NULL;
42
					GetSettings();
42
					GetSettings();
43
					SetLoginStatus(NULL, NULL);
43
					SetLoginStatus(NULL, NULL);
44
					DrawLoginScreen();
44
					DrawLoginScreen();
45
				}
45
				}
46
				break;
46
				break;
Line 58... Line 58...
58
					break;				
58
					break;				
59
				}
59
				}
60
				if (key==13)
60
				if (key==13)
61
				{
61
				{
62
					if (aim) break;
62
					if (aim) break;
63
					aim=GET_PORT;
63
					aim=RESOLVE;
64
					GetSettings();
64
					GetSettings();
65
					SetLoginStatus(NULL, NULL);
65
					SetLoginStatus(NULL, NULL);
66
					DrawLoginScreen();
66
					DrawLoginScreen();
67
				}
67
				}
68
				EAX=key<<8;
68
				EAX=key<<8;
Line 79... Line 79...
79
				if (!aim) { SetLoginStatus(NULL, NULL); break; }
79
				if (!aim) { SetLoginStatus(NULL, NULL); break; }
80
				if (!email_text) { notify("Enter email!"); aim=NULL; }
80
				if (!email_text) { notify("Enter email!"); aim=NULL; }
81
				if (!pass_text) { notify("Enter password!"); aim=NULL; }
81
				if (!pass_text) { notify("Enter password!"); aim=NULL; }
82
				if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; }
82
				if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; }
Line 83... Line 83...
83
				
83
				
84
				if (aim == GET_PORT)
84
				if (aim == RESOLVE)
85
				{
-
 
86
					SetLoginStatus(5, "Search for free local port...");
-
 
87
					local_port = GetFreePort(1000);
-
 
88
					if (!local_port) { notify("Error: There is no free local ports"); aim=NULL; break;}
85
				{
89
					SetLoginStatus(12, "Obtain server IP...");
-
 
90
					aim = GET_SERVER_IP;
-
 
Line -... Line 86...
-
 
86
					SetLoginStatus(1, "Resolving server address...");	
91
				}
87
					
92
 
88
					sockaddr.sin_family = AF_INET4;
-
 
89
					AX = POP_server_port;
93
				if (aim == GET_SERVER_IP)
90
					$xchg	al, ah
94
				{
91
					sockaddr.sin_port = AX;
95
					POP_server_IP = GetIPfromAdress(#POP_server_path);
-
 
96
					if (!POP_server_IP) { SetLoginStatus(12, "Can't obtain server IP. Retry..."); break; }
-
 
97
					SetLoginStatus(25, "Obtain to open socket..."w);
-
 
Line 98... Line -...
98
					aim = GET_SOCKET;
-
 
99
				}
-
 
100
 
-
 
101
				if (aim == GET_SOCKET)
-
 
102
				{
-
 
103
					socket = OpenSocket(local_port, POP_server_port, POP_server_IP, SOCKET_ACTIVE);
92
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
104
					if (socket == 0xffffffff) { SetLoginStatus(25, "Error obtaining socket. Retry..."); break;}
93
					if (!sockaddr.sin_addr) { SetLoginStatus(12, "Can't obtain server IP."); aim = FAILED; break;}
Line 105... Line 94...
105
					SetLoginStatus(40, "Establish a connection...");
94
 
106
					aim = CONNECT;
95
					aim = OPEN_CONNECTION;	
107
				}
96
				}
-
 
97
				
108
 
98
				if (aim == OPEN_CONNECTION)
109
				if (aim == CONNECT)
99
				{
110
				{
100
					SetLoginStatus(1, "Connecting to server...");	
111
					connection_status=StatusSocket(socket);
101
					
112
					if (connection_status==0) {notify("Connection to server isn't possible"); aim=NULL; break; };
-
 
113
					if (connection_status==7) {SetLoginStatus(40, "Server disconnected. Retry..."); break; };
102
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
114
					if (connection_status!=4) break; //0-connection isn't possible, 2-connecting, 4-connected, 7-server disconnected
103
					if (socketnum == 0xffffffff) { SetLoginStatus(13, "Cannot open socket."); aim = FAILED; break;}
Line -... Line 104...
-
 
104
					Connect(socketnum, #sockaddr, 16);
115
					SetLoginStatus(55, "Connection established. Reading answer...");
105
					SetLoginStatus(55, "Connection established. Waiting for answer...");
116
					immfree();
106
					aim = GET_ANSWER_CONNECT;	
117
					aim = GET_ANSWER_CONNECT;
107
				}
118
				}
108
 
119
				
109
		
Line 120... Line 110...
120
				if (aim == GET_ANSWER_CONNECT)
110
				if (aim == GET_ANSWER_CONNECT)
121
				{
111
				{
122
					if (!PollSocket(socket)) break;
112
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
123
					socket_char=ReadSocket(socket);
113
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(61, "Connection failed"); aim = FAILED; break;}
124
					immputc(socket_char);
114
					immbuffer[ticks]='\0';					
125
					
115
					
126
					if (socket_char=='\n')
116
					if (immbuffer[ticks-2]=='\n')
127
					{
-
 
128
						debug(#immbuffer);
117
					{
129
						if (strstr(#immbuffer,"+OK"))
118
						debug(#immbuffer);
130
						{
119
						if (strstr(#immbuffer,"+OK"))
131
							SetLoginStatus(60, "Verifying username...");
-
 
132
							aim = SEND_USER;
120
						{
133
							immfree();
121
							SetLoginStatus(60, "Verifying username...");
134
						}
122
							aim = SEND_USER;
135
						else
123
						}
-
 
124
						else
-
 
125
						{
-
 
126
							//aim=NULL; //may don't need retry?
-
 
127
							SetLoginStatus(55, "Failed to connect to server. Retry...");
136
						{
128
						}
Line 137... Line 129...
137
							immfree(); 
129
					}
138
							//aim=NULL; //may don't need retry?
130
					else
139
							SetLoginStatus(55, "Failed to connect to server. Retry...");
131
					{
140
						}
132
						SetLoginStatus(103, "Connection failed"); 
141
					}
133
					}
142
				}
134
				}
143
 
135
 
144
				if (aim == SEND_USER)
136
				if (aim == SEND_USER)
145
				{
137
				{
Line 146... Line 138...
146
					request_len = GetRequest("USER", #login);
138
					request_len = GetRequest("USER", #login);
147
					WriteSocket(socket,request_len,#request);
139
					Send(socketnum, #request, request_len, 0);
148
					if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;}
140
					if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;}
149
					SetLoginStatus(70, "Login verifying...");
141
					SetLoginStatus(70, "Login verifying...");
150
					debug("Send USER, awaiting answer...");
142
					debug("Send USER, awaiting answer...");
Line 151... Line 143...
151
					aim = GET_ANSWER_USER;
143
					aim = GET_ANSWER_USER;
152
				}
144
				}
153
 
145
 
154
				if (aim == GET_ANSWER_USER)
146
				if (aim == GET_ANSWER_USER)
155
				{
147
				{
156
					if (!PollSocket(socket)) break;
148
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
149
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus(81, "Connection failed"); break;}
-
 
150
					immbuffer[ticks]='\0';						
-
 
151
					
157
					socket_char=ReadSocket(socket);
152
					if (immbuffer[ticks-2]=='\n') 
-
 
153
					{
158
					immputc(socket_char);
154
						debug("GOT::");
159
					
155
						debug(#immbuffer);
160
					if (socket_char=='\n') 
156
						if (strstr(#immbuffer,"+OK"))
Line 161... Line 157...
161
					{
157
							{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password...");}
162
						debug("GOT::");
158
						else
163
						debug(#immbuffer);
159
							{ notify("Wrong username"); aim=NULL;}
164
						if (strstr(#immbuffer,"+OK"))
160
					}
165
							{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password..."); immfree(); }
161
					else
166
						else
162
					{
167
							{ notify("Wrong username"); immfree(); aim=NULL;}
163
						SetLoginStatus(103, "Connection failed"); 
168
					}
164
					}
Line 169... Line 165...
169
				}
165
				}
170
 
166
 
171
				if (aim == SEND_PASS)
167
				if (aim == SEND_PASS)
172
				{		
168
				{		
173
					debug("\n Send PASS, awaiting answer...");			
169
					debug("\n Send PASS, awaiting answer...");			
Line 174... Line 170...
174
					request_len = GetRequest("PASS", #pass_text);
170
					request_len = GetRequest("PASS", #pass_text);
175
					WriteSocket(socket,request_len,#request);
171
					Send(socketnum, #request, request_len, 0);
176
					if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;}
172
					if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;}
177
					aim = GET_ANSWER_PASS;
173
					aim = GET_ANSWER_PASS;
178
				}
174
				}
179
 
175
 
180
				if (aim == GET_ANSWER_PASS)
176
				if (aim == GET_ANSWER_PASS)
181
				{	
177
				{	
182
					if (!PollSocket(socket)) break;
-
 
183
					socket_char=ReadSocket(socket);
178
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
184
					immputc(socket_char);
179
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(101, "Server disconnected"); break;}
185
					
180
					immbuffer[ticks]='\0';						
186
					if (socket_char=='\n')
181
					
187
					{
182
					if (immbuffer[ticks-2]=='\n')
188
						debug("GOT::");
183
					{
189
						debug(#immbuffer);
-
 
190
						if (strstr(#immbuffer,"+OK"))
184
						debug("GOT::");
191
						{
185
						debug(#immbuffer);
-
 
186
						if (strstr(#immbuffer,"+OK"))
-
 
187
						{
-
 
188
							SetLoginStatus(100, "Entering mailbox...");
-
 
189
							aim=SEND_NSTAT;
Line 192... Line 190...
192
							SetLoginStatus(100, "Entering mailbox...");
190
							MailBoxLoop();
Line 193... Line 191...
193
							aim=SEND_NSTAT;
191
						}
194
							immfree();
192
						else