Skip to content

Commit

Permalink
wsd: LockUpdateResult captures the requested lock state
Browse files Browse the repository at this point in the history
Change-Id: I0b692e3875a7e3e5ea82ac2fee44c02ce2804b95
Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod authored and caolanm committed Aug 22, 2024
1 parent c71d8ed commit 73c124f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
36 changes: 22 additions & 14 deletions wsd/Storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ class StorageBase
/// The state of an asynchronous Upload request.
using AsyncUpload = AsyncRequest<UploadResult>;

STATE_ENUM(LockState,
LOCK, //< Lock the document.
UNLOCK, //< Unlock the document .
);

/// Represents the Lock request result, with a Result code
/// and a reason message (typically for errors).
/// Note: the reason message may be displayed to the clients.
Expand All @@ -279,14 +284,17 @@ class StorageBase
FAILED //< Other failures.
);

explicit LockUpdateResult(Status status)
: _status(status)
/// Construct a LockUpdateResult without a failure reason.
LockUpdateResult(Status status, LockState requestedLockState)
: LockUpdateResult(status, requestedLockState, /*reason=*/std::string())
{
}

LockUpdateResult(Status status, std::string reason)
/// Construct a LockUpdateResult with a failure reason.
LockUpdateResult(Status status, LockState requestedLockState, std::string reason)
: _status(status)
, _reason(std::move(reason))
, _requestedLockState(requestedLockState)
{
}

Expand All @@ -298,9 +306,12 @@ class StorageBase

const std::string& getReason() const { return _reason; }

LockState requestedLockState() const { return _requestedLockState; }

private:
Status _status;
std::string _reason;
LockState _requestedLockState;
};

/// The state of an asynchronous lock request.
Expand Down Expand Up @@ -374,11 +385,6 @@ class StorageBase

std::string getFileExtension() const { return Poco::Path(_fileInfo.getFilename()).getExtension(); }

STATE_ENUM(LockState,
LOCK, //< Lock the document.
UNLOCK, //< Unlock the document .
);

/// Update the locking state (check-in/out) of the associated file synchronously.
virtual LockUpdateResult updateLockState(const Authorization& auth, LockContext& lockCtx,
LockState lock, const Attributes& attribs) = 0;
Expand Down Expand Up @@ -526,20 +532,22 @@ class LocalStorage : public StorageBase
/// obtained using getFileInfo method
std::unique_ptr<LocalFileInfo> getLocalFileInfo();

LockUpdateResult updateLockState(const Authorization&, LockContext&, StorageBase::LockState,
LockUpdateResult updateLockState(const Authorization&, LockContext&,
StorageBase::LockState requestedLockState,
const Attributes&) override
{
return LockUpdateResult(LockUpdateResult::Status::OK);
return LockUpdateResult(LockUpdateResult::Status::OK, requestedLockState);
}

void updateLockStateAsync(const Authorization&, LockContext&, LockState, const Attributes&,
SocketPoll&,
void updateLockStateAsync(const Authorization&, LockContext&, LockState requestedLockState,
const Attributes&, SocketPoll&,
const AsyncLockStateCallback& asyncLockStateCallback) override
{
if (asyncLockStateCallback)
{
asyncLockStateCallback(AsyncLockUpdate(AsyncLockUpdate::State::Complete,
LockUpdateResult(LockUpdateResult::Status::OK)));
asyncLockStateCallback(AsyncLockUpdate(
AsyncLockUpdate::State::Complete,
LockUpdateResult(LockUpdateResult::Status::OK, requestedLockState)));
}
}

Expand Down
25 changes: 13 additions & 12 deletions wsd/wopi/WopiStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ StorageBase::LockUpdateResult WopiStorage::updateLockState(const Authorization&
const Attributes& attribs)
{
if (!lockCtx.supportsLocks())
return LockUpdateResult(LockUpdateResult::Status::UNSUPPORTED);
return LockUpdateResult(LockUpdateResult::Status::UNSUPPORTED, lock);

Poco::URI uriObject(getUri());
auth.authorizeURI(uriObject);
Expand Down Expand Up @@ -399,7 +399,7 @@ StorageBase::LockUpdateResult WopiStorage::updateLockState(const Authorization&
if (httpResponse->statusLine().statusCode() == http::StatusCode::OK)
{
lockCtx.setState(lock);
return LockUpdateResult(LockUpdateResult::Status::OK);
return LockUpdateResult(LockUpdateResult::Status::OK, lock);
}

failureReason = httpResponse->get("X-WOPI-LockFailureReason", "");
Expand All @@ -420,7 +420,7 @@ StorageBase::LockUpdateResult WopiStorage::updateLockState(const Authorization&
failureReason = std::string("Internal error: ") + exc.what();
}

return LockUpdateResult(LockUpdateResult::Status::FAILED, failureReason);
return LockUpdateResult(LockUpdateResult::Status::FAILED, lock, failureReason);
}

void WopiStorage::updateLockStateAsync(const Authorization& auth, LockContext& lockCtx,
Expand All @@ -434,15 +434,15 @@ void WopiStorage::updateLockStateAsync(const Authorization& auth, LockContext& l

// Always invoke the callback with the result of the async locking.
ScopedInvokeAsyncRequestCallback<AsyncLockStateCallback, AsyncLockUpdate> scopedInvokeCallback(
asyncLockStateCallback,
AsyncLockUpdate(AsyncLockUpdate::State::Error,
LockUpdateResult(LockUpdateResult::Status::FAILED, "Internal error")));
asyncLockStateCallback, AsyncLockUpdate(AsyncLockUpdate::State::Error,
LockUpdateResult(LockUpdateResult::Status::FAILED,
lock, "Internal error")));

if (!lockCtx.supportsLocks())
{
scopedInvokeCallback.setArg(
AsyncLockUpdate(AsyncLockUpdate::State::Complete,
LockUpdateResult(LockUpdateResult::Status::UNSUPPORTED)));
LockUpdateResult(LockUpdateResult::Status::UNSUPPORTED, lock)));
return;
}

Expand Down Expand Up @@ -509,8 +509,9 @@ void WopiStorage::updateLockStateAsync(const Authorization& auth, LockContext& l
if (httpResponse->statusLine().statusCode() == http::StatusCode::OK)
{
lockCtx.setState(lock);
return asyncLockStateCallback(AsyncLockUpdate(
AsyncLockUpdate::State::Complete, LockUpdateResult(LockUpdateResult::Status::OK)));
return asyncLockStateCallback(
AsyncLockUpdate(AsyncLockUpdate::State::Complete,
LockUpdateResult(LockUpdateResult::Status::OK, lock)));
}

const std::string failureReason = httpResponse->get("X-WOPI-LockFailureReason", "");
Expand All @@ -527,16 +528,16 @@ void WopiStorage::updateLockStateAsync(const Authorization& auth, LockContext& l

return asyncLockStateCallback(AsyncLockUpdate(
AsyncLockUpdate::State::Error,
LockUpdateResult(LockUpdateResult::Status::UNAUTHORIZED, failureReason)));
LockUpdateResult(LockUpdateResult::Status::UNAUTHORIZED, lock, failureReason)));
};

_lockHttpSession->setFinishedHandler(finishedCallback);

LOG_DBG("Async " << wopiLog << " request: " << httpRequest.header().toString());

// Notify client via callback that the request is in progress...
scopedInvokeCallback.setArg(AsyncLockUpdate(AsyncLockUpdate::State::Running,
LockUpdateResult(LockUpdateResult::Status::OK)));
scopedInvokeCallback.setArg(AsyncLockUpdate(
AsyncLockUpdate::State::Running, LockUpdateResult(LockUpdateResult::Status::OK, lock)));

// Make the request.
_lockHttpSession->asyncRequest(httpRequest, socketPoll);
Expand Down

0 comments on commit 73c124f

Please sign in to comment.