The SHDefaultAccessPolicy API (derives from SHAccessPolicy -> SHComponent -> SHDistributableObject -> BArchivable)

The SHDefaultAccessPolicy is a simple implementation of the SHAccessPolicy interface.  It can be used for common policy cases where you don't care too much about security issues or complex access control algorithms.  By default, this class allows every type of access.  You can, however, specify a password for this class to require, in which case only clients who connect with the given password are allowed to continue.



SHDefaultAccessPolicy(int port = SH_DEFAULT_PORT, int debugLevel = 0, const char * password = NULL, int32 threadPriority = B_REGULAR_PRIORITY, int32 encoding = SH_ENCODING_NONE)

This constructor lets you specify the port number, default debug level, and password.  All fields have defaults:  (port), if not specified, will default to the port SH_DEFAULT_PORT, as specified in <sockhop/SockHopConstants.h>.  (debugLevel) defaults to off (0), and (password) defaults to no password required.  If (port) is set to zero, the system will choose an available port to listen on.
 



virtual SHNodeSpec GetListeningLocation()

Returns an SHNodeSpec with the port number set to the port number specified in the constructor.  If (password) was specified in the constructor, the field "password", with the expected password string, will be added to the SpecMessage of the returned SHNodeSpec.
 



virtual bool OkayToAcceptConnection(SHNodeSpec & connectingSpec)

If no password was specified for this object, then this method always returns true.  If a password was specified, then this method will only return true if the client's (connectingSpec) has a field named "password" in its SpecMessage, and that field's contents is a string that matches our password exactly.
 



virtual bool OkayToWriteFile(const char * fileName)

Always returns true.
 



virtual bool OkayToReadFile(const char * fileName)

Always returns true.



virtual bool OkayToInstantiateObject(const BMessage & archive)

Always returns true.



virtual int GetDefaultDebugLevel()

Returns the debug level specified in the constructor.
 



virtual const char * GetName() const

Returns the string literal "default".



virtual status_t GetAddOnSpec(SHFileSpec & addTo) const

Passes the call on back to SHAccessPolicy::GetAddOnSpec().



SHDefaultAccessPolicy(BMessage * archive)

Looks for string fields named "port", "password", "debug", "priority", and "encoding" in (archive).  If it doesn't find them, defaults will be used.  "port", "debug", and "priority" should be string representations of integers, while "password" may be any string.  "encoding" may be one of the following:  "none", "batch", "zliblight", "zlibmedium", or "zlibheavy".
 



static BArchivable * Instantiate(BMessage * archive)

Needed to be an instantiatable BArchivable object.  Returns a new SHDefaultAccessPolicy, using the above (BMessage *) constructor.


virtual status_t Archive(BMessage * archive, bool deep=true) const

Dehydration method.  Must be called at the beginning of subclass's Archive() methods.