manipulate.h 15.1 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
/*
Linus Tolke's avatar
Linus Tolke committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * $Id: manipulate.h,v 0.3 1991/09/15 10:31:20 linus Exp $
 * Copyright (C) 1991  Lysator Academic Computer Association.
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
/*
 * $Id: manipulate.h,v 0.3 1991/09/15 10:31:20 linus Exp $
Per Cederqvist's avatar
Per Cederqvist committed
27
 *
Per Cederqvist's avatar
Per Cederqvist committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
 * manipulate.h
 *
 * Skapad av ceder n}gon g}ng efter 1990-05-25, men f|re 1990-07-05.
 */

/*
 * Definition of macros used in services.c and manipulate.c
 */

/* pers_no of the connected person. (0    if not logged in) */
#define ACTPERS (active_connection->pers_no)

/* person  of the connected person. (NULL if not logged in) */
#define ACT_P	(active_connection->person)

/* many functions can only be used if ACTPERS is logged in */

#define CHK_LOGIN(errortype)		\
{					\
    if ( ! ACTPERS )			\
    {					\
	kom_errno = KOM_LOGIN;		\
	return errortype;		\
    }					\
}


/* Conference 0 does never exist. */

#define CONF_ZERO(conf, errortype)	\
{					\
    if ( (conf) == 0 )			\
    {					\
	kom_errno = KOM_CONF_ZERO;	\
	return errortype;		\
    }					\
}
    

/* Check that a conference exists */

#define CHK_EXIST(conf, errortype)	\
{					\
    CONF_ZERO(conf, errortype);		\
    if ( !cached_conf_exists( conf ))	\
    {					\
	kom_errno = KOM_UNDEF_CONF;	\
	return errortype;		\
    }					\
}


/* do a cached_get_person_stat */

#define GET_P_STAT(p_stat_p, pers_no, failure)				\
{									\
    if ( ((p_stat_p) = cached_get_person_stat( pers_no )) == NULL)	\
    {									\
	return (failure);						\
    }									\
}

/* do a cached_get_conf_stat */

#define GET_C_STAT(c_stat_p, conf_no, failure)				\
{									\
    if ( ((c_stat_p) = cached_get_conf_stat( conf_no )) == NULL)	\
    {									\
	return (failure);						\
    }									\
}

/* do a cached_get_text_stat */

#define GET_T_STAT(t_stat_p, text_no, failure)				\
{									\
    if ( ((t_stat_p) = cached_get_text_stat( text_no )) == NULL)	\
    {									\
	return (failure);						\
    }									\
}


/*
 * ENA returns TRUE if ACTPERS has his privtype bit set, and has
 * enabled to at least req_lev.
 */

#define ENA(privtype, req_lev)	\
(active_connection->ena_level >=(req_lev) && (ACT_P)->privileges.privtype)



/*
 * Add a misc item to a text_status.
 * The item is put last on the list. Thus this macro should not be used
 * to add rec_time.
 *
 *	Text_stat * text_stat_pointer	Textstatus to modify
 *	Info_type   type_of_misc	Type om misc_item to add
 *		    tag_name		Tagname in Info_datum
 *		    value_of_misc	Value to set tag_name to.
 */
#define ADD_MISC(text_stat_pointer, type_of_misc, tag_name, value_of_misc) \
{									\
    /* Allocate space */						\
    text_stat_pointer->misc_items					\
    = srealloc(text_stat_pointer->misc_items,				\
	       (++(text_stat_pointer->no_of_misc)) * sizeof(Misc_info));\
									\
    /* Set type */							\
    text_stat_pointer->misc_items[ text_stat_pointer->no_of_misc-1 ]	\
    .type = type_of_misc;						\
									\
    /* Set value */							\
    text_stat_pointer->misc_items[ text_stat_pointer->no_of_misc-1 ]	\
    .datum.tag_name = value_of_misc;					\
}


/*
 * IMPL - returns with error "not implemented yet"
 */

#define IMPL(code)		\
{				\
    kom_errno = KOM_NOT_IMPL;	\
    return code;		\
}

/*
 * A value of the following type are returned from access_perm() and
 * fast_access_perm(). They are used to see how much ACTPERS is allowed to
 * read/modify the data of a given conference.
 *
 * access_perm() alway returns the "highest" from this list.
 * fast_access_perm() avoids reading the conference struct. It will only
 *		return "unlimited" if the conference is secret and ACTPERS
 *		is not a member of the conference. fast_access_perm() is used
 *		in lookup_name() which sometimes have to check the access
 *		permissions of _all_ conferences. If access_perm() was used
 *		_all_ conference statuses would have to be read in into the
 *		cache in a single atomic call, and that would mean that the
 *		cache would overflow if there are many conferences.
 *		Now only the conference statuses for secret conferences of
 *		which ACTPERS is not a member have to be read in.
 */

typedef enum {
    error,			/* The conf doesn't exist or other error. */
    none,			/* A secret conference. */
    read_protected,		/* An rd_prot conference. */
    limited,			/* An open conference. */
    member,			/* ACTPERS is a member of the conference. */
    unlimited			/* ACTPERS is supervisor of the conference.  */
} Access;



/*
 * Functions which manipulate the CONFERENCE struct.
 */

extern Bool
legal_passwd(const String pwd);

extern Success
do_set_passwd( Password        pwd,
	      const String   new_pwd);


extern Success
chk_passwd( Password   pwd,
	   const String     s );


/*
 * Locate the Member struct in CONF_C for person PERS_NO
 */

extern Member *
locate_member(Pers_no      pers_no,
	      Conference * conf_c);


/*
 * Return TRUE if ACTPERS is a supervisor to CONF.
 */

extern Bool		
is_supervisor(Conf_no      conf,
	      Conference * conf_c);/* Conference status for CONF or NULL */



/*
 * Add text_no to the list of texts in a conference. Return the local number
 * the text gets in this conference.
 */

extern Local_text_no
add_text_in_conf(Conference * conf_c,
		 Text_no      text_no);


/*
 * Set the global text_no of a certain local text_no if that local text_no
 * exists in the conf. No action is taken if the local text_no doesn't exist.
 * This function is probably only used to set the number to zero when a text
 * is deleted.
 */

extern void
set_loc_no (Conference    * conf_c,
	    Local_text_no   loc_no,
	    Text_no	    text_no);



/*
 * This function is called whenever a person leaves a conf,
 * i e when he pepsi():s or logout():s.
 */

extern void
leave_conf(void);


/*
 * Change presentation of a conference. If text_no is 0, there will be
 * no presentation.
 */

extern Success
do_set_presentation(Conf_no 	 conf_no,
		    Conference * conf_c,
		    Text_no	 text_no);


/*
 * Change motd of a conference. If text_no is 0, there will be
 * no motd.
 */

extern Success
do_set_etc_motd(Conf_no      conf_no,
		Conference * conf_c,
		Text_no      text_no);



/*
 * Delete a conference. Delete all references to this conf.
 */

extern void
do_delete_conf (Conf_no      conf_no,
		Conference * conf_c); /* Not NULL */


/*
 * Functions that manupulate the PERSON struct
 */

/*
 * Find the data about PERS_P:s membership in CONF_NO.
 * Return NULL if not found
 */

extern Membership *
locate_membership(Conf_no     conf_no,
		  Person    * pers_p);



/*
 * Change user_area of a person. If text_no is 0, there will be
 * no user_area.
 */

extern Success
do_set_user_area(Pers_no     pers_no,
		 Person	   * pers_p,
		 Text_no     text_no);

/*
 * Mark a text. No check is done if pers_p is really allowed to mark it.
 * Use mark_type==0 to unmark the text.
 */

Success
do_mark_text(Pers_no    pers_no,
	     Person    *pers_p,		/* May be NULL */
	     Text_no    text_no,
	     Text_stat *text_s,		/* May be NULL */
	     u_char     mark_type);

/*
 * Return a pointer to a Mark if pers_no has marked the text text_no.
 * Otherwise, return NULL.
 */
Mark *
locate_mark(Pers_no pers_no,
	    Person *pers_p,	/* May be NULL. */
	    Text_no text_no);

/*
 * Delete a person. (The mailbox is not deleted);.
 */

extern Success
do_delete_pers (Pers_no pers_no);


/*
 * Functions which work on CONFERENCES and/or PERSONS.
 */

/*
 * Add a member to a conference. All errorchecking should already
 * be done when this function is called. The person must not already
 * be a member of the conference. It is _not_ an error to make WHERE bigger
 * than the number of conferences the person is a member in.
 */

extern void
do_add_member(Conf_no	   conf_no,  /* Conference to add a new member to. */
	      Conference * conf_c,   /* Conf. status. Must NOT be NULL.  */
	      Pers_no	   pers_no,  /* Person to be added. */
	      Person	 * pers_p,   /* Pers. status. Must NOT be NULL. */
	      u_char	   priority, /* Prioritylevel to assign to this conf */
	      u_short	   where);    /* Sequence number in the list */

/*
 * Return TRUE if ACTPERS has enough privileges to access VICTIM's data.
 * VICTIM is a person or a conference.
 * Meaning of return values:
 *	unlimited: ACTPERS is supervisor of VICTIM, or ACTPERS is admin,
 *		   or ACTPERS is VICTIM
 *	none:	   VICTIM is secret, and ACTPERS is not a member
 *	member:	   ACTPERS is a member in VICTIM, but doesn't have unlimited
 *		   access.
 *	limited:   otherwise.
 *	error:	   see kom_errno
 */

extern Access
access_perm(Conf_no 	  victim,
	    Conference	* victim_c);	/* May be NULL */

/*
 * Fast version of access_perm. This function does not check if ATCPERS is a
 * supervisor of the conference. This function should be used i calls where
 * a lot of conferences are checked to avoid readin in conferences from the
 * cache.
 *
 * BUG: If a person is supervisor of a secret conf he is not member in the
 *	 result will be 'none'.
 *
 *	unlimited: ACTPERS is admin, or ACTPERS is VICTIM
 *	none:	   VICTIM is secret, and ACTPERS is not a member
 *	member:	   ACTPERS is a member in VICTIM, but doesn't have unlimited
 *		   access.
 *	limited:   otherwise.
 *	error:	   see kom_errno
 */
Access
fast_access_perm(Conf_no victim);


/*
 * Return TRUE if NAME is a legal name
 */

extern Bool
legal_name( String name );


/*
 * Return TRUE if NAME is not already used
 */

extern Bool
unique_name( const String name, Conf_no conf_no );



/*
 * Change the priority of a certain conference in a person.
 */
extern void
do_change_priority (Membership * mship,
		    u_char	 priority,
		    u_short	 where,
		    Pers_no	 pers_no,
		    Person     * pers_p);


/*
 * Delete a member from a conference.
 * No checks are made on the parameters.
 * The dynamically allocated areas conf_c->members.members and
 * pers_p->confs are NOT reallocated since they will anyhow sooner or later
 * be flushed from core.
 */

extern Success
do_sub_member(Conf_no	   conf_no, /* Conf to delete member from. */
	      Conference * conf_c,  /* May be NULL */
	      Member     * member,  /* May be NULL */
	      Pers_no	   pers_no, /* Person to be deleted. */
	      Person	 * pers_p,  /* May be NULL */
	      Membership * mship);   /* Pointer to the persons membership in
				       conf., or NULL if not known. */


/*
 * Functions which deal with TEXTS
 */

/*
 * Count how many recipients and cc_recipients a text has.
 */

extern int
count_recipients( Text_stat  *t_stat );


/*
 * Count how many footnotes a text has.
 */

extern int
count_footn( Text_stat  *t_stat );


/*
 * Count how many commments a text has.
 */

extern int
count_comment( Text_stat  *t_stat );


/*
 * Check if ACTPERS is allowed to read this text.
 * Returns TRUE if he is allowed to read it.
 */

extern Bool
text_read_access(Text_no     text_no,
		 Text_stat * text_stat);



/*
 * Check if CONF_NO is a recipient of the text whose text_stat is given.
 */

extern Bool
is_recipient(Conf_no	 conf_no,
	     Text_stat * t_stat);



/*
 * Check if comment is a comment to parent.
 */
Bool
is_comment_to(Text_no    comment,
	      Text_stat *parent);


/*
 * Check if footnote is a footnote to parent.
 */
Bool
is_footnote_to(Text_no    footnote,
	       Text_stat *parent);


/*
 * Return the conference which the text goes to. This is normally conf_no, but
 * it may be a super_conf. If ACTPERS is not allowed to submit a text to
 * conf_no or a super_conf, return 0.
 */

extern Conf_no
submit_to(Conf_no	conf_no, /* The conference the user is trying to */
	  			 /* submit a text to. */
	  Conference  * conf_c);	 /* May be NULL */


/*
 * Insert a rec_time misc item to a text_status.
 * The item is put at position POS on the list. (0 == first)
 * Take no action if the misc_item at POS is a rec_time.
 * This function is only used when a person marks his letters as read.
 *
 *	Text_stat * text_stat_pointer	Textstatus to modify
 *	int	    pos			Where to insert rec_time
 */

extern void
do_add_rec_time (Text_stat    * text_stat_ptr,
		 int		pos);


/*
 * Say that FOOTNOTE is a footnote to TEXT.
 */

extern Success
do_add_footnote(Text_no footnote,
		Text_no text);



/*
 * Say that COMMENT is a comment to TEXT.
 */

extern Success
do_add_comment(Text_no comment,
	       Text_no text);


    
/*
 * Say that RECEIVER is a recipient of TEXT.
 */
extern Success
do_add_recpt(Text_no 	 text,
	     Text_stat * text_s, /* May be NULL */
	     Conf_no	 receiver);

   

extern Success
do_add_cc_recpt(Text_no new_text,
		Text_stat *text_s, /* May be NULL */
		Conf_no receiver);

    

/*
 * Return number of lines in a text
 */

extern u_short
count_lines( String str );



/*
 * Delete misc_info at location loc.
 * If it is a recpt, cc_recpt, comm_to or footn_to delete any
 * loc_no, rec_time, sent_by or sent_at that might follow it.
 *
 * Note that the Misc_info is not reallocated.
 */

extern void
do_delete_misc (u_short	  * no_of_misc,
		Misc_info * misc,
		int	    loc);


/*
 * Delete a recipient from a text
 */
extern Success
do_sub_recpt (Text_no	     text_no,
	      Text_stat    * text_s,
	      Conf_no	     conf_no,
	      Conference   * conf_s );


/*
 * Delete the link between comment and comment_to.
 */
void
do_sub_comment (Text_no	       comment,
		Text_stat    * text_s,
		Text_no	       comment_to,
		Text_stat    * parent_s );

/*
 * Delete the link between footnote and footnote_to.
 */
void
do_sub_footnote (Text_no       footnote,
		Text_stat    * text_s,
		Text_no	       footnote_to,
		Text_stat    * parent_s );


/*
 * Check if ACTPERS has sent this text to conference CONF_NO
 */
extern Bool
is_sender(Text_stat * text_s,
	  Conf_no     conf_no);


/*
 * Check if ACTPERS has sent this text as a comment to parent.
 */
Bool
is_comm_sender(Text_stat * text_s,
	       Text_no     parent);


/*
 * Check if ACTPERS has sent this text as a footnote to parent.
 */
extern Bool
is_footn_sender(Text_stat * text_s,
		Text_no     parent);

    
/*
 * Check if ACTPERS is allowed to add a footnote to a text. Sets errno if
 * there is an error.
 */

extern Success
check_footn(Text_stat * t_stat);


/*
 * Check if ACTPERS is allowed to add a comment to a text. Sets errno if
 * there is an error. Note that it is allowed to comment a text even if
 * you are not allowed to read it.
 */

extern Success
check_comm(Text_stat * t_stat);


/*
 * Check if pers_no is a member in any of the recipients or cc_recipients
 * of text_s
 */
extern  Bool
is_member_in_recpt(Person    * person,
		   Text_stat * text_s);
extern void
forced_leave_conf(Pers_no pers_no,
		  Conf_no conf_no);