Subversion Repositories Kolibri OS

Rev

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

Rev 4153 Rev 4164
Line 10... Line 10...
10
unsigned char email_text[128];
10
unsigned char email_text[128];
11
unsigned char pass_text[32];
11
unsigned char pass_text[32];
12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
Line -... Line 14...
-
 
14
 
-
 
15
void StopConnect(dword message)
-
 
16
{
-
 
17
	if (message) notify(message);
-
 
18
	aim = STOP;
-
 
19
}
Line 14... Line 20...
14
 
20
 
15
 
21
 
16
void LoginBoxLoop()
22
void LoginBoxLoop()
17
{
23
{
Line 18... Line 24...
18
	int key, id;
24
	int key, id;
Line 19... Line 25...
19
	char socket_char;
25
	char socket_char;
20
 
26
 
21
	SetLoginStatus(NULL,NULL);
27
	SetLoginStatus(NULL);
22
 
28
 
23
	goto _LB_DRAW;
29
	goto _LB_DRAW;
24
	loop()
30
	loop()
25
	{
31
	{
26
		WaitEventTimeout(2);
32
		WaitEventTimeout(2);
27
		switch(EAX & 0xFF)
33
		switch(EAX & 0xFF)
28
		{
34
		{
29
			case evMouse:
35
			case evMouse:
Line 30... Line 36...
30
				IF (GetProcessSlot(Form.ID)-GetActiveProcess()!=0) break;
36
				if (!CheckActiveProcess(Form.ID)) break;
31
				edit_box_mouse stdcall (#login_box);
37
				edit_box_mouse stdcall (#login_box);
32
				edit_box_mouse stdcall (#pass_box);
38
				edit_box_mouse stdcall (#pass_box);
33
				break;
39
				break;
34
				
40
				
35
			case evButton:
41
			case evButton:
36
				id = GetButtonID(); 
42
				id = GetButtonID(); 
37
				if (id==1) SaveAndExit();
43
				if (id==1) SaveAndExit();
38
				if (id==11)	OptionsLoop();
-
 
39
				if (id==12)
44
				if (id==11)	SettingsDialog();
40
				{
45
				if (id==12)
41
					if (!aim) aim=RESOLVE; else aim=NULL;
46
				{
Line 42... Line 47...
42
					GetSettings();
47
					if (!aim) aim=RESOLVE; else aim=NULL;
Line 55... Line 60...
55
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
60
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
56
					edit_box_draw stdcall(#login_box);
61
					edit_box_draw stdcall(#login_box);
57
					edit_box_draw stdcall(#pass_box);
62
					edit_box_draw stdcall(#pass_box);
58
					break;				
63
					break;				
59
				}
64
				}
60
				if (key==13)
65
				if (key==13) && (!aim)
61
				{
66
				{
62
					if (aim) break;
-
 
63
					aim=RESOLVE;
67
					aim=RESOLVE;
64
					GetSettings();
68
					GetSettings();
65
					SetLoginStatus(NULL, NULL);
-
 
66
					DrawLoginScreen();
69
					DrawLoginScreen();
67
				}
70
				}
68
				EAX=key<<8;
71
				EAX=key<<8;
69
				edit_box_key stdcall(#login_box);
72
				edit_box_key stdcall(#login_box);
70
				edit_box_key stdcall(#pass_box);
73
				edit_box_key stdcall(#pass_box);
Line 74... Line 77...
74
				if !(DefineWindow(LOGIN_HEADER)) break;
77
				if !(DefineWindow(LOGIN_HEADER)) break;
75
				DrawLoginScreen();
78
				DrawLoginScreen();
76
				break;
79
				break;
Line 77... Line 80...
77
 
80
 
78
			default:
81
			default:
79
				if (!aim) { SetLoginStatus(NULL, NULL); break; }
82
				if (!aim) break;
80
				if (!email_text) { notify("Enter email!"); aim=NULL; }
83
				if (!email_text) StopConnect("Enter email!");
81
				if (!pass_text) { notify("Enter password!"); aim=NULL; }
84
				if (!pass_text) StopConnect("Enter password!");
Line 82... Line 85...
82
				if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; }
85
				if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
83
				
86
				
84
				if (aim == RESOLVE)
-
 
85
				{
-
 
86
					SetLoginStatus(1, "Resolving server address...");	
87
				if (aim == RESOLVE)
87
					
88
				{
88
					sockaddr.sin_family = AF_INET4;
89
					sockaddr.sin_family = AF_INET4;
89
					AX = POP_server_port;
90
					AX = POP_server_port;
90
					$xchg	al, ah
91
					$xchg	al, ah
91
					sockaddr.sin_port = AX;
92
					sockaddr.sin_port = AX;
92
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
-
 
93
					if (!sockaddr.sin_addr) { SetLoginStatus(12, "Can't obtain server IP."); aim = FAILED; break;}
93
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
-
 
94
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
94
 
95
					aim = OPEN_CONNECTION;
Line 95... Line 96...
95
					aim = OPEN_CONNECTION;	
96
					break;
96
				}
97
				}
97
				
-
 
98
				if (aim == OPEN_CONNECTION)
-
 
99
				{
98
				
100
					SetLoginStatus(1, "Connecting to server...");	
99
				if (aim == OPEN_CONNECTION)
101
					
100
				{
102
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
-
 
103
					if (socketnum == 0xffffffff) { SetLoginStatus(13, "Cannot open socket."); aim = FAILED; break;}
101
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
-
 
102
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
104
					Connect(socketnum, #sockaddr, 16);
103
					Connect(socketnum, #sockaddr, 16);
Line 105... Line 104...
105
					SetLoginStatus(55, "Connection established. Waiting for answer...");
104
					aim = GET_ANSWER_CONNECT;
106
					aim = GET_ANSWER_CONNECT;	
105
					break;
107
				}
106
				}
108
 
107
 
109
		
108
		
Line 110... Line 109...
110
				if (aim == GET_ANSWER_CONNECT)
109
				if (aim == GET_ANSWER_CONNECT)
111
				{
110
				{
112
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
113
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(61, "Connection failed"); aim = FAILED; break;}
111
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
114
					immbuffer[ticks]='\0';					
-
 
115
					
-
 
116
					if (immbuffer[ticks-2]=='\n')
112
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
117
					{
-
 
118
						debug(#immbuffer);
-
 
119
						if (strstr(#immbuffer,"+OK"))
-
 
120
						{
-
 
121
							SetLoginStatus(60, "Verifying username...");
-
 
122
							aim = SEND_USER;
-
 
123
						}
-
 
124
						else
113
					immbuffer[ticks]='\0';					
125
						{
-
 
126
							//aim=NULL; //may don't need retry?
114
					
127
							SetLoginStatus(55, "Failed to connect to server. Retry...");
115
					if (immbuffer[ticks-2]=='\n')
128
						}
116
					{
Line 129... Line 117...
129
					}
117
						if (strstr(#immbuffer,"+OK"))
130
					else
118
							aim = SEND_USER;
131
					{
119
						else
132
						SetLoginStatus(103, "Connection failed"); 
120
							StopConnect("Failed to connect to server. Retry...");
-
 
121
					}
133
					}
122
				}
134
				}
123
 
135
 
124
				if (aim == SEND_USER)
136
				if (aim == SEND_USER)
125
				{
137
				{
126
					request_len = GetRequest("USER", #login);
Line 138... Line 127...
138
					request_len = GetRequest("USER", #login);
127
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
139
					Send(socketnum, #request, request_len, 0);
128
					{
140
					if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;}
129
						SetLoginStatus("Failed to send USER. Retry...");
141
					SetLoginStatus(70, "Login verifying...");
130
						break;
142
					debug("Send USER, awaiting answer...");
131
					}
Line 143... Line 132...
143
					aim = GET_ANSWER_USER;
132
					aim = GET_ANSWER_USER;
144
				}
133
				}
145
 
-
 
146
				if (aim == GET_ANSWER_USER)
-
 
147
				{
134
 
148
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
135
				if (aim == GET_ANSWER_USER)
149
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus(81, "Connection failed"); break;}
136
				{
-
 
137
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
138
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
150
					immbuffer[ticks]='\0';						
139
					immbuffer[ticks]='\0';						
-
 
140
					
151
					
141
					if (immbuffer[ticks-2]=='\n') 
152
					if (immbuffer[ticks-2]=='\n') 
142
					{
153
					{
143
						if (strstr(#immbuffer,"+OK"))
154
						debug("GOT::");
144
							aim = SEND_PASS;
155
						debug(#immbuffer);
145
						else
156
						if (strstr(#immbuffer,"+OK"))
146
						{
Line 157... Line 147...
157
							{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password...");}
147
							debug(#immbuffer);
158
						else
148
							StopConnect("Wrong username");
159
							{ notify("Wrong username"); aim=NULL;}
-
 
160
					}
149
						}
161
					else
150
					}
-
 
151
					else
162
					{
152
					{
-
 
153
						StopConnect("Connection failed"); 
-
 
154
					}
163
						SetLoginStatus(103, "Connection failed"); 
155
				}
164
					}
156
 
Line 165... Line 157...
165
				}
157
				if (aim == SEND_PASS)
166
 
158
				{		
167
				if (aim == SEND_PASS)
159
					request_len = GetRequest("PASS", #pass_text);
168
				{		
160
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
169
					debug("\n Send PASS, awaiting answer...");			
161
					{
Line 170... Line 162...
170
					request_len = GetRequest("PASS", #pass_text);
162
						SetLoginStatus("Failed to send PASS. Retry...");
171
					Send(socketnum, #request, request_len, 0);
163
						break;
172
					if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;}
-
 
173
					aim = GET_ANSWER_PASS;
-
 
174
				}
164
					}
175
 
-
 
176
				if (aim == GET_ANSWER_PASS)
-
 
177
				{	
-
 
178
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
179
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(101, "Server disconnected"); break;}
-
 
180
					immbuffer[ticks]='\0';						
165
					aim = GET_ANSWER_PASS;
181
					
166
				}
182
					if (immbuffer[ticks-2]=='\n')
167
 
183
					{
168
				if (aim == GET_ANSWER_PASS)
184
						debug("GOT::");
169
				{	
185
						debug(#immbuffer);
170
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
186
						if (strstr(#immbuffer,"+OK"))
171
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
187
						{
172
					immbuffer[ticks]='\0';						
188
							SetLoginStatus(100, "Entering mailbox...");
173
					
189
							aim=SEND_NSTAT;
174
					if (immbuffer[ticks-2]=='\n')
Line 190... Line 175...
190
							MailBoxLoop();
175
					{
Line 191... Line 176...
191
						}
176
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
192
						else
177
						else
193
						{
178
						{
Line -... Line 179...
-
 
179
							StopConnect("Wrong password or POP3 disabled");
194
							notify("Wrong password");
180
							debug(#immbuffer);
195
							aim=NULL;
181
						}
196
						}
182
					}
197
					}
183
					else
Line 235... Line 221...
235
		DrawCaptButton(panel_x,panel_y+90,100,20,11,sc.work_button, sc.work_button_text,"Settings");
221
		DrawCaptButton(panel_x,panel_y+90,100,20,11,sc.work_button, sc.work_button_text,"Settings");
236
		DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Enter >");
222
		DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Enter >");
237
	} 
223
	} 
238
	else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop");
224
	else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop");
Line 239... Line 225...
239
	
225
	
240
	SetLoginStatus(cur_st_percent, cur_st_text);
226
	SetLoginStatus(cur_st_text);
Line 241... Line 227...
241
}
227
}
242
 
228
 
Line 269... Line 255...
269
}
255
}
Line 270... Line 256...
270
 
256
 
271
 
257
 
272
void GetSettings()
258
void GetSettings()
273
{
259
{
274
	GetServerPathAndLogin(); //get
260
	GetServerPathAndLogin();
275
	if (checked[CUSTOM])
-
 
276
	{
261
	if (checked[CUSTOM])
277
		if (!strcmp(#POP_server_path, "pop.gmail.com")) POP_server_port = 995;
262
	{
278
		else POP_server_port = DEFAULT_POP_PORT;
263
		POP_server_port = DEFAULT_POP_PORT;
279
	}
264
	}
280
	if (checked[MANUAL])
265
	if (checked[MANUAL])
281
	{
266
	{
282
		strcpy(#POP_server_path, #POP_server1);
267
		strcpy(#POP_server_path, #POP_server1);
283
		POP_server_port = atoi(#POP_server_port1);
-
 
284
	}
268
		POP_server_port = atoi(#POP_server_port1);
285
	debug(#POP_server_path);
269
	}
Line 286... Line 270...
286
	debug(itoa(POP_server_port));
270
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
287
}
271
}
288
 
272
 
289
void SetLoginStatus(dword percent1, text1)
-
 
290
{
273
void SetLoginStatus(dword text1)
291
	DrawProgressBar(10, Form.cheight-22, PANEL_W, 12, sc.work, sc.work_graph, 0x54B1D6, sc.work_text, percent1, text1);
274
{
292
	cur_st_percent = percent1;
275
	if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);