source: trunk/third/bonobo-activation/bonobo-activation/bonobo-activation-server-info.c @ 18563

Revision 18563, 6.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18562, which included commits to RCS files with non-trunk default branches.
RevLine 
[18310]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 */
43Bonobo_ActivationProperty *
44bonobo_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:
[18562]60 * @prop_name:
[18310]61 * @i18n_languages:
62 *
63 *
64 * Return value:
65 */
66const char *
67bonobo_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                     
76        if (i18n_languages) {
77                for (cur = i18n_languages; cur; cur = cur->next) {
78                        prop_name_buf = g_strdup_printf ("%s-%s", prop_name, (char *) cur->data);
79
80                        retval = bonobo_server_info_prop_lookup (server, prop_name_buf, NULL);
81                        g_free (prop_name_buf);
82
83                        if (retval)
84                                return retval;
85                }
86        }
87
88        prop = bonobo_server_info_prop_find (server, prop_name);
89        if (prop != NULL && prop->v._d == Bonobo_ACTIVATION_P_STRING)
90                return prop->v._u.value_string;
91
92        return NULL;
93}
94
95static void
96CORBA_sequence_CORBA_string_copy (CORBA_sequence_CORBA_string       *copy,
97                                  const CORBA_sequence_CORBA_string *original)
98{
99        int i;
100
101        copy->_maximum = original->_length;
102        copy->_length = original->_length;
103        copy->_buffer = CORBA_sequence_CORBA_string_allocbuf (original->_length);
104
105        for (i = 0; i < original->_length; i++) {
106                copy->_buffer[i] = CORBA_string_dup (original->_buffer[i]);
107        }
108
109        CORBA_sequence_set_release (copy, TRUE);
110}
111
112void
113Bonobo_ActivationPropertyValue_copy (Bonobo_ActivationPropertyValue       *copy,
114                                     const Bonobo_ActivationPropertyValue *original)
115{
116        copy->_d = original->_d;
117        switch (original->_d) {
118        case Bonobo_ACTIVATION_P_STRING:
119                copy->_u.value_string = CORBA_string_dup (original->_u.value_string);
120                break;
121        case Bonobo_ACTIVATION_P_NUMBER:
122                copy->_u.value_number = original->_u.value_number;
123                break;
124        case Bonobo_ACTIVATION_P_BOOLEAN:
125                copy->_u.value_boolean = original->_u.value_boolean;
126                break;
127        case Bonobo_ACTIVATION_P_STRINGV:
128                CORBA_sequence_CORBA_string_copy
129                        (&copy->_u.value_stringv,
130                         &original->_u.value_stringv);
131                break;
132        default:
133                g_assert_not_reached ();
134        }
135}
136
137void
138Bonobo_ActivationProperty_copy (Bonobo_ActivationProperty       *copy,
139                                const Bonobo_ActivationProperty *original)
140{
141        copy->name = CORBA_string_dup (original->name);
142        Bonobo_ActivationPropertyValue_copy (&copy->v, &original->v);
143}
144
145void
146CORBA_sequence_Bonobo_ActivationProperty_copy (
147        CORBA_sequence_Bonobo_ActivationProperty       *copy,
148        const CORBA_sequence_Bonobo_ActivationProperty *original)
149{
150        int i;
151
152        copy->_maximum = original->_length;
153        copy->_length = original->_length;
154        copy->_buffer = CORBA_sequence_Bonobo_ActivationProperty_allocbuf (original->_length);
155
156        for (i = 0; i < original->_length; i++) {
157                Bonobo_ActivationProperty_copy (&copy->_buffer[i], &original->_buffer[i]);
158        }
159
160        CORBA_sequence_set_release (copy, TRUE);
161}
162
163void
164Bonobo_ServerInfo_copy (Bonobo_ServerInfo *copy, const Bonobo_ServerInfo *original)
165{
[18562]166        copy->iid           = CORBA_string_dup (original->iid);
167        copy->server_type   = CORBA_string_dup (original->server_type);
[18310]168        copy->location_info = CORBA_string_dup (original->location_info);
[18562]169        copy->username      = CORBA_string_dup (original->username);
170        copy->hostname      = CORBA_string_dup (original->hostname);
171        copy->domain        = CORBA_string_dup (original->domain);
172
[18310]173        CORBA_sequence_Bonobo_ActivationProperty_copy (&copy->props, &original->props);
174}
175
176
177/**
178 * Bonobo_ServerInfo_duplicate:
179 * @original: %ServerInfo to copy.
180 *
181 * The return value should befreed with CORBA_free ().
182 *
183 * Return value: a newly allocated copy of @original.
184 */
185Bonobo_ServerInfo *
186Bonobo_ServerInfo_duplicate (const Bonobo_ServerInfo *original)
187{
188        Bonobo_ServerInfo *copy;
189
190        copy = Bonobo_ServerInfo__alloc ();
191        Bonobo_ServerInfo_copy (copy, original);
192       
193        return copy;
194}
195
196Bonobo_ServerInfoList *
197Bonobo_ServerInfoList_duplicate (const Bonobo_ServerInfoList *original)
198{
199        int i;
200        Bonobo_ServerInfoList *list;
201
202        if (!original)
203                return NULL;
204
205        list = Bonobo_ServerInfoList__alloc ();
206
207        list->_length = original->_length;
208        list->_maximum = list->_length;
209        list->_buffer = Bonobo_ServerInfoList_allocbuf (list->_length);
210
211        for (i = 0; i < list->_length; i++)
212                Bonobo_ServerInfo_copy (&list->_buffer [i], &original->_buffer [i]);
213
214        CORBA_sequence_set_release (list, TRUE);
215
216        return list;
217}
Note: See TracBrowser for help on using the repository browser.