dtcm: Resolve CID 87822
[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 #if !defined(linux)
45 extern char * strdup(const char *);
46 #endif
47
48 /*
49  * calendar_name@host[.domain] -> calendar_name
50  */
51 extern char *
52 _DtCmsTarget2Name(char *target)
53 {
54         return(_DtCmGetPrefix(target, '@'));
55 }
56  
57 /*
58  * calendar_name@host[.domain] -> host[.domain]
59  */
60 extern char *
61 _DtCmsTarget2Location(char *target)
62 {
63         char *ptr;
64
65         if (target == NULL)
66                 return (NULL);
67
68         if (ptr = strchr(target, '@')) {
69                 return (strdup(++ptr));
70         } else
71                 return (NULL);
72 }
73  
74 /*
75  * calendar_name@host[.domain] -> host
76  */
77 extern char *
78 _DtCmsTarget2Host(char *target)
79 {
80         char *location, *host;
81  
82         if ((location = _DtCmsTarget2Location(target)) != NULL) {
83                 host = _DtCmGetPrefix(location, '.');
84                 free(location);
85                 return(host);
86         } else
87                 return(NULL);
88 }
89
90 /*
91  * calendar_name@host[.domain] -> domain
92  */
93 extern char *
94 _DtCmsTarget2Domain(char *target)
95 {
96         char *location, *domain, *ptr;
97  
98         if ((location = _DtCmsTarget2Location(target)) != NULL) {
99                 if (ptr = strchr(location, '.'))
100                         domain = strdup(++ptr);
101                 else
102                         domain = NULL;
103                 free(location);
104                 return(domain);
105         } else
106                 return(NULL);
107 }
108