that it will free whatever else needs freeing.
*/
static void sessionDataFree( char* key, void* item ) {
- if( !strcmp( key, "xact_id" ) || !strcmp( key, "authkey" ) )
+ if( !strcmp( key, "xact_id" ) || !strcmp( key, "authkey" ) || !strncmp( key, "rs_size_", 8) )
free( item );
else if( !strcmp( key, "user_login" ) )
jsonObjectFree( (jsonObject*) item );
}
/**
+ @brief Initialize session cache.
+ @param ctx Pointer to the method context.
+
+ Create a cache for the session by making the session's userData member point
+ to an osrfHash instance.
+*/
+static void initSessionCache( osrfMethodContext* ctx ) {
+ ctx->session->userData = osrfNewHash();
+ osrfHashSetCallback( (osrfHash*) ctx->session->userData, &sessionDataFree );
+ ctx->session->userDataFree = &userDataFree;
+}
+
+/**
@brief Save a transaction id.
@param ctx Pointer to the method context.
// If the session doesn't already have a hash, create one. Make sure
// that the application session frees the hash when it terminates.
- if( NULL == cache ) {
- session->userData = cache = osrfNewHash();
- osrfHashSetCallback( cache, &sessionDataFree );
- ctx->session->userDataFree = &userDataFree;
- }
+ if( NULL == cache )
+ initSessionCache( ctx );
// Save the transaction id in the hash, with the key "xact_id"
osrfHashSet( cache, strdup( session->session_id ), "xact_id" );
// If the session doesn't already have a hash, create one. Make sure
// that the application session frees the hash when it terminates.
- if( NULL == cache ) {
- session->userData = cache = osrfNewHash();
- osrfHashSetCallback( cache, &sessionDataFree );
- ctx->session->userDataFree = &userDataFree;
- }
+ if( NULL == cache )
+ initSessionCache( ctx );
osrfHash* pcache = osrfHashGet(cache, "pcache");
// If the session doesn't already have a hash, create one. Make sure
// that the application session frees the hash when it terminates.
- if( NULL == cache ) {
- session->userData = cache = osrfNewHash();
- osrfHashSetCallback( cache, &sessionDataFree );
- ctx->session->userDataFree = &userDataFree;
- }
+ if( NULL == cache )
+ initSessionCache( ctx );
if( user_login )
osrfHashSet( cache, user_login, "user_login" );
// If the session doesn't already have a hash, create one. Make sure
// that the application session frees the hash when it terminates.
- if( NULL == cache ) {
- session->userData = cache = osrfNewHash();
- osrfHashSetCallback( cache, &sessionDataFree );
- ctx->session->userDataFree = &userDataFree;
- }
+ if( NULL == cache )
+ initSessionCache( ctx );
// Save the transaction id in the hash, with the key "xact_id"
if( authkey && *authkey )
const char* method_type = osrfHashGet( method_metadata, "methodtype" );
if (!rs_size) {
- int *rs_size_from_hash = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request );
+ int *rs_size_from_hash = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "rs_size_req_%d", ctx->request );
if (rs_size_from_hash) {
rs_size = *rs_size_from_hash;
osrfLogDebug(OSRF_LOG_MARK, "used rs_size from request-scoped hash: %d", rs_size);
char* pkey = osrfHashGet( class_meta, "primarykey" );
+ if (!ctx->session->userData)
+ initSessionCache( ctx );
+
char *inside_verify = osrfHashGet( (osrfHash*) ctx->session->userData, "inside_verify" );
int need_to_verify = 1;
// 2. figure out one consistent rs_size for verifyObjectPCRUD to use
// over the whole life of this request. This means if we've already set
- // up a req_%d_rs_size, do nothing.
- int *rs_size = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request );
+ // up a rs_size_req_%d, do nothing.
+ int *rs_size = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "rs_size_req_%d", ctx->request );
if (!rs_size) { // pointer null, so value not set in hash
- rs_size = (int *) safe_malloc( sizeof(int) );
+ rs_size = (int *) safe_malloc( sizeof(int) ); // will be freed by sessionDataFree()
unsigned long long result_count = dbi_result_get_numrows( result );
*rs_size = (int) result_count * (flesh_depth + 1); // yes, we could lose some bits, but come on
- osrfLogDebug( OSRF_LOG_MARK, "about to set rs_size to %d", *rs_size );
- osrfHashSet( (osrfHash *) ctx->session->userData, rs_size, "req_%d_rs_size", ctx->request );
- int *rs_size_test = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request );
- if (rs_size_test)
- osrfLogDebug( OSRF_LOG_MARK, "immediately after set, get says rs_size is %d", *rs_size_test );
- else
- osrfLogDebug( OSRF_LOG_MARK, "immediately after set, get says rs_size is NULL!" );
+ osrfHashSet( (osrfHash *) ctx->session->userData, rs_size, "rs_size_req_%d", ctx->request );
}
if( dbi_result_first_row( result )) {