xref: /reactos/dll/win32/jsproxy/main.c (revision cc439606)
1 /*
2  * Copyright 2014 Hans Leidekker for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "config.h"
20 #include "wine/port.h"
21 
22 #include <stdarg.h>
23 #include <sys/types.h>
24 #ifdef HAVE_SYS_SOCKET_H
25 # include <sys/socket.h>
26 #endif
27 #ifdef HAVE_NETINET_IN_H
28 # include <netinet/in.h>
29 #endif
30 #ifdef HAVE_NETDB_H
31 # include <netdb.h>
32 #endif
33 #ifdef __REACTOS__
34 #define COBJMACROS
35 #endif
36 #if defined(__MINGW32__) || defined (_MSC_VER)
37 # include <ws2tcpip.h>
38 #else
39 # define closesocket close
40 # define ioctlsocket ioctl
41 #endif
42 
43 #include "windef.h"
44 #include "winbase.h"
45 #ifndef __MINGW32__
46 #define USE_WS_PREFIX
47 #endif
48 #include "winsock2.h"
49 #include "ws2ipdef.h"
50 #include "winnls.h"
51 #include "wininet.h"
52 #ifndef __REACTOS__
53 #define COBJMACROS
54 #endif
55 #include "ole2.h"
56 #include "dispex.h"
57 #include "activscp.h"
58 #include "wine/debug.h"
59 #include "wine/heap.h"
60 #include "wine/unicode.h"
61 
62 static HINSTANCE instance;
63 
64 WINE_DEFAULT_DEBUG_CHANNEL(jsproxy);
65 
66 static CRITICAL_SECTION cs_jsproxy;
67 static CRITICAL_SECTION_DEBUG critsect_debug =
68 {
69     0, 0, &cs_jsproxy,
70     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
71       0, 0, { (DWORD_PTR)(__FILE__ ": cs_jsproxy") }
72 };
73 static CRITICAL_SECTION cs_jsproxy = { &critsect_debug, -1, 0, 0, 0, 0 };
74 
75 static const WCHAR global_funcsW[] = {'g','l','o','b','a','l','_','f','u','n','c','s',0};
76 static const WCHAR dns_resolveW[] = {'d','n','s','_','r','e','s','o','l','v','e',0};
77 
78 /******************************************************************
79  *      DllMain (jsproxy.@)
80  */
81 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
82 {
83     switch (reason)
84     {
85     case DLL_PROCESS_ATTACH:
86         instance = hinst;
87         DisableThreadLibraryCalls( hinst );
88         break;
89 
90     case DLL_PROCESS_DETACH:
91         break;
92     }
93     return TRUE;
94 }
95 
96 static inline WCHAR *strdupAW( const char *src, int len )
97 {
98     WCHAR *dst = NULL;
99     if (src)
100     {
101         int dst_len = MultiByteToWideChar( CP_ACP, 0, src, len, NULL, 0 );
102         if ((dst = heap_alloc( (dst_len + 1) * sizeof(WCHAR) )))
103         {
104             len = MultiByteToWideChar( CP_ACP, 0, src, len, dst, dst_len );
105             dst[dst_len] = 0;
106         }
107     }
108     return dst;
109 }
110 
111 static inline char *strdupWA( const WCHAR *src )
112 {
113     char *dst = NULL;
114     if (src)
115     {
116         int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
117         if ((dst = heap_alloc( len ))) WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
118     }
119     return dst;
120 }
121 
122 static struct pac_script
123 {
124     WCHAR *text;
125 } pac_script;
126 static struct pac_script *global_script = &pac_script;
127 
128 /******************************************************************
129  *      InternetDeInitializeAutoProxyDll (jsproxy.@)
130  */
131 BOOL WINAPI InternetDeInitializeAutoProxyDll( LPSTR mime, DWORD reserved )
132 {
133     TRACE( "%s, %u\n", debugstr_a(mime), reserved );
134 
135     EnterCriticalSection( &cs_jsproxy );
136 
137     heap_free( global_script->text );
138     global_script->text = NULL;
139 
140     LeaveCriticalSection( &cs_jsproxy );
141     return TRUE;
142 }
143 
144 static WCHAR *load_script( const char *filename )
145 {
146     HANDLE handle;
147     DWORD size, bytes_read;
148     char *buffer;
149     int len;
150     WCHAR *script = NULL;
151 
152     handle = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
153     if (handle == INVALID_HANDLE_VALUE) return NULL;
154 
155     size = GetFileSize( handle, NULL );
156     if (!(buffer = heap_alloc( size ))) goto done;
157     if (!ReadFile( handle, buffer, size, &bytes_read, NULL ) || bytes_read != size) goto done;
158 
159     len = MultiByteToWideChar( CP_ACP, 0, buffer, size, NULL, 0 );
160     if (!(script = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done;
161     MultiByteToWideChar( CP_ACP, 0, buffer, size, script, len );
162     script[len] = 0;
163 
164 done:
165     CloseHandle( handle );
166     heap_free( buffer );
167     return script;
168 }
169 
170 /******************************************************************
171  *      InternetInitializeAutoProxyDll (jsproxy.@)
172  */
173 BOOL WINAPI JSPROXY_InternetInitializeAutoProxyDll( DWORD version, LPSTR tmpfile, LPSTR mime,
174                                                     AutoProxyHelperFunctions *callbacks,
175                                                     LPAUTO_PROXY_SCRIPT_BUFFER buffer )
176 {
177     BOOL ret = FALSE;
178 
179     TRACE( "%u, %s, %s, %p, %p\n", version, debugstr_a(tmpfile), debugstr_a(mime), callbacks, buffer );
180 
181     if (callbacks) FIXME( "callbacks not supported\n" );
182 
183     EnterCriticalSection( &cs_jsproxy );
184 
185     if (buffer && buffer->dwStructSize == sizeof(*buffer) && buffer->lpszScriptBuffer)
186     {
187         DWORD i, len = 0;
188         for (i = 0; i < buffer->dwScriptBufferSize; i++)
189         {
190             if (!buffer->lpszScriptBuffer[i]) break;
191             len++;
192         }
193         if (len == buffer->dwScriptBufferSize)
194         {
195             SetLastError( ERROR_INVALID_PARAMETER );
196             LeaveCriticalSection( &cs_jsproxy );
197             return FALSE;
198         }
199         heap_free( global_script->text );
200         if ((global_script->text = strdupAW( buffer->lpszScriptBuffer, len ))) ret = TRUE;
201     }
202     else
203     {
204         heap_free( global_script->text );
205         if ((global_script->text = load_script( tmpfile ))) ret = TRUE;
206     }
207 
208     LeaveCriticalSection( &cs_jsproxy );
209     return ret;
210 }
211 
212 static HRESULT WINAPI dispex_QueryInterface(
213     IDispatchEx *iface, REFIID riid, void **ppv )
214 {
215     *ppv = NULL;
216 
217     if (IsEqualGUID( riid, &IID_IUnknown )  ||
218         IsEqualGUID( riid, &IID_IDispatch ) ||
219         IsEqualGUID( riid, &IID_IDispatchEx ))
220         *ppv = iface;
221     else
222         return E_NOINTERFACE;
223 
224     return S_OK;
225 }
226 
227 static ULONG WINAPI dispex_AddRef(
228     IDispatchEx *iface )
229 {
230     return 2;
231 }
232 
233 static ULONG WINAPI dispex_Release(
234     IDispatchEx *iface )
235 {
236     return 1;
237 }
238 
239 static HRESULT WINAPI dispex_GetTypeInfoCount(
240     IDispatchEx *iface, UINT *info )
241 {
242     return E_NOTIMPL;
243 }
244 
245 static HRESULT WINAPI dispex_GetTypeInfo(
246     IDispatchEx *iface, UINT info, LCID lcid, ITypeInfo **type_info )
247 {
248     return E_NOTIMPL;
249 }
250 
251 static HRESULT WINAPI dispex_GetIDsOfNames(
252     IDispatchEx *iface, REFIID riid, LPOLESTR *names, UINT count, LCID lcid, DISPID *id )
253 {
254     return E_NOTIMPL;
255 }
256 
257 static HRESULT WINAPI dispex_Invoke(
258     IDispatchEx *iface, DISPID member, REFIID riid, LCID lcid, WORD flags,
259     DISPPARAMS *params, VARIANT *result, EXCEPINFO *excep, UINT *err )
260 {
261     return E_NOTIMPL;
262 }
263 
264 static HRESULT WINAPI dispex_DeleteMemberByName(
265     IDispatchEx *iface, BSTR name, DWORD flags )
266 {
267     return E_NOTIMPL;
268 }
269 
270 static HRESULT WINAPI dispex_DeleteMemberByDispID(
271     IDispatchEx *iface, DISPID id )
272 {
273     return E_NOTIMPL;
274 }
275 
276 static HRESULT WINAPI dispex_GetMemberProperties(
277     IDispatchEx *iface, DISPID id, DWORD flags_fetch, DWORD *flags )
278 {
279     return E_NOTIMPL;
280 }
281 
282 static HRESULT WINAPI dispex_GetMemberName(
283     IDispatchEx *iface, DISPID id, BSTR *name )
284 {
285     return E_NOTIMPL;
286 }
287 
288 static HRESULT WINAPI dispex_GetNextDispID(
289     IDispatchEx *iface, DWORD flags, DISPID id, DISPID *next )
290 {
291     return E_NOTIMPL;
292 }
293 
294 static HRESULT WINAPI dispex_GetNameSpaceParent(
295     IDispatchEx *iface, IUnknown **unk )
296 {
297     return E_NOTIMPL;
298 }
299 
300 #define DISPID_GLOBAL_DNSRESOLVE  0x1000
301 
302 static HRESULT WINAPI dispex_GetDispID(
303     IDispatchEx *iface, BSTR name, DWORD flags, DISPID *id )
304 {
305     if (!strcmpW( name, dns_resolveW ))
306     {
307         *id = DISPID_GLOBAL_DNSRESOLVE;
308         return S_OK;
309     }
310     return DISP_E_UNKNOWNNAME;
311 }
312 
313 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
314 {
315     char *ret;
316     DWORD size = 0;
317 
318     GetComputerNameExA( format, NULL, &size );
319     if (GetLastError() != ERROR_MORE_DATA) return NULL;
320     if (!(ret = heap_alloc( size ))) return NULL;
321     if (!GetComputerNameExA( format, ret, &size ))
322     {
323         heap_free( ret );
324         return NULL;
325     }
326     return ret;
327 }
328 
329 static void printf_addr( const WCHAR *fmt, WCHAR *buf, struct sockaddr_in *addr )
330 {
331     sprintfW( buf, fmt,
332               (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 24 & 0xff),
333               (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 16 & 0xff),
334               (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 8 & 0xff),
335               (unsigned int)(ntohl( addr->sin_addr.s_addr ) & 0xff) );
336 }
337 
338 static HRESULT dns_resolve( const WCHAR *hostname, VARIANT *result )
339 {
340 #ifdef HAVE_GETADDRINFO
341         static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
342         WCHAR addr[16];
343         struct addrinfo *ai, *elem;
344         char *hostnameA;
345         int res;
346 
347         if (hostname[0])
348             hostnameA = strdupWA( hostname );
349         else
350             hostnameA = get_computer_name( ComputerNamePhysicalDnsFullyQualified );
351 
352         if (!hostnameA) return E_OUTOFMEMORY;
353         res = getaddrinfo( hostnameA, NULL, NULL, &ai );
354         heap_free( hostnameA );
355         if (res) return S_FALSE;
356 
357         elem = ai;
358         while (elem && elem->ai_family != AF_INET) elem = elem->ai_next;
359         if (!elem)
360         {
361             freeaddrinfo( ai );
362             return S_FALSE;
363         }
364         printf_addr( fmtW, addr, (struct sockaddr_in *)elem->ai_addr );
365         freeaddrinfo( ai );
366         V_VT( result ) = VT_BSTR;
367         V_BSTR( result ) = SysAllocString( addr );
368         return S_OK;
369 #else
370         FIXME("getaddrinfo not found at build time\n");
371         return S_FALSE;
372 #endif
373 }
374 
375 static HRESULT WINAPI dispex_InvokeEx(
376     IDispatchEx *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
377     VARIANT *result, EXCEPINFO *exep, IServiceProvider *caller )
378 {
379     if (id == DISPID_GLOBAL_DNSRESOLVE)
380     {
381         if (params->cArgs != 1) return DISP_E_BADPARAMCOUNT;
382         if (V_VT(&params->rgvarg[0]) != VT_BSTR) return DISP_E_BADVARTYPE;
383         return dns_resolve( V_BSTR(&params->rgvarg[0]), result );
384     }
385     return DISP_E_MEMBERNOTFOUND;
386 }
387 
388 static const IDispatchExVtbl dispex_vtbl =
389 {
390     dispex_QueryInterface,
391     dispex_AddRef,
392     dispex_Release,
393     dispex_GetTypeInfoCount,
394     dispex_GetTypeInfo,
395     dispex_GetIDsOfNames,
396     dispex_Invoke,
397     dispex_GetDispID,
398     dispex_InvokeEx,
399     dispex_DeleteMemberByName,
400     dispex_DeleteMemberByDispID,
401     dispex_GetMemberProperties,
402     dispex_GetMemberName,
403     dispex_GetNextDispID,
404     dispex_GetNameSpaceParent
405 };
406 
407 static IDispatchEx global_dispex = { &dispex_vtbl };
408 
409 static HRESULT WINAPI site_QueryInterface(
410     IActiveScriptSite *iface, REFIID riid, void **ppv )
411 {
412     *ppv = NULL;
413 
414     if (IsEqualGUID( &IID_IUnknown, riid ))
415         *ppv = iface;
416     else if (IsEqualGUID( &IID_IActiveScriptSite, riid ))
417         *ppv = iface;
418     else
419         return E_NOINTERFACE;
420 
421     IUnknown_AddRef( (IUnknown *)*ppv );
422     return S_OK;
423 }
424 
425 static ULONG WINAPI site_AddRef(
426     IActiveScriptSite *iface )
427 {
428     return 2;
429 }
430 
431 static ULONG WINAPI site_Release(
432     IActiveScriptSite *iface )
433 {
434     return 1;
435 }
436 
437 static HRESULT WINAPI site_GetLCID(
438     IActiveScriptSite *iface, LCID *lcid )
439 {
440     return E_NOTIMPL;
441 }
442 
443 static HRESULT WINAPI site_GetItemInfo(
444     IActiveScriptSite *iface, LPCOLESTR name, DWORD mask,
445     IUnknown **item, ITypeInfo **type_info )
446 {
447     if (!strcmpW( name, global_funcsW ) && mask == SCRIPTINFO_IUNKNOWN)
448     {
449         *item = (IUnknown *)&global_dispex;
450         return S_OK;
451     }
452     return E_NOTIMPL;
453 }
454 
455 static HRESULT WINAPI site_GetDocVersionString(
456     IActiveScriptSite *iface, BSTR *version )
457 {
458     return E_NOTIMPL;
459 }
460 
461 static HRESULT WINAPI site_OnScriptTerminate(
462     IActiveScriptSite *iface, const VARIANT *result, const EXCEPINFO *info )
463 {
464     return E_NOTIMPL;
465 }
466 
467 static HRESULT WINAPI site_OnStateChange(
468     IActiveScriptSite *iface, SCRIPTSTATE state )
469 {
470     return E_NOTIMPL;
471 }
472 
473 static HRESULT WINAPI site_OnScriptError(
474     IActiveScriptSite *iface, IActiveScriptError *error )
475 {
476     return E_NOTIMPL;
477 }
478 
479 static HRESULT WINAPI site_OnEnterScript(
480     IActiveScriptSite *iface )
481 {
482     return E_NOTIMPL;
483 }
484 
485 static HRESULT WINAPI site_OnLeaveScript(
486     IActiveScriptSite *iface )
487 {
488     return E_NOTIMPL;
489 }
490 
491 static const IActiveScriptSiteVtbl site_vtbl =
492 {
493     site_QueryInterface,
494     site_AddRef,
495     site_Release,
496     site_GetLCID,
497     site_GetItemInfo,
498     site_GetDocVersionString,
499     site_OnScriptTerminate,
500     site_OnStateChange,
501     site_OnScriptError,
502     site_OnEnterScript,
503     site_OnLeaveScript
504 };
505 
506 static IActiveScriptSite script_site = { &site_vtbl };
507 
508 static BSTR include_pac_utils( const WCHAR *script )
509 {
510     static const WCHAR pacjsW[] = {'p','a','c','.','j','s',0};
511     HMODULE hmod = GetModuleHandleA( "jsproxy.dll" );
512     HRSRC rsrc;
513     DWORD size;
514     const char *data;
515     BSTR ret;
516     int len;
517 
518     if (!(rsrc = FindResourceW( hmod, pacjsW, (LPCWSTR)40 ))) return NULL;
519     size = SizeofResource( hmod, rsrc );
520     data = LoadResource( hmod, rsrc );
521 
522     len = MultiByteToWideChar( CP_ACP, 0, data, size, NULL, 0 );
523     if (!(ret = SysAllocStringLen( NULL, len + strlenW( script ) + 1 ))) return NULL;
524     MultiByteToWideChar( CP_ACP, 0, data, size, ret, len );
525     strcpyW( ret + len, script );
526     return ret;
527 }
528 
529 #ifdef _WIN64
530 #define IActiveScriptParse_Release IActiveScriptParse64_Release
531 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
532 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
533 #else
534 #define IActiveScriptParse_Release IActiveScriptParse32_Release
535 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
536 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
537 #endif
538 
539 static BOOL run_script( const WCHAR *script, const WCHAR *url, const WCHAR *hostname, char **result_str, DWORD *result_len )
540 {
541     static const WCHAR jscriptW[] = {'J','S','c','r','i','p','t',0};
542     static const WCHAR findproxyW[] = {'F','i','n','d','P','r','o','x','y','F','o','r','U','R','L',0};
543     IActiveScriptParse *parser = NULL;
544     IActiveScript *engine = NULL;
545     IDispatch *dispatch = NULL;
546     BOOL ret = FALSE;
547     CLSID clsid;
548     DISPID dispid;
549     BSTR func = NULL, full_script = NULL;
550     VARIANT args[2], retval;
551     DISPPARAMS params;
552     HRESULT hr, init;
553 
554     init = CoInitialize( NULL );
555     hr = CLSIDFromProgID( jscriptW, &clsid );
556     if (hr != S_OK) goto done;
557 
558     hr = CoCreateInstance( &clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
559                            &IID_IActiveScript, (void **)&engine );
560     if (hr != S_OK) goto done;
561 
562     hr = IActiveScript_QueryInterface( engine, &IID_IActiveScriptParse, (void **)&parser );
563     if (hr != S_OK) goto done;
564 
565     hr = IActiveScriptParse_InitNew( parser );
566     if (hr != S_OK) goto done;
567 
568     hr = IActiveScript_SetScriptSite( engine, &script_site );
569     if (hr != S_OK) goto done;
570 
571     hr = IActiveScript_AddNamedItem( engine, global_funcsW, SCRIPTITEM_GLOBALMEMBERS );
572     if (hr != S_OK) goto done;
573 
574     if (!(full_script = include_pac_utils( script ))) goto done;
575 
576     hr = IActiveScriptParse_ParseScriptText( parser, full_script, NULL, NULL, NULL, 0, 0, 0, NULL, NULL );
577     if (hr != S_OK) goto done;
578 
579     hr = IActiveScript_SetScriptState( engine, SCRIPTSTATE_STARTED );
580     if (hr != S_OK) goto done;
581 
582     hr = IActiveScript_GetScriptDispatch( engine, NULL, &dispatch );
583     if (hr != S_OK) goto done;
584 
585     if (!(func = SysAllocString( findproxyW ))) goto done;
586     hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &func, 1, LOCALE_SYSTEM_DEFAULT, &dispid );
587     if (hr != S_OK) goto done;
588 
589     V_VT( &args[0] ) = VT_BSTR;
590     V_BSTR( &args[0] ) = SysAllocString( hostname );
591     V_VT( &args[1] ) = VT_BSTR;
592     V_BSTR( &args[1] ) = SysAllocString( url );
593 
594     params.rgvarg = args;
595     params.rgdispidNamedArgs = NULL;
596     params.cArgs = 2;
597     params.cNamedArgs = 0;
598     hr = IDispatch_Invoke( dispatch, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
599                            &params, &retval, NULL, NULL );
600     VariantClear( &args[0] );
601     VariantClear( &args[1] );
602     if (hr != S_OK)
603     {
604         WARN("script failed 0x%08x\n", hr);
605         goto done;
606     }
607     if ((*result_str = strdupWA( V_BSTR( &retval ) )))
608     {
609         TRACE( "result: %s\n", debugstr_a(*result_str) );
610         *result_len = strlen( *result_str ) + 1;
611         ret = TRUE;
612     }
613     VariantClear( &retval );
614 
615 done:
616     SysFreeString( full_script );
617     SysFreeString( func );
618     if (dispatch) IDispatch_Release( dispatch );
619     if (parser) IActiveScriptParse_Release( parser );
620     if (engine) IActiveScript_Release( engine );
621     if (SUCCEEDED( init )) CoUninitialize();
622     return ret;
623 }
624 
625 /******************************************************************
626  *      InternetGetProxyInfo (jsproxy.@)
627  */
628 BOOL WINAPI InternetGetProxyInfo( LPCSTR url, DWORD len_url, LPCSTR hostname, DWORD len_hostname, LPSTR *proxy,
629                                   LPDWORD len_proxy )
630 {
631     WCHAR *urlW = NULL, *hostnameW = NULL;
632     BOOL ret = FALSE;
633 
634     TRACE( "%s, %u, %s, %u, %p, %p\n", debugstr_a(url), len_url, hostname, len_hostname, proxy, len_proxy );
635 
636     EnterCriticalSection( &cs_jsproxy );
637 
638     if (!global_script->text)
639     {
640         SetLastError( ERROR_CAN_NOT_COMPLETE );
641         goto done;
642     }
643     if (hostname && len_hostname < strlen( hostname ))
644     {
645         SetLastError( ERROR_INSUFFICIENT_BUFFER );
646         goto done;
647     }
648     if (!(urlW = strdupAW( url, -1 ))) goto done;
649     if (hostname && !(hostnameW = strdupAW( hostname, -1 ))) goto done;
650 
651     TRACE( "%s\n", debugstr_w(global_script->text) );
652     ret = run_script( global_script->text, urlW, hostnameW, proxy, len_proxy );
653 
654 done:
655     heap_free( hostnameW );
656     heap_free( urlW );
657     LeaveCriticalSection( &cs_jsproxy );
658     return ret;
659 }
660