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

Revision 18563, 4.5 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.
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
65        return retval;
66}
67
68/**
69 * bonobo_activation_info_free:
70 * @actinfo: the %BonoboActivationInfo structure to free.
71 *
72 * Frees @actinfo.
73 *
74 */
75
76void
77bonobo_activation_info_free (BonoboActivationInfo * actinfo)
78{
79        g_free (actinfo->iid);
80        g_free (actinfo->user);
81        g_free (actinfo->host);
82        g_free (actinfo);
83}
84
85
86/**
87 * bonobo_activation_id_parse:
88 * @actid: the activation id structure.
89 *
90 * Returns a pointer to a newly allocated %BonoboActivationInfo
91 * structure (to be freed with bonobo_activation_info_free) initialized
92 * with the data of @actid.
93 *
94 * Return value: the %BonoboActivationInfo corresponding to @actid.
95 */
96
97BonoboActivationInfo *
98bonobo_activation_id_parse (const CORBA_char *actid)
99{
100        BonoboActivationInfo *retval;
101        char *splitme, *ctmp, *ctmp2;
102        char **parts[4];
103        const int nparts = sizeof (parts) / sizeof (parts[0]);
104        int bracket_count, partnum;
105
106        g_return_val_if_fail (actid, NULL);
107        if (strncmp (actid, "OAFAID:", sizeof ("OAFAID:") - 1))
108                return NULL;
109
110        ctmp = (char *) (actid + sizeof ("OAFAID:") - 1);
111        if (*ctmp != '[')
112                return NULL;
113
114        retval = bonobo_activation_info_new ();
115
116        splitme = g_alloca (strlen (ctmp) + 1);
117        strcpy (splitme, ctmp);
118
119        parts[0] = &(retval->iid);
120        parts[1] = &(retval->user);
121        parts[2] = &(retval->host);
122        for (partnum = bracket_count = 0, ctmp = ctmp2 = splitme;
123             bracket_count >= 0 && *ctmp && partnum < nparts; ctmp++) {
124
125                switch (*ctmp) {
126                case '[':
127                        if (bracket_count <= 0)
128                                ctmp2 = ctmp + 1;
129                        bracket_count++;
130                        break;
131                case ']':
132                        bracket_count--;
133                        if (bracket_count <= 0) {
134                                *ctmp = '\0';
135                                if (*ctmp2)
136                                        *parts[partnum++] = g_strdup (ctmp2);
137                        }
138                        break;
139                case ',':
140                        if (bracket_count == 1) {
141                                *ctmp = '\0';
142                                if (*ctmp2)
143                                        *parts[partnum++] = g_strdup (ctmp2);
144                                ctmp2 = ctmp + 1;
145                        }
146                        break;
147                default:
148                        break;
149                }
150        }
151
152        return retval;
153}
154
155
156/**
157 * bonobo_activation_info_stringify:
158 * @actinfo: the %BonoboActivationInfo to flatten.
159 *
160 * Serializes @actinfo into a char *. Should be freed with g_free ().
161 *
162 * Return value: the serialized version of @actinfo.
163 */
164char *
165bonobo_activation_info_stringify (const BonoboActivationInfo * actinfo)
166{
167        g_return_val_if_fail (actinfo, NULL);
168
169        return g_strconcat ("OAFAID:[",
170                            actinfo->iid ? actinfo->iid : "",
171                            ",",
172                            actinfo->user ? actinfo->user : "",
173                            ",",
174                            actinfo->host ? actinfo->host : "",
175                            "]", NULL);
176}
Note: See TracBrowser for help on using the repository browser.