mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[download] download.cpp -> download.c
elinks's hash instead of C++ map.
This commit is contained in:
parent
db99981ec5
commit
bb137d12e9
@ -1,6 +1,6 @@
|
|||||||
top_builddir=../..
|
top_builddir=../..
|
||||||
include $(top_builddir)/Makefile.config
|
include $(top_builddir)/Makefile.config
|
||||||
|
|
||||||
OBJS = download.obj history.o location.o session.o task.o
|
OBJS = download.o history.o location.o session.o task.o
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -53,38 +53,69 @@
|
|||||||
#include "util/conv.h"
|
#include "util/conv.h"
|
||||||
#include "util/error.h"
|
#include "util/error.h"
|
||||||
#include "util/file.h"
|
#include "util/file.h"
|
||||||
|
#include "util/hash.h"
|
||||||
#include "util/lists.h"
|
#include "util/lists.h"
|
||||||
#include "util/memlist.h"
|
#include "util/memlist.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "util/time.h"
|
#include "util/time.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/* TODO: tp_*() should be in separate file, I guess? --pasky */
|
/* TODO: tp_*() should be in separate file, I guess? --pasky */
|
||||||
|
|
||||||
|
|
||||||
INIT_LIST_OF(struct file_download, downloads);
|
INIT_LIST_OF(struct file_download, downloads);
|
||||||
|
|
||||||
std::map<std::string, std::string> uri_tempfiles;
|
static struct hash *uri_tempfiles;
|
||||||
|
|
||||||
void
|
void
|
||||||
clear_uri_tempfiles(void)
|
clear_uri_tempfiles(void)
|
||||||
{
|
{
|
||||||
uri_tempfiles.clear();
|
struct hash_item *item;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!uri_tempfiles) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach_hash_item (item, *uri_tempfiles, i) {
|
||||||
|
if (item->value) {
|
||||||
|
mem_free_set(&item->value, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_hash(&uri_tempfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
check_url_tempfiles(const char *url)
|
check_url_tempfiles(const char *url)
|
||||||
{
|
{
|
||||||
/* Caller must free value */
|
struct hash_item *item;
|
||||||
auto value = uri_tempfiles.find(url);
|
|
||||||
|
|
||||||
if (value == uri_tempfiles.end()) {
|
if (!uri_tempfiles || !url) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return null_or_stracpy((value->second).c_str());
|
item = get_hash_item(uri_tempfiles, url, strlen(url));
|
||||||
|
|
||||||
|
if (!item || !item->value) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stracpy(item->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_uri_tempfile(const char *url, const char *value)
|
||||||
|
{
|
||||||
|
if (!uri_tempfiles) {
|
||||||
|
uri_tempfiles = init_hash8();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uri_tempfiles) {
|
||||||
|
size_t len = strlen(url);
|
||||||
|
char *copy = memacpy(url, len);
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
add_hash_item(uri_tempfiles, copy, len, stracpy(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -563,7 +594,7 @@ download_data_store(struct download *download, struct file_download *file_downlo
|
|||||||
char *url = get_uri_string(file_download->uri, URI_PUBLIC);
|
char *url = get_uri_string(file_download->uri, URI_PUBLIC);
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
uri_tempfiles[url] = file_download->file;
|
set_uri_tempfile(url, file_download->file);
|
||||||
mem_free(url);
|
mem_free(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
srcs += files('download.cpp', 'history.c', 'location.c', 'session.c', 'task.c')
|
srcs += files('download.c', 'history.c', 'location.c', 'session.c', 'task.c')
|
||||||
|
Loading…
Reference in New Issue
Block a user