1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of gsignond
6 * Copyright (C) 2012-2013 Intel Corporation.
8 * Contact: Imran Zaman <imran.zaman@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include "gsignond-identity-info.h"
27 #include "gsignond-identity-info-internal.h"
31 _gsignond_identity_info_seq_cmp (
35 GSequenceIter *iter1 = NULL, *iter2 = NULL;
36 gboolean equal = TRUE;
42 if (g_sequence_get_length (two) == 0)
49 if (g_sequence_get_length (one) == 0)
55 if (g_sequence_get_length (one) != g_sequence_get_length (two))
58 iter1 = g_sequence_get_begin_iter (one);
59 while (!g_sequence_iter_is_end (iter1)) {
60 iter2 = g_sequence_get_iter_at_pos (two,
61 g_sequence_iter_get_position (iter1));
62 if (g_strcmp0 (g_sequence_get (iter1), g_sequence_get (iter2)) != 0) {
66 iter1 = g_sequence_iter_next (iter1);
79 return g_strcmp0 (a,b);
83 _gsignond_identity_info_sequence_to_variant (GSequence *seq)
86 GSequenceIter * iter = NULL;
88 GVariantBuilder builder;
90 if (!seq) return NULL;
92 g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
93 iter = g_sequence_get_begin_iter (seq);
94 while (!g_sequence_iter_is_end (iter)) {
95 const gchar * d = g_sequence_get (iter);
96 g_variant_builder_add (&builder, "s", d);
97 iter = g_sequence_iter_next (iter);
99 var = g_variant_builder_end (&builder);
104 _gsignond_identity_info_variant_to_sequence (GVariant *var)
108 GSequence *seq = NULL;
111 if (!var) return NULL;
113 seq = g_sequence_new ((GDestroyNotify)g_free);
114 g_variant_iter_init (&iter, var);
115 while (g_variant_iter_next (&iter, "s", &item)) {
116 g_sequence_insert_sorted (seq,
118 (GCompareDataFunc) _compare_strings,
125 _gsignond_identity_info_sequence_to_array (GSequence *seq)
127 gchar **items, **temp;
130 if (!seq) return NULL;
132 items = g_malloc0 ((g_sequence_get_length (seq) + 1) * sizeof (gchar *));
134 for (iter = g_sequence_get_begin_iter (seq);
135 iter != g_sequence_get_end_iter (seq);
136 iter = g_sequence_iter_next (iter)) {
137 *temp = g_sequence_get (iter);
144 _gsignond_identity_info_array_to_sequence (gchar **items)
147 GSequence *seq = NULL;
149 if (!items) return NULL;
151 seq = g_sequence_new ((GDestroyNotify) g_free);
153 g_sequence_insert_sorted (seq,
155 (GCompareDataFunc) _compare_strings,
163 _gsignond_identity_info_sec_context_list_cmp (
164 GSignondSecurityContextList *one,
165 GSignondSecurityContextList *two)
167 GSignondSecurityContextList *list_elem1 = NULL, *list_elem2 = NULL;
168 gboolean equal = TRUE;
170 if (one == NULL && two == NULL)
173 if ((one != NULL && two == NULL) ||
174 (one == NULL && two != NULL) ||
175 (g_list_length (one) != g_list_length (two)))
182 for ( ; list_elem1 != NULL; list_elem1 = g_list_next (list_elem1)) {
183 list_elem2 = g_list_nth (two, g_list_position (one, list_elem1));
184 if (!gsignond_security_context_match (
185 (GSignondSecurityContext *)list_elem1->data,
186 (GSignondSecurityContext *)list_elem2->data)) {
196 _gsignond_identity_info_methods_cmp (
200 GHashTableIter iter1;
201 GSequence *mechs1 = NULL, *mechs2 = NULL;
203 gboolean equal = TRUE;
205 if (one == NULL && two == NULL)
208 if ((one != NULL && two == NULL) ||
209 (one == NULL && two != NULL) ||
210 (g_hash_table_size (one) != g_hash_table_size (two)))
216 g_hash_table_iter_init(&iter1, one);
217 while (g_hash_table_iter_next (&iter1, (gpointer *)&key,
218 (gpointer *)&mechs1)) {
219 mechs2 = (GSequence *)g_hash_table_lookup (two, key);
220 equal = _gsignond_identity_info_seq_cmp (mechs1, mechs2);
230 * gsignond_identity_info_new:
232 * Creates new instance of GSignondIdentityInfo.
234 * Returns: (transfer full): #GSignondIdentityInfo object if successful,
237 GSignondIdentityInfo *
238 gsignond_identity_info_new (void)
240 GSignondIdentityInfo *info;
242 info = gsignond_dictionary_new ();
243 gsignond_identity_info_set_id (info, GSIGNOND_IDENTITY_INFO_NEW_IDENTITY);
249 * gsignond_identity_info_copy:
250 * @info: instance of #GSignondIdentityInfo
252 * Creates a copy of info structure.
254 * Returns: copy of the info.
256 GSignondIdentityInfo *
257 gsignond_identity_info_copy (GSignondIdentityInfo *info)
262 return gsignond_dictionary_copy (info);
266 * gsignond_identity_info_ref:
267 * @info: instance of #GSignondIdentityInfo
269 * Increment reference count of the info structure.
272 gsignond_identity_info_ref (GSignondIdentityInfo *info)
274 g_return_if_fail (info != NULL);
276 gsignond_dictionary_ref (info);
280 * gsignond_identity_info_unref:
281 * @info: instance of #GSignondIdentityInfo
283 * Decrement reference count of the info structure.
286 gsignond_identity_info_unref (GSignondIdentityInfo *info)
291 gsignond_dictionary_unref (info);
295 * gsignond_identity_info_get_id:
296 * @info: instance of #GSignondIdentityInfo
298 * Retrieves the id from the info.
300 * Returns: the id; negative id is returned in case of failure.
303 gsignond_identity_info_get_id (GSignondIdentityInfo *info)
305 g_assert (info != NULL);
307 GVariant *var = NULL;
308 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_ID);
310 g_return_val_if_fail (var != NULL, -1);
312 return g_variant_get_uint32 (var);
316 * gsignond_identity_info_set_id:
317 * @info: instance of #GSignondIdentityInfo
321 * Sets the id of the info.
323 * Returns: TRUE if successful, FALSE otherwise.
326 gsignond_identity_info_set_id (
327 GSignondIdentityInfo *info,
330 g_assert (info != NULL);
332 return gsignond_dictionary_set (
334 GSIGNOND_IDENTITY_INFO_ID,
335 g_variant_new_uint32 (id));
339 * gsignond_identity_info_get_is_identity_new:
340 * @info: instance of #GSignondIdentityInfo
342 * Retrieves the info whether the identity is new or not.
344 * Returns: TRUE if new, FALSE otherwise.
347 gsignond_identity_info_get_is_identity_new (GSignondIdentityInfo *info)
349 g_assert (info != NULL);
351 return GSIGNOND_IDENTITY_INFO_NEW_IDENTITY ==
352 gsignond_identity_info_get_id (info);
356 * gsignond_identity_info_set_identity_new:
357 * @info: instance of #GSignondIdentityInfo
359 * Sets the id of the identity info to be new.
361 * Returns: TRUE if successful, FALSE otherwise.
364 gsignond_identity_info_set_identity_new (
365 GSignondIdentityInfo *info)
367 g_assert (info != NULL);
369 return gsignond_identity_info_set_id (
371 GSIGNOND_IDENTITY_INFO_NEW_IDENTITY);
375 * gsignond_identity_info_get_username:
376 * @info: instance of #GSignondIdentityInfo
378 * Retrieves the username from the info.
380 * Returns: the username if successful, NULL otherwise.
383 gsignond_identity_info_get_username (GSignondIdentityInfo *info)
385 g_assert (info != NULL);
387 GVariant *var = NULL;
388 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_USERNAME);
390 return g_variant_get_string (var, NULL);
396 * gsignond_identity_info_set_username:
397 * @info: instance of #GSignondIdentityInfo
399 * @username: username to be set
401 * Sets the username of the info.
403 * Returns: TRUE if successful, FALSE otherwise.
406 gsignond_identity_info_set_username (
407 GSignondIdentityInfo *info,
408 const gchar *username)
410 g_assert (info != NULL);
413 return gsignond_dictionary_remove (info,
414 GSIGNOND_IDENTITY_INFO_USERNAME);
416 return gsignond_dictionary_set (
418 GSIGNOND_IDENTITY_INFO_USERNAME,
419 g_variant_new_string (username));
423 * gsignond_identity_info_remove_username:
424 * @info: instance of #GSignondIdentityInfo
426 * Removes username from the info.
429 gsignond_identity_info_remove_username (GSignondIdentityInfo *info)
431 g_assert (info != NULL);
433 gsignond_dictionary_remove (info, GSIGNOND_IDENTITY_INFO_USERNAME);
437 * gsignond_identity_info_get_is_username_secret:
438 * @info: instance of #GSignondIdentityInfo
440 * Retrieves the is_username_secret flag from the info.
442 * Returns: the is_username_secret flag.
445 gsignond_identity_info_get_is_username_secret (GSignondIdentityInfo *info)
447 g_assert (info != NULL);
449 GVariant *var = NULL;
450 var = gsignond_dictionary_get (info,
451 GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET);
453 return g_variant_get_boolean (var);
459 * gsignond_identity_info_set_username_secret:
460 * @info: instance of #GSignondIdentityInfo
462 * @store_secret: store_secret to be set
464 * Sets the store_secret of the info.
466 * Returns: TRUE if successful, FALSE otherwise.
469 gsignond_identity_info_set_username_secret (
470 GSignondIdentityInfo *info,
471 gboolean username_secret)
473 g_assert (info != NULL);
475 return gsignond_dictionary_set (
477 GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET,
478 g_variant_new_boolean(username_secret));
482 * gsignond_identity_info_get_secret:
483 * @info: instance of #GSignondIdentityInfo
485 * Retrieves the secret from the info.
487 * Returns: the secret if successful, NULL otherwise.
490 gsignond_identity_info_get_secret (GSignondIdentityInfo *info)
492 g_assert (info != NULL);
494 GVariant *var = NULL;
495 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_SECRET);
497 return g_variant_get_string (var, NULL);
503 * gsignond_identity_info_set_secret:
504 * @info: instance of #GSignondIdentityInfo
506 * @secret: secret to be set
508 * Sets the secret of the info.
510 * Returns: TRUE if successful, FALSE otherwise.
513 gsignond_identity_info_set_secret (
514 GSignondIdentityInfo *info,
517 g_assert (info != NULL);
520 return gsignond_dictionary_remove (info,
521 GSIGNOND_IDENTITY_INFO_SECRET);
523 return gsignond_dictionary_set (
525 GSIGNOND_IDENTITY_INFO_SECRET,
526 g_variant_new_string (secret));
530 * gsignond_identity_info_remove_secret:
531 * @info: instance of #GSignondIdentityInfo
533 * Removes secret from the info.
536 gsignond_identity_info_remove_secret (GSignondIdentityInfo *info)
538 g_assert (info != NULL);
540 gsignond_dictionary_remove (info, GSIGNOND_IDENTITY_INFO_SECRET);
544 * gsignond_identity_info_get_store_secret:
545 * @info: instance of #GSignondIdentityInfo
547 * Retrieves the store_secret flag from the info.
549 * Returns: the store_secret flag.
552 gsignond_identity_info_get_store_secret (GSignondIdentityInfo *info)
554 g_assert (info != NULL);
556 GVariant *var = NULL;
557 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_STORESECRET);
559 return g_variant_get_boolean (var);
565 * gsignond_identity_info_set_store_secret:
566 * @info: instance of #GSignondIdentityInfo
568 * @store_secret: store_secret to be set
570 * Sets the store_secret of the info.
572 * Returns: TRUE if successful, FALSE otherwise.
575 gsignond_identity_info_set_store_secret (
576 GSignondIdentityInfo *info,
577 gboolean store_secret)
579 g_assert (info != NULL);
581 return gsignond_dictionary_set (
583 GSIGNOND_IDENTITY_INFO_STORESECRET,
584 g_variant_new_boolean(store_secret));
588 * gsignond_identity_info_get_caption:
589 * @info: instance of #GSignondIdentityInfo
591 * Retrieves the caption from the info.
593 * Returns: the caption if successful, NULL otherwise.
596 gsignond_identity_info_get_caption (GSignondIdentityInfo *info)
598 g_assert (info != NULL);
600 GVariant *var = NULL;
601 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_CAPTION);
603 return g_variant_get_string (var, NULL);
609 * gsignond_identity_info_set_caption:
610 * @info: instance of #GSignondIdentityInfo
612 * @caption: caption to be set
614 * Sets the caption of the info.
616 * Returns: TRUE in case of success, FALSE otherwise.
619 gsignond_identity_info_set_caption (
620 GSignondIdentityInfo *info,
621 const gchar *caption)
623 g_assert (info != NULL);
626 return gsignond_dictionary_remove (info,
627 GSIGNOND_IDENTITY_INFO_CAPTION);
629 return gsignond_dictionary_set (
631 GSIGNOND_IDENTITY_INFO_CAPTION,
632 g_variant_new_string (caption));
636 * gsignond_identity_info_get_realms:
637 * @info: instance of #GSignondIdentityInfo
639 * Retrieves the realms from the info.
641 * Returns: (transfer full): the realms if successful, NULL Otherwise.
642 * when done realms should be freed using g_sequence_free.
645 gsignond_identity_info_get_realms (GSignondIdentityInfo *info)
647 g_assert (info != NULL);
649 GVariant *var = NULL;
650 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_REALMS);
652 return _gsignond_identity_info_variant_to_sequence (var);
658 * gsignond_identity_info_set_realms:
659 * @info: instance of #GSignondIdentityInfo
661 * @realms: (transfer none): realms to be set
663 * Sets the realms of the info.
665 * Returns: TRUE if successful, FALSE otherwise.
668 gsignond_identity_info_set_realms (
669 GSignondIdentityInfo *info,
672 g_assert (info != NULL);
674 g_return_val_if_fail (realms != NULL, FALSE);
675 return gsignond_dictionary_set (
677 GSIGNOND_IDENTITY_INFO_REALMS,
678 _gsignond_identity_info_sequence_to_variant (realms));
682 * gsignond_identity_info_get_methods:
683 * @info: instance of #GSignondIdentityInfo
685 * Retrieves the methods from the info whereas #GHashTable consists of
686 * (gchar*,GSequence*) and #GSequence is a sequence of gchar *.
688 * Returns: (transfer full): the methods if successful, NULL otherwise.
689 * when done, methods should be freed using g_hash_table_unref.
692 gsignond_identity_info_get_methods (GSignondIdentityInfo *info)
694 g_assert (info != NULL);
696 GVariant *var = NULL;
697 GHashTable *methods = NULL;
698 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_AUTHMETHODS);
702 gchar **vmechanisms = NULL;
703 GSequence *seq = NULL;
705 methods = g_hash_table_new_full ((GHashFunc) g_str_hash,
706 (GEqualFunc) g_str_equal,
707 (GDestroyNotify) g_free,
708 (GDestroyNotify) g_sequence_free);
710 g_variant_iter_init (&iter, var);
711 while (g_variant_iter_next (&iter, "{s^as}", &vmethod, &vmechanisms))
713 /* ownership of all content is transferred */
714 seq = _gsignond_identity_info_array_to_sequence (vmechanisms);
715 g_hash_table_insert (methods, vmethod, seq);
716 g_free (vmechanisms);
723 * gsignond_identity_info_set_methods:
724 * @info: instance of #GSignondIdentityInfo
726 * @methods: (transfer none): methods to be set whereas #GHashTable consists of
727 * (gchar*,#GSequence*) and #GSequence is a sequence of gchar *.
729 * Sets the methods of the info.
731 * Returns: TRUE if successful, FALSE otherwise.
734 gsignond_identity_info_set_methods (
735 GSignondIdentityInfo *info,
738 g_assert (info != NULL);
740 gchar **items = NULL;
741 GVariantBuilder builder;
745 GSequence *mechanisms = NULL;
747 g_return_val_if_fail (info != NULL, FALSE);
748 g_return_val_if_fail (methods != NULL, FALSE);
750 g_variant_builder_init (&builder, (const GVariantType *)"a{sas}");
751 g_hash_table_iter_init (&iter, methods);
752 while (g_hash_table_iter_next (&iter,
754 (gpointer)&mechanisms))
756 items = _gsignond_identity_info_sequence_to_array (mechanisms);
757 g_variant_builder_add (&builder, "{s^as}", method, items);
760 return gsignond_dictionary_set (
762 GSIGNOND_IDENTITY_INFO_AUTHMETHODS,
763 g_variant_builder_end (&builder));
767 * gsignond_identity_info_get_mechanisms:
768 * @info: instance of #GSignondIdentityInfo
770 * @method: the method for which mechanisms are sought
772 * Retrieves the mechanisms from the info.
774 * Returns: (transfer full): the mechanisms if successful, NULL otherwise.
775 * when done, mechanisms should be freed using g_sequence_free; #GSequence is a
776 * sequence of gchar *.
779 gsignond_identity_info_get_mechanisms (
780 GSignondIdentityInfo *info,
783 g_assert (info != NULL);
785 GVariant *var = NULL;
786 GSequence *mechanisms = NULL;
788 g_return_val_if_fail (method != NULL, NULL);
790 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_AUTHMETHODS);
796 g_variant_iter_init (&iter, var);
797 while (g_variant_iter_next (&iter, "{s^as}", &vmethod, &vmechanisms))
799 /* ownership of content is transferred */
800 if (vmethod != NULL && g_strcmp0 (vmethod, method) == 0) {
801 mechanisms = _gsignond_identity_info_array_to_sequence (
804 g_free (vmechanisms);
807 g_free (vmethod); vmethod = NULL;
808 g_strfreev (vmechanisms); vmechanisms = NULL;
815 * gsignond_identity_info_remove_method:
816 * @info: instance of #GSignondIdentityInfo
818 * Removes the method from the info.
820 * Returns: TRUE if successful, FALSE otherwise.
823 gsignond_identity_info_remove_method (
824 GSignondIdentityInfo *info,
827 g_assert (info != NULL);
829 GHashTable *methods = NULL;
830 gboolean ret = FALSE;
832 g_return_val_if_fail (method != NULL, FALSE);
834 methods = gsignond_identity_info_get_methods (info);
835 if (methods && g_hash_table_remove (methods, method)) {
836 ret = gsignond_identity_info_set_methods (info, methods);
839 g_hash_table_unref (methods);
844 * gsignond_identity_info_get_access_control_list:
845 * @info: instance of #GSignondIdentityInfo
847 * Retrieves the access control list from the info.
849 * Returns: (transfer full): the list if successful, NULL otherwise.
850 * when done, list should be freed using gsignond_security_context_list_free.
852 GSignondSecurityContextList *
853 gsignond_identity_info_get_access_control_list (GSignondIdentityInfo *info)
855 g_assert (info != NULL);
857 GVariant *var = NULL;
858 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_ACL);
860 return gsignond_security_context_list_from_variant (var);
866 * gsignond_identity_info_set_access_control_list:
867 * @info: instance of #GSignondIdentityInfo
869 * @acl: (transfer none): access control list to be set
871 * Sets the access control list of the info.
873 * Returns: TRUE if successful, FALSE otherwise.
876 gsignond_identity_info_set_access_control_list (
877 GSignondIdentityInfo *info,
878 const GSignondSecurityContextList *acl)
880 g_assert (info != NULL);
882 g_return_val_if_fail (acl != NULL, FALSE);
883 return gsignond_dictionary_set (
885 GSIGNOND_IDENTITY_INFO_ACL,
886 gsignond_security_context_list_to_variant (acl));
890 * gsignond_identity_info_get_owner:
891 * @info: instance of #GSignondIdentityInfo
893 * Retrieves the id from the info.
895 * Returns: (transfer full): the owner if successful, NULL otherwise.
896 * when done, owner list should be freed using
897 * gsignond_security_context_free.
899 GSignondSecurityContext *
900 gsignond_identity_info_get_owner (GSignondIdentityInfo *info)
902 g_assert (info != NULL);
904 GVariant *var = NULL;
905 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_OWNER);
907 return gsignond_security_context_from_variant (var);
913 * gsignond_identity_info_set_owner:
914 * @info: instance of #GSignondIdentityInfo
916 * @owners: (transfer none): owner to be set
918 * Sets the owner of the info.
920 * Returns: TRUE if successful, FALSE otherwise.
923 gsignond_identity_info_set_owner (
924 GSignondIdentityInfo *info,
925 const GSignondSecurityContext *owners)
927 g_assert (info != NULL);
929 g_return_val_if_fail (owners != NULL, FALSE);
930 return gsignond_dictionary_set (
932 GSIGNOND_IDENTITY_INFO_OWNER,
933 gsignond_security_context_to_variant (owners));
937 * gsignond_identity_info_get_validated:
938 * @info: instance of #GSignondIdentityInfo
940 * Retrieves the validated flag from the info.
942 * Returns: the validated flag.
945 gsignond_identity_info_get_validated (GSignondIdentityInfo *info)
947 g_assert (info != NULL);
949 GVariant *var = NULL;
950 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_VALIDATED);
952 return g_variant_get_boolean (var);
958 * gsignond_identity_info_set_validated:
959 * @info: instance of #GSignondIdentityInfo
961 * @validated: validated flag to be set
963 * Sets the validated flag of the info.
965 * Returns: TRUE if successful, FALSE otherwise.
968 gsignond_identity_info_set_validated (
969 GSignondIdentityInfo *info,
972 g_assert (info != NULL);
974 return gsignond_dictionary_set (
976 GSIGNOND_IDENTITY_INFO_VALIDATED,
977 g_variant_new_boolean (validated));
981 * gsignond_identity_info_get_identity_type:
982 * @info: instance of #GSignondIdentityInfo
984 * Retrieves the type from the info.
986 * Returns: the type; negative type is returned in case of failure.
989 gsignond_identity_info_get_identity_type (GSignondIdentityInfo *info)
991 g_assert (info != NULL);
993 GVariant *var = NULL;
994 var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_TYPE);
996 return g_variant_get_int32 (var);
1002 * gsignond_identity_info_set_identity_type:
1003 * @info: instance of #GSignondIdentityInfo
1005 * @type: type to be set
1007 * Sets the type of the info.
1009 * Returns: TRUE if successful, FALSE otherwise.
1012 gsignond_identity_info_set_identity_type (
1013 GSignondIdentityInfo *info,
1016 g_assert (info != NULL);
1018 return gsignond_dictionary_set (
1020 GSIGNOND_IDENTITY_INFO_TYPE,
1021 g_variant_new_int32 (type));
1025 * gsignond_identity_info_compare:
1026 * @info: instance1 of #GSignondIdentityInfo
1028 * @other: instance2 of #GSignondIdentityInfo
1030 * Compares two instances of #GSignondIdentityInfo for equality.
1032 * Returns: TRUE if the two instances are equal, FALSE otherwise.
1035 gsignond_identity_info_compare (
1036 GSignondIdentityInfo *info,
1037 GSignondIdentityInfo *other)
1039 g_assert (info != NULL && other != NULL);
1041 GSequence *info_realms = NULL, *other_realms = NULL;
1042 GHashTable *info_methods = NULL, *other_methods = NULL;
1043 GSignondSecurityContextList *info_acl = NULL, *other_acl = NULL;
1044 GSignondSecurityContext *info_owner = NULL, *other_owner = NULL;
1045 gboolean equal = FALSE;
1050 if (info == NULL || other == NULL)
1053 if (gsignond_identity_info_get_id (info) !=
1054 gsignond_identity_info_get_id (other)) {
1058 if (g_strcmp0 (gsignond_identity_info_get_username (info),
1059 gsignond_identity_info_get_username (other)) != 0) {
1063 if (g_strcmp0 (gsignond_identity_info_get_secret (info),
1064 gsignond_identity_info_get_secret (other)) != 0) {
1068 if (gsignond_identity_info_get_store_secret (info) !=
1069 gsignond_identity_info_get_store_secret (other)) {
1073 if (g_strcmp0 (gsignond_identity_info_get_caption (info),
1074 gsignond_identity_info_get_caption (other)) != 0) {
1078 info_realms = gsignond_identity_info_get_realms (info);
1079 other_realms = gsignond_identity_info_get_realms (other);
1080 equal = _gsignond_identity_info_seq_cmp (info_realms, other_realms);
1081 if (info_realms) g_sequence_free (info_realms);
1082 if (other_realms) g_sequence_free (other_realms);
1087 info_methods = gsignond_identity_info_get_methods (info);
1088 other_methods = gsignond_identity_info_get_methods (other);
1089 equal = _gsignond_identity_info_methods_cmp (info_methods, other_methods);
1090 if (info_methods) g_hash_table_unref (info_methods);
1091 if (other_methods) g_hash_table_unref (other_methods);
1096 info_acl = gsignond_identity_info_get_access_control_list (info);
1098 info_acl = g_list_sort (
1100 (GCompareFunc)gsignond_security_context_compare);
1101 other_acl = gsignond_identity_info_get_access_control_list (other);
1103 other_acl = g_list_sort (
1105 (GCompareFunc)gsignond_security_context_compare);
1106 equal = _gsignond_identity_info_sec_context_list_cmp (info_acl, other_acl);
1107 if (info_acl) gsignond_security_context_list_free (info_acl);
1108 if (other_acl) gsignond_security_context_list_free (other_acl);
1113 info_owner = gsignond_identity_info_get_owner (info);
1114 other_owner = gsignond_identity_info_get_owner (other);
1115 equal = gsignond_security_context_match (info_owner, other_owner);
1116 if (info_owner) gsignond_security_context_free (info_owner);
1117 if (other_owner) gsignond_security_context_free (other_owner);
1122 if (gsignond_identity_info_get_validated (info) !=
1123 gsignond_identity_info_get_validated (other)) {
1127 if (gsignond_identity_info_get_identity_type (info) !=
1128 gsignond_identity_info_get_identity_type (other)) {
1136 gsignond_identity_info_list_free (GSignondIdentityInfoList *list)
1138 g_return_if_fail (list != NULL);
1139 g_list_free_full (list, (GDestroyNotify)gsignond_identity_info_unref);