/** * @brief UpiWriteSuspendResumeData * * Write suspend / resume data to file * * @para data address of BackupDataType * @return NULL */ void UpiWriteSuspendResumeData(BackupDataType *data) { _backup_bool_ rtn; _backup_u8_ *buf; _backup_u32_ size; _backup_u32_ cmpResult; size = sizeof(BackupSuspendDataType)*BACKUP_MAX_LOG_SUSPEND_DATA; #ifndef UG31XX_SHELL_ALGORITHM buf = (_backup_u8_ *)&UpiWriteSuspendResumeData_buf[0]; #else ///< else of UG31XX_SHELL_ALGORITHM buf = (_backup_u8_ *)upi_malloc(size); #endif ///< end of UG31XX_SHELL_ALGORITHM #if defined (uG31xx_OS_WINDOWS) rtn = read_backup_file(data->suspendFileName, (_upi_u8_ *)buf, size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = read_backup_file(ptrSuspendFileName, (_upi_u8_ *)buf, size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Read suspend / resume data from file -> %d\n", __func__, rtn); if(rtn != _UPI_TRUE_) { #if defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(data->suspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(ptrSuspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Write suspend / resume data to file -> %d\n", __func__, rtn); #ifdef UG31XX_SHELL_ALGORITHM upi_free(buf); #endif ///< end of UG31XX_SHELL_ALGORITHM return; } cmpResult = upi_memcmp(buf, (_backup_u8_ *)(&data->backupSuspendData[0]), size); UG31_LOGN("[%s]: Compare suspend / resume data with file -> %d\n", __func__, (int)cmpResult); if(cmpResult != 0) { #if defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(data->suspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(ptrSuspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Write suspend / resume data to file -> %d\n", __func__, rtn); } #ifdef UG31XX_SHELL_ALGORITHM upi_free(buf); #endif ///< end of UG31XX_SHELL_ALGORITHM }
/** * @brief UpdateBackupFile * * Update backup file * * @para data address of BackupDataType * @return CHECK_BACKUP_FILE_STS */ _backup_u8_ UpdateBackupFile(BackupDataType *data) { _upi_bool_ rtn; PrepareData(data); #if defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(ptrBackupFileName, data->backupBuffer, data->backupBufferSize); #endif ///< end of defined (uG31xx_OS_WINDOWS) if(rtn == _UPI_FALSE_) { UG31_LOGD("[%s]: Write data to backup file fail.\n", __func__); return (CHECK_BACKUP_FILE_STS_WRITE_FAIL); } return (CHECK_BACKUP_FILE_STS_PASS); }
/** * @brief UpdateBackupFile * * Update backup file * * @para data address of BackupDataType * @return CHECK_BACKUP_FILE_STS */ _backup_u8_ UpdateBackupFile(BackupDataType *data) { _upi_bool_ rtn; PrepareData(data); rtn = write_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize); if(rtn == _UPI_FALSE_) { UG31_LOGD("[%s]: Write data to backup file fail.\n", __func__); return (CHECK_BACKUP_FILE_STS_WRITE_FAIL); } return (CHECK_BACKUP_FILE_STS_PASS); }
/* Change the links in one file. LINKS is a list of links in the document, along with their positions and the desired direction of the conversion. */ static void convert_links (const char *file, struct urlpos *links) { struct file_memory *fm; FILE *fp; const char *p; downloaded_file_t downloaded_file_return; struct urlpos *link; int to_url_count = 0, to_file_count = 0; logprintf (LOG_VERBOSE, _("Converting %s... "), file); { /* First we do a "dry run": go through the list L and see whether any URL needs to be converted in the first place. If not, just leave the file alone. */ int dry_count = 0; struct urlpos *dry; for (dry = links; dry; dry = dry->next) if (dry->convert != CO_NOCONVERT) ++dry_count; if (!dry_count) { logputs (LOG_VERBOSE, _("nothing to do.\n")); return; } } fm = wget_read_file (file); if (!fm) { logprintf (LOG_NOTQUIET, _("Cannot convert links in %s: %s\n"), file, strerror (errno)); return; } downloaded_file_return = downloaded_file (CHECK_FOR_FILE, file); if (opt.backup_converted && downloaded_file_return) write_backup_file (file, downloaded_file_return); /* Before opening the file for writing, unlink the file. This is important if the data in FM is mmaped. In such case, nulling the file, which is what fopen() below does, would make us read all zeroes from the mmaped region. */ if (unlink (file) < 0 && errno != ENOENT) { logprintf (LOG_NOTQUIET, _("Unable to delete %s: %s\n"), quote (file), strerror (errno)); wget_read_file_free (fm); return; } /* Now open the file for writing. */ fp = fopen (file, "wb"); if (!fp) { logprintf (LOG_NOTQUIET, _("Cannot convert links in %s: %s\n"), file, strerror (errno)); wget_read_file_free (fm); return; } /* Here we loop through all the URLs in file, replacing those of them that are downloaded with relative references. */ p = fm->content; for (link = links; link; link = link->next) { char *url_start = fm->content + link->pos; if (link->pos >= fm->length) { DEBUGP (("Something strange is going on. Please investigate.")); break; } /* If the URL is not to be converted, skip it. */ if (link->convert == CO_NOCONVERT) { DEBUGP (("Skipping %s at position %d.\n", link->url->url, link->pos)); continue; } /* Echo the file contents, up to the offending URL's opening quote, to the outfile. */ fwrite (p, 1, url_start - p, fp); p = url_start; switch (link->convert) { case CO_CONVERT_TO_RELATIVE: /* Convert absolute URL to relative. */ { char *newname = construct_relative (file, link->local_name); char *quoted_newname = local_quote_string (newname, link->link_css_p); if (link->link_css_p) p = replace_plain (p, link->size, fp, quoted_newname); else if (!link->link_refresh_p) p = replace_attr (p, link->size, fp, quoted_newname); else p = replace_attr_refresh_hack (p, link->size, fp, quoted_newname, link->refresh_timeout); DEBUGP (("TO_RELATIVE: %s to %s at position %d in %s.\n", link->url->url, newname, link->pos, file)); xfree (newname); xfree (quoted_newname); ++to_file_count; break; } case CO_CONVERT_TO_COMPLETE: /* Convert the link to absolute URL. */ { char *newlink = link->url->url; char *quoted_newlink = html_quote_string (newlink); if (link->link_css_p) p = replace_plain (p, link->size, fp, newlink); else if (!link->link_refresh_p) p = replace_attr (p, link->size, fp, quoted_newlink); else p = replace_attr_refresh_hack (p, link->size, fp, quoted_newlink, link->refresh_timeout); DEBUGP (("TO_COMPLETE: <something> to %s at position %d in %s.\n", newlink, link->pos, file)); xfree (quoted_newlink); ++to_url_count; break; } case CO_NULLIFY_BASE: /* Change the base href to "". */ p = replace_attr (p, link->size, fp, ""); break; case CO_NOCONVERT: abort (); break; } } /* Output the rest of the file. */ if (p - fm->content < fm->length) fwrite (p, 1, fm->length - (p - fm->content), fp); fclose (fp); wget_read_file_free (fm); logprintf (LOG_VERBOSE, "%d-%d\n", to_file_count, to_url_count); }
static int run_amz_file(clamz_downloader *dl, const clamz_config *cfg, FILE *amzfile, const char *fname) { char *inbuf; unsigned char *xml; size_t sz; clamz_playlist *pl; int i; int status, rv = 0; char *logname; FILE *logfile; sz = 0; inbuf = NULL; while (!feof(amzfile) && !ferror(amzfile)) { if (inbuf) inbuf = realloc(inbuf, (sz + 1024) * sizeof(char)); else inbuf = malloc((sz + 1024) * sizeof(char)); sz += fread(&inbuf[sz], 1, 1024, amzfile); } if (amzfile != stdin) fclose(amzfile); if (cfg->printonly && cfg->printasxml) { xml = decrypt_amz_file(inbuf, sz, fname); if (!xml) { free(inbuf); return 2; } printf("%s", xml); free(xml); free(inbuf); return 0; } else { if (!cfg->printonly) { if (write_backup_file(inbuf, sz, getbasename(fname))) { free(inbuf); return 3; } } pl = new_playlist(); if (read_amz_file(pl, inbuf, sz, fname)) { free(inbuf); free_playlist(pl); return 2; } if (!cfg->printonly) { logname = get_config_file_name("logs", getbasename(fname), ".log"); if (!logname) { free(inbuf); return 1; } logfile = fopen(logname, "w"); if (!logfile) { perror(logname); free(logname); free(inbuf); return 3; } free(logname); set_download_log_file(dl, logfile); } else { logfile = NULL; } if (cfg->printonly || cfg->verbose) print_pl_info(pl, fname); for (i = 0; i < pl->num_tracks; i++) { if (cfg->printonly || cfg->verbose) print_tr_info(pl->tracks[i], i + 1); status = download_track(dl, pl->tracks[i]); if (!rv) rv = status; fputc('\n', stderr); } set_download_log_file(dl, NULL); free(inbuf); free_playlist(pl); if (logfile) fclose(logfile); return rv; } }