All that was by way of saying, sorry for the ambivalence about sessions. They're really useful.
void * wftk_session_alloc (); void wftk_session_free (void * session); void wftk_session_current (void * session, XML * object); void wftk_session_configure (void * session, XML * config); void wftk_session_setuser (void * session, char * userid); XML * wftk_session_getuser (void * session); XML * wftk_session_stashvalue (void * session, const char * value); void wftk_session_freevalue (void * session, const char * value); XML * wftk_session_cache (void * session, XML * key, int * found); XML * wftk_session_cachecheck (void * session, XML * key);
void *
The
wftk_session_alloc
simply allocates a fresh wftk session. You must free the session with
wftk_session_free
.
void * session
The wftk_session_alloc
frees a session object and cleans up any associated configuration, cached objects,
and stashed values it may have.
Sets the given object as the "current" member of its class. This function should be considered deprecated, as it was an initial stab at caching. I don't think it makes a lot of sense at this point.void * session
,
XML * object
Sets the given XML as the configuration structure for the session. The configuration structure is used by the internal library and by adaptors to retrieve various named values for the session. Eventually we need to document those.void * session
,
XML * config
Sets the given userid as the current user of the session. This value will be used by the permissions database to determine permission levels, will be used as the "Requestor" role in processes started via action, and will be used to look up user information forvoid * session
,
const char * userid
wftk_session_getuser
.
XML *
void * session
Returns an XML user structure encoding everything wftk knows about the current user. This is pretty much limited to the
userid and contact information at this point.
XML *
Stashes a string value so that the heap manager (such as it is) can clean it up when the session is killed. The other benefit to this is that duplicated values can be managed together; if a value is already in the stash, then the same XML will be returned. This saves a lot of hassle about who should do the freeing of malloc'd strings. The XML returned is in the form of <value value="(string)">, where "(string)" is of course the value you supply.void * session
,
const char * value
If you want to avoid growing your session value stash, you can suggest that the session free your value when you know you're done with it. This decrements a reference count; values won't be freed if somebody else was using them. The values will all be freed when you free the session anyway, but if you have a long-term session this might come in handy.void * session
,
const char * value
XML *
The object cache is another useful feature of the session. The way you use it is simple. If you have the type (element name) and id (id attribute) of an object, you can create XML to that effect. An example would be <datasheet id="48">. Supply this "key" object to the cache, and if the object is found, your key will be freed and the cached version will be returned. If the object isn't cached, then the key will be kept in the cache (just in case it's a full object) and also returned. The "found" parameter can be used to signal whether the returned value is the original key or not; in many cases you won't care, so if this parameter is NULL, the function won't fail.void * session
,
XML * key
,
int * found
XML *
Thevoid * session
,
XML * key
wftk_session_cachecheck
function never adds anything to the cache. It returns NULL if the given key doesn't
find anything in the cache.