aux-items.h 10.6 KB
Newer Older
1
/*
2
 * $Id: aux-items.h,v 1.3 1998/06/14 14:50:44 byers Exp $
3
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
42
43
44
45
46
47
48
49
50
 * Copyright (C) 1994, 1995, 1996  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. 
 */
/* 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)


/*
 * Add aux item ITEM to Aux_item_list LIST. COUNTER is the highest aux_no
 * in the list (counter + 1 is the next aux_no
 */

#define ADD_AUX_ITEM(list, item, counter)                               \
{                                                                       \
    (list).items =                                                      \
        srealloc((list).items,                                          \
                 ((list).length + 1) * sizeof(Aux_item));               \
David Byers's avatar
David Byers committed
51
    copy_aux_item(&(list).items[(list).length], &item);                 \
52
53
54
55
56
57
    (counter) += 1;                                                     \
    (list).items[(list).length].aux_no = (counter);                     \
    (list).length += 1;                                                 \
}


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
/* 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

/* Valid values for object_type fields */

#define OTHER_OBJECT_TYPE 0
#define TEXT_OBJECT_TYPE 1
#define CONF_OBJECT_TYPE 2

typedef struct Aux_item_trigger_data_s
{
    short           action;
    short           object_type;
    unsigned long   item_index;
    unsigned long   object_no;
    void          * object;
} Aux_item_trigger_data;

typedef void (*Aux_item_trigger)(Aux_item_trigger_data *);

86
87
88
89
90
91
92
93
94
95
96
typedef struct Aux_item_definition_s {
    char                   *name;
    unsigned long           tag;
    Aux_item_flags          clear_flags;
    Aux_item_flags          set_flags;
    Bool                    author_only;
    Bool                    supervisor_only;
    Bool                    one_per_person;
    Bool                    may_not_delete;
    unsigned long           inherit_limit;
    Bool                    texts;
97
    short                   text_a; /* When can we add items of this type */
98
    Bool                    confs;
99
    short                   conf_a; /* When can we add items of this type */
100
101
102
103
    Bool                    letterboxes;
    Bool                    system;
    char                   *validate_regexp;
    struct re_pattern_buffer *cached_re_buf;
104
105
106
107
108
109
    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;
110
111
112
    struct Aux_item_definition_s *next;
} Aux_item_definition;

113
114
115
116
117
118
119
typedef struct
{
    char *name;
    Aux_item_trigger function;
} Aux_item_trigger_mapping;

extern Aux_item_trigger_mapping aux_item_triggers [];
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
extern Aux_item_definition empty_aux_item_definition;

/*
 * Predefined AUX Items
 */

#define AUX_Content_Type        1
#define AUX_Dont_Comment        2
#define AUX_Private_Comment     3
#define AUX_Quick_Reply         4





/* 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,
141
142
143
                       unsigned long *counter, Pers_no target_creator,
                       Bool creating, short object_type,
                       unsigned long object_no, void *object);
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161



/* 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,
162
163
                       unsigned long start_looking_at, Bool creating,
                       short object_type);
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184




/* 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. */

void prepare_aux_item_list(Aux_item_list *list, Pers_no creator);
void prepare_aux_item(Aux_item *item, Pers_no creator,
                      Aux_item_definition *def);



/* 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);


185
186
187
188
/* Get the function pointer for a named trigger */

Aux_item_trigger aux_item_find_trigger(char *trigger_name);

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* Get a pointer to the item in list with aux-no aux_no. Returns
 * NULL if there is no such item */

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,
                          Pers_no viewer,
                          Person *viewer_p);


/* 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,
211
212
213
214
                          Aux_item_list *list_to_delete_from,
                          short object_type,
                          unsigned long object_no,
                          void *object);
215
216
217
218
219
220
221



/* 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,
222
223
224
225
                            Aux_item_list *list_to_undelete_from,
                            short object_type,
                            unsigned long object_no,
                            void *object);
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241



/* 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 */
  
242
243
244
void text_stat_add_aux_item_list(Text_stat *text_s,
                                 Text_no text_no,
                                 Aux_item_list *item_list,
245
246
247
248
249
250
251
252
253
254
255
256
                                 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,
257
258
                                          Pers_no item_creator,
                                          Bool creating);
259
260
261
262
263
264
265



Success conf_stat_check_add_aux_item(Conference          *conf,
                                     Conf_no        conf_no,
                                     Aux_item            *item,
                                     Pers_no              creator,
266
267
                                     Aux_item_definition *def,
                                     Bool creating);
268
269
270
271
272

Success
conf_stat_check_add_aux_item_list(Conference    *conf,
                                  Conf_no        conf_no,
                                  Aux_item_list *list,
273
274
                                  Pers_no        creator,
                                  Bool creating);
275
276
277
278
279
280
281
282
283
284
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);
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299
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);

void
initialize_aux_items(char *);

void
aux_item_definition_add(Aux_item_definition *);