bdef3ddc62b1f59bd8a98bd5edf0ae884f37ce94
[framework/uifw/xorg/lib/libsm.git] / src / sm_misc.c
1 /*
2
3 Copyright 1993, 1998  The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 */
26
27 /*
28  * Author: Ralph Mor, X Consortium
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 #include <X11/SM/SMlib.h>
35 #include "SMlibint.h"
36 #include <stdio.h>
37
38 /*
39  * Free property
40  */
41
42 void
43 SmFreeProperty(SmProp *prop)
44 {
45     if (prop)
46     {
47         int i;
48
49         if (prop->name)
50             free (prop->name);
51         if (prop->type)
52             free (prop->type);
53         if (prop->vals)
54         {
55             for (i = 0; i < prop->num_vals; i++)
56                 if (prop->vals[i].value)
57                     free ((char *) prop->vals[i].value);
58             free ((char *) prop->vals);
59         }
60
61         free ((char *) prop);
62     }
63 }
64
65
66 /*
67  * Free reason messages
68  */
69
70 void
71 SmFreeReasons(int count, char **reasonMsgs)
72 {
73     if (reasonMsgs)
74     {
75         int i;
76
77         for (i = 0; i < count; i++)
78             free (reasonMsgs[i]);
79
80         free ((char *) reasonMsgs);
81     }
82 }
83
84
85 \f
86 /*
87  * Smc informational functions
88  */
89
90 int
91 SmcProtocolVersion(SmcConn smcConn)
92 {
93     return (smcConn->proto_major_version);
94 }
95
96
97 int
98 SmcProtocolRevision(SmcConn smcConn)
99 {
100     return (smcConn->proto_minor_version);
101 }
102
103
104 char *
105 SmcVendor(SmcConn smcConn)
106 {
107     char *string = (char *) malloc (strlen (smcConn->vendor) + 1);
108
109     strcpy (string, smcConn->vendor);
110
111     return (string);
112 }
113
114
115 char *
116 SmcRelease(SmcConn smcConn)
117 {
118     char *string = (char *) malloc (strlen (smcConn->release) + 1);
119
120     strcpy (string, smcConn->release);
121
122     return (string);
123 }
124
125
126 char *
127 SmcClientID(SmcConn smcConn)
128 {
129     char *clientId = (char *) malloc (strlen (smcConn->client_id) + 1);
130
131     strcpy (clientId, smcConn->client_id);
132
133     return (clientId);
134 }
135
136
137 IceConn
138 SmcGetIceConnection(SmcConn smcConn)
139 {
140     return (smcConn->iceConn);
141 }
142
143
144 \f
145 /*
146  * Sms informational functions
147  */
148
149 int
150 SmsProtocolVersion(SmsConn smsConn)
151 {
152     return (smsConn->proto_major_version);
153 }
154
155
156 int
157 SmsProtocolRevision(SmsConn smsConn)
158 {
159     return (smsConn->proto_minor_version);
160 }
161
162
163 char *
164 SmsClientID(SmsConn smsConn)
165 {
166     char *clientId = (char *) malloc (strlen (smsConn->client_id) + 1);
167
168     strcpy (clientId, smsConn->client_id);
169
170     return (clientId);
171 }
172
173
174 IceConn
175 SmsGetIceConnection(SmsConn smsConn)
176 {
177     return (smsConn->iceConn);
178 }