KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_security_Permissions_loadGroupList)
{
    int lines, i1;
    void* array;

    KNI_StartHandles(2);
    KNI_DeclareHandle(groups);
    KNI_DeclareHandle(tmpString);
    
    lines = permissions_load_group_list(&array);
    if (lines > 0) {
        char** list = (char**)array;
        SNI_NewArray(SNI_STRING_ARRAY,  lines, groups);
        if (KNI_IsNullHandle(groups))
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
        else
            for (i1 = 0; i1 < lines; i1++) {
                KNI_NewStringUTF(list[i1], tmpString);
                KNI_SetObjectArrayElement(groups, (jint)i1, tmpString);
            }
        permissions_dealloc(array);
    } else
        KNI_ReleaseHandle(groups); /* set object to NULL */

    KNI_EndHandlesAndReturnObject(groups);
}
/**
 * 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);
}
Exemplo n.º 3
0
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(KNITest_newStringUTF) {
    const char* buf = "hello";
    KNI_StartHandles(1);
    KNI_DeclareHandle(newStr);
    KNI_NewStringUTF(buf, newStr);
    KNI_EndHandlesAndReturnObject(newStr);
}
Exemplo n.º 4
0
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_mmedia_DefaultConfiguration_nListProtocolsNext) {
    ListIterator *iterator;
    char *p;
    unsigned int len;
    char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *proto = NULL;
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(stringObj);
    iterator = (ListIterator *)KNI_GetParameterAsInt(1);
    KNI_ReleaseHandle(stringObj);

    do {
        if (iterator == NULL || iterator->current == NULL) { /* Wrong parameter */
            KNI_ThrowNew(jsropIllegalArgumentException, "Illegal iterator");
            break;
        }
        /* finding next item in the list */
        if ((p = strchr(iterator->current, ' ')) != NULL) {
            len = (int)(p - iterator->current);
        } else {
            len = strlen(iterator->current);
        }
        if (len == 0) { /* End of list */
            break;
        }
        
        /* is the stack buffer enough for the item? */
        if (len >= sizeof stack_string_buffer / sizeof stack_string_buffer[0]) {
            proto = MMP_MALLOC(len + 1);
            if (proto == NULL) {
                KNI_ThrowNew(jsropOutOfMemoryError, NULL);
                break;
            }
        } else {
            proto = stack_string_buffer;
        }

        /* shift to next item in the list */
        memcpy(proto, iterator->current, len);
        proto[len] = '\0';
        iterator->current += len;
        while (*iterator->current == ' ') {
            iterator->current++;
        }
    } while (0);
    
    if (proto != NULL) {
        KNI_NewStringUTF(proto, stringObj);
        if (proto != stack_string_buffer) {
            MMP_FREE(proto);
        }
    }
    KNI_EndHandlesAndReturnObject(stringObj);
}
Exemplo n.º 5
0
/**
 * Retrives error message clears error state.
 * <p>Java declaration:
 * <pre>
 * private native String getErrorMessage0();
 * </pre>
 * @return Error message string
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_cardreader_PlatformCardDevice_getErrorMessage0) {
    jbyte err_msg[1024];
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(err_msg_handle);
    
    if (javacall_carddevice_get_error(err_msg, sizeof err_msg) == JAVACALL_TRUE) {
        KNI_NewStringUTF(err_msg, err_msg_handle);
    }
    
    KNI_EndHandlesAndReturnObject(err_msg_handle);
}
Exemplo n.º 6
0
Arquivo: emul.c Projeto: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_jsr82emul_EmulationClient_getServerIP() {
    char *value = getenv("JSR82_EMUL_IP");
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    if (NULL != value) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }
    
    KNI_EndHandlesAndReturnObject(result); 
}
Exemplo n.º 7
0
Arquivo: emul.c Projeto: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_jsr82emul_EmulationClient_getLocalIP() {
    char value[4 * 4];

    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    if (JAVACALL_OK == javacall_network_get_local_ip_address_as_string(value)) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }
    
    KNI_EndHandlesAndReturnObject(result); 
}
Exemplo n.º 8
0
/**
 * Gets the local IP number.
 * <p>
 * Java declaration:
 * <pre>
 *     static getHost0(V)Ljava/lang/String;
 * </pre>
 *
 * @return the local IP address as a dotted-quad <tt>String</tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_io_j2me_datagram_Protocol_getHost0(void) {
    char value[MAX_HOST_LENGTH];
    int status;

    KNI_StartHandles(1);
    KNI_DeclareHandle(result);

    status = pcsl_network_getLocalIPAddressAsString(value);

    if ((status == PCSL_NET_SUCCESS) && (value != NULL)) {
        KNI_NewStringUTF(value, result);
    } else {
        KNI_ReleaseHandle(result);
    }

    KNI_EndHandlesAndReturnObject(result);
}
KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_security_Permissions_loadGroupPermissions)
{
    int lines, i1;
	unsigned int str_len;
    void *array;
    jchar jbuff[64];
    char  group_name[64];

    KNI_StartHandles(3);
    KNI_DeclareHandle(members);
    KNI_DeclareHandle(tmpString);
    KNI_DeclareHandle(group);

    KNI_GetParameterAsObject(1, group);
    if (!KNI_IsNullHandle(group)) {
        str_len = KNI_GetStringLength(group);
        if (str_len <= sizeof(group_name)-1) {
            KNI_GetStringRegion(group, 0, str_len, jbuff);
            jchar_to_char(jbuff, group_name, str_len);
            lines = permissions_load_group_permissions(&array, group_name);
            if (lines > 0) {
                char **list = (char**)array;
                SNI_NewArray(SNI_STRING_ARRAY,  lines, members);
                if (KNI_IsNullHandle(members))
                    KNI_ThrowNew(midpOutOfMemoryError, NULL);
                else
                    for (i1 = 0; i1 < lines; i1++) {
                        KNI_NewStringUTF(list[i1], tmpString);
                        KNI_SetObjectArrayElement(members, (jint)i1,
                                                            tmpString);
                    }
                permissions_dealloc(array);
            } else
                KNI_ReleaseHandle(members);  /* set object to NULL */
        }
    } else
        KNI_ThrowNew(midpNullPointerException, "null group parameter");


    KNI_EndHandlesAndReturnObject(members);
}
Exemplo n.º 10
0
/*  private native String _eglQueryString ( int display , int name ) ; */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglQueryString() {

    jint display = KNI_GetParameterAsInt(1);
    jint name = KNI_GetParameterAsInt(2);
    const char *string;
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(stringHandle);
    
    string = eglQueryString((EGLDisplay)display, (EGLint)name);
#ifdef DEBUG
    printf("eglQueryString(0x%x, %d) = %s\n", display, name, string);
#endif
    
    if (string) {
        KNI_NewStringUTF(string, stringHandle);
    } else {
        /* Set stringHandle to null. */
        KNI_ReleaseHandle(stringHandle);
    }
    KNI_EndHandlesAndReturnObject(stringHandle);
}
Exemplo n.º 11
0
/**
 * Gets the requested IP number.
 * <p>
 * Java declaration:
 * <pre>
 *     getHost(Z)Ljava/lang/String;
 * </pre>
 *
 * @param local <tt>true</tt> to get the local host IP address, or
 *              <tt>false</tt> to get the remote host IP address.
 *
 * @return the IP address as a dotted-quad <tt>String</tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT 
Java_com_sun_midp_io_j2me_socket_Protocol_getHost0(void) {
    int local;
    void *pcslHandle;
    char value[MAX_HOST_LENGTH];
    int status = PCSL_NET_INVALID;

    local = (int)KNI_GetParameterAsBoolean(1);

    memset(value, '\0', MAX_HOST_LENGTH);

    KNI_StartHandles(2);
    KNI_DeclareHandle(result);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

    if (INVALID_HANDLE == pcslHandle) {
        KNI_ThrowNew(midpIOException, 
                     "invalid handle during socket::getHost");
    } else {
        if (local) {
            status = pcsl_socket_getlocaladdr(pcslHandle, value);
        } else {
            status = pcsl_socket_getremoteaddr(pcslHandle, value);
        }

        if (status == PCSL_NET_SUCCESS) {
            KNI_NewStringUTF(value, result);
        } else {
            KNI_ThrowNew(midpIOException, NULL);
        }
    }

    KNI_EndHandlesAndReturnObject(result);
}
Exemplo n.º 12
0
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_readStringArray) {
    int arrayLength;
    int i;

    KNI_StartHandles(2);
    KNI_DeclareHandle(returnArray);
    KNI_DeclareHandle(stringHandle);

    do {
        /*
         * First, read array length
         */
        ENSURE_SKIN_DATA_AVAILABILITY(sizeof(jint));
        memcpy((void*)&arrayLength, (void*)gsSkinFileDataPos, sizeof(jint));
        gsSkinFileDataPos += sizeof(jint);


        /*
         * Then create array
         */
        SNI_NewArray(SNI_STRING_ARRAY, arrayLength, returnArray);
        if (KNI_IsNullHandle(returnArray)) {
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
            break;
        }

        /*
         * And finally populate it with strings
         */
        for (i = 0; i < arrayLength; ++i) {
            unsigned char dataLength;
            unsigned char encoding;

            /* read data length */
            ENSURE_SKIN_DATA_AVAILABILITY(sizeof(char));
            dataLength = *((unsigned char*)gsSkinFileDataPos);
            gsSkinFileDataPos += 1;

            /* read encoding */
            ENSURE_SKIN_DATA_AVAILABILITY(sizeof(char));
            encoding = *((unsigned char*)gsSkinFileDataPos);
            gsSkinFileDataPos += 1;

            ENSURE_SKIN_DATA_AVAILABILITY(dataLength * sizeof(char));

            if (encoding == STRING_ENCODING_USASCII) {    
                int j;

                /* 
                 * In case of USASCII encoding, each byte of 
                 * string data corresponds to one string char
                 */
                int stringLength = dataLength;

                /* use gKNIBuffer for storing string chars */
                jchar* stringChars = (jchar*)gKNIBuffer;
                
                /* 
                 * Safety measure to prevent gKNIBuffer overflow 
                 * (which should never happens unless something is broken) 
                 */
                if (stringLength > (int)(KNI_BUFFER_SIZE/sizeof(jchar))) {
                    stringLength = (int)(KNI_BUFFER_SIZE/sizeof(jchar));
                    REPORT_WARN(LC_HIGHUI, 
                            "gKNIBuffer is too small for skin string");
                }

                /* fill string chars array */
                for (j = 0; j < stringLength; ++j) {
                    stringChars[j] = gsSkinFileDataPos[j];
                }

                /* and create string from it */
                KNI_NewString(stringChars, stringLength, stringHandle);
            } else if (encoding == STRING_ENCODING_UTF8) {
                KNI_NewStringUTF((char*)gsSkinFileDataPos, stringHandle);
            } else {
                KNI_ThrowNew(midpIllegalStateException, 
                        "Illegal skin string encoding");
                break;
            }
            
            KNI_SetObjectArrayElement(returnArray, i, stringHandle);

            gsSkinFileDataPos += dataLength;
        }

    } while (0);

    KNI_EndHandlesAndReturnObject(returnArray);
}