~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to xfce4-session/xfsm-dns.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: xfsm-dns.c 4771 2005-01-12 15:25:24Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *                                                                              
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *                                                                              
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 *
 
21
 * Parts of this file where taken from gnome-session/main.c, which
 
22
 * was written by Tom Tromey.
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#ifdef HAVE_SYS_TYPES_H
 
30
#include <sys/types.h>
 
31
#endif
 
32
#ifdef HAVE_SYS_SOCKET_H
 
33
#include <sys/socket.h>
 
34
#endif
 
35
#ifdef HAVE_SYS_UTSNAME_H
 
36
#include <sys/utsname.h>
 
37
#endif
 
38
 
 
39
#ifdef HAVE_MEMORY_H
 
40
#include <memory.h>
 
41
#endif
 
42
#ifdef HAVE_NETDB_H
 
43
#include <netdb.h>
 
44
#endif
 
45
#ifdef HAVE_STRING_H
 
46
#include <string.h>
 
47
#endif
 
48
#ifdef HAVE_UNISTD_H
 
49
#include <unistd.h>
 
50
#endif
 
51
 
 
52
#include <gtk/gtk.h>
 
53
 
 
54
#include <libxfcegui4/libxfcegui4.h>
 
55
 
 
56
#include <libxfsm/xfsm-util.h>
 
57
 
 
58
#include <xfce4-session/xfsm-global.h>
 
59
 
 
60
 
 
61
static gchar*
 
62
queryhostname (gchar *buffer, gsize length, gboolean readable)
 
63
{
 
64
#ifdef HAVE_GETHOSTNAME
 
65
  if (gethostname (buffer, length) == 0)
 
66
    return buffer;
 
67
#else
 
68
  struct utsname utsname;
 
69
  if (uname (&utsname) == 0)
 
70
    {
 
71
      g_strlcpy (buffer, utsname.nodename, length);
 
72
      return buffer;
 
73
    }
 
74
#endif
 
75
  if (readable)
 
76
    {
 
77
      g_strlcpy (buffer, _("(Unknown)"), length);
 
78
      return buffer;
 
79
    }
 
80
  return NULL;
 
81
}
 
82
 
 
83
 
 
84
static gboolean
 
85
check_for_dns (void)
 
86
{
 
87
#ifdef HAVE_GETADDRINFO
 
88
  struct addrinfo *result = NULL;
 
89
  struct addrinfo  hints;
 
90
#endif
 
91
  char   buffer[256];
 
92
  gchar *hostname;
 
93
 
 
94
  hostname = queryhostname (buffer, 256, FALSE);
 
95
  if (hostname == NULL)
 
96
    return FALSE;
 
97
 
 
98
#ifdef HAVE_GETADDRINFO
 
99
  bzero (&hints, sizeof (hints));
 
100
  hints.ai_socktype = SOCK_STREAM;
 
101
  hints.ai_flags = AI_CANONNAME;
 
102
 
 
103
  if (getaddrinfo (hostname, NULL, &hints, &result) != 0)
 
104
    return FALSE;
 
105
 
 
106
  if (g_ascii_strncasecmp (result->ai_canonname, hostname, 0) != 0)
 
107
    return FALSE;
 
108
#else
 
109
#ifdef HAVE_GETHOSTBYNAME
 
110
  if (gethostbyname (hostname) == NULL)
 
111
    {
 
112
      return FALSE;
 
113
    }
 
114
#endif
 
115
#endif
 
116
 
 
117
  return TRUE;
 
118
}
 
119
 
 
120
 
 
121
enum
 
122
{
 
123
  RESPONSE_LOG_IN,
 
124
  RESPONSE_TRY_AGAIN,
 
125
};
 
126
 
 
127
 
 
128
void
 
129
xfsm_dns_check (void)
 
130
{
 
131
  GtkWidget *msgbox = NULL;
 
132
  gchar      hostname[256];
 
133
  gint       response;
 
134
 
 
135
  while (!check_for_dns ())
 
136
    {
 
137
      if (msgbox == NULL)
 
138
        {
 
139
          queryhostname (hostname, 256, TRUE);
 
140
 
 
141
          msgbox = gtk_message_dialog_new (NULL, 0,
 
142
                                           GTK_MESSAGE_WARNING,
 
143
                                           GTK_BUTTONS_NONE,
 
144
                                           _("Could not look up internet address for %s.\n"
 
145
                                             "This will prevent Xfce from operating correctly.\n"
 
146
                                             "It may be possible to correct the problem by adding\n"
 
147
                                             "%s to the file /etc/hosts on your system."),
 
148
                                           hostname, hostname);
 
149
 
 
150
          gtk_dialog_add_buttons (GTK_DIALOG (msgbox),
 
151
                                  _("Continue anyway"), RESPONSE_LOG_IN,
 
152
                                  _("Try again"), RESPONSE_TRY_AGAIN,
 
153
                                  NULL);
 
154
 
 
155
          xfsm_window_add_border (GTK_WINDOW (msgbox));
 
156
          xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (msgbox));
 
157
        }
 
158
 
 
159
      gtk_dialog_set_default_response (GTK_DIALOG (msgbox), RESPONSE_TRY_AGAIN);
 
160
 
 
161
      response = xfsm_splash_screen_run (splash_screen, msgbox);
 
162
      if (response != RESPONSE_TRY_AGAIN)
 
163
        break;
 
164
 
 
165
      gtk_widget_hide (msgbox);
 
166
    }
 
167
 
 
168
  if (msgbox != NULL)
 
169
    gtk_widget_destroy (msgbox);
 
170
}
 
171
 
 
172