/* Plugin of Miranda IM for communicating with users of the AIM protocol. Copyright (c) 2008-2012 Boris Krasnovskiy Copyright (C) 2005-2006 Aaron Myles Landwehr This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "aim.h" #pragma warning( disable: 4706 ) char* process_status_msg (const char *str, const char* sn) { const char *src = str; size_t size = strlen(src) + 1; char* res = (char*)mir_alloc(size); char* dest = res; for (; *src; ++src) { if (src[0] == '\n' && (src == str || src[-1] != '\r')) { int off = dest - res; res = (char*)mir_realloc(res, ++size); dest = res + off; *(dest++) = '\r'; *(dest++) = *src; } else if (src[0] == '%' && src[1] == 'n') { size_t len = strlen(sn); int off = dest - res; res = (char*)mir_realloc(res, size + len); dest = res + off; size += len; memcpy(dest, sn, len); dest += len; ++src; } else if (src[0] == '%' && src[1] == 'd') { int off = dest - res; res = (char*)mir_realloc(res, size + 20); dest = res + off; size += 20; dest += GetDateFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20)-1; ++src; } else if (src[0] == '%' && src[1] == 't') { int off = dest - res; res = (char*)mir_realloc(res, size + 20); dest = res + off; size += 20; dest += GetTimeFormatA(LOCALE_USER_DEFAULT, 0, NULL, NULL, dest, 20)-1; ++src; } else *(dest++) = *src; } *dest = '\0'; return res; } void html_decode(char* str) { char *p, *q; // char *rstr = (char*)mir_alloc(strlen(str)*2); if (str == NULL) return; for ( p=q=str; *p!='\0'; p++,q++ ) { if ( *p == '&' ) { if ( !strnicmp( p, "&", 5 )) { *q = '&'; p += 4; } else if ( !strnicmp( p, "'", 6 )) { *q = '\''; p += 5; } else if ( !strnicmp( p, ">", 4 )) { *q = '>'; p += 3; } else if ( !strnicmp( p, "<", 4 )) { *q = '<'; p += 3; } else if ( !strnicmp( p, """, 6 )) { *q = '"'; p += 5; } else if ( *(p+1) == '#' ) { char* s = strchr(p, ';'); if (s) { wchar_t t[2] = { (wchar_t)atoi(p+2), 0 }; char *t1 = mir_utf8encodeW(t); if (t1 && *t1) { strcpy(q, t1); q += strlen(t1) - 1; } mir_free(t1); p = s; } else *q = *p; } else { *q = *p; } } else if ( *p == '<' ) { if ( !strnicmp( p, "

", 3 )) { strcpy(q, "\r\n\r\n"); q += 3; p += 2; } else if ( !strnicmp( p, "

", 4 )) { strcpy(q, "\r\n\r\n"); q += 3; p += 3; } else if ( !strnicmp( p, "
", 4 )) { strcpy(q, "\r\n"); ++q; p += 3; } else if ( !strnicmp( p, "
", 6 )) { strcpy(q, "\r\n"); ++q; p += 5; } else if ( !strnicmp( p, "
", 4 )) { strcpy(q, "\r\n"); ++q; p += 3; } else if ( !strnicmp( p, "
", 6 )) { strcpy(q, "\r\n"); ++q; p += 5; } /* else if ( !strnicmp( p, "", 3 )) { strcpy(q, "[b]"); q += 2; p += 2; } else if ( !strnicmp( p, "", 4 )) { strcpy(q, "[/b]"); q += 3; p += 3; } else if ( !strnicmp( p, "", 3 )) { strcpy(q, "[u]"); q += 2; p += 2; } else if ( !strnicmp( p, "", 4 )) { strcpy(q, "[/u]"); q += 3; p += 3; } else if ( !strnicmp( p, "", 3 )) { strcpy(q, "[i]"); q += 2; p += 2; } else if ( !strnicmp( p, "", 4 )) { strcpy(q, "[/i]"); q += 3; p += 3; } else if ( !strnicmp( p, "", 3 )) { strcpy(q, "[s]"); q += 2; p += 2; } else if ( !strnicmp( p, "", 4 )) { strcpy(q, "[/s]"); q += 3; p += 3; } else if ( !strnicmp( p, "'); strcpy(q, "[url"); q += 4; p += 7; while (*p != '>' && *p) *(q++) = *(p++); *q = ']'; --p; } */ else { char *l = strchr(p, '>'); if (l) { p = l; --q; } else *q = *p; } } else *q = *p; } *q = '\0'; } char* html_encode(const char* str) { char* s, *q; const char *p; int c; if (str == NULL) return NULL; for ( c=0, p=str; *p!='\0'; p++ ) { switch ( *p ) { case '&' : c += 5; break; case '\'': c += 6; break; case '>' : c += 4; break; case '<' : c += 4; break; case '"' : c += 6; break; case '\n': c += 4; break; default: c++; break; } } s = (char*)mir_alloc(c + 27); strcpy(s, ""); for ( p=str,q=s+12; *p!='\0'; p++ ) { switch ( *p ) { case '&' : memcpy( q, "&", 5 ); q += 5; break; // case '\'': memcpy( q, "'", 6 ); q += 6; break; case '>' : memcpy( q, ">", 4 ); q += 4; break; case '<' : memcpy( q, "<", 4 ); q += 4; break; case '"' : memcpy( q, """, 6 ); q += 6; break; case '\r': break; case '\n': memcpy( q, "
", 4 ); q += 4; break; default: *q = *p; ++q; break; } } strcpy(q, ""); return s; } char* html_to_bbcodes(char *src) { char *ptr; char *ptrl; char *rptr; char* dest = mir_strdup(src); while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+1) = 'b'; *(ptr+2) = ']'; if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+2) = 'b'; *(ptr+3) = ']'; } else { dest=(char*)mir_realloc(dest,strlen(dest)+6); memcpy(&dest[strlen(dest)],"[/b]",5); } } while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+1) = 'i'; *(ptr+2) = ']'; if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+2) = 'i'; *(ptr+3) = ']'; } else { dest=(char*)mir_realloc(dest,strlen(dest)+6); memcpy(&dest[strlen(dest)],"[/i]",5); } } while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+1) = 'u'; *(ptr+2) = ']'; if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+2) = 'u'; *(ptr+3) = ']'; } else { dest=(char*)mir_realloc(dest,strlen(dest)+6); memcpy(&dest[strlen(dest)],"[/u]",5); } } while ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+1) = 's'; *(ptr+2) = ']'; if ((ptr = strstr(dest, "")) != NULL || (ptr = strstr(dest, "")) != NULL) { *ptr = '['; *(ptr+2) = 's'; *(ptr+3) = ']'; } else { dest=(char*)mir_realloc(dest,strlen(dest)+6); memcpy(&dest[strlen(dest)],"[/s]",5); } } rptr = dest; while (ptr = strstr(rptr,"
"))) { ptr-=1; memmove(ptr, ptr+1, strlen(ptr+1) + 1); *(ptr)=']'; ptrl-=1; char* s1 = strstr(ptrl,""))) { ptr-=1; memmove(ptr, ptr+1, strlen(ptr+1) + 1); *(ptr)=']'; ptrl-=1; char* s1 = strstr(ptrl,""))) { memmove(ptrl+7,ptr,strlen(ptr)+1); *(ptrl+7)=']'; ptr=ptrl+7; char* s1 = strstr(ptr,""))) { memmove(ptrl+7,ptr,strlen(ptr)+1); *(ptrl+7)=']'; ptr=ptrl+7; char* s1 = strstr(ptr,""))) { *(ptr)=']'; if ((ptrl = strstr(ptr, "",7); memmove(ptr+7,ptr+8,strlen(ptr+8)+1); } } else rptr++; } while ((ptr = strstr(rptr, "[url="))) { int addr=ptr-rptr; dest=(char*)mir_realloc(dest,strlen(dest)+8); rptr=dest; ptr=rptr+addr; memmove(ptr+3, ptr, strlen(ptr)+1); memcpy(ptr,"",4); memmove(ptr+4,ptr+6,strlen(ptr+6)+1); } } else rptr++; } return dest; } void strip_tag(char* begin, char* end) { memmove(begin,end+1,strlen(end+1)+1); } //strip a tag within a string char* strip_tag_within(char* begin, char* end) { while(char* sub_begin=strchr(begin,'<')) { if (sub_begin'); strip_tag(sub_begin,sub_end); end=end-(sub_end-sub_begin)-1; } else break; } return end; } char* rtf_to_html(HWND hwndDlg,int DlgItem) { char* buf=(char*)mir_alloc(4024); size_t pos=0; int start=0; int end=1; BOOL Bold=false; BOOL Italic=false; BOOL Underline=false; char Face[32]=""; COLORREF Color; COLORREF BackColor; int Size=0; GETTEXTLENGTHEX tl; tl.flags=GTL_DEFAULT; tl.codepage=CP_ACP; int oldstart = 0, oldend = 0; SendDlgItemMessage(hwndDlg, DlgItem, EM_GETSEL, (WPARAM)&oldstart, (LPARAM)&oldend); int length=SendDlgItemMessage(hwndDlg, DlgItem, EM_GETTEXTLENGTHEX,(WPARAM)&tl,0); while(start"); pos+=3; } else { if (start!=0) { strcpy(&buf[pos],""); pos+=4; } } } if (Italic!=isItalic) { Italic=isItalic; if (isItalic) { strcpy(&buf[pos],""); pos+=3; } else { if (start!=0) { strcpy(&buf[pos],""); pos+=4; } } } if (Underline!=isUnderline) { Underline=isUnderline; if (isUnderline) { strcpy(&buf[pos],""); pos+=3; } else { if (start!=0) { strcpy(&buf[pos],""); pos+=4; } } } if ( Size != isSize || Color != isColor || BackColor != isBackColor || lstrcmpA( Face, cfOld.szFaceName )) { Size=isSize; Color=isColor; BackColor=isBackColor; strcpy(Face,cfOld.szFaceName); if (start!=0) { strcpy(&buf[pos],""); pos+=7; } strcpy(&buf[pos],">8),chBackColor,16); size_t len=strlen(chBackColor); if (len<6) { memmove(chBackColor+(6-len),chBackColor,len+1); for(int i=0;i<6;i++) chBackColor[i]='0'; } strcpy(&buf[pos],chBackColor); pos+=6; } if (!(cfOld.dwEffects & CFE_AUTOCOLOR)) { strcpy(&buf[pos]," color=#"); pos+=8; char chColor[7]; _itoa((_htonl(Color)>>8),chColor,16); size_t len=strlen(chColor); if (len<6) { memmove(chColor+(6-len),chColor,len+1); for(int i=0;i<6;i++) chColor[i]='0'; } strcpy(&buf[pos],chColor); pos+=6; } strcpy(&buf[pos]," size="); pos+=6; char chSize[2]; _itoa(Size,chSize,10); strcpy(&buf[pos],chSize); pos++; strcpy(&buf[pos],">"); pos++; } if (text[0]=='\r') { strcpy(&buf[pos],"
"); pos+=4; } else { char* txt = mir_utf8encodeT(text); strcpy(&buf[pos], txt); pos += strlen(txt); mir_free(txt); } start++; end++; } if (Bold) { strcpy(&buf[pos],""); pos+=4; } if (Italic) { strcpy(&buf[pos],""); pos+=4; } if (Underline) { strcpy(&buf[pos],""); pos+=4; } strcpy(&buf[pos],""); pos+=7; SendDlgItemMessage(hwndDlg, DlgItem, EM_SETSEL, oldstart, oldend); return buf; } void wcs_htons(wchar_t * ch) { if (ch == NULL) return; for(size_t i=0;i>4; _itoa(bit,store,16); memcpy(&string[i*2],store,1); bit=(bytes[i]&0x0F); _itoa(bit,store,16); memcpy(&string[i*2+1],store,1); } string[num_bytes*2]='\0'; return string; } void string_to_bytes(char* string, char* bytes) { char sbyte[3]; sbyte[2]='\0'; size_t length=strlen(string); for (size_t i=0; i