Beispiel #1
0
BasicString *Stack::Description() const
{
  if (mIsNull)
    return String::New("null");

  String *description = String::New("[");
  
  SinglyLinkedNode *node = mFront;
  bool first = true;
  
  Object *item;
  
  while (node)
  {
    if ((item = static_cast<Object*>(node->Value)))
    {
      BasicString *tmp = item->Description();

      if (!first)
        description->AppendChar(',');
      
      if (first)
        first = false;
        
      description->AppendString(tmp);
      
      UnReference(tmp);
    }
    node = node->Next;
  }
  description->AppendChar(']');
  return description;
}
void XStringLog::Append(CTSTR tstr, UINT len, bool linefeed)
{
    if (stopped) return;

    String str;
    str.AppendString(tstr, len);
    Append(str, linefeed);
}
Beispiel #3
0
void  XConfig::SaveTo(CTSTR lpPath)
{
    if (RootElement)
    {
        String tmpPath = lpPath;
        tmpPath.AppendString(TEXT(".tmp"));

        XFile file;
        if (file.Open(tmpPath, XFILE_WRITE, XFILE_CREATEALWAYS))
        {
            if (WriteFileData(file, 0, RootElement))
            {
                file.Close();
                OSRenameFile(tmpPath, lpPath);
            }
            else
            {
                Log(TEXT("XConfig::SaveTo: WriteFileData failed while writing %s."), lpPath);
            }
        }
    }
}
Beispiel #4
0
void  XConfig::Save()
{
    if(RootElement)
    {
        String tmpPath = strFileName;
        tmpPath.AppendString(TEXT(".tmp"));

        XFile file;
        if (file.Open(strFileName, XFILE_WRITE, XFILE_CREATEALWAYS))
        {
            if (WriteFileData(file, 0, RootElement))
            {
                file.Close();
                OSRenameFile(tmpPath, strFileName);
            }
            else
            {
                Log(TEXT("XConfig::Save: WriteFileData failed while writing %s."), strFileName.Array());
            }
        }
    }
}
String   String::ToLower() const 
{
    UInt32      c;
    const char* psource = GetData()->Data;
    const char* pend = psource + GetData()->GetSize();
    String      str;
    SPInt       bufferOffset = 0;
    char        buffer[512];

    while(psource < pend)
    {
        do {
            c = UTF8Util::DecodeNextChar_Advance0(&psource);
            UTF8Util::EncodeChar(buffer, &bufferOffset, OVR_towlower(wchar_t(c)));
        } while ((psource < pend) && (bufferOffset < SPInt(sizeof(buffer)-8)));

        // Append string a piece at a time.
        str.AppendString(buffer, bufferOffset);
        bufferOffset = 0;
    }

    return str;
}
Beispiel #6
0
BOOL ConfigFile::SaveAs(CTSTR lpPath)
{
    XFile newFile;
    
    String tmpPath = lpPath;
    tmpPath.AppendString(TEXT(".tmp"));

    if (newFile.Open(tmpPath, XFILE_WRITE, XFILE_CREATEALWAYS))
    {
        if (newFile.Write("\xEF\xBB\xBF", 3) != 3)
            return FALSE;
        if (!newFile.WriteAsUTF8(lpFileData))
            return FALSE;

        newFile.Close();
        if (!OSRenameFile(tmpPath, lpPath))
            Log(TEXT("ConfigFile::SaveAs: Unable to move new config file %s to %s"), tmpPath.Array(), lpPath);

        strFileName = lpPath;
        return TRUE;
    }

    return FALSE;
}
Beispiel #7
0
String HTTPGetString (CTSTR url, CTSTR extraHeaders, int *responseCode, String verb)
{
    HINTERNET hSession = NULL;
    HINTERNET hConnect = NULL;
    HINTERNET hRequest = NULL;
    URL_COMPONENTS  urlComponents;
    BOOL secure = FALSE;
	String result = "";
	String body = TEXT("");
	String nurl = url;

    String hostName, path;

    const TCHAR *acceptTypes[] = {
        TEXT("*/*"),
        NULL
    };

	if (verb == TEXT("POST")){
		CTSTR s = srchr(url, TEXT('?'));
		body = String(s + 1);
		nurl = nurl.Left(s - url);
	}

    hostName.SetLength(256);
    path.SetLength(1024);

    zero(&urlComponents, sizeof(urlComponents));

    urlComponents.dwStructSize = sizeof(urlComponents);
    
    urlComponents.lpszHostName = hostName;
    urlComponents.dwHostNameLength = hostName.Length();

    urlComponents.lpszUrlPath = path;
    urlComponents.dwUrlPathLength = path.Length();

	WinHttpCrackUrl(nurl, 0, 0, &urlComponents);

    if (urlComponents.nPort == 443)
        secure = TRUE;

    hSession = WinHttpOpen(TEXT("gecko test"), WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
    if (!hSession)
        goto failure;

    hConnect = WinHttpConnect(hSession, hostName, secure ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT, 0);
    if (!hConnect)
        goto failure;

    hRequest = WinHttpOpenRequest(hConnect, verb, path, NULL, WINHTTP_NO_REFERER, acceptTypes, secure ? WINHTTP_FLAG_SECURE|WINHTTP_FLAG_REFRESH : WINHTTP_FLAG_REFRESH);
    if (!hRequest)
        goto failure;

    BOOL bResults = WinHttpSendRequest(hRequest, extraHeaders, extraHeaders ? -1 : 0, body.Array(), 
		body.Length(), body.Length(), 0);

    // End the request.
    if (bResults)
        bResults = WinHttpReceiveResponse(hRequest, NULL);
    else
        goto failure;

    TCHAR statusCode[8];
    DWORD statusCodeLen;

    statusCodeLen = sizeof(statusCode);
    if (!WinHttpQueryHeaders (hRequest, WINHTTP_QUERY_STATUS_CODE, WINHTTP_HEADER_NAME_BY_INDEX, &statusCode, &statusCodeLen, WINHTTP_NO_HEADER_INDEX))
        goto failure;

    *responseCode = wcstoul(statusCode, NULL, 10);	

    if (bResults && *responseCode == 200)
    {
        CHAR buffer[16384];
        DWORD dwSize, dwOutSize;

        do 
        {
            // Check for available data.
            dwSize = 0;
            if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
                goto failure;

            if (!WinHttpReadData(hRequest, (LPVOID)buffer, dwSize, &dwOutSize))
            {
                goto failure;
            }
            else
            {
                if (!dwOutSize)
                    break;

				// Ensure the string is terminated.
				buffer[dwOutSize] = 0;

				String b = String((LPCSTR)buffer);
				result.AppendString(b);
            }
        } while (dwSize > 0);
    }

failure:
    if (hSession)
        WinHttpCloseHandle(hSession);
    if (hConnect)
        WinHttpCloseHandle(hConnect);
    if (hRequest)
        WinHttpCloseHandle(hRequest);

    return result;
}