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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2002
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *  jmms_jsr_handler.C
  15.  *
  16.  * Project:
  17.  * --------
  18.  *  MAUI
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  This file conains the store APIs for interacting with Jatayu Store module
  23.  *
  24.  * Author:
  25.  * -------
  26.  * -------
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * removed!
  33.  *
  34.  * removed!
  35.  * removed!
  36.  * removed!
  37.  *
  38.  * removed!
  39.  * removed!
  40.  * removed!
  41.  *
  42.  * removed!
  43.  * removed!
  44.  * removed!
  45.  *
  46.  * removed!
  47.  * removed!
  48.  * removed!
  49.  *
  50.  * removed!
  51.  * removed!
  52.  * removed!
  53.  *
  54.  * removed!
  55.  * removed!
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  * removed!
  63.  * removed!
  64.  * removed!
  65.  *
  66.  *------------------------------------------------------------------------------
  67.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  68.  *============================================================================
  69.  ****************************************************************************/
  70. #ifndef _MMI_JMMSJSRHANDLER_C
  71. #define _MMI_JMMSJSRHANDLER_C
  72. /***************************************************************************** 
  73. * Include
  74. *****************************************************************************/
  75. #include "MMI_features.h"
  76. #if (defined (JATAAYU_SUPPORT) && defined(MMS_SUPPORT))
  77. #include "JsrTypes.h"
  78. #include "JMMSJSRHandler.h"
  79. #include "PixtelDataTypes.h"
  80. #include "SettingProfile.h"
  81. #include "DebugInitDef.h"
  82. #include "FileManagerGProt.h"   /* file path util function */
  83. #include <ddl.h>
  84. #include <jcal.h>
  85. #include <jcalnet.h>
  86. #include "jdi_wspdatatype.h"
  87. #include "jdi_transport.h"
  88. #include "JMMSCoreAPI.h"
  89. /* jataayu files */
  90. #include "ddlbase.h"
  91. #include "jcutils.h"
  92. #include "ddlutils.h"
  93. #include "jdi_MMSErr.h"
  94. #include "jcerror.h"
  95. #include <jdi_communicator.h>
  96. #include <miscutils.h>
  97. #include <MM1DataTypes.h>
  98. #include <MessagingDatatypes.h>
  99. #include <MessagingAPI.h>
  100. #include "JMMSExdcl.h"
  101. #include "JMMSMainMMS.h"
  102. #include "JMMSProtocols.h"
  103. #include "JMMSMessageSettings.h"
  104. #include "JMMSMessageSettingsUtils.h"
  105. #include "JMMSConfig.h"
  106. #include "JMMSResEnum.h"
  107. #include "JMMSWriteMMS.h"
  108. #include "JMMSStoreHandling.h"
  109. #include "PrvMessagingDataTypes.h"
  110. #include "MM1Api.h"
  111. #include "Msg_Utils.h"
  112. #include "Msg_Presentation.h"
  113. #include "JMMSPushHandling.h"
  114. #include "JMMSCoreAPI.h"
  115. #include "JMMSDrafts.h"
  116. #include "JMMSExdcl.h"
  117. /* /#include "JMMSGdcl.h" */
  118. #include "JMMSCompose.h"
  119. #include "JMMSGprot.h"
  120. #include "JMMSInbox.h"
  121. #include "JMMSJSRHandler.h"
  122. #include "JMMSMainMMS.h"
  123. #include "JMMSMessageSettingsUtils.h"
  124. #include "JMMSOutbox.h"
  125. #include "JMMSProtocols.h"
  126. #include "JMMSPushHandling.h"
  127. #include "JMMSResEnum.h"
  128. #include "JMMSSent.h"
  129. #include "JMMSStoreHandling.h"
  130. #include "JMMSStructs.h"
  131. #include "JMMSTemplates.h"
  132. #include "JMMSUseDetails.h"
  133. #include "JMMSView.h"
  134. #include "JMMSWriteMMS.h"
  135. #include "TimerEvents.h"
  136. #include "wapadp.h"
  137. #include "JPushInboxCommonUI.h"
  138. #ifdef __MMI_UNIFIED_MESSAGE__
  139. #include "UnifiedMessageDef.h"
  140. #include "UnifiedMessageProt.h"
  141. #include "JMMSUMHandling.h"
  142. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  143. #ifdef MMI_JMMS_JAVA_MMS_SUPPORT
  144. /***************************************************************************** 
  145. * Define
  146. *****************************************************************************/
  147. /***************************************************************************** 
  148. * Typedef 
  149. *****************************************************************************/
  150. /***************************************************************************** 
  151. * Local Variable
  152. *****************************************************************************/
  153. static U32 media_obj_index = 1;
  154. /***************************************************************************** 
  155. * Local Function
  156. *****************************************************************************/
  157. /***************************************************************************** 
  158. * Global Variable
  159. *****************************************************************************/
  160. extern U64 g_jmms_normal_msgid;
  161. extern U64 g_jmms_java_msgid;
  162. /***************************************************************************** 
  163. * Global Function
  164. *****************************************************************************/
  165. JsrResult mmi_jmms_java_mms_error(JC_RETCODE error_code);
  166. mmi_jmms_java_addresses_type mmi_jmms_java_map_address_type(MMSAddressTypes type);
  167. extern int mmi_charset_ucs2_to_utf8_length_in_bytes(const kal_uint8 *raw);
  168. extern int mmi_charset_utf8_to_ucs2_length_in_bytes(const kal_uint8 *raw);
  169. extern kal_int32 mmi_chset_utf8_to_ucs2_string(kal_uint8 *dest, kal_int32 dest_size, kal_uint8 *src);
  170. extern kal_int32 mmi_chset_ucs2_to_utf8_string(kal_uint8 *dest, kal_int32 dest_size, kal_uint8 *src);
  171. extern JC_RETCODE mmi_jmms_jsr_form_send_request_pdu(MM1_HANDLE hMM1, MESSAGING_HANDLER *pMessaging);
  172. extern void mmi_jmms_entry_inbox_screen(void);
  173. extern void mmi_jmms_entry_outbox_screen(void);
  174. extern void mmi_jmms_entry_sent_screen(void);
  175. extern void mmi_jmms_entry_drafts_screen(void);
  176. extern U8 *mmi_jmms_get_activated_mmsc_url(jmms_context_struct *jmms_context);
  177. void mmi_jmms_MM1_decode_continue_start_timer(JC_UINT32 total_obj, error_callback new_err_cb);
  178. extern em_wap_user_agent_brand_enum wap_get_user_agent_brand(void);
  179. /* AT Command functions */
  180. /*****************************************************************************
  181.  * FUNCTION
  182.  *  mmi_jmms_get_folder_name_from_folderId
  183.  * DESCRIPTION
  184.  *  Find the name of Folder corresponding to Folder Id.
  185.  * PARAMETERS
  186.  *  folderId        [IN]        Id of folder
  187.  *  fname           [?]         [?]         Corresponding folder name
  188.  * RETURNS
  189.  *  void
  190.  *****************************************************************************/
  191. void mmi_jmms_get_folder_name_from_folderId(U8 folderId, S8 *fname)
  192. {
  193.     /*----------------------------------------------------------------*/
  194.     /* Local Variables                                                */
  195.     /*----------------------------------------------------------------*/
  196.     /*----------------------------------------------------------------*/
  197.     /* Code Body                                                      */
  198.     /*----------------------------------------------------------------*/
  199.     switch (folderId)
  200.     {
  201.         case JSR_INBOX:
  202.             strcpy((S8*) fname, (S8*) MMI_JMMS_INBOX);
  203.             break;
  204.         case JSR_OUTBOX:
  205.             strcpy((S8*) fname, (S8*) MMI_JMMS_OUTBOX);
  206.             break;
  207.         case JSR_SENT:
  208.             strcpy((S8*) fname, (S8*) MMI_JMMS_SENT);
  209.             break;
  210.         case JSR_DRAFTS:
  211.             strcpy((S8*) fname, (S8*) MMI_JMMS_DRAFTS);
  212.             break;
  213.         case JSR_TEMPLATES:
  214.             strcpy((S8*) fname, (S8*) MMI_JMMS_TEMPLATES);
  215.             break;
  216.     }
  217. }
  218. /*****************************************************************************
  219.  * FUNCTION
  220.  *  mmi_jmms_at_get_folder_info
  221.  * DESCRIPTION
  222.  *  Sets the folder information correponding to given Folder Id.
  223.  * PARAMETERS
  224.  *  folderId        [IN]        Id of Folder
  225.  *  folderInfo      [?]         [?]         Folder information
  226.  * RETURNS
  227.  *  void
  228.  *****************************************************************************/
  229. void mmi_jmms_at_get_folder_info(U8 folderId, JsrFolderInfo *folderInfo)
  230. {
  231.     /*----------------------------------------------------------------*/
  232.     /* Local Variables                                                */
  233.     /*----------------------------------------------------------------*/
  234.     FOLDER_INFO *pFolderInfo = NULL;
  235.     FOLDER_LIST *pFolderList = NULL;
  236.     U32 len = 0;
  237.     S8 *folder_name = NULL;
  238.     S8 fname[100];
  239.     JC_RETCODE eRet = JC_OK;
  240.     U8 numOfUnreadMsg = 0;
  241.     /*----------------------------------------------------------------*/
  242.     /* Code Body                                                      */
  243.     /*----------------------------------------------------------------*/
  244.     memset(fname, 0, 100);
  245.     mmi_jmms_get_folder_name_from_folderId(folderId, fname);
  246.     len = (strlen((PS8) fname) + 1) * ENCODING_LENGTH;
  247.     folder_name = (PS8) jdd_MemAlloc(len, sizeof(S8));
  248.     if (NULL == folder_name)
  249.     {
  250.         goto END;
  251.     }
  252.     AnsiiToUnicodeString((PS8) folder_name, (PS8) fname);
  253.     eRet = mmi_jmms_get_folder_list(&pFolderInfo);
  254.     if (eRet != JC_OK)
  255.     {
  256.         goto END;
  257.     }
  258.     pFolderList = pFolderInfo->pFolderList;
  259.     while (pFolderList)
  260.     {
  261.         if (pfnUnicodeStrcmp((S8*) pFolderList->pFolderName, (S8*) folder_name) == 0)
  262.         {
  263.             folderInfo->numOfMsg = pFolderList->uiTotalMessages;
  264.             //folderInfo->numOfUnreadMsg = (pFolderList->uiTotalMessages) - (pFolderList->uiTotalReadMessages);
  265.             if(strcmp((S8*)fname, (S8*) MMI_JMMS_INBOX) == 0)
  266.             {
  267.                 eRet = mmi_jmms_get_number_of_unread_messages_in_inbox(&numOfUnreadMsg);
  268.                 folderInfo->numOfUnreadMsg = numOfUnreadMsg;
  269.             }
  270.             else
  271.             {
  272.                 folderInfo->numOfUnreadMsg = 0;
  273.             }
  274.             break;
  275.         }
  276.         pFolderList = pFolderList->pNext;
  277.     }
  278. END:
  279.     if (folder_name != NULL)
  280.     {
  281.         jdd_MemFree(folder_name);
  282.         folder_name = NULL;
  283.     }
  284. }
  285. /*****************************************************************************
  286.  * FUNCTION
  287.  *  mmi_jmms_at_get_address_and_subject
  288.  * DESCRIPTION
  289.  *  Sets the folder information correponding to given Folder Id.
  290.  * PARAMETERS
  291.  *  list        [?]         [?]
  292.  *  index       [IN]        
  293.  *  address     [?]         [?]
  294.  *  subject     [?]         [?]
  295.  *  U8 folderId             Id of Folder(?)(?)
  296.  *  JsrFolderInfo* folderInfo  folder information(?)(?)
  297.  * RETURNS
  298.  *  void
  299.  *****************************************************************************/
  300. void mmi_jmms_at_get_address_and_subject(JsrMessageInfo *list, U32 index, S8 *address, S8 *subject)
  301. {
  302.     /*----------------------------------------------------------------*/
  303.     /* Local Variables                                                */
  304.     /*----------------------------------------------------------------*/
  305.     /*----------------------------------------------------------------*/
  306.     /* Code Body                                                      */
  307.     /*----------------------------------------------------------------*/
  308.     if (address != NULL)
  309.     {
  310.         if (strlen(address) > 39)
  311.         {
  312.             memcpy(list[index].address, address, 39);
  313.         }
  314.         else
  315.         {
  316.             strcpy((S8*) (list[index].address), (S8*) address);
  317.         }
  318.     }
  319.     if (subject != NULL)
  320.     {
  321.         if (strlen(subject) > 39)
  322.         {
  323.             memcpy(list[index].subject, subject, 39);
  324.         }
  325.         else
  326.         {
  327.             strcpy((S8*) (list[index].subject), (S8*) subject);
  328.         }
  329.     }
  330. }
  331. /*****************************************************************************
  332.  * FUNCTION
  333.  *  mmi_jmms_at_get_message_list
  334.  * DESCRIPTION
  335.  *  
  336.  * PARAMETERS
  337.  *  folderId        [IN]        
  338.  *  list            [?]         [?]
  339.  * RETURNS
  340.  *  void
  341.  *****************************************************************************/
  342. void mmi_jmms_at_get_message_list(U8 folderId, JsrMessageInfo *list)
  343. {
  344.     /*----------------------------------------------------------------*/
  345.     /* Local Variables                                                */
  346.     /*----------------------------------------------------------------*/
  347.     MESSAGE_LIST *pMessageList = NULL;
  348.     MESSAGE_LIST *pTempMessageList = NULL;
  349.     S8 fname[100];
  350.     U32 i = 0;
  351.     S32 msgType = -1;
  352.     U32 len = 0;
  353.     S8 *address = NULL;
  354.     S8 *subject = NULL;
  355.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  356.     /* for new phone suite */
  357.     U32 index = 1;
  358.     CONTENT_DATA Content = {0, };
  359.     JC_RETCODE eRet = JC_OK;
  360.     S8 *name_p = NULL;
  361.     S8 temp[40];
  362.     /*----------------------------------------------------------------*/
  363.     /* Code Body                                                      */
  364.     /*----------------------------------------------------------------*/
  365.     memset(fname, 0, 100);
  366.     mmi_jmms_get_folder_name_from_folderId(folderId, fname);
  367.     StoreRetFilter.uiStartIndex = 1;
  368.     StoreRetFilter.uiNumMessage = 0;
  369.     StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  370.     mmi_jmms_get_messages_list((S8*) fname, &pMessageList, &StoreRetFilter);
  371.     pTempMessageList = pMessageList;
  372.     while (pTempMessageList)
  373.     {
  374.         memset((S8*) & Content, 0, sizeof(CONTENT_DATA));
  375.     #ifdef __MMI_UNIFIED_MESSAGE__
  376.         list[i].msgId = pTempMessageList->uiExtraBytes & 0x00FFFFFF;
  377.     #else 
  378.         list[i].msgId = pTempMessageList->uiExtraBytes;
  379.     #endif 
  380.         //list[i].offset = 9; /* fixed 9 bytes */
  381.         list[i].offset = 0; /* fixed 0 bytes */
  382.         list[i].size = pTempMessageList->uiBufferLen;
  383.         msgType = pTempMessageList->pMessageHeaders->eMsgType;
  384.         /* for new phone suite */
  385.         Content.bIsStream = E_TRUE;
  386.         eRet = mmi_jmms_jdi_get_msg(g_jmms_context->hStoreHandle, index++, &Content);
  387.         memset(temp, 0, 40);
  388.         UnicodeToAnsii((S8*) temp, (S8*) Content.pFileName);
  389.         name_p = strrchr(temp, '\');
  390.         name_p++;
  391.         strcpy((S8*) list[i].filename, (S8*) name_p);
  392.         switch (msgType)
  393.         {
  394.             case E_MSG_TYPE_SEND:
  395.             {
  396.                 MESSAGE_SEND *pHeader = (MESSAGE_SEND*) pTempMessageList->pMessageHeaders->pHeaders;
  397.                 list[i].date = pHeader->uiDate;
  398.                 /* discussed with Manish for Templates. */
  399.                 if (0 == strcmp((S8*) fname, (S8*) MMI_JMMS_TEMPLATES))
  400.                 {
  401.                     /* list[i].fileType = JSR_SUFFIX_TEMPLATE; */
  402.                 }
  403.                 else
  404.                 {
  405.                     /* list[i].fileType = JSR_SUFFIX_SEND_REQ; */
  406.                 }
  407.                 if (pHeader->pFrom != NULL)
  408.                 {
  409.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pFrom)) + 1);
  410.                     address = jdd_MemAlloc(len, sizeof(U8));
  411.                     mmi_chset_ucs2_to_utf8_string((U8*) address, len, (U8*) pHeader->pFrom);
  412.                 }
  413.                 if (pHeader->pSubject != NULL)
  414.                 {
  415.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pSubject)) + 1);
  416.                     subject = jdd_MemAlloc(len, sizeof(U8));
  417.                     mmi_chset_ucs2_to_utf8_string((U8*) subject, len, (U8*) pHeader->pSubject);
  418.                 }
  419.                 mmi_jmms_at_get_address_and_subject(list, i, (S8*) address, (S8*) subject);
  420.             }
  421.                 break;
  422.             case E_MSG_TYPE_NOTIFICATION:
  423.             {
  424.                 MESSAGE_NOTIFICATION *pHeader = (MESSAGE_NOTIFICATION*) pTempMessageList->pMessageHeaders->pHeaders;
  425.                 list[i].date = 0;   /* date is not available in notification. */
  426.                 if (pHeader->pFrom != NULL)
  427.                 {
  428.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pFrom)) + 1);
  429.                     address = jdd_MemAlloc(len, sizeof(U8));
  430.                     mmi_chset_ucs2_to_utf8_string((U8*) address, len, (U8*) pHeader->pFrom);
  431.                 }
  432.                 if (pHeader->pSubject != NULL)
  433.                 {
  434.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pSubject)) + 1);
  435.                     subject = jdd_MemAlloc(len, sizeof(U8));
  436.                     mmi_chset_ucs2_to_utf8_string((U8*) subject, len, (U8*) pHeader->pSubject);
  437.                 }
  438.                 mmi_jmms_at_get_address_and_subject(list, i, (S8*) address, (S8*) subject);
  439.             }
  440.                 break;
  441.             case E_MSG_TYPE_DELIVERY_REPORT:
  442.             {
  443.                 DELIVERY_REPORT *pHeader = (DELIVERY_REPORT*) pTempMessageList->pMessageHeaders->pHeaders;
  444.                 list[i].date = pHeader->uiDate;
  445.                 /* delivery report doesn't have address and subject. */
  446.                 mmi_jmms_at_get_address_and_subject(list, i, NULL, NULL);
  447.             }
  448.                 break;
  449.             case E_MSG_TYPE_READ_REPORT:
  450.             {
  451.                 READ_REPORT *pHeader = (READ_REPORT*) pTempMessageList->pMessageHeaders->pHeaders;
  452.                 list[i].date = pHeader->uiDate;
  453.                 if (pHeader->pFrom != NULL)
  454.                 {
  455.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pFrom)) + 1);
  456.                     address = jdd_MemAlloc(len, sizeof(U8));
  457.                     mmi_chset_ucs2_to_utf8_string((U8*) address, len, (U8*) pHeader->pFrom);
  458.                 }
  459.                 /* read report doesn't have subject. */
  460.                 mmi_jmms_at_get_address_and_subject(list, i, (S8*) address, NULL);
  461.             }
  462.                 break;
  463.             case E_MSG_TYPE_RECEIVE:
  464.             {
  465.                 MESSAGE_RETRIEVAL *pHeader = (MESSAGE_RETRIEVAL*) pTempMessageList->pMessageHeaders->pHeaders;
  466.                 list[i].date = pHeader->uiDate;
  467.                 if (pHeader->pFrom != NULL)
  468.                 {
  469.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pFrom)) + 1);
  470.                     address = jdd_MemAlloc(len, sizeof(U8));
  471.                     mmi_chset_ucs2_to_utf8_string((U8*) address, len, (U8*) pHeader->pFrom);
  472.                 }
  473.                 if (pHeader->pSubject != NULL)
  474.                 {
  475.                     len = (mmi_charset_ucs2_to_utf8_length_in_bytes((U8*) (pHeader->pSubject)) + 1);
  476.                     subject = jdd_MemAlloc(len, sizeof(U8));
  477.                     mmi_chset_ucs2_to_utf8_string((U8*) subject, len, (U8*) pHeader->pSubject);
  478.                 }
  479.                 mmi_jmms_at_get_address_and_subject(list, i, (S8*) address, (S8*) subject);
  480.             }
  481.                 break;
  482.             default:
  483.                 break;
  484.         }
  485.         i++;
  486.         if (address != NULL)
  487.         {
  488.             jdd_MemFree(address);
  489.             address = NULL;
  490.         }
  491.         if (subject != NULL)
  492.         {
  493.             jdd_MemFree(subject);
  494.             subject = NULL;
  495.         }
  496.         if(Content.pFileName != NULL)
  497.         {
  498.             jdd_MemFree(Content.pFileName);
  499.             Content.pFileName = NULL;
  500.         }
  501.         pTempMessageList = pTempMessageList->pNext;
  502.     }
  503. }
  504. /*****************************************************************************
  505.  * FUNCTION
  506.  *  mmi_jmms_at_save_mms
  507.  * DESCRIPTION
  508.  *  
  509.  * PARAMETERS
  510.  *  fname       [?]     [?]
  511.  *  msgId       [?]     [?]
  512.  * RETURNS
  513.  *  
  514.  *****************************************************************************/
  515. JsrResult mmi_jmms_at_save_mms(char *fname, U32 *msgId)
  516. {
  517.     /*----------------------------------------------------------------*/
  518.     /* Local Variables                                                */
  519.     /*----------------------------------------------------------------*/
  520.     U32 filename_length = 0;
  521.     MSG_HANDLE hMsgHandle = NULL;
  522.     CONTENT_DATA EncapsulatedContent = {0, };
  523.     MESSAGE_HEADERS *MsgHeaders = NULL;
  524.     JC_RETCODE eRet = JC_OK;
  525.     JC_UINT32 msgIndex;
  526.     S8 folder_name[100];
  527.     JC_UINT32 uiFileLength = 0;
  528.     JDD_FILE hFile = NULL;
  529.     /*----------------------------------------------------------------*/
  530.     /* Code Body                                                      */
  531.     /*----------------------------------------------------------------*/
  532.     memset(folder_name, 0, 100);
  533.     mmi_jmms_get_folder_name_from_folderId(JSR_DRAFTS, folder_name);
  534.     /* fname is in ASCII */
  535.     filename_length = (strlen(fname) + 1) * ENCODING_LENGTH;
  536.     EncapsulatedContent.bIsStream = E_TRUE;
  537.     EncapsulatedContent.cbWriteCallback = NULL;
  538.     EncapsulatedContent.cbReadCallback = mmi_jmms_read_callback;
  539.     EncapsulatedContent.pStream = jdd_MemAlloc(sizeof(S8), filename_length);
  540.     AnsiiToUnicodeString(EncapsulatedContent.pStream, fname);
  541.     EncapsulatedContent.pFileName = EncapsulatedContent.pStream;
  542.     if (g_jmms_context->jmms_fs_handle == NULL)
  543.     {
  544.         if (jdd_FSInitialize(&g_jmms_context->jmms_fs_handle) != JC_OK)
  545.         {
  546.             eRet = JC_ERR_FILE_OPEN;
  547.             goto END;
  548.         }
  549.     }
  550.     hFile = jdd_FSOpen(g_jmms_context->jmms_fs_handle, (JC_CHAR*) EncapsulatedContent.pStream, E_OPEN_READ_MODE);
  551.     if (hFile == NULL)
  552.     {
  553.         eRet = JC_ERR_FILE_OPEN;
  554.         goto END;
  555.     }
  556.     eRet = jdd_FSGetSize(hFile, &uiFileLength);
  557.     if (JC_OK != eRet)
  558.     {
  559.         eRet = JC_ERR_FILE_OPEN;
  560.         goto END;
  561.     }
  562.     EncapsulatedContent.uiTotalSize = uiFileLength;
  563.     if (hFile != NULL)
  564.     {
  565.         jdd_FSClose(hFile);
  566.         hFile = NULL;
  567.     }
  568.     if (g_jmms_context->jmms_fs_handle != NULL)
  569.     {
  570.         jdd_FSDeinitialize(g_jmms_context->jmms_fs_handle);
  571.         g_jmms_context->jmms_fs_handle = NULL;
  572.     }
  573.     eRet = mmi_jmms_jdi_parse_msg_buffer(&hMsgHandle, &EncapsulatedContent, E_TYPE_MMS, E_FALSE);
  574.     /* Async changes start */
  575.     while (eRet == JC_ERR_MMS_PARSE_PENDING)
  576.     {
  577.         eRet = mmi_jmms_jdi_msg_parse_continue(hMsgHandle);
  578.     };
  579.     /* Async changes end */
  580.     if (JC_OK != eRet)
  581.     {
  582.         *msgId = 0;
  583.         if (hMsgHandle != NULL)
  584.         {
  585.             mmi_jmms_jdi_msg_deinit(hMsgHandle);
  586.             hMsgHandle = NULL;
  587.         }
  588.         goto END;
  589.     }
  590.     eRet = mmi_jmms_jdi_get_msg_headers(hMsgHandle, &MsgHeaders);
  591.     if (JC_OK != eRet)
  592.     {
  593.         *msgId = 0;
  594.         mmi_jmms_jdi_msg_deinit(hMsgHandle);
  595.         hMsgHandle = NULL;
  596.         goto END;
  597.     }
  598.     /* TO DO to be discussed. */
  599.     eRet = mmi_jmms_save_message_buffer_in_Store((S8*) folder_name, &msgIndex, MsgHeaders, &EncapsulatedContent, msgId);
  600.     if (JC_OK != eRet)
  601.     {
  602.         if (EncapsulatedContent.pStream != NULL)
  603.         {
  604.             if (g_jmms_context->jmms_fs_handle == NULL)
  605.             {
  606.                 if (jdd_FSInitialize(&g_jmms_context->jmms_fs_handle) != JC_OK)
  607.                 {
  608.                     eRet = JC_ERR_FILE_OPEN;
  609.                     goto END;
  610.                 }
  611.             }
  612.             jdd_FSDelete(g_jmms_context->jmms_fs_handle, EncapsulatedContent.pStream);
  613.             if (g_jmms_context->jmms_fs_handle != NULL)
  614.             {
  615.                 jdd_FSDeinitialize(g_jmms_context->jmms_fs_handle);
  616.                 g_jmms_context->jmms_fs_handle = NULL;
  617.             }
  618.         }
  619.     }
  620.   END:
  621.     if (EncapsulatedContent.pStream != NULL)
  622.     {
  623.         jdd_MemFree(EncapsulatedContent.pStream);
  624.         EncapsulatedContent.pStream = NULL;
  625.     }
  626.     if (hMsgHandle != NULL)
  627.     {
  628.         mmi_jmms_jdi_msg_deinit(hMsgHandle);
  629.         hMsgHandle = NULL;
  630.     }
  631.     return mmi_jmms_java_mms_error(eRet);
  632. }
  633. /*****************************************************************************
  634.  * FUNCTION
  635.  *  mmi_jmms_at_delete_mms
  636.  * DESCRIPTION
  637.  *  
  638.  * PARAMETERS
  639.  *  folderId                    [IN]        
  640.  *  msgId                       [IN]        
  641.  *  jmms_delete_callback        [IN]        
  642.  * RETURNS
  643.  *  void
  644.  *****************************************************************************/
  645. void mmi_jmms_at_delete_mms(U8 folderId, U32 msgId, void (*jmms_delete_callback) (JsrResult result))
  646. {
  647.     /*----------------------------------------------------------------*/
  648.     /* Local Variables                                                */
  649.     /*----------------------------------------------------------------*/
  650.     U32 msgIndex = 0;
  651.     S8 fname[100];
  652.     JC_RETCODE eRet = JC_OK;
  653.     RETRIEVE_FILTERS StoreRetFilter = {0, };
  654.     /*----------------------------------------------------------------*/
  655.     /* Code Body                                                      */
  656.     /*----------------------------------------------------------------*/
  657.     /* check if the MMS is open on phone. */
  658.     if (folderId == 0)
  659.     {
  660.         FOLDER_INFO *pFolderInfo = NULL;
  661.         FOLDER_LIST *pFolderList = NULL;
  662.         MESSAGE_LIST *pMessageList = NULL;
  663.         MESSAGE_LIST *pTempMessageList = NULL;
  664.         MMI_BOOL is_message_deleted = MMI_FALSE;
  665.         MMI_BOOL done = MMI_FALSE;
  666.         /* /manish ading here */
  667.         MMI_BOOL is_open = MMI_FALSE;
  668.         eRet = mmi_jmms_get_folder_list(&pFolderInfo);
  669.         if (eRet != JC_OK)
  670.         {
  671.             jmms_delete_callback(mmi_jmms_java_mms_error(eRet));
  672.             return;
  673.         }
  674.         pFolderList = pFolderInfo->pFolderList;
  675.         while (pFolderList)
  676.         {
  677.             memset(fname, 0, 100);
  678.             msgIndex = 0;
  679.             UnicodeToAnsii((S8*) fname, (S8*) pFolderList->pFolderName);
  680.             /* /manish chnging here 0n 2 Feb */
  681.             StoreRetFilter.uiStartIndex = 1;
  682.             StoreRetFilter.uiNumMessage = 0;
  683.             StoreRetFilter.eRetrieve = E_RETRIEVE_BY_INDEX;
  684.             mmi_jmms_get_messages_list((S8*) fname, &pMessageList, &StoreRetFilter);
  685.             pTempMessageList = pMessageList;
  686.             while (pTempMessageList)
  687.             {
  688.                 msgIndex++;
  689.             #ifdef __MMI_UNIFIED_MESSAGE__
  690.                 if ((pTempMessageList->uiExtraBytes & 0x00FFFFFF) == msgId)     /* msgId is stored in the extra bytes of message list. */
  691.             #else 
  692.                 if (pTempMessageList->uiExtraBytes == msgId)    /* msgId is stored in the extra bytes of message list. */
  693.             #endif 
  694.                 {
  695.                     is_message_deleted = MMI_TRUE;
  696.                     done = MMI_TRUE;
  697.                     is_open = mmi_jmms_is_msg_open((S8*) fname, msgId, msgIndex);
  698.                     if (is_open == MMI_FALSE)
  699.                     {
  700.                         eRet = mmi_jmms_delete_message(fname, msgIndex);
  701.                         if (eRet != JC_OK)
  702.                         {
  703.                             is_message_deleted = MMI_FALSE;
  704.                             break;
  705.                         }
  706.                         else
  707.                         {
  708.                             if (strcmp(fname, "Inbox") == 0)
  709.                             {
  710.                                 mmi_jmms_free_pending_node_if_present(msgIndex);
  711.                                 mmi_jmms_delete_msg_status((U8) (msgIndex - 1));
  712.                             }
  713.                             is_message_deleted = MMI_TRUE;
  714.                             break;
  715.                         }
  716.                     }
  717.                     else
  718.                     {
  719.                         is_message_deleted = MMI_FALSE;
  720.                         break;
  721.                     }
  722.                 }
  723.                 pTempMessageList = pTempMessageList->pNext;
  724.             }
  725.             if (done == MMI_TRUE)
  726.             {
  727.                 break;
  728.             }
  729.             pFolderList = pFolderList->pNext;
  730.         }
  731.         if (is_message_deleted == MMI_FALSE)
  732.         {
  733.             eRet = JC_ERR_STORE_INVALID_MSG_INDEX;
  734.         }
  735.     }
  736.     else
  737.     {
  738.         memset(fname, 0, 100);
  739.         mmi_jmms_get_folder_name_from_folderId((U8) folderId, (S8*) fname);
  740.         eRet = mmi_jmms_delete_all_message((S8*) fname);
  741.     }
  742.     /* Call the callback function */
  743.     jmms_delete_callback(mmi_jmms_java_mms_error(eRet));
  744. }
  745. /*****************************************************************************
  746.  * FUNCTION
  747.  *  mmi_jmms_is_msg_open
  748.  * DESCRIPTION
  749.  *  
  750.  * PARAMETERS
  751.  *  fname           [?]         [?]
  752.  *  msgId           [IN]        
  753.  *  msg_index       [IN]        
  754.  * RETURNS
  755.  *  
  756.  *****************************************************************************/
  757. MMI_BOOL mmi_jmms_is_msg_open(S8 *fname, U32 msgId, U32 msg_index)
  758. {
  759.     /*----------------------------------------------------------------*/
  760.     /* Local Variables                                                */
  761.     /*----------------------------------------------------------------*/
  762.     mmi_jmms_folder_name_enum folder_id;
  763.     MMI_BOOL is_open = MMI_FALSE;
  764.     /*----------------------------------------------------------------*/
  765.     /* Code Body                                                      */
  766.     /*----------------------------------------------------------------*/
  767.     if (strcmp(fname, "Inbox") == 0)
  768.     {
  769.         folder_id = E_JMMS_INBOX;
  770.     }
  771.     else if (strcmp(fname, "Outbox") == 0)
  772.     {
  773.         folder_id = E_JMMS_OUTBOX;
  774.     }
  775.     else if (strcmp(fname, "Drafts") == 0)
  776.     {
  777.         folder_id = E_JMMS_DRAFTS;
  778.     }
  779.     else if (strcmp(fname, "Sent") == 0)
  780.     {
  781.         folder_id = E_JMMS_SENT;
  782.     }
  783.     else
  784.     {
  785.         return is_open;
  786.     }
  787.     if ((g_jmms_context->msg_open_status[0] == folder_id
  788.          && g_jmms_context->msg_open_status[1] == (U32) (msgId))
  789.         || (g_jmms_context->msg_open_status[0] == folder_id && g_jmms_context->msg_open_status[1] == 0))
  790.     {
  791.         is_open = MMI_TRUE;
  792.         return is_open;
  793.     }
  794.     if (folder_id == E_JMMS_INBOX)
  795.     {
  796.         if (GetActiveScreenId() == SCR_ID_JMMS_NEW_MMS_IND)
  797.         {
  798.             if (g_jmms_context->pending_mms_info_list != NULL)
  799.             {
  800.                 if (g_jmms_context->pending_mms_info_list->Index == msg_index)
  801.                 {
  802.                     is_open = MMI_TRUE;
  803.                 }
  804.             }
  805.         }
  806.     }
  807.     return is_open;
  808. }
  809. /*****************************************************************************
  810.  * FUNCTION
  811.  *  mmi_jmms_free_pending_node_if_present
  812.  * DESCRIPTION
  813.  *  
  814.  * PARAMETERS
  815.  *  msg_index       [IN]        
  816.  * RETURNS
  817.  *  void
  818.  *****************************************************************************/
  819. void mmi_jmms_free_pending_node_if_present(U32 msg_index)
  820. {
  821.     /*----------------------------------------------------------------*/
  822.     /* Local Variables                                                */
  823.     /*----------------------------------------------------------------*/
  824.     jmms_pending_mms_info_struct *node = NULL;
  825.     jmms_pending_mms_info_struct *pre_node = NULL;
  826.     U8 type;
  827.     JC_INT32 index = 0;
  828.     U8 delivery_report_index = 0, read_report_index = 0;
  829.     /*----------------------------------------------------------------*/
  830.     /* Code Body                                                      */
  831.     /*----------------------------------------------------------------*/
  832.     if (g_jmms_context->pending_mms_info_list == NULL)
  833.     {
  834.         return;
  835.     }
  836.     node = g_jmms_context->pending_mms_info_list;
  837.     pre_node = node;
  838.     while (node != NULL)
  839.     {
  840.         index = (JC_INT32) (node->Index);
  841.         type = node->type;
  842.         if (type == E_MSG_TYPE_DELIVERY_REPORT)
  843.         {
  844.             delivery_report_index++;
  845.         }
  846.         else if (type == E_MSG_TYPE_READ_REPORT_RESPONSE)
  847.         {
  848.             read_report_index++;
  849.         }
  850.         if (index == msg_index)
  851.         {
  852.             break;
  853.         }
  854.         pre_node = node;
  855.         node = node->next;
  856.     }
  857.     if (node == NULL)
  858.     {
  859.         return;
  860.     }
  861.     if (pre_node == node)
  862.     {
  863.         g_jmms_context->pending_mms_info_list = node->next;
  864.     }
  865.     else
  866.     {
  867.         pre_node->next = node->next;
  868.     }
  869.     if (node->mms_url != NULL)
  870.     {
  871.         jdd_MemFree(node->mms_url);
  872.     }
  873.     jdd_MemFree(node);
  874.     node = NULL;
  875.     if (type == E_MSG_TYPE_NOTIFICATION || type == E_MSG_TYPE_RECEIVE)
  876.     {
  877.         return;
  878.     }
  879.     switch (type)
  880.     {
  881.         case E_MSG_TYPE_DELIVERY_REPORT:
  882.         {
  883.             jmms_pending_mms_delivery_reports_struct *node1 = NULL;
  884.             jmms_pending_mms_delivery_reports_struct *pre_node1 = NULL;
  885.             node1 = g_jmms_context->pending_delivery_reports;
  886.             if (g_jmms_context->pending_delivery_reports == NULL || delivery_report_index == 0)
  887.             {
  888.                 return;
  889.             }
  890.             else
  891.             {
  892.                 pre_node1 = node1;
  893.                 delivery_report_index--;
  894.                 while (delivery_report_index != 0 && node1 != NULL)
  895.                 {
  896.                     pre_node1 = node1;
  897.                     node1 = node1->next;
  898.                     delivery_report_index--;
  899.                 }
  900.                 if (node1 == NULL)
  901.                 {
  902.                     return;
  903.                 }
  904.                 if (pre_node1 == node1)
  905.                 {
  906.                     g_jmms_context->pending_delivery_reports = node1->next;
  907.                 }
  908.                 else
  909.                 {
  910.                     pre_node1->next = node1->next;
  911.                 }
  912.                 if (node1->to_p != NULL)
  913.                 {
  914.                     jdd_MemFree(node1->to_p);
  915.                 }
  916.                 jdd_MemFree(node1);
  917.                 node1 = NULL;
  918.             }
  919.             return;
  920.         }
  921.         case E_MSG_TYPE_READ_REPORT_RESPONSE:
  922.         {
  923.             jmms_pending_mms_read_reports_struct *node1 = NULL;
  924.             jmms_pending_mms_read_reports_struct *pre_node1 = NULL;
  925.             node1 = g_jmms_context->pending_read_reports;
  926.             if (g_jmms_context->pending_read_reports == NULL || read_report_index == 0)
  927.             {
  928.                 return;
  929.             }
  930.             else
  931.             {
  932.                 pre_node1 = node1;
  933.                 read_report_index--;
  934.                 while (read_report_index != 0 && node1 != NULL)
  935.                 {
  936.                     pre_node1 = node1;
  937.                     node1 = node1->next;
  938.                     read_report_index--;
  939.                 }
  940.                 if (node1 == NULL)
  941.                 {
  942.                     return;
  943.                 }
  944.                 if (pre_node1 == node1)
  945.                 {
  946.                     g_jmms_context->pending_read_reports = node1->next;
  947.                 }
  948.                 else
  949.                 {
  950.                     pre_node1->next = node1->next;
  951.                 }
  952.                 if (node1->from_p != NULL)
  953.                 {
  954.                     jdd_MemFree(node1->from_p);
  955.                 }
  956.                 jdd_MemFree(node1);
  957.                 node1 = NULL;
  958.             }
  959.             return;
  960.         }
  961.     }   /* /switch(type) */
  962. }
  963. /* /java functions */
  964. /*****************************************************************************
  965.  * FUNCTION
  966.  *  mmi_jmms_jsr_create_mms
  967.  * DESCRIPTION
  968.  *  
  969.  * PARAMETERS
  970.  *  message     [?]     [?]
  971.  *  buffer      [?]     [?]
  972.  * RETURNS
  973.  *  
  974.  *****************************************************************************/
  975. JsrResult mmi_jmms_jsr_create_mms(wap_mmc_send_appmms_req_struct *message, U8 *buffer)
  976. {
  977.     /*----------------------------------------------------------------*/
  978.     /* Local Variables                                                */
  979.     /*----------------------------------------------------------------*/
  980.     U16 datalen = 0;
  981.     JC_RETCODE eRet = JC_OK;
  982.     MESSAGE_SEND *pMessageSend = NULL;
  983.     MESSAGE_HEADERS *pMsgHeaders = NULL;
  984.     MSG_HANDLE hMsgHandle = NULL;
  985.     MM1_HDR_PARAM *pContentTypeParams = NULL;   /* For content type */
  986.     MM1_HDR_PARAM *pTempContentTypeParams = NULL;
  987.     MM1_HDR_PARAM *node = NULL;
  988.     S8 *address = NULL;
  989.     S8 *temp_address = NULL;
  990.     /*----------------------------------------------------------------*/
  991.     /* Code Body                                                      */
  992.     /*----------------------------------------------------------------*/
  993.     mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  994.     eRet = mmi_jmms_jdi_msg_init(&hMsgHandle, NULL);
  995.     if (JC_OK != eRet)
  996.     {
  997.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  998.         goto END;
  999.     }
  1000.     eRet = mmi_jmms_jdi_set_msg_type(hMsgHandle, E_TYPE_MMS);
  1001.     if (JC_OK != eRet)
  1002.     {
  1003.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1004.         goto END;
  1005.     }
  1006.     if (message->mms_type == 0)
  1007.     {
  1008.         eRet = mmi_jmms_jdi_set_presentation_type(hMsgHandle, E_PRESENTATION_SMIL);
  1009.     }
  1010.     else if (message->mms_type == 1)
  1011.     {
  1012.         eRet = mmi_jmms_jdi_set_presentation_type(hMsgHandle, E_PRESENTATION_NONE);
  1013.     }
  1014.     if (JC_OK != eRet)
  1015.     {
  1016.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1017.         goto END;
  1018.     }
  1019.     g_jmms_context->MsgHeaders_p = (MESSAGE_HEADERS*) jdd_MemAlloc(sizeof(MESSAGE_HEADERS), 1);
  1020.     if (NULL == g_jmms_context->MsgHeaders_p)
  1021.     {
  1022.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1023.         eRet = JC_ERR_MEMORY_ALLOCATION;
  1024.         goto END;
  1025.     }
  1026.     g_jmms_context->MsgHeader_type_p = (MESSAGE_SEND*) jdd_MemAlloc(sizeof(MESSAGE_SEND), 1);
  1027.     if (NULL == g_jmms_context->MsgHeader_type_p)
  1028.     {
  1029.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1030.         eRet = JC_ERR_MEMORY_ALLOCATION;
  1031.         goto END;
  1032.     }
  1033.     pMsgHeaders = g_jmms_context->MsgHeaders_p;
  1034.     pMessageSend = g_jmms_context->MsgHeader_type_p;
  1035.     eRet = mmi_jmms_set_mmsc_version();
  1036.     if (eRet != JC_OK)
  1037.     {
  1038.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1039.         goto END;
  1040.     }
  1041.     pMessageSend->pVersion = (JC_INT8*) g_jmms_context->version;
  1042.     if (wap_get_user_agent_brand() != EM_WAP_USERAGENT_BRAND_SE)
  1043.     {
  1044.         pMessageSend->uiExpiryTime = MAX_VALIDITY_PERIOD_VALUE;
  1045.     }
  1046.     else
  1047.     {
  1048.         pMessageSend->uiExpiryTime = 0;
  1049.         pMessageSend->uiDate = get_current_utc_time();
  1050.     }
  1051.     /* PMT HIMANSHU START 20060425 */
  1052.     /* For fixing the date & time issue */
  1053.     if (message->delivery_time > 604800)
  1054.     {
  1055.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1056.         eRet = E_JMMS_GENERAL_ERROR;
  1057.         goto END;
  1058.     }
  1059.     /* PMT HIMANSHU END 20060425 */
  1060.     pMessageSend->uiDeliveryTime = message->delivery_time;
  1061.     pMessageSend->eMsgPriority = (message->priority) + 1;
  1062.     pMessageSend->bDeliveryReport = E_FALSE;
  1063.     pMessageSend->bReadReport = E_FALSE;
  1064.     pMessageSend->bHideSender = E_FALSE;
  1065.     pMessageSend->bExpiryAbs = E_FALSE;
  1066.     pMessageSend->bDeliveryAbs = E_FALSE;
  1067.     mmi_jmms_free_addresses_list();
  1068.     if (buffer != NULL)
  1069.     {
  1070.         /* Retrieve Subject */
  1071.         {
  1072.             S8 *subject = NULL;
  1073.             U32 subject_len_ucs2 = 0;
  1074.             U32 subject_len = *(U32*) buffer;
  1075.             if (subject_len > 0)
  1076.             {
  1077.                 subject = (S8*) jdd_MemAlloc(sizeof(S8), subject_len + 1);
  1078.                 if (NULL == subject)
  1079.                 {
  1080.                     mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1081.                     eRet = JC_ERR_MEMORY_ALLOCATION;
  1082.                     goto END;
  1083.                 }
  1084.                 memcpy(subject, buffer + 8, subject_len);
  1085.                 datalen = subject_len + 8;
  1086.                 subject_len_ucs2 = mmi_charset_utf8_to_ucs2_length_in_bytes((U8*) subject);
  1087.                 g_jmms_context->subject = (S8*) jdd_MemAlloc(sizeof(S8), (subject_len_ucs2 + ENCODING_LENGTH));
  1088.                 if (g_jmms_context->subject == NULL)
  1089.                 {
  1090.                     mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1091.                     if (subject != NULL)
  1092.                     {
  1093.                         jdd_MemFree(subject);
  1094.                         subject = NULL;
  1095.                     }
  1096.                     eRet = JC_ERR_MEMORY_ALLOCATION;
  1097.                     goto END;
  1098.                 }
  1099.                 mmi_chset_utf8_to_ucs2_string(
  1100.                     (U8*) g_jmms_context->subject,
  1101.                     (subject_len_ucs2 + ENCODING_LENGTH),
  1102.                     (U8*) subject);
  1103.                 pMessageSend->pSubject = (JC_CHAR*) g_jmms_context->subject;
  1104.                 if (subject != NULL)
  1105.                 {
  1106.                     jdd_MemFree(subject);
  1107.                     subject = NULL;
  1108.                 }
  1109.             }
  1110.             else
  1111.             {
  1112.                 datalen = 4;
  1113.             }
  1114.         }
  1115.         /* Retrieve to addresses */
  1116.         while (message->to_addr_no > 0)
  1117.         {
  1118.             U32 address_len = 0;
  1119.             U32 addrType = 0;
  1120.             U8 ret = 0;
  1121.             memcpy(&addrType, (char*)(buffer + datalen), 4);
  1122.             memcpy(&address_len, (char*)(buffer + datalen + 4), 4);
  1123.             address = jdd_MemAlloc(sizeof(S8), address_len + 1);
  1124.             if (NULL == address)
  1125.             {
  1126.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1127.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1128.                 goto END;
  1129.             }
  1130.             memcpy(address, buffer + datalen + 8, address_len);
  1131.             datalen += address_len + 8;
  1132.             temp_address = jdd_MemAlloc(sizeof(S8), (address_len + 1) * ENCODING_LENGTH);
  1133.             if (NULL == temp_address)
  1134.             {
  1135.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1136.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1137.                 goto END;
  1138.             }
  1139.             AnsiiToUnicodeString((PS8) temp_address, (PS8) address);
  1140.             if((MMI_FALSE == mmi_jmms_check_address_input_format((U8*)temp_address))
  1141.                &&(MMI_FALSE == mmi_jmms_check_number_input_format((U8*)temp_address)))
  1142.             {
  1143.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1144.                 eRet = JC_ERR_INVALID_PARAMETER;
  1145.                 goto END;
  1146.             }
  1147.             g_jmms_context->address_list_flag = E_TO_ADDRESSES;
  1148.             ret = mmi_jmms_add_address_in_addresse_list(temp_address);
  1149.             if (ret != 0)
  1150.             {
  1151.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1152.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1153.                 goto END;
  1154.             }
  1155.             /* ASSERT(mmcAddrListToMms(addrType, address, &to)); */
  1156.             if (address != NULL)
  1157.             {
  1158.                 jdd_MemFree(address);
  1159.                 address = NULL;
  1160.             }
  1161.             if (temp_address != NULL)
  1162.             {
  1163.                 jdd_MemFree(temp_address);
  1164.                 temp_address = NULL;
  1165.             }
  1166.             message->to_addr_no--;
  1167.         }
  1168.         if (g_jmms_context->to_address_p != NULL)
  1169.         {
  1170.             g_jmms_context->to_p = mmi_jmms_get_to_addresses();
  1171.             if (g_jmms_context->to_p == NULL)
  1172.             {
  1173.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1174.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1175.                 goto END;
  1176.             }
  1177.             pMessageSend->pTo = (JC_CHAR*) g_jmms_context->to_p;
  1178.         }
  1179.         mmi_jmms_free_addresses_list();
  1180.         /* Retrieve cc addresses */
  1181.         while (message->cc_addr_no > 0)
  1182.         {
  1183.             U32 address_len = 0;
  1184.             U32 addrType = 0;
  1185.             U8 ret = 0;
  1186.             memcpy(&addrType, (char*)(buffer + datalen), 4);
  1187.             memcpy(&address_len, (char*)(buffer + datalen + 4), 4);
  1188.             address = jdd_MemAlloc(sizeof(S8), address_len + 1);
  1189.             if (NULL == address)
  1190.             {
  1191.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1192.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1193.                 goto END;
  1194.             }
  1195.             memcpy(address, buffer + datalen + 8, address_len);
  1196.             datalen += address_len + 8;
  1197.             temp_address = jdd_MemAlloc(sizeof(S8), (address_len + 1) * ENCODING_LENGTH);
  1198.             if (NULL == temp_address)
  1199.             {
  1200.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1201.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1202.                 goto END;
  1203.             }
  1204.             AnsiiToUnicodeString((PS8) temp_address, (PS8) address);
  1205.             if((MMI_FALSE == mmi_jmms_check_address_input_format((U8*)temp_address))
  1206.                &&(MMI_FALSE == mmi_jmms_check_number_input_format((U8*)temp_address)))
  1207.             {
  1208.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1209.                 eRet = JC_ERR_INVALID_PARAMETER;
  1210.                 goto END;
  1211.             }
  1212.             g_jmms_context->address_list_flag = E_CC_ADDRESSES;
  1213.             ret = mmi_jmms_add_address_in_addresse_list(temp_address);
  1214.             if (ret != 0)
  1215.             {
  1216.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1217.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1218.                 goto END;
  1219.             }
  1220.             if (address != NULL)
  1221.             {
  1222.                 jdd_MemFree(address);
  1223.                 address = NULL;
  1224.             }
  1225.             if (temp_address != NULL)
  1226.             {
  1227.                 jdd_MemFree(temp_address);
  1228.                 temp_address = NULL;
  1229.             }
  1230.             message->cc_addr_no--;
  1231.         }
  1232.         if (g_jmms_context->cc_address_p != NULL)
  1233.         {
  1234.             g_jmms_context->Cc_p = mmi_jmms_get_cc_addresses();
  1235.             if (g_jmms_context->Cc_p == NULL)
  1236.             {
  1237.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1238.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1239.                 goto END;
  1240.             }
  1241.             pMessageSend->pCc = (JC_CHAR*) g_jmms_context->Cc_p;
  1242.         }
  1243.         mmi_jmms_free_addresses_list();
  1244.         /* Retrieve bcc addresses */
  1245.         while (message->bcc_addr_no > 0)
  1246.         {
  1247.             U32 address_len = 0;
  1248.             U32 addrType = 0;
  1249.             U8 ret = 0;
  1250.             memcpy(&addrType, (char*)(buffer + datalen), 4);
  1251.             memcpy(&address_len, (char*)(buffer + datalen + 4), 4);
  1252.             address = jdd_MemAlloc(sizeof(S8), address_len + 1);
  1253.             if (address == NULL)
  1254.             {
  1255.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1256.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1257.                 goto END;
  1258.             }
  1259.             memcpy(address, buffer + datalen + 8, address_len);
  1260.             datalen += address_len + 8;
  1261.             temp_address = jdd_MemAlloc(sizeof(S8), (address_len + 1) * ENCODING_LENGTH);
  1262.             if (temp_address == NULL)
  1263.             {
  1264.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1265.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1266.                 goto END;
  1267.             }
  1268.             AnsiiToUnicodeString((PS8) temp_address, (PS8) address);
  1269.             if((MMI_FALSE == mmi_jmms_check_address_input_format((U8*)temp_address))
  1270.                &&(MMI_FALSE == mmi_jmms_check_number_input_format((U8*)temp_address)))
  1271.             {
  1272.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1273.                 eRet = JC_ERR_INVALID_PARAMETER;
  1274.                 goto END;
  1275.             }
  1276.             g_jmms_context->address_list_flag = E_BCC_ADDRESSES;
  1277.             ret = mmi_jmms_add_address_in_addresse_list(temp_address);
  1278.             if (ret != 0)
  1279.             {
  1280.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1281.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1282.                 goto END;
  1283.             }
  1284.             if (address != NULL)
  1285.             {
  1286.                 jdd_MemFree(address);
  1287.                 address = NULL;
  1288.             }
  1289.             if (temp_address != NULL)
  1290.             {
  1291.                 jdd_MemFree(temp_address);
  1292.                 temp_address = NULL;
  1293.             }
  1294.             message->bcc_addr_no--;
  1295.         }
  1296.         if (g_jmms_context->bcc_address_p != NULL)
  1297.         {
  1298.             g_jmms_context->bcc_p = mmi_jmms_get_bcc_addresses();
  1299.             if (g_jmms_context->bcc_p == NULL)
  1300.             {
  1301.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1302.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1303.                 goto END;
  1304.             }
  1305.             pMessageSend->pBcc = (JC_CHAR*) g_jmms_context->bcc_p;
  1306.         }
  1307.         mmi_jmms_free_addresses_list();
  1308.     }   /* /if(buffer!=NULL) */
  1309.     pMsgHeaders->eMsgType = E_MSG_TYPE_SEND;
  1310.     pMsgHeaders->pHeaders = pMessageSend;
  1311.     eRet = mmi_jmms_jdi_set_msg_headers(hMsgHandle, pMsgHeaders);
  1312.     if (JC_OK != eRet)
  1313.     {
  1314.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1315.         goto END;
  1316.     }
  1317.     /* Content type set here */
  1318.     jdi_MsgGetContentTypeParams(hMsgHandle, &pContentTypeParams);
  1319.     if (pContentTypeParams == NULL)
  1320.     {
  1321.         pContentTypeParams = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1322.         if (pContentTypeParams == NULL)
  1323.         {
  1324.             eRet = JC_ERR_MEMORY_ALLOCATION;
  1325.             mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1326.             goto END;
  1327.         }
  1328.         pContentTypeParams->pszName = jdi_UtilsStrdup("Application-ID");
  1329.         pContentTypeParams->pszValue = jdi_UtilsStrdup((JC_INT8*) (message->app_id));
  1330.         if(message->reply_app_id_len > 0)
  1331.         {
  1332.             pContentTypeParams->pNext = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1333.             if (pContentTypeParams->pNext == NULL)
  1334.             {
  1335.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1336.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1337.                 while (pContentTypeParams != NULL)
  1338.                 {
  1339.                     node = pContentTypeParams->pNext;
  1340.                     if (pContentTypeParams->pszName != NULL)
  1341.                     {
  1342.                         jdd_MemFree(pContentTypeParams->pszName);
  1343.                         pContentTypeParams->pszName = NULL;
  1344.                     }
  1345.                     if (pContentTypeParams->pszValue != NULL)
  1346.                     {
  1347.                         jdd_MemFree(pContentTypeParams->pszValue);
  1348.                         pContentTypeParams->pszValue = NULL;
  1349.                     }
  1350.                     jdd_MemFree(pContentTypeParams);
  1351.                     pContentTypeParams = node;
  1352.                 }
  1353.                 goto END;
  1354.             }
  1355.             pTempContentTypeParams = pContentTypeParams->pNext;
  1356.             pTempContentTypeParams->pszName = jdi_UtilsStrdup("Reply-To-Application-ID");
  1357.             pTempContentTypeParams->pszValue = jdi_UtilsStrdup((JC_INT8*) (message->reply_app_id));
  1358.         }
  1359.         if(message->start_cnt_id_len > 0)
  1360.         {
  1361.             pTempContentTypeParams->pNext = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1362.             if (pTempContentTypeParams->pNext == NULL)
  1363.             {
  1364.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1365.                 mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1366.                 while (pContentTypeParams != NULL)
  1367.                 {
  1368.                     node = pContentTypeParams->pNext;
  1369.                     if (pContentTypeParams->pszName != NULL)
  1370.                     {
  1371.                         jdd_MemFree(pContentTypeParams->pszName);
  1372.                         pContentTypeParams->pszName = NULL;
  1373.                     }
  1374.                     if (pContentTypeParams->pszValue != NULL)
  1375.                     {
  1376.                         jdd_MemFree(pContentTypeParams->pszValue);
  1377.                         pContentTypeParams->pszValue = NULL;
  1378.                     }
  1379.                     jdd_MemFree(pContentTypeParams);
  1380.                     pContentTypeParams = node;
  1381.                 }
  1382.                 goto END;
  1383.             }
  1384.             pTempContentTypeParams = pTempContentTypeParams->pNext;
  1385.             pTempContentTypeParams->pszName = jdi_UtilsStrdup("start");
  1386.             pTempContentTypeParams->pszValue = jdi_UtilsStrdup((JC_INT8*) (message->start_cnt_id));
  1387.         }
  1388.         if (pTempContentTypeParams != NULL)
  1389.         {
  1390.             pTempContentTypeParams->pNext = NULL;
  1391.         }
  1392.         jdi_MsgSetContentTypeParams(hMsgHandle, pContentTypeParams);
  1393.     }
  1394.     /* free any allocated memory */
  1395.     if (g_jmms_context->hMM1 != NULL)
  1396.     {
  1397.         /*eRet = jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE);*/
  1398.         /* Memory Leak Fix: jdi_MM1Cleanup is allocating memory for data chunk after freeing the context */
  1399.         eRet = jdi_MM1DeInitialize(g_jmms_context->hMM1);
  1400.         g_jmms_context->hMM1 = NULL;
  1401.     }
  1402.     eRet = jdi_MM1Initialize(&(g_jmms_context->hMM1));
  1403.     eRet = mmi_jmms_jsr_form_send_request_pdu(g_jmms_context->hMM1, (MESSAGING_HANDLER*) hMsgHandle);
  1404.     if (eRet != JC_OK)
  1405.     {
  1406.         mmi_jmms_free_mms_pdu_memory(g_jmms_context);
  1407.         goto END;
  1408.     }
  1409.     if (hMsgHandle != NULL)
  1410.     {
  1411.         mmi_jmms_jdi_msg_deinit(hMsgHandle);
  1412.         hMsgHandle = NULL;
  1413.         /* /manish-changing on 24 May to prevent End Key Bug */
  1414.         g_jmms_context->to_p = NULL;
  1415.         g_jmms_context->Cc_p = NULL;
  1416.         g_jmms_context->bcc_p = NULL;
  1417.         g_jmms_context->from_p = NULL;
  1418.         g_jmms_context->MsgHeader_type_p = NULL;
  1419.         g_jmms_context->MsgHeaders_p = NULL;
  1420.         g_jmms_context->subject = NULL;
  1421.         g_jmms_context->version = NULL;
  1422.     }
  1423.     return mmi_jmms_java_mms_error(JC_OK);
  1424.   END:
  1425.     if (address != NULL)
  1426.     {
  1427.         jdd_MemFree(address);
  1428.         address = NULL;
  1429.     }
  1430.     if (temp_address != NULL)
  1431.     {
  1432.         jdd_MemFree(temp_address);
  1433.         temp_address = NULL;
  1434.     }
  1435.     if (hMsgHandle != NULL)
  1436.     {
  1437.         mmi_jmms_jdi_msg_deinit(hMsgHandle);
  1438.         hMsgHandle = NULL;
  1439.         /* /manish adding here on 24 May */
  1440.         g_jmms_context->to_p = NULL;
  1441.         g_jmms_context->Cc_p = NULL;
  1442.         g_jmms_context->bcc_p = NULL;
  1443.         g_jmms_context->from_p = NULL;
  1444.         g_jmms_context->MsgHeader_type_p = NULL;
  1445.         g_jmms_context->MsgHeaders_p = NULL;
  1446.         g_jmms_context->subject = NULL;
  1447.         g_jmms_context->version = NULL;
  1448.     }
  1449.     if (g_jmms_context->hMM1 != NULL)
  1450.     {
  1451.         /*jdi_MM1Cleanup(g_jmms_context->hMM1, E_FALSE);*/
  1452.         /* Memory Leak Fix: jdi_MM1Cleanup is allocating memory for data chunk after freeing the context */
  1453.         jdi_MM1DeInitialize(g_jmms_context->hMM1);
  1454.         g_jmms_context->hMM1 = NULL;
  1455.     }
  1456.     /* /manish adding here on 24 May */
  1457.     mmi_jmms_free_addresses_list();
  1458.     return mmi_jmms_java_mms_error(eRet);
  1459. }
  1460. /*****************************************************************************
  1461.  * FUNCTION
  1462.  *  mmi_jmms_jsr_form_send_request_pdu
  1463.  * DESCRIPTION
  1464.  *  
  1465.  * PARAMETERS
  1466.  *  hMM1            [IN]        
  1467.  *  pMessaging      [?]         [?]
  1468.  * RETURNS
  1469.  *  
  1470.  *****************************************************************************/
  1471. JC_RETCODE mmi_jmms_jsr_form_send_request_pdu(MM1_HANDLE hMM1, MESSAGING_HANDLER *pMessaging)
  1472. {
  1473.     /*----------------------------------------------------------------*/
  1474.     /* Local Variables                                                */
  1475.     /*----------------------------------------------------------------*/
  1476.     JC_RETCODE eRet = JC_OK;
  1477.     MESSAGE_SEND *pSendInfo = NULL;
  1478.     JC_INT8 cMajorVersion = DEFAULT_MMS_MAJOR_VERSION;
  1479.     JC_INT8 cMinorVersion = E_MMS_MINOR_VERSION_2;
  1480.    /****** thanik 07-04-06 */
  1481.     MM1_HDR_PARAM *pContentTypeParams = NULL;   /* For content type */
  1482.     MM1_HDR_PARAM *pTempContentTypeParams = NULL;
  1483.     MM1_HDR_PARAM *node = NULL;
  1484.     /*----------------------------------------------------------------*/
  1485.     /* Code Body                                                      */
  1486.     /*----------------------------------------------------------------*/
  1487.    /**** thanik**/
  1488.     eRet = jdi_MM1SetMessageType(hMM1, E_MMS_SEND_REQUEST_VALUE);
  1489.     if (eRet != JC_OK)
  1490.     {
  1491.         goto error;
  1492.     }
  1493.     if (pMessaging->pMessageHeaders != NULL)
  1494.     {
  1495.         pSendInfo = (MESSAGE_SEND*) pMessaging->pMessageHeaders->pHeaders;
  1496.     }
  1497.     if (pSendInfo != NULL)
  1498.     {
  1499.         JC_CHAR *pFormattedAddress = NULL;
  1500.         if (pSendInfo->pVersion)
  1501.         {
  1502.             cMajorVersion = (JC_INT8) (jc_atoi(pSendInfo->pVersion));
  1503.             cMinorVersion = (JC_INT8) (jc_atoi((pSendInfo->pVersion) + 2));
  1504.         }
  1505.         eRet = jdi_MM1SetVersion(hMM1, cMajorVersion, cMinorVersion);
  1506.         if (eRet != JC_OK)
  1507.         {
  1508.             goto error;
  1509.         }
  1510.         if (pSendInfo->uiDate)
  1511.         {
  1512.             jdi_MM1SetDate(hMM1, pSendInfo->uiDate);
  1513.         }
  1514.         else
  1515.         {
  1516.             jdi_MM1SetDate(hMM1, jdd_TimerGetCurrentTime());
  1517.         }
  1518.         if (pSendInfo->pFrom)
  1519.         {
  1520.             GetFormattedAddress(&pFormattedAddress, pSendInfo->pFrom);
  1521.             if (pFormattedAddress != NULL)
  1522.             {
  1523.                 eRet = jdi_MM1SetFromAddress(hMM1, E_FALSE, pFormattedAddress, E_NONE);
  1524.                 jdd_MemFree(pFormattedAddress);
  1525.                 pFormattedAddress = NULL;
  1526.             }
  1527.             else
  1528.             {
  1529.                 eRet = jdi_MM1SetFromAddress(hMM1, E_FALSE, pSendInfo->pFrom, E_NONE);
  1530.             }
  1531.             if (eRet != JC_OK)
  1532.             {
  1533.                 goto error;
  1534.             }
  1535.         }
  1536.         if (pSendInfo->pTo)
  1537.         {
  1538.             GetFormattedAddress(&pFormattedAddress, pSendInfo->pTo);
  1539.             if (pFormattedAddress != NULL)
  1540.             {
  1541.                 eRet = jdi_MM1SetToAddress(hMM1, pFormattedAddress, E_NONE);
  1542.                 jdd_MemFree(pFormattedAddress);
  1543.                 pFormattedAddress = NULL;
  1544.             }
  1545.             else
  1546.             {
  1547.                 eRet = jdi_MM1SetToAddress(hMM1, pSendInfo->pTo, E_NONE);
  1548.             }
  1549.             if (eRet != JC_OK)
  1550.             {
  1551.                 goto error;
  1552.             }
  1553.         }
  1554.         if (pSendInfo->pCc)
  1555.         {
  1556.             GetFormattedAddress(&pFormattedAddress, pSendInfo->pCc);
  1557.             if (pFormattedAddress != NULL)
  1558.             {
  1559.                 eRet = jdi_MM1SetCCAddress(hMM1, pFormattedAddress, E_NONE);
  1560.                 jdd_MemFree(pFormattedAddress);
  1561.                 pFormattedAddress = NULL;
  1562.             }
  1563.             else
  1564.             {
  1565.                 eRet = jdi_MM1SetCCAddress(hMM1, pSendInfo->pCc, E_NONE);
  1566.             }
  1567.             if (eRet != JC_OK)
  1568.             {
  1569.                 goto error;
  1570.             }
  1571.         }
  1572.         if (pSendInfo->pBcc)
  1573.         {
  1574.             GetFormattedAddress(&pFormattedAddress, pSendInfo->pBcc);
  1575.             if (pFormattedAddress != NULL)
  1576.             {
  1577.                 eRet = jdi_MM1SetBCCAddress(hMM1, pFormattedAddress, E_NONE);
  1578.                 jdd_MemFree(pFormattedAddress);
  1579.                 pFormattedAddress = NULL;
  1580.             }
  1581.             else
  1582.             {
  1583.                 eRet = jdi_MM1SetBCCAddress(hMM1, pSendInfo->pBcc, E_NONE);
  1584.             }
  1585.             if (eRet != JC_OK)
  1586.             {
  1587.                 goto error;
  1588.             }
  1589.         }
  1590.         if (pSendInfo->pSubject)
  1591.         {
  1592.             eRet = jdi_MM1SetSubject(hMM1, pSendInfo->pSubject, E_NONE);
  1593.             if (eRet != JC_OK)
  1594.             {
  1595.                 goto error;
  1596.             }
  1597.         }
  1598.         eRet = jdi_MM1SetMessageClass(hMM1, (EMM1MessageClass) pSendInfo->eMsgClass);
  1599.         if (eRet != JC_OK)
  1600.         {
  1601.             goto error;
  1602.         }
  1603.         if (pSendInfo->uiExpiryTime)
  1604.         {
  1605.             eRet = jdi_MM1SetExpiryTime(hMM1, pSendInfo->uiExpiryTime, E_FALSE);
  1606.             if (eRet != JC_OK)
  1607.             {
  1608.                 goto error;
  1609.             }
  1610.         }
  1611.         if (pSendInfo->uiDeliveryTime)
  1612.         {
  1613.             eRet = jdi_MM1SetDeliveryTime(hMM1, pSendInfo->uiDeliveryTime, E_FALSE);
  1614.             if (eRet != JC_OK)
  1615.             {
  1616.                 goto error;
  1617.             }
  1618.         }
  1619.         if (pSendInfo->eMsgPriority > 0)
  1620.         {
  1621.             eRet = jdi_MM1SetPriority(hMM1, (EMM1MessagePriority) (pSendInfo->eMsgPriority - 1));
  1622.         }
  1623.         else
  1624.         {
  1625.             eRet = jdi_MM1SetPriority(hMM1, E_NORMAL_MESSAGE_PRIORITY);
  1626.         }
  1627.         eRet = jdi_MM1SetSenderVisibility(hMM1, ((pSendInfo->bHideSender == E_TRUE) ? E_FALSE : E_TRUE));
  1628.         if (eRet != JC_OK)
  1629.         {
  1630.             goto error;
  1631.         }
  1632.         eRet = jdi_MM1SetDeliveryReport(hMM1, pSendInfo->bDeliveryReport);
  1633.         if (eRet != JC_OK)
  1634.         {
  1635.             goto error;
  1636.         }
  1637.         eRet = jdi_MM1SetReadReplyReport(hMM1, pSendInfo->bReadReport);
  1638.         if (eRet != JC_OK)
  1639.         {
  1640.             goto error;
  1641.         }
  1642.     #ifdef ENABLE_MMS_VER_1_2
  1643.         if (cMinorVersion >= E_MMS_MINOR_VERSION_2 && pSendInfo->pMBoxInfo)
  1644.         {
  1645.             if (pSendInfo->pMBoxInfo->bMBoxStore == E_TRUE)
  1646.             {
  1647.                 eRet = jdi_MM1SetMMStore(hMM1, pSendInfo->pMBoxInfo->bMBoxStore);
  1648.                 if (eRet != JC_OK)
  1649.                 {
  1650.                     goto error;
  1651.                 }
  1652.                 eRet = jdi_MM1SetMMState(hMM1, (EMM1StoreStates) pSendInfo->pMBoxInfo->eMBoxState);
  1653.                 if (eRet != JC_OK)
  1654.                 {
  1655.                     goto error;
  1656.                 }
  1657.             }
  1658.             if (pSendInfo->pMBoxInfo->pMBoxFlagsType && pSendInfo->pMBoxInfo->pMBoxFlagsType->pAddTokens)
  1659.             {
  1660.                 eRet = jdi_MM1SetMMFlags(hMM1, E_ADD, pSendInfo->pMBoxInfo->pMBoxFlagsType->pAddTokens, E_UCS_2);
  1661.             }
  1662.             else if (pSendInfo->pMBoxInfo->pMBoxFlagsType && pSendInfo->pMBoxInfo->pMBoxFlagsType->pFilterTokens)
  1663.             {
  1664.                 eRet = jdi_MM1SetMMFlags(hMM1, E_REMOVE, pSendInfo->pMBoxInfo->pMBoxFlagsType->pFilterTokens, E_UCS_2);
  1665.             }
  1666.             else if (pSendInfo->pMBoxInfo->pMBoxFlagsType && pSendInfo->pMBoxInfo->pMBoxFlagsType->pFilterTokens)
  1667.             {
  1668.                 eRet = jdi_MM1SetMMFlags(hMM1, E_FILTER, pSendInfo->pMBoxInfo->pMBoxFlagsType->pFilterTokens, E_UCS_2);
  1669.             }
  1670.             if (eRet != JC_OK)
  1671.             {
  1672.                 goto error;
  1673.             }
  1674.         }
  1675.     #endif /* ENABLE_MMS_VER_1_2 */ 
  1676.         if (cMinorVersion > E_MMS_MINOR_VERSION_0 && pSendInfo->pReplyChargingInfo != NULL)
  1677.         {
  1678.             MM1_REPLY_CHARGING MM1ReplyChargingInfo;
  1679.             jc_memset(&MM1ReplyChargingInfo, 0x00, sizeof(MM1_REPLY_CHARGING));
  1680.             MM1ReplyChargingInfo.eReplyCharging = (EMM1ReplyCharging) pSendInfo->pReplyChargingInfo->eReplyCharging;
  1681.             MM1ReplyChargingInfo.uiRelativeTime = pSendInfo->pReplyChargingInfo->uiRelativeTime;
  1682.             MM1ReplyChargingInfo.uiSize = pSendInfo->pReplyChargingInfo->uiSize;
  1683.             if (pSendInfo->pReplyChargingInfo->eReplyCharging == E_REPLY_CHARGING_NOT_SUPPORTED)        /* i.e, if the message is a reply to a reply-charging req message */
  1684.             {
  1685.                 MM1ReplyChargingInfo.pszReplyId = pSendInfo->pReplyChargingInfo->pszReplyId;
  1686.             }
  1687.             eRet = jdi_MM1SetReplyCharging(hMM1, &MM1ReplyChargingInfo);
  1688.             if (eRet != JC_OK)
  1689.             {
  1690.                 goto error;
  1691.             }
  1692.         }
  1693.       /***** 27-03-06 ***/
  1694.         if (pMessaging->pParams != NULL)
  1695.         {
  1696.          /******** Thanik *** 07-04-06***/
  1697.             pContentTypeParams = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1698.             if (pContentTypeParams == NULL)
  1699.             {
  1700.                 eRet = JC_ERR_MEMORY_ALLOCATION;
  1701.                 goto error;
  1702.             }
  1703.             pContentTypeParams->pszName = jdi_UtilsStrdup(pMessaging->pParams->pszName);
  1704.             pContentTypeParams->pszValue = jdi_UtilsStrdup(pMessaging->pParams->pszValue);
  1705.             if(pMessaging->pParams->pNext != NULL)
  1706.             {
  1707.                 pContentTypeParams->pNext = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1708.                 if (pContentTypeParams->pNext == NULL)
  1709.                 {
  1710.                     eRet = JC_ERR_MEMORY_ALLOCATION;
  1711.                     goto error;
  1712.                 }
  1713.                 pTempContentTypeParams = pContentTypeParams->pNext;
  1714.                 pTempContentTypeParams->pszName = jdi_UtilsStrdup(pMessaging->pParams->pNext->pszName);
  1715.                 pTempContentTypeParams->pszValue = jdi_UtilsStrdup(pMessaging->pParams->pNext->pszValue);
  1716.             }
  1717.             if(pMessaging->pParams->pNext != NULL && pMessaging->pParams->pNext->pNext != NULL)
  1718.             {
  1719.                 pTempContentTypeParams->pNext = (MM1_HDR_PARAM*) jdd_MemAlloc(sizeof(MM1_HDR_PARAM), 1);
  1720.                 if (pTempContentTypeParams->pNext == NULL)
  1721.                 {
  1722.                     eRet = JC_ERR_MEMORY_ALLOCATION;
  1723.                     goto error;
  1724.                 }
  1725.                 pTempContentTypeParams = pTempContentTypeParams->pNext;
  1726.                 pTempContentTypeParams->pszName = jdi_UtilsStrdup(pMessaging->pParams->pNext->pNext->pszName);
  1727.                 pTempContentTypeParams->pszValue = jdi_UtilsStrdup(pMessaging->pParams->pNext->pNext->pszValue);
  1728.             }
  1729.             if (pTempContentTypeParams != NULL)
  1730.             {
  1731.                 pTempContentTypeParams->pNext = NULL;
  1732.             }
  1733.       /************* Thanik 07-04-06******/
  1734.             eRet = jdi_MM1SetContentType(hMM1, NULL, NULL, NULL, pContentTypeParams);
  1735.         }
  1736.       /***** 27-03-06 ***/
  1737.     }
  1738.     eRet = JC_OK;
  1739.   error:
  1740.     if (eRet != JC_OK)
  1741.     {
  1742.         while (pContentTypeParams != NULL)
  1743.         {
  1744.             node = pContentTypeParams->pNext;
  1745.             if (pContentTypeParams->pszName != NULL)
  1746.             {
  1747.                 jdd_MemFree(pContentTypeParams->pszName);
  1748.                 pContentTypeParams->pszName = NULL;
  1749.             }
  1750.             if (pContentTypeParams->pszValue != NULL)
  1751.             {
  1752.                 jdd_MemFree(pContentTypeParams->pszValue);
  1753.                 pContentTypeParams->pszValue = NULL;
  1754.             }
  1755.             jdd_MemFree(pContentTypeParams);
  1756.             pContentTypeParams = node;
  1757.         }
  1758.     }
  1759.     return eRet;
  1760. }
  1761. /*****************************************************************************
  1762.  * FUNCTION
  1763.  *  mmi_jmms_java_mms_error
  1764.  * DESCRIPTION
  1765.  *  
  1766.  * PARAMETERS
  1767.  *  error_code      [IN]        
  1768.  * RETURNS
  1769.  *  
  1770.  *****************************************************************************/
  1771. JsrResult mmi_jmms_java_mms_error(JC_RETCODE error_code)
  1772. {
  1773.     /*----------------------------------------------------------------*/
  1774.     /* Local Variables                                                */
  1775.     /*----------------------------------------------------------------*/
  1776.     /*----------------------------------------------------------------*/
  1777.     /* Code Body                                                      */
  1778.     /*----------------------------------------------------------------*/
  1779.     switch (error_code)
  1780.     {
  1781.         case JC_OK:
  1782.             return JSR_RESULT_OK;
  1783.         case JC_ERR_MEMORY_ALLOCATION:
  1784.             return JSR_RESULT_INSUFFICIENT_MEMORY;
  1785.         case JC_ERR_MSG_MAX_REACHED:
  1786.             return JSR_RESULT_EXCEED_MAX_MSGS;
  1787.         case JC_ERR_MMS_INVALID_HANDLE:
  1788.         case JC_ERR_MMS_INVALID_CONTENT_TYPE:
  1789.         case JC_ERR_MMS_INVALID_MMS_VERSION:
  1790.         case JC_ERR_MMS_INVALID_MESSAGE_TYPE:
  1791.         case JC_ERR_MMS_INVALID_HEADER:
  1792.         case JC_ERR_MSG_INVALID_HANDLE:
  1793.         case JC_ERR_MSG_INVALID_MESSAGING_TYPE:
  1794.         case JC_ERR_MSG_INVALID_PAGE_INDEX:
  1795.         case JC_ERR_MSG_INVALID_MEDIA_INDEX:
  1796.             return JSR_RESULT_INVALID_MESSAGE;
  1797.         case JC_ERR_STORE_INVALID_MSG_INDEX:
  1798.             return JSR_RESULT_MESSAGE_ID_NOT_FOUND;