Select Git revision
send-async.c
send-async.c 7.53 KiB
/*
* $Id: send-async.c,v 0.17 1996/07/28 12:46:31 ceder Exp $
* Copyright (C) 1991, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* 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.
*/
/*
* send-async.c -- Send messages about events to all connected clients.
*
* Written by Per Cederqvist 1990-07-22--23
*/
static char *rcsid = "$Id: send-async.c,v 0.17 1996/07/28 12:46:31 ceder Exp $";
#include "rcs.h"
USE(rcsid);
#include <stdio.h>
#include <setjmp.h>
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <time.h>
#include <sys/types.h>
#include "misc-types.h"
#include "s-string.h"
#include "kom-types.h"
#include "com.h"
#include "async.h"
#include "connections.h"
#include "internal-connections.h"
#include "async.h"
#include "send-async.h"
#include "prot-a-send-async.h"
#include "lyskomd.h"
#include "log.h"
#include "param.h"
#include "ldifftime.h"
#include "manipulate.h"
void
async_new_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':
prot_a_async_new_text(cptr, text_no, text_s);
break;
default:
restart_kom("async_new_text(): bad protocol.\n");
break;
}
}
void
async_i_am_on(Who_info info)
{
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: /* Not yet logged on. */
break;
case 'A':
prot_a_async_i_am_on(cptr, info);
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;
if (!param.send_async_messages)
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':
prot_a_async_logout(cptr, pers_no, session_no);
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;
if (!param.send_async_messages)
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':
/* Should check that cptr has enough privileges to know
anything about the conference. +++ */
if (fast_access_perm(conf_no,
cptr->pers_no,
cptr->person) > none)
{
prot_a_async_new_name(cptr, conf_no, old_name, new_name);
}
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;
if (!param.send_async_messages)
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':
prot_a_async_sync_db(cptr);
break;
default:
restart_kom("async_sync_db(): bad protocol.\n");
break;
}
}
}
extern void
async_forced_leave_conf (struct connection *cptr,
Conf_no conf_no)
{
if (!param.send_async_messages)
return;
switch(cptr->protocol)
{
case 0:
break;
case 'A':
prot_a_async_forced_leave_conf(cptr, conf_no);
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;
if (!param.send_async_messages)
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':
prot_a_async_login(cptr, pers_no, client_no);
break;
default:
restart_kom("async_login(): bad protocol.\n");
break;
}
}
}
void
async_rejected_connection(void)
{
Connection *cptr;
Session_no i = 0;
static time_t last_time = 0;
time_t curr_time;
if (!param.send_async_messages)
return;
time(&curr_time);
if (last_time != 0 && ldifftime(curr_time, last_time) < 60)
return;
last_time = curr_time;
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':
prot_a_async_rejected_connection(cptr);
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,
String message,
char force_message)
{
return async_send_group_message(recipient,
recipient,
sender,
message,
force_message);
}
Success
async_send_group_message(Pers_no recipient,
Conf_no group_recipient,
Pers_no sender,
String message,
char force_message)
{
Connection *cptr;
Session_no i = 0;
Success retval = FAILURE;
Bool tmp = FALSE;
if (!param.send_async_messages)
return FAILURE;
while ( (i = traverse_connections(i)) != 0)
{
cptr = get_conn_by_number(i);
if ( cptr == NULL )
{
log("async_send_message(): cptr == NULL\n");
return FAILURE;
}
switch(cptr->protocol)
{
case 0:
break;
case 'A':
if ( recipient == 0 ||
(recipient == cptr->pers_no && recipient != 0 ))
{
if (force_message)
{
tmp = cptr->want_async[ay_send_message];
cptr->want_async[ay_send_message] = TRUE;
}
prot_a_async_send_message(cptr, group_recipient,
sender, message);
if (force_message)
cptr->want_async[ay_send_message] = tmp;
retval = OK;
}
break;
default:
restart_kom("async_send_message(): bad protocol.\n");
break;
}
}
return retval;
}