Commit 3571df44 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(mark_as_read): Changed the arguments "int no_of_text; const

	Local_text_no *text_arr" into a single more modern-style
	Number_list argument.  Return KOM_LONG_ARRAY if the
	array is too long.  Simplified the code.
(set_read_ranges): Call CHK_CONNECTION before checking the
	supplied read_ranges.
parent ca5363a0
/*
* $Id: membership.c,v 0.92 2003/08/17 11:09:14 ceder Exp $
* $Id: membership.c,v 0.93 2003/08/20 17:40:18 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -1507,25 +1507,31 @@ read_ranges_postcondition(Membership *m,
* doen't get too CPU-intensive.)
*/
extern Success
mark_as_read (Conf_no conference,
int no_of_texts,
const Local_text_no * text_arr )
mark_as_read (Conf_no conference,
const Number_list *texts)
{
int i;
Membership * m;
Conference * conf_c;
Success retval = OK;
const Local_text_no * const text_arr_start = text_arr;
Local_text_no lno;
#ifdef DEBUG_MARK_AS_READ
Membership original;
int loop;
#endif
CHK_CONNECTION(FAILURE);
if (texts->length > param.mark_as_read_chunk)
{
kom_errno = KOM_LONG_ARRAY;
err_stat = param.mark_as_read_chunk;
return FAILURE;
}
CHK_LOGIN(FAILURE);
GET_C_STAT(conf_c, conference, FAILURE);
if ( (m = locate_membership( conference, ACT_P)) == NULL)
if ((m = locate_membership(conference, ACT_P)) == NULL)
{
set_conf_errno(active_connection, conference, KOM_NOT_MEMBER);
return FAILURE;
......@@ -1535,20 +1541,21 @@ mark_as_read (Conf_no conference,
read_ranges_precondition(m, &original, conf_c, "mark_as_read");
#endif
for( i = no_of_texts; i > 0; i--, text_arr++ )
for (i = 0; i < texts->length; i++)
{
if (*text_arr >= l2g_first_appendable_key(&conf_c->texts))
lno = texts->data[i];
if (lno >= l2g_first_appendable_key(&conf_c->texts))
{
kom_errno = KOM_NO_SUCH_LOCAL_TEXT;
err_stat = no_of_texts - i;
err_stat = i;
retval = FAILURE;
break; /* Exit for-loop */
}
if ( *text_arr == 0 )
if (lno == 0)
{
kom_errno = KOM_LOCAL_TEXT_ZERO;
err_stat = no_of_texts - i;
err_stat = i;
retval = FAILURE;
break; /* Exit for-loop */
}
......@@ -1556,17 +1563,17 @@ mark_as_read (Conf_no conference,
if (retval == OK)
{
for(text_arr = text_arr_start, i = no_of_texts; i > 0; i--, text_arr++)
for(i = 0; i < texts->length; i++)
{
/* Is it a letter to ACTPERS? If so, add a rec_time item. */
lno = texts->data[i];
/* Is it a letter to ACTPERS? If so, add a rec_time item. */
if (conference == ACTPERS)
add_rec_time(conf_c, *text_arr, ACTPERS);
add_rec_time(conf_c, lno, ACTPERS);
/* Update the Membership struct */
if (insert_loc_no(*text_arr, m) == OK
&& active_connection->cwc == conference )
if (insert_loc_no(lno, m) == OK
&& active_connection->cwc == conference)
{
++ACT_P->read_texts;
}
......@@ -1580,9 +1587,9 @@ mark_as_read (Conf_no conference,
if (read_ranges_postcondition(m, &original, conf_c, "mark_as_read") < 0)
{
kom_log("this was triggered by an attempt to mark this as read\n");
fprintf(stderr, "\n%lu { ", (unsigned long)no_of_texts);
for (loop = 0; loop < no_of_texts; loop++)
fprintf(stderr, "\n%lu ", (unsigned long)text_arr_start[loop]);
fprintf(stderr, "\n%lu { ", (unsigned long)texts->length);
for (i = 0; i < texts->length; i++)
fprintf(stderr, "\n%lu ", (unsigned long)texts->data[i]);
fprintf(stderr, "}\n");
}
#endif
......@@ -1695,10 +1702,11 @@ set_read_ranges(Conf_no conference,
Membership original;
#endif
CHK_CONNECTION(FAILURE);
if (check_range_list(read_ranges) == FAILURE)
return FAILURE;
CHK_CONNECTION(FAILURE);
CHK_LOGIN(FAILURE);
GET_C_STAT(conf_c, conference, FAILURE);
......
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