JMMSJsrHandler.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:133k
源码类别:

MTK

开发平台:

C/C++

  1.         case JC_ERR_FILE_SYS_INIT:
  2.         case JC_ERR_FILE_MOVE:
  3.         case JC_ERR_FILE_INVALID_SYSTEM_HANDLE:
  4.             return JSR_RESULT_FILE_OPERATION_ERROR;
  5.         default:
  6.             return JSR_RESULT_ERROR;
  7.     }
  8. }
  9. /*****************************************************************************
  10.  * FUNCTION
  11.  *  mmi_jmms_jsr_add_media_object
  12.  * DESCRIPTION
  13.  *  
  14.  * PARAMETERS
  15.  *  msgId       [IN]        
  16.  *  message     [?]         [?]
  17.  * RETURNS
  18.  *  
  19.  *****************************************************************************/
  20. JsrResult mmi_jmms_jsr_add_media_object(U32 msgId, wap_mmc_post_appmms_msg_part_res_struct *message)
  21. {
  22.     /*----------------------------------------------------------------*/
  23.     /* Local Variables                                                */
  24.     /*----------------------------------------------------------------*/
  25.     MEDIA_MIME_INFO *media_info_p = NULL;
  26.     JC_UINT32 file_size = 0;
  27.     JC_UINT32 read_cnt = 0;
  28.     FS_HANDLE file_handle;
  29.     JC_RETCODE ret_code = JC_OK;
  30.     JC_INT8 *media_buffer_p = NULL;
  31.     JC_INT8 *temp_buffer_p = NULL;
  32.     JC_CHAR *path_p = NULL;
  33.     JC_INT8 temp_file_path[40] = {0, };
  34.     JDD_FSHANDLE vFileSysHandle = NULL;
  35.     /*----------------------------------------------------------------*/
  36.     /* Code Body                                                      */
  37.     /*----------------------------------------------------------------*/
  38.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): Enters function mmi_jmms_jsr_add_media_object() n", __FILE__, __LINE__));
  39.     if ((message == NULL)
  40.         || (message->filepath_len == 0)
  41.         || (message->content_type_len == 0) || (message->content_id_len == 0 && message->content_location_len == 0))
  42.     {
  43.         return mmi_jmms_java_mms_error(JC_ERR_MSG_INVALID_HANDLE);
  44.     }
  45.     media_info_p = (MEDIA_MIME_INFO*) jdd_MemAlloc(sizeof(MEDIA_MIME_INFO), sizeof(U8));
  46.     if (media_info_p == NULL)
  47.     {
  48.         ret_code = JC_ERR_MEMORY_ALLOCATION;
  49.         goto ERROR_HANDLE;
  50.     }
  51.     /* Initialize the File System Handle */
  52.     ret_code = jdd_FSInitialize(&vFileSysHandle);
  53.     if(ret_code != JC_OK)
  54.     {
  55.         goto ERROR_HANDLE;
  56.     }
  57.     jc_sprintf(temp_file_path, "@mms\temp\~jsr_temp_file%d", media_obj_index);
  58.     media_obj_index++; /* increment index for next media object */
  59.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s (%s) n", "JMMS JSR Add Media File Name", temp_file_path));
  60.     jdi_UtilsCharToTchar((JC_CHAR **) &(path_p), temp_file_path);
  61.     if(path_p == NULL)
  62.     {
  63.         ret_code = JC_ERR_MEMORY_ALLOCATION;
  64.         goto ERROR_HANDLE;
  65.     }
  66.     ret_code = jdd_FSMove(NULL, (JC_CHAR*)message->filepath, vFileSysHandle, (JC_CHAR*) path_p);
  67.     if(ret_code != JC_OK)
  68.     {
  69.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Add Media File Move Failed", __FILE__, __LINE__));
  70.         goto ERROR_HANDLE;
  71.     }
  72.     if(vFileSysHandle)
  73.     {
  74.         jdd_FSDeinitialize(vFileSysHandle);
  75.         vFileSysHandle = NULL;
  76.     }
  77.     file_handle = FS_Open((U16*) path_p, FS_READ_ONLY);
  78.     FS_GetFileSize(file_handle, &file_size);
  79.     FS_Close(file_handle);
  80.     if (message->content_id_len > 0)
  81.     {
  82.         media_info_p->MimeHeaders.pContentID = (JC_INT8*) jdd_MemAlloc(sizeof(JC_INT8), message->content_id_len + 1);
  83.         if (media_info_p->MimeHeaders.pContentID == NULL)
  84.         {
  85.             ret_code = JC_ERR_MEMORY_ALLOCATION;
  86.             goto ERROR_HANDLE;
  87.         }
  88.         memcpy(media_info_p->MimeHeaders.pContentID, message->content_id, message->content_id_len);
  89.     }
  90.     if (message->content_location_len > 0)
  91.     {
  92.         ret_code = jdi_UtilsCharToTchar(
  93.                     (JC_CHAR **) & (media_info_p->MimeHeaders.pObjectName),
  94.                     (JC_INT8*) message->content_location);
  95.         if (media_info_p->MimeHeaders.pObjectName == NULL)
  96.         {
  97.             ret_code = JC_ERR_MEMORY_ALLOCATION;
  98.             goto ERROR_HANDLE;
  99.         }
  100.     }
  101.     media_info_p->MimeHeaders.bIsAttachment = 0;
  102.     if (strstr((S8*) message->content_type, "text/plain") != NULL)
  103.     {
  104.         media_info_p->MimeHeaders.pContentType = jdi_UtilsStrdup((JC_INT8*) ("text/plain"));
  105.         if (media_info_p->MimeHeaders.pContentType == NULL)
  106.         {
  107.             ret_code = JC_ERR_MEMORY_ALLOCATION;
  108.             goto ERROR_HANDLE;
  109.         }
  110.         media_info_p->ContentData.uiTotalSize = (file_size) * sizeof(JC_CHAR);
  111.         media_info_p->ContentData.uiCurSize = (file_size) * sizeof(JC_CHAR);
  112.         temp_buffer_p = (JC_INT8*) jdd_MemAlloc(file_size + 1, sizeof(JC_CHAR));
  113.         if (temp_buffer_p == NULL)
  114.         {
  115.             ret_code = JC_ERR_MEMORY_ALLOCATION;
  116.             goto ERROR_HANDLE;
  117.         }
  118.         file_handle = FS_Open((U16*) path_p, FS_READ_ONLY);
  119.         if (file_size > 0)
  120.         {
  121.             FS_Read(file_handle, temp_buffer_p, file_size, &read_cnt);
  122.         }
  123.         FS_Close(file_handle);
  124.         if (message->encoding_scheme == MMS_US_ASCII)
  125.         {
  126.             ret_code = jdi_UtilsCharToTchar((JC_CHAR **) & media_buffer_p, (JC_INT8*) temp_buffer_p);
  127.         }
  128.         else if (message->encoding_scheme == MMS_UTF8)
  129.         {
  130.             ret_code = jdi_UtilsUTF8ToTchar((JC_CHAR **) & media_buffer_p, (JC_UINT8*) temp_buffer_p, (JC_UINT32) file_size);
  131.         }
  132.         if (ret_code != JC_OK)
  133.         {
  134.             goto ERROR_HANDLE;
  135.         }
  136.         media_info_p->ContentData.pBuffer = (JC_UINT8*) media_buffer_p;
  137.     }
  138.     else
  139.     {
  140.         if (message->content_type_len > 0)
  141.         {
  142.             media_info_p->MimeHeaders.pContentType =
  143.                 (JC_INT8*) jdd_MemAlloc(message->content_type_len + 1, sizeof(JC_INT8));
  144.             if (media_info_p->MimeHeaders.pContentType == NULL)
  145.             {
  146.                 ret_code = JC_ERR_MEMORY_ALLOCATION;
  147.                 goto ERROR_HANDLE;
  148.             }
  149.             jc_strcpy(media_info_p->MimeHeaders.pContentType, message->content_type);
  150.         }
  151.         media_info_p->ContentData.bIsStream = E_TRUE;
  152.         media_info_p->ContentData.eCopyMemory = E_FALSE;
  153.         media_info_p->ContentData.pBuffer = NULL;
  154.         media_info_p->ContentData.uiCurSize = 0;
  155.         media_info_p->ContentData.uiTotalSize = file_size;
  156.         media_info_p->ContentData.cbReadCallback = mmi_jmms_read_callback;
  157.         media_info_p->ContentData.cbWriteCallback = NULL;
  158.         media_info_p->ContentData.uiStartOffset = 0;
  159.         media_info_p->ContentData.pFileName =
  160.             (JC_CHAR*) jdd_MemAlloc((jc_tcslen((JC_CHAR*) path_p) + 1), sizeof(JC_CHAR));
  161.         if (media_info_p->ContentData.pFileName == NULL)
  162.         {
  163.             ret_code = JC_ERR_MEMORY_ALLOCATION;
  164.             goto ERROR_HANDLE;
  165.         }
  166.         jc_tcscpy((UI_character_type*) media_info_p->ContentData.pFileName, (UI_character_type*) path_p);
  167.         media_info_p->ContentData.pStream = media_info_p->ContentData.pFileName;
  168.         /*media_info_p->MimeHeaders.bIsAttachment = 0;*/
  169.     }
  170.     /* add media */
  171.     ret_code = AddMediaToMM1Handle(g_jmms_context->hMM1, media_info_p,E_TRUE);
  172.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Media Object Added Sucessfully n", __FILE__, __LINE__));
  173.   ERROR_HANDLE:
  174.     if (ret_code != JC_OK)
  175.     {
  176.         if (media_info_p != NULL)
  177.         {
  178.             if (media_info_p->ContentData.pFileName != NULL)
  179.             {
  180.                 jdd_MemFree(media_info_p->ContentData.pFileName);
  181.             }
  182.             if (media_info_p->MimeHeaders.pContentType != NULL)
  183.             {
  184.                 jdd_MemFree(media_info_p->MimeHeaders.pContentType);
  185.             }
  186.             if (media_info_p->MimeHeaders.pContentID != NULL)
  187.             {
  188.                 jdd_MemFree(media_info_p->MimeHeaders.pContentID);
  189.             }
  190.             if (media_info_p->MimeHeaders.pObjectName != NULL)
  191.             {
  192.                 jdd_MemFree(media_info_p->MimeHeaders.pObjectName);
  193.             }
  194.             jdd_MemFree(media_info_p);
  195.         }
  196.     }
  197.     if (temp_buffer_p != NULL)
  198.     {
  199.         jdd_MemFree(temp_buffer_p);
  200.     }
  201.     if(path_p != NULL)
  202.     {
  203.         jdd_MemFree(path_p);
  204.     }
  205.     if(vFileSysHandle)
  206.     {
  207.         jdd_FSDeinitialize(vFileSysHandle);
  208.         vFileSysHandle = NULL;
  209.     }
  210.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "(%d): JMMS JSR Media Object returns with RetCode(%d) n", __LINE__, ret_code));
  211.     return (mmi_jmms_java_mms_error(ret_code));
  212. }
  213. /*****************************************************************************
  214.  * FUNCTION
  215.  *  mmi_jmms_jsr_delete_temp_media_files
  216.  * DESCRIPTION
  217.  *  Delete all the Temporary Media Files created while sending Java MMS
  218.  * PARAMETERS
  219.  *  void
  220.  * RETURNS
  221.  *  void
  222.  *****************************************************************************/
  223. void mmi_jmms_jsr_delete_temp_media_files(void)
  224. {
  225.     /*----------------------------------------------------------------*/
  226.     /* Local Variables                                                */
  227.     /*----------------------------------------------------------------*/
  228.     S32 i;
  229.     JC_CHAR *path_p = NULL;
  230.     JC_INT8 temp_file_path[40] = {0, };
  231.     JDD_FSHANDLE vFileSysHandle;
  232.     JC_RETCODE eRet;
  233.     /*----------------------------------------------------------------*/
  234.     /* Code Body                                                      */
  235.     /*----------------------------------------------------------------*/
  236.     eRet = jdd_FSInitialize(&vFileSysHandle);
  237.     if (JC_OK == eRet)
  238.     {
  239.         for (i = 1; i < media_obj_index; i++)
  240.         {
  241.             jc_sprintf(temp_file_path, "@mms\temp\~jsr_temp_file%d", i);
  242.             jdi_UtilsCharToTchar((JC_CHAR **) &(path_p), temp_file_path);
  243.             if(path_p)
  244.             {
  245.                 eRet = jdd_FSDelete(vFileSysHandle, path_p);
  246.                 PRINT_INFORMATION_2((MMI_TRACE_INFO, "JSR Media File(%d) Deleted with RetCode(%d):n", i, eRet));
  247.                 jdd_MemFree(path_p);
  248.                 path_p = NULL;
  249.             }
  250.         }
  251.         jdd_FSDeinitialize(vFileSysHandle);
  252.     }
  253.     media_obj_index = 1;
  254. }
  255. /*****************************************************************************
  256.  * FUNCTION
  257.  *  mmi_jmms_jsr_get_application_string_from_content_type
  258.  * DESCRIPTION
  259.  *  Returns the pointer to starting position of substring in source string
  260.  * PARAMETERS
  261.  *  contentType     [IN]
  262.  *  str_id          [IN]
  263.  * RETURNS
  264.  *  void
  265.  *****************************************************************************/
  266. S8* mmi_jmms_jsr_get_application_string_from_content_type(S8* contentType, jsr_string_id_enum str_id)
  267. {
  268.     S8* str_pos = NULL;
  269.     switch(str_id)
  270.     {
  271.         case JSR_APPLICATION_ID:
  272.             str_pos = strstr(contentType, "application-id");
  273.             if(str_pos == NULL)
  274.             {
  275.                 str_pos = strstr(contentType, "Application-ID");
  276.             }
  277.             break;
  278.         case JSR_REPLY_TO_APPLICATION_ID:
  279.             str_pos = strstr(contentType, "reply-to-application-id");
  280.             if(str_pos == NULL)
  281.             {
  282.                 str_pos = strstr(contentType, "Reply-To-Application-ID");
  283.             }
  284.             break;
  285.     }
  286.     return str_pos;
  287. }
  288. /*****************************************************************************
  289.  * FUNCTION
  290.  *  mmi_jmms_java_mms_set_content_type_params
  291.  * DESCRIPTION
  292.  *  
  293.  * PARAMETERS
  294.  *  resp                [?]     [?]
  295.  *  content_type        [?]     [?]
  296.  * RETURNS
  297.  *  void
  298.  *****************************************************************************/
  299. void mmi_jmms_java_mms_set_content_type_params(wap_mmc_recv_appmms_rsp_struct *resp, JC_INT8 *content_type)
  300. {
  301.     /*----------------------------------------------------------------*/
  302.     /* Local Variables                                                */
  303.     /*----------------------------------------------------------------*/
  304.     S8 *str_pos = NULL;
  305.     S8 *temp_str = NULL;
  306.     /*----------------------------------------------------------------*/
  307.     /* Code Body                                                      */
  308.     /*----------------------------------------------------------------*/
  309.     if ((str_pos = strstr(content_type, "start")) != NULL)
  310.     {
  311.         temp_str = str_pos;
  312.         str_pos = strstr(temp_str, "=");
  313.         temp_str = str_pos + 1;
  314.         str_pos = strstr(temp_str, ";");
  315.         if (str_pos == NULL)
  316.         {
  317.             resp->start_cnt_id_len = strlen(temp_str);
  318.         }
  319.         else
  320.         {
  321.             resp->start_cnt_id_len = strlen(temp_str) - strlen(str_pos);
  322.         }
  323.         if (resp->start_cnt_id_len > 99)
  324.         {
  325.             resp->start_cnt_id_len = 99;
  326.         }
  327.         memcpy(resp->start_cnt_id, temp_str, resp->start_cnt_id_len);
  328.     }
  329.     else
  330.     {
  331.         resp->start_cnt_id_len = 0;
  332.         memset(resp->start_cnt_id, 0, 100);
  333.     }
  334.     //TO DO need to discuss this.
  335.     //      if((str_pos = strstr(content_type, "Reply-To-Application-ID")) != NULL)
  336. //    if ((str_pos = strstr(content_type, "reply-to-application-id")) != NULL)
  337.     if ((str_pos = mmi_jmms_jsr_get_application_string_from_content_type(content_type, JSR_REPLY_TO_APPLICATION_ID)) != NULL)
  338.     {
  339.         temp_str = str_pos;
  340.         str_pos = strstr(temp_str, "=");
  341.         temp_str = str_pos + 1;
  342.         str_pos = strstr(temp_str, ";");
  343.         if (str_pos == NULL)
  344.         {
  345.             resp->reply_app_id_len = strlen(temp_str);
  346.         }
  347.         else
  348.         {
  349.             resp->reply_app_id_len = strlen(temp_str) - strlen(str_pos);
  350.         }
  351.         if (resp->reply_app_id_len > 99)
  352.         {
  353.             resp->reply_app_id_len = 99;
  354.         }
  355.         memcpy(resp->reply_app_id, temp_str, resp->reply_app_id_len);
  356.     }
  357.     else
  358.     {
  359.         resp->reply_app_id_len = 0;
  360.         memset(resp->reply_app_id, 0, 100);
  361.     }
  362. }
  363. /*****************************************************************************
  364.  * FUNCTION
  365.  *  mmi_jmms_jsr_get_message_details
  366.  * DESCRIPTION
  367.  *  
  368.  * PARAMETERS
  369.  *  msgId               [IN]        
  370.  *  recv_callback       [IN]        
  371.  *  buffer(?)           [IN](?)
  372.  *  resp            [?](?)(?)
  373.  *  buff_size       [?](?)(?)
  374.  * RETURNS
  375.  *  void
  376.  *****************************************************************************/
  377. void mmi_jmms_jsr_get_message_details(U32 msgId, MMI_JMMS_JSR_RETRIEVE_CALLBACK recv_callback)
  378. {
  379.     /*----------------------------------------------------------------*/
  380.     /* Local Variables                                                */
  381.     /*----------------------------------------------------------------*/
  382.     JC_RETCODE eRet = JC_OK;
  383.     JC_UINT32 uiNumObjects = 0;
  384.     //    EMM1MessageType eMM1MsgType = 0;
  385.     //    CONTENT_DATA EncapsulatedContent = {0, };
  386.     MESSAGE_LIST *list = NULL;
  387.     MESSAGE_LIST *list_node = NULL;
  388.     JC_INT32 index = 1;
  389.     U16 result = 0;
  390.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  391.     U8 count_msg = 0;
  392.     /*----------------------------------------------------------------*/
  393.     /* Code Body                                                      */
  394.     /*----------------------------------------------------------------*/
  395.     StoreRetFilter.uiStartIndex = 1;
  396.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  397.     eRet = mmi_mms_get_number_of_messages(MMI_JMMS_INBOX, &count_msg);
  398.     if (eRet != JC_OK)
  399.     {
  400.         result = JSR_RESULT_ERROR;
  401.         goto END;
  402.     }
  403.     while (count_msg != 0)
  404.     {
  405.         if (count_msg <= NUM_MSGS_IN_ONE_UNIT)  /* read 5 msgs at a time */
  406.         {
  407.             StoreRetFilter.uiNumMessage = count_msg;
  408.         }
  409.         else
  410.         {
  411.             StoreRetFilter.uiNumMessage = NUM_MSGS_IN_ONE_UNIT;
  412.         }
  413.         eRet = mmi_jmms_get_messages_list("Inbox", &list, &StoreRetFilter);
  414.         if (eRet != JC_OK || list == NULL)
  415.         {
  416.             result = JSR_RESULT_ERROR;
  417.             goto END;
  418.         }
  419.         list_node = list;
  420.         while (list_node != NULL)
  421.         {
  422.         #ifdef __MMI_UNIFIED_MESSAGE__
  423.             if ((list_node->uiExtraBytes & 0x00FFFFFF) == msgId)
  424.         #else 
  425.             if (list_node->uiExtraBytes == msgId)
  426.         #endif 
  427.             {
  428.                 break;
  429.             }
  430.             list_node = list_node->pNext;
  431.             index++;
  432.         }
  433.         mmi_jmms_free_messages_list();
  434.         list = NULL;
  435.         StoreRetFilter.uiStartIndex = StoreRetFilter.uiStartIndex + StoreRetFilter.uiNumMessage;
  436.         count_msg = count_msg - StoreRetFilter.uiNumMessage;
  437.     }
  438.     if (list_node == NULL)
  439.     {
  440.         result = JSR_RESULT_MESSAGE_ID_NOT_FOUND;
  441.         goto END;
  442.     }
  443.     if (g_jmms_context->pParseContent != NULL)
  444.     {
  445.         jdd_MemFree(g_jmms_context->pParseContent);
  446.         g_jmms_context->pParseContent = NULL;
  447.     }
  448.     if (g_jmms_context->pParseContent == NULL)
  449.     {
  450.         g_jmms_context->pParseContent = (CONTENT_DATA*) jdd_MemAlloc(sizeof(CONTENT_DATA), 1);
  451.     }
  452.     g_jmms_context->pParseContent->bIsStream = E_TRUE;
  453.     /* /core itself setting the file name and read callback */
  454.     eRet = mmi_jmms_get_message("Inbox", g_jmms_context->pParseContent, index);
  455.     if (eRet != JC_OK || g_jmms_context->pParseContent->pFileName == NULL)
  456.     {
  457.         result = JSR_RESULT_ERROR;
  458.         goto END;
  459.     }
  460.     if (g_jmms_context->hMM1 != NULL)
  461.     {
  462.         /*eRet = jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE);*/
  463.         /* Memory Leak Fix: jdi_MM1Cleanup is allocating memory for data chunk after freeing the context */
  464.         eRet = jdi_MM1DeInitialize(g_jmms_context->hMM1);
  465.         g_jmms_context->hMM1 = NULL;
  466.     }
  467.     eRet = jdi_MM1Initialize(&(g_jmms_context->hMM1));
  468.     if (eRet != JC_OK)
  469.     {
  470.         result = JSR_RESULT_ERROR;
  471.         goto END;
  472.     }
  473.     g_jmms_context->jsr_mms_receive_callback = recv_callback;
  474.     eRet = jdi_MM1Decode(g_jmms_context->hMM1, g_jmms_context->pParseContent, E_PARSE_HEADERS_MIMEPARTS, MsgCtrl_CreateStream, &uiNumObjects);  // TODO:: test it returns ok
  475.     if (eRet == JC_ERR_MMS_PARSE_PENDING)
  476.     {
  477.         mmi_jmms_MM1_decode_continue_start_timer(uiNumObjects, mmi_jmms_jsr_async_get_message_details_callback);
  478.         return;
  479.     }
  480.     mmi_jmms_jsr_async_get_message_details_callback(eRet);
  481.   END:
  482.     if (g_jmms_context->jsr_mms_receive_callback != NULL && result != 0)
  483.     {
  484.         wap_mmc_recv_appmms_rsp_struct *resp = NULL;
  485.         resp = (wap_mmc_recv_appmms_rsp_struct*) jdd_MemAlloc(sizeof(wap_mmc_recv_appmms_rsp_struct), 1);
  486.         if (resp != NULL)
  487.         {
  488.             resp->result = result;
  489.             g_jmms_context->jsr_mms_receive_callback(resp, NULL, 0);
  490.         }
  491.     }
  492.     if (g_jmms_context->pParseContent != NULL)
  493.     {
  494.         if (g_jmms_context->pParseContent->pFileName != NULL)
  495.         {
  496.             jdd_MemFree(g_jmms_context->pParseContent->pFileName);
  497.             g_jmms_context->pParseContent->pFileName = NULL;
  498.         }
  499.         jdd_MemFree(g_jmms_context->pParseContent);
  500.         g_jmms_context->pParseContent = NULL;
  501.     }
  502. }
  503. /*****************************************************************************
  504.  * FUNCTION
  505.  *  mmi_jmms_jsr_async_get_message_details_callback
  506.  * DESCRIPTION
  507.  *  
  508.  * PARAMETERS
  509.  *  eRet        [IN]        
  510.  * RETURNS
  511.  *  void
  512.  *****************************************************************************/
  513. void mmi_jmms_jsr_async_get_message_details_callback(JC_RETCODE eRet)
  514. {
  515.     /*----------------------------------------------------------------*/
  516.     /* Local Variables                                                */
  517.     /*----------------------------------------------------------------*/
  518.     EMM1MessageType eMM1MsgType = 0;
  519.     JC_UINT32 uiTempVal = 0;
  520.     EMM1MessagePriority eMM1MessagePriority = E_MSG_PRIORITY_NORMAL;
  521.     EMM1Charset eCharset = E_NONE;
  522.     JC_INT8 *content_type = NULL;
  523.     JC_CHAR *subject = NULL;
  524.     JC_UINT32 subject_len = 0;
  525.     MMS_ADDRESS_LIST *p_from_AddressList = NULL;
  526.     MMS_ADDRESS_LIST *p_to_AddressList = NULL;
  527.     MMS_ADDRESS_LIST *p_cc_AddressList = NULL;
  528.     U32 address_len = 0;
  529.     S8 *buf = NULL;
  530.     U16 datalen = 0;
  531.     U16 buf_size = 0;
  532.     wap_mmc_recv_appmms_rsp_struct *resp = NULL;
  533.     /*----------------------------------------------------------------*/
  534.     /* Code Body                                                      */
  535.     /*----------------------------------------------------------------*/
  536.     resp = (wap_mmc_recv_appmms_rsp_struct*) jdd_MemAlloc(sizeof(wap_mmc_recv_appmms_rsp_struct), 1);
  537.     if (resp == NULL)
  538.     {
  539.         goto END;
  540.     }
  541.     if (eRet != JC_OK)
  542.     {
  543.         resp->result = JSR_RESULT_ERROR;
  544.         goto END;
  545.     }
  546.     eRet = jdi_MM1GetMessageType(g_jmms_context->hMM1, &eMM1MsgType);
  547.     if (eRet != JC_OK)
  548.     {
  549.         resp->result = JSR_RESULT_ERROR;
  550.         goto END;
  551.     }
  552.     if (eMM1MsgType != E_MMS_RETRIEVE_CONFIRMATION_VALUE)
  553.     {
  554.         resp->result = JSR_RESULT_INVALID_MESSAGE;
  555.         goto END;
  556.     }
  557.     uiTempVal = jdi_MM1GetDate(g_jmms_context->hMM1);
  558.     if (uiTempVal)
  559.     {
  560.         resp->date = uiTempVal;
  561.     }
  562.     eRet = jdi_MM1GetPriority(g_jmms_context->hMM1, &eMM1MessagePriority);
  563.     if (eRet == JC_OK)
  564.     {
  565.         resp->priority = eMM1MessagePriority;
  566.     }
  567.     else
  568.     {
  569.         resp->priority = 1; /* /E_MSG_PRIORITY_NORMAL */
  570.     }
  571.     if (g_jmms_context->jsr_total_object > 0)
  572.     {
  573.         U8 count = 0;
  574.         MM1_CONTENT MM1Content = {0, };
  575.         for (count = 0; count < g_jmms_context->jsr_total_object; count++)
  576.         {
  577.             jdi_MM1GetContent(g_jmms_context->hMM1, &MM1Content, count);
  578.             if (jc_strstr(MM1Content.pszMimeType, "application/smil") != NULL)
  579.             {
  580.                 resp->bdy_part_no = (U8) g_jmms_context->jsr_total_object - 1;
  581.                 break;
  582.             }
  583.         }
  584.         if (count == g_jmms_context->jsr_total_object)
  585.         {
  586.             resp->bdy_part_no = (U8) g_jmms_context->jsr_total_object;
  587.         }
  588.     }
  589.     else
  590.     {
  591.         resp->bdy_part_no = (U8) g_jmms_context->jsr_total_object;
  592.     }
  593.     content_type = (JC_INT8*) jdi_MM1GetContentType(g_jmms_context->hMM1);
  594.     if (content_type == NULL)
  595.     {
  596.         resp->result = JSR_RESULT_ERROR;
  597.         goto END;
  598.     }
  599.     mmi_jmms_java_mms_set_content_type_params(resp, content_type);
  600.     eRet = jdi_MM1GetSubject(g_jmms_context->hMM1, &subject, &eCharset);
  601.     /* subject */
  602.     buf_size += 4;  /* subject_data_len 4bytes; */
  603.     if (subject)
  604.     {
  605.         buf_size += 4;  /* subject_encode_type 4bytes */
  606.         subject_len = mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) subject);
  607.         buf_size += subject_len;
  608.     }
  609.     /* from address  ///from address can be one only */
  610.     eRet = jdi_MM1GetFromAddress(g_jmms_context->hMM1, &p_from_AddressList);
  611.     if (eRet != JC_OK)
  612.     {
  613.         resp->result = JSR_RESULT_ERROR;
  614.         goto END;
  615.     }
  616.     resp->from_addr_no = 0;
  617.     if (p_from_AddressList != NULL && p_from_AddressList->pAddress != NULL)
  618.     {
  619.         resp->from_addr_no = 1;
  620.         address_len = pfnUnicodeStrlen((S8*) (p_from_AddressList->pAddress));
  621.         buf_size += (8 + address_len);
  622.     }
  623.     /* to address */
  624.     eRet = jdi_MM1GetToAddress(g_jmms_context->hMM1, &p_to_AddressList);
  625.     if (eRet != JC_OK)
  626.     {
  627.         resp->result = JSR_RESULT_ERROR;
  628.         goto END;
  629.     }
  630.     resp->to_addr_no = 0;
  631.     if (p_to_AddressList != NULL)
  632.     {
  633.         MMS_ADDRESS_LIST *to_list = p_to_AddressList;
  634.         while (to_list)
  635.         {
  636.             if (to_list->pAddress)
  637.             {
  638.                 resp->to_addr_no += 1;
  639.                 address_len = pfnUnicodeStrlen((S8*) (to_list->pAddress));
  640.                 buf_size += (8 + address_len);
  641.             }
  642.             to_list = to_list->pNext;
  643.         }
  644.     }
  645.     /* cc address */
  646.     eRet = jdi_MM1GetCCAddress(g_jmms_context->hMM1, &p_cc_AddressList);
  647.     if (eRet != JC_OK)
  648.     {
  649.         resp->result = JSR_RESULT_ERROR;
  650.         goto END;
  651.     }
  652.     resp->cc_addr_no = 0;
  653.     if (p_cc_AddressList != NULL)
  654.     {
  655.         MMS_ADDRESS_LIST *cc_list = p_cc_AddressList;
  656.         while (cc_list)
  657.         {
  658.             if (cc_list->pAddress)
  659.             {
  660.                 resp->cc_addr_no += 1;
  661.                 address_len = pfnUnicodeStrlen((S8*) (cc_list->pAddress));
  662.                 buf_size += (8 + address_len);
  663.             }
  664.             cc_list = cc_list->pNext;
  665.         }
  666.     }
  667.     buf = jdd_MemAlloc(sizeof(S8), buf_size);
  668.     if (buf == NULL)
  669.     {
  670.         resp->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  671.         goto END;
  672.     }
  673.     /* Pack subject */
  674.     if (subject)
  675.     {
  676.         S8 *temp_subject = NULL;
  677.         *(U32*) buf = subject_len;
  678.         *(U32*) (buf + 4) = MMI_JMMS_JSR_SUBJECT_ENCODED_VALUE;        /* /MMS_UTF8. Note::: Encoded value used is as given in mms_def.h file in Teleca. */
  679.         /* /TODO:: may need to confirm value */
  680.         temp_subject = jdd_MemAlloc(sizeof(S8), subject_len + 1);
  681.         if (temp_subject == NULL)
  682.         {
  683.             resp->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  684.             goto END;
  685.         }
  686.         mmi_chset_ucs2_to_utf8_string((U8*) temp_subject, (subject_len + 1), (U8*) subject);
  687.         memcpy(buf + 8, temp_subject, subject_len);
  688.         datalen += (8 + subject_len);
  689.         if (temp_subject != NULL)
  690.         {
  691.             jdd_MemFree(temp_subject);
  692.             temp_subject = NULL;
  693.         }
  694.     }
  695.     else
  696.     {
  697.         *(U32*) buf = 0;    /* subject_data_len=0 */
  698.         datalen += 4;
  699.     }
  700.     /* Pack from address field */
  701.     if (resp->from_addr_no == 1)
  702.     {
  703.         U32 temp_address_len = pfnUnicodeStrlen((S8*) (p_from_AddressList->pAddress));
  704.         U32 address_type;
  705.         S8 *temp_address = NULL;
  706.         address_type = mmi_jmms_java_map_address_type(p_from_AddressList->eAddressType);
  707.         memcpy((char*)(buf + datalen), &address_type, 4);
  708.         memcpy((char*)(buf + datalen + 4), &temp_address_len, 4);
  709.         temp_address = jdd_MemAlloc(sizeof(S8), temp_address_len + 1);
  710.         if (temp_address == NULL)
  711.         {
  712.             resp->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  713.             goto END;
  714.         }
  715.         UnicodeToAnsii(temp_address, (S8*) (p_from_AddressList->pAddress));
  716.         memcpy((char*)(buf + datalen + 8), temp_address, temp_address_len);
  717.         datalen += (8 + temp_address_len);
  718.         if (temp_address != NULL)
  719.         {
  720.             jdd_MemFree(temp_address);
  721.             temp_address = NULL;
  722.         }
  723.     }
  724.     /* /Pack to address field */
  725.     if (p_to_AddressList)
  726.     {
  727.         MMS_ADDRESS_LIST *to_list = p_to_AddressList;
  728.         while (to_list)
  729.         {
  730.             if (to_list->pAddress)
  731.             {
  732.                 U32 temp_address_len = pfnUnicodeStrlen((S8*) (to_list->pAddress));
  733.                 U32 address_type;
  734.                 S8 *temp_address = NULL;
  735.                 address_type = mmi_jmms_java_map_address_type(to_list->eAddressType);
  736.                 memcpy((char*)(buf + datalen), &address_type, 4);
  737.                 memcpy((char*)(buf + datalen + 4), &temp_address_len, 4);
  738.                 temp_address = jdd_MemAlloc(sizeof(S8), temp_address_len + 1);
  739.                 if (temp_address == NULL)
  740.                 {
  741.                     resp->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  742.                     goto END;
  743.                 }
  744.                 UnicodeToAnsii(temp_address, (S8*) (to_list->pAddress));
  745.                 memcpy((char*)(buf + datalen + 8), temp_address, temp_address_len);
  746.                 datalen += (8 + temp_address_len);
  747.                 if (temp_address != NULL)
  748.                 {
  749.                     jdd_MemFree(temp_address);
  750.                     temp_address = NULL;
  751.                 }
  752.             }
  753.             to_list = to_list->pNext;
  754.         }
  755.     }
  756.     /* Pack cc address field */
  757.     if (p_cc_AddressList)
  758.     {
  759.         MMS_ADDRESS_LIST *cc_list = p_cc_AddressList;
  760.         while (cc_list)
  761.         {
  762.             if (cc_list->pAddress)
  763.             {
  764.                 U32 temp_address_len = pfnUnicodeStrlen((S8*) (cc_list->pAddress));
  765.                 U32 address_type;
  766.                 S8 *temp_address = NULL;
  767.                 address_type = mmi_jmms_java_map_address_type(cc_list->eAddressType);
  768.                 memcpy((char*)(buf + datalen), &address_type, 4);
  769.                 memcpy((char*)(buf + datalen + 4), &temp_address_len, 4);
  770.                 temp_address = jdd_MemAlloc(sizeof(S8), temp_address_len + 1);
  771.                 if (temp_address == NULL)
  772.                 {
  773.                     resp->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  774.                     goto END;
  775.                 }
  776.                 UnicodeToAnsii(temp_address, (S8*) (cc_list->pAddress));
  777.                 memcpy((char*)(buf + datalen + 8), temp_address, temp_address_len);
  778.                 datalen += (8 + temp_address_len);
  779.                 if (temp_address != NULL)
  780.                 {
  781.                     jdd_MemFree(temp_address);
  782.                     temp_address = NULL;
  783.                 }
  784.             }
  785.             cc_list = cc_list->pNext;
  786.         }
  787.     }
  788.     resp->result = (U8) mmi_jmms_java_mms_error(JC_OK);
  789.   END:
  790.     if (g_jmms_context->jsr_mms_receive_callback != NULL)
  791.     {
  792.         if (resp != NULL)
  793.         {
  794.             g_jmms_context->jsr_mms_receive_callback(resp, buf, datalen);
  795.         }
  796.     }
  797.     if (g_jmms_context->pParseContent != NULL)
  798.     {
  799.         if (g_jmms_context->pParseContent->pFileName != NULL)
  800.         {
  801.             jdd_MemFree(g_jmms_context->pParseContent->pFileName);
  802.             g_jmms_context->pParseContent->pFileName = NULL;
  803.         }
  804.         jdd_MemFree(g_jmms_context->pParseContent);
  805.         g_jmms_context->pParseContent = NULL;
  806.     }
  807.     if (p_from_AddressList != NULL)
  808.     {
  809.         FreeAddressList(p_from_AddressList);
  810.     }
  811.     if (p_to_AddressList != NULL)
  812.     {
  813.         FreeAddressList(p_to_AddressList);
  814.     }
  815.     if (p_cc_AddressList != NULL)
  816.     {
  817.         FreeAddressList(p_cc_AddressList);
  818.     }
  819.     return;
  820. }
  821. /*****************************************************************************
  822.  * FUNCTION
  823.  *  mmi_jmms_java_map_address_type
  824.  * DESCRIPTION
  825.  *  
  826.  * PARAMETERS
  827.  *  type        [IN]        
  828.  * RETURNS
  829.  *  
  830.  *****************************************************************************/
  831. mmi_jmms_java_addresses_type mmi_jmms_java_map_address_type(MMSAddressTypes type)
  832. {
  833.     /*----------------------------------------------------------------*/
  834.     /* Local Variables                                                */
  835.     /*----------------------------------------------------------------*/
  836.     /*----------------------------------------------------------------*/
  837.     /* Code Body                                                      */
  838.     /*----------------------------------------------------------------*/
  839.     switch (type)
  840.     {
  841.         case E_PLMN:
  842.             return MMS_PLMN;
  843.         case E_IPV4:
  844.             return MMS_IPV4;
  845.         case E_MAIL:
  846.             return MMS_EMAIL;
  847.         case E_IPV6:
  848.         default:
  849.             return MMS_UNSUPPORTED;
  850.     }
  851.     return MMS_UNSUPPORTED;
  852. }
  853. /*****************************************************************************
  854.  * FUNCTION
  855.  *  mmi_jmms_jsr_generate_recv_msg_body_part
  856.  * DESCRIPTION
  857.  *  
  858.  * PARAMETERS
  859.  *  msgId               [IN]        
  860.  *  bdy_part_no         [?]         [?]
  861.  *  total_objects       [IN]        
  862.  *  response            [?]         [?]
  863.  * RETURNS
  864.  *  
  865.  *****************************************************************************/
  866. MMI_BOOL mmi_jmms_jsr_generate_recv_msg_body_part(
  867.             U32 msgId,
  868.             U8 *bdy_part_no,
  869.             U8 total_objects,
  870.             wap_mmc_read_appmms_msg_part_rsp_struct *response)
  871. {
  872.     /*----------------------------------------------------------------*/
  873.     /* Local Variables                                                */
  874.     /*----------------------------------------------------------------*/
  875.     MM1_CONTENT MM1Content = {0, };
  876.     MM1_HANDLE hMM1 = NULL;
  877.     JC_RETCODE eRet = JC_OK;
  878.     S8 *str_pos = NULL;
  879.     S8 *temp_str = NULL;
  880.     int read_handle = -1;
  881.     int write_handle = -1;
  882.     S8 *filename = NULL;
  883.     S8 *media_buffer_p = NULL;
  884.     int result = 0;
  885.     U32 bytes_written = 0;
  886.     S32 file_size = 0;
  887.     S32 buf_size = 0;
  888.     U8 part_no = 0;
  889.     /*----------------------------------------------------------------*/
  890.     /* Code Body                                                      */
  891.     /*----------------------------------------------------------------*/
  892.     part_no = (*bdy_part_no - 1);
  893.     if (g_jmms_context->hMM1 != NULL)
  894.     {
  895.         hMM1 = g_jmms_context->hMM1;
  896.     }
  897.     else
  898.     {
  899.         return FALSE;
  900.     }
  901.     eRet = jdi_MM1GetContent(hMM1, &MM1Content, part_no);
  902.     if (jc_strstr(MM1Content.pszMimeType, "application/smil") != NULL)
  903.     {
  904.         eRet = jdi_MM1GetContent(hMM1, &MM1Content, part_no + 1);
  905.         *bdy_part_no += 1;
  906.     }
  907.     response->result = JSR_RESULT_OK;
  908.     /* for content type: */
  909.     if ((str_pos = strstr((S8*) MM1Content.pszMimeType, ";")) != NULL)
  910.     {
  911.         response->content_type_len = str_pos - MM1Content.pszMimeType;
  912.     }
  913.     if (response->content_type_len > 255)
  914.     {
  915.         response->content_type_len = 255;
  916.     }
  917.     memset(response->content_type, 0, response->content_type_len + 1);
  918.     strncpy((S8*) response->content_type, (S8*) MM1Content.pszMimeType, (U8) response->content_type_len);     /* query */
  919.     /* For encoding scheme: */
  920.     temp_str = str_pos + 1;
  921.     if ((str_pos = strstr((S8*) temp_str, "Charset=utf-8")) != NULL)
  922.     {
  923.         response->encoding_scheme = MMS_UTF8;
  924.     }
  925.     else if ((str_pos = strstr((S8*) temp_str, "Charset=iso-8859-1")) != NULL)
  926.     {
  927.         response->encoding_scheme = MMS_ISO_8859_1;
  928.     }
  929.     else if ((str_pos = strstr((S8*) temp_str, "Charset=utf-16")) != NULL)
  930.     {
  931.         response->encoding_scheme = (U8) MMS_UTF16;
  932.     }
  933.     else if ((str_pos = strstr((S8*) temp_str, "Charset=us-ascii")) != NULL)
  934.     {
  935.         response->encoding_scheme = MMS_US_ASCII;
  936.     }
  937.     else
  938.     {
  939.         response->encoding_scheme = MMS_UNKNOWN_CHARSET;
  940.     }
  941.     /* for content id: */
  942.     response->content_id_len = strlen(MM1Content.pszContentID);
  943.     if (response->content_id_len < 100)
  944.     {
  945.         strcpy((S8*) response->content_id, (S8*) MM1Content.pszContentID);    /* query */
  946.     }
  947.     else
  948.     {
  949.         response->content_id_len = 99;
  950.         memset(response->content_id, 0, response->content_id_len + 1);
  951.         strncpy((S8*) response->content_id, (S8*) MM1Content.pszContentID, response->content_id_len); /* query */
  952.     }
  953.     /* for content location: */
  954.     response->content_location_len = strlen(MM1Content.pszObjectName);
  955.     if (response->content_location_len < 100)
  956.     {
  957.         strcpy((S8*) response->content_location, (S8*) MM1Content.pszObjectName);     /* query */
  958.     }
  959.     else
  960.     {
  961.         response->content_location_len = 99;
  962.         memset(response->content_location, 0, response->content_location_len + 1);
  963.         strncpy((S8*) response->content_location, (S8*) MM1Content.pszObjectName, response->content_location_len);    /* query */
  964.     }
  965.     /* for file path: */
  966.     if (MM1Content.MimeData.bIsStream == 1)
  967.     {
  968.         filename = (S8*) jdd_MemAlloc(sizeof(S8), 100);
  969.         if (NULL == filename)
  970.         {
  971.             response->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  972.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Insufficient Memory. n", __FILE__, __LINE__));
  973.             return FALSE;
  974.         }
  975.         AnsiiToUnicodeString((S8*) filename, (S8*) (JSR_MEDIA_OBJECT_FILE));
  976.         FS_Delete((U16*) filename);
  977.         write_handle = FS_Open((U16*) (filename), FS_CREATE_ALWAYS | FS_READ_WRITE);
  978.         if (write_handle < 0)
  979.         {
  980.             response->result = JSR_RESULT_FILE_OPERATION_ERROR;
  981.             jdd_MemFree(filename);
  982.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File Operation Error n", __FILE__, __LINE__));
  983.             return FALSE;
  984.         }
  985.         read_handle = FS_Open(MM1Content.MimeData.pFileName, FS_READ_ONLY);
  986.         if (read_handle < 0)
  987.         {
  988.             response->result = JSR_RESULT_FILE_OPERATION_ERROR;
  989.             jdd_MemFree(filename);
  990.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File Operation Error n", __FILE__, __LINE__));
  991.             return FALSE;
  992.         }
  993.         media_buffer_p = (S8*) jdd_MemAlloc(sizeof(S8), (512 + 1));
  994.         if (NULL == media_buffer_p)
  995.         {
  996.             response->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  997.             jdd_MemFree(filename);
  998.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Insufficient Memory n", __FILE__, __LINE__));
  999.             return FALSE;
  1000.         }
  1001.         FS_Seek(read_handle, MM1Content.MimeData.uiStartOffset, FS_FILE_BEGIN);
  1002.         file_size = MM1Content.MimeData.uiTotalSize;
  1003.         while (file_size)
  1004.         {
  1005.             if (file_size > 512)
  1006.             {
  1007.                 buf_size = 512;
  1008.             }
  1009.             else
  1010.             {
  1011.                 buf_size = file_size;
  1012.             }
  1013.             ASSERT(FS_Read(read_handle, media_buffer_p, buf_size, &bytes_written) == 0);
  1014.             result = FS_Write(write_handle, media_buffer_p, buf_size, &bytes_written);
  1015.             if (FS_NO_ERROR != result)
  1016.             {
  1017.                 response->result = JSR_RESULT_FILE_OPERATION_ERROR;
  1018.                 FS_Close(read_handle);
  1019.                 FS_Close(write_handle);
  1020.                 jdd_MemFree(filename);
  1021.                 jdd_MemFree(media_buffer_p);
  1022.                 PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File Operation Error n", __FILE__, __LINE__));
  1023.                 return FALSE;
  1024.             }
  1025.             file_size -= buf_size;
  1026.         }
  1027.         FS_Close(read_handle);
  1028.         FS_Close(write_handle);
  1029.         response->filepath_len = pfnUnicodeStrlen((S8*) filename);
  1030.         memset(response->filepath, 0, ((response->filepath_len + 1) * 2));
  1031.         pfnUnicodeStrcpy((S8*) response->filepath, (S8*) filename);
  1032.         jdd_MemFree(filename);
  1033.         jdd_MemFree(media_buffer_p);
  1034.     }
  1035.     else
  1036.     {
  1037.         if (g_jmms_context->jmms_fs_handle == NULL)
  1038.         {
  1039.             if (jdd_FSInitialize(&g_jmms_context->jmms_fs_handle) != JC_OK)
  1040.             {
  1041.                 eRet = JC_ERR_FILE_SYS_INIT;
  1042.                 PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File System Init Error n", __FILE__, __LINE__));
  1043.                 return FALSE;
  1044.             }
  1045.         }
  1046.         filename = (S8*) jdd_MemAlloc(sizeof(S8), 100);
  1047.         if (NULL == filename)
  1048.         {
  1049.             response->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  1050.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Insufficient Memory n", __FILE__, __LINE__));
  1051.             return FALSE;
  1052.         }
  1053.         AnsiiToUnicodeString((S8*) filename, (S8*) (JSR_MEDIA_OBJECT_FILE));
  1054.         FS_Delete((U16*) filename);
  1055.         write_handle = FS_Open((U16*) (filename), FS_CREATE_ALWAYS | FS_READ_WRITE);
  1056.         if (write_handle < 0)
  1057.         {
  1058.             response->result = JSR_RESULT_FILE_OPERATION_ERROR;
  1059.             jdd_MemFree(filename);
  1060.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File Operation Error n", __FILE__, __LINE__));
  1061.             return FALSE;
  1062.         }
  1063.         media_buffer_p = (S8*) jdd_MemAlloc(sizeof(S8), (512 + 1));
  1064.         if (NULL == media_buffer_p)
  1065.         {
  1066.             response->result = JSR_RESULT_INSUFFICIENT_MEMORY;
  1067.             jdd_MemFree(filename);
  1068.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR Insufficient Memory n", __FILE__, __LINE__));
  1069.             return FALSE;
  1070.         }
  1071.         if (MM1Content.MimeData.uiTotalSize > 0)
  1072.         {
  1073.             if ((response->encoding_scheme == MMS_US_ASCII) || (response->encoding_scheme == MMS_UTF8))
  1074.             {
  1075.                 response->encoding_scheme = MMS_UTF8;
  1076.                 buf_size = mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) MM1Content.MimeData.pBuffer);
  1077.                 mmi_chset_ucs2_to_utf8_string(
  1078.                     (U8*) media_buffer_p,
  1079.                     (buf_size + 1),
  1080.                     (U8*) MM1Content.MimeData.pBuffer);
  1081.                 result = FS_Write(write_handle, media_buffer_p, buf_size, &bytes_written);
  1082.             }
  1083.             else
  1084.             {
  1085.                 result = FS_Write(
  1086.                             write_handle,
  1087.                             MM1Content.MimeData.pBuffer,
  1088.                             MM1Content.MimeData.uiTotalSize,
  1089.                             &bytes_written);
  1090.             }
  1091.         }
  1092.         if (FS_NO_ERROR != result)
  1093.         {
  1094.             response->result = JSR_RESULT_FILE_OPERATION_ERROR;
  1095.             FS_Close(write_handle);
  1096.             jdd_MemFree(filename);
  1097.             PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d): JMMS JSR File Operation Error n", __FILE__, __LINE__));
  1098.             return FALSE;
  1099.         }
  1100.         FS_Close(write_handle);
  1101.         response->filepath_len = pfnUnicodeStrlen((S8*) filename);
  1102.         memset(response->filepath, 0, ((response->filepath_len + 1) * 2));
  1103.         pfnUnicodeStrcpy((S8*) response->filepath, (S8*) filename);
  1104.         jdd_MemFree(filename);
  1105.     }
  1106.     if (total_objects == *bdy_part_no)
  1107.     {
  1108.         /* jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE); */
  1109.         jdi_MM1DeInitialize(g_jmms_context->hMM1);
  1110.         g_jmms_context->hMM1 = NULL;
  1111.     }
  1112.     return TRUE;
  1113. }
  1114. /*****************************************************************************
  1115.  * FUNCTION
  1116.  *  mmi_jmms_check_msg_id
  1117.  * DESCRIPTION
  1118.  *  
  1119.  * PARAMETERS
  1120.  *  msgId       [IN]        
  1121.  * RETURNS
  1122.  *  
  1123.  *****************************************************************************/
  1124. MMI_BOOL mmi_jmms_check_msg_id(U32 msgId)
  1125. {
  1126.     /*----------------------------------------------------------------*/
  1127.     /* Local Variables                                                */
  1128.     /*----------------------------------------------------------------*/
  1129.     MESSAGE_LIST *pMessageList = NULL;
  1130.     MESSAGE_LIST *pTempMessageList = NULL;
  1131.     S8 fname[100];
  1132.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1133.     /*----------------------------------------------------------------*/
  1134.     /* Code Body                                                      */
  1135.     /*----------------------------------------------------------------*/
  1136.     memset(fname, 0, 100);
  1137.     mmi_jmms_get_folder_name_from_folderId(JSR_INBOX, fname);
  1138.     /* /manish chnging here 0n 2 Feb */
  1139.     StoreRetFilter.uiStartIndex = 1;
  1140.     StoreRetFilter.uiNumMessage = 0;
  1141.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1142.     mmi_jmms_get_messages_list((S8*) fname, &pMessageList, &StoreRetFilter);
  1143.     pTempMessageList = pMessageList;
  1144.     while (pTempMessageList)
  1145.     {
  1146.     #ifdef __MMI_UNIFIED_MESSAGE__
  1147.         if ((pTempMessageList->uiExtraBytes & 0x00FFFFFF) == msgId)
  1148.     #else 
  1149.         if (pTempMessageList->uiExtraBytes == msgId)
  1150.     #endif 
  1151.         {
  1152.             return TRUE;
  1153.         }
  1154.         pTempMessageList = pTempMessageList->pNext;
  1155.     }
  1156.     return FALSE;
  1157. }
  1158. /*****************************************************************************
  1159.  * FUNCTION
  1160.  *  mmi_jmms_update_folder
  1161.  * DESCRIPTION
  1162.  *  
  1163.  * PARAMETERS
  1164.  *  void
  1165.  * RETURNS
  1166.  *  void
  1167.  *****************************************************************************/
  1168. void mmi_jmms_update_folder(void)
  1169. {
  1170. #ifdef __MMI_UNIFIED_MESSAGE__
  1171.     mmi_um_jmms_refresh_ind();
  1172. #else /* __MMI_UNIFIED_MESSAGE__ */ 
  1173.     /*----------------------------------------------------------------*/
  1174.     /* Local Variables                                                */
  1175.     /*----------------------------------------------------------------*/
  1176.     U16 screen_id;
  1177.     S16 is_screen_update = 1;
  1178.     S8 *pFolderName = NULL;
  1179.     MESSAGE_LIST *pMessageList = NULL;
  1180.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1181.     /*----------------------------------------------------------------*/
  1182.     /* Code Body                                                      */
  1183.     /*----------------------------------------------------------------*/
  1184.     void (*entry_folder_screen_callback_hldr) (void) = NULL;
  1185.     StoreRetFilter.uiStartIndex = 1;
  1186.     StoreRetFilter.uiNumMessage = 0;
  1187.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1188.     screen_id = GetActiveScreenId();
  1189.     switch (screen_id)
  1190.     {
  1191.         case SCR_ID_JMMS_MAIN_MENU:
  1192.             break;
  1193.         case SCR_ID_JMMS_INBOX:
  1194.             pFolderName = (S8*) MMI_JMMS_INBOX;
  1195.             entry_folder_screen_callback_hldr = mmi_jmms_entry_inbox_screen;
  1196.             break;
  1197.         case SCR_ID_JMMS_OUTBOX:
  1198.             pFolderName = (S8*) MMI_JMMS_OUTBOX;
  1199.             entry_folder_screen_callback_hldr = mmi_jmms_entry_outbox_screen;
  1200.             break;
  1201.         case SCR_ID_JMMS_SENT:
  1202.             pFolderName = (S8*) MMI_JMMS_SENT;
  1203.             entry_folder_screen_callback_hldr = mmi_jmms_entry_sent_screen;
  1204.             break;
  1205.         case SCR_ID_JMMS_DRAFTS:
  1206.             pFolderName = (S8*) MMI_JMMS_DRAFTS;
  1207.             entry_folder_screen_callback_hldr = mmi_jmms_entry_drafts_screen;
  1208.             break;
  1209.         default:
  1210.             is_screen_update = 0;
  1211.             break;
  1212.     }
  1213.     if (is_screen_update == 0)
  1214.     {
  1215.         return;
  1216.     }
  1217.     if (pFolderName != NULL)
  1218.     {
  1219.         mmi_jmms_get_messages_list((S8*) pFolderName, &pMessageList, &StoreRetFilter);
  1220.         if (pMessageList == NULL)
  1221.         {
  1222.             GoBackToHistory(SCR_ID_JMMS_MAIN_MENU);
  1223.             return;
  1224.         }
  1225.         entry_folder_screen_callback_hldr();
  1226.     }
  1227.     else
  1228.     {
  1229.         mmi_jmms_entry_main_menu();
  1230.         DeleteNHistory(1);
  1231.     }
  1232. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1233. }
  1234. /*****************************************************************************
  1235.  * FUNCTION
  1236.  *  mmi_jmms_jsr_delete_msg
  1237.  * DESCRIPTION
  1238.  *  
  1239.  * PARAMETERS
  1240.  *  msgId       [IN]        
  1241.  * RETURNS
  1242.  *  void
  1243.  *****************************************************************************/
  1244. void mmi_jmms_jsr_delete_msg(U32 msgId)
  1245. {
  1246. mmi_jmms_delete_message_as_per_id(msgId);
  1247. }
  1248. /*****************************************************************************
  1249.  * FUNCTION
  1250.  *  mmi_jmms_jsr_send_mms
  1251.  * DESCRIPTION
  1252.  *  
  1253.  * PARAMETERS
  1254.  *  send_callback       [IN]        
  1255.  * RETURNS
  1256.  *  void
  1257.  *****************************************************************************/
  1258. void mmi_jmms_jsr_send_mms(MMI_JMMS_JSR_SEND_CALLBACK send_callback)
  1259. {
  1260.     /*----------------------------------------------------------------*/
  1261.     /* Local Variables                                                */
  1262.     /*----------------------------------------------------------------*/
  1263.     JC_RETCODE eRet = JC_OK;
  1264.     //    CONTENT_DATA EncapsulatedContent = {0, };
  1265.     //   COMM_FETCH_URL fetchUrlInfo = {0, };
  1266.     static U32 unique_value = 0;
  1267.     JC_INT8 Temp[50] = {0, };
  1268.     /*----------------------------------------------------------------*/
  1269.     /* Code Body                                                      */
  1270.     /*----------------------------------------------------------------*/
  1271.     /* PMT HIMANSHU START 20060425 */
  1272.     mmi_jmms_set_mms_downloading_busy();
  1273.     mmi_jmms_update_status_icon_indicator();
  1274.     /* PMT HIMANSHU END 20060425 */
  1275.     if (g_jmms_context->hMM1 == NULL)
  1276.     {
  1277.         (*send_callback) (mmi_jmms_java_mms_error(JC_ERR_MSG_INVALID_HANDLE));
  1278.         return;
  1279.     }
  1280.     if (g_jmms_context->pSendContent != NULL)
  1281.     {
  1282.         jdd_MemFree(g_jmms_context->pSendContent);
  1283.         g_jmms_context->pSendContent = NULL;
  1284.     }
  1285.     if (g_jmms_context->pSendContent == NULL)
  1286.     {
  1287.         g_jmms_context->pSendContent = (CONTENT_DATA*) jdd_MemAlloc(sizeof(CONTENT_DATA), 1);
  1288.     }
  1289.     g_jmms_context->pSendContent->bIsStream = E_TRUE;
  1290.     g_jmms_context->pSendContent->cbWriteCallback = mmi_jmms_write_callback;
  1291.     unique_value++;
  1292.     if (unique_value > 200000)
  1293.     {
  1294.         unique_value = 0;
  1295.     }
  1296.     jc_sprintf(Temp, "%s%d", "@mms\temp\jmms_tempJSendBuff", unique_value);
  1297.     jdi_UtilsCharToTchar((JC_CHAR **) & (g_jmms_context->pSendContent->pStream), Temp);
  1298.     if (g_jmms_context->jmms_fs_handle == NULL)
  1299.     {
  1300.         if (jdd_FSInitialize(&g_jmms_context->jmms_fs_handle) != JC_OK)
  1301.         {
  1302.             /* return JC_ERR_FILE_SYS_INIT; */
  1303.             (*send_callback) (JSR_RESULT_ERROR);
  1304.             return;
  1305.         }
  1306.     }
  1307.     jdd_FSDelete(g_jmms_context->jmms_fs_handle, g_jmms_context->pSendContent->pStream);
  1308.     if (g_jmms_context->jmms_fs_handle != NULL)
  1309.     {
  1310.         jdd_FSDeinitialize(g_jmms_context->jmms_fs_handle);
  1311.         g_jmms_context->jmms_fs_handle = NULL;
  1312.     }
  1313.     g_jmms_context->pSendContent->pFileName = g_jmms_context->pSendContent->pStream;
  1314.     g_jmms_context->jsr_mms_send_callback = send_callback;
  1315.     eRet = jdi_MM1GetEncodedStream(g_jmms_context->hMM1, g_jmms_context->pSendContent);
  1316.     if (eRet == JC_ERR_MMS_ENCODE_PENDING)
  1317.     {
  1318.         mmi_jmms_MM1_encode_continue_start_timer();
  1319.     }
  1320.     else
  1321.     {
  1322.         mmi_jmms_mm1_send_callback(eRet);
  1323.     }
  1324.     return;
  1325. }
  1326. /*****************************************************************************
  1327.  * FUNCTION
  1328.  *  mmi_jmms_mm1_send_callback
  1329.  * DESCRIPTION
  1330.  *  
  1331.  * PARAMETERS
  1332.  *  eRet        [IN]        
  1333.  * RETURNS
  1334.  *  void
  1335.  *****************************************************************************/
  1336. void mmi_jmms_mm1_send_callback(JC_RETCODE eRet)
  1337. {
  1338.     /*----------------------------------------------------------------*/
  1339.     /* Local Variables                                                */
  1340.     /*----------------------------------------------------------------*/
  1341.     U8 *temp = NULL;
  1342.     COMM_FETCH_URL fetchUrlInfo = {0, };
  1343.     JC_CHAR *fileptr = NULL;
  1344.     /*----------------------------------------------------------------*/
  1345.     /* Code Body                                                      */
  1346.     /*----------------------------------------------------------------*/
  1347.     if (JC_OK != eRet)
  1348.     {
  1349.         /*jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE);*/
  1350.         /* Memory Leak Fix: jdi_MM1Cleanup is allocating memory for data chunk after freeing the context */
  1351.         jdi_MM1DeInitialize(g_jmms_context->hMM1);
  1352.         g_jmms_context->hMM1 = NULL;
  1353.         goto END;
  1354.     }
  1355.     /*jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE);*/
  1356.     /* Memory Leak Fix: jdi_MM1Cleanup is allocating memory for data chunk after freeing the context */
  1357.     jdi_MM1DeInitialize(g_jmms_context->hMM1);
  1358.     g_jmms_context->hMM1 = NULL;
  1359.     fetchUrlInfo.eContentMode = E_COMM_BUFFER;
  1360.     temp = mmi_jmms_get_activated_mmsc_url(g_jmms_context);
  1361.     fetchUrlInfo.pszURL = (JC_CHAR*) temp;
  1362.     fetchUrlInfo.pszContentType = "application/vnd.wap.mms-message";
  1363.     if (g_jmms_context->pSendContent->bIsStream == E_FALSE)
  1364.     {
  1365.         fetchUrlInfo.bIsFile = E_FALSE;
  1366.         fetchUrlInfo.uUserDataMode.pucPostData = g_jmms_context->pSendContent->pBuffer;
  1367.     }
  1368.     else
  1369.     {
  1370.         fetchUrlInfo.bIsFile = E_TRUE;
  1371.         fetchUrlInfo.uUserDataMode.pmFileName = g_jmms_context->pSendContent->pFileName;
  1372.     }
  1373.     fetchUrlInfo.uiPostLen = g_jmms_context->pSendContent->uiTotalSize;
  1374.     fetchUrlInfo.pHeadersInfo = NULL;
  1375.     fetchUrlInfo.eCommFetchType = E_COMM_FETCH_POST;
  1376.     g_jmms_context->uiReferenceID = 0;
  1377.     eRet = jdi_CommunicationFetchURL(g_jmms_context->hCommHandle, &fetchUrlInfo, &(g_jmms_context->uiReferenceID));
  1378.     if (eRet == JC_OK)
  1379.     {
  1380.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d):n", "JMMS JSR Comm Fetch Send", g_jmms_context->uiReferenceID));
  1381.         fileptr = jdi_UtilsTcsDup(g_jmms_context->pSendContent->pFileName);
  1382.         eRet = mmi_jmms_add_comm_node(
  1383.                 g_jmms_context,
  1384.                 g_jmms_context->uiReferenceID,
  1385.                 E_TYPE_NEW_JAVA_MMS_SEND,
  1386.                 fileptr,
  1387.                 0,
  1388.                 1,
  1389.                 NULL);
  1390.         if (eRet != JC_OK)
  1391.         {
  1392.             eRet = jdi_CommunicationFreeReference(g_jmms_context->hCommHandle, g_jmms_context->uiReferenceID);
  1393.             g_jmms_context->uiReferenceID = 0;
  1394.             eRet = E_JMMS_GENERAL_ERROR;
  1395.             goto END;
  1396.         }
  1397.     }
  1398.     else
  1399.     {
  1400.         goto END;
  1401.     }
  1402.   END:
  1403.     if (eRet != JC_OK)
  1404.     {
  1405.         /* PMT VIKAS START 20060401 */
  1406.         mmi_jmms_reset_mms_downloading_busy();
  1407.         mmi_jmms_update_status_icon_indicator();
  1408.         /* PMT VIKAS END 20060401 */
  1409.         if (g_jmms_context->pSendContent != NULL && g_jmms_context->pSendContent->pStream != NULL)
  1410.         {
  1411.             if (g_jmms_context->jmms_fs_handle == NULL)
  1412.             {
  1413.                 if (jdd_FSInitialize(&g_jmms_context->jmms_fs_handle) != JC_OK)
  1414.                 {
  1415.                     /* return JC_ERR_FILE_SYS_INIT; */
  1416.                     g_jmms_context->jsr_mms_send_callback(JSR_RESULT_ERROR);
  1417.                     return;
  1418.                 }
  1419.             }
  1420.             jdd_FSDelete(g_jmms_context->jmms_fs_handle, g_jmms_context->pSendContent->pStream);
  1421.             if (g_jmms_context->jmms_fs_handle != NULL)
  1422.             {
  1423.                 jdd_FSDeinitialize(g_jmms_context->jmms_fs_handle);
  1424.                 g_jmms_context->jmms_fs_handle = NULL;
  1425.             }
  1426.         }
  1427.         if (fileptr != NULL)
  1428.         {
  1429.             jdd_MemFree(fileptr);
  1430.         }
  1431.         g_jmms_context->jsr_mms_send_callback(JSR_RESULT_ERROR);
  1432.         return;
  1433.     }
  1434.     if (g_jmms_context->pSendContent != NULL)
  1435.     {
  1436.         if (g_jmms_context->pSendContent->pStream != NULL)
  1437.         {
  1438.             jdd_MemFree(g_jmms_context->pSendContent->pStream);
  1439.             g_jmms_context->pSendContent->pStream = NULL;
  1440.         }
  1441.         jdd_MemFree(g_jmms_context->pSendContent);
  1442.         g_jmms_context->pSendContent = NULL;
  1443.     }
  1444.     return;
  1445. }
  1446. /*****************************************************************************
  1447.  * FUNCTION
  1448.  *  mmi_jmms_jsr_cancel_send_mms
  1449.  * DESCRIPTION
  1450.  *  
  1451.  * PARAMETERS
  1452.  *  msgId               [IN]        
  1453.  *  cancel_callback     [IN]        
  1454.  * RETURNS
  1455.  *  void
  1456.  *****************************************************************************/
  1457. void mmi_jmms_jsr_cancel_send_mms(U32 msgId, MMI_JMMS_JSR_SEND_CALLBACK cancel_callback)
  1458. {
  1459.     /*----------------------------------------------------------------*/
  1460.     /* Local Variables                                                */
  1461.     /*----------------------------------------------------------------*/
  1462.     JC_RETCODE eRet;
  1463.     /*----------------------------------------------------------------*/
  1464.     /* Code Body                                                      */
  1465.     /*----------------------------------------------------------------*/
  1466.     eRet = jdi_CommunicationStopReq(g_jmms_context->hCommHandle, g_jmms_context->uiReferenceID);
  1467.     if (eRet != JC_OK)
  1468.     {
  1469.         eRet = jdi_CommunicationFreeReference(g_jmms_context->hCommHandle, g_jmms_context->uiReferenceID);
  1470.         g_jmms_context->uiReferenceID = 0;
  1471.         (*cancel_callback) (JSR_RESULT_ERROR);
  1472.         return;
  1473.     }
  1474.     eRet = jdi_CommunicationFreeReference(g_jmms_context->hCommHandle, g_jmms_context->uiReferenceID);
  1475.     g_jmms_context->uiReferenceID = 0;
  1476.     g_jmms_context->jsr_mms_send_cancel_callback = cancel_callback;
  1477. }
  1478. /*****************************************************************************
  1479.  * FUNCTION
  1480.  *  mmi_jmms_get_content_type
  1481.  * DESCRIPTION
  1482.  *  
  1483.  * PARAMETERS
  1484.  *  pEncapsulatedContent        [?]         [?]
  1485.  *  mms_content_type            [IN]        
  1486.  * RETURNS
  1487.  *  
  1488.  *****************************************************************************/
  1489. JC_RETCODE mmi_jmms_get_content_type(CONTENT_DATA *pEncapsulatedContent, JC_INT8 **mms_content_type)
  1490. {
  1491.     /*----------------------------------------------------------------*/
  1492.     /* Local Variables                                                */
  1493.     /*----------------------------------------------------------------*/
  1494.     JC_RETCODE eRet = JC_OK;
  1495.     MM1_HANDLE hMM1 = NULL;
  1496.     CONTENT_DATA Decode;
  1497.     JC_UINT32 uiNumObjects = 0;
  1498.     EMM1MessageType eMM1MsgType = 0;
  1499.     JC_INT8 *content_type = NULL;
  1500.     U32 len = 0;
  1501.     JC_INT8 *temp_content_type = NULL;
  1502.     /*----------------------------------------------------------------*/
  1503.     /* Code Body                                                      */
  1504.     /*----------------------------------------------------------------*/
  1505.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "%s(%d) Enters mmi_jmms_get_content_type", __FILE__, __LINE__));
  1506.     eRet = jdi_MM1Initialize(&hMM1);
  1507.     if (eRet != JC_OK)
  1508.     {
  1509.         goto END;
  1510.     }
  1511.     jc_memset(&Decode, 0, sizeof(CONTENT_DATA));
  1512.     /* /for file streaming */
  1513.     Decode = *pEncapsulatedContent;
  1514.     eRet = jdi_MM1Decode(hMM1, &Decode, E_PARSE_HEADERS_ONLY, MsgCtrl_CreateStream, &uiNumObjects);     // TODO:: test it returns ok
  1515.     while (eRet == JC_ERR_MMS_PARSE_PENDING)
  1516.     {
  1517.         mmi_jmms_MM1_decode_continue_start_timer(uiNumObjects, NULL);
  1518.     }
  1519.     if (eRet != JC_OK)
  1520.     {
  1521.         eRet = JC_ERR_MEMORY_ALLOCATION;    /* eror type doesn't matter */
  1522.         goto END;
  1523.     }
  1524.     eRet = jdi_MM1GetMessageType(hMM1, &eMM1MsgType);
  1525.     if (eRet != JC_OK)
  1526.     {
  1527.         goto END;
  1528.     }
  1529.     if (eMM1MsgType != E_MMS_RETRIEVE_CONFIRMATION_VALUE)
  1530.     {
  1531.         eRet = E_JMMS_GENERAL_ERROR;    /* eror type doesn't matter */
  1532.         goto END;
  1533.     }
  1534.     content_type = (JC_INT8*) jdi_MM1GetContentType(hMM1);
  1535.     if (content_type == NULL)
  1536.     {
  1537.         eRet = E_JMMS_GENERAL_ERROR;
  1538.         goto END;
  1539.     }
  1540.     len = strlen((const char*)content_type);
  1541.     temp_content_type = (JC_INT8*) jdd_MemAlloc(sizeof(JC_INT8), len + 1);
  1542.     if (temp_content_type == NULL)
  1543.     {
  1544.         eRet = JC_ERR_MEMORY_ALLOCATION;
  1545.         goto END;
  1546.     }
  1547.     *mms_content_type = temp_content_type;
  1548.     strcpy((char*)temp_content_type, (const char*)content_type);
  1549.   END:
  1550.     jdi_MM1DeInitialize(hMM1);
  1551.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "(%d) Exits mmi_jmms_get_content_type with retcode %d", __LINE__, eRet));
  1552.     return eRet;
  1553. }
  1554. /*****************************************************************************
  1555.  * FUNCTION
  1556.  *  mmi_jmms_is_message_found
  1557.  * DESCRIPTION
  1558.  *  
  1559.  * PARAMETERS
  1560.  *  folderId        [IN]        
  1561.  *  msgId           [IN]        
  1562.  * RETURNS
  1563.  *  
  1564.  *****************************************************************************/
  1565. JC_RETCODE mmi_jmms_is_message_found(U8 folderId, U32 msgId)
  1566. {
  1567.     /*----------------------------------------------------------------*/
  1568.     /* Local Variables                                                */
  1569.     /*----------------------------------------------------------------*/
  1570.     MESSAGE_LIST *pMessageList = NULL;
  1571.     MESSAGE_LIST *pTempMessageList = NULL;
  1572.     S8 fname[100];
  1573.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  1574.     /*----------------------------------------------------------------*/
  1575.     /* Code Body                                                      */
  1576.     /*----------------------------------------------------------------*/
  1577.     memset(fname, 0, 100);
  1578.     mmi_jmms_get_folder_name_from_folderId(folderId, fname);
  1579.     StoreRetFilter.uiStartIndex = 1;
  1580.     StoreRetFilter.uiNumMessage = 0;
  1581.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  1582.     mmi_jmms_get_messages_list((S8*) fname, &pMessageList, &StoreRetFilter);
  1583.     pTempMessageList = pMessageList;
  1584.     while (pTempMessageList)
  1585.     {
  1586.     #ifdef __MMI_UNIFIED_MESSAGE__
  1587.         if ((pTempMessageList->uiExtraBytes & 0x00FFFFFF) == msgId)
  1588.     #else 
  1589.         if (pTempMessageList->uiExtraBytes == msgId)
  1590.     #endif 
  1591.         {
  1592.             return JC_OK;
  1593.         }
  1594.         pTempMessageList = pTempMessageList->pNext;
  1595.     }
  1596.     return JC_ERR_NOT_FOUND;
  1597. }
  1598. /*****************************************************************************
  1599.  * FUNCTION
  1600.  *  mmi_jmms_MM1_encode_continue_start_timer
  1601.  * DESCRIPTION
  1602.  *  
  1603.  * PARAMETERS
  1604.  *  void
  1605.  * RETURNS
  1606.  *  void
  1607.  *****************************************************************************/
  1608. void mmi_jmms_MM1_encode_continue_start_timer(void)
  1609. {
  1610.     /*----------------------------------------------------------------*/
  1611.     /* Local Variables                                                */
  1612.     /*----------------------------------------------------------------*/
  1613.     /*----------------------------------------------------------------*/
  1614.     /* Code Body                                                      */
  1615.     /*----------------------------------------------------------------*/
  1616.     StartTimer(JMMS_ASYNC_SEND_TIMER, JMMS_ASYNC_EVENT_TIME, mmi_jmms_mm1_encode_continue_callback);
  1617. }
  1618. /*****************************************************************************
  1619.  * FUNCTION
  1620.  *  mmi_jmms_mm1_encode_continue_callback
  1621.  * DESCRIPTION
  1622.  *  
  1623.  * PARAMETERS
  1624.  *  void
  1625.  * RETURNS
  1626.  *  void
  1627.  *****************************************************************************/
  1628. void mmi_jmms_mm1_encode_continue_callback(void)
  1629. {
  1630.     /*----------------------------------------------------------------*/
  1631.     /* Local Variables                                                */
  1632.     /*----------------------------------------------------------------*/
  1633.     JC_RETCODE eRet = JC_OK;
  1634.     /*----------------------------------------------------------------*/
  1635.     /* Code Body                                                      */
  1636.     /*----------------------------------------------------------------*/
  1637.     StopTimer(JMMS_ASYNC_SEND_TIMER);
  1638.     eRet = jdi_MM1EncodeNextPart(g_jmms_context->hMM1);
  1639.     if (eRet == JC_ERR_MMS_ENCODE_PENDING)
  1640.     {
  1641.         StartTimer(JMMS_ASYNC_SEND_TIMER, JMMS_ASYNC_EVENT_TIME, mmi_jmms_mm1_encode_continue_callback);
  1642.     }
  1643.     else
  1644.     {
  1645.         mmi_jmms_mm1_send_callback(eRet);
  1646.     }
  1647. }
  1648. /*****************************************************************************
  1649.  * FUNCTION
  1650.  *  mmi_jmms_MM1_decode_continue_start_timer
  1651.  * DESCRIPTION
  1652.  *  
  1653.  * PARAMETERS
  1654.  *  total_obj       [IN]        
  1655.  *  new_err_cb      [IN]        
  1656.  * RETURNS
  1657.  *  void
  1658.  *****************************************************************************/
  1659. void mmi_jmms_MM1_decode_continue_start_timer(JC_UINT32 total_obj, error_callback new_err_cb)
  1660. {
  1661.     /*----------------------------------------------------------------*/
  1662.     /* Local Variables                                                */
  1663.     /*----------------------------------------------------------------*/
  1664.     /*----------------------------------------------------------------*/
  1665.     /* Code Body                                                      */
  1666.     /*----------------------------------------------------------------*/
  1667.     g_jmms_context->async_parse_context.is_re_entrant=1;
  1668. StartTimer(JMMS_ASYNC_PARSE_TIMER, JMMS_ASYNC_EVENT_TIME, mmi_jmms_mm1_decode_continue_callback);
  1669.     g_jmms_context->jsr_total_object = total_obj;
  1670.     g_jmms_context->async_parse_context.callback = new_err_cb;
  1671. }
  1672. /*****************************************************************************
  1673.  * FUNCTION
  1674.  *  mmi_jmms_mm1_decode_continue_callback
  1675.  * DESCRIPTION
  1676.  *  
  1677.  * PARAMETERS
  1678.  *  void
  1679.  * RETURNS
  1680.  *  void
  1681.  *****************************************************************************/
  1682. void mmi_jmms_mm1_decode_continue_callback(void)
  1683. {
  1684.     /*----------------------------------------------------------------*/
  1685.     /* Local Variables                                                */
  1686.     /*----------------------------------------------------------------*/
  1687.     JC_RETCODE eRet = JC_OK;
  1688.     /*----------------------------------------------------------------*/
  1689.     /* Code Body                                                      */
  1690.     /*----------------------------------------------------------------*/
  1691.     StopTimer(JMMS_ASYNC_PARSE_TIMER);
  1692.     eRet = jdi_MM1DecodeNextPart(g_jmms_context->hMM1, &g_jmms_context->jsr_total_object);
  1693.     if (eRet == JC_ERR_MMS_PARSE_PENDING)
  1694.     {
  1695.         StartTimer(JMMS_ASYNC_PARSE_TIMER, JMMS_ASYNC_EVENT_TIME, mmi_jmms_mm1_decode_continue_callback);
  1696.     }
  1697.     else
  1698.     {
  1699.         mmi_jmms_parse_call_error_callback(eRet);
  1700.     }
  1701. }
  1702. /*****************************************************************************
  1703.  * FUNCTION
  1704.  *  mmi_jmms_get_attachment_filepath
  1705.  * DESCRIPTION
  1706.  *  This function is written to get the virtual file path, required during the
  1707.  *  installation of JAVA.
  1708.  * PARAMETERS
  1709.  *  filename        [IN]        
  1710.  *  msg             [OUT]       
  1711.  * RETURNS
  1712.  *  void
  1713.  *  
  1714.  *  Date       : July 19, 2006(?)
  1715.  *  Written By : RAJ KUMAR GUPTA(?)
  1716.  *****************************************************************************/
  1717. void mmi_jmms_get_attachment_filepath(S8 *filename, mms_get_attachment_rsp_struct *msg)
  1718. {
  1719.     /*----------------------------------------------------------------*/
  1720.     /* Local Variables                                                */
  1721.     /*----------------------------------------------------------------*/
  1722.     U8 media_count = 0;
  1723.     MEDIA_INFO *media_info;
  1724.     MEDIA_MIME_INFO *pMimeInfo = NULL;
  1725.     /*----------------------------------------------------------------*/
  1726.     /* Code Body                                                      */
  1727.     /*----------------------------------------------------------------*/
  1728.     msg->result = 0;
  1729.     /* Get the number of attachment with the MMS */
  1730.     mmi_jmms_jdi_get_media_count(g_jmms_context->msg_handle, 0, &media_count, E_TRUE);
  1731.     /* Atleast 2 files should be there that are .jar and .jad */
  1732.     if (media_count < 2)
  1733.     {
  1734.         return;
  1735.     }
  1736.     /* Get the MMS attachment information */
  1737.     if (mmi_jmms_compose_get_media_list(0, &media_info, &media_count, E_TRUE) == JMMS_COMP_OK)
  1738.     {
  1739.         U8 count = 0;
  1740.         for (count = 0; count < media_count; count++)
  1741.         {
  1742.             /* Check for the required file */
  1743.             if (pfnUnicodeStrcmp((S8*) filename, (S8*) media_info->pMimeInfo->MimeHeaders.pObjectName) == 0)
  1744.             {
  1745.                 /* File name matched. Set the result as 1. */
  1746.                 msg->result = 1;
  1747.                 break;
  1748.             }
  1749.             /* Move to the next attachment information node */
  1750.             media_info = media_info->pNext;
  1751.         }
  1752.         /* If the required file not found */
  1753.         if (msg->result == 0)
  1754.         {
  1755.             return;
  1756.         }
  1757.         /* Get the information of required attachment file. */
  1758.         pMimeInfo = media_info->pMimeInfo;
  1759.         /* Get the Virtual file name of the required attachment file. */
  1760.         pfnUnicodeStrcpy((kal_char*) msg->filepath, (kal_char*) pMimeInfo->ContentData.pFileName);
  1761.     }
  1762. }
  1763. #endif /* MMI_JMMS_JAVA_MMS_SUPPORT */ 
  1764. #endif /* (defined (JATAAYU_SUPPORT) && defined(MMS_SUPPORT)) */ 
  1765. #endif /* _MMI_JMMSJSRHANDLER_C */