Deleted Added
full compact
table.c (50476) table.c (90261)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/4/93";
37#endif
38static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/4/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/libexec/talkd/table.c 50476 1999-08-28 00:22:10Z peter $";
39 "$FreeBSD: head/libexec/talkd/table.c 90261 2002-02-05 21:06:56Z imp $";
40#endif /* not lint */
41
42/*
43 * Routines to handle insertion, deletion, etc on the table
44 * of requests kept by the daemon. Nothing fancy here, linear
45 * search on a double-linked list. A time is kept with each
46 * entry so that overly old invitations can be eliminated.
47 *

--- 4 unchanged lines hidden (view full) ---

52#include <sys/socket.h>
53#include <protocols/talkd.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <syslog.h>
58#include <unistd.h>
59
40#endif /* not lint */
41
42/*
43 * Routines to handle insertion, deletion, etc on the table
44 * of requests kept by the daemon. Nothing fancy here, linear
45 * search on a double-linked list. A time is kept with each
46 * entry so that overly old invitations can be eliminated.
47 *

--- 4 unchanged lines hidden (view full) ---

52#include <sys/socket.h>
53#include <protocols/talkd.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <syslog.h>
58#include <unistd.h>
59
60#include "extern.h"
61
60#define MAX_ID 16000 /* << 2^15 so I don't have sign troubles */
61
62#define NIL ((TABLE_ENTRY *)0)
63
64extern int debug;
65struct timeval tp;
66struct timezone txp;
67
68typedef struct table_entry TABLE_ENTRY;
69
70struct table_entry {
71 CTL_MSG request;
72 long time;
73 TABLE_ENTRY *next;
74 TABLE_ENTRY *last;
75};
76
62#define MAX_ID 16000 /* << 2^15 so I don't have sign troubles */
63
64#define NIL ((TABLE_ENTRY *)0)
65
66extern int debug;
67struct timeval tp;
68struct timezone txp;
69
70typedef struct table_entry TABLE_ENTRY;
71
72struct table_entry {
73 CTL_MSG request;
74 long time;
75 TABLE_ENTRY *next;
76 TABLE_ENTRY *last;
77};
78
79static void delete(TABLE_ENTRY *);
80
77TABLE_ENTRY *table = NIL;
78
81TABLE_ENTRY *table = NIL;
82
79void delete __P((TABLE_ENTRY *));
80CTL_MSG *find_request();
81CTL_MSG *find_match();
82int new_id __P((void));
83void print_request __P((char *, CTL_MSG *));
84
85/*
86 * Look in the table for an invitation that matches the current
87 * request looking for an invitation
88 */
89CTL_MSG *
83/*
84 * Look in the table for an invitation that matches the current
85 * request looking for an invitation
86 */
87CTL_MSG *
90find_match(request)
91 register CTL_MSG *request;
88find_match(CTL_MSG *request)
92{
89{
93 register TABLE_ENTRY *ptr;
90 TABLE_ENTRY *ptr;
94 time_t current_time;
95
96 gettimeofday(&tp, &txp);
97 current_time = tp.tv_sec;
98 if (debug)
99 print_request("find_match", request);
100 for (ptr = table; ptr != NIL; ptr = ptr->next) {
101 if ((ptr->time - current_time) > MAX_LIFE) {

--- 14 unchanged lines hidden (view full) ---

116 return ((CTL_MSG *)0);
117}
118
119/*
120 * Look for an identical request, as opposed to a complimentary
121 * one as find_match does
122 */
123CTL_MSG *
91 time_t current_time;
92
93 gettimeofday(&tp, &txp);
94 current_time = tp.tv_sec;
95 if (debug)
96 print_request("find_match", request);
97 for (ptr = table; ptr != NIL; ptr = ptr->next) {
98 if ((ptr->time - current_time) > MAX_LIFE) {

--- 14 unchanged lines hidden (view full) ---

113 return ((CTL_MSG *)0);
114}
115
116/*
117 * Look for an identical request, as opposed to a complimentary
118 * one as find_match does
119 */
120CTL_MSG *
124find_request(request)
125 register CTL_MSG *request;
121find_request(CTL_MSG *request)
126{
122{
127 register TABLE_ENTRY *ptr;
123 TABLE_ENTRY *ptr;
128 time_t current_time;
129
130 gettimeofday(&tp, &txp);
131 current_time = tp.tv_sec;
132 /*
133 * See if this is a repeated message, and check for
134 * out of date entries in the table while we are it.
135 */

--- 18 unchanged lines hidden (view full) ---

154 ptr->time = current_time;
155 return (&ptr->request);
156 }
157 }
158 return ((CTL_MSG *)0);
159}
160
161void
124 time_t current_time;
125
126 gettimeofday(&tp, &txp);
127 current_time = tp.tv_sec;
128 /*
129 * See if this is a repeated message, and check for
130 * out of date entries in the table while we are it.
131 */

--- 18 unchanged lines hidden (view full) ---

150 ptr->time = current_time;
151 return (&ptr->request);
152 }
153 }
154 return ((CTL_MSG *)0);
155}
156
157void
162insert_table(request, response)
163 CTL_MSG *request;
164 CTL_RESPONSE *response;
158insert_table(CTL_MSG *request, CTL_RESPONSE *response)
165{
159{
166 register TABLE_ENTRY *ptr;
160 TABLE_ENTRY *ptr;
167 time_t current_time;
168
169 gettimeofday(&tp, &txp);
170 current_time = tp.tv_sec;
171 request->id_num = new_id();
172 response->id_num = htonl(request->id_num);
173 /* insert a new entry into the top of the list */
174 ptr = (TABLE_ENTRY *)malloc(sizeof(TABLE_ENTRY));

--- 9 unchanged lines hidden (view full) ---

184 ptr->last = NIL;
185 table = ptr;
186}
187
188/*
189 * Generate a unique non-zero sequence number
190 */
191int
161 time_t current_time;
162
163 gettimeofday(&tp, &txp);
164 current_time = tp.tv_sec;
165 request->id_num = new_id();
166 response->id_num = htonl(request->id_num);
167 /* insert a new entry into the top of the list */
168 ptr = (TABLE_ENTRY *)malloc(sizeof(TABLE_ENTRY));

--- 9 unchanged lines hidden (view full) ---

178 ptr->last = NIL;
179 table = ptr;
180}
181
182/*
183 * Generate a unique non-zero sequence number
184 */
185int
192new_id()
186new_id(void)
193{
194 static int current_id = 0;
195
196 current_id = (current_id + 1) % MAX_ID;
197 /* 0 is reserved, helps to pick up bugs */
198 if (current_id == 0)
199 current_id = 1;
200 return (current_id);
201}
202
203/*
204 * Delete the invitation with id 'id_num'
205 */
206int
187{
188 static int current_id = 0;
189
190 current_id = (current_id + 1) % MAX_ID;
191 /* 0 is reserved, helps to pick up bugs */
192 if (current_id == 0)
193 current_id = 1;
194 return (current_id);
195}
196
197/*
198 * Delete the invitation with id 'id_num'
199 */
200int
207delete_invite(id_num)
208 int id_num;
201delete_invite(int id_num)
209{
202{
210 register TABLE_ENTRY *ptr;
203 TABLE_ENTRY *ptr;
211
212 ptr = table;
213 if (debug)
214 syslog(LOG_DEBUG, "delete_invite(%d)", id_num);
215 for (ptr = table; ptr != NIL; ptr = ptr->next) {
216 if (ptr->request.id_num == id_num)
217 break;
218 if (debug)

--- 4 unchanged lines hidden (view full) ---

223 return (SUCCESS);
224 }
225 return (NOT_HERE);
226}
227
228/*
229 * Classic delete from a double-linked list
230 */
204
205 ptr = table;
206 if (debug)
207 syslog(LOG_DEBUG, "delete_invite(%d)", id_num);
208 for (ptr = table; ptr != NIL; ptr = ptr->next) {
209 if (ptr->request.id_num == id_num)
210 break;
211 if (debug)

--- 4 unchanged lines hidden (view full) ---

216 return (SUCCESS);
217 }
218 return (NOT_HERE);
219}
220
221/*
222 * Classic delete from a double-linked list
223 */
231void
232delete(ptr)
233 register TABLE_ENTRY *ptr;
224static void
225delete(TABLE_ENTRY *ptr)
234{
235
236 if (debug)
237 print_request("delete", &ptr->request);
238 if (table == ptr)
239 table = ptr->next;
240 else if (ptr->last != NIL)
241 ptr->last->next = ptr->next;
242 if (ptr->next != NIL)
243 ptr->next->last = ptr->last;
244 free((char *)ptr);
245}
226{
227
228 if (debug)
229 print_request("delete", &ptr->request);
230 if (table == ptr)
231 table = ptr->next;
232 else if (ptr->last != NIL)
233 ptr->last->next = ptr->next;
234 if (ptr->next != NIL)
235 ptr->next->last = ptr->last;
236 free((char *)ptr);
237}