You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(106) |
Oct
(334) |
Nov
(246) |
Dec
(145) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(42) |
Feb
(53) |
Mar
(232) |
Apr
(109) |
May
(137) |
Jun
(63) |
Jul
(26) |
Aug
(263) |
Sep
(193) |
Oct
(507) |
Nov
(440) |
Dec
(241) |
2003 |
Jan
(567) |
Feb
(195) |
Mar
(504) |
Apr
(481) |
May
(524) |
Jun
(522) |
Jul
(594) |
Aug
(502) |
Sep
(643) |
Oct
(508) |
Nov
(430) |
Dec
(377) |
2004 |
Jan
(361) |
Feb
(251) |
Mar
(219) |
Apr
(499) |
May
(461) |
Jun
(419) |
Jul
(314) |
Aug
(519) |
Sep
(416) |
Oct
(247) |
Nov
(305) |
Dec
(382) |
2005 |
Jan
(267) |
Feb
(282) |
Mar
(327) |
Apr
(338) |
May
(189) |
Jun
(400) |
Jul
(462) |
Aug
(530) |
Sep
(316) |
Oct
(523) |
Nov
(481) |
Dec
(650) |
2006 |
Jan
(536) |
Feb
(361) |
Mar
(287) |
Apr
(146) |
May
(101) |
Jun
(169) |
Jul
(221) |
Aug
(498) |
Sep
(300) |
Oct
(236) |
Nov
(209) |
Dec
(205) |
2007 |
Jan
(30) |
Feb
(23) |
Mar
(26) |
Apr
(15) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dat...@us...> - 2006-08-17 23:59:02
|
Revision: 16820 Author: datallah Date: 2006-08-17 16:58:58 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16820&view=rev Log Message: ----------- Fix CID 250 (also change the behavior to be slightly more sane) and 213 (which wouldn't happen unless the sasl library returned some weird values) Modified Paths: -------------- trunk/src/protocols/jabber/auth.c Modified: trunk/src/protocols/jabber/auth.c =================================================================== --- trunk/src/protocols/jabber/auth.c 2006-08-17 22:42:28 UTC (rev 16819) +++ trunk/src/protocols/jabber/auth.c 2006-08-17 23:58:58 UTC (rev 16820) @@ -181,9 +181,9 @@ static void jabber_auth_start_cyrus(JabberStream *js) { - const char *clientout, *mech; + const char *clientout = NULL, *mech = NULL; char *enc_out; - unsigned coutlen; + unsigned coutlen = 0; xmlnode *auth; sasl_security_properties_t secprops; gboolean again; @@ -256,21 +256,29 @@ /* For everything else, fail the mechanism and try again */ default: gaim_debug_info("sasl", "sasl_state is %d, failing the mech and trying again\n", js->sasl_state); - if (strlen(mech)>0) { + + /* + * DAA: is this right? + * The manpage says that "mech" will contain the chosen mechanism on success. + * Presumably, if we get here that isn't the case and we shouldn't try again? + * I suspect that this never happens. + */ + if (mech && strlen(mech) > 0) { char *pos; - pos = strstr(js->sasl_mechs->str,mech); - g_assert(pos!=NULL); - g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str,strlen(mech)); + if ((pos = strstr(js->sasl_mechs->str, mech)) { + g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(mech)); + } + again = TRUE; } + sasl_dispose(&js->sasl); - again=TRUE; } } while (again); if (js->sasl_state == SASL_CONTINUE || js->sasl_state == SASL_OK) { auth = xmlnode_new("auth"); xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); - xmlnode_set_attrib(auth,"mechanism", mech); + xmlnode_set_attrib(auth, "mechanism", mech); if (clientout) { if (coutlen == 0) { xmlnode_insert_data(auth, "=", -1); @@ -332,7 +340,7 @@ char *mech_name = xmlnode_get_data(mechnode); #ifdef HAVE_CYRUS_SASL g_string_append(js->sasl_mechs, mech_name); - g_string_append_c(js->sasl_mechs,' '); + g_string_append_c(js->sasl_mechs, ' '); #else if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) digest_md5 = TRUE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-08-17 22:42:33
|
Revision: 16819 Author: seanegan Date: 2006-08-17 15:42:28 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16819&view=rev Log Message: ----------- Patch to eggtrayicon by Dan Winship makes icon transparent Modified Paths: -------------- trunk/COPYRIGHT trunk/ChangeLog trunk/plugins/docklet/eggtrayicon.c Modified: trunk/COPYRIGHT =================================================================== --- trunk/COPYRIGHT 2006-08-17 21:16:50 UTC (rev 16818) +++ trunk/COPYRIGHT 2006-08-17 22:42:28 UTC (rev 16819) @@ -317,6 +317,7 @@ Dan Willemsen Jason Willis Matt Wilson +Dan Winship Scott Wolchok Pui Lam Wong Justin Wood Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-08-17 21:16:50 UTC (rev 16818) +++ trunk/ChangeLog 2006-08-17 22:42:28 UTC (rev 16819) @@ -99,6 +99,7 @@ removed. * 'Highlight when nick said' option added to Message Notification plugin. + * The system tray icon is now transparent (Dan Winship) MSN Features: * Custom smiley receiving support (Irving Cordova & Francesco Fracassi) Modified: trunk/plugins/docklet/eggtrayicon.c =================================================================== --- trunk/plugins/docklet/eggtrayicon.c 2006-08-17 21:16:50 UTC (rev 16818) +++ trunk/plugins/docklet/eggtrayicon.c 2006-08-17 22:42:28 UTC (rev 16819) @@ -54,6 +54,9 @@ static void egg_tray_icon_realize (GtkWidget *widget); static void egg_tray_icon_unrealize (GtkWidget *widget); +static void egg_tray_icon_add (GtkContainer *container, + GtkWidget *widget); + static void egg_tray_icon_update_manager_window (EggTrayIcon *icon, gboolean dock_if_realized); static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon); @@ -109,6 +112,7 @@ { GObjectClass *gobject_class = (GObjectClass *)klass; GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; + GtkContainerClass *container_class = (GtkContainerClass *)klass; parent_class = g_type_class_peek_parent (klass); @@ -117,6 +121,8 @@ widget_class->realize = egg_tray_icon_realize; widget_class->unrealize = egg_tray_icon_unrealize; + container_class->add = egg_tray_icon_add; + g_object_class_install_property (gobject_class, PROP_ORIENTATION, g_param_spec_enum ("orientation", @@ -374,7 +380,37 @@ egg_tray_icon_update_manager_window (icon, TRUE); } +static gboolean +transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) +{ + gdk_window_clear_area (widget->window, event->area.x, event->area.y, + event->area.width, event->area.height); + return FALSE; +} + static void +make_transparent_again (GtkWidget *widget, GtkStyle *previous_style, + gpointer user_data) +{ + gdk_window_set_back_pixmap(widget->window, NULL, TRUE); +} + +static void +make_transparent (GtkWidget *widget, gpointer user_data) +{ + if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget)) + return; + + gtk_widget_set_app_paintable (widget, TRUE); + gtk_widget_set_double_buffered (widget, FALSE); + gdk_window_set_back_pixmap (widget->window, NULL, TRUE); + g_signal_connect (widget, "expose_event", + G_CALLBACK (transparent_expose_event), NULL); + g_signal_connect_after (widget, "style_set", + G_CALLBACK (make_transparent_again), NULL); +} + +static void egg_tray_icon_realize (GtkWidget *widget) { EggTrayIcon *icon = EGG_TRAY_ICON (widget); @@ -386,6 +422,8 @@ if (GTK_WIDGET_CLASS (parent_class)->realize) GTK_WIDGET_CLASS (parent_class)->realize (widget); + make_transparent (widget, NULL); + #if GTK_CHECK_VERSION(2,1,0) screen = gdk_screen_get_number (gtk_widget_get_screen (widget)); xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)); @@ -425,6 +463,14 @@ egg_tray_icon_manager_filter, icon); } +static void +egg_tray_icon_add (GtkContainer *container, GtkWidget *widget) +{ + g_signal_connect (widget, "realize", + G_CALLBACK (make_transparent), NULL); + GTK_CONTAINER_CLASS (parent_class)->add (container, widget); +} + #if GTK_CHECK_VERSION(2,1,0) EggTrayIcon * egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-08-17 21:16:54
|
Revision: 16818 Author: seanegan Date: 2006-08-17 14:16:50 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16818&view=rev Log Message: ----------- Remove a g_main_iteration, replace with an idle handler. Fixes the thread freeze on expanding contacts Modified Paths: -------------- trunk/src/gtkblist.c Modified: trunk/src/gtkblist.c =================================================================== --- trunk/src/gtkblist.c 2006-08-17 15:46:58 UTC (rev 16817) +++ trunk/src/gtkblist.c 2006-08-17 21:16:50 UTC (rev 16818) @@ -867,6 +867,24 @@ } } +struct _expand { + GtkTreeView *treeview; + GtkTreePath *path; + GaimBlistNode *node; +}; + +static gboolean +scroll_to_expanded_cell(struct _expand *ex) +{ + gtk_tree_view_scroll_to_cell(ex->treeview, ex->path, NULL, FALSE, 0, 0); + gaim_gtk_blist_update_contact(NULL, ex->node); + + gtk_tree_path_free(ex->path); + g_free(ex); + + return FALSE; +} + static void gaim_gtk_blist_expand_contact_cb(GtkWidget *w, GaimBlistNode *node) { @@ -875,6 +893,8 @@ GaimBlistNode *bnode; GtkTreePath *path; + struct _expand *ex = g_new0(struct _expand, 1); + if(!GAIM_BLIST_NODE_IS_CONTACT(node)) return; @@ -891,13 +911,12 @@ gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(gtkblist->treemodel), &iter, &parent, gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &parent) -1); path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); + /* Let the treeview draw so it knows where to scroll */ - while (gtk_events_pending()) - gtk_main_iteration(); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(gtkblist->treeview), path, NULL, FALSE, 0, 0); - - gaim_gtk_blist_update_contact(NULL, node->child); - gtk_tree_path_free(path); + ex->treeview = GTK_TREE_VIEW(gtkblist->treeview); + ex->path = path; + ex->node = node->child; + g_idle_add(scroll_to_expanded_cell, ex); } static void @@ -3933,6 +3952,8 @@ G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(gtkblist->treeview), TRUE); + gtk_widget_show(gtkblist->treeview); gtk_widget_set_name(gtkblist->treeview, "gaim_gtkblist_treeview"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 15:47:05
|
Revision: 16817 Author: datallah Date: 2006-08-17 08:46:58 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16817&view=rev Log Message: ----------- nosnilmot pointed out that I'm an idiot and this is a far less ugly way to achieve the same goal. (I swear I tried it first, but must have not actually saved the file when I tested it). Modified Paths: -------------- trunk/src/sslconn.c Modified: trunk/src/sslconn.c =================================================================== --- trunk/src/sslconn.c 2006-08-17 15:19:12 UTC (rev 16816) +++ trunk/src/sslconn.c 2006-08-17 15:46:58 UTC (rev 16817) @@ -71,7 +71,6 @@ { GaimSslConnection *gsc; GaimSslOps *ops; - void (*connect_func)(GaimSslConnection *gsc); gsc = data; gsc->connect_info = NULL; @@ -88,8 +87,7 @@ gsc->fd = source; ops = gaim_ssl_get_ops(); - connect_func = (ops->connect); - connect_func(gsc); + (ops->connect)(gsc); } GaimSslConnection * @@ -160,7 +158,6 @@ { GaimSslConnection *gsc; GaimSslOps *ops; - void (*connect_func)(GaimSslConnection *gsc); g_return_val_if_fail(fd != -1, NULL); g_return_val_if_fail(func != NULL, NULL); @@ -180,8 +177,7 @@ gsc->fd = fd; ops = gaim_ssl_get_ops(); - connect_func = ops->connect; - connect_func(gsc); + (ops->connect)(gsc); return (GaimSslConnection *)gsc; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 15:19:17
|
Revision: 16816 Author: datallah Date: 2006-08-17 08:19:12 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16816&view=rev Log Message: ----------- I will apologize in advance for this ugliness - it is necessary because we have a "connect" macro to cause the wgaim_connect() wrapper function to be used. Modified Paths: -------------- trunk/src/sslconn.c Modified: trunk/src/sslconn.c =================================================================== --- trunk/src/sslconn.c 2006-08-17 14:07:20 UTC (rev 16815) +++ trunk/src/sslconn.c 2006-08-17 15:19:12 UTC (rev 16816) @@ -71,6 +71,7 @@ { GaimSslConnection *gsc; GaimSslOps *ops; + void (*connect_func)(GaimSslConnection *gsc); gsc = data; gsc->connect_info = NULL; @@ -87,7 +88,8 @@ gsc->fd = source; ops = gaim_ssl_get_ops(); - ops->connect(gsc); + connect_func = (ops->connect); + connect_func(gsc); } GaimSslConnection * @@ -158,6 +160,7 @@ { GaimSslConnection *gsc; GaimSslOps *ops; + void (*connect_func)(GaimSslConnection *gsc); g_return_val_if_fail(fd != -1, NULL); g_return_val_if_fail(func != NULL, NULL); @@ -177,7 +180,8 @@ gsc->fd = fd; ops = gaim_ssl_get_ops(); - ops->connect(gsc); + connect_func = ops->connect; + connect_func(gsc); return (GaimSslConnection *)gsc; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 14:07:26
|
Revision: 16815 Author: datallah Date: 2006-08-17 07:07:20 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16815&view=rev Log Message: ----------- If g_open isn't a macro, we need to specify the mode variable Modified Paths: -------------- trunk/src/protocols/silc/util.c Modified: trunk/src/protocols/silc/util.c =================================================================== --- trunk/src/protocols/silc/util.c 2006-08-17 10:04:21 UTC (rev 16814) +++ trunk/src/protocols/silc/util.c 2006-08-17 14:07:20 UTC (rev 16815) @@ -234,7 +234,7 @@ } #endif - if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { if ((fstat(fd, &st)) == -1) { gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, strerror(errno)); @@ -254,7 +254,7 @@ return FALSE; } - if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { if ((fstat(fd, &st)) == -1) { gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, strerror(errno)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 10:04:31
|
Revision: 16814 Author: thekingant Date: 2006-08-17 03:04:21 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16814&view=rev Log Message: ----------- Revert SVN revision 16811. Kevin says it's crashing for him and I'm tired. ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16811&view=rev Modified Paths: -------------- trunk/src/Makefile.am trunk/src/Makefile.mingw trunk/src/protocols/simple/simple.c trunk/src/proxy.c trunk/src/proxy.h trunk/src/stun.c Removed Paths: ------------- trunk/src/dnsquery.c trunk/src/dnsquery.h Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/Makefile.am 2006-08-17 10:04:21 UTC (rev 16814) @@ -77,7 +77,6 @@ core.c \ debug.c \ desktopitem.c \ - dnsquery.c \ eventloop.c \ ft.c \ idle.c \ @@ -126,7 +125,6 @@ dbus-maybe.h \ debug.h \ desktopitem.h \ - dnsquery.h \ eventloop.h \ ft.h \ idle.h \ Modified: trunk/src/Makefile.mingw =================================================================== --- trunk/src/Makefile.mingw 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/Makefile.mingw 2006-08-17 10:04:21 UTC (rev 16814) @@ -95,7 +95,6 @@ conversation.c \ core.c \ debug.c \ - dnsquery.c \ dnssrv.c \ eventloop.c \ ft.c \ Deleted: trunk/src/dnsquery.c =================================================================== --- trunk/src/dnsquery.c 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/dnsquery.c 2006-08-17 10:04:21 UTC (rev 16814) @@ -1,774 +0,0 @@ -/** - * @file dnsquery.c DNS query API - * @ingroup core - * - * gaim - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "internal.h" -#include "debug.h" -#include "ntlm.h" -#include "util.h" - -struct _GaimDnsqueryData { -}; - -/************************************************************************** - * Global DNS query API - **************************************************************************/ - -#if defined(__unix__) || defined(__APPLE__) - -/* - * This structure represents both a pending DNS request and - * a free child process. - */ -typedef struct _DnsqueryResolverprocess DnsqueryResolverprocess; -struct _DnsqueryResolverprocess { - char *host; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - guint inpa; - int fd_in, fd_out; - pid_t dns_pid; -}; - -//static GSList *all_dns_children = NULL; -static GSList *free_dns_children = NULL; -static GQueue *queued_requests = NULL; - -static int number_of_dns_children = 0; - -static const int MAX_DNS_CHILDREN = 2; - -typedef struct { - char hostname[512]; - int port; -} dns_params_t; - -typedef struct { - dns_params_t params; - GaimProxyDnsConnectFunction callback; - gpointer data; -} queued_dns_request_t; - -/* - * Begin the DNS resolver child process functions. - */ -#ifdef HAVE_SIGNAL_H -static void -trap_gdb_bug() -{ - const char *message = - "Gaim's DNS child got a SIGTRAP signal.\n" - "This can be caused by trying to run gaim inside gdb.\n" - "There is a known gdb bug which prevents this. Supposedly gaim\n" - "should have detected you were using gdb and used an ugly hack,\n" - "check cope_with_gdb_brokenness() in dnsquery.c.\n\n" - "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; - fputs("\n* * *\n",stderr); - fputs(message,stderr); - fputs("* * *\n\n",stderr); - execlp("xmessage","xmessage","-center", message, NULL); - _exit(1); -} -#endif - -static void -cope_with_gdb_brokenness() -{ -#ifdef __linux__ - static gboolean already_done = FALSE; - char s[256], e[512]; - int n; - pid_t ppid; - - if (already_done) - return; - - already_done = TRUE; - ppid = getppid(); - snprintf(s, sizeof(s), "/proc/%d/exe", ppid); - n = readlink(s, e, sizeof(e)); - if (n < 0) - return; - - e[MIN(n,sizeof(e)-1)] = '\0'; - - if (strstr(e,"gdb")) - { - gaim_debug_info("dnsquery", - "Debugger detected, performing useless query...\n"); - gethostbyname("x.x.x.x.x"); - } -#endif -} - -/** - * When doing DNS queries on Unix and OS-X, we fork off a separate - * process and communicate with it using pipes. This function is - * called shortly after the child is forked, and the function exits - * the process after it's no longer needed. - */ -static void -gaim_dns_resolverprocess(int child_out, int child_in, gboolean show_debug) -{ - dns_params_t dns_params; - const size_t zero = 0; - int rc; -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - const size_t addrlen = sizeof(sin); -#endif - -#ifdef HAVE_SIGNAL_H - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGTRAP, trap_gdb_bug); -#endif - - /* - * We resolve 1 host name for each iteration of this - * while loop. - * - * The top half of this reads in the hostname and port - * number from the socket with our parent. The bottom - * half of this resolves the IP (blocking) and sends - * the result back to our parent, when finished. - */ - while (1) - { - const char ch = 'Y'; - fd_set fds; - struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; - - FD_ZERO(&fds); - FD_SET(child_in, &fds); - rc = select(child_in + 1, &fds, NULL, NULL, &tv); - if (rc < 0) { - if (show_debug) - printf("dns[%d]: select failed\n", getpid()); - close(child_out); - close(child_in); - _exit(1); - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: nobody needs me... =(\n", getpid()); - break; - } - - rc = read(child_in, &dns_params, sizeof(dns_params_t)); - if (rc < 0) { - if (show_debug) - printf("dns[%d]: read failed\n", getpid()); - close(child_out); - close(child_in); - _exit(1); - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); - break; - } - if (dns_params.hostname[0] == '\0') { - printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); - close(child_out); - close(child_in); - _exit(1); - } - /* Tell our parent that we read the data successfully */ - write(child_out, &ch, sizeof(ch)); - - /* We have the hostname and port, now resolve the IP */ - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", dns_params.port); - memset(&hints, 0, sizeof(hints)); - - /* - * This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); - write(child_out, &rc, sizeof(rc)); - if (rc != 0) { - close(child_out); - if (show_debug) - printf("dns[%d] Error: getaddrinfo returned %d\n", - getpid(), rc); - dns_params.hostname[0] = '\0'; - continue; - } - for (tmp = res; tmp != NULL; tmp = tmp->ai_next) - { - size_t ai_addrlen = tmp->ai_addrlen; - write(child_out, &ai_addrlen, sizeof(ai_addrlen)); - write(child_out, tmp->ai_addr, tmp->ai_addrlen); - } - freeaddrinfo(res); - write(child_out, &zero, sizeof(zero)); -#else - if (!inet_aton(dns_params.hostname, &sin.sin_addr)) - { - struct hostent *hp; - - hp = gethostbyname(dns_params.hostname); - if (hp == NULL) - { - if (show_debug) - printf("DNS Error: %d\n", h_errno); - write(child_out, &h_errno, sizeof(int)); - close(child_out); - close(child_in); - _exit(1); - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - - sin.sin_port = htons(dns_params.port); - write(child_out, &addrlen, sizeof(addrlen)); - write(child_out, &sin, addrlen); - write(child_out, &zero, sizeof(zero)); -#endif - dns_params.hostname[0] = '\0'; - } - - close(child_out); - close(child_in); - - _exit(0); -} - -static DnsqueryResolverprocess * -gaim_dns_new_resolverprocess(gboolean show_debug) -{ - DnsqueryResolverprocess *req; - int child_out[2], child_in[2]; - - /* Create pipes for communicating with the child process */ - if (pipe(child_out) || pipe(child_in)) { - gaim_debug_error("dnsquery", - "Could not create pipes: %s\n", strerror(errno)); - return NULL; - } - - req = g_new(DnsqueryResolverprocess, 1); - - cope_with_gdb_brokenness(); - - /* Fork! */ - req->dns_pid = fork(); - - /* If we are the child process... */ - if (req->dns_pid == 0) { - /* We should not access the parent's side of the pipes, so close them */ - close(child_out[0]); - close(child_in[1]); - - gaim_dns_resolverprocess(child_out[1], child_in[0], show_debug); - /* The thread calls _exit() rather than returning, so we never get here */ - } - - /* We should not access the child's side of the pipes, so close them */ - close(child_out[1]); - close(child_in[0]); - if (req->dns_pid == -1) { - gaim_debug_error("dnsquery", - "Could not create child process for DNS: %s\n", - strerror(errno)); - g_free(req); - return NULL; - } - - req->fd_out = child_out[0]; - req->fd_in = child_in[1]; - number_of_dns_children++; - gaim_debug_info("dnsquery", - "Created new DNS child %d, there are now %d children.\n", - req->dns_pid, number_of_dns_children); - - return req; -} -/* - * End the DNS resolver child process functions. - */ - -/* - * Begin the functions for dealing with the DNS child processes. - */ -static void -req_free(DnsqueryResolverprocess *req) -{ - g_return_if_fail(req != NULL); - - close(req->fd_in); - close(req->fd_out); - - g_free(req->host); - g_free(req); - - number_of_dns_children--; -} - -static int -send_dns_request_to_child(DnsqueryResolverprocess *req, dns_params_t *dns_params) -{ - char ch; - int rc; - pid_t pid; - - /* This waitpid might return the child's PID if it has recently - * exited, or it might return an error if it exited "long - * enough" ago that it has already been reaped; in either - * instance, we can't use it. */ - if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { - gaim_debug_warning("dnsquery", - "DNS child %d no longer exists\n", req->dns_pid); - return -1; - } else if (pid < 0) { - gaim_debug_warning("dnsquery", - "Wait for DNS child %d failed: %s\n", - req->dns_pid, strerror(errno)); - return -1; - } - - /* Let's contact this lost child! */ - rc = write(req->fd_in, dns_params, sizeof(*dns_params)); - if (rc < 0) { - gaim_debug_error("dnsquery", - "Unable to write to DNS child %d: %d\n", - req->dns_pid, strerror(errno)); - close(req->fd_in); - return -1; - } - - g_return_val_if_fail(rc == sizeof(*dns_params), -1); - - /* Did you hear me? (This avoids some race conditions) */ - rc = read(req->fd_out, &ch, sizeof(ch)); - if (rc != 1 || ch != 'Y') - { - gaim_debug_warning("dnsquery", - "DNS child %d not responding. Killing it!\n", - req->dns_pid); - kill(req->dns_pid, SIGKILL); - return -1; - } - - gaim_debug_info("dnsquery", - "Successfully sent DNS request to child %d\n", req->dns_pid); - - return 0; -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond); - -static void -release_dns_child(DnsqueryResolverprocess *req) -{ - g_free(req->host); - req->host = NULL; - - if (queued_requests && !g_queue_is_empty(queued_requests)) { - queued_dns_request_t *r = g_queue_pop_head(queued_requests); - req->host = g_strdup(r->params.hostname); - req->port = r->params.port; - req->callback = r->callback; - req->data = r->data; - - gaim_debug_info("dnsquery", - "Processing queued DNS query for '%s' with child %d\n", - req->host, req->dns_pid); - - if (send_dns_request_to_child(req, &(r->params)) != 0) { - req_free(req); - req = NULL; - - gaim_debug_warning("dnsquery", - "Intent of process queued query of '%s' failed, " - "requeueing...\n", r->params.hostname); - g_queue_push_head(queued_requests, r); - } else { - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - g_free(r); - } - - } else { - req->host = NULL; - req->callback = NULL; - req->data = NULL; - free_dns_children = g_slist_append(free_dns_children, req); - } -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond) -{ - DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; - int rc, err; - GSList *hosts = NULL; - struct sockaddr *addr = NULL; - size_t addrlen; - - gaim_debug_info("dnsquery", "Got response for '%s'\n", req->host); - gaim_input_remove(req->inpa); - - rc = read(req->fd_out, &err, sizeof(err)); - if ((rc == 4) && (err != 0)) - { - gchar *message; -#ifdef HAVE_GETADDRINFO - message = g_strdup_printf("DNS error: %s (pid=%d)", - gai_strerror(err), req->dns_pid); -#else - message = g_strdup_printf("DNS error: %d (pid=%d)", - err, req->dns_pid); -#endif - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - release_dns_child(req); - return; - } - - if (rc > 0) - { - while (rc > 0) { - rc = read(req->fd_out, &addrlen, sizeof(addrlen)); - if (rc > 0 && addrlen > 0) { - addr = g_malloc(addrlen); - rc = read(req->fd_out, addr, addrlen); - hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); - hosts = g_slist_append(hosts, addr); - } else { - break; - } - } - } else if (rc == -1) { - gchar *message; - message = g_strdup_printf("Error reading from DNS child: %s", strerror(errno)); - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - req_free(req); - return; - } else if (rc == 0) { - gchar *message; - close(req->fd_out); - message = g_strdup_printf("EOF reading from DNS child"); - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - req_free(req); - return; - } - -/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ - - req->callback(hosts, req->data, NULL); - - release_dns_child(req); -} -/* - * End the functions for dealing with the DNS child processes. - */ - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - DnsqueryResolverprocess *req = NULL; - dns_params_t dns_params; - gchar *host_temp; - gboolean show_debug; - - show_debug = gaim_debug_is_enabled(); - - host_temp = g_strstrip(g_strdup(hostname)); - strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); - g_free(host_temp); - dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; - dns_params.port = port; - - /* - * If we have any children, attempt to have them perform the DNS - * query. If we're able to send the query to a child, then req - * will be set to the DnsqueryResolverprocess. Otherwise, req will - * be NULL and we'll need to create a new DNS request child. - */ - while (free_dns_children != NULL) - { - req = free_dns_children->data; - free_dns_children = g_slist_remove(free_dns_children, req); - - if (send_dns_request_to_child(req, &dns_params) == 0) - /* We found an acceptable child, yay */ - break; - - req_free(req); - req = NULL; - } - - /* We need to create a new DNS request child */ - if (req == NULL) - { - if (number_of_dns_children >= MAX_DNS_CHILDREN) - { - queued_dns_request_t *r = g_new(queued_dns_request_t, 1); - memcpy(&(r->params), &dns_params, sizeof(dns_params)); - r->callback = callback; - r->data = data; - if (!queued_requests) - queued_requests = g_queue_new(); - g_queue_push_tail(queued_requests, r); - - gaim_debug_info("dnsquery", - "DNS query for '%s' queued\n", dns_params.hostname); - - return query_data; - } - - req = gaim_dns_new_resolverprocess(show_debug); - if (req == NULL) - { - gaim_debug_error("dnsquery", "oh dear, this is going to explode, I give up\n"); - return NULL; - } - send_dns_request_to_child(req, &dns_params); - } - - req->host = g_strdup(hostname); - req->port = port; - req->callback = callback; - req->data = data; - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - - return query_data; -} - -#elif defined _WIN32 /* end __unix__ || __APPLE__ */ - -typedef struct _dns_tdata { - char *hostname; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - GSList *hosts; - char *errmsg; -} dns_tdata; - -static gboolean dns_main_thread_cb(gpointer data) -{ - dns_tdata *td = (dns_tdata*)data; - if (td->errmsg != NULL) { - gaim_debug_info("dnsquery", "%s\n", td->errmsg); - } - td->callback(td->hosts, td->data, td->errmsg); - g_free(td->hostname); - g_free(td->errmsg); - g_free(td); - return FALSE; -} - -static gpointer -dns_thread(gpointer data) -{ - -#ifdef HAVE_GETADDRINFO - int rc; - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - struct hostent *hp; -#endif - dns_tdata *td = (dns_tdata*)data; - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", td->port); - memset(&hints, 0, sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(td->hostname, servname, &hints, &res); - if (rc == 0) - { - tmp = res; - while(res) { - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(res->ai_addrlen)); - td->hosts = g_slist_append(td->hosts, - g_memdup(res->ai_addr, res->ai_addrlen)); - res = res->ai_next; - } - freeaddrinfo(tmp); - } - else - { - td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); - } -#else - hp = gethostbyname(td->hostname); - if (hp != NULL) - { - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(td->port); - - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(sizeof(sin))); - td->hosts = g_slist_append(td->hosts, - g_memdup(&sin, sizeof(sin))); - } else { - td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); - } -#endif - /* back to main thread */ - g_idle_add(dns_main_thread_cb, td); - - return 0; -} - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - dns_tdata *td; - struct sockaddr_in sin; - GError* err = NULL; - - if (inet_aton(hostname, &sin.sin_addr)) - { - GSList *hosts = NULL; - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); - hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); - callback(hosts, data, NULL); - return query_data; - } - - gaim_debug_info("dnsquery", "DNS Lookup for: %s\n", hostname); - td = g_new0(dns_tdata, 1); - td->hostname = g_strdup(hostname); - td->port = port; - td->callback = callback; - td->data = data; - - if (!g_thread_create(dns_thread, td, FALSE, &err)) - { - gaim_debug_error("dnsquery", "DNS thread create failure: %s\n", err?err->message:""); - g_error_free(err); - g_free(td->hostname); - g_free(td); - return NULL; - } - - return query_data; -} - -#else /* not __unix__ or __APPLE__ or _WIN32 */ - -typedef struct { - gpointer data; - size_t addrlen; - struct sockaddr *addr; - GaimProxyDnsConnectFunction callback; -} DnsqueryResolverprocess; - -static gboolean host_resolved(gpointer data) -{ - DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; - GSList *hosts = NULL; - hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); - hosts = g_slist_append(hosts, req->addr); - req->callback(hosts, req->data, NULL); - g_free(req); - return FALSE; -} - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - struct sockaddr_in sin; - DnsqueryResolverprocess *req; - - if (!inet_aton(hostname, &sin.sin_addr)) - { - struct hostent *hp; - hp = gethostbyname(hostname); - if (hp == NULL) - { - gaim_debug_error("dnsquery", - "gaim_gethostbyname(\"%s\", %d) failed: %d\n", - hostname, port, h_errno); - return NULL; - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - - req = g_new(DnsqueryResolverprocess, 1); - req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); - req->addrlen = sizeof(sin); - req->data = data; - req->callback = callback; - gaim_timeout_add(10, host_resolved, req); - - return query_data; -} - -#endif /* not __unix__ or __APPLE__ or _WIN32 */ - -void -gaim_dnsquery_destroy(GaimDnsqueryData *query_data) -{ - g_free(query_data); -} Deleted: trunk/src/dnsquery.h =================================================================== --- trunk/src/dnsquery.h 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/dnsquery.h 2006-08-17 10:04:21 UTC (rev 16814) @@ -1,76 +0,0 @@ -/** - * @file dnsquery.h DNS query API - * @ingroup core - * - * gaim - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _GAIM_DNSQUERY_H_ -#define _GAIM_DNSQUERY_H_ - -#include <glib.h> - -typedef struct _GaimDnsqueryData GaimDnsqueryData; - -/** - * The "hosts" parameter is a linked list containing pairs of - * one size_t addrlen and one struct sockaddr *addr. - */ -typedef void (*GaimDnsqueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message); - - -#ifdef __cplusplus -extern "C" { -#endif - -/**************************************************************************/ -/** @name DNS query API */ -/**************************************************************************/ -/*@{*/ - -/** - * Do an asynchronous DNS query. - * - * @param hostname The hostname to resolve - * @param port A portnumber which is stored in the struct sockaddr - * @param callback Callback to call after resolving - * @param data Extra data for the callback function - * - * @return NULL if there was an error, or a reference to a data - * structure that can be used to cancel the pending - * connection, if needed. - */ -GaimDnsqueryData *gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data); - -/** - * Cancel a DNS query. - * - * @param query_data A pointer to the DNS query data that you want - * to cancel. - */ -void gaim_dnsquery_destroy(GaimDnsqueryData *query_data); - -/*@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _GAIM_DNSQUERY_H_ */ Modified: trunk/src/protocols/simple/simple.c =================================================================== --- trunk/src/protocols/simple/simple.c 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/protocols/simple/simple.c 2006-08-17 10:04:21 UTC (rev 16814) @@ -30,7 +30,6 @@ #include "blist.h" #include "conversation.h" #include "debug.h" -#include "dnsquery.h" #include "notify.h" #include "privacy.h" #include "prpl.h" @@ -1622,7 +1621,7 @@ } else { /* UDP */ gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); - gaim_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); + gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); } } Modified: trunk/src/proxy.c =================================================================== --- trunk/src/proxy.c 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/proxy.c 2006-08-17 10:04:21 UTC (rev 16814) @@ -31,7 +31,6 @@ #include "internal.h" #include "cipher.h" -#include "dnsquery.h" #include "debug.h" #include "notify.h" #include "ntlm.h" @@ -47,7 +46,6 @@ int fd; guint inpa; GaimProxyInfo *gpi; - GaimDnsqueryData *query_data; /** * This contains alternating length/char* values. The char* @@ -309,11 +307,6 @@ connect_infos = g_slist_remove(connect_infos, connect_info); - /* - if (connect_info->query_data != NULL) - gaim_dnsquery_destroy(connect_info->query_data); - */ - while (connect_info->hosts != NULL) { /* Discard the length... */ @@ -358,7 +351,681 @@ gaim_proxy_connect_info_destroy(connect_info); } +#if defined(__unix__) || defined(__APPLE__) + +/* + * This structure represents both a pending DNS request and + * a free child process. + */ +typedef struct { + char *host; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + guint inpa; + int fd_in, fd_out; + pid_t dns_pid; +} pending_dns_request_t; + +static GSList *free_dns_children = NULL; +static GQueue *queued_requests = NULL; + +static int number_of_dns_children = 0; + +static const int MAX_DNS_CHILDREN = 2; + +typedef struct { + char hostname[512]; + int port; +} dns_params_t; + +typedef struct { + dns_params_t params; + GaimProxyDnsConnectFunction callback; + gpointer data; +} queued_dns_request_t; + +/* + * Begin the DNS resolver child process functions. + */ +#ifdef HAVE_SIGNAL_H static void +trap_gdb_bug() +{ + const char *message = + "Gaim's DNS child got a SIGTRAP signal.\n" + "This can be caused by trying to run gaim inside gdb.\n" + "There is a known gdb bug which prevents this. Supposedly gaim\n" + "should have detected you were using gdb and used an ugly hack,\n" + "check cope_with_gdb_brokenness() in proxy.c.\n\n" + "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; + fputs("\n* * *\n",stderr); + fputs(message,stderr); + fputs("* * *\n\n",stderr); + execlp("xmessage","xmessage","-center", message, NULL); + _exit(1); +} +#endif + +static void +cope_with_gdb_brokenness() +{ +#ifdef __linux__ + static gboolean already_done = FALSE; + char s[256], e[512]; + int n; + pid_t ppid; + + if(already_done) + return; + already_done = TRUE; + ppid = getppid(); + snprintf(s, sizeof(s), "/proc/%d/exe", ppid); + n = readlink(s, e, sizeof(e)); + if(n < 0) + return; + + e[MIN(n,sizeof(e)-1)] = '\0'; + + if(strstr(e,"gdb")) { + gaim_debug_info("dns", + "Debugger detected, performing useless query...\n"); + gethostbyname("x.x.x.x.x"); + } +#endif +} + +static void +gaim_dns_resolverthread(int child_out, int child_in, gboolean show_debug) +{ + dns_params_t dns_params; + const size_t zero = 0; + int rc; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + const size_t addrlen = sizeof(sin); +#endif + +#ifdef HAVE_SIGNAL_H + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGCHLD, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGTRAP, trap_gdb_bug); +#endif + + /* + * We resolve 1 host name for each iteration of this + * while loop. + * + * The top half of this reads in the hostname and port + * number from the socket with our parent. The bottom + * half of this resolves the IP (blocking) and sends + * the result back to our parent, when finished. + */ + while (1) { + const char ch = 'Y'; + fd_set fds; + struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; + FD_ZERO(&fds); + FD_SET(child_in, &fds); + rc = select(child_in + 1, &fds, NULL, NULL, &tv); + if (!rc) { + if (show_debug) + printf("dns[%d]: nobody needs me... =(\n", getpid()); + break; + } + rc = read(child_in, &dns_params, sizeof(dns_params_t)); + if (rc < 0) { + perror("read()"); + break; + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); + _exit(0); + } + if (dns_params.hostname[0] == '\0') { + printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); + _exit(1); + } + /* Tell our parent that we read the data successfully */ + write(child_out, &ch, sizeof(ch)); + + /* We have the hostname and port, now resolve the IP */ + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", dns_params.port); + memset(&hints, 0, sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); + write(child_out, &rc, sizeof(rc)); + if (rc != 0) { + close(child_out); + if (show_debug) + printf("dns[%d] Error: getaddrinfo returned %d\n", + getpid(), rc); + dns_params.hostname[0] = '\0'; + continue; + } + tmp = res; + while (res) { + size_t ai_addrlen = res->ai_addrlen; + write(child_out, &ai_addrlen, sizeof(ai_addrlen)); + write(child_out, res->ai_addr, res->ai_addrlen); + res = res->ai_next; + } + freeaddrinfo(tmp); + write(child_out, &zero, sizeof(zero)); +#else + if (!inet_aton(dns_params.hostname, &sin.sin_addr)) { + struct hostent *hp; + if (!(hp = gethostbyname(dns_params.hostname))) { + write(child_out, &h_errno, sizeof(int)); + close(child_out); + if (show_debug) + printf("DNS Error: %d\n", h_errno); + _exit(0); + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + + sin.sin_port = htons(dns_params.port); + write(child_out, &addrlen, sizeof(addrlen)); + write(child_out, &sin, addrlen); + write(child_out, &zero, sizeof(zero)); +#endif + dns_params.hostname[0] = '\0'; + } + + close(child_out); + close(child_in); + + _exit(0); +} + +static pending_dns_request_t * +gaim_dns_new_resolverthread(gboolean show_debug) +{ + pending_dns_request_t *req; + int child_out[2], child_in[2]; + + /* Create pipes for communicating with the child process */ + if (pipe(child_out) || pipe(child_in)) { + gaim_debug_error("dns", + "Could not create pipes: %s\n", strerror(errno)); + return NULL; + } + + req = g_new(pending_dns_request_t, 1); + + cope_with_gdb_brokenness(); + + /* Fork! */ + req->dns_pid = fork(); + + /* If we are the child process... */ + if (req->dns_pid == 0) { + /* We should not access the parent's side of the pipes, so close them */ + close(child_out[0]); + close(child_in[1]); + + gaim_dns_resolverthread(child_out[1], child_in[0], show_debug); + /* The thread calls _exit() rather than returning, so we never get here */ + } + + /* We should not access the child's side of the pipes, so close them */ + close(child_out[1]); + close(child_in[0]); + if (req->dns_pid == -1) { + gaim_debug_error("dns", + "Could not create child process for DNS: %s\n", + strerror(errno)); + g_free(req); + return NULL; + } + + req->fd_out = child_out[0]; + req->fd_in = child_in[1]; + number_of_dns_children++; + gaim_debug_info("dns", + "Created new DNS child %d, there are now %d children.\n", + req->dns_pid, number_of_dns_children); + + return req; +} +/* + * End the DNS resolver child process functions. + */ + +/* + * Begin the functions for dealing with the DNS child processes. + */ +static void +req_free(pending_dns_request_t *req) +{ + g_return_if_fail(req != NULL); + + close(req->fd_in); + close(req->fd_out); + + g_free(req->host); + g_free(req); + + number_of_dns_children--; +} + +static int +send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params) +{ + char ch; + int rc; + pid_t pid; + + /* This waitpid might return the child's PID if it has recently + * exited, or it might return an error if it exited "long + * enough" ago that it has already been reaped; in either + * instance, we can't use it. */ + if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { + gaim_debug_warning("dns", + "DNS child %d no longer exists\n", req->dns_pid); + return -1; + } else if (pid < 0) { + gaim_debug_warning("dns", + "Wait for DNS child %d failed: %s\n", + req->dns_pid, strerror(errno)); + return -1; + } + + /* Let's contact this lost child! */ + rc = write(req->fd_in, dns_params, sizeof(*dns_params)); + if (rc < 0) { + gaim_debug_error("dns", + "Unable to write to DNS child %d: %d\n", + req->dns_pid, strerror(errno)); + close(req->fd_in); + return -1; + } + + g_return_val_if_fail(rc == sizeof(*dns_params), -1); + + /* Did you hear me? (This avoids some race conditions) */ + rc = read(req->fd_out, &ch, sizeof(ch)); + if (rc != 1 || ch != 'Y') + { + gaim_debug_warning("dns", + "DNS child %d not responding. Killing it!\n", + req->dns_pid); + kill(req->dns_pid, SIGKILL); + return -1; + } + + gaim_debug_info("dns", + "Successfully sent DNS request to child %d\n", req->dns_pid); + + return 0; +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond); + +static void +release_dns_child(pending_dns_request_t *req) +{ + g_free(req->host); + req->host = NULL; + + if (queued_requests && !g_queue_is_empty(queued_requests)) { + queued_dns_request_t *r = g_queue_pop_head(queued_requests); + req->host = g_strdup(r->params.hostname); + req->port = r->params.port; + req->callback = r->callback; + req->data = r->data; + + gaim_debug_info("dns", + "Processing queued DNS query for '%s' with child %d\n", + req->host, req->dns_pid); + + if (send_dns_request_to_child(req, &(r->params)) != 0) { + req_free(req); + req = NULL; + + gaim_debug_warning("dns", + "Intent of process queued query of '%s' failed, " + "requeueing...\n", r->params.hostname); + g_queue_push_head(queued_requests, r); + } else { + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + g_free(r); + } + + } else { + req->host = NULL; + req->callback = NULL; + req->data = NULL; + free_dns_children = g_slist_append(free_dns_children, req); + } +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond) +{ + pending_dns_request_t *req = (pending_dns_request_t*)data; + int rc, err; + GSList *hosts = NULL; + struct sockaddr *addr = NULL; + size_t addrlen; + + gaim_debug_info("dns", "Got response for '%s'\n", req->host); + gaim_input_remove(req->inpa); + + rc = read(req->fd_out, &err, sizeof(err)); + if ((rc == 4) && (err != 0)) + { + char message[1024]; +#ifdef HAVE_GETADDRINFO + g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)", + gai_strerror(err), req->dns_pid); +#else + g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", + err, req->dns_pid); +#endif + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + release_dns_child(req); + return; + } + if (rc > 0) + { + while (rc > 0) { + rc = read(req->fd_out, &addrlen, sizeof(addrlen)); + if (rc > 0 && addrlen > 0) { + addr = g_malloc(addrlen); + rc = read(req->fd_out, addr, addrlen); + hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); + hosts = g_slist_append(hosts, addr); + } else { + break; + } + } + } else if (rc == -1) { + char message[1024]; + g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + req_free(req); + return; + } else if (rc == 0) { + char message[1024]; + g_snprintf(message, sizeof(message), "EOF reading from DNS child"); + close(req->fd_out); + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + req_free(req); + return; + } + +/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ + + req->callback(hosts, req->data, NULL); + + release_dns_child(req); +} +/* + * End the functions for dealing with the DNS child processes. + */ + +int +gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) +{ + pending_dns_request_t *req = NULL; + dns_params_t dns_params; + gchar *host_temp; + gboolean show_debug; + + show_debug = gaim_debug_is_enabled(); + + host_temp = g_strstrip(g_strdup(hostname)); + strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); + g_free(host_temp); + dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; + dns_params.port = port; + + /* + * If we have any children, attempt to have them perform the DNS + * query. If we're able to send the query to a child, then req + * will be set to the pending_dns_request_t. Otherwise, req will + * be NULL and we'll need to create a new DNS request child. + */ + while (free_dns_children != NULL) { + req = free_dns_children->data; + free_dns_children = g_slist_remove(free_dns_children, req); + + if (send_dns_request_to_child(req, &dns_params) == 0) + /* We found an acceptable child, yay */ + break; + + req_free(req); + req = NULL; + } + + /* We need to create a new DNS request child */ + if (req == NULL) { + if (number_of_dns_children >= MAX_DNS_CHILDREN) { + queued_dns_request_t *r = g_new(queued_dns_request_t, 1); + memcpy(&(r->params), &dns_params, sizeof(dns_params)); + r->callback = callback; + r->data = data; + if (!queued_requests) + queued_requests = g_queue_new(); + g_queue_push_tail(queued_requests, r); + + gaim_debug_info("dns", + "DNS query for '%s' queued\n", dns_params.hostname); + + return 0; + } + + req = gaim_dns_new_resolverthread(show_debug); + if (req == NULL) + { + gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); + return -1; + } + send_dns_request_to_child(req, &dns_params); + } + + req->host = g_strdup(hostname); + req->port = port; + req->callback = callback; + req->data = data; + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + + return 0; +} + +#elif defined _WIN32 /* end __unix__ || __APPLE__ */ + +typedef struct _dns_tdata { + char *hostname; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + GSList *hosts; + char *errmsg; +} dns_tdata; + +static gboolean dns_main_thread_cb(gpointer data) { + dns_tdata *td = (dns_tdata*)data; + if (td->errmsg != NULL) { + gaim_debug_info("dns", "%s\n", td->errmsg); + } + td->callback(td->hosts, td->data, td->errmsg); + g_free(td->hostname); + g_free(td->errmsg); + g_free(td); + return FALSE; +} + +static gpointer dns_thread(gpointer data) { + +#ifdef HAVE_GETADDRINFO + int rc; + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + struct hostent *hp; +#endif + dns_tdata *td = (dns_tdata*)data; + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", td->port); + memset(&hints,0,sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) { + tmp = res; + while(res) { + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(res->ai_addrlen)); + td->hosts = g_slist_append(td->hosts, + g_memdup(res->ai_addr, res->ai_addrlen)); + res = res->ai_next; + } + freeaddrinfo(tmp); + } else { + td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); + } +#else + if ((hp = gethostbyname(td->hostname))) { + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + sin.sin_port = htons(td->port); + + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(sizeof(sin))); + td->hosts = g_slist_append(td->hosts, + g_memdup(&sin, sizeof(sin))); + } else { + td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); + } +#endif + /* back to main thread */ + g_idle_add(dns_main_thread_cb, td); + return 0; +} + +int +gaim_gethostbyname_async(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + dns_tdata *td; + struct sockaddr_in sin; + GError* err = NULL; + + if(inet_aton(hostname, &sin.sin_addr)) { + GSList *hosts = NULL; + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); + hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); + callback(hosts, data, NULL); + return 0; + } + + gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); + td = g_new0(dns_tdata, 1); + td->hostname = g_strdup(hostname); + td->port = port; + td->callback = callback; + td->data = data; + + if(!g_thread_create(dns_thread, td, FALSE, &err)) { + gaim_debug_error("dns", "DNS thread create failure: %s\n", err?err->message:""); + g_error_free(err); + g_free(td->hostname); + g_free(td); + return -1; + } + return 0; +} + +#else /* not __unix__ or __APPLE__ or _WIN32 */ + +typedef struct { + gpointer data; + size_t addrlen; + struct sockaddr *addr; + GaimProxyDnsConnectFunction callback; +} pending_dns_request_t; + +static gboolean host_resolved(gpointer data) +{ + pending_dns_request_t *req = (pending_dns_request_t*)data; + GSList *hosts = NULL; + hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); + hosts = g_slist_append(hosts, req->addr); + req->callback(hosts, req->data, NULL); + g_free(req); + return FALSE; +} + +int +gaim_gethostbyname_async(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + struct sockaddr_in sin; + pending_dns_request_t *req; + + if (!inet_aton(hostname, &sin.sin_addr)) { + struct hostent *hp; + if(!(hp = gethostbyname(hostname))) { + gaim_debug_error("dns", + "gaim_gethostbyname(\"%s\", %d) failed: %d\n", + hostname, port, h_errno); + return -1; + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + req = g_new(pending_dns_request_t, 1); + req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); + req->addrlen = sizeof(sin); + req->data = data; + req->callback = callback; + gaim_timeout_add(10, host_resolved, req); + return 0; +} + +#endif /* not __unix__ or __APPLE__ or _WIN32 */ + +static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) { GaimProxyConnectInfo *connect_info = data; @@ -1701,9 +2368,8 @@ return NULL; } - connect_info->query_data = gaim_dnsquery_a(connecthost, - connectport, connection_host_resolved, connect_info); - if (connect_info->query_data == NULL) + if (gaim_gethostbyname_async(connecthost, + connectport, connection_host_resolved, connect_info) != 0) { gaim_proxy_connect_info_destroy(connect_info); return NULL; @@ -1735,9 +2401,8 @@ connect_info->port = port; connect_info->gpi = gpi; - connect_info->query_data = gaim_dnsquery_a(gaim_proxy_info_get_host(gpi), - gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info); - if (connect_info->query_data == NULL) + if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), + gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) { gaim_proxy_connect_info_destroy(connect_info); return NULL; Modified: trunk/src/proxy.h =================================================================== --- trunk/src/proxy.h 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/proxy.h 2006-08-17 10:04:21 UTC (rev 16814) @@ -26,7 +26,6 @@ #define _GAIM_PROXY_H_ #include <glib.h> -#include "dnsquery.h" #include "eventloop.h" /** @@ -57,7 +56,6 @@ } GaimProxyInfo; -typedef struct _GaimDnsQueryData GaimDnsQueryData; typedef struct _GaimProxyConnectInfo GaimProxyConnectInfo; typedef void (*GaimProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); @@ -280,6 +278,18 @@ */ void gaim_proxy_connect_cancel(GaimProxyConnectInfo *connect_info); +/** + * Do an async dns query + * + * @param hostname The hostname to resolve + * @param port A portnumber which is stored in the struct sockaddr + * @param callback Callback to call after resolving + * @param data Extra data for the callback function + * + * @return Zero indicates the connection is pending. Any other value indicates failure. + */ +int gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data); + /*@}*/ #ifdef __cplusplus Modified: trunk/src/stun.c =================================================================== --- trunk/src/stun.c 2006-08-17 10:04:19 UTC (rev 16813) +++ trunk/src/stun.c 2006-08-17 10:04:21 UTC (rev 16814) @@ -40,7 +40,6 @@ #include "debug.h" #include "account.h" -#include "dnsquery.h" #include "dnssrv.h" #include "network.h" #include "proxy.h" @@ -360,7 +359,7 @@ gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); - gaim_dnsquery_a(servername, port, hbn_cb, NULL); + gaim_gethostbyname_async(servername, port, hbn_cb, NULL); g_free(resp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 10:04:28
|
Revision: 16813 Author: thekingant Date: 2006-08-17 03:04:19 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16813&view=rev Log Message: ----------- Revert SVN revision 16811. Kevin says it's crashing for him and I'm tired. ViewCVS Links: ------------- http://svn.sourceforge.net/gaim/?rev=16811&view=rev Modified Paths: -------------- branches/v2_0_0/src/Makefile.am branches/v2_0_0/src/Makefile.mingw branches/v2_0_0/src/protocols/simple/simple.c branches/v2_0_0/src/proxy.c branches/v2_0_0/src/proxy.h branches/v2_0_0/src/stun.c Removed Paths: ------------- branches/v2_0_0/src/dnsquery.c branches/v2_0_0/src/dnsquery.h Modified: branches/v2_0_0/src/Makefile.am =================================================================== --- branches/v2_0_0/src/Makefile.am 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/Makefile.am 2006-08-17 10:04:19 UTC (rev 16813) @@ -77,7 +77,6 @@ core.c \ debug.c \ desktopitem.c \ - dnsquery.c \ eventloop.c \ ft.c \ idle.c \ @@ -126,7 +125,6 @@ dbus-maybe.h \ debug.h \ desktopitem.h \ - dnsquery.h \ eventloop.h \ ft.h \ idle.h \ Modified: branches/v2_0_0/src/Makefile.mingw =================================================================== --- branches/v2_0_0/src/Makefile.mingw 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/Makefile.mingw 2006-08-17 10:04:19 UTC (rev 16813) @@ -95,7 +95,6 @@ conversation.c \ core.c \ debug.c \ - dnsquery.c \ dnssrv.c \ eventloop.c \ ft.c \ Deleted: branches/v2_0_0/src/dnsquery.c =================================================================== --- branches/v2_0_0/src/dnsquery.c 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/dnsquery.c 2006-08-17 10:04:19 UTC (rev 16813) @@ -1,774 +0,0 @@ -/** - * @file dnsquery.c DNS query API - * @ingroup core - * - * gaim - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "internal.h" -#include "debug.h" -#include "ntlm.h" -#include "util.h" - -struct _GaimDnsqueryData { -}; - -/************************************************************************** - * Global DNS query API - **************************************************************************/ - -#if defined(__unix__) || defined(__APPLE__) - -/* - * This structure represents both a pending DNS request and - * a free child process. - */ -typedef struct _DnsqueryResolverprocess DnsqueryResolverprocess; -struct _DnsqueryResolverprocess { - char *host; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - guint inpa; - int fd_in, fd_out; - pid_t dns_pid; -}; - -//static GSList *all_dns_children = NULL; -static GSList *free_dns_children = NULL; -static GQueue *queued_requests = NULL; - -static int number_of_dns_children = 0; - -static const int MAX_DNS_CHILDREN = 2; - -typedef struct { - char hostname[512]; - int port; -} dns_params_t; - -typedef struct { - dns_params_t params; - GaimProxyDnsConnectFunction callback; - gpointer data; -} queued_dns_request_t; - -/* - * Begin the DNS resolver child process functions. - */ -#ifdef HAVE_SIGNAL_H -static void -trap_gdb_bug() -{ - const char *message = - "Gaim's DNS child got a SIGTRAP signal.\n" - "This can be caused by trying to run gaim inside gdb.\n" - "There is a known gdb bug which prevents this. Supposedly gaim\n" - "should have detected you were using gdb and used an ugly hack,\n" - "check cope_with_gdb_brokenness() in dnsquery.c.\n\n" - "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; - fputs("\n* * *\n",stderr); - fputs(message,stderr); - fputs("* * *\n\n",stderr); - execlp("xmessage","xmessage","-center", message, NULL); - _exit(1); -} -#endif - -static void -cope_with_gdb_brokenness() -{ -#ifdef __linux__ - static gboolean already_done = FALSE; - char s[256], e[512]; - int n; - pid_t ppid; - - if (already_done) - return; - - already_done = TRUE; - ppid = getppid(); - snprintf(s, sizeof(s), "/proc/%d/exe", ppid); - n = readlink(s, e, sizeof(e)); - if (n < 0) - return; - - e[MIN(n,sizeof(e)-1)] = '\0'; - - if (strstr(e,"gdb")) - { - gaim_debug_info("dnsquery", - "Debugger detected, performing useless query...\n"); - gethostbyname("x.x.x.x.x"); - } -#endif -} - -/** - * When doing DNS queries on Unix and OS-X, we fork off a separate - * process and communicate with it using pipes. This function is - * called shortly after the child is forked, and the function exits - * the process after it's no longer needed. - */ -static void -gaim_dns_resolverprocess(int child_out, int child_in, gboolean show_debug) -{ - dns_params_t dns_params; - const size_t zero = 0; - int rc; -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - const size_t addrlen = sizeof(sin); -#endif - -#ifdef HAVE_SIGNAL_H - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGTRAP, trap_gdb_bug); -#endif - - /* - * We resolve 1 host name for each iteration of this - * while loop. - * - * The top half of this reads in the hostname and port - * number from the socket with our parent. The bottom - * half of this resolves the IP (blocking) and sends - * the result back to our parent, when finished. - */ - while (1) - { - const char ch = 'Y'; - fd_set fds; - struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; - - FD_ZERO(&fds); - FD_SET(child_in, &fds); - rc = select(child_in + 1, &fds, NULL, NULL, &tv); - if (rc < 0) { - if (show_debug) - printf("dns[%d]: select failed\n", getpid()); - close(child_out); - close(child_in); - _exit(1); - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: nobody needs me... =(\n", getpid()); - break; - } - - rc = read(child_in, &dns_params, sizeof(dns_params_t)); - if (rc < 0) { - if (show_debug) - printf("dns[%d]: read failed\n", getpid()); - close(child_out); - close(child_in); - _exit(1); - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); - break; - } - if (dns_params.hostname[0] == '\0') { - printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); - close(child_out); - close(child_in); - _exit(1); - } - /* Tell our parent that we read the data successfully */ - write(child_out, &ch, sizeof(ch)); - - /* We have the hostname and port, now resolve the IP */ - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", dns_params.port); - memset(&hints, 0, sizeof(hints)); - - /* - * This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); - write(child_out, &rc, sizeof(rc)); - if (rc != 0) { - close(child_out); - if (show_debug) - printf("dns[%d] Error: getaddrinfo returned %d\n", - getpid(), rc); - dns_params.hostname[0] = '\0'; - continue; - } - for (tmp = res; tmp != NULL; tmp = tmp->ai_next) - { - size_t ai_addrlen = tmp->ai_addrlen; - write(child_out, &ai_addrlen, sizeof(ai_addrlen)); - write(child_out, tmp->ai_addr, tmp->ai_addrlen); - } - freeaddrinfo(res); - write(child_out, &zero, sizeof(zero)); -#else - if (!inet_aton(dns_params.hostname, &sin.sin_addr)) - { - struct hostent *hp; - - hp = gethostbyname(dns_params.hostname); - if (hp == NULL) - { - if (show_debug) - printf("DNS Error: %d\n", h_errno); - write(child_out, &h_errno, sizeof(int)); - close(child_out); - close(child_in); - _exit(1); - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - - sin.sin_port = htons(dns_params.port); - write(child_out, &addrlen, sizeof(addrlen)); - write(child_out, &sin, addrlen); - write(child_out, &zero, sizeof(zero)); -#endif - dns_params.hostname[0] = '\0'; - } - - close(child_out); - close(child_in); - - _exit(0); -} - -static DnsqueryResolverprocess * -gaim_dns_new_resolverprocess(gboolean show_debug) -{ - DnsqueryResolverprocess *req; - int child_out[2], child_in[2]; - - /* Create pipes for communicating with the child process */ - if (pipe(child_out) || pipe(child_in)) { - gaim_debug_error("dnsquery", - "Could not create pipes: %s\n", strerror(errno)); - return NULL; - } - - req = g_new(DnsqueryResolverprocess, 1); - - cope_with_gdb_brokenness(); - - /* Fork! */ - req->dns_pid = fork(); - - /* If we are the child process... */ - if (req->dns_pid == 0) { - /* We should not access the parent's side of the pipes, so close them */ - close(child_out[0]); - close(child_in[1]); - - gaim_dns_resolverprocess(child_out[1], child_in[0], show_debug); - /* The thread calls _exit() rather than returning, so we never get here */ - } - - /* We should not access the child's side of the pipes, so close them */ - close(child_out[1]); - close(child_in[0]); - if (req->dns_pid == -1) { - gaim_debug_error("dnsquery", - "Could not create child process for DNS: %s\n", - strerror(errno)); - g_free(req); - return NULL; - } - - req->fd_out = child_out[0]; - req->fd_in = child_in[1]; - number_of_dns_children++; - gaim_debug_info("dnsquery", - "Created new DNS child %d, there are now %d children.\n", - req->dns_pid, number_of_dns_children); - - return req; -} -/* - * End the DNS resolver child process functions. - */ - -/* - * Begin the functions for dealing with the DNS child processes. - */ -static void -req_free(DnsqueryResolverprocess *req) -{ - g_return_if_fail(req != NULL); - - close(req->fd_in); - close(req->fd_out); - - g_free(req->host); - g_free(req); - - number_of_dns_children--; -} - -static int -send_dns_request_to_child(DnsqueryResolverprocess *req, dns_params_t *dns_params) -{ - char ch; - int rc; - pid_t pid; - - /* This waitpid might return the child's PID if it has recently - * exited, or it might return an error if it exited "long - * enough" ago that it has already been reaped; in either - * instance, we can't use it. */ - if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { - gaim_debug_warning("dnsquery", - "DNS child %d no longer exists\n", req->dns_pid); - return -1; - } else if (pid < 0) { - gaim_debug_warning("dnsquery", - "Wait for DNS child %d failed: %s\n", - req->dns_pid, strerror(errno)); - return -1; - } - - /* Let's contact this lost child! */ - rc = write(req->fd_in, dns_params, sizeof(*dns_params)); - if (rc < 0) { - gaim_debug_error("dnsquery", - "Unable to write to DNS child %d: %d\n", - req->dns_pid, strerror(errno)); - close(req->fd_in); - return -1; - } - - g_return_val_if_fail(rc == sizeof(*dns_params), -1); - - /* Did you hear me? (This avoids some race conditions) */ - rc = read(req->fd_out, &ch, sizeof(ch)); - if (rc != 1 || ch != 'Y') - { - gaim_debug_warning("dnsquery", - "DNS child %d not responding. Killing it!\n", - req->dns_pid); - kill(req->dns_pid, SIGKILL); - return -1; - } - - gaim_debug_info("dnsquery", - "Successfully sent DNS request to child %d\n", req->dns_pid); - - return 0; -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond); - -static void -release_dns_child(DnsqueryResolverprocess *req) -{ - g_free(req->host); - req->host = NULL; - - if (queued_requests && !g_queue_is_empty(queued_requests)) { - queued_dns_request_t *r = g_queue_pop_head(queued_requests); - req->host = g_strdup(r->params.hostname); - req->port = r->params.port; - req->callback = r->callback; - req->data = r->data; - - gaim_debug_info("dnsquery", - "Processing queued DNS query for '%s' with child %d\n", - req->host, req->dns_pid); - - if (send_dns_request_to_child(req, &(r->params)) != 0) { - req_free(req); - req = NULL; - - gaim_debug_warning("dnsquery", - "Intent of process queued query of '%s' failed, " - "requeueing...\n", r->params.hostname); - g_queue_push_head(queued_requests, r); - } else { - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - g_free(r); - } - - } else { - req->host = NULL; - req->callback = NULL; - req->data = NULL; - free_dns_children = g_slist_append(free_dns_children, req); - } -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond) -{ - DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; - int rc, err; - GSList *hosts = NULL; - struct sockaddr *addr = NULL; - size_t addrlen; - - gaim_debug_info("dnsquery", "Got response for '%s'\n", req->host); - gaim_input_remove(req->inpa); - - rc = read(req->fd_out, &err, sizeof(err)); - if ((rc == 4) && (err != 0)) - { - gchar *message; -#ifdef HAVE_GETADDRINFO - message = g_strdup_printf("DNS error: %s (pid=%d)", - gai_strerror(err), req->dns_pid); -#else - message = g_strdup_printf("DNS error: %d (pid=%d)", - err, req->dns_pid); -#endif - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - release_dns_child(req); - return; - } - - if (rc > 0) - { - while (rc > 0) { - rc = read(req->fd_out, &addrlen, sizeof(addrlen)); - if (rc > 0 && addrlen > 0) { - addr = g_malloc(addrlen); - rc = read(req->fd_out, addr, addrlen); - hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); - hosts = g_slist_append(hosts, addr); - } else { - break; - } - } - } else if (rc == -1) { - gchar *message; - message = g_strdup_printf("Error reading from DNS child: %s", strerror(errno)); - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - req_free(req); - return; - } else if (rc == 0) { - gchar *message; - close(req->fd_out); - message = g_strdup_printf("EOF reading from DNS child"); - gaim_debug_error("dnsquery", "%s\n", message); - req->callback(NULL, req->data, message); - g_free(message); - req_free(req); - return; - } - -/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ - - req->callback(hosts, req->data, NULL); - - release_dns_child(req); -} -/* - * End the functions for dealing with the DNS child processes. - */ - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - DnsqueryResolverprocess *req = NULL; - dns_params_t dns_params; - gchar *host_temp; - gboolean show_debug; - - show_debug = gaim_debug_is_enabled(); - - host_temp = g_strstrip(g_strdup(hostname)); - strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); - g_free(host_temp); - dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; - dns_params.port = port; - - /* - * If we have any children, attempt to have them perform the DNS - * query. If we're able to send the query to a child, then req - * will be set to the DnsqueryResolverprocess. Otherwise, req will - * be NULL and we'll need to create a new DNS request child. - */ - while (free_dns_children != NULL) - { - req = free_dns_children->data; - free_dns_children = g_slist_remove(free_dns_children, req); - - if (send_dns_request_to_child(req, &dns_params) == 0) - /* We found an acceptable child, yay */ - break; - - req_free(req); - req = NULL; - } - - /* We need to create a new DNS request child */ - if (req == NULL) - { - if (number_of_dns_children >= MAX_DNS_CHILDREN) - { - queued_dns_request_t *r = g_new(queued_dns_request_t, 1); - memcpy(&(r->params), &dns_params, sizeof(dns_params)); - r->callback = callback; - r->data = data; - if (!queued_requests) - queued_requests = g_queue_new(); - g_queue_push_tail(queued_requests, r); - - gaim_debug_info("dnsquery", - "DNS query for '%s' queued\n", dns_params.hostname); - - return query_data; - } - - req = gaim_dns_new_resolverprocess(show_debug); - if (req == NULL) - { - gaim_debug_error("dnsquery", "oh dear, this is going to explode, I give up\n"); - return NULL; - } - send_dns_request_to_child(req, &dns_params); - } - - req->host = g_strdup(hostname); - req->port = port; - req->callback = callback; - req->data = data; - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - - return query_data; -} - -#elif defined _WIN32 /* end __unix__ || __APPLE__ */ - -typedef struct _dns_tdata { - char *hostname; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - GSList *hosts; - char *errmsg; -} dns_tdata; - -static gboolean dns_main_thread_cb(gpointer data) -{ - dns_tdata *td = (dns_tdata*)data; - if (td->errmsg != NULL) { - gaim_debug_info("dnsquery", "%s\n", td->errmsg); - } - td->callback(td->hosts, td->data, td->errmsg); - g_free(td->hostname); - g_free(td->errmsg); - g_free(td); - return FALSE; -} - -static gpointer -dns_thread(gpointer data) -{ - -#ifdef HAVE_GETADDRINFO - int rc; - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - struct hostent *hp; -#endif - dns_tdata *td = (dns_tdata*)data; - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", td->port); - memset(&hints, 0, sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(td->hostname, servname, &hints, &res); - if (rc == 0) - { - tmp = res; - while(res) { - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(res->ai_addrlen)); - td->hosts = g_slist_append(td->hosts, - g_memdup(res->ai_addr, res->ai_addrlen)); - res = res->ai_next; - } - freeaddrinfo(tmp); - } - else - { - td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); - } -#else - hp = gethostbyname(td->hostname); - if (hp != NULL) - { - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(td->port); - - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(sizeof(sin))); - td->hosts = g_slist_append(td->hosts, - g_memdup(&sin, sizeof(sin))); - } else { - td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); - } -#endif - /* back to main thread */ - g_idle_add(dns_main_thread_cb, td); - - return 0; -} - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - dns_tdata *td; - struct sockaddr_in sin; - GError* err = NULL; - - if (inet_aton(hostname, &sin.sin_addr)) - { - GSList *hosts = NULL; - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); - hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); - callback(hosts, data, NULL); - return query_data; - } - - gaim_debug_info("dnsquery", "DNS Lookup for: %s\n", hostname); - td = g_new0(dns_tdata, 1); - td->hostname = g_strdup(hostname); - td->port = port; - td->callback = callback; - td->data = data; - - if (!g_thread_create(dns_thread, td, FALSE, &err)) - { - gaim_debug_error("dnsquery", "DNS thread create failure: %s\n", err?err->message:""); - g_error_free(err); - g_free(td->hostname); - g_free(td); - return NULL; - } - - return query_data; -} - -#else /* not __unix__ or __APPLE__ or _WIN32 */ - -typedef struct { - gpointer data; - size_t addrlen; - struct sockaddr *addr; - GaimProxyDnsConnectFunction callback; -} DnsqueryResolverprocess; - -static gboolean host_resolved(gpointer data) -{ - DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; - GSList *hosts = NULL; - hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); - hosts = g_slist_append(hosts, req->addr); - req->callback(hosts, req->data, NULL); - g_free(req); - return FALSE; -} - -GaimDnsqueryData * -gaim_dnsquery_a(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - GaimDnsqueryData *query_data; - struct sockaddr_in sin; - DnsqueryResolverprocess *req; - - if (!inet_aton(hostname, &sin.sin_addr)) - { - struct hostent *hp; - hp = gethostbyname(hostname); - if (hp == NULL) - { - gaim_debug_error("dnsquery", - "gaim_gethostbyname(\"%s\", %d) failed: %d\n", - hostname, port, h_errno); - return NULL; - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - - req = g_new(DnsqueryResolverprocess, 1); - req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); - req->addrlen = sizeof(sin); - req->data = data; - req->callback = callback; - gaim_timeout_add(10, host_resolved, req); - - return query_data; -} - -#endif /* not __unix__ or __APPLE__ or _WIN32 */ - -void -gaim_dnsquery_destroy(GaimDnsqueryData *query_data) -{ - g_free(query_data); -} Deleted: branches/v2_0_0/src/dnsquery.h =================================================================== --- branches/v2_0_0/src/dnsquery.h 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/dnsquery.h 2006-08-17 10:04:19 UTC (rev 16813) @@ -1,76 +0,0 @@ -/** - * @file dnsquery.h DNS query API - * @ingroup core - * - * gaim - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _GAIM_DNSQUERY_H_ -#define _GAIM_DNSQUERY_H_ - -#include <glib.h> - -typedef struct _GaimDnsqueryData GaimDnsqueryData; - -/** - * The "hosts" parameter is a linked list containing pairs of - * one size_t addrlen and one struct sockaddr *addr. - */ -typedef void (*GaimDnsqueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message); - - -#ifdef __cplusplus -extern "C" { -#endif - -/**************************************************************************/ -/** @name DNS query API */ -/**************************************************************************/ -/*@{*/ - -/** - * Do an asynchronous DNS query. - * - * @param hostname The hostname to resolve - * @param port A portnumber which is stored in the struct sockaddr - * @param callback Callback to call after resolving - * @param data Extra data for the callback function - * - * @return NULL if there was an error, or a reference to a data - * structure that can be used to cancel the pending - * connection, if needed. - */ -GaimDnsqueryData *gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data); - -/** - * Cancel a DNS query. - * - * @param query_data A pointer to the DNS query data that you want - * to cancel. - */ -void gaim_dnsquery_destroy(GaimDnsqueryData *query_data); - -/*@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _GAIM_DNSQUERY_H_ */ Modified: branches/v2_0_0/src/protocols/simple/simple.c =================================================================== --- branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 10:04:19 UTC (rev 16813) @@ -30,7 +30,6 @@ #include "blist.h" #include "conversation.h" #include "debug.h" -#include "dnsquery.h" #include "notify.h" #include "privacy.h" #include "prpl.h" @@ -1622,7 +1621,7 @@ } else { /* UDP */ gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); - gaim_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); + gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); } } Modified: branches/v2_0_0/src/proxy.c =================================================================== --- branches/v2_0_0/src/proxy.c 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/proxy.c 2006-08-17 10:04:19 UTC (rev 16813) @@ -31,7 +31,6 @@ #include "internal.h" #include "cipher.h" -#include "dnsquery.h" #include "debug.h" #include "notify.h" #include "ntlm.h" @@ -47,7 +46,6 @@ int fd; guint inpa; GaimProxyInfo *gpi; - GaimDnsqueryData *query_data; /** * This contains alternating length/char* values. The char* @@ -309,11 +307,6 @@ connect_infos = g_slist_remove(connect_infos, connect_info); - /* - if (connect_info->query_data != NULL) - gaim_dnsquery_destroy(connect_info->query_data); - */ - while (connect_info->hosts != NULL) { /* Discard the length... */ @@ -358,7 +351,681 @@ gaim_proxy_connect_info_destroy(connect_info); } +#if defined(__unix__) || defined(__APPLE__) + +/* + * This structure represents both a pending DNS request and + * a free child process. + */ +typedef struct { + char *host; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + guint inpa; + int fd_in, fd_out; + pid_t dns_pid; +} pending_dns_request_t; + +static GSList *free_dns_children = NULL; +static GQueue *queued_requests = NULL; + +static int number_of_dns_children = 0; + +static const int MAX_DNS_CHILDREN = 2; + +typedef struct { + char hostname[512]; + int port; +} dns_params_t; + +typedef struct { + dns_params_t params; + GaimProxyDnsConnectFunction callback; + gpointer data; +} queued_dns_request_t; + +/* + * Begin the DNS resolver child process functions. + */ +#ifdef HAVE_SIGNAL_H static void +trap_gdb_bug() +{ + const char *message = + "Gaim's DNS child got a SIGTRAP signal.\n" + "This can be caused by trying to run gaim inside gdb.\n" + "There is a known gdb bug which prevents this. Supposedly gaim\n" + "should have detected you were using gdb and used an ugly hack,\n" + "check cope_with_gdb_brokenness() in proxy.c.\n\n" + "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; + fputs("\n* * *\n",stderr); + fputs(message,stderr); + fputs("* * *\n\n",stderr); + execlp("xmessage","xmessage","-center", message, NULL); + _exit(1); +} +#endif + +static void +cope_with_gdb_brokenness() +{ +#ifdef __linux__ + static gboolean already_done = FALSE; + char s[256], e[512]; + int n; + pid_t ppid; + + if(already_done) + return; + already_done = TRUE; + ppid = getppid(); + snprintf(s, sizeof(s), "/proc/%d/exe", ppid); + n = readlink(s, e, sizeof(e)); + if(n < 0) + return; + + e[MIN(n,sizeof(e)-1)] = '\0'; + + if(strstr(e,"gdb")) { + gaim_debug_info("dns", + "Debugger detected, performing useless query...\n"); + gethostbyname("x.x.x.x.x"); + } +#endif +} + +static void +gaim_dns_resolverthread(int child_out, int child_in, gboolean show_debug) +{ + dns_params_t dns_params; + const size_t zero = 0; + int rc; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + const size_t addrlen = sizeof(sin); +#endif + +#ifdef HAVE_SIGNAL_H + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGCHLD, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGTRAP, trap_gdb_bug); +#endif + + /* + * We resolve 1 host name for each iteration of this + * while loop. + * + * The top half of this reads in the hostname and port + * number from the socket with our parent. The bottom + * half of this resolves the IP (blocking) and sends + * the result back to our parent, when finished. + */ + while (1) { + const char ch = 'Y'; + fd_set fds; + struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; + FD_ZERO(&fds); + FD_SET(child_in, &fds); + rc = select(child_in + 1, &fds, NULL, NULL, &tv); + if (!rc) { + if (show_debug) + printf("dns[%d]: nobody needs me... =(\n", getpid()); + break; + } + rc = read(child_in, &dns_params, sizeof(dns_params_t)); + if (rc < 0) { + perror("read()"); + break; + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); + _exit(0); + } + if (dns_params.hostname[0] == '\0') { + printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); + _exit(1); + } + /* Tell our parent that we read the data successfully */ + write(child_out, &ch, sizeof(ch)); + + /* We have the hostname and port, now resolve the IP */ + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", dns_params.port); + memset(&hints, 0, sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); + write(child_out, &rc, sizeof(rc)); + if (rc != 0) { + close(child_out); + if (show_debug) + printf("dns[%d] Error: getaddrinfo returned %d\n", + getpid(), rc); + dns_params.hostname[0] = '\0'; + continue; + } + tmp = res; + while (res) { + size_t ai_addrlen = res->ai_addrlen; + write(child_out, &ai_addrlen, sizeof(ai_addrlen)); + write(child_out, res->ai_addr, res->ai_addrlen); + res = res->ai_next; + } + freeaddrinfo(tmp); + write(child_out, &zero, sizeof(zero)); +#else + if (!inet_aton(dns_params.hostname, &sin.sin_addr)) { + struct hostent *hp; + if (!(hp = gethostbyname(dns_params.hostname))) { + write(child_out, &h_errno, sizeof(int)); + close(child_out); + if (show_debug) + printf("DNS Error: %d\n", h_errno); + _exit(0); + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + + sin.sin_port = htons(dns_params.port); + write(child_out, &addrlen, sizeof(addrlen)); + write(child_out, &sin, addrlen); + write(child_out, &zero, sizeof(zero)); +#endif + dns_params.hostname[0] = '\0'; + } + + close(child_out); + close(child_in); + + _exit(0); +} + +static pending_dns_request_t * +gaim_dns_new_resolverthread(gboolean show_debug) +{ + pending_dns_request_t *req; + int child_out[2], child_in[2]; + + /* Create pipes for communicating with the child process */ + if (pipe(child_out) || pipe(child_in)) { + gaim_debug_error("dns", + "Could not create pipes: %s\n", strerror(errno)); + return NULL; + } + + req = g_new(pending_dns_request_t, 1); + + cope_with_gdb_brokenness(); + + /* Fork! */ + req->dns_pid = fork(); + + /* If we are the child process... */ + if (req->dns_pid == 0) { + /* We should not access the parent's side of the pipes, so close them */ + close(child_out[0]); + close(child_in[1]); + + gaim_dns_resolverthread(child_out[1], child_in[0], show_debug); + /* The thread calls _exit() rather than returning, so we never get here */ + } + + /* We should not access the child's side of the pipes, so close them */ + close(child_out[1]); + close(child_in[0]); + if (req->dns_pid == -1) { + gaim_debug_error("dns", + "Could not create child process for DNS: %s\n", + strerror(errno)); + g_free(req); + return NULL; + } + + req->fd_out = child_out[0]; + req->fd_in = child_in[1]; + number_of_dns_children++; + gaim_debug_info("dns", + "Created new DNS child %d, there are now %d children.\n", + req->dns_pid, number_of_dns_children); + + return req; +} +/* + * End the DNS resolver child process functions. + */ + +/* + * Begin the functions for dealing with the DNS child processes. + */ +static void +req_free(pending_dns_request_t *req) +{ + g_return_if_fail(req != NULL); + + close(req->fd_in); + close(req->fd_out); + + g_free(req->host); + g_free(req); + + number_of_dns_children--; +} + +static int +send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params) +{ + char ch; + int rc; + pid_t pid; + + /* This waitpid might return the child's PID if it has recently + * exited, or it might return an error if it exited "long + * enough" ago that it has already been reaped; in either + * instance, we can't use it. */ + if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { + gaim_debug_warning("dns", + "DNS child %d no longer exists\n", req->dns_pid); + return -1; + } else if (pid < 0) { + gaim_debug_warning("dns", + "Wait for DNS child %d failed: %s\n", + req->dns_pid, strerror(errno)); + return -1; + } + + /* Let's contact this lost child! */ + rc = write(req->fd_in, dns_params, sizeof(*dns_params)); + if (rc < 0) { + gaim_debug_error("dns", + "Unable to write to DNS child %d: %d\n", + req->dns_pid, strerror(errno)); + close(req->fd_in); + return -1; + } + + g_return_val_if_fail(rc == sizeof(*dns_params), -1); + + /* Did you hear me? (This avoids some race conditions) */ + rc = read(req->fd_out, &ch, sizeof(ch)); + if (rc != 1 || ch != 'Y') + { + gaim_debug_warning("dns", + "DNS child %d not responding. Killing it!\n", + req->dns_pid); + kill(req->dns_pid, SIGKILL); + return -1; + } + + gaim_debug_info("dns", + "Successfully sent DNS request to child %d\n", req->dns_pid); + + return 0; +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond); + +static void +release_dns_child(pending_dns_request_t *req) +{ + g_free(req->host); + req->host = NULL; + + if (queued_requests && !g_queue_is_empty(queued_requests)) { + queued_dns_request_t *r = g_queue_pop_head(queued_requests); + req->host = g_strdup(r->params.hostname); + req->port = r->params.port; + req->callback = r->callback; + req->data = r->data; + + gaim_debug_info("dns", + "Processing queued DNS query for '%s' with child %d\n", + req->host, req->dns_pid); + + if (send_dns_request_to_child(req, &(r->params)) != 0) { + req_free(req); + req = NULL; + + gaim_debug_warning("dns", + "Intent of process queued query of '%s' failed, " + "requeueing...\n", r->params.hostname); + g_queue_push_head(queued_requests, r); + } else { + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + g_free(r); + } + + } else { + req->host = NULL; + req->callback = NULL; + req->data = NULL; + free_dns_children = g_slist_append(free_dns_children, req); + } +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond) +{ + pending_dns_request_t *req = (pending_dns_request_t*)data; + int rc, err; + GSList *hosts = NULL; + struct sockaddr *addr = NULL; + size_t addrlen; + + gaim_debug_info("dns", "Got response for '%s'\n", req->host); + gaim_input_remove(req->inpa); + + rc = read(req->fd_out, &err, sizeof(err)); + if ((rc == 4) && (err != 0)) + { + char message[1024]; +#ifdef HAVE_GETADDRINFO + g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)", + gai_strerror(err), req->dns_pid); +#else + g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", + err, req->dns_pid); +#endif + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + release_dns_child(req); + return; + } + if (rc > 0) + { + while (rc > 0) { + rc = read(req->fd_out, &addrlen, sizeof(addrlen)); + if (rc > 0 && addrlen > 0) { + addr = g_malloc(addrlen); + rc = read(req->fd_out, addr, addrlen); + hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); + hosts = g_slist_append(hosts, addr); + } else { + break; + } + } + } else if (rc == -1) { + char message[1024]; + g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + req_free(req); + return; + } else if (rc == 0) { + char message[1024]; + g_snprintf(message, sizeof(message), "EOF reading from DNS child"); + close(req->fd_out); + gaim_debug_error("dns", "%s\n", message); + req->callback(NULL, req->data, message); + req_free(req); + return; + } + +/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ + + req->callback(hosts, req->data, NULL); + + release_dns_child(req); +} +/* + * End the functions for dealing with the DNS child processes. + */ + +int +gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) +{ + pending_dns_request_t *req = NULL; + dns_params_t dns_params; + gchar *host_temp; + gboolean show_debug; + + show_debug = gaim_debug_is_enabled(); + + host_temp = g_strstrip(g_strdup(hostname)); + strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); + g_free(host_temp); + dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; + dns_params.port = port; + + /* + * If we have any children, attempt to have them perform the DNS + * query. If we're able to send the query to a child, then req + * will be set to the pending_dns_request_t. Otherwise, req will + * be NULL and we'll need to create a new DNS request child. + */ + while (free_dns_children != NULL) { + req = free_dns_children->data; + free_dns_children = g_slist_remove(free_dns_children, req); + + if (send_dns_request_to_child(req, &dns_params) == 0) + /* We found an acceptable child, yay */ + break; + + req_free(req); + req = NULL; + } + + /* We need to create a new DNS request child */ + if (req == NULL) { + if (number_of_dns_children >= MAX_DNS_CHILDREN) { + queued_dns_request_t *r = g_new(queued_dns_request_t, 1); + memcpy(&(r->params), &dns_params, sizeof(dns_params)); + r->callback = callback; + r->data = data; + if (!queued_requests) + queued_requests = g_queue_new(); + g_queue_push_tail(queued_requests, r); + + gaim_debug_info("dns", + "DNS query for '%s' queued\n", dns_params.hostname); + + return 0; + } + + req = gaim_dns_new_resolverthread(show_debug); + if (req == NULL) + { + gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); + return -1; + } + send_dns_request_to_child(req, &dns_params); + } + + req->host = g_strdup(hostname); + req->port = port; + req->callback = callback; + req->data = data; + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + + return 0; +} + +#elif defined _WIN32 /* end __unix__ || __APPLE__ */ + +typedef struct _dns_tdata { + char *hostname; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + GSList *hosts; + char *errmsg; +} dns_tdata; + +static gboolean dns_main_thread_cb(gpointer data) { + dns_tdata *td = (dns_tdata*)data; + if (td->errmsg != NULL) { + gaim_debug_info("dns", "%s\n", td->errmsg); + } + td->callback(td->hosts, td->data, td->errmsg); + g_free(td->hostname); + g_free(td->errmsg); + g_free(td); + return FALSE; +} + +static gpointer dns_thread(gpointer data) { + +#ifdef HAVE_GETADDRINFO + int rc; + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + struct hostent *hp; +#endif + dns_tdata *td = (dns_tdata*)data; + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", td->port); + memset(&hints,0,sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) { + tmp = res; + while(res) { + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(res->ai_addrlen)); + td->hosts = g_slist_append(td->hosts, + g_memdup(res->ai_addr, res->ai_addrlen)); + res = res->ai_next; + } + freeaddrinfo(tmp); + } else { + td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); + } +#else + if ((hp = gethostbyname(td->hostname))) { + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + sin.sin_port = htons(td->port); + + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(sizeof(sin))); + td->hosts = g_slist_append(td->hosts, + g_memdup(&sin, sizeof(sin))); + } else { + td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); + } +#endif + /* back to main thread */ + g_idle_add(dns_main_thread_cb, td); + return 0; +} + +int +gaim_gethostbyname_async(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + dns_tdata *td; + struct sockaddr_in sin; + GError* err = NULL; + + if(inet_aton(hostname, &sin.sin_addr)) { + GSList *hosts = NULL; + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); + hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); + callback(hosts, data, NULL); + return 0; + } + + gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); + td = g_new0(dns_tdata, 1); + td->hostname = g_strdup(hostname); + td->port = port; + td->callback = callback; + td->data = data; + + if(!g_thread_create(dns_thread, td, FALSE, &err)) { + gaim_debug_error("dns", "DNS thread create failure: %s\n", err?err->message:""); + g_error_free(err); + g_free(td->hostname); + g_free(td); + return -1; + } + return 0; +} + +#else /* not __unix__ or __APPLE__ or _WIN32 */ + +typedef struct { + gpointer data; + size_t addrlen; + struct sockaddr *addr; + GaimProxyDnsConnectFunction callback; +} pending_dns_request_t; + +static gboolean host_resolved(gpointer data) +{ + pending_dns_request_t *req = (pending_dns_request_t*)data; + GSList *hosts = NULL; + hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); + hosts = g_slist_append(hosts, req->addr); + req->callback(hosts, req->data, NULL); + g_free(req); + return FALSE; +} + +int +gaim_gethostbyname_async(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + struct sockaddr_in sin; + pending_dns_request_t *req; + + if (!inet_aton(hostname, &sin.sin_addr)) { + struct hostent *hp; + if(!(hp = gethostbyname(hostname))) { + gaim_debug_error("dns", + "gaim_gethostbyname(\"%s\", %d) failed: %d\n", + hostname, port, h_errno); + return -1; + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + req = g_new(pending_dns_request_t, 1); + req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); + req->addrlen = sizeof(sin); + req->data = data; + req->callback = callback; + gaim_timeout_add(10, host_resolved, req); + return 0; +} + +#endif /* not __unix__ or __APPLE__ or _WIN32 */ + +static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) { GaimProxyConnectInfo *connect_info = data; @@ -1701,9 +2368,8 @@ return NULL; } - connect_info->query_data = gaim_dnsquery_a(connecthost, - connectport, connection_host_resolved, connect_info); - if (connect_info->query_data == NULL) + if (gaim_gethostbyname_async(connecthost, + connectport, connection_host_resolved, connect_info) != 0) { gaim_proxy_connect_info_destroy(connect_info); return NULL; @@ -1735,9 +2401,8 @@ connect_info->port = port; connect_info->gpi = gpi; - connect_info->query_data = gaim_dnsquery_a(gaim_proxy_info_get_host(gpi), - gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info); - if (connect_info->query_data == NULL) + if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), + gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) { gaim_proxy_connect_info_destroy(connect_info); return NULL; Modified: branches/v2_0_0/src/proxy.h =================================================================== --- branches/v2_0_0/src/proxy.h 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/proxy.h 2006-08-17 10:04:19 UTC (rev 16813) @@ -26,7 +26,6 @@ #define _GAIM_PROXY_H_ #include <glib.h> -#include "dnsquery.h" #include "eventloop.h" /** @@ -57,7 +56,6 @@ } GaimProxyInfo; -typedef struct _GaimDnsQueryData GaimDnsQueryData; typedef struct _GaimProxyConnectInfo GaimProxyConnectInfo; typedef void (*GaimProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); @@ -280,6 +278,18 @@ */ void gaim_proxy_connect_cancel(GaimProxyConnectInfo *connect_info); +/** + * Do an async dns query + * + * @param hostname The hostname to resolve + * @param port A portnumber which is stored in the struct sockaddr + * @param callback Callback to call after resolving + * @param data Extra data for the callback function + * + * @return Zero indicates the connection is pending. Any other value indicates failure. + */ +int gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data); + /*@}*/ #ifdef __cplusplus Modified: branches/v2_0_0/src/stun.c =================================================================== --- branches/v2_0_0/src/stun.c 2006-08-17 08:41:44 UTC (rev 16812) +++ branches/v2_0_0/src/stun.c 2006-08-17 10:04:19 UTC (rev 16813) @@ -40,7 +40,6 @@ #include "debug.h" #include "account.h" -#include "dnsquery.h" #include "dnssrv.h" #include "network.h" #include "proxy.h" @@ -360,7 +359,7 @@ gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); - gaim_dnsquery_a(servername, port, hbn_cb, NULL); + gaim_gethostbyname_async(servername, port, hbn_cb, NULL); g_free(resp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 08:42:03
|
Revision: 16812 Author: thekingant Date: 2006-08-17 01:41:44 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16812&view=rev Log Message: ----------- Backport SVN revisions 16807-16811 from HEAD to v2_0_0 Original commit messages: 16807: This function was used by the chat userlist buttons, which are gone 16808: gaim_ssl_connect's are now cancelable (without crashing, anyway) This was relatively easy, because the PRPLs already keep a reference to the GaimSslConnection. I just needed to update the core ssl code to keep track of the GaimProxyConnectInfo, and to call gaim_proxy_connect_cancel() when gaim_ssl_close() is called 16809: gaim_ssl_connect's are now cancelable (without crashing, anyway) This was relatively easy, because the PRPLs already keep a reference to the GaimSslConnection. I just needed to update the core ssl code to keep track of the GaimProxyConnectInfo, and to call gaim_proxy_connect_cancel() when gaim_ssl_close() is called 16810: sf patch #1541754, from Sadrul Habib Chowdhury "Setting an account to 'offline' while it is connecting doesn't cause the connection to stop. This patch fixes that." 16811: Split the DNS query stuff out into it's own file. Eventually we should move the dnssrv code into this same file. Maybe even share some code? Also the first steps toward cancelable DNS queries. Modified Paths: -------------- branches/v2_0_0/plugins/ssl/ssl-gnutls.c branches/v2_0_0/plugins/ssl/ssl-nss.c branches/v2_0_0/src/Makefile.am branches/v2_0_0/src/Makefile.mingw branches/v2_0_0/src/gtkconv.c branches/v2_0_0/src/protocols/irc/irc.c branches/v2_0_0/src/protocols/simple/simple.c branches/v2_0_0/src/proxy.c branches/v2_0_0/src/proxy.h branches/v2_0_0/src/prpl.c branches/v2_0_0/src/sslconn.c branches/v2_0_0/src/sslconn.h branches/v2_0_0/src/stun.c Added Paths: ----------- branches/v2_0_0/src/dnsquery.c branches/v2_0_0/src/dnsquery.h Modified: branches/v2_0_0/plugins/ssl/ssl-gnutls.c =================================================================== --- branches/v2_0_0/plugins/ssl/ssl-gnutls.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/plugins/ssl/ssl-gnutls.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -100,27 +100,11 @@ static void -ssl_gnutls_connect_cb(gpointer data, gint source, GaimInputCondition cond) +ssl_gnutls_connect(GaimSslConnection *gsc) { - GaimSslConnection *gsc = (GaimSslConnection *)data; GaimSslGnutlsData *gnutls_data; static const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 }; - /* - * TODO: Uh, this needs to somehow check to make sure that gsc is - * still valid before actually doing anything. - */ - - if(source < 0) { - if(gsc->error_cb != NULL) - gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); - - gaim_ssl_close(gsc); - return; - } - - gsc->fd = source; - gnutls_data = g_new0(GaimSslGnutlsData, 1); gsc->private_data = gnutls_data; @@ -133,7 +117,7 @@ gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE, xcred); - gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(source)); + gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(gsc->fd)); gnutls_data->handshake_handler = gaim_input_add(gsc->fd, GAIM_INPUT_READ, ssl_gnutls_handshake_cb, gsc); @@ -204,7 +188,7 @@ { ssl_gnutls_init, ssl_gnutls_uninit, - ssl_gnutls_connect_cb, + ssl_gnutls_connect, ssl_gnutls_close, ssl_gnutls_read, ssl_gnutls_write Modified: branches/v2_0_0/plugins/ssl/ssl-nss.c =================================================================== --- branches/v2_0_0/plugins/ssl/ssl-nss.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/plugins/ssl/ssl-nss.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -237,16 +237,13 @@ } static void -ssl_nss_connect_cb(gpointer data, gint source, GaimInputCondition cond) +ssl_nss_connect(GaimSslConnection *gsc) { - GaimSslConnection *gsc = (GaimSslConnection *)data; GaimSslNssData *nss_data = g_new0(GaimSslNssData, 1); PRSocketOptionData socket_opt; gsc->private_data = nss_data; - gsc->fd = source; - nss_data->fd = PR_ImportTCPSocket(gsc->fd); if (nss_data->fd == NULL) @@ -359,7 +356,7 @@ { ssl_nss_init, ssl_nss_uninit, - ssl_nss_connect_cb, + ssl_nss_connect, ssl_nss_close, ssl_nss_read, ssl_nss_write Modified: branches/v2_0_0/src/Makefile.am =================================================================== --- branches/v2_0_0/src/Makefile.am 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/Makefile.am 2006-08-17 08:41:44 UTC (rev 16812) @@ -77,6 +77,7 @@ core.c \ debug.c \ desktopitem.c \ + dnsquery.c \ eventloop.c \ ft.c \ idle.c \ @@ -125,6 +126,7 @@ dbus-maybe.h \ debug.h \ desktopitem.h \ + dnsquery.h \ eventloop.h \ ft.h \ idle.h \ Modified: branches/v2_0_0/src/Makefile.mingw =================================================================== --- branches/v2_0_0/src/Makefile.mingw 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/Makefile.mingw 2006-08-17 08:41:44 UTC (rev 16812) @@ -95,6 +95,7 @@ conversation.c \ core.c \ debug.c \ + dnsquery.c \ dnssrv.c \ eventloop.c \ ft.c \ Copied: branches/v2_0_0/src/dnsquery.c (from rev 16811, trunk/src/dnsquery.c) =================================================================== --- branches/v2_0_0/src/dnsquery.c (rev 0) +++ branches/v2_0_0/src/dnsquery.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -0,0 +1,774 @@ +/** + * @file dnsquery.c DNS query API + * @ingroup core + * + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "internal.h" +#include "debug.h" +#include "ntlm.h" +#include "util.h" + +struct _GaimDnsqueryData { +}; + +/************************************************************************** + * Global DNS query API + **************************************************************************/ + +#if defined(__unix__) || defined(__APPLE__) + +/* + * This structure represents both a pending DNS request and + * a free child process. + */ +typedef struct _DnsqueryResolverprocess DnsqueryResolverprocess; +struct _DnsqueryResolverprocess { + char *host; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + guint inpa; + int fd_in, fd_out; + pid_t dns_pid; +}; + +//static GSList *all_dns_children = NULL; +static GSList *free_dns_children = NULL; +static GQueue *queued_requests = NULL; + +static int number_of_dns_children = 0; + +static const int MAX_DNS_CHILDREN = 2; + +typedef struct { + char hostname[512]; + int port; +} dns_params_t; + +typedef struct { + dns_params_t params; + GaimProxyDnsConnectFunction callback; + gpointer data; +} queued_dns_request_t; + +/* + * Begin the DNS resolver child process functions. + */ +#ifdef HAVE_SIGNAL_H +static void +trap_gdb_bug() +{ + const char *message = + "Gaim's DNS child got a SIGTRAP signal.\n" + "This can be caused by trying to run gaim inside gdb.\n" + "There is a known gdb bug which prevents this. Supposedly gaim\n" + "should have detected you were using gdb and used an ugly hack,\n" + "check cope_with_gdb_brokenness() in dnsquery.c.\n\n" + "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; + fputs("\n* * *\n",stderr); + fputs(message,stderr); + fputs("* * *\n\n",stderr); + execlp("xmessage","xmessage","-center", message, NULL); + _exit(1); +} +#endif + +static void +cope_with_gdb_brokenness() +{ +#ifdef __linux__ + static gboolean already_done = FALSE; + char s[256], e[512]; + int n; + pid_t ppid; + + if (already_done) + return; + + already_done = TRUE; + ppid = getppid(); + snprintf(s, sizeof(s), "/proc/%d/exe", ppid); + n = readlink(s, e, sizeof(e)); + if (n < 0) + return; + + e[MIN(n,sizeof(e)-1)] = '\0'; + + if (strstr(e,"gdb")) + { + gaim_debug_info("dnsquery", + "Debugger detected, performing useless query...\n"); + gethostbyname("x.x.x.x.x"); + } +#endif +} + +/** + * When doing DNS queries on Unix and OS-X, we fork off a separate + * process and communicate with it using pipes. This function is + * called shortly after the child is forked, and the function exits + * the process after it's no longer needed. + */ +static void +gaim_dns_resolverprocess(int child_out, int child_in, gboolean show_debug) +{ + dns_params_t dns_params; + const size_t zero = 0; + int rc; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + const size_t addrlen = sizeof(sin); +#endif + +#ifdef HAVE_SIGNAL_H + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGCHLD, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGTRAP, trap_gdb_bug); +#endif + + /* + * We resolve 1 host name for each iteration of this + * while loop. + * + * The top half of this reads in the hostname and port + * number from the socket with our parent. The bottom + * half of this resolves the IP (blocking) and sends + * the result back to our parent, when finished. + */ + while (1) + { + const char ch = 'Y'; + fd_set fds; + struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; + + FD_ZERO(&fds); + FD_SET(child_in, &fds); + rc = select(child_in + 1, &fds, NULL, NULL, &tv); + if (rc < 0) { + if (show_debug) + printf("dns[%d]: select failed\n", getpid()); + close(child_out); + close(child_in); + _exit(1); + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: nobody needs me... =(\n", getpid()); + break; + } + + rc = read(child_in, &dns_params, sizeof(dns_params_t)); + if (rc < 0) { + if (show_debug) + printf("dns[%d]: read failed\n", getpid()); + close(child_out); + close(child_in); + _exit(1); + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); + break; + } + if (dns_params.hostname[0] == '\0') { + printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); + close(child_out); + close(child_in); + _exit(1); + } + /* Tell our parent that we read the data successfully */ + write(child_out, &ch, sizeof(ch)); + + /* We have the hostname and port, now resolve the IP */ + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", dns_params.port); + memset(&hints, 0, sizeof(hints)); + + /* + * This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); + write(child_out, &rc, sizeof(rc)); + if (rc != 0) { + close(child_out); + if (show_debug) + printf("dns[%d] Error: getaddrinfo returned %d\n", + getpid(), rc); + dns_params.hostname[0] = '\0'; + continue; + } + for (tmp = res; tmp != NULL; tmp = tmp->ai_next) + { + size_t ai_addrlen = tmp->ai_addrlen; + write(child_out, &ai_addrlen, sizeof(ai_addrlen)); + write(child_out, tmp->ai_addr, tmp->ai_addrlen); + } + freeaddrinfo(res); + write(child_out, &zero, sizeof(zero)); +#else + if (!inet_aton(dns_params.hostname, &sin.sin_addr)) + { + struct hostent *hp; + + hp = gethostbyname(dns_params.hostname); + if (hp == NULL) + { + if (show_debug) + printf("DNS Error: %d\n", h_errno); + write(child_out, &h_errno, sizeof(int)); + close(child_out); + close(child_in); + _exit(1); + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + + sin.sin_port = htons(dns_params.port); + write(child_out, &addrlen, sizeof(addrlen)); + write(child_out, &sin, addrlen); + write(child_out, &zero, sizeof(zero)); +#endif + dns_params.hostname[0] = '\0'; + } + + close(child_out); + close(child_in); + + _exit(0); +} + +static DnsqueryResolverprocess * +gaim_dns_new_resolverprocess(gboolean show_debug) +{ + DnsqueryResolverprocess *req; + int child_out[2], child_in[2]; + + /* Create pipes for communicating with the child process */ + if (pipe(child_out) || pipe(child_in)) { + gaim_debug_error("dnsquery", + "Could not create pipes: %s\n", strerror(errno)); + return NULL; + } + + req = g_new(DnsqueryResolverprocess, 1); + + cope_with_gdb_brokenness(); + + /* Fork! */ + req->dns_pid = fork(); + + /* If we are the child process... */ + if (req->dns_pid == 0) { + /* We should not access the parent's side of the pipes, so close them */ + close(child_out[0]); + close(child_in[1]); + + gaim_dns_resolverprocess(child_out[1], child_in[0], show_debug); + /* The thread calls _exit() rather than returning, so we never get here */ + } + + /* We should not access the child's side of the pipes, so close them */ + close(child_out[1]); + close(child_in[0]); + if (req->dns_pid == -1) { + gaim_debug_error("dnsquery", + "Could not create child process for DNS: %s\n", + strerror(errno)); + g_free(req); + return NULL; + } + + req->fd_out = child_out[0]; + req->fd_in = child_in[1]; + number_of_dns_children++; + gaim_debug_info("dnsquery", + "Created new DNS child %d, there are now %d children.\n", + req->dns_pid, number_of_dns_children); + + return req; +} +/* + * End the DNS resolver child process functions. + */ + +/* + * Begin the functions for dealing with the DNS child processes. + */ +static void +req_free(DnsqueryResolverprocess *req) +{ + g_return_if_fail(req != NULL); + + close(req->fd_in); + close(req->fd_out); + + g_free(req->host); + g_free(req); + + number_of_dns_children--; +} + +static int +send_dns_request_to_child(DnsqueryResolverprocess *req, dns_params_t *dns_params) +{ + char ch; + int rc; + pid_t pid; + + /* This waitpid might return the child's PID if it has recently + * exited, or it might return an error if it exited "long + * enough" ago that it has already been reaped; in either + * instance, we can't use it. */ + if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { + gaim_debug_warning("dnsquery", + "DNS child %d no longer exists\n", req->dns_pid); + return -1; + } else if (pid < 0) { + gaim_debug_warning("dnsquery", + "Wait for DNS child %d failed: %s\n", + req->dns_pid, strerror(errno)); + return -1; + } + + /* Let's contact this lost child! */ + rc = write(req->fd_in, dns_params, sizeof(*dns_params)); + if (rc < 0) { + gaim_debug_error("dnsquery", + "Unable to write to DNS child %d: %d\n", + req->dns_pid, strerror(errno)); + close(req->fd_in); + return -1; + } + + g_return_val_if_fail(rc == sizeof(*dns_params), -1); + + /* Did you hear me? (This avoids some race conditions) */ + rc = read(req->fd_out, &ch, sizeof(ch)); + if (rc != 1 || ch != 'Y') + { + gaim_debug_warning("dnsquery", + "DNS child %d not responding. Killing it!\n", + req->dns_pid); + kill(req->dns_pid, SIGKILL); + return -1; + } + + gaim_debug_info("dnsquery", + "Successfully sent DNS request to child %d\n", req->dns_pid); + + return 0; +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond); + +static void +release_dns_child(DnsqueryResolverprocess *req) +{ + g_free(req->host); + req->host = NULL; + + if (queued_requests && !g_queue_is_empty(queued_requests)) { + queued_dns_request_t *r = g_queue_pop_head(queued_requests); + req->host = g_strdup(r->params.hostname); + req->port = r->params.port; + req->callback = r->callback; + req->data = r->data; + + gaim_debug_info("dnsquery", + "Processing queued DNS query for '%s' with child %d\n", + req->host, req->dns_pid); + + if (send_dns_request_to_child(req, &(r->params)) != 0) { + req_free(req); + req = NULL; + + gaim_debug_warning("dnsquery", + "Intent of process queued query of '%s' failed, " + "requeueing...\n", r->params.hostname); + g_queue_push_head(queued_requests, r); + } else { + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + g_free(r); + } + + } else { + req->host = NULL; + req->callback = NULL; + req->data = NULL; + free_dns_children = g_slist_append(free_dns_children, req); + } +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond) +{ + DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; + int rc, err; + GSList *hosts = NULL; + struct sockaddr *addr = NULL; + size_t addrlen; + + gaim_debug_info("dnsquery", "Got response for '%s'\n", req->host); + gaim_input_remove(req->inpa); + + rc = read(req->fd_out, &err, sizeof(err)); + if ((rc == 4) && (err != 0)) + { + gchar *message; +#ifdef HAVE_GETADDRINFO + message = g_strdup_printf("DNS error: %s (pid=%d)", + gai_strerror(err), req->dns_pid); +#else + message = g_strdup_printf("DNS error: %d (pid=%d)", + err, req->dns_pid); +#endif + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + release_dns_child(req); + return; + } + + if (rc > 0) + { + while (rc > 0) { + rc = read(req->fd_out, &addrlen, sizeof(addrlen)); + if (rc > 0 && addrlen > 0) { + addr = g_malloc(addrlen); + rc = read(req->fd_out, addr, addrlen); + hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); + hosts = g_slist_append(hosts, addr); + } else { + break; + } + } + } else if (rc == -1) { + gchar *message; + message = g_strdup_printf("Error reading from DNS child: %s", strerror(errno)); + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + req_free(req); + return; + } else if (rc == 0) { + gchar *message; + close(req->fd_out); + message = g_strdup_printf("EOF reading from DNS child"); + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + req_free(req); + return; + } + +/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ + + req->callback(hosts, req->data, NULL); + + release_dns_child(req); +} +/* + * End the functions for dealing with the DNS child processes. + */ + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + DnsqueryResolverprocess *req = NULL; + dns_params_t dns_params; + gchar *host_temp; + gboolean show_debug; + + show_debug = gaim_debug_is_enabled(); + + host_temp = g_strstrip(g_strdup(hostname)); + strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); + g_free(host_temp); + dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; + dns_params.port = port; + + /* + * If we have any children, attempt to have them perform the DNS + * query. If we're able to send the query to a child, then req + * will be set to the DnsqueryResolverprocess. Otherwise, req will + * be NULL and we'll need to create a new DNS request child. + */ + while (free_dns_children != NULL) + { + req = free_dns_children->data; + free_dns_children = g_slist_remove(free_dns_children, req); + + if (send_dns_request_to_child(req, &dns_params) == 0) + /* We found an acceptable child, yay */ + break; + + req_free(req); + req = NULL; + } + + /* We need to create a new DNS request child */ + if (req == NULL) + { + if (number_of_dns_children >= MAX_DNS_CHILDREN) + { + queued_dns_request_t *r = g_new(queued_dns_request_t, 1); + memcpy(&(r->params), &dns_params, sizeof(dns_params)); + r->callback = callback; + r->data = data; + if (!queued_requests) + queued_requests = g_queue_new(); + g_queue_push_tail(queued_requests, r); + + gaim_debug_info("dnsquery", + "DNS query for '%s' queued\n", dns_params.hostname); + + return query_data; + } + + req = gaim_dns_new_resolverprocess(show_debug); + if (req == NULL) + { + gaim_debug_error("dnsquery", "oh dear, this is going to explode, I give up\n"); + return NULL; + } + send_dns_request_to_child(req, &dns_params); + } + + req->host = g_strdup(hostname); + req->port = port; + req->callback = callback; + req->data = data; + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + + return query_data; +} + +#elif defined _WIN32 /* end __unix__ || __APPLE__ */ + +typedef struct _dns_tdata { + char *hostname; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + GSList *hosts; + char *errmsg; +} dns_tdata; + +static gboolean dns_main_thread_cb(gpointer data) +{ + dns_tdata *td = (dns_tdata*)data; + if (td->errmsg != NULL) { + gaim_debug_info("dnsquery", "%s\n", td->errmsg); + } + td->callback(td->hosts, td->data, td->errmsg); + g_free(td->hostname); + g_free(td->errmsg); + g_free(td); + return FALSE; +} + +static gpointer +dns_thread(gpointer data) +{ + +#ifdef HAVE_GETADDRINFO + int rc; + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + struct hostent *hp; +#endif + dns_tdata *td = (dns_tdata*)data; + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", td->port); + memset(&hints, 0, sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(td->hostname, servname, &hints, &res); + if (rc == 0) + { + tmp = res; + while(res) { + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(res->ai_addrlen)); + td->hosts = g_slist_append(td->hosts, + g_memdup(res->ai_addr, res->ai_addrlen)); + res = res->ai_next; + } + freeaddrinfo(tmp); + } + else + { + td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); + } +#else + hp = gethostbyname(td->hostname); + if (hp != NULL) + { + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + sin.sin_port = htons(td->port); + + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(sizeof(sin))); + td->hosts = g_slist_append(td->hosts, + g_memdup(&sin, sizeof(sin))); + } else { + td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); + } +#endif + /* back to main thread */ + g_idle_add(dns_main_thread_cb, td); + + return 0; +} + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + dns_tdata *td; + struct sockaddr_in sin; + GError* err = NULL; + + if (inet_aton(hostname, &sin.sin_addr)) + { + GSList *hosts = NULL; + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); + hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); + callback(hosts, data, NULL); + return query_data; + } + + gaim_debug_info("dnsquery", "DNS Lookup for: %s\n", hostname); + td = g_new0(dns_tdata, 1); + td->hostname = g_strdup(hostname); + td->port = port; + td->callback = callback; + td->data = data; + + if (!g_thread_create(dns_thread, td, FALSE, &err)) + { + gaim_debug_error("dnsquery", "DNS thread create failure: %s\n", err?err->message:""); + g_error_free(err); + g_free(td->hostname); + g_free(td); + return NULL; + } + + return query_data; +} + +#else /* not __unix__ or __APPLE__ or _WIN32 */ + +typedef struct { + gpointer data; + size_t addrlen; + struct sockaddr *addr; + GaimProxyDnsConnectFunction callback; +} DnsqueryResolverprocess; + +static gboolean host_resolved(gpointer data) +{ + DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; + GSList *hosts = NULL; + hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); + hosts = g_slist_append(hosts, req->addr); + req->callback(hosts, req->data, NULL); + g_free(req); + return FALSE; +} + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + struct sockaddr_in sin; + DnsqueryResolverprocess *req; + + if (!inet_aton(hostname, &sin.sin_addr)) + { + struct hostent *hp; + hp = gethostbyname(hostname); + if (hp == NULL) + { + gaim_debug_error("dnsquery", + "gaim_gethostbyname(\"%s\", %d) failed: %d\n", + hostname, port, h_errno); + return NULL; + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + req = g_new(DnsqueryResolverprocess, 1); + req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); + req->addrlen = sizeof(sin); + req->data = data; + req->callback = callback; + gaim_timeout_add(10, host_resolved, req); + + return query_data; +} + +#endif /* not __unix__ or __APPLE__ or _WIN32 */ + +void +gaim_dnsquery_destroy(GaimDnsqueryData *query_data) +{ + g_free(query_data); +} Copied: branches/v2_0_0/src/dnsquery.h (from rev 16811, trunk/src/dnsquery.h) =================================================================== --- branches/v2_0_0/src/dnsquery.h (rev 0) +++ branches/v2_0_0/src/dnsquery.h 2006-08-17 08:41:44 UTC (rev 16812) @@ -0,0 +1,76 @@ +/** + * @file dnsquery.h DNS query API + * @ingroup core + * + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_DNSQUERY_H_ +#define _GAIM_DNSQUERY_H_ + +#include <glib.h> + +typedef struct _GaimDnsqueryData GaimDnsqueryData; + +/** + * The "hosts" parameter is a linked list containing pairs of + * one size_t addrlen and one struct sockaddr *addr. + */ +typedef void (*GaimDnsqueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message); + + +#ifdef __cplusplus +extern "C" { +#endif + +/**************************************************************************/ +/** @name DNS query API */ +/**************************************************************************/ +/*@{*/ + +/** + * Do an asynchronous DNS query. + * + * @param hostname The hostname to resolve + * @param port A portnumber which is stored in the struct sockaddr + * @param callback Callback to call after resolving + * @param data Extra data for the callback function + * + * @return NULL if there was an error, or a reference to a data + * structure that can be used to cancel the pending + * connection, if needed. + */ +GaimDnsqueryData *gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data); + +/** + * Cancel a DNS query. + * + * @param query_data A pointer to the DNS query data that you want + * to cancel. + */ +void gaim_dnsquery_destroy(GaimDnsqueryData *query_data); + +/*@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _GAIM_DNSQUERY_H_ */ Modified: branches/v2_0_0/src/gtkconv.c =================================================================== --- branches/v2_0_0/src/gtkconv.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/gtkconv.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -1360,29 +1360,6 @@ } static void -chat_im_button_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) -{ - GaimGtkChatPane *gtkchat; - GtkTreeIter iter; - GtkTreeModel *model; - GtkTreeSelection *sel; - char *name; - - gtkchat = gtkconv->u.chat; - - model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); - - if (gtk_tree_selection_get_selected(sel, NULL, &iter)) - gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &name, -1); - else - return; - - chat_do_im(gtkconv, name); - g_free(name); -} - -static void ignore_cb(GtkWidget *w, GaimGtkConversation *gtkconv) { GaimConversation *conv = gtkconv->active_conv; Modified: branches/v2_0_0/src/protocols/irc/irc.c =================================================================== --- branches/v2_0_0/src/protocols/irc/irc.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/protocols/irc/irc.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -450,7 +450,7 @@ g_free(irc->inbuf); if (irc->gsc) { gaim_ssl_close(irc->gsc); - } else if (irc->fd > 0) { + } else if (irc->fd >= 0) { close(irc->fd); } if (irc->timer) Modified: branches/v2_0_0/src/protocols/simple/simple.c =================================================================== --- branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -30,6 +30,7 @@ #include "blist.h" #include "conversation.h" #include "debug.h" +#include "dnsquery.h" #include "notify.h" #include "privacy.h" #include "prpl.h" @@ -1621,7 +1622,7 @@ } else { /* UDP */ gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); - gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); + gaim_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); } } Modified: branches/v2_0_0/src/proxy.c =================================================================== --- branches/v2_0_0/src/proxy.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/proxy.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -31,6 +31,7 @@ #include "internal.h" #include "cipher.h" +#include "dnsquery.h" #include "debug.h" #include "notify.h" #include "ntlm.h" @@ -46,6 +47,7 @@ int fd; guint inpa; GaimProxyInfo *gpi; + GaimDnsqueryData *query_data; /** * This contains alternating length/char* values. The char* @@ -307,6 +309,11 @@ connect_infos = g_slist_remove(connect_infos, connect_info); + /* + if (connect_info->query_data != NULL) + gaim_dnsquery_destroy(connect_info->query_data); + */ + while (connect_info->hosts != NULL) { /* Discard the length... */ @@ -351,681 +358,7 @@ gaim_proxy_connect_info_destroy(connect_info); } -#if defined(__unix__) || defined(__APPLE__) - -/* - * This structure represents both a pending DNS request and - * a free child process. - */ -typedef struct { - char *host; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - guint inpa; - int fd_in, fd_out; - pid_t dns_pid; -} pending_dns_request_t; - -static GSList *free_dns_children = NULL; -static GQueue *queued_requests = NULL; - -static int number_of_dns_children = 0; - -static const int MAX_DNS_CHILDREN = 2; - -typedef struct { - char hostname[512]; - int port; -} dns_params_t; - -typedef struct { - dns_params_t params; - GaimProxyDnsConnectFunction callback; - gpointer data; -} queued_dns_request_t; - -/* - * Begin the DNS resolver child process functions. - */ -#ifdef HAVE_SIGNAL_H static void -trap_gdb_bug() -{ - const char *message = - "Gaim's DNS child got a SIGTRAP signal.\n" - "This can be caused by trying to run gaim inside gdb.\n" - "There is a known gdb bug which prevents this. Supposedly gaim\n" - "should have detected you were using gdb and used an ugly hack,\n" - "check cope_with_gdb_brokenness() in proxy.c.\n\n" - "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; - fputs("\n* * *\n",stderr); - fputs(message,stderr); - fputs("* * *\n\n",stderr); - execlp("xmessage","xmessage","-center", message, NULL); - _exit(1); -} -#endif - -static void -cope_with_gdb_brokenness() -{ -#ifdef __linux__ - static gboolean already_done = FALSE; - char s[256], e[512]; - int n; - pid_t ppid; - - if(already_done) - return; - already_done = TRUE; - ppid = getppid(); - snprintf(s, sizeof(s), "/proc/%d/exe", ppid); - n = readlink(s, e, sizeof(e)); - if(n < 0) - return; - - e[MIN(n,sizeof(e)-1)] = '\0'; - - if(strstr(e,"gdb")) { - gaim_debug_info("dns", - "Debugger detected, performing useless query...\n"); - gethostbyname("x.x.x.x.x"); - } -#endif -} - -static void -gaim_dns_resolverthread(int child_out, int child_in, gboolean show_debug) -{ - dns_params_t dns_params; - const size_t zero = 0; - int rc; -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - const size_t addrlen = sizeof(sin); -#endif - -#ifdef HAVE_SIGNAL_H - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGTRAP, trap_gdb_bug); -#endif - - /* - * We resolve 1 host name for each iteration of this - * while loop. - * - * The top half of this reads in the hostname and port - * number from the socket with our parent. The bottom - * half of this resolves the IP (blocking) and sends - * the result back to our parent, when finished. - */ - while (1) { - const char ch = 'Y'; - fd_set fds; - struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; - FD_ZERO(&fds); - FD_SET(child_in, &fds); - rc = select(child_in + 1, &fds, NULL, NULL, &tv); - if (!rc) { - if (show_debug) - printf("dns[%d]: nobody needs me... =(\n", getpid()); - break; - } - rc = read(child_in, &dns_params, sizeof(dns_params_t)); - if (rc < 0) { - perror("read()"); - break; - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); - _exit(0); - } - if (dns_params.hostname[0] == '\0') { - printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); - _exit(1); - } - /* Tell our parent that we read the data successfully */ - write(child_out, &ch, sizeof(ch)); - - /* We have the hostname and port, now resolve the IP */ - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", dns_params.port); - memset(&hints, 0, sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); - write(child_out, &rc, sizeof(rc)); - if (rc != 0) { - close(child_out); - if (show_debug) - printf("dns[%d] Error: getaddrinfo returned %d\n", - getpid(), rc); - dns_params.hostname[0] = '\0'; - continue; - } - tmp = res; - while (res) { - size_t ai_addrlen = res->ai_addrlen; - write(child_out, &ai_addrlen, sizeof(ai_addrlen)); - write(child_out, res->ai_addr, res->ai_addrlen); - res = res->ai_next; - } - freeaddrinfo(tmp); - write(child_out, &zero, sizeof(zero)); -#else - if (!inet_aton(dns_params.hostname, &sin.sin_addr)) { - struct hostent *hp; - if (!(hp = gethostbyname(dns_params.hostname))) { - write(child_out, &h_errno, sizeof(int)); - close(child_out); - if (show_debug) - printf("DNS Error: %d\n", h_errno); - _exit(0); - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - - sin.sin_port = htons(dns_params.port); - write(child_out, &addrlen, sizeof(addrlen)); - write(child_out, &sin, addrlen); - write(child_out, &zero, sizeof(zero)); -#endif - dns_params.hostname[0] = '\0'; - } - - close(child_out); - close(child_in); - - _exit(0); -} - -static pending_dns_request_t * -gaim_dns_new_resolverthread(gboolean show_debug) -{ - pending_dns_request_t *req; - int child_out[2], child_in[2]; - - /* Create pipes for communicating with the child process */ - if (pipe(child_out) || pipe(child_in)) { - gaim_debug_error("dns", - "Could not create pipes: %s\n", strerror(errno)); - return NULL; - } - - req = g_new(pending_dns_request_t, 1); - - cope_with_gdb_brokenness(); - - /* Fork! */ - req->dns_pid = fork(); - - /* If we are the child process... */ - if (req->dns_pid == 0) { - /* We should not access the parent's side of the pipes, so close them */ - close(child_out[0]); - close(child_in[1]); - - gaim_dns_resolverthread(child_out[1], child_in[0], show_debug); - /* The thread calls _exit() rather than returning, so we never get here */ - } - - /* We should not access the child's side of the pipes, so close them */ - close(child_out[1]); - close(child_in[0]); - if (req->dns_pid == -1) { - gaim_debug_error("dns", - "Could not create child process for DNS: %s\n", - strerror(errno)); - g_free(req); - return NULL; - } - - req->fd_out = child_out[0]; - req->fd_in = child_in[1]; - number_of_dns_children++; - gaim_debug_info("dns", - "Created new DNS child %d, there are now %d children.\n", - req->dns_pid, number_of_dns_children); - - return req; -} -/* - * End the DNS resolver child process functions. - */ - -/* - * Begin the functions for dealing with the DNS child processes. - */ -static void -req_free(pending_dns_request_t *req) -{ - g_return_if_fail(req != NULL); - - close(req->fd_in); - close(req->fd_out); - - g_free(req->host); - g_free(req); - - number_of_dns_children--; -} - -static int -send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params) -{ - char ch; - int rc; - pid_t pid; - - /* This waitpid might return the child's PID if it has recently - * exited, or it might return an error if it exited "long - * enough" ago that it has already been reaped; in either - * instance, we can't use it. */ - if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { - gaim_debug_warning("dns", - "DNS child %d no longer exists\n", req->dns_pid); - return -1; - } else if (pid < 0) { - gaim_debug_warning("dns", - "Wait for DNS child %d failed: %s\n", - req->dns_pid, strerror(errno)); - return -1; - } - - /* Let's contact this lost child! */ - rc = write(req->fd_in, dns_params, sizeof(*dns_params)); - if (rc < 0) { - gaim_debug_error("dns", - "Unable to write to DNS child %d: %d\n", - req->dns_pid, strerror(errno)); - close(req->fd_in); - return -1; - } - - g_return_val_if_fail(rc == sizeof(*dns_params), -1); - - /* Did you hear me? (This avoids some race conditions) */ - rc = read(req->fd_out, &ch, sizeof(ch)); - if (rc != 1 || ch != 'Y') - { - gaim_debug_warning("dns", - "DNS child %d not responding. Killing it!\n", - req->dns_pid); - kill(req->dns_pid, SIGKILL); - return -1; - } - - gaim_debug_info("dns", - "Successfully sent DNS request to child %d\n", req->dns_pid); - - return 0; -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond); - -static void -release_dns_child(pending_dns_request_t *req) -{ - g_free(req->host); - req->host = NULL; - - if (queued_requests && !g_queue_is_empty(queued_requests)) { - queued_dns_request_t *r = g_queue_pop_head(queued_requests); - req->host = g_strdup(r->params.hostname); - req->port = r->params.port; - req->callback = r->callback; - req->data = r->data; - - gaim_debug_info("dns", - "Processing queued DNS query for '%s' with child %d\n", - req->host, req->dns_pid); - - if (send_dns_request_to_child(req, &(r->params)) != 0) { - req_free(req); - req = NULL; - - gaim_debug_warning("dns", - "Intent of process queued query of '%s' failed, " - "requeueing...\n", r->params.hostname); - g_queue_push_head(queued_requests, r); - } else { - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - g_free(r); - } - - } else { - req->host = NULL; - req->callback = NULL; - req->data = NULL; - free_dns_children = g_slist_append(free_dns_children, req); - } -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond) -{ - pending_dns_request_t *req = (pending_dns_request_t*)data; - int rc, err; - GSList *hosts = NULL; - struct sockaddr *addr = NULL; - size_t addrlen; - - gaim_debug_info("dns", "Got response for '%s'\n", req->host); - gaim_input_remove(req->inpa); - - rc = read(req->fd_out, &err, sizeof(err)); - if ((rc == 4) && (err != 0)) - { - char message[1024]; -#ifdef HAVE_GETADDRINFO - g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)", - gai_strerror(err), req->dns_pid); -#else - g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", - err, req->dns_pid); -#endif - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - release_dns_child(req); - return; - } - if (rc > 0) - { - while (rc > 0) { - rc = read(req->fd_out, &addrlen, sizeof(addrlen)); - if (rc > 0 && addrlen > 0) { - addr = g_malloc(addrlen); - rc = read(req->fd_out, addr, addrlen); - hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); - hosts = g_slist_append(hosts, addr); - } else { - break; - } - } - } else if (rc == -1) { - char message[1024]; - g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - req_free(req); - return; - } else if (rc == 0) { - char message[1024]; - g_snprintf(message, sizeof(message), "EOF reading from DNS child"); - close(req->fd_out); - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - req_free(req); - return; - } - -/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ - - req->callback(hosts, req->data, NULL); - - release_dns_child(req); -} -/* - * End the functions for dealing with the DNS child processes. - */ - -int -gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) -{ - pending_dns_request_t *req = NULL; - dns_params_t dns_params; - gchar *host_temp; - gboolean show_debug; - - show_debug = gaim_debug_is_enabled(); - - host_temp = g_strstrip(g_strdup(hostname)); - strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); - g_free(host_temp); - dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; - dns_params.port = port; - - /* - * If we have any children, attempt to have them perform the DNS - * query. If we're able to send the query to a child, then req - * will be set to the pending_dns_request_t. Otherwise, req will - * be NULL and we'll need to create a new DNS request child. - */ - while (free_dns_children != NULL) { - req = free_dns_children->data; - free_dns_children = g_slist_remove(free_dns_children, req); - - if (send_dns_request_to_child(req, &dns_params) == 0) - /* We found an acceptable child, yay */ - break; - - req_free(req); - req = NULL; - } - - /* We need to create a new DNS request child */ - if (req == NULL) { - if (number_of_dns_children >= MAX_DNS_CHILDREN) { - queued_dns_request_t *r = g_new(queued_dns_request_t, 1); - memcpy(&(r->params), &dns_params, sizeof(dns_params)); - r->callback = callback; - r->data = data; - if (!queued_requests) - queued_requests = g_queue_new(); - g_queue_push_tail(queued_requests, r); - - gaim_debug_info("dns", - "DNS query for '%s' queued\n", dns_params.hostname); - - return 0; - } - - req = gaim_dns_new_resolverthread(show_debug); - if (req == NULL) - { - gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); - return -1; - } - send_dns_request_to_child(req, &dns_params); - } - - req->host = g_strdup(hostname); - req->port = port; - req->callback = callback; - req->data = data; - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - - return 0; -} - -#elif defined _WIN32 /* end __unix__ || __APPLE__ */ - -typedef struct _dns_tdata { - char *hostname; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - GSList *hosts; - char *errmsg; -} dns_tdata; - -static gboolean dns_main_thread_cb(gpointer data) { - dns_tdata *td = (dns_tdata*)data; - if (td->errmsg != NULL) { - gaim_debug_info("dns", "%s\n", td->errmsg); - } - td->callback(td->hosts, td->data, td->errmsg); - g_free(td->hostname); - g_free(td->errmsg); - g_free(td); - return FALSE; -} - -static gpointer dns_thread(gpointer data) { - -#ifdef HAVE_GETADDRINFO - int rc; - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - struct hostent *hp; -#endif - dns_tdata *td = (dns_tdata*)data; - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", td->port); - memset(&hints,0,sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) { - tmp = res; - while(res) { - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(res->ai_addrlen)); - td->hosts = g_slist_append(td->hosts, - g_memdup(res->ai_addr, res->ai_addrlen)); - res = res->ai_next; - } - freeaddrinfo(tmp); - } else { - td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); - } -#else - if ((hp = gethostbyname(td->hostname))) { - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(td->port); - - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(sizeof(sin))); - td->hosts = g_slist_append(td->hosts, - g_memdup(&sin, sizeof(sin))); - } else { - td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); - } -#endif - /* back to main thread */ - g_idle_add(dns_main_thread_cb, td); - return 0; -} - -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - dns_tdata *td; - struct sockaddr_in sin; - GError* err = NULL; - - if(inet_aton(hostname, &sin.sin_addr)) { - GSList *hosts = NULL; - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); - hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); - callback(hosts, data, NULL); - return 0; - } - - gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); - td = g_new0(dns_tdata, 1); - td->hostname = g_strdup(hostname); - td->port = port; - td->callback = callback; - td->data = data; - - if(!g_thread_create(dns_thread, td, FALSE, &err)) { - gaim_debug_error("dns", "DNS thread create failure: %s\n", err?err->message:""); - g_error_free(err); - g_free(td->hostname); - g_free(td); - return -1; - } - return 0; -} - -#else /* not __unix__ or __APPLE__ or _WIN32 */ - -typedef struct { - gpointer data; - size_t addrlen; - struct sockaddr *addr; - GaimProxyDnsConnectFunction callback; -} pending_dns_request_t; - -static gboolean host_resolved(gpointer data) -{ - pending_dns_request_t *req = (pending_dns_request_t*)data; - GSList *hosts = NULL; - hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); - hosts = g_slist_append(hosts, req->addr); - req->callback(hosts, req->data, NULL); - g_free(req); - return FALSE; -} - -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - struct sockaddr_in sin; - pending_dns_request_t *req; - - if (!inet_aton(hostname, &sin.sin_addr)) { - struct hostent *hp; - if(!(hp = gethostbyname(hostname))) { - gaim_debug_error("dns", - "gaim_gethostbyname(\"%s\", %d) failed: %d\n", - hostname, port, h_errno); - return -1; - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - - req = g_new(pending_dns_request_t, 1); - req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); - req->addrlen = sizeof(sin); - req->data = data; - req->callback = callback; - gaim_timeout_add(10, host_resolved, req); - return 0; -} - -#endif /* not __unix__ or __APPLE__ or _WIN32 */ - -static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) { GaimProxyConnectInfo *connect_info = data; @@ -2368,8 +1701,9 @@ return NULL; } - if (gaim_gethostbyname_async(connecthost, - connectport, connection_host_resolved, connect_info) != 0) + connect_info->query_data = gaim_dnsquery_a(connecthost, + connectport, connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; @@ -2401,8 +1735,9 @@ connect_info->port = port; connect_info->gpi = gpi; - if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), - gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) + connect_info->query_data = gaim_dnsquery_a(gaim_proxy_info_get_host(gpi), + gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; Modified: branches/v2_0_0/src/proxy.h =================================================================== --- branches/v2_0_0/src/proxy.h 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/proxy.h 2006-08-17 08:41:44 UTC (rev 16812) @@ -26,6 +26,7 @@ #define _GAIM_PROXY_H_ #include <glib.h> +#include "dnsquery.h" #include "eventloop.h" /** @@ -56,6 +57,7 @@ } GaimProxyInfo; +typedef struct _GaimDnsQueryData GaimDnsQueryData; typedef struct _GaimProxyConnectInfo GaimProxyConnectInfo; typedef void (*GaimProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); @@ -278,18 +280,6 @@ */ void gaim_proxy_connect_cancel(GaimProxyConnectInfo *connect_info); -/** - * Do an async dns query - * - * @param hostname The hostname to resolve - * @param port A portnumber which is stored in the struct sockaddr - * @param callback Callback to call after resolving - * @param data Extra data for the callback function - * - * @return Zero indicates the connection is pending. Any other value indicates failure. - */ -int gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data); - /*@}*/ #ifdef __cplusplus Modified: branches/v2_0_0/src/prpl.c =================================================================== --- branches/v2_0_0/src/prpl.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/prpl.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -171,6 +171,12 @@ return; } + if (!gaim_status_is_online(new_status)) + { + if (!gaim_account_is_disconnected(account)) + gaim_account_disconnect(account); + return; + } if (gaim_account_is_connecting(account)) /* @@ -191,13 +197,6 @@ { prpl_info->set_status(account, new_status); } - - if (!gaim_status_is_online(new_status)) - { - if (!gaim_account_is_disconnected(account)) - gaim_account_disconnect(account); - return; - } } void Modified: branches/v2_0_0/src/sslconn.c =================================================================== --- branches/v2_0_0/src/sslconn.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/sslconn.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -45,10 +45,14 @@ gaim_plugin_load(plugin); ops = gaim_ssl_get_ops(); - if (ops != NULL && ops->init != NULL) - return ops->init(); - else + if ((ops == NULL) || (ops->init == NULL) || (ops->uninit == NULL) || + (ops->connect == NULL) || (ops->close == NULL) || + (ops->read == NULL) || (ops->write == NULL)) + { return FALSE; + } + + return ops->init(); } gboolean @@ -62,25 +66,42 @@ #endif } +static void +gaim_ssl_connect_cb(gpointer data, gint source, const gchar *error_message) +{ + GaimSslConnection *gsc; + GaimSslOps *ops; + + gsc = data; + gsc->connect_info = NULL; + + if (source < 0) + { + if (gsc->error_cb != NULL) + gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); + + gaim_ssl_close(gsc); + return; + } + + gsc->fd = source; + + ops = gaim_ssl_get_ops(); + ops->connect(gsc); +} + GaimSslConnection * gaim_ssl_connect(GaimAccount *account, const char *host, int port, GaimSslInputFunction func, GaimSslErrorFunction error_func, void *data) { GaimSslConnection *gsc; - GaimSslOps *ops; - GaimProxyConnectInfo *connect_info; g_return_val_if_fail(host != NULL, NULL); g_return_val_if_fail(port != 0 && port != -1, NULL); g_return_val_if_fail(func != NULL, NULL); g_return_val_if_fail(gaim_ssl_is_supported(), NULL); - ops = gaim_ssl_get_ops(); - - g_return_val_if_fail(ops != NULL, NULL); - g_return_val_if_fail(ops->connect_cb != NULL, NULL); - if (!_ssl_initialized) { if (!ssl_init()) @@ -89,15 +110,16 @@ gsc = g_new0(GaimSslConnection, 1); + gsc->fd = -1; gsc->host = g_strdup(host); gsc->port = port; gsc->connect_cb_data = data; gsc->connect_cb = func; gsc->error_cb = error_func; - connect_info = gaim_proxy_connect(account, host, port, ops->connect_cb, gsc); + gsc->connect_info = gaim_proxy_connect(account, host, port, gaim_ssl_connect_cb, gsc); - if (connect_info == NULL) + if (gsc->connect_info == NULL) { g_free(gsc->host); g_free(gsc); @@ -141,11 +163,6 @@ g_return_val_if_fail(func != NULL, NULL); g_return_val_if_fail(gaim_ssl_is_supported(), NULL); - ops = gaim_ssl_get_ops(); - - g_return_val_if_fail(ops != NULL, NULL); - g_return_val_if_fail(ops->connect_cb != NULL, NULL); - if (!_ssl_initialized) { if (!ssl_init()) @@ -157,8 +174,10 @@ gsc->connect_cb_data = data; gsc->connect_cb = func; gsc->error_cb = error_func; + gsc->fd = fd; - ops->connect_cb(gsc, fd, GAIM_INPUT_READ); + ops = gaim_ssl_get_ops(); + ops->connect(gsc); return (GaimSslConnection *)gsc; } @@ -171,14 +190,15 @@ g_return_if_fail(gsc != NULL); ops = gaim_ssl_get_ops(); + (ops->close)(gsc); - if (gsc->inpa) + if (gsc->connect_info != NULL) + gaim_proxy_connect_cancel(gsc->connect_info); + + if (gsc->inpa > 0) gaim_input_remove(gsc->inpa); - if (ops != NULL && ops->close != NULL) - (ops->close)(gsc); - - if (gsc->fd != -1) + if (gsc->fd >= 0) close(gsc->fd); g_free(gsc->host); @@ -195,11 +215,7 @@ g_return_val_if_fail(len > 0, 0); ops = gaim_ssl_get_ops(); - - if (ops != NULL && (ops->read) != NULL) - return (ops->read)(gsc, data, len); - - return 0; + return (ops->read)(gsc, data, len); } size_t @@ -212,11 +228,7 @@ g_return_val_if_fail(len > 0, 0); ops = gaim_ssl_get_ops(); - - if (ops != NULL && (ops->write) != NULL) - return (ops->write)(gsc, data, len); - - return 0; + return (ops->write)(gsc, data, len); } void @@ -245,9 +257,7 @@ return; ops = gaim_ssl_get_ops(); + ops->uninit(); - if (ops != NULL && ops->uninit != NULL) - ops->uninit(); - _ssl_initialized = FALSE; } Modified: branches/v2_0_0/src/sslconn.h =================================================================== --- branches/v2_0_0/src/sslconn.h 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/sslconn.h 2006-08-17 08:41:44 UTC (rev 16812) @@ -54,6 +54,7 @@ int fd; int inpa; + GaimProxyConnectInfo *connect_info; void *private_data; }; @@ -61,13 +62,13 @@ /** * SSL implementation operations structure. * - * Every SSL implementation must provide one of these and register it. + * Every SSL implementation must provide all of these and register it. */ typedef struct { gboolean (*init)(void); void (*uninit)(void); - GaimInputFunction connect_cb; + void (*connect)(GaimSslConnection *gsc); void (*close)(GaimSslConnection *gsc); size_t (*read)(GaimSslConnection *gsc, void *data, size_t len); size_t (*write)(GaimSslConnection *gsc, const void *data, size_t len); Modified: branches/v2_0_0/src/stun.c =================================================================== --- branches/v2_0_0/src/stun.c 2006-08-17 07:44:52 UTC (rev 16811) +++ branches/v2_0_0/src/stun.c 2006-08-17 08:41:44 UTC (rev 16812) @@ -40,6 +40,7 @@ #include "debug.h" #include "account.h" +#include "dnsquery.h" #include "dnssrv.h" #include "network.h" #include "proxy.h" @@ -359,7 +360,7 @@ gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); - gaim_gethostbyname_async(servername, port, hbn_cb, NULL); + gaim_dnsquery_a(servername, port, hbn_cb, NULL); g_free(resp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 07:45:07
|
Revision: 16811 Author: thekingant Date: 2006-08-17 00:44:52 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16811&view=rev Log Message: ----------- Split the DNS query stuff out into it's own file. Eventually we should move the dnssrv code into this same file. Maybe even share some code? Also the first steps toward cancelable DNS queries. Modified Paths: -------------- trunk/src/Makefile.am trunk/src/Makefile.mingw trunk/src/protocols/simple/simple.c trunk/src/proxy.c trunk/src/proxy.h trunk/src/stun.c Added Paths: ----------- trunk/src/dnsquery.c trunk/src/dnsquery.h Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/Makefile.am 2006-08-17 07:44:52 UTC (rev 16811) @@ -77,6 +77,7 @@ core.c \ debug.c \ desktopitem.c \ + dnsquery.c \ eventloop.c \ ft.c \ idle.c \ @@ -125,6 +126,7 @@ dbus-maybe.h \ debug.h \ desktopitem.h \ + dnsquery.h \ eventloop.h \ ft.h \ idle.h \ Modified: trunk/src/Makefile.mingw =================================================================== --- trunk/src/Makefile.mingw 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/Makefile.mingw 2006-08-17 07:44:52 UTC (rev 16811) @@ -95,6 +95,7 @@ conversation.c \ core.c \ debug.c \ + dnsquery.c \ dnssrv.c \ eventloop.c \ ft.c \ Added: trunk/src/dnsquery.c =================================================================== --- trunk/src/dnsquery.c (rev 0) +++ trunk/src/dnsquery.c 2006-08-17 07:44:52 UTC (rev 16811) @@ -0,0 +1,774 @@ +/** + * @file dnsquery.c DNS query API + * @ingroup core + * + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "internal.h" +#include "debug.h" +#include "ntlm.h" +#include "util.h" + +struct _GaimDnsqueryData { +}; + +/************************************************************************** + * Global DNS query API + **************************************************************************/ + +#if defined(__unix__) || defined(__APPLE__) + +/* + * This structure represents both a pending DNS request and + * a free child process. + */ +typedef struct _DnsqueryResolverprocess DnsqueryResolverprocess; +struct _DnsqueryResolverprocess { + char *host; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + guint inpa; + int fd_in, fd_out; + pid_t dns_pid; +}; + +//static GSList *all_dns_children = NULL; +static GSList *free_dns_children = NULL; +static GQueue *queued_requests = NULL; + +static int number_of_dns_children = 0; + +static const int MAX_DNS_CHILDREN = 2; + +typedef struct { + char hostname[512]; + int port; +} dns_params_t; + +typedef struct { + dns_params_t params; + GaimProxyDnsConnectFunction callback; + gpointer data; +} queued_dns_request_t; + +/* + * Begin the DNS resolver child process functions. + */ +#ifdef HAVE_SIGNAL_H +static void +trap_gdb_bug() +{ + const char *message = + "Gaim's DNS child got a SIGTRAP signal.\n" + "This can be caused by trying to run gaim inside gdb.\n" + "There is a known gdb bug which prevents this. Supposedly gaim\n" + "should have detected you were using gdb and used an ugly hack,\n" + "check cope_with_gdb_brokenness() in dnsquery.c.\n\n" + "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; + fputs("\n* * *\n",stderr); + fputs(message,stderr); + fputs("* * *\n\n",stderr); + execlp("xmessage","xmessage","-center", message, NULL); + _exit(1); +} +#endif + +static void +cope_with_gdb_brokenness() +{ +#ifdef __linux__ + static gboolean already_done = FALSE; + char s[256], e[512]; + int n; + pid_t ppid; + + if (already_done) + return; + + already_done = TRUE; + ppid = getppid(); + snprintf(s, sizeof(s), "/proc/%d/exe", ppid); + n = readlink(s, e, sizeof(e)); + if (n < 0) + return; + + e[MIN(n,sizeof(e)-1)] = '\0'; + + if (strstr(e,"gdb")) + { + gaim_debug_info("dnsquery", + "Debugger detected, performing useless query...\n"); + gethostbyname("x.x.x.x.x"); + } +#endif +} + +/** + * When doing DNS queries on Unix and OS-X, we fork off a separate + * process and communicate with it using pipes. This function is + * called shortly after the child is forked, and the function exits + * the process after it's no longer needed. + */ +static void +gaim_dns_resolverprocess(int child_out, int child_in, gboolean show_debug) +{ + dns_params_t dns_params; + const size_t zero = 0; + int rc; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + const size_t addrlen = sizeof(sin); +#endif + +#ifdef HAVE_SIGNAL_H + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGCHLD, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGTRAP, trap_gdb_bug); +#endif + + /* + * We resolve 1 host name for each iteration of this + * while loop. + * + * The top half of this reads in the hostname and port + * number from the socket with our parent. The bottom + * half of this resolves the IP (blocking) and sends + * the result back to our parent, when finished. + */ + while (1) + { + const char ch = 'Y'; + fd_set fds; + struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; + + FD_ZERO(&fds); + FD_SET(child_in, &fds); + rc = select(child_in + 1, &fds, NULL, NULL, &tv); + if (rc < 0) { + if (show_debug) + printf("dns[%d]: select failed\n", getpid()); + close(child_out); + close(child_in); + _exit(1); + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: nobody needs me... =(\n", getpid()); + break; + } + + rc = read(child_in, &dns_params, sizeof(dns_params_t)); + if (rc < 0) { + if (show_debug) + printf("dns[%d]: read failed\n", getpid()); + close(child_out); + close(child_in); + _exit(1); + } + if (rc == 0) { + if (show_debug) + printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); + break; + } + if (dns_params.hostname[0] == '\0') { + printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); + close(child_out); + close(child_in); + _exit(1); + } + /* Tell our parent that we read the data successfully */ + write(child_out, &ch, sizeof(ch)); + + /* We have the hostname and port, now resolve the IP */ + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", dns_params.port); + memset(&hints, 0, sizeof(hints)); + + /* + * This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); + write(child_out, &rc, sizeof(rc)); + if (rc != 0) { + close(child_out); + if (show_debug) + printf("dns[%d] Error: getaddrinfo returned %d\n", + getpid(), rc); + dns_params.hostname[0] = '\0'; + continue; + } + for (tmp = res; tmp != NULL; tmp = tmp->ai_next) + { + size_t ai_addrlen = tmp->ai_addrlen; + write(child_out, &ai_addrlen, sizeof(ai_addrlen)); + write(child_out, tmp->ai_addr, tmp->ai_addrlen); + } + freeaddrinfo(res); + write(child_out, &zero, sizeof(zero)); +#else + if (!inet_aton(dns_params.hostname, &sin.sin_addr)) + { + struct hostent *hp; + + hp = gethostbyname(dns_params.hostname); + if (hp == NULL) + { + if (show_debug) + printf("DNS Error: %d\n", h_errno); + write(child_out, &h_errno, sizeof(int)); + close(child_out); + close(child_in); + _exit(1); + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + + sin.sin_port = htons(dns_params.port); + write(child_out, &addrlen, sizeof(addrlen)); + write(child_out, &sin, addrlen); + write(child_out, &zero, sizeof(zero)); +#endif + dns_params.hostname[0] = '\0'; + } + + close(child_out); + close(child_in); + + _exit(0); +} + +static DnsqueryResolverprocess * +gaim_dns_new_resolverprocess(gboolean show_debug) +{ + DnsqueryResolverprocess *req; + int child_out[2], child_in[2]; + + /* Create pipes for communicating with the child process */ + if (pipe(child_out) || pipe(child_in)) { + gaim_debug_error("dnsquery", + "Could not create pipes: %s\n", strerror(errno)); + return NULL; + } + + req = g_new(DnsqueryResolverprocess, 1); + + cope_with_gdb_brokenness(); + + /* Fork! */ + req->dns_pid = fork(); + + /* If we are the child process... */ + if (req->dns_pid == 0) { + /* We should not access the parent's side of the pipes, so close them */ + close(child_out[0]); + close(child_in[1]); + + gaim_dns_resolverprocess(child_out[1], child_in[0], show_debug); + /* The thread calls _exit() rather than returning, so we never get here */ + } + + /* We should not access the child's side of the pipes, so close them */ + close(child_out[1]); + close(child_in[0]); + if (req->dns_pid == -1) { + gaim_debug_error("dnsquery", + "Could not create child process for DNS: %s\n", + strerror(errno)); + g_free(req); + return NULL; + } + + req->fd_out = child_out[0]; + req->fd_in = child_in[1]; + number_of_dns_children++; + gaim_debug_info("dnsquery", + "Created new DNS child %d, there are now %d children.\n", + req->dns_pid, number_of_dns_children); + + return req; +} +/* + * End the DNS resolver child process functions. + */ + +/* + * Begin the functions for dealing with the DNS child processes. + */ +static void +req_free(DnsqueryResolverprocess *req) +{ + g_return_if_fail(req != NULL); + + close(req->fd_in); + close(req->fd_out); + + g_free(req->host); + g_free(req); + + number_of_dns_children--; +} + +static int +send_dns_request_to_child(DnsqueryResolverprocess *req, dns_params_t *dns_params) +{ + char ch; + int rc; + pid_t pid; + + /* This waitpid might return the child's PID if it has recently + * exited, or it might return an error if it exited "long + * enough" ago that it has already been reaped; in either + * instance, we can't use it. */ + if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { + gaim_debug_warning("dnsquery", + "DNS child %d no longer exists\n", req->dns_pid); + return -1; + } else if (pid < 0) { + gaim_debug_warning("dnsquery", + "Wait for DNS child %d failed: %s\n", + req->dns_pid, strerror(errno)); + return -1; + } + + /* Let's contact this lost child! */ + rc = write(req->fd_in, dns_params, sizeof(*dns_params)); + if (rc < 0) { + gaim_debug_error("dnsquery", + "Unable to write to DNS child %d: %d\n", + req->dns_pid, strerror(errno)); + close(req->fd_in); + return -1; + } + + g_return_val_if_fail(rc == sizeof(*dns_params), -1); + + /* Did you hear me? (This avoids some race conditions) */ + rc = read(req->fd_out, &ch, sizeof(ch)); + if (rc != 1 || ch != 'Y') + { + gaim_debug_warning("dnsquery", + "DNS child %d not responding. Killing it!\n", + req->dns_pid); + kill(req->dns_pid, SIGKILL); + return -1; + } + + gaim_debug_info("dnsquery", + "Successfully sent DNS request to child %d\n", req->dns_pid); + + return 0; +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond); + +static void +release_dns_child(DnsqueryResolverprocess *req) +{ + g_free(req->host); + req->host = NULL; + + if (queued_requests && !g_queue_is_empty(queued_requests)) { + queued_dns_request_t *r = g_queue_pop_head(queued_requests); + req->host = g_strdup(r->params.hostname); + req->port = r->params.port; + req->callback = r->callback; + req->data = r->data; + + gaim_debug_info("dnsquery", + "Processing queued DNS query for '%s' with child %d\n", + req->host, req->dns_pid); + + if (send_dns_request_to_child(req, &(r->params)) != 0) { + req_free(req); + req = NULL; + + gaim_debug_warning("dnsquery", + "Intent of process queued query of '%s' failed, " + "requeueing...\n", r->params.hostname); + g_queue_push_head(queued_requests, r); + } else { + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + g_free(r); + } + + } else { + req->host = NULL; + req->callback = NULL; + req->data = NULL; + free_dns_children = g_slist_append(free_dns_children, req); + } +} + +static void +host_resolved(gpointer data, gint source, GaimInputCondition cond) +{ + DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; + int rc, err; + GSList *hosts = NULL; + struct sockaddr *addr = NULL; + size_t addrlen; + + gaim_debug_info("dnsquery", "Got response for '%s'\n", req->host); + gaim_input_remove(req->inpa); + + rc = read(req->fd_out, &err, sizeof(err)); + if ((rc == 4) && (err != 0)) + { + gchar *message; +#ifdef HAVE_GETADDRINFO + message = g_strdup_printf("DNS error: %s (pid=%d)", + gai_strerror(err), req->dns_pid); +#else + message = g_strdup_printf("DNS error: %d (pid=%d)", + err, req->dns_pid); +#endif + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + release_dns_child(req); + return; + } + + if (rc > 0) + { + while (rc > 0) { + rc = read(req->fd_out, &addrlen, sizeof(addrlen)); + if (rc > 0 && addrlen > 0) { + addr = g_malloc(addrlen); + rc = read(req->fd_out, addr, addrlen); + hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); + hosts = g_slist_append(hosts, addr); + } else { + break; + } + } + } else if (rc == -1) { + gchar *message; + message = g_strdup_printf("Error reading from DNS child: %s", strerror(errno)); + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + req_free(req); + return; + } else if (rc == 0) { + gchar *message; + close(req->fd_out); + message = g_strdup_printf("EOF reading from DNS child"); + gaim_debug_error("dnsquery", "%s\n", message); + req->callback(NULL, req->data, message); + g_free(message); + req_free(req); + return; + } + +/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ + + req->callback(hosts, req->data, NULL); + + release_dns_child(req); +} +/* + * End the functions for dealing with the DNS child processes. + */ + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + DnsqueryResolverprocess *req = NULL; + dns_params_t dns_params; + gchar *host_temp; + gboolean show_debug; + + show_debug = gaim_debug_is_enabled(); + + host_temp = g_strstrip(g_strdup(hostname)); + strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); + g_free(host_temp); + dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; + dns_params.port = port; + + /* + * If we have any children, attempt to have them perform the DNS + * query. If we're able to send the query to a child, then req + * will be set to the DnsqueryResolverprocess. Otherwise, req will + * be NULL and we'll need to create a new DNS request child. + */ + while (free_dns_children != NULL) + { + req = free_dns_children->data; + free_dns_children = g_slist_remove(free_dns_children, req); + + if (send_dns_request_to_child(req, &dns_params) == 0) + /* We found an acceptable child, yay */ + break; + + req_free(req); + req = NULL; + } + + /* We need to create a new DNS request child */ + if (req == NULL) + { + if (number_of_dns_children >= MAX_DNS_CHILDREN) + { + queued_dns_request_t *r = g_new(queued_dns_request_t, 1); + memcpy(&(r->params), &dns_params, sizeof(dns_params)); + r->callback = callback; + r->data = data; + if (!queued_requests) + queued_requests = g_queue_new(); + g_queue_push_tail(queued_requests, r); + + gaim_debug_info("dnsquery", + "DNS query for '%s' queued\n", dns_params.hostname); + + return query_data; + } + + req = gaim_dns_new_resolverprocess(show_debug); + if (req == NULL) + { + gaim_debug_error("dnsquery", "oh dear, this is going to explode, I give up\n"); + return NULL; + } + send_dns_request_to_child(req, &dns_params); + } + + req->host = g_strdup(hostname); + req->port = port; + req->callback = callback; + req->data = data; + req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); + + return query_data; +} + +#elif defined _WIN32 /* end __unix__ || __APPLE__ */ + +typedef struct _dns_tdata { + char *hostname; + int port; + GaimProxyDnsConnectFunction callback; + gpointer data; + GSList *hosts; + char *errmsg; +} dns_tdata; + +static gboolean dns_main_thread_cb(gpointer data) +{ + dns_tdata *td = (dns_tdata*)data; + if (td->errmsg != NULL) { + gaim_debug_info("dnsquery", "%s\n", td->errmsg); + } + td->callback(td->hosts, td->data, td->errmsg); + g_free(td->hostname); + g_free(td->errmsg); + g_free(td); + return FALSE; +} + +static gpointer +dns_thread(gpointer data) +{ + +#ifdef HAVE_GETADDRINFO + int rc; + struct addrinfo hints, *res, *tmp; + char servname[20]; +#else + struct sockaddr_in sin; + struct hostent *hp; +#endif + dns_tdata *td = (dns_tdata*)data; + +#ifdef HAVE_GETADDRINFO + g_snprintf(servname, sizeof(servname), "%d", td->port); + memset(&hints, 0, sizeof(hints)); + + /* This is only used to convert a service + * name to a port number. As we know we are + * passing a number already, we know this + * value will not be really used by the C + * library. + */ + hints.ai_socktype = SOCK_STREAM; + rc = getaddrinfo(td->hostname, servname, &hints, &res); + if (rc == 0) + { + tmp = res; + while(res) { + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(res->ai_addrlen)); + td->hosts = g_slist_append(td->hosts, + g_memdup(res->ai_addr, res->ai_addrlen)); + res = res->ai_next; + } + freeaddrinfo(tmp); + } + else + { + td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); + } +#else + hp = gethostbyname(td->hostname); + if (hp != NULL) + { + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + sin.sin_port = htons(td->port); + + td->hosts = g_slist_append(td->hosts, + GSIZE_TO_POINTER(sizeof(sin))); + td->hosts = g_slist_append(td->hosts, + g_memdup(&sin, sizeof(sin))); + } else { + td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); + } +#endif + /* back to main thread */ + g_idle_add(dns_main_thread_cb, td); + + return 0; +} + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + dns_tdata *td; + struct sockaddr_in sin; + GError* err = NULL; + + if (inet_aton(hostname, &sin.sin_addr)) + { + GSList *hosts = NULL; + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); + hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); + callback(hosts, data, NULL); + return query_data; + } + + gaim_debug_info("dnsquery", "DNS Lookup for: %s\n", hostname); + td = g_new0(dns_tdata, 1); + td->hostname = g_strdup(hostname); + td->port = port; + td->callback = callback; + td->data = data; + + if (!g_thread_create(dns_thread, td, FALSE, &err)) + { + gaim_debug_error("dnsquery", "DNS thread create failure: %s\n", err?err->message:""); + g_error_free(err); + g_free(td->hostname); + g_free(td); + return NULL; + } + + return query_data; +} + +#else /* not __unix__ or __APPLE__ or _WIN32 */ + +typedef struct { + gpointer data; + size_t addrlen; + struct sockaddr *addr; + GaimProxyDnsConnectFunction callback; +} DnsqueryResolverprocess; + +static gboolean host_resolved(gpointer data) +{ + DnsqueryResolverprocess *req = (DnsqueryResolverprocess*)data; + GSList *hosts = NULL; + hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); + hosts = g_slist_append(hosts, req->addr); + req->callback(hosts, req->data, NULL); + g_free(req); + return FALSE; +} + +GaimDnsqueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimProxyDnsConnectFunction callback, gpointer data) +{ + GaimDnsqueryData *query_data; + struct sockaddr_in sin; + DnsqueryResolverprocess *req; + + if (!inet_aton(hostname, &sin.sin_addr)) + { + struct hostent *hp; + hp = gethostbyname(hostname); + if (hp == NULL) + { + gaim_debug_error("dnsquery", + "gaim_gethostbyname(\"%s\", %d) failed: %d\n", + hostname, port, h_errno); + return NULL; + } + memset(&sin, 0, sizeof(struct sockaddr_in)); + memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } else + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + req = g_new(DnsqueryResolverprocess, 1); + req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); + req->addrlen = sizeof(sin); + req->data = data; + req->callback = callback; + gaim_timeout_add(10, host_resolved, req); + + return query_data; +} + +#endif /* not __unix__ or __APPLE__ or _WIN32 */ + +void +gaim_dnsquery_destroy(GaimDnsqueryData *query_data) +{ + g_free(query_data); +} Property changes on: trunk/src/dnsquery.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/src/dnsquery.h =================================================================== --- trunk/src/dnsquery.h (rev 0) +++ trunk/src/dnsquery.h 2006-08-17 07:44:52 UTC (rev 16811) @@ -0,0 +1,76 @@ +/** + * @file dnsquery.h DNS query API + * @ingroup core + * + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_DNSQUERY_H_ +#define _GAIM_DNSQUERY_H_ + +#include <glib.h> + +typedef struct _GaimDnsqueryData GaimDnsqueryData; + +/** + * The "hosts" parameter is a linked list containing pairs of + * one size_t addrlen and one struct sockaddr *addr. + */ +typedef void (*GaimDnsqueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message); + + +#ifdef __cplusplus +extern "C" { +#endif + +/**************************************************************************/ +/** @name DNS query API */ +/**************************************************************************/ +/*@{*/ + +/** + * Do an asynchronous DNS query. + * + * @param hostname The hostname to resolve + * @param port A portnumber which is stored in the struct sockaddr + * @param callback Callback to call after resolving + * @param data Extra data for the callback function + * + * @return NULL if there was an error, or a reference to a data + * structure that can be used to cancel the pending + * connection, if needed. + */ +GaimDnsqueryData *gaim_dnsquery_a(const char *hostname, int port, GaimDnsqueryConnectFunction callback, gpointer data); + +/** + * Cancel a DNS query. + * + * @param query_data A pointer to the DNS query data that you want + * to cancel. + */ +void gaim_dnsquery_destroy(GaimDnsqueryData *query_data); + +/*@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _GAIM_DNSQUERY_H_ */ Property changes on: trunk/src/dnsquery.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/src/protocols/simple/simple.c =================================================================== --- trunk/src/protocols/simple/simple.c 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/protocols/simple/simple.c 2006-08-17 07:44:52 UTC (rev 16811) @@ -30,6 +30,7 @@ #include "blist.h" #include "conversation.h" #include "debug.h" +#include "dnsquery.h" #include "notify.h" #include "privacy.h" #include "prpl.h" @@ -1621,7 +1622,7 @@ } else { /* UDP */ gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); - gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); + gaim_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); } } Modified: trunk/src/proxy.c =================================================================== --- trunk/src/proxy.c 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/proxy.c 2006-08-17 07:44:52 UTC (rev 16811) @@ -31,6 +31,7 @@ #include "internal.h" #include "cipher.h" +#include "dnsquery.h" #include "debug.h" #include "notify.h" #include "ntlm.h" @@ -46,6 +47,7 @@ int fd; guint inpa; GaimProxyInfo *gpi; + GaimDnsqueryData *query_data; /** * This contains alternating length/char* values. The char* @@ -307,6 +309,11 @@ connect_infos = g_slist_remove(connect_infos, connect_info); + /* + if (connect_info->query_data != NULL) + gaim_dnsquery_destroy(connect_info->query_data); + */ + while (connect_info->hosts != NULL) { /* Discard the length... */ @@ -351,681 +358,7 @@ gaim_proxy_connect_info_destroy(connect_info); } -#if defined(__unix__) || defined(__APPLE__) - -/* - * This structure represents both a pending DNS request and - * a free child process. - */ -typedef struct { - char *host; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - guint inpa; - int fd_in, fd_out; - pid_t dns_pid; -} pending_dns_request_t; - -static GSList *free_dns_children = NULL; -static GQueue *queued_requests = NULL; - -static int number_of_dns_children = 0; - -static const int MAX_DNS_CHILDREN = 2; - -typedef struct { - char hostname[512]; - int port; -} dns_params_t; - -typedef struct { - dns_params_t params; - GaimProxyDnsConnectFunction callback; - gpointer data; -} queued_dns_request_t; - -/* - * Begin the DNS resolver child process functions. - */ -#ifdef HAVE_SIGNAL_H static void -trap_gdb_bug() -{ - const char *message = - "Gaim's DNS child got a SIGTRAP signal.\n" - "This can be caused by trying to run gaim inside gdb.\n" - "There is a known gdb bug which prevents this. Supposedly gaim\n" - "should have detected you were using gdb and used an ugly hack,\n" - "check cope_with_gdb_brokenness() in proxy.c.\n\n" - "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; - fputs("\n* * *\n",stderr); - fputs(message,stderr); - fputs("* * *\n\n",stderr); - execlp("xmessage","xmessage","-center", message, NULL); - _exit(1); -} -#endif - -static void -cope_with_gdb_brokenness() -{ -#ifdef __linux__ - static gboolean already_done = FALSE; - char s[256], e[512]; - int n; - pid_t ppid; - - if(already_done) - return; - already_done = TRUE; - ppid = getppid(); - snprintf(s, sizeof(s), "/proc/%d/exe", ppid); - n = readlink(s, e, sizeof(e)); - if(n < 0) - return; - - e[MIN(n,sizeof(e)-1)] = '\0'; - - if(strstr(e,"gdb")) { - gaim_debug_info("dns", - "Debugger detected, performing useless query...\n"); - gethostbyname("x.x.x.x.x"); - } -#endif -} - -static void -gaim_dns_resolverthread(int child_out, int child_in, gboolean show_debug) -{ - dns_params_t dns_params; - const size_t zero = 0; - int rc; -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - const size_t addrlen = sizeof(sin); -#endif - -#ifdef HAVE_SIGNAL_H - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGTRAP, trap_gdb_bug); -#endif - - /* - * We resolve 1 host name for each iteration of this - * while loop. - * - * The top half of this reads in the hostname and port - * number from the socket with our parent. The bottom - * half of this resolves the IP (blocking) and sends - * the result back to our parent, when finished. - */ - while (1) { - const char ch = 'Y'; - fd_set fds; - struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; - FD_ZERO(&fds); - FD_SET(child_in, &fds); - rc = select(child_in + 1, &fds, NULL, NULL, &tv); - if (!rc) { - if (show_debug) - printf("dns[%d]: nobody needs me... =(\n", getpid()); - break; - } - rc = read(child_in, &dns_params, sizeof(dns_params_t)); - if (rc < 0) { - perror("read()"); - break; - } - if (rc == 0) { - if (show_debug) - printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); - _exit(0); - } - if (dns_params.hostname[0] == '\0') { - printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); - _exit(1); - } - /* Tell our parent that we read the data successfully */ - write(child_out, &ch, sizeof(ch)); - - /* We have the hostname and port, now resolve the IP */ - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", dns_params.port); - memset(&hints, 0, sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); - write(child_out, &rc, sizeof(rc)); - if (rc != 0) { - close(child_out); - if (show_debug) - printf("dns[%d] Error: getaddrinfo returned %d\n", - getpid(), rc); - dns_params.hostname[0] = '\0'; - continue; - } - tmp = res; - while (res) { - size_t ai_addrlen = res->ai_addrlen; - write(child_out, &ai_addrlen, sizeof(ai_addrlen)); - write(child_out, res->ai_addr, res->ai_addrlen); - res = res->ai_next; - } - freeaddrinfo(tmp); - write(child_out, &zero, sizeof(zero)); -#else - if (!inet_aton(dns_params.hostname, &sin.sin_addr)) { - struct hostent *hp; - if (!(hp = gethostbyname(dns_params.hostname))) { - write(child_out, &h_errno, sizeof(int)); - close(child_out); - if (show_debug) - printf("DNS Error: %d\n", h_errno); - _exit(0); - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - - sin.sin_port = htons(dns_params.port); - write(child_out, &addrlen, sizeof(addrlen)); - write(child_out, &sin, addrlen); - write(child_out, &zero, sizeof(zero)); -#endif - dns_params.hostname[0] = '\0'; - } - - close(child_out); - close(child_in); - - _exit(0); -} - -static pending_dns_request_t * -gaim_dns_new_resolverthread(gboolean show_debug) -{ - pending_dns_request_t *req; - int child_out[2], child_in[2]; - - /* Create pipes for communicating with the child process */ - if (pipe(child_out) || pipe(child_in)) { - gaim_debug_error("dns", - "Could not create pipes: %s\n", strerror(errno)); - return NULL; - } - - req = g_new(pending_dns_request_t, 1); - - cope_with_gdb_brokenness(); - - /* Fork! */ - req->dns_pid = fork(); - - /* If we are the child process... */ - if (req->dns_pid == 0) { - /* We should not access the parent's side of the pipes, so close them */ - close(child_out[0]); - close(child_in[1]); - - gaim_dns_resolverthread(child_out[1], child_in[0], show_debug); - /* The thread calls _exit() rather than returning, so we never get here */ - } - - /* We should not access the child's side of the pipes, so close them */ - close(child_out[1]); - close(child_in[0]); - if (req->dns_pid == -1) { - gaim_debug_error("dns", - "Could not create child process for DNS: %s\n", - strerror(errno)); - g_free(req); - return NULL; - } - - req->fd_out = child_out[0]; - req->fd_in = child_in[1]; - number_of_dns_children++; - gaim_debug_info("dns", - "Created new DNS child %d, there are now %d children.\n", - req->dns_pid, number_of_dns_children); - - return req; -} -/* - * End the DNS resolver child process functions. - */ - -/* - * Begin the functions for dealing with the DNS child processes. - */ -static void -req_free(pending_dns_request_t *req) -{ - g_return_if_fail(req != NULL); - - close(req->fd_in); - close(req->fd_out); - - g_free(req->host); - g_free(req); - - number_of_dns_children--; -} - -static int -send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params) -{ - char ch; - int rc; - pid_t pid; - - /* This waitpid might return the child's PID if it has recently - * exited, or it might return an error if it exited "long - * enough" ago that it has already been reaped; in either - * instance, we can't use it. */ - if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { - gaim_debug_warning("dns", - "DNS child %d no longer exists\n", req->dns_pid); - return -1; - } else if (pid < 0) { - gaim_debug_warning("dns", - "Wait for DNS child %d failed: %s\n", - req->dns_pid, strerror(errno)); - return -1; - } - - /* Let's contact this lost child! */ - rc = write(req->fd_in, dns_params, sizeof(*dns_params)); - if (rc < 0) { - gaim_debug_error("dns", - "Unable to write to DNS child %d: %d\n", - req->dns_pid, strerror(errno)); - close(req->fd_in); - return -1; - } - - g_return_val_if_fail(rc == sizeof(*dns_params), -1); - - /* Did you hear me? (This avoids some race conditions) */ - rc = read(req->fd_out, &ch, sizeof(ch)); - if (rc != 1 || ch != 'Y') - { - gaim_debug_warning("dns", - "DNS child %d not responding. Killing it!\n", - req->dns_pid); - kill(req->dns_pid, SIGKILL); - return -1; - } - - gaim_debug_info("dns", - "Successfully sent DNS request to child %d\n", req->dns_pid); - - return 0; -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond); - -static void -release_dns_child(pending_dns_request_t *req) -{ - g_free(req->host); - req->host = NULL; - - if (queued_requests && !g_queue_is_empty(queued_requests)) { - queued_dns_request_t *r = g_queue_pop_head(queued_requests); - req->host = g_strdup(r->params.hostname); - req->port = r->params.port; - req->callback = r->callback; - req->data = r->data; - - gaim_debug_info("dns", - "Processing queued DNS query for '%s' with child %d\n", - req->host, req->dns_pid); - - if (send_dns_request_to_child(req, &(r->params)) != 0) { - req_free(req); - req = NULL; - - gaim_debug_warning("dns", - "Intent of process queued query of '%s' failed, " - "requeueing...\n", r->params.hostname); - g_queue_push_head(queued_requests, r); - } else { - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - g_free(r); - } - - } else { - req->host = NULL; - req->callback = NULL; - req->data = NULL; - free_dns_children = g_slist_append(free_dns_children, req); - } -} - -static void -host_resolved(gpointer data, gint source, GaimInputCondition cond) -{ - pending_dns_request_t *req = (pending_dns_request_t*)data; - int rc, err; - GSList *hosts = NULL; - struct sockaddr *addr = NULL; - size_t addrlen; - - gaim_debug_info("dns", "Got response for '%s'\n", req->host); - gaim_input_remove(req->inpa); - - rc = read(req->fd_out, &err, sizeof(err)); - if ((rc == 4) && (err != 0)) - { - char message[1024]; -#ifdef HAVE_GETADDRINFO - g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)", - gai_strerror(err), req->dns_pid); -#else - g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", - err, req->dns_pid); -#endif - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - release_dns_child(req); - return; - } - if (rc > 0) - { - while (rc > 0) { - rc = read(req->fd_out, &addrlen, sizeof(addrlen)); - if (rc > 0 && addrlen > 0) { - addr = g_malloc(addrlen); - rc = read(req->fd_out, addr, addrlen); - hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); - hosts = g_slist_append(hosts, addr); - } else { - break; - } - } - } else if (rc == -1) { - char message[1024]; - g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - req_free(req); - return; - } else if (rc == 0) { - char message[1024]; - g_snprintf(message, sizeof(message), "EOF reading from DNS child"); - close(req->fd_out); - gaim_debug_error("dns", "%s\n", message); - req->callback(NULL, req->data, message); - req_free(req); - return; - } - -/* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ - - req->callback(hosts, req->data, NULL); - - release_dns_child(req); -} -/* - * End the functions for dealing with the DNS child processes. - */ - -int -gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) -{ - pending_dns_request_t *req = NULL; - dns_params_t dns_params; - gchar *host_temp; - gboolean show_debug; - - show_debug = gaim_debug_is_enabled(); - - host_temp = g_strstrip(g_strdup(hostname)); - strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); - g_free(host_temp); - dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; - dns_params.port = port; - - /* - * If we have any children, attempt to have them perform the DNS - * query. If we're able to send the query to a child, then req - * will be set to the pending_dns_request_t. Otherwise, req will - * be NULL and we'll need to create a new DNS request child. - */ - while (free_dns_children != NULL) { - req = free_dns_children->data; - free_dns_children = g_slist_remove(free_dns_children, req); - - if (send_dns_request_to_child(req, &dns_params) == 0) - /* We found an acceptable child, yay */ - break; - - req_free(req); - req = NULL; - } - - /* We need to create a new DNS request child */ - if (req == NULL) { - if (number_of_dns_children >= MAX_DNS_CHILDREN) { - queued_dns_request_t *r = g_new(queued_dns_request_t, 1); - memcpy(&(r->params), &dns_params, sizeof(dns_params)); - r->callback = callback; - r->data = data; - if (!queued_requests) - queued_requests = g_queue_new(); - g_queue_push_tail(queued_requests, r); - - gaim_debug_info("dns", - "DNS query for '%s' queued\n", dns_params.hostname); - - return 0; - } - - req = gaim_dns_new_resolverthread(show_debug); - if (req == NULL) - { - gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); - return -1; - } - send_dns_request_to_child(req, &dns_params); - } - - req->host = g_strdup(hostname); - req->port = port; - req->callback = callback; - req->data = data; - req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - - return 0; -} - -#elif defined _WIN32 /* end __unix__ || __APPLE__ */ - -typedef struct _dns_tdata { - char *hostname; - int port; - GaimProxyDnsConnectFunction callback; - gpointer data; - GSList *hosts; - char *errmsg; -} dns_tdata; - -static gboolean dns_main_thread_cb(gpointer data) { - dns_tdata *td = (dns_tdata*)data; - if (td->errmsg != NULL) { - gaim_debug_info("dns", "%s\n", td->errmsg); - } - td->callback(td->hosts, td->data, td->errmsg); - g_free(td->hostname); - g_free(td->errmsg); - g_free(td); - return FALSE; -} - -static gpointer dns_thread(gpointer data) { - -#ifdef HAVE_GETADDRINFO - int rc; - struct addrinfo hints, *res, *tmp; - char servname[20]; -#else - struct sockaddr_in sin; - struct hostent *hp; -#endif - dns_tdata *td = (dns_tdata*)data; - -#ifdef HAVE_GETADDRINFO - g_snprintf(servname, sizeof(servname), "%d", td->port); - memset(&hints,0,sizeof(hints)); - - /* This is only used to convert a service - * name to a port number. As we know we are - * passing a number already, we know this - * value will not be really used by the C - * library. - */ - hints.ai_socktype = SOCK_STREAM; - if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) { - tmp = res; - while(res) { - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(res->ai_addrlen)); - td->hosts = g_slist_append(td->hosts, - g_memdup(res->ai_addr, res->ai_addrlen)); - res = res->ai_next; - } - freeaddrinfo(tmp); - } else { - td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); - } -#else - if ((hp = gethostbyname(td->hostname))) { - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = htons(td->port); - - td->hosts = g_slist_append(td->hosts, - GSIZE_TO_POINTER(sizeof(sin))); - td->hosts = g_slist_append(td->hosts, - g_memdup(&sin, sizeof(sin))); - } else { - td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); - } -#endif - /* back to main thread */ - g_idle_add(dns_main_thread_cb, td); - return 0; -} - -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - dns_tdata *td; - struct sockaddr_in sin; - GError* err = NULL; - - if(inet_aton(hostname, &sin.sin_addr)) { - GSList *hosts = NULL; - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); - hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); - callback(hosts, data, NULL); - return 0; - } - - gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); - td = g_new0(dns_tdata, 1); - td->hostname = g_strdup(hostname); - td->port = port; - td->callback = callback; - td->data = data; - - if(!g_thread_create(dns_thread, td, FALSE, &err)) { - gaim_debug_error("dns", "DNS thread create failure: %s\n", err?err->message:""); - g_error_free(err); - g_free(td->hostname); - g_free(td); - return -1; - } - return 0; -} - -#else /* not __unix__ or __APPLE__ or _WIN32 */ - -typedef struct { - gpointer data; - size_t addrlen; - struct sockaddr *addr; - GaimProxyDnsConnectFunction callback; -} pending_dns_request_t; - -static gboolean host_resolved(gpointer data) -{ - pending_dns_request_t *req = (pending_dns_request_t*)data; - GSList *hosts = NULL; - hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); - hosts = g_slist_append(hosts, req->addr); - req->callback(hosts, req->data, NULL); - g_free(req); - return FALSE; -} - -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) -{ - struct sockaddr_in sin; - pending_dns_request_t *req; - - if (!inet_aton(hostname, &sin.sin_addr)) { - struct hostent *hp; - if(!(hp = gethostbyname(hostname))) { - gaim_debug_error("dns", - "gaim_gethostbyname(\"%s\", %d) failed: %d\n", - hostname, port, h_errno); - return -1; - } - memset(&sin, 0, sizeof(struct sockaddr_in)); - memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - } else - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - - req = g_new(pending_dns_request_t, 1); - req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); - req->addrlen = sizeof(sin); - req->data = data; - req->callback = callback; - gaim_timeout_add(10, host_resolved, req); - return 0; -} - -#endif /* not __unix__ or __APPLE__ or _WIN32 */ - -static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) { GaimProxyConnectInfo *connect_info = data; @@ -2368,8 +1701,9 @@ return NULL; } - if (gaim_gethostbyname_async(connecthost, - connectport, connection_host_resolved, connect_info) != 0) + connect_info->query_data = gaim_dnsquery_a(connecthost, + connectport, connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; @@ -2401,8 +1735,9 @@ connect_info->port = port; connect_info->gpi = gpi; - if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), - gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) + connect_info->query_data = gaim_dnsquery_a(gaim_proxy_info_get_host(gpi), + gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; Modified: trunk/src/proxy.h =================================================================== --- trunk/src/proxy.h 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/proxy.h 2006-08-17 07:44:52 UTC (rev 16811) @@ -26,6 +26,7 @@ #define _GAIM_PROXY_H_ #include <glib.h> +#include "dnsquery.h" #include "eventloop.h" /** @@ -56,6 +57,7 @@ } GaimProxyInfo; +typedef struct _GaimDnsQueryData GaimDnsQueryData; typedef struct _GaimProxyConnectInfo GaimProxyConnectInfo; typedef void (*GaimProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); @@ -278,18 +280,6 @@ */ void gaim_proxy_connect_cancel(GaimProxyConnectInfo *connect_info); -/** - * Do an async dns query - * - * @param hostname The hostname to resolve - * @param port A portnumber which is stored in the struct sockaddr - * @param callback Callback to call after resolving - * @param data Extra data for the callback function - * - * @return Zero indicates the connection is pending. Any other value indicates failure. - */ -int gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data); - /*@}*/ #ifdef __cplusplus Modified: trunk/src/stun.c =================================================================== --- trunk/src/stun.c 2006-08-17 06:21:28 UTC (rev 16810) +++ trunk/src/stun.c 2006-08-17 07:44:52 UTC (rev 16811) @@ -40,6 +40,7 @@ #include "debug.h" #include "account.h" +#include "dnsquery.h" #include "dnssrv.h" #include "network.h" #include "proxy.h" @@ -359,7 +360,7 @@ gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); - gaim_gethostbyname_async(servername, port, hbn_cb, NULL); + gaim_dnsquery_a(servername, port, hbn_cb, NULL); g_free(resp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 06:21:32
|
Revision: 16810 Author: thekingant Date: 2006-08-16 23:21:28 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16810&view=rev Log Message: ----------- sf patch #1541754, from Sadrul Habib Chowdhury "Setting an account to 'offline' while it is connecting doesn't cause the connection to stop. This patch fixes that." Modified Paths: -------------- trunk/src/prpl.c Modified: trunk/src/prpl.c =================================================================== --- trunk/src/prpl.c 2006-08-17 05:47:58 UTC (rev 16809) +++ trunk/src/prpl.c 2006-08-17 06:21:28 UTC (rev 16810) @@ -171,6 +171,12 @@ return; } + if (!gaim_status_is_online(new_status)) + { + if (!gaim_account_is_disconnected(account)) + gaim_account_disconnect(account); + return; + } if (gaim_account_is_connecting(account)) /* @@ -191,13 +197,6 @@ { prpl_info->set_status(account, new_status); } - - if (!gaim_status_is_online(new_status)) - { - if (!gaim_account_is_disconnected(account)) - gaim_account_disconnect(account); - return; - } } void This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 05:48:03
|
Revision: 16809 Author: thekingant Date: 2006-08-16 22:47:58 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16809&view=rev Log Message: ----------- gaim_ssl_connect's are now cancelable (without crashing, anyway) This was relatively easy, because the PRPLs already keep a reference to the GaimSslConnection. I just needed to update the core ssl code to keep track of the GaimProxyConnectInfo, and to call gaim_proxy_connect_cancel() when gaim_ssl_close() is called Modified Paths: -------------- trunk/plugins/ssl/ssl-gnutls.c Modified: trunk/plugins/ssl/ssl-gnutls.c =================================================================== --- trunk/plugins/ssl/ssl-gnutls.c 2006-08-17 05:47:10 UTC (rev 16808) +++ trunk/plugins/ssl/ssl-gnutls.c 2006-08-17 05:47:58 UTC (rev 16809) @@ -100,27 +100,11 @@ static void -ssl_gnutls_connect_cb(gpointer data, gint source, GaimInputCondition cond) +ssl_gnutls_connect(GaimSslConnection *gsc) { - GaimSslConnection *gsc = (GaimSslConnection *)data; GaimSslGnutlsData *gnutls_data; static const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 }; - /* - * TODO: Uh, this needs to somehow check to make sure that gsc is - * still valid before actually doing anything. - */ - - if(source < 0) { - if(gsc->error_cb != NULL) - gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); - - gaim_ssl_close(gsc); - return; - } - - gsc->fd = source; - gnutls_data = g_new0(GaimSslGnutlsData, 1); gsc->private_data = gnutls_data; @@ -133,7 +117,7 @@ gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE, xcred); - gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(source)); + gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(gsc->fd)); gnutls_data->handshake_handler = gaim_input_add(gsc->fd, GAIM_INPUT_READ, ssl_gnutls_handshake_cb, gsc); @@ -204,7 +188,7 @@ { ssl_gnutls_init, ssl_gnutls_uninit, - ssl_gnutls_connect_cb, + ssl_gnutls_connect, ssl_gnutls_close, ssl_gnutls_read, ssl_gnutls_write This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 05:47:17
|
Revision: 16808 Author: thekingant Date: 2006-08-16 22:47:10 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16808&view=rev Log Message: ----------- gaim_ssl_connect's are now cancelable (without crashing, anyway) This was relatively easy, because the PRPLs already keep a reference to the GaimSslConnection. I just needed to update the core ssl code to keep track of the GaimProxyConnectInfo, and to call gaim_proxy_connect_cancel() when gaim_ssl_close() is called Modified Paths: -------------- trunk/plugins/ssl/ssl-nss.c trunk/src/protocols/irc/irc.c trunk/src/sslconn.c trunk/src/sslconn.h Modified: trunk/plugins/ssl/ssl-nss.c =================================================================== --- trunk/plugins/ssl/ssl-nss.c 2006-08-17 04:45:11 UTC (rev 16807) +++ trunk/plugins/ssl/ssl-nss.c 2006-08-17 05:47:10 UTC (rev 16808) @@ -237,16 +237,13 @@ } static void -ssl_nss_connect_cb(gpointer data, gint source, GaimInputCondition cond) +ssl_nss_connect(GaimSslConnection *gsc) { - GaimSslConnection *gsc = (GaimSslConnection *)data; GaimSslNssData *nss_data = g_new0(GaimSslNssData, 1); PRSocketOptionData socket_opt; gsc->private_data = nss_data; - gsc->fd = source; - nss_data->fd = PR_ImportTCPSocket(gsc->fd); if (nss_data->fd == NULL) @@ -359,7 +356,7 @@ { ssl_nss_init, ssl_nss_uninit, - ssl_nss_connect_cb, + ssl_nss_connect, ssl_nss_close, ssl_nss_read, ssl_nss_write Modified: trunk/src/protocols/irc/irc.c =================================================================== --- trunk/src/protocols/irc/irc.c 2006-08-17 04:45:11 UTC (rev 16807) +++ trunk/src/protocols/irc/irc.c 2006-08-17 05:47:10 UTC (rev 16808) @@ -450,7 +450,7 @@ g_free(irc->inbuf); if (irc->gsc) { gaim_ssl_close(irc->gsc); - } else if (irc->fd > 0) { + } else if (irc->fd >= 0) { close(irc->fd); } if (irc->timer) Modified: trunk/src/sslconn.c =================================================================== --- trunk/src/sslconn.c 2006-08-17 04:45:11 UTC (rev 16807) +++ trunk/src/sslconn.c 2006-08-17 05:47:10 UTC (rev 16808) @@ -45,10 +45,14 @@ gaim_plugin_load(plugin); ops = gaim_ssl_get_ops(); - if (ops != NULL && ops->init != NULL) - return ops->init(); - else + if ((ops == NULL) || (ops->init == NULL) || (ops->uninit == NULL) || + (ops->connect == NULL) || (ops->close == NULL) || + (ops->read == NULL) || (ops->write == NULL)) + { return FALSE; + } + + return ops->init(); } gboolean @@ -62,25 +66,42 @@ #endif } +static void +gaim_ssl_connect_cb(gpointer data, gint source, const gchar *error_message) +{ + GaimSslConnection *gsc; + GaimSslOps *ops; + + gsc = data; + gsc->connect_info = NULL; + + if (source < 0) + { + if (gsc->error_cb != NULL) + gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); + + gaim_ssl_close(gsc); + return; + } + + gsc->fd = source; + + ops = gaim_ssl_get_ops(); + ops->connect(gsc); +} + GaimSslConnection * gaim_ssl_connect(GaimAccount *account, const char *host, int port, GaimSslInputFunction func, GaimSslErrorFunction error_func, void *data) { GaimSslConnection *gsc; - GaimSslOps *ops; - GaimProxyConnectInfo *connect_info; g_return_val_if_fail(host != NULL, NULL); g_return_val_if_fail(port != 0 && port != -1, NULL); g_return_val_if_fail(func != NULL, NULL); g_return_val_if_fail(gaim_ssl_is_supported(), NULL); - ops = gaim_ssl_get_ops(); - - g_return_val_if_fail(ops != NULL, NULL); - g_return_val_if_fail(ops->connect_cb != NULL, NULL); - if (!_ssl_initialized) { if (!ssl_init()) @@ -89,15 +110,16 @@ gsc = g_new0(GaimSslConnection, 1); + gsc->fd = -1; gsc->host = g_strdup(host); gsc->port = port; gsc->connect_cb_data = data; gsc->connect_cb = func; gsc->error_cb = error_func; - connect_info = gaim_proxy_connect(account, host, port, ops->connect_cb, gsc); + gsc->connect_info = gaim_proxy_connect(account, host, port, gaim_ssl_connect_cb, gsc); - if (connect_info == NULL) + if (gsc->connect_info == NULL) { g_free(gsc->host); g_free(gsc); @@ -141,11 +163,6 @@ g_return_val_if_fail(func != NULL, NULL); g_return_val_if_fail(gaim_ssl_is_supported(), NULL); - ops = gaim_ssl_get_ops(); - - g_return_val_if_fail(ops != NULL, NULL); - g_return_val_if_fail(ops->connect_cb != NULL, NULL); - if (!_ssl_initialized) { if (!ssl_init()) @@ -157,8 +174,10 @@ gsc->connect_cb_data = data; gsc->connect_cb = func; gsc->error_cb = error_func; + gsc->fd = fd; - ops->connect_cb(gsc, fd, GAIM_INPUT_READ); + ops = gaim_ssl_get_ops(); + ops->connect(gsc); return (GaimSslConnection *)gsc; } @@ -171,14 +190,15 @@ g_return_if_fail(gsc != NULL); ops = gaim_ssl_get_ops(); + (ops->close)(gsc); - if (gsc->inpa) + if (gsc->connect_info != NULL) + gaim_proxy_connect_cancel(gsc->connect_info); + + if (gsc->inpa > 0) gaim_input_remove(gsc->inpa); - if (ops != NULL && ops->close != NULL) - (ops->close)(gsc); - - if (gsc->fd != -1) + if (gsc->fd >= 0) close(gsc->fd); g_free(gsc->host); @@ -195,11 +215,7 @@ g_return_val_if_fail(len > 0, 0); ops = gaim_ssl_get_ops(); - - if (ops != NULL && (ops->read) != NULL) - return (ops->read)(gsc, data, len); - - return 0; + return (ops->read)(gsc, data, len); } size_t @@ -212,11 +228,7 @@ g_return_val_if_fail(len > 0, 0); ops = gaim_ssl_get_ops(); - - if (ops != NULL && (ops->write) != NULL) - return (ops->write)(gsc, data, len); - - return 0; + return (ops->write)(gsc, data, len); } void @@ -245,9 +257,7 @@ return; ops = gaim_ssl_get_ops(); + ops->uninit(); - if (ops != NULL && ops->uninit != NULL) - ops->uninit(); - _ssl_initialized = FALSE; } Modified: trunk/src/sslconn.h =================================================================== --- trunk/src/sslconn.h 2006-08-17 04:45:11 UTC (rev 16807) +++ trunk/src/sslconn.h 2006-08-17 05:47:10 UTC (rev 16808) @@ -54,6 +54,7 @@ int fd; int inpa; + GaimProxyConnectInfo *connect_info; void *private_data; }; @@ -61,13 +62,13 @@ /** * SSL implementation operations structure. * - * Every SSL implementation must provide one of these and register it. + * Every SSL implementation must provide all of these and register it. */ typedef struct { gboolean (*init)(void); void (*uninit)(void); - GaimInputFunction connect_cb; + void (*connect)(GaimSslConnection *gsc); void (*close)(GaimSslConnection *gsc); size_t (*read)(GaimSslConnection *gsc, void *data, size_t len); size_t (*write)(GaimSslConnection *gsc, const void *data, size_t len); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-08-17 04:45:15
|
Revision: 16807 Author: thekingant Date: 2006-08-16 21:45:11 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16807&view=rev Log Message: ----------- This function was used by the chat userlist buttons, which are gone Modified Paths: -------------- trunk/src/gtkconv.c Modified: trunk/src/gtkconv.c =================================================================== --- trunk/src/gtkconv.c 2006-08-17 03:50:32 UTC (rev 16806) +++ trunk/src/gtkconv.c 2006-08-17 04:45:11 UTC (rev 16807) @@ -1360,29 +1360,6 @@ } static void -chat_im_button_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) -{ - GaimGtkChatPane *gtkchat; - GtkTreeIter iter; - GtkTreeModel *model; - GtkTreeSelection *sel; - char *name; - - gtkchat = gtkconv->u.chat; - - model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); - - if (gtk_tree_selection_get_selected(sel, NULL, &iter)) - gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &name, -1); - else - return; - - chat_do_im(gtkconv, name); - g_free(name); -} - -static void ignore_cb(GtkWidget *w, GaimGtkConversation *gtkconv) { GaimConversation *conv = gtkconv->active_conv; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aar...@us...> - 2006-08-17 03:50:59
|
Revision: 16806 Author: aaronsheldon Date: 2006-08-16 20:50:32 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16806&view=rev Log Message: ----------- Today is the 16th, not the 26th. Modified Paths: -------------- web/htdocs/news.txt Modified: web/htdocs/news.txt =================================================================== --- web/htdocs/news.txt 2006-08-17 03:13:15 UTC (rev 16805) +++ web/htdocs/news.txt 2006-08-17 03:50:32 UTC (rev 16806) @@ -1,5 +1,5 @@ MSN Crashing -August 26th, 2006 - 6:58PM PDT +August 16th, 2006 - 6:58PM PDT Yesterday, Gaim started crashing for a bunch of people (most notably Windows users) when trying to connect a MSN account. This is due to a bug in Gaim which has been fixed in subversion (<a href="faq.php#q14">don't use subversion</a>), and we're working on releasing a fix. We'll keep you updated. In the meantime, feel free to <a href='https://sourceforge.net/forum/message.php?msg_id=3867971'>commiserate</a> with your fellow MSN-using Wingaim users. :) # Summer of Code Update This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 03:13:23
|
Revision: 16805 Author: datallah Date: 2006-08-16 20:13:15 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16805&view=rev Log Message: ----------- Revision: 16804 Author: datallah Date: 10:40:44 PM, Wednesday, August 16, 2006 Message: Sadrul fixed this buglet which prevented the global buddy icon from being applied to new accounts ---- Modified : /trunk/src/gtkaccount.c Revision: 16801 Author: datallah Date: 9:06:27 PM, Wednesday, August 16, 2006 Message: Make the silc key permission checks safer and cover more cases (e.g. private key exists, but is not readable by you). ---- Modified : /trunk/src/protocols/silc/util.c Revision: 16800 Author: seanegan Date: 4:50:16 PM, Wednesday, August 16, 2006 Message: segfault fix ---- Modified : /trunk/src/gtkstatusbox.c Revision: 16799 Author: sadrul Date: 3:38:57 PM, Wednesday, August 16, 2006 Message: Use the proper setting-name. "seanegan: sadrul: Looks good. You may want to set the non-global-buddyicon account setting if use-global-buddyicon is not set" Also, if the user sets the buddy-icon from a per-account box, it unsets the use-global-budduicon setting for that account. ---- Modified : /trunk/src/gtkstatusbox.c Revision: 16798 Author: sadrul Date: 3:21:04 PM, Wednesday, August 16, 2006 Message: Do not show the icon-box for an account if it doesn't support buddyicons in the per-account statusboxes. Allow the peraccount boxes to change the icon only for that account. ---- Modified : /trunk/src/gtkblist.c Modified : /trunk/src/gtkstatusbox.c Revision: 16797 Author: seanegan Date: 3:05:07 PM, Wednesday, August 16, 2006 Message: fixes ---- Modified : /trunk/src/gtkstatusbox.c Revision: 16796 Author: datallah Date: 2:55:17 PM, Wednesday, August 16, 2006 Message: Fix bug #1541223 ---- Modified : /trunk/src/protocols/simple/simple.c Revision: 16795 Author: seanegan Date: 1:31:29 PM, Wednesday, August 16, 2006 Message: Now with 'compiling' feature ---- Modified : /trunk/src/gtkstatusbox.c Revision: 16794 Author: seanegan Date: 1:26:57 PM, Wednesday, August 16, 2006 Message: Only one file selector ---- Modified : /trunk/src/gtkstatusbox.c Revision: 16788 Author: datallah Date: 7:13:19 AM, Wednesday, August 16, 2006 Message: gdk_threads_init() is causing problems on win32 for some reason. ---- Modified : /trunk/src/gtkmain.c Modified Paths: -------------- branches/v2_0_0/src/gtkaccount.c branches/v2_0_0/src/gtkmain.c branches/v2_0_0/src/gtkstatusbox.c branches/v2_0_0/src/protocols/silc/util.c branches/v2_0_0/src/protocols/simple/simple.c Modified: branches/v2_0_0/src/gtkaccount.c =================================================================== --- branches/v2_0_0/src/gtkaccount.c 2006-08-17 02:40:44 UTC (rev 16804) +++ branches/v2_0_0/src/gtkaccount.c 2006-08-17 03:13:15 UTC (rev 16805) @@ -1119,7 +1119,7 @@ gaim_account_set_alias(account, NULL); /* Buddy Icon */ - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) == + if (new || gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) == gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->icon_check))) { icon_change = TRUE; } Modified: branches/v2_0_0/src/gtkmain.c =================================================================== --- branches/v2_0_0/src/gtkmain.c 2006-08-17 02:40:44 UTC (rev 16804) +++ branches/v2_0_0/src/gtkmain.c 2006-08-17 03:13:15 UTC (rev 16805) @@ -650,7 +650,9 @@ * threadify dbus when that gets initialized. Ugh. */ if (!g_thread_supported()) g_thread_init(NULL); +#ifndef _WIN32 gdk_threads_init(); +#endif #endif /* Glib has threads */ gui_check = gtk_init_check(&argc, &argv); Modified: branches/v2_0_0/src/gtkstatusbox.c =================================================================== --- branches/v2_0_0/src/gtkstatusbox.c 2006-08-17 02:40:44 UTC (rev 16804) +++ branches/v2_0_0/src/gtkstatusbox.c 2006-08-17 03:13:15 UTC (rev 16805) @@ -78,6 +78,7 @@ static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); static void do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift); +static void icon_choose_cb(const char *filename, gpointer data); static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); @@ -220,7 +221,65 @@ update_to_reflect_account_status(status_box, account, newstatus); } +static gboolean +icon_box_press_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) +{ + if (box->buddy_icon_sel) { + gtk_window_present(GTK_WINDOW(box->buddy_icon_sel)); + return FALSE; + } + + box->buddy_icon_sel = gaim_gtk_buddy_icon_chooser_new(NULL, icon_choose_cb, box); + gtk_widget_show_all(box->buddy_icon_sel); + return FALSE; +} + +static gboolean +icon_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) +{ + gdk_window_set_cursor(widget->window, box->hand_cursor); + gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon_hover); + return FALSE; +} + +static gboolean +icon_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) +{ + gdk_window_set_cursor(widget->window, box->arrow_cursor); + gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon) ; + return FALSE; +} + static void +setup_icon_box(GtkGaimStatusBox *status_box) +{ + if (status_box->account && + !gaim_account_get_ui_bool(status_box->account, GAIM_GTK_UI, "use-global-buddyicon", TRUE)) + { + char *string = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(status_box->account)); + gtk_gaim_status_box_set_buddy_icon(status_box, string); + g_free(string); + } + else + { + gtk_gaim_status_box_set_buddy_icon(status_box, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); + } + status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); + status_box->icon_box = gtk_event_box_new(); + status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); + status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); + + g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); + g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); + g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); + + gtk_container_add(GTK_CONTAINER(status_box->icon_box), status_box->icon); + + gtk_widget_show_all(status_box->icon_box); + gtk_widget_set_parent(status_box->icon_box, GTK_WIDGET(status_box)); +} + +static void gtk_gaim_status_box_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { @@ -236,10 +295,18 @@ statusbox->status_changed_signal = 0; } - if (statusbox->account) + if (statusbox->account) { + GaimPlugin *plug = gaim_plugins_find_with_id(gaim_account_get_protocol_id(statusbox->account)); + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo && prplinfo->icon_spec.format != NULL) { + setup_icon_box(statusbox); + } statusbox->status_changed_signal = gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", statusbox, GAIM_CALLBACK(account_status_changed_cb), statusbox); + } else { + setup_icon_box(statusbox); + } gtk_gaim_status_box_regenerate(statusbox); break; @@ -924,15 +991,33 @@ if (filename) { GList *accounts; - for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { - GaimAccount *account = accounts->data; - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddy-icon", TRUE) && - GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(account)))->icon_spec.format) { - char *icon = gaim_gtk_convert_buddy_icon(gaim_find_prpl(gaim_account_get_protocol_id(account)), - filename); - gaim_account_set_buddy_icon(account, icon); - g_free(icon); + + if (box->account) { + GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(box->account)); + if (plug) { + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo && prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(box->account, icon); + g_free(icon); + gaim_account_set_ui_bool(box->account, GAIM_GTK_UI, "use-global-buddyicon", FALSE); + } } + } else { + for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { + GaimAccount *account = accounts->data; + GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(account)); + if (plug) { + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo != NULL && + gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) && + prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(account, icon); + g_free(icon); + } + } + } } gtk_gaim_status_box_set_buddy_icon(box, filename); } @@ -940,37 +1025,6 @@ box->buddy_icon_sel = NULL; } -static gboolean -icon_box_press_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) -{ - GtkWidget *filesel; - - if (box->buddy_icon_sel) { - gtk_window_present(GTK_WINDOW(box->buddy_icon_sel)); - return FALSE; - } - - filesel = gaim_gtk_buddy_icon_chooser_new(NULL, icon_choose_cb, box); - gtk_widget_show_all(filesel); - return FALSE; -} - -static gboolean -icon_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) -{ - gdk_window_set_cursor(widget->window, box->hand_cursor); - gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon_hover); - return FALSE; -} - -static gboolean -icon_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) -{ - gdk_window_set_cursor(widget->window, box->arrow_cursor); - gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon) ; - return FALSE; -} - static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) { @@ -987,18 +1041,6 @@ status_box->vsep = gtk_vseparator_new(); status_box->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - status_box->buddy_icon = gdk_pixbuf_new_from_file("/home/seanegan/p1120233.jpg", NULL); - status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); - status_box->icon_box = gtk_event_box_new(); - status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); - status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); - g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); - g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); - - gtk_container_add(GTK_CONTAINER(status_box->icon_box), status_box->icon); - status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); @@ -1011,7 +1053,6 @@ gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0); gtk_widget_show_all(status_box->toggle_button); - gtk_widget_show_all(status_box->icon_box); #if GTK_CHECK_VERSION(2,4,0) gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE); #endif @@ -1062,7 +1103,6 @@ #endif gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); gtk_widget_set_parent(status_box->toggle_button, GTK_WIDGET(status_box)); - gtk_widget_set_parent(status_box->icon_box, GTK_WIDGET(status_box)); GTK_BIN(status_box)->child = status_box->toggle_button; gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); @@ -1166,34 +1206,37 @@ parent_alc = *allocation; parent_alc.height = MAX(1,req.height); parent_alc.y += 3; - parent_alc.width -= (parent_alc.height + 3); - combo_box_size_allocate(widget, &parent_alc); - icon_alc = *allocation; - icon_alc.height = MAX(1,req.height); - icon_alc.width = icon_alc.height; - icon_alc.x = allocation->width - icon_alc.width; - icon_alc.y += 3; + if (status_box->icon_box) + { + parent_alc.width -= (parent_alc.height + 3); + icon_alc = *allocation; + icon_alc.height = MAX(1,req.height); + icon_alc.width = icon_alc.height; + icon_alc.x = allocation->width - icon_alc.width; + icon_alc.y += 3; - if (status_box->icon_size != icon_alc.height) - { - if ((status_box->buddy_icon_path != NULL) && - (*status_box->buddy_icon_path != '\0')) + if (status_box->icon_size != icon_alc.height) { - scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, - icon_alc.height, icon_alc.width, FALSE, NULL); - status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); - do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); - g_object_unref(status_box->buddy_icon); - status_box->buddy_icon = scaled; - gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); + if ((status_box->buddy_icon_path != NULL) && + (*status_box->buddy_icon_path != '\0')) + { + scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, + icon_alc.height, icon_alc.width, FALSE, NULL); + g_object_unref(status_box->buddy_icon_hover); + status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); + do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); + g_object_unref(status_box->buddy_icon); + status_box->buddy_icon = scaled; + gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); + } + status_box->icon_size = icon_alc.height; } - status_box->icon_size = icon_alc.height; + gtk_widget_size_allocate(status_box->icon_box, &icon_alc); } - gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->icon_box, &icon_alc); - - gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->toggle_button, &parent_alc); + combo_box_size_allocate(widget, &parent_alc); + gtk_widget_size_allocate(status_box->toggle_button, &parent_alc); widget->allocation = *allocation; } @@ -1221,7 +1264,8 @@ (* callback) (status_box->vbox, callback_data); (* callback) (status_box->toggle_button, callback_data); (* callback) (status_box->arrow, callback_data); - (* callback) (status_box->icon_box, callback_data); + if (status_box->icon_box) + (* callback) (status_box->icon_box, callback_data); } combo_box_forall(container, include_internals, callback, callback_data); @@ -1230,7 +1274,7 @@ GtkWidget * gtk_gaim_status_box_new() { - return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); + return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", NULL, NULL); } GtkWidget * @@ -1351,7 +1395,8 @@ } } - gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); + if (box->account == NULL) + gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); } const char* Modified: branches/v2_0_0/src/protocols/silc/util.c =================================================================== --- branches/v2_0_0/src/protocols/silc/util.c 2006-08-17 02:40:44 UTC (rev 16804) +++ branches/v2_0_0/src/protocols/silc/util.c 2006-08-17 03:13:15 UTC (rev 16805) @@ -234,25 +234,44 @@ } #endif - fd = open(file_private_key, O_RDONLY); - if ((g_stat(file_private_key, &st)) == -1) { + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } else if ((g_stat(file_private_key, &st)) == -1) { /* If file doesn't exist */ if (errno == ENOENT) { gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); - silc_create_key_pair(SILCGAIM_DEF_PKCS, + if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, SILCGAIM_DEF_PKCS_LEN, file_public_key, file_private_key, NULL, (gc->password == NULL) ? "" : gc->password, - NULL, NULL, NULL, FALSE); - if (fd != -1) - close(fd); - fd = open(file_private_key, O_RDONLY); - g_stat(file_private_key, &st); + NULL, NULL, NULL, FALSE)) { + gaim_debug_error("silc", "Couldn't create key pair\n"); + return FALSE; + } + + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } + /* This shouldn't really happen because silc_create_key_pair() + * will set the permissions */ + else if ((g_stat(file_private_key, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + return FALSE; + } } else { gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, strerror(errno)); - if (fd != -1) - close(fd); return FALSE; } } @@ -270,7 +289,7 @@ if ((st.st_mode & 0777) != 0600) { gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" "Trying to change them ...\n", file_private_key); - if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { + if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { gaim_debug_error("silc", "Failed to change permissions for private key file!\n" "Permissions for your private key file must be 0600.\n"); Modified: branches/v2_0_0/src/protocols/simple/simple.c =================================================================== --- branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 02:40:44 UTC (rev 16804) +++ branches/v2_0_0/src/protocols/simple/simple.c 2006-08-17 03:13:15 UTC (rev 16805) @@ -604,7 +604,7 @@ const gchar *body, struct sip_dialog *dialog, TransCallback tc) { struct simple_account_data *sip = gc->proto_data; char *callid = dialog ? g_strdup(dialog->callid) : gencallid(); - char *auth = ""; + char *auth = NULL; const char *addh = ""; gchar *branch = genbranch(); gchar *tag = NULL; @@ -662,7 +662,7 @@ ++sip->cseq, method, callid, - auth, + auth ? auth : "", addh, strlen(body), body); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 02:40:54
|
Revision: 16804 Author: datallah Date: 2006-08-16 19:40:44 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16804&view=rev Log Message: ----------- Sadrul fixed this buglet which prevented the global buddy icon from being applied to new accounts Modified Paths: -------------- trunk/src/gtkaccount.c Modified: trunk/src/gtkaccount.c =================================================================== --- trunk/src/gtkaccount.c 2006-08-17 02:20:56 UTC (rev 16803) +++ trunk/src/gtkaccount.c 2006-08-17 02:40:44 UTC (rev 16804) @@ -1119,7 +1119,7 @@ gaim_account_set_alias(account, NULL); /* Buddy Icon */ - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) == + if (new || gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) == gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->icon_check))) { icon_change = TRUE; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-08-17 02:21:04
|
Revision: 16803 Author: seanegan Date: 2006-08-16 19:20:56 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16803&view=rev Log Message: ----------- MSN news Modified Paths: -------------- web/htdocs/news.txt Modified: web/htdocs/news.txt =================================================================== --- web/htdocs/news.txt 2006-08-17 01:58:20 UTC (rev 16802) +++ web/htdocs/news.txt 2006-08-17 02:20:56 UTC (rev 16803) @@ -1,3 +1,7 @@ +MSN Crashing +August 26th, 2006 - 6:58PM PDT +Yesterday, Gaim started crashing for a bunch of people (most notably Windows users) when trying to connect a MSN account. This is due to a bug in Gaim which has been fixed in subversion (<a href="faq.php#q14">don't use subversion</a>), and we're working on releasing a fix. We'll keep you updated. In the meantime, feel free to <a href='https://sourceforge.net/forum/message.php?msg_id=3867971'>commiserate</a> with your fellow MSN-using Wingaim users. :) +# Summer of Code Update July 6th, 2006 - 11:58PM PDT Sorry it's been so long since we last posted some news. Apparently we're busy people ...or maybe we're just lazy. Anyhoo, we've been alotted 8 summer of code projects this year. See our <a href="summerofcode/">Summer of Code</a> web page for more detailed info. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-17 01:58:24
|
Revision: 16802 Author: sadrul Date: 2006-08-16 18:58:20 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16802&view=rev Log Message: ----------- Add an option to beep on events. Modified Paths: -------------- trunk/console/plugins/gntgf.c Modified: trunk/console/plugins/gntgf.c =================================================================== --- trunk/console/plugins/gntgf.c 2006-08-17 01:06:27 UTC (rev 16801) +++ trunk/console/plugins/gntgf.c 2006-08-17 01:58:20 UTC (rev 16802) @@ -22,11 +22,13 @@ #define PLUGIN_STATIC_NAME "GntGf" -#define PREFS_EVENT "/plugins/gnt/gntgf/events" +#define PREFS_PREFIX "/plugins/gnt/gntgf" +#define PREFS_EVENT PREFS_PREFIX "/events" #define PREFS_EVENT_SIGNONF PREFS_EVENT "/signonf" #define PREFS_EVENT_IM_MSG PREFS_EVENT "/immsg" #define PREFS_EVENT_CHAT_MSG PREFS_EVENT "/chatmsg" #define PREFS_EVENT_CHAT_NICK PREFS_EVENT "/chatnick" +#define PREFS_BEEP PREFS_PREFIX "/beep" #include <glib.h> @@ -39,6 +41,7 @@ #include <gnt.h> #include <gntbox.h> #include <gntbutton.h> +#include <gntcheckbox.h> #include <gntlabel.h> #include <gnttree.h> @@ -96,6 +99,9 @@ int h, w; va_list args; + if (gaim_prefs_get_bool(PREFS_BEEP)) + beep(); + toast->window = window = gnt_vbox_new(FALSE); GNT_WIDGET_SET_FLAGS(window, GNT_WIDGET_TRANSIENT); GNT_WIDGET_UNSET_FLAGS(window, GNT_WIDGET_NO_BORDER); @@ -197,7 +203,7 @@ } prefs[] = { {PREFS_EVENT_SIGNONF, _("Buddy signs on/off")}, - {PREFS_EVENT_IM_MSG, _("You receive an IMs")}, + {PREFS_EVENT_IM_MSG, _("You receive an IM")}, {PREFS_EVENT_CHAT_MSG, _("Someone speaks in a chat")}, {PREFS_EVENT_CHAT_NICK, _("Someone says your name in a chat")}, {NULL, NULL} @@ -209,10 +215,16 @@ gaim_prefs_set_bool(key, gnt_tree_get_choice(tree, key)); } +static void +beep_toggled(GntCheckBox *check, gpointer null) +{ + gaim_prefs_set_bool(PREFS_BEEP, gnt_check_box_get_checked(check)); +} + static GntWidget * config_frame() { - GntWidget *window, *tree; + GntWidget *window, *tree, *check; int i; window = gnt_vbox_new(FALSE); @@ -236,6 +248,11 @@ gnt_tree_set_col_width(GNT_TREE(tree), 0, 40); g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(pref_toggled), NULL); + check = gnt_check_box_new(_("Beep too!")); + gnt_check_box_set_checked(GNT_CHECK_BOX(check), gaim_prefs_get_bool(PREFS_BEEP)); + g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(beep_toggled), NULL); + gnt_box_add_widget(GNT_BOX(window), check); + return window; } @@ -278,6 +295,8 @@ gaim_prefs_add_bool(PREFS_EVENT_IM_MSG, TRUE); gaim_prefs_add_bool(PREFS_EVENT_CHAT_MSG, TRUE); gaim_prefs_add_bool(PREFS_EVENT_CHAT_NICK, TRUE); + + gaim_prefs_add_bool(PREFS_BEEP, TRUE); } GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-17 01:06:31
|
Revision: 16801 Author: datallah Date: 2006-08-16 18:06:27 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16801&view=rev Log Message: ----------- Make the silc key permission checks safer and cover more cases (e.g. private key exists, but is not readable by you). Modified Paths: -------------- trunk/src/protocols/silc/util.c Modified: trunk/src/protocols/silc/util.c =================================================================== --- trunk/src/protocols/silc/util.c 2006-08-16 20:50:16 UTC (rev 16800) +++ trunk/src/protocols/silc/util.c 2006-08-17 01:06:27 UTC (rev 16801) @@ -234,25 +234,44 @@ } #endif - fd = open(file_private_key, O_RDONLY); - if ((g_stat(file_private_key, &st)) == -1) { + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } else if ((g_stat(file_private_key, &st)) == -1) { /* If file doesn't exist */ if (errno == ENOENT) { gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); - silc_create_key_pair(SILCGAIM_DEF_PKCS, + if (!silc_create_key_pair(SILCGAIM_DEF_PKCS, SILCGAIM_DEF_PKCS_LEN, file_public_key, file_private_key, NULL, (gc->password == NULL) ? "" : gc->password, - NULL, NULL, NULL, FALSE); - if (fd != -1) - close(fd); - fd = open(file_private_key, O_RDONLY); - g_stat(file_private_key, &st); + NULL, NULL, NULL, FALSE)) { + gaim_debug_error("silc", "Couldn't create key pair\n"); + return FALSE; + } + + if ((fd = g_open(file_private_key, O_RDONLY)) != -1) { + if ((fstat(fd, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + close(fd); + return FALSE; + } + } + /* This shouldn't really happen because silc_create_key_pair() + * will set the permissions */ + else if ((g_stat(file_private_key, &st)) == -1) { + gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", + file_private_key, strerror(errno)); + return FALSE; + } } else { gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, strerror(errno)); - if (fd != -1) - close(fd); return FALSE; } } @@ -270,7 +289,7 @@ if ((st.st_mode & 0777) != 0600) { gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" "Trying to change them ...\n", file_private_key); - if ((fd != -1) && (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { + if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { gaim_debug_error("silc", "Failed to change permissions for private key file!\n" "Permissions for your private key file must be 0600.\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-08-16 20:50:21
|
Revision: 16800 Author: seanegan Date: 2006-08-16 13:50:16 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16800&view=rev Log Message: ----------- segfault fix Modified Paths: -------------- trunk/src/gtkstatusbox.c Modified: trunk/src/gtkstatusbox.c =================================================================== --- trunk/src/gtkstatusbox.c 2006-08-16 19:38:57 UTC (rev 16799) +++ trunk/src/gtkstatusbox.c 2006-08-16 20:50:16 UTC (rev 16800) @@ -998,23 +998,28 @@ if (box->account) { GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(box->account)); - GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); - if (prplinfo->icon_spec.format) { - char *icon = gaim_gtk_convert_buddy_icon(plug, filename); - gaim_account_set_buddy_icon(box->account, icon); - g_free(icon); - gaim_account_set_ui_bool(box->account, GAIM_GTK_UI, "use-global-buddyicon", FALSE); + if (plug) { + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo && prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(box->account, icon); + g_free(icon); + gaim_account_set_ui_bool(box->account, GAIM_GTK_UI, "use-global-buddyicon", FALSE); + } } } else { for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { GaimAccount *account = accounts->data; GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(account)); - GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) && - prplinfo->icon_spec.format) { - char *icon = gaim_gtk_convert_buddy_icon(plug, filename); - gaim_account_set_buddy_icon(account, icon); - g_free(icon); + if (plug) { + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo != NULL && + gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) && + prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(account, icon); + g_free(icon); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-16 19:39:01
|
Revision: 16799 Author: sadrul Date: 2006-08-16 12:38:57 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16799&view=rev Log Message: ----------- Use the proper setting-name. "seanegan: sadrul: Looks good. You may want to set the non-global-buddyicon account setting if use-global-buddyicon is not set" Also, if the user sets the buddy-icon from a per-account box, it unsets the use-global-budduicon setting for that account. Modified Paths: -------------- trunk/src/gtkstatusbox.c Modified: trunk/src/gtkstatusbox.c =================================================================== --- trunk/src/gtkstatusbox.c 2006-08-16 19:21:04 UTC (rev 16798) +++ trunk/src/gtkstatusbox.c 2006-08-16 19:38:57 UTC (rev 16799) @@ -253,7 +253,8 @@ static void setup_icon_box(GtkGaimStatusBox *status_box) { - if (status_box->account) + if (status_box->account && + !gaim_account_get_ui_bool(status_box->account, GAIM_GTK_UI, "use-global-buddyicon", TRUE)) { char *string = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(status_box->account)); gtk_gaim_status_box_set_buddy_icon(status_box, string); @@ -1002,13 +1003,14 @@ char *icon = gaim_gtk_convert_buddy_icon(plug, filename); gaim_account_set_buddy_icon(box->account, icon); g_free(icon); + gaim_account_set_ui_bool(box->account, GAIM_GTK_UI, "use-global-buddyicon", FALSE); } } else { for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { GaimAccount *account = accounts->data; GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(account)); GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddy-icon", TRUE) && + if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddyicon", TRUE) && prplinfo->icon_spec.format) { char *icon = gaim_gtk_convert_buddy_icon(plug, filename); gaim_account_set_buddy_icon(account, icon); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2006-08-16 19:21:08
|
Revision: 16798 Author: sadrul Date: 2006-08-16 12:21:04 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16798&view=rev Log Message: ----------- Do not show the icon-box for an account if it doesn't support buddyicons in the per-account statusboxes. Allow the peraccount boxes to change the icon only for that account. Modified Paths: -------------- trunk/src/gtkblist.c trunk/src/gtkstatusbox.c Modified: trunk/src/gtkblist.c =================================================================== --- trunk/src/gtkblist.c 2006-08-16 19:05:07 UTC (rev 16797) +++ trunk/src/gtkblist.c 2006-08-16 19:21:04 UTC (rev 16798) @@ -4018,7 +4018,6 @@ gtkblist->statusbox = gtk_gaim_status_box_new(); gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->statusbox, FALSE, TRUE, 0); gtk_widget_set_name(gtkblist->statusbox, "gaim_gtkblist_statusbox"); - gtk_gaim_status_box_set_buddy_icon(gtkblist->statusbox, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); gtk_widget_show(gtkblist->statusbox); /* set the Show Offline Buddies option. must be done Modified: trunk/src/gtkstatusbox.c =================================================================== --- trunk/src/gtkstatusbox.c 2006-08-16 19:05:07 UTC (rev 16797) +++ trunk/src/gtkstatusbox.c 2006-08-16 19:21:04 UTC (rev 16798) @@ -78,6 +78,7 @@ static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); static void do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift); +static void icon_choose_cb(const char *filename, gpointer data); static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); @@ -220,7 +221,64 @@ update_to_reflect_account_status(status_box, account, newstatus); } +static gboolean +icon_box_press_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) +{ + if (box->buddy_icon_sel) { + gtk_window_present(GTK_WINDOW(box->buddy_icon_sel)); + return FALSE; + } + + box->buddy_icon_sel = gaim_gtk_buddy_icon_chooser_new(NULL, icon_choose_cb, box); + gtk_widget_show_all(box->buddy_icon_sel); + return FALSE; +} + +static gboolean +icon_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) +{ + gdk_window_set_cursor(widget->window, box->hand_cursor); + gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon_hover); + return FALSE; +} + +static gboolean +icon_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) +{ + gdk_window_set_cursor(widget->window, box->arrow_cursor); + gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon) ; + return FALSE; +} + static void +setup_icon_box(GtkGaimStatusBox *status_box) +{ + if (status_box->account) + { + char *string = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(status_box->account)); + gtk_gaim_status_box_set_buddy_icon(status_box, string); + g_free(string); + } + else + { + gtk_gaim_status_box_set_buddy_icon(status_box, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); + } + status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); + status_box->icon_box = gtk_event_box_new(); + status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); + status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); + + g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); + g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); + g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); + + gtk_container_add(GTK_CONTAINER(status_box->icon_box), status_box->icon); + + gtk_widget_show_all(status_box->icon_box); + gtk_widget_set_parent(status_box->icon_box, GTK_WIDGET(status_box)); +} + +static void gtk_gaim_status_box_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { @@ -236,10 +294,18 @@ statusbox->status_changed_signal = 0; } - if (statusbox->account) + if (statusbox->account) { + GaimPlugin *plug = gaim_plugins_find_with_id(gaim_account_get_protocol_id(statusbox->account)); + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo && prplinfo->icon_spec.format != NULL) { + setup_icon_box(statusbox); + } statusbox->status_changed_signal = gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", statusbox, GAIM_CALLBACK(account_status_changed_cb), statusbox); + } else { + setup_icon_box(statusbox); + } gtk_gaim_status_box_regenerate(statusbox); break; @@ -928,15 +994,27 @@ if (filename) { GList *accounts; - for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { - GaimAccount *account = accounts->data; - if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddy-icon", TRUE) && - GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(account)))->icon_spec.format) { - char *icon = gaim_gtk_convert_buddy_icon(gaim_find_prpl(gaim_account_get_protocol_id(account)), - filename); - gaim_account_set_buddy_icon(account, icon); + + if (box->account) { + GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(box->account)); + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(box->account, icon); g_free(icon); } + } else { + for (accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { + GaimAccount *account = accounts->data; + GaimPlugin *plug = gaim_find_prpl(gaim_account_get_protocol_id(account)); + GaimPluginProtocolInfo *prplinfo = GAIM_PLUGIN_PROTOCOL_INFO(plug); + if (gaim_account_get_ui_bool(account, GAIM_GTK_UI, "use-global-buddy-icon", TRUE) && + prplinfo->icon_spec.format) { + char *icon = gaim_gtk_convert_buddy_icon(plug, filename); + gaim_account_set_buddy_icon(account, icon); + g_free(icon); + } + } } gtk_gaim_status_box_set_buddy_icon(box, filename); } @@ -944,35 +1022,6 @@ box->buddy_icon_sel = NULL; } -static gboolean -icon_box_press_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) -{ - if (box->buddy_icon_sel) { - gtk_window_present(GTK_WINDOW(box->buddy_icon_sel)); - return FALSE; - } - - box->buddy_icon_sel = gaim_gtk_buddy_icon_chooser_new(NULL, icon_choose_cb, box); - gtk_widget_show_all(box->buddy_icon_sel); - return FALSE; -} - -static gboolean -icon_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) -{ - gdk_window_set_cursor(widget->window, box->hand_cursor); - gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon_hover); - return FALSE; -} - -static gboolean -icon_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, GtkGaimStatusBox *box) -{ - gdk_window_set_cursor(widget->window, box->arrow_cursor); - gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon) ; - return FALSE; -} - static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) { @@ -989,17 +1038,6 @@ status_box->vsep = gtk_vseparator_new(); status_box->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); - status_box->icon_box = gtk_event_box_new(); - status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); - status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); - g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); - g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); - - gtk_container_add(GTK_CONTAINER(status_box->icon_box), status_box->icon); - status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); @@ -1012,7 +1050,6 @@ gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0); gtk_widget_show_all(status_box->toggle_button); - gtk_widget_show_all(status_box->icon_box); #if GTK_CHECK_VERSION(2,4,0) gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE); #endif @@ -1063,7 +1100,6 @@ #endif gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); gtk_widget_set_parent(status_box->toggle_button, GTK_WIDGET(status_box)); - gtk_widget_set_parent(status_box->icon_box, GTK_WIDGET(status_box)); GTK_BIN(status_box)->child = status_box->toggle_button; gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); @@ -1167,35 +1203,37 @@ parent_alc = *allocation; parent_alc.height = MAX(1,req.height); parent_alc.y += 3; - parent_alc.width -= (parent_alc.height + 3); - combo_box_size_allocate(widget, &parent_alc); - icon_alc = *allocation; - icon_alc.height = MAX(1,req.height); - icon_alc.width = icon_alc.height; - icon_alc.x = allocation->width - icon_alc.width; - icon_alc.y += 3; + if (status_box->icon_box) + { + parent_alc.width -= (parent_alc.height + 3); + icon_alc = *allocation; + icon_alc.height = MAX(1,req.height); + icon_alc.width = icon_alc.height; + icon_alc.x = allocation->width - icon_alc.width; + icon_alc.y += 3; - if (status_box->icon_size != icon_alc.height) - { - if ((status_box->buddy_icon_path != NULL) && - (*status_box->buddy_icon_path != '\0')) + if (status_box->icon_size != icon_alc.height) { - scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, - icon_alc.height, icon_alc.width, FALSE, NULL); - g_object_unref(status_box->buddy_icon_hover); - status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); - do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); - g_object_unref(status_box->buddy_icon); - status_box->buddy_icon = scaled; - gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); + if ((status_box->buddy_icon_path != NULL) && + (*status_box->buddy_icon_path != '\0')) + { + scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, + icon_alc.height, icon_alc.width, FALSE, NULL); + g_object_unref(status_box->buddy_icon_hover); + status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); + do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); + g_object_unref(status_box->buddy_icon); + status_box->buddy_icon = scaled; + gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); + } + status_box->icon_size = icon_alc.height; } - status_box->icon_size = icon_alc.height; + gtk_widget_size_allocate(status_box->icon_box, &icon_alc); } - gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->icon_box, &icon_alc); - - gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->toggle_button, &parent_alc); + combo_box_size_allocate(widget, &parent_alc); + gtk_widget_size_allocate(status_box->toggle_button, &parent_alc); widget->allocation = *allocation; } @@ -1223,7 +1261,8 @@ (* callback) (status_box->vbox, callback_data); (* callback) (status_box->toggle_button, callback_data); (* callback) (status_box->arrow, callback_data); - (* callback) (status_box->icon_box, callback_data); + if (status_box->icon_box) + (* callback) (status_box->icon_box, callback_data); } combo_box_forall(container, include_internals, callback, callback_data); @@ -1232,7 +1271,7 @@ GtkWidget * gtk_gaim_status_box_new() { - return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); + return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", NULL, NULL); } GtkWidget * @@ -1353,7 +1392,8 @@ } } - gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); + if (box->account == NULL) + gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); } const char* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-08-16 19:05:13
|
Revision: 16797 Author: seanegan Date: 2006-08-16 12:05:07 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16797&view=rev Log Message: ----------- fixes Modified Paths: -------------- trunk/src/gtkstatusbox.c Modified: trunk/src/gtkstatusbox.c =================================================================== --- trunk/src/gtkstatusbox.c 2006-08-16 18:55:17 UTC (rev 16796) +++ trunk/src/gtkstatusbox.c 2006-08-16 19:05:07 UTC (rev 16797) @@ -989,7 +989,6 @@ status_box->vsep = gtk_vseparator_new(); status_box->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - status_box->buddy_icon = gdk_pixbuf_new_from_file("/home/seanegan/p1120233.jpg", NULL); status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); status_box->icon_box = gtk_event_box_new(); status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); @@ -1184,6 +1183,7 @@ { scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, icon_alc.height, icon_alc.width, FALSE, NULL); + g_object_unref(status_box->buddy_icon_hover); status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); g_object_unref(status_box->buddy_icon); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dat...@us...> - 2006-08-16 18:55:26
|
Revision: 16796 Author: datallah Date: 2006-08-16 11:55:17 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16796&view=rev Log Message: ----------- Fix bug #1541223 Modified Paths: -------------- trunk/src/protocols/simple/simple.c Modified: trunk/src/protocols/simple/simple.c =================================================================== --- trunk/src/protocols/simple/simple.c 2006-08-16 17:31:29 UTC (rev 16795) +++ trunk/src/protocols/simple/simple.c 2006-08-16 18:55:17 UTC (rev 16796) @@ -604,7 +604,7 @@ const gchar *body, struct sip_dialog *dialog, TransCallback tc) { struct simple_account_data *sip = gc->proto_data; char *callid = dialog ? g_strdup(dialog->callid) : gencallid(); - char *auth = ""; + char *auth = NULL; const char *addh = ""; gchar *branch = genbranch(); gchar *tag = NULL; @@ -662,7 +662,7 @@ ++sip->cseq, method, callid, - auth, + auth ? auth : "", addh, strlen(body), body); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |