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 _RO_H_ 18 #define _RO_H_ 19 20 #include <rights/Asset.h> 21 #include <rights/Right.h> 22 #include <uvector.h> 23 #include <ustring.h> 24 #include <sistream.h> 25 using namespace ustl; 26 27 class Asset; 28 class XMLDocumentImpl; 29 class XMLElementImpl; 30 class NodeImpl; 31 32 class Ro { 33 public: 34 enum ERRCODE { RO_NULL_STREAM, RO_ERR_BAD_XML, RO_OK, RO_BAD }; 35 36 /** 37 * Constructor for Ro. 38 */ 39 Ro(); 40 41 /** 42 * Destructor for Ro. 43 */ 44 ~Ro(); 45 46 /** 47 * Set id for Ro. 48 * @param id the id of Ro. 49 */ 50 void setRoID(string &id); 51 52 /** 53 * Get the id of Ro. 54 * @return the id of Ro. 55 */ 56 const string& getRoID() const; 57 58 /** 59 * Set version for Ro. 60 */ 61 void setRoVersion(string &version); 62 63 /** 64 * Add a asset into ro's asset list. 65 * @param asset the pointer of asset. 66 */ 67 void addAsset(Asset* asset); 68 69 /** 70 * Add a right into ro's right list. 71 * @param right the pointer of right. 72 */ 73 void addRight(Right* right); 74 75 /** 76 * Save the Ro. 77 */ 78 bool save(); 79 80 /** 81 * Verify the Ro. 82 */ 83 bool verify(); 84 85 /** 86 * Parse the ro from stream. 87 * @param roStream the input ro stream. 88 * @return RO_OK if parse successfully otherwise return error code. 89 */ 90 ERRCODE parse(istringstream *roStream); 91 92 /** 93 * Check the permission of the content. 94 * @param type the operation type. 95 * @param contentID the specific contentID. 96 * @return true/false to indicate result. 97 */ 98 bool checkPermission(OperationPermission::OPERATION type, 99 const string& contentID); 100 101 /** 102 * Consume the right related to content. 103 * @param type the operation type. 104 * @param contentID the specific contentID. 105 * @return the status of consume. 106 */ 107 ERRCODE consume(OperationPermission::OPERATION type, 108 const string& contentID); 109 110 /** 111 * Get CEK of content. 112 * @param contentID the specific content id. 113 * @return "" if not found otherwise return CEK. 114 */ 115 string getContentCek(const string& contentID); 116 117 /** 118 * Get Digest value of content. 119 * @param contentID the specific content id. 120 * @return "" if not found otherwise return digest value. 121 */ 122 string getContentHash(const string& contentID); 123 124 PRIVATE: 125 /** 126 * Handle the xml dom document. 127 * @param doc the pointer to the dom document. 128 * @return true/false to indicate the result. 129 */ 130 bool handleDocument(const XMLDocumentImpl* doc); 131 132 /** 133 * Handle the xml dom node which contains <right> element. 134 * @param curNode the dom node which contains <right> element. 135 * @return true/false to indicate the result. 136 */ 137 bool handleRights(const NodeImpl *curNode); 138 139 /** 140 * Handle the xml dom node which contains the <agreement> element. 141 * @param curNode the dom node which contains <agreement> element. 142 * @return true/false to indicate the result. 143 */ 144 bool handleAgreement(const NodeImpl *curNode); 145 146 /** 147 * Handle the xml dom node which contains the <asset> element. 148 * @param curNode the dom node which contains <asset> element. 149 * @return true/false to indicate the result. 150 */ 151 bool handleAsset(const NodeImpl *curNode); 152 153 /** 154 * Handle the xml dom node which contains the <permission> element. 155 * @param curNode the dom node which contains <permission> element. 156 * @return true/false to indicate the result. 157 */ 158 bool handlePermission(const NodeImpl *curNode); 159 160 /** 161 * Get the constraint in xml dom node. 162 * @param curNode the dom node which contains constraint. 163 * @return the constraint. 164 */ 165 Constraint* getConstraint(const NodeImpl *curNode); 166 167 /** 168 * Convert ISO8601 time to long. 169 * @param ts the string with ISO8601 time. 170 * @return the result value. 171 */ 172 long convertISO8601DateTimeToLong(const char* ts); 173 174 /** 175 * Convert ISO8601 period to long. 176 * @param ts the string with ISO8601 period. 177 * @return the result value. 178 */ 179 long convertISO8601PeriodToLong(const char* ts); 180 181 /** 182 * Load the rights related with specific contentinto content rights list. 183 * @param contentID the specific content id. 184 */ 185 void loadRights(const string& contentID); 186 187 /** 188 * Free the current content rights list. 189 */ 190 void freeRights(); 191 192 PRIVATE: 193 /** 194 * Disable the assignment between rights. 195 */ 196 Ro& operator=(const Ro& ro); 197 198 /** 199 * Disable copy constructor. 200 */ 201 Ro(const Ro& ro); 202 203 public: 204 vector<Asset*> mAssetList; 205 vector<Right*> mRightList; 206 207 PRIVATE: 208 string mRoID; /** the Ro id. */ 209 string mRoVersion; /** the Ro version. */ 210 XMLDocumentImpl *mDoc; /**< the xml document handle. */ 211 vector<Right*> mContentRightList; /**< the right list to store the result related with specific content. */ 212 Right* mProperRight; /**< the right to consume. */ 213 }; 214 #endif 215