void uno_EnvDcp_getPurpose(rtl_uString const * pEnvDcp, rtl_uString ** ppEnvPurpose) { sal_Int32 colIdx = rtl_ustr_indexOfChar_WithLength(pEnvDcp->buffer, pEnvDcp->length, ':'); if (colIdx >= 0) rtl_uString_newFromStr_WithLength(ppEnvPurpose, pEnvDcp->buffer + colIdx, pEnvDcp->length - colIdx); else rtl_uString_new(ppEnvPurpose); }
/* Send args to the OOo instance (using the 'fd' file descriptor) */ static sal_Bool send_args( int fd, rtl_uString *pCwdPath ) { rtl_uString *pBuffer = NULL, *pTmp = NULL; sal_Int32 nCapacity = 1000; rtl_String *pOut = NULL; sal_Bool bResult; size_t nLen; rtl_uString *pEscapedCwdPath = escape_path( pCwdPath ); sal_uInt32 nArg = 0; sal_uInt32 nArgCount = rtl_getAppCommandArgCount(); rtl_uString_new_WithLength( &pBuffer, nCapacity ); rtl_uString_new( &pTmp ); rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), RTL_CONSTASCII_STRINGPARAM( "InternalIPC::Arguments" ) ); if ( rtl_uString_getLength( pEscapedCwdPath ) ) { rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), RTL_CONSTASCII_STRINGPARAM( "1" ) ); rtl_uStringbuffer_insert( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), rtl_uString_getStr( pEscapedCwdPath ), rtl_uString_getLength( pEscapedCwdPath ) ); } else { rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), RTL_CONSTASCII_STRINGPARAM( "0" ) ); } for ( nArg = 0; nArg < nArgCount; ++nArg ) { rtl_uString *pEscapedTmp = NULL; rtl_uStringbuffer_insert_ascii( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), ",", 1 ); rtl_getAppCommandArg( nArg, &pTmp ); pEscapedTmp = escape_path( pTmp ); rtl_uStringbuffer_insert( &pBuffer, &nCapacity, rtl_uString_getLength( pBuffer ), rtl_uString_getStr( pEscapedTmp ), rtl_uString_getLength( pEscapedTmp ) ); rtl_uString_release( pEscapedTmp ); } if ( !rtl_convertUStringToString( &pOut, rtl_uString_getStr( pBuffer ), rtl_uString_getLength( pBuffer ), RTL_TEXTENCODING_UTF8, ( RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR ) ) ) { fprintf( stderr, "ERROR: cannot convert arguments to UTF-8\n" ); exit( 1 ); } nLen = rtl_string_getLength( pOut ) + 1; bResult = ( write( fd, rtl_string_getStr( pOut ), nLen ) == (ssize_t) nLen ); if ( bResult ) { char resp[ strlen( "InternalIPC::ProcessingDone" ) ]; ssize_t n = read( fd, resp, SAL_N_ELEMENTS( resp ) ); bResult = n == (ssize_t) SAL_N_ELEMENTS( resp ) && (memcmp( resp, "InternalIPC::ProcessingDone", SAL_N_ELEMENTS( resp ) ) == 0); } /* cleanup */ rtl_uString_release( pEscapedCwdPath ); rtl_uString_release( pBuffer ); rtl_uString_release( pTmp ); rtl_string_release( pOut ); return bResult; }
/* Construct the pipe name */ static rtl_uString * get_pipe_path( rtl_uString *pAppPath ) { rtl_uString *pPath = NULL, *pTmp = NULL, *pUserInstallation = NULL; rtl_uString *pResult = NULL, *pBasePath = NULL, *pAbsUserInstallation = NULL; rtlBootstrapHandle handle; rtl_uString *pMd5hash = NULL; sal_Unicode pUnicode[RTL_USTR_MAX_VALUEOFINT32]; /* setup bootstrap filename */ rtl_uString_newFromAscii( &pPath, "file://" ); rtl_uString_newConcat( &pPath, pPath, pAppPath ); rtl_uString_newConcat( &pPath, pPath, pTmp ); rtl_uString_newFromAscii( &pTmp, SAL_CONFIGFILE( "bootstrap" ) ); rtl_uString_newConcat( &pPath, pPath, pTmp ); /* read userinstallation value */ handle = rtl_bootstrap_args_open( pPath ); rtl_uString_newFromAscii( &pTmp, "UserInstallation" ); rtl_bootstrap_get_from_handle( handle, pTmp, &pUserInstallation, NULL ); rtl_bootstrap_args_close( handle ); /* turn it into an absolute path - unwinding symlinks etc. */ if ( osl_getProcessWorkingDir (&pBasePath) || osl_getAbsoluteFileURL( pBasePath, pUserInstallation, &pAbsUserInstallation ) ) rtl_uString_newFromString (&pAbsUserInstallation, pUserInstallation); /* create the pipe name */ pMd5hash = get_md5hash( pAbsUserInstallation ); if ( !pMd5hash ) rtl_uString_new( &pMd5hash ); if ( access( PIPEDEFAULTPATH, W_OK ) == 0 ) rtl_uString_newFromAscii( &pResult, PIPEDEFAULTPATH ); else if ( access( PIPEALTERNATEPATH, W_OK ) == 0 ) rtl_uString_newFromAscii( &pResult, PIPEALTERNATEPATH ); else { fprintf( stderr, "ERROR: no valid pipe path found.\n" ); exit( 1 ); } rtl_uString_newFromAscii( &pTmp, "/OSL_PIPE_" ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_ustr_valueOfInt32( pUnicode, (int)getuid(), 10 ); rtl_uString_newFromStr( &pTmp, pUnicode ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_uString_newFromAscii( &pTmp, "_SingleOfficeIPC_" ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_uString_newConcat( &pResult, pResult, pMd5hash ); /* cleanup */ rtl_uString_release( pMd5hash ); rtl_uString_release( pPath ); rtl_uString_release( pTmp ); if ( pBasePath ) { rtl_uString_release( pBasePath ); } rtl_uString_release( pUserInstallation ); rtl_uString_release( pAbsUserInstallation ); return pResult; }