]> cygwin.com Git - cygwin-apps/setup.git/blame - nio-ie5.cc
* (all): add cvsid tags
[cygwin-apps/setup.git] / nio-ie5.cc
CommitLineData
23c9e63c
DD
1/*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16/* The purpose of this file is to manage internet downloads using the
17 Internet Explorer version 5 DLLs. To use this method, the user
18 must already have installed and configured IE5. This module is
19 called from netio.cc, which is called from geturl.cc */
20
8507f105
DD
21static char *cvsid = "\n%%% $Id$\n";
22
23c9e63c
DD
23#include "win32.h"
24
25#include "resource.h"
26#include "state.h"
27#include "dialog.h"
28#include "msg.h"
29#include "netio.h"
30#include "nio-ie5.h"
31
32static HINTERNET internet = 0;
33
34NetIO_IE5::NetIO_IE5 (char *_url)
35 : NetIO (_url)
36{
37 if (internet == 0)
38 internet = InternetOpen ("Cygwin Setup", INTERNET_OPEN_TYPE_PRECONFIG,
39 NULL, NULL, 0);
40
41 DWORD flags =
42 INTERNET_FLAG_DONT_CACHE |
43 INTERNET_FLAG_KEEP_CONNECTION |
44 INTERNET_FLAG_PRAGMA_NOCACHE |
45 INTERNET_FLAG_RELOAD |
46 INTERNET_FLAG_EXISTING_CONNECT |
47 INTERNET_FLAG_PASSIVE;
48
4e8ff53f
DD
49 try_again:
50
51 if (net_user && net_passwd)
52 {
53 InternetSetOption (internet, INTERNET_OPTION_USERNAME,
54 net_user, strlen (net_user));
55 InternetSetOption (internet, INTERNET_OPTION_PASSWORD,
56 net_passwd, strlen (net_passwd));
57 }
58
23c9e63c
DD
59 if (net_proxy_user && net_proxy_passwd)
60 {
61 InternetSetOption (internet, INTERNET_OPTION_PROXY_USERNAME,
62 net_proxy_user, strlen (net_proxy_user));
63 InternetSetOption (internet, INTERNET_OPTION_PROXY_PASSWORD,
64 net_proxy_passwd, strlen (net_proxy_passwd));
65 }
66
67 connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
68
69 if (!connection)
70 {
71 if (GetLastError () == ERROR_INTERNET_EXTENDED_ERROR)
72 {
73 char buf[2000];
74 DWORD e, l=sizeof (buf);
75 InternetGetLastResponseInfo (&e, buf, &l);
76 MessageBox (0, buf, "Internet Error", 0);
77 }
23c9e63c 78 }
4e8ff53f
DD
79
80 DWORD type, type_s;
81 type_s = sizeof (type);
82 InternetQueryOption (connection, INTERNET_OPTION_HANDLE_TYPE,
83 &type, &type_s);
84
85 switch (type)
86 {
87 case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
88 case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
89 type_s = sizeof (DWORD);
90 if (HttpQueryInfo (connection,
91 HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
92 &type, &type_s, NULL))
93 {
94 if (type == 401) /* authorization required */
95 {
96 get_auth ();
97 goto try_again;
98 }
99 else if (type == 407) /* proxy authorization required */
100 {
101 get_proxy_auth ();
102 goto try_again;
103 }
104 else if (type >= 300)
105 {
106 connection = 0;
107 return;
108 }
109 }
110 }
23c9e63c
DD
111}
112
113NetIO_IE5::~NetIO_IE5 ()
114{
115 if (connection)
116 InternetCloseHandle (connection);
117}
118
119int
120NetIO_IE5::ok ()
121{
122 return (connection == NULL) ? 0 : 1;
123}
124
125int
126NetIO_IE5::read (char *buf, int nbytes)
127{
128 DWORD actual;
129 if (InternetReadFile (connection, buf, nbytes, &actual))
130 return actual;
131 return -1;
132}
This page took 0.033822 seconds and 5 git commands to generate.