4 * Copyright (c) 2000, Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * A copy of the GNU General Public License can be found at
14 * Written by DJ Delorie <dj@cygnus.com>
15 * Modified by Ulf Lamping to meet Wireshark use
19 /* The purpose of this file is to manage internet downloads using the
20 Internet Explorer version 5 DLLs. To use this method, the user
21 must already have installed and configured IE5. */
29 static HINTERNET internet = 0;
34 netio_ie5_connect (char const *url)
38 netio_ie5_t * netio_ie5_conn;
41 /* INTERNET_FLAG_DONT_CACHE |*/
42 INTERNET_FLAG_KEEP_CONNECTION |
43 INTERNET_FLAG_PRAGMA_NOCACHE |
44 INTERNET_FLAG_RELOAD |
45 INTERNET_FLAG_NO_CACHE_WRITE |
46 INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_PASSIVE;
50 HINSTANCE h = ws_load_library("wininet.dll");
53 /* XXX - how to return an error code? */
54 g_warning("Failed to load wininet.dll");
57 /* pop-up dialup dialog box */
58 /* XXX - do we need the dialup box or simply don't attempt an update in this case? */
59 dw_ret = InternetAttemptConnect (0);
60 if (dw_ret != ERROR_SUCCESS) {
61 g_warning("InternetAttemptConnect failed: %u", dw_ret);
64 internet = InternetOpen ("Wireshark Update", INTERNET_OPEN_TYPE_PRECONFIG,
66 if(internet == NULL) {
67 g_warning("InternetOpen failed %u", GetLastError());
72 netio_ie5_conn = g_malloc(sizeof(netio_ie5_t));
74 netio_ie5_conn->connection = InternetOpenUrl (internet, url, NULL, 0, flags, 0);
79 /* XXX - implement this option */
80 if (net_user && net_passwd)
82 InternetSetOption (connection, INTERNET_OPTION_USERNAME,
83 net_user, strlen (net_user));
84 InternetSetOption (connection, INTERNET_OPTION_PASSWORD,
85 net_passwd, strlen (net_passwd));
90 /* XXX - implement this option */
91 if (net_proxy_user && net_proxy_passwd)
93 InternetSetOption (connection, INTERNET_OPTION_PROXY_USERNAME,
94 net_proxy_user, strlen (net_proxy_user));
95 InternetSetOption (connection, INTERNET_OPTION_PROXY_PASSWORD,
96 net_proxy_passwd, strlen (net_proxy_passwd));
101 if (!HttpSendRequest (netio_ie5_conn->connection, 0, 0, 0, 0))
102 netio_ie5_conn->connection = 0;
104 if (!netio_ie5_conn->connection)
106 switch(GetLastError ()) {
107 case ERROR_INTERNET_EXTENDED_ERROR:
110 DWORD e, l = sizeof (buf);
111 InternetGetLastResponseInfo (&e, buf, &l);
112 MessageBox (0, buf, "Internet Error", 0);
115 case ERROR_INTERNET_NAME_NOT_RESOLVED:
116 g_warning("Internet error: The servername could not be resolved");
118 case ERROR_INTERNET_CANNOT_CONNECT:
119 g_warning("Internet error: Could not connect to the server");
122 g_warning("Internet error: %u", GetLastError ());
127 type_s = sizeof (type);
128 InternetQueryOption (netio_ie5_conn->connection, INTERNET_OPTION_HANDLE_TYPE,
133 case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
134 case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
135 type_s = sizeof (DWORD);
136 if (HttpQueryInfo (netio_ie5_conn->connection,
137 HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
138 &type, &type_s, NULL))
140 if (type == 401) /* authorization required */
142 netio_ie5_flush_io (netio_ie5_conn);
143 /* XXX - query net_user && net_passwd from user
148 else if (type == 407) /* proxy authorization required */
150 netio_ie5_flush_io (netio_ie5_conn);
151 /* XXX - query net_proxy_user && net_proxy_passwd from user
152 get_proxy_auth (NULL);*/
156 else if (type >= 300)
158 g_warning("Failed with HTTP response %u", type);
159 g_free(netio_ie5_conn);
165 return netio_ie5_conn;
169 netio_ie5_flush_io (netio_ie5_t * netio_e5_conn)
175 InternetReadFile (netio_e5_conn->connection, buf, 1024, &actual);
181 netio_ie5_disconnect (netio_ie5_t * netio_e5_conn)
183 if (netio_e5_conn->connection)
184 InternetCloseHandle (netio_e5_conn->connection);
185 g_free(netio_e5_conn);
189 netio_ie5_ok (netio_ie5_t * netio_e5_conn)
191 return (netio_e5_conn->connection == NULL) ? 0 : 1;
195 netio_ie5_read (netio_ie5_t * netio_e5_conn, char *buf, int nbytes)
198 if (InternetReadFile (netio_e5_conn->connection, buf, nbytes, &actual))