static const char *test_base64(void) { const char *cases[] = {"test", "longer string"}; unsigned long i; char enc[8192]; char dec[8192]; for (i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { ns_base64_encode((unsigned char *)cases[i], strlen(cases[i]), enc); ns_base64_decode((unsigned char *)enc, strlen(enc), dec); ASSERT(strcmp(cases[i], dec) == 0); } return NULL; }
void dlgVscpInterfaceSettings::OnButtonVscpSetConfigurationClick( wxCommandEvent& event ) { CDllWrapper dll; CCanalConfObj conf; foundMetods meth; wxString strDrvInfo; wxString path = m_PathToDriver->GetValue(); if ( 0 == path.Length() ) { wxMessageBox( _( "Must have a valid path to the driver." ) ); return; } // Check that the file exists if ( !( ::wxFileExists( path ) ) ) { wxMessageBox( _( "The path does not point to a valid file." ) ); return; } if ( CANAL_ERROR_SUCCESS != dll.loadGetDriverInfo( path, strDrvInfo, &meth ) ) { wxMessageBox( _( "Sorry! This driver does not appears to have a stored description of how it should be configurated. Ask the driver maker to include one!" ) ); return; } char buf[ 256000 ]; wxCharBuffer wxbuf = strDrvInfo.ToUTF8(); int baselen = strlen( wxbuf.data() ); int len = ns_base64_decode( (const unsigned char *)wxbuf.data(), baselen, buf ); if ( len != baselen ) { wxMessageBox( _( "The configurationd ata was either in the wrong form (should have been base64 encoded xml) or it was absent." ) ); return; } // OK we have valid data - Parse it wxString driverinfo = wxString::FromUTF8( buf ); if ( !conf.parseDriverInfo( driverinfo ) ) { wxMessageBox( _( "Failed to parse the configuration data." ) ); return; } // Start the wizard wxString resultConfString; wxString str = m_DriverConfigurationString->GetValue(); uint32_t resultFlags = 0; if ( !conf.runWizard( this, str, vscp_readStringValue( m_DriverFlags->GetValue() ), resultConfString, &resultFlags ) ) { wxMessageBox( _( "Failed to run configuration wizard." ) ); return; } m_DriverConfigurationString->SetValue( resultConfString ); wxString strWrk = wxString::Format( _( "%lu" ), resultFlags ); m_DriverFlags->SetValue( strWrk ); event.Skip(); }