1 /* 2 * Copyright (C) 2014 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 /*================================================================================================== 18 19 Source Name: dmMetaDataNode.cc 20 21 General Description: Implementation of the DMMetaDataNode class 22 23 ==================================================================================================*/ 24 25 #include <limits.h> 26 #include "dm_uri_utils.h" 27 #include "dmStringUtil.h" 28 #include "dmMetaDataNode.h" 29 #include "xpl_Logger.h" 30 31 DMMetaDataNode::DMMetaDataNode() 32 { 33 Init(); 34 } 35 36 37 DMConstraints * 38 DMMetaDataNode::GetConstraints() const 39 { 40 if ( m_nNumConstraints ) 41 return (DMConstraints*)&m_oConstraints; 42 else 43 return NULL; 44 } 45 46 void DMMetaDataNode::Init() 47 { 48 m_psName = NULL; 49 m_szID = NULL; 50 m_wAccessType = SYNCML_DM_GET_ACCESS_TYPE | SYNCML_DM_EXEC_ACCESS_TYPE; 51 m_nNodeFormat = SYNCML_DM_FORMAT_INVALID; 52 m_nMimeType = SYNCML_DM_DDF_MIME_TYPE_TEXTPLAIN; 53 m_nNumConstraints = 0; 54 m_nMaxChildrenMultiNodes = 0; 55 m_bIsHasMultiChildren = FALSE; 56 m_bIsMultiNode = FALSE; 57 m_bStoresPD = FALSE; 58 m_bPluginNode = FALSE; 59 m_bOPiDataParent = FALSE; 60 #ifdef LOB_SUPPORT 61 m_bESN = FALSE; 62 m_bProgressBarNeeded = FALSE; 63 #endif 64 } 65 66 67 void 68 DMMetaDataNode::CheckHasMultiNode(DMMetaDataBuffer oBuffer) 69 { 70 71 UINT16 nodeType; 72 73 74 oBuffer.SetOffset(oBuffer.ReadUINT32() + sizeof(UINT32)); 75 nodeType = oBuffer.ReadUINT16(); 76 if ( (nodeType & 0x80) == 0x80 ) 77 m_bIsHasMultiChildren = TRUE; 78 } 79 80 81 82 SYNCML_DM_RET_STATUS_T 83 DMMetaDataNode::Read(DMMetaDataBuffer oBuffer, 84 BOOLEAN bReadConstraints) 85 { 86 87 SYNCML_DM_RET_STATUS_T ret_status = SYNCML_DM_SUCCESS; 88 UINT16 nodeType; 89 90 Init(); 91 92 m_psName = oBuffer.ReadString(); 93 nodeType = oBuffer.ReadUINT16(); 94 if ( (nodeType & nodeMultiNode) == nodeMultiNode) 95 m_bIsMultiNode = TRUE; 96 97 #ifdef LOB_SUPPORT 98 if ( (nodeType & nodeESN) == nodeESN) 99 m_bESN = TRUE; 100 101 if ( (nodeType & nodeProgressBar) == nodeProgressBar) 102 m_bProgressBarNeeded = TRUE; 103 #endif 104 m_nNodeFormat = (UINT8)(nodeType & nodeTypeMask ); 105 106 if ( (nodeType & nodeHasID) != 0 ) 107 m_szID = oBuffer.ReadString(); 108 109 m_bPluginNode = ((nodeType & nodePluginNode) != 0); 110 m_bStoresPD = ((nodeType & nodeStoresPD) != 0); 111 112 m_wAccessType = oBuffer.ReadUINT8(); 113 m_nMimeType = oBuffer.ReadUINT8(); 114 m_nNumChildren = oBuffer.ReadUINT16(); 115 116 m_nOffsetChildren = oBuffer.GetOffset(); 117 118 if ( m_nNumChildren == 1 ) 119 CheckHasMultiNode(oBuffer); 120 121 if ( bReadConstraints ) 122 { 123 oBuffer.IncOffset(m_nNumChildren*sizeof(UINT32)); 124 m_nNumConstraints = oBuffer.ReadUINT8(); 125 ret_status = m_oConstraints.Read(&oBuffer, m_nNumConstraints, nodeType); 126 } 127 return ret_status; 128 129 130 } 131 132 133 SYNCML_DM_RET_STATUS_T 134 DMMetaDataNode::SetChildrenOffset(DMMetaDataBuffer * pBuffer, 135 UINT8 index) 136 { 137 if ( index > m_nNumChildren ) 138 return SYNCML_DM_SUCCESS; 139 140 pBuffer->SetOffset(m_nOffsetChildren + index*sizeof(UINT32)); 141 142 UINT32 offset = pBuffer->ReadUINT32(); 143 pBuffer->SetOffset(offset); 144 145 return SYNCML_DM_SUCCESS; 146 } 147 148 149 SYNCML_DM_RET_STATUS_T 150 DMMetaDataNode::GetMaxMultiNodeChildren(DMMetaDataBuffer oBuffer) 151 { 152 153 SYNCML_DM_RET_STATUS_T ret_status = SYNCML_DM_SUCCESS; 154 155 if ( m_bIsHasMultiChildren ) 156 { 157 oBuffer.SetOffset(m_nOffsetChildren); 158 UINT32 offset = oBuffer.ReadUINT32(); 159 oBuffer.SetOffset(offset); 160 DMMetaDataNode oChildren; 161 DMConstraints * pConstraints = NULL; 162 163 ret_status = oChildren.Read(oBuffer,TRUE); 164 if ( ret_status != SYNCML_DM_SUCCESS ) 165 return ret_status; 166 167 m_bOPiDataParent = oChildren.m_bStoresPD; 168 pConstraints = oChildren.GetConstraints(); 169 if ( pConstraints ) 170 m_nMaxChildrenMultiNodes = pConstraints->m_nMaxMultiNodes; 171 } 172 return ret_status; 173 } 174 175 176 SYNCML_DM_RET_STATUS_T 177 DMMetaDataNode::ReadName(DMMetaDataBuffer oBuffer) 178 { 179 180 SYNCML_DM_RET_STATUS_T ret_status = SYNCML_DM_SUCCESS; 181 182 Init(); 183 m_psName = oBuffer.ReadString(); 184 return ret_status; 185 } 186 187 188 BOOLEAN 189 DMMetaDataNode::VerifyAccessType(SYNCML_DM_ACCESS_TYPE_T accessType) const 190 { 191 XPL_LOG_DM_TMN_Debug(("DMMetaDataNode::VerifyAccessType: node m_wAccesstype is:%x, passed accessType is %x\n", m_wAccessType,accessType)); 192 return ( (m_wAccessType & accessType) == accessType ); 193 } 194 195 BOOLEAN DMMetaDataNode::VerifyMimeType(CPCHAR mimeType) const 196 { 197 return TRUE; 198 } 199 200 201 void DMMetaDataNode::GetMimeType(DMString & strType) 202 { 203 strType = "text/plain"; 204 } 205 206 void DMMetaDataNode::SetAccessType(SYNCML_DM_ACCESS_TYPE_T accessType) 207 { 208 m_wAccessType = accessType; 209 210 } 211 212 213 BOOLEAN DMMetaDataNode::IsLocal() 214 { 215 return ( (m_wAccessType & SYNCML_DM_LOCAL_ACCESS_TYPE) == SYNCML_DM_LOCAL_ACCESS_TYPE ); 216 217 } 218 219 BOOLEAN DMMetaDataNode::IsLeaf() 220 { 221 if ( m_nNodeFormat != SYNCML_DM_FORMAT_NODE && 222 m_nNodeFormat != SYNCML_DM_FORMAT_NODE_PDATA ) 223 return TRUE; 224 else 225 return FALSE; 226 } 227 228 SYNCML_DM_RET_STATUS_T DMMetaDataNode::SetPath(CPCHAR szPath) 229 { 230 if ( m_oPath.assign(szPath) == NULL ) 231 return SYNCML_DM_DEVICE_FULL; 232 return SYNCML_DM_SUCCESS; 233 } 234 235 SYNCML_DM_RET_STATUS_T DMMetaDataNode::AllocatePath(UINT32 size) 236 { 237 if ( m_oPath.allocate(size) == NULL ) 238 return SYNCML_DM_DEVICE_FULL; 239 return SetPath("."); 240 } 241 242 SYNCML_DM_RET_STATUS_T DMMetaDataNode::AppendSegment() 243 { 244 m_oPath.append((UINT8*)"/", 1); 245 m_oPath.append((UINT8*)m_psName,DmStrlen(m_psName)); 246 return SYNCML_DM_SUCCESS; 247 } 248 249 BOOLEAN 250 DMMetaDataNode::VerifyChildrenMultiNodesCount(UINT16 count, 251 BOOLEAN& bOPiDataParent ) const 252 { 253 bOPiDataParent = m_bOPiDataParent; 254 if ( m_nMaxChildrenMultiNodes > 0 ) 255 { 256 return ( (count < m_nMaxChildrenMultiNodes) ); 257 } 258 else 259 return TRUE; 260 } 261 262 BOOLEAN 263 DMMetaDataNode::VerifyOPINode( CPCHAR& szID, 264 SYNCML_DM_ACCESS_TYPE_T& wAccessType, 265 SYNCML_DM_FORMAT_T& nNodeFormat ) const 266 { 267 szID = m_szID; 268 wAccessType = m_wAccessType; 269 nNodeFormat = m_nNodeFormat; 270 271 return m_bPluginNode; 272 } 273