pan-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pan-devel] Problems building and using under versions of Windows ol


From: GISQUET Christophe
Subject: Re: [Pan-devel] Problems building and using under versions of Windows older than XP
Date: Tue, 24 May 2005 04:34:34 +0200
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Lenny Nero wrote:
 I'm not at the computer I do all my MinGW stuff, but the "freeaddrinfo"
was what I gave up on some time ago and feel that this is the reason why
the windows builds have stopped, others cant sort it either :(

It seems Windows 2000 hasn't a clear support for the *addrinfo, in spite of them being strings in wininet.dll

For the time being, I've tried to emulate it with gethostbyname and filling structs myself. With some code tweaking (*), it compiles and starts fine. The host is properly found and the socket seems to be properly opened, in particular with the proper IP. Unfortunately, probably due to my very limited knowledge of sockets , no data gets through when updating newsgroup list.

Its a shame as Pan was starting to look good, but I cant run to another
OS just because of that.

Matter of choices. Let's not debate about OSes.

(*) The attached patch corrects all of these:
- unknow SEEK_CUR in gmime stuff
- problem with DEFAULT_WEB_BROWSER not defined (unsatisfactory hack)
- use of gethostbyname and friends in place of getaddrinfo and friends
- segmentation fault in dialog-newuser.c because either pan_get_local_fqdn () or g_get_user_name() returns NULL and therefore the email can't be properly generated
Index: gmime/gmime-stream.h
===================================================================
RCS file: /cvs/gnome/pan/gmime/gmime-stream.h,v
retrieving revision 1.7
diff -B -b -d -u -r1.7 gmime-stream.h
--- gmime/gmime-stream.h        30 Dec 2002 16:37:57 -0000      1.7
+++ gmime/gmime-stream.h        24 May 2005 02:06:31 -0000
@@ -33,6 +33,9 @@
 #include <glib-object.h>
 #include <sys/types.h>
 #include <unistd.h>
+#ifdef _WIN32
+#  include <stdio.h>
+#endif
 #include <stdarg.h>
 
 #include "gmime-type-utils.h"
Index: pan/prefs.c
===================================================================
RCS file: /cvs/gnome/pan/pan/prefs.c,v
retrieving revision 1.371
diff -B -b -d -u -r1.371 prefs.c
--- pan/prefs.c 17 Mar 2005 06:12:15 -0000      1.371
+++ pan/prefs.c 24 May 2005 02:06:31 -0000
@@ -869,13 +869,14 @@
        replace_gstr (&external_editor, pan_config_get_string (KEY_APP_EDITOR, 
DEFAULT_EXTERNAL_EDITOR));
 
        replace_gstr (&external_web_browser, pan_config_get_string 
(KEY_APP_BROWSER, NULL));
+#ifndef _WIN32
        if (!external_web_browser) {
                const char * browser = g_getenv ("BROWSER");
                if (!is_nonempty_string(browser))
                        browser = DEFAULT_WEB_BROWSER;
                external_web_browser = g_strdup (browser);
        }
-
+#endif
        /* mail server preferences */
 
        replace_gstr (&mail_server_address, pan_config_get_string 
("/Pan/Mail/smtp_address", DEFAULT_VALUE_SMTP_ADDRESS));
Index: pan/sockets.c
===================================================================
RCS file: /cvs/gnome/pan/pan/sockets.c,v
retrieving revision 1.127
diff -B -b -d -u -r1.127 sockets.c
--- pan/sockets.c       15 Dec 2004 20:54:47 -0000      1.127
+++ pan/sockets.c       24 May 2005 02:06:31 -0000
@@ -80,15 +80,69 @@
        int sockfd;
        char hostbuf[128];
        char portbuf[32];
+#ifdef _WIN32
+       struct hostent* ans;
+       struct sockaddr_in server;
+       int i;
+#else
        struct addrinfo hints, *ans;
+        GList * l=NULL, *list=NULL, *ipv4_list=NULL, *ipv6_list=NULL;
+#endif
        GIOStatus status;
        GIOChannel * channel;
-        GList * l=NULL, *list=NULL, *ipv4_list=NULL, *ipv6_list=NULL;
 
        ensure_module_inited ();
 
        /* get an addrinfo for the host */
        g_snprintf (hostbuf, sizeof(hostbuf), "%*.*s", host->len, host->len, 
host->str);
+#ifdef _WIN32
+       /* Try opening scoket */
+       sockfd = socket (AF_INET, SOCK_STREAM, 0 /*IPPROTO_TCP*/);
+       if (sockfd < 0) {
+               g_message ("couldn't create a socket.");
+               return NULL;
+       }
+
+       /* Get host */
+       OutputDebugString (hostbuf);
+       if (!isalpha(hostbuf[0]))
+               ans = gethostbyaddr(hostbuf, host->len, AF_INET);
+       else
+               ans = gethostbyname(hostbuf);
+       if (WSAGetLastError())
+       {
+               if (WSAGetLastError() == 11001)
+                       g_message("Host not found...");
+               else
+                       g_message("Winsock error %li.\n", WSAGetLastError());   
+               return NULL;
+       }
+
+       /* Try connecting */
+       i = 0;
+       err = -1;
+       while (err<0 && ans->h_addr_list[i])
+       {
+               unsigned char *addr = ans->h_addr_list[i];
+               server.sin_addr.s_addr=*((unsigned long*)addr);
+               server.sin_family=AF_INET;
+               server.sin_port=htons(port);
+               g_snprintf(hostbuf, sizeof(hostbuf),
+                          "Trying host %u.%u.%u.%u, port %d\n",
+                          addr[0], addr[1], addr[2], addr[3], port);
+               OutputDebugString (hostbuf);
+               err = connect (sockfd,(struct sockaddr*)&server, 
sizeof(server));
+               i++;
+       }
+       
+       if (err < 0)
+       {
+               g_message ("Connect failed: %s", g_strerror(errno));
+               return NULL;
+       }
+       else
+               OutputDebugString ("Connection seems to be opened");
+#else
        g_snprintf (portbuf, sizeof(portbuf), "%d", port);
        memset (&hints, 0, sizeof(struct addrinfo));
        hints.ai_flags = 0;
@@ -142,6 +196,8 @@
                freeaddrinfo (ans);
                return NULL;
        }
+       freeaddrinfo (ans);
+#endif
 
        channel = g_io_channel_unix_new (sockfd);
 #ifndef G_OS_WIN32
@@ -153,7 +209,6 @@
        g_io_channel_set_line_term (channel, "\n", 1);
        log_add_va (LOG_INFO, _("New connection %p for %s, port %d"), channel, 
hostbuf, port);
 
-       freeaddrinfo (ans);
        return channel;
 }
 
Index: pan/util.c
===================================================================
RCS file: /cvs/gnome/pan/pan/util.c,v
retrieving revision 1.254
diff -B -b -d -u -r1.254 util.c
--- pan/util.c  2 May 2005 21:37:50 -0000       1.254
+++ pan/util.c  24 May 2005 02:06:31 -0000
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <time.h>
 
-#ifdef G_OS_WIN32
+#ifdef _WIN32
 #include <windows.h> /* for ShellExecute */
 #endif
 
Index: pan/dialogs/dialog-newuser.c
===================================================================
RCS file: /cvs/gnome/pan/pan/dialogs/dialog-newuser.c,v
retrieving revision 1.61
diff -B -b -d -u -r1.61 dialog-newuser.c
--- pan/dialogs/dialog-newuser.c        10 Dec 2004 17:52:51 -0000      1.61
+++ pan/dialogs/dialog-newuser.c        24 May 2005 02:06:31 -0000
@@ -116,8 +116,13 @@
 
        if (!email) {
                char * fqdn = pan_get_local_fqdn ();
+               const char * user_name = g_get_user_name();
+               if (user_name && fqdn)
                replace_gstr (&email,
-                       g_strdup_printf ("address@hidden", g_get_user_name(), 
fqdn));
+                                     g_strdup_printf ("address@hidden", 
user_name, fqdn));
+               else
+                       replace_gstr (&email,
+                                     g_strdup("address@hidden"));
                g_strstrip (email);
                g_free (fqdn);
        }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]