Skip to content

Commit

Permalink
ews: rename subscriptions class members
Browse files Browse the repository at this point in the history
Make the expression ``x->subscriptions`` for any given x unambiguous;
make a distinction between ``EWSPlugin::subscriptions``,
``EWSPlugin::SubManager::subscriptions`` and
``EWSPlugin::NotificationContext::subscriptions``.
  • Loading branch information
jengelh committed Oct 23, 2024
1 parent ac724ea commit 5e70545
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions exch/ews/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ EWSContext::EWSContext(int id, HTTP_AUTH_INFO ai, const char *data, uint64_t len
EWSContext::~EWSContext()
{
if(m_notify)
for(const tSubscriptionId& sub : m_notify->subscriptions)
for (const auto &sub : m_notify->nct_subs)
unsubscribe(sub);
}

Expand Down Expand Up @@ -1576,7 +1576,7 @@ BINARY EWSContext::serialize(const XID& xid) const
bool EWSContext::streamEvents(const tSubscriptionId& subscriptionId) const
{
if(m_notify)
m_notify->subscriptions.emplace_back(subscriptionId);
m_notify->nct_subs.emplace_back(subscriptionId);
return m_plugin.linkSubscription(subscriptionId, *this);
}

Expand Down Expand Up @@ -2141,10 +2141,10 @@ tSubscriptionId EWSContext::subscribe(const std::vector<sFolderId>& folderIds, u
detail::ExmdbSubscriptionKey key =
m_plugin.subscribe(m_auth_info.maildir, eventMask, true, rop_util_make_eid_ex(1, PRIVATE_FID_IPMSUBTREE),
subscriptionId.ID);
mgr->subscriptions.emplace_back(key);
mgr->inner_subs.emplace_back(key);
return subscriptionId;
}
mgr->subscriptions.reserve(folderIds.size());
mgr->inner_subs.reserve(folderIds.size());
std::string target;
std::string maildir;
for(const sFolderId& f : folderIds) {
Expand All @@ -2159,8 +2159,8 @@ tSubscriptionId EWSContext::subscribe(const std::vector<sFolderId>& folderIds, u
throw EWSError::InvalidSubscriptionRequest(E3200);
if(!(permissions(maildir, folderspec.folderId) & frightsReadAny))
continue; // TODO: proper error handling
mgr->subscriptions.emplace_back(m_plugin.subscribe(maildir, eventMask, all, folderspec.folderId,
subscriptionId.ID));
mgr->inner_subs.emplace_back(m_plugin.subscribe(maildir,
eventMask, all, folderspec.folderId, subscriptionId.ID));
}
return subscriptionId;
}
Expand Down
11 changes: 6 additions & 5 deletions exch/ews/ews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ int EWSContext::notify()

// S_SLEEP: Just woke up, check for new events and deliver update message
bool moreAny = false;
for(const tSubscriptionId& subscription : nctx.subscriptions) {
for (const auto &subscription : nctx.nct_subs) {
try {
auto[events, more] = getEvents(subscription);
moreAny = moreAny || more;
Expand All @@ -704,13 +704,14 @@ int EWSContext::notify()
}
}
for(const tSubscriptionId& subscription : msg.ErrorSubscriptionIds)
nctx.subscriptions.erase(std::remove(nctx.subscriptions.begin(), nctx.subscriptions.end(), subscription),
nctx.subscriptions.end());
nctx.nct_subs.erase(std::remove(nctx.nct_subs.begin(), nctx.nct_subs.end(), subscription),
nctx.nct_subs.end());
msg.success();
// If there are no more subscriptions to monitor or the stream expired, close it
// If there were more events than we could deliver in one message, proceed with the next chunk right away
// Otherwise just go back to sleep
nctx.state = (nctx.subscriptions.empty() || tp_now() > nctx.expire)? NS::S_CLOSING : moreAny? NS::S_SLEEP : NS::S_WRITE;
nctx.state = nctx.nct_subs.empty() || tp_now() > nctx.expire ?
NS::S_CLOSING : moreAny ? NS::S_SLEEP : NS::S_WRITE;
if(nctx.state == NS::S_SLEEP)
m_plugin.wakeContext(m_ID, m_plugin.event_stream_interval);
return flush();
Expand Down Expand Up @@ -790,7 +791,7 @@ EWSPlugin::SubManager::SubManager(const char *uname, const EWSPlugin &plugin) :
EWSPlugin::SubManager::~SubManager()
{
std::lock_guard ss_lock(ews.subscriptionLock);
for(const auto& subKey : subscriptions)
for (const auto &subKey : inner_subs)
ews.unsubscribe(subKey);
if(waitingContext)
ews.unlinkSubscription(*waitingContext);
Expand Down
4 changes: 2 additions & 2 deletions exch/ews/ews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class EWSPlugin {
std::string username; ///< Name of the user who created the subscription
Structures::sMailboxInfo mailboxInfo; ///< Target mailbox metadata
std::mutex lock; ///< I/O mutex
std::vector<detail::ExmdbSubscriptionKey> subscriptions; ///< Exmdb subscription keys
std::vector<detail::ExmdbSubscriptionKey> inner_subs; ///< Exmdb subscription keys
std::list<Structures::sNotificationEvent> events; ///< Events that occured since last check
std::optional<int> waitingContext; ///< ID of context waiting for events
};
Expand Down Expand Up @@ -339,7 +339,7 @@ class EWSContext {
inline explicit NotificationContext(gromox::time_point e) : state(S_INIT), expire(e) {}

State state;
std::vector<Structures::tSubscriptionId> subscriptions;
std::vector<Structures::tSubscriptionId> nct_subs;
gromox::time_point expire;
};

Expand Down

0 comments on commit 5e70545

Please sign in to comment.