1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * liboaf: A library for accessing oafd in a nice way. |
---|
4 | * |
---|
5 | * Copyright (C) 1999, 2000 Red Hat, Inc. |
---|
6 | * Copyright (C) 2000 Eazel, Inc. |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU Library General Public |
---|
10 | * License as published by the Free Software Foundation; either |
---|
11 | * version 2 of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This library is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * Library General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU Library General Public |
---|
19 | * License along with this library; if not, write to the Free |
---|
20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | * |
---|
22 | * Author: Elliot Lee <sopwith@redhat.com> |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | |
---|
27 | #include <config.h> |
---|
28 | |
---|
29 | #include <bonobo-activation/bonobo-activation-server-info.h> |
---|
30 | |
---|
31 | #include <string.h> |
---|
32 | |
---|
33 | /** |
---|
34 | * bonobo_server_info_prop_find: |
---|
35 | * @server: the server where to seek the data. |
---|
36 | * @prop_name: the data to seek in the server. |
---|
37 | * |
---|
38 | * Tries to find a server with the given property. Returns |
---|
39 | * NULL if not found. |
---|
40 | * |
---|
41 | * Return value: a pointer to the %Bonobo_ActivationProperty structure. |
---|
42 | */ |
---|
43 | Bonobo_ActivationProperty * |
---|
44 | bonobo_server_info_prop_find (Bonobo_ServerInfo *server, |
---|
45 | const char *prop_name) |
---|
46 | { |
---|
47 | int i; |
---|
48 | |
---|
49 | for (i = 0; i < server->props._length; i++) { |
---|
50 | if (!strcmp (server->props._buffer[i].name, prop_name)) |
---|
51 | return &server->props._buffer[i]; |
---|
52 | } |
---|
53 | |
---|
54 | return NULL; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * bonobo_server_info_prop_lookup: |
---|
59 | * @server: |
---|
60 | * @propname: |
---|
61 | * @i18n_languages: |
---|
62 | * |
---|
63 | * |
---|
64 | * Return value: |
---|
65 | */ |
---|
66 | const char * |
---|
67 | bonobo_server_info_prop_lookup (Bonobo_ServerInfo *server, |
---|
68 | const char *prop_name, |
---|
69 | GSList *i18n_languages) |
---|
70 | { |
---|
71 | GSList *cur; |
---|
72 | Bonobo_ActivationProperty *prop; |
---|
73 | const char *retval; |
---|
74 | char *prop_name_buf; |
---|
75 | char short_lang[3]; |
---|
76 | |
---|
77 | if (i18n_languages) { |
---|
78 | for (cur = i18n_languages; cur; cur = cur->next) { |
---|
79 | prop_name_buf = g_strdup_printf ("%s-%s", prop_name, (char *) cur->data); |
---|
80 | |
---|
81 | retval = bonobo_server_info_prop_lookup (server, prop_name_buf, NULL); |
---|
82 | g_free (prop_name_buf); |
---|
83 | |
---|
84 | if (!retval) { |
---|
85 | if (strlen ((char *) cur->data) > 2) { |
---|
86 | strncpy (short_lang, (char *) cur->data, 2); |
---|
87 | prop_name_buf = g_strdup_printf ("%s-%s", prop_name, short_lang); |
---|
88 | retval = bonobo_server_info_prop_lookup (server, prop_name_buf, NULL); |
---|
89 | g_free (prop_name_buf); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if (retval) |
---|
94 | return retval; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | prop = bonobo_server_info_prop_find (server, prop_name); |
---|
99 | if (prop != NULL && prop->v._d == Bonobo_ACTIVATION_P_STRING) |
---|
100 | return prop->v._u.value_string; |
---|
101 | |
---|
102 | return NULL; |
---|
103 | } |
---|
104 | |
---|
105 | static void |
---|
106 | CORBA_sequence_CORBA_string_copy (CORBA_sequence_CORBA_string *copy, |
---|
107 | const CORBA_sequence_CORBA_string *original) |
---|
108 | { |
---|
109 | int i; |
---|
110 | |
---|
111 | copy->_maximum = original->_length; |
---|
112 | copy->_length = original->_length; |
---|
113 | copy->_buffer = CORBA_sequence_CORBA_string_allocbuf (original->_length); |
---|
114 | |
---|
115 | for (i = 0; i < original->_length; i++) { |
---|
116 | copy->_buffer[i] = CORBA_string_dup (original->_buffer[i]); |
---|
117 | } |
---|
118 | |
---|
119 | CORBA_sequence_set_release (copy, TRUE); |
---|
120 | } |
---|
121 | |
---|
122 | void |
---|
123 | Bonobo_ActivationPropertyValue_copy (Bonobo_ActivationPropertyValue *copy, |
---|
124 | const Bonobo_ActivationPropertyValue *original) |
---|
125 | { |
---|
126 | copy->_d = original->_d; |
---|
127 | switch (original->_d) { |
---|
128 | case Bonobo_ACTIVATION_P_STRING: |
---|
129 | copy->_u.value_string = CORBA_string_dup (original->_u.value_string); |
---|
130 | break; |
---|
131 | case Bonobo_ACTIVATION_P_NUMBER: |
---|
132 | copy->_u.value_number = original->_u.value_number; |
---|
133 | break; |
---|
134 | case Bonobo_ACTIVATION_P_BOOLEAN: |
---|
135 | copy->_u.value_boolean = original->_u.value_boolean; |
---|
136 | break; |
---|
137 | case Bonobo_ACTIVATION_P_STRINGV: |
---|
138 | CORBA_sequence_CORBA_string_copy |
---|
139 | (©->_u.value_stringv, |
---|
140 | &original->_u.value_stringv); |
---|
141 | break; |
---|
142 | default: |
---|
143 | g_assert_not_reached (); |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | void |
---|
148 | Bonobo_ActivationProperty_copy (Bonobo_ActivationProperty *copy, |
---|
149 | const Bonobo_ActivationProperty *original) |
---|
150 | { |
---|
151 | copy->name = CORBA_string_dup (original->name); |
---|
152 | Bonobo_ActivationPropertyValue_copy (©->v, &original->v); |
---|
153 | } |
---|
154 | |
---|
155 | void |
---|
156 | CORBA_sequence_Bonobo_ActivationProperty_copy ( |
---|
157 | CORBA_sequence_Bonobo_ActivationProperty *copy, |
---|
158 | const CORBA_sequence_Bonobo_ActivationProperty *original) |
---|
159 | { |
---|
160 | int i; |
---|
161 | |
---|
162 | copy->_maximum = original->_length; |
---|
163 | copy->_length = original->_length; |
---|
164 | copy->_buffer = CORBA_sequence_Bonobo_ActivationProperty_allocbuf (original->_length); |
---|
165 | |
---|
166 | for (i = 0; i < original->_length; i++) { |
---|
167 | Bonobo_ActivationProperty_copy (©->_buffer[i], &original->_buffer[i]); |
---|
168 | } |
---|
169 | |
---|
170 | CORBA_sequence_set_release (copy, TRUE); |
---|
171 | } |
---|
172 | |
---|
173 | void |
---|
174 | Bonobo_ServerInfo_copy (Bonobo_ServerInfo *copy, const Bonobo_ServerInfo *original) |
---|
175 | { |
---|
176 | copy->iid = CORBA_string_dup (original->iid); |
---|
177 | copy->server_type = CORBA_string_dup (original->server_type); |
---|
178 | copy->location_info = CORBA_string_dup (original->location_info); |
---|
179 | copy->username = CORBA_string_dup (original->username); |
---|
180 | copy->hostname = CORBA_string_dup (original->hostname); |
---|
181 | copy->domain = CORBA_string_dup (original->domain); |
---|
182 | CORBA_sequence_Bonobo_ActivationProperty_copy (©->props, &original->props); |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | /** |
---|
187 | * Bonobo_ServerInfo_duplicate: |
---|
188 | * @original: %ServerInfo to copy. |
---|
189 | * |
---|
190 | * The return value should befreed with CORBA_free (). |
---|
191 | * |
---|
192 | * Return value: a newly allocated copy of @original. |
---|
193 | */ |
---|
194 | Bonobo_ServerInfo * |
---|
195 | Bonobo_ServerInfo_duplicate (const Bonobo_ServerInfo *original) |
---|
196 | { |
---|
197 | Bonobo_ServerInfo *copy; |
---|
198 | |
---|
199 | copy = Bonobo_ServerInfo__alloc (); |
---|
200 | Bonobo_ServerInfo_copy (copy, original); |
---|
201 | |
---|
202 | return copy; |
---|
203 | } |
---|
204 | |
---|
205 | Bonobo_ServerInfoList * |
---|
206 | Bonobo_ServerInfoList_duplicate (const Bonobo_ServerInfoList *original) |
---|
207 | { |
---|
208 | int i; |
---|
209 | Bonobo_ServerInfoList *list; |
---|
210 | |
---|
211 | if (!original) |
---|
212 | return NULL; |
---|
213 | |
---|
214 | list = Bonobo_ServerInfoList__alloc (); |
---|
215 | |
---|
216 | list->_length = original->_length; |
---|
217 | list->_maximum = list->_length; |
---|
218 | list->_buffer = Bonobo_ServerInfoList_allocbuf (list->_length); |
---|
219 | |
---|
220 | for (i = 0; i < list->_length; i++) |
---|
221 | Bonobo_ServerInfo_copy (&list->_buffer [i], &original->_buffer [i]); |
---|
222 | |
---|
223 | CORBA_sequence_set_release (list, TRUE); |
---|
224 | |
---|
225 | return list; |
---|
226 | } |
---|