-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARexx.c
356 lines (269 loc) · 7.04 KB
/
ARexx.c
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
/*
** SPDX-License-Identifier: GPL-3.0-or-later
** Copyright (c) 2023-2024 Rene W. Olsen <[email protected]>
*/
// --
#include "RVNCd.h"
// --
static Object * myARexxObject = NULL;
static struct Hook myARexxHook;
uint32 ARexxBit = 0;
struct Library * ARexxBase = NULL;
Class * ARexxClass = NULL;
static struct Config * ActiveConfig = NULL;
// --
static uint32 ARexxCallBack( struct Hook *h , Object *o, struct RexxMsg *msg );
static void ARexx_StartServer( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_StopServer( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_RestartServer( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_ServerStatus( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_Quit( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_ForceQuit( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_LoadConfig( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_SaveConfig( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_SaveASConfig( struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_SaveDefaultConfig(struct ARexxCmd *ac, struct RexxMsg *msg );
static void ARexx_Help( struct ARexxCmd *ac, struct RexxMsg *msg );
// Ideas!!
// Users connected .. 0-x .. if we expand it to a real sharing vnc server
// Disconnect user .. disconnect a client if there is one (pjs)
// query user info .. eg. ip address, connect time, online time, screen info
// CLIENTS
// QUERY # TYPE
// DISCONNECT #
static struct ARexxCmd Commands[] =
{
{ "STARTSERVER", 1, ARexx_StartServer, NULL, 0, NULL, 0, 0, NULL },
{ "STOPSERVER", 2, ARexx_StopServer, NULL, 0, NULL, 0, 0, NULL },
{ "RESTARTSERVER", 3, ARexx_RestartServer, NULL, 0, NULL, 0, 0, NULL },
{ "SERVERSTATUS", 4, ARexx_ServerStatus, NULL, 0, NULL, 0, 0, NULL },
{ "QUIT", 5, ARexx_Quit, NULL, 0, NULL, 0, 0, NULL },
{ "LOADCONFIG", 6, ARexx_LoadConfig, "FILE/F", 0, NULL, 0, 0, NULL },
{ "SAVECONFIG", 7, ARexx_SaveConfig, NULL, 0, NULL, 0, 0, NULL },
{ "SAVEASCONFIG", 8, ARexx_SaveASConfig, "FILE/F", 0, NULL, 0, 0, NULL },
{ "SAVEDEFAULTCONFIG", 9, ARexx_SaveDefaultConfig, NULL, 0, NULL, 0, 0, NULL },
{ "HELP", 10, ARexx_Help, NULL, 0, NULL, 0, 0, NULL },
{ "FORCEQUIT", 11, ARexx_ForceQuit, NULL, 0, NULL, 0, 0, NULL },
{ NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL },
};
// --
int ARexx_Setup( struct Config *cfg )
{
uint32 err;
int error;
// --
error = FALSE;
ARexxBase = (APTR) IIntuition->OpenClass( "arexx.class", 53, & ARexxClass );
if ( ARexxBase == NULL )
{
cfg->cfg_ProgramDisableARexx = TRUE;
Log_PrintF( cfg, LOGTYPE_Warning, "Error opening ARexx class, Disabling ARexx support" );
goto bailout;
}
// --
error = TRUE;
ActiveConfig = cfg;
myARexxHook.h_Entry = (HOOKFUNC) ARexxCallBack;
myARexxHook.h_SubEntry = NULL;
myARexxHook.h_Data = NULL;
// --
err = 0;
myARexxObject = IIntuition->NewObject( ARexxClass, NULL,
AREXX_ReplyHook, & myARexxHook,
AREXX_ErrorCode, & err,
AREXX_HostName, "rVNCd",
AREXX_Commands, Commands,
AREXX_NoSlot, TRUE,
TAG_END
);
if ( myARexxObject == NULL )
{
Log_PrintF( cfg, LOGTYPE_Error, "Error creating ARexx Object (%ld)", err );
goto bailout;
}
IIntuition->GetAttrs( myARexxObject,
AREXX_SigMask, & ARexxBit,
TAG_END
);
// --
error = FALSE;
bailout:
return( error );
}
// --
void ARexx_Cleanup( struct Config *cfg UNUSED )
{
if ( myARexxObject )
{
IIntuition->DisposeObject( myARexxObject );
myARexxObject = NULL;
ARexxBit = 0;
}
if ( ARexxBase )
{
IIntuition->CloseClass( (APTR) ARexxBase );
ARexxBase = NULL;
}
}
// --
void ARexx_Handle( struct Config *cfg UNUSED )
{
IIntuition->IDoMethod( myARexxObject, AM_HANDLEEVENT );
}
// --
static uint32 ARexxCallBack( struct Hook *h UNUSED, Object *o UNUSED, struct RexxMsg *msg UNUSED )
{
return( 0 );
}
// --
static void ARexx_StartServer( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
int err;
err = StartServer( ActiveConfig );
if ( err )
{
ac->ac_Result = "Failed";
}
else
{
ac->ac_Result = "Successful";
}
}
// --
static void ARexx_StopServer( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
int err;
err = StopServer( ActiveConfig );
if ( err )
{
ac->ac_Result = "Failed";
}
else
{
ac->ac_Result = "Successful";
}
}
// --
static void ARexx_RestartServer( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
int err;
err = RestartServer( ActiveConfig );
if ( err )
{
ac->ac_Result = "Failed";
}
else
{
ac->ac_Result = "Successful";
}
}
// --
static void ARexx_ServerStatus( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
char *txt;
/**/ if ( ActiveConfig->cfg_ServerStatus == PROCESS_Stopped )
{
txt = "Stopped";
}
else if ( ActiveConfig->cfg_ServerStatus == PROCESS_Starting )
{
txt = "Starting";
}
else if ( ActiveConfig->cfg_ServerStatus == PROCESS_Running )
{
txt = "Running";
}
else if ( ActiveConfig->cfg_ServerStatus == PROCESS_Stopping )
{
txt = "Shutting down";
}
else
{
txt = "Unknown";
}
ac->ac_Result = txt;
}
// --
static void ARexx_Quit( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
ac->ac_Result = "Exiting Program";
Func_Quit( ActiveConfig );
}
// --
static void ARexx_ForceQuit( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
ac->ac_Result = "Exiting Program";
Func_ForceQuit( ActiveConfig );
}
// --
static void ARexx_LoadConfig( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
struct CommandMessage *cmsg;
char *file;
char *str;
int err;
file = (APTR) ac->ac_ArgList[0];
str = "Failed";
if ( file )
{
Config_Reset( ActiveConfig );
err = Config_Read( ActiveConfig, file, TRUE );
if ( err )
{
Log_PrintF( ActiveConfig, LOGTYPE_Error, "Failed to load '%s' Config file", IDOS->FilePart( file ));
}
else
{
Log_PrintF( ActiveConfig, LOGTYPE_Info, "Config file '%s' loaded", IDOS->FilePart( file ) );
myGUI_Main_RefreshSettings( ActiveConfig );
myGUI_Main_CheckSettings( ActiveConfig );
str = "Successful";
// --
cmsg = myCalloc( sizeof( struct CommandMessage ) );
if ( cmsg )
{
cmsg->cm_Command = CMD_RefreshGUI;
IExec->PutMsg( CmdMsgPort, & cmsg->cm_Message );
}
}
}
ac->ac_Result = str;
}
// --
static void ARexx_SaveConfig( struct ARexxCmd *ac UNUSED, struct RexxMsg *msg UNUSED )
{
Config_Save( ActiveConfig, ActiveConfig->cfg_Config_Filename );
}
// --
static void ARexx_SaveASConfig( struct ARexxCmd *ac, struct RexxMsg *msg UNUSED )
{
char *file;
file = (APTR) ac->ac_ArgList[0];
if ( file )
{
Config_Save( ActiveConfig, file );
}
}
// --
static void ARexx_SaveDefaultConfig( struct ARexxCmd *ac UNUSED, struct RexxMsg *msg UNUSED )
{
Config_Save( ActiveConfig, NULL );
}
// --
static void ARexx_Help( struct ARexxCmd *ac UNUSED, struct RexxMsg *msg UNUSED )
{
char *str =
"STARTSERVER"
" STOPSERVER"
" RESTARTSERVER"
" SERVERSTATUS"
" QUIT"
" LOADCONFIG"
" SAVECONFIG"
" SAVEASCONFIG"
" SAVEDEFAULTCONFIG"
" HELP"
;
ac->ac_Result = str;
}
// --