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