aux-items.h 11.1 KB
Newer Older
1
/*
2
 * $Id: aux-items.h,v 1.13 1999/06/26 11:37:09 ceder Exp $
3
 * Copyright (C) 1994-1999  Lysator Academic Computer Association.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 *
 * 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. 
 */
/* Requires kom-types.h */


#define AUX_PREDEFINED_MIN      1
#define AUX_PREDEFINED_MAX      9999
#define AUX_CLIENT_SPECIFIC_MIN 10000
#define AUX_CLIENT_SPECIFIC_MAX 19999
#define AUX_EXPERIMENTAL_MIN    20000
#define AUX_EXPERIMENTAL_MAX    29999

#define AUX_IS_ILLEGAL(x) ((x) < 1)
#define AUX_IS_EXPERIMENTAL(x) ((x) >= AUX_EXPERIMENTAL_MIN && (x) <= AUX_EXPERIMENTAL_MAX)
#define AUX_IS_CLIENT_SPECIFIC(x) ((x) >= AUX_CLIENT_SPECIFIC_MIN && (x) <= AUX_CLIENT_SPECIFIC_MAX)
#define AUX_IS_PREDEFINED(x) (((x) >= AUX_PREDEFINED_MIN && (x) <= AUX_PREDEFINED_MAX) || (x) > AUX_EXPERIMENTAL_MAX)



42
43
44
45
46
47
48
49
50
51
52
/* Valid values for text_a etc. */

#define AUX_ITEM_ADD_ON_CREATE 1
#define AUX_ITEM_ADD_ON_MODIFY 2

/* Valid values for action trigger data field */

#define AUX_ITEM_ADD_ACTION    1
#define AUX_ITEM_DELETE_ACTION 2
#define AUX_ITEM_UNDELETE_ACTION 3

David Byers's avatar
David Byers committed
53
typedef struct Aux_item_definition_s Aux_item_definition;
54
55
56
57

typedef struct Aux_item_trigger_data_s
{
    short           action;
David Byers's avatar
David Byers committed
58
    Object_type     object_type;
59
60
61
    unsigned long   item_index;
    unsigned long   object_no;
    void          * object;
David Byers's avatar
David Byers committed
62
    Aux_item      * item;
63
64
65
66
} Aux_item_trigger_data;

typedef void (*Aux_item_trigger)(Aux_item_trigger_data *);

David Byers's avatar
David Byers committed
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
typedef enum {
    AUX_VALIDATE_FUNCTION,
    AUX_VALIDATE_REGEXP,
    AUX_VALIDATE_REJECT,
} Aux_item_validation_type;

typedef struct
{
    Aux_item                *item;
    Aux_item_definition     *def;
    Pers_no                  item_creator;
    Pers_no                  object_creator;
    Bool                     owner_check;
    Aux_item_list           *add_to_list;
    unsigned long            start_looking_at;
    Bool                     creating;
    Object_type              object_type;
} Aux_item_validation_data;

typedef Bool (*Aux_item_validation_function)(Aux_item_validation_data *);

typedef struct
{
    Aux_item_validation_type   type;
    union
    {
        struct
        {
            char                        *regexp;
            struct re_pattern_buffer    *cached_re_buf;
        } re;
        struct
        {
            Aux_item_validation_function function;
        } fn;
    } v;
} Aux_item_validator;



typedef struct
{
    const char *name;
    Aux_item_validation_function function;
} Aux_item_validator_mapping;

typedef struct
{
    const char *name;
    Aux_item_trigger function;
} Aux_item_trigger_mapping;

struct Aux_item_definition_s {
David Byers's avatar
David Byers committed
120
    char                   *  name;
David Byers's avatar
David Byers committed
121
122
123
    unsigned long             tag;
    Aux_item_flags            clear_flags;
    Aux_item_flags            set_flags;
David Byers's avatar
David Byers committed
124
    Bool                      disabled;
David Byers's avatar
David Byers committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    Bool                      author_only;
    Bool                      supervisor_only;
    Bool                      system_only;
    Bool                      one_per_person;
    Bool                      may_not_delete;
    unsigned long             inherit_limit;
    Bool                      texts;
    short                     text_a; /* When can we add items of this type */
    Bool                      confs;
    short                     conf_a; /* When can we add items of this type */
    Bool                      letterboxes;
    Bool                      system;
    unsigned long             num_validators;
    Aux_item_validator      * validators;
139
140
141
142
143
144
    unsigned long             num_delete_triggers;
    Aux_item_trigger        * delete_triggers;
    unsigned long             num_add_triggers;
    Aux_item_trigger        * add_triggers;
    unsigned long             num_undelete_triggers;
    Aux_item_trigger        * undelete_triggers;
145
    struct Aux_item_definition_s *next;
David Byers's avatar
David Byers committed
146
};
147

148

149
150
151
152
153
154
155
156
extern Aux_item_definition empty_aux_item_definition;

/* Inerit items from parent to target. counter is a pointer to
 * highest_aux_item or equivalent. target_creator is the creator
 * of the target object (author for texts, person for persons and
 * conference for conferences */

void aux_inherit_items(Aux_item_list *target, Aux_item_list *parent,
157
                       unsigned long *counter, Pers_no target_creator,
David Byers's avatar
David Byers committed
158
                       Bool creating, Object_type object_type,
159
                       unsigned long object_no, void *object);
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177



/* Check for permission to add item to some object. def is NULL or the
 * item definition. item_creator is the person creating the item.
 * object_creator is the person who created the object we're adding
 * the item to. owner_check is FALSE only if we don't want to check
 * author and supervisor related definition flags (when creating a
 * person or conference, for example.) add_to_list is the list of
 * items already on the object or NULL, and start_looking_at is the
 * first position in add_to_list that we should look at.
 *
 * If you think you need to call this, and you're not hacking functions
 * in aux-items.c, you should rethink your strategy. */

Bool aux_item_add_perm(Aux_item *item, Aux_item_definition *def,
                       Pers_no item_creator, Pers_no object_creator,
                       Bool owner_check, Aux_item_list *add_to_list,
178
                       unsigned long start_looking_at, Bool creating,
David Byers's avatar
David Byers committed
179
                       Object_type object_type);
180
181
182
183
184
185
186
187
188




/* Prepare the items in list for addition to an object. creator is the
 * person who will add the items. The items in list will be modified.
 * You need to call this before sending the list to any of the other
 * functions. */

189
void prepare_aux_item_list(Aux_item_list *list, Pers_no creator);
190
void prepare_aux_item(Aux_item *item, Pers_no creator,
191
                      Aux_item_definition *def);
192
193
194
195
196
197
198
199
200



/* Find the aux_item_definition for item. Returns a pointer to the
 * definition or NULL if the item's tag is invalid. */

Aux_item_definition *find_aux_item_definition(Aux_item *item);


201
202
203
204
/* Get the function pointer for a named trigger */

Aux_item_trigger aux_item_find_trigger(char *trigger_name);

David Byers's avatar
David Byers committed
205
206
207
208
/* Get the function pointer for a named validation function */

Aux_item_validation_function aux_item_find_validator(char *validator_name);

209
210
211
/* Get a pointer to the item in list with aux-no aux_no. Returns
 * NULL if there is no such item */

David Byers's avatar
David Byers committed
212
long find_aux_item_index(Aux_item_list *list, unsigned long aux_no);
213
214
215
216
217
218
219
220
221
222
223
Aux_item *find_aux_item(Aux_item_list *list, unsigned long aux_no);



/* Filter the items in original for sending to viewer. Result is a
 * pointer to an empty aux_item_list, in which copies of the items in
 * original will be places. All memory allocated in this call is
 * allocaed with tmp_alloc */

void filter_aux_item_list(Aux_item_list *original,
                          Aux_item_list *result,
David Byers's avatar
Server    
David Byers committed
224
                          Connection *conn);
225
226
227
228
229
230


/* delete items_to_delete from list_to_delete_from
 * list_to_delete_from and its elements may be modified */

void delete_aux_item_list(Number_list *items_to_delete,
231
                          Aux_item_list *list_to_delete_from,
David Byers's avatar
David Byers committed
232
                          Object_type object_type,
233
234
                          unsigned long object_no,
                          void *object);
235
236
237
238
239
240
241



/* undelete items in items_to_undelete from list_to_undelete_from
 * list_to_delete_from and its elements may be modified */

void undelete_aux_item_list(Number_list *items_to_undelete,
242
                            Aux_item_list *list_to_undelete_from,
David Byers's avatar
David Byers committed
243
                            Object_type object_type,
244
245
                            unsigned long object_no,
                            void *object);
246
247


David Byers's avatar
David Byers committed
248
249
250
void
commit_aux_item_list(Aux_item_list *list_to_commit);

251
252
253
254
255
256
257
258
259
260
261
262
263
264

/* Check if we may delete items_to_delete from list_to_delete_from
 * Elements in items_to_delete may be modified. Sets kom_errno,
 * err_stat and returns FAILURE if deletion of any single item is
 * not allowed */

Success check_delete_aux_item_list(Number_list *items_to_delete,
                                   Aux_item_list *list_to_delete_from);



/* Att item_list to the aux_item_list of text_s. item_creator is the
 * person who is adding the items. Does not check for permission first */
  
265
266
267
void text_stat_add_aux_item_list(Text_stat *text_s,
                                 Text_no text_no,
                                 Aux_item_list *item_list,
268
269
270
271
272
273
274
275
276
277
278
279
                                 Pers_no item_creator);



/* Check for permission to add items in list to aux_item_list
 * of text_s. item_creator is the person adding the items. Sets
 * kom_errno and err_stat and returns FAILURE if permission is
 * not granted. You MUST call perpare_aux_item_list on the list
 * before calling this! */

Success text_stat_check_add_aux_item_list(Text_stat *text_s,
                                          Aux_item_list *list,
280
281
                                          Pers_no item_creator,
                                          Bool creating);
282
283
284
285
286
287
288



Success conf_stat_check_add_aux_item(Conference          *conf,
                                     Conf_no        conf_no,
                                     Aux_item            *item,
                                     Pers_no              creator,
289
290
                                     Aux_item_definition *def,
                                     Bool creating);
291
292
293
294
295

Success
conf_stat_check_add_aux_item_list(Conference    *conf,
                                  Conf_no        conf_no,
                                  Aux_item_list *list,
296
297
                                  Pers_no        creator,
                                  Bool creating);
298
299
300
301
302
303
304
305
306
307
void
conf_stat_add_aux_item(Conference          *conf,
                       Conf_no              conf_no,
                       Aux_item            *item,
                       Aux_item_definition *def);
void
conf_stat_add_aux_item_list(Conference    *conf,
                            Conf_no        conf_no,
                            Aux_item_list *list,
                            Pers_no        creator);
308

309
310
311
312
313
314
315
316
317
void
system_add_aux_item_list(Info    *info,
                         Aux_item_list *item_list,
                         Pers_no        item_creator);

Success system_check_add_aux_item_list(Info *info,
                                       Aux_item_list *list,
                                       Pers_no creator);

David Byers's avatar
David Byers committed
318
319
void initialize_aux_items(char *);
void free_aux_item_definitions(void);
320

David Byers's avatar
David Byers committed
321
void aux_item_definition_add(Aux_item_definition *);
322
323

/* Parser function from aux-item-def.y. */
David Byers's avatar
David Byers committed
324
325
326
extern void parse_aux_item_definitions(char *file);