The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __PARSER_REL_H__ |
| 18 | #define __PARSER_REL_H__ |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | #include <drm_common_types.h> |
| 25 | |
| 26 | #define WRITE_RO_FLAG(whoIsAble, boolValue, Indicator, RIGHTS) do{\ |
| 27 | whoIsAble = boolValue;\ |
| 28 | Indicator |= RIGHTS;\ |
| 29 | }while(0) |
| 30 | |
| 31 | #define CHECK_VALIDITY(ret) do{\ |
| 32 | if(ret == NULL){\ |
| 33 | if(XML_ERROR_NO_SUCH_NODE != xml_errno)\ |
| 34 | return FALSE;\ |
| 35 | }\ |
| 36 | else\ |
| 37 | {\ |
| 38 | if(XML_ERROR_OK != xml_errno)\ |
| 39 | return FALSE;\ |
| 40 | }\ |
| 41 | }while(0) |
| 42 | |
| 43 | #define YMD_HMS_2_INT(year, mon, day, date, hour, min, sec, time) do{\ |
| 44 | date = year * 10000 + mon * 100 + day;\ |
| 45 | time = hour * 10000 + min * 100 + sec;\ |
| 46 | }while(0) |
| 47 | |
| 48 | #define DRM_UID_LEN 256 |
| 49 | #define DRM_KEY_LEN 16 |
| 50 | |
| 51 | #define XML_DOM_PARSER |
| 52 | |
| 53 | typedef struct _T_DRM_DATETIME { |
| 54 | int32_t date; /**< year * 10000 + mon *100 + day */ |
| 55 | int32_t time; /**< hour * 10000 + min *100 + sec */ |
| 56 | } T_DRM_DATETIME; |
| 57 | |
| 58 | typedef struct _T_DRM_Rights_Constraint { |
| 59 | uint8_t Indicator; /**< Indicate which is constrainted, the first one indicate 0001, second one indicate 0010 */ |
| 60 | uint8_t unUsed[3]; |
| 61 | int32_t Count; /**< The times that can be used */ |
| 62 | T_DRM_DATETIME StartTime; /**< The starting time */ |
| 63 | T_DRM_DATETIME EndTime; /**< The ending time */ |
| 64 | T_DRM_DATETIME Interval; /**< The interval time */ |
| 65 | } T_DRM_Rights_Constraint; |
| 66 | |
| 67 | typedef struct _T_DRM_Rights { |
| 68 | uint8_t Version[8]; /**< Version number */ |
| 69 | uint8_t uid[256]; /**< record the rights object name */ |
| 70 | uint8_t KeyValue[16]; /**< Decode base64 */ |
| 71 | int32_t bIsPlayable; /**< Is playable */ |
| 72 | int32_t bIsDisplayable; /**< Is displayable */ |
| 73 | int32_t bIsExecuteable; /**< Is executeable */ |
| 74 | int32_t bIsPrintable; /**< Is printable */ |
| 75 | T_DRM_Rights_Constraint PlayConstraint; /**< Play constraint */ |
| 76 | T_DRM_Rights_Constraint DisplayConstraint; /**< Display constraint */ |
| 77 | T_DRM_Rights_Constraint ExecuteConstraint; /**< Execute constraint */ |
| 78 | T_DRM_Rights_Constraint PrintConstraint; /**< Print constraint */ |
| 79 | } T_DRM_Rights; |
| 80 | |
| 81 | /** |
| 82 | * Input year and month, return how many days that month have |
| 83 | * \param year (in)Input the year |
| 84 | * \param month (in)Input the month |
| 85 | * \return |
| 86 | * -A positive integer, which is how many days that month have |
| 87 | * -When wrong input, return -1 |
| 88 | */ |
| 89 | int32_t drm_monthDays(int32_t year, int32_t month); |
| 90 | |
| 91 | /** |
| 92 | * Check whether the date and time is valid. |
| 93 | * \param year year of the date |
| 94 | * \param month month of the date |
| 95 | * \param day day of the date |
| 96 | * \param hour hour of the time |
| 97 | * \param min minute of the time |
| 98 | * \param sec second of the time |
| 99 | * \return |
| 100 | * -when it is a valid time, return 0 |
| 101 | * -when it is a invalid time, return -1 |
| 102 | */ |
| 103 | int32_t drm_checkDate(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, int32_t sec); |
| 104 | |
| 105 | /** |
| 106 | * Parse the rights object include xml format and wbxml format data |
| 107 | * |
| 108 | * \param buffer (in)Input the DRM rights object data |
| 109 | * \param bufferLen (in)The buffer length |
| 110 | * \param format (in)Which format, xml or wbxml |
| 111 | * \param pRights (out)A structure pointer which save the rights information |
| 112 | * |
| 113 | * \return |
| 114 | * -TRUE, when success |
| 115 | * -FALSE, when failed |
| 116 | */ |
| 117 | int32_t drm_relParser(uint8_t* buffer, int32_t bufferLen, int32_t Format, T_DRM_Rights* pRights); |
| 118 | |
| 119 | #ifdef __cplusplus |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | #endif /* __PARSER_REL_H__ */ |