Mercurial > pidgin.yaz
changeset 32207:9526ffc3a9f5
dnssrv: Refactor to reduce code duplication
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 20 Jul 2011 05:04:37 +0000 |
parents | 9821c19360b8 |
children | cb4705abb991 |
files | libpurple/dnssrv.c |
diffstat | 1 files changed, 48 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/dnssrv.c Tue Jul 19 20:07:25 2011 +0000 +++ b/libpurple/dnssrv.c Wed Jul 20 05:04:37 2011 +0000 @@ -250,6 +250,52 @@ return list; } +static PurpleSrvTxtQueryData * +query_data_new(int type, gchar *query, gpointer extradata) +{ + PurpleSrvTxtQueryData *query_data = g_new0(PurpleSrvTxtQueryData, 1); + query_data->type = type; + query_data->extradata = extradata; + query_data->query = query; +#ifndef _WIN32 + query_data->fd_in = -1; + query_data->fd_out = -1; +#endif + return query_data; +} + +void +purple_srv_txt_query_destroy(PurpleSrvTxtQueryData *query_data) +{ + PurpleSrvTxtQueryUiOps *ops = purple_srv_txt_query_get_ui_ops(); + + if (ops && ops->destroy) + ops->destroy(query_data); + + if (query_data->handle > 0) + purple_input_remove(query_data->handle); +#ifdef _WIN32 + if (query_data->resolver != NULL) + { + /* + * It's not really possible to kill a thread. So instead we + * just set the callback to NULL and let the DNS lookup + * finish. + */ + query_data->cb.srv = NULL; + return; + } + g_free(query_data->error_message); +#else + 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); +} + #ifdef USE_IDN static gboolean dns_str_is_ascii(const char *name) @@ -731,15 +777,8 @@ query); g_free(hostname); - query_data = g_new0(PurpleSrvTxtQueryData, 1); - query_data->type = PurpleDnsTypeSrv; + query_data = query_data_new(PurpleDnsTypeSrv, extradata, query); query_data->cb.srv = cb; - query_data->extradata = extradata; - query_data->query = query; -#ifndef _WIN32 - query_data->fd_in = -1; - query_data->fd_out = -1; -#endif if (purple_srv_txt_query_ui_resolve(query_data)) { @@ -868,15 +907,8 @@ query); g_free(hostname); - query_data = g_new0(PurpleSrvTxtQueryData, 1); - query_data->type = PurpleDnsTypeTxt; + query_data = query_data_new(PurpleDnsTypeTxt, query, extradata); query_data->cb.txt = cb; - query_data->extradata = extradata; - query_data->query = query; -#ifndef _WIN32 - query_data->fd_in = -1; - query_data->fd_out = -1; -#endif if (purple_srv_txt_query_ui_resolve(query_data)) { /* query intentionally not freed @@ -959,38 +991,6 @@ } void -purple_srv_txt_query_destroy(PurpleSrvTxtQueryData *query_data) -{ - PurpleSrvTxtQueryUiOps *ops = purple_srv_txt_query_get_ui_ops(); - - if (ops && ops->destroy) - ops->destroy(query_data); - - if (query_data->handle > 0) - purple_input_remove(query_data->handle); -#ifdef _WIN32 - if (query_data->resolver != NULL) - { - /* - * It's not really possible to kill a thread. So instead we - * just set the callback to NULL and let the DNS lookup - * finish. - */ - query_data->cb.srv = NULL; - return; - } - g_free(query_data->error_message); -#else - 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_txt_query_destroy(query_data);