aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/code/nelns/admin_service/admin_service.cpp?rev=1.4&content-type=text/x-cvsweb-markup/index.html
blob: 0e23cd2dc0e1145ac6d52d0e21829a61cd07e859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
<!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.4</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.4" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/nelns/admin_service/admin_service.cpp?rev=1.4','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>
Revision <B>1.4</B>, <i>Fri May 18 16:51:33 2001 UTC</i> (14 months ago) by <i>lecroart</i>
<BR>Branch: <b>MAIN</b>
<BR>Changes since <b>1.3: +405 -101
 lines</b><PRE>
ADDED: work in progress. added gtk
</PRE>
</td></tr></table><HR noshade><PRE>/** \file admin_service.cpp
 * Admin Service (AS)
 *
 * $Id: admin_service.cpp,v 1.4 2001/05/18 16:51:33 lecroart Exp $
 *
 */

/* Copyright, 2000 Nevrax Ltd.
 *
 * This file is part of NEVRAX NeL Network Services.
 * NEVRAX NeL Network Services 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 NeL Network Services 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 NeL Network Services; 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 () : Id(0xFFFFFFFF), Ready(false), Connected(false), InConfig(false) { }

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 &nbsp; &nbsp; &nbsp; &nbsp;Id; &nbsp; &nbsp; &nbsp; &nbsp; &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;ServiceAlias; &nbsp; &nbsp; &nbsp; &nbsp;/// alias of the service used in the AES and AS to find him (unique per AES)
 &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;ShortName; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// name of the service in short format (&quot;NS&quot; for example)
 &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;LongName; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// name of the service in long format (&quot;naming_service&quot;)
 &nbsp; &nbsp; &nbsp; &nbsp;bool &nbsp; &nbsp; &nbsp; &nbsp;Ready; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// true if the service is ready
 &nbsp; &nbsp; &nbsp; &nbsp;bool &nbsp; &nbsp; &nbsp; &nbsp;Connected; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// true if the service is connected to the AES
 &nbsp; &nbsp; &nbsp; &nbsp;bool &nbsp; &nbsp; &nbsp; &nbsp;InConfig; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// true if the service is in the configuration
};

typedef list&lt;CService&gt; TServices;
typedef list&lt;CService&gt;::iterator SIT;

struct CAdminExecutorService
{
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService () : Id(NextId++), SockId(NULL), Connected(false) { }

 &nbsp; &nbsp; &nbsp; &nbsp;TSockId &nbsp; &nbsp; &nbsp; &nbsp;SockId; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// connection to the AES
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 &nbsp; &nbsp; &nbsp; &nbsp;Id; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// uint32 to identify the AES where the service is running

 &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;ServerAlias; &nbsp; &nbsp; &nbsp; &nbsp;/// name of the layer4 connection, used to send message to this AES
 &nbsp; &nbsp; &nbsp; &nbsp;string &nbsp; &nbsp; &nbsp; &nbsp;ServerAddr; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// address in a string format (only the ip)
 &nbsp; &nbsp; &nbsp; &nbsp;bool &nbsp; &nbsp; &nbsp; &nbsp;Connected; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// true if the AES is connected

 &nbsp; &nbsp; &nbsp; &nbsp;TServices Services;

 &nbsp; &nbsp; &nbsp; &nbsp;vector&lt;string&gt; &nbsp; &nbsp; &nbsp; &nbsp;ServiceAliasList;

 &nbsp; &nbsp; &nbsp; &nbsp;SIT findService (uint32 sid, bool asrt = true)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SIT sit;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (sit = Services.begin(); sit != Services.end(); sit++)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((*sit).Id == sid)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (asrt)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlassert (sit != Services.end());
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return sit;
 &nbsp; &nbsp; &nbsp; &nbsp;}

private:
 &nbsp; &nbsp; &nbsp; &nbsp;static uint32 NextId;
};

uint32 CAdminExecutorService::NextId = 1;

typedef list&lt;CAdminExecutorService&gt; TAdminExecutorServices;
typedef list&lt;CAdminExecutorService&gt;::iterator AESIT;

TAdminExecutorServices AdminExecutorServices;

/////////////////

AESIT findAdminExecutorService (uint32 aesid, bool asrt = true)
{
 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit;
 &nbsp; &nbsp; &nbsp; &nbsp;for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((*aesit).Id == aesid)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;

 &nbsp; &nbsp; &nbsp; &nbsp;if (asrt)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlassert (aesit != AdminExecutorServices.end());
 &nbsp; &nbsp; &nbsp; &nbsp;return aesit;
}

AESIT findAdminExecutorService (string ServerAlias, bool asrt = true)
{
 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit;
 &nbsp; &nbsp; &nbsp; &nbsp;for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((*aesit).ServerAlias == ServerAlias)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;

 &nbsp; &nbsp; &nbsp; &nbsp;if (asrt)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlassert (aesit != AdminExecutorServices.end());
 &nbsp; &nbsp; &nbsp; &nbsp;return aesit;
}

void displayServices ()
{
 &nbsp; &nbsp; &nbsp; &nbsp;for (AESIT aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (SIT sit = (*aesit).Services.begin(); sit != (*aesit).Services.end(); sit++)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;&gt; %s %s %s %d %d&quot;, (*aesit).SockId-&gt;asString().c_str(), (*sit).ShortName.c_str(), (*sit).LongName.c_str(), (*aesit).Id, (*sit).Id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////// SCRIPT MANAGER /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

bool ScriptRunning = false;
string ScriptName;
uint32 ScriptPos;

void doNextScriptStep ()
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (ScriptRunning);


 &nbsp; &nbsp; &nbsp; &nbsp;// get the script

 &nbsp; &nbsp; &nbsp; &nbsp;try
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CConfigFile::CVar &amp;script = IService::ConfigFile.getVar(ScriptName);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// check the position

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ScriptPos*2 &gt;= (uint32)script.size())
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = false;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlinfo(&quot;end of the script&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// todo send that the script is finish to the admin
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// get the script line

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serverAlias;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serviceAlias;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serverAlias = script.asString (ScriptPos*2);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serviceAlias = script.asString (ScriptPos*2+1);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;catch(EBadSize &amp;)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning (&quot;script '%s' not contains a good number of entries (must be a multiple of 2)&quot;, ScriptName.c_str());
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = false;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (serverAlias, false);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = false;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning(&quot;don't find the server&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// send the resquest to the AES

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), &quot;STARTS&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (serviceAlias);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send ((*aesit).ServerAlias, msgout);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptPos++;
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;catch(EUnknownVar&amp;)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning (&quot;script '%s' not found&quot;, ScriptName.c_str());
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = false;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}
}

void initScript(string scriptName)
{
 &nbsp; &nbsp; &nbsp; &nbsp;if (ScriptRunning)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning(&quot;already running a script, reset it&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = false;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;try
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CConfigFile::CVar &amp;script = IService::ConfigFile.getVar(scriptName);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (sint i = 0 ; i &lt; script.size (); i+=2)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serverAlias = script.asString(i);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (serverAlias, false);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning(&quot;aes not running, can't run the script&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;catch(EConfigFile &amp;)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlwarning (&quot;bad config file&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;ScriptName = scriptName;
 &nbsp; &nbsp; &nbsp; &nbsp;ScriptPos = 0;
 &nbsp; &nbsp; &nbsp; &nbsp;ScriptRunning = true;

 &nbsp; &nbsp; &nbsp; &nbsp;doNextScriptStep();
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// 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 cbServiceList (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
/* &nbsp; &nbsp; &nbsp;// get the service list from the admin exec and send the list to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();
 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Services.clear();

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SL&quot;);

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbaes = 1;
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbaes);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id);

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbs;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (nbs);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbs);

 &nbsp; &nbsp; &nbsp; &nbsp;for (uint32 i = 0; i &lt; nbs; i++)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint32 sid;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial(sid);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Services.push_back (CService(sid));
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CService *s = &amp;(aes-&gt;Services.back());

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial(s-&gt;ShortName, s-&gt;LongName, s-&gt;Ready);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (s-&gt;Id, s-&gt;ShortName, s-&gt;LongName, s-&gt;Ready);
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
 &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;displayServices ();
*/}

static void cbServiceAliasList (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// get the service list from the admin exec and send the list to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;ServiceAliasList.clear ();
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serialCont (aes-&gt;ServiceAliasList);

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SAL&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serialCont (aes-&gt;ServiceAliasList);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
 &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo(&quot;new service alias list&quot;);
}


static void cbServiceIdentification (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 sid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);

 &nbsp; &nbsp; &nbsp; &nbsp;SIT sit = aes-&gt;findService(sid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial ((*sit).ShortName, (*sit).LongName);

 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:%d is identified to be '%s' '%s'&quot;, aes-&gt;Id, sid, (*sit).ShortName.c_str(), (*sit).LongName.c_str());

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SID&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, sid, (*sit).ShortName, (*sit).LongName);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
}

static void cbServiceReady (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 sid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);

 &nbsp; &nbsp; &nbsp; &nbsp;SIT sit = aes-&gt;findService(sid);
 &nbsp; &nbsp; &nbsp; &nbsp;(*sit).Ready = true;

 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:%d is ready&quot;, aes-&gt;Id, sid);

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SR&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, sid);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);

 &nbsp; &nbsp; &nbsp; &nbsp;// if we are in a script execution, continue
 &nbsp; &nbsp; &nbsp; &nbsp;if (ScriptRunning)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;doNextScriptStep();
}

static void cbServiceConnection (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
/* &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 sid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);

 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:%d connected&quot;, aes-&gt;Id, sid);

 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Services.push_back (CService(sid));

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SC&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, sid);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
*/}

static void cbServiceDisconnection (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;uint32 sid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);

 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:%d disconnected&quot;, aes-&gt;Id, sid);

 &nbsp; &nbsp; &nbsp; &nbsp;SIT sit = aes-&gt;findService(sid);

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SD&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, (*sit).Id);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);

 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Services.erase (sit);
}

// i'm connected to a new admin executor service
void cbAESConnection (const string &amp;serviceName, TSockId from, void *arg)
{
 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (serviceName); &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = &amp;(*aesit);
 &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;// set the appid to find the aes in O(1)
 &nbsp; &nbsp; &nbsp; &nbsp;from-&gt;setAppId ((uint64)aes);

 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Connected = true;
 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:* connected&quot;, aes-&gt;Id);
/* &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message that an admin exec is connected to all admin client
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;AESC&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
*/

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the new state of this AES
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;AES_LIST&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbaes = 1;
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbaes);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, aes-&gt;ServerAlias, aes-&gt;ServerAddr, aes-&gt;Connected);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
}

// i'm disconnected to an admin executor service
void cbAESDisconnection (const string &amp;serviceName, TSockId from, void *arg)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// get the aes with the appid
 &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService *aes = (CAdminExecutorService*) from-&gt;appId();

 &nbsp; &nbsp; &nbsp; &nbsp;aes-&gt;Connected = false;
 &nbsp; &nbsp; &nbsp; &nbsp;nlinfo (&quot;*:%d:* disconnected&quot;, aes-&gt;Id);
/* &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to all admin client that an admin exec is disconnected
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;AESD&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
*/

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the new state of this AES
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;AES_LIST&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbaes = 1;
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbaes);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (aes-&gt;Id, aes-&gt;ServerAlias, aes-&gt;ServerAddr, aes-&gt;Connected);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
}

static void cbLog (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// received an answer for a command, give it to all admin client

 &nbsp; &nbsp; &nbsp; &nbsp;// broadcast the message to the admin service
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;LOG&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;string log;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (log);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (log);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, 0);
}


TCallbackItem AESCallbackArray[] =
{
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;ESCR&quot;, cbExecuteSystemCommandResult },

 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SL&quot;, cbServiceList },
 &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 },

 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SAL&quot;, cbServiceAliasList },

 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;LOG&quot;, cbLog },
};


////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// CONNECTION TO THE CLIENT ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

void errorMessage(string message, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (netbase.getSIDA (), &quot;ERR&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (message);
 &nbsp; &nbsp; &nbsp; &nbsp;netbase.send (msgout, from);
}

//
// A new admin client is connected.
//
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;// send the list of all the aes
 &nbsp; &nbsp; &nbsp; &nbsp;//

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout2 (CNetManager::getSIDA (&quot;AS&quot;), &quot;AES_LIST&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit;
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbaes = (uint32)AdminExecutorServices.size();
 &nbsp; &nbsp; &nbsp; &nbsp;msgout2.serial (nbaes);
 &nbsp; &nbsp; &nbsp; &nbsp;for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// send info about the AES

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout2.serial ((*aesit).Id, (*aesit).ServerAlias, (*aesit).ServerAddr, (*aesit).Connected);
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout2, from);

 &nbsp; &nbsp; &nbsp; &nbsp;//
 &nbsp; &nbsp; &nbsp; &nbsp;// send the list of all services
 &nbsp; &nbsp; &nbsp; &nbsp;//

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA (&quot;AS&quot;), &quot;SERVICE_LIST&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;nbaes = (uint32)AdminExecutorServices.size();
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbaes);
 &nbsp; &nbsp; &nbsp; &nbsp;for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*aesit).Id);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint32 nbs = (uint32)(*aesit).Services.size();
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (nbs);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (SIT sit = (*aesit).Services.begin(); sit != (*aesit).Services.end(); sit++)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// send info about services of the AES
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*sit).Id, (*sit).ServiceAlias, (*sit).ShortName, (*sit).LongName);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial ((*sit).Ready, (*sit).Connected, (*sit).InConfig);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout, from);

 &nbsp; &nbsp; &nbsp; &nbsp;//
 &nbsp; &nbsp; &nbsp; &nbsp;// send service alias list
 &nbsp; &nbsp; &nbsp; &nbsp;//

 &nbsp; &nbsp; &nbsp; &nbsp;for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout2 (CNetManager::getSIDA (&quot;AS&quot;), &quot;SAL&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout2.serial ((*aesit).Id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgout2.serialCont ((*aesit).ServiceAliasList);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send (&quot;AS&quot;, msgout2, from);
 &nbsp; &nbsp; &nbsp; &nbsp;}
}


static void cbExecuteScript (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;string script;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (script);
 &nbsp; &nbsp; &nbsp; &nbsp;initScript (script);
}


static void cbExecuteSystemCommand (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;string command;
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 aesid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (aesid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (command);

 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (aesid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the aes, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't execute command, as didn't find the aes&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;// send the resquest to the AES

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), &quot;SYS&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (command);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send ((*aesit).ServerAlias, msgout);
}


static void cbStartService (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;string serviceName;
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 aesid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (aesid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (serviceName);

 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (aesid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the aes, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't start service, as didn't find the aes&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;// send the resquest to the AES

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), &quot;STARTS&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (serviceName);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send ((*aesit).ServerAlias, msgout);
}

static void cbStopService (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 aesid, sid;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (aesid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);

 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (aesid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't stop service, as didn't find the aes&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the aes, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;SIT sit = (*aesit).findService (sid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (sit == (*aesit).Services.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the s, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't stop service, as didn't find the service&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;// send the resquest to the AES

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), &quot;STOPS&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (sid);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send ((*aesit).ServerAlias, msgout);
}

static void cbExecCommand (CMessage&amp; msgin, TSockId from, CCallbackNetBase &amp;netbase)
{
 &nbsp; &nbsp; &nbsp; &nbsp;uint32 aesid, sid;
 &nbsp; &nbsp; &nbsp; &nbsp;string command;
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (aesid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (sid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgin.serial (command);

 &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (aesid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (aesit == AdminExecutorServices.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't stop service, as didn't find the aes&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the aes, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;SIT sit = (*aesit).findService (sid, false);
 &nbsp; &nbsp; &nbsp; &nbsp;if (sit == (*aesit).Services.end())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// don't find the s, send an error message
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorMessage (&quot;couldn't stop service, as didn't find the service&quot;, from, netbase);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;// send the resquest to the AES

 &nbsp; &nbsp; &nbsp; &nbsp;CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), &quot;EXEC_COMMAND&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (sid);
 &nbsp; &nbsp; &nbsp; &nbsp;msgout.serial (command);
 &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::send ((*aesit).ServerAlias, msgout);
}


TCallbackItem ClientCallbackArray[] =
{
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;SYS&quot;, cbExecuteSystemCommand },
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;EXEC&quot;, cbExecuteScript },
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;STARTS&quot;, cbStartService },
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;STOPS&quot;, cbStopService },
 &nbsp; &nbsp; &nbsp; &nbsp;{ &quot;EXEC_COMMAND&quot;, cbExecCommand },
};

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// SERVICE IMPLEMENTATION //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

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;DebugLog-&gt;addNegativeFilter (&quot;L0:&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DebugLog-&gt;addNegativeFilter (&quot;L1:&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DebugLog-&gt;addNegativeFilter (&quot;L2:&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &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;//
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Get the list of AESHosts, add in the structures and create connection to all AES
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CConfigFile::CVar &amp;host = ConfigFile.getVar (&quot;AESHosts&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (sint i = 0 ; i &lt; host.size (); i+=2)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serverAlias = host.asString(i);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serverAddr = host.asString(i+1);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// add to the list
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CAdminExecutorService aes;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aes.ServerAlias = serverAlias;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aes.ServerAddr = serverAddr;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AdminExecutorServices.push_back (aes);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// connect to the AES
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::setConnectionCallback (serverAlias, cbAESConnection, NULL);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::setDisconnectionCallback (serverAlias, cbAESDisconnection, NULL);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::addClient (serverAlias, serverAddr+&quot;:49996&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CNetManager::addCallbackArray (serverAlias, AESCallbackArray, sizeof (AESCallbackArray)/sizeof(AESCallbackArray[0]));
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Get the list of services in the shard
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CConfigFile::CVar &amp;serv = ConfigFile.getVar (&quot;Services&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (i = 0 ; i &lt; serv.size (); i+=2)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serverAlias = serv.asString(i);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string serviceAlias = serv.asString(i+1);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AESIT aesit = findAdminExecutorService (serverAlias);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// add new AES in the list
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CService s;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.ServiceAlias = serviceAlias;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.InConfig = true;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(*aesit).Services.push_back (s);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &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;}
};


// AS is a server connection to the admin client
// AESAS is a client connection to the admin executor

/// Naming Service
NLNET_SERVICE_MAIN (CAdminService, &quot;AS&quot;, &quot;admin_service&quot;, 49995, ClientCallbackArray);
</PRE>