Commit 15a05389 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Initial RCS checkin.

parent 6e33ec06
/*
* send-async.c -- Send messages about events to all connected clients.
*
* Written by Per Cederqvist 1990-07-22--23
*/
#include <stdio.h>
#include "lyskomd.h"
#include <kom-types.h>
#include <services.h>
#include "async.h"
#include "manipulate.h"
#include "com.h"
#include "connections.h"
#include "send-async.h"
#include "prot-a-send-async.h"
#include "prot-a-output.h"
#include "log.h"
#include "internal-connections.h"
extern Bool send_async_messages;
/*
* Check if person is a member in any of the recipients or cc_recipients
* of text_s
*/
static Bool
is_member_in_recpt(Person * person,
Text_stat * text_s)
{
int i;
for ( i = 0; i < text_s->no_of_misc; i++ )
{
switch(text_s->misc_items[ i ].type)
{
case recpt:
if ( locate_membership(text_s->misc_items[ i ].datum.recipient,
person) != NULL )
{
return TRUE;
}
break;
case cc_recpt:
if ( locate_membership(text_s->misc_items[ i ].datum.cc_recipient,
person) != NULL )
{
return TRUE;
}
break;
case comm_to:
case comm_in:
case footn_to:
case footn_in:
case loc_no:
case rec_time:
case sent_by:
case sent_at:
break;
#ifndef COMPILE_CHECKS
default:
log(__FILE__ ": is_member_in_recpt(): bad misc_item.\n");
break;
#endif
}
}
return FALSE;
}
void
async_new_text(Text_no text_no,
Text_stat *text_s)
{
Connection *cptr;
Session_no i = 0;
if (!send_async_messages)
return;
while ( (i = traverse_connections(i)) != 0 )
{
cptr = get_conn_by_number(i);
if ( cptr->person != NULL
&& is_member_in_recpt( cptr->person, text_s ) )
{
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 (!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_i_am_off(Pers_no pers_no)
{
Connection *cptr;
Session_no i = 0;
if (!send_async_messages)
return;
while ( (i = traverse_connections(i)) != 0 )
{
cptr = get_conn_by_number(i);
if ( cptr == NULL )
{
log("async_i_am_off(): cptr == NULL\n");
return;
}
switch(cptr->protocol)
{
case 0:
break;
case 'A':
prot_a_async_i_am_off(cptr, pers_no);
break;
default:
restart_kom("async_i_am_off(): bad protocol.\n");
break;
}
}
}
void
async_logout(Pers_no pers_no,
Session_no session_no)
{
Connection *cptr;
Session_no i = 0;
if (!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 (!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':
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 (!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 (!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 (!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_broadcast(Pers_no pers_no,
String message)
{
Connection *cptr;
Session_no i = 0;
if (!send_async_messages)
return;
while ( (i = traverse_connections(i)) != 0)
{
cptr = get_conn_by_number(i);
if ( cptr == NULL )
{
log("async_broadcast(): cptr == NULL\n");
return;
}
switch(cptr->protocol)
{
case 0:
break;
case 'A':
prot_a_async_broadcast(cptr, pers_no, message);
break;
default:
restart_kom("async_broadcast(): bad protocol.\n");
break;
}
}
}
void
async_rejected_connection(void)
{
Connection *cptr;
Session_no i = 0;
if (!send_async_messages)
return;
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)
{
Connection *cptr;
Session_no i = 0;
Success retval = FAILURE;
if (!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 ))
{
prot_a_async_send_message(cptr, recipient, sender, message);
retval = OK;
}
break;
default:
restart_kom("async_send_message(): bad protocol.\n");
break;
}
}
return retval;
}
extern void
async_new_text(Text_no text_no,
Text_stat *text_s);
extern void
async_i_am_on(Who_info info);
extern void
async_i_am_off(Pers_no person);
extern void
async_logout(Pers_no pers_no,
Session_no session_no);
extern void
async_new_name(Conf_no conf_no,
const String old_name,
const String new_name);
extern void
async_sync_db(void);
extern void
async_forced_leave_conf (Connection *cptr,
Conf_no conf_no);
extern void
async_login(Pers_no pers_no,
int client_no);
extern void
async_broadcast(Pers_no pers_no,
String message);
extern void
async_rejected_connection(void);
extern Success
async_send_message(Pers_no recipient,
Pers_no sender,
String message);
/*
* session.c
*
* Session control and miscellaneous.
*/
#include <time.h>
#include <stdlib.h>
#include "lyskomd.h"
#include <kom-types.h>
#include <services.h>
#include "manipulate.h"
#include "cache.h"
#include "com.h"
#include "connections.h"
#include "send-async.h"
#include "smalloc.h"
#include "log.h"
#include <kom-errno.h>
#include "config.h"
#include "internal-connections.h"
/*
* This function is called whenever a person leaves a conf,
* i e when he pepsi():s or logout():s.
*/
extern void
leave_conf(void)
{
Membership * mship;
if (active_connection->cwc != 0 )
{
if ((mship = locate_membership( active_connection->cwc, ACT_P ))
!= NULL )
{
time(&mship->last_time_read);
mark_person_as_changed (active_connection->pers_no);
}
else
{
log("ERROR: leave_conf(): Can't find membership of cwc.\n");
}
cached_unlock_conf( active_connection->cwc );
active_connection->cwc = 0;
}
}
/*
* Log in as user pers_no. If ACTPERS is a supervisor of pers_no the login
* will succeed regardless of the passwd. An logout() will automatically
* be performed if ACTPERS is logged in.
*/
extern Success
login (Pers_no pers_no,
const String passwd)
{
Person *pers_p;
GET_P_STAT(pers_p, pers_no, FAILURE);
#if 0
if ( !logins_allowed && !pers_p->privileges.wheel)
{
kom_errno = KOM_LOGIN_DISALLOWED;
return FAILURE;
}
#endif
if ( !is_supervisor(pers_no, NULL)
&& chk_passwd(pers_p->pwd, passwd) == FAILURE )
{
kom_errno = KOM_PWD;
return FAILURE;
}
logout(); /*+++ How many tries are allowed before disconnection? */
ACTPERS = pers_no;
ACT_P = pers_p;
cached_lock_person(pers_no);
pers_p->last_login = time(&active_connection->session_start);
++pers_p->sessions;
s_strcpy(&pers_p->username, active_connection->username);
mark_person_as_changed( pers_no );
async_login(ACTPERS, active_connection->session_no);
return OK;
}
/*
* Log out. Does not disconnect the client. The person is also automatically
* logged out if the connection is closed. Takes no action if noone is logged
* in on this line. Never fails.
*/
extern Success
logout( void )
{
if ( ACTPERS != 0 ) /* Is he logged in? Then log him out. */
{
async_i_am_off( ACTPERS );
async_logout( ACTPERS, active_connection->session_no );
leave_conf();
ACT_P->total_time_present +=
difftime(time(&ACT_P->last_login),
active_connection->session_start);
cached_unlock_person( ACTPERS );
mark_person_as_changed( ACTPERS );
}
s_clear(&active_connection -> what_am_i_doing);
active_connection->person = NULL;
active_connection->cwc = 0;
active_connection->pers_no = 0;
active_connection->ena_level = 0;
return OK;
}
/*
* Change Conference.
*
* You are not allowed to change to a conference unless you are a
* member in the conference.