annotate netinstall/geturl.cc @ 981:0205cafe98ff

[xemacs-hg @ 2002-08-30 08:25:48 by youngs] Don't look now, but 21.5.9 is on its way out the door! Don't forget what good 'ol Ma used to say... "Eat your brussels sprouts, little Johnny, so you can grow up big and strong."
author youngs
date Fri, 30 Aug 2002 08:26:22 +0000
parents 42a8626b741e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
1 /*
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
2 * Copyright (c) 2000, Red Hat, Inc.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
3 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
7 * (at your option) any later version.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
8 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
9 * A copy of the GNU General Public License can be found at
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
10 * http://www.gnu.org/
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
11 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
12 * Written by DJ Delorie <dj@cygnus.com>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
13 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
14 */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
15
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
16 /* The purpose of this file is to act as a pretty interface to
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
17 netio.cc. We add a progress dialog and some convenience functions
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
18 (like collect to string or file */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
19
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
20 #include "win32.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
21 #include "commctrl.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
22
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
23 #include <stdio.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
24 #include <stdlib.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
25 #include <errno.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
26
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
27 #include "dialog.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
28 #include "geturl.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
29 #include "resource.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
30 #include "netio.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
31 #include "msg.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
32 #include "log.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
33
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
34 static int is_showing = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
35 static HWND gw_dialog = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
36 static HWND gw_url = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
37 static HWND gw_rate = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
38 static HWND gw_progress = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
39 static HANDLE init_event;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
40 static int max_bytes = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
41
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
42 static BOOL
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
43 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
44 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
45 switch (id)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
46 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
47 case IDCANCEL:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
48 exit_setup (0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
49 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
50 return FALSE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
51 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
52
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
53 static BOOL CALLBACK
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
54 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
55 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
56 switch (message)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
57 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
58 case WM_INITDIALOG:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
59 gw_dialog = h;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
60 gw_url = GetDlgItem (h, IDC_DLS_URL);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
61 gw_rate = GetDlgItem (h, IDC_DLS_RATE);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
62 gw_progress = GetDlgItem (h, IDC_DLS_PROGRESS);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
63 SetEvent (init_event);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
64 return FALSE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
65 case WM_COMMAND:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
66 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
67 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
68 return FALSE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
69 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
70
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
71 static DWORD WINAPI
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
72 dialog (void *)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
73 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
74 MSG m;
672
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
75 HWND lgw_dialog = CreateDialog (hinstance, MAKEINTRESOURCE (IDD_DLSTATUS),
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
76 0, dialog_proc);
672
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
77 ShowWindow (lgw_dialog, SW_SHOWNORMAL);
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
78 UpdateWindow (lgw_dialog);
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
79 while (GetMessage (&m, 0, 0, 0) > 0) {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
80 TranslateMessage (&m);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
81 DispatchMessage (&m);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
82 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
83 return FALSE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
84 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
85
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
86 static DWORD start_tics;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
87
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
88 static void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
89 init_dialog (char *url, int length)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
90 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
91 if (gw_dialog == 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
92 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
93 DWORD tid;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
94 HANDLE thread;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
95 init_event = CreateEvent (0, 0, 0, 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
96 thread = CreateThread (0, 0, dialog, 0, 0, &tid);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
97 WaitForSingleObject (init_event, 1000);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
98 CloseHandle (init_event);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
99 SendMessage (gw_progress, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
100 is_showing = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
101 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
102 char *sl=url, *cp;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
103 for (cp=url; *cp; cp++)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
104 if (*cp == '/' || *cp == '\\' || *cp == ':')
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
105 sl = cp+1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
106 max_bytes = length;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
107 SetWindowText (gw_url, sl);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
108 SetWindowText (gw_rate, "Connecting...");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
109 SendMessage (gw_progress, PBM_SETPOS, (WPARAM) 0, 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
110 ShowWindow (gw_progress, (length > 0) ? SW_SHOW : SW_HIDE);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
111 ShowWindow (gw_dialog, SW_SHOWNORMAL);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
112 if (!is_showing)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
113 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
114 SetForegroundWindow (gw_dialog);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
115 is_showing = 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
116 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
117 start_tics = GetTickCount ();
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
118 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
119
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
120
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
121 static void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
122 progress (int bytes)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
123 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
124 static char buf[100];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
125 int kbps;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
126 static DWORD last_tics = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
127 DWORD tics = GetTickCount ();
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
128 if (tics == start_tics) // to prevent division by zero
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
129 return;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
130 if (tics < last_tics + 200) // to prevent flickering updates
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
131 return;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
132 last_tics = tics;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
133
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
134 kbps = bytes / (tics - start_tics);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
135 ShowWindow (gw_progress, (max_bytes > 0) ? SW_SHOW : SW_HIDE);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
136 if (max_bytes > 100)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
137 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
138 int perc = bytes / (max_bytes / 100);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
139 SendMessage (gw_progress, PBM_SETPOS, (WPARAM) perc, 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
140 sprintf (buf, "%3d %% (%dk/%dk) %d kb/s\n",
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
141 perc, bytes/1000, max_bytes/1000, kbps);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
142 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
143 else
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
144 sprintf (buf, "%d %d kb/s\n", bytes, kbps);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
145
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
146 SetWindowText (gw_rate, buf);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
147 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
148
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
149 struct GUBuf {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
150 GUBuf *next;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
151 int count;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
152 char buf[2000];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
153 };
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
154
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
155 char *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
156 get_url_to_string (char *_url)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
157 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
158 log (LOG_BABBLE, "get_url_to_string %s", _url);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
159 init_dialog (_url, 0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
160 NetIO *n = NetIO::open (_url);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
161 if (!n || !n->ok ())
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
162 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
163 delete n;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
164 log (LOG_BABBLE, "get_url_to_string failed!");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
165 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
166 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
167
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
168 if (n->file_size)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
169 max_bytes = n->file_size;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
170
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
171 GUBuf *bufs = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
172 GUBuf **nextp = &bufs;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
173 int total_bytes = 1; /* for the NUL */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
174 progress (0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
175 while (1)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
176 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
177 GUBuf *b = new GUBuf;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
178 *nextp = b;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
179 b->next = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
180 nextp = &(b->next);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
181
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
182 b->count = n->read (b->buf, sizeof (b->buf));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
183 if (b->count <= 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
184 break;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
185 total_bytes += b->count;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
186 progress (total_bytes);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
187 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
188
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
189 char *rv = (char *) malloc (total_bytes);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
190 char *rvp = rv;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
191 while (bufs && bufs->count > 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
192 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
193 GUBuf *tmp = bufs->next;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
194 memcpy (rvp, bufs->buf, bufs->count);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
195 rvp += bufs->count;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
196 delete bufs;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
197 bufs = tmp;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
198 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
199 *rvp = 0;
672
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
200
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
201 if (n)
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
202 delete n;
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
203
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
204 return rv;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
205 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
206
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
207 int
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
208 get_url_to_file (char *_url, char *_filename, int expected_length)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
209 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
210 log (LOG_BABBLE, "get_url_to_file %s %s", _url, _filename);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
211 init_dialog (_url, expected_length);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
212
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
213 remove (_filename); /* but ignore errors */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
214
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
215 NetIO *n = NetIO::open (_url);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
216 if (!n || !n->ok ())
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
217 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
218 delete n;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
219 log (LOG_BABBLE, "get_url_to_file failed!");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
220 return 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
221 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
222
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
223 FILE *f = fopen (_filename, "wb");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
224 if (!f)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
225 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
226 char *err = strerror (errno);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
227 if (!err)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
228 err = "(unknown error)";
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
229 fatal (IDS_ERR_OPEN_WRITE, _filename, err);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
230 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
231
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
232 if (n->file_size)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
233 max_bytes = n->file_size;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
234
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
235 int total_bytes = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
236 progress (0);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
237 while (1)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
238 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
239 char buf[8192];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
240 int count;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
241 count = n->read (buf, sizeof (buf));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
242 if (count <= 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
243 break;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
244 fwrite (buf, 1, count, f);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
245 total_bytes += count;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
246 progress (total_bytes);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
247 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
248
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
249 fclose (f);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
250
672
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
251 if (n)
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
252 delete n;
42a8626b741e [xemacs-hg @ 2001-10-26 02:42:53 by andyp]
andyp
parents: 448
diff changeset
253
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
254 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
255 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
256
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
257 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
258 dismiss_url_status_dialog ()
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
259 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
260 ShowWindow (gw_dialog, SW_HIDE);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
261 is_showing = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
262 }