Commit 9da729e4 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(do_unmark_text): New function: delete a mark.

(do_mark_mark_text): Never delete a mark. All callers
(mark_text, unmark_text): New functions.
(mark_text_old): Compatibility function that calls mark_text or
unmark_text depending on mark_type. This will now return an error if
you unmark at text that you had not marked.
parent 02c4827a
/* /*
* $Id: person.c,v 0.18 1993/01/16 23:17:19 ceder Exp $ * $Id: person.c,v 0.19 1993/08/05 00:21:49 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* All atomic calls that deals with persons. * All atomic calls that deals with persons.
*/ */
static char *rcsid = "$Id: person.c,v 0.18 1993/01/16 23:17:19 ceder Exp $"; static char *rcsid = "$Id: person.c,v 0.19 1993/08/05 00:21:49 ceder Exp $";
#include "rcs.h" #include "rcs.h"
USE(rcsid); USE(rcsid);
...@@ -36,7 +36,6 @@ USE(rcsid); ...@@ -36,7 +36,6 @@ USE(rcsid);
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <crypt.h>
#include "lyskomd.h" #include "lyskomd.h"
#include <kom-types.h> #include <kom-types.h>
...@@ -117,7 +116,8 @@ do_set_passwd( Password pwd, ...@@ -117,7 +116,8 @@ do_set_passwd( Password pwd,
/* /*
* Mark a text. No check is done if pers_p is really allowed to mark it. * Mark a text. No check is done if pers_p is really allowed to mark it.
* Use mark_type==0 to unmark the text. * This function can mark a text with mark_type == 0. If a previous mark
* existed it is changed to the given mark_type.
*/ */
static Success static Success
...@@ -145,7 +145,7 @@ do_mark_text(Pers_no pers_no, ...@@ -145,7 +145,7 @@ do_mark_text(Pers_no pers_no,
old_mark = markp; old_mark = markp;
} }
if (old_mark != NULL && mark_type != 0) if (old_mark != NULL)
{ {
/* Change marktype of an already marked text. (No need to check /* Change marktype of an already marked text. (No need to check
that the text exists). */ that the text exists). */
...@@ -154,10 +154,65 @@ do_mark_text(Pers_no pers_no, ...@@ -154,10 +154,65 @@ do_mark_text(Pers_no pers_no,
old_mark->mark_type = mark_type; old_mark->mark_type = mark_type;
mark_person_as_changed(pers_no); mark_person_as_changed(pers_no);
} }
else if (old_mark != NULL) else
{
/* A new mark. Check that the text exists. */
BUG(("do_mark_text(): new mark.\n"));
if ( text_s == NULL )
GET_T_STAT(text_s, text_no, FAILURE);
if (text_s->no_of_marks >= MAX_MARKS_TEXT
|| pers_p->marks.no_of_marks >= MAX_MARKS_PERSON)
{
kom_errno = KOM_MARK_LIMIT;
return FAILURE;
}
text_s->no_of_marks++;
mark_text_as_changed(text_no);
pers_p->marks.marks = srealloc(pers_p->marks.marks,
++pers_p->marks.no_of_marks * sizeof(Mark));
pers_p->marks.marks[pers_p->marks.no_of_marks - 1].text_no = text_no;
pers_p->marks.marks[pers_p->marks.no_of_marks - 1].mark_type
= mark_type;
mark_person_as_changed(pers_no);
}
return OK;
}
/* Unmark a text. Returns a failure if the text was not marked. */
static Success
do_unmark_text(Pers_no pers_no,
Person *pers_p, /* May be NULL */
Text_no text_no,
Text_stat *text_s) /* May be NULL */
{
Mark *markp;
Mark *old_mark = NULL;
int i;
BUGDECL;
if ( pers_p == NULL )
GET_P_STAT(pers_p, pers_no, FAILURE);
/* Locate the mark. */
for ( i = pers_p->marks.no_of_marks, markp = pers_p->marks.marks;
i > 0 && old_mark == NULL;
i--, markp++ )
{
if ( markp->text_no == text_no )
old_mark = markp;
}
if (old_mark != NULL)
{ {
/* Delete this mark. */ /* Delete this mark. */
BUG(("do_mark_text(): Delete mark.\n")); BUG(("do_unmark_text(): Delete mark.\n"));
while ( old_mark < ( pers_p->marks.marks while ( old_mark < ( pers_p->marks.marks
+ pers_p->marks.no_of_marks - 1 )) + pers_p->marks.no_of_marks - 1 ))
...@@ -175,7 +230,7 @@ do_mark_text(Pers_no pers_no, ...@@ -175,7 +230,7 @@ do_mark_text(Pers_no pers_no,
{ {
if ( text_s->no_of_marks == 0 ) if ( text_s->no_of_marks == 0 )
{ {
log("WNG: do_mark_text(): Text %d has no_of_marks==0,\ log("WNG: do_unmark_text(): Text %d has no_of_marks==0,\
but person %d had marked the text.", but person %d had marked the text.",
text_no, pers_no); text_no, pers_no);
} }
...@@ -187,35 +242,12 @@ do_mark_text(Pers_no pers_no, ...@@ -187,35 +242,12 @@ do_mark_text(Pers_no pers_no,
} }
/* ...but it is not an error if someone has deleted the text. */ /* ...but it is not an error if someone has deleted the text. */
} }
else if ( mark_type != 0 )
{
/* A new mark. Check that the text exists. */
BUG(("do_mark_text(): new mark.\n"));
if ( text_s == NULL )
GET_T_STAT(text_s, text_no, FAILURE);
if (text_s->no_of_marks >= MAX_MARKS_TEXT
|| pers_p->marks.no_of_marks >= MAX_MARKS_PERSON)
{
kom_errno = KOM_MARK_LIMIT;
return FAILURE;
}
text_s->no_of_marks++;
mark_text_as_changed(text_no);
pers_p->marks.marks = srealloc(pers_p->marks.marks,
++pers_p->marks.no_of_marks * sizeof(Mark));
pers_p->marks.marks[pers_p->marks.no_of_marks - 1].text_no = text_no;
pers_p->marks.marks[pers_p->marks.no_of_marks - 1].mark_type
= mark_type;
mark_person_as_changed(pers_no);
}
else else
{ {
/* An attempt to delete a non-existent mark. This is a noop. */ /* An attempt to delete a non-existent mark. */
BUG(("do_mark_text(): delete non-existent mark.\n")); BUG(("do_unmark_text(): delete non-existent mark.\n"));
kom_errno = KOM_NOT_MARKED;
return FAILURE;
} }
return OK; return OK;
...@@ -319,8 +351,8 @@ do_delete_pers (Pers_no pers_no) ...@@ -319,8 +351,8 @@ do_delete_pers (Pers_no pers_no)
for ( i = pers_p->marks.no_of_marks; i > 0; i-- ) for ( i = pers_p->marks.no_of_marks; i > 0; i-- )
{ {
if ( do_mark_text(pers_no, pers_p, if ( do_unmark_text(pers_no, pers_p,
pers_p->marks.marks[0].text_no, NULL, 0) != OK ) pers_p->marks.marks[0].text_no, NULL) != OK )
{ {
log("WNG: do_delete_pers(): can't unmark text %d (i == %d)\n", log("WNG: do_delete_pers(): can't unmark text %d (i == %d)\n",
pers_p->marks.marks[0].text_no, i); pers_p->marks.marks[0].text_no, i);
...@@ -398,23 +430,30 @@ chk_passwd (Password pwd, ...@@ -398,23 +430,30 @@ chk_passwd (Password pwd,
*/ */
extern Success extern Success
mark_text( Text_no text_no, /* Will fail if the user is not */ mark_text_old(Text_no text_no,
u_char mark_type ) /* allowed to read the text. */ u_char mark_type)
{
if (mark_type == 0)
return unmark_text(text_no);
else
return mark_text(text_no, mark_type);
}
extern Success
mark_text(Text_no text_no, /* Will fail if the user is not */
u_char mark_type) /* allowed to read the text. */
{ {
Text_stat *text_s = NULL; Text_stat *text_s = NULL;
BUGDECL; BUGDECL;
CHK_LOGIN(FAILURE); CHK_LOGIN(FAILURE);
if ( mark_type != 0 ) /* Check that the user is allowed to read the text. */
GET_T_STAT(text_s, text_no, FAILURE);
if ( !text_read_access(text_no, text_s) )
{ {
/* Check that the user is allowed to read the text. */ kom_errno = KOM_PERM;
GET_T_STAT(text_s, text_no, FAILURE); return FAILURE;
if ( !text_read_access(text_no, text_s) )
{
kom_errno = KOM_PERM;
return FAILURE;
}
} }
BUG(("Person %d markerar text %d med typ %d\n", BUG(("Person %d markerar text %d med typ %d\n",
...@@ -423,6 +462,18 @@ mark_text( Text_no text_no, /* Will fail if the user is not */ ...@@ -423,6 +462,18 @@ mark_text( Text_no text_no, /* Will fail if the user is not */
return do_mark_text(ACTPERS, ACT_P, text_no, text_s, mark_type); return do_mark_text(ACTPERS, ACT_P, text_no, text_s, mark_type);
} }
extern Success
unmark_text(Text_no text_no)
{
Text_stat *text_s = NULL;
BUGDECL;
CHK_LOGIN(FAILURE);
BUG(("Person %d avmarkerar text %d\n", ACTPERS, text_no));
return do_unmark_text(ACTPERS, ACT_P, text_no, text_s);
}
/* /*
* Create a new person. * Create a new person.
* *
...@@ -469,7 +520,7 @@ create_person (String name, ...@@ -469,7 +520,7 @@ create_person (String name,
if ( !legal_name( name ) ) if ( !legal_name( name ) )
{ {
kom_errno = KOM_BAD_NAME; /* kom_errno will be set by legal_name(). */
return 0; return 0;
} }
......
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