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

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.  * jBrowserDRMHandler.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This is DRm handler file for Browser
  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.  * removed!
  59.  * removed!
  60.  *
  61.  * removed!
  62.  * removed!
  63.  * removed!
  64.  *
  65.  * removed!
  66.  * removed!
  67.  * removed!
  68.  *
  69.  * removed!
  70.  * removed!
  71.  * removed!
  72.  *
  73.  *------------------------------------------------------------------------------
  74.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  75.  *============================================================================
  76.  ****************************************************************************/
  77. #ifndef _JBROWSERDRMHANDLER_C_
  78. #define _JBROWSERDRMHANDLER_C_
  79. #include "MMI_features.h"
  80. #ifdef __DRM_SUPPORT__
  81. #if defined (JATAAYU_SUPPORT) && defined (WAP_SUPPORT)
  82. #include "jBrowserDRMHandler.h"
  83. #include "JBrowserMMITypes.h"
  84. #include "drm_gprot.h"
  85. #include "jdd_MessagingConfig.h"
  86. #include "miscutils.h"
  87. brw_drm_context_struct g_brw_drm_cntx;
  88. /*****************************************************************************
  89.  * FUNCTION
  90.  *  jBrowser_drm_indication_handler
  91.  * DESCRIPTION
  92.  *  -
  93.  * PARAMETERS
  94.  *  pvDRMArg                    [?]         
  95.  *  pcMimeType                  [?]         
  96.  *  pstMimeContent              [?]         
  97.  *  cbResponseHandler           [IN]        
  98.  *  cbMoreContentHandler        [IN]        
  99.  *  pvAppArg                    [?]         
  100.  *  puiDRMRefID                 [?]         
  101.  *  pstDRMInfo                  [?]         
  102.  *  -(?)
  103.  * RETURNS
  104.  *  -
  105.  *****************************************************************************/
  106. JC_RETCODE jBrowser_drm_indication_handler(
  107.             void *pvDRMArg,
  108.             JC_INT8 *pcMimeType,
  109.             ST_MIME_CONTENT *pstMimeContent,
  110.             CB_DRM_RESPONSE_HANDLER cbResponseHandler,
  111.             CB_DRM_MORE_CONTENT_HANDLER cbMoreContentHandler,
  112.             void *pvAppArg,
  113.             JC_UINT32 *puiDRMRefID,
  114.             ST_DRM_PARSED_INFO *pstDRMInfo)
  115. {
  116.     /*----------------------------------------------------------------*/
  117.     /* Local Variables                                                */
  118.     /*----------------------------------------------------------------*/
  119.     /*----------------------------------------------------------------*/
  120.     /* Code Body                                                      */
  121.     /*----------------------------------------------------------------*/
  122.     g_brw_drm_cntx.drm_arg = pvDRMArg;
  123.     g_brw_drm_cntx.drm_content = pstMimeContent;
  124.     g_brw_drm_cntx.drm_response_callback = cbResponseHandler;
  125.     g_brw_drm_cntx.drm_app_arg = pvAppArg;
  126.     if (!jc_strcmp(pcMimeType, "application/vnd.oma.drm.message"))
  127.     {
  128.         g_brw_drm_cntx.drm_type = DRM_TYPE_MESSAGE;
  129.     }
  130.     else if (!jc_strcmp(pcMimeType, "application/vnd.oma.drm.content"))
  131.     {
  132.         g_brw_drm_cntx.drm_type = DRM_TYPE_CONTENT;
  133.     }
  134.     *puiDRMRefID = (JC_UINT32) g_brw_drm_cntx.drm_content->uData.pmFileName;
  135.     g_brw_drm_cntx.drm_ref_id = *puiDRMRefID;
  136.     jBrowser_send_parse_drm_event();
  137.     return JC_ERR_ASYNC_CALL;
  138. }
  139. /*****************************************************************************
  140.  * FUNCTION
  141.  *  jBrowser_send_parse_drm_event
  142.  * DESCRIPTION
  143.  *  -
  144.  * PARAMETERS
  145.  *  void
  146.  *  -(?)
  147.  * RETURNS
  148.  *  -(?)
  149.  *****************************************************************************/
  150. void jBrowser_send_parse_drm_event(void)
  151. {
  152.     /*----------------------------------------------------------------*/
  153.     /* Local Variables                                                */
  154.     /*----------------------------------------------------------------*/
  155.     JC_RETCODE iRet = JC_OK;
  156.     JC_EVENT_DATA eventData = {0};
  157.     /*----------------------------------------------------------------*/
  158.     /* Code Body                                                      */
  159.     /*----------------------------------------------------------------*/
  160.     jc_memset(&eventData, 0, sizeof(JC_EVENT_DATA));
  161.     eventData.pEventInfo = NULL;
  162.     eventData.uiEventInfoSize = 0;
  163.     eventData.iEventType = E_BRW_PARSE_DRM_EVENT;
  164.     eventData.destTaskInfo.iAppID = E_TASK_BROWSER_UI;
  165.     eventData.destTaskInfo.iTaskID = E_TASK_BROWSER_UI;
  166.     eventData.srcTaskInfo.iAppID = E_TASK_BROWSER_UI;
  167.     eventData.srcTaskInfo.iTaskID = E_TASK_BROWSER_UI;
  168.     iRet = jdd_QueueSend(&eventData);
  169.     if (JC_OK != iRet)
  170.     {
  171.         return;
  172.     }
  173. }
  174. /*****************************************************************************
  175.  * FUNCTION
  176.  *  jBrowser_parse_drm_content
  177.  * DESCRIPTION
  178.  *  -
  179.  * PARAMETERS
  180.  *  void
  181.  *  -(?)
  182.  * RETURNS
  183.  *  -(?)
  184.  *****************************************************************************/
  185. void jBrowser_parse_drm_content(void)
  186. {
  187.     /*----------------------------------------------------------------*/
  188.     /* Local Variables                                                */
  189.     /*----------------------------------------------------------------*/
  190.     ST_DRM_PARSED_INFO parsed_drm_info;
  191.     JC_RETCODE eRet = JC_OK;
  192.     JC_CHAR *drm_content_fname;
  193.     JDD_FSHANDLE fs_handle = NULL;
  194.     U32 drm_ret = 0;
  195.     /*----------------------------------------------------------------*/
  196.     /* Code Body                                                      */
  197.     /*----------------------------------------------------------------*/
  198.     if (!fs_handle)
  199.     {
  200.         eRet = jdd_FSInitialize(&fs_handle);
  201.         if (eRet != JC_OK)
  202.         {
  203.             goto ERROR_HANDLE;
  204.         }
  205.     }
  206.     parsed_drm_info.pstRightsObject = (ST_DRM_RIGHTS_OBJECT*) jdd_MemAlloc(sizeof(ST_DRM_RIGHTS_OBJECT), 1);
  207.     if (parsed_drm_info.pstRightsObject == NULL)
  208.     {
  209.         eRet = JC_ERR_MEMORY_ALLOCATION;
  210.         goto ERROR_HANDLE;
  211.     }
  212.     parsed_drm_info.pstRightsObject->pcContentID = NULL;
  213.     parsed_drm_info.pstRightsObject->eStatusCode = E_DRM_STATUS_OK;
  214.     parsed_drm_info.pstRightsObject->bIsRender = FALSE;
  215.     parsed_drm_info.pstRightsObject->bIsForwardLock = TRUE;
  216.     parsed_drm_info.pstRightsObject->uiStartTime = 0;
  217.     parsed_drm_info.pstRightsObject->uiDuration = 0;
  218.     parsed_drm_info.pstRightsObject->pstNext = NULL;
  219.     parsed_drm_info.pcContentType = NULL;
  220.     parsed_drm_info.stMimeContent.pucHeader = NULL;
  221.     parsed_drm_info.stMimeContent.uiHeaderLen = 0;
  222.     parsed_drm_info.stMimeContent.bIsBinaryHeader = FALSE;
  223.     parsed_drm_info.stMimeContent.eDataType = E_MIME_FILENAME;
  224.     parsed_drm_info.stMimeContent.uData.pucBuffer = NULL;
  225.     parsed_drm_info.stMimeContent.uData.pmFileName = NULL;
  226.     parsed_drm_info.stMimeContent.uiBufferLen = 0;
  227.     parsed_drm_info.stMimeContent.bHasMoreData = FALSE;
  228.     drm_content_fname =
  229.         (JC_CHAR*) jdd_FSFileNameTranslate(fs_handle, (JC_CHAR*) g_brw_drm_cntx.drm_content->uData.pmFileName);
  230.     if (drm_content_fname == NULL)
  231.     {
  232.         eRet = JC_ERR_MEMORY_ALLOCATION;
  233.         goto ERROR_HANDLE;
  234.     }
  235.     if (g_brw_drm_cntx.drm_type == DRM_TYPE_MESSAGE)
  236.     {
  237.         /* JC_CHAR                      tmp_ext_str[50]; */
  238.         JC_CHAR *encrypted_filename;
  239.         FS_HANDLE file_handle = NULL;
  240.         DRM_RIGHTS_STRUCT *drm_rights = NULL;
  241.         jdd_FSGetDownloadFileName(&encrypted_filename);
  242.         //AnsiiToUnicodeString((PS8)&tmp_ext_str, (PS8)"temp_file.extension");
  243.         //drm_ret  = DRM_process_direct_file((kal_uint8*)"application/vnd.oma.drm.message", (kal_wchar*)drm_content_fname, (kal_wchar*)tmp_ext_str, &content_length);
  244.         drm_ret = DRM_process_virtual_file(
  245.                     (kal_uint8*) "application/vnd.oma.drm.message",
  246.                     (kal_wchar*) drm_content_fname,
  247.                     (kal_wchar*) encrypted_filename);
  248.         /* if(drm_ret > DRM_PROC_RESULT_NO_PERMISSION) */
  249.         if (drm_ret == DRM_PROC_RESULT_OK)
  250.         {
  251.             file_handle = DRM_open_file((kal_wchar*) encrypted_filename, FS_READ_ONLY, DRM_PERMISSION_NONE);
  252.             if (file_handle <= 0)
  253.             {
  254.                 DRM_close_file(file_handle);
  255.                 eRet = JC_ERR_UNKNOWN;
  256.                 goto ERROR_HANDLE;
  257.             }
  258.             drm_rights = DRM_get_rights(file_handle);
  259.             parsed_drm_info.pstRightsObject->bIsRender = TRUE;
  260.             parsed_drm_info.stMimeContent.uData.pmFileName = encrypted_filename;
  261.             parsed_drm_info.pcContentType = jdi_UtilsStrdup((JC_INT8*) DRM_get_content_type(file_handle));
  262.             parsed_drm_info.stMimeContent.uiBufferLen = drm_rights->data_len;
  263.             DRM_close_file(file_handle);
  264.         }
  265.         else
  266.         {
  267.             eRet = JC_ERR_UNKNOWN;
  268.             goto ERROR_HANDLE;
  269.         }
  270.     }
  271.     else if (g_brw_drm_cntx.drm_type == DRM_TYPE_CONTENT)
  272.     {
  273.         drm_ret = DRM_process_virtual_file(
  274.                     (kal_uint8*) "application/vnd.oma.drm.content",
  275.                     (kal_wchar*) drm_content_fname,
  276.                     (kal_wchar*) drm_content_fname);
  277.     }
  278.     else
  279.     {
  280.         eRet = JC_ERR_UNKNOWN;
  281.         goto ERROR_HANDLE;
  282.     }
  283.   ERROR_HANDLE:
  284.     if (fs_handle)
  285.     {
  286.         jdd_FSDeinitialize(fs_handle);
  287.         fs_handle = NULL;
  288.     }
  289.     (g_brw_drm_cntx.drm_response_callback) (g_brw_drm_cntx.drm_app_arg, g_brw_drm_cntx.drm_ref_id, &parsed_drm_info);
  290. }
  291. /*****************************************************************************
  292.  * FUNCTION
  293.  *  jBrowser_drm_rights_update_handler
  294.  * DESCRIPTION
  295.  *  -
  296.  * PARAMETERS
  297.  *  uiDRMRefID          [IN]        
  298.  *  pstRightsObject     [?]         
  299.  *  bIsRendered         [IN]        
  300.  *  -(?)
  301.  * RETURNS
  302.  *  -(?)
  303.  *****************************************************************************/
  304. void jBrowser_drm_rights_update_handler(
  305.         JC_UINT32 uiDRMRefID,
  306.         ST_DRM_RIGHTS_OBJECT *pstRightsObject,
  307.         JC_BOOLEAN bIsRendered)
  308. {
  309.     /*----------------------------------------------------------------*/
  310.     /* Local Variables                                                */
  311.     /*----------------------------------------------------------------*/
  312.     /*----------------------------------------------------------------*/
  313.     /* Code Body                                                      */
  314.     /*----------------------------------------------------------------*/
  315.     return;
  316. }
  317. /*****************************************************************************
  318.  * FUNCTION
  319.  *  jBrowser_drm_more_content_handler
  320.  * DESCRIPTION
  321.  *  -
  322.  * PARAMETERS
  323.  *  pvAppArg            [?]         
  324.  *  uiDRMRefID          [IN]        
  325.  *  pucBuffer           [?]         
  326.  *  uiBufferLen         [IN]        
  327.  *  bHasMoreData        [IN]        
  328.  *  -(?)
  329.  * RETURNS
  330.  *  -
  331.  *****************************************************************************/
  332. JC_RETCODE jBrowser_drm_more_content_handler(
  333.             void *pvAppArg,
  334.             JC_UINT32 uiDRMRefID,
  335.             JC_UINT8 *pucBuffer,
  336.             JC_UINT32 uiBufferLen,
  337.             JC_BOOLEAN bHasMoreData)
  338. {
  339.     /*----------------------------------------------------------------*/
  340.     /* Local Variables                                                */
  341.     /*----------------------------------------------------------------*/
  342.     /*----------------------------------------------------------------*/
  343.     /* Code Body                                                      */
  344.     /*----------------------------------------------------------------*/
  345.     return JC_OK;
  346. }
  347. #endif /* defined (JATAAYU_SUPPORT) && defined (WAP_SUPPORT) */ 
  348. #endif /* __DRM_SUPPORT__ */ /* #ifdef __DRM_SUPPORT__ */
  349. #endif /* _JBROWSERDRMHANDLER_C_ */