aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html')
-rw-r--r--cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html253
1 files changed, 253 insertions, 0 deletions
diff --git a/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html b/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html
new file mode 100644
index 00000000..eb84b26f
--- /dev/null
+++ b/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html
@@ -0,0 +1,253 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
+<HEAD><style> A { color:black }</style>
+<!-- hennerik CVSweb $Revision: 1.93 $ -->
+<TITLE>code/nelns/admin_service/admin_service.cpp - view - 1.2</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee">
+<table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#aaaaaa"><tr valign=bottom><td><a href="admin_service.cpp"><IMG SRC="http://www.nevrax.org/inc/img/picto-up.gif" ALT="[BACK]" BORDER="0" WIDTH="14" HEIGHT="13"></a> <b>Return to <A HREF="admin_service.cpp">admin_service.cpp</A>
+ CVS log</b> <IMG SRC="http://www.nevrax.org/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="http://www.nevrax.org/inc/img/picto-dir.gif" ALT="[DIR]" BORDER="0" WIDTH="15" HEIGHT="13"> <b>Up to <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/nelns/">nelns</a> / <a href="/cvs/cvsweb.cgi/code/nelns/admin_service/">admin_service</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File: <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/nelns/">nelns</a> / <a href="/cvs/cvsweb.cgi/code/nelns/admin_service/">admin_service</a> / <a href="/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp">admin_service.cpp</a>&nbsp;(<A HREF="/cvs/cvsweb.cgi/~checkout~/code/nelns/admin_service/admin_service.cpp?rev=1.2" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/nelns/admin_service/admin_service.cpp?rev=1.2','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>
+Revision <B>1.2</B>, <i>Thu May 3 13:19:13 2001 UTC</i> (14 months, 3 weeks ago) by <i>lecroart</i>
+<BR>Branch: <b>MAIN</b>
+<BR>Changes since <b>1.1: +2 -6
+ lines</b><PRE>
+BUGFIX: now compile on linux
+</PRE>
+</td></tr></table><HR noshade><PRE>/** \file admin_service.cpp
+ * Admin Service (AS)
+ *
+ * $Id: admin_service.cpp,v 1.2 2001/05/03 13:19:13 lecroart Exp $
+ *
+ */
+
+/* Copyright, 2000 Nevrax Ltd.
+ *
+ * This file is part of NEVRAX D.T.C. SYSTEM.
+ * NEVRAX D.T.C. SYSTEM is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * NEVRAX D.T.C. SYSTEM is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NEVRAX D.T.C. SYSTEM; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#include &lt;string&gt;
+#include &lt;list&gt;
+
+#include &quot;nel/net/service.h&quot;
+#include &quot;nel/misc/debug.h&quot;
+#include &quot;nel/misc/config_file.h&quot;
+
+#include &quot;nel/net/net_manager.h&quot;
+
+
+using namespace std;
+using namespace NLMISC;
+using namespace NLNET;
+
+
+struct CService
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;CService(TSockId s) : AESSockId(s), AESId(NextAESId++) { }
+
+ &nbsp; &nbsp; &nbsp; &nbsp;TSockId &nbsp; &nbsp; &nbsp; &nbsp;AESSockId; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TSockId of the AES that have this service
+ &nbsp; &nbsp; &nbsp; &nbsp;uint32 &nbsp; &nbsp; &nbsp; &nbsp;AESId; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TSockId of the AES that have this service
+ &nbsp; &nbsp; &nbsp; &nbsp;uint32 &nbsp; &nbsp; &nbsp; &nbsp;SId; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// uint32 to identify the service
+ &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;ShortName;
+ &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;LongName;
+
+private:
+
+ &nbsp; &nbsp; &nbsp; &nbsp;static &nbsp; &nbsp; &nbsp; &nbsp;uint32 NextAESId;
+};
+
+uint32 CService::NextAESId = 0;
+
+list&lt;CService&gt; Services;
+typedef list&lt;CService&gt;::iterator sit;
+
+sit find (TSockId aesid, uint32 sid)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;sit it;
+ &nbsp; &nbsp; &nbsp; &nbsp;for (it = Services.begin(); it != Services.end(); it++)
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((*it).AESSockId== aesid &amp;&amp; (*it).SId == sid) break;
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp; &nbsp;return it;
+}
+
+sit find (uint32 aesid, uint32 sid)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;sit it;
+ &nbsp; &nbsp; &nbsp; &nbsp;for (it = Services.begin(); it != Services.end(); it++)
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((*it).AESId == aesid &amp;&amp; (*it).SId == sid) break;
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp; &nbsp;return it;
+}
+
+/*
+NLMISC_COMMAND (start, &quot;start a service&quot;, &quot;&lt;service_name&gt;&quot;)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;if(args.size() != 1 &amp;&amp; args.size() != 2) return false;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA(&quot;AES&quot;), &quot;ESC&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (args[1]);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;uint8 background = 0;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;if (args.size() == 2)
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (args[1] == &quot;&amp;&quot;)
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint8 background = 1;
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+
+ &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (background);
+ &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AES&quot;, msgout);
+ &nbsp; &nbsp; &nbsp; &nbsp;return true;
+}
+
+
+CLog logstdout;
+CStdDisplayer dispstdout;
+
+NLMISC_COMMAND (stop, &quot;stop a service&quot;, &quot;&lt;aesid&gt; &lt;sid&gt;&quot;)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;if(args.size() != 3) return false;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA(&quot;AES&quot;), &quot;SS&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (args[2]);
+ &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AES&quot;, msgout);
+}
+*/
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////// CONNECTION TO THE AES ///////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+static void cbExecuteSystemCommandResult (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;vector&lt;string&gt; result;
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serialCont (result);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo(&quot;command result&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;for (uint i = 0; i &lt; result.size(); i++)
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf (&quot;%s&quot;, result[i].c_str());
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo(&quot;end of command result&quot;);
+}
+
+static void cbServiceIdentification (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;string ShortName, LongName;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (ShortName);
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (LongName);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;%s %s %s is identified&quot;, from-&gt;asString().c_str(), ShortName.c_str(), LongName.c_str());
+}
+
+static void cbServiceReady (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;string ShortName, LongName;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (ShortName);
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (LongName);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;%s %s %s is ready&quot;, from-&gt;asString().c_str(), ShortName.c_str(), LongName.c_str());
+}
+
+static void cbServiceConnection (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;%s a service is connected&quot;, from-&gt;asString().c_str());
+}
+
+static void cbServiceDisconnection (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;string ShortName, LongName;
+
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (ShortName);
+ &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (LongName);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;%s %s %s is disconnected&quot;, from-&gt;asString().c_str(), ShortName.c_str(), LongName.c_str());
+}
+
+
+TCallbackItem AESCallbackArray[] =
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;ESCR&quot;, cbExecuteSystemCommandResult },
+
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SID&quot;, cbServiceIdentification },
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SR&quot;, cbServiceReady },
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SC&quot;, cbServiceConnection },
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SD&quot;, cbServiceDisconnection },
+};
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////// CONNECTION TO THE CLIENT ////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void clientConnection (const string &amp;serviceName, TSockId from, void *arg)
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;// new client, send him all out info about services
+
+ &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;client %s is connected&quot;, from-&gt;asString().c_str());
+ &nbsp; &nbsp; &nbsp; &nbsp;
+ &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AESAS&quot;), &quot;SL&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;uint32 size = (uint32)Services.size();
+ &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (size);
+ &nbsp; &nbsp; &nbsp; &nbsp;for (sit it = Services.begin(); it != Services.end(); it++)
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*it).AESId);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*it).SId);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*it).ShortName);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*it).LongName);
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, from);
+}
+
+TCallbackItem ASCallbackArray[] =
+{
+ &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;&quot;, NULL },
+};
+
+class CAdminService : public IService
+{
+public:
+
+ &nbsp; &nbsp; &nbsp; &nbsp;/// Init the service, load the universal time.
+ &nbsp; &nbsp; &nbsp; &nbsp;void &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;init ()
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::setConnectionCallback (&quot;AS&quot;, clientConnection, NULL);
+
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// connec to the AES
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::addClient (&quot;AES&quot;, &quot;localhost:49996&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::addCallbackArray (&quot;AES&quot;, AESCallbackArray, sizeof (AESCallbackArray)/sizeof(AESCallbackArray[0]));
+
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+
+ &nbsp; &nbsp; &nbsp; &nbsp;bool &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;update ()
+ &nbsp; &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;
+ &nbsp; &nbsp; &nbsp; &nbsp;}
+};
+
+
+/// Naming Service
+NLNET_SERVICE_MAIN (CAdminService, &quot;AS&quot;, &quot;admin_service&quot;, 49995, ASCallbackArray);
+</PRE> \ No newline at end of file