Cosmetic: Error messages cleanup.
[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  */
37 #define MICROSOFTCOM_URL "http://www.microsoft.com/WindowsXP/pro/downloads/servicepacks/sp1/checkedbuild.asp"
38
39
40 GList * /* of (GnomeVFSURI *) */ mod_uri_microsoftcom_list(void)
41 {
42 int base_size;
43 char *base_contents;
44 char *href,*href_end;
45 const char *href2;
46 GnomeVFSURI *uri;
47
48         base_contents=NULL;
49         if (GNOME_VFS_OK!=gnome_vfs_read_entire_file(MICROSOFTCOM_URL,&base_size,&base_contents)
50                         || base_size<=0) {
51                 g_warning(_("Cannot load base URL: %s"),MICROSOFTCOM_URL);
52                 goto fail_free_base_contents;
53                 }
54         base_contents[base_size-1]=0;   /* string terminator */
55         if (!(href=strstr(base_contents,"http://download.microsoft.com/")) || !(href_end=strchr(href,'"'))) {
56                 g_warning(_("Destination file URL not found in base URL: %s"),MICROSOFTCOM_URL);
57                 goto fail_free_base_contents;
58                 }
59         *href_end=0;
60         if (strncmp(href,"http://",strlen("http://"))) {
61                 g_warning(_("Destination file URL not valid: %s"),href);
62                 goto fail_free_base_contents;
63                 }
64         href2=captive_printf_alloca("httpcaptive://%s",href+strlen("http://"));
65         if (!(uri=gnome_vfs_uri_new(href2))) {
66                 g_warning(_("Found destination file URL not parsable: %s"),href2);
67                 goto fail_free_base_contents;
68                 }
69         g_free(base_contents);
70         return g_list_append(NULL,uri);
71
72 fail_free_base_contents:
73         g_free(base_contents);
74         return NULL;
75 }