/**
 * Create a new message and populate it with the given data. Memory will be
 * allocated for the new message. If the message length is longer than the
 * maximum length permitted for a SMS message, the new message will contain only
 * the maximum number of characters permitted for a SMS message.
 *
 * @param encodingType The SMS message encoding type.
 * @param msgAddr Source MSISDN phone number (32 chars).
 * @param sourcePortNum Source SMS port that the message was sent from.
 * @param destPortNum Destination SMS port that the message was sent to.
 * @param timeStamp Creation time.
 * @param msgLen Message size.
 * @param msgBuffer The body of the message.
 *
 * @return The new SMS message.
 */
SmsMessage* jsr120_sms_new_msg(jchar	  encodingType,
                               unsigned char  msgAddr[MAX_ADDR_LEN],
                               jchar	  sourcePortNum,
                               jchar	  destPortNum,
                               jlong	  timeStamp,
                               jchar	  msgLen,
                               unsigned char* msgBuffer) {

	SmsMessage *sms = (SmsMessage*)pcsl_mem_malloc(sizeof(SmsMessage));
	memset(sms, 0, sizeof(SmsMessage));

	sms->msgAddr = (char*)pcsl_mem_malloc(MAX_ADDR_LEN);
	sms->msgBuffer = (char*)pcsl_mem_malloc(msgLen);

    sms->encodingType  = encodingType;
    sms->sourcePortNum = sourcePortNum;
    sms->destPortNum   = destPortNum;
    sms->timeStamp     = timeStamp;
    sms->msgLen        = msgLen;

    memcpy(sms->msgAddr, msgAddr, MAX_ADDR_LEN);
    memcpy(sms->msgBuffer, msgBuffer, msgLen);

    return sms;
}
Example #2
0
/**
 * Create a new message and populate it with the given data. Memory will be
 * allocated for the new message. If the message length is longer than the
 * maximum length permitted for a CBS message, the new message will contain only
 * the maximum number of characters permitted for a CBS message.
 *
 * @param encodingType The CBS message encoding type.
 * @param msgID The message identifier.
 * @param msgLen The length of the message, excluding the terminating character.
 * @param msgBuffer The buffer that holds the text message and its terminating
 *	character.
 *
 * @return The new CBS message.
 */
CbsMessage* jsr120_cbs_new_msg(jchar encodingType,
                               jchar msgID,
                               jchar msgLen,
                               unsigned char* msgBuffer) {

    /* Create a new message structure. */
    CbsMessage* message = (CbsMessage*)pcsl_mem_malloc(sizeof(CbsMessage));
    memset(message, 0, sizeof(CbsMessage));

    /* Populate the message structure with the given data. */
    message->encodingType = encodingType;
    message->msgID = msgID;

    /* Keep the message length in range. */
    if (msgLen > MAX_CBS_MESSAGE_SIZE) {
        msgLen = MAX_CBS_MESSAGE_SIZE;
    }
    message->msgLen = msgLen;
    message->msgBuffer = (unsigned char*) pcsl_mem_malloc(msgLen);

    /* Copy the message. */
    memcpy(message->msgBuffer, msgBuffer, msgLen);

    return message;
}
Example #3
0
javacall_result bt_push_register_url(const char *url, const void *data,
        size_t size)
{
    bt_port_t port;
    bt_params_t params;
    bt_push_t *push;
    REPORT_INFO(LC_PUSH, "Bluetooth PushRegistry URL registration:");
    REPORT_INFO1(LC_PUSH, "%s", url);
    bt_push_parse_url(url, &port, &params);
    push = find_push(&port, NULL);
    if (push != NULL) {
        /* found existing entry with the same protocol/uuid, can not proceed */
        REPORT_ERROR(LC_PUSH, "Entry already exists, registration failed.");
        return JAVACALL_FAIL;
    }
    /* save the entry in the registry */
    push = (bt_push_t *)pcsl_mem_malloc(sizeof(bt_push_t));
    if (push == NULL) {
        REPORT_ERROR(LC_PUSH, "Failed to allocate memory.");
        return JAVACALL_FAIL;
    }
    memcpy(&push->port, &port, sizeof(bt_port_t));
    memcpy(&push->params, &params, sizeof(bt_params_t));
    push->record.id = BT_INVALID_SDDB_HANDLE;
    push->record.classes = 0;
    if (data != NULL) {
        push->record.data = pcsl_mem_malloc(size);
        if (push->record.data == NULL) {
            pcsl_mem_free(push);
            return JAVACALL_FAIL;
        }
        memcpy(push->record.data, data, size);
    } else {
        push->record.data = NULL;
    }
    push->record.size = size;
    push->server = BT_INVALID_HANDLE;
    push->client = NULL;
    push->next = g_registry;
    g_registry = push;
    g_count++;
    if (javacall_bt_sddb_update_record(&push->record.id, push->record.classes,
            push->record.data, push->record.size) != JAVACALL_OK) {
        return JAVACALL_FAIL;
    }
    push_save();
    REPORT_INFO(LC_PUSH, "Registration successful.");
    return JAVACALL_OK;
}
/**
 * Perform a platform-defined procedure for obtaining random bytes and
 * store the obtained bytes into b, starting from index 0.
 * (see IETF RFC 1750, Randomness Recommendations for Security,
 *  http://www.ietf.org/rfc/rfc1750.txt)
 * @param b array that receives random bytes
 * @param nbytes the number of random bytes to receive, must not be less than size of b
 * @return the number of actually obtained random bytes, -1 in case of an error
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(com_sun_midp_crypto_PRand_getRandomBytes) {
    jint size;
    jboolean res = KNI_FALSE;
    unsigned char* buffer;

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

    size = KNI_GetParameterAsInt(2);

    buffer = pcsl_mem_malloc(size);
    if (0 == buffer) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        int i;
        res = get_random_bytes_port(buffer, size);
        for(i=0; i<size; i++) {
            KNI_SetByteArrayElement(hBytes,i,(jbyte)buffer[i]);
        }
        pcsl_mem_free(buffer);
    }
    
    KNI_EndHandles();
    KNI_ReturnBoolean(res);
}
Example #5
0
/**
 * The opendir function opens directory named dirname. 
 */
void* pcsl_file_openfilelist(const pcsl_string * string)
{
    int rootLength;
    PCSLFileIterator* pIterator;

    pIterator = (PCSLFileIterator*)pcsl_mem_malloc(sizeof (PCSLFileIterator));
    if (pIterator == NULL) {
	/* Error in allocation */
	return NULL;
    }

    memset(pIterator, 0, sizeof(PCSLFileIterator));
    pIterator->iteratorHandle = INVALID_HANDLE_VALUE;

    /*
     * find the root dir of the string
     */
    rootLength = pcsl_string_last_index_of(string, FILESEP);
    if (-1 == rootLength) {
	rootLength = 0;
    } else {
	/* Include the file separator. */
	rootLength++;
    }

    pIterator->savedRootLength = rootLength;

    /*
     * FindFirstFile open and get the first file, so do not
     * do any thing more until get next is called.
     */
    return pIterator;

}
Example #6
0
/**
 * Create an MMS message structure, containing unformatted message data.
 *
 * @param length The total number of bytes in the buffer.
 * @param buffer The buffer that contains the entire MMS message, which is
 *     composed of both the unformatted message header and message body.
 *
 * @return An <code>MmsMessage</code> structure, containing the unformatted
 *     MMS message data.
 */
MmsMessage* createMmsMessageFromBuffer(char* buffer) {

    MmsMessage* mms = NULL;

    if (buffer != NULL) {

        char* p;
        int index = 0;
        int length;

        mms = (MmsMessage *)pcsl_mem_malloc(sizeof(MmsMessage));
        memset(mms, 0, sizeof(MmsMessage));
        p = buffer;

        /* Get the sender's address. */
        mms->fromAddress = getString(p, &index);

        /* Get the application ID string. */
        mms->appID = getString(p, &index);

        /* Get the reply-to application ID string. */
        mms->replyToAppID = getString(p, &index);

        /* Get the message length and data. */
        length = getInt(p, &index);
        mms->msgLen = length;
        mms->msgBuffer = getBytes(p, &index, length);
    }

    return mms;
}
Example #7
0
/**
 * See pcsl_network.h for definition.
 */
int pcsl_network_addrToString(unsigned char *ipBytes,
        unsigned short** pResult, int* pResultLen) {
    struct in_addr addr;
    char temp[80];
    int tempLen;
    int i;
    
    memcpy(&addr.s_addr, ipBytes, sizeof(addr.s_addr));

    strcpy(temp, inet_ntoa(addr));
    tempLen = strlen(temp);

    *pResult = (unsigned short*)pcsl_mem_malloc(tempLen *
                                               sizeof (unsigned short));
    if (NULL == *pResult) {
        return PCSL_NET_IOERROR;
    }

    for (i = 0; i < tempLen; i++) {
        (*pResult)[i] = temp[i];
    }

    *pResultLen = tempLen;
    return PCSL_NET_SUCCESS;
}
Example #8
0
/*
 * Test the pcsl_mem_malloc method and pcsl_mem_get_free_heap method
 * This test ensures that after a pcsl_mem_malloc call for 1000 bytes
 * that the heap size available is reduced by 1000 bytes.
 * note: acutally, the heap pcsl_memory.c impl adds 4 guard bytes, so
 * we have to take that into account...
 */
void testMalloc() {
    int spcBefore;
    int spcAfter;
    void * buffer;

    spcBefore = pcsl_mem_get_free_heap();

    buffer = pcsl_mem_malloc(1000);
    assertTrue("failed to allocate a 1000 byte buffer", 
	       (buffer != NULL));

    spcAfter = pcsl_mem_get_free_heap();

    if (spcAfter != -1) {
        assertTrue("pcsl_mem_malloc & heap_size_available mis-match",
		   (spcBefore - 1004 == spcAfter ||
		    spcBefore - 1000 == spcAfter));
    }

    spcBefore = pcsl_mem_get_free_heap();

    pcsl_mem_free(buffer);

    spcAfter = pcsl_mem_get_free_heap();

    if (spcAfter != -1) {
        assertTrue("pcsl_mem_free & heap_size_available mis-match",
		   (spcBefore + 1004 == spcAfter ||
		    spcBefore + 1000 == spcAfter));
    }
}
Example #9
0
/*
 * Test simple memory allocation 
 * This test checks to see that NULL is not returned from a pcsl_mem_malloc
 * call.  (Note:  NULL may be a valid return in a very full/limited
 * memory system)
 */
void testAllocation() {
    void * buffer = pcsl_mem_malloc(1000);

    assertTrue("failed to allocate a 1000 byte buffer", 
	       (buffer != NULL));

    pcsl_mem_free(buffer);
}
Example #10
0
/**
 * Create a new message and populate it with the given data. Memory
 * will be allocated for the new message.
 *
 * @param fromAddress The strinf of the address from which this message
 *     originated.
 * @param appID The application ID string for the recipient.
 * @param replyToAppID The application ID string of the sender.
 * @param msgBuffer A pointer to the message data.
 *
 * @return The new MMS message.
 */
MmsMessage* jsr205_mms_new_msg(char* fromAddress, char* appID,
    char* replyToAppID, int msgLen, unsigned char* msgBuffer) {

    MmsMessage* message = (MmsMessage*)pcsl_mem_malloc(sizeof(MmsMessage));
    memset(message, 0, sizeof(MmsMessage));

    /* Duplicate the address information. */
    message->fromAddress = (char*)pcsl_mem_strdup(fromAddress);
    message->appID = (char*)pcsl_mem_strdup(appID);
    message->replyToAppID = (char*)pcsl_mem_strdup(replyToAppID);

    /* Make a copy of the buffer length and of the message buffer. */
    message->msgLen = msgLen;
    message->msgBuffer = (char*)pcsl_mem_malloc(msgLen);
	memcpy(message->msgBuffer, msgBuffer, msgLen);

    return message;
}
/**
 * Reads the given file into the given buffer.
 * File contents is read as one piece.
 *
 * @param ppszError pointer to character string pointer to accept an error
 * @param pFileName file to read
 * @param outBuffer buffer where the file contents should be stored
 * @param outBufferLen length of the outBuffer
 *
 * @return status code (ALL_OK if there was no errors)
 */
MIDPError
read_file(char** ppszError, const pcsl_string* pFileName,
          char** outBuffer, long* outBufferLen) {
    int handle, status = ALL_OK;
    long fileSize, len;
    char* pszTemp;
    char* buffer = NULL;

    *ppszError  = NULL;
    *outBuffer  = NULL;
    *outBufferLen = 0;

    /* open the file */
    handle = storage_open(ppszError, pFileName, OPEN_READ);
    if (*ppszError != NULL) {
        if (!storage_file_exists(pFileName)) {
            return NOT_FOUND;
        }
        return IO_ERROR;
    }

    do {
        /* get the size of file */
        fileSize = storageSizeOf(ppszError, handle);
        if (*ppszError != NULL) {
            status = IO_ERROR;
            break;
        }

        if (fileSize > 0) {
            /* allocate a buffer to store the file contents */
            buffer = (char*)pcsl_mem_malloc(fileSize);
            if (buffer == NULL) {
                status = OUT_OF_MEMORY;
                break;
            }

            /* read the whole file */
            len = storageRead(ppszError, handle, buffer, fileSize);
            if (*ppszError != NULL || len != fileSize) {
                pcsl_mem_free(buffer);
                status = IO_ERROR;
            }
        }
    } while (0);

    /* close the file */
    storageClose(&pszTemp, handle);
    storageFreeError(pszTemp);

    if (status == ALL_OK) {
        *outBuffer    = buffer;
        *outBufferLen = fileSize;
    }

    return (MIDPError)status;
}
/**
 * Reads named secure resource of the suite with specified suiteId
 * from secure persistent storage.
 *
 * Note that when porting memory for the in/out parameter
 * returnValue MUST be allocated using pcsl_mem_malloc().
 * The caller is responsible for freeing it.
 *
 * @param suiteId           The suite id used to identify the MIDlet suite
 * @param resourceName      The name of secure resource to read from storage
 * @param returnValue       The in/out parameter that will return the
 *                          value part of the requested secure resource
 *                          (NULL is a valid return value)
 * @param valueSize         The length of the secure resource value
 *
 * @return one of the error codes:
 * <pre>
 *     ALL_OK, OUT_OF_MEMORY, NOT_FOUND,
 *     SUITE_CORRUPTED_ERROR, BAD_PARAMS
 * </pre>
 */
MIDPError
midp_suite_read_secure_resource(SuiteIdType suiteId,
                                const pcsl_string* resourceName,
                                jbyte **returnValue,
                                jint *valueSize) {
    pcsl_string filename = PCSL_STRING_NULL;
    char *pszError = NULL;
    MIDPError errorCode;
    int bytesRead;
    int handle;

    *returnValue = NULL;
    *valueSize = 0;

    errorCode = get_secure_resource_file(suiteId, resourceName, &filename);
    if (errorCode != ALL_OK) {
        pcsl_string_free(&filename);
        return errorCode;
    }

    handle = storage_open(&pszError, &filename, OPEN_READ);
    pcsl_string_free(&filename);
    if (pszError != NULL) {
        storageFreeError(pszError);
        return SUITE_CORRUPTED_ERROR;
    }

    do {
        bytesRead = storageRead(&pszError, handle,
            (char*)valueSize, sizeof (int));
        if (bytesRead != sizeof (int) || *valueSize == 0)
            break;

        *returnValue = (jbyte*)pcsl_mem_malloc(*valueSize * sizeof (jbyte));
        if (*returnValue == NULL) {
            errorCode = OUT_OF_MEMORY;
            break;
        }

        bytesRead = storageRead(&pszError, handle, (char*)(*returnValue),
            *valueSize * sizeof (jbyte));

        if (pszError != NULL || bytesRead != *valueSize) {
            errorCode = SUITE_CORRUPTED_ERROR;
            pcsl_mem_free(*returnValue);
            *returnValue = NULL;
            break;
        }
    } while (0);

    storageClose(&pszError, handle);
    storageFreeError(pszError);

    return errorCode;
}
Example #13
0
/**
 * The open function creates and returns a new file identifier for the 
 * file named by filename. Initially, the file position indicator for the 
 * file is at the beginning of the file.
 */
int pcsl_file_open(const pcsl_string * fileName, int flags, void **handle) {
    HANDLE fileHandle;

    DWORD dwDesiredAccess; 
    DWORD dwCreationDisposition;

    const jchar* pszOsFilename = pcsl_string_get_utf16_data(fileName);

    *handle = NULL;

    if (NULL == pszOsFilename) {
        return -1;
    }

    switch (flags & (PCSL_FILE_O_RDWR | PCSL_FILE_O_WRONLY | PCSL_FILE_O_RDONLY)) {
        case PCSL_FILE_O_RDONLY: dwDesiredAccess = GENERIC_READ;  break;
        case PCSL_FILE_O_WRONLY: dwDesiredAccess = GENERIC_WRITE; break;
        default: /* PCSL_FILE_O_RDWR or other flag combination */
            dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; break;
    }

    switch (flags & (PCSL_FILE_O_CREAT | PCSL_FILE_O_TRUNC)) {
        case PCSL_FILE_O_CREAT | PCSL_FILE_O_TRUNC: 
            dwCreationDisposition = CREATE_ALWAYS; break;
        case PCSL_FILE_O_CREAT: 
            dwCreationDisposition = OPEN_ALWAYS; break;
        case PCSL_FILE_O_TRUNC: 
            dwCreationDisposition = TRUNCATE_EXISTING; break;
        default:
            dwCreationDisposition = OPEN_EXISTING; break;
    }

    fileHandle = CreateFileW(pszOsFilename, dwDesiredAccess, 
        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreationDisposition, 
        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);

    pcsl_string_release_utf16_data(pszOsFilename, fileName);

    if (fileHandle == INVALID_HANDLE_VALUE) {
        return -1;
    }

    {
        PCSLFile* pFHandle = pcsl_mem_malloc(sizeof(PCSLFile));
        if (pFHandle == NULL) {
            CloseHandle(fileHandle);
            return -1;
        }

        pFHandle->createFlags = flags;
        pFHandle->fileHandle = fileHandle;
        *handle  = pFHandle;
        return 0;
    }
}
Example #14
0
/**
 * Create an MMS message from the given parameters.
 *
 * @param fromAddress The sender's MMS address.
 * @param appID The application ID corresponding to the message.
 * @param length The total number of bytes in the message.
 * @param buffer A pointer to the message bytes.
 *
 * @return The constructed MMS message.
 */
MmsMessage* createMmsMessage(char* fromAddress, char* appID, char* replyToAppID,
    jint length, char* buffer) {

    MmsMessage* mms = NULL;

    if (buffer != NULL) {

        mms = (MmsMessage*)pcsl_mem_malloc(sizeof(MmsMessage));
        memset(mms, 0, sizeof(MmsMessage));

        /* Copy the "from" address. */
        if (fromAddress == NULL) {
            mms->fromAddress = NULL;
        } else {
            mms->fromAddress = (char*)pcsl_mem_malloc(strlen(fromAddress)+1);
            strcpy(mms->fromAddress, fromAddress);
        }

        /* Copy the application ID string. */
        mms->appID = (char*)pcsl_mem_malloc(strlen(appID)+1);
        strcpy(mms->appID, appID);

        /* Copy the reply-to application ID string. */
        if (replyToAppID == NULL) {
            mms->replyToAppID = NULL;
        } else {
            mms->replyToAppID = (char*)pcsl_mem_malloc(strlen(replyToAppID)+1);
            strcpy(mms->replyToAppID, replyToAppID);
        }

        /* Copy the message length and the message bytes. */
        mms->msgLen = length;

        mms->msgBuffer = (char*)pcsl_mem_malloc(length);
        memcpy(mms->msgBuffer, buffer, length);
    }

    return mms;
}
/**
 * See pcsl_network_na.h for definition.
 */
void* na_create(int fd) {
    SocketHandle* handle =
        (SocketHandle*)pcsl_mem_malloc(sizeof(SocketHandle));

    if (handle != NULL) {
        handle->fd = fd;
        handle->check_flags = 0;
        handle->status = PCSL_NET_SUCCESS;
        handle->next = NULL;
    }

    return (void*)handle;
}
Example #16
0
/**
 * Creates a platform-specific handle.
 *
 * @param fd platform-specific file descriptor to be associated with
 *		the new handle
 *
 * @return the platform-specific handle; NULL if there was an error
 */
void *
wmaCreateSocketHandle(WMA_PROTOCOLS protocol, int fd) {
    jsr120_socket* ws;

    ws = (jsr120_socket*)pcsl_mem_malloc(sizeof(jsr120_socket));
    ws->sockProtocol = protocol;
    ws->sockFD = fd;

    ws->next = wmaSocketRoot;
    wmaSocketRoot = ws;

    return ws;
}
Example #17
0
/**
 * Send event to external event queue
 * This function is a sample implementation for Win32
 */
static void jmmpSendEvent(int type, int param1, int param2)
{
#if 0
    /* This memory SHOULD be deallocated from event handler */
    int* pParams = (int*)pcsl_mem_malloc(sizeof(int) * 2);

    if (pParams) {
        pParams[0] = param1;
        pParams[1] = param2;
        PostMessage(GET_MCIWND_HWND(), WM_MEDIA, type, (LPARAM)pParams);
    }
#endif
}
Example #18
0
/**
 * Get a formatted MMS header from unformatted MMS message data..
 *
 * @param message An MMS message, containing unformatted data.
 *
 * @return An <code>MmsHeader</code> structure, containing formatted MMS header
 *     data.
 */
MmsHeader* createMmsHeader(MmsMessage* message) {

    MmsHeader* header = NULL;

    if (message != NULL) {

        /* Later, read header length, then data to be formatted. */
        header = (MmsHeader *)pcsl_mem_malloc(sizeof(MmsHeader));
        memset(header, 0, sizeof(MmsHeader));
        /* Populate the header with data extracted from message fields. */
    }

    return header;
}
/**
 * Create a new list element with a numeric identifier.
 *
 * @param head	A pointer to the first element in the list.
 * @param num The number that identifies this element.
 * @param msid The MIDlet suite identifier.
 * @param userData  Anything the user needs to attach to this element.
 * @param userDataCallBack  A user-defined callback.
 *
 * @return A pointer to the element that was created.
 */
ListElement* jsr120_list_new_by_number(ListElement** head, jint num,
    AppIdType msid, void* userData, void* userDataCallback) {

    ListElement* q      = (ListElement*) pcsl_mem_malloc(sizeof(ListElement));
    q->next             = NULL;
    q->id               = num;
    q->msid         = msid;
    q->strid = NULL;
    q->userData = userData;
    q->userDataCallback = userDataCallback;
    q->isRegistered = 1;
    q->isNewMessage = 1;
    jsr120_list_add_first(head, q);

    return q;
}
Example #20
0
/*
 * Test the fact that global heap size never changes
 */
void testHeapSize() {
     void *buffer;
     int rv, rv2, rv3;

     rv = pcsl_mem_get_total_heap();
   
     buffer = pcsl_mem_malloc(1000);

     rv2 = pcsl_mem_get_total_heap();

     pcsl_mem_free(buffer);

     rv3 = pcsl_mem_get_total_heap();

     assertTrue("pcsl total heap size should never change, but did",
	        (rv == rv2) && (rv2 == rv3));
}  
Example #21
0
/**
 * Creates a new rendezvous point with the given sender and receiver. Returns 
 * a pointer to the rendezvous point, otherwise NULL if out of memory.
 */
static rendezvous *
rp_create(int sender, int receiver) {
    rendezvous *rp;

    rp = (rendezvous *)pcsl_mem_malloc(sizeof(rendezvous));
    if (rp == NULL) {
        return NULL;
    }

    rp->state = IDLE;
    rp->retcode = OK;
    rp->refcount = 0;
    rp->msg = INVALID_REFERENCE_ID;
    rp->sender = sender;
    rp->receiver = receiver;

    return rp;
}
Example #22
0
/** The initialize function initials the File System, it is only needed for RMFS, for RMFS, this
 *  function specifies one memory block to be File System storage.
 */
int pcsl_file_init()
{
  if (pcsl_string_is_active() == PCSL_FALSE) {
    return -1;
  }

#ifndef PCSL_RAMFS_USE_STATIC
    if (RamfsMemory == NULL) {
        /* allocate the chunk of memory to C heap */
        RamfsMemory = (char*)pcsl_mem_malloc(DEFAULT_RAMFS_SIZE);
        if (RamfsMemory == NULL) {
    	    return -1;
        }
    }
#endif /* ! PCSL_RAMSF_USE_STATIC */

    return rmfsInitialize((jint)RamfsMemory, DEFAULT_RAMFS_SIZE);
}
Example #23
0
javacall_bool bt_push_accept(bt_pushid_t pushid, const char *filter,
        javacall_handle *handle)
{
    bt_push_t *push = (bt_push_t *)pushid;
    bt_client_t *client;
    if (push == NULL) {
        return JAVACALL_FALSE;
    }
    client = (bt_client_t *)pcsl_mem_malloc(sizeof(bt_client_t));
    switch (push->port.protocol) {
        case BT_L2CAP:
            if (javacall_bt_l2cap_accept(push->server,
                    &client->handle, &client->bdaddr,
                    &client->rmtu, &client->tmtu) != JAVACALL_OK) {
                pcsl_mem_free(client);
                return JAVACALL_FALSE;
            }
            break;
        case BT_SPP:
        case BT_GOEP:
            if (javacall_bt_rfcomm_accept(push->server,
                    &client->handle, &client->bdaddr) != JAVACALL_OK) {
                pcsl_mem_free(client);
                return JAVACALL_FALSE;
            }
            break;
        default:
            pcsl_mem_free(client);
            return JAVACALL_FALSE;
    }
    if (bt_push_test_filter(client->bdaddr, filter) == JAVACALL_TRUE) {
        bt_client_t **client_ptr = &push->client;
        while (*client_ptr != NULL) {
            client_ptr = &(*client_ptr)->next;
        }
        *client_ptr = client;
        client->next = NULL;
        *handle = client->handle;
        return JAVACALL_TRUE;
    }
    close_handle(push->port.protocol, client->handle);
    pcsl_mem_free(client);
    return JAVACALL_FALSE;
}
Example #24
0
OsFile_Handle OsFile_open(const JvmPathChar *filename, const char *mode) {
  int name_len = fn_strlen(filename);
  pcsl_string pcsl_filename = PCSL_STRING_NULL;

  GUARANTEE(sizeof(jchar) == sizeof(JvmPathChar), "Types must match");

  if (pcsl_string_convert_from_utf16(filename, 
                                     name_len, 
                                     &pcsl_filename) != PCSL_STRING_OK) {
    return NULL;
  }

/*
  int pcsl_flags = (*mode == 'w') ? (PCSL_FILE_O_CREAT|PCSL_FILE_O_WRONLY|
                                     PCSL_FILE_O_TRUNC) :
                                    (PCSL_FILE_O_RDONLY);
*/

  int pcsl_flags;
  if(*mode == 'w') { 
    pcsl_flags = (PCSL_FILE_O_CREAT | PCSL_FILE_O_WRONLY | PCSL_FILE_O_TRUNC);
  } else if(*mode == 'a') {
    pcsl_flags = (PCSL_FILE_O_WRONLY | PCSL_FILE_O_APPEND);
  } else {
    pcsl_flags = PCSL_FILE_O_RDONLY;
  }

  void *pcsl_handle;
  if (pcsl_file_open(&pcsl_filename, pcsl_flags, &pcsl_handle) == 0) {
    pcsl_string_free(&pcsl_filename);
    OsFile_Handle handle =
      (OsFile_Handle)pcsl_mem_malloc(sizeof(struct _OsFile_Handle));
    if (handle) {
      handle->pcsl_handle = pcsl_handle;
    } else {
      pcsl_file_close(pcsl_handle);
    }
    return handle;
  } else {
    pcsl_string_free(&pcsl_filename);
    return NULL;
  }
}
Example #25
0
/**
 * Gets localized private root name corresponding to the root returned by
 * <code>System.getProperty("fileconn.dir.private")</code>.
 *
 * This method is called when the <code>fileconn.dir.private.name</code> system
 * property is retrieved.
 *
 * @return the localized name for the suite's private root
 */
char* getLocalizedPrivateDir()
{
    const int disks_num = getValidDisksSize();
    int i = 0;

    // since the value doesnt change, return cached value if exists
    if (localizedPrivate != NULL) {
        return localizedPrivate;
    }

    // find and copy private root name
    for (i = 0; i < disks_num; i++) {
        if (!strcmp("private", validDisks[i][0])) {
            localizedPrivate = (char*)pcsl_mem_malloc(strlen(validDisks[i][2]) + 1);
            strcpy(localizedPrivate, validDisks[i][2]);
        }
    }
    return localizedPrivate;
}
Example #26
0
/*
 * Test that a repeated pcsl_mem_initialize call is ignored
 */
void testDoubleInit() {
    void *buffer = pcsl_mem_malloc(1000);
    int i, rv;
    int *arr;

    arr = (int*) buffer;

    for (i = 0; i < 100; i++) {
        *(arr + i) = 727;
    } 

    rv = pcsl_mem_initialize(NULL, 4000);
    assertTrue("second pcsl_mem_initialize call fails",
	       rv == 0);
    
    assertTrue("data corrupt after pcsl_mem_initialize call",
	       *arr == 727 &&
	       *(arr + 50) == 727);
    pcsl_mem_free(buffer);
}
/**
 * Create a new list element with a string identifier.
 *
 * @param head A pointer to the first element in the list.
 * @param name The name which identifies this element. The name is duplicated.
 * @param msid The MIDlet suite identifier.
 * @param userData  Anything the user needs to attach to this element.
 * @param userDataCallBack  A user-defined callback.
 *
 * @return A pointer to the element that was created.
 */
ListElement* jsr120_list_new_by_name(ListElement** head, unsigned char* name,
    AppIdType msid, void* userData, void* userDataCallback) {

    ListElement* q = (ListElement*) pcsl_mem_malloc(sizeof(ListElement));
    q->next = NULL;
    q->id = -1;
    /* Duplicate the name. */
    if (name != NULL) {
        q->strid = (unsigned char*)pcsl_mem_strdup((char*)name);
    } else {
        q->strid = NULL;
    }
    q->msid = msid;
    q->userData = userData;
    q->userDataCallback = userDataCallback;
    q->isRegistered = 1;
    q->isNewMessage = 1;
    jsr120_list_add_first(head, q);
    return q;
}
Example #28
0
/**
 * Read a UTF-8 string. Note: This is not a full UTF-8 reader and just handles
 * simple cases.
 */
char* readUTF(MMSMessageContext *context) {
    char* s;
    int len;

    if (context->utfp >= context->utfend) {
        /* Attempt to read beyond stream length. */
        return NULL;
    }

    /* Pick up the length and advance the pointer beyond the length. */
    len = ((unsigned char)*context->utfp << 8) | (unsigned char)(*(context->utfp+1));
    context->utfp += 2;

    /* Pick up the string and advance the pointer beyond the string. */
    s = (char*)pcsl_mem_malloc(len + 1);
    strncpy(s, context->utfp, len);
    *(s + len) = '\0';  /* terminator */
    context->utfp += len;

    return s;
}
Example #29
0
/**
 * Create pcsl_string from the specified Java String object.
 * The caller is responsible for freeing the created pcsl_string when done.
 *
 * @param java_str pointer to the Java String instance
 * @param pcsl_str pointer to the pcsl_string instance
 * @return status of the operation
 */
pcsl_string_status midp_jstring_to_pcsl_string(jstring java_str,
					       pcsl_string * pcsl_str) {
  if (pcsl_str == NULL) {
    return PCSL_STRING_EINVAL;
  }

  if (KNI_IsNullHandle(java_str)) {
    * pcsl_str = PCSL_STRING_NULL;
    return PCSL_STRING_OK;
  } else {
    const jsize length  = KNI_GetStringLength(java_str);

    if (length < 0) {
      * pcsl_str = PCSL_STRING_NULL;
      return PCSL_STRING_ERR;
    } else if (length == 0) {
      * pcsl_str = PCSL_STRING_EMPTY;
      return PCSL_STRING_OK;
    } else {
      jchar * buffer = pcsl_mem_malloc(length * sizeof(jchar));

      if (buffer == NULL) {
	* pcsl_str = PCSL_STRING_NULL;
	return PCSL_STRING_ENOMEM;
      }

      KNI_GetStringRegion(java_str, 0, length, buffer);

      {
	pcsl_string_status status =
	  pcsl_string_convert_from_utf16(buffer, length, pcsl_str);

	pcsl_mem_free(buffer);

	return status;
      }
    }
  }
}
Example #30
0
/**
 * Create pcsl_string from the specified KNI CharArray object.
 * The caller is responsible for freeing the created pcsl_string when done.
 *
 * @param java_arr pointer to the KNI CharArray instance
 * @param length length of the text in the CharArray
 * @param pcsl_str pointer to the pcsl_string instance
 * @return status of the operation
 */
pcsl_string_status
midp_jchar_array_to_pcsl_string(jcharArray java_arr, jint length,
                                pcsl_string * pcsl_str) {
    if (pcsl_str == NULL) {
        return PCSL_STRING_EINVAL;
    }

    if (KNI_IsNullHandle(java_arr)) {
        *pcsl_str = PCSL_STRING_NULL;
        return PCSL_STRING_OK;
    } else if (length < 0) {
        *pcsl_str = PCSL_STRING_NULL;
        return PCSL_STRING_ERR;
    } else if (length == 0) {
        *pcsl_str = PCSL_STRING_EMPTY;
        return PCSL_STRING_OK;
    } else {
        jchar * buffer = pcsl_mem_malloc(length * sizeof(jchar));

        if (buffer == NULL) {
              * pcsl_str = PCSL_STRING_NULL;
            return PCSL_STRING_ENOMEM;
        }

          KNI_GetRawArrayRegion(java_arr, 0,
                                          length * sizeof(jchar),
                                          (jbyte *) buffer);

        {
            pcsl_string_status status =
                  pcsl_string_convert_from_utf16(buffer, length, pcsl_str);

              pcsl_mem_free(buffer);

            return status;
        }
    }
}