2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /*******************************************************************************
27 ** $XConsortium: fns.c /main/3 1995/11/03 10:26:30 rswiston $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
52 static char sccsid[] = "@(#)fns.c 1.3 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
56 * Copyright 1993 Sun Microsystems, Inc. All rights reserved
61 #include <EUSCompat.h>
79 extern char *strdup(const char *);
80 extern FILE *fdopen(int, const char *);
83 /* Data used by registration thread */
84 typedef struct _Registration_data {
89 static void *registration_thr(void *data);
91 static int register_calendar(const char *username, const char *location);
94 * Register a calendar location in FNS.
97 cm_register_calendar(const char *username, const char *location)
102 Registration_data *data;
104 data = (Registration_data *)malloc(sizeof(Registration_data));
110 data->username = strdup(username);
111 data->location = strdup(location);
113 error = thr_create(NULL, 0, registration_thr, data, THR_DETACHED, NULL);
116 printf("Could not create registration thread\n");
122 return cmfns_register_calendar(username, location);
128 registration_thr(void *data)
131 Registration_data *reg_data;
133 DP(("registration_thr: THREAD ENTER\n"));
138 reg_data = (Registration_data *)data;
140 DP(("registration_thr: Registering calendar\n"));
141 cmfns_register_calendar(reg_data->username, reg_data->location);
143 DP(("registration_thr: Registration complete. Freeing data\n"));
144 free(reg_data->username);
145 free(reg_data->location);
147 DP(("registration_thr: THREAD EXIT\n"));
155 * Extract the FNS name out of a file or directory. In the case of a
156 * file it should have the format of
160 * fns:name:for:the:fns:object
162 * In the case of a directory this routine looks for a file called
163 * ".FNSName" in the directory specified. This file should have the
164 * format described above.
166 * Caller is responsible for providing the buffer to place the name in.
169 * -1 Internal error or corrupted file
170 * 0 Could not access file/directory
171 * 1 Success. 'name' contains the FNS name
174 cmfns_name_from_file(
175 const char *path, /* Path to file to get name from */
176 char *name, /* Buffer to put name in */
177 int len) /* Length of buffer */
185 if ((fd = open(path, O_RDONLY)) < 0) {
189 if (fstat(fd, &statb) < 0) {
194 if (S_ISDIR(statb.st_mode)) {
197 /* path points to a directory. Look for .FNSName file */
199 newpath = (char *)malloc(strlen(path) + strlen(FNS_FILE) + 2);
200 if (newpath == NULL) {
203 sprintf(newpath, "%s/%s", path, FNS_FILE);
204 if ((fp = fopen(newpath, "r")) == NULL) {
210 if ((fp = fdopen(fd, "r")) == NULL) {
216 /* Get line from file */
217 if (fgets(name, len, fp) == NULL) {
222 /* Make sure we got a full line */
223 p = strrchr(name, '\n');
226 * If it is a comment line or we got a partial line
229 } while (*name == '#' || p == NULL);
231 /* Should have the name. Wipe out newline */
237 #endif /* FNS_DEMO */