Commit 376050b1 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(copy_public_confs): New arguments: keep_read and max_ranges. All

	callers updated.
(adjust_read): Now has external linkage.  Changed return type from
	void to Bool; return true if the membership was modified.
(do_get_membership): New arguments: keep_ranges and max_ranges.
	Renamed the want_read_texts argument to want_read_ranges.
	All callers updated.
(get_membership): New function.
parent d877e3f0
/*
* $Id: membership.c,v 0.78 2002/11/12 17:41:58 ceder Exp $
* $Id: membership.c,v 0.79 2002/11/13 00:41:15 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -37,6 +37,7 @@
#define DEBUG_MARK_AS_READ
#include <assert.h>
#include <stdio.h>
#ifdef HAVE_STRING_H
# include <string.h>
......@@ -144,7 +145,9 @@ copy_public_confs (Connection * conn, /* The connection for which we copy */
Pers_no pers_no, /* The person being censored */
Person * censor_p, /* The censored Person-struct */
Person * orig_p, /* The uncensored Person-struct */
Bool want_read)
Bool keep_read,
Bool want_read,
unsigned long max_ranges)
{
int i; /* Number of mships lefte in ORIG_P */
Membership * censor_m; /* Pointer in CENSOR_P */
......@@ -169,7 +172,17 @@ copy_public_confs (Connection * conn, /* The connection for which we copy */
*censor_m = *orig_m;
if (!want_read)
{
if (keep_read)
censor_m->skip_read_texts = TRUE;
else
censor_m->read_ranges = NULL;
}
else
{
if (max_ranges > 0 && censor_m->no_of_read_ranges > max_ranges)
censor_m->no_of_read_ranges = max_ranges;
}
if (vis == mv_censor_unread)
{
......@@ -377,8 +390,10 @@ add_rec_time(Conference * conf_c,
* This is currently only used from mark_as_read(), but it would be
* good to have a background task that does this whenever a text has
* been deleted.
*
* Returns non-zero if any change was performed.
*/
static void
Bool
adjust_read(Membership *m,
const Conference *conf)
{
......@@ -388,6 +403,7 @@ adjust_read(Membership *m,
struct read_range *tail;
struct read_range *begin;
struct read_range *end;
Bool change = FALSE;
Local_text_no conf_max; /* Highest used local_text_no in conf */
Local_text_no conf_min; /* Lowest used local_text_no in conf */
......@@ -397,7 +413,7 @@ adjust_read(Membership *m,
/* If nothing is marked as read, there is nothing to adjust. */
if (m->no_of_read_ranges == 0)
return;
return change;
/* (conf_min <= x < conf_max) if x is an existing local_text_no */
conf_min = l2g_next_key(&conf->texts, 0);
......@@ -423,7 +439,7 @@ adjust_read(Membership *m,
(unsigned long)m->priority,
(unsigned long)ptr->first_read,
(unsigned long)ptr->last_read);
return;
return change;
}
if (ptr != begin && (ptr-1)->last_read >= ptr->first_read)
......@@ -436,7 +452,7 @@ adjust_read(Membership *m,
(unsigned long)(ptr-1)->last_read,
(unsigned long)ptr->first_read,
(unsigned long)ptr->last_read);
return;
return change;
}
}
#endif
......@@ -456,6 +472,7 @@ adjust_read(Membership *m,
&& (prev == NULL || prev->last_read + 1 < ptr->first_read)
&& l2g_lookup(&conf->texts, ptr->first_read - 1) == 0)
{
change = TRUE;
ptr->first_read--;
if (ptr->first_read < conf_min)
ptr->first_read = 1;
......@@ -470,7 +487,11 @@ adjust_read(Membership *m,
if (past_block == 0 || past_block > limit)
past_block = limit;
if (ptr->last_read != past_block - 1)
{
ptr->last_read = past_block - 1;
change = TRUE;
}
}
/* Join any ranges that became adjacent. */
......@@ -489,6 +510,7 @@ adjust_read(Membership *m,
m->read_ranges = srealloc(
m->read_ranges,
m->no_of_read_ranges * sizeof(m->read_ranges[0]));
change = TRUE;
}
#ifndef NDEFENSIVE_CHECKS
......@@ -507,7 +529,8 @@ adjust_read(Membership *m,
(unsigned long)ptr->first_read,
(unsigned long)ptr->last_read);
ptr->last_read = ptr->first_read;
return;
change = TRUE;
return change;
}
if (ptr != begin && ptr->first_read <= (ptr-1)->last_read)
......@@ -521,10 +544,12 @@ adjust_read(Membership *m,
sfree(m->read_ranges);
m->read_ranges = NULL;
m->no_of_read_ranges = 0;
return;
change = TRUE;
return change;
}
}
#endif
return change;
}
/*
......@@ -1441,12 +1466,13 @@ mark_as_read (Conf_no conference,
static Success
do_get_membership (Pers_no pers_no,
do_get_membership(Pers_no pers_no,
unsigned short first,
unsigned short no_of_confs,
Bool want_read_texts,
Membership_list *memberships
)
Bool keep_ranges,
Bool want_read_ranges,
unsigned long max_ranges,
Membership_list *memberships)
{
Person * p_orig;
Person temp_pers;
......@@ -1479,10 +1505,10 @@ do_get_membership (Pers_no pers_no,
if ( acc != unlimited )
{
copy_public_confs (active_connection, pers_no,
&temp_pers, p_orig,
want_read_texts);
&temp_pers, p_orig, keep_ranges,
want_read_ranges, max_ranges);
}
else if ( !want_read_texts )
else if (!want_read_ranges || max_ranges != 0)
{
/* Delete info about read texts. */
temp_pers.conferences.confs
......@@ -1494,10 +1520,26 @@ do_get_membership (Pers_no pers_no,
(temp_pers.conferences.no_of_confs
* sizeof(Membership) ));
for ( i = 0; i < temp_pers.conferences.no_of_confs; i++ )
if (!want_read_ranges)
{
for (i = 0; i < temp_pers.conferences.no_of_confs; i++)
if (keep_ranges)
temp_pers.conferences.confs[i].skip_read_texts = TRUE;
else
temp_pers.conferences.confs[i].read_ranges = NULL;
}
else
{
assert(max_ranges != 0);
for (i = 0; i < temp_pers.conferences.no_of_confs; i++)
if (temp_pers.conferences.confs[i].no_of_read_ranges
> max_ranges)
{
temp_pers.conferences.confs[i].no_of_read_ranges =
max_ranges;
}
}
}
*memberships = temp_pers.conferences;
......@@ -1535,7 +1577,9 @@ get_membership_old (Pers_no pers_no,
result = do_get_membership (pers_no,
first,
no_of_confs,
TRUE,
want_read_texts,
0,
memberships
);
......@@ -1559,14 +1603,33 @@ get_membership_10(Pers_no pers_no,
unsigned short first,
unsigned short no_of_confs,
Bool want_read_texts,
Membership_list *memberships
)
Membership_list *memberships)
{
/* CHK_CONNECTION in do_get_membership */
return do_get_membership (pers_no,
first,
no_of_confs,
TRUE,
want_read_texts,
0,
memberships);
}
extern Success
get_membership(Pers_no pers_no,
unsigned short first,
unsigned short no_of_confs,
Bool want_read_ranges,
unsigned long max_ranges,
Membership_list * memberships)
{
/* CHK_CONNECTION in do_get_membership */
return do_get_membership (pers_no,
first,
no_of_confs,
FALSE,
want_read_ranges,
max_ranges,
memberships);
}
......
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