summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoredwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-01-11 02:03:51 (GMT)
committer edwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-01-11 02:03:51 (GMT)
commit57149f46f69a52fac3c69c0772ce85f6be8b639a (patch)
treed68e0f8bbf5737c844fc0e5ffe98ab15547db2e5
parentff0d33071d3bdc77251c81ffec346129aa1fc76c (diff)
added anonymous user/group and improved session api. started with json network stuff
git-svn-id: https://open.syn3.nl/syn3/svndav/default/trunk/projects/synapse@166 99606f1f-bbb2-4562-8e6b-387ddef1dc61
-rw-r--r--cmessageman.cpp8
-rw-r--r--cmessageman.h4
-rw-r--r--cmodule.cpp3
-rw-r--r--cmodule.h3
-rw-r--r--cnet.cpp1
-rw-r--r--cnet.h1
-rw-r--r--cnetman.h45
-rw-r--r--csession.h1
-rw-r--r--cuser.cpp2
-rw-r--r--cuserman.cpp33
-rw-r--r--cuserman.h1
-rw-r--r--modules/conn_json.module/module.cpp231
-rw-r--r--modules/core.module/module.cpp263
-rw-r--r--modules/net.module/module.cpp2
-rw-r--r--modules/test.module/module.cpp16
15 files changed, 425 insertions, 189 deletions
diff --git a/cmessageman.cpp b/cmessageman.cpp
index d8fba71..82147b4 100644
--- a/cmessageman.cpp
+++ b/cmessageman.cpp
@@ -518,7 +518,7 @@ CeventPtr CmessageMan::getEvent(const string & name)
/*!
\fn CmessageMan::isModuleReady(string name)
*/
-bool CmessageMan::isModuleReady(string path)
+int CmessageMan::isModuleReady(string path)
{
CsessionPtr session;
string name;
@@ -528,12 +528,12 @@ bool CmessageMan::isModuleReady(string path)
{
session=userMan.getSession(sessionId);
//session exists and is still active, and its the module?
- if (session && session->isEnabled() && session->module->name==name)
+ if (session && session->isEnabled() && session->module->name==name && session->module->readySession==session->id)
{
- return (session->module->ready);
+ return (session->module->readySession);
}
}
- return false;
+ return SESSION_DISABLED;
}
diff --git a/cmessageman.h b/cmessageman.h
index 43afe65..3462d4b 100644
--- a/cmessageman.h
+++ b/cmessageman.h
@@ -55,9 +55,9 @@ public:
bool sendMessage(const CmodulePtr & modulePtr, const CmsgPtr & msg);
void checkThread();
- CsessionPtr loadModule(string path, string userName);
+ CsessionPtr loadModule(string path, string userName);
CeventPtr getEvent(const string & name);
- bool isModuleReady(string path);
+ int isModuleReady(string path);
void doShutdown(int exit);
mutex threadMutex;
diff --git a/cmodule.cpp b/cmodule.cpp
index dcb66d8..58702ea 100644
--- a/cmodule.cpp
+++ b/cmodule.cpp
@@ -25,8 +25,7 @@ Cmodule::Cmodule()
soHandle=NULL;
defaultSessionId=SESSION_DISABLED;
soDefaultHandler=NULL;
- ready=false;
-
+ readySession=SESSION_DISABLED;
}
diff --git a/cmodule.h b/cmodule.h
index 7ccfc9f..6d13adf 100644
--- a/cmodule.h
+++ b/cmodule.h
@@ -62,7 +62,8 @@ public:
int defaultSessionId;
string name;
string path;
- bool ready;
+ int readySession;
+
//event handling stuff,
//converting an event string into an actual function call.
diff --git a/cnet.cpp b/cnet.cpp
index 5ea8a43..f2a32e8 100644
--- a/cnet.cpp
+++ b/cnet.cpp
@@ -193,6 +193,7 @@ void Cnet::connectHandler(
}
//handle the results of a read (incoming data)
+//used for both client and servers.
void Cnet::readHandler(
const boost::system::error_code& ec,
std::size_t bytesTransferred)
diff --git a/cnet.h b/cnet.h
index 2360b0d..5625851 100644
--- a/cnet.h
+++ b/cnet.h
@@ -11,6 +11,7 @@
// Copyright: See COPYING file that comes with this distribution
//
//
+
#ifndef CNET_H
#define CNET_H
diff --git a/cnetman.h b/cnetman.h
index 5778784..982f541 100644
--- a/cnetman.h
+++ b/cnetman.h
@@ -10,6 +10,51 @@
// Copyright: See COPYING file that comes with this distribution
//
//
+
+/** Synapse network states/flow:
+
+ CnetMan is threadsafe, Cnet is NOT.
+
+ For clients:
+ runConnect(id,host,port,reconnectTime)
+ -> returns false if error
+ -> calls back connecting(id)
+ on succesfull resolving and connecting:
+ -> calls back connected(id)
+ -> calls back read(id,...) for all incoming data until disconnected
+ -> calls back disconnected(id,error);
+ if reconnectTime>0 and doDisconnect was not called: sleeps and starts over again..
+ -> returns true;
+
+ For servers:
+ First call runListen to open the port:
+ runListen(int port)
+ -> returns false if error
+ -> calls back listening(port)
+ -> listens on port, keeps running until user calls doClose(port) or until error
+ -> calls back closed(port)
+ -> returns true
+
+ Now call runAccept to accept new connections:
+ runAccept(int port, int id)
+ -> returns false if errror
+ -> calls back accepting(port,id)
+ -> waits for new connection on port until user calls doDisconnect(id).or until error
+ on newly accepted connection:
+ -> calls back connected(id);
+ -> calls back read(id,...) for all incoming data until disconnected
+ -> calls back disconnected(id,error);
+ -> returns true;
+
+ Writing data can be done with doWrite(..). Offcourse only after connected(id) was called back.
+ if writing fails a disconnection occurs.
+
+ Server and client code can be almost the same so its very easy to change your client into a server or vice versa: Only the first few steps are different, after the connection is eshtablised all the calls and callbacks are the same.
+
+
+*/
+
+
#ifndef CNETMAN_H
#define CNETMAN_H
diff --git a/csession.h b/csession.h
index 6f60930..5e7db1e 100644
--- a/csession.h
+++ b/csession.h
@@ -42,6 +42,7 @@ public:
bool isEnabled();
void endThread();
bool startThread();
+
CuserPtr user;
CmodulePtr module;
int id;
diff --git a/cuser.cpp b/cuser.cpp
index 5c28c73..606c4e0 100644
--- a/cuser.cpp
+++ b/cuser.cpp
@@ -74,6 +74,8 @@ string Cuser::getName()
*/
bool Cuser::isPassword(const string & password)
{
+ //blank passwords not allowed, they are used for module and core users.
+
if (password!="" && this->password!="")
return (this->password==password);
else
diff --git a/cuserman.cpp b/cuserman.cpp
index 5f72694..47aff82 100644
--- a/cuserman.cpp
+++ b/cuserman.cpp
@@ -28,27 +28,32 @@ CuserMan::CuserMan()
addGroup(CgroupPtr(new Cgroup("modules")));
addGroup(CgroupPtr(new Cgroup("users")));
addGroup(CgroupPtr(new Cgroup("everyone")));
+ addGroup(CgroupPtr(new Cgroup("anonymous")));
CuserPtr user;
user=CuserPtr(new Cuser("core",""));
user->addMemberGroup(getGroup("core"));
user->addMemberGroup(getGroup("modules"));
user->addMemberGroup(getGroup("everyone"));
+ user->addMemberGroup(getGroup("anonymous"));
addUser(user);
user=CuserPtr(new Cuser("module",""));
user->addMemberGroup(getGroup("modules"));
user->addMemberGroup(getGroup("everyone"));
+ user->addMemberGroup(getGroup("anonymous"));
addUser(user);
- //anonymous isnt member of anything
- user=CuserPtr(new Cuser("anonymous",""));
+ //anonymous is only member of anonymous and probably only can send a core_Login.
+ user=CuserPtr(new Cuser("anonymous","anonymous"));
+ user->addMemberGroup(getGroup("anonymous"));
addUser(user);
//testusers
user=CuserPtr(new Cuser("psy","as"));
user->addMemberGroup(getGroup("users"));
user->addMemberGroup(getGroup("everyone"));
+ user->addMemberGroup(getGroup("anonymous"));
addUser(user);
user=CuserPtr(new Cuser("admin","bs"));
@@ -56,6 +61,7 @@ CuserMan::CuserMan()
user->addMemberGroup(getGroup("core"));
user->addMemberGroup(getGroup("modules"));
user->addMemberGroup(getGroup("everyone"));
+ user->addMemberGroup(getGroup("anonymous"));
addUser(user);
// for (int i=0; i<MAX_SESSIONS; i++)
@@ -252,4 +258,25 @@ void CuserMan::print()
void CuserMan::doShutdown()
{
shutdown=true;
-} \ No newline at end of file
+}
+
+
+
+string CuserMan::login(const int & sessionId, const string & userName, const string & password)
+{
+ CsessionPtr session=getSession(sessionId);
+ if (!session)
+ return (string("Session not found"));
+ else
+ {
+ CuserPtr user(getUser(userName));
+ if (!user || !user->isPassword(password))
+ return (string("Login invalid"));
+ else
+ {
+ //change user
+ session->user=user;
+ return (string());
+ }
+ }
+}
diff --git a/cuserman.h b/cuserman.h
index ad131c5..fb6fe0f 100644
--- a/cuserman.h
+++ b/cuserman.h
@@ -40,6 +40,7 @@ public:
bool delSession(const int id);
void print();
void doShutdown();
+ string login(const int & sessionId, const string & userName, const string & password);
private:
bool shutdown;
diff --git a/modules/conn_json.module/module.cpp b/modules/conn_json.module/module.cpp
index 3eb266a..deef81d 100644
--- a/modules/conn_json.module/module.cpp
+++ b/modules/conn_json.module/module.cpp
@@ -5,33 +5,235 @@
using namespace json_spirit;
+int networkSessionId=0;
+
SYNAPSE_REGISTER(module_Init)
{
Cmsg out;
-// out.clear();
-// out.event="core_ChangeModule";
-// out["maxThreads"]=10;
-// out.send();
-//
-// out.clear();
-// out.event="core_ChangeSession";
-// out["maxThreads"]=10;
-// out.send();
-//
-// ///tell the rest of the world we are ready for duty
-// out.clear();
-// out.event="core_Ready";
-// out.send();
+ //max number of parallel module threads
+ out.clear();
+ out.event="core_ChangeModule";
+ out["maxThreads"]=100;
+ out.send();
+
+ //The default session will be used to receive broadcasts that need to be transported via json.
+ //Make sure we only process message at a time, so they stay in order.
+ out.clear();
+ out.event="core_ChangeSession";
+ out["maxThreads"]=1;
+ out.send();
+
+ //We use a ANONYMOUS session that run the threads for network connection handeling.
+ //new connections will be anonymous and have to login with core_Login.
+ out.clear();
+ out.event="core_NewSession";
+ out["maxThreads"]=1;
+ out.send();
+
+ //make sure the anonymous session has the right to receive the basic stuff:
+ out.clear();
+ out.event="core_ChangeEvent";
+ out["event"]="conn_json_Connect";
+ out["recvGroup"]="anonymous";
+ out.send();
+
+ out["event"]="conn_json_Listen";
+ out.send();
+
+ out["event"]="conn_json_Disconnect";
+ out.send();
+
+ out["event"]="conn_json_Close";
+ out.send();
+ //register a special handler without specified event
+ //this will receive all events that are not handled elsewhere in this module.
out.clear();
out.event="core_Register";
out["handler"]="all";
out.send();
+}
+
+
+
+
+
+
+// We extent the CnetMan class with our own network handlers.
+// As soon as something with a network connection 'happens', these handlers will be called.
+// This stuff basically runs as anonymous, until a user uses core_login to change the user.
+class CnetModule : public CnetMan
+{
+ /** We started listening on a port
+ */
+ void listening(int port)
+ {
+ //start a new anonymous acceptor to accept new incoming connections and handle the incomming data
+ Cmsg out;
+ out.event="core_NewSession";
+ out["username"]="anonymous";
+ out["password"]="anonymous";
+ out["port"]=port;
+ out.send();
+ }
+
+ /** Connection 'id' is trying to connect to host:port
+ * Sends: net_Connecting
+ */
+ void connecting(int id, string host, string port)
+ {
+ Cmsg out;
+ out.dst=id;
+ out.event="conn_Connecting";
+ out["host"]=host;
+ out["port"]=port;
+ out["type"]="json";
+ out.send();
+ }
+
+ /** Connection 'id' is established.
+ * Sends: conn_Connected
+ */
+ void connected(int id)
+ {
+ Cmsg out;
+ out.dst=id;
+ out.event="conn_Connected";
+ out["type"]="json";
+ out.send();
+ }
+
+ /** Connection 'id' has received new data.
+ */
+ void read(int id, asio::streambuf &readBuffer, std::size_t bytesTransferred)
+ {
+ Cmsg out;
+ //TODO: isnt there a more efficient way to convert the streambuf to string?
+ const char* s=boost::asio::buffer_cast<const char*>(readBuffer.data());
+ //remove newline..
+ out["data"].str().erase();
+ out["data"].str().append(s,bytesTransferred-1);
+
+ //parse json and send message
+ INFO("session " << id << " got " << out["data"]);
+ }
+
+ /** 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();
+ }
+};
+
+CnetModule net;
+
+
+
+SYNAPSE_REGISTER(module_SessionStart)
+{
+
+ //first new session, this is the network thread session
+ if (!networkSessionId)
+ {
+ networkSessionId=msg.dst;
+
+ //tell the rest of the world we are ready for duty
+ Cmsg out;
+ out.event="core_Ready";
+ out.src=networkSessionId;
+ out.send();
+
+ return;
+ }
+
+ //new session that was started to run the acceptor for a port:
+ if (msg.isSet("port"))
+ {
+ net.runAccept(msg["port"], msg.dst);
+
+ //we're done, delete our session
+ Cmsg out;
+ out.event="core_DelSession";
+ out.src=msg.dst;
+ out.send();
+ }
+
+}
+
+/** Client-only: Create a new json connection, connects to host:port for session src
+ */
+SYNAPSE_REGISTER(conn_json_Connect)
+{
+ if (msg.dst==networkSessionId)
+ net.runConnect(msg.src, msg["host"], msg["port"]);
+ else
+ ERROR("Send to the wrong session id");
+}
+
+/** Server only: Creates a new server and listens specified port
+ */
+SYNAPSE_REGISTER(conn_json_Listen)
+{
+ if (msg.dst==networkSessionId)
+ {
+ net.runListen(msg["port"]);
+ }
+ else
+ ERROR("Send to the wrong session id");
+
}
+
+/** Server only: Stop listening on a port
+ */
+SYNAPSE_REGISTER(conn_json_Close)
+{
+ if (msg.dst==networkSessionId)
+ net.doClose(msg["port"]);
+ else
+ ERROR("Send to the wrong session id");
+}
+
+
+
+
+/** Disconnections the connection related to src
+ */
+SYNAPSE_REGISTER(conn_json_Disconnect)
+{
+ net.doDisconnect(msg.src);
+}
+
+
+/** When a session ends, make sure the corresponding network connection is disconnected as well.
+ *
+ */
+SYNAPSE_REGISTER(module_SessionEnded)
+{
+ net.doDisconnect(msg["session"]);
+}
+
+/** Called when synapse whats the module to shutdown completely
+ * This makes sure that all ports and network connections are closed, so there wont be any 'hanging' threads left.
+ * If you care about data-ordering, send this to session-id that sended you the net_Connected.
+ */
+SYNAPSE_REGISTER(module_Shutdown)
+{
+ //let the net module shut down to fix the rest
+ net.doShutdown();
+}
+
+
/** Recursively converts a Cvar to a json_spirit Value.
*/
void Cvar2Value(Cvar &var,Value &value)
@@ -43,6 +245,7 @@ void Cvar2Value(Cvar &var,Value &value)
break;
case(CVAR_STRING):
value=(string)var;
+ break;
case(CVAR_LONG_DOUBLE):
value=(double)var;
break;
diff --git a/modules/core.module/module.cpp b/modules/core.module/module.cpp
index 9ff0e84..4c3c630 100644
--- a/modules/core.module/module.cpp
+++ b/modules/core.module/module.cpp
@@ -33,147 +33,109 @@ SYNAPSE_REGISTER(module_Init)
return;
}
-
- ///module_Error
+ /// SET CORE EVENT PERMISSIONS:
+ // these permissions should never be changed!
out.clear();
out.event="core_ChangeEvent";
- out["event"]="module_Error";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="everyone";
- out.send();
- ///set permissions on these important core features
- //The handlers where already registered by init()
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_ChangeEvent";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
+ /// basic core events
+ out["event"]= "module_Error"; /// SEND to module on all kinds of errors
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "everyone";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_Register";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
+ out["event"]= "core_ChangeEvent"; /// RECV to change permissions of events
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "core";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_Init";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="modules";
+ out["event"]= "core_Register"; /// RECV to register handlers
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "core";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_LoadModule";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
- out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_Shutdown";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="modules";
+ /// module loading and unloading
+ out["event"]= "core_LoadModule"; /// RECV to load a module
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "core";
out.send();
- /// core_Login
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_SessionStart";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="everyone";
+ out["event"]= "module_Init"; /// SEND to module after loading it
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "modules";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_SessionStarted";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="everyone";
+ out["event"]= "module_Shutdown"; /// SEND because we want to unload the module cleanup
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "modules";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_Login";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="modules";
+
+ /// session handling
+ out["event"]= "core_NewSession"; /// RECV to start a new session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "modules";
+ out["recvGroup"]= "core";
out.send();
+ out["event"]= "module_SessionStart"; /// SEND to newly started session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "anonymous";
+ out.send();
- /// core_NewSession
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_NewSession";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
+ out["event"]= "module_SessionStarted"; /// SEND to broadcast, on newly created session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "everyone";
out.send();
- /// core_Logout
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_Logout";
- out["modifyGroup"]="core";
- out["sendGroup"]="everyone";
- out["recvGroup"]="core";
+ out["event"]= "core_DelSession"; /// RECV to delete src session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "anonymous";
+ out["recvGroup"]= "core";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_SessionEnd";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="everyone";
+ out["event"]= "module_SessionEnd"; /// SEND to ended session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "anonymous";
out.send();
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="module_SessionEnded";
- out["modifyGroup"]="core";
- out["sendGroup"]="core";
- out["recvGroup"]="everyone";
+ out["event"]= "module_SessionEnded"; /// SEND to broadcast, on ended session
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "core";
+ out["recvGroup"]= "everyone";
out.send();
- /// core_ChangeModule
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_ChangeModule";
- out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
+ out["event"]= "core_Login"; /// RECV to login the src session with specified user and password
+ out["modifyGroup"]= "core";
+ out["sendGroup"]= "anonymous";
+ out["recvGroup"]= "core";
out.send();
- /// core_ChangeSession
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_ChangeSession";
+ out["event"]="module_Login"; /// SEND to session after succesfull login
out["modifyGroup"]="core";
- out["sendGroup"]="modules";
- out["recvGroup"]="core";
+ out["sendGroup"]="core";
+ out["recvGroup"]="anonymous";
out.send();
- /// core_Ready
- out.clear();
- out.event="core_ChangeEvent";
- out["event"]="core_Ready";
+ out["event"]="core_ChangeSession"; /// RECV to change src session parameters
out["modifyGroup"]="core";
out["sendGroup"]="modules";
out["recvGroup"]="core";
out.send();
+ /// END OF PERMISSIONS
//we're done with our stuff,
//load the first application module:
@@ -207,14 +169,18 @@ SYNAPSE_REGISTER(core_LoadModule)
{
DEB("module " << (string)msg["path"] << " is already loaded");
//is it ready as well?
- if (!messageMan->isModuleReady(msg["path"]))
- return;
- else
+ int readySession=messageMan->isModuleReady(msg["path"]);
+ if (readySession!=SESSION_DISABLED)
{
- //send out a modulename_ready to the requesting session to inform its already ready:
+ //send out a modulename_ready to the requesting session to inform the module is already ready:
out.event=module.getName((string)msg["path"])+"_Ready";
DEB("module is already ready, sending a " << out.event);
out.dst=msg.src;
+ out["session"]=readySession;
+ }
+ else
+ {
+ return;
}
}
else
@@ -281,7 +247,7 @@ SYNAPSE_REGISTER(core_Register)
SYNAPSE_REGISTER(core_ChangeEvent)
{
- //since permissions are very imporatant, make sure the user didnt make a typo.
+ //since permissions are very important, make sure the user didnt make a typo.
//(normally we dont care about typo's since then something just wouldn't work, but this function will work if the user doesnt specify one or more parameters.)
if (msg.returnIfOtherThan("sendGroup","event","recvGroup","modifyGroup",NULL))
return;
@@ -333,50 +299,22 @@ SYNAPSE_REGISTER(core_ChangeEvent)
}
/** core_Login
- * Check username and password and starts new session.
- * Sends: module_SessionStart to new session
- * Sends: module_SessionStarted to broadcast
+ * Check username and password and changes users of src session.
* Sends: module_Login to src
*/
SYNAPSE_REGISTER(core_Login)
{
string error;
- Cmsg startmsg;
Cmsg loginmsg;
-
{
lock_guard<mutex> lock(messageMan->threadMutex);
- CsessionPtr session=messageMan->userMan.getSession(msg.src);
- if (!session)
- error="Session not found";
- else
+ error=messageMan->userMan.login(msg.src, msg["username"], msg["password"]);
+ if (error=="")
{
- CuserPtr user(messageMan->userMan.getUser(msg["username"]));
- if (!user || !user->isPassword(msg["password"]))
- error="Login invalid";
- else
- {
- CsessionPtr newSession=CsessionPtr(new Csession(user,session->module));
- int sessionId=messageMan->userMan.addSession(newSession);
- if (sessionId==SESSION_DISABLED)
- error="cant create new session";
- else
- {
- //set max threads?
- if (msg["maxThreads"] > 0)
- newSession->maxThreads=msg["maxThreads"];
-
- //send startmessage to the new session:
- startmsg.event="module_SessionStart";
- startmsg.dst=sessionId;
- startmsg["username"]=msg["username"];
-
- //send login message to the session that was requesting the login
- loginmsg.event="module_Login";
- loginmsg.dst=msg.src;
- loginmsg["username"]=msg["username"];
- }
- }
+ //send login message to the session that was requesting the login
+ loginmsg.event="module_Login";
+ loginmsg.dst=msg.src;
+ loginmsg["username"]=msg["username"];
}
}
@@ -385,12 +323,6 @@ SYNAPSE_REGISTER(core_Login)
else
{
loginmsg.send();
- startmsg.send();
- //also broadcast module_SessionStarted, so other modules know that a session is started
- startmsg.event="module_SessionStarted";
- startmsg["session"]=startmsg.dst;
- startmsg.dst=0;
- startmsg.send();
}
}
@@ -417,18 +349,26 @@ SYNAPSE_REGISTER(core_NewSession)
error="cant create new session";
else
{
- //set max threads?
- if (msg["maxThreads"] > 0)
- newSession->maxThreads=msg["maxThreads"];
-
- //send startmessage to the new session:
- startmsg.event="module_SessionStart";
- startmsg.dst=sessionId;
- if (msg.isSet("pars"))
+ //login?
+ if (msg.isSet("username"))
+ error=messageMan->userMan.login(sessionId, msg["username"], msg["password"]);
+
+ if (error!="")
+ {
+ //login failed, delete session again
+ messageMan->userMan.delSession(msg.src);
+ }
{
- startmsg["pars"]=msg["pars"];
+ //set max threads?
+ if (msg.isSet("maxThreads") && msg["maxThreads"] > 0)
+ newSession->maxThreads=msg["maxThreads"];
+
+ //send startmessage to the new session, copy all parameters.
+ startmsg=msg;
+ startmsg.event="module_SessionStart";
+ startmsg.dst=sessionId;
+ startmsg.src=0;
}
- startmsg["username"]=session->user->getName();
}
}
}
@@ -438,7 +378,9 @@ SYNAPSE_REGISTER(core_NewSession)
else
{
startmsg.send();
+
//also broadcast module_SessionStarted, so other modules know that a session is started
+ startmsg.clear();
startmsg.event="module_SessionStarted";
startmsg["session"]=startmsg.dst;
startmsg.dst=0;
@@ -506,7 +448,7 @@ SYNAPSE_REGISTER(core_Shutdown)
}
-SYNAPSE_REGISTER(core_Logout)
+SYNAPSE_REGISTER(core_DelSession)
{
string error;
Cmsg endmsg;
@@ -597,7 +539,8 @@ SYNAPSE_REGISTER(core_Ready)
else
{
out.event=session->module->name+"_Ready";
- session->module->ready=true;
+ out["session"]=session->id;;
+ session->module->readySession=session->id;
}
}
diff --git a/modules/net.module/module.cpp b/modules/net.module/module.cpp
index 4348485..2f9fc12 100644
--- a/modules/net.module/module.cpp
+++ b/modules/net.module/module.cpp
@@ -28,7 +28,7 @@ SYNAPSE_REGISTER(module_Init)
//max number of parallel threads
out.clear();
out.event="core_ChangeModule";
- out["maxThreads"]=3000;
+ out["maxThreads"]=1000;
out.send();
//The default session will be used to call the run-functions.
diff --git a/modules/test.module/module.cpp b/modules/test.module/module.cpp
index 5c2fd1d..0c8ca32 100644
--- a/modules/test.module/module.cpp
+++ b/modules/test.module/module.cpp
@@ -47,7 +47,7 @@ SYNAPSE_REGISTER(module_Init)
// out.send();
- for (int bla=0; bla < 2; bla++)
+/* for (int bla=0; bla < 10; bla++)
{
out.clear();
out.event="test";
@@ -59,7 +59,9 @@ SYNAPSE_REGISTER(module_Init)
out.event="core_Shutdown";
out.dst=0;
- out.send();
+ out.send();*/
+
+
}
@@ -87,6 +89,16 @@ SYNAPSE_REGISTER(lirc_Ready)
}
+SYNAPSE_REGISTER(conn_json_Ready)
+{
+ Cmsg out;
+ out.clear();
+ out.event="conn_json_Listen";
+ out["port"]="12345";
+ out.dst=msg["session"];
+ out.send();
+}
+
SYNAPSE_REGISTER(net_Ready)
{
Cmsg out;