LCOV - code coverage report
Current view: top level - extensions/source/plugin/unx - plugcon.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 141 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      12             :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13             :  * it under the terms of the GNU Lesser General Public License version 3
      14             :  * only, as published by the Free Software Foundation.
      15             :  *
      16             :  * OpenOffice.org is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU Lesser General Public License version 3 for more details
      20             :  * (a copy is included in the LICENSE file that accompanied this code).
      21             :  *
      22             :  * You should have received a copy of the GNU Lesser General Public License
      23             :  * version 3 along with OpenOffice.org.  If not, see
      24             :  * <http://www.openoffice.org/license.html>
      25             :  * for a copy of the LGPLv3 License.
      26             :  *
      27             :  ************************************************************************/
      28             : 
      29             : 
      30             : #ifdef AIX
      31             : #define _LINUX_SOURCE_COMPAT
      32             : #include <sys/timer.h>
      33             : #undef _LINUX_SOURCE_COMPAT
      34             : #endif
      35             : 
      36             : #include <plugin/unx/plugcon.hxx>
      37             : 
      38             : #include <cstdarg>
      39             : #include <vector>
      40             : 
      41           0 : sal_uInt32 PluginConnector::GetStreamID( NPStream* pStream )
      42             : {
      43           0 :     size_t nLen = m_aNPWrapStreams.size();
      44           0 :     for( size_t i = 0; i < nLen; i++ )
      45           0 :         if( m_aNPWrapStreams[ i ] == pStream )
      46           0 :             return static_cast<sal_uInt32>(i);
      47             :     SAL_WARN("extensions.plugin", "NPStream has no ID");
      48           0 :     return UnknownStreamID;
      49             : }
      50             : 
      51           0 : sal_uInt32 PluginConnector::GetNPPID( NPP instance )
      52             : {
      53           0 :     size_t nLen = m_aInstances.size();
      54           0 :     for( size_t i=0; i <nLen; i++ )
      55           0 :         if( m_aInstances[ i ]->instance == instance )
      56           0 :             return static_cast<sal_uInt32>(i);
      57             :     SAL_WARN("extensions.plugin", "NPP has no ID");
      58             : 
      59           0 :     return UnknownNPPID;
      60             : }
      61             : 
      62             : struct PtrStruct
      63             : {
      64             :     char* pData;
      65             :     sal_uLong nBytes;
      66             : 
      67           0 :     PtrStruct( char* i_pData, sal_uLong i_nBytes )
      68           0 :     : pData( i_pData ), nBytes( i_nBytes ) {}
      69             : };
      70             : 
      71           0 : sal_uLong PluginConnector::FillBuffer( char*& rpBuffer,
      72             :                                    const char* pFunction,
      73             :                                    sal_uLong nFunctionLen,
      74             :                                    va_list ap )
      75             : {
      76           0 :     std::vector< PtrStruct > aList;
      77           0 :     aList.reserve( 5 );
      78             : 
      79           0 :     sal_uLong nDataSize = nFunctionLen + sizeof( sal_uLong );
      80             :     char* pNext;
      81             : 
      82           0 :     do {
      83           0 :         pNext = va_arg( ap, char* );
      84           0 :         if( pNext )
      85             :         {
      86           0 :             aList.push_back( PtrStruct( pNext, va_arg( ap, sal_uLong ) ) );
      87           0 :             nDataSize += aList.back().nBytes + sizeof(sal_uLong);
      88             :         }
      89             :     } while( pNext );
      90             : 
      91           0 :     rpBuffer = new char[ nDataSize ];
      92           0 :     char* pRun = rpBuffer;
      93           0 :     memcpy( pRun, &nFunctionLen, sizeof( nFunctionLen ) );
      94           0 :     pRun += sizeof( nFunctionLen );
      95           0 :     memcpy( pRun, pFunction, nFunctionLen );
      96           0 :     pRun += nFunctionLen;
      97             : 
      98           0 :     for( std::vector<PtrStruct>::const_iterator it = aList.begin(); it != aList.end(); ++it )
      99             :     {
     100           0 :         memcpy( pRun, &it->nBytes, sizeof( sal_uLong ) );
     101           0 :         pRun += sizeof( sal_uLong );
     102           0 :         memcpy( pRun, it->pData, it->nBytes );
     103           0 :         pRun += it->nBytes;
     104             :     }
     105           0 :     return nDataSize;
     106             : }
     107             : 
     108           0 : MediatorMessage* PluginConnector::Transact( const char* pFunction,
     109             :                                             sal_uLong nFunctionLen, ... )
     110             : {
     111             :     va_list ap;
     112             :     char* pBuffer;
     113             : 
     114           0 :     va_start( ap, nFunctionLen );
     115           0 :     sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
     116           0 :     va_end( ap );
     117           0 :     MediatorMessage* pRet = TransactMessage( nSize, pBuffer );
     118           0 :     delete[] pBuffer;
     119           0 :     return pRet;
     120             : }
     121             : 
     122           0 : MediatorMessage* PluginConnector::Transact( sal_uInt32 nFunction, ... )
     123             : {
     124             :     va_list ap;
     125             :     char* pBuffer;
     126             : 
     127           0 :     va_start( ap, nFunction );
     128           0 :     sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
     129           0 :     va_end( ap );
     130           0 :     MediatorMessage* pRet = TransactMessage( nSize, pBuffer );
     131           0 :     delete[] pBuffer;
     132           0 :     return pRet;
     133             : }
     134             : 
     135           0 : sal_uLong PluginConnector::Send( sal_uInt32 nFunction, ... )
     136             : {
     137             :     va_list ap;
     138             :     char* pBuffer;
     139             : 
     140           0 :     va_start( ap, nFunction );
     141           0 :     sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
     142           0 :     va_end( ap );
     143           0 :     sal_uLong nRet = SendMessage( nSize, pBuffer );
     144           0 :     delete[] pBuffer;
     145           0 :     return nRet;
     146             : }
     147             : 
     148           0 : void PluginConnector::Respond( sal_uLong nID,
     149             :                                char* pFunction,
     150             :                                sal_uLong nFunctionLen, ... )
     151             : {
     152             :     va_list ap;
     153             :     char* pBuffer;
     154             : 
     155           0 :     va_start( ap, nFunctionLen );
     156           0 :     sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
     157           0 :     va_end( ap );
     158           0 :     SendMessage( nSize, pBuffer, nID | ( 1 << 24 ) );
     159           0 :     delete[] pBuffer;
     160           0 : }
     161             : 
     162           0 : MediatorMessage* PluginConnector::WaitForAnswer( sal_uLong nMessageID )
     163             : {
     164           0 :     if( ! m_bValid )
     165           0 :         return NULL;
     166             : 
     167           0 :     nMessageID &= 0x00ffffff;
     168           0 :     while( m_pListener )
     169             :     {
     170             :         {
     171           0 :             osl::MutexGuard aGuard( m_aQueueMutex );
     172           0 :             for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
     173             :             {
     174           0 :                 MediatorMessage* pMessage = m_aMessageQueue[ i ];
     175           0 :                 sal_uLong nID = pMessage->m_nID;
     176           0 :                 if(  ( nID & 0xff000000 ) &&
     177           0 :                      ( ( nID & 0x00ffffff ) == nMessageID ) )
     178             :                 {
     179           0 :                     m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
     180           0 :                     return pMessage;
     181             :                 }
     182           0 :             }
     183             :         }
     184           0 :         if( ! m_aMessageQueue.empty() )
     185           0 :             CallWorkHandler();
     186           0 :         WaitForMessage( 2000 );
     187             :     }
     188           0 :     return NULL;
     189             : }
     190             : 
     191           0 : ConnectorInstance::ConnectorInstance( NPP inst, char* type,
     192             :                                       int args, char* pargnbuf, sal_uLong nargnbytes,
     193             :                                       char* pargvbuf, sal_uLong nargvbytes,
     194             :                                       char* savedata, sal_uLong savebytes ) :
     195             :         instance( inst ),
     196             :         pShell( NULL ),
     197             :         pWidget( NULL ),
     198             :         pForm( NULL ),
     199             :         pGtkWindow( NULL ),
     200             :         pGtkWidget( NULL ),
     201             :         bShouldUseXEmbed( false ),
     202             :         nArg( args ),
     203             :         pArgnBuf( pargnbuf ),
     204           0 :         pArgvBuf( pargvbuf )
     205             : {
     206           0 :     memset( &window, 0, sizeof(window) );
     207           0 :     pMimeType = new char[ strlen( type ) + 1 ];
     208           0 :     strcpy( pMimeType, type );
     209           0 :     aData.len = savebytes;
     210           0 :     aData.buf = savedata;
     211           0 :     argn = new char*[ nArg ];
     212           0 :     argv = new char*[ nArg ];
     213             :     int i;
     214           0 :     char* pRun = pArgnBuf;
     215           0 :     for( i = 0; i < nArg; i++ )
     216             :     {
     217           0 :         argn[i] = pRun;
     218           0 :         while( *pRun != 0 && (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
     219           0 :             pRun++;
     220           0 :         if( (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
     221           0 :             pRun++;
     222             :     }
     223           0 :     pRun = pArgvBuf;
     224           0 :     for( i = 0; i < nArg; i++ )
     225             :     {
     226           0 :         argv[i] = pRun;
     227           0 :         while( *pRun != 0 && (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
     228           0 :             pRun++;
     229           0 :         if( (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
     230           0 :             pRun++;
     231             :     }
     232           0 : }
     233             : 
     234           0 : ConnectorInstance::~ConnectorInstance()
     235             : {
     236           0 :     delete [] pMimeType;
     237           0 :     delete [] argn;
     238           0 :     delete [] argv;
     239           0 :     delete [] pArgnBuf;
     240           0 :     delete [] pArgvBuf;
     241           0 :     delete [] (char*)aData.buf;
     242           0 : }
     243             : 
     244           0 : const char* GetCommandName( CommandAtoms eCommand )
     245             : {
     246           0 :     switch( eCommand )
     247             :     {
     248           0 :         case eNPN_GetURL:               return "NPN_GetURL";
     249           0 :         case eNPN_GetURLNotify:         return "NPN_GetURLNotify";
     250           0 :         case eNPN_DestroyStream:        return "NPN_DestroyStream";
     251           0 :         case eNPN_NewStream:            return "NPN_NewStream";
     252           0 :         case eNPN_PostURLNotify:        return "NPN_PostURLNotify";
     253           0 :         case eNPN_PostURL:              return "NPN_PostURL";
     254           0 :         case eNPN_RequestRead:          return "NPN_RequestRead";
     255           0 :         case eNPN_Status:               return "NPN_Status";
     256           0 :         case eNPN_Version:              return "NPN_Version";
     257           0 :         case eNPN_Write:                return "NPN_Write";
     258           0 :         case eNPN_UserAgent:            return "NPN_UserAgent";
     259             : 
     260           0 :         case eNPP_DestroyStream:        return "NPP_DestroyStream";
     261           0 :         case eNPP_Destroy:              return "NPP_Destroy";
     262           0 :         case eNPP_DestroyPhase2:        return "NPP_DestroyPhase2";
     263           0 :         case eNPP_NewStream:            return "NPP_NewStream";
     264           0 :         case eNPP_New:                  return "NPP_New";
     265           0 :         case eNPP_SetWindow:            return "NPP_SetWindow";
     266           0 :         case eNPP_StreamAsFile:         return "NPP_StreamAsFile";
     267           0 :         case eNPP_URLNotify:            return "NPP_URLNotify";
     268           0 :         case eNPP_WriteReady:           return "NPP_WriteReady";
     269           0 :         case eNPP_Write:                return "NPP_Write";
     270           0 :         case eNPP_GetMIMEDescription:   return "NPP_GetMIMEDescription";
     271           0 :         case eNPP_Initialize:           return "NPP_Initialize";
     272           0 :         case eNPP_Shutdown:             return "NPP_Shutdown";
     273             : 
     274           0 :         case eMaxCommand:               return "eMaxCommand";
     275           0 :         default:                        return "unknown command";
     276             :     }
     277             :     return NULL;
     278             : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10