run vala
[moonshot-ui.git] / src / moonshot-identities-manager.c
1 /* moonshot-identities-manager.c generated by valac 0.10.4, the Vala compiler
2  * generated from moonshot-identities-manager.vala, do not modify */
3
4
5 #include <glib.h>
6 #include <glib-object.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <glib/gstdio.h>
11 #include <config.h>
12 #include <gdk-pixbuf/gdk-pixdata.h>
13
14
15 #define TYPE_IDENTITIES_MANAGER (identities_manager_get_type ())
16 #define IDENTITIES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_IDENTITIES_MANAGER, IdentitiesManager))
17 #define IDENTITIES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_IDENTITIES_MANAGER, IdentitiesManagerClass))
18 #define IS_IDENTITIES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_IDENTITIES_MANAGER))
19 #define IS_IDENTITIES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_IDENTITIES_MANAGER))
20 #define IDENTITIES_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_IDENTITIES_MANAGER, IdentitiesManagerClass))
21
22 typedef struct _IdentitiesManager IdentitiesManager;
23 typedef struct _IdentitiesManagerClass IdentitiesManagerClass;
24 typedef struct _IdentitiesManagerPrivate IdentitiesManagerPrivate;
25
26 #define TYPE_ID_CARD (id_card_get_type ())
27 #define ID_CARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ID_CARD, IdCard))
28 #define ID_CARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ID_CARD, IdCardClass))
29 #define IS_ID_CARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ID_CARD))
30 #define IS_ID_CARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ID_CARD))
31 #define ID_CARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ID_CARD, IdCardClass))
32
33 typedef struct _IdCard IdCard;
34 typedef struct _IdCardClass IdCardClass;
35 #define __g_slist_free_g_object_unref0(var) ((var == NULL) ? NULL : (var = (_g_slist_free_g_object_unref (var), NULL)))
36 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
37 #define _g_free0(var) (var = (g_free (var), NULL))
38 #define _g_key_file_free0(var) ((var == NULL) ? NULL : (var = (g_key_file_free (var), NULL)))
39 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
40
41 struct _IdentitiesManager {
42         GObject parent_instance;
43         IdentitiesManagerPrivate * priv;
44         GSList* id_card_list;
45 };
46
47 struct _IdentitiesManagerClass {
48         GObjectClass parent_class;
49 };
50
51
52 static gpointer identities_manager_parent_class = NULL;
53
54 GType identities_manager_get_type (void) G_GNUC_CONST;
55 GType id_card_get_type (void) G_GNUC_CONST;
56 enum  {
57         IDENTITIES_MANAGER_DUMMY_PROPERTY
58 };
59 static void _g_slist_free_g_object_unref (GSList* self);
60 #define IDENTITIES_MANAGER_FILE_NAME "identities.txt"
61 IdentitiesManager* identities_manager_new (void);
62 IdentitiesManager* identities_manager_construct (GType object_type);
63 static char* identities_manager_get_data_dir (IdentitiesManager* self);
64 IdCard* id_card_new (void);
65 IdCard* id_card_construct (GType object_type);
66 void id_card_set_issuer (IdCard* self, const char* value);
67 void id_card_set_username (IdCard* self, const char* value);
68 void id_card_set_password (IdCard* self, const char* value);
69 void id_card_set_services (IdCard* self, char** value, int value_length1);
70 const char* id_card_get_username (IdCard* self);
71 const char* id_card_get_issuer (IdCard* self);
72 void id_card_set_nai (IdCard* self, const char* value);
73 void identities_manager_store_id_cards (IdentitiesManager* self);
74 const char* id_card_get_password (IdCard* self);
75 char** id_card_get_services (IdCard* self, int* result_length1);
76 IdCard* identities_manager_load_gss_eap_id_file (IdentitiesManager* self);
77 GdkPixbuf* find_icon (const char* name, gint size);
78 void id_card_set_pixbuf (IdCard* self, GdkPixbuf* value);
79 void identities_manager_store_gss_eap_id_file (IdentitiesManager* self, IdCard* id_card);
80 static void identities_manager_finalize (GObject* obj);
81 static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
82 static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
83 static gint _vala_array_length (gpointer array);
84 static int _vala_strcmp0 (const char * str1, const char * str2);
85
86
87
88 static void _g_slist_free_g_object_unref (GSList* self) {
89         g_slist_foreach (self, (GFunc) g_object_unref, NULL);
90         g_slist_free (self);
91 }
92
93
94 static gpointer _g_object_ref0 (gpointer self) {
95         return self ? g_object_ref (self) : NULL;
96 }
97
98
99 IdentitiesManager* identities_manager_construct (GType object_type) {
100         IdentitiesManager * self = NULL;
101         GKeyFile* key_file;
102         char* path;
103         char* filename;
104         gint identities_uris_length1;
105         gint _identities_uris_size_;
106         char** _tmp1_;
107         gsize _tmp0_;
108         char** identities_uris;
109         GError * _inner_error_ = NULL;
110         self = (IdentitiesManager*) g_object_new (object_type, NULL);
111         key_file = g_key_file_new ();
112         path = identities_manager_get_data_dir (self);
113         filename = g_build_filename (path, IDENTITIES_MANAGER_FILE_NAME, NULL);
114         {
115                 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &_inner_error_);
116                 if (_inner_error_ != NULL) {
117                         goto __catch0_g_error;
118                 }
119         }
120         goto __finally0;
121         __catch0_g_error:
122         {
123                 GError * e;
124                 e = _inner_error_;
125                 _inner_error_ = NULL;
126                 {
127                         fprintf (stdout, "Error: %s\n", e->message);
128                         _g_error_free0 (e);
129                 }
130         }
131         __finally0:
132         if (_inner_error_ != NULL) {
133                 _g_free0 (filename);
134                 _g_free0 (path);
135                 _g_key_file_free0 (key_file);
136                 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
137                 g_clear_error (&_inner_error_);
138                 return NULL;
139         }
140         identities_uris = (_tmp1_ = g_key_file_get_groups (key_file, &_tmp0_), identities_uris_length1 = _tmp0_, _identities_uris_size_ = identities_uris_length1, _tmp1_);
141         {
142                 char** identity_collection;
143                 int identity_collection_length1;
144                 int identity_it;
145                 identity_collection = identities_uris;
146                 identity_collection_length1 = identities_uris_length1;
147                 for (identity_it = 0; identity_it < identities_uris_length1; identity_it = identity_it + 1) {
148                         char* identity;
149                         identity = g_strdup (identity_collection[identity_it]);
150                         {
151                                 {
152                                         IdCard* id_card;
153                                         char* _tmp2_;
154                                         char* _tmp3_;
155                                         char* _tmp4_;
156                                         char* _tmp5_;
157                                         char* _tmp6_;
158                                         char* _tmp7_;
159                                         gint _tmp9__length1;
160                                         gint __tmp9__size_;
161                                         char** _tmp10_;
162                                         gsize _tmp8_;
163                                         char** _tmp9_;
164                                         char** _tmp11_;
165                                         gint _tmp11__length1;
166                                         char** _tmp12_;
167                                         char* _tmp13_;
168                                         char* _tmp14_;
169                                         id_card = id_card_new ();
170                                         _tmp2_ = g_key_file_get_string (key_file, identity, "Issuer", &_inner_error_);
171                                         if (_inner_error_ != NULL) {
172                                                 _g_object_unref0 (id_card);
173                                                 goto __catch1_g_error;
174                                         }
175                                         id_card_set_issuer (id_card, _tmp3_ = _tmp2_);
176                                         _g_free0 (_tmp3_);
177                                         _tmp4_ = g_key_file_get_string (key_file, identity, "Username", &_inner_error_);
178                                         if (_inner_error_ != NULL) {
179                                                 _g_object_unref0 (id_card);
180                                                 goto __catch1_g_error;
181                                         }
182                                         id_card_set_username (id_card, _tmp5_ = _tmp4_);
183                                         _g_free0 (_tmp5_);
184                                         _tmp6_ = g_key_file_get_string (key_file, identity, "Password", &_inner_error_);
185                                         if (_inner_error_ != NULL) {
186                                                 _g_object_unref0 (id_card);
187                                                 goto __catch1_g_error;
188                                         }
189                                         id_card_set_password (id_card, _tmp7_ = _tmp6_);
190                                         _g_free0 (_tmp7_);
191                                         _tmp9_ = (_tmp10_ = g_key_file_get_string_list (key_file, identity, "Services", &_tmp8_, &_inner_error_), _tmp9__length1 = _tmp8_, __tmp9__size_ = _tmp9__length1, _tmp10_);
192                                         if (_inner_error_ != NULL) {
193                                                 _g_object_unref0 (id_card);
194                                                 goto __catch1_g_error;
195                                         }
196                                         _tmp12_ = (_tmp11_ = _tmp9_, _tmp11__length1 = _tmp9__length1, _tmp11_);
197                                         id_card_set_services (id_card, _tmp12_, _tmp9__length1);
198                                         _tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
199                                         id_card_set_nai (id_card, _tmp14_ = g_strconcat (_tmp13_ = g_strconcat (id_card_get_username (id_card), "@", NULL), id_card_get_issuer (id_card), NULL));
200                                         _g_free0 (_tmp14_);
201                                         _g_free0 (_tmp13_);
202                                         self->id_card_list = g_slist_prepend (self->id_card_list, _g_object_ref0 (id_card));
203                                         _g_object_unref0 (id_card);
204                                 }
205                                 goto __finally1;
206                                 __catch1_g_error:
207                                 {
208                                         GError * e;
209                                         e = _inner_error_;
210                                         _inner_error_ = NULL;
211                                         {
212                                                 fprintf (stdout, "Error:  %s\n", e->message);
213                                                 _g_error_free0 (e);
214                                         }
215                                 }
216                                 __finally1:
217                                 if (_inner_error_ != NULL) {
218                                         _g_free0 (identity);
219                                         identities_uris = (_vala_array_free (identities_uris, identities_uris_length1, (GDestroyNotify) g_free), NULL);
220                                         _g_free0 (filename);
221                                         _g_free0 (path);
222                                         _g_key_file_free0 (key_file);
223                                         g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
224                                         g_clear_error (&_inner_error_);
225                                         return NULL;
226                                 }
227                                 _g_free0 (identity);
228                         }
229                 }
230         }
231         identities_uris = (_vala_array_free (identities_uris, identities_uris_length1, (GDestroyNotify) g_free), NULL);
232         _g_free0 (filename);
233         _g_free0 (path);
234         _g_key_file_free0 (key_file);
235         return self;
236 }
237
238
239 IdentitiesManager* identities_manager_new (void) {
240         return identities_manager_construct (TYPE_IDENTITIES_MANAGER);
241 }
242
243
244 void identities_manager_store_id_cards (IdentitiesManager* self) {
245         GKeyFile* key_file;
246         char* text;
247         GError * _inner_error_ = NULL;
248         g_return_if_fail (self != NULL);
249         key_file = g_key_file_new ();
250         {
251                 GSList* id_card_collection;
252                 GSList* id_card_it;
253                 id_card_collection = self->id_card_list;
254                 for (id_card_it = id_card_collection; id_card_it != NULL; id_card_it = id_card_it->next) {
255                         IdCard* id_card;
256                         id_card = _g_object_ref0 ((IdCard*) id_card_it->data);
257                         {
258                                 gint _tmp0_;
259                                 g_key_file_set_string (key_file, id_card_get_issuer (id_card), "Issuer", id_card_get_issuer (id_card));
260                                 g_key_file_set_string (key_file, id_card_get_issuer (id_card), "Username", id_card_get_username (id_card));
261                                 g_key_file_set_string (key_file, id_card_get_issuer (id_card), "Password", id_card_get_password (id_card));
262                                 g_key_file_set_string_list (key_file, id_card_get_issuer (id_card), "Services", (const gchar* const*) id_card_get_services (id_card, &_tmp0_), _tmp0_);
263                                 _g_object_unref0 (id_card);
264                         }
265                 }
266         }
267         text = g_key_file_to_data (key_file, NULL, NULL);
268         {
269                 char* path;
270                 char* filename;
271                 path = identities_manager_get_data_dir (self);
272                 filename = g_build_filename (path, IDENTITIES_MANAGER_FILE_NAME, NULL);
273                 g_file_set_contents (filename, text, (gssize) (-1), &_inner_error_);
274                 if (_inner_error_ != NULL) {
275                         _g_free0 (filename);
276                         _g_free0 (path);
277                         goto __catch2_g_error;
278                 }
279                 _g_free0 (filename);
280                 _g_free0 (path);
281         }
282         goto __finally2;
283         __catch2_g_error:
284         {
285                 GError * e;
286                 e = _inner_error_;
287                 _inner_error_ = NULL;
288                 {
289                         fprintf (stdout, "Error:  %s\n", e->message);
290                         _g_error_free0 (e);
291                 }
292         }
293         __finally2:
294         if (_inner_error_ != NULL) {
295                 _g_free0 (text);
296                 _g_key_file_free0 (key_file);
297                 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
298                 g_clear_error (&_inner_error_);
299                 return;
300         }
301         _g_free0 (text);
302         _g_key_file_free0 (key_file);
303 }
304
305
306 static char* identities_manager_get_data_dir (IdentitiesManager* self) {
307         char* result = NULL;
308         char* path;
309         char* _tmp0_;
310         g_return_val_if_fail (self != NULL, NULL);
311         path = NULL;
312         path = (_tmp0_ = g_build_filename (g_get_user_data_dir (), PACKAGE_TARNAME, NULL), _g_free0 (path), _tmp0_);
313         if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
314                 g_mkdir (path, 0700);
315         }
316         result = path;
317         return result;
318 }
319
320
321 IdCard* identities_manager_load_gss_eap_id_file (IdentitiesManager* self) {
322         IdCard* result = NULL;
323         IdCard* id_card;
324         char* text;
325         char* id_card_data[2] = {0};
326         char* filename;
327         char** _tmp2_;
328         char** _tmp3_;
329         char** _tmp4_ = NULL;
330         char** _tmp5_;
331         gint _tmp5__length1;
332         char** _tmp6_;
333         char* _tmp7_;
334         char* _tmp8_;
335         GdkPixbuf* _tmp9_;
336         GError * _inner_error_ = NULL;
337         g_return_val_if_fail (self != NULL, NULL);
338         id_card = id_card_new ();
339         text = NULL;
340         filename = g_build_filename (g_get_home_dir (), ".gss_eap_id", NULL);
341         {
342                 char* _tmp0_ = NULL;
343                 char* _tmp1_;
344                 g_file_get_contents (filename, &_tmp0_, NULL, &_inner_error_);
345                 text = (_tmp1_ = _tmp0_, _g_free0 (text), _tmp1_);
346                 if (_inner_error_ != NULL) {
347                         goto __catch3_g_error;
348                 }
349         }
350         goto __finally3;
351         __catch3_g_error:
352         {
353                 GError * e;
354                 e = _inner_error_;
355                 _inner_error_ = NULL;
356                 {
357                         result = NULL;
358                         _g_error_free0 (e);
359                         _g_free0 (filename);
360                         _vala_array_destroy (id_card_data, 2, (GDestroyNotify) g_free);
361                         _g_free0 (text);
362                         _g_object_unref0 (id_card);
363                         return result;
364                 }
365         }
366         __finally3:
367         if (_inner_error_ != NULL) {
368                 _g_free0 (filename);
369                 _vala_array_destroy (id_card_data, 2, (GDestroyNotify) g_free);
370                 _g_free0 (text);
371                 _g_object_unref0 (id_card);
372                 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
373                 g_clear_error (&_inner_error_);
374                 return NULL;
375         }
376         if (_vala_strcmp0 (text, "") == 0) {
377                 result = NULL;
378                 _g_free0 (filename);
379                 _vala_array_destroy (id_card_data, 2, (GDestroyNotify) g_free);
380                 _g_free0 (text);
381                 _g_object_unref0 (id_card);
382                 return result;
383         }
384         memcpy (id_card_data, _tmp2_ = g_strsplit (text, "\n", 2), 2 * sizeof (char*));
385         if (_vala_strcmp0 (id_card_data[1], "") != 0) {
386                 id_card_set_password (id_card, id_card_data[1]);
387         }
388         memcpy (id_card_data, _tmp3_ = g_strsplit (id_card_data[0], "@", 2), 2 * sizeof (char*));
389         id_card_set_username (id_card, id_card_data[0]);
390         id_card_set_issuer (id_card, id_card_data[1]);
391         _tmp6_ = (_tmp5_ = (_tmp4_ = g_new0 (char*, 3 + 1), _tmp4_[0] = g_strdup ("email"), _tmp4_[1] = g_strdup ("jabber"), _tmp4_[2] = g_strdup ("irc"), _tmp4_), _tmp5__length1 = 3, _tmp5_);
392         id_card_set_services (id_card, _tmp6_, 3);
393         _tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
394         id_card_set_nai (id_card, _tmp8_ = g_strconcat (_tmp7_ = g_strconcat (id_card_get_username (id_card), "@", NULL), id_card_get_issuer (id_card), NULL));
395         _g_free0 (_tmp8_);
396         _g_free0 (_tmp7_);
397         id_card_set_pixbuf (id_card, _tmp9_ = find_icon ("avatar-default", 48));
398         _g_object_unref0 (_tmp9_);
399         result = id_card;
400         _g_free0 (filename);
401         _vala_array_destroy (id_card_data, 2, (GDestroyNotify) g_free);
402         _g_free0 (text);
403         return result;
404 }
405
406
407 void identities_manager_store_gss_eap_id_file (IdentitiesManager* self, IdCard* id_card) {
408         char* text;
409         char* filename;
410         GError * _inner_error_ = NULL;
411         g_return_if_fail (self != NULL);
412         text = g_strdup ("");
413         if (id_card != NULL) {
414                 char* _tmp0_;
415                 char* _tmp1_;
416                 char* _tmp2_;
417                 char* _tmp3_;
418                 text = (_tmp3_ = g_strconcat (_tmp2_ = g_strconcat (_tmp1_ = g_strconcat (_tmp0_ = g_strconcat (id_card_get_username (id_card), "@", NULL), id_card_get_issuer (id_card), NULL), "\n", NULL), id_card_get_password (id_card), NULL), _g_free0 (text), _tmp3_);
419                 _g_free0 (_tmp2_);
420                 _g_free0 (_tmp1_);
421                 _g_free0 (_tmp0_);
422         }
423         filename = g_build_filename (g_get_home_dir (), ".gss_eap_id", NULL);
424         {
425                 g_file_set_contents (filename, text, (gssize) (-1), &_inner_error_);
426                 if (_inner_error_ != NULL) {
427                         goto __catch4_g_error;
428                 }
429         }
430         goto __finally4;
431         __catch4_g_error:
432         {
433                 GError * e;
434                 e = _inner_error_;
435                 _inner_error_ = NULL;
436                 {
437                         fprintf (stdout, "Error:  %s\n", e->message);
438                         _g_error_free0 (e);
439                 }
440         }
441         __finally4:
442         if (_inner_error_ != NULL) {
443                 _g_free0 (filename);
444                 _g_free0 (text);
445                 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
446                 g_clear_error (&_inner_error_);
447                 return;
448         }
449         _g_free0 (filename);
450         _g_free0 (text);
451 }
452
453
454 static void identities_manager_class_init (IdentitiesManagerClass * klass) {
455         identities_manager_parent_class = g_type_class_peek_parent (klass);
456         G_OBJECT_CLASS (klass)->finalize = identities_manager_finalize;
457 }
458
459
460 static void identities_manager_instance_init (IdentitiesManager * self) {
461 }
462
463
464 static void identities_manager_finalize (GObject* obj) {
465         IdentitiesManager * self;
466         self = IDENTITIES_MANAGER (obj);
467         __g_slist_free_g_object_unref0 (self->id_card_list);
468         G_OBJECT_CLASS (identities_manager_parent_class)->finalize (obj);
469 }
470
471
472 GType identities_manager_get_type (void) {
473         static volatile gsize identities_manager_type_id__volatile = 0;
474         if (g_once_init_enter (&identities_manager_type_id__volatile)) {
475                 static const GTypeInfo g_define_type_info = { sizeof (IdentitiesManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) identities_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IdentitiesManager), 0, (GInstanceInitFunc) identities_manager_instance_init, NULL };
476                 GType identities_manager_type_id;
477                 identities_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "IdentitiesManager", &g_define_type_info, 0);
478                 g_once_init_leave (&identities_manager_type_id__volatile, identities_manager_type_id);
479         }
480         return identities_manager_type_id__volatile;
481 }
482
483
484 static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
485         if ((array != NULL) && (destroy_func != NULL)) {
486                 int i;
487                 for (i = 0; i < array_length; i = i + 1) {
488                         if (((gpointer*) array)[i] != NULL) {
489                                 destroy_func (((gpointer*) array)[i]);
490                         }
491                 }
492         }
493 }
494
495
496 static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
497         _vala_array_destroy (array, array_length, destroy_func);
498         g_free (array);
499 }
500
501
502 static gint _vala_array_length (gpointer array) {
503         int length;
504         length = 0;
505         if (array) {
506                 while (((gpointer*) array)[length]) {
507                         length++;
508                 }
509         }
510         return length;
511 }
512
513
514 static int _vala_strcmp0 (const char * str1, const char * str2) {
515         if (str1 == NULL) {
516                 return -(str1 != str2);
517         }
518         if (str2 == NULL) {
519                 return str1 != str2;
520         }
521         return strcmp (str1, str2);
522 }
523
524
525
526