Mercurial > pidgin
changeset 31742:ad79fa168cee
Fixes to the PurpleSrvTxtQueryUiOps code. Refs #12647
committer: Paul Aurich <paul@darkrain42.org>
author | thijsalkemade@gmail.com |
---|---|
date | Sun, 17 Jul 2011 17:14:21 +0000 |
parents | f7c94fc60a0c |
children | a40d1cb09beb |
files | ChangeLog.API libpurple/dnssrv.c libpurple/dnssrv.h |
diffstat | 3 files changed, 65 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog.API Sun Jul 17 05:29:19 2011 +0000 +++ b/ChangeLog.API Sun Jul 17 17:14:21 2011 +0000 @@ -1,6 +1,10 @@ Pidgin and Finch: The Pimpin' Penguin IM Clients That're Good for the Soul version 2.10.0: + libpurple: + Added: + * purple_srv_txt_query_destroy (accidentally left out of 2.8.0) + Pidgin: Added: * pidgin_dialogs_plugins_info (should not be used by anything but Pidgin)
--- a/libpurple/dnssrv.c Sun Jul 17 05:29:19 2011 +0000 +++ b/libpurple/dnssrv.c Sun Jul 17 17:14:21 2011 +0000 @@ -523,7 +523,7 @@ } waitpid(query_data->pid, &status, 0); - purple_srv_cancel(query_data); + purple_srv_txt_query_destroy(query_data); } #else /* _WIN32 */ @@ -583,7 +583,7 @@ query_data->resolver = NULL; query_data->handle = 0; - purple_srv_cancel(query_data); + purple_srv_txt_query_destroy(query_data); return FALSE; } @@ -736,6 +736,8 @@ query_data->cb.srv = cb; query_data->extradata = extradata; query_data->query = query; + query_data->fd_in = -1; + query_data->fd_out = -1; if (purple_srv_txt_query_ui_resolve(query_data)) { @@ -868,6 +870,8 @@ query_data->cb.txt = cb; query_data->extradata = extradata; query_data->query = query; + query_data->fd_in = -1; + query_data->fd_out = -1; if (purple_srv_txt_query_ui_resolve(query_data)) { /* query intentionally not freed @@ -949,7 +953,7 @@ } void -purple_srv_cancel(PurpleSrvTxtQueryData *query_data) +purple_srv_txt_query_destroy(PurpleSrvTxtQueryData *query_data) { PurpleSrvTxtQueryUiOps *ops = purple_srv_txt_query_get_ui_ops(); @@ -969,19 +973,27 @@ query_data->cb.srv = NULL; return; } - g_free(query_data->query); g_free(query_data->error_message); #else - close(query_data->fd_out); - close(query_data->fd_in); + if (query_data->fd_out != -1) + close(query_data->fd_out); + if (query_data->fd_in != -1) + close(query_data->fd_in); #endif + g_free(query_data->query); g_free(query_data); } void purple_txt_cancel(PurpleSrvTxtQueryData *query_data) { - purple_srv_cancel(query_data); + purple_srv_txt_query_destroy(query_data); +} + +void +purple_srv_cancel(PurpleSrvTxtQueryData *query_data) +{ + purple_srv_txt_query_destroy(query_data); } const gchar * @@ -1006,12 +1018,38 @@ static void purple_srv_query_resolved(PurpleSrvTxtQueryData *query_data, GList *records) { + GList *sorted_records, *l; + PurpleSrvResponse *records_array; + int i; + g_return_if_fail(records != NULL); + + if (query_data->cb.srv == NULL) { + purple_srv_txt_query_destroy(query_data); + + g_list_foreach(records, (GFunc)g_free, NULL); + g_list_free(records); + return; + } + + sorted_records = purple_srv_sort(records); + + purple_debug_info("dnssrv", "SRV records resolved for %s, count: %d\n", query_data->query, g_list_length(sorted_records)); + + records_array = g_new(PurpleSrvResponse, g_list_length(sorted_records)); + + i = 0; + + for (l = sorted_records; l; l = l->next, i++) { + records_array[i] = *(PurpleSrvResponse *)l->data; + } + + query_data->cb.srv(records_array, i, query_data->extradata); - purple_debug_info("dnssrv", "SRV records resolved for %s, count: %d\n", query_data->query, g_list_length(records)); + purple_srv_txt_query_destroy(query_data); - if (query_data->cb.srv != NULL) - query_data->cb.srv(purple_srv_sort(records)->data, g_list_length(records), query_data->extradata); + g_list_foreach(sorted_records, (GFunc)g_free, NULL); + g_list_free(sorted_records); } /* @@ -1024,8 +1062,16 @@ purple_debug_info("dnssrv", "TXT entries resolved for %s, count: %d\n", query_data->query, g_list_length(entries)); + /* the callback should g_free the entries. + */ if (query_data->cb.txt != NULL) query_data->cb.txt(entries, query_data->extradata); + else { + g_list_foreach(entries, (GFunc)g_free, NULL); + g_list_free(entries); + } + + purple_srv_txt_query_destroy(query_data); } static void @@ -1036,7 +1082,7 @@ if (query_data->cb.srv != NULL) query_data->cb.srv(NULL, 0, query_data->extradata); - purple_srv_cancel(query_data); + purple_srv_txt_query_destroy(query_data); } static gboolean
--- a/libpurple/dnssrv.h Sun Jul 17 05:29:19 2011 +0000 +++ b/libpurple/dnssrv.h Sun Jul 17 17:14:21 2011 +0000 @@ -133,6 +133,8 @@ * Cancel an SRV or DNS query. * * @param query_data The request to cancel. + * + * @deprecated Use purple_srv_txt_query_destroy instead */ void purple_srv_cancel(PurpleSrvTxtQueryData *query_data); @@ -170,6 +172,8 @@ * * @param query_data The request to cancel. * @since 2.6.0 + * + * @deprecated Use purple_srv_txt_query_destroy instead */ void purple_txt_cancel(PurpleSrvTxtQueryData *query_data);