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