@@ -2097,6 +2097,25 @@ bool ClientSession::handlePresentationInfo(const std::shared_ptr<Message>& paylo
2097
2097
return forwardToClient (payload);
2098
2098
}
2099
2099
2100
+ namespace
2101
+ {
2102
+ class RemoveClipFile
2103
+ {
2104
+ private:
2105
+ std::string _clipFile;
2106
+ public:
2107
+ RemoveClipFile (const std::string& clipFile)
2108
+ : _clipFile(clipFile)
2109
+ {
2110
+ }
2111
+ ~RemoveClipFile ()
2112
+ {
2113
+ fprintf (stderr, " remove %s\n " , _clipFile.c_str ());
2114
+ FileUtil::removeFile (_clipFile);
2115
+ }
2116
+ };
2117
+ }
2118
+
2100
2119
bool ClientSession::handleKitToClientMessage (const std::shared_ptr<Message>& payload)
2101
2120
{
2102
2121
LOG_TRC (" handling kit-to-client [" << payload->abbr () << ' ]' );
@@ -2453,13 +2472,9 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
2453
2472
2454
2473
std::cerr << " FOO len: " << res.size () << " \n " ;
2455
2474
2456
- // FileUtil::removeFile(std::string("/tmp/cliptest"));
2457
- // std::ofstream fileStream;
2458
- // fileStream.open("/tmp/cliptest");
2459
- // fileStream.write(res.data(), res.size());
2460
- // fileStream.close();
2475
+ // final cleanup via clipFileRemove dtor
2476
+ std::shared_ptr<RemoveClipFile> clipFileRemove;
2461
2477
2462
- // final cleanup ...
2463
2478
bool removeClipFile = true ;
2464
2479
if (!empty && (!_wopiFileInfo || !_wopiFileInfo->getDisableCopy ()))
2465
2480
{
@@ -2475,6 +2490,9 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
2475
2490
else
2476
2491
fprintf (stderr, " don't save clipboard\n " );
2477
2492
2493
+ if (removeClipFile)
2494
+ clipFileRemove = std::make_shared<RemoveClipFile>(clipFile);
2495
+
2478
2496
for (const auto & it : _clipSockets)
2479
2497
{
2480
2498
auto socket = it.lock ();
@@ -2494,25 +2512,18 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
2494
2512
headers.emplace_back (" Cache-Control" , " no-cache" );
2495
2513
headers.emplace_back (" Connection" , " close" );
2496
2514
2497
- if (removeClipFile)
2498
- {
2499
- fprintf (stderr, " we will want to remove %s\n " , clipFile.c_str ());
2500
- session->setFinishedHandler ([clipFile](const std::shared_ptr<http::ServerSession>&) {
2501
- fprintf (stderr, " FINISHED WITH %s\n " , clipFile.c_str ());
2502
- FileUtil::removeFile (clipFile);
2503
- });
2504
- }
2515
+ // on final session dtor clipFileRemove cleanup removes clipboard file
2516
+ session->setFinishedHandler ([clipFileRemove](const std::shared_ptr<http::ServerSession>&) {});
2505
2517
2518
+ // Hand over socket to ServerSession which async provides clipboard
2519
+ // content backed by clipFile
2506
2520
session->asyncUpload (clipFile, std::move (headers));
2507
- // session->asyncUpload("/tmp/cliptest", std::move(headers));
2508
2521
socket->setHandler (std::static_pointer_cast<ProtocolHandlerInterface>(session));
2509
2522
2510
2523
LOG_INF (" Queued " << (empty?" empty" :" clipboard" ) << " response for send." );
2511
2524
}
2512
2525
2513
2526
fprintf (stderr, " removeClipFile is %d\n " , removeClipFile);
2514
- // if (removeClipFile)
2515
- // FileUtil::removeFile(clipFile);
2516
2527
#endif
2517
2528
_clipSockets.clear ();
2518
2529
return true ;
0 commit comments