Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtcm / server / utility.c
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 /* $XConsortium: utility.c /main/4 1995/11/09 12:54:25 rswiston $ */
24 /*
25  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
26  *  (c) Copyright 1993, 1994 International Business Machines Corp.
27  *  (c) Copyright 1993, 1994 Novell, Inc.
28  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
29  */
30
31 #include <EUSCompat.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <rpc/rpc.h>
36 #if defined(SunOS) || defined(USL) || defined(__uxp__)
37 #include <netdb.h>
38 #include <sys/systeminfo.h>
39 #endif
40
41 #include "utility.h"
42 #include "lutil.h"
43
44 extern char * strdup(const char *);
45
46 /*
47  * calendar_name@host[.domain] -> calendar_name
48  */
49 extern char *
50 _DtCmsTarget2Name(char *target)
51 {
52         return(_DtCmGetPrefix(target, '@'));
53 }
54  
55 /*
56  * calendar_name@host[.domain] -> host[.domain]
57  */
58 extern char *
59 _DtCmsTarget2Location(char *target)
60 {
61         char *ptr;
62
63         if (target == NULL)
64                 return (NULL);
65
66         if (ptr = strchr(target, '@')) {
67                 return (strdup(++ptr));
68         } else
69                 return (NULL);
70 }
71  
72 /*
73  * calendar_name@host[.domain] -> host
74  */
75 extern char *
76 _DtCmsTarget2Host(char *target)
77 {
78         char *location, *host;
79  
80         if ((location = _DtCmsTarget2Location(target)) != NULL) {
81                 host = _DtCmGetPrefix(location, '.');
82                 free(location);
83                 return(host);
84         } else
85                 return(NULL);
86 }
87
88 /*
89  * calendar_name@host[.domain] -> domain
90  */
91 extern char *
92 _DtCmsTarget2Domain(char *target)
93 {
94         char *location, *domain, *ptr;
95  
96         if ((location = _DtCmsTarget2Location(target)) != NULL) {
97                 if (ptr = strchr(location, '.'))
98                         domain = strdup(++ptr);
99                 else
100                         domain = NULL;
101                 free(location);
102                 return(domain);
103         } else
104                 return(NULL);
105 }
106