Fix typo in license headers
[oweals/cde.git] / cde / lib / tt / lib / api / c / api_session_prop.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 libraries 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 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: api_session_prop.C /main/4 1995/11/28 19:22:54 cde-sun $                                                    
28 /*
29  *
30  * api_session_prop.cc
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  */
34
35 #include "mp/mp_c.h"
36 #include "api/c/tt_c.h"
37 #include "api/c/api_api.h"
38 #include "api/c/api_mp.h"
39 #include "api/c/api_handle.h"
40 #include "util/tt_audit.h"
41
42
43 char *
44 tt_session_prop(const char *sessid, const char *propname, int i)
45 {
46         _Tt_audit audit;
47         Tt_status status = audit.entry("Cri", TT_SESSION_PROP, sessid,
48                                         propname, i);
49         char *result;
50
51         if (status != TT_OK) {
52                 audit.exit((char *)error_pointer(status));
53                 return (char *)error_pointer(status);
54         }
55
56         result = _tt_session_prop(sessid, propname, i);
57         audit.exit(result);
58
59         return result;
60 }
61
62
63 Tt_status
64 tt_session_prop_add(const char *sessid, const char *propname, const char *value)
65 {
66         _Tt_audit audit;
67         Tt_status status = audit.entry("CrnI", TT_SESSION_PROP_ADD, sessid,
68                                         propname, value,
69                                         (char *) 0 == value ? 0 : strlen(value));
70
71         if (status != TT_OK) {
72                 audit.exit(status);
73                 return status;
74         }
75
76         status = _tt_session_prop_add(sessid, propname, value);
77         audit.exit(status);
78
79         return status;
80 }
81
82
83 int
84 tt_session_prop_count(const char *sessid, const char *propname)
85 {
86         _Tt_audit audit;
87         Tt_status status = audit.entry("Cr", TT_SESSION_PROP_COUNT,
88                                         sessid, propname);
89         int result;
90
91         if (status != TT_OK) {
92                 audit.exit(error_int(status));
93                 return error_int(status);
94         }
95
96         result = _tt_session_prop_count(sessid, propname);
97         audit.exit(result);
98
99         return result;
100 }
101
102
103 Tt_status
104 tt_session_prop_set(const char *sessid, const char *propname,
105                      const char *value)
106 {
107         _Tt_audit audit;
108         Tt_status status = audit.entry("CrnI", TT_SESSION_PROP_SET, sessid,
109                                            propname, value,
110                                            (char *) 0 == value ? 0 : strlen(value));
111
112         if (status != TT_OK) {
113                 audit.exit(status);
114                 return status;
115         }
116
117         status = _tt_session_prop_set(sessid, propname, value);
118         audit.exit(status);
119
120         return status;
121 }
122
123
124 Tt_status
125 tt_session_bprop(const char *sessid, const char *propname, int i,
126                  unsigned char **value, int *length)
127 {
128         _Tt_audit audit;
129         Tt_status status = audit.entry("Cri", TT_SESSION_BPROP, sessid,
130                                            propname, i);
131
132         if (status != TT_OK) {
133                 audit.exit(status);
134                 return status;
135         }
136
137         status = _tt_session_bprop(sessid, propname, i, value, length);
138         audit.exit(status);
139
140         return status;
141 }
142
143
144 Tt_status
145 tt_session_bprop_add(const char *sessid, const char *propname,
146                      const unsigned char *value, int length)
147 {
148         _Tt_audit audit;
149         Tt_status status = audit.entry("CrnI", TT_SESSION_BPROP_ADD, sessid,
150                                            propname, value, length);
151
152         if (status != TT_OK) {
153                 audit.exit(status);
154                 return status;
155         }
156
157         status = _tt_session_bprop_add(sessid, propname, value, length);
158         audit.exit(status);
159
160         return status;
161 }
162
163
164 Tt_status
165 tt_session_bprop_set(const char *sessid, const char *propname,
166                      const unsigned char *value, int length)
167 {
168         _Tt_audit audit;
169         Tt_status status = audit.entry("CrnI", TT_SESSION_BPROP_ADD, sessid,
170                                            propname, value, length);
171
172         if (status != TT_OK) {
173                 audit.exit(status);
174                 return status;
175         }
176
177         status = _tt_session_bprop_set(sessid, propname, value, length);
178         audit.exit(status);
179
180         return status;
181 }
182
183
184 char *
185 tt_session_propname(const char *sessid, int n)
186 {
187         _Tt_audit audit;
188         Tt_status status = audit.entry("Ci", TT_SESSION_PROPNAME, sessid, n);
189         char *result;
190
191         if (status != TT_OK) {
192                 audit.exit((char *)error_pointer(status));
193                 return (char *)error_pointer(status);
194         }
195
196         result = _tt_session_propname(sessid, n);
197         audit.exit(result);
198
199         return result;
200 }
201
202
203 int
204 tt_session_propnames_count(const char *sessid)
205 {
206         _Tt_audit audit;
207         Tt_status status = audit.entry("C", TT_SESSION_PROPNAMES_COUNT,
208                                             sessid);
209         int result;
210
211         if (status != TT_OK) {
212                 audit.exit(error_int(status));
213                 return error_int(status);
214         }
215
216         result = _tt_session_propnames_count(sessid);
217         audit.exit(result);
218
219         return result;
220 }
221
222
223 /*
224  * return the character string value of the specified property on the session
225  */
226 char *
227 _tt_session_prop(const char *sessid, const char *propname, int i)
228 {
229         unsigned char *v;
230         int junk;
231         Tt_status rc;
232
233         rc = _tt_session_bprop(sessid,propname,i, &v, &junk);
234         if (rc==TT_OK) {
235                 return (char *)v;
236         } else {
237                 return (char *)error_pointer(rc);
238         }
239 }
240
241 /* 
242  * Return the ith value of the specified property on the session
243  */
244 Tt_status
245 _tt_session_bprop(const char *sessid, const char *propname,
246                   int i, unsigned char **value,  int *length)
247 {
248         _Tt_string      val;
249         Tt_status       err;
250         _Tt_c_session   *d_session;
251         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
252
253
254         PCOMMIT;
255
256         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
257         if (!strcmp(sessid,(char *)(d_session->id()))) {
258                 err = d_session->c_getprop(propname, i, val);
259                 if (err != TT_OK) {
260                         return err;
261                 }
262                 if (val.len() == 0) {
263                         *value = (unsigned char *)tt_malloc(1);
264                         **value = '\0';
265                         *length = 0;
266                 } else {
267                         *length = val.len();
268                         *value = (unsigned char *)_tt_strdup(val, *length);
269                 }
270                 return TT_OK;
271         } else {
272                 return TT_ERR_POINTER;
273         }
274 }
275
276 /*
277  * Add the character string value to the property for the session
278  */
279 Tt_status
280 _tt_session_prop_add(const char *sessid, const char *propname,
281                      const char *value)
282 {
283         return _tt_session_bprop_add(sessid, propname,
284                                      (unsigned char *)value,
285                                      (char *)0==value?0:strlen(value));
286 }
287
288 /* 
289  * Add the value to the property for the session
290  */
291 Tt_status
292 _tt_session_bprop_add(const char *sessid, const char *propname,
293                       unsigned const char *value, int length)
294 {
295         _Tt_c_session   *d_session;
296         _Tt_string val(value, length);
297         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
298
299         PCOMMIT;
300
301         d_session = _tt_c_mp->default_c_procid()->default_session().c_pointer();
302         if (!strcmp(sessid, (char *)(d_session->id()))) {
303                 return d_session->c_addprop(propname, val);
304         } else {
305                 return TT_ERR_POINTER;
306         }
307 }
308
309 /* 
310  * Return the number of values for the property on the session
311  */
312 int
313 _tt_session_prop_count(const char *sessid, const char *propname)
314 {
315         int cnt;
316         Tt_status err;
317         _Tt_c_session   *d_session;
318         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
319
320         PCOMMIT;
321
322         d_session = d_procid->default_session().c_pointer();
323         if (!strcmp(sessid,(char *)(d_session->id()))) {
324                 err = d_session->c_propcount(propname, cnt);
325                 if (err != TT_OK) {
326                         return error_int(err);
327                 } else {
328                         return cnt;
329                 }
330         } else {
331                 return error_int(TT_ERR_POINTER);
332         }
333 }
334
335
336 /*
337  * Replace all the values of the property of the session with the
338  * supplied character string value
339  */
340 Tt_status
341 _tt_session_prop_set(const char *sessid, const char *propname,
342                      const char *value)
343 {
344         return _tt_session_bprop_set(sessid, propname,
345                                      (unsigned char *)value,
346                                      (char *) 0 == value ? 0 : strlen(value));
347 }
348
349 /* 
350  * Replace all of the values of the property of the session
351  */
352 Tt_status
353 _tt_session_bprop_set(const char *sessid, const char *propname,
354                       unsigned const char *value, int length)
355 {
356         _Tt_string                      val(value, length);
357         _Tt_c_session   *d_session;
358         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
359
360         PCOMMIT;
361
362         d_session = d_procid->default_session().c_pointer();
363         if (!strcmp(sessid,(char *)(d_session->id()))) {
364                 return(d_session->c_setprop(propname, val));
365         } else {
366                 return TT_ERR_POINTER;
367         }
368 }
369
370 /* 
371  * Return the nth propname of the session
372  */
373 char *
374 _tt_session_propname(const char *sessid, int n)
375 {
376         _Tt_string                      prop;
377         Tt_status                       err;
378         _Tt_c_session   *d_session;
379         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
380
381         PTR_PCOMMIT(char_ptr);
382
383         d_session = d_procid->default_session().c_pointer();
384         if (!strcmp(sessid,(char *)(d_session->id()))) {
385                 err =  d_session->c_propname(n, prop);
386                 if (err != TT_OK) {
387                         return (char *)error_pointer(err);
388                 }
389                 return _tt_strdup(prop);
390         } else {
391                 return (char *)error_pointer(TT_ERR_POINTER);
392         }
393 }
394
395 /* 
396  * Return the number of properties on the session
397  */
398 int
399 _tt_session_propnames_count(const char *sessid)
400 {
401         int                             cnt;
402         Tt_status                       err;
403         _Tt_c_session   *d_session;
404         _Tt_c_procid    *d_procid = _tt_c_mp->default_c_procid().c_pointer();
405
406         PCOMMIT;
407
408         d_session = d_procid->default_session().c_pointer();
409         if (!strcmp(sessid,(char *)(d_session->id()))) {
410                 err = d_session->c_propnames_count(cnt);
411                 if (err != TT_OK) {
412                         return error_int(err);
413                 } else {
414                         return cnt;
415                 }
416         } else {
417                 return error_int(TT_ERR_POINTER);
418         }
419 }