Remove dynamic XPsp1 location URL detection to prevent lockups.
[captive.git] / src / install / acquire / microsoftcom.c
1 /* $Id$
2  * W32 modules finder from microsoft.com Internet download
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "microsoftcom.h"       /* self */
23 #include <glib/gmessages.h>
24 #include <libgnomevfs/gnome-vfs-uri.h>
25 #include <libgnomevfs/gnome-vfs-result.h>
26 #include <libgnomevfs/gnome-vfs-utils.h>
27 #include <string.h>
28
29 #include <captive/macros.h>
30
31
32 /* Config: */
33 /* Do we really need to use indirection by the following 'base' URL?
34  * It appears to me as if some Microsoft Service Pack files URLs
35  * have changed in the past.
36  * Currently we use fixed MICROSOFTDOWNLOAD_URL as we would have to
37  * implement custom Gnome-VFS http timeouts as 'ACQUIRE_CABINET_READ_RAW_READ_TIMEOUT'.
38  */
39 #if 0
40 #define MICROSOFTCOM_URL "http://www.microsoft.com/WindowsXP/pro/downloads/servicepacks/sp1/checkedbuild.asp"
41 #else
42 #define MICROSOFTDOWNLOAD_URL "http://download.microsoft.com/download/9/7/6/9763833d-bd58-41e2-9911-50f64c7252a3/xpsp1a_en_x86_CHK.exe"
43 #endif
44
45
46 GList * /* of (GnomeVFSURI *) */ mod_uri_microsoftcom_list(void)
47 {
48 #ifdef MICROSOFTCOM_URL
49 int base_size;
50 char *base_contents,*href_end;
51 #endif
52 char *href;
53 const char *href2;
54 GnomeVFSURI *uri;
55
56 #ifdef MICROSOFTCOM_URL
57         base_contents=NULL;
58         if (GNOME_VFS_OK!=gnome_vfs_read_entire_file(MICROSOFTCOM_URL,&base_size,&base_contents)
59                         || base_size<=0) {
60                 g_warning(_("Cannot load base URL: %s"),MICROSOFTCOM_URL);
61                 goto fail_free_base_contents;
62                 }
63         base_contents[base_size-1]=0;   /* string terminator */
64         if (!(href=strstr(base_contents,"http://download.microsoft.com/")) || !(href_end=strchr(href,'"'))) {
65                 g_warning(_("Destination file URL not found in base URL: %s"),MICROSOFTCOM_URL);
66                 goto fail_free_base_contents;
67                 }
68         *href_end=0;
69 #else
70         href=MICROSOFTDOWNLOAD_URL;
71 #endif
72         if (strncmp(href,"http://",strlen("http://"))) {
73                 g_warning(_("Destination file URL not valid: %s"),href);
74                 goto fail_free_base_contents;
75                 }
76         href2=captive_printf_alloca("httpcaptive://%s",href+strlen("http://"));
77         if (!(uri=gnome_vfs_uri_new(href2))) {
78                 g_warning(_("Found destination file URL not parsable: %s"),href2);
79                 goto fail_free_base_contents;
80                 }
81 #ifdef MICROSOFTCOM_URL
82         g_free(base_contents);
83 #endif
84         return g_list_append(NULL,uri);
85
86 fail_free_base_contents:
87 #ifdef MICROSOFTCOM_URL
88         g_free(base_contents);
89 #endif
90         return NULL;
91 }