/** * Add a MMS message to the message pool. If the pool is full (i.e., there are * at least <code>MAX_MMS_MESSAGES_IN_MMS_POOL</code>), then the oldest messages * are discarded. * * @param msg The message to be added. * * @return <code>WMA_OK</code> if the message was successfully added to the * pool. <code>WMA_ERR</code>, otherwise. */ WMA_STATUS jsr205_mms_pool_add_msg(MmsMessage* msg) { ListElement* newItem; /* If there is no message to add, bail out. */ if (msg == NULL) { return WMA_ERR; } /* Make room for this message, if necessary. */ jsr205_mms_pool_check_quota(); /* Create the new pool item and add it to the pool. */ newItem = jsr120_list_new_by_name(NULL, (unsigned char*)msg->appID, UNUSED_SUITE_ID, (void*)msg, 0); jsr120_list_add_last(&MMSPool_messages, newItem); jsr205_mms_pool_increase_msg_count(); /* Notify all listeners of the new message. */ jsr205_mms_message_arrival_notifier(msg); return WMA_OK; }
/** * Send an MMS message. * * @param sendingToSelf <code>1</code> if sending the message to this device; * <code>0</code>, otherwise. * @param toAddr The recipient's MMS address. * @param fromAddr The sender's MMS address. * @param appID The application ID string associated with this message. * @param replyToAppID The reply-to application ID string associated with this * message. * @param msgLen The total length, in bytes, of the MMS message. * @param msg A pointer to the MMS message, which contains both the message * header and message body structures. * @param bytesWritten Returns the number of bytes written after successful * write operation. This is only set if this function returns * WMA_NET_SUCCESS. * @param pContext pointer to location to save operation context for asynchronous * operations * * @return WMA_NET_SUCCESS for successful write operation;\n * WMA_NET_WOULDBLOCK if the operation would block,\n * WMA_NET_INTERRUPTED for an Interrupted IO Exception\n * WMA_NET_IOERROR for all other errors. */ WMA_STATUS jsr205_mms_write(jint sendingToSelf, char *toAddr, char* fromAddr, char* appID, char* replyToAppID, jint msgLen, char* msg, jint *bytesWritten, void **pContext) { /** The writing index. */ int index = 0; /** The return status. */ WMA_STATUS status; jsr120_udp_emulator_context *context; char *buffer; #if ENABLE_WMA_LOOPBACK MmsMessage* mms; (void)sendingToSelf; (void)toAddr; #else if (sendingToSelf == WMA_NET_IOERROR) { return WMA_NET_IOERROR; } #endif if (appID == NULL) appID = ""; if (replyToAppID == NULL) replyToAppID = ""; if (*pContext == NULL) { context = (jsr120_udp_emulator_context *)pcsl_mem_malloc(sizeof(*context)); if (context == NULL) return WMA_NET_IOERROR; memset(context, 0, sizeof(*context)); /* * Create storage for the following: * - Application ID and its terminator (1 byte) * - The 1-byte terminator for the replyToAppID, or the 1-byte * special flag when replyToAppID is NULL. * - The message length data * - The message data. */ context->totalLength = strlen(fromAddr) + 1 + strlen(appID) + 1 + strlen(replyToAppID) + 1 + sizeof(int) + msgLen; buffer = (char*)pcsl_mem_malloc(context->totalLength); if (buffer == NULL) { pcsl_mem_free(context); return WMA_NET_IOERROR; } *pContext = context; memset(buffer, 0, context->totalLength); context->msg_buffer = buffer; /* Populate the buffer to be written. */ wma_put_string(buffer, &index, (char*)fromAddr); wma_put_string(buffer, &index, (char*)appID); wma_put_string(buffer, &index, (char*)replyToAppID); wma_put_int(buffer, &index, msgLen); wma_put_bytes(buffer, &index, (char *)msg, msgLen); } else { context = (jsr120_udp_emulator_context*)*pContext; buffer = context->msg_buffer; } #if ENABLE_WMA_LOOPBACK mms = createMmsMessage(fromAddr, appID, replyToAppID, msgLen, msg); /* Add the message to the pool. */ jsr205_mms_pool_add_msg(mms); /* Notify all listeners of the new message. */ jsr205_mms_message_arrival_notifier(mms); /* Fake the written count as well as the "sending" status. */ *bytesWritten = context->totalLength; status = WMA_NET_SUCCESS; #else { int outputPort = mmsOutPortNumber; /* The buffer to be written would have the reply-to address. */ (void)replyToAppID; /* If talking to ourselves, redirect output to the in-port. */ if (sendingToSelf != 0) { outputPort = mmsInPortNumber; } status = jsr205_datagram_write(WMA_MMS_PROTOCOL, outputPort, mmsHandle, toAddr, fromAddr, context->totalLength, buffer, bytesWritten, context); } #endif if (status != WMA_NET_WOULDBLOCK) { /* * Message was sent or operation aborted, so free the buffer and * context. */ pcsl_mem_free(buffer); pcsl_mem_free(context); *pContext = NULL; } return status; }
/** * Send an MMS message. * * @param sendingToSelf <code>1</code> if sending the message to this device; * <code>0</code>, otherwise. * @param toAddr The recipient's MMS address. * @param fromAddr The sender's MMS address. * @param appID The application ID string associated with this message. * @param replyToAppID The reply-to application ID string associated with this * message. * @param msgLen The total length, in bytes, of the MMS message. * @param msg A pointer to the MMS message, which contains both the message * header and message body structures. * @param bytesWritten Returns the number of bytes written after successful * write operation. This is only set if this function returns * WMA_NET_SUCCESS. * * @return WMA_NET_SUCCESS for successful write operation;\n * WMA_NET_WOULDBLOCK if the operation would block,\n * WMA_NET_INTERRUPTED for an Interrupted IO Exception\n * WMA_NET_IOERROR for all other errors. */ WMA_STATUS jsr205_mms_write(jint sendingToSelf, char *toAddr, char* fromAddr, char* appID, char* replyToAppID, jint msgLen, char* msg, jint *bytesWritten) { /** The total length of all data to be written. */ jint totalLength = 0; /** The buffer that will contain all data to be written. */ char* buffer = NULL; /** The writing index. */ jint index = 0; /** The return status. */ WMA_STATUS status; if (appID == NULL) appID = ""; if (replyToAppID == NULL) replyToAppID = ""; /* * Create storage for the following: * - Application ID and its terminator (1 byte) * - The 1-byte terminator for the replyToAppID, or the 1-byte * special flag when replyToAppID is NULL. * - The message length data * - The message data. */ totalLength = strlen(fromAddr) + 1 + strlen(appID) + 1 + strlen(replyToAppID) + 1 + sizeof(int) + msgLen; buffer = (char*)pcsl_mem_malloc(totalLength); if (buffer == NULL) { return WMA_NET_IOERROR; } memset(buffer, 0, totalLength); /* Populate the buffer to be written. */ wma_put_string(buffer, &index, (char*)fromAddr); wma_put_string(buffer, &index, (char*)appID); wma_put_string(buffer, &index, (char*)replyToAppID); wma_put_int(buffer, &index, msgLen); wma_put_bytes(buffer, &index, (char *)msg, msgLen); #if ENABLE_WMA_LOOPBACK (void)sendingToSelf; (void)toAddr; MmsMessage* mms = createMmsMessage(fromAddr, appID, replyToAppID, msgLen, msg); /* Add the message to the pool. */ jsr205_mms_pool_add_msg(mms); /* Notify all listeners of the new message. */ jsr205_mms_message_arrival_notifier(mms); /* Fake the written count as well as the "sending" status. */ *bytesWritten = totalLength; status = WMA_NET_SUCCESS; #else /* The buffer to be written would have the reply-to address. */ (void)replyToAppID; int outputPort = mmsOutPortNumber; if (sendingToSelf != 0) { /* Talking to ourselves; redirect output to the in-port. */ outputPort = mmsInPortNumber; } status = jsr205_datagram_write(outputPort, mmsHandle, toAddr, fromAddr, totalLength, buffer, bytesWritten); #endif /* Message was sent, so free the buffer. */ pcsl_mem_free(buffer); return status; }