dmProcessScriptSession.cc revision 3fa3e56afc259ce982ca4f8b51be7378b7e2021e
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 Header Name: dmProcessScriptSession.cc 20 21 General Description: Implementation of DMProcessScriptSession class. 22 23==================================================================================================*/ 24 25#include "dmProcessScriptSession.h" 26#include "dm_ua_handlecommand.h" 27#include "xpl_Logger.h" 28 29/*================================================================================================== 30FUNCTION : DMProcessScriptSession::DMProcessScriptSession 31 32DESCRIPTION : The class constructor. 33ARGUMENT PASSED : sml_ContentType 34 sml_EncodingType 35OUTPUT PARAMETER: 36RETURN VALUE : 37IMPORTANT NOTES : 38==================================================================================================*/ 39DMProcessScriptSession::DMProcessScriptSession() 40{ 41 42 inAtomicCommand = FALSE; 43 commandCount = 0; 44 m_bSessionAborted = FALSE; 45 46 serverSessionId = 0; 47 serverRetryCount = 0; 48 clientRetryCount = 0; 49 50 m_nSecState = DM_CLIENT_NO_SERVER_Y_AUTH; 51 isServCredsMissing = FALSE; 52 53#ifdef LOB_SUPPORT 54 DMGetData lrgObjData; 55 isLargeObjectSupported = FALSE; 56 dmTreeObj.Get("./DevDetail/LrgObj", lrgObjData,SYNCML_DM_REQUEST_TYPE_SERVER); 57 isLargeObjectSupported = !lrgObjData.m_oData.compare("false"); 58 // Get default MaxObjectSize 59 DMNode* pNode= dmTreeObj.FindNodeByURI("./DevDetail/Ext/MaxObjSize"); 60 dmtMaxObjectSize = dmTreeObj.readOneWordFromTree(pNode, 0); 61#endif 62} 63 64/*================================================================================================== 65FUNCTION : DMProcessScriptSession::~DMProcessScriptSession 66 67DESCRIPTION : The class destructor. 68ARGUMENT PASSED : 69OUTPUT PARAMETER: 70RETURN VALUE : 71IMPORTANT NOTES : 72==================================================================================================*/ 73DMProcessScriptSession::~DMProcessScriptSession () 74{ 75 while ( userData.aStatuses.size() > 0 ) 76 { 77 smlFreeStatus((SmlStatusPtr_t)userData.aStatuses[0]); 78 userData.aStatuses.remove(0); 79 } 80 81 while ( userData.aResults.size() > 0 ) 82 { 83 smlFreeResults( userData.aResults[0]._pGetExecResult ); 84 userData.aResults[0]._pGetExecResult= NULL; 85 86 if ( userData.aResults[0]._type == SYNCML_DM_RESULT_VALUE::Enum_Result_GetStruct || 87 userData.aResults[0]._type == SYNCML_DM_RESULT_VALUE::Enum_Result_GetStructData ) 88 { 89 90 if (userData.aResults[0]._oGetStructPos.psRetData ) 91 { 92 delete userData.aResults[0]._oGetStructPos.psRetData; 93 } 94 } 95 userData.aResults.remove(0); 96 } 97} 98 99/*================================================================================================== 100FUNCTION : DMProcessScriptSession::IncCommandCount 101 102DESCRIPTION : This function will increment the value of data member commandCount by 1. 103ARGUMENT PASSED : newCommandCount 104OUTPUT PARAMETER: 105RETURN VALUE : 106IMPORTANT NOTES : 107==================================================================================================*/ 108void 109DMProcessScriptSession::IncCommandCount () 110{ 111 commandCount++; 112} 113 114/*================================================================================================== 115Function: DMProcessScriptSession::SetInAtomicCommand 116 117Description: The function will set the value of data member inAtomicCommand. 118ARGUMENT PASSED : newInAtomicCommand 119OUTPUT PARAMETER: 120RETURN VALUE : 121IMPORTANT NOTES : 122==================================================================================================*/ 123void 124DMProcessScriptSession::SetInAtomicCommand (BOOLEAN newInAtomicCommand) 125{ 126 inAtomicCommand = newInAtomicCommand; 127} 128 129/*================================================================================================== 130Function: DMProcessScriptSession::GetInAtomicCommand 131 132Description: The function will return the value of data member inAtomicCommand. 133ARGUMENT PASSED : 134OUTPUT PARAMETER: 135RETURN VALUE : inAtomicCommand 136IMPORTANT NOTES : 137==================================================================================================*/ 138BOOLEAN 139DMProcessScriptSession::GetInAtomicCommand() 140{ 141 return inAtomicCommand; 142} 143 144 145/*================================================================================================== 146Function: DMProcessScriptSession::GetServerSessionId 147 148Description: The function will return the value of data member serverSessionId. 149ARGUMENT PASSED : 150OUTPUT PARAMETER: 151RETURN VALUE : serverSessionId 152IMPORTANT NOTES : 153==================================================================================================*/ 154UINT16 155DMProcessScriptSession::GetServerSessionId() 156{ 157 return serverSessionId; 158} 159 160 161/*================================================================================================== 162Function: DMProcessScriptSession::GetSendInstanceId 163 164Description: The function will return the value of data member sendInstanceId. 165ARGUMENT PASSED : 166OUTPUT PARAMETER: 167RETURN VALUE : sendInstanceId 168IMPORTANT NOTES : 169==================================================================================================*/ 170InstanceID_t 171DMProcessScriptSession::GetSendInstanceId () 172{ 173 return sendInstanceId; 174} 175 176/*================================================================================================== 177Function: DMProcessScriptSession::SetClientRetryCount 178 179Description: The function will set the clientRetryCount to a new value. 180ARGUMENT PASSED : 181OUTPUT PARAMETER: 182RETURN VALUE : void 183IMPORTANT NOTES : 184==================================================================================================*/ 185void 186DMProcessScriptSession::SetClientRetryCount (UINT8 newcount) 187{ 188 clientRetryCount = newcount; 189} 190 191/*================================================================================================== 192Function: DMProcessScriptSession::IncClientRetryCount 193 194Description: The function will increment the clientRetryCount by 1. 195ARGUMENT PASSED : 196OUTPUT PARAMETER: 197RETURN VALUE : void 198IMPORTANT NOTES : 199==================================================================================================*/ 200void 201DMProcessScriptSession::IncClientRetryCount () 202{ 203 clientRetryCount++; 204} 205 206 207/*================================================================================================== 208FUNCTION : DMProcessScriptSession::SessionStart 209 210DESCRIPTION : The UserAgen::SessionStart calls this function after it creates MgmtSession object. 211 The function will perform the following operations: 212 1) Call SessionStart() to setup the DM tree. 213 2) Register the DM engine with the SYNCML toolkit. 214 3) Connect the client with the server. 215 4) Build and send the package one. 216ARGUMENT PASSED : p_SessionStart 217OUTPUT PARAMETER: 218RETURN VALUE : 219IMPORTANT NOTES : 220==================================================================================================*/ 221SYNCML_DM_RET_STATUS_T 222DMProcessScriptSession::Start(const UINT8 *docInputBuffer, 223 UINT32 inDocSize, 224 BOOLEAN isWBXML, 225 DMBuffer & oResult) 226{ 227 SYNCML_DM_RET_STATUS_T ret_stat = SYNCML_DM_FAIL; 228 Ret_t sml_ret_stat; 229 230 XPL_LOG_DM_SESS_Debug(("Entered DMProcessScriptSession::SessionStart, buf=%x,size=%d, wbxml=%d\n", docInputBuffer, inDocSize, isWBXML)); 231 232 XPL_LOG_DM_SESS_Debug(("Entered DMProcessScriptSession::SessionStart, resultbuf=%x", &oResult)); 233 234 ret_stat = Init(isWBXML); 235 if ( ret_stat != SYNCML_DM_SUCCESS ) 236 return ret_stat; 237 238 /* Register the DM engine with the SYNCML toolkit. */ 239 userData.pSessionMng = this; 240 userData.pPkgBuilder = &m_oPkgBuilder; 241 ret_stat = RegisterDmEngineWithSyncmlToolkit(&userData); 242 XPL_LOG_DM_SESS_Debug(("after entered\n")); 243 244 if ( ret_stat != SYNCML_DM_SUCCESS ) 245 { 246 XPL_LOG_DM_SESS_Debug(("Exiting: RegisterDmEngineWithSyncmlToolkit failed\n")); 247 return (ret_stat); 248 } 249 250 251 sml_ret_stat = smlLockWriteBuffer(recvInstanceId, &pWritePos, &workspaceFreeSize); 252 XPL_LOG_DM_SESS_Debug(("after smlLockWriteBuffer\n")); 253 254 if ( sml_ret_stat != SML_ERR_OK ) 255 return SYNCML_DM_FAIL; 256 257 memcpy(pWritePos,docInputBuffer,inDocSize); 258 XPL_LOG_DM_SESS_Debug(("after memcpy\n")); 259 260 recvSmlDoc.dataSize = inDocSize; 261 262 ret_stat = ParseMessage(); 263 XPL_LOG_DM_SESS_Debug(("after ParseMessage\n")); 264 265 if (ret_stat != SYNCML_DM_SUCCESS) 266 return ret_stat; 267 268 269 smlLockReadBuffer(sendInstanceId, &pReadPos, &workspaceUsedSize); 270 XPL_LOG_DM_SESS_Debug(("after smlLockReadBuffer\n")); 271 272 /* Set sendSmlDoc point to workspace */ 273 if ( workspaceUsedSize ) 274 { 275 oResult.assign(pReadPos,workspaceUsedSize); 276 if ( oResult.getBuffer() == NULL ) 277 ret_stat = SYNCML_DM_DEVICE_FULL; 278 else 279 ret_stat = SYNCML_DM_SUCCESS; 280 } 281 282 XPL_LOG_DM_SESS_Debug(("dmProcessScriptSession:: workspaceUsedSize:%d, ret_stat:%d", workspaceUsedSize, ret_stat)); 283 XPL_LOG_DM_SESS_Debug(("dmProcessScriptSession:: oResult.getBuffer()=%x, size=%d\n", oResult.getBuffer(), oResult.getSize())); 284 return ret_stat; 285} 286 287/*================================================================================================== 288FUNCTION : DMProcessScriptSession::ParseMessage 289 290DESCRIPTION : The UserAgent::TransportMsg will call this function after RecvMessage() call 291 returned. 292 The function will use SyncML toolkit smlProcessData() function to parse and 293 process commands in the package. 294ARGUMENT PASSED : 295OUTPUT PARAMETER: 296RETURN VALUE : 297IMPORTANT NOTES : 298 299 300 This method will perform the following operations: 301 1) Unlock both of the Toolkit Buffers. 302 2) Call smlProcessData for the first command. 303 3) Loop around smlProcessData on the next command while checking for Multiple Messages 304 305==================================================================================================*/ 306SYNCML_DM_RET_STATUS_T 307DMProcessScriptSession::ParseMessage() 308{ 309 Ret_t sml_ret_stat; 310 SYNCML_DM_RET_STATUS_T ret_stat = SYNCML_DM_SUCCESS; 311 312 smlUnlockWriteBuffer(recvInstanceId, recvSmlDoc.dataSize); 313 314 /* Process the first command in the incoming message */ 315 sml_ret_stat = smlProcessData(recvInstanceId, SML_FIRST_COMMAND); 316 317 if (sml_ret_stat != SML_ERR_OK) 318 return(SYNCML_DM_FAIL); 319 320 /* Loop through the remaining commands until we reach the end of the 321 current toolkit workspace */ 322 while (sml_ret_stat != SML_ERR_XLT_END_OF_BUFFER) 323 { 324 sml_ret_stat = smlProcessData(recvInstanceId, SML_NEXT_COMMAND); 325 /* The callback routines set this value when they realize we need 326 to begin processing the other buffer. */ 327 328 /* Anything wrong with the command, or inMultipleMessageMode is TRUE, break out here. 329 * The callbacks set inMultipleMessageMode when they can no longer 330 * fit anything into the outgoing message workspace 331 */ 332 if ((sml_ret_stat != SML_ERR_OK) ) 333 break; 334 } 335 336 if (sml_ret_stat != SML_ERR_OK && sml_ret_stat != SML_ERR_XLT_END_OF_BUFFER) 337 { 338 ret_stat = dmTreeObj.GetLockContextManager().ReleaseIDInternal(SYNCML_DM_LOCKID_CURRENT, SYNCML_DM_ROLLBACK); 339 ret_stat = SYNCML_DM_FAIL; 340 KCDBG("dmProcessScriptSession:: sml_ret_stat:%d, ret_stat:%d", sml_ret_stat, ret_stat); 341 } 342 343 return (ret_stat); 344} 345 346 347/*================================================================================================== 348FUNCTION : DMProcessScriptSession::SetToolkitCallbacks 349 350DESCRIPTION : This function will to set toolkit callback functions. 351 352 353ARGUMENT PASSED : 354OUTPUT PARAMETER: 355RETURN VALUE : It returns SYNCML_DM_SUCCESS. 356IMPORTANT NOTES : 357 358 359==================================================================================================*/ 360SYNCML_DM_RET_STATUS_T 361DMProcessScriptSession::SetToolkitCallbacks(SmlCallbacks_t * pSmlCallbacks) 362{ 363 364 pSmlCallbacks->startMessageFunc = HandleStartMessage; 365 pSmlCallbacks->endMessageFunc = HandleEndMessage; 366 367 /* Sync Command callbacks */ 368 pSmlCallbacks->addCmdFunc = HandleAddCommand; 369 370 pSmlCallbacks->alertCmdFunc = HandleAlertCommand; 371 pSmlCallbacks->copyCmdFunc = HandleCopyCommand; 372 pSmlCallbacks->deleteCmdFunc = HandleDeleteCommand; 373 pSmlCallbacks->getCmdFunc = HandleGetCommand; 374 375 pSmlCallbacks->startAtomicFunc = HandleStartAtomicCommand; 376 pSmlCallbacks->endAtomicFunc = HandleEndAtomicCommand; 377 378 pSmlCallbacks->startSequenceFunc = HandleStartSequenceCommand; 379 pSmlCallbacks->endSequenceFunc = HandleEndSequenceCommand; 380 381 pSmlCallbacks->execCmdFunc = HandleExecCommand; 382 pSmlCallbacks->statusCmdFunc = HandleStatusCommand; 383 pSmlCallbacks->replaceCmdFunc = HandleReplaceCommand; 384 385 /* The transmitChunkFunc callback is required for support of Large Objects. */ 386 387 pSmlCallbacks->transmitChunkFunc = NULL; 388 389 return SYNCML_DM_SUCCESS; 390} 391 392DMClientServerCreds * DMProcessScriptSession::GetClientServerCreds() 393{ 394 return &clientServerCreds; 395} 396