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. * Copyright (C) 1991-2002 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -1508,24 +1508,30 @@ read_ranges_postcondition(Membership *m, ...@@ -1508,24 +1508,30 @@ read_ranges_postcondition(Membership *m,
*/ */
extern Success extern Success
mark_as_read (Conf_no conference, mark_as_read (Conf_no conference,
int no_of_texts, const Number_list *texts)
const Local_text_no * text_arr )
{ {
int i; int i;
Membership * m; Membership * m;
Conference * conf_c; Conference * conf_c;
Success retval = OK; Success retval = OK;
const Local_text_no * const text_arr_start = text_arr; Local_text_no lno;
#ifdef DEBUG_MARK_AS_READ #ifdef DEBUG_MARK_AS_READ
Membership original; Membership original;
int loop;
#endif #endif
CHK_CONNECTION(FAILURE); 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); CHK_LOGIN(FAILURE);
GET_C_STAT(conf_c, conference, 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); set_conf_errno(active_connection, conference, KOM_NOT_MEMBER);
return FAILURE; return FAILURE;
...@@ -1535,20 +1541,21 @@ mark_as_read (Conf_no conference, ...@@ -1535,20 +1541,21 @@ mark_as_read (Conf_no conference,
read_ranges_precondition(m, &original, conf_c, "mark_as_read"); read_ranges_precondition(m, &original, conf_c, "mark_as_read");
#endif #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; kom_errno = KOM_NO_SUCH_LOCAL_TEXT;
err_stat = no_of_texts - i; err_stat = i;
retval = FAILURE; retval = FAILURE;
break; /* Exit for-loop */ break; /* Exit for-loop */
} }
if ( *text_arr == 0 ) if (lno == 0)
{ {
kom_errno = KOM_LOCAL_TEXT_ZERO; kom_errno = KOM_LOCAL_TEXT_ZERO;
err_stat = no_of_texts - i; err_stat = i;
retval = FAILURE; retval = FAILURE;
break; /* Exit for-loop */ break; /* Exit for-loop */
} }
...@@ -1556,17 +1563,17 @@ mark_as_read (Conf_no conference, ...@@ -1556,17 +1563,17 @@ mark_as_read (Conf_no conference,
if (retval == OK) 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) if (conference == ACTPERS)
add_rec_time(conf_c, *text_arr, ACTPERS); add_rec_time(conf_c, lno, ACTPERS);
/* Update the Membership struct */ /* Update the Membership struct */
if (insert_loc_no(lno, m) == OK
if (insert_loc_no(*text_arr, m) == OK && active_connection->cwc == conference)
&& active_connection->cwc == conference )
{ {
++ACT_P->read_texts; ++ACT_P->read_texts;
} }
...@@ -1580,9 +1587,9 @@ mark_as_read (Conf_no conference, ...@@ -1580,9 +1587,9 @@ mark_as_read (Conf_no conference,
if (read_ranges_postcondition(m, &original, conf_c, "mark_as_read") < 0) 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"); kom_log("this was triggered by an attempt to mark this as read\n");
fprintf(stderr, "\n%lu { ", (unsigned long)no_of_texts); fprintf(stderr, "\n%lu { ", (unsigned long)texts->length);
for (loop = 0; loop < no_of_texts; loop++) for (i = 0; i < texts->length; i++)
fprintf(stderr, "\n%lu ", (unsigned long)text_arr_start[loop]); fprintf(stderr, "\n%lu ", (unsigned long)texts->data[i]);
fprintf(stderr, "}\n"); fprintf(stderr, "}\n");
} }
#endif #endif
...@@ -1695,10 +1702,11 @@ set_read_ranges(Conf_no conference, ...@@ -1695,10 +1702,11 @@ set_read_ranges(Conf_no conference,
Membership original; Membership original;
#endif #endif
CHK_CONNECTION(FAILURE);
if (check_range_list(read_ranges) == FAILURE) if (check_range_list(read_ranges) == FAILURE)
return FAILURE; return FAILURE;
CHK_CONNECTION(FAILURE);
CHK_LOGIN(FAILURE); CHK_LOGIN(FAILURE);
GET_C_STAT(conf_c, conference, FAILURE); GET_C_STAT(conf_c, conference, FAILURE);
......
Supports Markdown
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