Subversion Repositories Kolibri OS

Rev

Rev 6278 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6278 Rev 6641
1
//Leency & SoUrcerer, LGPL
1
//Leency & SoUrcerer, LGPL
2
 
2
 
3
//LoginPanel
3
//LoginPanel
4
#define PANEL_W 220
4
#define PANEL_W 220
5
#define PANEL_H 140
5
#define PANEL_H 140
6
int panel_x, panel_y;
6
int panel_x, panel_y;
7
 
7
 
8
//edit_boxes at LoginPanel 
8
//edit_boxes at LoginPanel 
9
int	mouse_dd;
9
int	mouse_dd;
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};
14
 
14
 
15
 
15
 
16
void LoginNetworkProcess()
16
void LoginNetworkProcess()
17
{
17
{
18
	if (aim) switch(aim)
18
	if (aim) switch(aim)
19
	{
19
	{
20
		case RESOLVE:
20
		case RESOLVE:
21
					if (!email_text) StopConnect("Enter email!");
21
					if (!email_text) StopConnect("Enter email!");
22
					if (!pass_text) StopConnect("Enter password!");
22
					if (!pass_text) StopConnect("Enter password!");
23
					if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
23
					if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
24
					if (!aim) return;
24
					if (!aim) return;
25
 
25
 
26
					sockaddr.sin_family = AF_INET4;
26
					sockaddr.sin_family = AF_INET4;
27
					AX = POP_server_port;
27
					AX = POP_server_port;
28
					$xchg	al, ah
28
					$xchg	al, ah
29
					sockaddr.sin_port = AX;
29
					sockaddr.sin_port = AX;
30
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
30
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
31
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
31
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
32
					else aim = OPEN_CONNECTION;
32
					else aim = OPEN_CONNECTION;
33
					break;
33
					break;
34
		case OPEN_CONNECTION:
34
		case OPEN_CONNECTION:
35
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
35
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
36
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
36
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
37
					Connect(socketnum, #sockaddr, 16);
37
					Connect(socketnum, #sockaddr, 16);
38
					aim = GET_ANSWER_CONNECT;
38
					aim = GET_ANSWER_CONNECT;
39
					break;
39
					break;
40
		case GET_ANSWER_CONNECT:
40
		case GET_ANSWER_CONNECT:
41
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
41
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
42
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
42
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
43
					immbuffer[ticks]='\0';					
43
					immbuffer[ticks]='\0';					
44
					if (immbuffer[ticks-2]=='\n')
44
					if (immbuffer[ticks-2]=='\n')
45
					{
45
					{
46
						if (strstr(#immbuffer,"+OK"))
46
						if (strstr(#immbuffer,"+OK"))
47
							aim = SEND_USER;
47
							aim = SEND_USER;
48
						else
48
						else
49
							StopConnect("Failed to connect to server. Retry...");
49
							StopConnect("Failed to connect to server. Retry...");
50
					}
50
					}
51
					break;
51
					break;
52
		case SEND_USER:
52
		case SEND_USER:
53
					request_len = GetRequest("USER", #login);
53
					request_len = GetRequest("USER", #login);
54
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
54
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
55
					{
55
					{
56
						SetLoginStatus("Failed to send USER. Retry...");
56
						SetLoginStatus("Failed to send USER. Retry...");
57
						break;
57
						break;
58
					}
58
					}
59
					else aim = GET_ANSWER_USER;
59
					else aim = GET_ANSWER_USER;
60
					break;
60
					break;
61
		case GET_ANSWER_USER:
61
		case GET_ANSWER_USER:
62
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
62
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
63
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
63
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
64
					immbuffer[ticks]='\0';						
64
					immbuffer[ticks]='\0';						
65
					if (immbuffer[ticks-2]=='\n') 
65
					if (immbuffer[ticks-2]=='\n') 
66
					{
66
					{
67
						if (strstr(#immbuffer,"+OK"))
67
						if (strstr(#immbuffer,"+OK"))
68
							aim = SEND_PASS;
68
							aim = SEND_PASS;
69
						else
69
						else
70
						{
70
						{
71
							debug(#immbuffer);
71
							debug(#immbuffer);
72
							StopConnect("Wrong username");
72
							StopConnect("Wrong username");
73
						}
73
						}
74
					}
74
					}
75
					else
75
					else
76
					{
76
					{
77
						StopConnect("Connection failed"); 
77
						StopConnect("Connection failed"); 
78
					}
78
					}
79
					break;
79
					break;
80
		case SEND_PASS:
80
		case SEND_PASS:
81
					request_len = GetRequest("PASS", #pass_text);
81
					request_len = GetRequest("PASS", #pass_text);
82
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
82
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
83
					{
83
					{
84
						SetLoginStatus("Failed to send PASS. Retry...");
84
						SetLoginStatus("Failed to send PASS. Retry...");
85
						break;
85
						break;
86
					}
86
					}
87
					else aim = GET_ANSWER_PASS;
87
					else aim = GET_ANSWER_PASS;
88
					break;
88
					break;
89
		case GET_ANSWER_PASS:
89
		case GET_ANSWER_PASS:
90
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
90
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
91
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
91
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
92
					immbuffer[ticks]='\0';						
92
					immbuffer[ticks]='\0';						
93
					
93
					
94
					if (immbuffer[ticks-2]=='\n')
94
					if (immbuffer[ticks-2]=='\n')
95
					{
95
					{
96
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
96
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
97
						else
97
						else
98
						{
98
						{
99
							StopConnect("Wrong password or POP3 disabled");
99
							StopConnect("Wrong password or POP3 disabled");
100
							debug(#immbuffer);
100
							debug(#immbuffer);
101
						}
101
						}
102
					}
102
					}
103
					else
103
					else
104
					{
104
					{
105
						StopConnect("Connection failed"); 
105
						StopConnect("Connection failed"); 
106
					}
106
					}
107
	}
107
	}
108
}
108
}
109
 
109
 
110
 
110
 
111
void LoginBoxLoop()
111
void LoginBoxLoop()
112
{
112
{
113
	int id;
113
	int id;
114
 
114
 
115
	SetLoginStatus(NULL);
115
	SetLoginStatus(NULL);
116
	goto _LB_DRAW;
116
	goto _LB_DRAW;
117
	loop()
117
	loop()
118
	{
118
	{
119
		WaitEventTimeout(2);
119
		WaitEventTimeout(2);
120
		switch(EAX & 0xFF)
120
		switch(EAX & 0xFF)
121
		{
121
		{
122
			case evMouse:
122
			case evMouse:
123
				if (!CheckActiveProcess(Form.ID)) break;
123
				if (!CheckActiveProcess(Form.ID)) break;
124
				edit_box_mouse stdcall (#login_box);
124
				edit_box_mouse stdcall (#login_box);
125
				edit_box_mouse stdcall (#pass_box);
125
				edit_box_mouse stdcall (#pass_box);
126
				break;
126
				break;
127
				
127
				
128
			case evButton:
128
			case evButton:
129
				id = GetButtonID(); 
129
				id = GetButtonID(); 
130
				if (id==1) SaveAndExit();
130
				if (id==1) SaveAndExit();
131
				if (id==11)	SettingsDialog();
131
				if (id==11)	SettingsDialog();
132
				if (id==12)
132
				if (id==12)
133
				{
133
				{
134
					if (!aim) aim=RESOLVE; else aim=NULL;
134
					if (!aim) aim=RESOLVE; else aim=NULL;
135
					GetSettings();
135
					GetSettings();
136
					DrawLoginScreen();
136
					DrawLoginScreen();
137
				}
137
				}
138
				break;
138
				break;
139
				
139
				
140
			case evKey:
140
			case evKey:
141
				GetKeys();
141
				GetKeys();
142
				if (key_scancode==SCAN_CODE_TAB)
142
				if (key_scancode==SCAN_CODE_TAB)
143
				{
143
				{
144
					if (login_box.flags & 0b10)
144
					if (login_box.flags & 0b10)
145
						{ pass_box.flags = 0b11; login_box.flags = 0; }
145
						{ pass_box.flags = 0b11; login_box.flags = 0; }
146
					else
146
					else
147
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
147
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
148
					edit_box_draw stdcall(#login_box);
148
					edit_box_draw stdcall(#login_box);
149
					edit_box_draw stdcall(#pass_box);
149
					edit_box_draw stdcall(#pass_box);
150
					break;				
150
					break;				
151
				}
151
				}
152
				if (key_scancode==SCAN_CODE_ENTER) && (!aim)
152
				if (key_scancode==SCAN_CODE_ENTER) && (!aim)
153
				{
153
				{
154
					aim=RESOLVE;
154
					aim=RESOLVE;
155
					GetSettings();
155
					GetSettings();
156
					DrawLoginScreen();
156
					DrawLoginScreen();
157
				}
157
				}
158
				EAX=key_ascii<<8;
158
				EAX = key_editbox;
159
				edit_box_key stdcall(#login_box);
159
				edit_box_key stdcall(#login_box);
160
				edit_box_key stdcall(#pass_box);
160
				edit_box_key stdcall(#pass_box);
161
				break;
161
				break;
162
				
162
				
163
			case evReDraw: _LB_DRAW:
163
			case evReDraw: _LB_DRAW:
164
				if !(DefineWindow(LOGIN_HEADER)) break;
164
				if !(DefineWindow(LOGIN_HEADER)) break;
165
				DrawLoginScreen();
165
				DrawLoginScreen();
166
				break;
166
				break;
167
 
167
 
168
			default:
168
			default:
169
				LoginNetworkProcess();				
169
				LoginNetworkProcess();				
170
		}
170
		}
171
	}
171
	}
172
}
172
}
173
 
173
 
174
 
174
 
175
 
175
 
176
void DrawLoginScreen()
176
void DrawLoginScreen()
177
{				
177
{				
178
	panel_x = Form.cwidth - PANEL_W /2;
178
	panel_x = Form.cwidth - PANEL_W /2;
179
	panel_y = Form.cheight - PANEL_H /2 - 5;
179
	panel_y = Form.cheight - PANEL_H /2 - 5;
180
 
180
 
181
	DrawBar(0,0, Form.cwidth, Form.cheight, system.color.work);
181
	DrawBar(0,0, Form.cwidth, Form.cheight, system.color.work);
182
	
182
	
183
	WriteText(panel_x,panel_y,0x80,system.color.work_text,"Your Email:");
183
	WriteText(panel_x,panel_y,0x80,system.color.work_text,"Your Email:");
184
	login_box.left = panel_x+3;
184
	login_box.left = panel_x+3;
185
	login_box.top = panel_y+15;
185
	login_box.top = panel_y+15;
186
	DrawEditBox(#login_box);
186
	DrawEditBox(#login_box);
187
	
187
	
188
	WriteText(panel_x,panel_y+40,0x80,system.color.work_text,"Password:");
188
	WriteText(panel_x,panel_y+40,0x80,system.color.work_text,"Password:");
189
	pass_box.left = panel_x+3;
189
	pass_box.left = panel_x+3;
190
	pass_box.top = panel_y+55;
190
	pass_box.top = panel_y+55;
191
	DrawEditBox(#pass_box);
191
	DrawEditBox(#pass_box);
192
	
192
	
193
	if (!aim)
193
	if (!aim)
194
	{
194
	{
195
		DrawCaptButton(panel_x,panel_y+90,100,22,11,system.color.work_button, system.color.work_button_text,"Settings");
195
		DrawCaptButton(panel_x,panel_y+90,100,22,11,system.color.work_button, system.color.work_button_text,"Settings");
196
		DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Enter >");
196
		DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Enter >");
197
	} 
197
	} 
198
	else DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Stop");
198
	else DrawCaptButton(panel_x+120,panel_y+90,100,22,12,system.color.work_button, system.color.work_button_text,"Stop");
199
	
199
	
200
	SetLoginStatus(cur_st_text);
200
	SetLoginStatus(cur_st_text);
201
}
201
}
202
 
202
 
203
 
203
 
204
void GetSettings()
204
void GetSettings()
205
{
205
{
206
	strcpy(#login, #email_text);
206
	strcpy(#login, #email_text);
207
	ESBYTE[strchr(#login,'@')] = NULL;
207
	ESBYTE[strchr(#login,'@')] = NULL;
208
	
208
	
209
	if (checked[CUSTOM])
209
	if (checked[CUSTOM])
210
	{
210
	{
211
		strcpy(#POP_server_path, "pop.");
211
		strcpy(#POP_server_path, "pop.");
212
		strcat(#POP_server_path, strchr(#email_text,'@')+1);
212
		strcat(#POP_server_path, strchr(#email_text,'@')+1);
213
		POP_server_port = DEFAULT_POP_PORT;
213
		POP_server_port = DEFAULT_POP_PORT;
214
	}
214
	}
215
	if (checked[MANUAL])
215
	if (checked[MANUAL])
216
	{
216
	{
217
		strcpy(#POP_server_path, #POP_server1);
217
		strcpy(#POP_server_path, #POP_server1);
218
		POP_server_port = atoi(#POP_server_port1);
218
		POP_server_port = atoi(#POP_server_port1);
219
	}
219
	}
220
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
220
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
221
}
221
}
222
 
222
 
223
void SetLoginStatus(dword text1)
223
void SetLoginStatus(dword text1)
224
{
224
{
225
	if (text1) WriteText(10, Form.cheight-22, 0x80, system.color.work_text, text1);
225
	if (text1) WriteText(10, Form.cheight-22, 0x80, system.color.work_text, text1);
226
	cur_st_text = text1;
226
	cur_st_text = text1;
227
}
227
}
228
>
-
 
229
>
-