From 31d3a6408d045eadaff094d4c11bf017817743d7 Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:28:18 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@4 4f64403b-2f21-0410-a795-97e2b3489a10 --- attache/UploadSettings.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 attache/UploadSettings.cpp (limited to 'attache/UploadSettings.cpp') diff --git a/attache/UploadSettings.cpp b/attache/UploadSettings.cpp new file mode 100644 index 0000000..d91bc7e --- /dev/null +++ b/attache/UploadSettings.cpp @@ -0,0 +1,95 @@ +#include "common.h" +#include "UploadSettings.h" + +bool UploadSettings::SetAddress(TCHAR * lpszAddress) +{ + TCHAR szScheme[MAX_PATH]; + TCHAR szUserName[MAX_PATH]; + TCHAR szPassword[MAX_PATH]; + TCHAR szHostName[MAX_PATH]; + TCHAR szUrlPath[MAX_PATH]; + TCHAR szExtraInfo[MAX_PATH]; + + URL_COMPONENTS url; + memset(&url, 0, sizeof(URL_COMPONENTS)); + url.dwStructSize = sizeof(URL_COMPONENTS); + url.lpszScheme = szScheme; + url.dwSchemeLength = MAX_PATH; + url.lpszHostName = szHostName; + url.dwHostNameLength = MAX_PATH; + url.lpszUserName = szUserName; + url.dwUserNameLength = MAX_PATH; + url.lpszPassword = szPassword; + url.dwPasswordLength = MAX_PATH; + url.lpszUrlPath = szUrlPath; + url.dwUrlPathLength = MAX_PATH; + url.lpszExtraInfo = szExtraInfo; + url.dwExtraInfoLength = MAX_PATH; + + if (!InternetCrackUrl(lpszAddress, 0, 0, &url)) + return false; + + // Verify that none of the other bits got filled in: + if (_tcscmp(url.lpszScheme, _T("http")) != 0) + return false; + if (url.nPort != INTERNET_DEFAULT_HTTP_PORT) + return false; // Not supported yet. + if (url.lpszUserName[0]) + return false; + if (url.lpszPassword[0]) + return false; + if (url.lpszExtraInfo[0]) + return false; + + _tcsncpy(m_strHostName, szHostName, 1024); + _tcsncpy(m_strUrlPath,szUrlPath, MAX_PATH); + + return true; +} + +TCHAR *UploadSettings::GetAddress() const +{ + // TODO: Use InternetCreateUrl to put it back together. + TCHAR *strAddress = (TCHAR *)malloc(1024 * sizeof(TCHAR)); + mir_sntprintf(strAddress, 1024, _T("http://%s%s"), m_strHostName, m_strUrlPath); + + return strAddress; +} + +void UploadSettings::AddFile(TCHAR * lpszFieldName, TCHAR * lpszPathName, TCHAR * lpszContentType) +{ + // TODO: Open the file here, so that we can guarantee it's valid all the way through? + m_files.push_back(FileInfo(lpszFieldName, lpszPathName, lpszContentType)); +} + +void UploadSettings::ClearFiles() +{ + m_files.clear(); +} + +void UploadSettings::GetFiles(FileInfoList *pFiles) const +{ + // TODO: If we start storing file handles in the FileInfo object, we ought to use DuplicateHandle? + pFiles->clear(); + for(FileInfoList::ListNode *n = m_files.start(); n; n = n->next) + pFiles->push_back(n->info); + //std::copy(m_files.begin(), m_files.end(), std::back_inserter(*pFiles)); +} + +void UploadSettings::ClearFields() +{ + m_fields.clear(); +} + +void UploadSettings::GetFields(FieldInfoList *pFields) const +{ + pFields->clear(); + for(FieldInfoList::ListNode *n = m_fields.start(); n; n = n->next) + pFields->push_back(n->info); + //std::copy(m_fields.begin(), m_fields.end(), std::back_inserter(*pFields)); +} + +void UploadSettings::AddField(TCHAR * lpszFieldName, TCHAR *lpszFieldValue) +{ + m_fields.push_back(FieldInfo(lpszFieldName, lpszFieldValue)); +} -- cgit v1.2.3