Initial original import from: fuse-2.4.2-2.fc4
[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/downloads/details.aspx?familyid=7a4d8d12-9f5d-42bb-b31c-7b31657c869c"
41 #else
42 #define MICROSOFTDOWNLOAD_URL "http://download.microsoft.com/download/e/c/6/ec6e00ab-ec05-4673-b8db-0658cf65f043/WindowsXP-KB835935-SP2-DEBUG-ENU.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 GnomeVFSURI *uri;
54
55 #ifdef MICROSOFTCOM_URL
56         base_contents=NULL;
57         if (GNOME_VFS_OK!=gnome_vfs_read_entire_file(MICROSOFTCOM_URL,&base_size,&base_contents)
58                         || base_size<=0) {
59                 g_warning(_("Cannot load base URL: %s"),MICROSOFTCOM_URL);
60                 goto fail_free_base_contents;
61                 }
62         base_contents[base_size-1]=0;   /* string terminator */
63         if (!(href=strstr(base_contents,"http://download.microsoft.com/")) || !(href_end=strchr(href,'"'))) {
64                 g_warning(_("Destination file URL not found in base URL: %s"),MICROSOFTCOM_URL);
65                 goto fail_free_base_contents;
66                 }
67         *href_end=0;
68 #else
69         href=MICROSOFTDOWNLOAD_URL;
70 #endif
71         if (!(uri=gnome_vfs_uri_new(href))) {
72                 g_warning(_("Found destination file URL not parsable: %s"),href);
73                 goto fail_free_base_contents;
74                 }
75 #ifdef MICROSOFTCOM_URL
76         g_free(base_contents);
77 #endif
78         return g_list_append(NULL,uri);
79
80 fail_free_base_contents:
81 #ifdef MICROSOFTCOM_URL
82         g_free(base_contents);
83 #endif
84         return NULL;
85 }