Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtcm / server / utility.c
1 /* $XConsortium: utility.c /main/4 1995/11/09 12:54:25 rswiston $ */
2 /*
3  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
4  *  (c) Copyright 1993, 1994 International Business Machines Corp.
5  *  (c) Copyright 1993, 1994 Novell, Inc.
6  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
7  */
8
9 #include <EUSCompat.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <rpc/rpc.h>
14 #if defined(SunOS) || defined(USL) || defined(__uxp__)
15 #include <netdb.h>
16 #include <sys/systeminfo.h>
17 #endif
18
19 #include "utility.h"
20 #include "lutil.h"
21
22 extern char * strdup(const char *);
23
24 /*
25  * calendar_name@host[.domain] -> calendar_name
26  */
27 extern char *
28 _DtCmsTarget2Name(char *target)
29 {
30         return(_DtCmGetPrefix(target, '@'));
31 }
32  
33 /*
34  * calendar_name@host[.domain] -> host[.domain]
35  */
36 extern char *
37 _DtCmsTarget2Location(char *target)
38 {
39         char *ptr;
40
41         if (target == NULL)
42                 return (NULL);
43
44         if (ptr = strchr(target, '@')) {
45                 return (strdup(++ptr));
46         } else
47                 return (NULL);
48 }
49  
50 /*
51  * calendar_name@host[.domain] -> host
52  */
53 extern char *
54 _DtCmsTarget2Host(char *target)
55 {
56         char *location, *host;
57  
58         if ((location = _DtCmsTarget2Location(target)) != NULL) {
59                 host = _DtCmGetPrefix(location, '.');
60                 free(location);
61                 return(host);
62         } else
63                 return(NULL);
64 }
65
66 /*
67  * calendar_name@host[.domain] -> domain
68  */
69 extern char *
70 _DtCmsTarget2Domain(char *target)
71 {
72         char *location, *domain, *ptr;
73  
74         if ((location = _DtCmsTarget2Location(target)) != NULL) {
75                 if (ptr = strchr(location, '.'))
76                         domain = strdup(++ptr);
77                 else
78                         domain = NULL;
79                 free(location);
80                 return(domain);
81         } else
82                 return(NULL);
83 }
84