00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024 #include <unistd.h>
00025 #include <string.h>
00026
00027 #include "libuau.h"
00028 #include "network.h"
00029 #include "ftp.h"
00030 #include "util.h"
00031 #include "error.h"
00032 #include "parseupdates.h"
00033 #include "md5.h"
00034
00035 #ifdef WITH_DMALLOC
00036 # include <dmalloc.h>
00037 #endif
00038
00047 GPtrArray *
00048 luau_net_queryServer(const AProgInfo *info) {
00049 GPtrArray *updates;
00050 GString *contents, *temp;
00051 int len;
00052
00053 if (info->url == NULL) {
00054 ERROR("Can't check for updates: no URL specified in database");
00055 return NULL;
00056 }
00057 contents = lutil_ftp_getURL(info->url);
00058 if (contents == NULL) {
00059 ERROR("Couldn't read/download file %s", info->url);
00060 return NULL;
00061 }
00062
00063 len = strlen(info->url);
00064 if (len > 3 && lutil_streq(info->url+len-3, ".gz")) {
00065 DBUGOUT("Updates file is compressed: uncompressing");
00066 temp = lutil_uncompress(contents);
00067 g_string_free(contents, TRUE);
00068 if (temp == NULL) {
00069 ERROR("Couldn't uncompress gzipped file: aborting");
00070 return NULL;
00071 }
00072 contents = temp;
00073 }
00074
00075 updates = luau_parseUpdateFileXML(contents->str);
00076
00077 g_string_free(contents, TRUE);
00078
00079 return updates;
00080 }
00081
00092 gboolean
00093 luau_net_downloadUpdate(const AProgInfo* info, const AUpdate *update, APkgType pkgType, const char* downloadTo) {
00094 char md5[33], *loc;
00095 APackage *package;
00096 gboolean loopAgain, result;
00097 int choice;
00098
00099 md5[0] = '\0';
00100
00101 package = luau_getUpdatePackage(update, pkgType);
00102
00103 if (package == NULL || package->mirrors == NULL || package->mirrors->len == 0) {
00104 ERROR("Couldn't get filename for this update!");
00105 return FALSE;
00106 }
00107
00108 loc = luau_getPackageURL(package);
00109 result = lutil_ftp_downloadToFile(loc, downloadTo);
00110 if (result == FALSE) {
00111 ERROR("Couldn't retrieve file");
00112 return FALSE;
00113 }
00114
00115 if (package->md5sum[0] != '\0') {
00116 lutil_md5_file(downloadTo, md5);
00117 if (md5[0] == '\0') {
00118 ERROR("Couldn't compute md5sum of file");
00119 return FALSE;
00120 }
00121
00122 result = FALSE;
00123 if (! lutil_streq(md5, package->md5sum)) {
00124 while (1) {
00125 loopAgain = FALSE;
00126 choice = lutil_error_prompt("MD5 Sum Mismatch", "The computed md5 sum of the downloaded file does not match the expected value", 3, 2, "Re-Download", "Use Anyway", "Cancel");
00127 switch (choice) {
00128 case 0:
00129 unlink(downloadTo);
00130 result = luau_net_downloadUpdate(info, update, pkgType, downloadTo);
00131 break;
00132 case 1:
00133 result = TRUE;
00134 break;
00135 case 2:
00136 ERROR("Couldn't download update: md5sum mismatch (found %s, expected %s)", md5, package->md5sum);
00137 result = FALSE;
00138 unlink(downloadTo);
00139 break;
00140 default:
00141 loopAgain = TRUE;
00142 }
00143
00144 if (!loopAgain)
00145 break;
00146 }
00147 } else {
00148 result = TRUE;
00149 }
00150 } else {
00151 result = TRUE;
00152 }
00153
00154 return result;
00155 }
00156