Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 68390
Collapse All | Expand All

(-)netapplet-1.0.0/ChangeLog.gentoo (+88 lines)
Line 0 Link Here
1
2005-01-08  Richard Ferguson  <gentoo@fergusnet.com>
2
	
3
	* src/netdaemon.c: reworked get_interfaces to read /proc/net/dev instead
4
					   of parsing /etc/conf.d/net.  This is needed because the
5
					   new net scripts don't need to have an entry in the
6
					   conf.d/net file.  The default is always dhcp.
7
	
8
	* src/netapplet.c: added some logic to the other_essid function to 
9
					   properly handle existing keys for given essid's
10
	
11
2004-12-31  Richard Ferguson  <gentoo@fergusnet.com>
12
	
13
	* src/netdaemon.c: added some new code to clear the essid stored
14
					   in the wireless file after an association is made.
15
					   we do this because not having an essid defined is
16
					   a better default then having an essid defined that 
17
					   is not available.
18
	
19
	* src/netapplet.c: Same as above, plus some general code cleanups.
20
	
21
2004-12-30  Richard Ferguson  <gentoo@fergusnet.com>
22
	
23
	* src/netdaemon.c: implemented new get_keys handler for new
24
					   encryption key code.  Updated essid hanlder
25
					   for new key maniplulation option.  Also removed
26
					   support for direct iwconfig execution.  This new
27
					   release will depend on wireless-config or the new
28
					   baselayout code.
29
	
30
	* src/netapplet.c: implemented new key code to remove requirement
31
					   on gnome-keyring.
32
33
	* src/netcommon.c: moved a few functions to here that can be used
34
					   by both applet and daemon
35
36
2004-12-23  Richard Ferguson  <gentoo@fergusnet.com>
37
	
38
	* src/netdaemon.c: fixed syntax of how the wireless file is saved.
39
					   Cleaned up essid/key argument excaping.
40
	
41
	* src/netapplet.c: changed listing of preferred aps to a sub menu
42
					   to not clutter the main menu.  Also increased the
43
					   limit to 10.  Cleaned up a few places where strings
44
					   were getting transmitted without proper escaping.
45
46
2004-12-22  Richard Ferguson  <gentoo@fergusnet.com>
47
	
48
	* src/netdaemon.c: implemented gentoo preferred aps behavior
49
	
50
	* src/netapplet.c: implemented gentoo preferred aps behavior, a list of
51
					   the last five aps you successfully connected to 
52
53
2004-12-16  Richard Ferguson  <gentoo@fergusnet.com>
54
	
55
	* src/netdaemon.c: fix a few issues with regards to active interfaces
56
	
57
					   general clean up of gentoo additions
58
					   
59
	* src/netapplet.c: more work on the new wireless behavior.  Should be
60
					   working semi reliably.  let me know if you run into
61
					   problems
62
					   
63
					   general clean up of gentoo additions
64
	
65
2004-12-15  Richard Ferguson  <gentoo@fergusnet.com>
66
	
67
	* src/netdaemon.c: removed skip_poll completely
68
	
69
					   clean up poll_interfaces function
70
					   
71
					   added call to netdaemon_do_change_active() for direct 
72
					   iwconfig mode to get a new ip
73
					   
74
					   fixed a few memory leaks in netdaemon_do_change_essid()
75
					   
76
	* src/netapplet.c: first attempt at showing the available accesspoints
77
					   even when the wireless connection is not active.  This 
78
					   has a known limitation of only supporting a single
79
					   wireless interface
80
81
82
2004-12-15  Richard Ferguson  <gentoo@fergusnet.com>
83
84
	* ported existing 0.98.0 patch to new 1.0.0 release.
85
	
86
YYYY-MM-DD  NAME  <email>
87
88
	* file: change
(-)netapplet-1.0.0/config.h.in (+9 lines)
Lines 6-11 Link Here
6
/* Name of default gettext domain */
6
/* Name of default gettext domain */
7
#undef GETTEXT_PACKAGE
7
#undef GETTEXT_PACKAGE
8
8
9
/* gst network-admin executable path */
10
#undef GST_NETWORKADMIN_PATH
11
12
/* gst network-admin installed */
13
#undef GST_NETWORKADMIN_TOOL
14
9
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
15
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
10
#undef HAVE_BIND_TEXTDOMAIN_CODESET
16
#undef HAVE_BIND_TEXTDOMAIN_CODESET
11
17
Lines 63-68 Link Here
63
/* Minor Version Number */
69
/* Minor Version Number */
64
#undef MINOR_VERSION
70
#undef MINOR_VERSION
65
71
72
/* network configuration enabled */
73
#undef NETWORK_CONF_TOOL
74
66
/* Name of package */
75
/* Name of package */
67
#undef PACKAGE
76
#undef PACKAGE
68
77
(-)netapplet-1.0.0/configure (-9 / +74 lines)
Lines 309-315 Link Here
309
# include <unistd.h>
309
# include <unistd.h>
310
#endif"
310
#endif"
311
311
312
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot MAJOR_VERSION MINOR_VERSION MICRO_VERSION MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP GETTEXT_PACKAGE INTLTOOL_DESKTOP_RULE INTLTOOL_DIRECTORY_RULE INTLTOOL_KEYS_RULE INTLTOOL_PROP_RULE INTLTOOL_OAF_RULE INTLTOOL_PONG_RULE INTLTOOL_SERVER_RULE INTLTOOL_SHEET_RULE INTLTOOL_SOUNDLIST_RULE INTLTOOL_UI_RULE INTLTOOL_XAM_RULE INTLTOOL_KBD_RULE INTLTOOL_XML_RULE INTLTOOL_CAVES_RULE INTLTOOL_SCHEMAS_RULE INTLTOOL_THEME_RULE INTLTOOL_EXTRACT INTLTOOL_MERGE INTLTOOL_UPDATE INTLTOOL_PERL USE_NLS MSGFMT GMSGFMT XGETTEXT CATALOGS CATOBJEXT DATADIRNAME GMOFILES INSTOBJEXT INTLLIBS PO_IN_DATADIR_TRUE PO_IN_DATADIR_FALSE POFILES POSUB PKG_CONFIG NETAPPLET_CFLAGS NETAPPLET_LIBS NETDAEMON_CFLAGS NETDAEMON_LIBS LIBOBJS LTLIBOBJS'
312
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot MAJOR_VERSION MINOR_VERSION MICRO_VERSION MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP GETTEXT_PACKAGE INTLTOOL_DESKTOP_RULE INTLTOOL_DIRECTORY_RULE INTLTOOL_KEYS_RULE INTLTOOL_PROP_RULE INTLTOOL_OAF_RULE INTLTOOL_PONG_RULE INTLTOOL_SERVER_RULE INTLTOOL_SHEET_RULE INTLTOOL_SOUNDLIST_RULE INTLTOOL_UI_RULE INTLTOOL_XAM_RULE INTLTOOL_KBD_RULE INTLTOOL_XML_RULE INTLTOOL_CAVES_RULE INTLTOOL_SCHEMAS_RULE INTLTOOL_THEME_RULE INTLTOOL_EXTRACT INTLTOOL_MERGE INTLTOOL_UPDATE INTLTOOL_PERL USE_NLS MSGFMT GMSGFMT XGETTEXT CATALOGS CATOBJEXT DATADIRNAME GMOFILES INSTOBJEXT INTLLIBS PO_IN_DATADIR_TRUE PO_IN_DATADIR_FALSE POFILES POSUB PKG_CONFIG NETAPPLET_CFLAGS NETAPPLET_LIBS NETDAEMON_CFLAGS NETDAEMON_LIBS NETWORKADMIN_TOOL LIBOBJS LTLIBOBJS'
313
ac_subst_files=''
313
ac_subst_files=''
314
314
315
# Initialize some variables set by options.
315
# Initialize some variables set by options.
Lines 6059-6081 Link Here
6059
  else
6059
  else
6060
     PKG_CONFIG_MIN_VERSION=0.9.0
6060
     PKG_CONFIG_MIN_VERSION=0.9.0
6061
     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
6061
     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
6062
        echo "$as_me:$LINENO: checking for libgnomeui-2.0 libglade-2.0 gnome-keyring-1" >&5
6062
        echo "$as_me:$LINENO: checking for libgnomeui-2.0 libglade-2.0" >&5
6063
echo $ECHO_N "checking for libgnomeui-2.0 libglade-2.0 gnome-keyring-1... $ECHO_C" >&6
6063
echo $ECHO_N "checking for libgnomeui-2.0 libglade-2.0... $ECHO_C" >&6
6064
6064
6065
        if $PKG_CONFIG --exists "libgnomeui-2.0 libglade-2.0 gnome-keyring-1" ; then
6065
        if $PKG_CONFIG --exists "libgnomeui-2.0 libglade-2.0" ; then
6066
            echo "$as_me:$LINENO: result: yes" >&5
6066
            echo "$as_me:$LINENO: result: yes" >&5
6067
echo "${ECHO_T}yes" >&6
6067
echo "${ECHO_T}yes" >&6
6068
            succeeded=yes
6068
            succeeded=yes
6069
6069
6070
            echo "$as_me:$LINENO: checking NETAPPLET_CFLAGS" >&5
6070
            echo "$as_me:$LINENO: checking NETAPPLET_CFLAGS" >&5
6071
echo $ECHO_N "checking NETAPPLET_CFLAGS... $ECHO_C" >&6
6071
echo $ECHO_N "checking NETAPPLET_CFLAGS... $ECHO_C" >&6
6072
            NETAPPLET_CFLAGS=`$PKG_CONFIG --cflags "libgnomeui-2.0 libglade-2.0 gnome-keyring-1"`
6072
            NETAPPLET_CFLAGS=`$PKG_CONFIG --cflags "libgnomeui-2.0 libglade-2.0"`
6073
            echo "$as_me:$LINENO: result: $NETAPPLET_CFLAGS" >&5
6073
            echo "$as_me:$LINENO: result: $NETAPPLET_CFLAGS" >&5
6074
echo "${ECHO_T}$NETAPPLET_CFLAGS" >&6
6074
echo "${ECHO_T}$NETAPPLET_CFLAGS" >&6
6075
6075
6076
            echo "$as_me:$LINENO: checking NETAPPLET_LIBS" >&5
6076
            echo "$as_me:$LINENO: checking NETAPPLET_LIBS" >&5
6077
echo $ECHO_N "checking NETAPPLET_LIBS... $ECHO_C" >&6
6077
echo $ECHO_N "checking NETAPPLET_LIBS... $ECHO_C" >&6
6078
            NETAPPLET_LIBS=`$PKG_CONFIG --libs "libgnomeui-2.0 libglade-2.0 gnome-keyring-1"`
6078
            NETAPPLET_LIBS=`$PKG_CONFIG --libs "libgnomeui-2.0 libglade-2.0"`
6079
            echo "$as_me:$LINENO: result: $NETAPPLET_LIBS" >&5
6079
            echo "$as_me:$LINENO: result: $NETAPPLET_LIBS" >&5
6080
echo "${ECHO_T}$NETAPPLET_LIBS" >&6
6080
echo "${ECHO_T}$NETAPPLET_LIBS" >&6
6081
        else
6081
        else
Lines 6083-6089 Link Here
6083
            NETAPPLET_LIBS=""
6083
            NETAPPLET_LIBS=""
6084
            ## If we have a custom action on failure, don't print errors, but
6084
            ## If we have a custom action on failure, don't print errors, but
6085
            ## do set a variable so people can do so.
6085
            ## do set a variable so people can do so.
6086
            NETAPPLET_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libgnomeui-2.0 libglade-2.0 gnome-keyring-1"`
6086
            NETAPPLET_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libgnomeui-2.0 libglade-2.0"`
6087
            echo $NETAPPLET_PKG_ERRORS
6087
            echo $NETAPPLET_PKG_ERRORS
6088
        fi
6088
        fi
6089
6089
Lines 6098-6105 Link Here
6098
  if test $succeeded = yes; then
6098
  if test $succeeded = yes; then
6099
     :
6099
     :
6100
  else
6100
  else
6101
     { { echo "$as_me:$LINENO: error: Library requirements (libgnomeui-2.0 libglade-2.0 gnome-keyring-1) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&5
6101
     { { echo "$as_me:$LINENO: error: Library requirements (libgnomeui-2.0 libglade-2.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&5
6102
echo "$as_me: error: Library requirements (libgnomeui-2.0 libglade-2.0 gnome-keyring-1) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&2;}
6102
echo "$as_me: error: Library requirements (libgnomeui-2.0 libglade-2.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them." >&2;}
6103
   { (exit 1); exit 1; }; }
6103
   { (exit 1); exit 1; }; }
6104
  fi
6104
  fi
6105
6105
Lines 6573-6578 Link Here
6573
  fi
6573
  fi
6574
fi
6574
fi
6575
6575
6576
6577
### check for network-admin from gnome system tools package
6578
6579
# Extract the first word of "network-admin", so it can be a program name with args.
6580
set dummy network-admin; ac_word=$2
6581
echo "$as_me:$LINENO: checking for $ac_word" >&5
6582
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
6583
if test "${ac_cv_path_NETWORKADMIN_TOOL+set}" = set; then
6584
  echo $ECHO_N "(cached) $ECHO_C" >&6
6585
else
6586
  case $NETWORKADMIN_TOOL in
6587
  [\\/]* | ?:[\\/]*)
6588
  ac_cv_path_NETWORKADMIN_TOOL="$NETWORKADMIN_TOOL" # Let the user override the test with a path.
6589
  ;;
6590
  *)
6591
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6592
for as_dir in $PATH
6593
do
6594
  IFS=$as_save_IFS
6595
  test -z "$as_dir" && as_dir=.
6596
  for ac_exec_ext in '' $ac_executable_extensions; do
6597
  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6598
    ac_cv_path_NETWORKADMIN_TOOL="$as_dir/$ac_word$ac_exec_ext"
6599
    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
6600
    break 2
6601
  fi
6602
done
6603
done
6604
6605
  ;;
6606
esac
6607
fi
6608
NETWORKADMIN_TOOL=$ac_cv_path_NETWORKADMIN_TOOL
6609
6610
if test -n "$NETWORKADMIN_TOOL"; then
6611
  echo "$as_me:$LINENO: result: $NETWORKADMIN_TOOL" >&5
6612
echo "${ECHO_T}$NETWORKADMIN_TOOL" >&6
6613
else
6614
  echo "$as_me:$LINENO: result: no" >&5
6615
echo "${ECHO_T}no" >&6
6616
fi
6617
6618
if test "x${NETWORKADMIN_TOOL}" = "x"; then
6619
	{ echo "$as_me:$LINENO: WARNING: network-admin executable not found in your path" >&5
6620
echo "$as_me: WARNING: network-admin executable not found in your path" >&2;}
6621
else
6622
6623
cat >>confdefs.h <<\_ACEOF
6624
#define NETWORK_CONF_TOOL 1
6625
_ACEOF
6626
6627
6628
cat >>confdefs.h <<\_ACEOF
6629
#define GST_NETWORKADMIN_TOOL 1
6630
_ACEOF
6631
6632
6633
cat >>confdefs.h <<_ACEOF
6634
#define GST_NETWORKADMIN_PATH "${NETWORKADMIN_TOOL}"
6635
_ACEOF
6636
6637
fi
6638
6639
6576
### build makefiles
6640
### build makefiles
6577
6641
6578
                                                            ac_config_files="$ac_config_files Makefile icons/Makefile icons/16x16/Makefile icons/24x24/Makefile src/Makefile po/Makefile.in"
6642
                                                            ac_config_files="$ac_config_files Makefile icons/Makefile icons/16x16/Makefile icons/24x24/Makefile src/Makefile po/Makefile.in"
Lines 7327-7332 Link Here
7327
s,@NETAPPLET_LIBS@,$NETAPPLET_LIBS,;t t
7391
s,@NETAPPLET_LIBS@,$NETAPPLET_LIBS,;t t
7328
s,@NETDAEMON_CFLAGS@,$NETDAEMON_CFLAGS,;t t
7392
s,@NETDAEMON_CFLAGS@,$NETDAEMON_CFLAGS,;t t
7329
s,@NETDAEMON_LIBS@,$NETDAEMON_LIBS,;t t
7393
s,@NETDAEMON_LIBS@,$NETDAEMON_LIBS,;t t
7394
s,@NETWORKADMIN_TOOL@,$NETWORKADMIN_TOOL,;t t
7330
s,@LIBOBJS@,$LIBOBJS,;t t
7395
s,@LIBOBJS@,$LIBOBJS,;t t
7331
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
7396
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
7332
CEOF
7397
CEOF
(-)netapplet-1.0.0/configure.in (-1 / +14 lines)
Lines 40-46 Link Here
40
40
41
### get cflags and libs
41
### get cflags and libs
42
42
43
PKG_CHECK_MODULES(NETAPPLET, libgnomeui-2.0 libglade-2.0 gnome-keyring-1)
43
PKG_CHECK_MODULES(NETAPPLET, libgnomeui-2.0 libglade-2.0)
44
PKG_CHECK_MODULES(NETDAEMON, glib-2.0)
44
PKG_CHECK_MODULES(NETDAEMON, glib-2.0)
45
45
46
### look for iwlib
46
### look for iwlib
Lines 93-98 Link Here
93
  fi
93
  fi
94
fi
94
fi
95
95
96
97
### check for network-admin from gnome system tools package
98
99
AC_PATH_PROG(NETWORKADMIN_TOOL, network-admin)
100
if test "x${NETWORKADMIN_TOOL}" = "x"; then
101
	AC_MSG_WARN([network-admin executable not found in your path])
102
else
103
	AC_DEFINE(NETWORK_CONF_TOOL, 1, [network configuration enabled])
104
    AC_DEFINE(GST_NETWORKADMIN_TOOL, 1, [gst network-admin installed])
105
    AC_DEFINE_UNQUOTED(GST_NETWORKADMIN_PATH, "${NETWORKADMIN_TOOL}", [gst network-admin executable path])
106
fi
107
	  
108
96
### build makefiles
109
### build makefiles
97
110
98
AC_OUTPUT([
111
AC_OUTPUT([
(-)netapplet-1.0.0/netapplet.desktop (-1 / +2 lines)
Lines 25-34 Link Here
25
Comment[pt_BR]=Mini-Aplicativo do Painel do Seletor de Rede
25
Comment[pt_BR]=Mini-Aplicativo do Painel do Seletor de Rede
26
Comment[zh_CN]=网络选择器面板小程序
26
Comment[zh_CN]=网络选择器面板小程序
27
Comment[zh_TW]=網路選擇器面板程式
27
Comment[zh_TW]=網路選擇器面板程式
28
Categories=GNOME;Application;System;Utility;
29
Encoding=UTF-8
28
Exec=netapplet
30
Exec=netapplet
29
Icon=netapplet.png
31
Icon=netapplet.png
30
Terminal=false
32
Terminal=false
31
Type=Application
33
Type=Application
32
TryExec=netapplet
34
TryExec=netapplet
33
Categories=GNOME;Application;Internet;X-Ximian-Main;
34
StartupNotify=false
35
StartupNotify=false
(-)netapplet-1.0.0/src/netapplet.c (-339 / +447 lines)
Lines 21-27 Link Here
21
#include <errno.h>
21
#include <errno.h>
22
#include <gnome.h>
22
#include <gnome.h>
23
#include <glade/glade-xml.h>
23
#include <glade/glade-xml.h>
24
#include <gnome-keyring.h>
25
24
26
#include "eggtrayicon.h"
25
#include "eggtrayicon.h"
27
#include "netcommon.h"
26
#include "netcommon.h"
Lines 39-58 Link Here
39
# define N_(String) (String)
38
# define N_(String) (String)
40
#endif
39
#endif
41
40
42
#define ETHERNET_ICON		"gnome-dev-ethernet"
41
#define ETHERNET_ICON	"gnome-dev-ethernet"
43
#define DIALUP_ICON		"gnome-dev-modem"
42
#define DIALUP_ICON		"gnome-dev-modem"
44
#define WIRELESS_ICON_0         "wireless-tower-0"
43
#define WIRELESS_ICON_0	"wireless-tower-0"
45
#define WIRELESS_ICON_1         "wireless-tower-1"
44
#define WIRELESS_ICON_1	"wireless-tower-1"
46
#define WIRELESS_ICON_2         "wireless-tower-2"
45
#define WIRELESS_ICON_2	"wireless-tower-2"
47
#define WIRELESS_ICON_3         "wireless-tower-3"
46
#define WIRELESS_ICON_3	"wireless-tower-3"
48
#define WIRELESS_ICON_4         "wireless-tower-4"
47
#define WIRELESS_ICON_4	"wireless-tower-4"
49
#define DISCONNECT_ICON		"stock_calc-cancel"
48
#define DISCONNECT_ICON	"stock_calc-cancel"
50
#define BROKEN_ICON		"stock_calc-cancel"
49
#define BROKEN_ICON		"stock_calc-cancel"
51
#define UNKNOWN_ICON            "stock_unknown"
50
#define UNKNOWN_ICON	"stock_unknown"
52
51
53
#define GLADE_APPLET		GLADEDIR "/netapplet.glade"
52
#define GLADE_APPLET	GLADEDIR "/netapplet.glade"
54
53
55
#define YAST2_ARGV { "/opt/kde3/bin/kdesu", "-n", "/sbin/yast2", "lan", NULL }
54
#define MAX_PREFERRED_APS 10
56
55
57
typedef struct {
56
typedef struct {
58
	char *interface;	/* interface name, e.g. eth0 */
57
	char *interface;	/* interface name, e.g. eth0 */
Lines 61-74 Link Here
61
} Connection;
60
} Connection;
62
61
63
typedef struct {
62
typedef struct {
64
	double strength;	/* wireless quality, should be [0.0, 1.0) */
63
	double strength;		/* wireless quality, should be [0.0, 1.0) */
65
	char *essid;		/* ESSID name */
64
	char *essid;			/* ESSID name */
66
	gboolean is_encrypted;	/* is this network encrypted ? */
65
	gboolean is_encrypted;	/* is this network encrypted ? */
67
} Accesspoint;
66
} Accesspoint;
68
67
69
typedef struct {
68
typedef struct {
70
	GIOChannel *channel;		/* our GIO to the daemon */
69
	GIOChannel *channel;	/* our GIO to the daemon */
71
	GHashTable *handlers;		/* hash of msg -> handler */
70
	GHashTable *handlers;	/* hash of msg -> handler */
72
	gboolean authorized;
71
	gboolean authorized;
73
72
74
	EggTrayIcon *tray_icon;
73
	EggTrayIcon *tray_icon;
Lines 76-96 Link Here
76
	GtkWidget *icon;
75
	GtkWidget *icon;
77
	GtkTooltips *tooltips;
76
	GtkTooltips *tooltips;
78
	GtkWidget *popup_menu;
77
	GtkWidget *popup_menu;
79
	const char *default_keyring;
80
	const char *icon_name;
78
	const char *icon_name;
81
	int last_panel_h;
79
	int last_panel_h;
82
80
83
	GSList *connections;		/* of Connection */
81
	GSList *connections;		/* of Connection */
84
	Connection *active;		/* active connection */
82
	Connection *active;			/* active connection */
85
83
84
	int wireless_available;		/* do we have a wireless interface? */ 	
85
	char *wireless_interface;	/* which is the wireless interface? */
86
		
86
	GSList *accesspoints;		/* of Accesspoints */
87
	GSList *accesspoints;		/* of Accesspoints */
87
	Accesspoint *active_ap;         /* Active access point */
88
	Accesspoint *active_ap;		/* Active access point */
88
	double link_quality;		/* global link quality [0,1] */
89
	double link_quality;		/* global link quality [0,1] */
90
	gboolean clear_essid;		/* do we need to clear the essid? */
91
92
	GList *preferred_aps;		/* of preferred accesspoints */
93
	GSList *keys;				/* of essids with associated keys */
94
	gboolean need_keys;			/* keep track if we need a keys update */
89
} NetApplet;
95
} NetApplet;
90
96
91
static NetApplet *netapplet;
97
static NetApplet *netapplet;
92
98
93
static void populate_popup_menu (void);
99
static void populate_popup_menu (void);
100
static void other_essid_cb (GtkMenuItem*, gpointer);
94
101
95
static void
102
static void
96
netapplet_set_icon (const char *icon_name)
103
netapplet_set_icon (const char *icon_name)
Lines 160-168 Link Here
160
			tip = g_strdup_printf ("Wireless connection (secure): "
167
			tip = g_strdup_printf ("Wireless connection (secure): "
161
			 "%d%%", (int)(netapplet->active_ap->strength * 100));
168
			 "%d%%", (int)(netapplet->active_ap->strength * 100));
162
	} else {
169
	} else {
163
		g_warning ("icon_name=%s\n", icon_name);
170
		tip = _("Unknown connection");
164
		g_assert_not_reached ();
165
		return; /* bleh */
166
	}
171
	}
167
172
168
	gtk_tooltips_set_tip (netapplet->tooltips, netapplet->button,
173
	gtk_tooltips_set_tip (netapplet->tooltips, netapplet->button,
Lines 173-202 Link Here
173
static void
178
static void
174
netapplet_set_connection (Connection *conn)
179
netapplet_set_connection (Connection *conn)
175
{
180
{
176
	netcommon_send_message (netapplet->channel, "change", conn->interface,
181
	netcommon_send_message (netapplet->channel, "set_active", conn->interface,
177
				NULL);
182
				NULL);
178
}
183
}
179
184
185
static guint
186
essid_has_key(gchar* essid) {
187
	GSList *iter;
188
	gchar *escaped, *key_essid;
189
190
	escaped = escape_essid_for_key(essid);
191
	
192
	for (iter = netapplet->keys; iter != NULL; iter=iter->next) {
193
		key_essid = iter->data;
194
		if (strcmp(key_essid, escaped) == 0) {
195
			g_free(escaped);
196
			return 1;
197
		}
198
	}
199
	
200
	g_free(escaped);
201
	return 0;
202
}
203
204
205
static guint
206
preferred_aps_add(gchar* newessid) {
207
	GList *iter, *paps;
208
	gchar *essid;
209
	guint found= 0;
210
	guint len, i;
211
	
212
	paps = netapplet->preferred_aps;
213
	
214
	for (iter = paps; iter != NULL; iter=iter->next) {
215
		essid = iter->data;
216
		if (strcmp(essid, newessid) == 0) {
217
			if (iter == paps) {
218
				/* already first entry */
219
				return 0;
220
			} else {
221
				found = 1;
222
				break;
223
			}
224
		}
225
	}
226
	
227
	/* if we found it, move it to the front of
228
	 * the list */
229
	if (found)
230
		paps = g_list_remove(paps, essid);
231
	else 
232
		essid = g_strdup(newessid);
233
	
234
	paps = g_list_prepend(paps, essid);
235
236
	/* trim list to limit entries */
237
	len = g_list_length(paps);
238
	
239
	if (len > MAX_PREFERRED_APS) {
240
		for (i=0; i<len-MAX_PREFERRED_APS; i++) {
241
			iter = g_list_last(paps);
242
			essid = iter->data;
243
			paps = g_list_remove(paps, essid);
244
			g_free(essid);
245
		}
246
	}
247
248
	netapplet->preferred_aps = paps;
249
	
250
	return 1;
251
}
252
180
static void
253
static void
181
netapplet_set_essid (const char *essid, const char *key)
254
netapplet_set_preferred_aps (void)
182
{
255
{
183
	if (netapplet->active) {
256
	GList *iter;
184
		char *escaped_essid;
257
	GString *msg;
258
	gchar *essid;
259
	
260
	msg = g_string_sized_new (512);	/* start big to avoid resizes */
261
	g_string_printf (msg, "set_preferred_aps");
262
	
263
	for (iter = netapplet->preferred_aps; iter != NULL; iter=iter->next) {
264
		essid = netcommon_escape_argument(iter->data);
265
		g_string_append_printf(msg, " %s", essid);
266
		g_free(essid);
267
	}
268
	
269
	netcommon_send_message(netapplet->channel, msg->str, NULL);
185
270
186
		escaped_essid = netcommon_escape_argument (essid);
271
	g_string_free(msg, TRUE);
272
}
187
273
188
		netcommon_send_message (netapplet->channel, "essid",
274
static void
189
					netapplet->active->interface,
275
netapplet_set_essid (const char *essid, const char *use_key, const char *key)
190
					escaped_essid, key, NULL);
276
{
277
	char *iface;
278
	char *escaped_essid;
279
	char *escaped_key;
280
	
281
	if (netapplet->active && 
282
		(strcmp(netapplet->active->type, "Wireless") == 0)) {
283
		iface = g_strdup(netapplet->active->interface);
284
	} else if (netapplet->wireless_available) {
285
		iface = g_strdup(netapplet->wireless_interface);
286
	} else {
287
		return;
288
	}
289
	
290
	escaped_essid = netcommon_escape_argument (essid);
291
	escaped_key = netcommon_escape_argument (key);
292
293
	netcommon_send_message (netapplet->channel, "set_essid",
294
				iface, escaped_essid, use_key, escaped_key, NULL);
191
295
192
		g_free (escaped_essid);
296
	/* we just set the essid, once we get a connect signal,
297
	 * clear it */
298
	netapplet->clear_essid = TRUE;
299
	netapplet->need_keys = TRUE;
300
	
301
	g_free (escaped_essid);
302
	g_free (escaped_key);
303
	g_free (iface);
304
}
305
306
static void
307
netapplet_clr_essid (const gchar *up_interface)
308
{
309
	char *iface;
310
	
311
	if (netapplet->active && 
312
		(strcmp(netapplet->active->type, "Wireless") == 0)) {
313
		iface = g_strdup(netapplet->active->interface);
314
	} else if (netapplet->wireless_available) {
315
		iface = g_strdup(netapplet->wireless_interface);
316
	} else {
317
		return;
193
	}
318
	}
319
	
320
	netcommon_send_message (netapplet->channel, "clr_essid",
321
				iface, up_interface, NULL);
322
323
	/* the essid has been cleared */
324
	netapplet->clear_essid = FALSE;
325
326
	g_free (iface);
194
}
327
}
195
328
196
static void
329
static void
197
netapplet_get_connections (void)
330
netapplet_get_connections (void)
198
{
331
{
199
	netcommon_send_message (netapplet->channel, "list_interfaces", NULL);
332
	netcommon_send_message (netapplet->channel, "get_interfaces", NULL);
200
}
333
}
201
334
202
static void
335
static void
Lines 208-225 Link Here
208
static void
341
static void
209
netapplet_get_wireless (const char *interface)
342
netapplet_get_wireless (const char *interface)
210
{
343
{
211
	netcommon_send_message (netapplet->channel, "wireless", interface,
344
	netcommon_send_message (netapplet->channel, "get_wireless", interface,
212
				NULL);
345
				NULL);
213
}
346
}
214
347
215
static void
348
static void
216
netapplet_get_accesspoints (const char *interface)
349
netapplet_get_accesspoints (const char *interface)
217
{
350
{
218
	netcommon_send_message (netapplet->channel, "accesspoints", interface,
351
	netcommon_send_message (netapplet->channel, "get_accesspoints", interface,
219
				NULL);
352
				NULL);
220
}
353
}
221
354
222
static void
355
static void
356
netapplet_get_keys (void)
357
{
358
	netcommon_send_message (netapplet->channel, "get_keys", NULL);
359
}
360
361
static void
362
netapplet_get_preferred_aps (void)
363
{
364
	netcommon_send_message (netapplet->channel, "get_preferred_aps", NULL);
365
}
366
367
static void
223
conn_free (Connection *conn)
368
conn_free (Connection *conn)
224
{
369
{
225
	g_free (conn->interface);
370
	g_free (conn->interface);
Lines 251-256 Link Here
251
	netapplet->active_ap = NULL;
396
	netapplet->active_ap = NULL;
252
}
397
}
253
398
399
static void
400
netapplet_free_keys (void)
401
{
402
	g_slist_foreach (netapplet->keys, (GFunc) essid_free, NULL);
403
	g_slist_free (netapplet->keys);
404
	netapplet->keys = NULL;
405
}
406
407
static void
408
netapplet_free_preferred_aps (void)
409
{
410
	g_list_foreach (netapplet->preferred_aps, (GFunc) essid_free, NULL);
411
	g_list_free (netapplet->preferred_aps);
412
	netapplet->preferred_aps = NULL;
413
}
414
254
static Connection *
415
static Connection *
255
netapplet_get_connection_by_interface (const char *interface)
416
netapplet_get_connection_by_interface (const char *interface)
256
{
417
{
Lines 354-359 Link Here
354
515
355
	netapplet_get_connections ();
516
	netapplet_get_connections ();
356
	netapplet_get_active ();
517
	netapplet_get_active ();
518
	netapplet_get_keys ();	
519
	netapplet_get_preferred_aps ();	
357
}
520
}
358
521
359
static void
522
static void
Lines 367-373 Link Here
367
	conn = netapplet_get_connection_by_interface (interface);
530
	conn = netapplet_get_connection_by_interface (interface);
368
	g_assert (conn != NULL);
531
	g_assert (conn != NULL);
369
532
370
	netapplet_set_connection (conn);
533
	if (strcmp(conn->type, "Wireless") == 0) {
534
		if (netapplet->preferred_aps) {
535
			/* do we have a preferred_aps list? */
536
			netapplet_clr_essid("1");
537
		} else {
538
			/* if we don't, ask for essid/key */
539
			other_essid_cb(NULL,NULL);
540
		}
541
	} else 
542
		netapplet_set_connection (conn);
371
}
543
}
372
544
373
static void
545
static void
Lines 394-671 Link Here
394
	gtk_widget_destroy (dialog);
566
	gtk_widget_destroy (dialog);
395
}
567
}
396
568
397
typedef void (*GDICallback) (gpointer user_data);
398
399
typedef struct {
400
	gboolean create_if_needed;
401
	GDICallback callback;
402
	gpointer user_data;
403
} GetDefaultInfo;
404
405
static void
406
set_default_keyring_cb (GnomeKeyringResult result,
407
			gpointer data)
408
{
409
	GetDefaultInfo *gdi = data;
410
411
	if (result != GNOME_KEYRING_RESULT_OK) {
412
		g_warning (_("Error trying to set default keyring: %d"),
413
			   result);
414
		g_free (gdi);
415
		return;
416
	}
417
418
	netapplet->default_keyring = "default";
419
420
	gdi->callback (gdi->user_data);
421
	g_free (gdi);
422
}
423
424
425
static void
426
create_keyring_cb (GnomeKeyringResult result, gpointer data)
427
{
428
	GetDefaultInfo *gdi = data;
429
430
	if (result != GNOME_KEYRING_RESULT_OK) {
431
		g_warning (_("Error trying to create keyring: %d"),
432
			   result);
433
		g_free (gdi);
434
		return;
435
	}
436
437
	gnome_keyring_set_default_keyring ("default", set_default_keyring_cb,
438
					   gdi, NULL);
439
}
440
441
static void
442
get_default_keyring_cb (GnomeKeyringResult result, const char *string,
443
			gpointer data)
444
{
445
	GetDefaultInfo *gdi = data;
446
	
447
	if (result != GNOME_KEYRING_RESULT_OK) {
448
		g_warning (_("Error trying to get default keyring: %d"),
449
			   result);
450
		g_free (gdi);
451
		return;
452
	}
453
454
	/*
455
	 * Ugh.  If there isn't a default keyring we have to create one
456
	 * ourselves, which is incredibly inconvenient.
457
	 */
458
	if (string == NULL && gdi->create_if_needed) {
459
		gnome_keyring_create ("default",
460
				      NULL, /* ask user */
461
				      create_keyring_cb,
462
				      gdi, NULL);
463
	} else {
464
		/* Note! "string" could still be NULL */
465
		netapplet->default_keyring = g_strdup (string);
466
		gdi->callback (gdi->user_data);
467
		g_free (gdi);
468
	}
469
}
470
471
static void
472
get_default_keyring (gboolean create_if_needed,
473
		     GDICallback callback,
474
		     gpointer user_data)
475
{
476
	GetDefaultInfo *gdi = g_new0 (GetDefaultInfo, 1);
477
478
	gdi->create_if_needed = create_if_needed;
479
	gdi->callback = callback;
480
	gdi->user_data = user_data;
481
482
	/*
483
	 * Ugh.  We have to try to get the default keyring and stick it
484
	 * in some ugly-ass global variable because some keyring functions 
485
	 * (notably gnome_keyring_unlock() won't take NULL to mean the
486
	 * default keyring.
487
	 *
488
	 * This is fixed in 0.3.x keyring, so hopefully will be
489
	 * temporary.
490
	 */
491
	gnome_keyring_get_default_keyring (get_default_keyring_cb, gdi, NULL);
492
}
493
494
static void
495
create_item_cb (GnomeKeyringResult result,
496
		guint32 val G_GNUC_UNUSED,
497
		gpointer data G_GNUC_UNUSED)
498
{
499
	if (result != GNOME_KEYRING_RESULT_OK)
500
		g_warning (_("Unable to save to keyring!  Err: %d"), result);
501
}
502
503
static void
504
create_item (const char *essid, const char *key)
505
{
506
	GnomeKeyringAttributeList *attributes;
507
	GnomeKeyringAttribute attr;
508
	char *name;
509
510
	attributes = gnome_keyring_attribute_list_new ();
511
512
	attr.name = g_strdup ("essid");
513
	attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
514
	attr.value.string = g_strdup (essid);
515
	g_array_append_val (attributes, attr);
516
517
	name = g_strdup_printf (_("Password for network \"%s\""), essid);
518
519
	gnome_keyring_item_create (netapplet->default_keyring,
520
				   GNOME_KEYRING_ITEM_GENERIC_SECRET,
521
				   name,
522
				   attributes,
523
				   key,
524
				   TRUE,
525
				   create_item_cb, NULL, NULL);
526
527
	g_free (name);
528
}
529
530
typedef struct {
531
	char *essid;
532
	char *key;
533
} SaveInfo;
534
535
static void
536
queue_create (gpointer user_data)
537
{
538
	SaveInfo *sinfo = user_data;
539
540
	if (netapplet->default_keyring != NULL)
541
		create_item (sinfo->essid, sinfo->key);
542
543
	g_free (sinfo->essid);
544
	g_free (sinfo->key);
545
	g_free (sinfo);
546
}
547
548
static void
549
keyring_save (const char *essid, const char *key)
550
{
551
	SaveInfo *sinfo;
552
553
	sinfo = g_new0 (SaveInfo, 1);
554
	sinfo->essid = g_strdup (essid);
555
	sinfo->key = g_strdup (key);
556
557
	if (netapplet->default_keyring == NULL)
558
		get_default_keyring (TRUE, queue_create, sinfo);
559
	else
560
		create_item (essid, key);
561
}
562
563
static void
564
entry_changed_cb (GtkEntry *entry, gpointer user_data)
565
{
566
	GtkWidget *widget = GTK_WIDGET (user_data);
567
	const char *text;
568
569
	text = gtk_entry_get_text (entry);
570
571
	if (text == NULL || *text == '\0')
572
		gtk_widget_set_sensitive (widget, FALSE);
573
	else
574
		gtk_widget_set_sensitive (widget, TRUE);
575
}
576
577
static void
569
static void
578
show_key_dialog (const char *essid)
570
get_key (const char *essid)
579
{
571
{
580
	GladeXML *xml;
572
	GladeXML *xml;
581
	GtkWidget *dialog, *entry_key, *checkbox_keyring;
573
	GtkWidget *dialog, *entry_key;
582
	char *old_essid;
583
574
584
	xml = glade_xml_new (GLADE_APPLET, "dialog-key", NULL);
575
	xml = glade_xml_new (GLADE_APPLET, "dialog-key", NULL);
585
	dialog = glade_xml_get_widget (xml, "dialog-key");
576
	dialog = glade_xml_get_widget (xml, "dialog-key");
586
	
577
	
587
	checkbox_keyring = glade_xml_get_widget (xml, "checkbutton-keyring");
588
	gtk_widget_set_sensitive (checkbox_keyring, FALSE);
589
		
590
	entry_key = glade_xml_get_widget (xml, "entry-key");
591
	g_signal_connect (entry_key, "changed",
592
			  G_CALLBACK (entry_changed_cb),
593
			  checkbox_keyring);
594
595
	old_essid = g_strdup (essid);
596
597
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
578
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
598
		const char *key;
579
		const char *key;
599
580
581
		entry_key = glade_xml_get_widget (xml, "entry-key");
600
		key = gtk_entry_get_text (GTK_ENTRY (entry_key));
582
		key = gtk_entry_get_text (GTK_ENTRY (entry_key));
601
583
602
		netapplet_set_essid (old_essid, key);
584
		netapplet_set_essid (essid, "1", key);
603
604
		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox_keyring)))
605
			keyring_save (old_essid, key);
606
	}
585
	}
607
586
608
	g_free (old_essid);
609
	gtk_widget_destroy (dialog);
587
	gtk_widget_destroy (dialog);
610
	g_object_unref (xml);
588
	g_object_unref (xml);
611
}
589
}
612
590
613
static void
591
static void
614
get_item_cb (GnomeKeyringResult result, GList *list, gpointer data)
615
{
616
	char *essid = data;
617
	GnomeKeyringFound *found;
618
619
	if (result != GNOME_KEYRING_RESULT_OK) {
620
		show_key_dialog (essid);
621
		return;
622
	}
623
624
	/* Not found in keyring */
625
	if (list == NULL) {
626
		show_key_dialog (essid);
627
		return;
628
	}
629
630
	found = (GnomeKeyringFound *) list->data;
631
632
	netapplet_set_essid (essid, found->secret);
633
634
	g_free (essid);
635
}
636
637
static void
638
get_item (const char *essid)
639
{
640
	gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
641
				   get_item_cb,
642
				   g_strdup (essid),
643
				   NULL,
644
				   "essid",
645
				   GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
646
				   essid,
647
				   NULL);
648
}
649
650
static void
651
queue_get (gpointer user_data)
652
{
653
	const char *essid = user_data;
654
655
	if (netapplet->default_keyring != NULL)
656
		get_item (essid);
657
}
658
659
static void
660
keyring_load (const char *essid)
661
{
662
	if (netapplet->default_keyring == NULL)
663
		get_default_keyring (FALSE, queue_get, (gpointer) essid);
664
	else
665
		get_item (essid);
666
}
667
668
static void
669
essid_activate_cb (GtkMenuItem *mi G_GNUC_UNUSED,
592
essid_activate_cb (GtkMenuItem *mi G_GNUC_UNUSED,
670
		   gpointer user_data G_GNUC_UNUSED)
593
		   gpointer user_data G_GNUC_UNUSED)
671
594
Lines 677-723 Link Here
677
	ap = netapplet_get_accesspoint_by_essid (essid);
600
	ap = netapplet_get_accesspoint_by_essid (essid);
678
	g_assert (ap);
601
	g_assert (ap);
679
602
680
	if (ap->is_encrypted)
603
	if (ap->is_encrypted) {
681
		keyring_load (ap->essid);
604
		if (essid_has_key(ap->essid))
605
			netapplet_set_essid (ap->essid, "0", "");
606
		else 
607
			get_key (ap->essid);
608
	} else
609
		netapplet_set_essid (ap->essid, "1", "");
610
611
	/* set to clear essid */
612
	netapplet->clear_essid = TRUE;
613
	netapplet->need_keys = TRUE;
614
}
615
616
static guint
617
other_essid_clear_key() {
618
	GtkWidget *dialog;
619
	guint clear;
620
	
621
	dialog = gtk_message_dialog_new_with_markup (
622
			NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
623
			_("<span weight=\"bold\" size=\"larger\">"
624
			  "Exisiting key found for ESSID"
625
			  "</span>\n\n"
626
			  "An exisiting key has been found for the desired ESSID.  "
627
			  "You either did not specify a key or entered a blank key.  "
628
			  "Do you want to use the existing key or clear the stored key?"));
629
	gtk_dialog_add_buttons (GTK_DIALOG (dialog),
630
				"_Use Exisiting Key", GTK_RESPONSE_CANCEL,
631
				"_Clear Key", GTK_RESPONSE_OK,
632
				NULL);
633
634
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) 
635
		clear = 1;
682
	else
636
	else
683
		netapplet_set_essid (ap->essid, "");
637
		clear = 0;	
638
	
639
	gtk_widget_destroy (dialog);
640
	return clear;
684
}
641
}
685
642
686
static void
643
static void
687
other_essid_cb (GtkMenuItem *mi G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)
644
other_essid_cb (GtkMenuItem *mi G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)
688
{
645
{
689
	GtkWidget *dialog, *entry_key, *checkbox_keyring;
646
	GtkWidget *dialog, *entry_key;
690
	GladeXML *xml;
647
	GladeXML *xml;
691
648
692
	xml = glade_xml_new (GLADE_APPLET, "dialog-essid", NULL);
649
	xml = glade_xml_new (GLADE_APPLET, "dialog-essid", NULL);
693
	dialog = glade_xml_get_widget (xml, "dialog-essid");
650
	dialog = glade_xml_get_widget (xml, "dialog-essid");
694
651
	
695
	checkbox_keyring = glade_xml_get_widget (xml, "checkbutton-keyring");
696
	gtk_widget_set_sensitive (checkbox_keyring, FALSE);
697
698
	entry_key = glade_xml_get_widget (xml, "entry-key");
699
	g_signal_connect (entry_key, "changed",
700
			  G_CALLBACK (entry_changed_cb), checkbox_keyring);
701
702
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
652
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
703
		GtkWidget *entry_essid;
653
		GtkWidget *entry_essid;
704
		const char *essid, *key;
654
		const gchar *essid, *key;
705
655
706
		entry_essid = glade_xml_get_widget (xml, "entry-essid");
656
		entry_essid = glade_xml_get_widget (xml, "entry-essid");
657
		entry_key = glade_xml_get_widget (xml, "entry-key");
707
658
708
		essid = gtk_entry_get_text (GTK_ENTRY (entry_essid));
659
		essid = gtk_entry_get_text (GTK_ENTRY (entry_essid));
709
		key = gtk_entry_get_text (GTK_ENTRY (entry_key));
660
		key = gtk_entry_get_text (GTK_ENTRY (entry_key));
661
		
662
		if (essid_has_key((gchar*) essid)) {
663
			if (!strcmp(key, "")) {
664
				/* there is an existing key, but no key was 
665
				 * entered, do we want to clear the key or 
666
				 * use what is already there? */
667
				if (other_essid_clear_key())
668
					netapplet_set_essid(essid, "1", key);
669
				else
670
					netapplet_set_essid(essid, "0", key);
671
					
672
			} else {
673
				/* there is an exisiting key, but use the
674
				 * entered key instead */
675
				netapplet_set_essid (essid, "1", key);
676
			}
677
		} else
678
			/* no exisiting key, use what was entered */
679
			netapplet_set_essid (essid, "1", key);
710
680
711
		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox_keyring)))
681
		/* set to clear essid */
712
			keyring_save (essid, key);
682
		netapplet->clear_essid = TRUE;
713
683
		netapplet->need_keys = TRUE;
714
		netapplet_set_essid (essid, key);
715
	}
684
	}
716
685
717
	gtk_widget_destroy (dialog);
686
	gtk_widget_destroy (dialog);
718
	g_object_unref (xml);
687
	g_object_unref (xml);
719
}
688
}
720
689
690
static void
691
refresh_accesspoints_cb (GtkMenuItem *mi G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)
692
{
693
	char *iface;
694
	
695
	if (netapplet->active && 
696
		(strcmp(netapplet->active->type, "Wireless") == 0)) {
697
		iface = g_strdup(netapplet->active->interface);
698
	} else if (netapplet->wireless_available) {
699
		iface = g_strdup(netapplet->wireless_interface);
700
	} else {
701
		return;
702
	}
703
	
704
	netapplet_get_accesspoints(iface);
705
	
706
	g_free(iface);
707
}
708
709
static void
710
preferred_aps_activate_cb (GtkMenuItem *mi G_GNUC_UNUSED,
711
		   gpointer user_data G_GNUC_UNUSED)
712
{
713
	gchar *essid;
714
	essid = g_object_get_data (G_OBJECT (mi), "essid");
715
	
716
	/* update preferred aps and reup the network*/
717
	if (preferred_aps_add(essid)) {
718
		netapplet_set_preferred_aps();
719
		populate_popup_menu();
720
	}
721
722
	netapplet_clr_essid ("1"); 
723
}
724
725
721
static GtkWidget *
726
static GtkWidget *
722
get_label (GtkWidget *info_dialog, GladeXML *xml, const char *name)
727
get_label (GtkWidget *info_dialog, GladeXML *xml, const char *name)
723
{
728
{
Lines 876-887 Link Here
876
	g_free (mac);
881
	g_free (mac);
877
}
882
}
878
883
884
#ifdef NETWORK_CONF_TOOL
879
static void
885
static void
880
configure_activate_cb (GtkMenuItem *mi G_GNUC_UNUSED,
886
configure_activate_cb (GtkMenuItem *mi G_GNUC_UNUSED,
881
		       gpointer user_data G_GNUC_UNUSED)
887
		       gpointer user_data G_GNUC_UNUSED)
882
{
888
{
883
	char *argv[] = YAST2_ARGV;
884
	GError *err = NULL;
889
	GError *err = NULL;
890
	
891
	char *argv[2];
892
	argv[0] = GST_NETWORKADMIN_PATH;
893
	argv[1] = NULL;
885
894
886
	if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &err)) {
895
	if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &err)) {
887
		GtkWidget *dialog;
896
		GtkWidget *dialog;
Lines 896-902 Link Here
896
905
897
		g_error_free (err);
906
		g_error_free (err);
898
	}
907
	}
908
	return;
899
}
909
}
910
#endif
900
911
901
static void
912
static void
902
quit_cb (GtkMenuItem *mi G_GNUC_UNUSED,
913
quit_cb (GtkMenuItem *mi G_GNUC_UNUSED,
Lines 965-972 Link Here
965
static void
976
static void
966
populate_popup_menu (void)
977
populate_popup_menu (void)
967
{
978
{
968
	GtkWidget *mi, *image;
979
	GtkWidget *mi, *sm, *image;
969
	GSList *iter;
980
	GSList *iter;
981
	GList *iter2;
970
982
971
	g_list_foreach (GTK_MENU_SHELL (netapplet->popup_menu)->children,
983
	g_list_foreach (GTK_MENU_SHELL (netapplet->popup_menu)->children,
972
			remove_old_items, netapplet->popup_menu);
984
			remove_old_items, netapplet->popup_menu);
Lines 1034-1042 Link Here
1034
	/* Build list of wireless accesspoints ... */
1046
	/* Build list of wireless accesspoints ... */
1035
	if (netapplet->accesspoints)
1047
	if (netapplet->accesspoints)
1036
		mi = gtk_menu_item_new_with_label (_("Wireless Networks"));
1048
		mi = gtk_menu_item_new_with_label (_("Wireless Networks"));
1037
	else if (!(netapplet->active &&
1038
		   strcmp (netapplet->active->type, "Wireless") == 0))
1039
		mi = gtk_menu_item_new_with_label (_("Wireless disabled"));
1040
	else
1049
	else
1041
		mi = gtk_menu_item_new_with_label (
1050
		mi = gtk_menu_item_new_with_label (
1042
					_("No wireless networks available"));
1051
					_("No wireless networks available"));
Lines 1069-1078 Link Here
1069
		gtk_widget_show (mi);
1078
		gtk_widget_show (mi);
1070
		g_free (display_name);
1079
		g_free (display_name);
1071
	}
1080
	}
1081
		
1082
	mi = gtk_separator_menu_item_new ();
1083
	gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1084
	gtk_widget_show (mi);
1085
1086
	if (netapplet->preferred_aps) {
1087
		sm = gtk_menu_new();
1088
1089
		for (iter2 = netapplet->preferred_aps; iter2 != NULL; iter2 = iter2->next) {
1090
			char *essid = iter2->data;
1091
	
1092
			mi = gtk_image_menu_item_new_with_mnemonic (essid);
1093
1094
			if (essid_has_key(essid)) {
1095
				image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
1096
						GTK_ICON_SIZE_MENU);
1097
				gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
1098
						image);
1099
			}
1100
			
1101
			gtk_menu_shell_append (GTK_MENU_SHELL (sm), mi);
1102
1103
			g_object_set_data_full (G_OBJECT (mi), "essid",
1104
						g_strdup (essid), g_free);
1105
			g_signal_connect (mi, "activate",
1106
					  G_CALLBACK (preferred_aps_activate_cb), NULL);
1107
			gtk_widget_set_sensitive (mi, netapplet->authorized);
1108
			gtk_widget_show (mi);
1109
		}
1110
		
1111
		image = gtk_image_new_from_stock (GTK_STOCK_INDEX,
1112
					  GTK_ICON_SIZE_MENU);
1113
		mi = gtk_image_menu_item_new_with_mnemonic (_("Preferred Networks"));
1114
		gtk_image_menu_item_set_image ((GtkImageMenuItem*) mi, image);
1115
		gtk_widget_show (mi);
1116
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), sm);
1117
		gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1118
	}
1072
1119
1073
	if (netapplet->active &&
1120
	if (netapplet->wireless_available) { 
1074
	    strcmp (netapplet->active->type, "Wireless") == 0) { 
1121
		mi = gtk_menu_item_new_with_label ("Other Network...");
1075
		mi = gtk_menu_item_new_with_label ("Other ...");
1076
		gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu),
1122
		gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu),
1077
				       mi);
1123
				       mi);
1078
		g_signal_connect (mi, "activate", G_CALLBACK (other_essid_cb),
1124
		g_signal_connect (mi, "activate", G_CALLBACK (other_essid_cb),
Lines 1080-1091 Link Here
1080
1126
1081
		gtk_widget_set_sensitive (mi, netapplet->authorized);
1127
		gtk_widget_set_sensitive (mi, netapplet->authorized);
1082
		gtk_widget_show (mi);
1128
		gtk_widget_show (mi);
1083
	}
1129
	
1084
1130
		
1085
	mi = gtk_separator_menu_item_new ();
1131
		image = gtk_image_new_from_stock (GTK_STOCK_REFRESH,
1086
	gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1132
					  GTK_ICON_SIZE_MENU);
1087
	gtk_widget_show (mi);
1133
		mi = gtk_image_menu_item_new_with_mnemonic (_("Refresh Networks"));
1134
		gtk_image_menu_item_set_image ((GtkImageMenuItem*) mi, image);
1135
		gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1136
		g_signal_connect (mi, "activate", G_CALLBACK (refresh_accesspoints_cb),
1137
				  NULL);
1088
1138
1139
		gtk_widget_set_sensitive (mi, netapplet->authorized);
1140
		gtk_widget_show (mi);
1141
		
1142
		mi = gtk_separator_menu_item_new ();
1143
		gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1144
		gtk_widget_show (mi);
1145
	}
1146
	
1089
	/* 'Connection Information' item */
1147
	/* 'Connection Information' item */
1090
	image = gtk_image_new_from_stock (GTK_STOCK_PROPERTIES,
1148
	image = gtk_image_new_from_stock (GTK_STOCK_PROPERTIES,
1091
					  GTK_ICON_SIZE_MENU);
1149
					  GTK_ICON_SIZE_MENU);
Lines 1096-1101 Link Here
1096
	gtk_widget_show (mi);
1154
	gtk_widget_show (mi);
1097
	g_signal_connect (mi, "activate", G_CALLBACK (show_info_cb), netapplet);
1155
	g_signal_connect (mi, "activate", G_CALLBACK (show_info_cb), netapplet);
1098
1156
1157
#ifdef NETWORK_CONF_TOOL
1099
	/* 'Configure Network Settings' item */
1158
	/* 'Configure Network Settings' item */
1100
	image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES,
1159
	image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES,
1101
					  GTK_ICON_SIZE_MENU);
1160
					  GTK_ICON_SIZE_MENU);
Lines 1106-1111 Link Here
1106
	gtk_widget_show (mi);
1165
	gtk_widget_show (mi);
1107
	g_signal_connect (mi, "activate", G_CALLBACK (configure_activate_cb),
1166
	g_signal_connect (mi, "activate", G_CALLBACK (configure_activate_cb),
1108
			  netapplet);
1167
			  netapplet);
1168
#endif 
1109
1169
1110
	mi = gtk_separator_menu_item_new ();
1170
	mi = gtk_separator_menu_item_new ();
1111
	gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
1171
	gtk_menu_shell_append (GTK_MENU_SHELL (netapplet->popup_menu), mi);
Lines 1325-1339 Link Here
1325
	netapplet->accesspoints = new_aps;
1385
	netapplet->accesspoints = new_aps;
1326
	netapplet->active_ap = new_active;
1386
	netapplet->active_ap = new_active;
1327
1387
1328
	netapplet->active->icon = wireless_icon (netapplet->active);
1329
	netapplet_set_icon (netapplet->active->icon);
1330
1331
	if (changed)
1388
	if (changed)
1332
		populate_popup_menu ();
1389
		populate_popup_menu ();
1333
	else
1390
	else
1334
		update_popup_accesspoint_strengths ();
1391
		update_popup_accesspoint_strengths ();
1335
}
1392
}
1336
1393
1394
static void
1395
netapplet_handle_keys (GIOChannel *channel G_GNUC_UNUSED,
1396
			       char **args)
1397
{
1398
	GSList *keys = NULL;
1399
	char **iter;
1400
	
1401
	for (iter = &args[1]; *iter != NULL; iter++) {
1402
		char *essid;
1403
		essid = g_strdup(*iter);
1404
		keys = g_slist_append(keys, essid);
1405
	}
1406
1407
	netapplet_free_keys();
1408
	netapplet->keys = keys;
1409
	netapplet->need_keys = FALSE;
1410
	populate_popup_menu();	
1411
}
1412
1413
static void
1414
netapplet_handle_preferred_aps (GIOChannel *channel G_GNUC_UNUSED,
1415
			       char **args)
1416
{
1417
	GList *p_aps = NULL;
1418
	char **iter;
1419
	
1420
	for (iter = &args[1]; *iter != NULL; iter++) {
1421
		char *essid;
1422
		essid = g_strdup(*iter);
1423
		p_aps = g_list_append(p_aps, essid);
1424
	}
1425
1426
	netapplet_free_preferred_aps();
1427
	netapplet->preferred_aps = p_aps;
1428
1429
	populate_popup_menu();	
1430
}
1431
1337
/*
1432
/*
1338
 * handle the 'wireless' message, which tells us the active ESSID
1433
 * handle the 'wireless' message, which tells us the active ESSID
1339
 *
1434
 *
Lines 1372-1377 Link Here
1372
			netapplet->active_ap = ap;
1467
			netapplet->active_ap = ap;
1373
	}
1468
	}
1374
1469
1470
	if (preferred_aps_add(args[1]))
1471
		netapplet_set_preferred_aps();
1472
1473
	if (netapplet->clear_essid)
1474
		netapplet_clr_essid("0");
1475
	
1476
	if (netapplet->need_keys) 
1477
		netapplet_get_keys();
1478
	
1375
out:
1479
out:
1376
	populate_popup_menu ();
1480
	populate_popup_menu ();
1377
}
1481
}
Lines 1382-1391 Link Here
1382
{
1486
{
1383
	netapplet_set_icon (DISCONNECT_ICON);
1487
	netapplet_set_icon (DISCONNECT_ICON);
1384
	netapplet->active = NULL;
1488
	netapplet->active = NULL;
1385
	if (netapplet->accesspoints) {
1489
	netapplet->active_ap = NULL;
1386
		/* remove no-longer-valid wireless information */
1387
		netapplet_free_accesspoints ();
1388
	}
1389
1490
1390
	populate_popup_menu ();
1491
	populate_popup_menu ();
1391
}
1492
}
Lines 1431-1436 Link Here
1431
	char **iter;
1532
	char **iter;
1432
	Connection *new_active = NULL;
1533
	Connection *new_active = NULL;
1433
1534
1535
	if (netapplet->wireless_available)
1536
		g_free(netapplet->wireless_interface);
1537
		
1538
	netapplet->wireless_available = 0;
1539
	
1434
	/*
1540
	/*
1435
	 * This is used to restore netapplet->active to the new Connection
1541
	 * This is used to restore netapplet->active to the new Connection
1436
	 * value obtained below.  This avoids a race where netapplet->active
1542
	 * value obtained below.  This avoids a race where netapplet->active
Lines 1454-1459 Link Here
1454
		if (strcmp (type, TYPE_WIRELESS) == 0) {
1560
		if (strcmp (type, TYPE_WIRELESS) == 0) {
1455
			conn->type = "Wireless";
1561
			conn->type = "Wireless";
1456
			conn->icon = wireless_icon (conn);
1562
			conn->icon = wireless_icon (conn);
1563
1564
			/* track the wireless interface.  for more than one wireless
1565
			 * interface, the first one becomes default */
1566
			if (!netapplet->wireless_available) {
1567
				netapplet->wireless_available = 1;
1568
				netapplet->wireless_interface = g_strdup(interface);
1569
			}
1457
		} else if (strcmp (type, TYPE_ETHERNET) == 0) {
1570
		} else if (strcmp (type, TYPE_ETHERNET) == 0) {
1458
			conn->type = "Ethernet";
1571
			conn->type = "Ethernet";
1459
			conn->icon = ETHERNET_ICON;
1572
			conn->icon = ETHERNET_ICON;
Lines 1522-1530 Link Here
1522
	if (g_str_has_prefix (netapplet->active->type, "Wireless")) {
1635
	if (g_str_has_prefix (netapplet->active->type, "Wireless")) {
1523
		netapplet_get_accesspoints (netapplet->active->interface);
1636
		netapplet_get_accesspoints (netapplet->active->interface);
1524
		netapplet_get_wireless (netapplet->active->interface);
1637
		netapplet_get_wireless (netapplet->active->interface);
1525
	} else if (netapplet->accesspoints) {
1638
	} else {
1526
		/* remove no-longer-valid wireless information */
1639
		netapplet->active_ap = NULL;
1527
		netapplet_free_accesspoints ();
1528
	}
1640
	}
1529
1641
1530
	if (changed) {
1642
	if (changed) {
Lines 1601-1618 Link Here
1601
	/* Protocol handlers */
1713
	/* Protocol handlers */
1602
	applet->handlers = g_hash_table_new (g_str_hash, g_str_equal);
1714
	applet->handlers = g_hash_table_new (g_str_hash, g_str_equal);
1603
1715
1604
	g_hash_table_insert (applet->handlers, "interfaces",
1716
	g_hash_table_insert (applet->handlers, "interfaces", netapplet_handle_interfaces);
1605
			     netapplet_handle_interfaces);
1717
	g_hash_table_insert (applet->handlers, "active", netapplet_handle_active);
1606
	g_hash_table_insert (applet->handlers, "active",
1718
	g_hash_table_insert (applet->handlers, "wireless", netapplet_handle_wireless);
1607
			     netapplet_handle_active);
1719
	g_hash_table_insert (applet->handlers, "accesspoints", netapplet_handle_accesspoints);
1608
	g_hash_table_insert (applet->handlers, "wireless",
1720
	g_hash_table_insert (applet->handlers, "preferred_aps", netapplet_handle_preferred_aps);
1609
			     netapplet_handle_wireless);
1721
	g_hash_table_insert (applet->handlers, "keys", netapplet_handle_keys);
1610
	g_hash_table_insert (applet->handlers, "accesspoints",
1722
	g_hash_table_insert (applet->handlers, "disconnected", netapplet_handle_disconnected);
1611
			     netapplet_handle_accesspoints);
1723
	g_hash_table_insert (applet->handlers, "unauthorized", netapplet_handle_unauthorized);
1612
	g_hash_table_insert (applet->handlers, "disconnected",
1613
			     netapplet_handle_disconnected);
1614
	g_hash_table_insert (applet->handlers, "unauthorized",
1615
			     netapplet_handle_unauthorized);
1616
1724
1617
	return applet;
1725
	return applet;
1618
}
1726
}
(-)netapplet-1.0.0/src/netapplet.glade (-71 / +5 lines)
Lines 681-687 Link Here
681
	      <property name="max_length">0</property>
681
	      <property name="max_length">0</property>
682
	      <property name="text" translatable="yes"></property>
682
	      <property name="text" translatable="yes"></property>
683
	      <property name="has_frame">True</property>
683
	      <property name="has_frame">True</property>
684
	      <property name="invisible_char" translatable="yes">*</property>
684
	      <property name="invisible_char">*</property>
685
	      <property name="activates_default">True</property>
685
	      <property name="activates_default">True</property>
686
	    </widget>
686
	    </widget>
687
	    <packing>
687
	    <packing>
Lines 778-788 Link Here
778
			      <property name="visible">True</property>
778
			      <property name="visible">True</property>
779
			      <property name="can_focus">True</property>
779
			      <property name="can_focus">True</property>
780
			      <property name="editable">True</property>
780
			      <property name="editable">True</property>
781
			      <property name="visibility">False</property>
781
			      <property name="visibility">True</property>
782
			      <property name="max_length">0</property>
782
			      <property name="max_length">0</property>
783
			      <property name="text" translatable="yes"></property>
783
			      <property name="text" translatable="yes"></property>
784
			      <property name="has_frame">True</property>
784
			      <property name="has_frame">True</property>
785
			      <property name="invisible_char" translatable="yes">*</property>
785
			      <property name="invisible_char">*</property>
786
			      <property name="activates_default">True</property>
786
			      <property name="activates_default">True</property>
787
			    </widget>
787
			    </widget>
788
			    <packing>
788
			    <packing>
Lines 798-836 Link Here
798
			  <property name="fill">True</property>
798
			  <property name="fill">True</property>
799
			</packing>
799
			</packing>
800
		      </child>
800
		      </child>
801
802
		      <child>
803
			<widget class="GtkHBox" id="hbox10">
804
			  <property name="border_width">6</property>
805
			  <property name="visible">True</property>
806
			  <property name="homogeneous">False</property>
807
			  <property name="spacing">0</property>
808
809
			  <child>
810
			    <widget class="GtkCheckButton" id="checkbutton-keyring">
811
			      <property name="visible">True</property>
812
			      <property name="can_focus">True</property>
813
			      <property name="label" translatable="yes">Add to Keyring</property>
814
			      <property name="use_underline">True</property>
815
			      <property name="relief">GTK_RELIEF_NORMAL</property>
816
			      <property name="focus_on_click">True</property>
817
			      <property name="active">False</property>
818
			      <property name="inconsistent">False</property>
819
			      <property name="draw_indicator">True</property>
820
			    </widget>
821
			    <packing>
822
			      <property name="padding">0</property>
823
			      <property name="expand">False</property>
824
			      <property name="fill">False</property>
825
			    </packing>
826
			  </child>
827
			</widget>
828
			<packing>
829
			  <property name="padding">0</property>
830
			  <property name="expand">True</property>
831
			  <property name="fill">True</property>
832
			</packing>
833
		      </child>
834
		    </widget>
801
		    </widget>
835
		    <packing>
802
		    <packing>
836
		      <property name="padding">0</property>
803
		      <property name="padding">0</property>
Lines 972-982 Link Here
972
	      <property name="can_focus">True</property>
939
	      <property name="can_focus">True</property>
973
	      <property name="has_focus">True</property>
940
	      <property name="has_focus">True</property>
974
	      <property name="editable">True</property>
941
	      <property name="editable">True</property>
975
	      <property name="visibility">False</property>
942
	      <property name="visibility">True</property>
976
	      <property name="max_length">0</property>
943
	      <property name="max_length">0</property>
977
	      <property name="text" translatable="yes"></property>
944
	      <property name="text" translatable="yes"></property>
978
	      <property name="has_frame">True</property>
945
	      <property name="has_frame">True</property>
979
	      <property name="invisible_char" translatable="yes">*</property>
946
	      <property name="invisible_char">*</property>
980
	      <property name="activates_default">True</property>
947
	      <property name="activates_default">True</property>
981
	    </widget>
948
	    </widget>
982
	    <packing>
949
	    <packing>
Lines 992-1030 Link Here
992
	  <property name="fill">False</property>
959
	  <property name="fill">False</property>
993
	</packing>
960
	</packing>
994
      </child>
961
      </child>
995
996
      <child>
997
	<widget class="GtkHBox" id="hbox8">
998
	  <property name="border_width">6</property>
999
	  <property name="visible">True</property>
1000
	  <property name="homogeneous">False</property>
1001
	  <property name="spacing">0</property>
1002
1003
	  <child>
1004
	    <widget class="GtkCheckButton" id="checkbutton-keyring">
1005
	      <property name="visible">True</property>
1006
	      <property name="can_focus">True</property>
1007
	      <property name="label" translatable="yes">Add to Keyring</property>
1008
	      <property name="use_underline">True</property>
1009
	      <property name="relief">GTK_RELIEF_NORMAL</property>
1010
	      <property name="focus_on_click">True</property>
1011
	      <property name="active">False</property>
1012
	      <property name="inconsistent">False</property>
1013
	      <property name="draw_indicator">True</property>
1014
	    </widget>
1015
	    <packing>
1016
	      <property name="padding">0</property>
1017
	      <property name="expand">False</property>
1018
	      <property name="fill">False</property>
1019
	    </packing>
1020
	  </child>
1021
	</widget>
1022
	<packing>
1023
	  <property name="padding">0</property>
1024
	  <property name="expand">False</property>
1025
	  <property name="fill">False</property>
1026
	</packing>
1027
      </child>
1028
    </widget>
962
    </widget>
1029
  </child>
963
  </child>
1030
</widget>
964
</widget>
(-)netapplet-1.0.0/src/netcommon.c (-1 / +28 lines)
Lines 13-19 Link Here
13
13
14
#include "netcommon.h"
14
#include "netcommon.h"
15
15
16
//#define NETCOMMON_DEBUG
16
#define NETCOMMON_DEBUG
17
17
18
#ifdef NETCOMMON_DEBUG
18
#ifdef NETCOMMON_DEBUG
19
# include <time.h>
19
# include <time.h>
Lines 224-226 Link Here
224
224
225
	return escaped;
225
	return escaped;
226
}
226
}
227
228
/* ESSID Related Functions */
229
230
void
231
essid_free (char *essid)
232
{
233
	g_free (essid);
234
}
235
236
gchar *
237
escape_essid_for_key (const gchar *essid)
238
{
239
	gchar *escaped;
240
241
	escaped = g_strdup(essid);
242
	escaped = g_strcanon(escaped, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", '_');
243
	return escaped;
244
}
245
246
gchar *
247
escape_essid_for_quotes (const gchar *essid)
248
{
249
	gchar *escaped;
250
	escaped  = g_strescape(essid, NULL);
251
	return escaped;
252
}
253
(-)netapplet-1.0.0/src/netcommon.h (+4 lines)
Lines 23-26 Link Here
23
23
24
extern gboolean netapplet_get_clipboard (void);
24
extern gboolean netapplet_get_clipboard (void);
25
25
26
void essid_free (char *essid);
27
gchar * escape_essid_for_key (const gchar *essid);
28
gchar * escape_essid_for_quotes (const gchar *essid);
29
26
#endif
30
#endif
(-)netapplet-1.0.0/src/netdaemon.c (-237 / +607 lines)
Lines 13-18 Link Here
13
#include <unistd.h>
13
#include <unistd.h>
14
#include <fcntl.h>
14
#include <fcntl.h>
15
#include <errno.h>
15
#include <errno.h>
16
#include <getopt.h>
16
#include <signal.h>
17
#include <signal.h>
17
#include <sys/types.h>
18
#include <sys/types.h>
18
#include <sys/stat.h>
19
#include <sys/stat.h>
Lines 25-62 Link Here
25
26
26
#include "netcommon.h"
27
#include "netcommon.h"
27
28
28
#define NETWORK_SYSCONF_PATH    "/etc/sysconfig/network"
29
#define PROC_NET_DEV	"/proc/net/dev"
29
#define IFCFG_PREFIX            "ifcfg-"
30
#define CONFD_WIRELESS	"/etc/conf.d/wireless"
30
#define GETCFG_CMD		"/sbin/getcfg"
31
#define NET_INIT_PREFIX	"/etc/init.d/net."
31
#define GETCFG_INTERFACE_CMD	"/sbin/getcfg-interface"
32
#define NET_INIT_ARGS	"--quiet"
32
#define IFUP_BIN		"/sbin/ifup"
33
33
#define IFDOWN_BIN		"/sbin/ifdown"
34
#define ROUTE_CMD			"/sbin/route"
34
#define ROUTE_CMD               "/sbin/route"
35
#define MAX_QUAL_OVERRIDE	90	/* for driver's with a broken max */
35
#define MAX_QUAL_OVERRIDE	90	/* for driver's with a broken max */
36
36
37
#define ROUTE_ARGV              { ROUTE_CMD, "-n", NULL }
37
#define ROUTE_ARGV              { ROUTE_CMD, "-n", NULL }
38
38
39
#define TIMEOUT_INTERVAL        10000
39
#define TIMEOUT_INTERVAL          60000
40
#define TIMEOUT_INTERVAL_ONE_SHOT 20000
40
41
41
typedef struct {
42
typedef struct {
42
	GIOChannel *channel;	/* GIOChannel that requested this scan */
43
	GIOChannel *channel;	/* GIOChannel that requested this scan */
43
	char *interface;	/* network interface we are scanning */
44
	char *interface;		/* network interface we are scanning */
44
	int fd;			/* open fd from iw_sockets_open () */
45
	int fd;					/* open fd from iw_sockets_open () */
45
} ScanningInfo;
46
} ScanningInfo;
46
47
47
typedef struct {
48
typedef struct {
48
	char essid[IW_ESSID_MAX_SIZE + 1];	/* ESSID name */
49
	char essid[IW_ESSID_MAX_SIZE + 1];	/* ESSID name */
49
	int quality;				/* link quality */
50
	int quality;						/* link quality */
50
	gboolean is_encrypted;			/* is this AP encrypted? */
51
	gboolean is_encrypted;				/* is this AP encrypted? */
51
} APInfo;
52
} APInfo;
52
53
53
static GHashTable *hash;			/* hash table for commands */
54
static GHashTable *hash;				/* hash table for commands */
54
static GSList *current_connections;		/* list of GIOChannels */
55
static GSList *current_connections;		/* list of GIOChannels */
55
56
56
static gboolean skip_poll = FALSE;              /* Skip one round of polling,
57
static char *active_iface = NULL;		/* The last active interface */
57
						   for slow network changes */
58
59
static gboolean poll_interfaces (gpointer user_data G_GNUC_UNUSED);
60
static gboolean poll_interfaces_one_shot (gpointer user_data G_GNUC_UNUSED);
61
62
static GSList *
63
essid_extract(gchar *str) {
64
	guint i, start = 0;
65
	gint in_essid = 0;
66
	gchar c, *essid;
67
	
68
	GSList *list = NULL;
69
	
70
	for (i=0; i<strlen(str); i++) {
71
		c = str[i];
72
73
		if (!in_essid) {
74
			if (c == '"') {
75
				start = i+1;
76
				in_essid = 1;
77
			}
78
		} else {
79
			if (c == '\\') {
80
				i++;
81
				continue;
82
			} else if (c == '"') {
83
				gint len = i - start;
84
				essid = g_new0(gchar, len+1);
85
				strncpy(essid, &str[start], len);
86
				list = g_slist_append(list, essid);
87
				
88
				in_essid = 0;
89
			}
90
		}
91
	}
92
93
	return list;
94
}
95
96
static GSList *
97
gentoo_wireless_get_keys() {
98
	GError *err = NULL;
99
	GIOChannel *file;
100
	gchar *data;
101
	gchar **key_data;
102
	GSList *essid_list = NULL;
103
	
104
	file = g_io_channel_new_file( CONFD_WIRELESS, "r", &err );
105
	if( !file ) {
106
		g_error( "Unable to open "CONFD_WIRELESS": %s", 
107
			err->message);
108
		g_error_free(err);
109
		return NULL;
110
	}
111
	
112
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) == 
113
		   G_IO_STATUS_NORMAL && essid_list == NULL) {
114
		
115
		
116
		if (g_str_has_prefix(data, "key_")) { 
117
			key_data = g_strsplit_set (data, "_=", 0);
118
			if 	(key_data[1] != NULL) 
119
				essid_list = g_slist_prepend(essid_list, g_strdup(key_data[1]));
120
121
			g_strfreev(key_data);
122
		}
123
		g_free(data);
124
	}
125
126
	/* close the file */
127
	if ( g_io_channel_shutdown (file, FALSE, &err) != G_IO_STATUS_NORMAL ) {
128
		g_error ("Unable to close "CONFD_WIRELESS" : %s\n",
129
				err->message);
130
		g_error_free (err);
131
	}	
132
	g_io_channel_unref( file );
133
134
	if (essid_list != NULL)
135
		return essid_list;
136
	else 
137
		return NULL;
138
}
139
140
static GSList *
141
gentoo_wireless_get_preferred_aps() {
142
	GError *err = NULL;
143
	GIOChannel *file;
144
	gchar *data;
145
	gchar **pref_data;
146
	GSList *essid_list = NULL;
147
	
148
	file = g_io_channel_new_file( CONFD_WIRELESS, "r", &err );
149
	if( !file ) {
150
		g_error( "Unable to open "CONFD_WIRELESS": %s", 
151
			err->message);
152
		g_error_free(err);
153
		return NULL;
154
	}
155
	
156
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) == 
157
		   G_IO_STATUS_NORMAL && essid_list == NULL) {
158
		
159
		
160
		if (g_str_has_prefix(data, "preferred_aps")) { 
161
			pref_data = g_strsplit_set (data, "()", 0);
162
			if 	(pref_data[1] != NULL) 
163
				essid_list = essid_extract(pref_data[1]);
164
			
165
			g_strfreev(pref_data);
166
		}
167
		g_free(data);
168
	}
169
170
	/* close the file */
171
	if ( g_io_channel_shutdown (file, FALSE, &err) != G_IO_STATUS_NORMAL ) {
172
		g_error ("Unable to close "CONFD_WIRELESS" : %s\n",
173
				err->message);
174
		g_error_free (err);
175
	}	
176
	g_io_channel_unref( file );
177
178
	if (essid_list != NULL)
179
		return essid_list;
180
	else 
181
		return NULL;
182
}
183
184
static void
185
gentoo_wireless_set_preferred_aps(gchar** list) {
186
	GError *err = NULL;
187
	GString *output;
188
	GIOChannel *file;
189
	gchar *data = NULL;
190
	gchar **essid, *escaped; 
191
192
	file = g_io_channel_new_file (CONFD_WIRELESS, "r", &err);
193
	if (!file) {
194
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
195
		g_error_free (err);
196
		return;
197
	}
198
	
199
	output = g_string_sized_new (512);  /* start big to prevent resizing */
200
201
	/* remove the preferred_aps line */
202
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) ==
203
			G_IO_STATUS_NORMAL) {
204
		if (!g_str_has_prefix (data, "preferred_aps"))
205
			g_string_append (output, data);
206
207
		g_free (data);
208
	}
209
210
	if (err) {
211
		g_warning ("Failed to read %s: %s\n", CONFD_WIRELESS, err->message);
212
		g_error_free (err);
213
		return;
214
	}
215
216
	/* add back the updated lines */
217
	g_string_append_printf(output, "preferred_aps=( ");
218
219
	for (essid=&list[0]; *essid != NULL; essid++) {
220
		escaped = escape_essid_for_quotes(*essid);
221
		g_string_append_printf(output, "\"%s\" ", escaped);
222
		g_free(escaped);
223
	}
224
225
	g_string_append_printf(output, ")\n");
226
	
227
	/* close, truncate, and reopen the file for writing */
228
	g_io_channel_unref (file);
229
	file = g_io_channel_new_file (CONFD_WIRELESS, "w", &err);
230
	if (!file) {
231
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
232
		g_error_free (err);
233
		g_string_free(output, TRUE);
234
		return;
235
	}
58
236
59
static char *active_iface = NULL;               /* The last active interface */
237
	/* write out the new file in one swoop */
238
	if (g_io_channel_write_chars (file, output->str, -1, NULL, &err) !=
239
			G_IO_STATUS_NORMAL) {
240
		g_warning ("Failed to write to %s: %s\n", CONFD_WIRELESS, err->message);
241
		g_error_free (err);
242
		g_string_free(output, TRUE);
243
		g_io_channel_unref (file);
244
		return;
245
	}
246
	g_string_free(output, TRUE);
247
	g_io_channel_flush (file, NULL);
248
	g_io_channel_unref (file);
249
}
250
251
static guint
252
gentoo_verify_device(gchar *device) {
253
	gchar *initscript;
254
	guint verify;
255
	
256
	initscript = g_strconcat( NET_INIT_PREFIX, device, NULL );
257
	
258
	/* make sure we have an initscript for this device */
259
	if (g_file_test(initscript, G_FILE_TEST_EXISTS))
260
		verify = 1;
261
	else
262
		verify = 0;
263
	
264
	g_free( initscript );
265
	
266
	return verify;
267
}
60
268
61
static const char *
269
static const char *
62
get_network_type (const char *interface)
270
get_network_type (const char *interface)
Lines 87-163 Link Here
87
get_interfaces (void)
295
get_interfaces (void)
88
{
296
{
89
	GError *err = NULL;
297
	GError *err = NULL;
90
	GDir *dir;
91
	const char *name;
92
	GSList *iface_list = NULL;
298
	GSList *iface_list = NULL;
93
299
	GIOChannel *file;
94
	dir = g_dir_open (NETWORK_SYSCONF_PATH, 0, &err);
300
	gchar *data, *data2;
95
	if (!dir) {
301
	gchar **ifacedata;
96
		g_error ("Unable to open "NETWORK_SYSCONF_PATH": %s",
302
	guint skip;
97
			 err->message);
303
	
304
	file = g_io_channel_new_file( PROC_NET_DEV, "r", &err );
305
	if( !file ) {
306
		g_error( "Unable to open "PROC_NET_DEV": %s", 
307
			err->message);
308
		g_error_free(err);
98
		return NULL;
309
		return NULL;
99
	}
310
	}
100
311
	
101
	do {
312
	/* extract devices known to kernel */	
102
		char *interface;
313
	skip = 2;
103
		const char *argv[3];
314
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) == G_IO_STATUS_NORMAL) {
104
315
		/* skip first two lines */
105
		name = g_dir_read_name (dir);
316
		if (skip) {
106
		if (name == NULL || strncmp (name, IFCFG_PREFIX,
317
			skip--;
107
					     sizeof (IFCFG_PREFIX) - 1) != 0)
318
			g_free(data);
108
			continue;
109
110
		/* Blacklist the loopback device */
111
		if (strcmp (name, IFCFG_PREFIX"lo") == 0)
112
			continue;
113
114
		/* 
115
		 * Blacklist "ip6tnl*" and "mip6mnha" interfaces, which
116
		 * the SUSE package miplv6 dumps into the sysconf path.
117
		 */
118
		if (g_str_has_prefix (name, IFCFG_PREFIX"ip6tnl") ||
119
		    g_str_has_prefix (name, IFCFG_PREFIX"mipmnha"))
120
			continue;
121
122
		argv[0] = GETCFG_INTERFACE_CMD;
123
		argv[1] = (char *) name + sizeof (IFCFG_PREFIX) - 1;
124
		argv[2] = NULL;
125
126
		if (!g_spawn_sync (NULL, (char **) argv, NULL, 0,
127
				   NULL, NULL, &interface, NULL,
128
				   NULL, &err)) {
129
			g_warning ("Unable to execute "
130
				   GETCFG_INTERFACE_CMD": %s",
131
				   err->message);
132
			g_error_free (err);
133
			continue;
319
			continue;
134
		}
320
		}
135
321
		
136
		if (interface != NULL && interface[0] != '\0') {
322
		data2 = g_strchug(data);
137
			/* strip whitespace */
323
		ifacedata =  g_strsplit_set (data2, ":", 0);
138
			interface = g_strstrip (interface);
324
		/* if the device is no the loopback */
139
325
		if (strcmp(ifacedata[0], "lo")) { 
140
			/*
326
			if (gentoo_verify_device(ifacedata[0])) {
141
			 * Workaround for some strange behavior in
327
				iface_list = g_slist_prepend (iface_list, g_strdup(ifacedata[0]));
142
			 * getcfg-interface.  If you bring up a ppp0
143
			 * interface, and if you run it (as root), it
144
			 * might return "no" as the interface name while
145
			 * it's in the process of connecting.  If that's
146
			 * the case, then return the name as the
147
			 * interface instead.
148
			 */
149
			if (strcmp (interface, "no") == 0) {
150
				g_free (interface);
151
				interface = g_strdup (argv[1]);
152
			}
328
			}
329
		}
330
			
331
		g_strfreev(ifacedata);
332
		g_free(data);
333
	}
153
334
154
			iface_list = g_slist_prepend (iface_list, interface);
335
	/* close the file */
155
		} else
336
	if ( g_io_channel_shutdown (file, FALSE, &err) != G_IO_STATUS_NORMAL ) {
156
			g_free (interface);
337
		g_error ("Unable to close /etc/conf.d/net : %s\n",
157
338
				err->message);
158
	} while (name);
339
		g_error_free (err);
159
340
	}	
160
	g_dir_close (dir);
341
	g_io_channel_unref( file );
161
342
162
	return iface_list;
343
	return iface_list;
163
}
344
}
Lines 171-189 Link Here
171
	iface_list = get_interfaces ();
352
	iface_list = get_interfaces ();
172
353
173
	for (iter = iface_list; iter != NULL; iter = iter->next) {
354
	for (iter = iface_list; iter != NULL; iter = iter->next) {
174
		const char *argv[3], *interface = iter->data;
355
		const char *argv[4], *interface = iter->data;
356
		gchar *initscript = g_strconcat( NET_INIT_PREFIX, interface, NULL );
175
357
176
		argv[0] = IFDOWN_BIN;
358
		/* GENTOO: we use the gentoo stop init scripts
177
		argv[1] = interface;
359
		   when bringing the interfaces down
178
		argv[2] = NULL;
360
		   ie /etc/init.d/net.IFX stop
361
		 */
362
		argv[0] = initscript;
363
		argv[1] = NET_INIT_ARGS;
364
		argv[2] = "stop";
365
		argv[3] = NULL;
179
366
180
		if (!g_spawn_sync (NULL, (char **) argv, NULL,
367
		if (!g_spawn_sync (NULL, (char **) argv, NULL,
181
				   0, NULL, NULL, NULL, NULL, NULL,
368
				   0, NULL, NULL, NULL, NULL, NULL,
182
				   &err)) {
369
				   &err)) {
183
			g_warning ("Unable to exec " IFDOWN_BIN ": %s",
370
			g_warning ("Unable to exec %s stop: %s", initscript,
184
				   err->message);
371
				   err->message);
185
			g_error_free (err);
372
			g_error_free (err);
186
		}
373
		}
374
		g_free( initscript );
187
	}
375
	}
188
376
189
	g_free (active_iface);
377
	g_free (active_iface);
Lines 203-213 Link Here
203
}
391
}
204
392
205
static void
393
static void
206
netdaemon_do_change_active (GIOChannel *channel G_GNUC_UNUSED, char **args)
394
netdaemon_do_set_active (GIOChannel *channel G_GNUC_UNUSED, char **args)
207
{
395
{
208
	const char *argv[3];
396
	const char *argv[4];
209
	GError *err = NULL;
397
	GError *err = NULL;
210
	int ret;
398
	int ret;
399
	gchar* initscript;
211
400
212
	if (!args[1])
401
	if (!args[1])
213
		return;
402
		return;
Lines 219-233 Link Here
219
	 */
408
	 */
220
	netdaemon_disconnect_all ();
409
	netdaemon_disconnect_all ();
221
410
222
	argv[0] = IFUP_BIN;
411
	/* GENTOO: as for disconnect_all() we use the init scripts
223
	argv[1] = args[1];
412
	   found in /etc/init.d/net.IFX here
224
	argv[2] = NULL;
413
	 */
414
	initscript = g_strconcat( NET_INIT_PREFIX, args[1], NULL );
415
	argv[0] = initscript;
416
	argv[1] = NET_INIT_ARGS;
417
	argv[2] = "start";
418
	argv[3] = NULL;
225
419
226
	if (!g_spawn_sync (NULL, (char **) argv, NULL,
420
	if (!g_spawn_sync (NULL, (char **) argv, NULL,
227
			   0, NULL, NULL, NULL, NULL, &ret,
421
			   0, NULL, NULL, NULL, NULL, &ret,
228
			   &err)) {
422
			   &err)) {
229
		g_warning ("Unable to exec " IFUP_BIN ": %s",
423
		g_warning ("Unable to exec %s start: %s", initscript, 
230
			   err->message);
424
				err->message);
231
		g_error_free (err);
425
		g_error_free (err);
232
	}
426
	}
233
427
Lines 237-251 Link Here
237
		active_iface = g_strdup (args[1]);
431
		active_iface = g_strdup (args[1]);
238
	}
432
	}
239
433
240
	/* 
434
	g_free( initscript );
241
	 * Let's skip the next poll so we can wait for these interfaces to
435
242
	 * come up.
436
	/* add a one time call to poll_interfaces after the
243
	 */
437
	 * active update applies */
244
	skip_poll = TRUE;
438
	g_timeout_add (TIMEOUT_INTERVAL_ONE_SHOT, poll_interfaces_one_shot, NULL);
245
}
439
}
246
440
247
static void
441
static void
248
netdaemon_do_list_interfaces (GIOChannel *channel G_GNUC_UNUSED,
442
netdaemon_do_get_interfaces (GIOChannel *channel G_GNUC_UNUSED,
249
			      char **args G_GNUC_UNUSED)
443
			      char **args G_GNUC_UNUSED)
250
{
444
{
251
	GSList *iface_list, *iter;
445
	GSList *iface_list, *iter;
Lines 263-269 Link Here
263
		if (active_iface != NULL &&
457
		if (active_iface != NULL &&
264
		    strcmp (active_iface, interface) == 0)
458
		    strcmp (active_iface, interface) == 0)
265
			found_active = TRUE;
459
			found_active = TRUE;
266
460
		
267
		type = get_network_type (interface);
461
		type = get_network_type (interface);
268
462
269
		if (ifaces == NULL)
463
		if (ifaces == NULL)
Lines 326-345 Link Here
326
		}
520
		}
327
	}
521
	}
328
522
329
	/*
523
	/* Changed the behavior so that if the no active iface is 
330
	 * FIXME: Not totally sure this is right.  We may want to check to
524
	 * detected in the above route command, assume we have been 
331
	 * make sure the interface is up before unconditionally sending
525
	 * disconnected.
332
	 * the old active iface, but this is better than nothing.
333
	 */
526
	 */
334
	if (active_iface != NULL)
527
	
335
		netcommon_send_message (channel, "active", active_iface, NULL);
528
	if (active_iface != NULL) {
336
	else {
529
		g_free(active_iface);
337
		/*
530
		active_iface = NULL;
338
		 * we did not find an active interface - tell the client
339
		 * as much
340
		 */
341
		netcommon_send_message (channel, "disconnected", NULL);
342
	}
531
	}
532
	
533
	netcommon_send_message (channel, "disconnected", NULL);
343
534
344
out:
535
out:
345
	g_strfreev (lines);
536
	g_strfreev (lines);
Lines 411-416 Link Here
411
	for (iter = aps; iter != NULL; iter = iter->next) {
602
	for (iter = aps; iter != NULL; iter = iter->next) {
412
		APInfo *ap = iter->data, *best;
603
		APInfo *ap = iter->data, *best;
413
604
605
606
		/* essid hidden filter, this may need work for other network drivers */
607
		if (strcmp(ap->essid, "<hidden>") == 0)
608
			continue;
609
414
		/*
610
		/*
415
		 * Scanning returns an entry for each AP on a given ESSID, but
611
		 * Scanning returns an entry for each AP on a given ESSID, but
416
		 * we only want to see one entry per ESSID, with the highest
612
		 * we only want to see one entry per ESSID, with the highest
Lines 662-678 Link Here
662
	}
858
	}
663
}
859
}
664
860
665
static char *
861
static void
666
escape_essid (const char *essid)
862
netdaemon_do_list_accesspoints (GIOChannel *channel G_GNUC_UNUSED,
863
			      char **args G_GNUC_UNUSED)
864
{
865
	GSList *iface_list, *iter;
866
	char *pargs[3];
867
868
	iface_list = get_interfaces ();
869
	if (!iface_list)
870
		return;
871
872
	pargs[0] = "accesspoints";
873
	pargs[1] = NULL;
874
	pargs[2] = NULL;
875
	
876
	for (iter = iface_list; iter != NULL; iter = iter->next) {
877
		const char *interface = iter->data;
878
		const char *type;
879
880
		type = get_network_type (interface);
881
		
882
		if (strcmp (type, TYPE_WIRELESS) == 0) {
883
			pargs[1] = g_strdup(interface);
884
		}
885
	}
886
887
	g_slist_foreach (iface_list, (GFunc) g_free, NULL);
888
	g_slist_free (iface_list);
889
890
	if (pargs[1] != NULL) {
891
		netdaemon_do_get_accesspoints(channel, pargs); 
892
		g_free(pargs[1]);
893
	}
894
}
895
896
static gchar*
897
essid_compress(gchar* essid) {
898
		
899
	gchar c;
900
	guint i, j = 0;
901
	gchar *cessid;
902
	
903
	cessid = g_new0(gchar, strlen(essid) + 1);
904
	
905
	for (i=0; i<strlen(essid); i++) {
906
		c = essid[i];
907
		
908
		if (i == (strlen(essid)-1)) {
909
			cessid[j++] = essid[i];
910
		} else {
911
			if (essid[i] == '\\') {
912
				if (essid[i+1] == ' ') {
913
					cessid[j++] = essid[i];
914
				}
915
			} else {
916
				cessid[j++] = essid[i];
917
			}
918
		}
919
	}
920
921
	return cessid;
922
}
923
924
static void
925
netdaemon_do_get_keys (GIOChannel *channel G_GNUC_UNUSED, char **args G_GNUC_UNUSED)
926
{
927
	GSList *essid_list;
928
	GSList *iter;
929
	GString *msg;
930
931
    msg = g_string_sized_new (256);
932
	g_string_printf(msg, "keys");
933
	
934
	essid_list = gentoo_wireless_get_keys();
935
	if (essid_list == NULL)
936
		return;
937
938
	for (iter=essid_list; iter!=NULL; iter=iter->next) {
939
		/* essid is already in a form suitable for sending*/
940
		g_string_append_printf(msg, " %s", (gchar*) iter->data);
941
	}
942
943
	g_slist_foreach(essid_list, (GFunc) essid_free, NULL);
944
	g_slist_free(essid_list);
945
	
946
	netcommon_send_message(channel, msg->str, NULL);
947
}
948
	
949
static void
950
netdaemon_do_get_preferred_aps (GIOChannel *channel G_GNUC_UNUSED, char **args G_GNUC_UNUSED)
667
{
951
{
668
	char **tokens;
952
	GSList *essid_list;
669
	char *escaped;
953
	GSList *iter;
954
	GString *msg;
955
	gchar *essid, *escaped;
956
		
957
958
    msg = g_string_sized_new (256);
959
	g_string_printf(msg, "preferred_aps");
960
	
961
	essid_list = gentoo_wireless_get_preferred_aps();
962
	if (essid_list == NULL)
963
		return;
670
964
671
	tokens = g_strsplit (essid, "'", 0);
965
	for (iter=essid_list; iter!=NULL; iter=iter->next) {
672
	escaped = g_strjoinv ("'\\''", tokens);
966
		essid = essid_compress(iter->data);
673
	g_strfreev (tokens);
967
		escaped = netcommon_escape_argument (essid);
968
		g_string_append_printf(msg, " %s", escaped);
969
		g_free(escaped);
970
		g_free(essid);
971
	}
972
973
	g_slist_foreach(essid_list, (GFunc) essid_free, NULL);
974
	g_slist_free(essid_list);
975
	
976
	netcommon_send_message(channel, msg->str, NULL);
977
}
674
978
675
	return escaped;
979
static void
980
netdaemon_do_set_preferred_aps (GIOChannel *channel G_GNUC_UNUSED, char **args G_GNUC_UNUSED)
981
{
982
	gentoo_wireless_set_preferred_aps(&args[1]);	
676
}
983
}
677
984
678
/*
985
/*
Lines 681-815 Link Here
681
 * args[0] is 'essid' (ignored)
988
 * args[0] is 'essid' (ignored)
682
 * args[1] is the current interface
989
 * args[1] is the current interface
683
 * args[2] is the new ESSID
990
 * args[2] is the new ESSID
684
 * args[3] is the new ESSID's wireless encryption key ("" if no key)
991
 * args[3] tells us whether to manipulate the key entry
992
 * args[4] is the new ESSID's wireless encryption key ("" if no key)
685
 */
993
 */
686
static void
994
static void
687
netdaemon_do_change_essid (GIOChannel *channel, char **args)
995
netdaemon_do_set_essid (GIOChannel *channel, char **args)
688
{
996
{
997
	GError *err = NULL;
689
	GString *output;
998
	GString *output;
690
	const char *argv[3];
691
	char *data = NULL, *getcfg, *p, *cfg;
692
	GIOChannel *file;
999
	GIOChannel *file;
693
	GError *err = NULL;
1000
	char *data = NULL, *essid_prefix, *key_prefix, *escaped_essid;
694
	char *escaped_essid;
695
1001
696
	argv[0] = GETCFG_CMD;
1002
	file = g_io_channel_new_file (CONFD_WIRELESS, "r", &err);
697
	argv[1] = args[1];
1003
	if (!file) {
698
	argv[2] = NULL;
1004
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
1005
		g_error_free (err);
1006
		return;
1007
	}
1008
	
1009
	/* setup wireless-config strings */
1010
	essid_prefix = g_strdup_printf("essid_%s=", args[1]);
1011
	escaped_essid = escape_essid_for_key(args[2]);
1012
	key_prefix = g_strdup_printf("key_%s=", escaped_essid);
1013
	g_free(escaped_essid);
1014
	
1015
	output = g_string_sized_new (512);  /* start big to prevent resizing */
699
1016
700
	/* get the configuration information for this interface */
1017
	/* remove the offending lines */
701
	if (!g_spawn_sync (NULL, (char **) argv, NULL, 0, NULL, NULL,
1018
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) ==
702
			   &getcfg, NULL, NULL, &err)) {
1019
			G_IO_STATUS_NORMAL) {
703
			g_warning ("Unable to execute "GETCFG_CMD": %s",
1020
		
704
				   err->message);
1021
		if (!g_str_has_prefix (data, essid_prefix) && 
705
			g_error_free (err);
1022
			(!g_str_has_prefix (data, key_prefix) || !strcmp(args[3], "0")))
706
			return;
1023
			g_string_append (output, data);
1024
1025
		g_free (data);
707
	}
1026
	}
708
1027
709
	/* get the ifcfg name for this interface */
1028
	if (err) {
710
	cfg = strstr (getcfg, "HWD_CONFIG_0");
1029
		g_warning ("Failed to read %s: %s\n", CONFD_WIRELESS, err->message);
711
	if (!cfg) {
1030
		g_error_free (err);
712
		g_warning ("Unable to determine configuration file for "
1031
		g_free(essid_prefix);
713
			   "interface %s", args[1]);
1032
		g_free(key_prefix);
714
		goto out_free_getcfg;
1033
		return;
715
	}
716
	cfg = strstr (cfg, "=");
717
	if (!cfg) {
718
		g_warning ("Unable to determine configuration file for "
719
			   "interface %s", args[1]);
720
		goto out_free_getcfg;
721
	}
722
	cfg++;
723
	p = strstr (cfg, ";");
724
	if (!p) {
725
		g_warning ("Unable to determine configuration file for "
726
			   "interface %s", args[1]);
727
		goto out_free_getcfg;
728
	}
1034
	}
729
	p[0] = '\0';
730
	cfg = g_strdup_printf (NETWORK_SYSCONF_PATH"/"IFCFG_PREFIX"%s", cfg);
731
1035
732
	output = g_string_sized_new (512);  /* start big to prevent resizing */
1036
	/* add back the updated lines */
1037
	escaped_essid = escape_essid_for_quotes(args[2]);
1038
	g_string_append_printf (output, "%s\"%s\"\n", essid_prefix, escaped_essid);
1039
	g_free(escaped_essid);
1040
	if (!strcmp(args[3], "1") && strcmp(args[4],"")) {
1041
		g_string_append_printf (output, "%s\"%s\"\n", key_prefix, args[4]);
1042
	}
1043
	
1044
	g_free(essid_prefix);
1045
	g_free(key_prefix);
1046
1047
	/* close, truncate, and reopen the file for writing */
1048
	g_io_channel_unref (file);
1049
	file = g_io_channel_new_file (CONFD_WIRELESS, "w", &err);
1050
	if (!file) {
1051
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
1052
		g_error_free (err);
1053
		g_string_free(output, TRUE);
1054
		return;
1055
	}
733
1056
734
	file = g_io_channel_new_file (cfg, "r", &err);
1057
	/* write out the new file in one swoop */
1058
	if (g_io_channel_write_chars (file, output->str, -1, NULL, &err) !=
1059
			G_IO_STATUS_NORMAL) {
1060
		g_warning ("Failed to write to %s: %s\n", CONFD_WIRELESS, err->message);
1061
		g_error_free (err);
1062
		g_string_free(output, TRUE);
1063
		g_io_channel_unref (file);
1064
		return;
1065
	}
1066
	g_string_free(output, TRUE);
1067
	g_io_channel_flush (file, NULL);
1068
	g_io_channel_unref (file);
1069
1070
	netdaemon_do_set_active (channel, args);
1071
			
1072
	return;
1073
}
1074
1075
static void
1076
netdaemon_do_clr_essid (GIOChannel *channel, char **args)
1077
{
1078
	GError *err = NULL;
1079
	GString *output;
1080
	GIOChannel *file;
1081
	char *data = NULL, *essid_prefix;
1082
1083
	file = g_io_channel_new_file (CONFD_WIRELESS, "r", &err);
735
	if (!file) {
1084
	if (!file) {
736
		g_warning ("Failed to open %s: %s\n", cfg, err->message);
1085
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
737
		g_error_free (err);
1086
		g_error_free (err);
738
		goto out_free_getcfg;
1087
		return;
739
	}
1088
	}
1089
	
1090
	/* setup wireless-config strings */
1091
	essid_prefix = g_strdup_printf("essid_%s=", args[1]);
1092
	
1093
	output = g_string_sized_new (512);  /* start big to prevent resizing */
740
1094
741
	/* remove the offending lines */
1095
	/* remove the offending lines */
742
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) ==
1096
	while (g_io_channel_read_line (file, &data, NULL, NULL, &err) ==
743
			G_IO_STATUS_NORMAL) {
1097
			G_IO_STATUS_NORMAL) {
744
		if (!g_str_has_prefix (data, "WIRELESS_ESSID=") &&
1098
		
745
		    !g_str_has_prefix (data, "WIRELESS_NWID=''") &&
1099
		if (!g_str_has_prefix (data, essid_prefix))
746
		    !g_str_has_prefix (data, "WIRELESS_KEY=''") &&
747
		    !g_str_has_prefix (data, "WIRELESS_KEY_0=") &&
748
		    !g_str_has_prefix (data, "WIRELESS_KEY_LENGTH=") &&
749
		    !g_str_has_prefix (data, "WIRELESS_AP") &&
750
		    !g_str_has_prefix (data, "WIRELESS_BITRATE") &&
751
		    !g_str_has_prefix (data, "WIRELESS_CHANNEL") &&
752
		    !g_str_has_prefix (data, "WIRELESS_MODE") &&
753
		    !g_str_has_prefix (data, "WIRELESS_FREQUENCY") &&
754
		    !g_str_has_prefix (data, "WIRELESS_DEFAULT_KEY="))
755
			g_string_append (output, data);
1100
			g_string_append (output, data);
756
1101
757
		g_free (data);
1102
		g_free (data);
758
	}
1103
	}
1104
	
1105
	g_free(essid_prefix);
759
1106
760
	if (err) {
1107
	if (err) {
761
		g_warning ("Failed to read %s: %s\n", cfg, err->message);
1108
		g_warning ("Failed to read %s: %s\n", CONFD_WIRELESS, err->message);
762
		g_error_free (err);
1109
		g_error_free (err);
763
		goto out;
1110
		return;
764
	}
1111
	}
765
1112
766
	/* add back the updated lines */
767
	escaped_essid = escape_essid (args[2]);
768
	g_string_append_printf (output, "WIRELESS_ESSID='%s'\n",
769
				escaped_essid);
770
	g_free (escaped_essid);
771
772
	g_string_append_printf (output, "WIRELESS_KEY_0='%s'\n", args[3]);
773
774
	/* return the other lines to a nice sane default */
775
	g_string_append_printf (output, "WIRELESS_NWID=''\n");
776
	g_string_append_printf (output, "WIRELESS_KEY=''\n");
777
	g_string_append_printf (output, "WIRELESS_DEFAULT_KEY='0'\n");
778
	g_string_append_printf (output, "WIRELESS_KEY_LENGTH='128'\n");
779
	g_string_append_printf (output, "WIRELESS_AP=''\n");
780
	g_string_append_printf (output, "WIRELESS_BITRATE='auto'\n");
781
	g_string_append_printf (output, "WIRELESS_CHANNEL=''\n");
782
	g_string_append_printf (output, "WIRELESS_MODE='Managed'\n");
783
	g_string_append_printf (output, "WIRELESS_FREQUENCY=''");
784
785
	/* close, truncate, and reopen the file for writing */
1113
	/* close, truncate, and reopen the file for writing */
786
	g_io_channel_unref (file);
1114
	g_io_channel_unref (file);
787
	file = g_io_channel_new_file (cfg, "w", &err);
1115
	file = g_io_channel_new_file (CONFD_WIRELESS, "w", &err);
788
	if (!file) {
1116
	if (!file) {
789
		g_warning ("Failed to open %s: %s\n", cfg, err->message);
1117
		g_warning ("Failed to open %s: %s\n", CONFD_WIRELESS, err->message);
790
		g_error_free (err);
1118
		g_error_free (err);
791
		goto out;
1119
		g_string_free(output, TRUE);
1120
		return;
792
	}
1121
	}
793
1122
794
	/* write out the new file in one swoop */
1123
	/* write out the new file in one swoop */
795
	if (g_io_channel_write_chars (file, output->str, -1, NULL, &err) !=
1124
	if (g_io_channel_write_chars (file, output->str, -1, NULL, &err) !=
796
			G_IO_STATUS_NORMAL) {
1125
			G_IO_STATUS_NORMAL) {
797
		g_warning ("Failed to write to %s: %s\n", cfg, err->message);
1126
		g_warning ("Failed to write to %s: %s\n", CONFD_WIRELESS, err->message);
798
		g_error_free (err);
1127
		g_error_free (err);
799
		goto out;
1128
		g_string_free(output, TRUE);
1129
		g_io_channel_unref (file);
1130
		return;
800
	}
1131
	}
801
1132
	g_string_free(output, TRUE);
802
	g_io_channel_flush (file, NULL);
1133
	g_io_channel_flush (file, NULL);
803
804
	netdaemon_do_change_active (channel, args);
805
806
out:
807
	g_string_free (output, TRUE);
808
	g_io_channel_unref (file);
1134
	g_io_channel_unref (file);
809
	g_free (cfg);
810
1135
811
out_free_getcfg:
1136
	if (!strcmp(args[2], "1")) 
812
	g_free (getcfg);
1137
		netdaemon_do_set_active (channel, args);
1138
	
1139
	return;
813
}
1140
}
814
1141
815
static void
1142
static void
Lines 850-860 Link Here
850
		iw_pr_ether (ap_addr, wrq.u.ap_addr.sa_data);
1177
		iw_pr_ether (ap_addr, wrq.u.ap_addr.sa_data);
851
1178
852
		if (!is_valid_ap_address (ap_addr)) {
1179
		if (!is_valid_ap_address (ap_addr)) {
853
			/* This is kind of ugly... */
1180
			char *argv[] = { "clr_essid", (char *) interface,
854
			char *argv[] = { "essid", (char *) interface,
1181
					 "0", NULL };
855
					 "any", "", NULL };
856
1182
857
			netdaemon_do_change_essid (channel, argv);
1183
			netdaemon_do_clr_essid (channel, argv);
858
			goto out;
1184
			goto out;
859
		}
1185
		}
860
	}
1186
	}
Lines 922-927 Link Here
922
		current_connections = g_slist_prepend (current_connections,
1248
		current_connections = g_slist_prepend (current_connections,
923
						       gio);
1249
						       gio);
924
		g_io_add_watch (gio, G_IO_HUP, connection_hup, NULL);
1250
		g_io_add_watch (gio, G_IO_HUP, connection_hup, NULL);
1251
1252
		/* after new connection is made, poll interfaces so
1253
		 * the client gets an immediate update */
1254
		poll_interfaces(NULL);
925
	}
1255
	}
926
1256
927
	/* our listener socket hung up - we are dead */
1257
	/* our listener socket hung up - we are dead */
Lines 995-1055 Link Here
995
	if (!hash)
1325
	if (!hash)
996
		g_error ("Failed to initialize the hash table\n");
1326
		g_error ("Failed to initialize the hash table\n");
997
1327
998
	g_hash_table_insert (hash, "change", netdaemon_do_change_active);
1328
	g_hash_table_insert (hash, "get_interfaces", netdaemon_do_get_interfaces);
999
	g_hash_table_insert (hash, "disconnect", netdaemon_do_disconnect);
1000
	g_hash_table_insert (hash, "list_interfaces",
1001
			     netdaemon_do_list_interfaces);
1002
	g_hash_table_insert (hash, "get_active", netdaemon_do_get_active);
1329
	g_hash_table_insert (hash, "get_active", netdaemon_do_get_active);
1003
	g_hash_table_insert (hash, "wireless", netdaemon_do_get_wireless);
1330
	g_hash_table_insert (hash, "set_active", netdaemon_do_set_active);
1004
	g_hash_table_insert (hash, "accesspoints",
1331
	g_hash_table_insert (hash, "disconnect", netdaemon_do_disconnect);
1005
			     netdaemon_do_get_accesspoints);
1332
	g_hash_table_insert (hash, "get_wireless", netdaemon_do_get_wireless);
1006
	g_hash_table_insert (hash, "essid", netdaemon_do_change_essid);
1333
	g_hash_table_insert (hash, "get_accesspoints", netdaemon_do_get_accesspoints);
1334
	g_hash_table_insert (hash, "get_preferred_aps", netdaemon_do_get_preferred_aps);
1335
	g_hash_table_insert (hash, "set_preferred_aps", netdaemon_do_set_preferred_aps);
1336
	g_hash_table_insert (hash, "set_essid", netdaemon_do_set_essid);
1337
	g_hash_table_insert (hash, "clr_essid", netdaemon_do_clr_essid);
1338
	g_hash_table_insert (hash, "get_keys", netdaemon_do_get_keys);
1007
}
1339
}
1008
1340
1009
static gboolean
1341
static gboolean
1010
poll_interfaces (gpointer user_data G_GNUC_UNUSED)
1342
poll_interfaces (gpointer user_data G_GNUC_UNUSED)
1011
{
1343
{
1012
	GSList *iface_list;
1013
	GSList *iter;
1344
	GSList *iter;
1014
1345
1015
	/*
1016
	 * Skip this round of polling since we just activated an interface
1017
	 * and don't want to be overzealous in case the interface doesn't
1018
	 * come up right away.
1019
	 */
1020
	if (skip_poll) {
1021
		skip_poll = FALSE;
1022
		return TRUE;
1023
	}
1024
1025
	iface_list = get_interfaces ();
1026
1027
	for (iter = current_connections; iter != NULL; iter = iter->next) {
1346
	for (iter = current_connections; iter != NULL; iter = iter->next) {
1028
		GIOChannel *channel = iter->data;
1347
		GIOChannel *channel = iter->data;
1029
1348
1030
		netdaemon_do_list_interfaces (channel, NULL);
1349
		netdaemon_do_get_interfaces (channel, NULL);
1031
		netdaemon_do_get_active (channel, NULL);
1350
		netdaemon_do_get_active (channel, NULL);
1351
		netdaemon_do_list_accesspoints (channel, NULL);
1032
	}
1352
	}
1033
1353
1034
	g_slist_foreach (iface_list, (GFunc) g_free, NULL);
1035
	g_slist_free (iface_list);
1036
1037
	return TRUE;
1354
	return TRUE;
1038
}
1355
}
1039
1356
1357
static gboolean
1358
poll_interfaces_one_shot(gpointer user_data G_GNUC_UNUSED)
1359
{
1360
	poll_interfaces(NULL);
1361
	return FALSE;
1362
}
1363
1040
static void
1364
static void
1041
netdaemon_init_timeouts (void)
1365
netdaemon_init_timeouts (void)
1042
{
1366
{
1043
	g_timeout_add (TIMEOUT_INTERVAL, poll_interfaces, NULL);
1367
	g_timeout_add (TIMEOUT_INTERVAL, poll_interfaces, NULL);
1044
}
1368
}
1045
1369
1370
static void
1371
netdaemon_print_usage (void)
1372
{
1373
	fprintf (stderr, "\n" "usage : netdaemon [--no-daemon] [--help]\n");
1374
	fprintf (stderr,
1375
		"\n"
1376
		"        --no-daemon    Don't become a daemon\n"
1377
		"        --help         Show this information and exit\n"
1378
		"\n");
1379
}
1380
1046
int
1381
int
1047
main (void)
1382
main (int argc, char *argv[])
1048
{
1383
{
1049
	GMainLoop *loop;
1384
	GMainLoop *loop;
1050
	gboolean daemonize = TRUE;
1385
	gboolean daemonize = TRUE;
1051
1386
1052
	/* FIXME: add cmdline option parsing here, e.g. for daemonize */
1387
	/* Parse options: Copied from NetworkManager ;) */
1388
	while (1)
1389
	{
1390
		int c;
1391
		int option_index = 0;
1392
		const char *opt;
1393
1394
		static struct option options[] = {
1395
			{"no-daemon",   0, NULL, 0},
1396
			{"help",        0, NULL, 0},
1397
			{NULL,          0, NULL, 0}
1398
		};
1399
1400
		c = getopt_long (argc, argv, "", options, &option_index);
1401
		if (c == -1)
1402
			break;
1403
1404
		switch (c)
1405
		{
1406
		case 0:
1407
			opt = options[option_index].name;
1408
			if (strcmp (opt, "help") == 0)
1409
			{
1410
				netdaemon_print_usage ();
1411
				exit (EXIT_SUCCESS);
1412
			}
1413
			else if (strcmp (opt, "no-daemon") == 0)
1414
				daemonize = FALSE;
1415
			break;
1416
1417
		default:
1418
			netdaemon_print_usage ();
1419
			exit (EXIT_FAILURE);
1420
			break;
1421
		}
1422
	}
1053
1423
1054
	if (daemonize) {
1424
	if (daemonize) {
1055
		int fd;
1425
		int fd;

Return to bug 68390