send-async.c 10.6 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: send-async.c,v 0.25 1999/01/18 11:55:32 byers 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
 */

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.25 1999/01/18 11:55:32 byers 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"
Per Cederqvist's avatar
Per Cederqvist committed
65

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

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

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

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

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

149
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
	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':
167
168
	    if (cptr->username_valid == TRUE)
		prot_a_async_logout(cptr, pers_no, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	    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;

187
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
	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':
205
206
207
	    /* Check that cptr has enough privileges to know
	       anything about the conference. */
            if (cptr->username_valid == TRUE &&
208
209
210
211
212
		(fast_access_perm(conf_no,
                                  cptr->pers_no,
                                  cptr->person) > none ||
                 ENA_C(cptr, admin, 2) ||
                 ENA_C(cptr, wheel, 8)))
213
214
215
            {
                prot_a_async_new_name(cptr, conf_no, old_name, new_name);
            }
Per Cederqvist's avatar
Per Cederqvist committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
	    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;

239
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	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':
257
258
	    if (cptr->username_valid == TRUE)
		prot_a_async_sync_db(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
259
260
261
262
263
264
265
266
267
268
269
270
271
	    break;
	default:
	    restart_kom("async_sync_db(): bad protocol.\n");
	    break;
	}
    }
}


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

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

296
    if (!param.send_async_messages)
Per Cederqvist's avatar
Per Cederqvist committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
	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':
314
315
	    if (cptr->username_valid == TRUE)
		prot_a_async_login(cptr, pers_no, client_no);
Per Cederqvist's avatar
Per Cederqvist committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
	    break;
		
	default:
	    restart_kom("async_login(): bad protocol.\n");
	    break;
	}
    }
}

void
async_rejected_connection(void)
{
    Connection *cptr;
    Session_no i = 0;
330
331
    static time_t last_time = 0;
    time_t curr_time;
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
337
338
339
340
341
    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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
    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':
357
358
	    if (cptr->username_valid == TRUE)
		prot_a_async_rejected_connection(cptr);
Per Cederqvist's avatar
Per Cederqvist committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	    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,
375
		   String  message,
376
                   Bool    force_message)
377
{
378
379
380
381
382
    return async_send_group_message(recipient,
                                    recipient,
                                    sender,
                                    message,
                                    force_message);
383
384
385
386
387
388
}

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

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

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

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

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


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
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
541


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;
    }
}