Annotation of freem/src/ssvn_system.c, revision 1.5
1.1 snw 1: /*
1.5 ! snw 2: * $Id: ssvn_system.c,v 1.4 2025/03/09 19:50:47 snw Exp $
1.4 snw 3: * ^$SYSTEM ssvn
1.1 snw 4: *
5: *
1.3 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.4 snw 8: * Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.5 ! snw 26: * $Log: ssvn_system.c,v $
! 27: * Revision 1.4 2025/03/09 19:50:47 snw
! 28: * Second phase of REUSE compliance and header reformat
! 29: *
1.4 snw 30: *
31: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
32: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 33: **/
34:
35: #include <inttypes.h>
36: #include <stdio.h>
37: #include <stdlib.h>
38: #include <string.h>
39: #if defined(HAVE_STDINT_H)
40: # include <stdint.h>
41: #endif
42: #include "mref.h"
43: #include "mpsdef.h"
44: #include "shmmgr.h"
45: #include "iniconf.h"
46:
47: void ssvn_system_set(char *sub)
48: {
49: char k_buf[255];
50: char d_buf[255];
51:
52: d_buf[0] = '\201';
53: d_buf[1] = '\201';
54: snprintf (k_buf, 254, "^$SYSTEM\202%s\201", sub);
55:
56: symtab_shm (set_sym, k_buf, d_buf);
57:
58: }
59:
60: void ssvn_system_update(void)
61: {
62: FILE *fp;
63: char line[255];
64: char line_ns[255];
65:
66: char k_buf[255];
67: char d_buf[255];
68:
69: ssvn_system_set ("MAPPINGS");
70: ssvn_system_set ("MAINTENANCE_MODE");
71: ssvn_system_set ("DAEMON_PID");
72: ssvn_system_set ("MWAPI");
73: ssvn_system_set ("EVENT");
74: ssvn_system_set ("ERRMSG");
75: ssvn_system_set ("NAME_LENGTH");
76: ssvn_system_set ("DEFPSIZE");
77: ssvn_system_set ("DEFUDFSVSIZ");
78: ssvn_system_set ("DEFNSIZE");
79: ssvn_system_set ("MAXNO_OF_RBUF");
80: ssvn_system_set ("DEFNO_OF_RBUF");
81: ssvn_system_set ("DEFPSIZE0");
82: ssvn_system_set ("NO_GLOBLS");
83: ssvn_system_set ("NO_OF_GBUF");
84: ssvn_system_set ("NESTLEVLS");
85: ssvn_system_set ("PARDEPTH");
86: ssvn_system_set ("PATDEPTH");
87: ssvn_system_set ("TRLIM");
88: ssvn_system_set ("ARGS_IN_ESC");
89: ssvn_system_set ("ZTLEN");
90: ssvn_system_set ("FUNLEN");
91: ssvn_system_set ("STRING_MAX");
92: ssvn_system_set ("$NEXTOK");
93: ssvn_system_set ("EOK");
94: ssvn_system_set ("OFFOK");
95: ssvn_system_set ("BIG_ENDIAN");
96: ssvn_system_set ("ZDATE_FORMAT");
97: ssvn_system_set ("ZTIME_FORMAT");
98:
99: fp = fopen (config_file, "r");
100:
101: while (fgets (line, 254, fp) != NULL) {
102:
103: if (line[0] == '[') {
104: strcpy (line_ns, line + 1);
105: line_ns[strlen (line_ns) - 2] = '\0';
106:
107: snprintf (k_buf, 254, "^$SYSTEM\202NAMESPACE\202%s\201", line_ns);
108: symtab_shm (set_sym, k_buf, "\201");
109: }
110:
111: }
112:
113: fclose (fp);
114:
115: snprintf (k_buf, 254, "^$SYSTEM\202CHANNELS\202TERMINAL\201");
116: snprintf (d_buf, 254, "0,0\201");
117: symtab_shm (set_sym, k_buf, d_buf);
118:
119: snprintf (k_buf, 254, "^$SYSTEM\202CHANNELS\202FILE\201");
120: snprintf (d_buf, 254, "1,%d\201", FIRSTSCK - 1);
121: symtab_shm (set_sym, k_buf, d_buf);
122:
123: snprintf (k_buf, 254, "^$SYSTEM\202CHANNELS\202SOCKET\201");
124: snprintf (d_buf, 254, "%d,%d\201", FIRSTSCK, MAXDEV - 1);
125: symtab_shm (set_sym, k_buf, d_buf);
126:
127: ssvn_job_update ();
128:
129: }
130:
131: void ssvn_system(short action, char *key, char *data)
132: {
133:
134: freem_ref_t *r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
135: NULLPTRCHK(r,"ssvn_system");
136:
137: mref_init (r, MREF_RT_SSV, "^$SYSTEM");
138: internal_to_mref (r, key);
139:
140: if ((r->subscript_count > 2) && (strcmp (r->subscripts[0], "EVENT") != 0) && (strcmp (r->subscripts[0], "MAPPINGS") != 0)) {
141: merr_raise (INVREF);
142: goto done;
143: }
144:
145: switch (action) {
146:
147: case get_sym:
148:
149: if (strcmp (r->subscripts[0], "NAMESPACE") == 0) {
150:
151: symtab_shm (action, key, data);
152: merr_clear ();
153: break;
154:
155: }
156: else if (strcmp (r->subscripts[0], "MAPPINGS") == 0) {
157:
158: if ((strcmp (r->subscripts[1], "GLOBAL") == 0) || (strcmp (r->subscripts[1], "ROUTINE") == 0)) {
159:
160: merr_clear ();
161: symtab_shm (action, key, data);
162:
163: break;
164:
165: }
166: else {
167:
168: merr_raise (M38);
169: break;
170:
171: }
172:
173: }
174: else if (strcmp (r->subscripts[0], "ENVIRONMENT") == 0) {
175: char varnam[255];
176: char res[255];
177: char *e;
178:
179: strcpy (varnam, r->subscripts[1]);
180:
181: e = getenv (varnam);
182:
183: if (e == NULL) {
184: sprintf (data, "\201");
185: break;
186: }
187: else {
188: strcpy (res, e);
189: stcnv_c2m (res);
190: stcpy (data, res);
191: }
192:
193: break;
194: }
195: else if (strcmp (r->subscripts[0], "MAINTENANCE_MODE") == 0) {
196:
197: snprintf (data, 511, "%d\201", shm_config->hdr->maintenance_mode);
198: merr_clear ();
199: break;
200:
201: }
202: else if (strcmp (r->subscripts[0], "DAEMON_PID") == 0) {
203:
204: snprintf (data, 511, "%d\201", shm_config->hdr->first_process);
205: merr_clear ();
206: break;
207:
208: }
209: else if (strcmp (r->subscripts[0], "MWAPI") == 0) {
210:
211: #if defined(MWAPI_GTK)
212: snprintf (data, 511, "1\201");
213: #else
214: snprintf (data, 511, "0\201");
215: #endif
216: merr_clear ();
217: break;
218:
219: }
220: else if (strcmp (r->subscripts[0], "EVENT") == 0) {
221:
222: symtab_shm (action, key, data);
223: merr_clear ();
224: break;
225:
226: }
227: else if (strcmp (r->subscripts[0], "ERRMSG") == 0) {
228:
229: int errnum;
230:
231: errnum = merr_code_to_num (r->subscripts[1]);
232:
233: if (errnum == -1) {
234: merr_raise (M38);
235: break;
236: }
237:
1.2 snw 238: sprintf (data, "%s", errmes[errnum]);
1.1 snw 239: merr_clear ();
240: break;
241:
242: }
243: else if (strcmp (r->subscripts[0], "NAME_LENGTH") == 0) {
244:
245: sprintf (data, "255\201");
246: merr_clear ();
247: break;
248:
249: }
250: else if (strcmp (r->subscripts[0], "DEFPSIZE") == 0) {
251: sprintf (data, "%ld\201", DEFPSIZE);
252: merr_clear ();
253: break;
254: }
255: else if (strcmp (r->subscripts[0], "DEFUDFSVSIZ") == 0) {
1.2 snw 256: sprintf (data, "%ld\201", (long) DEFUDFSVSIZ);
1.1 snw 257: merr_clear ();
258: break;
259: }
260: else if (strcmp (r->subscripts[0], "DEFNSIZE") == 0) {
1.2 snw 261: sprintf (data, "%ld\201", (long) DEFNSIZE);
1.1 snw 262: merr_clear ();
263: break;
264: }
265: else if (strcmp (r->subscripts[0], "MAXNO_OF_RBUF") == 0) {
1.2 snw 266: sprintf (data, "%d\201", MAXNO_OF_RBUF);
1.1 snw 267: merr_clear ();
268: break;
269: }
270: else if (strcmp (r->subscripts[0], "DEFNO_OF_RBUF") == 0) {
1.2 snw 271: sprintf (data, "%ld\201", (long) DEFNO_OF_RBUF);
1.1 snw 272: merr_clear ();
273: break;
274: }
275: else if (strcmp (r->subscripts[0], "DEFPSIZE0") == 0) {
1.2 snw 276: sprintf (data, "%d\201", DEFPSIZE0);
1.1 snw 277: merr_clear ();
278: break;
279: }
280: else if (strcmp (r->subscripts[0], "NO_GLOBLS") == 0) {
1.2 snw 281: sprintf (data, "%d\201", NO_GLOBLS);
1.1 snw 282: merr_clear ();
283: break;
284: }
285: else if (strcmp (r->subscripts[0], "NO_OF_GBUF") == 0) {
1.2 snw 286: sprintf (data, "%d\201", NO_OF_GBUF);
1.1 snw 287: merr_clear ();
288: break;
289: }
290: else if (strcmp (r->subscripts[0], "NESTLEVLS") == 0) {
1.2 snw 291: sprintf (data, "%d\201", NESTLEVLS);
1.1 snw 292: merr_clear ();
293: break;
294: }
295: else if (strcmp (r->subscripts[0], "PARDEPTH") == 0) {
1.2 snw 296: sprintf (data, "%d\201", PARDEPTH);
1.1 snw 297: merr_clear ();
298: break;
299: }
300: else if (strcmp (r->subscripts[0], "PATDEPTH") == 0) {
1.2 snw 301: sprintf (data, "%d\201", PATDEPTH);
1.1 snw 302: merr_clear ();
303: break;
304: }
305: else if (strcmp (r->subscripts[0], "TRLIM") == 0) {
1.2 snw 306: sprintf (data, "%d\201", TRLIM);
1.1 snw 307: merr_clear ();
308: break;
309: }
310: else if (strcmp (r->subscripts[0], "ARGS_IN_ESC") == 0) {
1.2 snw 311: sprintf (data, "%d\201", ARGS_IN_ESC);
1.1 snw 312: merr_clear ();
313: break;
314: }
315: else if (strcmp (r->subscripts[0], "ZTLEN") == 0) {
1.2 snw 316: sprintf (data, "%d\201", ZTLEN);
1.1 snw 317: merr_clear ();
318: break;
319: }
320: else if (strcmp (r->subscripts[0], "FUNLEN") == 0) {
1.2 snw 321: sprintf (data, "%d\201", FUNLEN);
1.1 snw 322: merr_clear ();
323: break;
324: }
325: else if (strcmp (r->subscripts[0], "STRING_MAX") == 0) {
326:
1.2 snw 327: sprintf (data, "%d\201", STRLEN);
1.1 snw 328: merr_clear ();
329: break;
330:
331: }
332: else if (strcmp (r->subscripts[0], "$NEXTOK") == 0) {
333:
334: sprintf (data, "1\201");
335: merr_clear ();
336: break;
337:
338: }
339: else if (strcmp (r->subscripts[0], "EOK") == 0) {
340:
341: sprintf (data, "1\201");
342: merr_clear ();
343: break;
344:
345: }
346: else if (strcmp (r->subscripts[0], "OFFOK") == 0) {
347:
348: sprintf (data, "1\201");
349: merr_clear ();
350: break;
351:
352: }
353: else if (strcmp (r->subscripts[0], "BIG_ENDIAN") == 0) {
354:
355: #if defined(HAVE_STDINT_H)
356: volatile uint32_t i = 0x01234567;
357:
358: if ((*((uint8_t*)(&i)) == 0x67) == 0) {
359: sprintf (data, "1\201");
360: }
361: else {
362: sprintf (data, "0\201");
363: }
364:
365: merr_clear ();
366: break;
367: #else
368: merr_raise (M29);
369: goto done;
370: #endif
371: }
372: else if (strcmp (r->subscripts[0], "ZDATE_FORMAT") == 0) {
373: get_conf ("SYSTEM", "zdate_format", data);
374: stcnv_c2m (data);
375:
376:
377: break;
378: }
379: else if (strcmp (r->subscripts[0], "ZTIME_FORMAT") == 0) {
380: get_conf ("SYSTEM", "ztime_format", data);
381: stcnv_c2m (data);
382:
383: break;
384: }
385: else if (strcmp (r->subscripts[0], "CHANNELS") == 0) {
386: symtab_shm (action, key, data);
387: break;
388: }
389: /*
390: else {
391: symtab_shm (action, key, data);
392: break;
393: }
394: */
395:
396: merr_raise (M29);
397: goto done;
398:
399: case bigquery:
400: case fra_query:
401: case fra_order:
402: /*
403: if (strcmp (r->subscripts[0], "NAMESPACE") != 0) {
404: merr_raise (M29);
405: goto done;
406: }
407: */
408:
409: symtab_shm (action, key, data);
410: merr_clear ();
411: goto done;
412:
413: case kill_sym:
414: case set_sym:
415: if ((strcmp (r->subscripts[0], "MAINTENANCE_MODE") == 0) && (action == set_sym)) {
416: shm_config->hdr->maintenance_mode = tvexpr (data);
417: merr_clear ();
418: goto done;
419: }
420:
421: if ((strcmp (r->subscripts[0], "EVENT") != 0) && (strcmp (r->subscripts[0], "MAPPINGS") != 0)) {
422: merr_raise (M29);
423: goto done;
424: }
425:
426: if ((strcmp (r->subscripts[0], "MAPPINGS") == 0) && ((strcmp (r->subscripts[1], "GLOBAL") != 0) && (strcmp (r->subscripts[1], "ROUTINE") != 0))) {
427: merr_raise (M38);
428: goto done;
429: }
430:
431: symtab_shm (action, key, data);
432: merr_clear ();
433: goto done;
434:
1.5 ! snw 435: case fra_dat:
1.1 snw 436: symtab_shm (action, key, data);
437: merr_clear ();
438: goto done;
439:
440: default:
441: merr_raise (INVREF);
442: break;
443:
444: }
445:
446: done:
447:
448: free (r);
449:
450: return;
451: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>