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

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) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * mmi_imps_ps.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements all protocol related function/interface for IMPS application.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  *------------------------------------------------------------------------------
  80.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  81.  *============================================================================
  82.  ****************************************************************************/
  83. #ifndef _MMI_IMPS_PS_C
  84. #define _MMI_IMPS_PS_C
  85. #include "MMI_features.h"
  86. #ifdef __MMI_IMPS__
  87. /*  Include: MMI header file */
  88. #include "stdC.h"
  89. #include "L4Dr1.h"
  90. #include "PixtelDataTypes.h"
  91. #include "GlobalDefs.h"
  92. #include "CommonScreens.h"
  93. #include "DebugInitDef.h"
  94. #include "GlobalConstants.h"
  95. #include "FrameworkStruct.h"
  96. #include "EventsGprot.h"
  97. #include "HistoryGprot.h"
  98. #include "wgui_categories.h"
  99. #include "wgui_categories_inputs.h"
  100. #include "wgui_inline_edit.h"
  101. #include "wgui_tab_bars.h"
  102. #include "wgui_categories_IMPS.h"
  103. #include "mmi_imps_enum.h"
  104. #include "mmi_imps_prot.h"
  105. #include "Mmi_imps_gprot.h"
  106. #include "AlarmFrameworkProt.h"
  107. #include "FileManagerGProt.h"
  108. #include "DateTimeGprot.h"
  109. /* ... Add More MMI header */
  110. /*  Include: PS header file */
  111. /* ... Add More PS header */
  112. #ifdef MMI_ON_HARDWARE_P
  113. typedef struct
  114. {
  115.     U8 ref_count;
  116.     U16 msg_len;
  117. } imps_local_para_hdr;
  118. /***************************************************************************** 
  119. * Define
  120. *****************************************************************************/
  121. #define IMPS_MEMSET(addr, value, structure) memset(((U8*)addr)+sizeof(imps_local_para_hdr), value, (S32)(sizeof(structure) - sizeof(imps_local_para_hdr)))
  122. /***************************************************************************** 
  123. * Typedef 
  124. *****************************************************************************/
  125. /***************************************************************************** 
  126. * Local Variable
  127. *****************************************************************************/
  128. /***************************************************************************** 
  129. * Local Function
  130. *****************************************************************************/
  131. /***************************************************************************** 
  132. * Global Variable
  133. *****************************************************************************/
  134. /***************************************************************************** 
  135. * Global Function
  136. *****************************************************************************/
  137. /*****************************************************************************
  138.  * FUNCTION
  139.  *  mmi_imps_init_ps_before_idle
  140.  * DESCRIPTION
  141.  *  Initialize protocol event handlers when MMI power on.
  142.  *  This is to prevent ready indication comes too early
  143.  * PARAMETERS
  144.  *  void
  145.  * RETURNS
  146.  *  void
  147.  *****************************************************************************/
  148. void mmi_imps_init_ps_before_idle(void)
  149. {
  150.     /*----------------------------------------------------------------*/
  151.     /* Local Variables                                                */
  152.     /*----------------------------------------------------------------*/
  153.     /*----------------------------------------------------------------*/
  154.     /* Code Body                                                      */
  155.     /*----------------------------------------------------------------*/
  156.     SetProtocolEventHandler(mmi_imps_ps_ready_ind, MSG_ID_MMI_IMPS_READY_IND);
  157. }
  158. /*****************************************************************************
  159.  * FUNCTION
  160.  *  mmi_imps_init_ps_hdlr
  161.  * DESCRIPTION
  162.  *  Initialize all protocol event handlers.
  163.  * PARAMETERS
  164.  *  void
  165.  * RETURNS
  166.  *  void
  167.  *****************************************************************************/
  168. void mmi_imps_init_ps_hdlr(void)
  169. {
  170.     /*----------------------------------------------------------------*/
  171.     /* Local Variables                                                */
  172.     /*----------------------------------------------------------------*/
  173.     /*----------------------------------------------------------------*/
  174.     /* Code Body                                                      */
  175.     /*----------------------------------------------------------------*/
  176.     SetProtocolEventHandler(mmi_imps_ps_login_rsp, MSG_ID_MMI_IMPS_LOGIN_RSP);
  177.     SetProtocolEventHandler(mmi_imps_ps_abort_login_rsp, MSG_ID_MMI_IMPS_ABORT_LOGIN_RSP);
  178.     SetProtocolEventHandler(mmi_imps_ps_logout_rsp, MSG_ID_MMI_IMPS_LOGOUT_RSP);
  179.     SetProtocolEventHandler(mmi_imps_ps_get_contact_list_rsp, MSG_ID_MMI_IMPS_GET_CONTACT_LIST_RSP);
  180.     SetProtocolEventHandler(mmi_imps_ps_view_contact_list_rsp, MSG_ID_MMI_IMPS_VIEW_CONTACT_LIST_RSP);
  181.     SetProtocolEventHandler(mmi_imps_abort_get_pa_rsp, MSG_ID_MMI_IMPS_ABORT_GET_PA_RSP);
  182.     SetProtocolEventHandler(mmi_imps_ps_pa_notify_ind, MSG_ID_MMI_IMPS_PA_NOTIFY_IND);
  183.     SetProtocolEventHandler(mmi_imps_ps_newmsg_ind, MSG_ID_MMI_IMPS_NEWMESSAGE_IND);
  184.     SetProtocolEventHandler(mmi_imps_ps_update_pa_rsp, MSG_ID_MMI_IMPS_UPDATE_PA_RSP);
  185.     SetProtocolEventHandler(mmi_imps_ps_get_watch_list_rsp, MSG_ID_MMI_IMPS_GET_WATCHER_LIST_RSP);
  186.     SetProtocolEventHandler(mmi_imps_ps_abort_get_watch_list_rsp, MSG_ID_MMI_IMPS_ABORT_GET_WATCHER_LIST_RSP);
  187.     SetProtocolEventHandler(mmi_imps_ps_create_group_rsp, MSG_ID_MMI_IMPS_CREATE_GROUP_RSP);
  188.     SetProtocolEventHandler(mmi_imps_ps_block_entity_rsp, MSG_ID_MMI_IMPS_BLOCK_ENTITY_RSP);
  189.     SetProtocolEventHandler(mmi_imps_ps_join_group_rsp, MSG_ID_MMI_IMPS_JOIN_GROUP_RSP);
  190.     SetProtocolEventHandler(mmi_imps_ps_abort_search_rsp, MSG_ID_MMI_IMPS_ABORT_SEARCH_RSP);
  191.     SetProtocolEventHandler(mmi_imps_ps_send_msg_rsp, MSG_ID_MMI_IMPS_SEND_MESSAGE_RSP);
  192.     SetProtocolEventHandler(mmi_imps_ps_del_group_rsp, MSG_ID_MMI_IMPS_DELETE_GROUP_RSP);
  193.     SetProtocolEventHandler(mmi_imps_ps_del_contact_list_rsp, MSG_ID_MMI_IMPS_DEL_CONTACT_LIST_RSP);
  194.     SetProtocolEventHandler(mmi_imps_ps_leave_group_rsp, MSG_ID_MMI_IMPS_LEAVE_GROUP_RSP);
  195.     SetProtocolEventHandler(mmi_imps_ps_leave_group_ind, MSG_ID_MMI_IMPS_LEAVE_GROUP_IND);
  196.     SetProtocolEventHandler(mmi_imps_ps_invite_rsp, MSG_ID_MMI_IMPS_INVITE_RSP);
  197.     SetProtocolEventHandler(mmi_imps_ps_invite_response_ind, MSG_ID_MMI_IMPS_INVITE_RESPONSE_IND);
  198.     SetProtocolEventHandler(mmi_imps_ps_server_disconn_ind, MSG_ID_MMI_IMPS_DISCONNECT_IND);
  199.     SetProtocolEventHandler(mmi_imps_ps_group_change_ind, MSG_ID_MMI_IMPS_GROUP_CHANGE_NOTIFY_IND);
  200.     SetProtocolEventHandler(mmi_imps_ps_invite_ind, MSG_ID_MMI_IMPS_INVITE_IND);
  201.     SetProtocolEventHandler(mmi_imps_ps_get_block_list_rsp, MSG_ID_MMI_IMPS_GET_BLOCK_LIST_RSP);
  202.     SetProtocolEventHandler(mmi_imps_ps_add_contact_list_rsp, MSG_ID_MMI_IMPS_ADD_CONTACT_LIST_RSP);
  203. #ifndef __MTK_TARGET__
  204.     imps_p->gen_info.ps_ready_state |= IMPS_LOGIN_PS_READY;
  205.     imps_p->gen_info.ps_ready_state |= IMPS_LOGIN_RAC_READY;
  206. #endif /* __MTK_TARGET__ */ 
  207. }
  208. /*****************************************************************************
  209.  * FUNCTION
  210.  *  mmi_imps_ps_send_msg
  211.  * DESCRIPTION
  212.  *  Wrapper function to send message to IMPS module
  213.  * PARAMETERS
  214.  *  msg_id              [IN]        
  215.  *  local_param_ptr     [?]         
  216.  *  peer_buf_ptr        [?]         
  217.  * RETURNS
  218.  *  void
  219.  *****************************************************************************/
  220. void mmi_imps_ps_send_msg(U16 msg_id, void *local_param_ptr, void *peer_buf_ptr)
  221. {
  222.     /*----------------------------------------------------------------*/
  223.     /* Local Variables                                                */
  224.     /*----------------------------------------------------------------*/
  225.     MYQUEUE Message;
  226.     /*----------------------------------------------------------------*/
  227.     /* Code Body                                                      */
  228.     /*----------------------------------------------------------------*/
  229.     /* store the index of request */
  230.     imps_p->gen_info.curr_action = msg_id;
  231.     Message.oslSrcId = MOD_MMI;
  232.     Message.oslDestId = MOD_IMPS;
  233.     Message.oslMsgId = msg_id;
  234.     Message.oslDataPtr = (oslParaType*) local_param_ptr;
  235.     Message.oslPeerBuffPtr = peer_buf_ptr;
  236.     OslMsgSendExtQueue(&Message);
  237. }
  238. /*****************************************************************************
  239.  * FUNCTION
  240.  *  mmi_imps_ps_login_req
  241.  * DESCRIPTION
  242.  *  Send MSG_ID_MMI_IMPS_LOGIN_REQ to PS.
  243.  * PARAMETERS
  244.  *  void
  245.  * RETURNS
  246.  *  void
  247.  *****************************************************************************/
  248. void mmi_imps_ps_login_req(void)
  249. {
  250.     /*----------------------------------------------------------------*/
  251.     /* Local Variables                                                */
  252.     /*----------------------------------------------------------------*/
  253.     /* send login request to PS */
  254.     mmi_imps_login_req_struct *req;
  255.     mmi_imps_prof_struct *act_prof = &imps_p->act_prof;
  256.     /*----------------------------------------------------------------*/
  257.     /* Code Body                                                      */
  258.     /*----------------------------------------------------------------*/
  259.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_LOGIN_REQ || imps_p->gen_info.is_login)
  260.     {
  261.         return;
  262.     }
  263.     req = (mmi_imps_login_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_login_req_struct));
  264.     IMPS_MEMSET(req, 0, mmi_imps_login_req_struct);
  265.     /* connection type, shall be set according to the enum value of PS */
  266.     if (act_prof->conn_type == 0)
  267.     {
  268.         req->conn_type = IMPS_CONN_TYPE_HTTP;
  269.     }
  270.     else
  271.     {
  272.         req->conn_type = IMPS_CONN_TYPE_WSP_CO;
  273.     }
  274.     /* data account */
  275.     req->net_id = act_prof->dt_acct;
  276.     /* user proxy */
  277.     req->use_proxy = act_prof->use_proxy;
  278.     /* proxy info */
  279.     if (act_prof->use_proxy)
  280.     {
  281.         req->prx_port = act_prof->proxy_port;
  282.         req->prx_ip[0] = act_prof->proxy_ip[0];
  283.         req->prx_ip[1] = act_prof->proxy_ip[1];
  284.         req->prx_ip[2] = act_prof->proxy_ip[2];
  285.         req->prx_ip[3] = act_prof->proxy_ip[3];
  286.         strcpy((S8*) req->prx_usrn, (S8*) act_prof->proxy_username);
  287.         strcpy((S8*) req->prx_pwd, (S8*) act_prof->proxy_passwd);
  288.     }
  289.     /* user name */
  290.     strcpy((S8*) req->imps_usrn, (S8*) act_prof->username);
  291.     /* password */
  292.     strcpy((S8*) req->imps_pwd, (S8*) act_prof->passwd);
  293.     /* server */
  294.     strcpy((S8*) req->imps_server, (S8*) act_prof->server);
  295.     /* currently no usage */
  296.     req->imps_service_set = 0xff;
  297.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_LOGIN_REQ, (void*)req, NULL);
  298. }
  299. /*****************************************************************************
  300.  * FUNCTION
  301.  *  mmi_imps_ps_login_rsp
  302.  * DESCRIPTION
  303.  *  Handler for MSG_ID_MMI_IMPS_LOGIN_RSP.
  304.  * PARAMETERS
  305.  *  msg     [IN]        Result of response
  306.  * RETURNS
  307.  *  void
  308.  *****************************************************************************/
  309. void mmi_imps_ps_login_rsp(void *msg)
  310. {
  311.     /*----------------------------------------------------------------*/
  312.     /* Local Variables                                                */
  313.     /*----------------------------------------------------------------*/
  314.     mmi_imps_login_rsp_struct *rsp = (mmi_imps_login_rsp_struct*) msg;
  315.     /*----------------------------------------------------------------*/
  316.     /* Code Body                                                      */
  317.     /*----------------------------------------------------------------*/
  318.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_ABORT_LOGIN_REQ)
  319.     {
  320.         return;
  321.     }
  322.     /* restore current action */
  323.     imps_p->gen_info.curr_action = 0;
  324.     if (rsp->result == IMPS_OK)
  325.     {
  326.         imps_p->gen_info.is_login = TRUE;
  327.         /* reload contact list from cache */
  328.         mmi_imps_util_init_list();
  329.         /* update status icon */
  330.         mmi_imps_util_update_login_icon();
  331.         /* entry contact list screen */
  332.         imps_p->gen_info.no_tab = 1;
  333.         if (imps_p->gen_info.is_reentry)
  334.         {
  335.             mmi_imps_re_entry_app();
  336.         }
  337.         else
  338.         {
  339.             if (GetActiveScreenId() == SCR_ID_IMPS_PROGRESS)
  340.             {
  341.                 mmi_imps_pre_entry_cont();
  342.                 DeleteScreenIfPresent(SCR_ID_IMPS_PROGRESS);
  343.             }
  344.             else
  345.             {
  346.                 /* in other screen, replace progress screen by the result screen */
  347.                 HistoryReplace(SCR_ID_IMPS_PROGRESS, SCR_ID_IMPS_CONT, mmi_imps_pre_entry_cont);
  348.             }
  349.             DeleteScreenIfPresent(SCR_ID_IMPS_MAIN);
  350.         }
  351.         /* send request to get latest contact list */
  352.         mmi_imps_ps_get_contact_list_req();
  353.     }
  354.     else
  355.     {
  356.         /* for non auto-login case */
  357.         if (IsScreenPresent(SCR_ID_IMPS_PROGRESS) || GetActiveScreenId() == SCR_ID_IMPS_PROGRESS)
  358.         {
  359.             mmi_imps_util_disp_err_popup(mmi_imps_util_get_err_str(rsp->result));
  360.             /* if it's re_entry from other application */
  361.             if (imps_p->gen_info.is_reentry)
  362.             {
  363.                 HistoryReplace(SCR_ID_IMPS_PROGRESS, SCR_ID_IMPS_MAIN, mmi_imps_entry_main);
  364.             }
  365.             else
  366.             {
  367.                 DeleteScreenIfPresent(SCR_ID_IMPS_PROGRESS);
  368.             }
  369.         }
  370.         imps_p->gen_info.is_reentry = FALSE;
  371.     }
  372. }
  373. /*****************************************************************************
  374.  * FUNCTION
  375.  *  mmi_imps_ps_abort_login_req
  376.  * DESCRIPTION
  377.  *  Abort login process
  378.  * PARAMETERS
  379.  *  void
  380.  * RETURNS
  381.  *  void
  382.  *****************************************************************************/
  383. void mmi_imps_ps_abort_login_req(void)
  384. {
  385.     /*----------------------------------------------------------------*/
  386.     /* Local Variables                                                */
  387.     /*----------------------------------------------------------------*/
  388.     /*----------------------------------------------------------------*/
  389.     /* Code Body                                                      */
  390.     /*----------------------------------------------------------------*/
  391.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_ABORT_LOGIN_REQ, NULL, NULL);
  392. }
  393. /*****************************************************************************
  394.  * FUNCTION
  395.  *  mmi_imps_ps_abort_login_rsp
  396.  * DESCRIPTION
  397.  *  Abort login process
  398.  * PARAMETERS
  399.  *  msg     [IN]        Result of response
  400.  * RETURNS
  401.  *  void
  402.  *****************************************************************************/
  403. void mmi_imps_ps_abort_login_rsp(void *msg)
  404. {
  405.     /*----------------------------------------------------------------*/
  406.     /* Local Variables                                                */
  407.     /*----------------------------------------------------------------*/
  408.     /*----------------------------------------------------------------*/
  409.     /* Code Body                                                      */
  410.     /*----------------------------------------------------------------*/
  411.     /* restore current action */
  412.     imps_p->gen_info.curr_action = 0;
  413.     if (imps_p->gen_info.is_reentry)
  414.     {
  415.         mmi_imps_re_entry_app();
  416.     }
  417.     else
  418.     {
  419.         mmi_imps_login_abort_finish();
  420.     }
  421. }
  422. /*****************************************************************************
  423.  * FUNCTION
  424.  *  mmi_imps_ps_logout_req
  425.  * DESCRIPTION
  426.  *  Send MSG_ID_MMI_IMPS_LOGOUT_REQ to PS.
  427.  * PARAMETERS
  428.  *  void
  429.  * RETURNS
  430.  *  void
  431.  *****************************************************************************/
  432. void mmi_imps_ps_logout_req(void)
  433. {
  434.     /*----------------------------------------------------------------*/
  435.     /* Local Variables                                                */
  436.     /*----------------------------------------------------------------*/
  437.     /*----------------------------------------------------------------*/
  438.     /* Code Body                                                      */
  439.     /*----------------------------------------------------------------*/
  440.     /* send login request to PS */
  441.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_LOGOUT_REQ, NULL, NULL);
  442. }
  443. /*****************************************************************************
  444.  * FUNCTION
  445.  *  mmi_imps_ps_logout_rsp
  446.  * DESCRIPTION
  447.  *  Handler for MSG_ID_MMI_IMPS_LOGOUT_RSP.
  448.  * PARAMETERS
  449.  *  msg     [IN]        Result of response
  450.  * RETURNS
  451.  *  void
  452.  *****************************************************************************/
  453. void mmi_imps_ps_logout_rsp(void *msg)
  454. {
  455.     /*----------------------------------------------------------------*/
  456.     /* Local Variables                                                */
  457.     /*----------------------------------------------------------------*/
  458.     /*----------------------------------------------------------------*/
  459.     /* Code Body                                                      */
  460.     /*----------------------------------------------------------------*/
  461.     /* restore current action */
  462.     imps_p->gen_info.curr_action = 0;
  463.     /* because logout will be always success, no checking procedure required */
  464.     imps_p->gen_info.is_login = FALSE;
  465.     if (imps_p->gen_info.is_reentry)
  466.     {
  467.         mmi_imps_re_entry_app();
  468.     }
  469.     else
  470.     {
  471.         mmi_imps_logout_complete();
  472.     }
  473.     mmi_imps_util_update_login_icon();
  474. }
  475. #define CONT_PS_IMPS
  476. /*****************************************************************************
  477.  * FUNCTION
  478.  *  mmi_imps_ps_get_contact_list_req
  479.  * DESCRIPTION
  480.  *  Send MSG_ID_MMI_IMPS_GET_CONTACT_REQ to PS.
  481.  * PARAMETERS
  482.  *  void
  483.  * RETURNS
  484.  *  void
  485.  *****************************************************************************/
  486. void mmi_imps_ps_get_contact_list_req(void)
  487. {
  488.     /*----------------------------------------------------------------*/
  489.     /* Local Variables                                                */
  490.     /*----------------------------------------------------------------*/
  491.     /*----------------------------------------------------------------*/
  492.     /* Code Body                                                      */
  493.     /*----------------------------------------------------------------*/
  494.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_GET_CONTACT_LIST_REQ, NULL, NULL);
  495.     /* restore current action -- won't store state for background update */
  496.     imps_p->gen_info.curr_action = 0;
  497. }
  498. /*****************************************************************************
  499.  * FUNCTION
  500.  *  mmi_imps_ps_get_contact_list_rsp
  501.  * DESCRIPTION
  502.  *  Handler for MSG_ID_MMI_IMPS_GET_CONTACT_LIST_RSP.
  503.  * PARAMETERS
  504.  *  msg     [IN]        Result of response
  505.  * RETURNS
  506.  *  void
  507.  *****************************************************************************/
  508. void mmi_imps_ps_get_contact_list_rsp(void *msg)
  509. {
  510.     /*----------------------------------------------------------------*/
  511.     /* Local Variables                                                */
  512.     /*----------------------------------------------------------------*/
  513.     mmi_imps_get_contact_list_rsp_struct *rsp = (mmi_imps_get_contact_list_rsp_struct*) msg;
  514.     /*----------------------------------------------------------------*/
  515.     /* Code Body                                                      */
  516.     /*----------------------------------------------------------------*/
  517.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_LOGOUT_REQ || imps_p->gen_info.is_login == FALSE)
  518.     {
  519.         return;
  520.     }
  521.     /* restore current action */
  522.     imps_p->gen_info.curr_action = 0;
  523.     if (rsp->result == IMPS_OK && (rsp->contact_list_id_list.entity_count > 0 || rsp->default_contact_list_id_p))
  524.     {
  525.         S32 i = 0, j, k, l = 0;
  526.         S32 ps_count, local_count;
  527.         S32 new_ids[IMPS_MAX_NO_GROUP];
  528.         memset(&new_ids, 0, sizeof(new_ids));
  529.         /* default contact list */
  530.         ps_count = (S32) rsp->contact_list_id_list.entity_count;
  531.         if (ps_count > IMPS_MAX_NO_GROUP)
  532.         {
  533.             ps_count = IMPS_MAX_NO_GROUP;
  534.         }
  535.         local_count = (S32) imps_p->group_info.no_group;
  536.         if (rsp->default_contact_list_id_p)
  537.         {
  538.             /* check if the default contact list is on server */
  539.             for (i = 0; i < local_count; i++)
  540.             {
  541.                 if (mmi_imps_util_is_id_same
  542.                     ((S8*) rsp->default_contact_list_id, (S8*) imps_p->group_info.group_list[i].group_id))
  543.                 {
  544.                     imps_p->group_info.group_list[i].is_sync = TRUE;
  545.                     break;
  546.                 }
  547.             }
  548.             /* default contact list presently is not in global context */
  549.             if (i == local_count && l < IMPS_MAX_NO_GROUP)
  550.             {
  551.                 /* store it in the new_id list, make it equal to ps_count to distinguish with others */
  552.                 new_ids[l++] = ps_count;
  553.             }
  554.         }
  555.         /* sync group id with contact list Update contact list info if it's not sync */
  556.         /* from PS to local part, find out new group ids */
  557.         for (j = 0; j < ps_count; j++)
  558.         {
  559.             for (k = 0; k < local_count; k++)
  560.             {
  561.                 /* mark is_retrieve to TRUE to mean the group is retrieved and is still stored on server */
  562.                 if (imps_p->group_info.group_list[k].is_sync == FALSE)
  563.                 {
  564.                     if (mmi_imps_util_is_id_same
  565.                         ((S8*) imps_p->group_info.group_list[k].group_id,
  566.                          (S8*) rsp->contact_list_id_list.entity[j].id))
  567.                     {
  568.                         imps_p->group_info.group_list[k].is_sync = TRUE;
  569.                         break;
  570.                     }
  571.                 }
  572.             }
  573.             /* only allow IMPS_MAX_NO_GROUP of groups */
  574.             if (l < IMPS_MAX_NO_GROUP && k == local_count)
  575.             {
  576.                 new_ids[l++] = j;
  577.             }
  578.         }
  579.         /* removed dangling ids */
  580.         for (k = (local_count - 1); k >= 0; k--)
  581.         {
  582.             if (imps_p->group_info.group_list[k].is_sync == FALSE)
  583.             {
  584.                 if (k < (local_count - 1))
  585.                 {
  586.                     memcpy(
  587.                         &imps_p->group_info.group_list[k],
  588.                         &imps_p->group_info.group_list[k + 1],
  589.                         (local_count - k - 1) * sizeof(mmi_imps_group_struct));
  590.                 }
  591.                 local_count--;
  592.                 memset(&imps_p->group_info.group_list[local_count], 0, sizeof(mmi_imps_group_struct));
  593.             }
  594.         }
  595.         /* fill the new id list into group list if there are still some empty slots */
  596.         for (k = 0; (k < l && local_count < IMPS_MAX_NO_GROUP); k++, local_count++)
  597.         {
  598.             if (new_ids[k] == ps_count) /* it's the default contact list */
  599.             {
  600.                 strcpy((S8*) imps_p->group_info.group_list[local_count].group_id, (S8*) rsp->default_contact_list_id);
  601.             }
  602.             else
  603.             {
  604.                 strcpy(
  605.                     (S8*) imps_p->group_info.group_list[local_count].group_id,
  606.                     (S8*) rsp->contact_list_id_list.entity[new_ids[k]].id);
  607.             }
  608.             imps_p->group_info.group_list[local_count].is_sync = TRUE;
  609.         }
  610.         imps_p->group_info.no_group = (U8) local_count;
  611.         /* send request to get detail information of each contact list */
  612.         if (local_count)
  613.         {
  614.             imps_p->gen_info.curr_group = 0;
  615.             mmi_imps_ps_view_contact_list_req(0);
  616.         }
  617.         else
  618.         {
  619.             mmi_imps_sync_cont_list();
  620.             imps_p->gen_info.auto_update_done = TRUE;
  621.         }
  622.     }
  623.     else
  624.     {
  625.         /* get contact list data using local-saved data if group is not empty */
  626.         if (imps_p->group_info.no_group)
  627.         {
  628.             mmi_imps_ps_view_contact_list_req(0);
  629.         }
  630.         else
  631.         {
  632.             mmi_imps_ps_get_block_list_req();
  633.         }
  634.     }
  635. }
  636. /*****************************************************************************
  637.  * FUNCTION
  638.  *  mmi_imps_ps_view_next_contact_list
  639.  * DESCRIPTION
  640.  *  Send request to view the detail information of next contact list
  641.  * PARAMETERS
  642.  *  void
  643.  * RETURNS
  644.  *  void
  645.  *****************************************************************************/
  646. void mmi_imps_ps_view_next_contact_list(void)
  647. {
  648.     /*----------------------------------------------------------------*/
  649.     /* Local Variables                                                */
  650.     /*----------------------------------------------------------------*/
  651.     /*----------------------------------------------------------------*/
  652.     /* Code Body                                                      */
  653.     /*----------------------------------------------------------------*/
  654.     imps_p->gen_info.curr_group++;
  655.     if (imps_p->gen_info.curr_group != imps_p->group_info.no_group)
  656.     {
  657.         /* still some group not retrieved */
  658.         mmi_imps_ps_view_contact_list_req(imps_p->gen_info.curr_group);
  659.     }
  660.     else
  661.     {
  662.         mmi_imps_ps_get_about_me_req();
  663.     }
  664. }
  665. /*****************************************************************************
  666.  * FUNCTION
  667.  *  mmi_imps_ps_view_contact_list_req
  668.  * DESCRIPTION
  669.  *  Send MSG_ID_MMI_IMPS_VIEW_CONTACT_REQ to PS.
  670.  * PARAMETERS
  671.  *  index       [IN]        Index of group to be retrieved.
  672.  * RETURNS
  673.  *  void
  674.  *****************************************************************************/
  675. void mmi_imps_ps_view_contact_list_req(U8 index)
  676. {
  677.     /*----------------------------------------------------------------*/
  678.     /* Local Variables                                                */
  679.     /*----------------------------------------------------------------*/
  680.     mmi_imps_view_contact_list_req_struct *req =
  681.         (mmi_imps_view_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_view_contact_list_req_struct));
  682.     /*----------------------------------------------------------------*/
  683.     /* Code Body                                                      */
  684.     /*----------------------------------------------------------------*/
  685.     IMPS_MEMSET(req, 0, mmi_imps_view_contact_list_req_struct);
  686.     strcpy((S8*) req->contact_list_id, (S8*) imps_p->group_info.group_list[index].group_id);
  687.     /* send view contact list request to PS */
  688.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_VIEW_CONTACT_LIST_REQ, (void*)req, NULL);
  689.     /* restore current action -- won't store state for background update */
  690.     imps_p->gen_info.curr_action = 0;
  691. }
  692. /*****************************************************************************
  693.  * FUNCTION
  694.  *  mmi_imps_ps_view_contact_list_rsp
  695.  * DESCRIPTION
  696.  *  Handler for MSG_ID_MMI_IMPS_VIEW_CONTACT_LIST_RSP.
  697.  * PARAMETERS
  698.  *  msg     [IN]        Result of response
  699.  * RETURNS
  700.  *  void
  701.  *****************************************************************************/
  702. void mmi_imps_ps_view_contact_list_rsp(void *msg)
  703. {
  704.     /*----------------------------------------------------------------*/
  705.     /* Local Variables                                                */
  706.     /*----------------------------------------------------------------*/
  707.     mmi_imps_view_contact_list_rsp_struct *rsp = (mmi_imps_view_contact_list_rsp_struct*) msg;
  708.     /*----------------------------------------------------------------*/
  709.     /* Code Body                                                      */
  710.     /*----------------------------------------------------------------*/
  711.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_LOGOUT_REQ || imps_p->gen_info.is_login == FALSE)
  712.     {
  713.         return;
  714.     }
  715.     /* restore current action */
  716.     imps_p->gen_info.curr_action = 0;
  717.     if (rsp->result == IMPS_OK)
  718.     {
  719.         S32 i, j, count;
  720.         S32 curr_no_cont = (S32) imps_p->cont_info.no_cont;
  721.         mmi_imps_cont_struct *cont;
  722.         count = (S32) rsp->user_nick_list.entity_count;
  723.         /* update info of this contact list */
  724.         if (rsp->display_name_p)
  725.         {
  726.             pfnUnicodeStrcpy(
  727.                 (S8*) imps_p->group_info.group_list[imps_p->gen_info.curr_group].group_name,
  728.                 (S8*) rsp->display_name);
  729.         }
  730.         /* update contacts in file buffer */
  731.         for (i = 0; i < count; i++)
  732.         {
  733.             /* still compare "Myself" to prevent abnormal case */
  734.             for (j = 0; j < curr_no_cont; j++)
  735.             {
  736.                 cont = &imps_p->cont_info.cont_list[j];
  737.                 if (mmi_imps_util_is_id_same((S8*) rsp->user_nick_list.entity[i].id, (S8*) cont->id))
  738.                 {
  739.                     /* if j == 0, duplicated */
  740.                     if (j == 0)
  741.                     {
  742.                         break;
  743.                     }
  744.                     /* check if the user already updated */
  745.                     if ((cont->comm_state & IMPS_CONT_PA_READY) == 0)
  746.                     {
  747.                         cont->comm_state |= IMPS_CONT_PA_READY;
  748.                         strcpy(
  749.                             (S8*) cont->group_id,
  750.                             (S8*) imps_p->group_info.group_list[imps_p->gen_info.curr_group].group_id);
  751.                         /* use server-provided name if the user did not modify the nick for the contact */
  752.                         if (pfnUnicodeStrlen((S8*) rsp->user_nick_list.entity[i].sname))
  753.                         {
  754.                             pfnUnicodeStrcpy((S8*) cont->nick_name, (S8*) rsp->user_nick_list.entity[i].sname);
  755.                         }
  756.                         cont->availability = IMPS_PA_USER_UNKNOWN;
  757.                         break;
  758.                     }
  759.                     else
  760.                     {
  761.                         /* to prevent single contact belongs to multiple contact lists cases */
  762.                         break;
  763.                     }
  764.                 }
  765.             }
  766.             /* not in contact list -- new id */
  767.             if ((j == curr_no_cont) && (0 < curr_no_cont < IMPS_MAX_NO_CONT))
  768.             {
  769.                 /* to prevent abnormal case -- empty id */
  770.                 if (strlen((S8*) rsp->user_nick_list.entity[i].id))
  771.                 {
  772.                     cont = &imps_p->cont_info.cont_list[j];
  773.                     strcpy((S8*) cont->id, (S8*) rsp->user_nick_list.entity[i].id);
  774.                     pfnUnicodeStrcpy((S8*) cont->nick_name, (S8*) rsp->user_nick_list.entity[i].sname);
  775.                     cont->comm_state |= IMPS_CONT_PA_READY;
  776.                     strcpy(
  777.                         (S8*) cont->group_id,
  778.                         (S8*) imps_p->group_info.group_list[imps_p->gen_info.curr_group].group_id);
  779.                     cont->availability = IMPS_PA_USER_UNKNOWN;
  780.                     curr_no_cont++;
  781.                     imps_p->cont_info.no_cont++;
  782.                 }
  783.             }
  784.         }
  785.         /* send request to retrieve PA of each friend */
  786.         if (imps_p->act_prof.auto_update && count)
  787.         {
  788.             mmi_imps_ps_get_pa_req((void*)rsp);
  789.         }
  790.         else
  791.         {
  792.             mmi_imps_ps_view_next_contact_list();
  793.         }
  794.     }
  795.     else
  796.     {
  797.         mmi_imps_ps_view_next_contact_list();
  798.     }
  799. }
  800. /*****************************************************************************
  801.  * FUNCTION
  802.  *  mmi_imps_ps_edit_contact_list_req
  803.  * DESCRIPTION
  804.  *  Send MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_REQ to PS.
  805.  * PARAMETERS
  806.  *  void
  807.  * RETURNS
  808.  *  void
  809.  *****************************************************************************/
  810. void mmi_imps_ps_edit_contact_list_req(void)
  811. {
  812.     /*----------------------------------------------------------------*/
  813.     /* Local Variables                                                */
  814.     /*----------------------------------------------------------------*/
  815.     mmi_imps_edit_contact_list_req_struct *req =
  816.         (mmi_imps_edit_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_edit_contact_list_req_struct));
  817.     mmi_imps_group_inline_struct *grp_edit = imps_p->group_info.inline_edit_group;
  818.     /*----------------------------------------------------------------*/
  819.     /* Code Body                                                      */
  820.     /*----------------------------------------------------------------*/
  821.     IMPS_MEMSET(req, 0, mmi_imps_edit_contact_list_req_struct);
  822.     strcpy((S8*) req->contact_list_id, (S8*) imps_p->group_info.group_list[imps_p->group_info.curr_item].group_id);
  823.     req->display_name_p = TRUE;
  824.     pfnUnicodeStrcpy((S8*) req->display_name, (S8*) grp_edit->group_name);
  825.     if (grp_edit->open_status == IMPS_STATUS_OPEN)
  826.     {
  827.         req->authorize_pa |= (IMPS_PA_USER_AVAILABILITY | IMPS_PA_ONLINE_STATUS);
  828.     }
  829.     if (grp_edit->open_text == IMPS_STATUS_OPEN)
  830.     {
  831.         req->authorize_pa |= IMPS_PA_STATUS_TEXT;
  832.     }
  833.     if (grp_edit->open_pic == IMPS_STATUS_OPEN)
  834.     {
  835.         req->authorize_pa |= IMPS_PA_STATUS_CONTENT;
  836.     }
  837.     if (grp_edit->open_mood == IMPS_STATUS_OPEN)
  838.     {
  839.         req->authorize_pa |= IMPS_PA_STATUS_MOOD;
  840.     }
  841.     if (req->authorize_pa)
  842.     {
  843.         req->authorize_pa_p = TRUE;
  844.     }
  845.     req->subscribe_pa = IMPS_PA_ATTR_VALUE_NO_PIC;
  846.     req->subscribe_user_pa = IMPS_PA_ATTR_VALUE_NO_PIC;
  847.     req->subscribe_pa_user_p = TRUE;
  848.     req->subscribe_pa_p = TRUE;
  849.     req->return_content = TRUE;
  850.     SetProtocolEventHandler(mmi_imps_ps_edit_contact_list_rsp, MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_RSP);
  851.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_REQ, (void*)req, NULL);
  852. }
  853. /*****************************************************************************
  854.  * FUNCTION
  855.  *  mmi_imps_ps_edit_contact_list_rsp
  856.  * DESCRIPTION
  857.  *  Handler for MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_RSP.
  858.  * PARAMETERS
  859.  *  msg     [IN]        Result of response
  860.  * RETURNS
  861.  *  void
  862.  *****************************************************************************/
  863. void mmi_imps_ps_edit_contact_list_rsp(void *msg)
  864. {
  865.     /*----------------------------------------------------------------*/
  866.     /* Local Variables                                                */
  867.     /*----------------------------------------------------------------*/
  868.     mmi_imps_edit_contact_list_rsp_struct *rsp = (mmi_imps_edit_contact_list_rsp_struct*) msg;
  869.     /*----------------------------------------------------------------*/
  870.     /* Code Body                                                      */
  871.     /*----------------------------------------------------------------*/
  872.     /* restore current action */
  873.     imps_p->gen_info.curr_action = 0;
  874.     mmi_imps_group_edit_done(rsp->result);
  875. }
  876. /*****************************************************************************
  877.  * FUNCTION
  878.  *  mmi_imps_ps_add_contact_list_req
  879.  * DESCRIPTION
  880.  *  Send MSG_ID_MMI_IMPS_ADD_CONTACT_LIST_REQ to PS.
  881.  * PARAMETERS
  882.  *  void
  883.  * RETURNS
  884.  *  void
  885.  *****************************************************************************/
  886. void mmi_imps_ps_add_contact_list_req(void)
  887. {
  888.     /*----------------------------------------------------------------*/
  889.     /* Local Variables                                                */
  890.     /*----------------------------------------------------------------*/
  891.     mmi_imps_add_contact_list_req_struct *req =
  892.         (mmi_imps_add_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_add_contact_list_req_struct));
  893.     mmi_imps_group_inline_struct *grp_edit = imps_p->group_info.inline_edit_group;
  894.     S8 *buff = OslMalloc(IMPS_MAX_ID_LEN);
  895.     S8 *buff2 = OslMalloc(IMPS_MAX_ID_LEN);
  896.     /*----------------------------------------------------------------*/
  897.     /* Code Body                                                      */
  898.     /*----------------------------------------------------------------*/
  899.     IMPS_MEMSET(req, 0, mmi_imps_add_contact_list_req_struct);
  900.     /* generate group id */
  901.     UnicodeToAnsii((S8*) buff2, (S8*) grp_edit->group_name);
  902.     sprintf((S8*) buff, "%s/%s", imps_p->act_prof.username, buff2);
  903.     strcpy((S8*) req->contact_list_id, (S8*) buff);
  904.     OslMfree(buff);
  905.     OslMfree(buff2);
  906.     req->display_name_p = TRUE;
  907.     pfnUnicodeStrcpy((S8*) req->display_name, (S8*) grp_edit->group_name);
  908.     if (grp_edit->open_status == IMPS_STATUS_OPEN)
  909.     {
  910.         req->authorize_pa |= (IMPS_PA_USER_AVAILABILITY | IMPS_PA_ONLINE_STATUS);
  911.     }
  912.     if (grp_edit->open_text == IMPS_STATUS_OPEN)
  913.     {
  914.         req->authorize_pa |= IMPS_PA_STATUS_TEXT;
  915.     }
  916.     if (grp_edit->open_pic == IMPS_STATUS_OPEN)
  917.     {
  918.         req->authorize_pa |= IMPS_PA_STATUS_CONTENT;
  919.     }
  920.     if (grp_edit->open_mood == IMPS_STATUS_OPEN)
  921.     {
  922.         req->authorize_pa |= IMPS_PA_STATUS_MOOD;
  923.     }
  924.     req->subscribe_pa = IMPS_PA_ATTR_VALUE_NO_PIC;
  925.     if (req->authorize_pa)
  926.     {
  927.         /* authorize_pa_p = TRUE only when authorize_pa is not none */
  928.         req->authorize_pa_p = TRUE;
  929.     }
  930.     req->subscribe_pa_p = TRUE;
  931.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_ADD_CONTACT_LIST_REQ, (void*)req, NULL);
  932. }
  933. /*****************************************************************************
  934.  * FUNCTION
  935.  *  mmi_imps_ps_add_contact_list_rsp
  936.  * DESCRIPTION
  937.  *  Handler for MSG_ID_MMI_IMPS_ADD_CONTACT_LIST_RSP.
  938.  * PARAMETERS
  939.  *  msg     [IN]        Result of response
  940.  * RETURNS
  941.  *  void
  942.  *****************************************************************************/
  943. void mmi_imps_ps_add_contact_list_rsp(void *msg)
  944. {
  945.     /*----------------------------------------------------------------*/
  946.     /* Local Variables                                                */
  947.     /*----------------------------------------------------------------*/
  948.     mmi_imps_add_contact_list_rsp_struct *rsp = (mmi_imps_add_contact_list_rsp_struct*) msg;
  949.     /*----------------------------------------------------------------*/
  950.     /* Code Body                                                      */
  951.     /*----------------------------------------------------------------*/
  952.     /* restore current action */
  953.     imps_p->gen_info.curr_action = 0;
  954.     mmi_imps_group_edit_done(rsp->result);
  955. }
  956. /*****************************************************************************
  957.  * FUNCTION
  958.  *  mmi_imps_ps_del_cont_req
  959.  * DESCRIPTION
  960.  *  Send request to remove one contact from contact list.
  961.  * PARAMETERS
  962.  *  void
  963.  * RETURNS
  964.  *  void
  965.  *****************************************************************************/
  966. void mmi_imps_ps_del_cont_req(void)
  967. {
  968.     /*----------------------------------------------------------------*/
  969.     /* Local Variables                                                */
  970.     /*----------------------------------------------------------------*/
  971.     mmi_imps_edit_contact_list_req_struct *req =
  972.         (mmi_imps_edit_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_edit_contact_list_req_struct));
  973.     /*----------------------------------------------------------------*/
  974.     /* Code Body                                                      */
  975.     /*----------------------------------------------------------------*/
  976.     IMPS_MEMSET(req, 0, mmi_imps_edit_contact_list_req_struct);
  977.     strcpy((S8*) req->contact_list_id, (S8*) imps_p->cont_info.cont_list[imps_p->cont_info.curr_cont].group_id);
  978.     req->user_nick_list.entity_count = 1;
  979.     strcpy((S8*) req->user_nick_list.entity[0].id, (S8*) imps_p->cont_info.cont_list[imps_p->cont_info.curr_cont].id);
  980.     req->user_nick_list.entity[0].entity_type = IMPS_ENTITY_TYPE_USER;
  981.     SetProtocolEventHandler(mmi_imps_ps_del_cont_rsp, MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_RSP);
  982.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_REQ, (void*)req, NULL);
  983. }
  984. /*****************************************************************************
  985.  * FUNCTION
  986.  *  mmi_imps_ps_del_cont_rsp
  987.  * DESCRIPTION
  988.  *  Response handler for deleting one contact
  989.  * PARAMETERS
  990.  *  msg     [IN]        Result of response
  991.  * RETURNS
  992.  *  void
  993.  *****************************************************************************/
  994. void mmi_imps_ps_del_cont_rsp(void *msg)
  995. {
  996.     /*----------------------------------------------------------------*/
  997.     /* Local Variables                                                */
  998.     /*----------------------------------------------------------------*/
  999.     mmi_imps_edit_contact_list_rsp_struct *rsp = (mmi_imps_edit_contact_list_rsp_struct*) msg;
  1000.     /*----------------------------------------------------------------*/
  1001.     /* Code Body                                                      */
  1002.     /*----------------------------------------------------------------*/
  1003.     /* restore current action */
  1004.     imps_p->gen_info.curr_action = 0;
  1005.     mmi_imps_del_cont_finished((S32) rsp->result);
  1006. }
  1007. /*****************************************************************************
  1008.  * FUNCTION
  1009.  *  mmi_imps_ps_del_contact_list_req
  1010.  * DESCRIPTION
  1011.  *  Send request to delete a contact list
  1012.  * PARAMETERS
  1013.  *  void
  1014.  * RETURNS
  1015.  *  void
  1016.  *****************************************************************************/
  1017. void mmi_imps_ps_del_contact_list_req(void)
  1018. {
  1019.     /*----------------------------------------------------------------*/
  1020.     /* Local Variables                                                */
  1021.     /*----------------------------------------------------------------*/
  1022.     mmi_imps_del_contact_list_req_struct *req =
  1023.         (mmi_imps_del_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_del_contact_list_req_struct));
  1024.     /*----------------------------------------------------------------*/
  1025.     /* Code Body                                                      */
  1026.     /*----------------------------------------------------------------*/
  1027.     IMPS_MEMSET(req, 0, mmi_imps_del_contact_list_req_struct);
  1028.     strcpy((S8*) req->contact_list_id, (S8*) imps_p->group_info.group_list[imps_p->group_info.curr_item].group_id);
  1029.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_DEL_CONTACT_LIST_REQ, (void*)req, NULL);
  1030. }
  1031. /*****************************************************************************
  1032.  * FUNCTION
  1033.  *  mmi_imps_ps_del_contact_list_rsp
  1034.  * DESCRIPTION
  1035.  *  Response handler for deleting contact list
  1036.  * PARAMETERS
  1037.  *  msg     [IN]        Result of response
  1038.  * RETURNS
  1039.  *  void
  1040.  *****************************************************************************/
  1041. void mmi_imps_ps_del_contact_list_rsp(void *msg)
  1042. {
  1043.     /*----------------------------------------------------------------*/
  1044.     /* Local Variables                                                */
  1045.     /*----------------------------------------------------------------*/
  1046.     mmi_imps_del_contact_list_rsp_struct *rsp = (mmi_imps_del_contact_list_rsp_struct*) msg;
  1047.     /*----------------------------------------------------------------*/
  1048.     /* Code Body                                                      */
  1049.     /*----------------------------------------------------------------*/
  1050.     mmi_imps_group_del_done((S32) rsp->result);
  1051.     /* restore current action */
  1052.     imps_p->gen_info.curr_action = 0;
  1053. }
  1054. /*****************************************************************************
  1055.  * FUNCTION
  1056.  *  mmi_imps_add_cont_req
  1057.  * DESCRIPTION
  1058.  *  Send request to adding new contacts to a group
  1059.  * PARAMETERS
  1060.  *  group_id        [IN]        Groud id
  1061.  *  cont_id         [IN]        Contact id to be added
  1062.  *  nick_name       [IN]        Nick name of the contact
  1063.  * RETURNS
  1064.  *  void
  1065.  *****************************************************************************/
  1066. void mmi_imps_add_cont_req(U8 *group_id, U8 *cont_id, S8 *nick_name)
  1067. {
  1068.     /*----------------------------------------------------------------*/
  1069.     /* Local Variables                                                */
  1070.     /*----------------------------------------------------------------*/
  1071.     mmi_imps_edit_contact_list_req_struct *req =
  1072.         (mmi_imps_edit_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_edit_contact_list_req_struct));
  1073.     /*----------------------------------------------------------------*/
  1074.     /* Code Body                                                      */
  1075.     /*----------------------------------------------------------------*/
  1076.     IMPS_MEMSET(req, 0, mmi_imps_edit_contact_list_req_struct);
  1077.     strcpy((S8*) req->contact_list_id, (S8*) group_id);
  1078.     req->add_user = TRUE;
  1079.     req->user_nick_list.entity_count = 1;
  1080.     req->subscribe_pa_p = TRUE;
  1081.     req->subscribe_pa |= IMPS_PA_ATTR_VALUE_NO_PIC;
  1082.     req->subscribe_pa_user_p = TRUE;
  1083.     req->subscribe_user_pa |= IMPS_PA_ATTR_VALUE_NO_PIC;
  1084.     strcpy((S8*) req->user_nick_list.entity[0].id, (S8*) cont_id);
  1085.     req->user_nick_list.entity[0].entity_type = IMPS_ENTITY_TYPE_USER;
  1086.     if (pfnUnicodeStrlen(nick_name))
  1087.     {
  1088.         pfnUnicodeStrcpy((S8*) req->user_nick_list.entity[0].sname, (S8*) nick_name);
  1089.     }
  1090.     SetProtocolEventHandler(mmi_imps_add_cont_rsp, MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_RSP);
  1091.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_REQ, (void*)req, NULL);
  1092. }
  1093. /*****************************************************************************
  1094.  * FUNCTION
  1095.  *  mmi_imps_add_cont_rsp
  1096.  * DESCRIPTION
  1097.  *  Response handler of adding new contact
  1098.  * PARAMETERS
  1099.  *  msg     [IN]        Result of response
  1100.  * RETURNS
  1101.  *  void
  1102.  *****************************************************************************/
  1103. void mmi_imps_add_cont_rsp(void *msg)
  1104. {
  1105.     /*----------------------------------------------------------------*/
  1106.     /* Local Variables                                                */
  1107.     /*----------------------------------------------------------------*/
  1108.     mmi_imps_edit_contact_list_rsp_struct *rsp = (mmi_imps_edit_contact_list_rsp_struct*) msg;
  1109.     /*----------------------------------------------------------------*/
  1110.     /* Code Body                                                      */
  1111.     /*----------------------------------------------------------------*/
  1112.     /* restore current action */
  1113.     imps_p->gen_info.curr_action = 0;
  1114.     mmi_imps_add_cont_finished(rsp->result);
  1115.     /* to sync with block list */
  1116.     mmi_imps_ps_get_block_list_req();
  1117. }
  1118. /*****************************************************************************
  1119.  * FUNCTION
  1120.  *  mmi_imps_edit_cont_req
  1121.  * DESCRIPTION
  1122.  *  Send request to edit nick name of a contact
  1123.  * PARAMETERS
  1124.  *  group_id        [?]     
  1125.  *  cont_id         [?]     
  1126.  *  nick_name       [?]     
  1127.  * RETURNS
  1128.  *  void
  1129.  *****************************************************************************/
  1130. void mmi_imps_edit_cont_req(U8 *group_id, U8 *cont_id, S8 *nick_name)
  1131. {
  1132.     /*----------------------------------------------------------------*/
  1133.     /* Local Variables                                                */
  1134.     /*----------------------------------------------------------------*/
  1135.     mmi_imps_edit_contact_list_req_struct *req =
  1136.         (mmi_imps_edit_contact_list_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_edit_contact_list_req_struct));
  1137.     /*----------------------------------------------------------------*/
  1138.     /* Code Body                                                      */
  1139.     /*----------------------------------------------------------------*/
  1140.     IMPS_MEMSET(req, 0, mmi_imps_edit_contact_list_req_struct);
  1141.     strcpy((S8*) req->contact_list_id, (S8*) group_id);
  1142.     req->add_user = TRUE;
  1143.     req->user_nick_list.entity_count = 1;
  1144.     strcpy((S8*) req->user_nick_list.entity[0].id, (S8*) cont_id);
  1145.     req->user_nick_list.entity[0].entity_type = IMPS_ENTITY_TYPE_USER;
  1146.     if (pfnUnicodeStrlen(nick_name))
  1147.     {
  1148.         pfnUnicodeStrcpy((S8*) req->user_nick_list.entity[0].sname, (S8*) nick_name);
  1149.     }
  1150.     SetProtocolEventHandler(mmi_imps_edit_cont_rsp, MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_RSP);
  1151.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_EDIT_CONTACT_LIST_REQ, (void*)req, NULL);
  1152. }
  1153. /*****************************************************************************
  1154.  * FUNCTION
  1155.  *  mmi_imps_edit_cont_rsp
  1156.  * DESCRIPTION
  1157.  *  Response handler of editing nick name of a contact
  1158.  * PARAMETERS
  1159.  *  msg     [IN]        Result of response
  1160.  * RETURNS
  1161.  *  void
  1162.  *****************************************************************************/
  1163. void mmi_imps_edit_cont_rsp(void *msg)
  1164. {
  1165.     /*----------------------------------------------------------------*/
  1166.     /* Local Variables                                                */
  1167.     /*----------------------------------------------------------------*/
  1168.     mmi_imps_edit_contact_list_rsp_struct *rsp = (mmi_imps_edit_contact_list_rsp_struct*) msg;
  1169.     /*----------------------------------------------------------------*/
  1170.     /* Code Body                                                      */
  1171.     /*----------------------------------------------------------------*/
  1172.     mmi_imps_about_friend_edit_finish(rsp->result);
  1173.     imps_p->gen_info.curr_action = 0;
  1174. }
  1175. #define ADD_SEARCH_PS_PROT
  1176. /*****************************************************************************
  1177.  * FUNCTION
  1178.  *  mmi_imps_ps_search_req
  1179.  * DESCRIPTION
  1180.  *  Send MSG_ID_MMI_IMPS_SEARCH_REQ to PS.
  1181.  * PARAMETERS
  1182.  *  type        [IN]        Flag to indicate it's to search user or group
  1183.  * RETURNS
  1184.  *  void
  1185.  *****************************************************************************/
  1186. void mmi_imps_ps_search_req(U8 type)
  1187. {
  1188.     /*----------------------------------------------------------------*/
  1189.     /* Local Variables                                                */
  1190.     /*----------------------------------------------------------------*/
  1191.     mmi_imps_search_req_struct *req =
  1192.         (mmi_imps_search_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_search_req_struct));
  1193.     mmi_imps_search_struct *search_p = imps_p->search_data;
  1194.     /*----------------------------------------------------------------*/
  1195.     /* Code Body                                                      */
  1196.     /*----------------------------------------------------------------*/
  1197.     IMPS_MEMSET(req, 0, mmi_imps_search_req_struct);
  1198.     imps_p->search_result.count = 0;
  1199.     req->search_type = type;
  1200.     req->search_limit = IMPS_MAX_SEARCH_RESULT;
  1201.     req->user_onlinestatus = FALSE;
  1202.     if (type == IMPS_SEARCH_USER)
  1203.     {
  1204.         if (pfnUnicodeStrlen((S8*) search_p->username))
  1205.         {
  1206.             UnicodeToAnsii((S8*) req->user_id, (S8*) search_p->username);
  1207.         }
  1208.         if (pfnUnicodeStrlen((S8*) search_p->phone))
  1209.         {
  1210.             UnicodeToAnsii((S8*) req->user_mobile_number, (S8*) search_p->phone);
  1211.         }
  1212.         if (pfnUnicodeStrlen((S8*) search_p->alias))
  1213.         {
  1214.             pfnUnicodeStrcpy((S8*) req->user_alias, (S8*) search_p->alias);
  1215.         }
  1216.         if (pfnUnicodeStrlen((S8*) search_p->email))
  1217.         {
  1218.             UnicodeToAnsii((S8*) req->user_emailaddress, (S8*) search_p->email);
  1219.         }
  1220.     }
  1221.     else    /* group */
  1222.     {
  1223.         if (pfnUnicodeStrlen((S8*) search_p->room_name))
  1224.         {
  1225.             pfnUnicodeStrcpy((S8*) req->group_name, (S8*) search_p->room_name);
  1226.         }
  1227.         if (pfnUnicodeStrlen((S8*) search_p->room_topic))
  1228.         {
  1229.             pfnUnicodeStrcpy((S8*) req->group_topic, (S8*) search_p->room_topic);
  1230.         }
  1231.         if (pfnUnicodeStrlen((S8*) search_p->room_owner))
  1232.         {
  1233.             UnicodeToAnsii((S8*) req->group_user_id_owner, (S8*) search_p->room_owner);
  1234.         }
  1235.         if (pfnUnicodeStrlen((S8*) search_p->room_joined_user))
  1236.         {
  1237.             UnicodeToAnsii((S8*) req->group_user_id_joined, (S8*) search_p->room_joined_user);
  1238.         }
  1239.     }
  1240.     SetProtocolEventHandler(mmi_imps_ps_search_rsp, MSG_ID_MMI_IMPS_SEARCH_RSP);
  1241.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_SEARCH_REQ, (void*)req, NULL);
  1242. }
  1243. /*****************************************************************************
  1244.  * FUNCTION
  1245.  *  mmi_imps_ps_search_rsp
  1246.  * DESCRIPTION
  1247.  *  Handler for MSG_ID_MMI_IMPS_SEARCH_RSP. This handler is for searching contacts
  1248.  * PARAMETERS
  1249.  *  msg     [IN]        Result of response
  1250.  * RETURNS
  1251.  *  void
  1252.  *****************************************************************************/
  1253. void mmi_imps_ps_search_rsp(void *msg)
  1254. {
  1255.     /*----------------------------------------------------------------*/
  1256.     /* Local Variables                                                */
  1257.     /*----------------------------------------------------------------*/
  1258.     mmi_imps_search_rsp_struct *rsp = (mmi_imps_search_rsp_struct*) msg;
  1259.     U16 active_scr = GetActiveScreenId();
  1260.     /*----------------------------------------------------------------*/
  1261.     /* Code Body                                                      */
  1262.     /*----------------------------------------------------------------*/
  1263.     /* restore current action */
  1264.     imps_p->gen_info.curr_action = 0;
  1265.     if (rsp->result == IMPS_OK)
  1266.     {
  1267.         S32 i, j;
  1268.         S32 count = (S32) rsp->search_result.entity_count;
  1269.         /* copy data to local buffer */
  1270.         for (i = 0, j = (S32) imps_p->search_result.count; i < count && j < IMPS_MAX_SEARCH_RESULT; i++, j++)
  1271.         {
  1272.             mmi_imps_entity_struct *local_entity = &imps_p->search_result.entity[j];
  1273.             imps_entity_struct *ps_entity = &rsp->search_result.entity[i];
  1274.             strncpy((S8*) local_entity->id, (S8*) ps_entity->id, (IMPS_MAX_ID_LEN - 1));
  1275.             pfnUnicodeStrncpy((S8*) local_entity->sname, (S8*) ps_entity->sname, IMPS_MAX_NAME_LEN);
  1276.         }
  1277.         imps_p->search_result.count = (U8) j;
  1278.         if (rsp->completion_flag)
  1279.         {
  1280.             if (active_scr == SCR_ID_IMPS_PROGRESS)
  1281.             {
  1282.                 mmi_imps_entry_search_result(); /* display list of user */
  1283.             }
  1284.             else
  1285.             {
  1286.                 HistoryReplace(SCR_ID_IMPS_PROGRESS, SCR_ID_IMPS_SEARCH_RESULT, mmi_imps_entry_search_result);
  1287.                 return;
  1288.             }
  1289.         }
  1290.         else
  1291.         {
  1292.             return; /* do nothing */
  1293.         }
  1294.     }
  1295.     else
  1296.     {
  1297.         if (imps_p->search_result.count == 0)
  1298.         {
  1299.             mmi_imps_util_disp_err_popup(mmi_imps_util_get_err_str(rsp->result));
  1300.             if (active_scr == SCR_ID_IMPS_PROGRESS)
  1301.             {
  1302.                 DeleteScreenIfPresent(SCR_ID_IMPS_PROGRESS);
  1303.             }
  1304.             else
  1305.             {
  1306.                 mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_SEARCH_OPT);
  1307.             }
  1308.             return;
  1309.         }
  1310.         else
  1311.         {
  1312.             if (active_scr == SCR_ID_IMPS_PROGRESS)
  1313.             {
  1314.                 mmi_imps_entry_search_result(); /* display list of user */
  1315.             }
  1316.             else
  1317.             {
  1318.                 HistoryReplace(SCR_ID_IMPS_PROGRESS, SCR_ID_IMPS_SEARCH_RESULT, mmi_imps_entry_search_result);
  1319.                 DeleteScreenIfPresent(SCR_ID_IMPS_SEARCH_OPT);
  1320.                 if (imps_p->search_result.search_cause == IMPS_SEARCH_CONT)
  1321.                 {
  1322.                     DeleteScreenIfPresent(SCR_ID_IMPS_CONT_SEARCH);
  1323.                 }
  1324.                 else
  1325.                 {
  1326.                     DeleteScreenIfPresent(SCR_ID_IMPS_CHAT_ROOM_SEARCH);
  1327.                 }
  1328.                 return;
  1329.             }
  1330.         }
  1331.     }
  1332.     /* determine the screen to go back */
  1333.     if (imps_p->search_result.search_cause == IMPS_SEARCH_CONT)
  1334.     {
  1335.         mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_ADD_CONT);
  1336.     }
  1337.     else
  1338.     {
  1339.         mmi_imps_util_del_scr_after_progress(SCR_ID_IMPS_CHAT_ROOM);
  1340.     }
  1341. }
  1342. /*****************************************************************************
  1343.  * FUNCTION
  1344.  *  mmi_imps_ps_abort_search_req
  1345.  * DESCRIPTION
  1346.  *  Send MSG_ID_MMI_IMPS_ABORT_SEARCH_REQ to PS
  1347.  * PARAMETERS
  1348.  *  void
  1349.  *  msg(?)      [IN]        Result of response
  1350.  * RETURNS
  1351.  *  void
  1352.  *****************************************************************************/
  1353. void mmi_imps_ps_abort_search_req(void)
  1354. {
  1355.     /*----------------------------------------------------------------*/
  1356.     /* Local Variables                                                */
  1357.     /*----------------------------------------------------------------*/
  1358.     /*----------------------------------------------------------------*/
  1359.     /* Code Body                                                      */
  1360.     /*----------------------------------------------------------------*/
  1361.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_ABORT_SEARCH_REQ, NULL, NULL);
  1362. }
  1363. /*****************************************************************************
  1364.  * FUNCTION
  1365.  *  mmi_imps_ps_abort_search_rsp
  1366.  * DESCRIPTION
  1367.  *  Handler for MSG_ID_MMI_IMPS_ABORT_SEARCH_RSP. This handler is for searching contacts
  1368.  * PARAMETERS
  1369.  *  msg     [IN]        Result of response
  1370.  * RETURNS
  1371.  *  void
  1372.  *****************************************************************************/
  1373. void mmi_imps_ps_abort_search_rsp(void *msg)
  1374. {
  1375.     /*----------------------------------------------------------------*/
  1376.     /* Local Variables                                                */
  1377.     /*----------------------------------------------------------------*/
  1378.     /*----------------------------------------------------------------*/
  1379.     /* Code Body                                                      */
  1380.     /*----------------------------------------------------------------*/
  1381.     mmi_imps_abort_search_finish();
  1382.     /* restore current action */
  1383.     imps_p->gen_info.curr_action = 0;
  1384. }
  1385. #define PA_PS_IMPS
  1386. /*****************************************************************************
  1387.  * FUNCTION
  1388.  *  mmi_imps_sync_cont_list
  1389.  * DESCRIPTION
  1390.  *  Remove dangling contacts and flush data to file system
  1391.  * PARAMETERS
  1392.  *  void
  1393.  * RETURNS
  1394.  *  void
  1395.  *****************************************************************************/
  1396. void mmi_imps_sync_cont_list(void)
  1397. {
  1398.     /*----------------------------------------------------------------*/
  1399.     /* Local Variables                                                */
  1400.     /*----------------------------------------------------------------*/
  1401.     S32 i, j;
  1402.     S32 count = (S32) imps_p->cont_info.no_cont;
  1403.     S32 no_group = (S32) imps_p->group_info.no_group;
  1404.     mmi_imps_cont_info_struct *cont_info = &imps_p->cont_info;
  1405.     /*----------------------------------------------------------------*/
  1406.     /* Code Body                                                      */
  1407.     /*----------------------------------------------------------------*/
  1408.     /* reset number of members */
  1409.     for (j = 0; j < no_group; j++)
  1410.     {
  1411.         imps_p->group_info.group_list[j].no_users = 0;
  1412.     }
  1413.     /* sync contacts -- remove dangling contacts */
  1414.     for (i = 1; i < count; i++) /* start from 1 to neglect MySelf */
  1415.     {
  1416.         if ((cont_info->cont_list[i].comm_state & IMPS_CONT_PA_READY) == 0)
  1417.         {
  1418.             if (i < (count - 1))
  1419.             {
  1420.                 memcpy(
  1421.                     &cont_info->cont_list[i],
  1422.                     &cont_info->cont_list[i + 1],
  1423.                     (count - i - 1) * sizeof(mmi_imps_cont_struct));
  1424.             }
  1425.             count--;
  1426.             memset(&cont_info->cont_list[count], 0, sizeof(mmi_imps_cont_struct));
  1427.         }
  1428.         else
  1429.         {
  1430.             /* find out the contact list the user belongs to */
  1431.             for (j = 0; j < no_group; j++)
  1432.                 if (mmi_imps_util_is_id_same
  1433.                     ((S8*) cont_info->cont_list[i].group_id, (S8*) imps_p->group_info.group_list[j].group_id))
  1434.                 {
  1435.                     imps_p->group_info.group_list[j].no_users++;
  1436.                 }
  1437.         }
  1438.     }
  1439.     imps_p->cont_info.no_cont = (U8) count;
  1440.     /* flush data to file system */
  1441.     mmi_imps_util_write_cont();
  1442.     mmi_imps_util_write_group();
  1443.     /* redraw contact list */
  1444.     mmi_imps_cont_redraw_list();
  1445. }
  1446. /*****************************************************************************
  1447.  * FUNCTION
  1448.  *  mmi_imps_ps_get_pa_req
  1449.  * DESCRIPTION
  1450.  *  Send MSG_ID_MMI_IMPS_GET_PA_REQ to PS.
  1451.  * PARAMETERS
  1452.  *  data        [IN]        Pointer to contact list
  1453.  * RETURNS
  1454.  *  void
  1455.  *****************************************************************************/
  1456. void mmi_imps_ps_get_pa_req(void *data)
  1457. {
  1458.     /*----------------------------------------------------------------*/
  1459.     /* Local Variables                                                */
  1460.     /*----------------------------------------------------------------*/
  1461.     S32 i;
  1462.     mmi_imps_view_contact_list_rsp_struct *ids = (mmi_imps_view_contact_list_rsp_struct*) data;
  1463.     S32 count = (S32) ids->user_nick_list.entity_count;
  1464.     mmi_imps_get_pa_req_struct *req =
  1465.         (mmi_imps_get_pa_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_get_pa_req_struct));
  1466.     /*----------------------------------------------------------------*/
  1467.     /* Code Body                                                      */
  1468.     /*----------------------------------------------------------------*/
  1469.     IMPS_MEMSET(req, 0, mmi_imps_get_pa_req_struct);
  1470.     req->user_id_list.entity_count = (U8) ids->user_nick_list.entity_count;
  1471.     req->subscribe_pa = IMPS_PA_ATTR_VALUE_NO_PIC;
  1472.     for (i = 0; i < count; i++)
  1473.     {
  1474.         strcpy((S8*) req->user_id_list.entity[i].id, (S8*) ids->user_nick_list.entity[i].id);
  1475.     }
  1476.     SetProtocolEventHandler(mmi_imps_ps_get_pa_rsp, MSG_ID_MMI_IMPS_GET_PA_RSP);
  1477.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_GET_PA_REQ, (void*)req, NULL);
  1478.     /* restore current action -- do not have to store action for background update cases */
  1479.     imps_p->gen_info.curr_action = 0;
  1480. }
  1481. /*****************************************************************************
  1482.  * FUNCTION
  1483.  *  mmi_imps_ps_get_pa_rsp
  1484.  * DESCRIPTION
  1485.  *  Handler for MSG_ID_MMI_IMPS_GET_PA_RSP.
  1486.  * PARAMETERS
  1487.  *  msg     [IN]        Result of response
  1488.  * RETURNS
  1489.  *  void
  1490.  *****************************************************************************/
  1491. void mmi_imps_ps_get_pa_rsp(void *msg)
  1492. {
  1493.     /*----------------------------------------------------------------*/
  1494.     /* Local Variables                                                */
  1495.     /*----------------------------------------------------------------*/
  1496.     mmi_imps_get_pa_rsp_struct *rsp = (mmi_imps_get_pa_rsp_struct*) msg;
  1497.     /*----------------------------------------------------------------*/
  1498.     /* Code Body                                                      */
  1499.     /*----------------------------------------------------------------*/
  1500.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_LOGOUT_REQ || imps_p->gen_info.is_login == FALSE)
  1501.     {
  1502.         return;
  1503.     }
  1504.     /* restore current action */
  1505.     imps_p->gen_info.curr_action = 0;
  1506.     if (rsp->result == IMPS_OK)
  1507.     {
  1508.         S32 i, j;
  1509.         S32 ps_count = (S32) rsp->pa_val_list_info.entity_num;
  1510.         S32 local_count = (S32) imps_p->cont_info.no_cont;
  1511.         imps_pa_value_struct *pa_value;
  1512.         mmi_imps_cont_struct *cont;
  1513.         imps_pa_value_publisher_struct *pa_value_publisher = OslMalloc(sizeof(imps_pa_value_publisher_struct));
  1514.         FS_HANDLE fileHandle = 0;
  1515.         U32 len;
  1516.         S32 result;
  1517.         fileHandle = FS_Open((const WCHAR *) rsp->pa_val_list_info.entity_list_file_path, FS_READ_ONLY);
  1518.         /* update information of users */
  1519.         for (i = 0; i < ps_count; i++)
  1520.         {
  1521.             /* keneng : read pa value from file */
  1522.             if (fileHandle > 0)
  1523.             {
  1524.                 result = FS_Read(fileHandle, (void *) pa_value_publisher, sizeof(imps_pa_value_publisher_struct), &len);
  1525.             }
  1526.             else
  1527.             {
  1528.                 break;
  1529.             }
  1530.             
  1531.             for (j = 0; j < local_count; j++)
  1532.             {
  1533.                 if (result < FS_NO_ERROR)
  1534.                 {
  1535.                     break;
  1536.                 }
  1537.                 
  1538.                 if (imps_p->cont_info.cont_list[j].comm_state & IMPS_CONT_PA_READY)
  1539.                 {
  1540.                     if (mmi_imps_util_is_id_same
  1541.                         ((S8*) imps_p->cont_info.cont_list[j].id,
  1542.                          (S8*) pa_value_publisher->publisher_user_id))
  1543.                     {
  1544.                         cont = &imps_p->cont_info.cont_list[j];
  1545.                         pa_value = &pa_value_publisher->pa_value;
  1546.                         /* default availability */
  1547.                         cont->availability = IMPS_PA_USER_NOT_AVAILABLE;
  1548.                         if (pa_value->online_status_qualifier)  /* if user is online, the availability depends on his setting */
  1549.                         {
  1550.                             if (pa_value->online_status == TRUE)
  1551.                             {
  1552.                                 if (pa_value->user_availability_qualifier)
  1553.                                 {
  1554.                                     cont->availability = pa_value->user_availability;
  1555.                                 }
  1556.                                 else
  1557.                                 {
  1558.                                     cont->availability = IMPS_PA_USER_AVAILABLE;
  1559.                                 }
  1560.                             }
  1561.                         }
  1562.                         else
  1563.                         {
  1564.                             if (pa_value->user_availability_qualifier)
  1565.                             {
  1566.                                 cont->availability = pa_value->user_availability;
  1567.                             }
  1568.                         }
  1569.                         if (pa_value->status_mood_qualifier)
  1570.                         {
  1571.                             cont->mood = pa_value->status_mood;
  1572.                         }
  1573.                         if (pa_value->status_text_qualifier)
  1574.                         {
  1575.                             pfnUnicodeStrcpy((S8*) cont->prof_text, (S8*) pa_value->status_text);
  1576.                         }
  1577.                         /*
  1578.                          * currently no usage 
  1579.                          * if(pa_value->status_content_qualifier)
  1580.                          */
  1581.                     }
  1582.                 }
  1583.             }
  1584.         }
  1585.         FS_Close(fileHandle);
  1586.         FS_Delete((const WCHAR *) rsp->pa_val_list_info.entity_list_file_path);
  1587.         OslMfree(pa_value_publisher);
  1588.         mmi_imps_cont_redraw_list();
  1589.     }
  1590.     else
  1591.     {
  1592.         /* do nothing */
  1593.     }
  1594.     mmi_imps_ps_view_next_contact_list();
  1595. }
  1596. /*****************************************************************************
  1597.  * FUNCTION
  1598.  *  mmi_imps_ps_get_about_me_rsp
  1599.  * DESCRIPTION
  1600.  *  Response handler of MSG_ID_MMI_IMPS_GET_PA_REQ for about me
  1601.  * PARAMETERS
  1602.  *  msg     [IN]        Result of response
  1603.  * RETURNS
  1604.  *  void
  1605.  *****************************************************************************/
  1606. void mmi_imps_ps_get_about_me_rsp(void *msg)
  1607. {
  1608.     /*----------------------------------------------------------------*/
  1609.     /* Local Variables                                                */
  1610.     /*----------------------------------------------------------------*/
  1611.     mmi_imps_get_pa_rsp_struct *rsp = (mmi_imps_get_pa_rsp_struct*) msg;
  1612.     /*----------------------------------------------------------------*/
  1613.     /* Code Body                                                      */
  1614.     /*----------------------------------------------------------------*/
  1615.     if (imps_p->gen_info.curr_action == MSG_ID_MMI_IMPS_LOGOUT_REQ || imps_p->gen_info.is_login == FALSE)
  1616.     {
  1617.         return;
  1618.     }
  1619.     if (rsp->result == IMPS_OK)
  1620.     {
  1621.         mmi_imps_nvram_struct *nvram_buff = (mmi_imps_nvram_struct*) OslMalloc(sizeof(mmi_imps_nvram_struct));
  1622.         imps_pa_value_struct *pa_value;
  1623.         mmi_imps_cont_struct *cont;
  1624.         imps_pa_value_publisher_struct *pa_value_publisher = OslMalloc(sizeof(imps_pa_value_publisher_struct));
  1625.         FS_HANDLE fileHandle = 0;
  1626.         U32 len;
  1627.         fileHandle = FS_Open((const WCHAR *) rsp->pa_val_list_info.entity_list_file_path, FS_READ_ONLY);
  1628.         if (fileHandle > 0)
  1629.         {
  1630.             FS_Read(fileHandle, (void *) pa_value_publisher, sizeof(imps_pa_value_publisher_struct), &len);
  1631.         }
  1632.         /* read data from NVRAM */
  1633.         mmi_imps_util_read_nvram((void*)nvram_buff);
  1634.         cont = &imps_p->cont_info.cont_list[0];
  1635.         pa_value = &pa_value_publisher->pa_value;
  1636.         /* default regarded as online */
  1637.         cont->availability = IMPS_PA_USER_AVAILABLE;
  1638.         if (pa_value->online_status_qualifier)
  1639.         {
  1640.             if (pa_value->online_status == TRUE)
  1641.             {
  1642.                 if (pa_value->user_availability_qualifier)
  1643.                 {
  1644.                     cont->availability = pa_value->user_availability;
  1645.                 }
  1646.             }
  1647.             else
  1648.             {
  1649.                 cont->availability = IMPS_PA_USER_NOT_AVAILABLE;
  1650.             }
  1651.         }
  1652.         if (pa_value->status_mood_qualifier)
  1653.         {
  1654.             cont->mood = pa_value->status_mood;
  1655.         }
  1656.         else
  1657.         {
  1658.             cont->mood = nvram_buff->about_me.mood;
  1659.         }
  1660.         if (pa_value->status_text_qualifier)
  1661.         {
  1662.             pfnUnicodeStrcpy((S8*) cont->prof_text, (S8*) pa_value->status_text);
  1663.             pfnUnicodeStrcpy((S8*) nvram_buff->about_me.my_prof, (S8*) cont->prof_text);
  1664.         }
  1665.         else
  1666.         {
  1667.             pfnUnicodeStrcpy((S8*) cont->prof_text, (S8*) nvram_buff->about_me.my_prof);
  1668.         }
  1669.         FS_Close(fileHandle);
  1670.         FS_Delete((const WCHAR *) rsp->pa_val_list_info.entity_list_file_path);
  1671.         OslMfree(pa_value_publisher);
  1672.         /* status */
  1673.         nvram_buff->about_me.status = (U8) cont->availability;
  1674.         nvram_buff->about_me.mood = (U8) cont->mood;
  1675.         mmi_imps_util_write_nvram((void*)nvram_buff);
  1676.         OslMfree(nvram_buff);
  1677.         mmi_imps_cont_redraw_list();
  1678.     }
  1679.     mmi_imps_ps_get_block_list_req();
  1680. }
  1681. /*****************************************************************************
  1682.  * FUNCTION
  1683.  *  mmi_imps_ps_get_about_me_req
  1684.  * DESCRIPTION
  1685.  *  Send MSG_ID_MMI_IMPS_GET_PA_REQ to get detailed information of myself.
  1686.  * PARAMETERS
  1687.  *  void
  1688.  * RETURNS
  1689.  *  void
  1690.  *****************************************************************************/
  1691. void mmi_imps_ps_get_about_me_req(void)
  1692. {
  1693.     /*----------------------------------------------------------------*/
  1694.     /* Local Variables                                                */
  1695.     /*----------------------------------------------------------------*/
  1696.     mmi_imps_get_pa_req_struct *req =
  1697.         (mmi_imps_get_pa_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_get_pa_req_struct));
  1698.     /*----------------------------------------------------------------*/
  1699.     /* Code Body                                                      */
  1700.     /*----------------------------------------------------------------*/
  1701.     req->user_id_list.entity_count = 1;
  1702.     req->subscribe_pa = IMPS_PA_ATTR_VALUE_NO_PIC;
  1703.     strcpy((S8*) req->user_id_list.entity[0].id, (S8*) imps_p->cont_info.cont_list[0].id);
  1704.     req->user_id_list.entity[0].entity_type = 0;
  1705.     SetProtocolEventHandler(mmi_imps_ps_get_about_me_rsp, MSG_ID_MMI_IMPS_GET_PA_RSP);
  1706.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_GET_PA_REQ, (void*)req, NULL);
  1707.     /* restore current action -- do not have to store action for background update cases */
  1708.     imps_p->gen_info.curr_action = 0;
  1709. }
  1710. /*****************************************************************************
  1711.  * FUNCTION
  1712.  *  mmi_imps_ps_get_single_pa_req
  1713.  * DESCRIPTION
  1714.  *  Send MSG_ID_MMI_IMPS_GET_PA_REQ to get detailed information of a user.
  1715.  * PARAMETERS
  1716.  *  id      [IN]        Id of contact to get
  1717.  * RETURNS
  1718.  *  void
  1719.  *****************************************************************************/
  1720. void mmi_imps_ps_get_single_pa_req(U8 *id)
  1721. {
  1722.     /*----------------------------------------------------------------*/
  1723.     /* Local Variables                                                */
  1724.     /*----------------------------------------------------------------*/
  1725.     mmi_imps_get_pa_req_struct *req =
  1726.         (mmi_imps_get_pa_req_struct*) OslConstructDataPtr(sizeof(mmi_imps_get_pa_req_struct));
  1727.     /*----------------------------------------------------------------*/
  1728.     /* Code Body                                                      */
  1729.     /*----------------------------------------------------------------*/
  1730.     IMPS_MEMSET(req, 0, mmi_imps_get_pa_req_struct);
  1731.     req->user_id_list.entity_count = 1;
  1732.     req->user_id_list.entity[0].entity_type = IMPS_ENTITY_TYPE_USER;
  1733.     req->subscribe_pa = IMPS_PA_ATTR_VALUE;
  1734.     strcpy((S8*) req->user_id_list.entity[0].id, (S8*) id);
  1735.     mmi_imps_ps_send_msg(MSG_ID_MMI_IMPS_GET_PA_REQ, (void*)req, NULL);
  1736.     SetProtocolEventHandler(mmi_imps_ps_get_single_pa_rsp, MSG_ID_MMI_IMPS_GET_PA_RSP);
  1737. }
  1738. /*****************************************************************************
  1739.  * FUNCTION
  1740.  *  mmi_imps_ps_get_single_pa_rsp
  1741.  * DESCRIPTION
  1742.  *  Handler for MSG_ID_MMI_IMPS_GET_PA_RSP.
  1743.  * PARAMETERS
  1744.  *  msg     [IN]        Result of response
  1745.  * RETURNS
  1746.  *  void
  1747.  *****************************************************************************/
  1748. void mmi_imps_ps_get_single_pa_rsp(void *msg)
  1749. {
  1750.     /*----------------------------------------------------------------*/
  1751.     /* Local Variables                                                */
  1752.     /*----------------------------------------------------------------*/
  1753.     mmi_imps_get_pa_rsp_struct *rsp = (mmi_imps_get_pa_rsp_struct*) msg;
  1754.     /*----------------------------------------------------------------*/
  1755.     /* Code Body                                                      */
  1756.     /*----------------------------------------------------------------*/
  1757.     /* restore current action */
  1758.     imps_p->gen_info.curr_action = 0;
  1759.     if (rsp->result == IMPS_OK)
  1760.     {
  1761.         imps_pa_value_publisher_struct *pa_value_publisher = OslMalloc(sizeof(imps_pa_value_publisher_struct));
  1762.         FS_HANDLE fileHandle = 0;
  1763.         U32 len;
  1764.         S32 result = FS_ERROR_RESERVED;
  1765.         fileHandle = FS_Open((const WCHAR *) rsp->pa_val_list_info.entity_list_file_path, FS_READ_ONLY);
  1766.         if (fileHandle > 0)
  1767.         {
  1768.             result = FS_Read(fileHandle, (void *) pa_value_publisher, sizeof(imps_pa_value_publisher_struct), &len);