#include "oils_constants.h"
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_settings.h"
+#include "opensrf/osrf_application.h"
#ifdef __cplusplus
extern "C" {
jsonObject* oilsUtilsQuickReq( const char* service, const char* method,
const jsonObject* params );
+jsonObject* oilsUtilsQuickReqCtx( osrfMethodContext* ctx, const char* service,
+ const char* method, const jsonObject* params );
+
jsonObject* oilsUtilsStorageReq( const char* method, const jsonObject* params );
jsonObject* oilsUtilsCStoreReq( const char* method, const jsonObject* params );
* Searches the storage server for a user with the given username
* Caller is responsible for freeing the returned object
*/
-jsonObject* oilsUtilsFetchUserByUsername( const char* name );
+jsonObject* oilsUtilsFetchUserByUsername( osrfMethodContext* ctx, const char* name );
/**
// Fetch a row from the actor.usr table, by username if available,
// or by barcode if not.
if(uname) {
- userObj = oilsUtilsFetchUserByUsername( uname );
+ userObj = oilsUtilsFetchUserByUsername( ctx, uname );
if( userObj && JSON_NULL == userObj->type ) {
jsonObjectFree( userObj );
userObj = NULL; // username not found
osrfLogInfo( OSRF_LOG_MARK, "Fetching user by barcode %s", barcode );
jsonObject* params = jsonParseFmt("{\"barcode\":\"%s\"}", barcode);
- jsonObject* card = oilsUtilsQuickReq(
- "open-ils.cstore", "open-ils.cstore.direct.actor.card.search", params );
+ jsonObject* card = oilsUtilsQuickReqCtx(
+ ctx, "open-ils.cstore", "open-ils.cstore.direct.actor.card.search", params );
jsonObjectFree( params );
if( card && card->type != JSON_NULL ) {
jsonObjectFree( card );
params = jsonParseFmt( "[%s]", userid );
free( userid );
- userObj = oilsUtilsQuickReq(
- "open-ils.cstore", "open-ils.cstore.direct.actor.user.retrieve", params );
+ userObj = oilsUtilsQuickReqCtx(
+ ctx, "open-ils.cstore", "open-ils.cstore.direct.actor.user.retrieve", params );
jsonObjectFree( params );
if( userObj && JSON_NULL == userObj->type ) {
// user not found (shouldn't happen, due to foreign key)
}
/**
+ @brief Perform a remote procedure call, propagating session
+ locale and timezone
+ @param service The name of the service to invoke.
+ @param method The name of the method to call.
+ @param params The parameters to be passed to the method, if any.
+ @return A copy of whatever the method returns as a result, or a JSON_NULL if the method
+ doesn't return anything.
+
+ If the @a params parameter points to a JSON_ARRAY, pass each element of the array
+ as a separate parameter. If it points to any other kind of jsonObject, pass it as a
+ single parameter. If it is NULL, pass no parameters.
+
+ The calling code is responsible for freeing the returned object by calling jsonObjectFree().
+*/
+jsonObject* oilsUtilsQuickReqCtx( osrfMethodContext* ctx, const char* service,
+ const char* method, const jsonObject* params ) {
+ if(!(service && method && ctx)) return NULL;
+
+ osrfLogDebug(OSRF_LOG_MARK, "oilsUtilsQuickReqCtx(): %s - %s (%s)", service, method, ctx->session->session_tz );
+
+ // Open an application session with the service, and send the request
+ osrfAppSession* session = osrfAppSessionClientInit( service );
+ osrf_app_session_set_tz(session, ctx->session->session_tz);
+ int reqid = osrfAppSessionSendRequest( session, params, method, 1 );
+
+ // Get the response
+ osrfMessage* omsg = osrfAppSessionRequestRecv( session, reqid, 60 );
+ jsonObject* result = jsonObjectClone( osrfMessageGetResult(omsg) );
+
+ // Clean up
+ osrfMessageFree(omsg);
+ osrfAppSessionFree(session);
+ return result;
+}
+
+/**
@brief Call a method of the open-ils.storage service.
@param method Name of the method.
@param params Parameters to be passed to the method, if any.
The calling code is responsible for freeing the returned object by calling jsonObjectFree().
*/
-jsonObject* oilsUtilsFetchUserByUsername( const char* name ) {
+jsonObject* oilsUtilsFetchUserByUsername( osrfMethodContext* ctx, const char* name ) {
if(!name) return NULL;
jsonObject* params = jsonParseFmt("{\"usrname\":\"%s\"}", name);
- jsonObject* user = oilsUtilsQuickReq(
- "open-ils.cstore", "open-ils.cstore.direct.actor.user.search", params );
+ jsonObject* user = oilsUtilsQuickReqCtx(
+ ctx, "open-ils.cstore", "open-ils.cstore.direct.actor.user.search", params );
jsonObjectFree(params);
long id = oilsFMGetObjectId(user);