예제 #1
0
void VBridge::setpointCB(const sensor_msgs::JointStateConstPtr& msg)
{
  //To ensure safety commands, set all to zero first
  for(unsigned int i=0;i<m_cmdvel.size();i++)
    m_cmdvel[i].data = 0.0; 
  
  //First, ensure that the velocity is not empty, if so, raise an error
  if(msg->velocity.size() < 1)
  {
    ROS_ERROR("VELOCITY BRIDGE: I received an empty velocity message - command refused");
    streamOut(); //Zeros
    return;
  }
  if(msg->velocity.size() != msg->name.size() )
  {
    ROS_ERROR("VELOCITY BRIDGE: velocity message has different size of name size - command refused");
    streamOut(); //Zeros
    return;
  }
  
  for(unsigned int i=0;i<msg->name.size();i++)
  {
    std::map<std::string,int>::iterator it=m_sot2jnt.find(msg->name[i]);
    if(it!=m_sot2jnt.end())
      m_cmdvel[it->second].data = msg->velocity[i];
  }
  
  //stream out
    streamOut();
}
예제 #2
0
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool BarlineTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 4, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Barline barlineOut(12, Barline::repeatEnd, 12);
    barlineOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Barline barlineIn;
        barlineIn.Deserialize(streamIn,
            PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((barlineIn == barlineOut)
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
예제 #3
0
void ExifShellExtension::PasteExifFromClipboard()
{
   Win32::Clipboard cb(GetActiveWindow());

   if (cb.IsFormatAvail(m_uiExifClipboardFormat))
   {
      std::vector<BYTE> vecData;
      cb.GetData(m_uiExifClipboardFormat, vecData);

      CString cszOutputFilename = m_cszFilename + _T(".exifshellext-rename");

      // rewrite jpeg file using new exif data
      {
         Stream::FileStream streamIn(m_cszFilename, Stream::FileStream::modeOpen, Stream::FileStream::accessRead,
            Stream::FileStream::shareRead);

         Stream::FileStream streamOut(cszOutputFilename, Stream::FileStream::modeCreateNew, Stream::FileStream::accessWrite,
            Stream::FileStream::shareRead);

         ExifRewriter rewriter(streamIn, streamOut, vecData);
         rewriter.Start();
      }

      // TODO now set old file date/time

      // rename
      ::DeleteFile(m_cszFilename);
      ::MoveFile(cszOutputFilename, m_cszFilename);
   }
}
예제 #4
0
/// Tests Serialization
/// @return True if all tests were executed, false if not
bool FontSettingTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Dec 6, 2004
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    FontSetting fontSettingOut(wxT("Arial"), 12, FontSetting::weightBold, true,
        true, true, wxColor(255,0,0));
    fontSettingOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        FontSetting fontSettingIn;
        fontSettingIn.Deserialize(streamIn,
            PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((fontSettingIn == fontSettingOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}    
/// Tests Serialization
/// @return True if all tests were executed, false if not
bool GuitarTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Dec 8, 2004
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Guitar guitarOut(1, wxT("Test"), 2, 3, 4, 5, 6, 7, 8, 9);
    guitarOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Guitar guitarIn;
        guitarIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((guitarIn == guitarOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
예제 #6
0
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool PositionTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 18, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Position positionOut(12, 4, 2);
    positionOut.SetVibrato();
    positionOut.SetVolumeSwell(Dynamic::off, Dynamic::mp, 1);
    positionOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Position positionIn;
        positionIn.Deserialize(streamIn,
            PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((positionIn == positionOut)
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
/// Tests Serialization
/// @return True if all tests were executed, false if not
bool KeySignatureTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Dec 10, 2004
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    KeySignature keySignatureOut(KeySignature::minorKey, KeySignature::threeFlats);
    keySignatureOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        KeySignature keySignatureIn;
        keySignatureIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((keySignatureIn == keySignatureOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
/// Tests the Serialization Fucntions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 11, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Direction directionOut(12, Direction::toCoda, Direction::activeDaCapo, 4);
    directionOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Direction directionIn;
        directionIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((directionIn == directionOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool AlternateEndingTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Dec 4, 2004
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    AlternateEnding alternateEndingOut(1, 2, testNumbers);
    alternateEndingOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        AlternateEnding alternateEndingIn;
        alternateEndingIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((alternateEndingIn == alternateEndingOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);

	return (true);
}
예제 #10
0
bool B9MatCat::save()
{
    QString sPath = QCoreApplication::applicationDirPath()+"/"+m_sModelName+".b9m";
    QFile outFile(sPath);
    outFile.open(QIODevice::WriteOnly);
    if(!outFile.isOpen()) return false;
    QDataStream outStream(&outFile);
    streamOut(&outStream);
    return true;
}
예제 #11
0
// virtual
LLIOPipe::EStatus LLFilterSD2XMLRPCResponse::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	LLFastTimer t(FTM_PROCESS_SD2XMLRPC_RESPONSE);

	PUMP_DEBUG;
	// This pipe does not work if it does not have everyting. This
	// could be addressed by making a stream parser for llsd which
	// handled partial information.
	if(!eos)
	{
		return STATUS_BREAK;
	}

	PUMP_DEBUG;
	// we have everyting in the buffer, so turn the structure data rpc
	// response into an xml rpc response.
	LLBufferStream stream(channels, buffer.get());
	stream << XML_HEADER << XMLRPC_METHOD_RESPONSE_HEADER << std::flush;	// Flush, or buffer->count() returns too much!
	LLSD sd;
	LLSDSerialize::fromNotation(sd, stream, buffer->count(channels.in()));

	PUMP_DEBUG;
	LLIOPipe::EStatus rv = STATUS_ERROR;
	if(sd.has("response"))
	{
		PUMP_DEBUG;
		// it is a normal response. pack it up and ship it out.
		stream.precision(DEFAULT_PRECISION);
		stream << XMLRPC_RESPONSE_HEADER;
		streamOut(stream, sd["response"]);
		stream << XMLRPC_RESPONSE_FOOTER << XMLRPC_METHOD_RESPONSE_FOOTER;
		rv = STATUS_DONE;
	}
	else if(sd.has("fault"))
	{
		PUMP_DEBUG;
		// it is a fault.
		stream << XMLRPC_FAULT_1 << sd["fault"]["code"].asInteger()
			<< XMLRPC_FAULT_2
			<< xml_escape_string(sd["fault"]["description"].asString())
			<< XMLRPC_FAULT_3 << XMLRPC_METHOD_RESPONSE_FOOTER;
		rv = STATUS_DONE;
	}
	else
	{
		llwarns << "Unable to determine the type of LLSD response." << llendl;
	}
	PUMP_DEBUG;
	return rv;
}
예제 #12
0
bool Workspace::ImportSketch(Project * project, QString sketchFullPath) 
{
	QString name = QFileInfo(sketchFullPath).fileName();
	QString path = QFileInfo(sketchFullPath).absolutePath();

	// Copy main sketch file to project source folder, 
	// adjusting the code as necessary

	QStringList importLibs;
	
	QFile file(sketchFullPath);
	file.open(QFile::ReadOnly | QFile::Text);
	QTextStream streamIn(&file);
	QString fileContent = streamIn.readAll();
	file.close();
	QStringList list = fileContent.split("\n");
	for (int i=0; i<list.count(); i++) {
		if (list[i].indexOf("#include") >= 0) {
			QString text = list[i];
			text.remove(0, text.indexOf("#include") +  8);
			text = text.trimmed();
			text = text.remove(0, 1); //remove first quote or "<"
			int p = text.indexOf(".h");
			if (p > 0) {
				text = text.left(p);
				importLibs.append(text);
			}
		}
	}

	fileContent = "#include \"mariamole_auto_generated.h\"\n" + fileContent;
	QFile outFile(config.workspace + "/" + project->name + "/source/" + project->name + ".cpp"); // main.cpp
	outFile.open(QFile::WriteOnly);
	QTextStream streamOut(&outFile);
	streamOut << fileContent;
	outFile.close();
	ProjectFile pfile;
	pfile.name = project->name + ".cpp"; //"main.cpp";
	pfile.open = false;
	pfile.type = ptSource;
	project->files.push_back(pfile);

	//CopyFileToProject(qApp->applicationDirPath() + "/templates/main.h", "main.h", project);		
	CopyFileToProject(qApp->applicationDirPath() + "/templates/mariamole_auto_generated.h", "mariamole_auto_generated.h", project);		

	ImportFilesFromSketchDirectory(project, path);

	for (int i=0; i < importLibs.count(); i++) {
		ImportLibrary(project, importLibs[i], "");
	}

	return true;
}
예제 #13
0
void KPrWebPresentation::createMainPage( KProgress *progressBar )
{
    QTextCodec *codec = KGlobal::charsets()->codecForName( m_encoding );
    KTempFile tmp;
    QString dest = QString( "%1/index.html" ).arg( path );
    QFile file( tmp.name() );
    file.open( IO_WriteOnly );
    QTextStream streamOut( &file );
    streamOut.setCodec( codec );

    writeStartOfHeader( streamOut, codec, i18n("Table of Contents"), QString() );
    streamOut << "</head>\n";

    streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";

    streamOut << "<h1 align=\"center\"><font color=\"" << titleColor.name()
              << "\">" << title << "</font></h1>";

    streamOut << "<p align=\"center\"><a href=\"html/slide_1.html\">";
    streamOut << i18n("Click here to start the Slideshow");
    streamOut << "</a></p>\n";

    streamOut << "<p><b>" << i18n("Table of Contents") << "</b></p>\n";

    // create list of slides (with proper link)
    streamOut << "<ol>\n";
    for ( unsigned int i = 0; i < slideInfos.count(); i++ )
        streamOut << "  <li><a href=\"html/slide_" << i+1 << ".html\">" << slideInfos[ i ].slideTitle << "</a></li>\n";
    streamOut << "</ol>\n";

    // footer: author name, e-mail
    QString htmlAuthor = email.isEmpty() ? escapeHtmlText( codec, author ) :
                         QString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
    streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.koffice.org/kpresenter\">KPresenter</a>" )
                                      .arg( KGlobal::locale()->formatDate ( QDate::currentDate() ) ).arg( htmlAuthor ) );

    streamOut << "</body>\n</html>\n";
    file.close();

    KIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);


    progressBar->setProgress( progressBar->totalSteps() );
    kapp->processEvents();
}
예제 #14
0
ArgProcessor::ArgProcessor(QObject *parent) : QObject(parent)
{
    QTextStream streamOut(stdout);
    QTextStream streamIn(stdin);
#ifdef Q_OS_WIN
    QString defaultPort_ = "COM3";
#elif defined(Q_OS_MAC)
    QString defaultPort_ = "/dev/tty.usbmodem261";
#else
    QString defaultPort_ = "/dev/ttyACM0";
#endif
    streamOut << "Port (default is " + defaultPort_ + "): ";
    streamOut.flush();
    mPort = streamIn.readLine();
    if(mPort.isEmpty()) {
        mPort = defaultPort_;
    }

    streamOut << "Camera index (default is 0): ";
    streamOut.flush();
    mCamera = streamIn.readLine().toInt();

    streamOut << "Camera width (default is 1280): ";
    streamOut.flush();
    mWidth = streamIn.readLine().toInt();
    if(mWidth == 0) {
        mWidth = 1280;
    }

    streamOut << "Camera height (default is 720): ";
    streamOut.flush();
    mHeight = streamIn.readLine().toInt();
    if(mHeight == 0) {
        mHeight = 720;
    }

    streamOut << "Camera fps (default is 25.0): ";
    streamOut.flush();
    mFps = streamIn.readLine().toInt();
    if(mFps == 0) {
        mFps = 25.0;
    }
}
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool ScoreTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 6, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Score scoreOut;
    wxUint32 i = 0;
    for (; i < 3; i++)
    {
        scoreOut.m_guitarArray.Add(new Guitar);
        scoreOut.m_chordDiagramArray.Add(new ChordDiagram);
        scoreOut.m_floatingTextArray.Add(new FloatingText);
        scoreOut.m_guitarInArray.Add(new GuitarIn);
        scoreOut.m_tempoMarkerArray.Add(new TempoMarker);
        scoreOut.m_dynamicArray.Add(new Dynamic);
        scoreOut.m_alternateEndingArray.Add(new AlternateEnding);
        scoreOut.m_systemArray.Add(new System);
    }
    scoreOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Score scoreIn;
        scoreIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((scoreIn == scoreOut)
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
/// Tests the Serialization Functions
/// @return True if all tests were executed, false if not
bool StaffTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 5, 2005

    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Staff staffOut(4, Staff::BASS_CLEF);
    wxUint32 i = 0;
    for (; i < 3; i++)
    {
        staffOut.m_positionArray[0].Add(new Position);
        staffOut.m_positionArray[1].Add(new Position);
    }
    staffOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Staff staffIn;
        staffIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((staffIn == staffOut)
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
예제 #17
0
/// Tests the Serialization Fucntions
/// @return True if all tests were executed, false if not
bool ChordDiagramTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 15, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    ChordName chordName;
    chordName.SetFormula(ChordName::minor);
    
    // Write test data to stream
    ChordDiagram chordDiagramOut(chordName, 3, 3, 4, 5, 5, 3,
        ChordDiagram::stringMuted);
    chordDiagramOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        ChordDiagram chordDiagramIn;
        chordDiagramIn.Deserialize(streamIn,
            PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((chordDiagramIn == chordDiagramOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
예제 #18
0
void LLFilterSD2XMLRPC::streamOut(std::ostream& ostr, const LLSD& sd)
{
	ostr << "<value>";
	switch(sd.type())
	{
	case LLSD::TypeMap:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(map) BEGIN" << llendl;
#endif
		ostr << "<struct>";
		if(ostr.fail())
		{
			llinfos << "STREAM FAILURE writing struct" << llendl;
		}
		LLSD::map_const_iterator it = sd.beginMap();
		LLSD::map_const_iterator end = sd.endMap();
		for(; it != end; ++it)
		{
			ostr << "<member><name>" << xml_escape_string((*it).first)
				<< "</name>";
			streamOut(ostr, (*it).second);
			if(ostr.fail())
			{
				llinfos << "STREAM FAILURE writing '" << (*it).first
						<< "' with sd type " << (*it).second.type() << llendl;
			}
			ostr << "</member>";
		}
		ostr << "</struct>";
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(map) END" << llendl;
#endif
		break;
	}
	case LLSD::TypeArray:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(array) BEGIN" << llendl;
#endif
		ostr << "<array><data>";
		LLSD::array_const_iterator it = sd.beginArray();
		LLSD::array_const_iterator end = sd.endArray();
		for(; it != end; ++it)
		{
			streamOut(ostr, *it);
			if(ostr.fail())
			{
				llinfos << "STREAM FAILURE writing array element sd type "
						<< (*it).type() << llendl;
			}
		}
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(array) END" << llendl;
#endif
		ostr << "</data></array>";
		break;
	}
	case LLSD::TypeUndefined:
		// treat undefined as a bool with a false value.
	case LLSD::TypeBoolean:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(bool)" << llendl;
#endif
		ostr << "<boolean>" << (sd.asBoolean() ? "1" : "0") << "</boolean>";
		break;
	case LLSD::TypeInteger:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(int)" << llendl;
#endif
		ostr << "<i4>" << sd.asInteger() << "</i4>";
		break;
	case LLSD::TypeReal:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(real)" << llendl;
#endif
		ostr << "<double>" << sd.asReal() << "</double>";
		break;
	case LLSD::TypeString:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(string)" << llendl;
#endif
		ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
		break;
	case LLSD::TypeUUID:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(uuid)" << llendl;
#endif
		// serialize it as a string
		ostr << "<string>" << sd.asString() << "</string>";
		break;
	case LLSD::TypeURI:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(uri)" << llendl;
#endif
		// serialize it as a string
		ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
		break;
	}
	case LLSD::TypeBinary:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(binary)" << llendl;
#endif
		// this is pretty inefficient, but we'll deal with that
		// problem when it becomes one.
		ostr << "<base64>";
		LLSD::Binary buffer = sd.asBinary();
		if(!buffer.empty())
		{
			// *TODO: convert to LLBase64
			int b64_buffer_length = apr_base64_encode_len(buffer.size());
			char* b64_buffer = new char[b64_buffer_length];
			b64_buffer_length = apr_base64_encode_binary(
				b64_buffer,
				&buffer[0],
				buffer.size());
			ostr.write(b64_buffer, b64_buffer_length - 1);
			delete[] b64_buffer;
		}
		ostr << "</base64>";
		break;
	}
	case LLSD::TypeDate:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		llinfos << "streamOut(date)" << llendl;
#endif
		// no need to escape this since it will be alpha-numeric.
		ostr << "<dateTime.iso8601>" << sd.asString() << "</dateTime.iso8601>";
		break;
	default:
		// unhandled type
		llwarns << "Unhandled structured data type: " << sd.type()
			<< llendl;
		break;
	}
	ostr << "</value>";
}
예제 #19
0
파일: wall.cpp 프로젝트: fasterwego/octopus
void Wall::modwallCmd(const QString &from, const QStringList &list) {
    octAssert(list.size() < 3);

    int num = list[0].toInt();
    QString replacement = QString::null;
    if (list[1] != "")
        replacement = list[1];

    // Read the current wall and store it in a list
    QFile fwall(manager()->dataDir() + "/wall");
    if (!fwall.open(QIODevice::ReadOnly)) {
        octInfo("Could not read wall file\n");
        return;
    }
    QTextStream stream(&fwall);
    QString line;
    QStringList l;
    while ((line = stream.readLine()) != QString::null)
        l << line;
    fwall.close();

    if (!l.count()) {
        manager()->connectionPlugin()->serverSend(from, "Wall is empty");
        return;
    }

    if (!num || (num > l.count())) {
        manager()->connectionPlugin()->serverSend(from, "Invalid wall line number");
        return;
    }

    // Remove the element and save the file
    QStringList::Iterator it = l.end();
    for (;num > 0; --num)
        it--;

    QString message = *it;
    if(replacement.isNull())
        l.erase(it);
    else {
        QRegExp regex("(([\\d/]+) ([\\d:]+) ([\\w ]{8}) )(.*)"); //@attention Wall format dependant
        if(regex.exactMatch(message)) { // should always be the case, we just want to get the datas
            replacement = regex.cap(1) + replacement;
            *it = replacement;
        }
    }
    QFile fout(manager()->dataDir() + "/wall");
    if (!fout.open(QIODevice::WriteOnly)) {
        octInfo("Could not write wall file\n");
        return;
    }

    QTextStream streamOut(&fout);
    for (it = l.begin(); it != l.end(); it++)
        streamOut << *it + "\n";

    fout.close();
    loadWall();

    // Send messages
    manager()->connectionPlugin()->serverSend(from, "You modify the wall ");
    manager()->connectionPlugin()->serverBroadcastOthers(from, from + " modifies the wall ");
    manager()->logPlugin()->write("modwall", from + " modifies the wall :\n  - " + message + "\n  + " + replacement);
}
예제 #20
0
// virtual
LLIOPipe::EStatus LLFilterSD2XMLRPCRequest::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	LLFastTimer t(FTM_PROCESS_SD2XMLRPC_REQUEST);
	// This pipe does not work if it does not have everyting. This
	// could be addressed by making a stream parser for llsd which
	// handled partial information.
	PUMP_DEBUG;
	if(!eos)
	{
		llinfos << "!eos" << llendl;
		return STATUS_BREAK;
	}

	// See if we can parse it
	LLBufferStream stream(channels, buffer.get());
	LLSD sd;
	LLSDSerialize::fromNotation(sd, stream, buffer->count(channels.in()));
	if(stream.fail())
	{
		llinfos << "STREAM FAILURE reading structure data." << llendl;
	}

	PUMP_DEBUG;
	// We can get the method and parameters from either the member
	// function or passed in via the buffer. We prefer the buffer if
	// we found a parameter and a method, or fall back to using
	// mMethod and putting everyting in the buffer into the parameter.
	std::string method;
	LLSD param_sd;
	if(sd.has("method") && sd.has("parameter"))
	{
		method = sd["method"].asString();
		param_sd = sd["parameter"];
	}
	else
	{
		method = mMethod;
		param_sd = sd;
	}
	if(method.empty())
	{
		llwarns << "SD -> XML Request no method found." << llendl;
		return STATUS_ERROR;
	}

	PUMP_DEBUG;
	// We have a method, and some kind of parameter, so package it up
	// and send it out.
	LLBufferStream ostream(channels, buffer.get());
	ostream.precision(DEFAULT_PRECISION);
	if(ostream.fail())
	{
		llinfos << "STREAM FAILURE setting precision" << llendl;
	}
	ostream << XML_HEADER << XMLRPC_REQUEST_HEADER_1
		<< xml_escape_string(method) << XMLRPC_REQUEST_HEADER_2;
	if(ostream.fail())
	{
		llinfos << "STREAM FAILURE writing method headers" << llendl;
	}
	switch(param_sd.type())
	{
	case LLSD::TypeMap:
		// If the params are a map, then we do not want to iterate
		// through them since the iterators returned will be map
		// ordered un-named values, which will lose the names, and
		// only stream the values, turning it into an array.
		ostream << "<param>";
		streamOut(ostream, param_sd);
		ostream << "</param>";
		break;
	case LLSD::TypeArray:
	{

		LLSD::array_iterator it = param_sd.beginArray();
		LLSD::array_iterator end = param_sd.endArray();
		for(; it != end; ++it)
		{
			ostream << "<param>";
			streamOut(ostream, *it);
			ostream << "</param>";
		}
		break;
	}
	default:
		ostream << "<param>";
		streamOut(ostream, param_sd);
		ostream << "</param>";
		break;
	}

	stream << XMLRPC_REQUEST_FOOTER << std::flush;
	return STATUS_DONE;
}
예제 #21
0
void KPrWebPresentation::createSlidesHTML( KProgress *progressBar )
{
    QTextCodec *codec = KGlobal::charsets()->codecForName( m_encoding );

    const QString brtag ( "<br" + QString(isXML()?" /":"") + ">" );

    for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {

        unsigned int pgNum = i + 1; // pgquiles # elpauer . org - I think this is a bug, seems to be an overflow if we have max_unsigned_int slides
        KTempFile tmp;
        QString dest= QString( "%1/html/slide_%2.html" ).arg( path ).arg( pgNum );
        QString next= QString( "slide_%2.html" ).arg( pgNum<slideInfos.count() ? pgNum+1 : (m_bLoopSlides ? 1 : pgNum ) ); // Ugly, but it works

        QFile file( tmp.name() );
        file.open( IO_WriteOnly );
        QTextStream streamOut( &file );
        streamOut.setCodec( codec );

        writeStartOfHeader( streamOut, codec, slideInfos[ i ].slideTitle, next );

        // ### TODO: transform documentinfo.xml into many <META> elements (at least the author!)

        if ( i > 0 ) {
            streamOut <<  "<link rel=\"first\" href=\"slide_1.html\"" << ( isXML() ?" /":"") << ">\n";
            streamOut <<  "<link rel=\"prev\" href=\"slide_" << pgNum - 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
        }
        if ( i < slideInfos.count() - 1 ) {
            streamOut <<  "<link rel=\"next\" href=\"slide_" << pgNum + 1 << ".html\"" << ( isXML() ?" /":"") << ">\n";
            streamOut <<  "<link rel=\"last\" href=\"slide_" << slideInfos.count() << ".html\"" << ( isXML() ?" /":"") << ">\n";
        }
        streamOut <<  "<link rel=\"contents\" href=\"../index.html\"" << ( isXML() ?" /":"") << ">\n";

        streamOut << "</head>\n";
        streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";

        if (m_bWriteHeader) {
            streamOut << "  <center>\n";

            if ( i > 0 )
                streamOut << "    <a href=\"slide_1.html\">";
                streamOut << "<img src=\"../pics/first.png\" border=\"0\" alt=\"" << i18n( "First" )
                              << "\" title=\"" << i18n( "First" ) << "\"" << ( isXML() ?" /":"") << ">";
            if ( i > 0 )
                streamOut << "</a>";

            streamOut << "\n";

            if ( i > 0 )
                streamOut << "    <a href=\"slide_" << pgNum - 1 << ".html\">";
                streamOut << "<img src=\"../pics/prev.png\" border=\"0\" alt=\"" << i18n( "Previous" )
                              << "\" title=\"" << i18n( "Previous" ) << "\"" << ( isXML() ?" /":"") << ">";
            if ( i > 0 )
                streamOut << "</a>";

            streamOut << "\n";

            if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
                streamOut << "    <a href=\"" << next << "\">";
                streamOut << "<img src=\"../pics/next.png\" border=\"0\" alt=\"" << i18n( "Next" )
                          << "\" title=\"" << i18n( "Next" ) << "\"" << ( isXML() ?" /":"") << ">";
            if ( (m_bLoopSlides) || (i < slideInfos.count() - 1 ) )
                streamOut << "</a>";

            streamOut << "\n";

            if ( i < slideInfos.count() - 1 )
                streamOut << "    <a href=\"slide_" << slideInfos.count() << ".html\">";
                streamOut << "<img src=\"../pics/last.png\" border=\"0\" alt=\"" << i18n( "Last" )
                      << "\" title=\"" << i18n( "Last" ) << "\"" << ( isXML() ?" /":"") << ">";
            if ( i < slideInfos.count() - 1 )
                streamOut << "</a>";

            streamOut << "\n" << "    &nbsp; &nbsp; &nbsp; &nbsp;\n";

            streamOut << "    <a href=\"../index.html\">";
            streamOut << "<img src=\"../pics/home.png\" border=\"0\" alt=\"" << i18n( "Home" )
                      << "\" title=\"" << i18n( "Home" ) << "\"" << ( isXML() ?" /":"") << ">";
            streamOut << "</a>\n";

            streamOut << " </center>" << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n"; // ### TODO: is noshade W3C?

            streamOut << "  <center>\n    <font color=\"" << escapeHtmlText( codec, titleColor.name() ) << "\">\n";
            streamOut << "    <b>" << escapeHtmlText( codec, title ) << "</b> - <i>" << escapeHtmlText( codec, slideInfos[ i ].slideTitle ) << "</i>\n";

            streamOut << "    </font>\n  </center>\n";

            streamOut << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">" << brtag << "\n";
	}

        streamOut << "  <center>\n    ";

	if ( (m_bLoopSlides) || (i < slideInfos.count() - 1) )
            streamOut << "<a href=\"" << next << "\">";

	    streamOut << "<img src=\"../pics/slide_" << pgNum << ".png\" border=\"0\" alt=\""
                      << i18n( "Slide %1" ).arg( pgNum ) << "\"" << ( isXML() ?" /":"") << ">";

	    if ( i < slideInfos.count() - 1 )
                streamOut << "</a>";

            streamOut << "\n";

            streamOut << "    </center>\n";

	if (m_bWriteFooter) {
	    	streamOut << brtag << "<hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";

            QPtrList<KPrPage> _tmpList( doc->getPageList() );
            QString note ( escapeHtmlText( codec, _tmpList.at(i)->noteText() ) );
            if ( !note.isEmpty() ) {
                streamOut << "  <b>" << escapeHtmlText( codec, i18n( "Note" ) ) << "</b>\n";
                streamOut << " <blockquote>\n";

                streamOut << note.replace( "\n", brtag );

                streamOut << "  </blockquote><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
            }

            streamOut << "  <center>\n";

            QString htmlAuthor;
            if (email.isEmpty())
                htmlAuthor=escapeHtmlText( codec, author );
            else
                htmlAuthor=QString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
            streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.koffice.org/kpresenter\">KPresenter</a>" )
                                          .arg( KGlobal::locale()->formatDate ( QDate::currentDate() ) ).arg( htmlAuthor ) );

            streamOut << "    </center><hr noshade=\"noshade\"" << ( isXML() ?" /":"") << ">\n";
        }

        streamOut << "</body>\n</html>\n";

        file.close();

        KIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);

        int p = progressBar->progress();
        progressBar->setProgress( ++p );
        kapp->processEvents();
    }
}