1 // ClientConnection.h 2 3 #ifndef NET_FS_CLIENT_CONNECTION_H 4 #define NET_FS_CLIENT_CONNECTION_H 5 6 #include <OS.h> 7 #include <SupportDefs.h> 8 9 #include "ClientVolume.h" 10 #include "Locker.h" 11 #include "Permissions.h" 12 #include "QueryDomain.h" 13 #include "RequestHandler.h" 14 15 class AttrDirInfo; 16 class AttributeChangedEvent; 17 class AttributeDirectory; 18 class AttributeInfo; 19 class ClientConnectionListener; 20 class Connection; 21 class EntryCreatedEvent; 22 class EntryMovedEvent; 23 class EntryRemovedEvent; 24 class NodeHandleMap; 25 class RequestConnection; 26 class SecurityContext; 27 class StatChangedEvent; 28 class User; 29 class Share; 30 class VolumeManager; 31 32 // ClientConnection 33 class ClientConnection : private RequestHandler, 34 private ClientVolume::NodeMonitoringProcessor, 35 private QueryDomain { 36 public: 37 ClientConnection(Connection* connection, 38 SecurityContext* securityContext, 39 User* user, 40 ClientConnectionListener* listener); 41 ~ClientConnection(); 42 43 status_t Init(); 44 45 void Close(); 46 47 bool GetReference(); 48 void PutReference(); 49 50 void UserRemoved(User* user); 51 void ShareRemoved(Share* share); 52 void UserPermissionsChanged(Share* share, 53 User* user, Permissions permissions); 54 55 private: 56 class ConnectionReference; 57 struct VolumeMap; 58 class ClientVolumePutter; 59 friend class ClientVolumePutter; 60 struct VolumeNodeMonitoringEvent; 61 struct NodeMonitoringEventQueue; 62 struct QueryHandleUnlocker; 63 friend struct QueryHandleUnlocker; 64 struct ClientVolumeFilter; 65 struct HasQueryPermissionClientVolumeFilter; 66 67 virtual status_t VisitConnectionBrokenRequest( 68 ConnectionBrokenRequest* request); 69 virtual status_t VisitInitConnectionRequest( 70 InitConnectionRequest* request); 71 virtual status_t VisitMountRequest(MountRequest* request); 72 virtual status_t VisitUnmountRequest(UnmountRequest* request); 73 virtual status_t VisitReadVNodeRequest( 74 ReadVNodeRequest* request); 75 virtual status_t VisitWriteStatRequest( 76 WriteStatRequest* request); 77 virtual status_t VisitCreateFileRequest( 78 CreateFileRequest* request); 79 virtual status_t VisitOpenRequest(OpenRequest* request); 80 virtual status_t VisitCloseRequest(CloseRequest* request); 81 virtual status_t VisitReadRequest(ReadRequest* request); 82 virtual status_t VisitWriteRequest(WriteRequest* request); 83 virtual status_t VisitCreateLinkRequest( 84 CreateLinkRequest* request); 85 virtual status_t VisitUnlinkRequest(UnlinkRequest* request); 86 virtual status_t VisitCreateSymlinkRequest( 87 CreateSymlinkRequest* request); 88 virtual status_t VisitReadLinkRequest(ReadLinkRequest* request); 89 virtual status_t VisitRenameRequest(RenameRequest* request); 90 virtual status_t VisitMakeDirRequest(MakeDirRequest* request); 91 virtual status_t VisitRemoveDirRequest( 92 RemoveDirRequest* request); 93 virtual status_t VisitOpenDirRequest(OpenDirRequest* request); 94 virtual status_t VisitReadDirRequest(ReadDirRequest* request); 95 virtual status_t VisitWalkRequest(WalkRequest* request); 96 virtual status_t VisitMultiWalkRequest( 97 MultiWalkRequest* request); 98 virtual status_t VisitOpenAttrDirRequest( 99 OpenAttrDirRequest* request); 100 virtual status_t VisitReadAttrDirRequest( 101 ReadAttrDirRequest* request); 102 virtual status_t VisitReadAttrRequest(ReadAttrRequest* request); 103 virtual status_t VisitWriteAttrRequest( 104 WriteAttrRequest* request); 105 virtual status_t VisitRemoveAttrRequest( 106 RemoveAttrRequest* request); 107 virtual status_t VisitRenameAttrRequest( 108 RenameAttrRequest* request); 109 virtual status_t VisitStatAttrRequest(StatAttrRequest* request); 110 virtual status_t VisitOpenQueryRequest( 111 OpenQueryRequest* request); 112 virtual status_t VisitReadQueryRequest( 113 ReadQueryRequest* request); 114 115 // ClientVolume::NodeMonitoringProcessor 116 virtual void ProcessNodeMonitoringEvent(int32 volumeID, 117 NodeMonitoringEvent* event); 118 void CloseNodeMonitoringEventQueue(); 119 120 // QueryDomain 121 virtual bool QueryDomainIntersectsWith(Volume* volume); 122 virtual void ProcessQueryEvent(NodeMonitoringEvent* event); 123 124 void _Close(); 125 void _MarkClosed(bool error); 126 127 void _GetNodeInfo(Node* node, NodeInfo* info); 128 void _GetEntryInfo(Entry* entry, EntryInfo* info); 129 status_t _GetAttrInfo(Request* request, 130 const char* name, const attr_info& attrInfo, 131 const void* data, AttributeInfo* info); 132 status_t _GetAttrDirInfo(Request* request, 133 AttributeDirectory* attrDir, 134 AttrDirInfo* info); 135 136 status_t _CreateVolume(ClientVolume** volume); 137 ClientVolume* _GetVolume(int32 id); 138 void _PutVolume(ClientVolume* volume); 139 void _UnmountVolume(ClientVolume* volume); 140 void _UnmountAllVolumes(); 141 142 static int32 _NodeMonitoringProcessorEntry(void* data); 143 int32 _NodeMonitoringProcessor(); 144 145 status_t _PushNodeMonitoringEvent(int32 volumeID, 146 NodeMonitoringEvent* event); 147 148 status_t _EntryCreated(ClientVolume* volume, 149 EntryCreatedEvent* event, 150 NodeMonitoringRequest*& request); 151 status_t _EntryRemoved(ClientVolume* volume, 152 EntryRemovedEvent* event, 153 NodeMonitoringRequest*& request); 154 status_t _EntryMoved(ClientVolume* volume, 155 EntryMovedEvent* event, 156 NodeMonitoringRequest*& request); 157 status_t _NodeStatChanged(ClientVolume* volume, 158 StatChangedEvent* event, 159 NodeMonitoringRequest*& request); 160 status_t _NodeAttributeChanged(ClientVolume* volume, 161 AttributeChangedEvent* event, 162 NodeMonitoringRequest*& request); 163 164 bool _KnownAttributeType(type_code type); 165 void _ConvertAttribute(const attr_info& info, 166 void* buffer); 167 168 status_t _OpenQuery(const char* queryString, 169 uint32 flags, port_id remotePort, 170 int32 remoteToken, QueryHandle** handle); 171 status_t _CloseQuery(QueryHandle* handle); 172 status_t _LockQueryHandle(int32 cookie, 173 QueryHandle** handle); 174 void _UnlockQueryHandle(NodeHandle* nodeHandle); 175 176 int32 _GetAllClientVolumeIDs(int32* volumeIDs, 177 int32 arraySize, 178 ClientVolumeFilter* filter = NULL); 179 int32 _GetContainingClientVolumes( 180 Directory* directory, int32* volumeIDs, 181 int32 arraySize, 182 ClientVolumeFilter* filter = NULL); 183 184 private: 185 RequestConnection* fConnection; 186 SecurityContext* fSecurityContext; 187 Locker fSecurityContextLock; 188 User* fUser; 189 VolumeMap* fVolumes; 190 NodeHandleMap* fQueryHandles; 191 ClientConnectionListener* fListener; 192 NodeMonitoringEventQueue* fNodeMonitoringEvents; 193 thread_id fNodeMonitoringProcessor; 194 Locker fLock; 195 int32 fReferenceCount; 196 int32 fInitialized; 197 bool fClosed; 198 bool fError; 199 bool fInverseClientEndianess; 200 }; 201 202 // ClientConnectionListener 203 class ClientConnectionListener { 204 public: 205 ClientConnectionListener(); 206 virtual ~ClientConnectionListener(); 207 208 virtual void ClientConnectionClosed( 209 ClientConnection* connection, 210 bool broken) = 0; 211 }; 212 213 #endif // NET_FS_CLIENT_CONNECTION_H 214