Hi,

I made a small patch to setup.exe. It adds the following command line argument:

-p --proxy HTTP/FTP proxy (host:port)

The only modified file is net.cc, which is attached to this mail.

Basically, the modifications are:
- Inclusion of <sstream> and "getopt++/StringOption.h"
- Addition of static StringOption ProxyOption ("", 'p', "proxy",
"HTTP/FTP proxy (host:port)", false);
 - Modification of NetPage::OnInit () method to modify
NetIO::net_method , NetIO::net_proxy_host and NetIO::net_proxy_port

I think my changes are conformed to the Cygwin coding guidelines and I
hope to see this patch accepted.

As it is my very first patch, I'm not sure if I must send it to this
mailing-list; or to the cygwin-patches one ?

Thanks in advance for your comments.

Vincent
/*
 * Copyright (c) 2000, Red Hat, Inc.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by DJ Delorie <[EMAIL PROTECTED]>
 *
 */

/* The purpose of this file is to get the network configuration
   information from the user. */

#if 0
static const char *cvsid =
  "\n%%% $Id: net.cc,v 2.17 2005/05/04 14:52:34 maxb Exp $\n";
#endif

#include "net.h"

#include "LogSingleton.h"

#include "win32.h"
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include "dialog.h"
#include "resource.h"
#include "netio.h"
#include "msg.h"

#include "getopt++/StringOption.h"
#include "propsheet.h"
#include "threebar.h"
#include "ConnectionSetting.h"
extern ThreeBarProgressPage Progress;

static StringOption ProxyOption ("", 'p', "proxy", "HTTP/FTP proxy 
(host:port)", false);

static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
static ConnectionSetting theSetting;
static bool doing_loading = false;

void
NetPage::CheckIfEnableNext ()
{
  int e = 0, p = 0, pu = 0;
  DWORD ButtonFlags = PSWIZB_BACK;

  if (NetIO::net_method == IDC_NET_IE5)
    pu = 1;
  if (NetIO::net_method == IDC_NET_IE5 || NetIO::net_method == IDC_NET_DIRECT)
    e = 1;
  else if (NetIO::net_method == IDC_NET_PROXY)
    {
      p = pu = 1;
      if (NetIO::net_proxy_host && NetIO::net_proxy_port)
        e = 1;
    }
        if (e)
        {
                // There's something in the proxy and port boxes, enable "Next".
                ButtonFlags |= PSWIZB_NEXT;
        }

  GetOwner ()->SetButtons (ButtonFlags);

  EnableWindow (GetDlgItem (IDC_PROXY_HOST), p);
  EnableWindow (GetDlgItem (IDC_PROXY_PORT), p);
}

static void
load_dialog (HWND h)
{
  doing_loading = true;

  rbset (h, rb, NetIO::net_method);
  eset (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
  if (NetIO::net_proxy_port == 0)
    NetIO::net_proxy_port = 80;
  eset (h, IDC_PROXY_PORT, NetIO::net_proxy_port);

  doing_loading = false;
}

static void
save_dialog (HWND h)
{
  // Without this, save_dialog() is called in the middle of load_dialog()
  // because the window receives a message when the value changes.  If this
  // happens, save_dialog() tries to read the values of the fields, resulting
  // in the net_proxy_port being reset to zero - this is the cause of the
  // preference not sticking.
  if (doing_loading)
    return;

  NetIO::net_method = rbget (h, rb);
  NetIO::net_proxy_host = eget (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
  NetIO::net_proxy_port = eget (h, IDC_PROXY_PORT);
}

bool
NetPage::Create ()
{
  return PropertyPage::Create (IDD_NET);
}

void
NetPage::OnInit ()
{
  HWND h = GetHWND ();
  std::string proxyString(((std::string)ProxyOption).c_str());

  if (!NetIO::net_method)
    NetIO::net_method = IDC_NET_DIRECT;

  if (proxyString.size())
  {
    NetIO::net_method = IDC_NET_PROXY;

    unsigned int pos = proxyString.find_last_of(':');
    if (pos >= 0)
    {
      NetIO::net_proxy_host = strdup(proxyString.substr(0, pos).c_str());
      if (pos < proxyString.size()-1)
      {
        std::string portString = proxyString.substr(pos+1, 
proxyString.size()-(pos+1));
        std::istringstream iss(portString, std::istringstream::in);
        iss >> NetIO::net_proxy_port;
      }
    }
  }

  load_dialog (h);
  CheckIfEnableNext();

  // Check to see if any radio buttons are selected. If not, select a default.
  if ((!SendMessage (GetDlgItem (IDC_NET_IE5), BM_GETCHECK, 0, 0) ==
       BST_CHECKED)
      && (!SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0)
          == BST_CHECKED))
    {
      SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_CLICK, 0, 0);
    }
}

long
NetPage::OnNext ()
{
  save_dialog (GetHWND ());

  log (LOG_PLAIN) << "net: "
    << ((NetIO::net_method == IDC_NET_IE5) ? "IE5" :
        (NetIO::net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy") << endLog;

  Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD);
  return IDD_INSTATUS;
}

long
NetPage::OnUnattended()
{
  return OnNext ();
}

long
NetPage::OnBack ()
{
  save_dialog (GetHWND ());
  return 0;
}

bool
NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
{
  switch (id)
    {
    case IDC_NET_IE5:
    case IDC_NET_DIRECT:
    case IDC_NET_PROXY:
    case IDC_PROXY_HOST:
    case IDC_PROXY_PORT:
      save_dialog (GetHWND());
      CheckIfEnableNext ();
      break;

    default:
      // Wasn't recognized or handled.
      return false;
    }

  // Was handled since we never got to default above.
  return true;
}
2008-01-21  Vincent Privat <[EMAIL PROTECTED]>

        * net.cc (OnInit): New StringOption (ProxyOption)
        This new option (-p) allows to call setup.exe with a proxy
        in its command-line arguments.

Reply via email to