void VJSImage::_save(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPictureCodecFactoryRef fact; const VPictureCodec* encoder = nil; bool ok = false; VPicture* pic = inPict->GetPict(); if (pic != nil) { VFile* file = ioParms.RetainFileParam(1); if (file != nil) { VString mimetype; ioParms.GetStringParam(2, mimetype); if (mimetype.IsEmpty()) { VString extension; file->GetExtension(extension); if (extension.IsEmpty()) extension = L"pic"; encoder = fact->RetainEncoderForExtension(extension); } else encoder = fact->RetainEncoderByIdentifier(mimetype); if (encoder != nil) { VError err = VE_OK; if (file->Exists()) err = file->Delete(); if (err == VE_OK) { VValueBag *pictureSettings = nil; VValueBag *bagMetas = (VValueBag*)inPict->RetainMetaBag(); if (bagMetas != nil) { pictureSettings = new VValueBag(); ImageEncoding::stWriter settingsWriter(pictureSettings); VValueBag *bagRetained = settingsWriter.CreateOrRetainMetadatas( bagMetas); if (bagRetained) bagRetained->Release(); } err=encoder->Encode(*pic, pictureSettings, *file); QuickReleaseRefCountable(bagMetas); QuickReleaseRefCountable(pictureSettings); if (err == VE_OK) ok = true; } encoder->Release(); } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); } ioParms.ReturnBool(ok); }
VError removeGroupFromGroup(VJSParms_callStaticFunction& ioParms, CUAGGroup* inGroup, const VString& s) { VError err = VE_OK; CUAGDirectory* dir = inGroup->GetDirectory(); CUAGGroup* group; { StErrorContextInstaller errs(false); group = dir->RetainGroup(s); if (group == nil) { VUUID id; id.FromString(s); group = dir->RetainGroup(id); } } if (group != nil) { err = inGroup->RemoveFromGroup(group); } else { err = ThrowError(VE_UAG_GROUPNAME_DOES_NOT_EXIST, s); } QuickReleaseRefCountable(group); return err; }
void VJSSession::_getUser( XBOX::VJSParms_getProperty& ioParms, CUAGSession* inSession) { VString s; CUAGUser* user = inSession->RetainUser(); if (user != nil) ioParms.ReturnValue(user->CreateJSUserObject(ioParms.GetContext())); QuickReleaseRefCountable(user); }
VJSPictureContainer::~VJSPictureContainer() { if (/*fOwnsPict &&*/ fPict != NULL) delete fPict; if (fMetaInfoIsValid) { JS4D::UnprotectValue(fContext, fMetaInfo); } QuickReleaseRefCountable(fMetaBag); }
void VJSGlobalClass::do_GetProgressIndicator(VJSParms_callStaticFunction& ioParms, VJSGlobalObject *inContext) { if (ioParms.IsStringParam(1)) { VString userinfo; ioParms.GetStringParam(1, userinfo); VProgressIndicator* progress = VProgressManager::RetainProgressIndicator(userinfo); if (progress != nil) ioParms.ReturnValue(VJSProgressIndicator::CreateInstance(ioParms.GetContextRef(), progress)); QuickReleaseRefCountable(progress); } }
void VJSSession::_promoteWith(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { sLONG promotionToken = 0; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { promotionToken = inSession->PromoteIntoGroup(group); } QuickReleaseRefCountable(group); ioParms.ReturnNumber(promotionToken); }
void VJSSession::_belongsTo(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { bool ok = false; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { ok = inSession->BelongsTo(group); } QuickReleaseRefCountable(group); ioParms.ReturnBool(ok); }
void VJSSession::_promoteWith(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { sLONG promotionToken = 0; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { CUAGThreadPrivilege* privileges = static_cast<CUAGThreadPrivilege*>(ioParms.GetContext().GetGlobalObjectPrivateInstance()->GetSpecific('uagX')); promotionToken = inSession->PromoteIntoGroup(group, privileges); } QuickReleaseRefCountable(group); ioParms.ReturnNumber(promotionToken); }
void VJSSession::_belongsTo(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { bool ok = false; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { CUAGThreadPrivilege* privileges = static_cast<CUAGThreadPrivilege*>(ioParms.GetContext().GetGlobalObjectPrivateInstance()->GetSpecific('uagX')); ok = inSession->BelongsTo(group, privileges); } QuickReleaseRefCountable(group); ioParms.ReturnBool(ok); }
VJSContextPool::~VJSContextPool() { if (fManager != NULL) fManager->_UnRegisterPool( this); xbox_assert( (fUsedContexts.size() == 0) && (fUnusedContexts.size() == 0) ); if (fNoUsedContextEvent != NULL) { if (fNoUsedContextEvent->Unlock()) QuickReleaseRefCountable( fNoUsedContextEvent); } fRequiredScripts.clear(); }
void VJSDirectory::_save(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory) { VFile* dest = ioParms.RetainFileParam(1); if (dest != nil || ioParms.CountParams() == 0) ioParms.ReturnBool(inDirectory->Save(dest) == VE_OK); else { XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); ioParms.ReturnBool(false); } QuickReleaseRefCountable(dest); }
VError VJSContextPool::_ReleaseContext( VJSGlobalContext* inContext) { VError err = VE_OK; if (inContext != NULL) { if (inContext != NULL) { if (fDelegate != NULL) { err = fDelegate->UninitializeJSContext( inContext); } QuickReleaseRefCountable( inContext); } } return err; }
VJSRequestHandler* VRPCService::_CreateRequestHandlerForMethods() { // TBD: use a module function handler instead of a global function handler VRIAJSCallbackGlobalFunction *callback = new VRIAJSCallbackGlobalFunction( L"doRequest"); VJSRequestHandler *handler = new VJSRequestHandler( fApplication, fPatternForMethods, callback); if (handler != NULL) { handler->SetEnable( true); VFilePath rpcImpl; VRIAServerApplication::Get()->GetWAFrameworkFolderPath( rpcImpl); rpcImpl.ToSubFolder( L"Core").ToSubFolder( L"Runtime").ToSubFolder( L"rpcService"); rpcImpl.SetFileName( L"rpc-server.js", true); VFile *file = new VFile( rpcImpl); handler->RegisterIncludedFile( file); QuickReleaseRefCountable( file); } return handler; }
void VJSSession::_checkPermission(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { bool ok = false; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { ok = inSession->BelongsTo(group); } if (!ok) { VString groupName; if (group != nil) group->GetName(groupName); ThrowError(VE_UAG_SESSION_FAILED_PERMISSION, groupName); } QuickReleaseRefCountable(group); ioParms.ReturnBool(ok); }
void VJSSession::_checkPermission(VJSParms_callStaticFunction& ioParms, CUAGSession* inSession) { bool ok = false; CUAGGroup* group = RetainParamGroup(inSession->GetDirectory(), ioParms, 1); if (group != nil) { CUAGThreadPrivilege* privileges = static_cast<CUAGThreadPrivilege*>(ioParms.GetContext().GetGlobalObjectPrivateInstance()->GetSpecific('uagX')); ok = inSession->BelongsTo(group, privileges); } if (!ok) { VString groupName; if (group != nil) group->GetName(groupName); ThrowError(VE_UAG_SESSION_FAILED_PERMISSION, groupName); } QuickReleaseRefCountable(group); ioParms.ReturnBool(ok); }
void VJSImage::_setPath(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPicture* pic = inPict->GetPict(); VString path; if (pic != nil) { if (ioParms.CountParams() == 0 || ioParms.IsNullParam(1)) { pic->SetOutsidePath(""); // empty string means no outside } else if (ioParms.IsBooleanParam(1)) { pic->SetOutsidePath("*"); } else if (ioParms.IsStringParam(1)) { ioParms.GetStringParam(1, path); pic->SetOutsidePath(path); if (!path.IsEmpty()) pic->ReloadFromOutsidePath(); } else { VFile* file = ioParms.RetainFileParam(1); if (file != nil) { file->GetPath(path, FPS_POSIX); pic->SetOutsidePath(path); if (file->Exists()) pic->ReloadFromOutsidePath(); } else pic->SetOutsidePath(""); QuickReleaseRefCountable(file); } //inPict->SetModif(); } }
void VJSImage::_saveMeta(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPicture* pic = inPict->GetPict(); if (pic != nil) { bool okmeta = false; VString jsonString; if (ioParms.IsObjectParam(1)) { VJSObject metadata(ioParms.GetContextRef()); ioParms.GetParamObject(1, metadata); okmeta = true; VJSJSON json(ioParms.GetContextRef()); json.Stringify(metadata, jsonString); } else { if (inPict->MetaInfoInited()) { okmeta = true; VJSValue metadata(ioParms.GetContextRef(), inPict->GetMetaInfo()); VJSJSON json(ioParms.GetContextRef()); json.Stringify(metadata, jsonString); } } if (okmeta) { VValueBag* bag = new VValueBag(); bag->FromJSONString(jsonString); inPict->SetMetaBag(bag); QuickReleaseRefCountable(bag); } //inPict->SetModif(); } }
XBOX::VError VRPCService::GetProxy( XBOX::VString& outProxy, const XBOX::VString& inModulePath, const XBOX::VString& inNamespace, const IHTTPRequest* inRequest, IHTTPResponse* inResponse) { VError err = VE_OK; outProxy.Clear(); if (fApplication != NULL) { VRIAContext *riaContext = fApplication->RetainNewContext( err); if (err == VE_OK) { VRPCCatalog *catalog = fApplication->RetainRPCCatalog( riaContext, &err, inRequest, inResponse); if (err == VE_OK) { if (catalog != NULL) { MapOfRPCSchema schemas; err = catalog->RetainSchemasByModule( inModulePath, schemas); if (err == VE_OK) { // Build the proxy VFile *bodyFile = NULL, *templateFile = NULL; VFilePath path; VRIAServerApplication::Get()->GetWAFrameworkFolderPath( path); path.ToSubFolder( L"Core").ToSubFolder( L"Runtime").ToSubFolder( L"rpcService"); path.SetFileName( L"proxy-body.js", true); bodyFile = new VFile( path); if (bodyFile == NULL) err = vThrowError( VE_MEMORY_FULL); if (err == VE_OK) { path.SetFileName( L"proxy-template.js", true); templateFile = new VFile( path); if (templateFile == NULL) err = vThrowError( VE_MEMORY_FULL); } if (err == VE_OK && bodyFile->Exists() && templateFile->Exists()) { VString templateString; VFileStream bodyStream( bodyFile); VFileStream templateStream( templateFile); err = bodyStream.OpenReading(); if (err == VE_OK) templateStream.OpenReading(); if (err == VE_OK) err = bodyStream.GetText( outProxy); if (err == VE_OK) { VValueBag bag; bag.SetString( L"rpc-pattern", fPatternForMethods); bag.SetString( L"publishInGlobalNamespace", (fPublishInClientGlobalNamespace) ? L"true" : L"false"); outProxy.Format( &bag); } if (err == VE_OK) err = templateStream.GetText( templateString); if (err == VE_OK) { if (templateString.BeginsWith( L"/*")) { // sc 28/08/2014, remove the copyright VIndex end = templateString.Find( L"*/"); if (end > 0) { templateString.Remove( 1, end + 1); } } for (MapOfRPCSchema::const_iterator iter = schemas.begin() ; iter != schemas.end() ; ++iter) { VValueBag bag; bag.SetString( L"function-name", iter->first.GetMethodName()); bag.SetString( L"namespace", inNamespace); bag.SetString( L"modulePath", inModulePath); VString proxy( templateString); proxy.Format( &bag); outProxy.AppendString( proxy); } } bodyStream.CloseReading(); templateStream.CloseReading(); } else { err = vThrowError( VE_FILE_NOT_FOUND); } QuickReleaseRefCountable( bodyFile); QuickReleaseRefCountable( templateFile); } } else { err = vThrowError( VE_RIA_RPC_CATALOG_NOT_FOUND); } } } ReleaseRefCountable( &riaContext); } return err; }
VRIAJSRuntimeContext::~VRIAJSRuntimeContext() { fContextMap.clear(); QuickReleaseRefCountable( fCurrentUAGSession); }
void VJSPictureContainer::SetMetaBag(const XBOX::VValueBag* metaBag) { QuickReleaseRefCountable(fMetaBag); fMetaBag = RetainRefCountable(metaBag); }
CUAGDirectory* VRIAServerSolution::_OpenUAGDirectory( VError& outError) { outError = VE_OK; CUAGDirectory *directory = nil; CUAGManager *uag = VComponentManager::RetainComponentOfType<CUAGManager>(); if (uag != NULL) { if (testAssert(fDesignSolution != NULL)) { StUseLogger logger; VMicrosecondsCounter usCounter; VProjectItem *dirItem = fDesignSolution->GetProjectItemFromTag( kUAGDirectoryTag); if (dirItem != NULL) { VFilePath directoryPath; dirItem->GetFilePath( directoryPath); usCounter.Start(); logger.Log( fLoggerID, eL4JML_Information, L"Opening the users and groups directory"); VFile file( directoryPath); directory = uag->RetainDirectory( file, FA_READ_WRITE, NULL, NULL, &outError); } if (directory == NULL && outError == VE_OK) { VFilePath solpath; fDesignSolution->GetSolutionFilePath(solpath); solpath.SetExtension(RIAFileKind::kDirectoryFileExtension); VFile defaultDirFile(solpath); directory = uag->RetainDirectory( defaultDirFile, FA_READ_WRITE, NULL, NULL, &outError, NULL, true); } if (directory != NULL && outError == VE_OK) { // Create an "admin" user if needed CUAGGroup *adminGroup = directory->RetainSpecialGroup( CUAGDirectory::AdminGroup); CUAGGroup *debuggerGroup = directory->RetainSpecialGroup( CUAGDirectory::DebuggerGroup); if ((adminGroup != NULL) && (debuggerGroup != NULL)) { StErrorContextInstaller errorContext( VE_UAG_USERNAME_DOES_NOT_EXIST, VE_OK); CUAGUser *adminUser = directory->RetainUser( L"admin"); if (adminUser == NULL) adminUser = directory->AddOneUser( L"admin", L"", L"", outError); if ((outError == VE_OK) && (adminUser != NULL)) { VUUID adminUserID, userID; adminUser->GetID( adminUserID); CUAGUserVector users; adminGroup->RetainUsers( users); bool hasAdminUser = false; for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter) { (*userIter)->GetID( userID); hasAdminUser = (adminUserID == userID); } if (!hasAdminUser) outError = adminUser->PutIntoGroup( adminGroup); if (outError == VE_OK) { users.clear(); debuggerGroup->RetainUsers( users); hasAdminUser = false; for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter) { (*userIter)->GetID( userID); hasAdminUser = (adminUserID == userID); } if (!hasAdminUser) outError = adminUser->PutIntoGroup( debuggerGroup); } } ReleaseRefCountable( &adminUser); } QuickReleaseRefCountable( adminGroup); QuickReleaseRefCountable( debuggerGroup); } if (directory != NULL && outError == VE_OK) { VString logMsg; logMsg.Printf( "Users and groups directory opened (duration: %i ms)", usCounter.Stop()/1000); logger.Log( fLoggerID, eL4JML_Information, logMsg); } } uag->Release(); } else { outError = ThrowError( VE_RIA_UAG_COMPONENT_NOT_FOUND); } return directory; }
VError VJSONBinaryImporter::GetValue(VJSONValue& outVal) { VError err = VE_OK; sBYTE btype = *((uBYTE*)fCurPtr); ++fCurPtr; switch (btype) { case JSON_null: outVal.SetNull(); break; case JSON_undefined: outVal.SetUndefined(); break; case JSON_true: outVal.SetBool(true); break; case JSON_false: outVal.SetBool(false); break; case JSON_string: { VString s; sLONG len = *((sLONG*)fCurPtr); fCurPtr += 4; s.FromBlock(fCurPtr, len * 2, VTC_UTF_16); fCurPtr += (len * 2); outVal.SetString(s); } break; case JSON_date: { VTime dd; sLONG8 ll = *((sLONG8*)fCurPtr); fCurPtr += 8; dd.FromMilliseconds(ll); outVal.SetTime(dd); } break; case JSON_number: { Real rr = *((Real*)fCurPtr); fCurPtr += sizeof(Real); outVal.SetNumber(rr); } break; case JSON_object: { if (*((sWORD*)fCurPtr) == -2) { outVal.SetUndefined(); } else { VJSONObject* obj = new VJSONObject(); sWORD len; do { len = *((sWORD*)fCurPtr); fCurPtr += 2; if (len >= 0) { VString name; name.FromBlock(fCurPtr, (sLONG)len * 2, VTC_UTF_16); fCurPtr += ((sLONG)len * 2); VJSONValue val; err = GetValue(val); obj->SetProperty(name, val); } } while (err == VE_OK && len != -1); outVal.SetObject(obj); QuickReleaseRefCountable(obj); } } break; case JSON_array: { sLONG count = *((sLONG*)fCurPtr); fCurPtr += 4; if (count == -2) { outVal.SetUndefined(); } else { VJSONArray* arr = new VJSONArray(); for (sLONG i = 0; i < count && err == VE_OK; ++i) { VJSONValue val; err = GetValue(val); arr->Push(val); } outVal.SetArray(arr); QuickReleaseRefCountable(arr); } } break; default: xbox_assert(false); break; } return err; }