summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/connectionhandler.cc9
-rw-r--r--src/connectionhandler.h5
-rw-r--r--src/munia_proto.cc8
3 files changed, 19 insertions, 3 deletions
diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc
index 26cce46..8b48c03 100644
--- a/src/connectionhandler.cc
+++ b/src/connectionhandler.cc
@@ -80,9 +80,16 @@ void ConnectionHandler::subscribe(clientid_t clientid, nodeid_t nodeid)
DEBUG(conn, "Added subscriber of %d\n", (int)nodeid);
}
-void ConnectionHandler::unsubscribe(clientid_t clientid, nodeid_t nodeid)
+bool ConnectionHandler::unsubscribe(clientid_t clientid, nodeid_t nodeid)
{
+ if(connlist[clientid].find(nodeid) == connlist[clientid].end())
+ {
+ // Trying to unsubscribe from a node that is not subscribed.
+ return false;
+ }
+
connlist[clientid].erase(nodeid);
+ return true;
}
SubscriberList ConnectionHandler::subscriberlist(NodeIdList nodes)
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index 39f1c54..13f5d02 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -54,7 +54,10 @@ public:
bool authenticated(clientid_t clientid);
void subscribe(clientid_t clientid, nodeid_t nodeid);
- void unsubscribe(clientid_t clientid, nodeid_t nodeid);
+
+ //! Remove subscription from connection list.
+ //! \returns false if subscriptionid is not in the list
+ bool unsubscribe(clientid_t clientid, nodeid_t nodeid);
SubscriberList subscriberlist(NodeIdList nodelist);
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index 2230a0a..0508f9f 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -270,7 +270,13 @@ int callback_lws_node(struct lws *wsi,
}
else if(omi->cmd == cmd::unsubscribe)
{
- connection_handler.unsubscribe(wsi, omi->unsubscribe.id);
+ if(!connection_handler.unsubscribe(wsi, omi->unsubscribe.id))
+ {
+ // id wasn't in the subscriptionlist skip
+ omi++;
+ continue;
+ }
+
NodeIdList ids;
try
{