/**
 * Sets a property key to the specified value.
 *
 * @param props The property set in which to add/modify <tt>key</tt>
 * @param key The key to set
 * @param value The value to set <tt>key</tt> to
 */
static void
setProp(Property** props, const char* key , const char* value) {
    /* Try to find the property in the current pool. */
    Property *p;
    for (p= *props; p; p = p->next) {
        if (strcmp(key, p->key) == 0) {
            midpFree((void*)p->value);
            p->value = midpStrdup(value);
            /*
             * if midpStrdup fails we will just return without setting
             * the value to anything other than NULL
             */
            return;
        }
    }

    /* If the value is not defined, add it now */
    p = (Property*)midpMalloc(sizeof(Property));
    if (NULL != p){
        p->next = *props ;
        p->key = midpStrdup(key);
        p->value = midpStrdup(value);

        if ((p->key == NULL) || (p->value == NULL)) {
            /* do nothing if there is no memory */
            midpFree((void*)p->key);
            midpFree((void*)p->value);
            midpFree(p);
            return;
        }
        *props = p ;
    }
}
/**
 * Gets the value of the specified property key in the internal
 * property set. If the key is not found in the internal property
 * set, the application property set is then searched.
 * <p>
 * Java declaration:
 * <pre>
 *     getProperty0(Ljava.lang.String;)Ljava.lang.String;
 * <pre>
 *
 * @param key The key to search for
 *
 * @return The value associated with <tt>key<tt> if found, otherwise
 *         <tt>null<tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_main_Configuration_getProperty0) {
    jchar* uStr;
    const char* key;
    const char* value;
    int strLen;

    KNI_StartHandles(2);
    KNI_DeclareHandle(str);
    KNI_DeclareHandle(result);

    KNI_GetParameterAsObject(1, str);
    strLen = KNI_GetStringLength(str);

    if (strLen <= 0 || (uStr = (jchar*) midpMalloc(strLen * sizeof(jchar))) == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        KNI_GetStringRegion(str, 0, strLen, uStr);
        key = UnicodeToCString(uStr, strLen);
        midpFree(uStr);

        /* Look up the property value */
        value = getInternalProperty(key);
        midpFree((void *)key);

        if (value != NULL) {
            KNI_NewStringUTF(value, result);
        } else {
            KNI_ReleaseHandle(result);
        }
    }
    KNI_EndHandlesAndReturnObject(result);
}
/**
 * Finalizes the locale system.
 */
void 
finalizeLocaleMethod() {
    if (lc != NULL) {
	midpFree(lc->locale);                /* Allocated in getLocaleInfo() */
        midpFree(lc);
        lc = NULL;
    }
}
/** Unlinks listener node from the list and frees its resources */
static void deleteListenerNodeByRef(RecordStoreListener **listenerRef) {
    RecordStoreListener *listenerPtr;

    listenerPtr = *listenerRef;
    *listenerRef = listenerPtr->next;
    pcsl_string_free(&listenerPtr->recordStoreName);
    midpFree(listenerPtr->listenerId);
    midpFree(listenerPtr);
}
示例#5
0
/** Free memory allocated for screen buffer */
void gxj_free_screen_buffer() {
    if (gxj_system_screen_buffer.pixelData != NULL) {
        midpFree(gxj_system_screen_buffer.pixelData);
        gxj_system_screen_buffer.pixelData = NULL;
    }
    if (gxj_system_screen_buffer.alphaData != NULL) {
        midpFree(gxj_system_screen_buffer.alphaData);
        gxj_system_screen_buffer.alphaData = NULL;
    }
}
示例#6
0
/**
 * Sets a property key to the specified value. If the key does
 * not exist and <tt>useMalloc<tt> is <tt>KNI_TRUE<tt>, use
 * <tt>midpMalloc()<tt> to make a copy of the contents of
 * <tt>key<tt>. If the key does not exist and <tt>useMalloc<tt>
 * is <tt>KNI_FALSE<tt>, make a copy of the pointer to
 * <tt>key<tt>. If the <tt>key<tt> already exists in the
 * property lists, modify its associated value.
 *
 * @param propertySet The property set in which to add/modify
 *                    <tt>key<tt>
 * @param key The key to set
 * @param value The value to associate with <tt>key<tt>
 * @param useMalloc If <tt>KNI_TRUE<tt>, use <tt>midpMalloc()<tt>
 *                  to make a copy of the contents of <tt>value<tt>,
 *                  otherwise make a copy of the pointer to
 *                  <tt>value<tt>.
 */
static void
setProp(Property** propertySet, const char* key, const char* value,
        jboolean useMalloc) {
    Property *p;
    for (p = *propertySet; p; p = p->next) {
        if (strcmp(key, p->key) == 0) {
            if (IS_NEW_VALUE(p)) {
                midpFree((void *)p->value);
            }
            if (useMalloc) {
                SET_NEW_VALUE(p);
                p->value = midpStrdup(value);
            } else {
                UNSET_NEW_VALUE(p);
                p->value = value;
            }
            /*
             * if midpStrdup fails we will just return without setting
             * the value to anything other than NULL
             */
            return;
        }
    }

    /* If the value is not defined, add it now */
    p = (Property*)midpMalloc(sizeof(Property));
    if (NULL != p){
        p->next = *propertySet;
        CLEAR_FLAGS(p);
        if (useMalloc) {
            SET_NEW_VALUE(p);
            SET_NEW_KEY(p);
            p->key = midpStrdup(key);
            p->value = midpStrdup(value);
        } else {
            UNSET_NEW_VALUE(p);
            UNSET_NEW_KEY(p);
            p->value = value;
            p->key = key;
        }

        if ((p->key == NULL) || (p->value == NULL && value != NULL)) {
            /* do nothing if there is no memory */
            if (useMalloc) {
                midpFree((void *)p->key);
                midpFree((void *)p->value);
            }
            midpFree((void *)p);
            return;
        }
        *propertySet = p ;
    }
}
示例#7
0
/* Returns the entry size or less than zero if error.
 *  If the entry does not exist, size is 0 and *ppEntry is NULL
 */
long
midpGetJarEntry(void* handle, const pcsl_string * name,
                unsigned char** ppEntry) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    char*  entryData = NULL;
    int status;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    *ppEntry = NULL;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (pName == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (pCompBuffer == NULL) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (entryInfo.status == JAR_ENTRY_NOT_FOUND) {
        return 0;
    }
    
    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    entryData = midpMalloc((size_t)entryInfo.decompLen);
    if (entryData == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    status = inflateJarEntry(&pJarInfo->fileObj, &pJarInfo->heapManObj,
                             &entryInfo, (unsigned char*)entryData, 0);
    if (status != 0) {
        midpFree(entryData);
        return MIDP_JAR_CORRUPT_ERROR;
    }

    *ppEntry = (unsigned char*)entryData;
    return entryInfo.decompLen;
}
示例#8
0
int 
midpIterateJarEntries(void *handle, filterFuncT *filter, actionFuncT *action) {

    MidpJarInfo *pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    pcsl_string entryName;
    unsigned char *nameBuf;
    int status = 1;
    pcsl_string_status res;

    entryInfo = getFirstJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo);

    while (entryInfo.status == 0) {
        
        nameBuf =  (unsigned char*) midpMalloc(entryInfo.nameLen);
        if (nameBuf == NULL) {
            status = MIDP_JAR_OUT_OF_MEM_ERROR;
            break;
        }
        
        entryInfo.status = getJarEntryName(&pJarInfo->fileObj, &entryInfo, nameBuf);
        if (entryInfo.status != 0) {
            status = MIDP_JAR_CORRUPT_ERROR;
            midpFree(nameBuf);
            break;
        }

        res = pcsl_string_convert_from_utf8((jbyte*)nameBuf, entryInfo.nameLen,
                                            &entryName);
        midpFree(nameBuf);
        if (PCSL_STRING_OK != res) {
            status = MIDP_JAR_OUT_OF_MEM_ERROR;
            break;
        }
       
        if ((*filter)(&entryName)) {
            /* name match: call action */   
            if (!(*action)(&entryName)) {
                status = 0;
                pcsl_string_free(&entryName);
                break;
            }
        }
        
        pcsl_string_free(&entryName);
        
        entryInfo = getNextJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo, 
                                        &entryInfo);
        
    }
       
    return status;
}
/**
 * Finalizes a property set.
 *
 * @param props The property set to finalize
 */
static void
finalizeProps(Property* props) {
    Property *prop, *tmp;

    if (props != NULL) {
    for (prop = props ; prop ; prop = tmp ){
        tmp = prop->next;
        midpFree((void*)prop->key);
        midpFree((void*)prop->value);
        midpFree(prop);
    }
    }
}
extern "C" void gxpport_createimmutable_from_mutable
(gxpport_mutableimage_native_handle srcMutableImagePtr,
 gxpport_image_native_handle *newImmutableImagePtr,
 gxutl_native_image_error_codes* creationErrorPtr) {

    /* Convert from source QPixmap to destination QImage */
    QPixmap* srcPixmap = gxpportqt_get_mutableimage_pixmap(srcMutableImagePtr);

    int rscSize = ImgRscSize(srcPixmap); /* new img is the same size */

    /* Check resource limit before copying */
    if (midpCheckResourceLimit(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {
        /* Exceeds resource limit */
        *creationErrorPtr  = GXUTL_NATIVE_IMAGE_RESOURCE_LIMIT;
        return;
    }

    _Platform_ImmutableImage* immutableImage =
        (_Platform_ImmutableImage*)midpMalloc(sizeof(_Platform_ImmutableImage));
    if (immutableImage == NULL) {
        *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;
        return;
    }

    immutableImage->qimage = new QImage(srcPixmap->convertToImage());
    if (NULL == immutableImage->qimage) {
	midpFree(immutableImage);
        *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;
        return;
    }

    if (immutableImage->qimage->isNull()) {
        delete immutableImage->qimage;
	midpFree(immutableImage);
        *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;
        return;    
    }

    /* Copying succeeds */
    if (midpIncResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {
        REPORT_ERROR(LC_LOWUI, "Error in updating resource limit"
                     " for Immutable image");
    }

    immutableImage->marker = 1;
    immutableImage->qpixmap = NULL;

    *newImmutableImagePtr = immutableImage;
    *creationErrorPtr = GXUTL_NATIVE_IMAGE_NO_ERROR;
}
示例#11
0
/**
 * Compare two strings using locale- and level-specific rules.
 * <p>
 * Java declaration:
 * <pre>
 *     compare0(Ljava/lang/String;Ljava/lang/String;II)I
 * </pre>
 *
 * @param locale_index  the locale index in supported locales list
 * @param hstr1         first string to compare
 * @param hstr2         second string to compare
 * @param level         the collation level to use
 * @return negative if <code>s1</code> belongs before <code>s2</code>,
 *      zero if the strings are equal, positive if <code>s1</code> belongs
 *      after <code>s2</code>
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_j2me_global_StringComparatorImpl_compare0() {
   jint locale_index = KNI_GetParameterAsInt(1);
   jint level = KNI_GetParameterAsInt(4);
   jchar *s1, *s2;
   jsize s1_len, s2_len;
   jint res, compare_result = 0;

   KNI_StartHandles(2);
   KNI_DeclareHandle(hstr1);
   KNI_DeclareHandle(hstr2);
   KNI_GetParameterAsObject(2, hstr1);
   KNI_GetParameterAsObject(3, hstr2);

   s1_len = KNI_GetStringLength(hstr1);
   if (s1_len == -1){
		KNI_ThrowNew(midpNullPointerException, NULL);
   } else {
	   s1 = (jchar *)midpMalloc(s1_len * sizeof(jchar));
	   if (NULL == s1) {
		   KNI_ThrowNew(midpOutOfMemoryError, 
			   "Cannot allocate string for collation");
	   } else {
		   s2_len = KNI_GetStringLength(hstr2);
		   if (s2_len == -1){
			   KNI_ThrowNew(midpNullPointerException, NULL);
		   } else {
			   s2 = (jchar *)midpMalloc(s2_len * sizeof(jchar));
			   if (NULL == s2) {
				   KNI_ThrowNew(midpOutOfMemoryError, 
					   "Cannot allocate string for collation");
			   } else {
				   KNI_GetStringRegion(hstr1, 0, s1_len, s1);
				   KNI_GetStringRegion(hstr2, 0, s2_len, s2);
				   res = jsr238_compare_strings(locale_index, s1, s1_len, s2, s2_len, 
													   level, &compare_result);
				   if (res < 0){
						KNI_ThrowNew(midpRuntimeException,"Error comparing strings");
				   }
				   midpFree(s2);
			   }
		   }
		   midpFree(s1);
	   }
   }

   KNI_EndHandles();
   KNI_ReturnInt(compare_result);
}
void gxpport_destroy_immutable(gxpport_image_native_handle imagePtr) {

    _Platform_ImmutableImage* immutableImage = 
        (_Platform_ImmutableImage*)imagePtr;

    if (NULL != immutableImage) {
        if (NULL != immutableImage->qimage) {
            int rscSize = ImgRscSize(immutableImage->qimage);

            /* Update the resource count */
            if (midpDecResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {
                REPORT_ERROR(LC_LOWUI,"Error in updating resource limit for"
                             " Immutable image");
            }

            delete immutableImage->qimage;
        }

        if (NULL != immutableImage->qpixmap) {
            delete immutableImage->qpixmap;
        }

	midpFree(immutableImage);
    }
}
示例#13
0
/**
 * Get index of supported locales for collation by its name.
 * <p>
 * Java declaration:
 * <pre>
 *     getDevLocaleIndex(Ljava/lang/String)I
 * </pre>
 *
 * @param locale name
 * @return internal index of locale or -1 if locale is not supported 
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_j2me_global_CollationAbstractionLayerImpl_getCollationLocaleIndex() {
	jint result =-1, index = 0;
	jsize len = 0;
	int error = 0;
	jchar* locale_name;

	KNI_StartHandles(1);
	KNI_DeclareHandle(hstr1);
	KNI_GetParameterAsObject(1, hstr1);

	if (KNI_IsNullHandle(hstr1)) {
		locale_name = NULL;
	} else  {
		len = KNI_GetStringLength(hstr1);
		locale_name = (jchar *)midpMalloc((len + 1) * sizeof(jchar));
		if (NULL == locale_name) {
		   KNI_ThrowNew(midpOutOfMemoryError, 
			   "Out of memory");
		   error = 1;
		} else {
			KNI_GetStringRegion(hstr1, 0, len, locale_name);
			locale_name[len]=0;
		}
	}

	if (!error){
		result = jsr238_get_collation_locale_index(locale_name, &index);
		if (result < 0) index =-1;
		midpFree(locale_name);
	}

	KNI_EndHandles();
	KNI_ReturnInt(index);
}
示例#14
0
int
midpJarEntryExists(void* handle, const pcsl_string * name) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (NULL == pName) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (NULL == pCompBuffer) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (JAR_ENTRY_NOT_FOUND == entryInfo.status) {
        return 0;
    }

    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    return 1;
}
示例#15
0
int testReadJadFile_1(void) {
    int    jadsize   =  0;
    char*  jad_buf   =  NULL;
    char*  jad       =  "../../../src/common/native/share/unittests/jad1.jad";
    int    res       =  ALL_OK;
    MidpString jadURL = {0,NULL};

    REPORT_INFO(LC_AMS, "############# This test should pass.");
    jadURL = midpCharsToJchars(jad);
    jadsize = (int)readJadFile (jadURL, &jad_buf);
    if ((jadsize <= 0) || (!jad_buf)) {
        REPORT_WARN1(LC_AMS, "Can't open JAD file %s", jad);
        res = NO_JAD_FILE;
    } else {
        REPORT_INFO1(LC_AMS, "JAD content is:\n%s\n", jad_buf);
    }

    midpFreeString(jadURL);

    if (jad_buf) {
        midpFree(jad_buf);
    } /* end of if */

    return res;
} /* testReadJadFile_1 */
/**
 * Loads a native image data from image cache into ImageData..
 * <p>
 * Java declaration:
 * <pre>
 *     boolean loadAndCreateImmutableImageDataFromCache0(ImageData imageData,
 *                                                       int suiteId,
 *                                                       String resName);
 * </pre>
 *
 * @param imageData The ImageData to be populated
 * @param suiteId   The suite Id
 * @param resName   The name of the image resource
 * @return true if a cached image was loaded, false otherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(javax_microedition_lcdui_SuiteImageCacheImpl_loadAndCreateImmutableImageDataFromCache0) {
#if ENABLE_IMAGE_CACHE
    int len;
    SuiteIdType suiteId;
    jboolean status = KNI_FALSE;
    unsigned char *rawBuffer = NULL;

    KNI_StartHandles(2);

    GET_PARAMETER_AS_PCSL_STRING(3, resName)

    KNI_DeclareHandle(imageData);
    KNI_GetParameterAsObject(1, imageData);

    suiteId = KNI_GetParameterAsInt(2);

    len = loadImageFromCache(suiteId, &resName, &rawBuffer);
    if (len != -1 && rawBuffer != NULL) {
        /* image is found in cache */
        status = img_load_imagedata_from_raw_buffer(KNIPASSARGS
                 imageData, rawBuffer, len);
    }

    midpFree(rawBuffer);

    RELEASE_PCSL_STRING_PARAMETER

    KNI_EndHandles();
    KNI_ReturnBoolean(status);
#else
    KNI_ReturnBoolean(KNI_FALSE);
#endif
}
示例#17
0
/**
 * Prints a <tt>MidpString</tt> with a given message. A new line will
 * be emitted after <tt>mstr</tt>.  This output goes to the log in cases
 * were the log service defined <code>REPORT_LEVEL <= LOG_INFORMATION</code>
 * conditional is true.
 *
 * @param message the specified message to print 
 * @param mstr the <tt>MidpString</tt> to print
 */
void
printMidpStringWithMessageImpl(char* message, MidpString mstr) {
    char* msg = NULL;
    char* tag;

    if ((mstr.len <= 0) && (!message)) {
              REPORT_INFO(LC_MIDPSTRING, 
		    "printMidpString() No input");
        return;
    }

    if (message) {
        tag = message;
    } else {
        tag = "message = NULL:";
    }

    if (mstr.len > 0) {
        msg = midpJcharsToChars(mstr);
        if (msg) {
          REPORT_INFO2(LC_MIDPSTRING, "%s: %s", tag, msg);
	    midpFree(msg);
        } else {
            REPORT_INFO1(LC_MIDPSTRING, 
	        "%s: printMidpString can't convert MidpString to char*",tag);
        }
    }
}
extern "C" MidpError
QString2pcsl_string(QString &qstring, pcsl_string &pstring) {
    pcsl_string_status pe;
    if (qstring.isNull()) {
	    pstring = PCSL_STRING_NULL;
    } else if (qstring.isEmpty()) {
	    pstring = PCSL_STRING_EMPTY;
    } else {
        jint mstring_len = qstring.length();
        jchar* mstring_data = (jchar *)midpMalloc(sizeof(jchar) * mstring_len);
        if (mstring_data == NULL) {
	        pstring = PCSL_STRING_NULL;
            return KNI_ENOMEM;
        } else {
            for (int i = 0; i < mstring_len; i++) {
            mstring_data[i] = qstring[i].unicode();
            }
            pe = pcsl_string_convert_from_utf16(mstring_data,
                                                mstring_len, &pstring);
            midpFree(mstring_data);
            if (PCSL_STRING_OK != pe) {
                return KNI_ENOMEM;
            }
        }
    }
    return KNI_OK;
}
示例#19
0
/**
 * Gets the length of a specific converted string as an array of 
 * Unicode bytes.
 * <p>
 * Java declaration:
 * <pre>
 *     sizeOfByteInUnicode(I[BII)I
 * </pre>
 *
 * @param handler  handle returned from getHandler
 * @param b  buffer of bytes to be converted
 * @param offset  offset into the provided buffer
 * @param length  length of data to be processed
 *
 * @return length of the converted string, or zero if the
 *         arguments were not valid
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_i18n_j2me_Conv_sizeOfByteInUnicode() {
    int   length = KNI_GetParameterAsInt(4);
    int   offset = KNI_GetParameterAsInt(3);
    int       id = KNI_GetParameterAsInt(1);
    char    *buf;
    jint  result = 0;

    KNI_StartHandles(1);
    KNI_DeclareHandle(b);

    KNI_GetParameterAsObject(2, b);
    buf = (char*)midpMalloc(length);

    if (buf == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        KNI_GetRawArrayRegion(b, offset, length, (jbyte*)buf);

        result = lcConv[id] 
               ? lcConv[id]->sizeOfByteInUnicode((const unsigned char *)buf, 
                                                  offset, length) 
               : 0;

        midpFree(buf);
    }

    KNI_EndHandles();
    KNI_ReturnInt(result);
}
示例#20
0
文件: rms.c 项目: jiangxilong/yari
/*
 * Insert a new node to the front of the linked list
 *
 * @param suiteId : ID of the suite
 * @param name : Name of the record store
 * @param handle : Handle of the opened file
 *
 * @return 0 if node is successfully inserted
 *  return  OUT_OF_MEM_LEN if memory allocation fails
 *
 */
static int
recordStoreCreateLock(SuiteIdType suiteId, const pcsl_string * name_str,
                      int handle) {
    lockFileList* newNodePtr;

    newNodePtr = (lockFileList *)midpMalloc(sizeof(lockFileList));
    if (newNodePtr == NULL) {
        return OUT_OF_MEM_LEN;
    }

    newNodePtr->suiteId = suiteId;

    /*IMPL_NOTE: check for error codes instead of null strings*/
    pcsl_string_dup(name_str, &newNodePtr->recordStoreName);
    if (pcsl_string_is_null(&newNodePtr->recordStoreName)) {
        midpFree(newNodePtr);
        return OUT_OF_MEM_LEN;
    }

    newNodePtr->handle = handle;
    newNodePtr->next = NULL;

    if (lockFileListPtr == NULL) {
        lockFileListPtr = newNodePtr;
    } else {
        newNodePtr->next = lockFileListPtr;
        lockFileListPtr = newNodePtr;
    }

    return 0;
}
/**
 * Gets the registered MIDlet name for the given inbound connection handle.
 * <p>
 * Java declaration:
 * <pre>
 *     getMIDlet0(J[BI)I
 * </pre>
 *
 * @param handle The handle to inbound connection
 * @param midletName A byte array to store the MIDlet name
 * @param midletNameLength The size of <tt>midlet</tt>
 *
 * @return <tt>0</tt> if successful, otherwise <tt>-1</tt>
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_getMIDlet0) {
    int   midletNameLength;
    char* regentry;
    int   regentryLength;
    int   ret = -1;
    int   handle;

    midletNameLength = (int)KNI_GetParameterAsInt(3);
    handle           = (int)KNI_GetParameterAsInt(1);

    KNI_StartHandles(1);

    KNI_DeclareHandle(midletName);
    KNI_GetParameterAsObject(2, midletName);

    regentry = pushfindfd(handle);
    if (NULL != regentry) {
        regentryLength = strlen(regentry) + 1;      /* Include trailing '\0' */
        if (regentryLength < midletNameLength) {
            memcpy((char*)JavaByteArray(midletName),
                   regentry, regentryLength);
            ret = 0;
        }
        midpFree(regentry);
    }
    KNI_EndHandles();

    KNI_ReturnInt(ret);
}
示例#22
0
/**
 * Gets a handle to specific character encoding conversion routine.
 * <p>
 * Java declaration:
 * <pre>
 *     getHandler(Ljava/lang/String;)I
 * </pre>
 *
 * @param encoding character encoding
 *
 * @return identifier for requested handler, or <tt>-1</tt> if
 *         the encoding was not supported.
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_i18n_j2me_Conv_getHandler() {
    jint     result = 0;

    KNI_StartHandles(1);

    KNI_DeclareHandle(str);
    KNI_GetParameterAsObject(1, str);

    if (!KNI_IsNullHandle(str)) {
        int      strLen = KNI_GetStringLength(str);
	jchar* strBuf;

	/* Instead of always multiplying the length by sizeof(jchar),
	 * we shift left by 1. This can be done because jchar has a
	 * size of 2 bytes.
	 */
	strBuf = (jchar*)midpMalloc(strLen<<1);
	if (strBuf != NULL) { 
	    KNI_GetStringRegion(str, 0, strLen, strBuf);
	    result = getLcConvMethodsID(strBuf, strLen);
	    midpFree(strBuf);
	} else {
	    KNI_ThrowNew(midpOutOfMemoryError, NULL);
	}
    }

    KNI_EndHandles();
    KNI_ReturnInt(result);
}
示例#23
0
int testReadJadFile_2(void) {
    int    jadsize   =  0;
    char*  jad_buf   =  NULL;
    char*  jad       =  "../../../src/common/native/share/unittests/no_such_a_file.jad";
    int    res       =  NO_JAD_FILE;
    MidpString jadURL = {0,NULL};

    REPORT_INFO(LC_AMS, "#############  This test should fail. Trying to load file that doesn't exist.\n");
    jadURL = midpCharsToJchars(jad);
    jadsize = (int)readJadFile (jadURL, &jad_buf);
    if ((jadsize <= 0) || (!jad_buf)) {
        REPORT_WARN1(LC_AMS, "\nCan't open JAD file %s\n", jad);
        res = ALL_OK;
    } else {
        REPORT_INFO1(LC_AMS, "JAD content is:\n%s\n", jad_buf);
    }

    midpFreeString(jadURL);

    if (jad_buf) {
        midpFree(jad_buf);
    } /* end of if */

    return res;
} /* testReadJadFile_2 */
/**
 * Adds a connection to the push registry.
 * <p>
 * Java declaration:
 * <pre>
 *     add0([B)I
 * </pre>
 *
 * @param connection The connection to add to the push registry
 *
 * @return <tt>0</tt> upon successfully adding the connection, otherwise
 *         <tt>-1</tt> if connection already exists
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_add0) {

    char *szConn = NULL;
    int connLen;
    int ret = -1;

    KNI_StartHandles(1);
    KNI_DeclareHandle(conn);

    KNI_GetParameterAsObject(1, conn);
    connLen = KNI_GetArrayLength(conn);

    szConn = midpMalloc(connLen);

    if (szConn != NULL) {
        KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn);
        ret = pushadd(szConn);
        midpFree(szConn);
    }

    if ((szConn == NULL) || (ret == -2)) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnInt(ret);
}
示例#25
0
void midp_file_cache_flush(char** ppszError, int handle) {
    char *buf;     /* write buffer */
    long bufsize;  /* its size */
    *ppszError = NULL;

    if (mFileCache == NULL || mFileCache->handle != handle
            || mFileCache->blocks == NULL) {
        return;
    }

    /* allocate a buffer, as large as possible, but no larger than the cache */
    /* the buffer will be freed before the function returns */
    bufsize = mFileCache->size;
    do {
        buf = (char*)midpMalloc(bufsize);

        if (buf != NULL) {
            midp_file_cache_flush_using_buffer(ppszError, handle, buf, bufsize);
            midpFree(buf);
            break;
        } else if (bufsize > (signed) (4*sizeof(MidpFileCacheBlock))) {
            /* we prefer to have at least some buffer so that failure to
               allocate a big buffer does not lead to slowing down write
               operations by multiple times (e.g. 5x to 12x on non-cached
               compact flash) */
            bufsize >>= 1;
        } else {
            /* failed to allocate buffer of any size */
            midp_file_cache_flush_using_buffer(ppszError, handle, NULL, 0);
            break;
        }
    } while(1);
/**
 * Adds an entry to the alarm registry.
 * <p>
 * Java declaration:
 * <pre>
 *     addalarm0([BJ)J
 * </pre>
 *
 * @param midlet The entry to add to the alarm registry
 * @param time The time the alarm will be go off
 *
 * @return <tt>0</tt> if this is the first alarm registered with
 *         the given <tt>midlet</tt>, otherwise the time of the
 *         previosly registered alarm.
 */
KNIEXPORT KNI_RETURNTYPE_LONG
KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_addAlarm0) {

    char *szConn = NULL;
    int connLen;
    jlong alarm = 0;
    jlong lastalarm = 0;
    int ret = 0;

    alarm = KNI_GetParameterAsLong(2);

    KNI_StartHandles(1);
    KNI_DeclareHandle(conn);

    KNI_GetParameterAsObject(1, conn);
    connLen = KNI_GetArrayLength(conn);

    szConn = midpMalloc(connLen);
    if (szConn != NULL) {
        KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn);
        ret = alarmadd(szConn, alarm, &lastalarm);
        midpFree(szConn);
    }

    if ((szConn == NULL) || (ret == -2)) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnLong(lastalarm);
}
示例#27
0
static void sendControlStringField(KNIDECLARGS kjobject objectHandle,
                                   kjobject stringObj, jfieldID fieldID) {
    int len;
    jchar *data = NULL;
    (void) _arguments;
    (void) _p_mb;
    (void) _ee;

    KNI_GetObjectField(objectHandle, fieldID, stringObj);
    len = KNI_GetStringLength(stringObj);
    if (len > 0) {
        data = (jchar*)midpMalloc(len * sizeof(jchar));
        if (data == NULL) {
            len = 0; /* IMPL_NOTE: throw out of memory */
        } else {
            KNI_GetStringRegion(stringObj, 0, len, data);
        }
    }

    write(controlPipe[1], &len, sizeof(int));
    if (len > 0) {
        write(controlPipe[1], data, len * sizeof(jchar));
        midpFree(data);
    }
}
示例#28
0
/**
 * Gets localized names corresponding to roots returned by
 * FileSystemRegistry.listRoots() method. There is one localized name
 * corresponding to each root returned by method. Localized names are in the
 * same order as returned by method and are separated by ';' symbol.
 * If there is no localized name for root, non-localized (logical) name is
 * returned in the property for this root. Root names returned through this
 * property cannot contain ';' symbol.
 *
 * This method is called when the <code>fileconn.dir.roots.names</code> system
 * property is retrieved.
 *
 * @return the localized names for mounted roots separated by ';' symbol
 */
extern "C" char* getLocalizedMountedRoots()
{
    DEBUG_PRINT("getLocalizedMountedRoots")

    // it could be no calls to FileConnection API before getting this system
    // property so the subsystem could be not initialized.
    initNativeFileSystemMonitor();

    QString locals;
    for (QListIterator<MidpFileRoot> i(si->getFileRoots()); i.current(); ++i)
    {
        if (!locals.isEmpty())
        {
            locals += ';';
        }
       locals += (*i)->getLocalRoot();
    }

    if (locals.isEmpty())
    {
        return NULL;
    }

    // if it's not a first call then free previously allocated  buffer
    if (localizedNames != NULL)
    {
        midpFree(localizedNames);
    }

    localizedNames = (char*)midpMalloc(locals.length() + 1);
    return strcpy(localizedNames, locals);
}
示例#29
0
/**
 * Gets the length of a specific converted string as an array of 
 * Unicode characters.
 * <p>
 * Java declaration:
 * <pre>
 *     sizeOfUnicodeInByte(I[CII)I
 * </pre>
 *
 * @param handler  handle returned from getHandler
 * @param c  buffer of characters to be converted
 * @param offset  offset into the provided buffer
 * @param length  length of data to be processed
 *
 * @return length of the converted string, or zero if the
 *         arguments were not valid
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_i18n_j2me_Conv_sizeOfUnicodeInByte() {
    int   length = KNI_GetParameterAsInt(4);
    int   offset = KNI_GetParameterAsInt(3);
    int       id = KNI_GetParameterAsInt(1);
    jchar *buf;
    jint  result = 0;

    KNI_StartHandles(1);
    KNI_DeclareHandle(c);

    KNI_GetParameterAsObject(2, c);

    /* Instead of always multiplying the length by sizeof(jchar),
     * we shift left by 1. This can be done because jchar has a
     * size of 2 bytes.
     */
    buf = (jchar*)midpMalloc(length<<1);

    if (buf == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        KNI_GetRawArrayRegion(c, offset<<1, length<<1, (jbyte*)buf);

        result = lcConv[id] 
               ? lcConv[id]->sizeOfUnicodeInByte((const jchar *)buf, 
                                                  offset, length) 
               : 0;
        midpFree(buf);
    }

    KNI_EndHandles();
    KNI_ReturnInt(result);
}
示例#30
0
/**
 * Converts an array of bytes to converted array of characters.
 * <p>
 * Java declaration:
 * <pre>
 *     byteToChar(I[BII[CII)I
 * </pre>
 *
 * @param handler  handle returned from getHandler
 * @param input  buffer of bytes to be converted
 * @param in_offset  offset into the provided buffer
 * @param in_len  length of data to be processed
 * @param output  buffer of converted bytes
 * @param out_offset  offset into the provided output buffer
 * @param out_len  length of data processed
 *
 * @return length of the converted string, or zero if the
 *         arguments were not valid
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_cldc_i18n_j2me_Conv_byteToChar() {
    int   outLength = KNI_GetParameterAsInt(7);
    int   outOffset = KNI_GetParameterAsInt(6);
    int    inLength = KNI_GetParameterAsInt(4);
    int    inOffset = KNI_GetParameterAsInt(3);
    int          id = KNI_GetParameterAsInt(1);
    char*     inBuf;
    jchar* outBuf;
    jint     result = 0;

    KNI_StartHandles(2);
    KNI_DeclareHandle(output);
    KNI_DeclareHandle(input);

    KNI_GetParameterAsObject(5, output);
    KNI_GetParameterAsObject(2, input);

    inBuf  = (char*)midpMalloc(inLength);
    if (inBuf != NULL) {
	/* Instead of always multiplying the length by sizeof(jchar),
	 * we shift left by 1. This can be done because jchar has a
	 * size of 2 bytes.
	 */
	outBuf = (jchar*)midpMalloc(outLength<<1);
	if (outBuf != NULL) {
	    KNI_GetRawArrayRegion(input, inOffset, inLength, (jbyte*)inBuf);
	    result = (lcConv[id] ? 
		       lcConv[id]->nativeToUnicode((const unsigned char *)
						   inBuf,  inLength, 
						   outBuf, outLength): 0);
	    KNI_SetRawArrayRegion(output, outOffset<<1, outLength<<1, 
				  (jbyte*)outBuf);

	    midpFree(inBuf);
	    midpFree(outBuf);
	} else {
	    midpFree(inBuf);
	    KNI_ThrowNew(midpOutOfMemoryError, NULL);
	}
    } else {
	KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnInt(result);
}