summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoredwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-07-10 18:25:38 (GMT)
committer edwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-07-10 18:25:38 (GMT)
commit7029f84a9954145d775c48512f8876dd9c571f21 (patch)
treea3e027d263fd015050cffcbbe786f6e6465b6004
parent3200dd6e0a897403bb9ec045b858dd8e28cf60ea (diff)
cleanup by cookie, for conn_net
git-svn-id: https://open.syn3.nl/syn3/svndav/default/trunk/projects/synapse@355 99606f1f-bbb2-4562-8e6b-387ddef1dc61
-rw-r--r--cuserman.cpp20
-rw-r--r--cuserman.h1
-rw-r--r--modules/conn_json.module/module.cpp22
-rw-r--r--modules/core.module/module.cpp45
4 files changed, 76 insertions, 12 deletions
diff --git a/cuserman.cpp b/cuserman.cpp
index 17daf80..fcc7047 100644
--- a/cuserman.cpp
+++ b/cuserman.cpp
@@ -239,6 +239,26 @@ bool CuserMan::delSession(const int sessionId)
}
}
+list<int> CuserMan::delCookieSessions(int cookie, CmodulePtr module)
+{
+ list<int> deletedIds;
+
+ if (cookie!=0)
+ {
+ for (int sessionId=1; sessionId<MAX_SESSIONS; sessionId++)
+ {
+ if (sessions[sessionId])
+ {
+ if (sessions[sessionId]->cookie==cookie && sessions[sessionId]->module==module)
+ {
+ delSession(sessionId);
+ deletedIds.push_back(sessionId);
+ }
+ }
+ }
+ }
+ return (deletedIds);
+}
string CuserMan::getStatusStr()
diff --git a/cuserman.h b/cuserman.h
index d18976b..a9f74fd 100644
--- a/cuserman.h
+++ b/cuserman.h
@@ -38,6 +38,7 @@ public:
int addSession( CsessionPtr session);
CsessionPtr getSession(const int & sessionId);
bool delSession(const int id);
+ list<int> delCookieSessions(int cookie, CmodulePtr module);
string getStatusStr();
void doShutdown();
string login(const int & sessionId, const string & userName, const string & password);
diff --git a/modules/conn_json.module/module.cpp b/modules/conn_json.module/module.cpp
index de03825..dadf1dd 100644
--- a/modules/conn_json.module/module.cpp
+++ b/modules/conn_json.module/module.cpp
@@ -92,18 +92,16 @@ class CnetModule : public Cnet
readBuffer.consume(dataStr.length());
}
-// /** Connection 'id' is disconnected, or a connect-attempt has failed.
-// * Sends: conn_Disconnected
-// */
-// void disconnected(int id, const boost::system::error_code& ec)
-// {
-// Cmsg out;
-// out.dst=id;
-// out.event="conn_Disconnected";
-// out["reason"]=ec.message();
-// out["type"]="json";
-// out.send();
-// }
+ /** Connection 'id' is disconnected, or a connect-attempt has failed.
+ * Sends: conn_Disconnected
+ */
+ void disconnected(int id, const boost::system::error_code& ec)
+ {
+ Cmsg out;
+ out.event="core_DelCookieSessions";
+ out["cookie"]=id;
+ out.send();
+ }
};
CnetMan<CnetModule> net;
diff --git a/modules/core.module/module.cpp b/modules/core.module/module.cpp
index 817a5ac..0d76a32 100644
--- a/modules/core.module/module.cpp
+++ b/modules/core.module/module.cpp
@@ -145,6 +145,12 @@ SYNAPSE_REGISTER(module_Init)
out["recvGroup"]= "core";
out.send();
+ out["event"]= "core_DelCookieSessions"; // RECV to delete src sessions by cookie
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "core";
+ out.send();
+
out["event"]= "module_SessionEnd"; // SEND to ended session
out["modifyGroup"]= "core";
out["sendGroup"]= "core";
@@ -642,6 +648,45 @@ SYNAPSE_REGISTER(core_DelSession)
}
}
+/** Delete all sessions with cookie specified by \c cookie.
+
+Only deletes sessions belonging to \c src module.
+
+\par Broadcasts \c module_SessionEnded:
+ To indicate to the rest of the world that the sessions have been ended.
+ \arg \c session The session that has been ended.
+*/
+SYNAPSE_REGISTER(core_DelCookieSessions)
+{
+ string error;
+ list<int> deletedIds;
+
+ {
+ lock_guard<mutex> lock(messageMan->threadMutex);
+ CsessionPtr session=messageMan->userMan.getSession(msg.src);
+ if (!session)
+ error="Session not found";
+
+ deletedIds=messageMan->userMan.delCookieSessions(msg["cookie"], session->module);
+ }
+
+ if (error!="")
+ msg.returnError(error);
+ else
+ {
+ Cmsg out;
+ BOOST_FOREACH(int id, deletedIds)
+ {
+
+ //inform the rest of the world
+ out.event="module_SessionEnded";
+ out["session"]=id;
+ out.dst=0;
+ out.send();
+ }
+ }
+}
+
/** Changes the settings of the \c src module.
\param maxThreads (optional) The maximum number of threads for the module. (default 1, e.g. single threaded)