Commit 880ac08d authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(struct delete_list): New struct.

(delete_list_append): New static function.
(execute_deletions): New static function.
(check_misc_infos): Adjusted to the fact that the texts member of
	Conference is now a l2g.
(adjust_text_list): Deleted.
(check_created_texts): The "created" argument now points to a
	Local_to_global.  Removed the check for "bad created_texts array"
	since it can no longer be bad in that way.
(check_membership): Adjusted to the fact that the texts member of
	Conference is now a l2g.
(check_texts_in_conf): The "tlist" argument now points to a
	Local_to_global.  Removed the check for "bad created_texts array"
	since it can no longer be bad in that way.
parent 2b107568
/*
* $Id: dbck.c,v 0.39 1998/07/08 16:25:13 ceder Exp $
* $Id: dbck.c,v 0.40 1998/07/26 16:48:17 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -29,7 +29,7 @@
*/
static const char *
rcsid = "$Id: dbck.c,v 0.39 1998/07/08 16:25:13 ceder Exp $";
rcsid = "$Id: dbck.c,v 0.40 1998/07/26 16:48:17 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -51,6 +51,7 @@ USE(rcsid);
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <assert.h>
#include "getopt.h"
#include "misc-types.h"
......@@ -71,6 +72,7 @@ USE(rcsid);
#include "version-info.h"
#include "ram-output.h"
#include "unused.h"
#include "local-to-global.h"
#define OPT_PERS_PRESENTATION_CONF 1
......@@ -156,6 +158,38 @@ static Person_scratchpad *person_scratchpad[MAX_CONF];
int buglevel = 0;
#endif
struct delete_list {
struct delete_list *next;
Local_text_no lno;
};
static void
delete_list_append(struct delete_list **head,
Local_text_no lno)
{
struct delete_list *item = smalloc(sizeof(struct delete_list));
item->next = *head;
item->lno = lno;
*head = item;
}
static void
execute_deletions(Local_to_global *l2g,
struct delete_list **head)
{
struct delete_list *item;
while (*head != NULL)
{
item = *head;
*head = item->next;
l2g_delete(l2g, item->lno);
sfree(item);
}
}
#if defined(HAVE_VFPRINTF) && defined(HAVE_STDARG_H)
extern void
log (const char * format, ...)
......@@ -430,7 +464,9 @@ check_misc_infos(Text_no tno,
Misc_info_group group;
Conference *c;
Text_stat *t;
Local_text_no conf_min;
Local_text_no conf_max;
long errors=0;
while (previous = (Misc_info *)misc,
......@@ -464,33 +500,32 @@ check_misc_infos(Text_no tno,
break;
/* Check loc_no */
if ( group.local_no < c->texts.first_local_no )
conf_min = l2g_lookup(&c->texts, 0);
conf_max = l2g_first_appendable_key(&c->texts);
if (group.local_no < conf_min)
{
log("Text %lu: Recipient %lu<%lu> loc_no is less than %lu\n",
(unsigned long)tno, (unsigned long)group.recipient,
(unsigned long)group.local_no,
(unsigned long)c->texts.first_local_no);
(unsigned long)conf_min);
errors++;
}
else if ( c->texts.first_local_no + c->texts.no_of_texts - 1
< group.local_no )
else if (group.local_no >= conf_max)
{
log("Text %lu: Recipient %lu<%lu> loc_no > %lu\n",
log("Text %lu: Recipient %lu<%lu> loc_no >= %lu\n",
(unsigned long)tno, (unsigned long)group.recipient,
(unsigned long)group.local_no,
(unsigned long)(c->texts.first_local_no
+ c->texts.no_of_texts - 1));
(unsigned long)conf_max);
errors++;
}
else if ( c->texts.texts[group.local_no
- c->texts.first_local_no] != tno )
else if (l2g_lookup(&c->texts, group.local_no) != tno)
{
log("Text %lu: Recipient %lu<%lu>: %s to %lu.\n",
(unsigned long)tno, (unsigned long)group.recipient,
(unsigned long)group.local_no,
"that local number is mapped",
(unsigned long)c->texts.texts[group.local_no
- c->texts.first_local_no]);
(unsigned long)l2g_lookup(&c->texts, group.local_no));
errors++;
}
......@@ -520,33 +555,32 @@ check_misc_infos(Text_no tno,
break;
/* Check loc_no */
if ( group.local_no < c->texts.first_local_no )
conf_min = l2g_lookup(&c->texts, 0);
conf_max = l2g_first_appendable_key(&c->texts);
if (group.local_no < conf_min)
{
log("Text %lu: CC_Recipient %lu<%lu> is less than %lu\n",
(unsigned long)tno, (unsigned long)group.cc_recipient,
(unsigned long)group.local_no,
(unsigned long)c->texts.first_local_no);
(unsigned long)conf_min);
errors++;
}
else if ( c->texts.first_local_no + c->texts.no_of_texts - 1
< group.local_no )
else if (group.local_no >= conf_max)
{
log("Text %lu: CC_Recipient %lu<%lu> loc_no > %lu\n",
log("Text %lu: CC_Recipient %lu<%lu> loc_no >= %lu\n",
(unsigned long)tno, (unsigned long)group.cc_recipient,
(unsigned long)group.local_no,
(unsigned long)(c->texts.first_local_no
+ c->texts.no_of_texts - 1));
(unsigned long)conf_max);
errors++;
}
else if ( c->texts.texts[group.local_no
- c->texts.first_local_no] != tno )
else if (l2g_lookup(&c->texts, group.local_no) != tno)
{
log("Text %lu: CC_Recipient %lu<%lu>: %s to %lu.\n",
(unsigned long)tno, (unsigned long)group.cc_recipient,
(unsigned long)group.local_no,
"that local number is mapped",
(unsigned long)c->texts.texts[group.local_no
- c->texts.first_local_no]);
(unsigned long)l2g_lookup(&c->texts, group.local_no));
errors++;
}
......@@ -576,33 +610,33 @@ check_misc_infos(Text_no tno,
break;
/* Check loc_no */
if ( group.local_no < c->texts.first_local_no )
conf_min = l2g_lookup(&c->texts, 0);
conf_max = l2g_first_appendable_key(&c->texts);
if (group.local_no < conf_min)
{
log("Text %lu: BCC_Recipient %lu<%lu> is less than %lu\n",
(unsigned long)tno, (unsigned long)group.bcc_recipient,
(unsigned long)group.local_no,
(unsigned long)c->texts.first_local_no);
(unsigned long)conf_min);
errors++;
}
else if ( c->texts.first_local_no + c->texts.no_of_texts - 1
< group.local_no )
else if (group.local_no >= conf_max)
{
log("Text %lu: BCC_Recipient %lu<%lu> loc_no > %lu\n",
log("Text %lu: BCC_Recipient %lu<%lu> loc_no >= %lu\n",
(unsigned long)tno, (unsigned long)group.bcc_recipient,
(unsigned long)group.local_no,
(unsigned long)(c->texts.first_local_no
+ c->texts.no_of_texts - 1));
(unsigned long)conf_max);
errors++;
}
else if ( c->texts.texts[group.local_no
- c->texts.first_local_no] != tno )
else if (l2g_lookup(&c->texts, group.local_no) != tno)
{
log("Text %lu: BCC_Recipient %lu<%lu>: %s to %lu.\n",
(unsigned long)tno, (unsigned long)group.bcc_recipient,
(unsigned long)group.local_no,
"that local number is mapped",
(unsigned long)c->texts.texts[group.local_no
- c->texts.first_local_no]);
(unsigned long)l2g_lookup(&c->texts,
group.local_no));
errors++;
}
......@@ -797,86 +831,48 @@ check_texts(void)
return errors;
}
static Bool
adjust_text_list(Text_list *text_list)
{
unsigned long zeroes;
unsigned long i;
for (zeroes = 0;
zeroes < text_list->no_of_texts && text_list->texts[ zeroes ] == 0;
zeroes++)
;
if ( zeroes > 0 )
{
text_list->no_of_texts -= zeroes;
text_list->first_local_no += zeroes;
for ( i = 0; i < text_list->no_of_texts; i++)
text_list->texts[ i ] = text_list->texts[ i + zeroes ];
text_list->texts = srealloc(text_list->texts,
(text_list->no_of_texts
* sizeof(Text_no)));
}
return (zeroes > 0) ? TRUE : FALSE;
}
static int
check_created_texts(Pers_no pno,
Text_list *created)
Local_to_global *created)
{
unsigned long i;
Text_stat *t;
int errors=0;
L2g_iterator iter;
struct delete_list *del_list = NULL;
for ( i=0; i < created->no_of_texts; i++ )
for (l2gi_searchall(&iter, created); !iter.search_ended; l2gi_next(&iter))
{
if (created->texts[i] != 0)
{
t = cached_get_text_stat(created->texts[i]);
if ( t != NULL && t->author != pno)
{
log("Person %lu is author of text %lu whose author is %lu.\n",
(unsigned long)pno, (unsigned long)created->texts[i],
(unsigned long)t->author);
errors++;
}
assert(iter.tno != 0);
assert(iter.lno != 0);
if ( t == NULL )
{
log("Person %lu is author of text %lu, which doesn't exist.\n",
(unsigned long)pno, (unsigned long)created->texts[i]);
if ( rflag ||
confirm("Repair by setting to text_no to 0 in local map"))
{
created->texts[i] = 0;
mark_person_as_changed(pno);
modifications++;
log("Repaired: created_texts corrected.\n");
}
else
errors++;
}
t = cached_get_text_stat(iter.tno);
if ( t != NULL && t->author != pno)
{
log("Person %lu is author of text %lu whose author is %lu.\n",
(unsigned long)pno, (unsigned long)iter.tno,
(unsigned long)t->author);
errors++;
}
}
if ( created->no_of_texts > 0 && created->texts[0] == 0 )
{
log("Person %lu has a bad created_texts array. Starts with a 0.\n",
(unsigned long)pno);
if ( rflag || confirm ("Repair by adjusting created_texts"))
if ( t == NULL )
{
adjust_text_list(created);
mark_person_as_changed(pno);
modifications++;
log("Repaired: created_texts adjusted.\n");
log("Person %lu is author of text %lu, which doesn't exist.\n",
(unsigned long)pno, (unsigned long)iter.tno);
if ( rflag ||
confirm("Repair by setting to text_no to 0 in local map"))
{
delete_list_append(&del_list, iter.lno);
mark_person_as_changed(pno);
modifications++;
log("Repaired: created_texts corrected.\n");
}
else
errors++;
}
else
errors++;
}
execute_deletions(created, &del_list);
return errors;
}
......@@ -900,16 +896,14 @@ check_membership(Pers_no pno,
else
{
/* Check read texts */
if ( mship->last_text_read >
conf->texts.first_local_no + conf->texts.no_of_texts - 1)
if (mship->last_text_read >= l2g_first_appendable_key(&conf->texts))
{
log("Person %lu %s %lu in conf %lu, which only has %lu texts.\n",
(unsigned long)pno,
"has read text",
(unsigned long)mship->last_text_read,
(unsigned long)mship->conf_no,
(unsigned long)(conf->texts.first_local_no
+ conf->texts.no_of_texts - 1));
(unsigned long)(l2g_first_appendable_key(&conf->texts) -1));
errors++;
}
......@@ -1105,28 +1099,49 @@ is_recipient(Conf_no conf_no,
static int
check_texts_in_conf(Conf_no cc,
Text_list *tlist)
Local_to_global *tlist)
{
unsigned long i;
Text_stat *t;
int errors=0;
for ( i=0; i < tlist->no_of_texts; i++ )
L2g_iterator iter;
struct delete_list *del_list = NULL;
for (l2gi_searchall(&iter, tlist); !iter.search_ended; l2gi_next(&iter))
{
if (tlist->texts[i] != 0)
assert(iter.lno != 0);
assert(iter.tno != 0);
t = cached_get_text_stat(iter.tno);
if (t == NULL)
{
t = cached_get_text_stat(tlist->texts[i]);
if ( t == NULL )
log("Text %lu<%lu> in conference %lu is non-existent.\n",
(unsigned long)iter.tno,
(unsigned long)iter.lno,
(unsigned long)cc);
if (rflag || confirm("Repair by deleting the Text_no in the map?"))
{
log("Text %lu<%lu> in conference %lu is non-existent.\n",
(unsigned long)tlist->texts[i],
(unsigned long)i + tlist->first_local_no,
delete_list_append(&del_list, iter.lno);
mark_conference_as_changed(cc);
modifications++;
log("Repaired: %lu is no longer a recipient.\n",
(unsigned long)cc);
}
else
errors++;
}
else
{
if (!is_recipient(cc, t))
{
log("Text %lu<%lu> in conference %lu %s.\n",
(unsigned long)iter.tno,
(unsigned long)iter.lno,
(unsigned long)cc,
"doesn't have the conference as recipient");
if (rflag
|| confirm("Repair by setting Text_no to 0 in the map?") )
if (confirm("Repair by deleting Text_no from the map?") )
{
tlist->texts[i]=0;
delete_list_append(&del_list, iter.lno);
mark_conference_as_changed(cc);
modifications++;
log("Repaired: %lu is no longer a recipient.\n",
......@@ -1135,46 +1150,10 @@ check_texts_in_conf(Conf_no cc,
else
errors++;
}
else
{
if ( !is_recipient(cc, t) )
{
log("Text %lu<%lu> in conference %lu %s.\n",
(unsigned long)tlist->texts[i],
(unsigned long)i + tlist->first_local_no,
(unsigned long)cc,
"doesn't have the conference as recipient");
if (confirm("Repair by setting Text_no to 0 in the map?") )
{
tlist->texts[i]=0;
mark_conference_as_changed(cc);
modifications++;
log("Repaired: %lu is no longer a recipient.\n",
(unsigned long)cc);
}
else
errors++;
}
}
}
}
execute_deletions(tlist, &del_list);
if ( tlist->no_of_texts > 0 && tlist->texts[0] == 0 )
{
log("Conference %lu has a bad Text_list. Starts with a 0.\n",
(unsigned long)cc);
if ( rflag || confirm ("Repair by adjusting text_list"))
{
adjust_text_list(tlist);
mark_conference_as_changed(cc);
modifications++;
log("Repaired: text_list adjusted.\n");
}
else
errors++;
}
return errors;
}
......
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