コード例 #1
0
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
{
  iconv_t iconvString=iconv_open("UTF-8", strSourceCharset.c_str());

  if (iconvString != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    size_t outBytes = (inBytes * 4) + 1;
    char *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(iconvString, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
      return ;
    }

    strDest.ReleaseBuffer();

    iconv_close(iconvString);
  }
}
コード例 #2
0
ファイル: CharsetConverter.cpp プロジェクト: jimmyswimmy/plex
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
{
  iconv_t iconvString=iconv_open("UTF-8", strSourceCharset.c_str());

  if (iconvString != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1);
    size_t outBytes = (strSource.length() + 1) * 4;
    const char *src = strSource.c_str();
    char       *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(iconvString, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv(iconvString, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();

    iconv_close(iconvString);
  }
}
コード例 #3
0
void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvUtf8ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf8ToStringCharset = iconv_open(strCharset.c_str(), UTF8_SOURCE);
  }

  if (m_iconvUtf8ToStringCharset != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes - 1;

    if (iconv_const(m_iconvUtf8ToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
コード例 #4
0
void CCharsetConverter::subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest)
{
  CStdStringA strFlipped;

  // No need to flip hebrew/arabic as mplayer does the flipping

  if (m_iconvSubtitleCharsetToW == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetSubtitleCharSet();
    m_iconvSubtitleCharsetToW = iconv_open(WCHAR_CHARSET, strCharset.c_str());
  }

  if (m_iconvSubtitleCharsetToW != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;
    char *dst = (char*)strDest.GetBuffer(inBytes * sizeof(wchar_t));
    size_t outBytes = inBytes * sizeof(wchar_t);

    if (iconv_const(m_iconvSubtitleCharsetToW, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
コード例 #5
0
ファイル: CharsetConverter.cpp プロジェクト: jimmyswimmy/plex
void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvUtf8ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf8ToStringCharset = iconv_open(strCharset.c_str(), UTF8_SOURCE);
  }

  if (m_iconvUtf8ToStringCharset != (iconv_t) - 1)
  {
    size_t inBytes  = strSource.length() + 1;
    size_t outBytes = strSource.length() + 1;
    const char *src = strSource.c_str();
    char       *dst = strDest.GetBuffer(inBytes);

    if (iconv_const(m_iconvUtf8ToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv_const(m_iconvUtf8ToStringCharset, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();
  }
}
コード例 #6
0
CStdStringA TerDateTimeFormatter::GetFormattedTime(SYSTEMTIME& st, const CStdStringA& sFormatPicture)
{
	CStdString sDate;
	int ir = GetTimeFormat(m_locale, 0, &st, sFormatPicture.c_str(), sDate.GetBuffer(MAX_PATH), MAX_PATH);
	sDate.ReleaseBuffer();

	return sDate;
}
コード例 #7
0
ファイル: CharsetConverter.cpp プロジェクト: jimmyswimmy/plex
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    size_t outBytes = inBytes * sizeof(wchar_t);
    char      * dst = (char*)wString.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }

    if (iconv(m_iconvUtf8toW, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }
    wString.ReleaseBuffer();
  }
}
コード例 #8
0
ファイル: DocFileField.cpp プロジェクト: killbug2004/WSProf
DocFileField::DocFileField(const WrdCharacterProperties& props, WordParserInfo& wpi) : RTFfield(wpi.GetFileContext())
{
    the_RTFFieldInst = new RTFfldinst(m_pContext);

    CStdStringA sFont = wpi.m_FontTable.getFontFamilyName(props.getFontIndexForSymbol()).getFaceName().c_str();

    if ((int)sFont.find(" ") > 0)
    {
        sFont = "\"" + sFont + "\"";
    }

    CStdStringA sInst;
    if (1 & props.getFontSize())
        sInst.Format("SYMBOL %d \\f %s \\s %.1f", props.getSymbolCharacter() & 0xFF, sFont.c_str(), ((double)props.getFontSize())/2);
    else
        sInst.Format("SYMBOL %d \\f %s \\s %d", props.getSymbolCharacter() & 0xFF, sFont.c_str(), props.getFontSize()/2);
    the_RTFFieldInst->AddObject(new DocFilePCData(m_pContext, sInst));

    CreateResult();
    // the_RTFFieldResult->AddObject( new DocFileChrfmt(props , wpi, false) );//TODO - need a double check
}
コード例 #9
0
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    char *dst = new char[inBytes * sizeof(wchar_t)];
    size_t outBytes = inBytes * sizeof(wchar_t);
    char *outdst = dst;
    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &outdst, &outBytes))
    {
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      wString = utf8String;
    }
    else
    {
      wString = (WCHAR *)dst;
    }
    delete[] dst;
  }
}
コード例 #10
0
ファイル: TestUtils.cpp プロジェクト: killbug2004/WSProf
CStdString CTestUtils::CopyTestFileToTempFile(const CStdString& sSource)
{
	if(_taccess(sSource, 0) != 0)
	{
		CStdStringA sError;
		sError.Format("CTestUtils::CopyTestFileToTempFile - source file (%s) doesn't exist.", sSource.c_str());
		throw std::exception(sError.c_str());
	}

	TCHAR szTempPath[ MAX_PATH ] = {0};
	::GetTempPath( MAX_PATH, szTempPath );
	TCHAR szTempFileName[MAX_PATH] = {0};
	::GetTempFileName( szTempPath, _T( "wst" ), 0, szTempFileName );

	if (!CopyFile(sSource.c_str(), szTempFileName, false))
	{
		CStdStringA sError;
		sError.Format("CTestUtils::CopyTestFileToTempFile copy file failed - source file (%s) destination file (%s)", sSource.c_str(), szTempFileName);
		throw std::exception(sError.c_str());
	}
	return CStdString(szTempFileName);

}
コード例 #11
0
ファイル: CharsetConverter.cpp プロジェクト: jimmyswimmy/plex
void CCharsetConverter::subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest)
{
  CStdStringA strFlipped;

  // No need to flip hebrew/arabic as mplayer does the flipping

  if (m_iconvSubtitleCharsetToW == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetSubtitleCharSet();
    m_iconvSubtitleCharsetToW = iconv_open(WCHAR_CHARSET, strCharset.c_str());
  }

  if (m_iconvSubtitleCharsetToW != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1);
    size_t outBytes = (strSource.length() + 1) * sizeof(wchar_t);
    const char *src = strSource.c_str();
    char       *dst = (char*)strDest.GetBuffer(outBytes);

    if (iconv_const(m_iconvSubtitleCharsetToW, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv_const(m_iconvSubtitleCharsetToW, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
コード例 #12
0
ファイル: Server.cpp プロジェクト: soulic/FileZilla-Server
BOOL CServer::ProcessCommand(CAdminSocket *pAdminSocket, int nID, unsigned char *pData, int nDataLength)
{
	switch (nID)
	{
	case 2:
		if (!nDataLength) {
			unsigned char buffer[2];
			buffer[0] = m_nServerState / 256;
			buffer[1] = m_nServerState % 256;
			pAdminSocket->SendCommand(1, 2, buffer, 2);
		}
		else if (nDataLength == 2) {
			ToggleActive(*pData * 256 + pData[1]);
			unsigned char buffer[2];
			buffer[0] = m_nServerState / 256;
			buffer[1] = m_nServerState % 256;
			pAdminSocket->SendCommand(1, 2, buffer, 2);
		}
		else
			pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length") + 1);
		break;
	case 3:
		if (!nDataLength) {
			pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length") + 1);
		}
		else if (*pData == USERCONTROL_GETLIST) {
			int len = 4;
			std::map<int, t_connectiondata>::iterator iter;
			for (iter = m_UsersList.begin(); iter != m_UsersList.end(); ++iter) {
				const t_connectiondata& data = iter->second;
				auto ip = ConvToNetwork(data.ip);
				auto user = ConvToNetwork(data.user);
				len += 4 + ip.size() + 2 + 4 + user.size() + 2 + 1;
				if (data.transferMode) {
					auto physicalFile = ConvToNetwork(data.physicalFile);
					auto logicalFile = ConvToNetwork(data.logicalFile);
					len += 2 + physicalFile.size() + 2 + logicalFile.size();

					if (data.currentOffset != 0)
						len += 8;
					if (data.totalSize != -1)
						len += 8;
				}
			}
			unsigned char *buffer = new unsigned char[len];
			buffer[0] = USERCONTROL_GETLIST;
			buffer[1] = ((m_UsersList.size() / 256) / 256) & 0xff;
			buffer[2] = (m_UsersList.size() / 256) & 0xff;
			buffer[3] = m_UsersList.size() % 256;
			unsigned char *p = buffer + 4;
			for (iter = m_UsersList.begin(); iter != m_UsersList.end(); ++iter) {
				const t_connectiondata& data = iter->second;
				auto ip = ConvToNetwork(data.ip);
				auto user = ConvToNetwork(data.user);

				memcpy(p, &data.userid, 4);
				p += 4;
				*p++ = (ip.size() / 256) & 0xff;
				*p++ = ip.size() % 256;
				memcpy(p, ip.c_str(), ip.size());
				p += ip.size();

				memcpy(p, &data.port, 4);
				p += 4;

				*p++ = (user.size() / 256) & 0xff;
				*p++ = user.size() % 256;
				memcpy(p, user.c_str(), user.size());
				p += user.size();

				*p = data.transferMode;
				if (data.transferMode) {
					// Bit 5 and 6 indicate presence of currentOffset and totalSize.
					if (data.currentOffset != 0) {
						*p |= 0x20;
					}
					if (data.totalSize != -1) {
						*p |= 0x40;
					}
					p++;

					auto physicalFile = ConvToNetwork(data.physicalFile);
					*p++ = (physicalFile.size() / 256) & 0xff;
					*p++ = physicalFile.size() % 256;
					memcpy(p, physicalFile.c_str(), physicalFile.size());
					p += physicalFile.size();

					auto logicalFile = ConvToNetwork(data.logicalFile);
					*p++ = (logicalFile.size() / 256) & 0xff;
					*p++ = logicalFile.size() % 256;
					memcpy(p, logicalFile.c_str(), logicalFile.size());
					p += logicalFile.size();

					if (data.currentOffset != 0) {
						memcpy(p, &data.currentOffset, 8);
						p += 8;
					}
					if (data.totalSize != -1) {
						memcpy(p, &data.totalSize, 8);
						p += 8;
					}
				}
				else {
					p++;
				}
			}
			m_pAdminInterface->SendCommand(1, 3, buffer, len);
			delete [] buffer;
		}
		else if (*pData == USERCONTROL_KICK || *pData == USERCONTROL_BAN) {
			if (nDataLength != 5)
				pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1);
			else {
				int nUserID;
				memcpy(&nUserID, pData+1, 4);

				std::map<int, t_connectiondata>::iterator iter = m_UsersList.find(nUserID);
				if (iter!=m_UsersList.end()) {
					if (*pData == USERCONTROL_BAN) {
						// Get the list of IP filter rules.
						CStdString ips = m_pOptions->GetOption(OPTION_IPFILTER_DISALLOWED);
						if (ips != _T(""))
							ips += _T(" ");

						int pos = ips.Find(' ');
						while (pos != -1) {
							CStdString blockedIP = ips.Left(pos);
							ips = ips.Mid(pos + 1);
							pos = ips.Find(' ');

							if (MatchesFilter(blockedIP, iter->second.ip))
								break;
						}
						if (pos == -1) {
							ips = m_pOptions->GetOption(OPTION_IPFILTER_DISALLOWED);
							if (ips != _T(""))
								ips += _T(" ");
							ips += iter->second.ip;
							m_pOptions->SetOption(OPTION_IPFILTER_DISALLOWED, ips);
						}
					}
					t_controlmessage *msg = new t_controlmessage;
					msg->command = USERCONTROL_KICK;
					msg->socketid = nUserID;
					iter->second.pThread->PostThreadMessage(WM_FILEZILLA_THREADMSG, FTM_CONTROL, (LPARAM)msg);
					char buffer[2];
					buffer[0] = *pData;
					buffer[1] = 0;
					pAdminSocket->SendCommand(1, 3, &buffer, 2);
				}
				else {
					char buffer[2];
					buffer[0] = USERCONTROL_KICK;
					buffer[1] = 1;
					pAdminSocket->SendCommand(1, 3, &buffer, 2);
				}
			}
		}
		else
			pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data", strlen("\001Protocol error: Invalid data")+1);
		break;
	case 5:
		if (!nDataLength) {
			unsigned char *pBuffer = NULL;
			DWORD nBufferLength = 0;
			if (m_pOptions && m_pOptions->GetAsCommand(&pBuffer, &nBufferLength)) {
				pAdminSocket->SendCommand(1, 5, pBuffer, nBufferLength);
				delete [] pBuffer;
			}
		}
		else if (m_pOptions) {
			if (nDataLength < 2)
				pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1);
			else {
				CStdString const listenPorts = m_pOptions->GetOption(OPTION_SERVERPORT);
				CStdString const listenPortsSsl = m_pOptions->GetOption(OPTION_TLSPORTS);
				bool const enableSsl = m_pOptions->GetOptionVal(OPTION_ENABLETLS) != 0;
				CStdString const ipBindings = m_pOptions->GetOption(OPTION_IPBINDINGS);
				int const nAdminListenPort = (int)m_pOptions->GetOptionVal(OPTION_ADMINPORT);
				CStdString const adminIpBindings = m_pOptions->GetOption(OPTION_ADMINIPBINDINGS);

				CStdString peerIP;
				UINT port = 0;
				bool bLocal = false;
				if (!pAdminSocket->GetPeerName(peerIP, port))
					return FALSE;
				else
					bLocal = IsLocalhost(peerIP);

				if (!m_pOptions->ParseOptionsCommand(pData, nDataLength, bLocal)) {
					pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data, could not import settings.", strlen("\001Protocol error: Invalid data, could not import settings.")+1);
					char buffer = 1;
					pAdminSocket->SendCommand(1, 5, &buffer, 1);
					break;
				}

				char buffer = 0;
				pAdminSocket->SendCommand(1, 5, &buffer, 1);

				unsigned int threadnum = (int)m_pOptions->GetOptionVal(OPTION_THREADNUM);
				if (m_nServerState & STATE_ONLINE) {
					if (threadnum > m_ThreadArray.size()) {
						while (threadnum > m_ThreadArray.size()) {
							int index = GetNextThreadNotificationID();
							CServerThread *pThread = new CServerThread(WM_FILEZILLA_SERVERMSG + index);
							m_ThreadNotificationIDs[index] = pThread;
							if (pThread->Create(THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED)) {
								pThread->ResumeThread();
								m_ThreadArray.push_back(pThread);
							}
						}
						CStdString str;
						str.Format(_T("Number of threads increased to %d."), threadnum);
						ShowStatus(str, 0);
					}
					else if (threadnum < m_ThreadArray.size()) {
						CStdString str;
						str.Format(_T("Decreasing number of threads to %d."), threadnum);
						ShowStatus(str, 0);
						unsigned int i = 0;
						std::vector<CServerThread *> newList;
						for (auto iter = m_ThreadArray.begin(); iter != m_ThreadArray.end(); iter++, i++) {
							if (i >= threadnum) {
								(*iter)->PostThreadMessage(WM_FILEZILLA_THREADMSG, FTM_GOOFFLINE, 2);
								m_ClosedThreads.push_back(*iter);
							}
							else
								newList.push_back(*iter);
						}
						m_ThreadArray.swap(newList);
					}
				}
				if (listenPorts != m_pOptions->GetOption(OPTION_SERVERPORT) ||
					enableSsl != (m_pOptions->GetOptionVal(OPTION_ENABLETLS) != 0) ||
					(m_pOptions->GetOptionVal(OPTION_ENABLETLS) && listenPortsSsl != m_pOptions->GetOption(OPTION_TLSPORTS)) ||
					ipBindings != m_pOptions->GetOption(OPTION_IPBINDINGS))
				{
					if (!m_ListenSocketList.empty()) {
						ShowStatus(_T("Closing all listening sockets"), 0);
						for (std::list<CListenSocket*>::iterator listIter = m_ListenSocketList.begin(); listIter != m_ListenSocketList.end(); ++listIter) {
							(*listIter)->Close();
							delete *listIter;
						}
						m_ListenSocketList.clear();

						if (!CreateListenSocket()) {
							ShowStatus(_T("Failed to create a listen socket on any of the specified ports. Server is not online!"), 1);
							m_nServerState &= ~STATE_ONLINE;
						}
						else {
							ShowStatus(_T("Listen socket port changed"), 0);
							if (!(m_nServerState & STATE_MASK_GOOFFLINE))
								m_nServerState |= STATE_ONLINE;
						}
						SendState();
					}
				}
				if (nAdminListenPort != m_pOptions->GetOptionVal(OPTION_ADMINPORT) || adminIpBindings != m_pOptions->GetOption(OPTION_ADMINIPBINDINGS)) {
					CreateAdminListenSocket();
				}

				VerifyTlsSettings(pAdminSocket);
				VerifyPassiveModeSettings(pAdminSocket);
			}
		}
		break;
	case 6:
		if (!nDataLength) {
			unsigned char *pBuffer = NULL;
			DWORD nBufferLength = 0;
			CPermissions permissions = CPermissions(std::function<void()>());
			permissions.GetAsCommand(&pBuffer, &nBufferLength);
			pAdminSocket->SendCommand(1, 6, pBuffer, nBufferLength);
			delete [] pBuffer;
		}
		else {
			if (nDataLength < 2)
				pAdminSocket->SendCommand(1, 1, "\001Protocol error: Unexpected data length", strlen("\001Protocol error: Unexpected data length")+1);
			else {
				CPermissions permissions = CPermissions(std::function<void()>());
				if (!permissions.ParseUsersCommand(pData, nDataLength)) {
					pAdminSocket->SendCommand(1, 1, "\001Protocol error: Invalid data, could not import account settings.", strlen("\001Protocol error: Invalid data, could not import account settings.")+1);
					char buffer = 1;
					pAdminSocket->SendCommand(1, 6, &buffer, 1);
					break;
				}
				char buffer = 0;
				pAdminSocket->SendCommand(1, 6, &buffer, 1);
			}
		}
		break;
	case 8:
		pAdminSocket->SendCommand(1, 8, NULL, 0);
		break;
	default:
		{
			CStdStringA str;
			str.Format("\001Protocol error: Unknown command (%d).", nID);
			pAdminSocket->SendCommand(1, 1, str.c_str(), str.GetLength());
		}
		break;
	}

	return TRUE;
}
コード例 #13
0
ファイル: Converter.cpp プロジェクト: killbug2004/WSProf
long PASCAL CchFetchLpszError(long fce, char FAR *lpszError, long cb)
{
	CStdStringA sErrorMessage;

	switch( fce )
	{
	default:
		{
			int nSolidError = -( fce - fceWorkshareLastDefined );
			switch( nSolidError )
			{
			default:
				return 0;
			case Solid::Canceled:
				sErrorMessage = "Pdf conversion cancelled\0";
				break;
			case Solid::BadData:
				sErrorMessage = "The Pdf document may be corrupt\0";
				break;
			case Solid::IOError:
				sErrorMessage = "Pdf conversion IO error\0";
				break;
			case Solid::IOFileLocked:
				sErrorMessage = "Pdf conversion IO file locked\0";
				break;
			case Solid::ProtectedFile:
				sErrorMessage = "Workshare is unable to open Pdf files with copy protection\0";
				break;
			case Solid::InternalError:
				sErrorMessage = "Pdf conversion internal error\0";
				break;
			case Solid::InvalidPagesRange:
				sErrorMessage = "Pdf conversion invalid page range\0";
				break;
			case Solid::NoBppConversion:
				sErrorMessage = "Pdf bits per pixel conversion failed\0";
				break;
			case Solid::NoGrayScale:
				sErrorMessage = "Pdf gray scale conversion failed\0";
				break;
			case Solid::PSDUnsupportedMode:
				sErrorMessage = "Pdf is password protected, unable to convert\0";
				break;
			case Solid::TablesNotFound:
				sErrorMessage = "Pdf conversion found no tables to extract\0";
				break;
			case Solid::ImagesNotFound:
				sErrorMessage = "Pdf conversion found no images to extract\0";
				break;
			case Solid::UnsupportedEncryptionHandler:
				sErrorMessage = "Pdf has unsupported encryption\0";
				break;
			case Solid::MissingCertificate:
				sErrorMessage = "Pdf has missing certifucate\0";
				break;
			case Solid::Unknown:
				sErrorMessage = "An unknown error has occured\0";
				break;
			}
			break;
		}
	case fceOpenInFileErr:
		sErrorMessage = "Could not open input file\0";
		break;
	case fceReadErr:
		sErrorMessage = "Error during read\0";
		break;
	case fceWriteErr:
		sErrorMessage = "Error during write\0";
		break;
	case fceInvalidFile:
		sErrorMessage = "Invalid data in conversion file\0";
		break;
	case fceNoMemory:
		sErrorMessage = "Out of memory\0";
		break;
	case fceOpenOutFileErr:
		sErrorMessage = "Could not open output file\0";
		break;
	case fceUserCancel:
		sErrorMessage = "Conversion cancelled by user\0";
		break;
	case fceWrongFileType:
		sErrorMessage = "Wrong file type for this converter\0";
		break;
	case fceWorkshareNotLicensed:
		sErrorMessage = "Workshare needs to be licensed for Protect to enable this functionality\0";
		break;
	case fceWorkshareExportNotImplimented:
		sErrorMessage = "Workshare does not provide save functionality for Pdf files\0";
		break;
	case fceWorkshareNoConcurrentConversions:
		sErrorMessage = "Conversions cannot run concurrently\0";
		break;
	}

	if( cb > (long)sErrorMessage.length() )
	{
		strcpy_s( lpszError, cb, sErrorMessage.c_str() );
		return (long)sErrorMessage.length();
	}

	return 0;
}