Index: src/libvortex.def =================================================================== --- src/libvortex.def (revision 686) +++ src/libvortex.def (working copy) @@ -403,12 +403,13 @@ vortex_mutex_destroy vortex_mutex_lock vortex_mutex_unlock +vortex_profiles_acquire vortex_profiles_cleanup vortex_profiles_get_actual_list -vortex_profiles_get_actual_list_ref vortex_profiles_get_automatic_mime vortex_profiles_get_mime_type vortex_profiles_get_transfer_encoding +vortex_profiles_has_profiles vortex_profiles_init vortex_profiles_invoke_close vortex_profiles_invoke_frame_received @@ -420,6 +421,7 @@ vortex_profiles_register vortex_profiles_register_extended_start vortex_profiles_registered +vortex_profiles_release vortex_profiles_set_automatic_mime vortex_profiles_set_mime_type vortex_profiles_unregister Index: src/vortex_greetings.c =================================================================== --- src/vortex_greetings.c (revision 686) +++ src/vortex_greetings.c (working copy) @@ -63,7 +63,7 @@ **/ int __vortex_greetings_build_message (VortexConnection * connection, char * greetings_buffer, int buffer_size) { - axlList * registered_profiles = vortex_profiles_get_actual_list_ref (); + axlList * registered_profiles = NULL; int iterator; int next_index = 0; const char * localize = NULL; @@ -117,6 +117,7 @@ memcpy (greetings_buffer + next_index, ">\x0D\x0A", 3); next_index += 3; + registered_profiles = vortex_profiles_acquire (); if (registered_profiles != NULL) { iterator = 0; while (iterator < axl_list_length (registered_profiles)) { @@ -142,6 +143,7 @@ if ((next_index + size + 36) >= buffer_size) { vortex_log (LOG_DOMAIN, VORTEX_LEVEL_CRITICAL, "found buffer to build greetings to be not enough to hold current profiles to advertise"); + vortex_profiles_release(registered_profiles); return -1; } /* end if */ @@ -162,6 +164,7 @@ } /* end if */ } /* end if */ + vortex_profiles_release(registered_profiles); /* terminate greetings */ memcpy (greetings_buffer + next_index, "\x0D\x0A", 13); @@ -183,16 +186,13 @@ **/ axl_bool vortex_greetings_send (VortexConnection * connection) { - axlList * registered_profiles; - /* tecnically, the greetings initial message can't be larger * than 4096 initial window. */ char greetings_buffer[5100]; int next_index = 0; /* build up supported registered profiles */ - registered_profiles = vortex_profiles_get_actual_list_ref (); - if (registered_profiles == NULL) { + if (!vortex_profiles_has_profiles()) { vortex_log (LOG_DOMAIN, VORTEX_LEVEL_CRITICAL, "unable to build and send greetings message: unable to find any profile registered"); __vortex_connection_set_not_connected (connection, "unable to build and send greetings message: unable to find any profile registered"); @@ -367,16 +367,13 @@ **/ axl_bool vortex_greetings_client_send (VortexConnection * connection) { - axlList * registered_profiles; - /* tecnically, the greetings initial message can't be larger * than 4096 initial window. */ char greetings_buffer[5100]; int next_index = 0; /* build up supported registered profiles */ - registered_profiles = vortex_profiles_get_actual_list_ref (); - if (registered_profiles == NULL) { + if (!vortex_profiles_has_profiles ()) { vortex_log (LOG_DOMAIN, VORTEX_LEVEL_CRITICAL, "unable to build and send greetings message: unable to found any profile registered"); return axl_false; Index: src/vortex_profiles.c =================================================================== --- src/vortex_profiles.c (revision 686) +++ src/vortex_profiles.c (working copy) @@ -35,6 +35,7 @@ * Email address: * info@aspl.es - http://www.aspl.es/vortex */ +#include #include /* local include */ @@ -892,19 +893,39 @@ * @brief Return current profiles registered, in a internally created * list. * - * - * @return A reference to the profile list. Do not manipulate or - * dealloc the list. + * @return A reference to the profile list. This reference must be released + * with vortex_profiles_release when not being used anymore */ -axlList * vortex_profiles_get_actual_list_ref () +axlList * vortex_profiles_acquire () { - /* get current context */ VortexCtx * ctx = vortex_ctx_get (); - - /* return the reference */ + vortex_mutex_lock(&ctx->profiles_list_mutex); return ctx->profiles_list; } +/** + * @brief Release current profiles list + */ +void vortex_profiles_release (axlList* list) +{ + VortexCtx * ctx = vortex_ctx_get (); + assert( ctx->profiles_list == list ); + vortex_mutex_unlock(&ctx->profiles_list_mutex); +} + +/** + * @ brief Return true if there are profiles currently registered + */ +axl_bool vortex_profiles_has_profiles () +{ + VortexCtx * ctx = vortex_ctx_get(); + axl_bool rpy; + vortex_mutex_lock(&ctx->profiles_list_mutex); + rpy = !!ctx->profiles_list; + vortex_mutex_unlock(&ctx->profiles_list_mutex); + return rpy; +} + /** * @brief Return the actual number of profiles registered. * Index: src/vortex_profiles.h =================================================================== --- src/vortex_profiles.h (revision 686) +++ src/vortex_profiles.h (working copy) @@ -83,9 +83,10 @@ int vortex_profiles_is_defined_received (const char * uri); axlList * vortex_profiles_get_actual_list (); +axl_bool vortex_profiles_has_profiles (); +axlList * vortex_profiles_acquire (); +void vortex_profiles_release (axlList * list); -axlList * vortex_profiles_get_actual_list_ref (); - int vortex_profiles_registered (); axl_bool vortex_profiles_is_registered (const char * uri);