Liza 0.9e: now working somehow... Need muck work to clear code.

git-svn-id: svn://kolibrios.org@4166 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2013-11-04 23:27:39 +00:00
parent e45fb26043
commit 71a9f8e4cf
9 changed files with 153 additions and 222 deletions

View File

@ -108,20 +108,12 @@ inline fastcall void utf8rutodos( ESI)
CASE 0xA9: // (c) --- âûëåò Î_î
{
ESBYTE[EDI] = 'c';
//ESBYTE[EDI] = '(';
//ESBYTE[EDI+1] = 'c';
//ESBYTE[EDI+2] = ')';
//EDI+=2;
ESI++;
BREAK;
}
CASE 0xAE: // (r)
{
ESBYTE[EDI] = 'r';
//ESBYTE[EDI] = '(';
//ESBYTE[EDI+1] = 'r';
//ESBYTE[EDI+2] = ')';
//EDI+=2;
ESI++;
BREAK;
}
@ -162,7 +154,7 @@ inline fastcall void utf8rutodos( ESI)
FOR (;j<2;j++)
{
ch=ESBYTE[htmlcolor+j];
IF (ch==0x0d) || (ch=='\9') RETURN '';
IF (ch==0x0d) || (ch=='\9') RETURN 0;
IF ((ch>='0') && (ch<='9')) ch -= '0';
IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
@ -172,6 +164,7 @@ inline fastcall void utf8rutodos( ESI)
AL=symbol;
}
:dword ConvertMemSize(unsigned int bytes)
{
unsigned char size_prefix[8], size_nm[4];
@ -180,7 +173,7 @@ inline fastcall void utf8rutodos( ESI)
else if (bytes>=1024) strcpy(#size_nm, " Kb");
else strcpy(#size_nm, " b ");
while (bytes>1023) bytes/=1024;
strcpy(#size_prefix, itoa(bytes));
itoa_(#size_prefix, bytes);
strcat(#size_prefix, #size_nm);
return #size_prefix;
}

View File

@ -220,8 +220,8 @@ inline fastcall int GetActiveProcess()
:int CheckActiveProcess(int Form_ID)
{
int id=GetProcessSlot(Form_ID);
if (id==GetActiveProcess()) return 1;
int id9=GetProcessSlot(Form_ID);
if (id9==GetActiveProcess()) return 1;
return 0;
}

View File

@ -1,88 +0,0 @@
#define SOCKET_PASSIVE 0
#define SOCKET_ACTIVE 1
inline fastcall int GetNumOfActiveNetworkDevices()
{
$mov eax,74
BL = -1;
$int 0x40
}
inline fastcall dword OpenUnixSocket( ECX, EDX, ESI, EDI)
{
$mov eax,75
$mov bl,0
$int 0x40
}
/* ======================= OLD =========================*/
inline fastcall dword OpenSocket( ECX, EDX, ESI, EDI)
{
$mov eax,53
$mov ebx,5
$int 0x40
}
inline fastcall dword CloseSocket( ECX )
{
$mov eax, 53
$mov ebx, 8
$int 0x40
}
inline fastcall int StatusSocket( ECX)
{
$mov eax,53
$mov ebx,6
$int 0x40
}
inline fastcall dword ReadSocket( ECX)
{
$mov eax,53
$mov ebx,3
$int 0x40
return BL;
}
inline fastcall dword ReadNetworkData( ECX, EDX, ESI)
{
$mov eax, 53
$mov ebx, 11
$int 0x40
}
inline fastcall dword PollSocket( ECX)
{
$mov eax,53
$mov ebx,2
$int 0x40
}
inline fastcall dword WriteSocket( ECX, EDX, ESI)
{
$mov eax,53
$mov ebx,7
$int 0x40
}
inline fastcall int IsPortFree( ECX)
{
$mov eax,53
$mov ebx,9
$int 0x40
}
unsigned int GetFreePort(int port_i)
{
for (; port_i<65535; port_i++;)
if (IsPortFree(port_i)==1) return port_i;
return 0;
}

View File

@ -265,41 +265,6 @@ unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
*to = '\0';
}*/
dword itoa( ESI)
{
unsigned char buffer[11];
$pusha
EDI = #buffer;
ECX = 10;
if (ESI < 0)
{
$mov al, '-'
$stosb
$neg esi
}
$mov eax, esi
$push -'0'
F2:
$xor edx, edx
$div ecx
$push edx
$test eax, eax
$jnz F2
F3:
$pop eax
$add al, '0'
$stosb
$jnz F3
$mov al, '\0'
$stosb
$popa
return #buffer;
}
inline fastcall dword atoi( EDI)
{
@ -362,10 +327,77 @@ inline fastcall strttl( EDX)
}while(AL!=0);
}
unsigned char buffer[11];
dword itoa( ESI)
{
$pusha
EDI = #buffer;
ECX = 10;
if (ESI < 0)
{
$mov al, '-'
$stosb
$neg esi
}
$mov eax, esi
$push -'0'
F2:
$xor edx, edx
$div ecx
$push edx
$test eax, eax
$jnz F2
F3:
$pop eax
$add al, '0'
$stosb
$jnz F3
$mov al, '\0'
$stosb
$popa
return #buffer;
}
inline fastcall itoa_(signed int EDI, ESI)
{
$pusha
EBX = EDI;
ECX = 10;
if (ESI > 90073741824)
{
$mov al, '-'
$stosb
$neg esi
}
$mov eax, esi
$push -'0'
F2:
$xor edx, edx
$div ecx
$push edx
$test eax, eax
$jnz F2
F3:
$pop eax
$add al, '0'
$stosb
$jnz F3
$mov al, '\0'
$stosb
$popa
return EBX;
}
void debugi(dword d_int)
{
char tmpch[11];
strcpy(#tmpch, itoa(d_int));
char tmpch[12];
itoa_(#tmpch, d_int);
debug(#tmpch);
}

View File

@ -21,6 +21,8 @@ struct letter_attr
letter_attr atr;
dword mails_db;
void letter_attr::CreateArray()
{
free(mails_db);

View File

@ -45,9 +45,9 @@ enum {
#define WIN_H 440
#define WIN_MIN_W 500
#define WIN_MIN_H 380
#define LOGIN_HEADER "Login - Email client Liza 0.9b"
#define OPTIONS_HEADER "Options - Email client Liza 0.9b"
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.9b"
#define LOGIN_HEADER "Login - Email client Liza 0.9e"
#define OPTIONS_HEADER "Options - Email client Liza 0.9e"
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.9e"
#define BUFFERSIZE 512
proc_info Form;
system_colors sc;
@ -145,6 +145,23 @@ void SaveAndExit()
ExitProcess();
}
int GetRequest(dword command, text)
{
strcpy(#request, command);
if (text)
{
chrcat(#request, ' ');
strcat(#request, text);
}
strcat(#request, "\n");
return strlen(#request);
}
void StopConnect(dword message)
{
if (message) notify(message);
aim = STOP;
}
stop:

View File

@ -12,11 +12,7 @@ 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()
@ -227,18 +223,6 @@ void DrawLoginScreen()
}
int GetRequest(dword command, text)
{
strcpy(#request, command);
if (text)
{
chrcat(#request, ' ');
strcat(#request, text);
}
strcat(#request, "\n");
return strlen(#request);
}
void GetServerPathAndLogin()
{
int i=strchr(#email_text,'@');

View File

@ -11,8 +11,9 @@ scroll_bar scroll2 = { 17,200,210, LIST_INFO_H,18,0,115,15,0,0xCCCccc,0xD2CED0,0
char *listbuffer;
char *listpointer;
char *mailbuffer;
char *mailpointer;
char *mailstart;
char *mailend;
int mailsize;
enum {
@ -32,8 +33,6 @@ void MailBoxLoop()
int key, id;
mouse m;
int panels_drag = 0;
char socket_char;
int letter_size;
dword line_col, text_col;
mail_list.h = Form.cheight/4;
@ -98,8 +97,8 @@ void MailBoxLoop()
if (id==GET_MAIL) aim = SEND_NSTAT;
if (id==SAVE_LETTER)
{
if (!mailbuffer) break;
WriteFile(strlen(mailbuffer), mailbuffer, "mail.txt");
if (!mailstart) break;
WriteFile(strlen(mailstart), mailstart, "mail.txt");
pause(10);
RunProgram("tinypad", "mail.txt");
}
@ -180,8 +179,6 @@ void MailBoxLoop()
if (strstr(#immbuffer,"+OK"))
{
mail_list.count = GetMailCount();
debug("Letters:");
debug(itoa(mail_list.count));
free(listbuffer);
listbuffer = mem_Alloc(30*mail_list.count); //24* original
listpointer = listbuffer;
@ -235,44 +232,45 @@ void MailBoxLoop()
StopConnect("Error while trying to get letter from server");
break;
}
letter_size = atr.GetSize(mail_list.current+1) + 1024;
free(mailbuffer);
if (!mailbuffer = malloc(letter_size))
mailsize = atr.GetSize(mail_list.current+1) + 1024;
free(mailstart);
if (!mailstart = malloc(mailsize))
{
debug("alloc error!");
aim=NULL;
break;
}
mailpointer = mailbuffer;
mailend = mailstart;
aim = GET_ANSWER_RETR;
}
if (aim == GET_ANSWER_RETR)
{
aim=NULL;
break;
ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT);
ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
if (ticks == 0xffffffff) break;
mailpointer = mailpointer + ticks;
mailend = mailend + ticks;
if (!aim) break;
if (letter_size + mailbuffer - mailpointer - 2 < 0)
if (mailsize + mailstart - mailend - 2 < 0)
{
debug("Resizing buffer");
letter_size += 4096;
mailbuffer = realloc(mailbuffer, letter_size);
if (!mailbuffer) { StopConnect("Realloc error!"); break;}
mailsize += 4096;
mailstart = realloc(mailstart, mailsize);
if (!mailstart) { StopConnect("Realloc error!"); break;}
}
if (letter_size>9000)
if (mailsize>9000)
{
id = mailpointer - mailbuffer * 100 ;
id /= letter_size - 1024;
id = mailend - mailstart * 100 ;
id /= mailsize - 1024;
if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
}
//debug(mailstart);
//pause(10);
//debug("======================");
ParseMail();
}
@ -368,7 +366,7 @@ void DrawLetter()
letter_view.SetSizes(0, mail_list.y+mail_list.h+LIST_INFO_H+1, Form.cwidth - scroll2.size_x - 1,
Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 60, 12);
if (mailbuffer) && (!aim)
if (mailstart) && (!aim)
{
for ( ; i < letter_view.first; i++) cur_line = GetNextLine(cur_line);
@ -377,7 +375,7 @@ void DrawLetter()
next_line = GetNextLine(cur_line);
line_text = CopyBetweenOffsets(cur_line, next_line);
cur_line = next_line;
if (cur_line >= mailpointer) || (cur_line==1) break;
if (cur_line >= mailend) || (cur_line==1) break;
DrawBar(letter_view.x, i*letter_view.line_h + letter_view.y, letter_view.w, letter_view.line_h, 0xFFFfff);
if (line_text) { WriteText(letter_view.x+5, i*letter_view.line_h+letter_view.y+3, 0x80, 0, line_text); free(line_text);}
}
@ -430,8 +428,7 @@ void DrawStatusBar()
void SetMailBoxStatus(dword percent1, text1)
{
DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1, text1);
cur_st_percent = percent1;
if (text1) WriteText(3, Form.cheight -status_bar_h + 3, 0x80, sc.work_text, text1);
cur_st_text = text1;
}
@ -439,7 +436,7 @@ void SetMailBoxStatus(dword percent1, text1)
void StopLoading()
{
aim = NULL;
mailbuffer = free(mailbuffer);
mailstart = free(mailstart);
to = from = date = subj = cur_charset = NULL;
}
@ -449,16 +446,15 @@ int GetMailCount(){
return atoi(#tmpbuf4);
}
int GetLetterSize_(int number){
int GetLetterSize_(int number)
{
char search_num[24];
char letter_size1[24];
char mailsize1[24];
strcpy(#search_num, "\n"); // 0x0d, 0x0a
strcat(#search_num, itoa(number));
strcat(#search_num, " ");
strcpyb(listbuffer, #letter_size1, #search_num, "\x0d");
return atoi(#letter_size1);
itoa_(#search_num+1, number);
chrcat(#search_num, ' ');
strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
return atoi(#mailsize1);
}

View File

@ -5,44 +5,39 @@ void ParseMail()
dword line_off, new_buf;
char tline[256];
if ( mailpointer-mailbuffer>9 ) if (strncmp(mailpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
if ( mailend-mailstart > 9) if (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
{
debug("End of mail detected");
mailpointer = mailpointer - 5;
if (strstr(mailbuffer, "+OK")!=mailbuffer)
mailend -= 5;
if (strstr(mailstart, "+OK")!=mailstart)
{
aim = GET_ANSWER_RETR;
mailpointer = mailbuffer;
mailend = mailstart;
debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
return;
}
aim=NULL;
DSBYTE[mailpointer] = '\0';
debug("Real letter size:");
debugi(mailpointer - mailbuffer);
DSBYTE[mailend] = '\0';
mailsize = mailend - mailstart;
if (strstri(mailbuffer, "quoted-printable")!=0)
if (strstri(mailstart, "quoted-printable")!=0)
{
debug ("getting qp");
new_buf = malloc(mailpointer-mailbuffer);
qp_decode stdcall (mailbuffer, new_buf, mailpointer-mailbuffer);
new_buf = malloc(mailend-mailstart);
qp_decode stdcall (mailstart, new_buf, mailend-mailstart);
if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
else
{
free(mailbuffer);
mailbuffer = new_buf;
mailpointer = strlen(mailbuffer) + mailbuffer;
free(mailstart);
mailstart = new_buf;
mailsize = strlen(mailstart);
mailend = mailsize + mailstart;
}
}
debug ("getting list info");
GetHeader(#from, "\nFrom:");
GetHeader(#to, "\nTo:");
GetHeader(#date, "\nDate:");
GetHeader(#subj, "\nSubject:");
mdata = strstr(mailbuffer, "\n\r") + 3; // 0x0d 0x0a, 0x0a
debug ("converting to dos");
ConvertToDOS(mdata, mailbuffer);
mdata = strstr(mailstart, "\n\r") + 3; // 0x0d 0x0a, 0x0a
ConvertToDOS(mdata, mailstart);
FromHTMLtoTXT();
letter_view.first = letter_view.count = 0;
@ -87,13 +82,13 @@ void FromHTMLtoTXT()
{
dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0;
int i;
if (strstri(mdata, "<html>")==0) && (strstri(mailbuffer, "text/html")==0) {debug("no html tags found"); return;}
if (strstri(mdata, "<html>")==0) && (strstri(mailstart, "text/html")==0) {debug("no html tags found"); return;}
debug ("converting: html -> txt");
cur_chr = mdata;
txt_buf_srt = malloc(mailpointer - mailbuffer);
txt_buf_srt = malloc(mailend - mailstart);
txt_buf_end = txt_buf_srt;
while (cur_chr < mailpointer)
while (cur_chr < mailend)
{
if (DSBYTE[cur_chr]=='<') is_tag = 1;
if (!is_tag)
@ -107,7 +102,7 @@ void FromHTMLtoTXT()
}
DSBYTE[txt_buf_end] = '\0';
strcpy(mdata, txt_buf_srt);
mailpointer = strlen(mailbuffer) + mailbuffer; //тупо везде это ставить
mailend = strlen(mailstart) + mailstart;
free(txt_buf_srt);
}
@ -147,7 +142,7 @@ void GetHeader(dword workstr, searchstr)
char tmpbuf[512];
dword Qoff;
strcpyb(mailbuffer, workstr, searchstr, "\n");
strcpyb(mailstart, workstr, searchstr, "\n");
if (strstri(workstr, "?Q?"))
{
qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));