コード例 #1
0
ファイル: UrlSerializer.cpp プロジェクト: HiPiH/Oreka
void UrlSerializer::UnEscapeUrl(CStdString& in, CStdString& out)
{
	// Translates all %xx escaped sequences to corresponding ascii characters
	out = "";
	char pchHex[3];
	for (unsigned int i = 0; i<in.size(); i++)
	{
		switch (in.GetAt(i))
		{
			case '+':
				out += ' ';
				break;
			case '%':
				if (in.GetAt(++i) == '%')
				{
					out += '%';
					break;
				}
				pchHex[0] = in.GetAt(i);
				pchHex[1] = in.GetAt(++i);
				pchHex[2] = 0;
				out += (char)strtol(pchHex, NULL, 16);
				break;
			default:
				out += in.GetAt(i);
		}
	}
}
コード例 #2
0
ファイル: Utils.cpp プロジェクト: uchitaso/orkweb
void FileEscapeName(CStdString& in, CStdString& out)
{
	// Translates all the characters that are not in file_ok_chars string into %xx sequences
	// %xx specifies the character ascii code in hexadecimal
	out = "";
	for (unsigned int i = 0 ; i<in.size() ; i++)
	{
		if (strchr(file_ok_chars, in.GetAt(i)))
		{
			out += in.GetAt(i);
		}
		else
		{
			out += '%';
			out += hex_digits[((unsigned char) in.GetAt(i)) >> 4];
			out += hex_digits[in.GetAt(i) & 0x0F];
		}
	}
}
コード例 #3
0
ファイル: UrlSerializer.cpp プロジェクト: HiPiH/Oreka
void UrlSerializer::EscapeUrl(CStdString& in, CStdString& out)
{
	// Translates all the characters that are not in url_ok_chars string into %xx sequences
	// %xx specifies the character ascii code in hexadecimal
	out = "";
	for (unsigned int i = 0 ; i<in.size() ; i++)
	{
		if (in.GetAt(i) == ' ')
			out += '+';
		else if (strchr(url_ok_chars, in.GetAt(i)))
			out += in.GetAt(i);
		else
		{
			out += '%';
			out += hex_digits[((unsigned char) in.GetAt(i)) >> 4];
			out += hex_digits[in.GetAt(i) & 0x0F];
		}
	}
}
コード例 #4
0
ファイル: Utils.cpp プロジェクト: uchitaso/orkweb
bool StringIsDigit(CStdString& string)
{
	int size = string.size();
	for(int i=0; i<size; i++)
	{
		if(isdigit(string.GetAt(i)) == false)
		{
			return false;
		}
	}
	return true;
}
コード例 #5
0
ファイル: Utils.cpp プロジェクト: uchitaso/orkweb
bool StringIsPhoneNumber(CStdString& string)
{
	int size = string.size();
	for(int i=0; i<size; i++)
	{
		char c = string.GetAt(i);
		if(isdigit(c) == false && c != '-' && c != '*' && c != '#')
		{
			return false;
		}
	}
	return true;
}
コード例 #6
0
ファイル: DocProvHelper.cpp プロジェクト: killbug2004/WSProf
CStdString DocProvHelper::GenerateUniquePathNameFromDocID(CStdString sDocumentID) const
{
	sDocumentID.Trim();

	/* TXTEX_IGNORE */ 	sDocumentID.Replace( '\\', _T('/') );
	/* TXTEX_IGNORE */ 	sDocumentID.Replace( _T("://"), _T("/") );

	int nLastPeriod = (x64_int_cast)sDocumentID.length() - 4;
	/* TXTEX_IGNORE */ 	if( nLastPeriod >= 0 && sDocumentID.GetAt( nLastPeriod ) == _T('.') )
		/* TXTEX_IGNORE */ 		sDocumentID.SetAt( nLastPeriod, _T('_') );

	return ReplaceInvalidFileNameChars(sDocumentID);

}
コード例 #7
0
ファイル: functions.cpp プロジェクト: rdmeneze/SMSBox-PIC
int GetListTokens(CStdString strTokens,  CStdString token ,LstString& lstTokens)
{
	CStdString sAux,sTmp;
	char buffer[512];
	int i,j;

	if ( strTokens != "" ){
		sAux = strTokens.GetAt( strTokens.GetLength( ) - 1 ) ;
		if ( sAux != token ){
			sAux = strTokens + token;
		}
		else{
			sAux = strTokens;
		}

		i = 0;
		j = sAux.find_first_of( token );

		for ( ;; ){
			memset( (char *)buffer, 0, sizeof( buffer ) );

			if ( j-i > 1 ){
				sAux.copy( buffer, j-i, i );
			}

			sTmp = buffer;

			if ( sTmp != "" )
			{
				lstTokens.push_back( (LPCSTR)sTmp );
			}

			i = ++j;
			j = sAux.find_first_of( token, i );

			if ( j == -1 ) {
				break;
			}
		}
	}
	return 0;
}
コード例 #8
0
void CTestLongNameOpen::TestReturnPathIncludesCorrectDrive()
{
	Gen::CFilePath wrd;
	TCHAR pszShortname[MAX_PATH] = {0};
	DWORD  dwSize = GetShortPathName(sLongFileNameDifferentDrive.c_str(), pszShortname, MAX_PATH);
	if(dwSize == 0)
	{
		assertTest(_T("Failed to extract short name") == false);
	}

	TCHAR chExpectedDriveLetter = sLongFileNameDifferentDrive.GetAt(0);
	TCHAR chExpUpperLetter;
	TCHAR chExpLowerLetter;
	if (chExpectedDriveLetter <= _T('Z'))	// It's upper case
	{
		chExpUpperLetter = chExpectedDriveLetter;
		chExpLowerLetter = chExpUpperLetter + (_T('a') - _T('A'));
	}
	else
	{
		chExpLowerLetter = chExpectedDriveLetter;
		chExpUpperLetter = chExpLowerLetter - (_T('a') - _T('A'));
	}

	assertTest((pszShortname[0] == chExpUpperLetter) || (pszShortname[0] == chExpLowerLetter));
	CStdString stInput, stOutput;
	stInput = pszShortname;
	bool bOK = wrd.GenerateLongFilePath(stInput, stOutput);
	assertMessage(bOK, _T("Call to GenerateLongFilePath returned failure"));

	CStdString sMsg;
	sMsg.Format(_T("Expected GenerateLongFilePath to generate %s.  Instead got %s"),
		sLongFileNameDifferentDrive.c_str(),
		stOutput.c_str());
	assertMessage(stOutput.CompareNoCase(sLongFileNameDifferentDrive) == 0, sMsg);

	assertTest((stOutput[0] == chExpUpperLetter) || (stOutput[0] == chExpLowerLetter));
}
コード例 #9
0
ファイル: NetworkLinux.cpp プロジェクト: jrahaim/xbmc
void CNetworkInterfaceLinux::SetSettings(NetworkAssignment& assignment, CStdString& ipAddress, CStdString& networkMask, CStdString& defaultGateway, CStdString& essId, CStdString& key, EncMode& encryptionMode)
{
#if defined(TARGET_LINUX)
    FILE* fr = fopen("/etc/network/interfaces", "r");
    if (!fr)
    {
        // TODO
        return;
    }

    FILE* fw = fopen("/tmp/interfaces.temp", "w");
    if (!fw)
    {
        // TODO
        fclose(fr);
        return;
    }

    char* line = NULL;
    size_t linel = 0;
    CStdString s;
    bool foundInterface = false;
    bool dataWritten = false;

    while (getdelim(&line, &linel, '\n', fr) > 0)
    {
        vector<CStdString> tokens;

        s = line;
        s.TrimLeft(" \t").TrimRight(" \n");

        // skip comments
        if (!foundInterface && (s.length() == 0 || s.GetAt(0) == '#'))
        {
            fprintf(fw, "%s", line);
            continue;
        }

        // look for "iface <interface name> inet"
        CUtil::Tokenize(s, tokens, " ");
        if (tokens.size() == 2 &&
                tokens[0].Equals("auto") &&
                tokens[1].Equals(GetName()))
        {
            continue;
        }
        else if (!foundInterface &&
                 tokens.size() == 4 &&
                 tokens[0].Equals("iface") &&
                 tokens[1].Equals(GetName()) &&
                 tokens[2].Equals("inet"))
        {
            foundInterface = true;
            WriteSettings(fw, assignment, ipAddress, networkMask, defaultGateway, essId, key, encryptionMode);
            dataWritten = true;
        }
        else if (foundInterface &&
                 tokens.size() == 4 &&
                 tokens[0].Equals("iface"))
        {
            foundInterface = false;
            fprintf(fw, "%s", line);
        }
        else if (!foundInterface)
        {
            fprintf(fw, "%s", line);
        }
    }
    free(line);

    if (!dataWritten && assignment != NETWORK_DISABLED)
    {
        fprintf(fw, "\n");
        WriteSettings(fw, assignment, ipAddress, networkMask, defaultGateway, essId, key, encryptionMode);
    }

    fclose(fr);
    fclose(fw);

    // Rename the file
    if (rename("/tmp/interfaces.temp", "/etc/network/interfaces") < 0)
    {
        // TODO
        return;
    }

    std::string cmd = "/sbin/ifdown " + GetName();
    if (system(cmd.c_str()) != 0)
        CLog::Log(LOGERROR, "Unable to stop interface %s", GetName().c_str());
    else
        CLog::Log(LOGINFO, "Stopped interface %s", GetName().c_str());

    if (assignment != NETWORK_DISABLED)
    {
        cmd = "/sbin/ifup " + GetName();
        if (system(cmd.c_str()) != 0)
            CLog::Log(LOGERROR, "Unable to start interface %s", GetName().c_str());
        else
            CLog::Log(LOGINFO, "Started interface %s", GetName().c_str());
    }
#endif
}
コード例 #10
0
ファイル: NetworkLinux.cpp プロジェクト: jrahaim/xbmc
void CNetworkInterfaceLinux::GetSettings(NetworkAssignment& assignment, CStdString& ipAddress, CStdString& networkMask, CStdString& defaultGateway, CStdString& essId, CStdString& key, EncMode& encryptionMode)
{
    ipAddress = "0.0.0.0";
    networkMask = "0.0.0.0";
    defaultGateway = "0.0.0.0";
    essId = "";
    key = "";
    encryptionMode = ENC_NONE;
    assignment = NETWORK_DISABLED;

#if defined(TARGET_LINUX)
    FILE* fp = fopen("/etc/network/interfaces", "r");
    if (!fp)
    {
        // TODO
        return;
    }

    char* line = NULL;
    size_t linel = 0;
    CStdString s;
    bool foundInterface = false;

    while (getdelim(&line, &linel, '\n', fp) > 0)
    {
        vector<CStdString> tokens;

        s = line;
        s.TrimLeft(" \t").TrimRight(" \n");

        // skip comments
        if (s.length() == 0 || s.GetAt(0) == '#')
            continue;

        // look for "iface <interface name> inet"
        CUtil::Tokenize(s, tokens, " ");
        if (!foundInterface &&
                tokens.size() >=3 &&
                tokens[0].Equals("iface") &&
                tokens[1].Equals(GetName()) &&
                tokens[2].Equals("inet"))
        {
            if (tokens[3].Equals("dhcp"))
            {
                assignment = NETWORK_DHCP;
                foundInterface = true;
            }
            if (tokens[3].Equals("static"))
            {
                assignment = NETWORK_STATIC;
                foundInterface = true;
            }
        }

        if (foundInterface && tokens.size() == 2)
        {
            if (tokens[0].Equals("address")) ipAddress = tokens[1];
            else if (tokens[0].Equals("netmask")) networkMask = tokens[1];
            else if (tokens[0].Equals("gateway")) defaultGateway = tokens[1];
            else if (tokens[0].Equals("wireless-essid")) essId = tokens[1];
            else if (tokens[0].Equals("wireless-key"))
            {
                key = tokens[1];
                if (key.length() > 2 && key[0] == 's' && key[1] == ':')
                    key.erase(0, 2);
                encryptionMode = ENC_WEP;
            }
            else if (tokens[0].Equals("wpa-ssid")) essId = tokens[1];
            else if (tokens[0].Equals("wpa-proto") && tokens[1].Equals("WPA")) encryptionMode = ENC_WPA;
            else if (tokens[0].Equals("wpa-proto") && tokens[1].Equals("WPA2")) encryptionMode = ENC_WPA2;
            else if (tokens[0].Equals("wpa-psk")) key = tokens[1];
            else if (tokens[0].Equals("auto") || tokens[0].Equals("iface") || tokens[0].Equals("mapping")) break;
        }
    }
    free(line);

    // Fallback in case wpa-proto is not set
    if (key != "" && encryptionMode == ENC_NONE)
        encryptionMode = ENC_WPA;

    fclose(fp);
#endif
}
コード例 #11
0
ファイル: ObjectEntry.cpp プロジェクト: RIVeR-Lab/eposcmd
BOOL CObjectEntry::SetValue(CStdString strValue)
{
    CMmcDataConversion conversion;
    BOOL oResult(FALSE);

    //Reset
    ResetValue();

    //SetValue
    switch(m_DataType)
    {
        case ODT_BOOLEAN:
            {
                if(InitValue(sizeof(WORD)))
                {
                    if(strValue.CompareNoCase("TRUE") == 0)
                    {
                        *((WORD*)m_pValue) = TRUE;
                        oResult = TRUE;
                    }
                    else
                    {
                        *((WORD*)m_pValue) = FALSE;
                        oResult = TRUE;
                    }
                }
            };break;

        case ODT_INT8:
            {
                if(InitValue(sizeof(char)))
                {
                    oResult = conversion.CharStr2Char(strValue, ((char*)m_pValue), FALSE);
                }
            };break;
        case ODT_INT16:
            {
                if(InitValue(sizeof(short)))
                {
                    oResult = conversion.ShortStr2Short(strValue, ((short*)m_pValue), FALSE);
                }
            };break;
        case ODT_INT32:
            {
                if(InitValue(sizeof(long)))
                {
                    oResult = conversion.LongStr2Long(strValue, ((long*)m_pValue), FALSE);
                }
            };break;
        case ODT_INT64:
            {
                if(InitValue(sizeof(__int64)))
                {
                    oResult = conversion.Int64Str2Int64(strValue, ((__int64*)m_pValue), FALSE);
                }
            };break;
        case ODT_UINT8:
            {
                if(InitValue(sizeof(BYTE)))
                {
                    oResult = conversion.ByteStr2Byte(strValue, ((BYTE*)m_pValue), FALSE);
                }
            };break;
        case ODT_UINT16:
            {
                if(InitValue(sizeof(WORD)))
                {
                    oResult = conversion.WordStr2Word(strValue, ((WORD*)m_pValue));
                }
            };break;
        case ODT_UINT32:
            {
                if(InitValue(sizeof(DWORD)))
                {
                    oResult = conversion.DWordStr2DWord(strValue, ((DWORD*)m_pValue), FALSE);
                }
            };break;
        case ODT_UINT64:
            {
                if(InitValue(sizeof(unsigned __int64)))
                {
                    oResult = conversion.UInt64Str2UInt64(strValue, ((unsigned __int64*)m_pValue), FALSE);
                }
            };break;
        case ODT_FLOAT:
            {
                if(InitValue(sizeof(float)))
                {
                    oResult = conversion.FloatStr2Float(strValue, ((float*)m_pValue), FALSE);
                }
            };break;
        case ODT_STRING:
            {
                if(InitValue(strlen(strValue))*sizeof(TCHAR))
                {
                    for(DWORD d=0;d<m_dValueSize;d++)
                    {
                        *((TCHAR*)m_pValue+d) = strValue.GetAt(d);
                    }
                    oResult = TRUE;
                }
            };break;
    }

    return oResult;
}
コード例 #12
0
void CNetworkInterfaceLinux::SetSettings(NetworkAssignment& assignment, CStdString& ipAddress, CStdString& networkMask, CStdString& defaultGateway, CStdString& essId, CStdString& key, EncMode& encryptionMode)
{
#ifndef __APPLE__
   FILE* fr = fopen("/etc/network/interfaces", "r");
   if (!fr)
   {
      // TODO
      return;
   }

   FILE* fw = fopen("/tmp/interfaces.temp", "w");
   if (!fw)
   {
      // TODO
      return;
   }

   char* line = NULL;
   size_t linel = 0;
   CStdString s;
   bool foundInterface = false;
   bool dataWritten = false;

   while (getdelim(&line, &linel, '\n', fr) > 0)
   {
      vector<CStdString> tokens;

      s = line;
      s.TrimLeft(" \t").TrimRight(" \n");

      // skip comments
      if (!foundInterface && (s.length() == 0 || s.GetAt(0) == '#'))
      {
        fprintf(fw, "%s", line);
        continue;
      }

      // look for "iface <interface name> inet"
      CUtil::Tokenize(s, tokens, " ");
      if (tokens.size() == 2 &&
          tokens[0].Equals("auto") &&
          tokens[1].Equals(GetName()))
      {
         continue;
      }
      else if (!foundInterface &&
          tokens.size() == 4 &&
          tokens[0].Equals("iface") &&
          tokens[1].Equals(GetName()) &&
          tokens[2].Equals("inet"))
      {
         foundInterface = true;
         WriteSettings(fw, assignment, ipAddress, networkMask, defaultGateway, essId, key, encryptionMode);
         dataWritten = true;
      }
      else if (foundInterface &&
               tokens.size() == 4 &&
               tokens[0].Equals("iface"))
      {
        foundInterface = false;
        fprintf(fw, "%s", line);
      }
      else if (!foundInterface)
      {
        fprintf(fw, "%s", line);
      }
   }

   if (line)
     free(line);

   if (!dataWritten && assignment != NETWORK_DISABLED)
   {
      fprintf(fw, "\n");
      WriteSettings(fw, assignment, ipAddress, networkMask, defaultGateway, essId, key, encryptionMode);
   }

   fclose(fr);
   fclose(fw);

   // Rename the file
   // NEUROS: Since on the Link we have sudo setup with no password, this will always work
   system("sudo cp /tmp/interfaces.temp /etc/network/interfaces");

   CLog::Log(LOGINFO, "Stopping interface %s", GetName().c_str());
   std::string cmd = "sudo /sbin/ifdown " + GetName();
   system(cmd.c_str());

   if (assignment != NETWORK_DISABLED)
   {
      CLog::Log(LOGINFO, "Starting interface %s", GetName().c_str());
      cmd = "sudo /sbin/ifup " + GetName();
      system(cmd.c_str());
   }
#endif
}
コード例 #13
0
ファイル: OrkClient.cpp プロジェクト: havoc83/oreka
bool OrkHttpClient::ExecuteUrl(const CStdString& request, CStdString& response, const CStdString& hostname, const int tcpPort, int timeout)
{
	CStdString logMsg;
	response = "";
	ACE_SOCK_Connector  connector;
	ACE_SOCK_Stream peer;
	ACE_INET_Addr peer_addr;
	if(timeout < 1){timeout = 1;}
	ACE_Time_Value aceTimeout (timeout);
	CStdString requestDetails;
	requestDetails.Format("timeout:%d http://%s:%d/%s", timeout, hostname, tcpPort, request);
	time_t beginRequestTimestamp = time(NULL);

	char szTcpPort[10];
	sprintf(szTcpPort, "%d", tcpPort);
	iovec iov[8];
	iov[0].iov_base = (IOV_TYPE)"GET ";
	iov[0].iov_len = 4; // Length of "GET ".
	iov[1].iov_base = (PSTR)(PCSTR)request;
	iov[1].iov_len = request.size();
	iov[2].iov_base = (IOV_TYPE)" HTTP/1.0\r\n";
	iov[2].iov_len = 11;
	iov[3].iov_base = (IOV_TYPE)"Host: ";
	iov[3].iov_len = 6;
	iov[4].iov_base = (PSTR)(PCSTR)hostname;
	iov[4].iov_len = hostname.size();
	iov[5].iov_base = (IOV_TYPE)":";
	iov[5].iov_len = 1;
	iov[6].iov_base = szTcpPort;
	iov[6].iov_len = strlen(szTcpPort);
	iov[7].iov_base = (IOV_TYPE)"\r\n\r\n";
	iov[7].iov_len = 4;

	if (peer_addr.set (tcpPort, (PCSTR)hostname) == -1)
	{
		logMsg.Format("peer_addr.set()  errno=%d %s", errno, requestDetails);
		LogError(logMsg);
		return false;
	}
	else if (connector.connect (peer, peer_addr, &aceTimeout) == -1)
	{
		if (errno == ETIME)
		{
		}
		logMsg.Format("connector.connect()  errno=%d %s", errno, requestDetails);
		LogError(logMsg);
		return false;
	}
	else if (peer.sendv_n (iov, 8, &aceTimeout) == -1)
	{
		logMsg.Format("peer.sendv_n  errno=%d %s", errno, requestDetails);
		LogError(logMsg);
		return false;
	}

	ssize_t numReceived = 0;
#define BUFSIZE 4096
	char buf [BUFSIZE];

	CStdString header;
	bool gotHeader = false;
	while ( ((numReceived = peer.recv (buf, BUFSIZE, &aceTimeout)) > 0)  && ((time(NULL) - beginRequestTimestamp) <= timeout) )
	{
		for(int i=0; i<numReceived; i++)
		{
			if(!gotHeader)
			{
				// extract header (delimited by CR-LF-CR-LF)
				header += buf[i];
				size_t headerSize = header.size();
				if (headerSize > 4 &&
					header.GetAt(headerSize-1) == '\n' && 
					header.GetAt(headerSize-2) == '\r' &&
					header.GetAt(headerSize-3) == '\n' &&
					header.GetAt(headerSize-4) == '\r'		)
				{
					gotHeader = true;
				}
			}
			else
			{
				// extract content
				response += buf[i];
			}
		}
	}
	peer.close();
	
	logMsg.Format("%s:%d response:%s",hostname, tcpPort, response);
	LOG4CXX_DEBUG(m_log, logMsg);
	if(numReceived < 0)
	{
		logMsg.Format("numReceived:%d %s", numReceived, requestDetails);
		LogError(logMsg);
		return false;
	}
	if(header.size() > 15 && header.GetAt(9) == '4' && header.GetAt(10) == '0' && header.GetAt(11) == '0')
	{
		logMsg.Format("HTTP header:%s ** request:%s\nIgnore this message", header, requestDetails);
		LOG4CXX_ERROR(m_log, logMsg);
		return true;
	}
	if(header.size() < 15 || response.size() <= 0)
	{
		logMsg.Format("HTTP header:%s ** request:%s ** response:%s ** header size:%d  response size:%d", header, requestDetails, response, header.size(), response.size());
		LogError(logMsg);
		return false;
	}
	if(	header.GetAt(9) != '2' ||
		header.GetAt(10) != '0' ||
		header.GetAt(11) != '0' ||
		header.GetAt(12) != ' ' ||
		header.GetAt(13) != 'O' ||
		header.GetAt(14) != 'K'		)
	{
		logMsg.Format("HTTP header:%s ** request:%s", header, requestDetails);
		LogError(logMsg);
		return false;
	}
	return true;
}