SourceMod SDK  1.7
IHandleSys.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
34 
51 #include <IShareSys.h>
52 #include <sp_vm_types.h>
53 
54 #define SMINTERFACE_HANDLESYSTEM_NAME "IHandleSys"
55 #define SMINTERFACE_HANDLESYSTEM_VERSION 5
56 
58 #define DEFAULT_IDENTITY NULL
59 
60 #define NO_HANDLE_TYPE 0
61 
62 #define BAD_HANDLE 0
63 
64 namespace SourceMod
65 {
69  typedef unsigned int HandleType_t;
70 
74  typedef unsigned int Handle_t;
75 
76 
77  /*
78  * About type checking:
79  * Types can be inherited - a Parent type ("Supertype") can have child types.
80  * When accessing handles, type checking is done. This table shows how this is resolved:
81  *
82  * HANDLE CHECK -> RESULT
83  * ------ ----- ------
84  * Parent Parent Success
85  * Parent Child Fail
86  * Child Parent Success
87  * Child Child Success
88  */
89 
93  enum HandleError
94  {
95  HandleError_None = 0,
96  HandleError_Changed,
97  HandleError_Type,
98  HandleError_Freed,
99  HandleError_Index,
100  HandleError_Access,
101  HandleError_Limit,
102  HandleError_Identity,
103  HandleError_Owner,
104  HandleError_Version,
105  HandleError_Parameter,
106  HandleError_NoInherit,
107  };
108 
112  enum HTypeAccessRight
113  {
114  HTypeAccess_Create = 0,
115  HTypeAccess_Inherit,
116  /* -------------- */
117  HTypeAccess_TOTAL,
118  };
119 
125  enum HandleAccessRight
126  {
127  HandleAccess_Read,
128  HandleAccess_Delete,
129  HandleAccess_Clone,
130  /* ------------- */
131  HandleAccess_TOTAL,
132  };
133 
135  #define HANDLE_RESTRICT_IDENTITY (1<<0)
136 
137  #define HANDLE_RESTRICT_OWNER (1<<1)
138 
142  struct TypeAccess
143  {
146  {
147  hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
148  }
149  unsigned int hsVersion;
150  IdentityToken_t *ident;
151  bool access[HTypeAccess_TOTAL];
152  };
153 
158  {
161  {
162  hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
163  }
164  unsigned int hsVersion;
165  unsigned int access[HandleAccess_TOTAL];
166  };
167 
172  {
174  {
175  }
176  HandleSecurity(IdentityToken_t *owner, IdentityToken_t *identity)
177  : pOwner(owner), pIdentity(identity)
178  {
179  }
180  IdentityToken_t *pOwner;
181  IdentityToken_t *pIdentity;
182  };
183 
188  {
189  public:
191  virtual unsigned int GetDispatchVersion()
192  {
193  return SMINTERFACE_HANDLESYSTEM_VERSION;
194  }
195  public:
202  virtual void OnHandleDestroy(HandleType_t type, void *object) =0;
203 
213  virtual bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
214  {
215  return false;
216  }
217  };
218 
222  class IHandleSys : public SMInterface
223  {
224  public:
225  virtual unsigned int GetInterfaceVersion()
226  {
227  return SMINTERFACE_HANDLESYSTEM_VERSION;
228  }
229  virtual const char *GetInterfaceName()
230  {
231  return SMINTERFACE_HANDLESYSTEM_NAME;
232  }
233  public:
252  virtual HandleType_t CreateType(const char *name,
253  IHandleTypeDispatch *dispatch,
254  HandleType_t parent,
255  const TypeAccess *typeAccess,
256  const HandleAccess *hndlAccess,
257  IdentityToken_t *ident,
258  HandleError *err) =0;
259 
268  virtual bool RemoveType(HandleType_t type, IdentityToken_t *ident) =0;
269 
277  virtual bool FindHandleType(const char *name, HandleType_t *type) =0;
278 
289  virtual Handle_t CreateHandle(HandleType_t type,
290  void *object,
291  IdentityToken_t *owner,
292  IdentityToken_t *ident,
293  HandleError *err) =0;
294 
304  virtual HandleError FreeHandle(Handle_t handle, const HandleSecurity *pSecurity) =0;
305 
316  virtual HandleError CloneHandle(Handle_t handle,
317  Handle_t *newhandle,
318  IdentityToken_t *newOwner,
319  const HandleSecurity *pSecurity) =0;
320 
330  virtual HandleError ReadHandle(Handle_t handle,
331  HandleType_t type,
332  const HandleSecurity *pSecurity,
333  void **object) =0;
334 
342  virtual bool InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHandleAccess) =0;
343 
355  virtual Handle_t CreateHandleEx(HandleType_t type,
356  void *object,
357  const HandleSecurity *pSec,
358  const HandleAccess *pAccess,
359  HandleError *err) =0;
360 
366  virtual Handle_t FastCloneHandle(Handle_t hndl) =0;
367 
375  virtual bool TypeCheck(HandleType_t given, HandleType_t actual) = 0;
376  };
377 }
378 
379 #endif //_INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
380 
virtual unsigned int GetDispatchVersion()
Definition: IHandleSys.h:191
virtual bool TypeCheck(HandleType_t given, HandleType_t actual)=0
Type checks two handles.
virtual HandleError ReadHandle(Handle_t handle, HandleType_t type, const HandleSecurity *pSecurity, void **object)=0
Retrieves the contents of a handle.
virtual bool InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHandleAccess)=0
Sets access permissions on one or more structures.
Provides functions for managing Handles.
Definition: IHandleSys.h:222
Defines the Share System, responsible for shared resources and dependencies.
This is used to define per-type access rights.
Definition: IHandleSys.h:142
virtual void OnHandleDestroy(HandleType_t type, void *object)=0
Called when destroying a handle. Must be implemented.
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
IdentityToken_t * pIdentity
Definition: IHandleSys.h:181
virtual HandleType_t CreateType(const char *name, IHandleTypeDispatch *dispatch, HandleType_t parent, const TypeAccess *typeAccess, const HandleAccess *hndlAccess, IdentityToken_t *ident, HandleError *err)=0
Creates a new Handle type. NOTE: Currently, a child type may not have its own children. NOTE: Handle names must be unique if not private.
virtual bool FindHandleType(const char *name, HandleType_t *type)=0
Finds a handle type by name.
This pair of tokens is used for identification.
Definition: IHandleSys.h:171
HandleAccess()
Definition: IHandleSys.h:160
virtual bool RemoveType(HandleType_t type, IdentityToken_t *ident)=0
Removes a handle type. NOTE: This removes all child types.
unsigned int hsVersion
Definition: IHandleSys.h:164
IdentityToken_t * pOwner
Definition: IHandleSys.h:180
Hooks type-specific Handle operations.
Definition: IHandleSys.h:187
unsigned int access[HandleAccess_TOTAL]
Definition: IHandleSys.h:165
Definition: IAdminSystem.h:63
unsigned int hsVersion
Definition: IHandleSys.h:149
virtual HandleError CloneHandle(Handle_t handle, Handle_t *newhandle, IdentityToken_t *newOwner, const HandleSecurity *pSecurity)=0
Clones a handle by adding to its internal reference count. Its data, type, and security permissions r...
virtual Handle_t CreateHandleEx(HandleType_t type, void *object, const HandleSecurity *pSec, const HandleAccess *pAccess, HandleError *err)=0
Creates a new handle.
virtual HandleError FreeHandle(Handle_t handle, const HandleSecurity *pSecurity)=0
Frees the memory associated with a handle and calls any destructors. NOTE: This function will decreme...
virtual bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
Called to get the size of a handle's memory usage in bytes. Implementation is optional.
Definition: IHandleSys.h:213
virtual Handle_t FastCloneHandle(Handle_t hndl)=0
Clones a handle, bypassing security checks.
TypeAccess()
Definition: IHandleSys.h:145
virtual Handle_t CreateHandle(HandleType_t type, void *object, IdentityToken_t *owner, IdentityToken_t *ident, HandleError *err)=0
Creates a new handle.
virtual const char * GetInterfaceName()
Must return a string defining the interface's unique name.
Definition: IHandleSys.h:229
virtual unsigned int GetInterfaceVersion()
Must return an integer defining the interface's version.
Definition: IHandleSys.h:225
IdentityToken_t * ident
Definition: IHandleSys.h:150
bool access[HTypeAccess_TOTAL]
Definition: IHandleSys.h:151
This is used to define per-Handle access rights.
Definition: IHandleSys.h:157