send-async.c 11.2 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: send-async.c,v 0.29 1999/05/30 09:26:44 ceder Exp $
3
 * Copyright (C) 1991, 1993-1999  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
 */

David Byers's avatar
David Byers committed
31
32
33
34
35

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

36
static const char *
37
rcsid = "$Id: send-async.c,v 0.29 1999/05/30 09:26:44 ceder Exp $";
38
39
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
40

Per Cederqvist's avatar
Per Cederqvist committed
41
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
42
#include <setjmp.h>
43
44
45
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
46
47
#include <time.h>
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
48
49

#include "misc-types.h"
50
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
51
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
52
#include "com.h"
53
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
54
#include "connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
55
#include "internal-connections.h"
56
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
57
58
#include "send-async.h"
#include "prot-a-send-async.h"
Per Cederqvist's avatar
Per Cederqvist committed
59
#include "lyskomd.h"
Per Cederqvist's avatar
Per Cederqvist committed
60
#include "log.h"
61
#include "param.h"
62
#include "ldifftime.h"
63
#include "manipulate.h"
64
#include "kom-errno.h"
65
#include "server-time.h"
Per Cederqvist's avatar
Per Cederqvist committed
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
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)
81
	    prot_a_async_new_text_old(cptr, text_no, text_s);
82
83
84
85
86
87
88
89
	break;
    default:
	restart_kom("async_new_text(): bad protocol.\n");
	break;
    }
}

    
Per Cederqvist's avatar
Per Cederqvist committed
90
void
91
async_new_text(struct connection *cptr,
92
93
               Text_no    	  text_no, 
               Text_stat         *text_s)
Per Cederqvist's avatar
Per Cederqvist committed
94
{
95
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
96
97
	return;

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

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

121
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
122
123
124
125
126
127
128
129
130
131
132
	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':
133
134
	    if (cptr->username_valid == TRUE)
		prot_a_async_i_am_on(cptr, info);
Per Cederqvist's avatar
Per Cederqvist committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
	    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;

150
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
151
152
153
154
155
156
157
158
	return;

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

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
159
	    kom_log("async_logout(): cptr == NULL\n");
Per Cederqvist's avatar
Per Cederqvist committed
160
161
162
163
164
165
166
167
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
168
169
	    if (cptr->username_valid == TRUE)
		prot_a_async_logout(cptr, pers_no, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	    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;

188
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
189
190
191
192
193
194
195
196
	return;

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

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
197
	    kom_log("async_new_name(): cptr == NULL\n");
Per Cederqvist's avatar
Per Cederqvist committed
198
199
200
201
202
203
204
205
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
206
207
208
	    /* Check that cptr has enough privileges to know
	       anything about the conference. */
            if (cptr->username_valid == TRUE &&
209
210
211
212
213
		(fast_access_perm(conf_no,
                                  cptr->pers_no,
                                  cptr->person) > none ||
                 ENA_C(cptr, admin, 2) ||
                 ENA_C(cptr, wheel, 8)))
214
215
216
            {
                prot_a_async_new_name(cptr, conf_no, old_name, new_name);
            }
Per Cederqvist's avatar
Per Cederqvist committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
	    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;

240
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
241
242
243
244
245
246
247
248
	return;

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

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
249
	    kom_log("async_sync_db(): cptr == NULL\n");
Per Cederqvist's avatar
Per Cederqvist committed
250
251
252
253
254
255
256
257
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
258
259
	    if (cptr->username_valid == TRUE)
		prot_a_async_sync_db(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
260
261
262
263
264
265
266
267
268
269
270
271
272
	    break;
	default:
	    restart_kom("async_sync_db(): bad protocol.\n");
	    break;
	}
    }
}


extern void
async_forced_leave_conf (struct connection *cptr,
			 Conf_no 	   conf_no)
{
273
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
274
275
276
277
278
279
280
	return;

    switch(cptr->protocol)
    {
    case 0:
	break;
    case 'A':
281
282
	if (cptr->username_valid == TRUE)
	    prot_a_async_forced_leave_conf(cptr, conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	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;

297
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
298
299
300
301
302
303
304
305
	return;

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

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
306
	    kom_log("async_login(): cptr == NULL\n");
Per Cederqvist's avatar
Per Cederqvist committed
307
308
309
310
311
312
313
314
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
315
316
	    if (cptr->username_valid == TRUE)
		prot_a_async_login(cptr, pers_no, client_no);
Per Cederqvist's avatar
Per Cederqvist committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
	    break;
		
	default:
	    restart_kom("async_login(): bad protocol.\n");
	    break;
	}
    }
}

void
async_rejected_connection(void)
{
    Connection *cptr;
    Session_no i = 0;
331
    static time_t last_time = 0;
Per Cederqvist's avatar
Per Cederqvist committed
332

333
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
334
335
	return;

336
    if (last_time != 0 && ldifftime(current_time, last_time) < 60)
337
338
	 return;

339
    last_time = current_time;
340
	
Per Cederqvist's avatar
Per Cederqvist committed
341
342
343
344
345
346
    while ( (i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
347
	    kom_log("async_rejected_connections(): cptr == NULL\n");
Per Cederqvist's avatar
Per Cederqvist committed
348
349
350
351
352
353
354
355
	    return;
	}

	switch(cptr->protocol)
	{
	case 0:
	    break;
	case 'A':
356
357
	    if (cptr->username_valid == TRUE)
		prot_a_async_rejected_connection(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
	    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,
374
		   String  message,
375
                   Bool    force_message)
376
{
377
378
379
380
381
    return async_send_group_message(recipient,
                                    recipient,
                                    sender,
                                    message,
                                    force_message);
382
383
384
385
386
387
}

Success
async_send_group_message(Pers_no recipient,
			 Conf_no group_recipient,
			 Pers_no sender,
388
			 String  message,
389
                         Bool    force_message)
Per Cederqvist's avatar
Per Cederqvist committed
390
391
392
393
{
    Connection *cptr;
    Session_no i = 0;
    Success retval = FAILURE;
394
    Bool tmp = FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
395

396
397
    kom_errno = KOM_MESSAGE_NOT_SENT;
    
398
    if (!param.send_async_messages)
399
400
401
    {
        err_stat = 0;
        kom_errno = KOM_FEATURE_DISABLED;
Per Cederqvist's avatar
Per Cederqvist committed
402
	return FAILURE;
403
    }
Per Cederqvist's avatar
Per Cederqvist committed
404
405
406
407
408
409
410

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

	if ( cptr == NULL )
	{
David Byers's avatar
David Byers committed
411
	    kom_log("async_send_message(): cptr == NULL\n");
412
413
            err_stat = 0;
            kom_errno = KOM_INTERNAL_ERROR;
Per Cederqvist's avatar
Per Cederqvist committed
414
415
416
417
418
419
420
421
	    return FAILURE;
	}

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


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;
    }
}
David Byers's avatar
David Byers committed
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540


void
async_new_recipient(struct connection   *cptr,
                    Text_no              text_no,
                    Conf_no              conf_no,
                    Info_type            type)
{
    if (!param.send_async_messages)
        return;

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


void
async_sub_recipient(struct connection   *cptr,
                    Text_no              text_no,
                    Conf_no              conf_no,
                    Info_type            type)
{
    if (!param.send_async_messages)
        return;

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


void
async_new_membership(struct connection   *cptr,
                     Pers_no pers_no,
                     Conf_no conf_no)
{
    if (!param.send_async_messages)
        return;

    switch(cptr->protocol)
    {
    case 0:
        break;
    case 'A':
        if (cptr->username_valid == TRUE)
            prot_a_async_new_membership(cptr, pers_no, conf_no);
        break;
    default:
        restart_kom("async_new_membership(): bad protocol.\n");
        break;
    }
}
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

#ifdef DEBUG_CALLS
void
async_garb_ended(int no_deleted)
{
    Connection *cptr;
    Session_no i = 0;
     
    if (!param.send_async_messages)
	return;
     
    while ((i = traverse_connections(i)) != 0)
    {
	cptr = get_conn_by_number(i);
     
	switch(cptr->protocol)
	{
	case 0:
	    /* No protocol specified yet */
	    break;
	case 'A':
	    /* Check that connection is logged on.  */
	    if (cptr->username_valid == TRUE)
		prot_a_async_garb_ended(cptr, no_deleted);
	    break;
	default:
	    restart_kom("async_garb_ended(): bad protocol.\n");
	    break;
	}
    }
}

#endif