Share<IAudio> AudioFactory::CreateFromRaw(const FileIdRef& fileId, AudioFileType audioFileType, const MemoryData& data, uint sampleCount, uint channelCount, uint samplerRate, uint bitsPerSample, ResourceShareType shareType /*= ResourceShareType::Share*/) { Share<IAudio> buffer; if (shareType != ResourceShareType::None) { buffer = Find(fileId); RETURN_SELF_IF_NOT_NULL(buffer); } switch (audioFileType) { #ifdef MEDUSA_OGG case AudioFileType::ogg: buffer = new OggAudio(data, fileId); break; #endif case AudioFileType::wav: buffer = new WavAudio(data, fileId); break; default: return nullptr; } buffer->SetSampleCount(sampleCount); buffer->SetChannelCount(sampleCount); buffer->SetSampleRate(samplerRate); buffer->SetBitsPerSample(bitsPerSample); Add(buffer, shareType); return buffer; }
// AddShare // // The caller gets a reference, if _share is not NULL. status_t SecurityContext::AddShare(const char* name, const char* path, Share** _share) { if (!name) return B_BAD_VALUE; // check, if the share does already exist ContextLocker _(this); if (fShares->Get(name)) return B_BAD_VALUE; // create a the share Share* share = new(std::nothrow) Share; if (!share) return B_NO_MEMORY; Reference<Share> shareReference(share, true); status_t error = share->Init(name, path); if (error != B_OK) return error; // add the share error = fShares->Put(name, share); if (error != B_OK) return error; shareReference.Detach(); if (_share) { *_share = share; share->AddReference(); } return B_OK; }
void Input<T>::adjust_mac(Share<T>& share, T& value) { T tmp; tmp.mul(MC.get_alphai(), value); tmp.add(share.get_mac(),tmp); share.set_mac(tmp); }
Share<const IStream> MemoryPackage::OnReadFile(const FileEntry& file, FileDataType dataType /*= FileDataType::Binary*/) const { UN_USED(dataType); Share<MemoryStream> memoryStream = mMemoryStreamDict.GetOptional(&file, nullptr); RETURN_NULL_IF_NULL(memoryStream); memoryStream->Rewind(); return memoryStream; }
// FindShare // // The caller gets a reference. Share* SecurityContext::FindShare(const char* name) { if (!name) return NULL; ContextLocker _(this); Share* share = fShares->Get(name); if (share) share->AddReference(); return share; }
Share<IShader> ShaderFactory::CreateShader( const FileIdRef& fileId,const List<HeapString>* defines/*=nullptr*/,ResourceShareType shareType /*= ResourceShareType::Share*/) { Share<IShader> result = nullptr; if (shareType != ResourceShareType::None) { result = Find(fileId); RETURN_SELF_IF_NOT_NULL(result); } result=ShaderCreater::Instance().Create(fileId.Name,fileId); if (result==nullptr) { switch(FileInfo::ExtractType(fileId.Name)) { case FileType::fsh: result=new BasePixelShader(fileId); break; case FileType::vsh: result=new BaseVertexShader(fileId); break; default: MEDUSA_ASSERT_FAILED("Unsupported shader file type"); return nullptr; } } MemoryData data= FileSystem::Instance().ReadAllData(fileId); if (data.IsNull()) { Log::FormatError("Cannot find:{}-{}", fileId.Name, fileId.Order); return nullptr; } StringRef str(data.Cast<char>()); if(result->Initialize(str,defines)) { Add(result, shareType); return result; } else { result = nullptr; } return nullptr; }
Share<IStream> MemoryPackage::OnWriteFile(FileEntry& file, FileOpenMode openMode /*= FileOpenMode::ReadOnly*/, FileDataType dataType /*= FileDataType::Binary*/) { UN_USED(dataType); Share<MemoryStream> memoryStream = mMemoryStreamDict.GetOptional(&file, nullptr); if (memoryStream == nullptr) { if (openMode == FileOpenMode::ReadOnly) { return nullptr; } memoryStream = new MemoryStream(); mMemoryStreamDict.Add(&file, memoryStream); } memoryStream->Rewind(); return memoryStream; }
Share<QuadModel> ModelFactory::CreateQuad( const FileIdRef& fileId ,ResourceShareType shareType /*= ResourceShareType::Share*/) { Share<QuadModel> model = nullptr; if (shareType != ResourceShareType::None) { model = Find(fileId).CastPtr<QuadModel>(); RETURN_SELF_IF_NOT_NULL(model); } auto material= MaterialFactory::Instance().CreateSingleTexture(fileId); model=new QuadModel(fileId,material,Rect2I(Point2I::Zero,material->FirstTexture()->Size())); model->Initialize(); Add(model, shareType); return model; }
// destructor SecurityContext::~SecurityContext() { // remove all user references for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) { User* user = it.Next().value; user->RemoveReference(); } // remove all share references for (ShareMap::Iterator it = fShares->GetIterator(); it.HasNext();) { Share* share = it.Next().value; share->RemoveReference(); } delete fUsers; delete fShares; delete fPermissions; delete fNode2Path; delete fPath2Node; }
Share<TiledTileset> TiledTilesetFactory::Create(const FileIdRef& fileId, ResourceShareType shareType /*= ResourceShareType::Share*/) { if (shareType != ResourceShareType::None) { auto val = Find(fileId); RETURN_SELF_IF_NOT_NULL(val); } Share<TiledTileset> model = new TiledTileset(fileId); RETURN_NULL_IF_NULL(model); if (model->LoadFromFileSystem(fileId)) { Add(model, shareType); } else { model = nullptr; } return model; }
// RemoveShare // // The caller gets a reference, if _share is not NULL. status_t SecurityContext::RemoveShare(const char* name, Share** _share) { if (!name) return B_BAD_VALUE; ContextLocker _(this); // get the share Share* share = FindShare(name); if (!share) return B_ENTRY_NOT_FOUND; Reference<Share> shareReference(share, true); // remove it status_t error = RemoveShare(share); if (error == B_OK && _share) { *_share = share; share->AddReference(); } return error; }
void FrameBuffer::AttachTexture( GraphicsAttachment attachment,GraphicsTextureTarget textureTarget, const Share<ITexture>& texture,int level ) { if(mRenderBuffers.ContainsKey(attachment)||mTextures.ContainsKey(attachment)) { MEDUSA_ASSERT_FAILED("Duplicate attachment"); return; } mTextures.Add(attachment,texture); Bind(true); Render::Instance().AttachTextureToFrameBuffer(attachment,textureTarget,texture->Texture(),level); Bind(false); UpdateClearMask(attachment,true); }
Share<Camera> CameraFactory::CreateDefault(StringRef name, const Size2F& winSize, bool isOrtho/*=false*/, bool isResizeable /*= true*/, ResourceShareType shareType /*= ResourceShareType::Share*/) { Share<Camera> camera; if (shareType!=ResourceShareType::None) { camera = Find(name); RETURN_SELF_IF_NOT_NULL(camera); } if (camera == nullptr) { camera = new Camera(name); camera->ResetDefault(winSize, isOrtho); Add(camera, shareType); if (isResizeable) { mResizeableCameras.Add(camera); } } return camera; }
void RenderStateTree::Release(const Share<RenderStateTreeLeafNode>& node) { RETURN_IF_NULL(node); auto* parent = node->Parent(); if (parent!=nullptr) { if (node->IsShared()) { node->Release(); } else { //single ref parent->Remove(node); //find most top empty parent if (parent->IsEmpty()) { auto* top = parent; auto* prevTop = parent; do { prevTop = top; top = top->Parent(); } while (top != mRoot&&top->IsSingle()); top->Remove(prevTop); } } } else { } }
// GetShares status_t SecurityContext::GetShares(BMessage* shares) { if (!shares) return B_BAD_VALUE; ContextLocker _(this); // iterate through all shares and add their names to the message for (ShareMap::Iterator it = fShares->GetIterator(); it.HasNext();) { Share* share = it.Next().value; // add name status_t error = shares->AddString("shares", share->GetName()); if (error != B_OK) return error; // add path error = shares->AddString("paths", share->GetPath()); if (error != B_OK) return error; } return B_OK; }
ISkeleton::ISkeleton(StringRef name, const Share<ISkeletonModel>& model) :INode(name), mModel(model), mAvatarModel(nullptr), mIsBoneVisible(false), mIsSlotVisible(true) { Start(); SetSize(model->GetBoundingSize()); SetAvatarModel(mModel->DefaultAvatar()); //create bones const List<SkeletonBoneModel*>& bones = mModel->Bones(); for (auto boneModel : bones) { SkeletonBone* bone = new SkeletonBone(boneModel); bone->SetSkeleton(this); mBones.Add(bone); mBoneDict.Add(boneModel->Name(), bone); } for (auto bone : mBones) { SkeletonBoneModel* parentBoneModel = bone->Model()->Parent(); if (parentBoneModel != nullptr) { SkeletonBone* parentBone = FindBone(parentBoneModel->Name()); parentBone->AddBone(bone); } } //create slots const List<SkeletonSlotModel*>& slots = mModel->Slots(); uintp slotCount = slots.Count(); FOR_EACH_SIZE(i, slotCount) { SkeletonSlotModel* slotModel = slots[i]; SkeletonBone* bone = FindBone(slotModel->ParentBone()->Name()); SkeletonSlot* slot = new SkeletonSlot(this, slotModel); slot->EnableManaged(); //slot->SetLogicZ(i); bone->AddSlot(slot); mSlots.Add(slot); mSlotDict.Add(slotModel->Name(), slot); AddChild(slot); }
Share<ShapeGeneralMesh> MeshFactory::CreateShapeCircleMesh(float radius, float precision, const Color4F& color) { //material->SetDrawMode(GraphicsDrawMode::TriangleFan); Share<ShapeGeneralMesh> mesh = new ShapeGeneralMesh(); uint count = (uint)Math::Ceil(Math::PI2 / precision); Point3F center(radius, radius); mesh->AppendVertex(center); mesh->AppendIndex(0); mesh->SetSize(msize3(2 * radius, 2 * radius, 0.f)); FOR_EACH_UINT32(i, count) { float a = i*precision; Point3F pos(radius + radius*Math::Cos(a), radius + radius*Math::Sin(a)); mesh->AppendVertex(pos); mesh->AppendIndex(i + 1); }
Share<ShapeQuadMesh> MeshFactory::CreateShapeQuadMesh(const Rect2F& rect, const Color4F& color) { Share<ShapeQuadMesh> mesh = new ShapeQuadMesh(); mesh->Initialize(rect, color); return mesh; }
Share<ShapeTriangleMesh> MeshFactory::CreateShapeTriangleMesh(const Point3F& p1, const Point3F& p2, const Point3F& p3, const Color4F& color) { Share<ShapeTriangleMesh> mesh = new ShapeTriangleMesh(); mesh->Initialize(p1, p2, p3, color); return mesh; }
Share<ShapeTriangleMesh> MeshFactory::CreateShapeTriangleMesh(float width, float height, const Color4F& color) { Share<ShapeTriangleMesh> mesh = new ShapeTriangleMesh(); mesh->Initialize(width, height, color); return mesh; }
// MessageReceived void NetFSServer::MessageReceived(BMessage* message) { switch (message->what) { case NETFS_REQUEST_GET_MESSENGER: { // for the time being we process all requests here BMessage reply; reply.AddMessenger("messenger", be_app_messenger); _SendReply(message, &reply); break; } case NETFS_REQUEST_ADD_USER: { // get user name and password const char* user; const char* password; if (message->FindString("user", &user) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } if (message->FindString("password", &password) != B_OK) password = NULL; // add the user status_t error = fSecurityContext->AddUser(user, password); _SendReply(message, error); break; } case NETFS_REQUEST_REMOVE_USER: { // get user name const char* userName; if (message->FindString("user", &userName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // remove the user User* user; status_t error = fSecurityContext->RemoveUser(userName, &user); if (error == B_OK) { // propagate the information to the client connections AutoLocker<Locker> _(fLock); for (int32 i = 0; ClientConnection* connection = (ClientConnection*)fClientConnections.ItemAt(i); i++) { connection->UserRemoved(user); } user->RemoveReference(); } _SendReply(message, error); break; } case NETFS_REQUEST_GET_USERS: { // get the users BMessage reply; BMessage users; status_t error = fSecurityContext->GetUsers(&users); if (error == B_OK) error = reply.AddMessage("users", &users); if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_GET_USER_STATISTICS: { // get user name const char* userName; if (message->FindString("user", &userName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // get the user User* user = fSecurityContext->FindUser(userName); if (!user) { _SendReply(message, B_ENTRY_NOT_FOUND); break; } Reference<User> userReference(user, true); // get the statistics BMessage statistics; status_t error = StatisticsManager::GetDefault() ->GetUserStatistics(user, &statistics); // prepare the reply BMessage reply; if (error == B_OK) error = reply.AddMessage("statistics", &statistics); // send the reply if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_ADD_SHARE: { // get share name and path const char* share; const char* path; if (message->FindString("share", &share) != B_OK || message->FindString("path", &path) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // add the share status_t error = fSecurityContext->AddShare(share, path); if (error == B_OK) _ServerInfoUpdated(); _SendReply(message, error); break; } case NETFS_REQUEST_REMOVE_SHARE: { // get share name const char* shareName; if (message->FindString("share", &shareName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // remove the share Share* share; status_t error = fSecurityContext->RemoveShare(shareName, &share); if (error == B_OK) { // propagate the information to the client connections AutoLocker<Locker> _(fLock); for (int32 i = 0; ClientConnection* connection = (ClientConnection*)fClientConnections.ItemAt(i); i++) { connection->ShareRemoved(share); } share->RemoveReference(); } if (error == B_OK) _ServerInfoUpdated(); _SendReply(message, error); break; } case NETFS_REQUEST_GET_SHARES: { // get the shares BMessage reply; BMessage shares; status_t error = fSecurityContext->GetShares(&shares); if (error == B_OK) error = reply.AddMessage("shares", &shares); if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_GET_SHARE_USERS: { // get share name const char* shareName; if (message->FindString("share", &shareName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } AutoLocker<Locker> securityContextLocker(fSecurityContext); // get the share Share* share = fSecurityContext->FindShare(shareName); if (!share) { _SendReply(message, B_ENTRY_NOT_FOUND); break; } Reference<Share> shareReference(share, true); // get all users BMessage allUsers; status_t error = fSecurityContext->GetUsers(&allUsers); if (error != B_OK) { _SendReply(message, error); break; } // filter the users with mount permission BMessage users; const char* userName; for (int32 i = 0; allUsers.FindString("users", i, &userName) == B_OK; i++) { if (User* user = fSecurityContext->FindUser(userName)) { // get the user's permissions Permissions permissions = fSecurityContext ->GetNodePermissions(share->GetPath(), user); user->RemoveReference(); // add the user, if they have the permission to mount the // share if (permissions.ImpliesMountSharePermission()) { error = users.AddString("users", userName); if (error != B_OK) { _SendReply(message, error); break; } } } } securityContextLocker.Unlock(); // prepare the reply BMessage reply; if (error == B_OK) error = reply.AddMessage("users", &users); // send the reply if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_GET_SHARE_STATISTICS: { // get share name const char* shareName; if (message->FindString("share", &shareName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // get the share Share* share = fSecurityContext->FindShare(shareName); if (!share) { _SendReply(message, B_ENTRY_NOT_FOUND); break; } Reference<Share> shareReference(share, true); // get the statistics BMessage statistics; status_t error = StatisticsManager::GetDefault() ->GetShareStatistics(share, &statistics); // prepare the reply BMessage reply; if (error == B_OK) error = reply.AddMessage("statistics", &statistics); // send the reply if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_SET_USER_PERMISSIONS: { // get share and user name, and the permissions const char* shareName; const char* userName; uint32 permissions; if (message->FindString("share", &shareName) != B_OK || message->FindString("user", &userName) != B_OK || message->FindInt32("permissions", (int32*)&permissions) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // get the share and the user Share* share = fSecurityContext->FindShare(shareName); User* user = fSecurityContext->FindUser(userName); Reference<Share> shareReference(share); Reference<User> userReference(user); if (!share || !user) { _SendReply(message, B_ENTRY_NOT_FOUND); break; } // set the permissions status_t error = B_OK; if (permissions == 0) { fSecurityContext->ClearNodePermissions(share->GetPath(), user); } else { error = fSecurityContext->SetNodePermissions(share->GetPath(), user, permissions); } if (error == B_OK) { // propagate the information to the client connections AutoLocker<Locker> _(fLock); for (int32 i = 0; ClientConnection* connection = (ClientConnection*)fClientConnections.ItemAt(i); i++) { connection->UserPermissionsChanged(share, user, permissions); } } _SendReply(message, error); break; } case NETFS_REQUEST_GET_USER_PERMISSIONS: { // get share and user name const char* shareName; const char* userName; if (message->FindString("share", &shareName) != B_OK || message->FindString("user", &userName) != B_OK) { _SendReply(message, B_BAD_VALUE); break; } // get the share and the user Share* share = fSecurityContext->FindShare(shareName); User* user = fSecurityContext->FindUser(userName); Reference<Share> shareReference(share); Reference<User> userReference(user); if (!share || !user) { _SendReply(message, B_ENTRY_NOT_FOUND); break; } // get the permissions Permissions permissions = fSecurityContext->GetNodePermissions( share->GetPath(), user); // prepare the reply BMessage reply; status_t error = reply.AddInt32("permissions", (int32)permissions.GetPermissions()); // send it if (error == B_OK) _SendReply(message, &reply); else _SendReply(message, error); break; } case NETFS_REQUEST_SAVE_SETTINGS: { status_t error = _SaveSettings(); // send a reply _SendReply(message, error); break; } } }
Resource * CreateDropDown( XMLIterator i, XMLCreatorEnv *env ) { XMLCreatorEnv ch_env; const char *p_name = "create dropdown"; BeginParentWidget( env, p_name, ch_env ); XMLAttributes attributes; XMLStyle branch_style; CascadeStyles( i, env, attributes, branch_style, ch_env); // skins & fonts for caption std::string skinName = get_attribute( attributes, "title_skin"); std::string fontName = get_attribute( attributes, "title_font"); SkinMan &skins = QuerySkinMan( skinName ); FontSet &fonts = QueryFontSet( fontName ); // caption position int titleAlign = 0; try_attribute_i( attributes, "title_align", &titleAlign ); std::vector<int> pos = to_integer_vector( "0,0" ); std::string position; if ( try_attribute( attributes, "title_distance", &position ) ) { pos = to_integer_vector( position ); if ( pos.size() != 2 ) { throw Error("pos attribute must have x and y coordinates"); } } CaptionStyle style( skins, fonts, titleAlign, Pos(pos[0], pos[1]) ); // temporary hub for child widget SPointer<HubWidget> ptr = new HubWidget( 100, 100 ); ch_env["parent_hub"] = ptr.get(); // create child element ChildsFromXML( i, &ch_env ); if( ptr->ChildrenCount() != 1 ) throw Error("DropDown widget %s must have one and only content.", (*i)._name.c_str()); Widget *content = ptr->FirstChild(); ptr->Retrieve( content ); if ( IWList *p_items = dynamic_cast< IWList *>( content )) { typedef DropButton< ListMenu, RadioLogic > ListMenuButton; ListMenu *lm = new ListMenuButton( style, p_items ); p_items->Items().SetFollowMode( ListLogic::FULL_FOLLOW ); p_items->Items().AllwaysSelected( 1 ); InsertChildWidget( lm, attributes, env ); SetHint( lm, attributes ); return new AnyResource< Widget *>( lm ); } else if ( IWTableList *p_table = dynamic_cast< IWTableList *>( content )) { Share< DataConnector > dataCon = dynamic_cast< DataTableWidget &>( p_table->Table() ) .GetDataConnector(); typedef DropButton< TableMenu, RadioLogic > TableMenuButton; TableMenu *tm = new TableMenuButton( style, p_table, dataCon.GetTarget() ); dynamic_cast< ListLogic &>( p_table->Enumerator() ) .SetFollowMode( ListLogic::FULL_FOLLOW ); dynamic_cast< ListLogic &>( p_table->Enumerator() ) .AllwaysSelected( 1 ); InsertChildWidget( tm, attributes, env ); SetHint( tm, attributes ); return new AnyResource< Widget *>( tm ); } return NULL; }
// Archive status_t SecurityContext::Archive(BMessage* archive, bool deep) const { if (!archive) return B_BAD_VALUE; status_t error = B_OK; ContextLocker _(const_cast<SecurityContext*>(this)); // users int32 userCount = fUsers->Size(); for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) { User* user = it.Next().value; BMessage userArchive; error = user->Archive(&userArchive, deep); if (error != B_OK) return error; error = archive->AddMessage("users", &userArchive); if (error != B_OK) return error; } // shares for (ShareMap::Iterator it = fShares->GetIterator(); it.HasNext();) { Share* share = it.Next().value; BMessage shareArchive; error = share->Archive(&shareArchive, deep); if (error != B_OK) return error; error = archive->AddMessage("shares", &shareArchive); if (error != B_OK) return error; } // permissions // we slice them per user BMessage* tmpUserArchives = new(std::nothrow) BMessage[userCount]; if (!tmpUserArchives) return B_NO_MEMORY; ArrayDeleter<BMessage> deleter(tmpUserArchives); HashMap<HashKey32<User*>, BMessage*> userArchives; int32 i = 0; for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) { User* user = it.Next().value; error = userArchives.Put(user, tmpUserArchives + i); if (error != B_OK) return error; i++; } // fill the per user archives for (PermissionMap::Iterator it = fPermissions->GetIterator(); it.HasNext();) { PermissionMap::Entry entry = it.Next(); BMessage* userArchive = userArchives.Get(entry.key.user); error = userArchive->AddInt32(entry.key.path.GetString(), entry.value.GetPermissions()); if (error != B_OK) return error; } // put the user permissions together BMessage permissionsArchive; for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) { User* user = it.Next().value; error = permissionsArchive.AddMessage(user->GetName(), userArchives.Get(user)); if (error != B_OK) return error; } error = archive->AddMessage("permissions", &permissionsArchive); if (error != B_OK) return error; return B_OK; }
// _LoadSecurityContext status_t NetFSServer::_LoadSecurityContext(SecurityContext** _securityContext) { // create a security context SecurityContext* securityContext = new(std::nothrow) SecurityContext; if (!securityContext) return B_NO_MEMORY; status_t error = securityContext->InitCheck(); if (error != B_OK) { delete securityContext; return error; } ObjectDeleter<SecurityContext> securityContextDeleter(securityContext); // load from driver settings for the time being DriverSettings settings; error = settings.Load("netfs-server"); if (error != B_OK) return error; // load users DriverParameter parameter; for (DriverParameterIterator it = settings.GetParameterIterator("user"); it.GetNext(¶meter);) { const char* userName = parameter.ValueAt(0); const char* password = parameter.GetParameterValue("password"); if (!userName) { WARN("Skipping nameless user settings entry.\n"); continue; } // PRINT(("user: %s, password: %s\n", parameter.ValueAt(0), // parameter.GetParameterValue("password"))); error = securityContext->AddUser(userName, password); if (error != B_OK) ERROR("ERROR: Failed to add user `%s'\n", userName); } // load shares for (DriverParameterIterator it = settings.GetParameterIterator("share"); it.GetNext(¶meter);) { const char* shareName = parameter.ValueAt(0); const char* path = parameter.GetParameterValue("path"); if (!shareName || !path) { WARN("settings: Skipping invalid share settings entry (no name" " or no path).\n"); continue; } // PRINT(("share: %s, path: %s\n", parameter.ValueAt(0), // parameter.GetParameterValue("path"))); Share* share; error = securityContext->AddShare(shareName, path, &share); if (error != B_OK) { ERROR("ERROR: Failed to add share `%s'\n", shareName); continue; } Reference<Share> shareReference(share, true); DriverParameter userParameter; // iterate through the share users for (DriverParameterIterator userIt = parameter.GetParameterIterator("user"); userIt.GetNext(&userParameter);) { const char* userName = userParameter.ValueAt(0); // PRINT((" user: %s\n", userName)); User* user = securityContext->FindUser(userName); if (!user) { ERROR("ERROR: Undefined user `%s'.\n", userName); continue; } Reference<User> userReference(user, true); DriverParameter permissionsParameter; if (!userParameter.FindParameter("permissions", &permissionsParameter)) { continue; } Permissions permissions; for (int32 i = 0; i < permissionsParameter.CountValues(); i++) { const char* permission = permissionsParameter.ValueAt(i); // PRINT((" permission: %s\n", permission)); if (strcmp(permission, "mount") == 0) { permissions.AddPermissions(MOUNT_SHARE_PERMISSION); } else if (strcmp(permission, "query") == 0) { permissions.AddPermissions(QUERY_SHARE_PERMISSION); } else if (strcmp(permission, "read") == 0) { permissions.AddPermissions(READ_PERMISSION | READ_DIR_PERMISSION | RESOLVE_DIR_ENTRY_PERMISSION); } else if (strcmp(permission, "write") == 0) { permissions.AddPermissions(WRITE_PERMISSION | WRITE_DIR_PERMISSION); } else if (strcmp(permission, "all") == 0) { permissions.AddPermissions(ALL_PERMISSIONS); } } error = securityContext->SetNodePermissions(share->GetPath(), user, permissions); if (error != B_OK) { ERROR("ERROR: Failed to set permissions for share `%s'\n", share->GetName()); } } } securityContextDeleter.Detach(); *_securityContext = securityContext; return B_OK; }
// constructor SecurityContext::SecurityContext(BMessage* archive) : BArchivable(archive), fUsers(new(std::nothrow) UserMap), fShares(new(std::nothrow) ShareMap), fPermissions(new(std::nothrow) PermissionMap), fNode2Path(new(std::nothrow) NodePathMap), fPath2Node(new(std::nothrow) PathNodeMap) { if (InitCheck() != B_OK) return; status_t error = B_OK; // users BMessage userArchive; for (int32 i = 0; archive->FindMessage("users", i, &userArchive) == B_OK; i++) { User tmpUser; error = tmpUser.Unarchive(&userArchive); if (error != B_OK) return; error = AddUser(tmpUser.GetName(), tmpUser.GetPassword()); if (error != B_OK) return; } // shares BMessage shareArchive; for (int32 i = 0; archive->FindMessage("shares", i, &shareArchive) == B_OK; i++) { Share tmpShare; error = tmpShare.Unarchive(&shareArchive); if (error != B_OK) return; error = AddShare(tmpShare.GetName(), tmpShare.GetPath()); if (error != B_OK) return; } // permissions BMessage permissionsArchive; if (archive->FindMessage("permissions", &permissionsArchive) != B_OK) return; #ifdef ANTARES_TARGET_PLATFORM_DANO const char* userName; #else char* userName; #endif type_code type; for (int32 userIndex = 0; permissionsArchive.GetInfo(B_MESSAGE_TYPE, userIndex, &userName, &type) == B_OK; userIndex++) { User* user = FindUser(userName); if (!user) return; Reference<User> userReference(user, true); error = permissionsArchive.FindMessage(userName, &userArchive); if (error != B_OK) return; // got a user: iterate through its permissions #ifdef ANTARES_TARGET_PLATFORM_DANO const char* path; #else char* path; #endif for (int32 i = 0; userArchive.GetInfo(B_INT32_TYPE, i, &path, &type) == B_OK; i++) { uint32 permissions; error = userArchive.FindInt32(path, (int32*)&permissions); if (error == B_OK) error = SetNodePermissions(path, user, permissions); } } }