ECode HttpURLConnection::GetResponseCode(
    /* [out] */ Int32* responseCode)
{
    VALIDATE_NOT_NULL(responseCode)

    // Call getInputStream() first since getHeaderField() doesn't return
    // exceptions
    AutoPtr<IInputStream> is;
    FAIL_RETURN(GetInputStream((IInputStream**)&is));
    String response;
    GetHeaderField(0, &response);
    if (response.IsNull()) {
        *responseCode = -1;
        return NOERROR;
    }
    response = response.Trim();
    Int32 mark = response.IndexOf(" ") + 1;
    if (mark == 0) {
        *responseCode = -1;
        return NOERROR;
    }
    Int32 last = mark + 3;
    if (last > response.GetLength()) {
        last = response.GetLength();
    }
    mResponseCode = StringUtils::ParseInt32(response.Substring(mark, last));
    if ((last + 1) <= response.GetLength()) {
        mResponseMessage = response.Substring(last + 1);
    }
    *responseCode = mResponseCode;
    return NOERROR;
}
Example #2
0
String Base64::Decode(const String& input)
{
	BIO *biomem = BIO_new_mem_buf(
		const_cast<char*>(input.CStr()), input.GetLength());
	BIO *bio64 = BIO_new(BIO_f_base64());
	BIO_push(bio64, biomem);
	BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);

	auto *outbuf = new char[input.GetLength()];

	size_t len = 0;
	int rc;

	while ((rc = BIO_read(bio64, outbuf + len, input.GetLength() - len)) > 0)
		len += rc;

	String ret = String(outbuf, outbuf + len);
	BIO_free_all(bio64);
	delete [] outbuf;

	if (ret.IsEmpty() && !input.IsEmpty())
		throw std::invalid_argument("Not a valid base64 string");

	return ret;
}
Example #3
0
void HttpRequest::FinishHeaders()
{
	if (m_State == HttpRequestStart) {
		String rqline = RequestMethod + " " + RequestUrl->Format(true) + " HTTP/1." + (ProtocolVersion == HttpVersion10 ? "0" : "1") + "\r\n";
		m_Stream->Write(rqline.CStr(), rqline.GetLength());
		m_State = HttpRequestHeaders;
	}

	if (m_State == HttpRequestHeaders) {
		AddHeader("User-Agent", "Icinga/" + Application::GetAppVersion());

		if (ProtocolVersion == HttpVersion11) {
			AddHeader("Transfer-Encoding", "chunked");
			if (!Headers->Contains("Host"))
				AddHeader("Host", RequestUrl->GetHost() + ":" + RequestUrl->GetPort());
		}

		ObjectLock olock(Headers);
		for (const Dictionary::Pair& kv : Headers)
		{
			String header = kv.first + ": " + kv.second + "\r\n";
			m_Stream->Write(header.CStr(), header.GetLength());
		}

		m_Stream->Write("\r\n", 2);

		m_State = HttpRequestBody;
	}
}
Example #4
0
String UrlUtils::CanonicalizePath(
    /* [in] */ const String& _path,
    /* [in] */ Boolean discardRelativePrefix)
{
    String path = _path;
    // the first character of the current path segment
    Int32 segmentStart = 0;

    // the number of segments seen thus far that can be erased by sequences of '..'.
    Int32 deletableSegments = 0;

    for (Int32 i = 0; i <= path.GetLength(); ) {
        Int32 nextSegmentStart;
        if (i == path.GetLength()) {
            nextSegmentStart = i;
        } else if (path.GetChar(i) == '/') {
            nextSegmentStart = i + 1;
        } else {
            i++;
            continue;
        }

        /*
         * We've encountered either the end of a segment or the end of the
         * complete path. If the final segment was "." or "..", remove the
         * appropriate segments of the path.
         */
        if (i == segmentStart + 1 && path.RegionMatches(segmentStart, String("."), 0, 1)) {
            // Given "abc/def/./ghi", remove "./" to get "abc/def/ghi".
            String part = path.Substring(0, segmentStart);
            part += path.Substring(nextSegmentStart);
            path = part;
            i = segmentStart;
        }
        else if (i == segmentStart + 2 && path.RegionMatches(segmentStart, String(".."), 0, 2)) {
            if (deletableSegments > 0 || discardRelativePrefix) {
                // Given "abc/def/../ghi", remove "def/../" to get "abc/ghi".
                deletableSegments--;
                Int32 prevSegmentStart = path.LastIndexOf('/', segmentStart - 2) + 1;
                String part = path.Substring(0, prevSegmentStart);
                part += path.Substring(nextSegmentStart);
                path = part;
                i = segmentStart = prevSegmentStart;
            }
            else {
                // There's no segment to delete; this ".." segment must be retained.
                i++;
                segmentStart = i;
            }
        }
        else {
            if (i > 0) {
                deletableSegments++;
            }
            i++;
            segmentStart = i;
        }
    }
    return path;
}
HGLOBAL POTraceCtl::CreateDropFilesW(const String& strUrl)
{
	int nBufferSize = sizeof(DROPFILES) + sizeof(wchar) * (strUrl.GetLength() + 1) + sizeof(wchar);

	// Allocate memory from the heap for the DROPFILES struct.
	HGLOBAL hgDrop = GlobalAlloc( GHND | GMEM_SHARE, nBufferSize);
	if( NULL == hgDrop )
		return 0;
	
	DROPFILES* pDrop = (DROPFILES*) GlobalLock(hgDrop);
	if( NULL == pDrop )
	{
		GlobalFree(hgDrop);
		return 0;
	}

	pDrop->pFiles = sizeof(DROPFILES);
	pDrop->fWide = TRUE;

	wchar* pszBuff = (wchar*) (LPBYTE(pDrop) + sizeof(DROPFILES));
	chustd::Memory::Copy16(pszBuff, strUrl.GetBuffer(), strUrl.GetLength() + 1);
	
	GlobalUnlock(hgDrop);

	return hgDrop;
}
Example #6
0
ECode Proxy::Validate(
    /* [in] */ const String& hostname,
    /* [in] */ const String& port,
    /* [in] */ const String& exclList,
    /* [out] */ Int32* result)
{
    VALIDATE_NOT_NULL(result)

    AutoPtr<IMatcher> match;
    HOSTNAME_PATTERN->Matcher(hostname, (IMatcher**)&match);
    AutoPtr<IMatcher> listMatch;
    EXCLLIST_PATTERN->Matcher(exclList, (IMatcher**)&listMatch);
    Boolean isMatch;
    if (match->Matches(&isMatch), !isMatch) {
        *result = IProxy::PROXY_HOSTNAME_INVALID;
        return NOERROR;
    }
    if (listMatch->Matches(&isMatch), !isMatch) {
        *result = IProxy::PROXY_EXCLLIST_INVALID;
        return NOERROR;
    }
    if (hostname.GetLength() > 0 && port.GetLength() == 0) {
        *result = IProxy::PROXY_PORT_EMPTY;
        return NOERROR;
    }
    if (port.GetLength() > 0) {
        if (hostname.GetLength() == 0) {
            *result = IProxy::PROXY_HOSTNAME_EMPTY;
            return NOERROR;
        }
        Int32 portVal = -1;
        // try {
        ECode ec = StringUtils::Parse(port, &portVal);
        // } catch (NumberFormatException ex) {
        if (FAILED(ec)) {
            if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) {
                *result = IProxy::PROXY_PORT_INVALID;
                return NOERROR;
            }
            else return ec;
        }
        // }
        if (portVal <= 0 || portVal > 0xFFFF) {
            *result = IProxy::PROXY_PORT_INVALID;
            return NOERROR;
        }
    }
    *result = IProxy::PROXY_VALID;
    return NOERROR;
}
Example #7
0
String CdmaMmiCode::MakeEmptyNull(
    /* [in] */ const String& s)
{
    if (!s.IsNull() && s.GetLength() == 0) return String(NULL);

    return s;
}
Example #8
0
/**
*  @brief
*    Constructor
*/
Buffer::Buffer(PLSound::SoundManager &cSoundManager, const String &sName, bool bStream) :
	PLSound::Buffer(cSoundManager, sName)
{
	// Load the sound buffer
	if (sName.GetLength())
		LoadBuffer(sName, bStream);
}
void CComposingView::OnDraw(
    /* [in] */ ICanvas* canvas)
{
    if (EDIT_PINYIN == mComposingStatus
            || SHOW_PINYIN == mComposingStatus) {
        DrawForPinyin(canvas);
        return;
    }

    Float x, y;
    Int32 top = 0;
    x = mPaddingLeft + LEFT_RIGHT_MARGIN;
    y = -(mFmi->GetTop(&top), top) + mPaddingTop;

    mPaint->SetColor(mStrColorHl);
    Int32 width, height;
    GetWidth(&width);
    GetHeight(&height);
    mHlDrawable->SetBounds(mPaddingLeft, mPaddingTop, width
            - mPaddingRight, height - mPaddingBottom);
    mHlDrawable->Draw(canvas);

    String splStr = mDecInfo->GetOrigianlSplStr()->ToString();
    canvas->DrawText(splStr, 0, splStr.GetLength(), x, y, mPaint);
}
void CComposingView::OnMeasure(
    /* [in] */ Int32 widthMeasureSpec,
    /* [in] */ Int32 heightMeasureSpec)
{
    Float width = 0.f;
    Int32 height = 0, bottom = 0, top = 0;
    height = (mFmi->GetBottom(&bottom), bottom) - (mFmi->GetTop(&top), top) + mPaddingTop + mPaddingBottom;

    if (NULL == mDecInfo) {
        width = 0;
    }
    else {
        width = mPaddingLeft + mPaddingRight + LEFT_RIGHT_MARGIN * 2;

        String str;
        if (SHOW_STRING_LOWERCASE == mComposingStatus) {
            str = mDecInfo->GetOrigianlSplStr()->ToString();
        }
        else {
            str = mDecInfo->GetComposingStrForDisplay();
        }
        Float value = 0.f;
        mPaint->MeasureText(str, 0, str.GetLength(), &value);
        width += value;
    }
    SetMeasuredDimension((Int32) (width + 0.5f), height);
}
Example #11
0
String::String(String& s)
{
	mLength = s.GetLength();
	mBuffer = new char[mLength+1];
	memset(mBuffer, 0, mLength+1);
	strncpy(mBuffer, s.string(), mLength);
}
Example #12
0
void StrUtil::WriteString(const String &s, Stream *out)
{
    size_t len = s.GetLength();
    out->WriteInt32(len);
    if (len > 0)
        out->Write(s.GetCStr(), len);
}
Example #13
0
   /// Returns true if the supplied UNC path contains a Share name.
   bool 
   FileUtilities::IsValidUNCFolder(const String &sPath)
   {
      if (!IsUNCPath(sPath))
         return false;

      // We have at least \\server

      int shareStartPos = sPath.Find(_T("\\"), 3);
      if (shareStartPos < 0)
         return false;

      // We have at least \\server\

      int folderStartPos = sPath.Find(_T("\\"), shareStartPos + 1);
      if (folderStartPos < 0)
         return false;

      // We have at least \\server\share\

      int length = sPath.GetLength();
      if (folderStartPos == length-1)
         return false;

      // We have something after \\server\share. That is a folder.
      return true;
   }
Example #14
0
bool String::operator < (const String& compareTo) const
{
	//return !( (*this) > compareTo );
	int size1 = (*this).GetLength();
	int size2 = compareTo.GetLength();
	return ( size1 < size2 );
}
Example #15
0
// Concatenation operator
String String::operator + (const String& aString) const
{
	int size1 = GetLength(Text);
	int size2 = aString.GetLength();

	// +1 accounts for NULL-terminator
	int trueLength = size1 + size2 + 1;

	String concText = String(trueLength);
	

	// Copy all characters from source to concText; +1 accounts for NULL-terminator
	int i = 0;
	while ( i < trueLength )
	{
		if ( i < size1 )
		{
			concText[i] = Text[i];
		}
		else
		{
			concText[i] = aString[i-size1];
		}
		i++;
	}

	return concText;
}
Example #16
0
//[-------------------------------------------------------]
//[ Public virtual PLDatabase::DatabaseQuery functions    ]
//[-------------------------------------------------------]
PLDatabase::DatabaseQueryResult *DatabaseQuery::Execute(const String &sSQL)
{
	PGconn   *pPostgreSQL = static_cast<Database&>(GetDatabase()).GetPostgreSQL();
	PGresult *pResult     = PQexec(pPostgreSQL, sSQL);
	if (pResult) {
		const int nStatus = PQresultStatus(pResult);
		if (PQresultStatus(pResult) == PGRES_TUPLES_OK) {
			// Return the result
			return new DatabaseQueryResult(*this, *pResult);
		}

		// Get the error message
		String sMessage;
		if (nStatus == PGRES_FATAL_ERROR || nStatus == PGRES_NONFATAL_ERROR)
			sMessage = PQresultErrorMessage(pResult);

		// Cleanup
		PQclear(pResult);

		// Print the error message
		if (sMessage.GetLength())
			PL_LOG(Error, "PostgreSQL can't execute the given SQL statement! Error: " + sMessage)
		else
			PL_LOG(Error, "PostgreSQL can't execute the given SQL statement!")
	} else {
Example #17
0
   void
   StringParser::Base64Decode(const String &sInput, String &sOutput)
   {

      if (sInput.GetLength() == 0)
      {
         sOutput.Empty();
         return;
      }

      AnsiString sInputStr = sInput;

      MimeCodeBase64 DeCoder;
      DeCoder.AddLineBreak(false);
      DeCoder.SetInput(sInputStr, sInputStr.GetLength(), false);
      
      AnsiString output;
      DeCoder.GetOutput(output);

      int length = output.GetLength();
      // Since we're going to store the result in
      // a normal StdString, we can't return null
      // characters.
      for (int i = 0; i < length; i++)
      {
         if (output[i] == 0)
            output[i] = '\t';
      }

      sOutput = output;
   }
Example #18
0
Int32 CSplitClockView::GetAmPmPartEndIndex(
    /* [in] */ const String& formatString)
{
    Boolean hasAmPm = FALSE;
    Int32 length = formatString.GetLength();
    for (Int32 i = length - 1; i >= 0; i--) {
        Char32 c = formatString.GetChar(i);
        Boolean isAmPm = c == 'a';
        Boolean isWhitespace = Character::IsWhitespace(c);
        if (isAmPm) {
            hasAmPm = TRUE;
        }
        if (isAmPm || isWhitespace) {
            continue;
        }
        if (i == length - 1) {

            // First character was not AM/PM and not whitespace, so it's not ending with AM/PM.
            return -1;
        } else {

            // If we have AM/PM at all, return last index, or -1 to indicate that it's not
            // ending with AM/PM.
            return hasAmPm ? i + 1 : -1;
        }
    }

    // Only AM/PM and whitespaces? The whole string is AM/PM. Else: Only whitespaces in the
    // string.
    return hasAmPm ? 0 : -1;
}
Example #19
0
void HttpUtility::SendJsonBody(HttpResponse& response, const Value& val)
{
	response.AddHeader("Content-Type", "application/json");

	String body = JsonEncode(val);
	response.WriteBody(body.CStr(), body.GetLength());
}
Example #20
0
/*
*  @brief
*    AngelScript function callback
*/
void Script::AngelScriptFunctionCallback(asIScriptGeneric *pAngelScriptGeneric)
{
	// Get the global function
	GlobalFunction *psGlobalFunction = reinterpret_cast<GlobalFunction*>(pAngelScriptGeneric->GetFunctionUserData());

	// Get the number of arguments AngelScript gave to us and transform the arguments into a functor parameters string
	String sParams;
	const int nNumOfArguments = pAngelScriptGeneric->GetArgCount();
	for (int i=0; i<nNumOfArguments; i++) {
		String sValue;
		const int nAngelScriptArgTypeId = pAngelScriptGeneric->GetArgTypeId(i);
		switch (nAngelScriptArgTypeId) {
			case asTYPEID_BOOL:		sValue = pAngelScriptGeneric->GetArgByte(i);						break;
			case asTYPEID_INT8:		sValue = pAngelScriptGeneric->GetArgByte(i);						break;
			case asTYPEID_INT16:	sValue = static_cast<int16>(pAngelScriptGeneric->GetArgWord(i));	break;
			case asTYPEID_INT32:	sValue = static_cast<int32>(pAngelScriptGeneric->GetArgDWord(i));	break;
			case asTYPEID_INT64:	sValue = pAngelScriptGeneric->GetArgQWord(i);						break;
			case asTYPEID_UINT8:	sValue = pAngelScriptGeneric->GetArgByte(i);						break;
			case asTYPEID_UINT16:	sValue = static_cast<uint32>(pAngelScriptGeneric->GetArgWord(i));	break;
			case asTYPEID_UINT32:	sValue = static_cast<uint32>(pAngelScriptGeneric->GetArgDWord(i));	break;
			case asTYPEID_UINT64:	sValue = pAngelScriptGeneric->GetArgQWord(i);						break;
			case asTYPEID_FLOAT:	sValue = pAngelScriptGeneric->GetArgFloat(i);						break;
			case asTYPEID_DOUBLE:	sValue = pAngelScriptGeneric->GetArgDouble(i);						break;
			default:
				// Is it a string?
				if (nAngelScriptArgTypeId == pAngelScriptGeneric->GetEngine()->GetTypeIdByDecl("string"))
					sValue = static_cast<std::string*>(pAngelScriptGeneric->GetArgObject(i))->c_str();
				else
					; // Do nothing
				break;
		}

		// Add to functor parameters
		sParams += String("Param") + i + "=\"" + sValue + "\" ";
	}

	// Call the functor
	const String sReturn = psGlobalFunction->pDynFunc->CallWithReturn(sParams);

	// Process the functor return
	if (sReturn.GetLength()) {
		switch (psGlobalFunction->pDynFunc->GetReturnTypeID()) {
			case TypeBool:		pAngelScriptGeneric->SetReturnByte(sReturn.GetBool());												break;
			case TypeDouble:	pAngelScriptGeneric->SetReturnDouble(sReturn.GetDouble());											break;
			case TypeFloat:		pAngelScriptGeneric->SetReturnFloat(sReturn.GetFloat());											break;
			case TypeInt:		pAngelScriptGeneric->SetReturnDWord(sReturn.GetInt());												break;
			case TypeInt16:		pAngelScriptGeneric->SetReturnWord(static_cast<asWORD>(sReturn.GetInt()));							break;
			case TypeInt32:		pAngelScriptGeneric->SetReturnDWord(sReturn.GetInt());												break;
			case TypeInt64:		pAngelScriptGeneric->SetReturnQWord(sReturn.GetInt64());											break;
			case TypeInt8:		pAngelScriptGeneric->SetReturnByte(static_cast<asBYTE>(sReturn.GetInt()));							break;
			case TypeString:	pAngelScriptGeneric->SetReturnAddress(new CScriptString(sReturn.GetASCII(), sReturn.GetLength()));	break;	// AngelScript takes over the control of the allocated object
			case TypeUInt16:	pAngelScriptGeneric->SetReturnWord(sReturn.GetUInt16());											break;
			case TypeUInt32:	pAngelScriptGeneric->SetReturnDWord(sReturn.GetUInt32());											break;
			case TypeUInt64:	pAngelScriptGeneric->SetReturnQWord(sReturn.GetUInt64());											break;
			case TypeUInt8:		pAngelScriptGeneric->SetReturnByte(sReturn.GetUInt8());												break;
			default:																												break;
		}
	}
}
Example #21
0
int StrUtil::StringToInt(const String &s, int def_val)
{
    if (!s.GetCStr())
        return def_val;
    char *stop_ptr;
    int val = strtol(s.GetCStr(), &stop_ptr, 0);
    return (stop_ptr == s.GetCStr() + s.GetLength()) ? val : def_val;
}
Example #22
0
void Script::PushArgument(const String &sString)
{
	if (m_pAngelScriptContext) {
		CScriptString *pCScriptString = new CScriptString(sString.GetASCII(), sString.GetLength());
		m_pAngelScriptContext->SetArgObject(m_nCurrentArgument++, pCScriptString);
		pCScriptString->Release();	// Destroy our CScriptString instance
	}
}
Example #23
0
bool Script::BeginCall(const String &sFunctionName, const String &sFunctionSignature, const String &sNamespace)
{
	// [TODO] Add namespace support
	if (sNamespace.GetLength())
		return false;	// Error! Not implemented, yet. Get us out of here right now!

	// There must be a valid AngelScript engine and module instance
	if (m_pAngelScriptEngine && m_pAngelScriptModule) {
		// Is there already a context instance that will execute the script?
		if (!m_pAngelScriptContext) {
			m_pAngelScriptContext = m_pAngelScriptEngine->CreateContext();
			if (!m_pAngelScriptContext)
				LogOutput(Log::Error, "Failed to create the context");

			// [TODO] Add SetLineCallback
			//		cout << "Failed to set the line callback function." << endl;
		}
		if (m_pAngelScriptContext) {
			// Get the AngelScript function declaration
			const String sFunctionDeclaration = GetAngelScriptFunctionDeclaration(sFunctionName, sFunctionSignature, false);

			// Find the function ID for the function we want to execute
			const int nFunctionID = m_pAngelScriptModule->GetFunctionIdByDecl(sFunctionDeclaration);
			if (nFunctionID >= 0) {
				// Prepare the script context with the function we wish to execute
				int nResult = m_pAngelScriptContext->Prepare(nFunctionID);
				if (nResult >= 0) {
					// Current argument is 0
					m_nCurrentArgument = 0;

					// Done
					return true;
				} else {
					// Error!
					String sErrorDescription;
					switch (nResult) {
						case asCONTEXT_ACTIVE:
							// If your're here, you may have tried to call a script function by using PixelLights functors,
							// AngelScript can only run one function per script context call...
							sErrorDescription = " (The context is still active or suspended)";
							break;

						case asNO_FUNCTION:
							sErrorDescription = " (The function id doesn't exist)";
							break;
					}
					LogOutput(Log::Error, "Failed to prepare the context for the function '" + sFunctionDeclaration + "'" + sErrorDescription);
				}
			} else {
				// Error!
				LogOutput(Log::Error, "The function '" + sFunctionDeclaration + "' was not found");
			}
		}
	}

	// Error!
	return false;
}
Example #24
0
bool CryptoHash::Digest(
    const HashType hashType,
    const String& data,
    OTData& digest)
{
    OTData plaintext(data.Get(), data.GetLength());

    return Digest(hashType, plaintext, digest);
}
// FIXME: leaks
result RichTextPanel::Construct(const Dimension& dim, const String & text) {
	result r = E_SUCCESS;
	TextElement* textElement;
	int width, height;
	Color color = Color::GetColor(COLOR_ID_WHITE);
	Font font;

	Dimension textDim;
	int textActualLen;

	enrichedText = new EnrichedText();
	r = enrichedText->Construct(dim);
	TryCatch(r == E_SUCCESS, , "Failed Construct EnrichedText");

	r = font.Construct(FONT_STYLE_PLAIN, TEXT_FONT_SIZE);
	TryCatch(r == E_SUCCESS, , "Failed Construct Font");

	textElement = new TextElement();
	r = textElement->Construct(text);
	TryCatch(r == E_SUCCESS, , "Failed TextElement");
	r = textElement->SetTextColor(color);
	TryCatch(r == E_SUCCESS, , "Failed SetTextColor");
	r = textElement->SetFont(font);
	TryCatch(r == E_SUCCESS, , "Failed SetFont");

	r = enrichedText->Add(*textElement);
	TryCatch(r == E_SUCCESS, , "Failed Add textElement");


	height = enrichedText->GetTotalLineHeight();

	r = enrichedText->GetTextExtent(0, text.GetLength(), textDim, textActualLen);
	TryCatch(r == E_SUCCESS, , "Failed GetTextExtent");
	width = dim.width < textDim.width ? dim.width : textDim.width;

	r = Panel::Construct(Rectangle(0, 0, width, height));
	TryCatch(r == E_SUCCESS, , "Failed Construct RichTextPanel parent");

	TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult(), "Failed GetSize");
	AppLog("Size received: %d x %d", width, height);

	r = SetSize(width, height);
	TryCatch(r == E_SUCCESS, , "Failed SetSize");

//	SetBackgroundColor(color);
	TryCatch(GetLastResult() == E_SUCCESS, r = GetLastResult(), "Failed SetBackgroundColor");

	return r;

	CATCH:
	    AppLogException("$${Function:Construct} is failed.", GetErrorMessage(r));

	    if (textElement)
	    	delete textElement;

	    return r;
}
Example #26
0
//[-------------------------------------------------------]
//[ Public virtual PLCore::Script functions               ]
//[-------------------------------------------------------]
bool Script::IsGlobalFunction(const String &sName, const String &sNamespace)
{
	// [TODO] Add namespace support
	if (sNamespace.GetLength())
		return false;	// Not implemented, yet. Get us out of here right now!

	// There must be a valid AngelScript engine and module instance
	return (m_pAngelScriptEngine && m_pAngelScriptModule && m_pAngelScriptModule->GetFunctionIdByName(sName) >= 0);
}
Example #27
0
   bool
   MailImporter::GetRootLevelDirectory_(const String &fullPath, String &rootLevel)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Takes an input parameter such as C:\DataDir\Account\Sub1\Sub2\Test.eml and
   // returns the root of that hierarcy, such as C:\Datadir\Account in this case.
   //---------------------------------------------------------------------------()
   {
      // The file must be located in the data directory. Make sure this is the case.
      const String dataDirectory = IniFileSettings::Instance()->GetDataDirectory();

      if (!fullPath.StartsWith(dataDirectory))
         return false;

      int currentTrimPosition = dataDirectory.GetLength() + 1;

      const String publicFolderName = IMAPConfiguration::GetPublicFolderDiskName();

      // Is the file located in the public folder?
      if (fullPath.FindNoCase(publicFolderName, currentTrimPosition) == currentTrimPosition)
      {
         // The file is located in the public folder.
         currentTrimPosition += publicFolderName.GetLength() + 1;
      }
      else
      {
         // The file is either located in the queue folder or in an account folder.
         int slashPosition = fullPath.Find(_T("\\"), currentTrimPosition);
         if (slashPosition < 0)
            return false;

         int accountSlashPosition = fullPath.Find(_T("\\"), slashPosition+1);

         if (accountSlashPosition > 0)
         {
            // The file is locate din the queue folder.
            currentTrimPosition = accountSlashPosition+1;
         }
      }

      rootLevel = fullPath.Mid(0, currentTrimPosition);
      return true;
   }
Example #28
0
bool CryptoHash::HMAC(
        const CryptoHash::HashType hashType,
        const OTPassword& inputKey,
        const String& inputData,
        OTPassword& outputDigest) const
{
    OTData convertedData(inputData.Get(), inputData.GetLength());

    return HMAC(hashType, inputKey, convertedData, outputDigest);
}
String WifiTile::RemoveDoubleQuotes(
    /* [in] */ const String& string)
{
    if (string == NULL) return String(NULL);
    const Int32 length = string.GetLength();
    if ((length > 1) && (string.GetChar(0) == '"') && (string.GetChar(length - 1) == '"')) {
        return string.Substring(1, length - 1);
    }
    return string;
}
Example #30
0
void HttpResponse::AddHeader(const String& key, const String& value)
{
	if (m_State != HttpResponseHeaders) {
		Log(LogWarning, "HttpResponse", "Tried to add header after headers had already been sent.");
		return;
	}

	String header = key + ": " + value + "\r\n";
	m_Stream->Write(header.CStr(), header.GetLength());
}