2 * Copyright (c) 2000, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
13 * Modified by Ulf Lamping to meet Wireshark use
17 /* The purpose of this file is to manage internet downloads using the
18 Internet Explorer version 5 DLLs. To use this method, the user
19 must already have installed and configured IE5. */
21 #include "windows.h"
\r
22 #include <wininet.h>
\r
23 #include "nio-ie5.h"
\r
27 static HINTERNET internet = 0;
\r
32 netio_ie5_connect (char const *url)
36 netio_ie5_t * netio_ie5_conn;
\r
39 /* INTERNET_FLAG_DONT_CACHE |*/
\r
40 INTERNET_FLAG_KEEP_CONNECTION |
\r
41 INTERNET_FLAG_PRAGMA_NOCACHE |
\r
42 INTERNET_FLAG_RELOAD |
\r
43 INTERNET_FLAG_NO_CACHE_WRITE |
\r
44 INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE;
\r
48 HINSTANCE h = LoadLibrary ("wininet.dll");
51 /* XXX - how to return an error code? */
52 g_warning("Failed to load wininet.dll");
55 /* pop-up dialup dialog box */
\r
56 /* XXX - do we need the dialup box or simply don't attempt an update in this case? */
\r
57 dw_ret = InternetAttemptConnect (0);
58 if (dw_ret != ERROR_SUCCESS) {
\r
59 g_warning("InternetAttemptConnect failed: %u", dw_ret);
\r
62 internet = InternetOpen ("Wireshark Update", INTERNET_OPEN_TYPE_PRECONFIG,
64 if(internet == NULL) {
\r
65 g_warning("InternetOpen failed %u", GetLastError());
\r
70 netio_ie5_conn = g_malloc(sizeof(netio_ie5_t));
\r
72 netio_ie5_conn->connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
77 /* XXX - implement this option */
78 if (net_user && net_passwd)
80 InternetSetOption (connection, INTERNET_OPTION_USERNAME,
81 net_user, strlen (net_user));
82 InternetSetOption (connection, INTERNET_OPTION_PASSWORD,
83 net_passwd, strlen (net_passwd));
88 /* XXX - implement this option */
89 if (net_proxy_user && net_proxy_passwd)
91 InternetSetOption (connection, INTERNET_OPTION_PROXY_USERNAME,
92 net_proxy_user, strlen (net_proxy_user));
93 InternetSetOption (connection, INTERNET_OPTION_PROXY_PASSWORD,
94 net_proxy_passwd, strlen (net_proxy_passwd));
99 if (!HttpSendRequest (netio_ie5_conn->connection, 0, 0, 0, 0))
100 netio_ie5_conn->connection = 0;
102 if (!netio_ie5_conn->connection)
104 switch(GetLastError ()) {
\r
105 case ERROR_INTERNET_EXTENDED_ERROR:
\r
108 DWORD e, l = sizeof (buf);
109 InternetGetLastResponseInfo (&e, buf, &l);
110 MessageBox (0, buf, "Internet Error", 0);
\r
113 case ERROR_INTERNET_NAME_NOT_RESOLVED:
\r
114 g_warning("Internet error: The servername could not be resolved");
\r
116 case ERROR_INTERNET_CANNOT_CONNECT:
\r
117 g_warning("Internet error: Could not connect to the server");
\r
120 g_warning("Internet error: %u", GetLastError ());
\r
125 type_s = sizeof (type);
126 InternetQueryOption (netio_ie5_conn->connection, INTERNET_OPTION_HANDLE_TYPE,
131 case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
132 case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
133 type_s = sizeof (DWORD);
134 if (HttpQueryInfo (netio_ie5_conn->connection,
135 HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
136 &type, &type_s, NULL))
138 if (type == 401) /* authorization required */
140 netio_ie5_flush_io (netio_ie5_conn);
\r
141 /* XXX - query net_user && net_passwd from user
\r
146 else if (type == 407) /* proxy authorization required */
148 netio_ie5_flush_io (netio_ie5_conn);
149 /* XXX - query net_proxy_user && net_proxy_passwd from user
\r
150 get_proxy_auth (NULL);*/
154 else if (type >= 300)
156 g_warning("Failed with HTTP response %u", type);
\r
157 g_free(netio_ie5_conn);
163 return netio_ie5_conn;
167 netio_ie5_flush_io (netio_ie5_t * netio_e5_conn)
173 InternetReadFile (netio_e5_conn->connection, buf, 1024, &actual);
179 netio_ie5_disconnect (netio_ie5_t * netio_e5_conn)
181 if (netio_e5_conn->connection)
182 InternetCloseHandle (netio_e5_conn->connection);
\r
183 g_free(netio_e5_conn);
187 netio_ie5_ok (netio_ie5_t * netio_e5_conn)
189 return (netio_e5_conn->connection == NULL) ? 0 : 1;
193 netio_ie5_read (netio_ie5_t * netio_e5_conn, char *buf, int nbytes)
196 if (InternetReadFile (netio_e5_conn->connection, buf, nbytes, &actual))