From: Alexandra Ellwood Date: Thu, 11 Sep 2008 21:30:10 +0000 (+0000) Subject: Removed favorite identities object from public API and merged functionality X-Git-Tag: krb5-1.7-alpha1~439 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cbb1c9234d8ac30b56be08ffac77c4127de82b6e;p=krb5.git Removed favorite identities object from public API and merged functionality into the preferences API to reduce function calls. Added options parameter to favorite identities (Mac OS X support still needed for options though). Updated test cases to reflect these changes. ticket: 6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20712 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/kim/kim_preferences.h b/src/include/kim/kim_preferences.h index 15e2e3eb0..fd9797523 100644 --- a/src/include/kim/kim_preferences.h +++ b/src/include/kim/kim_preferences.h @@ -31,142 +31,6 @@ extern "C" { #include -/*! - * \page kim_favorite_identities_overview KIM Favorite Identities Overview - * - * \section kim_favorite_identities_introduction Introduction - * - * As Kerberos becomes more widespread, the number of possible Kerberos - * identities and realms a user might want to use will become very large. - * Sites may list hundreds of realms in their Kerberos configuration files. - * In addition, sites may wish to use DNS SRV records to avoid having to list - * all the realms they use in their Kerberos configuration. As a result, the - * list of realms in the Kerberos configuration may be exceedingly large and/or - * incomplete. Users may also use multiple identities from the same realm. - * - * On platforms which use a GUI to acquire credentials, the KIM would like - * to to display a list of identities for the user to select from. Depending on - * what is appropriate for the platform, identities may be displayed in a popup - * menu or other list. - * - * To solve this problem, the KIM maintains a list of favorite identities - * specifically for identity selection. This list is a set of unique identities - * in alphabetical order (as appropriate for the user's language localization). - * - * On most platforms the list of favorite identities has both an administrator - * preference and a user preference which overrides it. The administrator - * preference exists only to initialize the favorite identities for new user - * accounts. Once the user modifies the list their favorite identities may - * diverge from the site favorite identities preference. - * - * \note The location of user preferences and the semantics of - * preference synchronization is platform-specific. Where possible KIM will use - * platform-specific preference mechanisms. - * - * Most callers will not need to use the favorite identities APIs. However if you - * are implementing your own graphical prompt callback or a credential management - * application, you may to view and/or edit the user's favorite identities. - * - * \section kim_favorite_identities_edit Viewing and Editing the Favorite Identities - * - * First, you need to acquire the Favorite Identities stored in the user's - * preferences using #kim_preferences_create() and - * #kim_preferences_get_favorite_identities(). Or you can use - * #kim_favorite_identities_create() to get an empty identities list if you want to - * overwrite the user's identities list entirely. See \ref kim_preferences_overview - * for more information on modifying the user's preferences. - * - * Then use #kim_favorite_identities_get_number_of_identities() and - * #kim_favorite_identities_get_identity_at_index() to display the identities list. - * Use #kim_favorite_identities_add_identity() and #kim_favorite_identities_remove_identity() - * to change which identities are in the identities list. Identities are always stored in - * alphabetical order and duplicate identities are not permitted, so when you add or remove a - * identity you should redisplay the entire list. - * - * Once you are done editing the identities list, store changes in the user's preference file - * using #kim_preferences_set_favorite_identities() and #kim_preferences_synchronize(). - * - * See \ref kim_favorite_identities_reference for information on specific APIs. - */ - -/*! - * \defgroup kim_favorite_identities_reference KIM Favorite Identities Documentation - * @{ - */ - -/*! - * \param out_favorite_identities on exit, a new favorite identities object. - * Must be freed with kim_favorite_identities_free(). - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Create a new favorite identities list. - */ -kim_error kim_favorite_identities_create (kim_favorite_identities *out_favorite_identities); - -/*! - * \param out_favorite_identities on exit, a new favorite identities object which is - * a copy of in_favorite_identities. - * Must be freed with kim_favorite_identities_free(). - * \param in_favorite_identities a favorite identities object. - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Copy a favorite identities list. - */ -kim_error kim_favorite_identities_copy (kim_favorite_identities *out_favorite_identities, - kim_favorite_identities in_favorite_identities); - -/*! - * \param in_favorite_identities a favorite identities object. - * \param out_number_of_identities on exit, the number of identities in \a in_favorite_identities. - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Get the number of identities in a favorite identities list. - */ -kim_error kim_favorite_identities_get_number_of_identities (kim_favorite_identities in_favorite_identities, - kim_count *out_number_of_identities); - -/*! - * \param in_favorite_identities a favorite identities object. - * \param in_index a index into the identities list (starting at 0). - * \param out_realm on exit, the identity at \a in_index in \a in_favorite_identities. - * Must be freed with kim_string_free(). - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Get the Nth identity in a favorite identities list. - */ -kim_error kim_favorite_identities_get_identity_at_index (kim_favorite_identities in_favorite_identities, - kim_count in_index, - kim_identity *out_identity); -/*! - * \param io_favorite_identities a favorite identities object. - * \param in_identity an identity string to add to \a in_favorite_identities. - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Add an identity to a favorite identities list. - */ -kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favorite_identities, - kim_identity in_identity); - -/*! - * \param io_favorite_identities a favorite identities object. - * \param in_identity an identity to remove from \a in_favorite_identities. - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Remove an identity from a identities list. - */ -kim_error kim_favorite_identities_remove_identity (kim_favorite_identities io_favorite_identities, - kim_identity in_identity); - -/*! - * \param io_favorite_identities a favorite identities object. - * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Empty a favorite identities list. - */ -kim_error kim_favorite_identities_remove_all_identities (kim_favorite_identities io_favorite_identities); - -/*! - * \param io_favorite_identities the favorite identities object to be freed. Set to NULL on exit. - * \brief Free memory associated with an identities list. - */ - -void kim_favorite_identities_free (kim_favorite_identities *io_favorite_identities); - -/*!@}*/ - /*! * \page kim_preferences_overview KIM Preferences Overview * @@ -228,13 +92,51 @@ void kim_favorite_identities_free (kim_favorite_identities *io_favorite_identiti * * \section kim_preferences_favorite_identities Favorite Identities Preferences * - * When presenting a graphical interface for credential acquisition, KIM - * may need to display a list of identities for the user to select from. - * This list is generated by the user's favorite identities preference. - * You can view and edit the favorite identities preference using - * #kim_preferences_get_favorite_identities() and - * #kim_preferences_set_favorite_identities(). Please see the - * \ref kim_favorite_identities_overview for more information. + * As Kerberos becomes more widespread, the number of possible Kerberos + * identities and realms a user might want to use will become very large. + * Sites may list hundreds of realms in their Kerberos configuration files. + * In addition, sites may wish to use DNS SRV records to avoid having to list + * all the realms they use in their Kerberos configuration. As a result, the + * list of realms in the Kerberos configuration may be exceedingly large and/or + * incomplete. Users may also use multiple identities from the same realm. + * + * On platforms which use a GUI to acquire credentials, the KIM would like + * to to display a list of identities for the user to select from. Depending on + * what is appropriate for the platform, identities may be displayed in a popup + * menu or other list. + * + * To solve this problem, the KIM maintains a list of favorite identities + * specifically for identity selection. This list is a set of unique identities + * in alphabetical order (as appropriate for the user's language localization). + * + * Each identity may optionally have its own options for ticket acquisition. + * This allows KIM UIs to remember what ticket options worked for a specific + * identity. For example if the user normally wants renewable tickets but + * they have one identity at a KDC which rejects requests for renewable tickets, + * the "not renewable" option can be associated with that identity without + * changing the user's default preference to get renewable tickets. If an + * identity should use the default options, just pass KIM_OPTIONS_DEFAULT. + * + * Most callers will not need to use the favorite identities APIs. However if you + * are implementing your own graphical prompt callback or a credential management + * application, you may to view and/or edit the user's favorite identities. + * + * \section kim_favorite_identities_edit Viewing and Editing the Favorite Identities + * + * First, you need to acquire the Favorite Identities stored in the user's + * preferences using #kim_preferences_create(). + * + * Then use #kim_preferences_get_number_of_favorite_identities() and + * #kim_preferences_get_favorite_identity_at_index() to display the identities list. + * Use #kim_preferences_add_favorite_identity() and #kim_preferences_remove_favorite_identity() + * to change which identities are in the identities list. Identities are always stored in + * alphabetical order and duplicate identities are not permitted, so when you add or remove a + * identity you should redisplay the entire list. If you wish to replace the + * identities list entirely, use #kim_preferences_remove_all_favorite_identities() + * to clear the list before adding your identities. + * + * Once you are done editing the favorite identities list, store changes in the + * user's preference file using #kim_preferences_synchronize(). * * See \ref kim_preferences_reference for information on specific APIs. */ @@ -439,28 +341,59 @@ kim_error kim_preferences_get_maximum_renewal_lifetime (kim_preferences in_pref kim_lifetime *out_maximum_renewal_lifetime); /*! - * \param io_preferences a preferences object to modify. - * \param in_favorite_identities a favorite identities object. - * See \ref kim_favorite_identities_overview for more information on KIM - * Favorite Identities. + * \param in_preferences a preferences object. + * \param out_number_of_identities on exit, the number of identities in \a in_preferences. + * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. + * \brief Get the number of favorite identities in a preferences object. + */ +kim_error kim_preferences_get_number_of_favorite_identities (kim_preferences in_preferences, + kim_count *out_number_of_identities); + +/*! + * \param kim_preferences a preferences object. + * \param in_index a index into the identities list (starting at 0). + * \param out_identity on exit, the identity at \a in_index in \a in_preferences. + * Must be freed with kim_string_free(). + * \param out_options on exit, the options associated with identity at \a in_index + * in \a in_favorite_identities. May be KIM_OPTIONS_DEFAULT. + * Pass NULL if you do not want the options associated with the identity. + * Must be freed with kim_options_free(). + * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. + * \brief Get the Nth favorite identity in a preferences object. + */ +kim_error kim_preferences_get_favorite_identity_at_index (kim_preferences in_preferences, + kim_count in_index, + kim_identity *out_identity, + kim_options *out_options); + +/*! + * \param io_preferences a preferences object. + * \param in_identity an identity to add to \a io_preferences. + * \param in_options options which will be associated with that identity. + * Use KIM_OPTIONS_DEFAULT if the identity should use + * the user's default options. + * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. + * \brief Add a favorite identity to a preferences object. + */ +kim_error kim_preferences_add_favorite_identity (kim_preferences io_preferences, + kim_identity in_identity, + kim_options in_options); + +/*! + * \param io_preferences a preferences object. + * \param in_identity an identity to remove from \a io_preferences. * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Set the user's preferred list of identities. - * \sa kim_preferences_get_favorite_identities() + * \brief Remove a favorite identity from a preferences object. */ -kim_error kim_preferences_set_favorite_identities (kim_preferences io_preferences, - kim_favorite_identities in_favorite_identities); +kim_error kim_preferences_remove_favorite_identity (kim_preferences io_preferences, + kim_identity in_identity); /*! - * \param in_preferences a preferences object. - * \param out_favorite_identities on exit, a copy of the favorite identities specified in \a in_preferences. - * See \ref kim_favorite_identities_overview for more information on KIM - * Favorite Identities. Must be freed with kim_favorite_identities_free(). + * \param io_preferences a preferences object. * \return On success, #KIM_NO_ERROR. On failure, an error code representing the failure. - * \brief Get the user's preferred list of identities. - * \sa kim_preferences_set_favorite_identities() + * \brief Remove all favorite identities in a preferences object. */ -kim_error kim_preferences_get_favorite_identities (kim_preferences in_preferences, - kim_favorite_identities *out_favorite_identities); +kim_error kim_preferences_remove_all_favorite_identities (kim_preferences io_preferences); /*! * \param in_preferences a preferences object. diff --git a/src/include/kim/kim_types.h b/src/include/kim/kim_types.h index 9c611d226..545d7479c 100644 --- a/src/include/kim/kim_types.h +++ b/src/include/kim/kim_types.h @@ -122,12 +122,6 @@ struct kim_selection_hints_opaque; */ typedef struct kim_selection_hints_opaque *kim_selection_hints; -struct kim_favorite_identities_opaque; -/*! - * A KIM Favorite Realms object. See \ref kim_favorite_identities_overview for more information. - */ -typedef struct kim_favorite_identities_opaque *kim_favorite_identities; - struct kim_preferences_opaque; /*! * A KIM Preferences object. See \ref kim_preferences_overview for more information. diff --git a/src/kim/lib/kim.exports b/src/kim/lib/kim.exports index 8792c74f8..a685aeea6 100644 --- a/src/kim/lib/kim.exports +++ b/src/kim/lib/kim.exports @@ -27,12 +27,6 @@ kim_prompt_callback_none kim_options_create kim_options_copy -kim_options_set_prompt_callback -kim_options_get_prompt_callback -kim_options_set_data -kim_options_get_data -kim_options_set_prompt_response -kim_options_get_prompt_response kim_options_set_start_time kim_options_get_start_time kim_options_set_lifetime @@ -70,15 +64,6 @@ kim_selection_hints_remember_identity kim_selection_hints_forget_identity kim_selection_hints_free -kim_favorite_identities_create -kim_favorite_identities_copy -kim_favorite_identities_get_number_of_identities -kim_favorite_identities_get_identity_at_index -kim_favorite_identities_add_identity -kim_favorite_identities_remove_identity -kim_favorite_identities_remove_all_identities -kim_favorite_identities_free - kim_preferences_create kim_preferences_copy kim_preferences_set_options @@ -89,8 +74,11 @@ kim_preferences_set_client_identity kim_preferences_get_client_identity kim_preferences_set_remember_client_identity kim_preferences_get_remember_client_identity -kim_preferences_set_favorite_identities -kim_preferences_get_favorite_identities +kim_preferences_get_number_of_favorite_identities +kim_preferences_get_favorite_identity_at_index +kim_preferences_add_favorite_identity +kim_preferences_remove_favorite_identity +kim_preferences_remove_all_favorite_identities kim_preferences_synchronize kim_preferences_free diff --git a/src/kim/lib/kim_options.c b/src/kim/lib/kim_options.c index d5bba9a84..f210bb4fa 100644 --- a/src/kim/lib/kim_options.c +++ b/src/kim/lib/kim_options.c @@ -129,35 +129,36 @@ kim_error kim_options_copy (kim_options *out_options, kim_options in_options) { kim_error err = KIM_NO_ERROR; - kim_options options = NULL; + kim_options options = KIM_OPTIONS_DEFAULT; if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err) { + if (!err && in_options != KIM_OPTIONS_DEFAULT) { err = kim_options_allocate (&options); - } - - if (!err) { - options->prompt_callback = in_options->prompt_callback; - options->prompt_callback_data = in_options->prompt_callback_data; + + if (!err) { + options->prompt_callback = in_options->prompt_callback; + options->prompt_callback_data = in_options->prompt_callback_data; #warning copy prompt responses here - } - - if (!err) { - options->start_time = in_options->start_time; - options->lifetime = in_options->lifetime; - options->renewable = in_options->renewable; - options->renewal_lifetime = in_options->renewal_lifetime; - options->forwardable = in_options->forwardable; - options->proxiable = in_options->proxiable; - options->addressless = in_options->addressless; + } - if (in_options->service_name) { - err = kim_string_copy (&options->service_name, in_options->service_name); + if (!err) { + options->start_time = in_options->start_time; + options->lifetime = in_options->lifetime; + options->renewable = in_options->renewable; + options->renewal_lifetime = in_options->renewal_lifetime; + options->forwardable = in_options->forwardable; + options->proxiable = in_options->proxiable; + options->addressless = in_options->addressless; + + if (in_options->service_name) { + err = kim_string_copy (&options->service_name, + in_options->service_name); + } } } - + if (!err) { *out_options = options; options = NULL; diff --git a/src/kim/lib/kim_preferences.c b/src/kim/lib/kim_preferences.c index f64ae5c15..6b1fb5cc9 100644 --- a/src/kim/lib/kim_preferences.c +++ b/src/kim/lib/kim_preferences.c @@ -26,76 +26,103 @@ #include "kim_private.h" -#pragma mark -- KIM Favorite Realms -- - -struct kim_favorite_identities_opaque { +struct kim_favorites_opaque { kim_count count; kim_identity *identities; + kim_options *options; }; -struct kim_favorite_identities_opaque kim_favorite_identities_initializer = { 0, NULL }; -struct kim_favorite_identities_opaque kim_empty_favorite_identities_struct = { 0, NULL }; -const kim_favorite_identities kim_empty_favorite_identities = &kim_empty_favorite_identities_struct; +struct kim_preferences_opaque { + kim_options options; + kim_boolean options_changed; + kim_boolean remember_options; + kim_boolean remember_options_changed; + kim_identity client_identity; + kim_boolean client_identity_changed; + kim_boolean remember_client_identity; + kim_boolean remember_client_identity_changed; + kim_lifetime minimum_lifetime; + kim_lifetime maximum_lifetime; + kim_boolean lifetime_range_changed; + kim_lifetime minimum_renewal_lifetime; + kim_lifetime maximum_renewal_lifetime; + kim_boolean renewal_lifetime_range_changed; + struct kim_favorites_opaque favorites; + kim_boolean favorites_changed; +}; +const struct kim_favorites_opaque kim_default_favorites = { 0, NULL, NULL }; -/* ------------------------------------------------------------------------ */ +struct kim_preferences_opaque kim_preferences_initializer = { +NULL, +FALSE, +kim_default_remember_options, +FALSE, +kim_default_client_identity, +FALSE, +kim_default_remember_client_identity, +FALSE, +kim_default_minimum_lifetime, +kim_default_maximum_lifetime, +FALSE, +kim_default_minimum_renewal_lifetime, +kim_default_maximum_renewal_lifetime, +FALSE, +{ 0, NULL, NULL }, +FALSE +}; -static inline kim_error kim_favorite_identities_allocate (kim_favorite_identities *out_favorite_identities) -{ - kim_error err = KIM_NO_ERROR; - kim_favorite_identities favorite_identities = NULL; - - if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - - if (!err) { - favorite_identities = malloc (sizeof (*favorite_identities)); - if (!favorite_identities) { err = KIM_OUT_OF_MEMORY_ERR; } - } - - if (!err) { - *favorite_identities = kim_favorite_identities_initializer; - *out_favorite_identities = favorite_identities; - favorite_identities = NULL; - } - - kim_favorite_identities_free (&favorite_identities); - - return check_error (err); -} /* ------------------------------------------------------------------------ */ -static inline kim_error kim_favorite_identities_resize (kim_favorite_identities io_favorite_identities, - kim_count in_new_count) +static kim_error kim_favorites_resize (kim_favorites io_favorites, + kim_count in_new_count) { kim_error err = KIM_NO_ERROR; - if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && io_favorite_identities->count != in_new_count) { + if (!err && io_favorites->count != in_new_count) { kim_identity *identities = NULL; + kim_options *options = NULL; if (in_new_count == 0) { - if (io_favorite_identities->identities) { - free (io_favorite_identities->identities); + if (io_favorites->identities) { + free (io_favorites->identities); + } + if (io_favorites->options) { + free (io_favorites->options); } } else { - if (!io_favorite_identities->identities) { + if (!io_favorites->identities) { identities = malloc (sizeof (*identities) * in_new_count); } else { - identities = realloc (io_favorite_identities->identities, + identities = realloc (io_favorites->identities, sizeof (*identities) * in_new_count); } if (!identities) { err = KIM_OUT_OF_MEMORY_ERR; } + + if (!err) { + if (!io_favorites->options) { + options = malloc (sizeof (*options) * in_new_count); + } else { + options = realloc (io_favorites->options, + sizeof (*options) * in_new_count); + } + if (!options) { err = KIM_OUT_OF_MEMORY_ERR; } + } } if (!err) { - io_favorite_identities->count = in_new_count; - io_favorite_identities->identities = identities; + io_favorites->count = in_new_count; + io_favorites->identities = identities; + io_favorites->options = options; identities = NULL; + options = NULL; } if (identities) { free (identities); } + if (options ) { free (options); } } return check_error (err); @@ -103,77 +130,47 @@ static inline kim_error kim_favorite_identities_resize (kim_favorite_identities /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_create (kim_favorite_identities *out_favorite_identities) -{ - kim_error err = KIM_NO_ERROR; - kim_favorite_identities favorite_identities = NULL; - - if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - - if (!err) { - err = kim_favorite_identities_allocate (&favorite_identities); - } - - if (!err) { - *out_favorite_identities = favorite_identities; - favorite_identities = NULL; - } - - kim_favorite_identities_free (&favorite_identities); - - return check_error (err); -} - -/* ------------------------------------------------------------------------ */ - -kim_error kim_favorite_identities_copy (kim_favorite_identities *out_favorite_identities, - kim_favorite_identities in_favorite_identities) +static kim_error kim_favorites_copy (kim_favorites in_favorites, + kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; - kim_favorite_identities favorite_identities = NULL; - - if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !in_favorite_identities ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err) { - err = kim_favorite_identities_allocate (&favorite_identities); - } + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = kim_favorite_identities_resize (favorite_identities, in_favorite_identities->count); + err = kim_favorites_resize (io_favorites, in_favorites->count); } if (!err) { kim_count i; - for (i = 0; !err && i < favorite_identities->count; i++) { - err = kim_identity_copy (&favorite_identities->identities[i], - in_favorite_identities->identities[i]); + for (i = 0; !err && i < io_favorites->count; i++) { + err = kim_identity_copy (&io_favorites->identities[i], + in_favorites->identities[i]); + + if (!err) { + err = kim_options_copy (&io_favorites->options[i], + in_favorites->options[i]); + } } } - if (!err) { - *out_favorite_identities = favorite_identities; - favorite_identities = NULL; - } - - kim_favorite_identities_free (&favorite_identities); - return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_get_number_of_identities (kim_favorite_identities in_favorite_identities, - kim_count *out_number_of_identities) +kim_error kim_favorites_get_number_of_identities (kim_favorites in_favorites, + kim_count *out_number_of_identities) { kim_error err = KIM_NO_ERROR; - if (!err && !in_favorite_identities ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_favorites ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_number_of_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - *out_number_of_identities = in_favorite_identities->count; + *out_number_of_identities = in_favorites->count; } return check_error (err); @@ -181,24 +178,27 @@ kim_error kim_favorite_identities_get_number_of_identities (kim_favorite_identit /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_get_identity_at_index (kim_favorite_identities in_favorite_identities, - kim_count in_index, - kim_identity *out_identity) +kim_error kim_favorites_get_identity_at_index (kim_favorites in_favorites, + kim_count in_index, + kim_identity *out_identity, + kim_options *out_options) { kim_error err = KIM_NO_ERROR; - if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } + /* out_options may be NULL */ if (!err) { - if (in_index >= in_favorite_identities->count) { + if (in_index >= in_favorites->count) { err = kim_error_set_message_for_code (KIM_BAD_IDENTITY_INDEX_ERR, in_index); } } if (!err) { - err = kim_identity_copy (out_identity, in_favorite_identities->identities[in_index]); + err = kim_identity_copy (out_identity, + in_favorites->identities[in_index]); } return check_error (err); @@ -206,27 +206,36 @@ kim_error kim_favorite_identities_get_identity_at_index (kim_favorite_identities /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favorite_identities, - kim_identity in_identity) +kim_error kim_favorites_add_identity (kim_favorites io_favorites, + kim_identity in_identity, + kim_options in_options) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; + kim_options options = NULL; kim_count insert_at = 0; - if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + /* in_options may be KIM_OPTIONS_DEFAULT (NULL) */ if (!err) { err = kim_identity_copy (&identity, in_identity); } + if (!err) { + err = kim_options_copy (&options, in_options); + } + if (!err) { kim_count i; - for (i = 0; !err && i < io_favorite_identities->count; i++) { + for (i = 0; !err && i < io_favorites->count; i++) { kim_comparison identity_comparison = 0; - err = kim_identity_compare (in_identity, io_favorite_identities->identities[i], &identity_comparison); + err = kim_identity_compare (in_identity, + io_favorites->identities[i], + &identity_comparison); if (!err) { if (kim_comparison_is_greater_than (identity_comparison)) { @@ -236,7 +245,8 @@ kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favor /* already in list */ kim_string display_string = NULL; - err = kim_identity_get_display_string (in_identity, &display_string); + err = kim_identity_get_display_string (in_identity, + &display_string); if (!err) { err = kim_error_set_message_for_code (KIM_IDENTITY_ALREADY_IN_LIST_ERR, @@ -252,19 +262,27 @@ kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favor } if (!err) { - err = kim_favorite_identities_resize (io_favorite_identities, io_favorite_identities->count + 1); + err = kim_favorites_resize (io_favorites, + io_favorites->count + 1); } if (!err) { - kim_count move_count = io_favorite_identities->count - 1 - insert_at; + kim_count move_count = io_favorites->count - 1 - insert_at; - memmove (&io_favorite_identities->identities[insert_at + 1], - &io_favorite_identities->identities[insert_at], - move_count * sizeof (*io_favorite_identities->identities)); - io_favorite_identities->identities[insert_at] = identity; + memmove (&io_favorites->identities[insert_at + 1], + &io_favorites->identities[insert_at], + move_count * sizeof (*io_favorites->identities)); + io_favorites->identities[insert_at] = identity; identity = NULL; + + memmove (&io_favorites->options[insert_at + 1], + &io_favorites->options[insert_at], + move_count * sizeof (*io_favorites->options)); + io_favorites->options[insert_at] = options; + options = NULL; } + kim_options_free (&options); kim_identity_free (&identity); return check_error (err); @@ -272,35 +290,41 @@ kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favor /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_remove_identity (kim_favorite_identities io_favorite_identities, - kim_identity in_identity) +kim_error kim_favorites_remove_identity (kim_favorites io_favorites, + kim_identity in_identity) { kim_error err = KIM_NO_ERROR; kim_boolean found = FALSE; kim_count i; - if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - for (i = 0; !err && !found && i < io_favorite_identities->count; i++) { - kim_identity identity = io_favorite_identities->identities[i]; + for (i = 0; !err && !found && i < io_favorites->count; i++) { + kim_identity identity = io_favorites->identities[i]; + kim_options options = io_favorites->options[i]; err = kim_identity_compare (in_identity, identity, &found); if (!err && found) { kim_error terr = KIM_NO_ERROR; - kim_count new_count = io_favorite_identities->count - 1; + kim_count new_count = io_favorites->count - 1; + + memmove (&io_favorites->identities[i], + &io_favorites->identities[i + 1], + (new_count - i) * sizeof (*io_favorites->identities)); - memmove (&io_favorite_identities->identities[i], - &io_favorite_identities->identities[i + 1], - (new_count - i) * sizeof (*io_favorite_identities->identities)); + memmove (&io_favorites->options[i], + &io_favorites->options[i + 1], + (new_count - i) * sizeof (*io_favorites->options)); - terr = kim_favorite_identities_resize (io_favorite_identities, new_count); + terr = kim_favorites_resize (io_favorites, new_count); if (terr) { kim_debug_printf ("failed to resize list to %d. Continuing.", new_count); } + kim_options_free (&options); kim_identity_free (&identity); } } @@ -324,21 +348,24 @@ kim_error kim_favorite_identities_remove_identity (kim_favorite_identities io_fa /* ------------------------------------------------------------------------ */ -kim_error kim_favorite_identities_remove_all_identities (kim_favorite_identities io_favorite_identities) +kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; - if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_count i; - for (i = 0; i < io_favorite_identities->count; i++) { - kim_identity_free (&io_favorite_identities->identities[i]); + for (i = 0; i < io_favorites->count; i++) { + kim_identity_free (&io_favorites->identities[i]); + kim_options_free (&io_favorites->options[i]); } - free (io_favorite_identities->identities); - io_favorite_identities->count = 0; - io_favorite_identities->identities = NULL; + free (io_favorites->identities); + free (io_favorites->options); + io_favorites->count = 0; + io_favorites->identities = NULL; + io_favorites->options = NULL; } return check_error (err); @@ -346,60 +373,19 @@ kim_error kim_favorite_identities_remove_all_identities (kim_favorite_identities /* ------------------------------------------------------------------------ */ -void kim_favorite_identities_free (kim_favorite_identities *io_favorite_identities) +static void kim_favorites_free (kim_favorites io_favorites) { - if (io_favorite_identities && *io_favorite_identities && - *io_favorite_identities != kim_default_favorite_identities) { - kim_count i; - - for (i = 0; i < (*io_favorite_identities)->count; i++) { - kim_identity_free (&(*io_favorite_identities)->identities[i]); - } - free ((*io_favorite_identities)->identities); - free (*io_favorite_identities); - *io_favorite_identities = NULL; + kim_count i; + + for (i = 0; i < io_favorites->count; i++) { + kim_identity_free (&io_favorites->identities[i]); + kim_options_free (&io_favorites->options[i]); } + free (io_favorites->identities); + free (io_favorites->options); } -#pragma mark -- KIM Preferences -- - -struct kim_preferences_opaque { - kim_options options; - kim_boolean options_changed; - kim_boolean remember_options; - kim_boolean remember_options_changed; - kim_identity client_identity; - kim_boolean client_identity_changed; - kim_boolean remember_client_identity; - kim_boolean remember_client_identity_changed; - kim_lifetime minimum_lifetime; - kim_lifetime maximum_lifetime; - kim_boolean lifetime_range_changed; - kim_lifetime minimum_renewal_lifetime; - kim_lifetime maximum_renewal_lifetime; - kim_boolean renewal_lifetime_range_changed; - kim_favorite_identities favorite_identities; - kim_boolean favorite_identities_changed; -}; - -struct kim_preferences_opaque kim_preferences_initializer = { -NULL, -FALSE, -kim_default_remember_options, -FALSE, -kim_default_client_identity, -FALSE, -kim_default_remember_client_identity, -FALSE, -kim_default_minimum_lifetime, -kim_default_maximum_lifetime, -FALSE, -kim_default_minimum_renewal_lifetime, -kim_default_maximum_renewal_lifetime, -FALSE, -NULL, -FALSE -}; +#pragma mark - /* ------------------------------------------------------------------------ */ @@ -508,9 +494,15 @@ static kim_error kim_preferences_read (kim_preferences in_preferences) } if (!err) { - err = kim_os_preferences_get_favorite_identities_for_key (kim_preference_key_favorite_identities, - kim_default_favorite_identities, - &in_preferences->favorite_identities); + struct kim_favorites_opaque favorites = kim_default_favorites; + + err = kim_os_preferences_get_favorites_for_key (kim_preference_key_favorites, + &favorites); + + if (!err) { + kim_favorites_remove_all_identities (&in_preferences->favorites); + in_preferences->favorites = favorites; + } } if (!err) { @@ -537,6 +529,10 @@ static kim_error kim_preferences_read (kim_preferences in_preferences) &in_preferences->maximum_renewal_lifetime); } + if (!err) { + + } + return check_error (err); } @@ -637,9 +633,9 @@ static kim_error kim_preferences_write (kim_preferences in_preferences) in_preferences->remember_client_identity); } - if (!err && in_preferences->favorite_identities_changed) { - err = kim_os_preferences_set_favorite_identities_for_key (kim_preference_key_favorite_identities, - in_preferences->favorite_identities); + if (!err && in_preferences->favorites_changed) { + err = kim_os_preferences_set_favorites_for_key (kim_preference_key_favorites, + &in_preferences->favorites); } if (!err && in_preferences->lifetime_range_changed) { @@ -660,6 +656,16 @@ static kim_error kim_preferences_write (kim_preferences in_preferences) } } + if (!err) { + in_preferences->options_changed = 0; + in_preferences->remember_options_changed = 0; + in_preferences->client_identity_changed = 0; + in_preferences->remember_client_identity_changed = 0; + in_preferences->lifetime_range_changed = 0; + in_preferences->renewal_lifetime_range_changed = 0; + in_preferences->favorites_changed = 0; + } + return check_error (err); } @@ -748,7 +754,8 @@ kim_error kim_preferences_copy (kim_preferences *out_preferences, } if (!err) { - err = kim_favorite_identities_copy (&preferences->favorite_identities, in_preferences->favorite_identities); + err = kim_favorites_copy (&preferences->favorites, + &in_preferences->favorites); } if (!err) { @@ -1050,23 +1057,77 @@ kim_error kim_preferences_get_maximum_renewal_lifetime (kim_preferences in_pref /* ------------------------------------------------------------------------ */ -kim_error kim_preferences_set_favorite_identities (kim_preferences io_preferences, - kim_favorite_identities in_favorite_identities) +kim_error kim_preferences_get_number_of_favorite_identities (kim_preferences in_preferences, + kim_count *out_number_of_identities) +{ + return check_error (kim_favorites_get_number_of_identities (&in_preferences->favorites, + out_number_of_identities)); +} + +/* ------------------------------------------------------------------------ */ + +kim_error kim_preferences_get_favorite_identity_at_index (kim_preferences in_preferences, + kim_count in_index, + kim_identity *out_identity, + kim_options *out_options) +{ + kim_error err = KIM_NO_ERROR; + + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + /* out_options may be NULL */ + + if (!err) { + err = kim_favorites_get_identity_at_index (&in_preferences->favorites, + in_index, + out_identity, + out_options); + } + + return check_error (err); +} + +/* ------------------------------------------------------------------------ */ + +kim_error kim_preferences_add_favorite_identity (kim_preferences io_preferences, + kim_identity in_identity, + kim_options in_options) { kim_error err = KIM_NO_ERROR; - kim_favorite_identities favorite_identities = NULL; - if (!err && !io_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + /* in_options may be KIM_OPTIONS_DEFAULT (NULL) */ + + if (!err) { + err = kim_favorites_add_identity (&io_preferences->favorites, + in_identity, in_options); + } + + if (!err) { + io_preferences->favorites_changed = 1; + } + + return check_error (err); +} + +/* ------------------------------------------------------------------------ */ + +kim_error kim_preferences_remove_favorite_identity (kim_preferences io_preferences, + kim_identity in_identity) +{ + kim_error err = KIM_NO_ERROR; + + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = kim_favorite_identities_copy (&favorite_identities, in_favorite_identities); + err = kim_favorites_remove_identity (&io_preferences->favorites, + in_identity); } if (!err) { - kim_favorite_identities_free (&io_preferences->favorite_identities); - io_preferences->favorite_identities = favorite_identities; - io_preferences->favorite_identities_changed = TRUE; + io_preferences->favorites_changed = 1; } return check_error (err); @@ -1074,16 +1135,18 @@ kim_error kim_preferences_set_favorite_identities (kim_preferences io_pr /* ------------------------------------------------------------------------ */ -kim_error kim_preferences_get_favorite_identities (kim_preferences in_preferences, - kim_favorite_identities *out_favorite_identities) +kim_error kim_preferences_remove_all_favorite_identities (kim_preferences io_preferences) { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = kim_favorite_identities_copy (out_favorite_identities, in_preferences->favorite_identities); + err = kim_favorites_remove_all_identities (&io_preferences->favorites); + } + + if (!err) { + io_preferences->favorites_changed = 1; } return check_error (err); @@ -1115,7 +1178,8 @@ void kim_preferences_free (kim_preferences *io_preferences) if (io_preferences && *io_preferences) { kim_options_free (&(*io_preferences)->options); kim_identity_free (&(*io_preferences)->client_identity); - kim_favorite_identities_free (&(*io_preferences)->favorite_identities); + kim_favorites_free (&(*io_preferences)->favorites); + free (*io_preferences); *io_preferences = NULL; } diff --git a/src/kim/lib/kim_preferences_private.h b/src/kim/lib/kim_preferences_private.h index c52ea670b..831fba452 100644 --- a/src/kim/lib/kim_preferences_private.h +++ b/src/kim/lib/kim_preferences_private.h @@ -29,7 +29,7 @@ #include -extern const kim_favorite_identities kim_empty_favorite_identities; +typedef struct kim_favorites_opaque *kim_favorites; typedef enum kim_preference_key_enum { kim_preference_key_lifetime, @@ -41,13 +41,14 @@ typedef enum kim_preference_key_enum { kim_preference_key_remember_options, kim_preference_key_client_identity, kim_preference_key_remember_client_identity, - kim_preference_key_favorite_identities, + kim_preference_key_favorites, kim_preference_key_minimum_lifetime, kim_preference_key_maximum_lifetime, kim_preference_key_minimum_renewal_lifetime, kim_preference_key_maximum_renewal_lifetime } kim_preference_key; + #define kim_default_lifetime 10*60*60 #define kim_default_renewable TRUE #define kim_default_renewal_lifetime 7*24*60*60 @@ -57,12 +58,36 @@ typedef enum kim_preference_key_enum { #define kim_default_remember_options TRUE #define kim_default_client_identity KIM_IDENTITY_ANY #define kim_default_remember_client_identity TRUE -#define kim_default_favorite_identities kim_empty_favorite_identities #define kim_default_minimum_lifetime 10*60 #define kim_default_maximum_lifetime 10*60*60 #define kim_default_minimum_renewal_lifetime 10*60 #define kim_default_maximum_renewal_lifetime 7*24*60*60 +extern const struct kim_favorites_opaque kim_default_favorites; + + +/* Helper functions for use by kim_os_preferences_get_favorites_for_key + * and kim_os_preferences_set_favorites_for_key */ + +kim_error kim_favorites_get_number_of_identities (kim_favorites in_favorites, + kim_count *out_number_of_identities); + +kim_error kim_favorites_get_identity_at_index (kim_favorites in_favorites, + kim_count in_index, + kim_identity *out_identity, + kim_options *out_options); + +kim_error kim_favorites_add_identity (kim_favorites io_favorites, + kim_identity in_identity, + kim_options in_options); + +kim_error kim_favorites_remove_identity (kim_favorites io_favorites, + kim_identity in_identity); + +kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites); + + +/* OS-specific functions to be implemented per-platform */ kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, kim_identity in_hardcoded_default, @@ -71,12 +96,11 @@ kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, kim_identity in_identity); -kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key in_key, - kim_favorite_identities in_hardcoded_default, - kim_favorite_identities *out_favorite_identities); +kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, + kim_favorites io_favorites); -kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key in_key, - kim_favorite_identities in_favorite_identities); +kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, + kim_favorites in_favorites); kim_error kim_os_preferences_get_time_for_key (kim_preference_key in_key, kim_time in_hardcoded_default, diff --git a/src/kim/lib/mac/kim_os_preferences.c b/src/kim/lib/mac/kim_os_preferences.c index 3606f1a85..fac8cf644 100644 --- a/src/kim/lib/mac/kim_os_preferences.c +++ b/src/kim/lib/mac/kim_os_preferences.c @@ -81,7 +81,7 @@ static kim_error kim_os_preferences_cfstring_for_key (kim_preference_key in_key *out_kim_string_key = CFSTR ("RememberClientIdentity"); *out_kll_string_key = CFSTR ("KLRememberPrincipal"); - } else if (in_key == kim_preference_key_favorite_identities) { + } else if (in_key == kim_preference_key_favorites) { *out_kim_string_key = CFSTR ("FavoriteIdentities"); *out_kll_string_key = CFSTR ("KLFavoriteIdentities"); @@ -272,14 +272,13 @@ kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key in_key, - kim_favorite_identities in_hardcoded_default, - kim_favorite_identities *out_favorite_identities) +kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, + kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; CFArrayRef value = NULL; - if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFArrayGetTypeID (), @@ -288,15 +287,12 @@ kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key if (!err) { if (!value || CFArrayGetCount (value) < 1) { - err = kim_favorite_identities_copy (out_favorite_identities, in_hardcoded_default); + err = kim_favorites_remove_all_identities (io_favorites); } else { - kim_favorite_identities favorite_identities = NULL; CFIndex count = CFArrayGetCount (value); CFIndex i; - err = kim_favorite_identities_create (&favorite_identities); - for (i = 0; !err && i < count; i++) { CFStringRef cfstring = NULL; kim_string string = NULL; @@ -316,44 +312,42 @@ kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key } if (!err) { - err = kim_favorite_identities_add_identity (favorite_identities, identity); + err = kim_favorites_add_identity (io_favorites, identity, + KIM_OPTIONS_DEFAULT); } kim_identity_free (&identity); kim_string_free (&string); } - - if (!err) { - *out_favorite_identities = favorite_identities; - favorite_identities = NULL; - } - - kim_favorite_identities_free (&favorite_identities); } } + if (err) { + kim_favorites_remove_all_identities (io_favorites); + } + if (value) { CFRelease (value); } return check_error (err); } /* ------------------------------------------------------------------------ */ - -kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key in_key, - kim_favorite_identities in_favorite_identities) +kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, + kim_favorites in_favorites) { kim_error err = KIM_NO_ERROR; kim_count count = 0; CFMutableArrayRef value = NULL; - if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = kim_favorite_identities_get_number_of_identities (in_favorite_identities, &count); + err = kim_favorites_get_number_of_identities (in_favorites, &count); } if (!err) { - value = CFArrayCreateMutable (kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); + value = CFArrayCreateMutable (kCFAllocatorDefault, count, + &kCFTypeArrayCallBacks); if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } @@ -362,10 +356,13 @@ kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key for (i = 0; !err && i < count; i++) { kim_identity identity = NULL; + kim_options options = NULL; kim_string string = NULL; CFStringRef cfstring = NULL; - err = kim_favorite_identities_get_identity_at_index (in_favorite_identities, i, &identity); + err = kim_favorites_get_identity_at_index (in_favorites, i, + &identity, + &options); if (!err) { err = kim_identity_get_string (identity, &string); @@ -381,6 +378,7 @@ kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key if (cfstring) { CFRelease (cfstring); } kim_string_free (&string); + kim_options_free (&options); kim_identity_free (&identity); } } diff --git a/src/kim/test/main.c b/src/kim/test/main.c index c1c5bd19e..03194bf1c 100644 --- a/src/kim/test/main.c +++ b/src/kim/test/main.c @@ -64,17 +64,7 @@ int main (int argc, const char * argv[]) test_kim_preferences_set_client_identity (state); - test_kim_selection_hints_set_service_identity_hint (state); - - test_kim_selection_hints_set_client_realm_hint (state); - - test_kim_selection_hints_set_user_hint (state); - - test_kim_selection_hints_set_service_realm_hint (state); - - test_kim_selection_hints_set_service_hint (state); - - test_kim_selection_hints_set_server_hint (state); + test_kim_selection_hints_set_hint (state); test_kim_selection_hints_remember_identity (state); diff --git a/src/kim/test/test_kim_common.c b/src/kim/test/test_kim_common.c index 1e10aae0f..b28fac395 100644 --- a/src/kim/test/test_kim_common.c +++ b/src/kim/test/test_kim_common.c @@ -92,41 +92,19 @@ void end_test (kim_test_state_t in_state) void fail_if_error (kim_test_state_t in_state, const char *in_function, - kim_error in_err, + kim_error in_err, const char *in_format, ...) { if (in_err) { va_list args; + kim_string message = NULL; - printf ("\tFAILURE: "); - printf ("%s() got %d (%s) ", - in_function, in_err, kim_error_message (in_err)); - - va_start (args, in_format); - vprintf (in_format, args); - va_end (args); - - printf ("\n"); - - in_state->test_fail_count++; - } -} - -/* ------------------------------------------------------------------------ */ - -void fail_if_error_code (kim_test_state_t in_state, - const char *in_function, - kim_error_code in_code, - const char *in_format, - ...) -{ - if (in_code) { - va_list args; + kim_error err = kim_string_get_last_error_message (&message, err); printf ("\tFAILURE: "); printf ("%s() got %d (%s) ", - in_function, in_code, error_message (in_code)); + in_function, in_err, !err ? message : "Unknown"); va_start (args, in_format); vprintf (in_format, args); @@ -135,6 +113,8 @@ void fail_if_error_code (kim_test_state_t in_state, printf ("\n"); in_state->test_fail_count++; + + kim_string_free (&message); } } diff --git a/src/kim/test/test_kim_common.h b/src/kim/test/test_kim_common.h index bb85cb18c..e7ac3eb30 100644 --- a/src/kim/test/test_kim_common.h +++ b/src/kim/test/test_kim_common.h @@ -57,16 +57,6 @@ __attribute__ ((__format__ (__printf__, 4, 5))) #endif ; -void fail_if_error_code (kim_test_state_t in_state, - const char *in_function, - kim_error_code in_code, - const char *in_format, - ...) -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -__attribute__ ((__format__ (__printf__, 4, 5))) -#endif -; - void log_failure (kim_test_state_t in_state, const char *in_format, ...) diff --git a/src/kim/test/test_kim_identity.c b/src/kim/test/test_kim_identity.c index db225e54c..e799aade2 100644 --- a/src/kim/test/test_kim_identity.c +++ b/src/kim/test/test_kim_identity.c @@ -33,10 +33,10 @@ typedef struct test_identity_d { const char *realm; kim_count component_count; const char *components[5]; -} test_identity_t; +} test_identity; -test_identity_t test_identities[] = { +test_identity test_identities[] = { {"a@B", "a@B", 0, "B", 1, { "a", NULL, NULL, NULL, NULL } }, {"user@EXAMPLE.COM", "user@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "user", NULL, NULL, NULL, NULL } }, {"krbtgt@EXAMPLE.COM", "krbtgt@EXAMPLE.COM", 0, "EXAMPLE.COM", 1, { "krbtgt", NULL, NULL, NULL, NULL } }, @@ -66,8 +66,7 @@ void test_kim_identity_create_from_krb5_principal (kim_test_state_t state) start_test (state, "kim_identity_create_from_krb5_principal"); for (i = 0; test_identities[i].string; i++) { - krb5_error_code code = 0; - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; krb5_context context = NULL; krb5_principal principal = NULL; kim_identity identity = NULL; @@ -75,32 +74,32 @@ void test_kim_identity_create_from_krb5_principal (kim_test_state_t state) printf ("."); - code = krb5_init_context (&context); - fail_if_error_code (state, "krb5_init_context", code, - "while initializing context"); + err = krb5_init_context (&context); + fail_if_error (state, "krb5_init_context", err, + "while initializing context"); - if (!code) { - code = krb5_parse_name (context, test_identities[i].string, &principal); - fail_if_error_code (state, "krb5_parse_name", code, - "while creating krb5_principal for %s", - test_identities[i].string); + if (!err) { + err = krb5_parse_name (context, test_identities[i].string, &principal); + fail_if_error (state, "krb5_parse_name", err, + "while creating krb5_principal for %s", + test_identities[i].string); } - if (!code && !err) { + if (!err) { err = kim_identity_create_from_krb5_principal (&identity, context, principal); fail_if_error (state, "kim_identity_create_from_string", err, "while creating the identity for %s", test_identities[i].string); } - if (!code && !err) { + if (!err) { err = kim_identity_get_string (identity, &string); fail_if_error (state, "kim_identity_get_string", err, "while getting the string for %s", test_identities[i].string); } - if (!code && !err && strcmp (string, test_identities[i].string)) { + if (!err && strcmp (string, test_identities[i].string)) { log_failure (state, "Unexpected string (got '%s', expected '%s')", string, test_identities[i].string); } @@ -125,7 +124,7 @@ void test_kim_identity_create_from_string (kim_test_state_t state) start_test (state, "kim_identity_create_from_string"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string string = NULL; @@ -169,7 +168,7 @@ void test_kim_identity_copy (kim_test_state_t state) start_test (state, "kim_identity_copy"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_identity identity_copy = NULL; kim_string string = NULL; @@ -188,7 +187,7 @@ void test_kim_identity_copy (kim_test_state_t state) fail_if_error (state, "kim_identity_copy", err, "while copying %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_string (identity_copy, &string); fail_if_error (state, "kim_identity_get_string", err, @@ -207,7 +206,7 @@ void test_kim_identity_copy (kim_test_state_t state) } printf ("\n"); - + end_test (state); } @@ -220,7 +219,7 @@ void test_kim_identity_compare (kim_test_state_t state) start_test (state, "kim_identity_create_from_string"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; printf ("."); @@ -233,7 +232,7 @@ void test_kim_identity_compare (kim_test_state_t state) for (j = 0; !err && test_identities[j].string; j++) { kim_identity compare_to_identity = NULL; kim_comparison comparison = 0; - + err = kim_identity_create_from_string (&compare_to_identity, test_identities[j].string); fail_if_error (state, "kim_identity_create_from_string", err, "while creating the identity for %s", @@ -250,21 +249,21 @@ void test_kim_identity_compare (kim_test_state_t state) if (i == j && !kim_comparison_is_equal_to (comparison)) { log_failure (state, "Expected %s and %s to be equal but kim_identity_compare returned %d", test_identities[i].string, test_identities[j].string, comparison); - + } else if (i != j && kim_comparison_is_equal_to (comparison)) { log_failure (state, "Expected %s and %s to be NOT equal but kim_identity_compare returned %d", test_identities[i].string, test_identities[j].string, comparison); } } - + kim_identity_free (&compare_to_identity); } - + kim_identity_free (&identity); } printf ("\n"); - + end_test (state); } @@ -273,11 +272,11 @@ void test_kim_identity_compare (kim_test_state_t state) void test_kim_identity_get_display_string (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_display_string"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string string = NULL; @@ -307,7 +306,7 @@ void test_kim_identity_get_display_string (kim_test_state_t state) } printf ("\n"); - + end_test (state); } @@ -316,11 +315,11 @@ void test_kim_identity_get_display_string (kim_test_state_t state) void test_kim_identity_get_realm (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_realm"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string realm = NULL; @@ -349,7 +348,7 @@ void test_kim_identity_get_realm (kim_test_state_t state) } printf ("\n"); - + end_test (state); } @@ -358,11 +357,11 @@ void test_kim_identity_get_realm (kim_test_state_t state) void test_kim_identity_get_number_of_components (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_number_of_components"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_count count = 0; @@ -384,17 +383,17 @@ void test_kim_identity_get_number_of_components (kim_test_state_t state) if (!err && (count != test_identities[i].component_count)) { log_failure (state, "Unexpected component count of %s (got %d, expected %d)", - test_identities[i].string, (int) count, (int) test_identities[i].component_count); + test_identities[i].string, (int) count, (int) test_identities[i].component_count); } kim_identity_free (&identity); } printf ("\n"); - + end_test (state); } - + /* ------------------------------------------------------------------------ */ void test_kim_identity_get_component_at_index (kim_test_state_t state) @@ -404,7 +403,7 @@ void test_kim_identity_get_component_at_index (kim_test_state_t state) start_test (state, "kim_identity_get_component_at_index"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_count c = 0; @@ -438,7 +437,7 @@ void test_kim_identity_get_component_at_index (kim_test_state_t state) } printf ("\n"); - + end_test (state); } @@ -451,8 +450,7 @@ void test_kim_identity_get_krb5_principal (kim_test_state_t state) start_test (state, "kim_identity_get_krb5_principal"); for (i = 0; test_identities[i].string; i++) { - krb5_error_code code = 0; - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; krb5_context context = NULL; krb5_principal principal = NULL; krb5_principal identity_principal = NULL; @@ -460,36 +458,36 @@ void test_kim_identity_get_krb5_principal (kim_test_state_t state) printf ("."); - code = krb5_init_context (&context); - fail_if_error_code (state, "krb5_init_context", code, - "while initializing context"); + err = krb5_init_context (&context); + fail_if_error (state, "krb5_init_context", err, + "while initializing context"); - if (!code) { - code = krb5_parse_name (context, test_identities[i].string, &principal); - fail_if_error_code (state, "krb5_parse_name", code, - "while creating krb5_principal for %s", - test_identities[i].string); + if (!err) { + err = krb5_parse_name (context, test_identities[i].string, &principal); + fail_if_error (state, "krb5_parse_name", err, + "while creating krb5_principal for %s", + test_identities[i].string); } - if (!code && !err) { + if (!err && !err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); fail_if_error (state, "kim_identity_create_from_string", err, "while creating the identity for %s", test_identities[i].string); } - if (!code && !err) { + if (!err && !err) { err = kim_identity_get_krb5_principal (identity, context, &identity_principal); fail_if_error (state, "kim_identity_get_krb5_principal", err, "while getting the krb5_principal for %s", test_identities[i].string); } - if (!code && !err) { + if (!err && !err) { if (!krb5_principal_compare (context, principal, identity_principal)) { log_failure (state, "Principal and identity principal for %s do not match", test_identities[i].string); - } + } } kim_identity_free (&identity); @@ -499,7 +497,7 @@ void test_kim_identity_get_krb5_principal (kim_test_state_t state) } printf ("\n"); - + end_test (state); } @@ -512,7 +510,7 @@ void test_kim_identity_is_tgt_service (kim_test_state_t state) start_test (state, "kim_identity_is_tgt_service"); for (i = 0; test_identities[i].string; i++) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_identity_t identity = NULL; kim_boolean_t is_tgt_service = 0; diff --git a/src/kim/test/test_kim_preferences.c b/src/kim/test/test_kim_preferences.c index 8b7a54912..8ce61fe08 100644 --- a/src/kim/test/test_kim_preferences.c +++ b/src/kim/test/test_kim_preferences.c @@ -26,6 +26,8 @@ #include "test_kim_preferences.h" +#define TEST_LIFETIME 7777 + /* ------------------------------------------------------------------------ */ void test_kim_preferences_create (kim_test_state_t state) @@ -34,7 +36,7 @@ void test_kim_preferences_create (kim_test_state_t state) start_test (state, "kim_preferences_create"); { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_preferences prefs = NULL; err = kim_preferences_create (&prefs); @@ -55,7 +57,7 @@ void test_kim_preferences_copy (kim_test_state_t state) start_test (state, "test_kim_preferences_copy"); { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_preferences prefs = NULL; kim_preferences prefs_copy = NULL; @@ -80,46 +82,56 @@ void test_kim_preferences_copy (kim_test_state_t state) void test_kim_preferences_set_options (kim_test_state_t state) { + kim_error err = KIM_NO_ERROR; start_test (state, "kim_preferences_set_options"); - { - kim_error err = NULL; + if (!err) { kim_preferences prefs = NULL; - kim_options old_options = NULL; - kim_options new_options = NULL; - kim_options verify_options = NULL; - const char *custom_data = "Some custom data"; - const char *verify_custom_data = NULL; + kim_options options = NULL; err = kim_preferences_create (&prefs); fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); if (!err) { - err = kim_preferences_get_options (prefs, &old_options); + err = kim_preferences_get_options (prefs, &options); fail_if_error (state, "kim_preferences_get_options", err, "while getting old options"); - } - - if (!err) { - err = kim_options_create (&new_options); - fail_if_error (state, "kim_options_create", err, - "while creating options"); } - + if (!err) { - err = kim_options_set_data (new_options, custom_data); + err = kim_options_set_lifetime (options, TEST_LIFETIME); fail_if_error (state, "kim_options_set_data", err, - "while setting the custom data to %s", custom_data); + "while setting the lifetime to %d", TEST_LIFETIME); } if (!err) { - err = kim_preferences_set_options (prefs, new_options); + err = kim_preferences_set_options (prefs, options); fail_if_error (state, "kim_preferences_set_options", err, "while setting the new options"); } - + + if (!err) { + err = kim_preferences_synchronize (prefs); + fail_if_error (state, "kim_preferences_synchronize", err, + "while setting the identity to KIM_IDENTITY_ANY"); + } + + kim_options_free (&options); + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + kim_options verify_options = NULL; + kim_lifetime lifetime = 0; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + + if (!err) { err = kim_preferences_get_options (prefs, &verify_options); fail_if_error (state, "kim_preferences_get_options", err, @@ -127,29 +139,21 @@ void test_kim_preferences_set_options (kim_test_state_t state) } if (!err) { - err = kim_options_get_data (verify_options, (const void **)&verify_custom_data); + err = kim_options_get_lifetime (verify_options, &lifetime); fail_if_error (state, "kim_options_get_data", err, "while getting the custom data of the verify options"); } - if (!err && custom_data != verify_custom_data) { - log_failure (state, "Unexpected custom data in options (got %p, expected %p)", - verify_custom_data, custom_data); + if (!err && lifetime != TEST_LIFETIME) { + log_failure (state, "Unexpected lifetime in options (got %d, expected %d)", + (int) lifetime, TEST_LIFETIME); } - - if (!err) { - err = kim_preferences_set_options (prefs, old_options); - fail_if_error (state, "kim_preferences_set_options", err, - "while restoring the options"); - } - - kim_options_free (&old_options); - kim_options_free (&new_options); + kim_options_free (&verify_options); kim_preferences_free (&prefs); } - end_test (state); + end_test (state); } /* ------------------------------------------------------------------------ */ @@ -157,12 +161,12 @@ void test_kim_preferences_set_options (kim_test_state_t state) void test_kim_preferences_set_remember_options (kim_test_state_t state) { + kim_error err = KIM_NO_ERROR; + start_test (state, "kim_preferences_set_remember_options"); - { - kim_error err = NULL; + if (!err) { kim_preferences prefs = NULL; - kim_boolean remember_options = FALSE; err = kim_preferences_create (&prefs); fail_if_error (state, "kim_preferences_create", err, @@ -174,6 +178,23 @@ void test_kim_preferences_set_remember_options (kim_test_state_t state) "while setting the preference to remember options"); } + if (!err) { + err = kim_preferences_synchronize (prefs); + fail_if_error (state, "kim_preferences_synchronize", err, + "while setting the identity to KIM_IDENTITY_ANY"); + } + + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + kim_boolean remember_options = TRUE; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + if (!err) { err = kim_preferences_get_remember_options (prefs, &remember_options); fail_if_error (state, "kim_preferences_get_remember_options", err, @@ -185,12 +206,39 @@ void test_kim_preferences_set_remember_options (kim_test_state_t state) remember_options); } + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + if (!err) { err = kim_preferences_set_remember_options (prefs, FALSE); fail_if_error (state, "kim_preferences_set_remember_options", err, "while setting the preference to remember options"); } + if (!err) { + err = kim_preferences_synchronize (prefs); + fail_if_error (state, "kim_preferences_synchronize", err, + "while setting the identity to KIM_IDENTITY_ANY"); + } + + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + kim_boolean remember_options = FALSE; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + if (!err) { err = kim_preferences_get_remember_options (prefs, &remember_options); fail_if_error (state, "kim_preferences_get_remember_options", err, @@ -213,32 +261,49 @@ void test_kim_preferences_set_remember_options (kim_test_state_t state) void test_kim_preferences_set_client_identity (kim_test_state_t state) { + kim_error err = KIM_NO_ERROR; + kim_string test_string = "user@EXAMPLE.COM"; + kim_identity test_identity = KIM_IDENTITY_ANY; + kim_identity identity = KIM_IDENTITY_ANY; + kim_comparison comparison = 0; + start_test (state, "kim_preferences_set_client_identity"); - { - kim_error err = NULL; + + if (!err) { + err = kim_identity_create_from_string (&test_identity, test_string); + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_string); + } + + if (!err) { kim_preferences prefs = NULL; - kim_string test_string = "user@EXAMPLE.COM"; - kim_identity test_identity = KIM_IDENTITY_ANY; - kim_string string = NULL; - kim_identity identity = KIM_IDENTITY_ANY; - kim_comparison comparison = 0; - + err = kim_preferences_create (&prefs); fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); if (!err) { - err = kim_identity_create_from_string (&test_identity, test_string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", test_string); + err = kim_preferences_set_client_identity (prefs, KIM_IDENTITY_ANY); + fail_if_error (state, "kim_preferences_set_client_identity", err, + "while setting the identity to KIM_IDENTITY_ANY"); } if (!err) { - err = kim_preferences_set_client_identity (prefs, KIM_IDENTITY_ANY); - fail_if_error (state, "kim_preferences_set_client_identity", err, + err = kim_preferences_synchronize (prefs); + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } + + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); if (!err) { err = kim_preferences_get_client_identity (prefs, &identity); @@ -252,12 +317,40 @@ void test_kim_preferences_set_client_identity (kim_test_state_t state) kim_identity_free (&identity); } + kim_preferences_free (&prefs); + } + + if (!err) { + kim_preferences prefs = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + if (!err) { err = kim_preferences_set_client_identity (prefs, test_identity); fail_if_error (state, "kim_preferences_set_client_identity", err, "while setting the identity to %s", test_string); } + if (!err) { + err = kim_preferences_synchronize (prefs); + fail_if_error (state, "kim_preferences_synchronize", err, + "while setting the identity to KIM_IDENTITY_ANY"); + } + + kim_preferences_free (&prefs); + } + + + if (!err) { + kim_preferences prefs = NULL; + kim_string string = NULL; + + err = kim_preferences_create (&prefs); + fail_if_error (state, "kim_preferences_create", err, + "while creating preferences"); + if (!err) { err = kim_preferences_get_client_identity (prefs, &identity); fail_if_error (state, "kim_preferences_get_client_identity", err, @@ -269,25 +362,26 @@ void test_kim_preferences_set_client_identity (kim_test_state_t state) fail_if_error (state, "kim_identity_get_string", err, "while getting the string for client identity preference"); } - + if (!err) { err = kim_identity_compare (identity, test_identity, &comparison); fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the identity preference %s", + "while comparing %s to the identity preference %s", test_string, string ? string : "NULL"); } - + if (!err && !kim_comparison_is_equal_to (comparison)) { log_failure (state, "Unexpected client identity preference (got %s, expected %s)", string ? string : "NULL", test_string); kim_identity_free (&identity); } - + kim_string_free (&string); - kim_identity_free (&identity); - kim_identity_free (&test_identity); kim_preferences_free (&prefs); } + kim_identity_free (&identity); + kim_identity_free (&test_identity); + end_test (state); } diff --git a/src/kim/test/test_kim_selection_hints.c b/src/kim/test/test_kim_selection_hints.c index 696082df8..2a24a610e 100644 --- a/src/kim/test/test_kim_selection_hints.c +++ b/src/kim/test/test_kim_selection_hints.c @@ -27,335 +27,88 @@ #include "test_kim_selection_hints.h" #define KSH_TEST_ID "edu.mit.Kerberos.test_kim" -#define KSH_SERVICE_IDENTITY "service/server.example.com@EXAMPLE.COM" -#define KSH_SERVICE "service" -#define KSH_SERVER "server.example.com" -#define KSH_SERVICE_REALM "EXAMPLE.COM" -#define KSH_USER "jdoe" -#define KSH_CLIENT_REALM "USERS.EXAMPLE.COM" #define KSH_IDENTITY "jdoe@USERS.EXAMPLE.COM" +typedef struct test_selection_hint_d { + kim_string key; + kim_string hint; +} test_selection_hint; + +test_selection_hint test_hints[] = { + { kim_hint_key_service_identity, "service/server.example.com@EXAMPLE.COM" }, + { kim_hint_key_service, "service" }, + { kim_hint_key_server, "server.example.com" }, + { kim_hint_key_service_realm, "EXAMPLE.COM" }, + { kim_hint_key_user, "jdoe" }, + { kim_hint_key_client_realm, "USERS.EXAMPLE.COM" }, + { NULL, NULL } +}; /* ------------------------------------------------------------------------ */ -void test_kim_selection_hints_set_service_identity_hint (kim_test_state_t state) +void test_kim_selection_hints_set_hint (kim_test_state_t state) { - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_identity service_identity = NULL; - kim_identity identity = KIM_IDENTITY_ANY; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_service_identity_hint"); - - if (!err) { - err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, - "while creating selection hints for %s", KSH_TEST_ID); - } - - if (!err) { - err = kim_identity_create_from_string (&service_identity, - KSH_SERVICE_IDENTITY); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating an identity for %s", - KSH_SERVICE_IDENTITY); - } - - if (!err) { - err = kim_selection_hints_set_service_identity_hint (hints, service_identity); - fail_if_error (state, "kim_selection_hints_set_service_identity_hint", - err, "while setting service identity to %s", - KSH_SERVICE_IDENTITY); - } - - if (!err) { - err = kim_selection_hints_get_service_identity_hint (hints, &identity); - fail_if_error (state, "kim_selection_hints_get_service_identity_hint", - err, "while getting service identity %s", - KSH_SERVICE_IDENTITY); - } - - if (!err && identity) { - err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, - "while getting the string for the service identity hint"); - } + kim_error err = KIM_NO_ERROR; + kim_count i = 0; - if (!err) { - err = kim_identity_compare (service_identity, identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the identity hint %s", - KSH_SERVICE_IDENTITY, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected service identity hint (got %s, expected %s)", - string ? string : "NULL", KSH_SERVICE_IDENTITY); - kim_identity_free (&identity); - } + start_test (state, "test_kim_selection_hints_set_hint"); - kim_string_free (&string); - kim_identity_free (&service_identity); - kim_selection_hints_free (&hints); - - end_test (state); -} - -/* ------------------------------------------------------------------------ */ + for (i = 0; !err && test_hints[i].key; i++) { + kim_selection_hints hints = NULL; + kim_string string = NULL; + kim_comparison comparison = 0; + + printf ("."); -void test_kim_selection_hints_set_client_realm_hint (kim_test_state_t state) -{ - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_client_realm_hint"); - - if (!err) { err = kim_selection_hints_create (&hints, KSH_TEST_ID); fail_if_error (state, "kim_selection_hints_create", err, "while creating selection hints for %s", KSH_TEST_ID); + + if (!err) { + err = kim_selection_hints_set_hint (hints, test_hints[i].key, test_hints[i].hint); + fail_if_error (state, "kim_selection_hints_set_hint", + err, "while setting hint %s to %s", + test_hints[i].key, test_hints[i].hint); + } + + if (!err) { + err = kim_selection_hints_get_hint (hints, test_hints[i].key, &string); + fail_if_error (state, "kim_selection_hints_get_hint", + err, "while getting hint %s", test_hints[i].key); + } + + if (!err) { + err = kim_string_compare (test_hints[i].hint, string, &comparison); + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to %s (hint %s)", + test_hints[i].hint, + string ? string : "NULL", test_hints[i].key); + } + + if (!err && !kim_comparison_is_equal_to (comparison)) { + log_failure (state, "Unexpected hint %s (got %s, expected %s)", + test_hints[i].key, + string ? string : "NULL", + test_hints[i].hint); + } + + kim_string_free (&string); + kim_selection_hints_free (&hints); } - if (!err) { - err = kim_selection_hints_set_client_realm_hint (hints, KSH_CLIENT_REALM); - fail_if_error (state, "kim_selection_hints_set_client_realm_hint", - err, "while setting client realm hint to %s", - KSH_CLIENT_REALM); - } - - if (!err) { - err = kim_selection_hints_get_client_realm_hint (hints, &string); - fail_if_error (state, "kim_selection_hints_get_client_realm_hint", - err, "while getting the client realm %s", - KSH_CLIENT_REALM); - } - - if (!err) { - err = kim_string_compare (KSH_CLIENT_REALM, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the client realm hint %s", - KSH_CLIENT_REALM, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected client realm hint (got %s, expected %s)", - string ? string : "NULL", KSH_CLIENT_REALM); - } - - kim_string_free (&string); - kim_selection_hints_free (&hints); - end_test (state); } -/* ------------------------------------------------------------------------ */ -void test_kim_selection_hints_set_user_hint (kim_test_state_t state) -{ - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_user_hint"); - - if (!err) { - err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, - "while creating selection hints for %s", KSH_TEST_ID); - } - - if (!err) { - err = kim_selection_hints_set_user_hint (hints, KSH_USER); - fail_if_error (state, "kim_selection_hints_set_user_hint", - err, "while setting user hint to %s", - KSH_USER); - } - - if (!err) { - err = kim_selection_hints_get_user_hint (hints, &string); - fail_if_error (state, "kim_selection_hints_get_user_hint", - err, "while getting the user hint %s", - KSH_USER); - } - - if (!err) { - err = kim_string_compare (KSH_USER, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the user hint %s", - KSH_USER, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected user hint (got %s, expected %s)", - string ? string : "NULL", KSH_USER); - } - - kim_string_free (&string); - kim_selection_hints_free (&hints); - - end_test (state); -} - -/* ------------------------------------------------------------------------ */ - -void test_kim_selection_hints_set_service_realm_hint (kim_test_state_t state) -{ - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_service_realm_hint"); - - if (!err) { - err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, - "while creating selection hints for %s", KSH_TEST_ID); - } - - if (!err) { - err = kim_selection_hints_set_service_realm_hint (hints, KSH_SERVICE_REALM); - fail_if_error (state, "kim_selection_hints_set_service_realm_hint", - err, "while setting service realm to %s", - KSH_SERVICE_REALM); - } - - if (!err) { - err = kim_selection_hints_get_service_realm_hint (hints, &string); - fail_if_error (state, "kim_selection_hints_get_service_realm_hint", - err, "while getting the service realm hint %s", - KSH_SERVICE_REALM); - } - - if (!err) { - err = kim_string_compare (KSH_SERVICE_REALM, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the service realm hint %s", - KSH_SERVICE_REALM, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected service realm hint (got %s, expected %s)", - string ? string : "NULL", KSH_SERVICE_REALM); - } - - kim_string_free (&string); - kim_selection_hints_free (&hints); - - end_test (state); -} - -/* ------------------------------------------------------------------------ */ - -void test_kim_selection_hints_set_service_hint (kim_test_state_t state) -{ - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_service_hint"); - - if (!err) { - err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, - "while creating selection hints for %s", KSH_TEST_ID); - } - - if (!err) { - err = kim_selection_hints_set_service_hint (hints, KSH_SERVICE); - fail_if_error (state, "kim_selection_hints_set_service_hint", - err, "while setting service hint to %s", - KSH_SERVICE); - } - - if (!err) { - err = kim_selection_hints_get_service_hint (hints, &string); - fail_if_error (state, "kim_selection_hints_get_service_hint", - err, "while getting the service hint %s", - KSH_SERVICE); - } - - if (!err) { - err = kim_string_compare (KSH_SERVICE, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the service hint %s", - KSH_SERVICE, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected service hint (got %s, expected %s)", - string ? string : "NULL", KSH_SERVICE); - } - - kim_string_free (&string); - kim_selection_hints_free (&hints); - - end_test (state); -} - -/* ------------------------------------------------------------------------ */ - -void test_kim_selection_hints_set_server_hint (kim_test_state_t state) -{ - kim_error err = NULL; - kim_selection_hints hints = NULL; - kim_string string = NULL; - kim_comparison comparison = 0; - - start_test (state, "kim_selection_hints_set_server_hint"); - - if (!err) { - err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, - "while creating selection hints for %s", KSH_TEST_ID); - } - - if (!err) { - err = kim_selection_hints_set_server_hint (hints, KSH_SERVER); - fail_if_error (state, "kim_selection_hints_set_server_hint", - err, "while setting server hint to %s", - KSH_SERVER); - } - - if (!err) { - err = kim_selection_hints_get_server_hint (hints, &string); - fail_if_error (state, "kim_selection_hints_get_server_hint", - err, "while getting the server hint %s", - KSH_SERVER); - } - - if (!err) { - err = kim_string_compare (KSH_SERVER, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the server hint %s", - KSH_SERVER, string ? string : "NULL"); - } - - if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected server hint (got %s, expected %s)", - string ? string : "NULL", KSH_SERVER); - } - - kim_string_free (&string); - kim_selection_hints_free (&hints); - - end_test (state); -} /* ------------------------------------------------------------------------ */ void test_kim_selection_hints_remember_identity (kim_test_state_t state) { - kim_error err = NULL; + kim_error err = KIM_NO_ERROR; kim_selection_hints hints = NULL; - kim_identity service_identity = NULL; + kim_count i = 0; kim_identity client_identity = NULL; kim_string string = NULL; kim_identity identity = KIM_IDENTITY_ANY; @@ -369,12 +122,11 @@ void test_kim_selection_hints_remember_identity (kim_test_state_t state) "while creating selection hints for %s", KSH_TEST_ID); } - if (!err) { - err = kim_identity_create_from_string (&service_identity, - KSH_SERVICE_IDENTITY); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating an identity for %s", - KSH_SERVICE_IDENTITY); + for (i = 0; !err && test_hints[i].key; i++) { + err = kim_selection_hints_set_hint (hints, test_hints[i].key, test_hints[i].hint); + fail_if_error (state, "kim_selection_hints_set_hint", + err, "while setting hint %s to %s", + test_hints[i].key, test_hints[i].hint); } if (!err) { @@ -385,48 +137,6 @@ void test_kim_selection_hints_remember_identity (kim_test_state_t state) KSH_IDENTITY); } - if (!err) { - err = kim_selection_hints_set_service_identity_hint (hints, service_identity); - fail_if_error (state, "kim_selection_hints_set_service_identity_hint", - err, "while setting service identity to %s", - KSH_SERVICE_IDENTITY); - } - - if (!err) { - err = kim_selection_hints_set_client_realm_hint (hints, KSH_CLIENT_REALM); - fail_if_error (state, "kim_selection_hints_set_client_realm_hint", - err, "while setting client realm to %s", - KSH_CLIENT_REALM); - } - - if (!err) { - err = kim_selection_hints_set_user_hint (hints, KSH_USER); - fail_if_error (state, "kim_selection_hints_set_user_hint", - err, "while setting user to %s", - KSH_USER); - } - - if (!err) { - err = kim_selection_hints_set_service_realm_hint (hints, KSH_SERVICE_REALM); - fail_if_error (state, "kim_selection_hints_set_service_realm_hint", - err, "while setting service realm to %s", - KSH_SERVICE_REALM); - } - - if (!err) { - err = kim_selection_hints_set_service_hint (hints, KSH_SERVICE); - fail_if_error (state, "kim_selection_hints_set_service_hint", - err, "while setting service to %s", - KSH_SERVICE); - } - - if (!err) { - err = kim_selection_hints_set_server_hint (hints, KSH_SERVER); - fail_if_error (state, "kim_selection_hints_set_server_hint", - err, "while setting server to %s", - KSH_SERVER); - } - if (!err) { err = kim_selection_hints_remember_identity (hints, client_identity); fail_if_error (state, "kim_selection_hints_remember_identity", @@ -462,7 +172,6 @@ void test_kim_selection_hints_remember_identity (kim_test_state_t state) kim_string_free (&string); kim_identity_free (&identity); kim_identity_free (&client_identity); - kim_identity_free (&service_identity); kim_selection_hints_free (&hints); end_test (state); diff --git a/src/kim/test/test_kim_selection_hints.h b/src/kim/test/test_kim_selection_hints.h index fac9a3d5d..1bc0ce0e0 100644 --- a/src/kim/test/test_kim_selection_hints.h +++ b/src/kim/test/test_kim_selection_hints.h @@ -29,17 +29,7 @@ #include "test_kim_common.h" -void test_kim_selection_hints_set_service_identity_hint (kim_test_state_t state); - -void test_kim_selection_hints_set_client_realm_hint (kim_test_state_t state); - -void test_kim_selection_hints_set_user_hint (kim_test_state_t state); - -void test_kim_selection_hints_set_service_realm_hint (kim_test_state_t state); - -void test_kim_selection_hints_set_service_hint (kim_test_state_t state); - -void test_kim_selection_hints_set_server_hint (kim_test_state_t state); +void test_kim_selection_hints_set_hint (kim_test_state_t state); void test_kim_selection_hints_remember_identity (kim_test_state_t state);