Exemple #1
0
    void testConvert() {

        StringBuffer str(TEST_STRING);

        char* toUtf8   = toMultibyte(TEXT(TEST_STRING));
        char* toLatin1 = toMultibyte(TEXT(TEST_STRING), "iso_8859-1");

        StringBuffer cnv;
        cnv.convert(TEXT(TEST_STRING));
        fprintf(stderr, "\nConverted string: %s\n", cnv.c_str());
        CPPUNIT_ASSERT((strcmp(cnv.c_str(), toUtf8) == 0));

        cnv.convert(TEXT(TEST_STRING), "iso_8859-1");
        fprintf(stderr, "\nConverted string: %s\n", cnv.c_str());
        CPPUNIT_ASSERT((strcmp(cnv.c_str(), toLatin1) == 0));
    }
Exemple #2
0
void HttpConnection::readResponseHeaders() 
{
    WCHAR *wbuffer = new WCHAR[1024];
    DWORD  ddsize = 1024;
	StringBuffer headerString;

    responseHeaders.clear();

    BOOL reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL);
    if (reqDone == false) {
        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
            // Allocate the necessary buffer.
            delete [] wbuffer;
            wbuffer = new WCHAR[ddsize];
            reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL);
        }
    }
    if (reqDone) {
		headerString.convert(wbuffer);
		LOG.debug("Response Headers:", headerString.c_str());

		ArrayList headers;
		headerString.split(headers, "\r\n");

		StringBuffer *prop;

		for(ArrayElement* e=headers.front(); e; e=headers.next()) {
			prop = dynamic_cast<StringBuffer *>(e);
			if(prop->empty()) continue;

			size_t colon = prop->find(":");
			if (colon != StringBuffer::npos) {
				StringBuffer key = prop->substr(0, colon);
				StringBuffer value = prop->substr(colon+1);
				responseHeaders.put(key.trim(),value.trim());                              
                if (canBeLogged(key)) {
				    LOG.debug("\t%s : %s", key.c_str(), value.c_str());
                } else {
                    LOG.debug("\t%s : *****", key.c_str());
                }
			}
			else {
				LOG.debug("\t%s", prop->c_str());
			}
		}
    } else {
        DWORD err = GetLastError();
        const char* msg = createHttpErrorMessage(err);
        LOG.error("[HttpConnection] Error reading response headers - code %d: %s", err, msg);
        delete [] msg;
    }
}
void CPicturesSettings::OnBnClickedPicturesButSelect() {

    if (!ssconf) return;

    // Get the default browse folder to the current path of pictures
    StringBuffer path = ssconf->getProperty(PROPERTY_MEDIAHUB_PATH);
    WCHAR* defaultPath = toWideChar(path.c_str());

    CString caption;
    caption.LoadString(IDS_SELECT_PICTURES_FOLDER);

    // Open the browse for folder window (modal)
    wstring newPath;
    if ( browseFolder(newPath, defaultPath, caption.GetBuffer(), GetSafeHwnd()) ) {
        // Update the UI label and save the new path
        SetDlgItemText(IDC_PICTURES_EDIT_FOLDER, newPath.c_str());
        path.convert(newPath.c_str());
        ssconf->setProperty(PROPERTY_MEDIAHUB_PATH, path.c_str());
    }

    delete [] defaultPath;
}
    void insertRawItem(const char* testFileName, const int expectedResult, 
                       const WCHAR* inputItemKey, const WCHAR* expectedOutName) {


        // Read the input file
        char* content = NULL;
        size_t len;
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, testFileName);
        bool fileLoaded = readFile(inFile.c_str(), &content, &len, true);
        CPPUNIT_ASSERT_MESSAGE("Failed to load test file", fileLoaded);
        
        // Create a SyncItem containing the raw file data
        SyncItem item(inputItemKey);
        item.setData(content, (long)len);
        delete [] content;

        int ret = fmss->insertItem(item);

        // TESTS
        CPPUNIT_ASSERT_MESSAGE("wrong status returned", ret == expectedResult);
        if (fmss->isErrorCode(ret)) {
            return;
        }
        WString outKey(item.getKey());
        CPPUNIT_ASSERT_MESSAGE("wrong item's key returned", outKey == expectedOutName);

        StringBuffer outFile(outputDir);
        StringBuffer outName;
        outName.convert(expectedOutName);
        outFile.append(outName);
        CPPUNIT_ASSERT_MESSAGE("output file not found", fileExists(outFile.c_str()) );

        char* outContent = NULL;
        size_t outLen;
        readFile(outFile.c_str(), &outContent, &outLen, true);
        CPPUNIT_ASSERT( outLen == len );
        delete [] outContent;
    }
    void insertItem(const char* testFileName, const int expectedResult, 
                    const char* expectedOutName, const char* forceFileName = NULL) {

        FileData file = createFileData(testFileName);
        if (forceFileName) {
            WString wname;
            StringBuffer tmp(forceFileName);
            wname = tmp;
            file.setName(wname.c_str());
        }

        // Create a SyncItem containing the OMA file data
        SyncItem item(TEXT("test1"));
        char* data = file.format();
        item.setData(data, (long)strlen(data));
        delete [] data;

        int ret = fmss->insertItem(item);

        // TESTS
        CPPUNIT_ASSERT_MESSAGE("wrong status returned", ret == expectedResult);
        if (fmss->isErrorCode(ret)) {
            return;
        }
        StringBuffer outKey;
        outKey.convert(item.getKey());
        CPPUNIT_ASSERT_MESSAGE("wrong item's key returned", outKey == expectedOutName);

        StringBuffer outFile(outputDir);
        outFile.append(expectedOutName);
        CPPUNIT_ASSERT_MESSAGE("output file not found", fileExists(outFile.c_str()) );

        char* outContent = NULL;
        size_t outLen;
        readFile(outFile.c_str(), &outContent, &outLen, true);
        CPPUNIT_ASSERT( (int)outLen == file.getSize() );
        delete [] outContent;
    }
void CMediaHubSetting::OnBnClickedMediaHubButSelect() {
   
    // Get the default browse folder to the current path of videos       
    CString path;
    GetDlgItemText(IDC_MEDIA_HUB_EDIT_FOLDER, path);
    
    WCHAR* t = toWideChar(getMediaHubDefault().c_str());
    CString mediaHub = t;
    CString mediaDir = path;
    int found = mediaDir.Find(mediaHub);
    if (found > -1) {
        mediaDir.Truncate(found);
    }

    CString caption;
    caption.LoadString(IDS_MEDIA_HUB_TITLE_PICKER);
    
    // Open the browse for folder window (modal)
    wstring newPath;
    if ( browseFolder(newPath, mediaDir.GetBuffer(), caption.GetBuffer(), GetSafeHwnd()) ) {
        // Update the UI label and save the new path
        if (newPath.find_last_of(L"\\") == newPath.length() -1) {
            newPath = newPath.substr(0, newPath.length() -1);
        }
        newPath.append(t);
        SetDlgItemText(IDC_MEDIA_HUB_EDIT_FOLDER, newPath.c_str());     

        // check if the folder is different to the default one we enable the "reset" button
        StringBuffer t; t.convert(newPath.c_str());
        if (t != getFullMediaHubDefault()) {
            GetDlgItem(IDC_MEDIA_HUB_BUT_RESET)->EnableWindow(TRUE);
        } else {
            GetDlgItem(IDC_MEDIA_HUB_BUT_RESET)->EnableWindow(FALSE);
        }

    }   
    delete [] t;
}
Exemple #7
0
StringBuffer getCompleteName(const char *dir, const WCHAR *name) {
    StringBuffer fileName;
    fileName.convert(name);
    return getCompleteName(dir, fileName);
}
bool CCalendarSettings::saveSettings(bool saveToDisk)
{
    CString remoteName, outlookFolder, syncType;
    CString s1;
    _bstr_t bst;
    WindowsSyncSourceConfig* ssconf = ((OutlookConfig*)getConfig())->getSyncSourceConfig(APPOINTMENT_);

    GetDlgItemText(IDC_CALENDAR_EDIT_REMOTE, remoteName);
    GetDlgItemText(IDC_CALENDAR_EDIT_FOLDER, outlookFolder);

    // change values
    if(remoteName == ""){
        // remote name is empty
        s1.LoadString(IDS_ERROR_SET_REMOTE_NAME);
        wsafeMessageBox(s1);
        return false;
    }

    if (UICustomization::showWarningOnChangeFromOneWay) {
        int currentSyncType = getSyncTypeIndex(ssconf->getSync());
        int newSyncType = lstSyncType.GetCurSel();
        if (checkOneWayToTwoWay(currentSyncType, newSyncType)) {
           return false;
        }
    }

    // sync source enabled
    ssconf->setSync(getSyncTypeName(lstSyncType.GetCurSel()));

    // Date Filter
    int filterPos = lstFilter.GetCurSel();
    ssconf->getDateFilter().setRelativeLowerDate(getDateFilterValue(filterPos));


    // Note: use 'toMultibyte' which uses charset UTF-8.
    //       (when writing to winreg, toWideChar is then called)
    char* olFolder = toMultibyte(outlookFolder.GetBuffer());
    if (olFolder) {
        // If folder has changed, clear anchors
        if (UICustomization::clearAnchorsOnFolderChange) {
            const char * original = ssconf->getFolderPath();
            if (strcmp(original, olFolder) != 0) {
                ssconf->setLast(0);
                ssconf->setEndTimestamp(0);
            }
        }
        
        ssconf->setFolderPath(olFolder);
        delete [] olFolder;
    }

    if(checkInclude.GetCheck() == BST_CHECKED){
        ssconf->setUseSubfolders(true);
    }
    else {
        ssconf->setUseSubfolders(false);
    }

    StringBuffer remName;
    remName.convert(remoteName.GetBuffer());
    if (!remName.null()) {
        ssconf->setURI(remName.c_str());
    }   

    // Never save to winreg, will save when 'OK' is clicked on SyncSettings.
    //if(saveToDisk)
    //    ((OutlookConfig*)getConfig())->save();

    return true;
}