static sal_Bool cpyBootstrapSocketPath(sal_Char *name, size_t len) { sal_Bool bRet = sal_False; rtl_uString *pName = 0, *pValue = 0; rtl_uString_newFromAscii(&pName, "OSL_SOCKET_PATH"); if (rtl_bootstrap_get(pName, &pValue, NULL)) { if (pValue && pValue->length > 0) { rtl_String *pStrValue = 0; rtl_uString2String(&pStrValue, pValue->buffer, pValue->length, RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS); if (pStrValue) { if (pStrValue->length > 0) { size_t nCopy = (len-1 < (size_t)pStrValue->length) ? len-1 : (size_t)pStrValue->length; strncpy (name, pStrValue->buffer, nCopy); name[nCopy] = '\0'; bRet = (size_t)pStrValue->length < len; } rtl_string_release(pStrValue); } } rtl_uString_release(pName); } return bRet; }
/* Get fd of the pipe of the already running OOo. */ static int connect_pipe( rtl_uString *pPipePath ) { int fd; size_t len; struct sockaddr_un addr; rtl_String *pPipeStr = ustr_to_str( pPipePath ); memset( &addr, 0, sizeof( addr ) ); if ( ( fd = socket( AF_UNIX, SOCK_STREAM, 0 ) ) < 0 ) return fd; (void)fcntl( fd, F_SETFD, FD_CLOEXEC ); addr.sun_family = AF_UNIX; strncpy( addr.sun_path, rtl_string_getStr( pPipeStr ), sizeof( addr.sun_path ) - 1 ); rtl_string_release( pPipeStr ); /* cut / paste from osl's pipe.c */ #if defined(FREEBSD) len = SUN_LEN( &addr ); #else len = sizeof( addr ); #endif if ( connect( fd, (struct sockaddr *)&addr, len ) < 0 ) { close(fd); fd = -1; } return fd; }
oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Options, oslSecurity Security) { oslPipe pPipe=0; rtl_String* strPipeName=0; sal_Char* pszPipeName=0; if ( ustrPipeName != 0 ) { rtl_uString2String( &strPipeName, rtl_uString_getStr(ustrPipeName), rtl_uString_getLength(ustrPipeName), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS ); pszPipeName = rtl_string_getStr(strPipeName); pPipe = osl_psz_createPipe(pszPipeName, Options, Security); if ( strPipeName != 0 ) { rtl_string_release(strPipeName); } } return pPipe; }
/* Compute the OOo md5 hash from 'pText' */ static rtl_uString * get_md5hash( rtl_uString *pText ) { rtl_uString *pResult = NULL; sal_Int32 nCapacity = 100; unsigned char *pData = NULL; sal_uInt32 nSize = 0; rtlDigest digest; sal_uInt32 md5_key_len = 0; sal_uInt8* md5_buf = NULL; sal_uInt32 i = 0; #if OSL_DEBUG_LEVEL > 1 rtl_String *pOut; #endif if ( !pText ) return NULL; #if OSL_DEBUG_LEVEL > 1 pOut = ustr_to_str( pText ); fprintf (stderr, "Generate pipe md5 for '%s'\n", pOut->buffer); rtl_string_release( pOut ); #endif pData = (unsigned char *)rtl_uString_getStr( pText ); nSize = rtl_uString_getLength( pText ) * sizeof( sal_Unicode ); if ( !pData ) return NULL; digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); if ( digest == 0 ) return NULL; md5_key_len = rtl_digest_queryLength( digest ); md5_buf = (sal_uInt8 *)calloc( md5_key_len, sizeof( sal_uInt8 ) ); rtl_digest_init( digest, pData , nSize ); rtl_digest_update( digest, pData, nSize ); rtl_digest_get( digest, md5_buf, md5_key_len ); rtl_digest_destroy( digest ); /* create hex-value string from the MD5 value to keep the string size minimal */ rtl_uString_new_WithLength( &pResult, nCapacity ); for ( ; i < md5_key_len; ++i ) { char val[3]; snprintf( val, 3, "%x", md5_buf[i] ); /* sic! we ignore some of the 0's */ rtl_uStringbuffer_insert_ascii( &pResult, &nCapacity, rtl_uString_getLength( pResult ), val, strlen( val ) ); } /* cleanup */ free( md5_buf ); return pResult; }
void exec_pagein (Args *args) { rtl_String * path = ustr_to_str(args->pAppPath); pagein_execute(rtl_string_getStr(path), "pagein-common"); if (args->pPageinType) { pagein_execute(rtl_string_getStr(path), args->pPageinType); } rtl_string_release(path); }
static void ustr_debug( const char *pMessage, rtl_uString *pStr ) { rtl_String *pOut = ustr_to_str( pStr ); fprintf( stderr, "%s: %s\n", pMessage, rtl_string_getStr( pOut ) ); rtl_string_release( pOut ); return; }
sal_Int32 SAL_CALL rtl_str_valueOfDouble(sal_Char * pStr, double d) { rtl_String * pResult = NULL; sal_Int32 nLen; rtl_math_doubleToString( &pResult, 0, 0, d, rtl_math_StringFormat_G, RTL_STR_MAX_VALUEOFDOUBLE - RTL_CONSTASCII_LENGTH("-x.E-xxx"), '.', 0, 0, sal_True); nLen = pResult->length; OSL_ASSERT(nLen < RTL_STR_MAX_VALUEOFDOUBLE); rtl_copyMemory(pStr, pResult->buffer, (nLen + 1) * sizeof(sal_Char)); rtl_string_release(pResult); return nLen; }
static char * _compose_locale( rtl_Locale * pLocale, char * buffer, size_t n ) { /* check if a valid locale is specified */ if( pLocale && pLocale->Language && (pLocale->Language->length == 2 || pLocale->Language->length == 3) ) { size_t offset = 0; /* convert language code to ascii */ { rtl_String *pLanguage = NULL; rtl_uString2String( &pLanguage, pLocale->Language->buffer, pLocale->Language->length, RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); if( SAL_INT_CAST(sal_uInt32, pLanguage->length) < n ) { strcpy( buffer, pLanguage->buffer ); offset = pLanguage->length; } rtl_string_release( pLanguage ); } /* convert country code to ascii */ if( pLocale->Country && (pLocale->Country->length == 2) ) { rtl_String *pCountry = NULL; rtl_uString2String( &pCountry, pLocale->Country->buffer, pLocale->Country->length, RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); if( offset + pCountry->length + 1 < n ) { strcpy( buffer + offset++, "_" ); strcpy( buffer + offset, pCountry->buffer ); offset += pCountry->length; } rtl_string_release( pCountry ); } /* convert variant to ascii - check if there is enough space for the variant string */ if( pLocale->Variant && pLocale->Variant->length && ( SAL_INT_CAST(sal_uInt32, pLocale->Variant->length) < n - 6 ) ) { rtl_String *pVariant = NULL; rtl_uString2String( &pVariant, pLocale->Variant->buffer, pLocale->Variant->length, RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); if( offset + pVariant->length + 1 < n ) { strcpy( buffer + offset, pVariant->buffer ); offset += pVariant->length; } rtl_string_release( pVariant ); } return buffer; } return NULL; }
/* 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; }
oslProcessError SAL_CALL osl_executeProcess_WithRedirectedIO( rtl_uString *ustrImageName, rtl_uString *ustrArguments[], sal_uInt32 nArguments, oslProcessOption Options, oslSecurity Security, rtl_uString *ustrWorkDir, rtl_uString *ustrEnvironment[], sal_uInt32 nEnvironmentVars, oslProcess *pProcess, oslFileHandle *pInputWrite, oslFileHandle *pOutputRead, oslFileHandle *pErrorRead ) { oslProcessError Error; sal_Char* pszWorkDir=0; sal_Char** pArguments=0; sal_Char** pEnvironment=0; unsigned int idx; char szImagePath[PATH_MAX] = ""; char szWorkDir[PATH_MAX] = ""; if ( ustrImageName && ustrImageName->length ) { FileURLToPath( szImagePath, PATH_MAX, ustrImageName ); } if ( ustrWorkDir != 0 && ustrWorkDir->length ) { FileURLToPath( szWorkDir, PATH_MAX, ustrWorkDir ); pszWorkDir = szWorkDir; } if ( pArguments == 0 && nArguments > 0 ) { pArguments = (sal_Char**) malloc( ( nArguments + 2 ) * sizeof(sal_Char*) ); } for ( idx = 0 ; idx < nArguments ; ++idx ) { rtl_String* strArg =0; rtl_uString2String( &strArg, rtl_uString_getStr(ustrArguments[idx]), rtl_uString_getLength(ustrArguments[idx]), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS ); pArguments[idx]=strdup(rtl_string_getStr(strArg)); rtl_string_release(strArg); pArguments[idx+1]=0; } for ( idx = 0 ; idx < nEnvironmentVars ; ++idx ) { rtl_String* strEnv=0; if ( pEnvironment == 0 ) { pEnvironment = (sal_Char**) malloc( ( nEnvironmentVars + 2 ) * sizeof(sal_Char*) ); } rtl_uString2String( &strEnv, rtl_uString_getStr(ustrEnvironment[idx]), rtl_uString_getLength(ustrEnvironment[idx]), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS ); pEnvironment[idx]=strdup(rtl_string_getStr(strEnv)); rtl_string_release(strEnv); pEnvironment[idx+1]=0; } Error = osl_psz_executeProcess(szImagePath, pArguments, Options, Security, pszWorkDir, pEnvironment, pProcess, pInputWrite, pOutputRead, pErrorRead ); if ( pArguments != 0 ) { for ( idx = 0 ; idx < nArguments ; ++idx ) { if ( pArguments[idx] != 0 ) { free(pArguments[idx]); } } free(pArguments); } if ( pEnvironment != 0 ) { for ( idx = 0 ; idx < nEnvironmentVars ; ++idx ) { if ( pEnvironment[idx] != 0 ) { free(pEnvironment[idx]); } } free(pEnvironment); } return Error; }