Commit 598ae16e authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Use init_foo() instead fo EMPTY_FOO.

Use param."foo" (from param.h) instead of "FOO".
(struct jubel): New struct.
(jubel_root): New variable.
(register_jubel, free_all_jubel, ok_to_create_next_text): New functions.
(create_text, create_anonymous_text): Check ok_to_create_next_text().
parent 8832d442
/*
* $Id: text.c,v 0.25 1993/10/18 12:31:08 ceder Exp $
* $Id: text.c,v 0.26 1994/02/19 04:25:44 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -28,7 +28,7 @@
* All atomic calls that deals with texts.
*/
static char *rcsid = "$Id: text.c,v 0.25 1993/10/18 12:31:08 ceder Exp $";
static char *rcsid = "$Id: text.c,v 0.26 1994/02/19 04:25:44 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -59,6 +59,7 @@ USE(rcsid);
#include "minmax.h"
#include "admin.h"
#include "send-async.h"
#include "param.h"
/*
* Static functions
......@@ -297,7 +298,7 @@ submit_to(Conf_no conf_no, /* The conference the user is trying to */
if ( conf_c == NULL )
GET_C_STAT(conf_c, conf_no, 0);
for ( i=0; i < MAX_SUPER_CONF_LOOP; i++)
for ( i=0; i < param.max_super_conf_loop; i++)
{
acc = access_perm (conf_no, conf_c, ACTPERS, ACT_P);
......@@ -904,7 +905,7 @@ check_footn(Text_stat * t_stat)
return FAILURE;
}
if ( count_footn( t_stat ) >= MAX_FOOT )
if ( count_footn( t_stat ) >= param.max_foot )
{
kom_errno = KOM_FOOT_LIMIT;
return FAILURE;
......@@ -922,7 +923,7 @@ check_footn(Text_stat * t_stat)
static Success
check_comm(Text_stat * t_stat)
{
if ( count_comment( t_stat ) >= MAX_COMM )
if ( count_comment( t_stat ) >= param.max_comm )
{
kom_errno = KOM_COMM_LIMIT;
return FAILURE;
......@@ -1729,7 +1730,9 @@ send_async_new_text (Text_no text_no,
{
Connection *cptr;
Session_no i = 0;
Text_stat filtered = EMPTY_TEXT_STAT;
Text_stat filtered;
init_text_stat(&filtered);
while ( (i = traverse_connections(i)) != 0 )
{
......@@ -1750,7 +1753,97 @@ send_async_new_text (Text_no text_no,
}
}
}
/*
* Special case handling of special text numbers.
*
* In the KOMmunity, there has arisen an odd phenomenon known as
* "jubel" to the local citizens of LysKOM. There are several kinds
* of "jubel"; a text number divisible by 1000 is one famous such.
*
* There is a feeling that jubels, at least the more prominent jubels,
* should not be created by automatic postings. This code is
* primarily aimed at stopping such things, but it can have other, eh,
* interesting uses as well...
*/
struct jubel {
struct jubel *next;
Pers_no bad_guy;
Text_no divisor; /* 0 is used to represent infinity */
Text_no remainder;
};
static struct jubel *jubel_root = NULL;
/*
* register_jubel(char*) - tell lyskomd about a jubel, and a
* person which is not allowed to create that jubel. The argument is
* a string consisting of two or three numbers:
* persno textno
* persno divisor remainder
* meaning that PERSNO is not allowed to create text TEXTNO, or any
* text number which fulfills the relation textno%DIVISOR==REMAINDER.
*/
void
register_jubel(Pers_no pno,
Text_no divis, /* 0 if no division should be made. */
Text_no tno)
{
struct jubel *j = smalloc(sizeof(struct jubel));
j->next = jubel_root;
j->bad_guy = pno;
j->divisor = divis;
j->remainder = tno;
jubel_root = j;
}
/* Free the jubel list */
void
free_all_jubel(void)
{
struct jubel *a;
struct jubel *b;
a = jubel_root;
while (a != NULL)
{
b = a;
a = a->next;
sfree(b);
}
jubel_root = NULL;
}
/* Check if it is ok for ACTPERS to create the next text. */
static Bool
ok_to_create_next_text(void)
{
struct jubel *j;
Text_no next_tno;
Bool is_jubel = FALSE;
next_tno = query_next_text_num();
for (j = jubel_root; j != NULL; j = j->next)
{
if ((j->divisor == 0 && next_tno == j->remainder)
|| (j->divisor != 0 && next_tno%j->divisor == j->remainder))
{
if (ACTPERS == j->bad_guy)
{
log("Stopped person %d from creating jubel %lu",
ACTPERS, next_tno);
return FALSE;
}
else
is_jubel = TRUE;
}
}
if (is_jubel)
log("Granted jubel %lu to person %d.\n", next_tno, ACTPERS);
return TRUE;
}
/*
* Create a text.
......@@ -1775,12 +1868,20 @@ create_text(const String message,
/* Check the length of the text. */
if ( s_strlen (message) > TEXT_LEN )
if ( s_strlen (message) > param.text_len )
{
kom_errno = KOM_LONG_STR;
return 0;
}
/* Check that the author is allowed to write this text number */
if (ok_to_create_next_text() == FALSE)
{
kom_errno = KOM_TEMPFAIL;
return 0;
}
/* Check all misc-items */
if ( create_text_check_misc(&no_of_misc, misc) != OK
......@@ -1847,12 +1948,20 @@ create_anonymous_text(const String message,
/* Check the length of the text. */
if ( s_strlen (message) > TEXT_LEN )
if ( s_strlen (message) > param.text_len )
{
kom_errno = KOM_LONG_STR;
return 0;
}
/* Check that the author is allowed to write this text number */
if (ok_to_create_next_text() == FALSE)
{
kom_errno = KOM_TEMPFAIL;
return 0;
}
/* Check all misc-items */
if ( create_text_check_misc(&no_of_misc, misc) != OK
......@@ -2045,7 +2154,7 @@ add_recipient( Text_no text_no,
return FAILURE;
}
if ( count_recipients( t_stat ) >= MAX_RECIPIENTS )
if ( count_recipients( t_stat ) >= param.max_recipients )
{
kom_errno = KOM_RECIPIENT_LIMIT;
return 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