status_t ConvertFromAMessage(const os::Message & from, Message & to) { to.Clear(); to.what = from.GetCode(); int numNames = from.GetNumNames(); for (int32 i=0; i<numNames; i++) { int type; int count; std::string name = from.GetName(i); if (from.GetNameInfo(name.c_str(), &type, &count) == B_NO_ERROR) { for (int j=0; j<count; j++) { const void * nextItem; size_t itemSize; if (from.FindData(name.c_str(), type, &nextItem, &itemSize, j) != B_NO_ERROR) return B_ERROR; // do any necessary translation from the AtheOS data types to Muscle data types switch(type) { case os::T_POINT: { const os::Point * p = static_cast<const os::Point *>(nextItem); Point pPoint(p->x, p->y); if (to.AddPoint(name.c_str(), pPoint) != B_NO_ERROR) return B_ERROR; } break; case os::T_RECT: { const os::Rect * r = static_cast<const os::Rect *>(nextItem); Rect pRect(r->left, r->top, r->right, r->bottom); if (to.AddRect(name.c_str(), pRect) != B_NO_ERROR) return B_ERROR; } break; case os::T_MESSAGE: { os::Message amsg; if (amsg.Unflatten(static_cast<const uint8 *>(nextItem)) != B_NO_ERROR) return B_ERROR; Message * newMsg = newnothrow Message; if (newMsg) { MessageRef msgRef(newMsg); if (ConvertFromAMessage(amsg, *newMsg) != B_NO_ERROR) return B_ERROR; if (to.AddMessage(name.c_str(), msgRef) != B_NO_ERROR) return B_ERROR; } else {WARN_OUT_OF_MEMORY; return B_ERROR;} } break; default: if (to.AddData(name.c_str(), type, nextItem, itemSize) != B_NO_ERROR) return B_ERROR; break; } } } } return B_NO_ERROR; }
// --------------------------------------------------------- // CNSmlCmdsBase::ProcessStatusCmdL // Handles Status command from a server. // --------------------------------------------------------- EXPORT_C void CNSmlCmdsBase::ProcessStatusCmdL( SmlStatus_t* aStatus ) { //msgRef if ( !aStatus->msgRef ) { return; } if ( !aStatus->msgRef->content ) { return; } TPtr8 msgRef( (TUint8*) aStatus->msgRef->content, aStatus->msgRef->length, aStatus->msgRef->length ); TrimRightSpaceAndNull( msgRef ); if ( msgRef.Length() == 0 ) { return; } //cmd if ( !aStatus->cmd ) { return; } if ( !aStatus->cmd->content ) { return; } TPtr8 cmd( (TUint8*) aStatus->cmd->content, aStatus->cmd->length, aStatus->cmd->length ); TrimRightSpaceAndNull( cmd ); if ( cmd.Length() == 0 ) { return; } //cmdRef HBufC8* cmdRef = NULL; if ( !aStatus->cmdRef ) { if ( cmd == KNSmlAgentSyncHdr ) { cmdRef = HBufC8::NewLC( KNSmlAgentSyncHdrCmdID.iTypeLength ); *cmdRef = KNSmlAgentSyncHdrCmdID; } else { return; } } else if ( !aStatus->cmdRef->content ) { if ( cmd == KNSmlAgentSyncHdr ) { cmdRef = HBufC8::NewLC( KNSmlAgentSyncHdrCmdID.iTypeLength ); *cmdRef = KNSmlAgentSyncHdrCmdID; } else { return; } } else { TPtr8 cmdRefPtr ( (TUint8*) aStatus->cmdRef->content, aStatus->cmdRef->length, aStatus->cmdRef->length ); TrimRightSpaceAndNull( cmdRefPtr ); if ( cmdRefPtr.Length() == 0 ) { if ( cmd == KNSmlAgentSyncHdr ) { cmdRef = HBufC8::NewLC( KNSmlAgentSyncHdrCmdID.iTypeLength ); *cmdRef = KNSmlAgentSyncHdrCmdID; } else { return; } } else { cmdRef = HBufC8::NewLC( cmdRefPtr.Length() ); *cmdRef = cmdRefPtr; } } // Status code TPtr8 statusCode( (TUint8*) aStatus->data->content, aStatus->data->length, aStatus->data->length ); TrimRightSpaceAndNull( statusCode ); if ( statusCode.Length() == 0 ) { CleanupStack::PopAndDestroy(); //cmdRef return; } TLex8 lexicalStatus( statusCode ); TInt numericStatus; if ( lexicalStatus.Val (numericStatus ) != KErrNone ) { CleanupStack::PopAndDestroy(); //cmdRef return; } TInt entryID = 0; TBool statusIsMatching; statusIsMatching = iResponseController->MatchStatusElement( msgRef, *cmdRef , numericStatus, entryID ); if ( !statusIsMatching ) { } else { // chal element is stored for later use if ( aStatus->chal ) { if ( aStatus->chal->meta ) { if ( aStatus->chal->meta->content && aStatus->chal->meta->contentType == SML_PCDATA_EXTENSION && aStatus->chal->meta->extension == SML_EXT_METINF ) { SmlMetInfMetInf_t* metInf; metInf = (SmlMetInfMetInf_t*) aStatus->chal->meta->content; if ( metInf->type ) { if ( metInf->type->content ) { TPtr8 chalType( (TUint8*) metInf->type->content, metInf->type->length, metInf->type->length ); TrimRightSpaceAndNull( chalType ); if ( chalType.Length() > 0 ) { iResponseController->SetChalTypeL( entryID, chalType ); } } } if ( metInf->format ) { if ( metInf->format->content ) { TPtr8 chalFormat( (TUint8*) metInf->format->content, metInf->format->length, metInf->format->length ); TrimRightSpaceAndNull( chalFormat ); if ( chalFormat.Length() > 0 ) { iResponseController->SetChalFormatL( entryID, chalFormat ); } else { iResponseController->SetChalFormatL( entryID, KNSmlAgentChrFormat ); } } else { iResponseController->SetChalFormatL( entryID, KNSmlAgentChrFormat ); } } else { iResponseController->SetChalFormatL( entryID, KNSmlAgentChrFormat ); } if ( metInf->nextnonce ) { if ( metInf->nextnonce->content ) { TPtr8 chalNextNonce( (TUint8*) metInf->nextnonce->content, metInf->nextnonce->length, metInf->nextnonce->length ); TrimRightSpaceAndNull( chalNextNonce ); if ( chalNextNonce.Length() > 0 ) { iResponseController->SetChalNextNonceL( entryID, chalNextNonce ); } } } } } } } CleanupStack::PopAndDestroy(); //cmdRef if ( statusIsMatching ) { iAgent->CheckServerStatusCodeL( entryID ); } }