merge the formfield patch from ooo-build
[ooovba.git] / applied_patches / 0112-unxsplash-new-osl-pipe.diff
blob7ff71c4b7a4611a496ec23fbccfccab4aacc92a6
1 diff --git a/desktop/unx/source/start.c b/desktop/unx/source/start.c
2 index 05ef574..c7d5d4c 100644
3 --- desktop/unx/source/start.c
4 +++ desktop/unx/source/start.c
5 @@ -49,8 +49,10 @@
7 #include <osl/nlsupport.h>
8 #include <osl/process.h>
9 +#include <osl/thread.h>
10 #include <rtl/bootstrap.h>
11 #include <rtl/digest.h>
12 +#include <rtl/ustrbuf.h>
13 #include <sal/main.h>
15 #include "splashx.h"
16 @@ -131,7 +133,7 @@ get_md5hash( rtl_uString *pText )
17 return NULL;
19 rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
20 - if ( digest <= 0 )
21 + if ( digest == 0 )
22 return NULL;
24 sal_uInt32 md5_key_len = rtl_digest_queryLength( digest );
25 @@ -254,33 +256,108 @@ connect_pipe( rtl_uString *pPipePath )
26 return fd;
29 +/* Escape: "," -> "\\,", "\0" -> "\\0", "\\" -> "\\\\" */
30 +static rtl_uString *
31 +escape_path( rtl_uString *pToEscape )
33 + rtl_uString *pBuffer = NULL;
34 + sal_Int32 nCapacity = 1000;
36 + rtl_uString_new_WithLength( &pBuffer, nCapacity );
38 + sal_Int32 i = 0;
39 + sal_Int32 nEscapeLength = rtl_uString_getLength( pToEscape );
40 + for ( ; i < nEscapeLength; ++i )
41 + {
42 + sal_Unicode c = pToEscape->buffer[i];
43 + switch ( c )
44 + {
45 + case (sal_Unicode)'\0':
46 + rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
47 + rtl_uString_getLength( pBuffer ),
48 + RTL_CONSTASCII_STRINGPARAM( "\\0" ) );
49 + break;
50 + case (sal_Unicode)',':
51 + rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
52 + rtl_uString_getLength( pBuffer ),
53 + RTL_CONSTASCII_STRINGPARAM( "\\," ) );
54 + break;
55 + case (sal_Unicode)'\\':
56 + rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
57 + rtl_uString_getLength( pBuffer ),
58 + RTL_CONSTASCII_STRINGPARAM( "\\\\" ) );
59 + break;
60 + default:
61 + rtl_uStringbuffer_insert( &pBuffer, &nCapacity,
62 + rtl_uString_getLength( pBuffer ),
63 + &c, 1 );
64 + }
65 + }
67 + return pBuffer;
70 /* Send args to the OOo instance (using the 'fd' file descriptor) */
71 static sal_Bool
72 -send_args( int fd )
73 +send_args( int fd, rtl_uString *pCwdPath )
75 rtl_uString *pBuffer = NULL, *pTmp = NULL;
76 - sal_Int32 nCapacity = 100;
77 + sal_Int32 nCapacity = 1000;
78 rtl_String *pOut = NULL;
79 sal_Bool bResult;
80 size_t nLen;
81 + rtl_uString *pEscapedCwdPath = escape_path( pCwdPath );
83 rtl_uString_new_WithLength( &pBuffer, nCapacity );
84 rtl_uString_new( &pTmp );
86 + rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
87 + rtl_uString_getLength( pBuffer ),
88 + RTL_CONSTASCII_STRINGPARAM( "InternalIPC::Arguments" ) );
90 + sal_Bool bDontConvertNext = sal_False;
91 sal_uInt32 nArg;
92 sal_uInt32 nArgCount = osl_getCommandArgCount();
93 for ( nArg = 0; nArg < nArgCount; ++nArg )
95 + rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
96 + rtl_uString_getLength( pBuffer ),
97 + ",", 1 );
99 osl_getCommandArg( nArg, &pTmp );
101 + if ( rtl_uString_getLength( pTmp ) == 0 )
102 + continue;
104 + // this is not a param, we have to prepend filenames with file://
105 + // FIXME: improve the check
106 + if ( pTmp->buffer[0] != (sal_Unicode)'-' )
108 + sal_Int32 nFirstColon = rtl_ustr_indexOfChar_WithLength( pTmp->buffer, pTmp->length, ':' );
109 + sal_Int32 nFirstSlash = rtl_ustr_indexOfChar_WithLength( pTmp->buffer, pTmp->length, '/' );
111 + // check that pTmp is not an URI yet
112 + if ( nFirstColon < 1 || ( nFirstSlash != nFirstColon + 1 ) )
114 + // some of the switches (currently just -pt) don't want to
115 + // have the filenames as URIs
116 + if ( !bDontConvertNext )
117 + osl_getAbsoluteFileURL( pCwdPath, pTmp, &pTmp );
121 + // don't convert filenames with some of the switches
122 + // (currently just -pt)
123 + bDontConvertNext = !rtl_ustr_ascii_compareIgnoreAsciiCase( pTmp->buffer, "-pt" );
125 + rtl_uString *pEscapedTmp = escape_path( pTmp );
127 rtl_uStringbuffer_insert( &pBuffer, &nCapacity,
128 rtl_uString_getLength( pBuffer ),
129 - rtl_uString_getStr( pTmp ),
130 - rtl_uString_getLength( pTmp ) );
131 + rtl_uString_getStr( pEscapedTmp ),
132 + rtl_uString_getLength( pEscapedTmp ) );
134 - rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity,
135 - rtl_uString_getLength( pBuffer ),
136 - "|", 1 );
137 + rtl_uString_release( pEscapedTmp );
140 ustr_debug( "Pass args", pBuffer );
141 @@ -288,9 +365,10 @@ send_args( int fd )
142 pOut = ustr_to_str( pBuffer );
144 nLen = rtl_string_getLength( pOut ) + 1;
145 - bResult = ( write( fd, rtl_string_getStr( pOut ), nLen ) == nLen );
146 + bResult = ( write( fd, rtl_string_getStr( pOut ), nLen ) == (ssize_t) nLen );
148 /* cleanup */
149 + rtl_uString_release( pEscapedCwdPath );
150 rtl_uString_release( pBuffer );
151 rtl_uString_release( pTmp );
152 rtl_string_release( pOut );
153 @@ -422,7 +500,7 @@ read_percent( int status_fd, int *pPercent )
155 static char pBuffer[BUFFER_LEN + 1];
156 static char *pNext = pBuffer;
157 - static size_t nRead = 0;
158 + static ssize_t nRead = 0;
160 char *pBegin;
161 char *pIter;
162 @@ -681,7 +759,12 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
163 pPipePath = get_pipe_path( pAppPath );
165 if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
166 - bSentArgs = send_args( fd );
168 + rtl_uString *pCwdPath = NULL;
169 + osl_getProcessWorkingDir( &pCwdPath );
171 + bSentArgs = send_args( fd, pCwdPath );
173 #if OSL_DEBUG_LEVEL > 0
174 else
175 ustr_debug( "Failed to connect to pipe", pPipePath );