dtcm: Resolve CID 87822
[oweals/cde.git] / cde / programs / dtcm / libDtCmP / util.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*******************************************************************************
24 **
25 **  util.h
26 **
27 **  static char sccsid[] = "@(#)util.h 1.38 94/12/20 Copyr 1991 Sun Microsystems, Inc."; 
28 **
29 **  $XConsortium: util.h /main/5 1995/11/03 10:39:22 rswiston $
30 **
31 **  RESTRICTED CONFIDENTIAL INFORMATION:
32 **
33 **  The information in this document is subject to special
34 **  restrictions in a confidential disclosure agreement between
35 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
36 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
37 **  Sun's specific written approval.  This document and all copies
38 **  and derivative works thereof must be returned or destroyed at
39 **  Sun's request.
40 **
41 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
42 **
43 *******************************************************************************/
44
45 /*                                                                      *
46  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
47  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
48  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
49  * (c) Copyright 1993, 1994 Novell, Inc.                                *
50  */
51
52 #ifndef _UTIL_H
53 #define _UTIL_H
54
55 #include <sys/types.h>
56 #include <X11/Xlib.h>
57 #include <csa.h>
58 #include "ansi_c.h"
59 #include "timeops.h"
60 #include "props.h"
61
62
63 #define DATAVER1        1       /* RPC versions 1 & 2 */
64 #define DATAVER2        2       /* RPC version 3 */
65 #define DATAVER3        3       /* RPC version 4 and RPC version 5 with
66                                    old file store */
67 #define DATAVER4        4       /* RPC version 5 with new data store */
68 #define DATAVER_ARCHIVE -1      /* archive version.  Nothing is read_only */
69
70
71 #define MAXSTRING       80
72 #define CERROR          1
73 #define PWERROR         2
74 #define FILEERROR       3
75 #define SPACEERROR      4
76 #define DOTS(a)         (a[0]=='.' && (a[1]==0 || (a[1]=='.' && a[2]==0)))
77
78 typedef struct lines {
79         char            *s;
80         struct lines    *next;
81 } Lines;
82
83 typedef enum {appt_read, appt_write} Allocation_reason;
84
85 /*
86 **  Structure for list of properties
87 */
88 typedef struct Pentry {
89         char            *property_name;
90         char            *property_value;
91         struct Pentry   *next;
92 } Pentry;
93
94 typedef enum {
95         ORDER_MDY,
96         ORDER_DMY,
97         ORDER_YMD
98 } OrderingType;
99  
100 typedef enum {
101         SEPARATOR_BLANK,
102         SEPARATOR_SLASH,
103         SEPARATOR_DOT,
104         SEPARATOR_DASH
105 } SeparatorType;
106
107 /*
108  * This convenience structure is used by the utility functions to set pointers
109  * to the actual data array so hard coding indexes into the array elsewhere
110  * in the front end isn't necessary.
111  */
112 typedef struct {
113         /*
114          * Read-only attributes
115          */
116         CSA_attribute   *identifier;
117         CSA_attribute   *modified_time;
118         CSA_attribute   *author;
119         CSA_attribute   *number_recurrence;
120
121         /*
122          * Read-write attributes
123          */
124         CSA_attribute   *time;
125         CSA_attribute   *type;
126         CSA_attribute   *subtype;
127         CSA_attribute   *private;
128         CSA_attribute   *end_time;
129         CSA_attribute   *show_time;
130         CSA_attribute   *what;
131         CSA_attribute   *state;
132         CSA_attribute   *repeat_type;
133         CSA_attribute   *repeat_times;
134         CSA_attribute   *repeat_interval;
135         CSA_attribute   *repeat_week_num;
136         CSA_attribute   *recurrence_rule;
137         CSA_attribute   *beep;
138         CSA_attribute   *flash;
139         CSA_attribute   *mail;
140         CSA_attribute   *popup;
141         CSA_attribute   *sequence_end_date;
142
143         /*
144          * The actual name array and count
145          */
146
147         CSA_attribute_reference *names;
148         int             num_names;
149
150         /*
151          * The actual data array and count
152          */
153         CSA_attribute   *attrs;
154         CSA_uint32      count;
155
156         /* Whether the structure has been filled in with a query */
157
158         int             filled;
159         Allocation_reason reason;
160         
161         /* the version of the back end this appointment structure 
162            was intended for */
163
164         int             version;
165 } Dtcm_appointment;
166
167 /*
168  * This convenience structure is used by the entry_to_cal, attrs_to_cal, and
169  * cal_to_attrs utility functions
170  */
171 typedef struct {
172         /*
173          * Read-only attributes
174          */
175         CSA_attribute   *cal_name;
176         CSA_attribute   *server_version;
177         CSA_attribute   *num_entries;
178         CSA_attribute   *cal_size;
179
180         /*
181          * Read-write attributes
182          */
183         CSA_attribute   *access_list;
184         CSA_attribute   *time_zone;
185
186         /*
187          * The actual name array and count
188          */
189
190         CSA_attribute_reference *names;
191         int             num_names;
192
193         /*
194          * The actual data array and count
195          */
196         CSA_attribute           *attrs;
197         CSA_uint32              count;
198
199         /* Whether the structure has been filled in with a query */
200
201         int             filled;
202         Allocation_reason reason;
203         
204         /* the version of the back end this calendar structure 
205            was intended for */
206
207         int             version;
208 } Dtcm_calendar;
209
210 /*
211  * Utility functions to to provide pointers into the arrays passed back and
212  * forth to the backend.  These functions and structures make hard coding
213  * indexes into the arrays unnecessary.
214  */
215 extern Dtcm_appointment *allocate_appt_struct   P((Allocation_reason , int, ...));
216 extern CSA_return_code  query_appt_struct       P((CSA_session_handle, 
217                                                    CSA_entry_handle, 
218                                                    Dtcm_appointment *));
219 extern Dtcm_calendar    *allocate_cal_struct    P((Allocation_reason, int, ...));
220 extern CSA_return_code  query_cal_struct        P((CSA_session_handle, 
221                                                    Dtcm_calendar *));
222 extern void             free_appt_struct        P((Dtcm_appointment**));
223 extern void             free_cal_struct         P((Dtcm_calendar**));
224
225 extern boolean_t        cal_ident_index_ro      P((int, int));
226 extern boolean_t        entry_ident_index_ro    P((int, int));
227 extern CSA_enum         cal_ident_index_tag     P((int));
228 extern CSA_enum         entry_ident_index_tag   P((int));
229 extern boolean_t        ident_name_ro   P((char*, int));
230 extern void             initialize_cal_attr     P((int, CSA_attribute*,
231                                                    Allocation_reason, int));
232 extern void             initialize_entry_attr   P((int, CSA_attribute*,
233                                                    Allocation_reason, int));
234 extern void             set_appt_links          P((Dtcm_appointment*));
235 extern void             set_cal_links           P((Dtcm_calendar*));
236 extern void             scrub_cal_attr_list     P((Dtcm_calendar*));
237 extern void             setup_range             P((CSA_attribute**,
238                                                    CSA_enum**, int*, time_t,
239                                                    time_t, CSA_sint32, CSA_sint32,
240                                                    boolean_t, int));
241 extern void             free_range              P((CSA_attribute**,
242                                                    CSA_enum**, int));
243
244 /*
245  * Other utilty functions
246  */
247 extern int              blank_buf               P((char*));
248 extern int              embedded_blank          P((char*));
249 extern char             *ckalloc                P(());
250 extern char             *cm_def_printer         P(());
251 extern char             *cm_get_credentials     P(());
252 extern char             *cm_get_local_domain    P(());
253 extern char             *cm_get_local_host      P(());
254 extern char             *cm_get_uname           P(());
255 extern char             *cm_pqtarget            P((char*));
256 extern char             *cm_strcat              P((char*, char*));
257 extern char             *cm_strcpy              P((char*, char*));
258 extern char             *cm_strdup              P((char*));
259 extern int              cm_strlen               P((char*));
260 extern char             *cm_target2domain       P((char*));
261 extern char             *cm_target2host         P((char*));
262 extern char             *cm_target2location     P((char*));
263 extern char             *cm_target2name         P((char*));
264 extern char             *cr_to_str              P((char*));
265 extern void             destroy_lines           P((Lines*));
266 extern void             expand_esc_chars        P((char*));
267 extern char             *get_head               P((char*, char));
268 extern char             *get_tail               P((char*, char));
269 extern void             print_tick              P((time_t));
270 extern boolean_t        same_path               P((char*, char*));
271 extern boolean_t        same_user               P((char*, char*));
272 extern char             *str_to_cr              P((char*));
273 extern char             *strncat                P(());
274 extern char             *substr                 P((char*, int, int n));
275 extern void             syserr                  P((char*, int, int, int));
276 extern Lines            *text_to_lines          P((char*, int));
277 extern int              get_data_version        P((CSA_session_handle));
278 extern int              get_server_version      P((CSA_session_handle));
279 extern CSA_sint32       privacy_set             P((Dtcm_appointment *));
280 extern CSA_sint32       showtime_set            P((Dtcm_appointment *));
281 extern int              max                     P((int, int));
282 extern int              min                     P((int, int));
283 extern int              parse_date              P((OrderingType, SeparatorType, char*, char*, char*, char*));
284
285 extern int              datestr2mdy             P((char*, OrderingType, SeparatorType, char*));
286 extern void             format_tick             P((time_t, OrderingType, SeparatorType, char*));
287 extern void             format_time             P((Tick, DisplayType, char*));
288
289 /*
290  * In Motif you can't associate user data with items in a list.  To get around
291  * this we have the following simple functions that maintain a list of
292  * user data.  We use the intrinscs coding style to reinforce the
293  * relationship these routines have to the XmList* functions.
294  */
295 typedef struct _CmDataItem {
296         struct _CmDataItem      *next;
297         void                    *data;
298 } CmDataItem;
299
300 typedef struct _CmDataList {
301         CmDataItem      *head;
302         CmDataItem      *tail;
303         int             count;
304 } CmDataList;
305
306 extern CmDataList       *CmDataListCreate       P((void));
307 extern void             CmDataListDestroy       P((CmDataList *, int));
308 extern int              CmDataListAdd           P((CmDataList *, void *, int));
309 extern void             *CmDataListGetData      P((CmDataList *, int));
310 extern void             *CmDataListDeletePos    P((CmDataList *, int, int));
311 extern void             CmDataListDeleteAll     P((CmDataList *, int));
312
313
314 #endif