Annotation of freem/src/ssvn_lock.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * ssvn_lock.c
15: * ^$LOCK 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 <stdio.h>
41: #include <stdlib.h>
42: #include <string.h>
43:
44: #include "mpsdef.h"
45: #include "mref.h"
46:
47: void ssvn_lock_add(char *key, pid_t owner_job, int count)
48: {
49: register int i;
50:
51: char *t_buf;
52: char *k_buf;
53: char *d_buf;
54: freem_ref_t *r;
55:
56: t_buf = (char *) malloc (STRLEN * sizeof (char));
57: NULLPTRCHK(t_buf,"ssvn_lock_add");
58:
59: k_buf = (char *) malloc (STRLEN * sizeof (char));
60: NULLPTRCHK(k_buf,"ssvn_lock_add");
61:
62: d_buf = (char *) malloc (STRLEN * sizeof (char));
63: NULLPTRCHK(d_buf,"ssvn_lock_add");
64:
65: r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
66: NULLPTRCHK(r,"ssvn_lock_add");
67:
68: mref_init (r, MREF_RT_GLOBAL, "");
69: internal_to_mref (r, key);
70: mref_to_external (r, t_buf);
71:
72: //printf ("key = '%s'\r\n", key);
73: //printf ("r = '%s'\r\n", t_buf);
74:
75: for (i = 0; i < strlen (t_buf); i++) {
76:
77: if (t_buf[i] == '\001') {
78: t_buf[i] = '\0';
79: break;
80: }
81:
82: }
83:
84: snprintf (k_buf, STRLEN - 1, "^$LOCK\202%s\201", t_buf);
85: snprintf (d_buf, STRLEN - 1, "%ld,%d\201\0", owner_job, count);
86:
87: symtab_shm (set_sym, k_buf, d_buf);
88:
89: free (t_buf);
90: free (k_buf);
91: free (d_buf);
92: free (r);
93:
94: }
95:
96: void ssvn_lock_remove(char *key)
97: {
98: register int i;
99:
100: char *t_buf;
101: char *k_buf;
102: char *d_buf;
103: freem_ref_t *r;
104:
105: t_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
106: NULLPTRCHK(t_buf,"ssvn_lock_add");
107:
108: k_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
109: NULLPTRCHK(k_buf,"ssvn_lock_add");
110:
111: d_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
112: NULLPTRCHK(d_buf,"ssvn_lock_add");
113:
114: r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
115: NULLPTRCHK(r,"ssvn_lock_add");
116:
117: mref_init (r, MREF_RT_GLOBAL, "");
118: internal_to_mref (r, key);
119: mref_to_external (r, t_buf);
120:
121: for (i = 0; i < strlen (t_buf); i++) {
122:
123: if (t_buf[i] == '\001') {
124: t_buf[i] = '\0';
125: break;
126: }
127:
128: }
129:
130: snprintf (k_buf, STRLEN - 1, "^$LOCK\202%s\201", t_buf);
131: snprintf (d_buf, STRLEN - 1, " \201");
132:
133: symtab_shm (kill_sym, k_buf, d_buf);
134:
135: }
136:
137: void ssvn_lock(short action, char *key, char *data)
138: {
139:
140: switch (action) {
141:
142: case set_sym:
143: case kill_sym:
144: //TODO: remove lock
145: merr_raise (M29);
146: return;
147:
148: default:
149: symtab_shm (action, key, data);
150: break;
151:
152: }
153:
154: return;
155: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>