2
#include <seahorse-servers.h>
3
#include <seahorse-gconf.h>
6
#define SEAHORSE_SERVERS_TYPE_SERVER_INFO (seahorse_servers_server_info_get_type ())
7
#define SEAHORSE_SERVERS_SERVER_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfo))
8
#define SEAHORSE_SERVERS_SERVER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfoClass))
9
#define SEAHORSE_SERVERS_IS_SERVER_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO))
10
#define SEAHORSE_SERVERS_IS_SERVER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SEAHORSE_SERVERS_TYPE_SERVER_INFO))
11
#define SEAHORSE_SERVERS_SERVER_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SEAHORSE_SERVERS_TYPE_SERVER_INFO, SeahorseServersServerInfoClass))
13
typedef struct _SeahorseServersServerInfo SeahorseServersServerInfo;
14
typedef struct _SeahorseServersServerInfoClass SeahorseServersServerInfoClass;
15
typedef struct _SeahorseServersServerInfoPrivate SeahorseServersServerInfoPrivate;
17
struct _SeahorseServersServerInfo {
18
GTypeInstance parent_instance;
19
volatile int ref_count;
20
SeahorseServersServerInfoPrivate * priv;
23
SeahorseValidUriFunc validator;
26
struct _SeahorseServersServerInfoClass {
27
GTypeClass parent_class;
28
void (*finalize) (SeahorseServersServerInfo *self);
34
SEAHORSE_SERVERS_DUMMY_PROPERTY
36
static GHashTable* seahorse_servers_types;
37
static void _g_slist_free_g_free (GSList* self);
39
SEAHORSE_SERVERS_SERVER_INFO_DUMMY_PROPERTY
41
static SeahorseServersServerInfo* seahorse_servers_server_info_new (void);
42
static gpointer seahorse_servers_server_info_parent_class = NULL;
43
static GType seahorse_servers_server_info_get_type (void);
44
static gpointer seahorse_servers_server_info_ref (gpointer instance);
45
static void seahorse_servers_server_info_unref (gpointer instance);
46
static gpointer seahorse_servers_parent_class = NULL;
47
static void seahorse_servers_dispose (GObject * obj);
48
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
52
static void _g_slist_free_g_free (GSList* self) {
53
g_slist_foreach (self, ((GFunc) (g_free)), NULL);
58
GSList* seahorse_servers_get_types (void) {
62
GList* type_collection;
64
type_collection = g_hash_table_get_keys (seahorse_servers_types);
65
for (type_it = type_collection; type_it != NULL; type_it = type_it->next) {
67
type = ((const char*) (type_it->data));
71
results = g_slist_append (results, (_tmp0 = type, (_tmp0 == NULL ? NULL : g_strdup (_tmp0))));
74
(type_collection == NULL ? NULL : (type_collection = (g_list_free (type_collection), NULL)));
80
char* seahorse_servers_get_description (const char* type) {
81
SeahorseServersServerInfo* _tmp0;
82
SeahorseServersServerInfo* server;
85
g_return_val_if_fail (type != NULL, NULL);
87
server = (_tmp0 = ((SeahorseServersServerInfo*) (g_hash_table_lookup (seahorse_servers_types, type))), (_tmp0 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp0)));
91
return (_tmp1 = NULL, (server == NULL ? NULL : (server = (seahorse_servers_server_info_unref (server), NULL))), _tmp1);
95
return (_tmp3 = (_tmp2 = server->description, (_tmp2 == NULL ? NULL : g_strdup (_tmp2))), (server == NULL ? NULL : (server = (seahorse_servers_server_info_unref (server), NULL))), _tmp3);
99
void seahorse_servers_register_type (const char* type, const char* description, SeahorseValidUriFunc validate) {
100
SeahorseServers* dummy;
101
SeahorseServersServerInfo* info;
106
SeahorseServersServerInfo* _tmp5;
108
g_return_if_fail (type != NULL);
109
g_return_if_fail (description != NULL);
110
/* Work around for: http://bugzilla.gnome.org/show_bug.cgi?id=543190 */
111
dummy = seahorse_servers_new ();
112
info = seahorse_servers_server_info_new ();
115
info->type = (_tmp1 = (_tmp0 = type, (_tmp0 == NULL ? NULL : g_strdup (_tmp0))), (info->type = (g_free (info->type), NULL)), _tmp1);
118
info->description = (_tmp3 = (_tmp2 = description, (_tmp2 == NULL ? NULL : g_strdup (_tmp2))), (info->description = (g_free (info->description), NULL)), _tmp3);
119
info->validator = validate;
122
g_hash_table_replace (seahorse_servers_types, (_tmp4 = type, (_tmp4 == NULL ? NULL : g_strdup (_tmp4))), (_tmp5 = info, (_tmp5 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp5))));
123
(dummy == NULL ? NULL : (dummy = (g_object_unref (dummy), NULL)));
124
(info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL)));
128
GSList* seahorse_servers_get_uris (void) {
132
servers = seahorse_gconf_get_string_list (KEYSERVER_KEY);
134
/* The values are 'uri name', remove the name part */
136
GSList* value_collection;
138
value_collection = servers;
139
for (value_it = value_collection; value_it != NULL; value_it = value_it->next) {
143
value = (_tmp2 = ((char*) (value_it->data)), (_tmp2 == NULL ? NULL : g_strdup (_tmp2)));
150
parts = (_tmp0 = g_strsplit (value, " ", 2), parts_length1 = -1, _tmp0);
152
results = g_slist_append (results, (_tmp1 = parts[0], (_tmp1 == NULL ? NULL : g_strdup (_tmp1))));
153
value = (g_free (value), NULL);
154
parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL);
159
return (_tmp3 = results, (servers == NULL ? NULL : (servers = (_g_slist_free_g_free (servers), NULL))), _tmp3);
163
GSList* seahorse_servers_get_names (void) {
167
servers = seahorse_gconf_get_string_list (KEYSERVER_KEY);
169
/* The values are 'uri name', remove the uri part */
171
GSList* value_collection;
173
value_collection = servers;
174
for (value_it = value_collection; value_it != NULL; value_it = value_it->next) {
178
value = (_tmp3 = ((char*) (value_it->data)), (_tmp3 == NULL ? NULL : g_strdup (_tmp3)));
184
parts = (_tmp0 = g_strsplit (value, " ", 2), parts_length1 = -1, _tmp0);
185
if (parts_length1 == 2 && g_utf8_strlen (parts[1], -1) > 0) {
188
results = g_slist_append (results, (_tmp1 = parts[1], (_tmp1 == NULL ? NULL : g_strdup (_tmp1))));
192
results = g_slist_append (results, (_tmp2 = parts[0], (_tmp2 == NULL ? NULL : g_strdup (_tmp2))));
194
value = (g_free (value), NULL);
195
parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL);
200
return (_tmp4 = results, (servers == NULL ? NULL : (servers = (_g_slist_free_g_free (servers), NULL))), _tmp4);
204
/* Check to see if the passed uri is valid against registered validators */
205
gboolean seahorse_servers_is_valid_uri (const char* uri) {
209
SeahorseServersServerInfo* _tmp2;
210
SeahorseServersServerInfo* info;
212
g_return_val_if_fail (uri != NULL, FALSE);
214
parts = (_tmp0 = g_strsplit (uri, ":", 2), parts_length1 = -1, _tmp0);
215
if (parts_length1 == 0) {
217
return (_tmp1 = FALSE, (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), _tmp1);
220
info = (_tmp2 = ((SeahorseServersServerInfo*) (g_hash_table_lookup (seahorse_servers_types, parts[0]))), (_tmp2 == NULL ? NULL : seahorse_servers_server_info_ref (_tmp2)));
223
return (_tmp3 = FALSE, (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), (info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL))), _tmp3);
225
return (_tmp4 = info->validator (uri), (parts = (_vala_array_free (parts, parts_length1, ((GDestroyNotify) (g_free))), NULL)), (info == NULL ? NULL : (info = (seahorse_servers_server_info_unref (info), NULL))), _tmp4);
229
SeahorseServers* seahorse_servers_new (void) {
230
SeahorseServers * self;
231
self = g_object_newv (SEAHORSE_TYPE_SERVERS, 0, NULL);
236
static SeahorseServersServerInfo* seahorse_servers_server_info_new (void) {
237
SeahorseServersServerInfo* self;
238
self = ((SeahorseServersServerInfo*) (g_type_create_instance (SEAHORSE_SERVERS_TYPE_SERVER_INFO)));
243
static void seahorse_servers_server_info_class_init (SeahorseServersServerInfoClass * klass) {
244
seahorse_servers_server_info_parent_class = g_type_class_peek_parent (klass);
248
static void seahorse_servers_server_info_instance_init (SeahorseServersServerInfo * self) {
253
static GType seahorse_servers_server_info_get_type (void) {
254
static GType seahorse_servers_server_info_type_id = 0;
255
if (G_UNLIKELY (seahorse_servers_server_info_type_id == 0)) {
256
static const GTypeInfo g_define_type_info = { sizeof (SeahorseServersServerInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_servers_server_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseServersServerInfo), 0, (GInstanceInitFunc) seahorse_servers_server_info_instance_init };
257
static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
258
seahorse_servers_server_info_type_id = g_type_register_fundamental (g_type_fundamental_next (), "SeahorseServersServerInfo", &g_define_type_info, &g_define_type_fundamental_info, 0);
260
return seahorse_servers_server_info_type_id;
264
static gpointer seahorse_servers_server_info_ref (gpointer instance) {
265
SeahorseServersServerInfo* self;
267
g_atomic_int_inc (&self->ref_count);
272
static void seahorse_servers_server_info_unref (gpointer instance) {
273
SeahorseServersServerInfo* self;
275
if (g_atomic_int_dec_and_test (&self->ref_count)) {
276
g_type_free_instance (((GTypeInstance *) (self)));
281
static void seahorse_servers_class_init (SeahorseServersClass * klass) {
282
seahorse_servers_parent_class = g_type_class_peek_parent (klass);
283
G_OBJECT_CLASS (klass)->dispose = seahorse_servers_dispose;
286
/* TODO: What do we specify to free ServerInfo? */
288
seahorse_servers_types = (_tmp0 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL), (seahorse_servers_types == NULL ? NULL : (seahorse_servers_types = (g_hash_table_unref (seahorse_servers_types), NULL))), _tmp0);
293
static void seahorse_servers_instance_init (SeahorseServers * self) {
297
static void seahorse_servers_dispose (GObject * obj) {
298
SeahorseServers * self;
299
self = SEAHORSE_SERVERS (obj);
300
G_OBJECT_CLASS (seahorse_servers_parent_class)->dispose (obj);
304
GType seahorse_servers_get_type (void) {
305
static GType seahorse_servers_type_id = 0;
306
if (G_UNLIKELY (seahorse_servers_type_id == 0)) {
307
static const GTypeInfo g_define_type_info = { sizeof (SeahorseServersClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_servers_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseServers), 0, (GInstanceInitFunc) seahorse_servers_instance_init };
308
seahorse_servers_type_id = g_type_register_static (G_TYPE_OBJECT, "SeahorseServers", &g_define_type_info, 0);
310
return seahorse_servers_type_id;
314
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
315
if (array != NULL && destroy_func != NULL) {
317
if (array_length >= 0)
318
for (i = 0; i < array_length; i = i + 1) {
319
if (((gpointer*) (array))[i] != NULL)
320
destroy_func (((gpointer*) (array))[i]);
323
for (i = 0; ((gpointer*) (array))[i] != NULL; i = i + 1) {
324
destroy_func (((gpointer*) (array))[i]);