[Patch] Proxy command-line argument

2008-01-20 Thread Vincent Privat
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

Re: [Patch] Proxy command-line argument

2008-01-20 Thread Christopher Faylor
On Mon, Jan 21, 2008 at 12:19:56AM -0500, Christopher Faylor wrote:
On Mon, Jan 21, 2008 at 02:38:35AM +0100, Vincent Privat wrote:
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 ?

Since cygwin-patches says this:

* cygwin-patches: a list for submitting patches to the Cygwin DLL and
the other components of the winsup directory (if you aren't sure what
this means, then you shouldn't be sending email here).  Discussions of
supplied patches are also acceptable, of course.  Only subscribers may
submit email to this list.

that should narrow down your choice to either this mailing list or
   the cygwin mailing list or
cygwin-apps and cygwin-apps is the correct choice.

cgf


Re: [Patch] Proxy command-line argument

2008-01-20 Thread Christopher Faylor
On Mon, Jan 21, 2008 at 02:38:35AM +0100, Vincent Privat wrote:
I made a small patch to setup.exe. It adds the following command line argument:

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

Thanks!

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 ?

Since cygwin-patches says this:

* cygwin-patches: a list for submitting patches to the Cygwin DLL and
the other components of the winsup directory (if you aren't sure what
this means, then you shouldn't be sending email here).  Discussions of
supplied patches are also acceptable, of course.  Only subscribers may
submit email to this list.

that should narrow down your choice to either this mailing list or
cygwin-apps and cygwin-apps is the correct choice.

Thanks in advance for your comments.

Please provide this as an actual patch:

http://en.wikipedia.org/wiki/Patch_%28Unix%29

A patch is basically just a diff -du old new.  Sending the whole file makes
it hard to figure out what you've changed.

If possible, a patch against the current CVS sources is preferred.  See:

http://sourceware.org/cygwin-apps/setup.html

cgf