コード例 #1
0
ファイル: httpwstest.cpp プロジェクト: pranavk/online
void HTTPWSTest::testPasswordProtectedDocumentWithWrongPassword()
{
    try
    {
        const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods");
        const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();

        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
        Poco::Net::WebSocket socket = *connectLOKit(request, _response);

        // Send a load request with incorrect password
        sendTextFrame(socket, "load url=" + documentURL + " password=2");

        std::string response;
        getResponseMessage(socket, "error:", response, true);
        CPPUNIT_ASSERT_MESSAGE("did not receive an error: message as expected", !response.empty());
        {
            Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
            CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tokens.count());

            std::string errorCommand;
            std::string errorKind;
            LOOLProtocol::getTokenString(tokens[0], "cmd", errorCommand);
            LOOLProtocol::getTokenString(tokens[1], "kind", errorKind);
            CPPUNIT_ASSERT_EQUAL(std::string("load"), errorCommand);
            CPPUNIT_ASSERT_EQUAL(std::string("wrongpassword"), errorKind);
        }
        socket.shutdown();
        Util::removeFile(documentPath);
    }
    catch (const Poco::Exception& exc)
    {
        CPPUNIT_FAIL(exc.displayText());
    }
}
コード例 #2
0
ファイル: httpwstest.cpp プロジェクト: pranavk/online
void HTTPWSTest::testImpressPartCountChanged()
{
    try
    {
        // Load a document
        const std::string documentPath = Util::getTempFilePath(TDOC, "insert-delete.odp");
        const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();

        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
        Poco::Net::WebSocket socket = *connectLOKit(request, _response);

        sendTextFrame(socket, "load url=" + documentURL);
        sendTextFrame(socket, "status");
        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));

        // check total slides 1
        sendTextFrame(socket, "status");

        std::string response;
        getResponseMessage(socket, "status:", response, true);
        CPPUNIT_ASSERT_MESSAGE("did not receive a status: message as expected", !response.empty());
        {
            Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
            CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count());

            // Expected format is something like 'type= parts= current= width= height='.
            const std::string prefix = "parts=";
            const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
            CPPUNIT_ASSERT_EQUAL(1, totalParts);
        }

        /* FIXME partscountchanged: was removed, update accordingly
        // insert 10 slides
        for (unsigned it = 1; it <= 10; it++)
        {
            sendTextFrame(socket, "uno .uno:InsertPage");
            getResponseMessage(socket, "partscountchanged:", response, false);
            CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty());
            {
                Poco::JSON::Parser parser;
                Poco::Dynamic::Var result = parser.parse(response);
                Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
                CPPUNIT_ASSERT(values["action"] == "PartInserted");
            }
        }

        // delete 10 slides
        for (unsigned it = 1; it <= 10; it++)
        {
            sendTextFrame(socket, "uno .uno:DeletePage");
            getResponseMessage(socket, "partscountchanged:", response, false);
            CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty());
            {
                Poco::JSON::Parser parser;
                Poco::Dynamic::Var result = parser.parse(response);
                Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
                CPPUNIT_ASSERT(values["action"] == "PartDeleted");
            }
        }

        // undo delete slides
        for (unsigned it = 1; it <= 10; it++)
        {
            sendTextFrame(socket, "uno .uno:Undo");
            getResponseMessage(socket, "partscountchanged:", response, false);
            CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty());
            {
                Poco::JSON::Parser parser;
                Poco::Dynamic::Var result = parser.parse(response);
                Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
                CPPUNIT_ASSERT(values["action"] == "PartInserted");
            }
        }

        // redo inserted slides
        for (unsigned it = 1; it <= 10; it++)
        {
            sendTextFrame(socket, "uno .uno:Redo");
            getResponseMessage(socket, "partscountchanged:", response, false);
            CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty());
            {
                Poco::JSON::Parser parser;
                Poco::Dynamic::Var result = parser.parse(response);
                Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>();
                CPPUNIT_ASSERT(values["action"] == "PartDeleted");
            }
        }
        */

        socket.shutdown();
        Util::removeFile(documentPath);
    }
    catch (const Poco::Exception& exc)
    {
        CPPUNIT_FAIL(exc.displayText());
    }
}
コード例 #3
0
void * listener( void * inConnection )
{
#ifndef WNT
	sigset_t			theSigset;
#endif
	PAPIConnection *	theConnection = ( PAPIConnection * )inConnection;

#ifndef WNT
	sigemptyset( &theSigset );
	sigaddset( &theSigset, SIGHUP );
	pthread_sigmask( SIG_BLOCK, &theSigset, 0 );
#endif
	setListenerThreadStatus( inConnection, RUNNING );
	while ( getListenerThreadStatus( inConnection ) == RUNNING )
	{
		PAPIStatus		theStatus;
		PAPIMessage *	theMessage;
		if ( theConnection->mFD != INVALID_SOCKET )
		{
			int	bHaveMessage = haveMessage( theConnection );
			if ( bHaveMessage == 0 )
			{
				continue;
			}
			else if ( bHaveMessage == -1 )
			{
				papiClose( theConnection->mFD );
				theConnection->mFD = INVALID_SOCKET;
				if ( lockMutex( theConnection->mConnectionStateChangeMutex )
				     == 0 )
				{
					theConnection->mConnectionListener( PAPIDisconnected,
													theConnection->mUserData );
					unlockMutex( theConnection->mConnectionStateChangeMutex );
				}
				if ( isDaemonEnabled() != 1 )
				{
					break;
				}
				continue;
			}	
			theMessage = getResponseMessage( theConnection, &theStatus );
			if ( theMessage != 0 )
			{
				if ( theMessage->mName == PAPImodifyNotification	||
				 	 theMessage->mName == PAPIaddNotification		||
				 	 theMessage->mName == PAPIremoveNotification )
				{
					sendInternalNotification( theConnection, theMessage );
					sendNotification( theConnection, theMessage );
					deleteMessage( theMessage );
				}
				else if ( theMessage->mName == PAPIRespSuccessContinueSASLAuth&&
				          theConnection->mAuthHandler != 0 )
				{
					handleSASLAuth( theConnection, theMessage );
				}
				else
				{
					if ( lockMutex( theConnection->mSavedMessageMutex ) == 0 )
					{
						theConnection->mSavedMessage = theMessage;
						unlockMutex( theConnection->mSavedMessageMutex );
					}
				}
			}
		}
		else
		{
			if ( lockMutex( theConnection->mConnectionStateChangeMutex ) == 0 )
			{
				theConnection->mFD = daemonConnect( 1 );
				setBlocking( theConnection, 0 );
				if ( theConnection->mFD != INVALID_SOCKET )
				{
					theConnection->mConnectionListener( PAPIConnected,
													theConnection->mUserData );
				}
				unlockMutex( theConnection->mConnectionStateChangeMutex );
				if ( theConnection->mFD == INVALID_SOCKET )
				{
					papiSleep( 10 );
				}
			}
		}
	}
	setListenerThreadStatus( inConnection, NOT_RUNNING );
	return 0;
}