diff options
-rw-r--r-- | plugins/FTPFileYM/src/dbentry.cpp | 18 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/dialog.cpp | 17 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/ftpfile.cpp | 5 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/job_delete.cpp | 2 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/job_generic.cpp | 6 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/job_packer.cpp | 11 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/job_upload.cpp | 18 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/mir_db.cpp | 40 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/mir_db.h | 6 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/serverlist.cpp | 36 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/utils.cpp | 64 | ||||
-rw-r--r-- | plugins/FTPFileYM/src/utils.h | 4 |
12 files changed, 93 insertions, 134 deletions
diff --git a/plugins/FTPFileYM/src/dbentry.cpp b/plugins/FTPFileYM/src/dbentry.cpp index d592c7c450..492666db45 100644 --- a/plugins/FTPFileYM/src/dbentry.cpp +++ b/plugins/FTPFileYM/src/dbentry.cpp @@ -29,7 +29,7 @@ DBEntry::DBEntry(DBEntry *entry) {
m_fileID = entry->m_fileID;
m_iFtpNum = entry->m_iFtpNum;
- mir_strcpy(m_szFileName, entry->m_szFileName);
+ strncpy_s(m_szFileName, entry->m_szFileName, _TRUNCATE);
}
DBEntry* DBEntry::getFirst()
@@ -47,10 +47,14 @@ DBEntry *DBEntry::getNext(DBEntry *entry) for (; entryID < count; entryID++) {
int ftpNum = DB::getByteF(0, MODULE_FILES, "Ftp%d", entryID, -1);
if (ftpNum != -1) {
- if (!DB::getAStringF(0, MODULE_FILES, "Filename%d", entryID, szValue)) {
+ CMStringA frmt;
+ frmt.Format("Filename%d", entryID);
+ ptrA Value(db_get_sa(NULL, MODULE, frmt));
+ if (Value) {
+ strncpy_s(szValue, Value, _TRUNCATE);
entry->m_fileID = entryID;
entry->m_iFtpNum = ftpNum;
- mir_strcpy(entry->m_szFileName, szValue);
+ strncpy_s(entry->m_szFileName, szValue, _TRUNCATE);
entry->m_deleteTS = DB::getDwordF(0, MODULE_FILES, "DeleteTS%d", entryID, 0);
entryID++;
return entry;
@@ -87,10 +91,14 @@ DBEntry* DBEntry::get(int fileID) int ftpNum = DB::getByteF(0, MODULE_FILES, "Ftp%d", fileID, -1);
if (ftpNum != -1) {
- if (!DB::getAStringF(0, MODULE_FILES, "Filename%d", fileID, szValue)) {
+ CMStringA frmt;
+ frmt.Format("Filename%d", fileID);
+ ptrA Value(db_get_sa(NULL, MODULE, frmt));
+ if (Value) {
+ strncpy_s(szValue, Value, _TRUNCATE);
entry->m_fileID = fileID;
entry->m_iFtpNum = ftpNum;
- mir_strcpy(entry->m_szFileName, szValue);
+ strncpy_s(entry->m_szFileName, szValue, _TRUNCATE);
entry->m_deleteTS = DB::getDwordF(0, MODULE_FILES, "DeleteTS%d", fileID, 0);
return entry;
}
diff --git a/plugins/FTPFileYM/src/dialog.cpp b/plugins/FTPFileYM/src/dialog.cpp index 2096f0bb60..bed6074e26 100644 --- a/plugins/FTPFileYM/src/dialog.cpp +++ b/plugins/FTPFileYM/src/dialog.cpp @@ -79,10 +79,14 @@ UploadDialog::Tab::Tab(GenericJob *Job) : m_stzComplet[0] = 0;
m_stzRemain[0] = 0;
- wchar_t buff[256];
+ CMStringW buff = m_job->m_tszFileName;
TCITEM tab = { 0 };
tab.mask = TCIF_TEXT;
- tab.pszText = Utils::getTextFragment(m_job->m_tszFileName, 20, buff);
+ if (mir_wstrlen(buff) > 20) {
+ buff = buff.Left(20);
+ buff.Append(L"...");
+ }
+ tab.pszText = buff.GetBuffer();
TabCtrl_InsertItem(uDlg->m_hwndTabs, uDlg->m_tabs.size(), &tab);
{
mir_cslock lock(mutexTabs);
@@ -130,12 +134,15 @@ void UploadDialog::Tab::select() void UploadDialog::Tab::labelCompleted()
{
- wchar_t buff[64], buff2[256];
- mir_snwprintf(buff2, L"* %s", Utils::getTextFragment(m_job->m_tszFileName, 20, buff));
+ CMStringW buff(FORMAT, L"* %s", m_job->m_tszFileName);
+ if (mir_wstrlen(buff) > 20) {
+ buff = buff.Left(22);
+ buff.Append(L"...");
+ }
TCITEM tab = { 0 };
tab.mask = TCIF_TEXT;
- tab.pszText = buff2;
+ tab.pszText = buff.GetBuffer();
TabCtrl_SetItem(uDlg->m_hwndTabs, index(), &tab);
}
diff --git a/plugins/FTPFileYM/src/ftpfile.cpp b/plugins/FTPFileYM/src/ftpfile.cpp index 0d81de53f0..8d97382f11 100644 --- a/plugins/FTPFileYM/src/ftpfile.cpp +++ b/plugins/FTPFileYM/src/ftpfile.cpp @@ -109,7 +109,10 @@ void InitMenuItems() mi2.pszService = MS_FTPFILE_CONTACTMENU;
for (int i = 0; i < ServerList::FTP_COUNT; i++) {
- if (DB::getStringF(0, MODULE, "Name%d", i, stzName))
+ CMStringA frmt;
+ frmt.Format("Name%d", i);
+ ptrA Name(db_get_sa(NULL, MODULE, frmt));
+ if (Name)
mir_snwprintf(stzName, TranslateT("FTP Server %d"), i + 1);
mi.root = (opt.bUseSubmenu) ? hMenu : nullptr;
diff --git a/plugins/FTPFileYM/src/job_delete.cpp b/plugins/FTPFileYM/src/job_delete.cpp index 0a39dd7ab1..6bb44b32dd 100644 --- a/plugins/FTPFileYM/src/job_delete.cpp +++ b/plugins/FTPFileYM/src/job_delete.cpp @@ -90,7 +90,7 @@ void DeleteJob::run() }
else if (manDlg != nullptr && m_treeItem) {
wchar_t *error = mir_a2u(szError);
- mir_wstrcpy(m_treeItem->m_tszToolTip, error);
+ wcsncpy_s(m_treeItem->m_tszToolTip, error, _TRUNCATE);
m_treeItem->setState(Manager::TreeItem::_ERROR());
FREE(error);
}
diff --git a/plugins/FTPFileYM/src/job_generic.cpp b/plugins/FTPFileYM/src/job_generic.cpp index 719da74d3f..5e732ad0dd 100644 --- a/plugins/FTPFileYM/src/job_generic.cpp +++ b/plugins/FTPFileYM/src/job_generic.cpp @@ -41,9 +41,9 @@ GenericJob::GenericJob(GenericJob *job) : m_ftp(job->m_ftp),
m_tab(job->m_tab)
{
- mir_wstrcpy(m_tszFilePath, job->m_tszFilePath);
- mir_wstrcpy(m_tszFileName, job->m_tszFileName);
- mir_strcpy(m_szSafeFileName, job->m_szSafeFileName);
+ wcsncpy_s(m_tszFilePath, job->m_tszFilePath, _TRUNCATE);
+ wcsncpy_s(m_tszFileName, job->m_tszFileName, _TRUNCATE);
+ strncpy_s(m_szSafeFileName, job->m_szSafeFileName, _TRUNCATE);
}
GenericJob::~GenericJob()
diff --git a/plugins/FTPFileYM/src/job_packer.cpp b/plugins/FTPFileYM/src/job_packer.cpp index 8428faf58c..79c4c9454e 100644 --- a/plugins/FTPFileYM/src/job_packer.cpp +++ b/plugins/FTPFileYM/src/job_packer.cpp @@ -39,27 +39,28 @@ void PackerJob::getZipFilePath() wchar_t *pch;
if (m_files.size() == 1) {
- mir_wstrcpy(stzFileName, Utils::getFileNameFromPath(m_files[0]));
+ wcsncpy_s(stzFileName, Utils::getFileNameFromPath(m_files[0]), _TRUNCATE);
pch = wcsrchr(stzFileName, '.');
if (pch) *pch = 0;
}
else {
- mir_wstrcpy(buff, m_files[0]);
+ wcsncpy_s(buff, m_files[0], _TRUNCATE);
pch = wcsrchr(buff, '\\');
if (pch) {
*pch = 0;
pch = wcsrchr(buff, '\\');
- if (pch) mir_wstrcpy(stzFileName, pch + 1);
+ if (pch)
+ wcsncpy_s(stzFileName, pch + 1, _TRUNCATE);
}
}
if (stzFileName[0] == '\0')
- mir_wstrcpy(stzFileName, L"archive");
+ wcsncpy_s(stzFileName, L"archive", _TRUNCATE);
GetTempPath(_countof(buff), buff);
mir_snwprintf(m_tszFilePath, L"%s%s.zip", buff, stzFileName);
- mir_wstrcpy(m_tszFileName, Utils::getFileNameFromPath(m_tszFilePath));
+ wcsncpy_s(m_tszFileName, Utils::getFileNameFromPath(m_tszFilePath), _TRUNCATE);
if (opt.bSetZipName)
Utils::setFileNameDlg(m_tszFileName);
diff --git a/plugins/FTPFileYM/src/job_upload.cpp b/plugins/FTPFileYM/src/job_upload.cpp index a083225d57..f7edbebf25 100644 --- a/plugins/FTPFileYM/src/job_upload.cpp +++ b/plugins/FTPFileYM/src/job_upload.cpp @@ -36,7 +36,7 @@ UploadJob::UploadJob(UploadJob *job) : GenericJob(job),
m_fp(nullptr), m_uiSent(0), m_uiTotalSent(0), m_uiFileSize(0)
{
- mir_strcpy(m_szFileLink, job->m_szFileLink);
+ strncpy_s(m_szFileLink, job->m_szFileLink, _TRUNCATE);
for (int i = 0; i < _countof(m_lastSpeed); i++)
m_lastSpeed[i] = 0;
}
@@ -47,7 +47,10 @@ UploadJob::UploadJob(PackerJob *job) : for (int i = 0; i < _countof(m_lastSpeed); i++)
m_lastSpeed[i] = 0;
- Utils::makeSafeString(job->m_tszFileName, m_szSafeFileName);
+ CMStringA buf = _T2A(job->m_tszFileName);
+ Utils::makeSafeString(buf);
+ strncpy_s(m_szSafeFileName, buf.c_str(), _TRUNCATE);
+
m_status = STATUS_CREATED;
}
@@ -64,9 +67,12 @@ void UploadJob::addToUploadDlg() {
for (UINT i = 0; i < m_files.size(); i++) {
UploadJob *jobCopy = new UploadJob(this);
- mir_wstrcpy(jobCopy->m_tszFilePath, m_files[i]);
- mir_wstrcpy(jobCopy->m_tszFileName, Utils::getFileNameFromPath(jobCopy->m_tszFilePath));
- Utils::makeSafeString(jobCopy->m_tszFileName, jobCopy->m_szSafeFileName);
+ wcsncpy_s(jobCopy->m_tszFilePath, m_files[i], _TRUNCATE);
+ wcsncpy_s(jobCopy->m_tszFileName, Utils::getFileNameFromPath(jobCopy->m_tszFilePath), _TRUNCATE);
+
+ CMStringA buf = jobCopy->m_tszFileName;
+ Utils::makeSafeString(buf);
+ strncpy_s(jobCopy->m_szSafeFileName, buf.c_str(), _TRUNCATE);
UploadDialog::Tab *newTab = new UploadDialog::Tab(jobCopy);
jobCopy->m_tab = newTab;
@@ -290,7 +296,7 @@ void UploadJob::upload() if (fileExistsOnServer()) {
int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_FILEEXISTS), nullptr, DlgProcFileExists, (LPARAM)m_szSafeFileName);
if (res == IDC_RENAME) {
- if (Utils::setFileNameDlgA(m_szSafeFileName) == true)
+ if (Utils::setFileNameDlg(_A2T(m_szSafeFileName)) == true)
curl_easy_setopt(hCurl, CURLOPT_URL, getUrlString());
}
else if (res == IDC_COPYURL) {
diff --git a/plugins/FTPFileYM/src/mir_db.cpp b/plugins/FTPFileYM/src/mir_db.cpp index e7c693585a..fcd6d35cc7 100644 --- a/plugins/FTPFileYM/src/mir_db.cpp +++ b/plugins/FTPFileYM/src/mir_db.cpp @@ -74,46 +74,6 @@ int DB::getDwordF(MCONTACT hContact, char *szModule, char *szSetting, int id, in return db_get_dw(hContact, szModule, formSet, iErrorValue);
}
-int DB::getAString(MCONTACT hContact, char *szModule, char *szSetting, char *buff)
-{
- DBVARIANT dbv;
- if (!db_get_s(hContact, szModule, szSetting, &dbv)) {
- mir_strcpy(buff, dbv.pszVal);
- db_free(&dbv);
- return 0;
- }
-
- buff[0] = 0;
- return 1;
-}
-
-int DB::getAStringF(MCONTACT hContact, char *szModule, char *szSetting, int id, char *buff)
-{
- char formSet[256];
- mir_snprintf(formSet, szSetting, id);
- return getAString(hContact, szModule, formSet, buff);
-}
-
-int DB::getString(MCONTACT hContact, char *szModule, char *szSetting, wchar_t *buff)
-{
- DBVARIANT dbv;
- if (!db_get_ws(hContact, szModule, szSetting, &dbv)) {
- mir_wstrcpy(buff, dbv.ptszVal);
- db_free(&dbv);
- return 0;
- }
-
- buff[0] = 0;
- return 1;
-}
-
-int DB::getStringF(MCONTACT hContact, char *szModule, char *szSetting, int id, wchar_t *buff)
-{
- char formSet[256];
- mir_snprintf(formSet, szSetting, id);
- return getString(hContact, szModule, formSet, buff);
-}
-
int DB::deleteSettingF(MCONTACT hContact, char *szModule, char *szSetting, int id)
{
char formSet[256];
diff --git a/plugins/FTPFileYM/src/mir_db.h b/plugins/FTPFileYM/src/mir_db.h index 750f6c6b8a..bc92bd1e15 100644 --- a/plugins/FTPFileYM/src/mir_db.h +++ b/plugins/FTPFileYM/src/mir_db.h @@ -34,11 +34,5 @@ public: static int getWordF(MCONTACT hContact, char *szModule, char *szSetting, int id, int iErrorValue = -1);
static int getDwordF(MCONTACT hContact, char *szModule, char *szSetting, int id, int iErrorValue = -1);
- // !!!!!!!!!!!!!!!!!!! dangerous as hell
- static int getAString(MCONTACT hContact, char *szModule, char *szSetting, char *buff);
- static int getAStringF(MCONTACT hContact, char *szModule, char *szSetting, int id, char *buff);
- static int getString(MCONTACT hContact, char *szModule, char *szSetting, wchar_t *buff);
- static int getStringF(MCONTACT hContact, char *szModule, char *szSetting, int id, wchar_t *buff);
-
static int deleteSettingF(MCONTACT hContact, char *szModule, char *szSetting, int id);
};
diff --git a/plugins/FTPFileYM/src/serverlist.cpp b/plugins/FTPFileYM/src/serverlist.cpp index fbbd700fac..a2b865bcee 100644 --- a/plugins/FTPFileYM/src/serverlist.cpp +++ b/plugins/FTPFileYM/src/serverlist.cpp @@ -63,15 +63,35 @@ void ServerList::saveToDb() const ServerList::FTP::FTP(int index)
{
- if (DB::getStringF(0, MODULE, "Name%d", index, m_stzName))
+ CMStringA frmt;
+ frmt.Format("Name%d", index);
+ ptrA Name(db_get_sa(NULL, MODULE, frmt));
+ if (Name)
mir_snwprintf(m_stzName, TranslateT("FTP Server %d"), index + 1);
-
- DB::getAStringF(0, MODULE, "Password%d", index, m_szPass);
- DB::getAStringF(0, MODULE, "Server%d", index, m_szServer);
- DB::getAStringF(0, MODULE, "User%d", index, m_szUser);
- DB::getAStringF(0, MODULE, "Url%d", index, m_szUrl);
- DB::getAStringF(0, MODULE, "Dir%d", index, m_szDir);
- DB::getAStringF(0, MODULE, "Chmod%d", index, m_szChmod);
+ frmt.Format("Password%d", index);
+ ptrA Pass(db_get_sa(NULL, MODULE, frmt));
+ if (Pass)
+ strncpy_s(m_szPass, Pass, _TRUNCATE);
+ frmt.Format("Server%d", index);
+ ptrA Server(db_get_sa(NULL, MODULE, frmt));
+ if (Server)
+ strncpy_s(m_szServer, Server, _TRUNCATE);
+ frmt.Format("User%d", index);
+ ptrA User(db_get_sa(NULL, MODULE, frmt));
+ if (User)
+ strncpy_s(m_szUser, User, _TRUNCATE);
+ frmt.Format("Url%d", index);
+ ptrA Url(db_get_sa(NULL, MODULE, frmt));
+ if (Url)
+ strncpy_s(m_szUrl, Url, _TRUNCATE);
+ frmt.Format("Dir%d", index);
+ ptrA Dir(db_get_sa(NULL, MODULE, frmt));
+ if (Dir)
+ strncpy_s(m_szDir, Dir, _TRUNCATE);
+ frmt.Format("Chmod%d", index);
+ ptrA Chmod(db_get_sa(NULL, MODULE, frmt));
+ if (Chmod)
+ strncpy_s(m_szChmod, Chmod, _TRUNCATE);
m_ftpProto = (FTP::EProtoType)DB::getWordF(0, MODULE, "FtpProto%d", index, FTP::FT_STANDARD);
m_iPort = DB::getWordF(0, MODULE, "Port%d", index, 21);
m_bPassive = DB::getByteF(0, MODULE, "Passive%d", index, 0) ? true : false;
diff --git a/plugins/FTPFileYM/src/utils.cpp b/plugins/FTPFileYM/src/utils.cpp index 34491f7e2a..4d1250b1f0 100644 --- a/plugins/FTPFileYM/src/utils.cpp +++ b/plugins/FTPFileYM/src/utils.cpp @@ -65,24 +65,12 @@ wchar_t* Utils::getFileNameFromPath(wchar_t *stzPath) else return L"file.zip";
}
-wchar_t* Utils::getTextFragment(wchar_t *stzText, size_t length, wchar_t *buff)
-{
- if (mir_wstrlen(stzText) > length) {
- mir_wstrcpy(buff, stzText);
- buff[length - 1] = 0;
- mir_wstrcat(buff, L"...");
- return buff;
- }
-
- return stzText;
-}
-
void Utils::copyToClipboard(char *szText)
{
if (szText) {
if (OpenClipboard(nullptr)) {
EmptyClipboard();
- HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, 1024);
+ HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, mir_strlen(szText) + 1);
char *pchData = (char *)GlobalLock(hClipboardData);
mir_strcpy(pchData, szText);
GlobalUnlock(hClipboardData);
@@ -95,24 +83,12 @@ void Utils::copyToClipboard(char *szText) const char from_chars[] = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ !@#$%^&=,{}[];'`";
const char to_chars[] = "abvgdeezziiklmnoprstufhccwwqyqeuaABVGDEEZZIIKLMNOPRSTUFHCCWWQYQEUA_________________";
-char* Utils::makeSafeString(wchar_t *input, char *output)
+CMStringA Utils::makeSafeString(CMStringA &input)
{
- char *buff = mir_u2a(input);
- size_t length = mir_strlen(buff);
-
- for (UINT i = 0; i < length; i++) {
- for (int j = 0; from_chars[j] != 0; j++) {
- if (buff[i] == from_chars[j]) {
- buff[i] = to_chars[j];
- break;
- }
- }
- }
-
- mir_strcpy(output, buff);
- FREE(buff);
-
- return output;
+ int len = mir_strlen(from_chars);
+ for (int i = 0; i < len; i++)
+ input.Replace(from_chars[i], to_chars[i]);
+ return input;
}
void Utils::curlSetOpt(CURL *hCurl, ServerList::FTP *ftp, char *url, struct curl_slist *headerList, char *errorBuff)
@@ -134,10 +110,13 @@ void Utils::curlSetOpt(CURL *hCurl, ServerList::FTP *ftp, char *url, struct curl if (ftp->m_bPassive)
curl_easy_setopt(hCurl, CURLOPT_FTPPORT, 0);
- else if (!DB::getAString(0, MODULE, "LocalIP", buff))
- curl_easy_setopt(hCurl, CURLOPT_FTPPORT, buff);
- else
- curl_easy_setopt(hCurl, CURLOPT_FTPPORT, "-");
+ else {
+ ptrA localip(db_get_sa(NULL, MODULE, "LocalIP"));
+ if (localip)
+ curl_easy_setopt(hCurl, CURLOPT_FTPPORT, localip);
+ else
+ curl_easy_setopt(hCurl, CURLOPT_FTPPORT, "-");
+ }
mir_snprintf(buff, "%s:%s", ftp->m_szUser, ftp->m_szPass);
curl_easy_setopt(hCurl, CURLOPT_USERPWD, buff);
@@ -197,23 +176,6 @@ bool Utils::setFileNameDlg(wchar_t *nameBuff) return false;
}
-bool Utils::setFileNameDlgA(char *nameBuff)
-{
- wchar_t buff[64];
- wchar_t *tmp = mir_a2u(nameBuff);
- mir_wstrcpy(buff, tmp);
- FREE(tmp);
-
- bool res = setFileNameDlg(buff);
- if (res) {
- char *p = mir_u2a(buff);
- mir_strcpy(nameBuff, p);
- FREE(p);
- }
-
- return res;
-}
-
void Utils::createFileDownloadLink(char *szUrl, char *fileName, char *buff, int buffSize)
{
if (szUrl[mir_strlen(szUrl) - 1] == '/')
diff --git a/plugins/FTPFileYM/src/utils.h b/plugins/FTPFileYM/src/utils.h index de5fd9d911..084e66a664 100644 --- a/plugins/FTPFileYM/src/utils.h +++ b/plugins/FTPFileYM/src/utils.h @@ -35,13 +35,11 @@ public: static HANDLE getIconHandle(const char *szName);
static wchar_t *getFileNameFromPath(wchar_t *stzPath);
- static wchar_t *getTextFragment(wchar_t *stzText, size_t length, wchar_t *buff);
- static char *makeSafeString(wchar_t *input, char *output);
+ static CMStringA makeSafeString(CMStringA &input);
static void createFileDownloadLink(char *szUrl, char *fileName, char *buff, int buffSize);
static void copyToClipboard(char *szText);
static void curlSetOpt(CURL *hCurl, ServerList::FTP *ftp, char *url, struct curl_slist *headerList, char *errorBuff);
static bool setFileNameDlg(wchar_t *nameBuff);
- static bool setFileNameDlgA(char *nameBuff);
};
|