send-async.c 8.92 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: send-async.c,v 0.23 1998/08/07 23:14:07 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1993, 1994, 1995, 1996  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
26
27
28
29
30
/*
 * send-async.c -- Send messages about events to all connected clients.
 *
 * Written by Per Cederqvist 1990-07-22--23
 */

31
static const char *
32
rcsid = "$Id: send-async.c,v 0.23 1998/08/07 23:14:07 ceder Exp $";
33
34
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
35

Per Cederqvist's avatar
Per Cederqvist committed
36
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
37
#include <setjmp.h>
38
39
40
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
41
42
#include <time.h>
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
43
44

#include "misc-types.h"
45
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
46
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
#include "com.h"
48
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
#include "connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
50
#include "internal-connections.h"
51
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
52
53
#include "send-async.h"
#include "prot-a-send-async.h"
Per Cederqvist's avatar
Per Cederqvist committed
54
#include "lyskomd.h"
Per Cederqvist's avatar
Per Cederqvist committed
55
#include "log.h"
56
#include "param.h"
57
#include "ldifftime.h"
58
#include "manipulate.h"
59
#include "kom-errno.h"
Per Cederqvist's avatar
Per Cederqvist committed
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
void
async_new_text_old(struct connection *cptr,
                   Text_no    	  text_no, 
                   Text_stat         *text_s)
{
    if (!param.send_async_messages)
	return;

    switch(cptr->protocol)
    {
    case 0:
	break;
    case 'A':
	if (cptr->username_valid == TRUE)
75
	    prot_a_async_new_text_old(cptr, text_no, text_s);
76
77
78
79
80
81
82
83
	break;
    default:
	restart_kom("async_new_text(): bad protocol.\n");
	break;
    }
}

    
Per Cederqvist's avatar
Per Cederqvist committed
84
void
85
async_new_text(struct connection *cptr,
86
87
               Text_no    	  text_no, 
               Text_stat         *text_s)
Per Cederqvist's avatar
Per Cederqvist committed
88
{
89
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
90
91
	return;

92
    switch(cptr->protocol)
Per Cederqvist's avatar
Per Cederqvist committed
93
    {
94
95
96
    case 0:
	break;
    case 'A':
97
98
	if (cptr->username_valid == TRUE)
	    prot_a_async_new_text(cptr, text_no, text_s);
99
100
101
102
	break;
    default:
	restart_kom("async_new_text(): bad protocol.\n");
	break;
Per Cederqvist's avatar
Per Cederqvist committed
103
104
105
106
107
108
109
110
111
112
113
114
    }
}

    
    
	    
void
async_i_am_on(Who_info info)
{
    Connection *cptr;
    Session_no i = 0;

115
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
116
117
118
119
120
121
122
123
124
125
126
	return;

    while ( (i = traverse_connections(i)) != 0 )
    {
	cptr = get_conn_by_number(i);

	switch(cptr->protocol)
	{
	case 0:			/* Not yet logged on. */
	    break;
	case 'A':
127
128
	    if (cptr->username_valid == TRUE)
		prot_a_async_i_am_on(cptr, info);
Per Cederqvist's avatar
Per Cederqvist committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	    break;
	default:
	    restart_kom("async_i_am_on(): bad protocol.\n");
	    break;
	}
    }
}

void
async_logout(Pers_no pers_no, 
	     Session_no session_no)
{
    Connection *cptr;
    Session_no i = 0;

144
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	return;

    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_logout(): cptr == NULL\n");
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
162
163
	    if (cptr->username_valid == TRUE)
		prot_a_async_logout(cptr, pers_no, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	    break;
	default:
	    restart_kom("async_logout(): bad protocol.\n");
	    break;
	}
    }
}



void
async_new_name(Conf_no 	     conf_no,
	       const String  old_name,
	       const String  new_name)
{
    Connection *cptr;
    Session_no i = 0;

182
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	return;

    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_new_name(): cptr == NULL\n");
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
200
201
202
203
	    /* Check that cptr has enough privileges to know
	       anything about the conference. */
            if (cptr->username_valid == TRUE &&
		fast_access_perm(conf_no,
204
205
206
207
208
                                 cptr->pers_no,
                                 cptr->person) > none)
            {
                prot_a_async_new_name(cptr, conf_no, old_name, new_name);
            }
Per Cederqvist's avatar
Per Cederqvist committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	    break;
		
	default:
	    restart_kom("async_new_name(): bad protocol.\n");
	    break;
	}
    }
}




#if 0    
conf_deleted
conf_created
#endif

void
async_sync_db(void)
{
    Connection *cptr;
    Session_no i = 0;

232
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
	return;

    while ( (i = traverse_connections(i)) != 0 )
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_sync_db(): cptr == NULL\n");
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
250
251
	    if (cptr->username_valid == TRUE)
		prot_a_async_sync_db(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
252
253
254
255
256
257
258
259
260
261
262
263
264
	    break;
	default:
	    restart_kom("async_sync_db(): bad protocol.\n");
	    break;
	}
    }
}


extern void
async_forced_leave_conf (struct connection *cptr,
			 Conf_no 	   conf_no)
{
265
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
266
267
268
269
270
271
272
	return;

    switch(cptr->protocol)
    {
    case 0:
	break;
    case 'A':
273
274
	if (cptr->username_valid == TRUE)
	    prot_a_async_forced_leave_conf(cptr, conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
	break;
    default:
	restart_kom("async_forced_leave_conf(): bad protocol.\n");
	break;
    }
}

void
async_login(Pers_no	pers_no,
	    int		client_no)
{
    Connection *cptr;
    Session_no i = 0;

289
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
	return;

    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_login(): cptr == NULL\n");
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
307
308
	    if (cptr->username_valid == TRUE)
		prot_a_async_login(cptr, pers_no, client_no);
Per Cederqvist's avatar
Per Cederqvist committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
	    break;
		
	default:
	    restart_kom("async_login(): bad protocol.\n");
	    break;
	}
    }
}

void
async_rejected_connection(void)
{
    Connection *cptr;
    Session_no i = 0;
323
324
    static time_t last_time = 0;
    time_t curr_time;
Per Cederqvist's avatar
Per Cederqvist committed
325

326
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
327
328
	return;

329
330
331
332
333
334
    time(&curr_time);
    if (last_time != 0 && ldifftime(curr_time, last_time) < 60)
	 return;

    last_time = curr_time;
	
Per Cederqvist's avatar
Per Cederqvist committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_rejected_connections(): cptr == NULL\n");
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
350
351
	    if (cptr->username_valid == TRUE)
		prot_a_async_rejected_connection(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
	    break;
		
	default:
	    restart_kom("async_rejected_connection(): bad protocol.\n");
	    break;
	}
    }
}


/*
 * Returns failure if no message was sent.
 */
Success
async_send_message(Pers_no recipient,
		   Pers_no sender,
368
		   String  message,
369
                   Bool    force_message)
370
{
371
372
373
374
375
    return async_send_group_message(recipient,
                                    recipient,
                                    sender,
                                    message,
                                    force_message);
376
377
378
379
380
381
}

Success
async_send_group_message(Pers_no recipient,
			 Conf_no group_recipient,
			 Pers_no sender,
382
			 String  message,
383
                         Bool    force_message)
Per Cederqvist's avatar
Per Cederqvist committed
384
385
386
387
{
    Connection *cptr;
    Session_no i = 0;
    Success retval = FAILURE;
388
    Bool tmp = FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
389

390
391
    kom_errno = KOM_MESSAGE_NOT_SENT;
    
392
    if (!param.send_async_messages)
393
394
395
    {
        err_stat = 0;
        kom_errno = KOM_FEATURE_DISABLED;
Per Cederqvist's avatar
Per Cederqvist committed
396
	return FAILURE;
397
    }
Per Cederqvist's avatar
Per Cederqvist committed
398
399
400
401
402
403
404
405

    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
	    log("async_send_message(): cptr == NULL\n");
406
407
            err_stat = 0;
            kom_errno = KOM_INTERNAL_ERROR;
Per Cederqvist's avatar
Per Cederqvist committed
408
409
410
411
412
413
414
415
	    return FAILURE;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
416
417
418
	    if ((recipient == 0 ||
		 (recipient == cptr->pers_no && recipient != 0 ))
		&& cptr->username_valid == TRUE)
Per Cederqvist's avatar
Per Cederqvist committed
419
	    {
420
421
422
                if (force_message)
                {
                    tmp = cptr->want_async[ay_send_message];
423
                    cptr->want_async[ay_send_message] = TRUE;
424
                }
425
426
		prot_a_async_send_message(cptr, group_recipient,
					  sender, message);
427
428
                if (force_message)
                    cptr->want_async[ay_send_message] = tmp;
Per Cederqvist's avatar
Per Cederqvist committed
429
430
431
432
433
434
435
436
437
438
439
440
		retval = OK;
	    }
	    break;
		
	default:
	    restart_kom("async_send_message(): bad protocol.\n");
	    break;
	}
    }
    
    return retval;
}
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463


void
async_deleted_text(struct connection *cptr,
                   Text_no    	  text_no, 
                   Text_stat         *text_s)
{
    if (!param.send_async_messages)
	return;

    switch(cptr->protocol)
    {
    case 0:
	break;
    case 'A':
	if (cptr->username_valid == TRUE)
	    prot_a_async_deleted_text(cptr, text_no, text_s);
	break;
    default:
	restart_kom("async_deleted_text(): bad protocol.\n");
	break;
    }
}