1 /*******************************************************************************
5 ** $XConsortium: fns.c /main/3 1995/11/03 10:26:30 rswiston $
7 ** RESTRICTED CONFIDENTIAL INFORMATION:
9 ** The information in this document is subject to special
10 ** restrictions in a confidential disclosure agreement between
11 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
13 ** Sun's specific written approval. This document and all copies
14 ** and derivative works thereof must be returned or destroyed at
17 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 *******************************************************************************/
22 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
23 * (c) Copyright 1993, 1994 International Business Machines Corp. *
24 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
25 * (c) Copyright 1993, 1994 Novell, Inc. *
30 static char sccsid[] = "@(#)fns.c 1.3 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
34 * Copyright 1993 Sun Microsystems, Inc. All rights reserved
39 #include <EUSCompat.h>
57 extern char *strdup(const char *);
58 extern FILE *fdopen(int, const char *);
61 /* Data used by registration thread */
62 typedef struct _Registration_data {
67 static void *registration_thr(void *data);
69 static int register_calendar(const char *username, const char *location);
72 * Register a calendar location in FNS.
75 cm_register_calendar(const char *username, const char *location)
80 Registration_data *data;
82 data = (Registration_data *)malloc(sizeof(Registration_data));
88 data->username = strdup(username);
89 data->location = strdup(location);
91 error = thr_create(NULL, 0, registration_thr, data, THR_DETACHED, NULL);
94 printf("Could not create registration thread\n");
100 return cmfns_register_calendar(username, location);
106 registration_thr(void *data)
109 Registration_data *reg_data;
111 DP(("registration_thr: THREAD ENTER\n"));
116 reg_data = (Registration_data *)data;
118 DP(("registration_thr: Registering calendar\n"));
119 cmfns_register_calendar(reg_data->username, reg_data->location);
121 DP(("registration_thr: Registration complete. Freeing data\n"));
122 free(reg_data->username);
123 free(reg_data->location);
125 DP(("registration_thr: THREAD EXIT\n"));
133 * Extract the FNS name out of a file or directory. In the case of a
134 * file it should have the format of
138 * fns:name:for:the:fns:object
140 * In the case of a directory this routine looks for a file called
141 * ".FNSName" in the directory specified. This file should have the
142 * format described above.
144 * Caller is responsible for providing the buffer to place the name in.
147 * -1 Internal error or corrupted file
148 * 0 Could not access file/directory
149 * 1 Success. 'name' contains the FNS name
152 cmfns_name_from_file(
153 const char *path, /* Path to file to get name from */
154 char *name, /* Buffer to put name in */
155 int len) /* Length of buffer */
163 if ((fd = open(path, O_RDONLY)) < 0) {
167 if (fstat(fd, &statb) < 0) {
172 if (S_ISDIR(statb.st_mode)) {
175 /* path points to a directory. Look for .FNSName file */
177 newpath = (char *)malloc(strlen(path) + strlen(FNS_FILE) + 2);
178 if (newpath == NULL) {
181 sprintf(newpath, "%s/%s", path, FNS_FILE);
182 if ((fp = fopen(newpath, "r")) == NULL) {
188 if ((fp = fdopen(fd, "r")) == NULL) {
194 /* Get line from file */
195 if (fgets(name, len, fp) == NULL) {
200 /* Make sure we got a full line */
201 p = strrchr(name, '\n');
204 * If it is a comment line or we got a partial line
207 } while (*name == '#' || p == NULL);
209 /* Should have the name. Wipe out newline */
215 #endif /* FNS_DEMO */