gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r794 - in GNUnet: . src/conf


From: durner
Subject: [GNUnet-SVN] r794 - in GNUnet: . src/conf
Date: Thu, 19 May 2005 11:38:53 -0700 (PDT)

Author: durner
Date: 2005-05-19 11:38:15 -0700 (Thu, 19 May 2005)
New Revision: 794

Added:
   GNUnet/src/conf/wizard_curs.c
   GNUnet/src/conf/wizard_util.c
   GNUnet/src/conf/wizard_util.h
Modified:
   GNUnet/configure.ac
   GNUnet/src/conf/Makefile.am
   GNUnet/src/conf/confdata.c
   GNUnet/src/conf/gnunet-setup.c
   GNUnet/src/conf/mconf.c
   GNUnet/src/conf/mconf_dialog.h
   GNUnet/src/conf/mconf_util.c
   GNUnet/src/conf/wizard.c
   GNUnet/src/conf/wizard_callbacks.c
Log:
- menuconfig: support for pdcurses and MinGW
- new curses-based wizard
- allow preformatted output in dialog_msgbox()es

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/configure.ac 2005-05-19 18:38:15 UTC (rev 794)
@@ -321,14 +321,16 @@
 
 # GNUnet Setup
 curses=1
+pdcurses=0
 AC_CHECK_HEADER([ncurses.h], [AC_DEFINE([CURSES_LOC], [<ncurses.h>], [Curses 
location])],
  [AC_CHECK_HEADER([ncurses/ncurses.h], AC_DEFINE([CURSES_LOC], 
[<ncurses/ncurses.h>]),
  [AC_CHECK_HEADER([curses.h], AC_DEFINE([CURSES_LOC], [<curses.h>]),
  [AC_CHECK_HEADER([ncurses/curses.h], AC_DEFINE([CURSES_LOC], 
[<ncurses/curses.h>]),
  curses=0)])])])
-AC_CHECK_LIB(ncurses, scrollok,,curses=0)
+AC_CHECK_LIB(ncurses, scrollok,,AC_CHECK_LIB(pdcurses, 
scrollok,pdcurses=1,curses=0))
 AC_DEFINE_UNQUOTED([HAVE_CURSES], $curses, [We have curses])
 AM_CONDITIONAL(HAVE_CURSES, test x$curses = x1)
+AM_CONDITIONAL(HAVE_PDCURSES, test x$pdcurses = x1)
 
 # check for gtk >= 2.4.0
 AC_MSG_CHECKING(for gtk)

Modified: GNUnet/src/conf/Makefile.am
===================================================================
--- GNUnet/src/conf/Makefile.am 2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/Makefile.am 2005-05-19 18:38:15 UTC (rev 794)
@@ -20,16 +20,20 @@
  lex.zconf.c \
  lkc_proto.h \
  qconf.h \
- bool.h
+ bool.h \
+ wizard_util.h
 
 if HAVE_CURSES
+if HAVE_PDCURSES
+ pdcurses_lib = -lpdcurses
+else
  curses_lib = -lncurses
 endif
+endif
 
 lkc_defs.h: $(srcdir)/lkc_proto.h
        sed < $(srcdir)/lkc_proto.h > $@ 's/P(\([^,]*\),.*/#define \1 (\*\1_p)/'
 
-
 if HAVE_CURSES
 mconf_src = \
   mconf.c \
@@ -41,7 +45,8 @@
   mconf_msgbox.c \
   mconf_textbox.c \
   mconf_util.c \
-  mconf_yesno.c
+  mconf_yesno.c \
+  wizard_curs.c
 endif
 
 if HAVE_GTK
@@ -79,10 +84,12 @@
  $(mconf_src) \
  $(gconf_src) \
  $(gbasic_src) \
+ $(wizard_util_src) \
+ wizard_util.c \
  gnunet-setup.c
 
 gnunet_setup_LDFLAGS = \
- $(curses_lib) $(gconf_libs)
+ $(curses_lib) $(pdcurses_lib) $(gconf_libs)
 
 gnunet_setup_LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la

Modified: GNUnet/src/conf/confdata.c
===================================================================
--- GNUnet/src/conf/confdata.c  2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/confdata.c  2005-05-19 18:38:15 UTC (rev 794)
@@ -206,8 +206,6 @@
        }
        }
        
-       doneParseConfig();
-       
        sym_change_count = 1;
 
        return 0;

Modified: GNUnet/src/conf/gnunet-setup.c
===================================================================
--- GNUnet/src/conf/gnunet-setup.c      2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/gnunet-setup.c      2005-05-19 18:38:15 UTC (rev 794)
@@ -34,8 +34,9 @@
        " config\t\ttext-based configuration\n"
        " menuconfig\ttext-based menu\n"
        " xconfig\tX configuration\n"
-       " gconfig\tGTK configuration\n\n"
-                                                                       " 
wizard-gtk\tBasic GTK configuration\n\n"));
+       " gconfig\tGTK configuration\n"
+                       " wizard-curses\tBasic text-based graphical 
configuration\n"
+                       " wizard-gtk\tBasic GTK configuration\n\n"));
 }
 
 #if HAVE_CURSES
@@ -55,7 +56,7 @@
     return 0;
   }
 
-  initUtil(NULL, 0, NULL);
+  initUtil(0, NULL, NULL);
 
   if (strncmp(argv[1], "config", 6) == 0)
     conf_main(argc - 1, &argv[1]);
@@ -66,6 +67,13 @@
     puts("Menuconfig is not available\n");
 #endif
   }
+  else if (strncmp(argv[1], "wizard-curses", 13) == 0) {
+#if HAVE_CURSES
+    wizard_curs_main(argc - 1, &argv[1]);
+#else
+    puts("Wizard-curses is not available\n");
+#endif
+  }
   else if (strncmp(argv[1], "wizard-gtk", 10) == 0) {
 #if HAVE_GTK
     wizard_main(argc - 1, &argv[1]);

Modified: GNUnet/src/conf/mconf.c
===================================================================
--- GNUnet/src/conf/mconf.c     2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/mconf.c     2005-05-19 18:38:15 UTC (rev 794)
@@ -31,8 +31,14 @@
  * @author Nils Durner
  */
 
+#include "platform.h"
+#include "gnunet_util.h"
+
+#ifndef MINGW
 #include <sys/ioctl.h>
 #include <sys/wait.h>
+#include <termios.h>
+#endif
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -41,7 +47,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
 #include <unistd.h>
 
 #include "mconf_dialog.h"
@@ -250,8 +255,10 @@
 
 static char filename[PATH_MAX+1] = "/etc/GNUnet/.config";
 static int indent;
+#ifndef MINGW
 static struct termios ios_org;
-static int rows, cols;
+#endif
+int rows = 0, cols = 0;
 static int child_count;
 static int single_menu_mode;
 
@@ -263,15 +270,17 @@
 static void conf_string(struct menu *menu);
 static void conf_load(void);
 static void conf_save(void);
-static void show_textbox(const char *title, const char *text, int r, int c);
-static void show_helptext(const char *title, const char *text);
 static void show_help(struct menu *menu);
 static void show_readme(void);
 
-static void init_wsize(void)
+void init_wsize(void)
 {
-       struct winsize ws;
        char *env;
+       
+       rows = cols = 0;
+       
+#ifndef MINGW
+  struct winsize ws;
 
        if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
                rows = 24;
@@ -279,6 +288,7 @@
        } else {
                rows = ws.ws_row;
                cols = ws.ws_col;
+#endif
                if (!rows) {
                        env = getenv("LINES");
                        if (env)
@@ -293,7 +303,9 @@
                        if (!cols)
                                cols = 80;
                }
+#ifndef MINGW
        }
+#endif
 
        if (rows < 19 || cols < 80) {
                end_dialog();
@@ -636,7 +648,7 @@
        }
 }
 
-static void show_textbox(const char *title, const char *text, int r, int c)
+void show_textbox(const char *title, const char *text, int r, int c)
 {
        int fd;
 
@@ -648,7 +660,7 @@
        UNLINK(".help.tmp");
 }
 
-static void show_helptext(const char *title, const char *text)
+void show_helptext(const char *title, const char *text)
 {
        show_textbox(title, text, rows, cols);
 }
@@ -796,7 +808,9 @@
 
 static void conf_cleanup(void)
 {
+#ifndef MINGW
        tcsetattr(1, TCSAFLUSH, &ios_org);
+#endif
        UNLINK(".help.tmp");
        UNLINK("lxdialog.scrltmp");
 }
@@ -807,6 +821,7 @@
        int stat;
   const char * LANG;
   char * configFile;
+  struct menu *root;
 
   LANG = getenv("LANG");
   if (LANG == NULL)
@@ -823,7 +838,11 @@
                       2);
   }
 
-       conf_parse(configFile);
+       /* This configurator is also called from the wizard configurator.
+        * Check whether the templates are already parsed. */
+       root = menu_get_root_menu(NULL);
+       if (!(root && root->prompt))
+               conf_parse(configFile);
   FREE(configFile);
   
        conf_read(NULL);
@@ -837,6 +856,7 @@
                        single_menu_mode = 1;
        }
 
+#ifndef MINGW
        {
                struct sigaction sa;
                sa.sa_handler = winch_handler;
@@ -846,8 +866,10 @@
        }
 
        tcgetattr(1, &ios_org);
+#endif
        atexit(conf_cleanup);
        init_dialog();
+       
        init_wsize();
        conf(&rootmenu);
 

Modified: GNUnet/src/conf/mconf_dialog.h
===================================================================
--- GNUnet/src/conf/mconf_dialog.h      2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/mconf_dialog.h      2005-05-19 18:38:15 UTC (rev 794)
@@ -191,6 +191,9 @@
 struct dialog_list_item *first_sel_item(int item_no,
                struct dialog_list_item **items);
 
+void show_textbox(const char *title, const char *text, int r, int c);
+void show_helptext(const char *title, const char *text);
+
 /*
  * This is the base for fictitious keys, which activate
  * the buttons.

Modified: GNUnet/src/conf/mconf_util.c
===================================================================
--- GNUnet/src/conf/mconf_util.c        2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/mconf_util.c        2005-05-19 18:38:15 UTC (rev 794)
@@ -220,7 +220,10 @@
 do_resize_dialog ()
 {
        should_resize = 0;
+  /* TODO */
+#ifndef MINGW
        resizeterm(new_rows, new_cols);
+#endif
        COLS = new_cols;
        LINES = new_rows;
 #ifdef KEY_RESIZE
@@ -239,7 +242,7 @@
 {
     int newl, cur_x, cur_y;
     int i, prompt_len, room, wlen;
-    char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
+    char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *sp_nl;
 
     strcpy (tempstr, prompt);
 
@@ -248,10 +251,10 @@
     /*
      * Remove newlines
      */
-    for(i=0; i<prompt_len; i++) {
+/*    for(i=0; i<prompt_len; i++) {
        if(tempstr[i] == '\n') tempstr[i] = ' ';
     }
-
+*/
     if (prompt_len <= width - x * 2) { /* If prompt is short */
        wmove (win, y, (width - prompt_len) / 2);
        waddstr (win, tempstr);
@@ -261,34 +264,54 @@
        newl = 1;
        word = tempstr;
        while (word && *word) {
-           sp = index(word, ' ');
-           if (sp)
+           sp = strchr(word, ' ');
+           sp_nl = strchr(word, '\n');
+           
+           if (sp_nl && (sp_nl < sp || !sp))
+               sp = sp_nl;
+           else
+               sp_nl = NULL;
+           
+           if (sp)     
                *sp++ = 0;
 
-           /* Wrap to next line if either the word does not fit,
-              or it is the first word of a new sentence, and it is
-              short, and the next word does not fit. */
-           room = width - cur_x;
-           wlen = strlen(word);
-           if (wlen > room ||
-               (newl && wlen < 4 && sp && wlen+1+strlen(sp) > room
-               && (!(sp2 = index(sp, ' ')) || wlen+1+(sp2-sp) > room))) {
-               cur_y++;
-               cur_x = x;
-           }
-           wmove (win, cur_y, cur_x);
-           waddstr (win, word);
-           getyx (win, cur_y, cur_x);
-           cur_x++;
-           if (sp && *sp == ' ') {
-               cur_x++;        /* double space */
-               while (*++sp == ' ');
-               newl = 1;
-           } else
-               newl = 0;
-           word = sp;
+                       if (sp_nl) {
+                               /* "\n" encountered */
+                               wmove (win, cur_y, cur_x);
+                               waddstr (win, word);
+                               cur_y++;
+                               cur_x = x;
+                               wmove (win, cur_y, cur_x);
+                               newl = 1;
+                       }
+                       else {
+                               /*      Wrap to next line if either the word 
does not fit,
+                                               or it is the first word of a 
new sentence, and it is
+                                               short, and the next word does 
not fit. */
+                               room = width - cur_x;
+                               wlen = strlen (word);
+                               if (wlen > room ||
+                                       (newl && wlen < 4 && sp && wlen + 1 + 
strlen (sp) > room &&
+                                       (!(sp2 = strchr (sp, ' ')) || wlen + 1 
+ (sp2 - sp) > room)))
+                               {
+                                       cur_y++;
+                       cur_x = x;
+                               }
+                               wmove (win, cur_y, cur_x);
+                               waddstr (win, word);
+                               getyx (win, cur_y, cur_x);
+                               cur_x++;
+                               if (sp && *sp == ' ') {
+                                       cur_x++;                        /* 
double space */
+                                       while (*++sp == ' ');
+                                 newl = 1;
+                               }
+                               else
+                               newl = 0;
+                       }
+                       word = sp;
+               }
        }
-    }
 }
 
 /*

Modified: GNUnet/src/conf/wizard.c
===================================================================
--- GNUnet/src/conf/wizard.c    2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/wizard.c    2005-05-19 18:38:15 UTC (rev 794)
@@ -47,35 +47,7 @@
        
   gtk_combo_box_append_text(GTK_COMBO_BOX(cmbNIC), name);
   
-  sym = sym_find("INTERFACE", "NETWORK");
-  if (sym)
-  {
-       sym_calc_value_ext(sym, 1);
-       nic = sym_get_string_value(sym);
-#ifdef WINDOWS
-               /* default NIC for unixes */
-               if (strcmp(nic, "eth0") == 0)
-                       nic = NULL;
-#endif
-  }
-
-  if (nic)
-  {
-       /* The user has selected a NIC before */
-       defaultNIC = 0;
-       
-       int niclen = strlen(nic);
-       int inslen = strlen(name);
-       if (inslen >= niclen)
-       {
-#ifdef WINDOWS
-               if (strncmp(name + inslen - niclen - 1, nic, niclen) == 0)
-#else
-               if (strcmp(name, nic) == 0)
-#endif
-                       defaultNIC = 1; /* This is the previous selection */
-       }
-  }
+       defaultNIC = wiz_is_nic_default(name, defaultNIC);
   
   /* Make default selection */
   if (defaultNIC)
@@ -115,49 +87,8 @@
        sym = sym_find("INTERFACE", "NETWORK");
        if (sym)
        {               
-#ifdef MINGW
-               ListNICs(insert_nic);
-#else
-               char entry[11], *dst;
-               FILE *f = popen("ifconfig", "r");
-               if (!f)
-                       return;
-                       
-               while(1)
-               {
-                       int i = 0;
-                       int c = fgetc(f);
-                       
-                       if (c == EOF)
-                               break;
+               wiz_enum_nics(insert_nic);
 
-                       dst = entry;
-                       
-                       /* Read interface name until the first space (or colon 
under OS X) */
-                       while (c != EOF && c != '\n' &&
-#ifdef OSX
-                               c != ':'
-#else
-                               c != ' '
-#endif
-                               && i < 10)
-                       {
-                               *dst++ = c;
-                               i++;
-                               c = fgetc(f);
-                       }
-                       *dst = 0;
-
-                       if (entry[0])
-                               insert_nic(entry, strcmp(entry, "eth0") == 0);
-
-                       while(c != '\n' && c != EOF)
-                               c = fgetc(f);
-               }
-
-               pclose(f);
-#endif
-
                gtk_widget_set_usize(cmbNIC, 10, -1);
        }
 

Modified: GNUnet/src/conf/wizard_callbacks.c
===================================================================
--- GNUnet/src/conf/wizard_callbacks.c  2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/wizard_callbacks.c  2005-05-19 18:38:15 UTC (rev 794)
@@ -148,103 +148,7 @@
 void
 on_finish_clicked (GtkButton * button, gpointer user_data)
 {
-#ifdef WINDOWS
-       if (doAutoStart)
-       {
-               if (IsWinNT())
-               {
-                       char szErr[250];
-                       
-                       switch(InstallAsService())
-                       {
-                               case 0:
-                               case 1:
-                                       break;
-                               case 2:
-                           SetErrnoFromWinError(GetLastError());
-                           sprintf(szErr, _("Error: can't open Service Control 
Manager: %s\n"),
-                               _win_strerror(errno));
-
-                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
-                                       return;
-                               case 3:
-                           SetErrnoFromWinError(GetLastError());
-                           sprintf(szErr, _("Error: can't create service: 
%s\n"),
-                               _win_strerror(errno));
-
-                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
-                                       return;
-                               default:
-                                       MessageBox(GetActiveWindow(), 
_("Unknown error"), _("Error"),
-                                               MB_ICONSTOP | MB_OK);
-                       }
-               }
-               else
-               {
-                       char szPath[_MAX_PATH + 1];
-                       plibc_conv_to_win_path("/bin/gnunetd.exe", szPath);
-                       
-                       if (RegSetValue(HKEY_LOCAL_MACHINE,
-                               
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", REG_SZ, szPath, 
-                               strlen(szPath)) != ERROR_SUCCESS)
-                       {
-                       MessageBox(GetActiveWindow(), _("Cannot write to the 
regisitry"),
-                               _("Error"), MB_ICONSTOP | MB_OK);               
                        
-                       }
-               }
-       }
-       else
-       {
-               if (IsWinNT())
-               {
-                       char szErr[250];
-                       
-                       switch (UninstallService())
-                       {
-                               case 0:
-                               case 1:
-                                       break;
-                               case 2:
-                           SetErrnoFromWinError(GetLastError());
-                           sprintf(szErr, _("Error: can't open Service Control 
Manager: %s\n"),
-                               _win_strerror(errno));
-
-                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
-                                       return;
-                               case 3:
-                           SetErrnoFromWinError(GetLastError());
-                           sprintf(szErr, _("Error: can't access the service: 
%s\n"),
-                               _win_strerror(errno));
-
-                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
-                                       return;
-                               case 4:
-                           SetErrnoFromWinError(GetLastError());
-                           sprintf(szErr, _("Error: can't delete the service: 
%s\n"),
-                               _win_strerror(errno));
-
-                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
-                                       break;
-                               default:
-                                       MessageBox(GetActiveWindow(), 
_("Unknown error"), _("Error"),
-                                               MB_ICONSTOP | MB_OK);           
                                                
-                       }
-               }
-               else
-               {
-                       HKEY hKey;
-                       
-                 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                       "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, 
KEY_SET_VALUE,
-                       &hKey) == ERROR_SUCCESS)
-                 {
-                   RegDeleteValue(hKey, "GNUnet");
-               
-                   RegCloseKey(hKey);
-                 }
-               }
-       }
-#endif
+       wiz_autostart(doAutoStart);
        
        if (save_conf())
                gtk_widget_destroy(curwnd);

Added: GNUnet/src/conf/wizard_curs.c
===================================================================
--- GNUnet/src/conf/wizard_curs.c       2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/wizard_curs.c       2005-05-19 18:38:15 UTC (rev 794)
@@ -0,0 +1,435 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file conf/wizard_curs.c
+ * @brief A easy-to-use configuration assistant for curses
+ * @author Nils Durner
+ */
+
+#include "gnunet_util.h"
+
+#define LKC_DIRECT_LINK
+#include "lkc.h"
+
+#include "mconf_dialog.h"
+#include "wizard_util.h"
+
+extern int cols, rows;
+
+static struct dialog_list_item **nic_items;
+static int nic_item_count = 0;
+
+void insert_nic_curs(char *name, int defaultNIC)
+{
+       struct dialog_list_item *item;
+
+       /* Copy NIC data */     
+       nic_items = (nic_item_count) ?
+               realloc(nic_items, (nic_item_count + 1) * sizeof(struct 
dialog_list_item *)) :
+               malloc(sizeof(struct dialog_list_item *));
+
+       item = malloc(sizeof(struct dialog_list_item));
+       memset(item, 0, sizeof(struct dialog_list_item));
+       nic_items[nic_item_count] = item;
+       item->name = strdup(name);
+       item->namelen = strlen(name);
+  item->selected = wiz_is_nic_default(name, defaultNIC);
+
+       nic_item_count++;
+}
+
+int wizard_curs_main(int argc, char *argv[])
+{
+  const char * LANG;
+  char * configFile;
+  void *active_ptr = NULL;
+       int idx, ret, autostart, adv = 0;
+       struct symbol *sym;
+       char *defval;
+
+  LANG = getenv("LANG");
+  if (LANG == NULL)
+      LANG = "en";
+  if (strncmp(LANG, "en", 2) == 0)
+      LANG = NULL;
+  configFile = MALLOC(strlen(DATADIR"/config.in") + 4);
+  strcpy(configFile,
+                DATADIR"/config.in");   
+  if (LANG != NULL) {
+      strcat(configFile, ".");
+      strncat(configFile,
+                      LANG,
+                      2);
+  }
+
+  conf_parse(configFile);
+  FREE(configFile);
+  
+  conf_read(NULL);
+
+  init_dialog();
+  init_wsize();
+       dialog_clear();
+
+       if (dialog_msgbox(_("GNUnet configuration"), 
+               _("Welcome to GNUnet!\n\nThis assistant will ask you a few 
basic questions "
+                 "in order to configure GNUnet.\n\nPlease visit our homepage 
at\n\t"
+                 "http://www.gnunet.org\nand join our community at\n\t"
+                 "http://www.gnunet.org/drupal/\n\nHave a lot of fun,\n\nthe 
GNUnet team"),
+               rows, cols - 5, 1) == -1)
+               goto end;
+
+       dialog_clear();
+       
+  wiz_enum_nics(insert_nic_curs);
+
+       /* Network interface */
+       while (true) {
+               ret = dialog_menu(_("GNUnet configuration"),
+                                               _("Choose the network interface 
that connects your computer to "
+                                                       "the internet from the 
list below."), rows, cols - 5, 10,
+                                               0, active_ptr, nic_item_count - 
1, nic_items);
+               
+               if (ret == 2) {
+                       /* Help */
+                       dialog_msgbox(_("Help"), _("The \"Network interface\" 
is the device "
+                               "that connects your computer to the internet. 
This is usually a modem, "
+                               "an ISDN card or a network card in case you are 
using DSL."), rows,
+                               cols - 5, 1);
+               }
+               else if (ret <= 1) {
+                       /* Select or Exit */
+                       char *dst;
+#ifdef MINGW
+                       char nic[21];
+#else
+                       char *nic;
+#endif
+                       for(idx = 0; idx < nic_item_count; idx++) {
+                               
+                               if (nic_items[idx]->selected) {
+#ifdef MINGW
+                                       char *src = 
strrchr(nic_items[idx]->name, '-') + 2;
+                                       dst = nic;
+                                       while(*src)
+                                               *dst++ = *src++;
+                                       dst[-1] = 0;
+#else
+                                       nic = entry;
+#endif
+                                       sym = sym_lookup("INTERFACE", 
"NETWORK", 0);
+                                       sym_set_string_value(sym, nic);
+                                       sym = sym_lookup("INTERFACES", "LOAD", 
0);
+                                       sym_set_string_value(sym, nic);
+                               }
+                               
+                               free(nic_items[idx]->name);
+                               free(nic_items[idx]);
+                       }
+                       free(nic_items);
+                       
+                       break;
+               }
+       }
+       
+       if (ret == 1 || ret == -1)
+               goto end;
+       
+       dialog_clear();
+       
+       /* IP address */
+       if (sym = sym_find("IP", "NETWORK")) {
+               sym_calc_value_ext(sym, 1);
+               defval = sym_get_string_value(sym);
+       }
+       else
+               defval = NULL;
+       
+       while(true) {
+               ret = dialog_inputbox(_("GNUnet configuration"), _("What is 
this computer's "
+                       "public IP adress or hostname?\n\nIf in doubt, leave 
this empty."),
+                       rows, cols - 5, defval ? defval : "");
+               
+               if (ret == 1) {
+                       /* Help */
+                       dialog_msgbox(_("Help"), _("If your provider always 
assigns the same "
+                               "IP-Address to you (a \"static\" IP-Address), 
enter it into the "
+                               "\"IP-Address\" field. If your IP-Address 
changes every now and then "
+                               "(\"dynamic\" IP-Address) but there's a 
hostname that always points "
+                               "to your actual IP-Address (\"Dynamic DNS\"), 
you can also enter it "
+                               "here.\nIf in doubt, leave the field empty. 
GNUnet will then try to "
+                               "determine your IP-Address."), rows, cols - 5, 
1);
+               }
+               else if (ret <= 0)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+               
+       sym_set_string_value(sym, dialog_input_result);
+       
+       dialog_clear();
+
+       /* NAT? */
+       while(true) {
+               ret = dialog_yesno(_("GNUnet configuration"), _("Is this 
machine behind "
+                               "NAT?\n\nIf you are connected to the internet 
through another computer "
+                               "doing SNAT, a router or a \"hardware 
firewall\" and other computers "
+                               "on the internet cannot connect to this 
computer, say \"yes\" here. "
+                               "Answer \"no\" on direct connections through 
modems, ISDN cards and "
+                               "DNAT (also known as \"port forwarding\")."), 
rows, cols - 5);
+               
+               if (ret != -2)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+       else
+               sym_set_tristate_value(sym, !ret); /* ret is inverted */
+       
+       /* Upstream */
+       if (sym = sym_find("MAXNETUPBPSTOTAL", "LOAD")) {
+               sym_calc_value_ext(sym, 1);
+               defval = sym_get_string_value(sym);
+       }
+       else
+               defval = NULL;
+
+       while(true) {
+               ret = dialog_inputbox(_("GNUnet configuration"), _("How much 
upstream "
+                       "(Bytes/s) may be used?"), rows, cols - 5, defval ? 
defval : "");
+               
+               if (ret == 1) {
+                       /* Help */
+                       dialog_msgbox(_("Help"), _("You can limit GNUnet's 
ressource usage "
+                               "here.\n\nThe \"upstream\" is the data channel 
through which data "
+                               "is *sent* to the internet. The limit is either 
the total maximum "
+                               "for this computer or how much GNUnet itself is 
allowed to use. You "
+                               "can specify that later. If you have a 
flatrate, you can set it to "
+                               "the maximum speed of your internet 
connection."), rows, cols - 5, 1);
+               }
+               else if (ret <= 0)
+                       break;
+       }
+
+       if (ret == -1)
+               goto end;
+
+       sym_set_string_value(sym, dialog_input_result);
+
+       dialog_clear();
+
+       /* Downstram */
+       if (sym = sym_find("MAXNETDOWNBPSTOTAL", "LOAD")) {
+               sym_calc_value_ext(sym, 1);
+               defval = sym_get_string_value(sym);
+       }
+       else
+               defval = NULL;
+
+       while(true) {
+               ret = dialog_inputbox(_("GNUnet configuration"), _("How much 
downstream "
+                       "(Bytes/s) may be used?"), rows, cols - 5, defval ? 
defval : "");
+               
+               if (ret == 1) {
+                       /* Help */
+                       dialog_msgbox(_("Help"), _("You can limit GNUnet's 
ressource usage "
+                               "here.\n\nThe \"downstream\" is the data 
channel through which data "
+                               "is *received* from the internet. The limit is 
either the total maximum "
+                               "for this computer or how much GNUnet itself is 
allowed to use. You "
+                               "can specify that later. If you have a flatrate 
you can set it to "
+                               "the maximum speed of your internet 
connection."), rows, cols - 5, 1);
+               }
+               else if (ret <= 0)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+
+       sym_set_string_value(sym, dialog_input_result);
+
+       dialog_clear();
+
+       /* Bandwidth allocation */
+       while (true) {
+               ret = dialog_yesno(_("GNUnet configuration"), _("Share denoted 
bandwidth "
+                               "with other applications?\n\nSay \"yes\" here, 
if you don't want other "
+                               "network traffic to interfere with GNUnet's 
operation, but still wish to "
+                               "constrain GNUnet's bandwidth usage to values 
entered in the previous "
+                               "steps, or if you can't reliably measure the 
maximum capabilities "
+                               "of your connection. \"No\" can be very useful 
if other applications "
+                               "are causing a lot of traffic on your LAN.  In 
this case, you do not "
+                               "want to limit the traffic that GNUnet can 
inflict on your internet "
+                               "connection whenever your high-speed LAN gets 
used (e.g. by NFS)."),
+                               rows, cols - 5);
+               
+               if (ret != -2)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+       else
+               sym_set_tristate_value(sym, !ret); /* ret is inverted */
+       
+       dialog_clear();
+
+       /* Max CPU */
+       if (sym = sym_find("MAXCPULOAD", "LOAD")) {
+               sym_calc_value_ext(sym, 1);
+               defval = sym_get_string_value(sym);
+       }
+       else
+               defval = NULL;
+
+       while(true) {
+               ret = dialog_inputbox(_("GNUnet configuration"), _("How much 
CPU (in %) may "
+                       "be used?"), rows, cols - 5, defval ? defval : "");
+               
+               if (ret == 1) {
+                       /* Help */
+                       dialog_msgbox(_("Help"), _("You can limit GNUnet's 
ressource usage "
+                               "here.\n\nThis is the percentage of processor 
time GNUnet is allowed "
+                               "to use."), rows, cols - 5, 1);
+               }
+               else if (ret <= 0)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+
+       sym_set_string_value(sym, dialog_input_result);
+       
+       dialog_clear();
+
+       /* Migration */
+       while(true) {
+               ret = dialog_yesno(_("GNUnet configuration"), _("Store migrated 
content?"
+                               "\n\nGNUnet is able to store data from other 
peers in your datastore. "
+                               "This is useful if an adversary has access to 
your inserted content and "
+                               "you need to deny that the content is yours. 
With \"content migration\" "
+                               "on, the content could have \"migrated\" over 
the internet to your node"
+                               " without your knowledge.\nIt also helps to 
spread popular content over "
+                               "different peers to enhance availability."), 
rows, cols - 5);
+                               
+               if (ret != -2)
+                       break;
+       }
+
+       if (ret == -1)
+               goto end;
+       else
+               sym_set_tristate_value(sym, !ret); /* ret is inverted */
+
+       dialog_clear();
+
+       /* Quota */
+       if (sym = sym_find("DISKQUOTA", "FS")) {
+               sym_calc_value_ext(sym, 1);
+               defval = sym_get_string_value(sym);
+       }
+       else
+               defval = NULL;
+
+       while(true) {
+               ret = dialog_inputbox(_("GNUnet configuration"), _("What's the 
maximum "
+                       "datastore size in MB?\n\nThe GNUnet datastore contains 
all data that "
+                       "GNUnet generates (index data, inserted and migrated 
content)."),
+                       rows, cols - 5, defval ? defval : "");
+               
+               if (ret == 1) {
+                       /* Help - not available */
+               }
+               else if (ret <= 0)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+
+       sym_set_string_value(sym, dialog_input_result);
+
+       dialog_clear();
+
+       /* Autostart */
+       while(true) {
+               ret = dialog_yesno(_("GNUnet configuration"), _("Do you want to 
launch "
+                               "GNUnet as a system service?"
+                               "\n\nIf you say \"yes\" here, the GNUnet 
background process will be "
+                               "automatically started when you turn on your 
computer. If you say \"no\""
+                               " here, you have to launch GNUnet yourself each 
time you want to use it."),
+                               rows, cols - 5);
+                               
+               if (ret != -2)
+                       break;
+       }
+
+       if (ret == -1)
+               goto end;
+       else
+               autostart = !ret; /* ret is inverted */
+
+       dialog_clear();
+
+       /* Advanced */
+       while(true) {
+               ret = dialog_yesno(_("GNUnet configuration"), _("If you are an 
experienced "
+                               "user, you may want to tweak your GNUnet 
installation using the enhanced "
+                               "configurator.\n\nDo you want to start it 
now?"), rows, cols - 5);
+                               
+               if (ret != -2)
+                       break;
+       }
+       
+       if (ret == -1)
+               goto end;
+       else
+               adv = !ret;
+
+       /* Save config */
+       wiz_autostart(autostart);
+       while(true) {
+               if (conf_write(NULL) != 0) {
+                       ret = dialog_yesno(_("GNUnet configuration"),
+                                                       _("Cannot save 
configuration.\n\nTry again?"), rows, cols - 5);
+               }
+               else
+                       ret = 1;
+                       
+               if (ret == 1 || ret == -1)
+                       break;
+       }
+       
+end:
+  end_dialog();
+
+       if (adv) {
+               mconf_main(argc, argv);
+       }
+
+  return 0;
+}
+
+/* end of wizard_curs.c */

Added: GNUnet/src/conf/wizard_util.c
===================================================================
--- GNUnet/src/conf/wizard_util.c       2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/wizard_util.c       2005-05-19 18:38:15 UTC (rev 794)
@@ -0,0 +1,228 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file conf/wizard_util.c
+ * @brief Common helper functions
+ * @author Nils Durner
+ */
+
+#include "gnunet_util.h"
+#include "platform.h"
+
+#define LKC_DIRECT_LINK
+#include "lkc.h"
+
+#include "mconf_dialog.h"
+
+/**
+ * @brief Enumerate all network interfaces
+ * @param callback the callback function
+ */
+void wiz_enum_nics(void (*callback) (char *, int)) {
+#ifdef MINGW
+               ListNICs(callback);
+#else
+               char entry[11], *dst;
+               FILE *f = popen("ifconfig", "r");
+               if (!f)
+                       return;
+                       
+               while(1)
+               {
+                       int i = 0;
+                       int c = fgetc(f);
+                       
+                       if (c == EOF)
+                               break;
+
+                       dst = entry;
+                       
+                       /* Read interface name until the first space (or colon 
under OS X) */
+                       while (c != EOF && c != '\n' &&
+#ifdef OSX
+                               c != ':'
+#else
+                               c != ' '
+#endif
+                               && i < 10)
+                       {
+                               *dst++ = c;
+                               i++;
+                               c = fgetc(f);
+                       }
+                       *dst = 0;
+
+                       if (entry[0])
+                               insert_nic(entry, strcmp(entry, "eth0") == 0);
+
+                       while(c != '\n' && c != EOF)
+                               c = fgetc(f);
+               }
+
+               pclose(f);
+#endif
+}
+
+/**
+ * @brief Determine whether a NIC makes a good default
+ */
+int wiz_is_nic_default(const char *name, int suggestion) {
+       char *nic;      
+       struct symbol *sym = sym_find("INTERFACE", "NETWORK");
+  
+  if (sym)
+  {
+       sym_calc_value_ext(sym, 1);
+       nic = sym_get_string_value(sym);
+#ifdef WINDOWS
+               /* default NIC for unixes */
+               if (strcmp(nic, "eth0") == 0)
+                       nic = NULL;
+#endif
+  }
+
+  if (nic)
+  {
+       /* The user has selected a NIC before */
+       suggestion = 0;
+       
+       int niclen = strlen(nic);
+       int inslen = strlen(name);
+       if (inslen >= niclen)
+       {
+#ifdef WINDOWS
+               if (strncmp(name + inslen - niclen - 1, nic, niclen) == 0)
+#else
+               if (strcmp(name, nic) == 0)
+#endif
+                       suggestion = 1; /* This is the previous selection */
+       }
+  }
+  
+  return suggestion;
+}
+
+/* @brief Make GNUnet start automatically */
+void wiz_autostart(int doAutoStart) {
+#ifdef WINDOWS
+       if (doAutoStart)
+       {
+               if (IsWinNT())
+               {
+                       char szErr[250];
+                       
+                       switch(InstallAsService())
+                       {
+                               case 0:
+                               case 1:
+                                       break;
+                               case 2:
+                           SetErrnoFromWinError(GetLastError());
+                           sprintf(szErr, _("Error: can't open Service Control 
Manager: %s\n"),
+                               _win_strerror(errno));
+
+                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
+                                       return;
+                               case 3:
+                           SetErrnoFromWinError(GetLastError());
+                           sprintf(szErr, _("Error: can't create service: 
%s\n"),
+                               _win_strerror(errno));
+
+                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
+                                       return;
+                               default:
+                                       MessageBox(GetActiveWindow(), 
_("Unknown error"), _("Error"),
+                                               MB_ICONSTOP | MB_OK);
+                       }
+               }
+               else
+               {
+                       char szPath[_MAX_PATH + 1];
+                       plibc_conv_to_win_path("/bin/gnunetd.exe", szPath);
+                       
+                       if (RegSetValue(HKEY_LOCAL_MACHINE,
+                               
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", REG_SZ, szPath, 
+                               strlen(szPath)) != ERROR_SUCCESS)
+                       {
+                       MessageBox(GetActiveWindow(), _("Cannot write to the 
regisitry"),
+                               _("Error"), MB_ICONSTOP | MB_OK);               
                        
+                       }
+               }
+       }
+       else
+       {
+               if (IsWinNT())
+               {
+                       char szErr[250];
+                       int iErr;
+                       
+                       switch (UninstallService())
+                       {
+                               case 0:
+                               case 1:
+                                       break;
+                               case 2:
+                                       iErr = GetLastError();
+                           SetErrnoFromWinError(iErr);
+                           sprintf(szErr, _("Error: can't open Service Control 
Manager: %s (#%i)\n"),
+                               _win_strerror(errno), iErr);
+
+                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
+                                       return;
+                               case 3:
+                                       iErr = GetLastError();
+                           SetErrnoFromWinError(iErr);
+                           sprintf(szErr, _("Error: can't access the service: 
%s (#%i)\n"),
+                               _win_strerror(errno), iErr);
+
+                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
+                                       return;
+                               case 4:
+                                       iErr = GetLastError();
+                           SetErrnoFromWinError(iErr);
+                           sprintf(szErr, _("Error: can't delete the service: 
%s (#%i)\n"),
+                               _win_strerror(errno), iErr);
+
+                                       MessageBox(GetActiveWindow(), szErr, 
_("Error"), MB_ICONSTOP | MB_OK);
+                                       break;
+                               default:
+                                       MessageBox(GetActiveWindow(), 
_("Unknown error"), _("Error"),
+                                               MB_ICONSTOP | MB_OK);           
                                                
+                       }
+               }
+               else
+               {
+                       HKEY hKey;
+                       
+                 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                       "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, 
KEY_SET_VALUE,
+                       &hKey) == ERROR_SUCCESS)
+                 {
+                   RegDeleteValue(hKey, "GNUnet");
+               
+                   RegCloseKey(hKey);
+                 }
+               }
+       }
+#endif
+}
+
+/* end of wizard_util.c */

Added: GNUnet/src/conf/wizard_util.h
===================================================================
--- GNUnet/src/conf/wizard_util.h       2005-05-19 18:34:56 UTC (rev 793)
+++ GNUnet/src/conf/wizard_util.h       2005-05-19 18:38:15 UTC (rev 794)
@@ -0,0 +1,38 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file conf/wizard_util.h
+ * @brief Common helper functions
+ * @author Nils Durner
+ */
+
+#ifndef _WIZARD_UTIL_H_
+#define _WIZARD_UTIL_H_
+
+#include "platform.h"
+
+int wiz_enum_nics(void (*callback) (char *, int));
+int wiz_is_nic_default(const char *name, int suggestion);
+void wiz_autostart(int doAutoStart);
+
+#endif //_WIZARD_UTIL_H_
+
+/* end of wizard_util.c */





reply via email to

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