/**
 * Get maximal allowed number of isolates in the case of MVM mode.
 * For SVM, simply return 1.
 */
int getMaxIsolates() {

#if ENABLE_MULTIPLE_ISOLATES

    static int midpMaxIsolates = 0;
    if (midpMaxIsolates == 0) {
        int jvmMaxIsolates = JVM_MaxIsolates();
        midpMaxIsolates  = getInternalPropertyInt("MAX_ISOLATES");
        if (0 == midpMaxIsolates) {
            REPORT_INFO(LC_AMS, "MAX_ISOLATES property not set");
            midpMaxIsolates = MAX_ISOLATES;
        }
        if (midpMaxIsolates > jvmMaxIsolates){
            REPORT_WARN1(LC_AMS,
                "MAX_ISOLATES exceeds VM limit %d, decreased", jvmMaxIsolates);
            midpMaxIsolates = jvmMaxIsolates;
        }
        setMaxIsolates(midpMaxIsolates);
    }
    return midpMaxIsolates;

#else

    return 1;

#endif /* ENABLE_MULTIPLE_ISOLATES */
}
Esempio n. 2
0
int midp_vsnprintf(char *buffer, int bufferSize, 
        const char* format, va_list argptr) {

	int rv, num;
    char vsprintf_buffer[VSPRINTF_BUFFER_SIZE];

    /* Fill num as minimum of bufferSize and VSPRINTF_BUFFER_SIZE */
	if (bufferSize > VSPRINTF_BUFFER_SIZE) {
        num = VSPRINTF_BUFFER_SIZE;
		REPORT_WARN1(LC_CORE,
            "Internal buffer is smaller than %d, data truncated", bufferSize);
	} else 
        num = bufferSize;
 
   /* IMPL_NOTE: using vsprintf function is not safely because it can
    * overflow output buffer. The javacall implementation will support
	* size limit format output and this function will be used here.
    * Current implementation detects buffer overflow by checking the last
	* byte and reports about it. In this case the VSPRINTF_BUFFER_SIZE
    * value need be increased.
    */
    rv = vsprintf(vsprintf_buffer, format, argptr);
    if (rv > VSPRINTF_BUFFER_SIZE - 1) {
		REPORT_CRIT2(LC_CORE, "Internal buffer %p overflow detected at %p !!!",
            vsprintf_buffer, vsprintf_buffer + VSPRINTF_BUFFER_SIZE);
    }
    if (num  > rv + 1) {
		num = rv + 1;
	} else 
        vsprintf_buffer[num - 1] = 0;

    memcpy(buffer, vsprintf_buffer, num);

    return rv;
}
Esempio n. 3
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 */
Esempio n. 4
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 */
Esempio n. 5
0
/**
 * Reads named property with heap size parameter and returns it in bytes.
 * When the property is not found provided default value is used instead.
 *
 * @param propertyName name of heap size property
 * @param defaultValue default value for the case of missing property
 * @return size value in bytes
 */
static int getHeapSizeProperty(const char *propertyName, int defaultValue) {

    int value;
    value = getInternalPropertyInt(propertyName);
    if (0 == value) {
        REPORT_WARN1(LC_AMS, "%s property not set", propertyName);
        value = defaultValue;
    }
    /* Check overflow */
    value = (value < 0 || value > 0x200000) ?
        0x7FFFFFFF /* MAX_INT */ :
        value * 1024;
    return value;
}
MidpProperties jad_main(char* jadbuf, int jadsize) {

    MidpProperties jadsmp = {0,ALL_OK,NULL};
    jchar* jchar_buffer = NULL;
    jchar* save_jchar_buffer = NULL;
    int jbufsize = -1;
#if REPORT_LEVEL <= LOG_INFORMATION
    int res = 0;
#endif
    jbufsize = jadsize * sizeof(jchar);

    jchar_buffer = (jchar*)midpMalloc(jbufsize+2);
    if (!jchar_buffer) {
        midpFree(jadbuf);
        jadsmp.status = OUT_OF_MEMORY;
        return jadsmp;
    }
    memset(jchar_buffer,0,(jbufsize + 2));

    convertChar2JChar(jadbuf,jchar_buffer,jadsize);
    midpFree(jadbuf);
    save_jchar_buffer = jchar_buffer;



    REPORT_INFO(LC_AMS, "####################### Start JAD parsing");

    /* during execution of this function jadbuf pointer will be changed
       status will be set during midpParseJad() execution */
    jadsmp = midpParseJad(jchar_buffer);
    midpFree(save_jchar_buffer);
    switch (jadsmp.status) {
    case OUT_OF_STORAGE:
        REPORT_WARN1(LC_AMS, "OUT_OF_STORAGE by JAD %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_JAR_URL_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_NAME_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_VENDOR_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_SUITE_VERSION_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NO_JAR_SIZE_PROP:
        REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case NUMBER_ERROR:
        REPORT_INFO1(LC_AMS,
		     "Error during parsing JAR size written in JAD %d",
		     jadsmp.status);
        midp_free_properties(&jadsmp);
        return jadsmp;

    case BAD_PARAMS:
    case BAD_JAD_KEY:
    case BAD_JAD_VALUE:
        REPORT_INFO1(LC_AMS,
		     "Some NOT mandatory Jad properties is not valid %d",
		     jadsmp.status);
        break;

    case ALL_OK:
        REPORT_INFO1(LC_AMS, "Jad ALL_OK %d", jadsmp.status);
        break;

    default:
        /* for an unknown result assuming OUT_OF_MEMORY */
        REPORT_INFO1(LC_AMS, "JAD parse OUT_OF_MEMORY %d", jadsmp.status);
        return jadsmp;
    } /* end of switch */

#if REPORT_LEVEL <= LOG_INFORMATION
    reportToLog(LOG_INFORMATION, LC_AMS,
		"######################### End of JAD parsing\n"
		"jad_main() : number of JAD properties = %d",
		jadsmp.numberOfProperties);

    for (res = 0; res < jadsmp.numberOfProperties*2; res+=2 ) {
        printPcslStringWithMessage(" ", &jadsmp.pStringArr[res]);
        printPcslStringWithMessage(" ", &jadsmp.pStringArr[res+1]);
    }
#endif

    return jadsmp;
} /* end of jad_main */
Esempio n. 7
0
int registerFileInstallerTests() {

    if (!register_test(test_jad_1,testReadJadFile_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n", test_jad_1);
    }

    if (!register_test(test_jad_2,testReadJadFile_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",test_jad_2);
    }

    if (!register_test(testCreateRelativeURL_1m,testCreateRelativeURL_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testCreateRelativeURL_1m);
    }

    if (!register_test(testCreateRelativeURL_2m,testCreateRelativeURL_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testCreateRelativeURL_2m);
    }

    if (!register_test(testMidpGetVersion_1m,testMidpGetVersion_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpGetVersion_1m);
    }

    if (!register_test(testMidpGetVersion_2m,testMidpGetVersion_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpGetVersion_2m);
    }

    if (!register_test(testMidpGetVersion_3m,testMidpGetVersion_3)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpGetVersion_3m);
    }

    if (!register_test(testMidpGetVersion_4m,testMidpGetVersion_4)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpGetVersion_4m);
    }

    if (!register_test(testMidpCompareVersion_1m,testMidpCompareVersion_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpCompareVersion_1m);
    }

    if (!register_test(testMidpCompareVersion_2m,testMidpCompareVersion_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpCompareVersion_2m);
    }

    if (!register_test(testMidpCompareVersion_3m,testMidpCompareVersion_3)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testMidpCompareVersion_3m);
    }

        /*
    if (!register_test(fileInstallerTest,testInstalFileUsingJad)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",fileInstallerTest);
}

    if (!register_test(fileInstallerTestJar,testInstalFileUsingJar)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",fileInstallerTestJar);
}

    if (!register_test(fileInstallerTestBadJad,testInstalFileUsingBadJad)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",fileInstallerTestBadJad);
}
    */

    /*
    if (!register_test(testParseJad_1m,testParseJad_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testParseJad_1m);
}

    if (!register_test(testParseJad_2m,testParseJad_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testParseJad_2m);
}

    if (!register_test(testParseManifest_1m,testParseManifest_1)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testParseManifest_1m);
}

    if (!register_test(testParseManifest_2m,testParseManifest_2)) {
        REPORT_WARN1(LC_AMS, "Registration of test %s failed.\n",testParseManifest_2);
}
    */
  return 1;

} /* end of registerFileInstallerTests */
/**
 * Reads in a property file and makes the key/value pairs available
 * to MIDP as a property set.
 *
 * @param fd An open file descriptor of the property file to read.
 * @param props A property set to hold the key/value pairs read from
 *              the property file.
 * @return <tt>0</tt> for success, otherwise <tt>-1</tt>
 */
static int
parseConfig(int fd, Property** props) {
    char *buffer;
    int bufferSize;
    int i;
    int j;
    int key_index;
    int value_index;
    int len;
    char *errStr = NULL;
    int startPos;
    int endPos;

    bufferSize = storageSizeOf(&errStr, fd);
    buffer = (char *)midpMalloc(bufferSize);
    if (buffer == NULL) {
        REPORT_WARN(LC_CORE, 
            "midpMalloc failed to allocate buffer for config file."); 
        return -1;
    }

    /* Read the config file in one pass */
    len = storageRead(&errStr, fd, buffer, bufferSize);
    if ((errStr != NULL) || (len != bufferSize)) {
        REPORT_WARN1(LC_CORE, 
             "Warning: can not read config file: %s", errStr);
    
        storageFreeError(errStr);
        midpFree(buffer);
        return 0;
    }

    startPos = 0;
    for (i = startPos; i < bufferSize; i++) {
        if (buffer[i] == '\n') {
            
            buffer[i] = 0;

            /* Skip comment lines which begin  with '#'*/
            if (buffer[startPos] != '#') {
                
                /* Parse the line */
                key_index = startPos;
                for (j = key_index; buffer[j]; j++){

                    Property *prop;

                    if (buffer[j] == ':') {
                        buffer[j] = 0;
                        value_index = ++j;

                        prop = (Property *) midpMalloc(sizeof(Property));
                        if (NULL != prop) {
                            char *key, *value;
                            key = midpStrdup(buffer + key_index);
                            value = midpStrdup(buffer + value_index);
                            
                            /* trim leading and trailing white spaces */
                            trim_WhiteSpace(key);
                            trim_WhiteSpace(value);

                            prop->next = *props;
                            prop->key = key;
                            prop->value = value;
        
                            if ((prop->key == NULL) || (prop->value == NULL)) {
                                midpFree((void*)prop->key);
                                midpFree((void*)prop->value);
                                midpFree(prop);

                                /*
                                 * since we are freeing memory, we're not
                                 * exactly out of memory at this point
                                 */
                                break;
                            }

                            *props = prop;
                        }

                        break;
                    }
                }
            }
            endPos = i;
            startPos = endPos + 1;
        }
    }
    midpFree(buffer);
    return 0;
}