source: trunk/third/bonobo-activation/bonobo-activation/bonobo-activation-id.c @ 18311

Revision 18311, 4.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18310, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2/*
3 *  bonobo-activation: A library for accessing bonobo-activation-server.
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#include <config.h>
27
28#include <bonobo-activation/bonobo-activation-id.h>
29#include <bonobo-activation/bonobo-activation-private.h>
30
31/**
32 * bonobo_activation_info_new:
33 *
34 * This function allocates a %BonoboActicationInfo structure and returns it.
35 * Should NOT be called from outside of this code.
36 *
37 * Return value: a newly allocated non-initialized %BonoboActicationInfo structure.
38 */
39BonoboActivationInfo *
40bonobo_activation_info_new (void)
41{
42        return g_new0 (BonoboActivationInfo, 1);
43}
44
45/**
46 * bonobo_activation_servinfo_to_actinfo:
47 * @servinfo: An array of %Bonobo_ServerInfo structures.
48 *
49 * This function converts a %Bonobo_ServerInfo structure to a
50 * %BonoboActivationInfo structure. The returned structure should
51 * be freed with bonobo_activation_info_free.
52 *
53 * Return value: a newly allocated initialized %BonoboActivationInfo structure.
54 */
55
56BonoboActivationInfo *
57bonobo_activation_servinfo_to_actinfo (const Bonobo_ServerInfo * servinfo)
58{
59        BonoboActivationInfo *retval = bonobo_activation_info_new ();
60
61        retval->iid = g_strdup (servinfo->iid);
62        retval->user = g_strdup (servinfo->username);
63        retval->host = g_strdup (servinfo->hostname);
64        retval->domain = g_strdup (servinfo->domain);
65
66        return retval;
67}
68
69/**
70 * bonobo_activation_info_free:
71 * @actinfo: the %BonoboActivationInfo structure to free.
72 *
73 * Frees @actinfo.
74 *
75 */
76
77void
78bonobo_activation_info_free (BonoboActivationInfo * actinfo)
79{
80        g_free (actinfo->iid);
81        g_free (actinfo->user);
82        g_free (actinfo->host);
83        g_free (actinfo->domain);
84        g_free (actinfo);
85}
86
87
88/**
89 * bonobo_activation_id_parse:
90 * @actid: the activation id structure.
91 *
92 * Returns a pointer to a newly allocated %BonoboActivationInfo
93 * structure (to be freed with bonobo_activation_info_free) initialized
94 * with the data of @actid.
95 *
96 * Return value: the %BonoboActivationInfo corresponding to @actid.
97 */
98
99BonoboActivationInfo *
100bonobo_activation_id_parse (const CORBA_char *actid)
101{
102        BonoboActivationInfo *retval;
103        char *splitme, *ctmp, *ctmp2;
104        char **parts[4];
105        const int nparts = sizeof (parts) / sizeof (parts[0]);
106        int bracket_count, partnum;
107
108        g_return_val_if_fail (actid, NULL);
109        if (strncmp (actid, "OAFAID:", sizeof ("OAFAID:") - 1))
110                return NULL;
111
112        ctmp = (char *) (actid + sizeof ("OAFAID:") - 1);
113        if (*ctmp != '[')
114                return NULL;
115
116        retval = bonobo_activation_info_new ();
117
118        splitme = g_alloca (strlen (ctmp) + 1);
119        strcpy (splitme, ctmp);
120
121        parts[0] = &(retval->iid);
122        parts[1] = &(retval->user);
123        parts[2] = &(retval->host);
124        parts[3] = &(retval->domain);
125        for (partnum = bracket_count = 0, ctmp = ctmp2 = splitme;
126             bracket_count >= 0 && *ctmp && partnum < nparts; ctmp++) {
127
128                switch (*ctmp) {
129                case '[':
130                        if (bracket_count <= 0)
131                                ctmp2 = ctmp + 1;
132                        bracket_count++;
133                        break;
134                case ']':
135                        bracket_count--;
136                        if (bracket_count <= 0) {
137                                *ctmp = '\0';
138                                if (*ctmp2)
139                                        *parts[partnum++] = g_strdup (ctmp2);
140                        }
141                        break;
142                case ',':
143                        if (bracket_count == 1) {
144                                *ctmp = '\0';
145                                if (*ctmp2)
146                                        *parts[partnum++] = g_strdup (ctmp2);
147                                ctmp2 = ctmp + 1;
148                        }
149                        break;
150                default:
151                        break;
152                }
153        }
154
155        return retval;
156}
157
158
159/**
160 * bonobo_activation_info_stringify:
161 * @actinfo: the %BonoboActivationInfo to flatten.
162 *
163 * Serializes @actinfo into a char *. Should be freed with g_free ().
164 *
165 * Return value: the serialized version of @actinfo.
166 */
167char *
168bonobo_activation_info_stringify (const BonoboActivationInfo * actinfo)
169{
170        g_return_val_if_fail (actinfo, NULL);
171
172        return g_strconcat ("OAFAID:[",
173                            actinfo->iid ? actinfo->iid : "",
174                            ",",
175                            actinfo->user ? actinfo->user : "",
176                            ",",
177                            actinfo->host ? actinfo->host : "",
178                            ",",
179                            actinfo->domain ? actinfo->domain : "",
180                            "]", NULL);
181}
182
183
184
Note: See TracBrowser for help on using the repository browser.