1: /*
2: * $Id: iftab.c,v 1.3 2025/03/09 19:14:25 snw Exp $
3: * implementation of the freem transactions-in-flight symbol table
4: *
5: *
6: * Author: Serena Willis <snw@coherent-logic.com>
7: * Copyright (C) 1998 MUG Deutschland
8: * Copyright (C) 2020, 2025 Coherent Logic Development LLC
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: *
26: * $Log: iftab.c,v $
27: * Revision 1.3 2025/03/09 19:14:25 snw
28: * First phase of REUSE compliance and header reformat
29: *
30: *
31: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
32: * SPDX-License-Identifier: AGPL-3.0-or-later
33: **/
34:
35: #include <stdlib.h>
36: #include "iftab.h"
37: #include "mpsdef.h"
38: #include "transact.h"
39:
40: iftab *iftab_head;
41:
42: iftab *iftab_insert(short action, char *key, char *data, int tlevel)
43: {
44: iftab *t;
45:
46: for (t = iftab_head; t != NULL; t = t->next) {
47:
48: if (stcmp (t->key, key) == 0) {
49:
50: /* the key already exists. this is now an update. */
51: free (t->data);
52:
53: t->data = malloc (stlen (data) + 1);
54: NULLPTRCHK(t->data,"iftab_insert");
55:
56: stcpy (t->data, data);
57: t->killed = FALSE;
58:
59: return t;
60: }
61:
62: }
63:
64: /* key did not exist. this is now a true insert. */
65:
66: t = (iftab *) malloc (sizeof (iftab));
67: NULLPTRCHK(t,"iftab_insert");
68:
69: t->key = malloc (stlen (key) + 1);
70: NULLPTRCHK(t->key,"iftab_insert");
71:
72: t->data = malloc (stlen (data) + 1);
73: NULLPTRCHK(t->data,"iftab_insert");
74:
75: stcpy (t->key, key);
76: stcpy (t->data, data);
77:
78: t->killed = FALSE;
79: t->tlevel = tlevel;
80: t->action = action;
81:
82: t->next = iftab_head;
83: iftab_head = t;
84:
85: return t;
86: }
87:
88: iftab *iftab_retrieve(char *key, char *data)
89: {
90: iftab *t;
91:
92: for (t = iftab_head; t != NULL; t = t->next) {
93: if (stcmp (t->key, key) == 0) {
94:
95: data = (char *) malloc (stlen (t->data) + 1);
96: NULLPTRCHK(data,"iftab_retrieve");
97:
98: stcpy (data, t->data);
99:
100: return t;
101: }
102: }
103:
104: return (iftab *) NULL;
105: }
106:
107: void iftab_delete(char *key)
108: {
109: iftab *t = iftab_head;
110: iftab *p = NULL;
111:
112:
113: if ((t != (iftab *) NULL) && (stcmp (t->key, key) == 0)) {
114: iftab_head = t->next;
115:
116: free (t->key);
117: free (t->data);
118: free (t);
119: return;
120: }
121:
122: while ((t != NULL) && (stcmp (t->key, key) != 0)) {
123: p = t;
124: t = t->next;
125: }
126:
127: if (t == NULL) return;
128:
129: p->next = t->next;
130: free (t->key);
131: free (t->data);
132: free (t);
133:
134: return;
135: }
136:
137: iftab *iftab_kill(char *key)
138: {
139: iftab *t;
140:
141: for(t = iftab_head; t != NULL; t = t->next) {
142: if (stcmp (t->key, key) == 0) {
143: t->killed = TRUE;
144:
145: return t;
146: }
147: }
148:
149: t = iftab_insert (kill_sym, key, "\201", tp_level);
150: t->killed = TRUE;
151:
152: return t;
153: }
154:
155: void iftab_pop_tlevel(int tlevel)
156: {
157: iftab *t;
158:
159: for (t = iftab_head; t != NULL; t = t->next) {
160: if (t->tlevel == tlevel) iftab_delete (t->key);
161: }
162: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>