Commit 8b5a6dea authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(is_member_in): New static function.

(is_member_in_recpt): Use is_member_in to simplify code.
(is_member_in_recpt_of): New static function.
(is_member_in_linked_recpt): New static function.
(interested_party): New static function. This also considers if
	the potential message recipient is a member of a recipient of a
	text that is linked to the text, via a misc-info or a aux-item.
(send_async_sub_recipient): Use interested_party to determine if
	the asynchronous message should be sent.
(send_async_deleted_text): Ditto.
(send_async_new_text_old): Ditto.
(send_async_new_text): Ditto.
(send_async_add_recipient): Ditto.
(text_read_access): Added const qualifiers.
parent 6885b3fa
/*
* $Id: text.c,v 0.99 2003/01/07 07:53:14 ceder Exp $
* $Id: text.c,v 0.100 2003/01/13 10:05:29 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -86,6 +86,9 @@ filter_secret_info(Text_stat *result,
const Connection *viewer_conn,
Bool output_bcc);
static Bool
interested_party(const Connection *cptr,
const Text_stat *text_s);
/*
* Static functions
*/
......@@ -394,6 +397,21 @@ do_add_recipient(Text_no text,
return OK;
}
static Bool
is_member_in(const Person *person,
Conf_no conf_no,
Bool skip_passive)
{
Membership *mship;
if ((mship = locate_membership(conf_no, person)) != NULL)
{
if (!(mship->type.passive && skip_passive))
return TRUE;
}
return FALSE;
}
/*
......@@ -407,7 +425,6 @@ is_member_in_recpt(const Person *person,
Bool skip_passive)
{
int i;
Membership *mship;
for (i = 0; i < text_s->no_of_misc; i++)
{
......@@ -416,12 +433,9 @@ is_member_in_recpt(const Person *person,
case recpt:
case cc_recpt:
case bcc_recpt:
if ((mship = locate_membership(
text_s->misc_items[i].datum.recipient, person)) != NULL)
{
if (!(mship->type.passive && skip_passive))
return TRUE;
}
if (is_member_in(person, text_s->misc_items[i].datum.recipient,
skip_passive) == TRUE)
return TRUE;
break;
case comm_to:
......@@ -446,6 +460,122 @@ is_member_in_recpt(const Person *person,
return FALSE;
}
static Bool
is_member_in_recpt_of(const Person *person,
const Text_no text_no,
Bool skip_passive)
{
Text_stat *text_s;
GET_T_STAT(text_s, text_no, FALSE);
return is_member_in_recpt(person, text_s, skip_passive);
}
/*
* Check if person is a member in any of the recipients of a text that
* is linked to this text. If skip_passive is true, ignore passive
* memberships.
*/
static Bool
is_member_in_linked_recpt(const Person *person,
const Text_stat *text_s,
Bool skip_passive)
{
int i;
Text_no linked_nr;
String *data;
String copy;
String_size end;
for (i = 0; i < text_s->no_of_misc; i++)
{
switch(text_s->misc_items[i].type)
{
case comm_to:
case comm_in:
case footn_to:
case footn_in:
linked_nr = text_s->misc_items[i].datum.text_link;
if (is_member_in_recpt_of(person, linked_nr, skip_passive) == TRUE)
return TRUE;
break;
case recpt:
case cc_recpt:
case bcc_recpt:
case loc_no:
case rec_time:
case sent_by:
case sent_at:
break;
#ifndef COMPILE_CHECKS
default:
#endif
case unknown_info:
kom_log("is_member_in_linked_recpt(): bad misc_item.\n");
break;
}
}
for (i = 0; i < text_s->aux_item_list.length; i++)
{
data = &text_s->aux_item_list.items[i].data;
switch (text_s->aux_item_list.items[i].tag)
{
case aux_cross_reference:
/* Data is "T", optional space, a text number, a space, and
some junk we don't care about. */
if (s_strlen(*data) < 2 || data->string[0] != 'T')
continue;
copy = s_fsubstr(*data, 1, END_OF_STRING);
linked_nr = s_strtol(copy, &end);
if (end == -1)
continue;
if (end >= s_strlen(copy))
continue;
if (copy.string[end] != ' ')
continue;
if (is_member_in_recpt_of(person, linked_nr, skip_passive) == TRUE)
return TRUE;
break;
case aux_mx_mime_belongs_to:
case aux_mx_mime_part_in:
/* Data is a single text number. */
linked_nr = s_strtol(*data, &end);
if (end == -1)
continue;
if (end != s_strlen(copy))
continue;
if (is_member_in_recpt_of(person, linked_nr, skip_passive) == TRUE)
return TRUE;
case aux_faq_for_conf:
/* Data is a conference number. 0 means the entire system. */
linked_nr = s_strtol(*data, &end);
if (end == -1)
continue;
if (end != s_strlen(copy))
continue;
if (linked_nr == 0
|| is_member_in(person, linked_nr, skip_passive) == TRUE)
return TRUE;
default:
break;
}
}
return FALSE;
}
/*
* Return number of lines in a text
......@@ -539,17 +669,14 @@ send_async_sub_recipient(Text_no text_no,
while ((i = traverse_connections(i)) != 0)
{
cptr = get_conn_by_number(i);
if (cptr->person != NULL
&& is_member_in_recpt(cptr->person, text_s, TRUE) == TRUE)
if (interested_party(cptr, text_s)
&& text_read_access(cptr, text_no, text_s))
{
Text_stat copy;
filter_secret_info(&copy, text_s, cptr, TRUE);
if (find_recipient(conf_no, &copy) != -1
&& is_member_in_recpt(cptr->person, &copy, TRUE) == TRUE)
{
if (find_recipient(conf_no, &copy) != -1)
async_sub_recipient(cptr, text_no, conf_no, type);
}
}
}
}
......@@ -1130,9 +1257,25 @@ filter_secret_info(Text_stat *result,
}
}
static Bool
interested_party(const Connection *cptr,
const Text_stat *text_s)
{
if (cptr->person == NULL)
return FALSE;
if (is_member_in_recpt(cptr->person, text_s, TRUE) == TRUE)
return TRUE;
if (is_member_in_linked_recpt(cptr->person, text_s, TRUE) == TRUE)
return TRUE;
return FALSE;
}
/*
* Send message to all recipients that a text has been deleted
* Send message to all interested parties that a text has been deleted.
*/
static void
......@@ -1148,10 +1291,10 @@ send_async_deleted_text(Text_no text_no,
while ((i = traverse_connections(i)) != 0)
{
cptr = get_conn_by_number(i);
filter_secret_info(&filtered, text_s, cptr, TRUE);
if (cptr->person != NULL
&& is_member_in_recpt(cptr->person, &filtered, TRUE) == TRUE)
{
if (interested_party(cptr, text_s)
&& text_read_access(cptr, text_no, text_s))
{
filter_secret_info(&filtered, text_s, cptr, TRUE);
async_deleted_text(cptr, text_no, &filtered);
}
}
......@@ -1217,9 +1360,9 @@ send_async_deleted_text(Text_no text_no,
*/
Bool
text_read_access(Connection *conn,
Text_no text_no,
Text_stat * text_stat)
text_read_access(const Connection *conn,
Text_no text_no,
const Text_stat *text_stat)
{
return person_text_read_access(text_no,
text_stat,
......@@ -1246,9 +1389,9 @@ text_read_access(Connection *conn,
Bool
person_text_read_access(Text_no text_no,
Text_stat * text_stat,
const Text_stat * text_stat,
Pers_no pers_no,
Person * pers_stat)
const Person * pers_stat)
{
int i = 0;
Misc_info *misc = NULL;
......@@ -1932,11 +2075,10 @@ send_async_new_text_old(Text_no text_no,
* since it is allocated with tmp_alloc we do not need to free
* the memory now.
*/
filter_secret_info(&filtered, text_s, cptr, FALSE);
if (cptr->person != NULL
&& is_member_in_recpt(cptr->person, &filtered, TRUE) == TRUE)
if (interested_party(cptr, text_s)
&& text_read_access(cptr, text_no, text_s))
{
filter_secret_info(&filtered, text_s, cptr, FALSE);
async_new_text_old(cptr, text_no, &filtered);
}
}
......@@ -1961,11 +2103,10 @@ send_async_new_text(Text_no text_no,
* since it is allocated with tmp_alloc we do not need to free
* the memory now.
*/
filter_secret_info(&filtered, text_s, cptr, TRUE);
if (cptr->person != NULL
&& is_member_in_recpt(cptr->person, &filtered, TRUE) == TRUE)
if (interested_party(cptr, text_s)
&& text_read_access(cptr, text_no, text_s))
{
filter_secret_info(&filtered, text_s, cptr, TRUE);
async_new_text(cptr, text_no, &filtered);
}
}
......@@ -2484,17 +2625,14 @@ send_async_add_recipient(Text_no text_no,
while ((i = traverse_connections(i)) != 0)
{
cptr = get_conn_by_number(i);
if (cptr->person != NULL
&& is_member_in_recpt(cptr->person, text_s, TRUE) == TRUE)
if (interested_party(cptr, text_s)
&& text_read_access(cptr, text_no, text_s))
{
Text_stat copy;
filter_secret_info(&copy, text_s, cptr, TRUE);
if (find_recipient(conf_no, &copy) != -1
&& is_member_in_recpt(cptr->person, &copy, TRUE) == TRUE)
{
if (find_recipient(conf_no, &copy) != -1)
async_new_recipient(cptr, text_no, conf_no, type);
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment