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 <sal/log.hxx>
37 :
38 : #include <plugin/unx/plugcon.hxx>
39 :
40 : #include <cstdarg>
41 : #include <vector>
42 :
43 0 : sal_uInt32 PluginConnector::GetStreamID( NPStream* pStream )
44 : {
45 0 : size_t nLen = m_aNPWrapStreams.size();
46 0 : for( size_t i = 0; i < nLen; i++ )
47 0 : if( m_aNPWrapStreams[ i ] == pStream )
48 0 : return static_cast<sal_uInt32>(i);
49 : SAL_WARN("extensions.plugin", "NPStream has no ID");
50 0 : return UnknownStreamID;
51 : }
52 :
53 0 : sal_uInt32 PluginConnector::GetNPPID( NPP instance )
54 : {
55 0 : size_t nLen = m_aInstances.size();
56 0 : for( size_t i=0; i <nLen; i++ )
57 0 : if( m_aInstances[ i ]->instance == instance )
58 0 : return static_cast<sal_uInt32>(i);
59 : SAL_WARN("extensions.plugin", "NPP has no ID");
60 :
61 0 : return UnknownNPPID;
62 : }
63 :
64 : struct PtrStruct
65 : {
66 : char* pData;
67 : sal_uLong nBytes;
68 :
69 0 : PtrStruct( char* i_pData, sal_uLong i_nBytes )
70 0 : : pData( i_pData ), nBytes( i_nBytes ) {}
71 : };
72 :
73 0 : sal_uLong PluginConnector::FillBuffer( char*& rpBuffer,
74 : const char* pFunction,
75 : sal_uLong nFunctionLen,
76 : va_list ap )
77 : {
78 0 : std::vector< PtrStruct > aList;
79 0 : aList.reserve( 5 );
80 :
81 0 : sal_uLong nDataSize = nFunctionLen + sizeof( sal_uLong );
82 : char* pNext;
83 :
84 0 : do {
85 0 : pNext = va_arg( ap, char* );
86 0 : if( pNext )
87 : {
88 0 : aList.push_back( PtrStruct( pNext, va_arg( ap, sal_uLong ) ) );
89 0 : nDataSize += aList.back().nBytes + sizeof(sal_uLong);
90 : }
91 : } while( pNext );
92 :
93 0 : rpBuffer = new char[ nDataSize ];
94 0 : char* pRun = rpBuffer;
95 0 : memcpy( pRun, &nFunctionLen, sizeof( nFunctionLen ) );
96 0 : pRun += sizeof( nFunctionLen );
97 0 : memcpy( pRun, pFunction, nFunctionLen );
98 0 : pRun += nFunctionLen;
99 :
100 0 : for( std::vector<PtrStruct>::const_iterator it = aList.begin(); it != aList.end(); ++it )
101 : {
102 0 : memcpy( pRun, &it->nBytes, sizeof( sal_uLong ) );
103 0 : pRun += sizeof( sal_uLong );
104 0 : memcpy( pRun, it->pData, it->nBytes );
105 0 : pRun += it->nBytes;
106 : }
107 0 : return nDataSize;
108 : }
109 :
110 0 : MediatorMessage* PluginConnector::Transact( const char* pFunction,
111 : sal_uLong nFunctionLen, ... )
112 : {
113 : va_list ap;
114 : char* pBuffer;
115 :
116 0 : va_start( ap, nFunctionLen );
117 0 : sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
118 0 : va_end( ap );
119 0 : MediatorMessage* pRet = TransactMessage( nSize, pBuffer );
120 0 : delete[] pBuffer;
121 0 : return pRet;
122 : }
123 :
124 0 : MediatorMessage* PluginConnector::Transact( sal_uInt32 nFunction, ... )
125 : {
126 : va_list ap;
127 : char* pBuffer;
128 :
129 0 : va_start( ap, nFunction );
130 0 : sal_uLong nSize = FillBuffer( pBuffer, reinterpret_cast<char*>(&nFunction), sizeof( nFunction ), ap );
131 0 : va_end( ap );
132 0 : MediatorMessage* pRet = TransactMessage( nSize, pBuffer );
133 0 : delete[] pBuffer;
134 0 : return pRet;
135 : }
136 :
137 0 : sal_uLong PluginConnector::Send( sal_uInt32 nFunction, ... )
138 : {
139 : va_list ap;
140 : char* pBuffer;
141 :
142 0 : va_start( ap, nFunction );
143 0 : sal_uLong nSize = FillBuffer( pBuffer, reinterpret_cast<char*>(&nFunction), sizeof( nFunction ), ap );
144 0 : va_end( ap );
145 0 : sal_uLong nRet = SendMessage( nSize, pBuffer );
146 0 : delete[] pBuffer;
147 0 : return nRet;
148 : }
149 :
150 0 : void PluginConnector::Respond( sal_uLong nID,
151 : char* pFunction,
152 : sal_uLong nFunctionLen, ... )
153 : {
154 : va_list ap;
155 : char* pBuffer;
156 :
157 0 : va_start( ap, nFunctionLen );
158 0 : sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
159 0 : va_end( ap );
160 0 : SendMessage( nSize, pBuffer, nID | ( 1 << 24 ) );
161 0 : delete[] pBuffer;
162 0 : }
163 :
164 0 : MediatorMessage* PluginConnector::WaitForAnswer( sal_uLong nMessageID )
165 : {
166 0 : if( ! m_bValid )
167 0 : return NULL;
168 :
169 0 : nMessageID &= 0x00ffffff;
170 0 : while( m_pListener )
171 : {
172 : {
173 0 : osl::MutexGuard aGuard( m_aQueueMutex );
174 0 : for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
175 : {
176 0 : MediatorMessage* pMessage = m_aMessageQueue[ i ];
177 0 : sal_uLong nID = pMessage->m_nID;
178 0 : if( ( nID & 0xff000000 ) &&
179 0 : ( ( nID & 0x00ffffff ) == nMessageID ) )
180 : {
181 0 : m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
182 0 : return pMessage;
183 : }
184 0 : }
185 : }
186 0 : if( ! m_aMessageQueue.empty() )
187 0 : CallWorkHandler();
188 0 : WaitForMessage( 2000 );
189 : }
190 0 : return NULL;
191 : }
192 :
193 0 : ConnectorInstance::ConnectorInstance( NPP inst, char* type,
194 : int args, char* pargnbuf, sal_uLong nargnbytes,
195 : char* pargvbuf, sal_uLong nargvbytes,
196 : char* savedata, sal_uLong savebytes ) :
197 : instance( inst ),
198 : pShell( NULL ),
199 : pWidget( NULL ),
200 : pForm( NULL ),
201 : pGtkWindow( NULL ),
202 : pGtkWidget( NULL ),
203 : bShouldUseXEmbed( false ),
204 : nArg( args ),
205 : pArgnBuf( pargnbuf ),
206 0 : pArgvBuf( pargvbuf )
207 : {
208 0 : memset( &window, 0, sizeof(window) );
209 0 : pMimeType = new char[ strlen( type ) + 1 ];
210 0 : strcpy( pMimeType, type );
211 0 : aData.len = savebytes;
212 0 : aData.buf = savedata;
213 0 : argn = new char*[ nArg ];
214 0 : argv = new char*[ nArg ];
215 : int i;
216 0 : char* pRun = pArgnBuf;
217 0 : for( i = 0; i < nArg; i++ )
218 : {
219 0 : argn[i] = pRun;
220 0 : while( *pRun != 0 && (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
221 0 : pRun++;
222 0 : if( (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
223 0 : pRun++;
224 : }
225 0 : pRun = pArgvBuf;
226 0 : for( i = 0; i < nArg; i++ )
227 : {
228 0 : argv[i] = pRun;
229 0 : while( *pRun != 0 && (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
230 0 : pRun++;
231 0 : if( (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
232 0 : pRun++;
233 : }
234 0 : }
235 :
236 0 : ConnectorInstance::~ConnectorInstance()
237 : {
238 0 : delete [] pMimeType;
239 0 : delete [] argn;
240 0 : delete [] argv;
241 0 : delete [] pArgnBuf;
242 0 : delete [] pArgvBuf;
243 0 : delete [] static_cast<char*>(aData.buf);
244 0 : }
245 :
246 0 : const char* GetCommandName( CommandAtoms eCommand )
247 : {
248 0 : switch( eCommand )
249 : {
250 0 : case eNPN_GetURL: return "NPN_GetURL";
251 0 : case eNPN_GetURLNotify: return "NPN_GetURLNotify";
252 0 : case eNPN_DestroyStream: return "NPN_DestroyStream";
253 0 : case eNPN_NewStream: return "NPN_NewStream";
254 0 : case eNPN_PostURLNotify: return "NPN_PostURLNotify";
255 0 : case eNPN_PostURL: return "NPN_PostURL";
256 0 : case eNPN_RequestRead: return "NPN_RequestRead";
257 0 : case eNPN_Status: return "NPN_Status";
258 0 : case eNPN_Version: return "NPN_Version";
259 0 : case eNPN_Write: return "NPN_Write";
260 0 : case eNPN_UserAgent: return "NPN_UserAgent";
261 :
262 0 : case eNPP_DestroyStream: return "NPP_DestroyStream";
263 0 : case eNPP_Destroy: return "NPP_Destroy";
264 0 : case eNPP_DestroyPhase2: return "NPP_DestroyPhase2";
265 0 : case eNPP_NewStream: return "NPP_NewStream";
266 0 : case eNPP_New: return "NPP_New";
267 0 : case eNPP_SetWindow: return "NPP_SetWindow";
268 0 : case eNPP_StreamAsFile: return "NPP_StreamAsFile";
269 0 : case eNPP_URLNotify: return "NPP_URLNotify";
270 0 : case eNPP_WriteReady: return "NPP_WriteReady";
271 0 : case eNPP_Write: return "NPP_Write";
272 0 : case eNPP_GetMIMEDescription: return "NPP_GetMIMEDescription";
273 0 : case eNPP_Initialize: return "NPP_Initialize";
274 0 : case eNPP_Shutdown: return "NPP_Shutdown";
275 :
276 0 : case eMaxCommand: return "eMaxCommand";
277 0 : default: return "unknown command";
278 : }
279 : return NULL;
280 : }
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|