static IMPL_RTL_STRINGDATA* IMPL_RTL_STRINGNAME( ImplAlloc )( sal_Int32 nLen ) { IMPL_RTL_STRINGDATA * pData = (SAL_INT_CAST(sal_uInt32, nLen) <= ((SAL_MAX_UINT32 - sizeof (IMPL_RTL_STRINGDATA)) / sizeof (IMPL_RTL_STRCODE))) ? (IMPL_RTL_STRINGDATA *) rtl_allocateMemory( sizeof (IMPL_RTL_STRINGDATA) + nLen * sizeof (IMPL_RTL_STRCODE)) : NULL; if (pData != NULL) { pData->refCount = 1; pData->length = nLen; pData->buffer[nLen] = 0; } return pData; }
static oslPipe getPipe(JNIEnv * env, jobject obj_this) { jclass tclass; jfieldID fid; tclass = (*env)->GetObjectClass(env, obj_this); if (tclass == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find class"); return NULL; } fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); if (fid == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find field"); return NULL; } return (oslPipe) SAL_INT_CAST( sal_IntPtr, (*env)->GetLongField(env, obj_this, fid)); }
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; }
/* * Class: com_sun_star_lib_connections_pipe_PipeConnection * Method: connect * Signature: (Lcom/sun/star/beans/NativeService;)V */ SAL_DLLPUBLIC_EXPORT void #if defined WNT PipeConnection_create #else JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI #endif (JNIEnv * env, jobject obj_this, jstring name) { enum { START = 0, INMONITOR, GOTNAME, CREATED }; short state = START; jclass tclass; jfieldID fid; oslSecurity psec = osl_getCurrentSecurity(); oslPipe npipe = NULL; rtl_uString * pname = NULL; if ((*env)->MonitorEnter(env, obj_this) != 0) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot synchronize on the object"); goto error; } state = INMONITOR; /* check connection state */ npipe = getPipe(env, obj_this); if ((*env)->ExceptionOccurred(env) != NULL) goto error; if (npipe != NULL) { ThrowException(env, "com/sun/star/io/IOException", "native pipe is already connected"); goto error; } /* save the pipe name */ tclass = (*env)->GetObjectClass(env, obj_this); if (tclass == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find class"); goto error; } fid = (*env)->GetFieldID(env, tclass, "_aDescription", "Ljava/lang/String;"); if (fid == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find field"); goto error; } (*env)->SetObjectField(env, obj_this, fid, (jobject)name); /* convert pipe name to rtl_uString */ pname = jstring2ustring(env, name); if (pname == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot convert name"); goto error; } state = GOTNAME; /* try to connect */ npipe = osl_createPipe(pname, osl_Pipe_OPEN, psec); if (npipe == NULL) { ThrowException(env, "java/lang/RuntimeException", "cannot create native pipe"); goto error; } state = CREATED; /* save the pipe */ tclass = (*env)->GetObjectClass(env, obj_this); if (tclass == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find class"); goto error; } fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); if (fid == NULL) { ThrowException(env, "java/lang/RuntimeException", "native pipe cannot find field"); goto error; } (*env)->SetLongField( env, obj_this, fid, SAL_INT_CAST(jlong, (sal_IntPtr) npipe)); /* done */ rtl_uString_release(pname); (*env)->MonitorExit(env, obj_this); osl_freeSecurityHandle(psec); return; error: switch (state) { case CREATED: osl_closePipe(npipe); osl_releasePipe(npipe); case GOTNAME: rtl_uString_release(pname); case INMONITOR: (*env)->MonitorExit(env, obj_this); case START: osl_freeSecurityHandle(psec); default: break; } return; }