Skip to content
Snippets Groups Projects
Commit e94ebe02 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add support for actually downloading files.

Just add this to your syncterm.ini:

[WebLists]
Synchronet=http://synchro.net/syncterm.lst
AtariAge=http://www.sfhqbbs.org/ataribbslist-syncterm.php
parent 91346ecf
No related branches found
No related tags found
No related merge requests found
Pipeline #8012 passed
...@@ -2773,6 +2773,27 @@ load_bbslist(struct bbslist **list, ...@@ -2773,6 +2773,27 @@ load_bbslist(struct bbslist **list,
/* System BBS List */ /* System BBS List */
if (stricmp(shared_list, listpath)) /* don't read the same list twice */ if (stricmp(shared_list, listpath)) /* don't read the same list twice */
read_list(shared_list, list, defaults, listcount, SYSTEM_BBSLIST); read_list(shared_list, list, defaults, listcount, SYSTEM_BBSLIST);
/* Web lists */
if (settings.webgets) {
char cache_path[MAX_PATH + 1];
if (get_syncterm_filename(cache_path, sizeof(cache_path), SYNCTERM_PATH_CACHE, false)) {
backslash(cache_path);
strlcat(cache_path, "syncterm-system-cache", sizeof(cache_path));
mkpath(cache_path);
backslash(cache_path);
for (size_t i = 0; settings.webgets[i]; i++) {
char *lpath;
int len = asprintf(&lpath, "%s%s.lst", cache_path, settings.webgets[i]->name);
if (len < 1) {
free(lpath);
}
else {
read_list(lpath, list, defaults, listcount, SYSTEM_BBSLIST);
free(lpath);
}
}
}
}
sort_list(list, listcount, cur, bar, current); sort_list(list, listcount, cur, bar, current);
if (current) if (current)
free(current); free(current);
......
...@@ -1556,10 +1556,94 @@ load_settings(struct syncterm_settings *set) ...@@ -1556,10 +1556,94 @@ load_settings(struct syncterm_settings *set)
/* Shell TERM settings */ /* Shell TERM settings */
iniReadSString(inifile, "SyncTERM", "TERM", "syncterm", set->TERM, sizeof(set->TERM)); iniReadSString(inifile, "SyncTERM", "TERM", "syncterm", set->TERM, sizeof(set->TERM));
/* Web lists */
if (inifile) {
iniFreeNamedStringList(set->webgets);
set->webgets = iniReadNamedStringList(inifile, "WebLists");
}
if (inifile) if (inifile)
fclose(inifile); fclose(inifile);
} }
sem_t download_complete_sem;
void
download_thread(void *args)
{
struct webget_request *req = args;
iniReadHttp(req);
sem_post(&download_complete_sem);
}
void
update_webget_progress(struct webget_request *reqs, size_t items, bool leaveup)
{
size_t sz = items * 120;
char *helpbuf = malloc(sz);
if (helpbuf == NULL)
return;
size_t pos = 0;
static int cur = 0;
static int bar = 0;
bool errors = false;
for (size_t i = 0; i < items; i++) {
if (sz < pos)
break;
assert_pthread_mutex_lock(&reqs[i].mtx);
if (reqs[i].msg) {
helpbuf[pos++] = '`';
helpbuf[pos] = 0;
errors = true;
}
if (reqs[i].cb_data & UINT64_C(0x8000000000000000)) {
helpbuf[pos++] = '`';
helpbuf[pos] = 0;
errors = true;
}
int added = snprintf(&helpbuf[pos], sz - pos, "%-20s: %-20s ",
reqs[i].name, reqs[i].state ? reqs[i].state : "");
pos += added;
if (sz > pos) {
if (reqs[i].msg) {
int added = snprintf(&helpbuf[pos], sz - pos, "%s`\r\n", reqs[i].msg);
pos += added;
}
else if (reqs[i].cb_data & UINT64_C(0x8000000000000000)) {
int added = snprintf(&helpbuf[pos], sz - pos, "Thread Failed to Start`\r\n");
pos += added;
}
else {
char received[10];
char total[10];
byte_estimate_to_str(reqs[i].received_size, received, sizeof(received), 0, 3);
byte_estimate_to_str(reqs[i].remote_size, total, sizeof(total), 0, 3);
if (reqs[i].remote_size) {
int added = snprintf(&helpbuf[pos], sz - pos, "%9s/%-9s ", received, total);
pos += added;
if (sz > pos) {
int pct = reqs[i].received_size * 100 / reqs[i].remote_size;
int added = snprintf(&helpbuf[pos], sz - pos, "~%.*s~%.*s\r\n", pct, "", 10 - pct, "");
pos += added;
}
}
else {
int added = snprintf(&helpbuf[pos], sz - pos, "%9s\r\n", received);
pos += added;
}
}
}
assert_pthread_mutex_unlock(&reqs[i].mtx);
}
uifc.showbuf(((leaveup && errors) ? 0 : WIN_DYN | WIN_ACT) | WIN_HLP | WIN_SAV | WIN_MID | WIN_IMM,
0, 0, 74, items + 4, "Web Cache Update", helpbuf, &cur, &bar);
if (leaveup) {
cur = 0;
bar = 0;
}
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -2073,6 +2157,42 @@ main(int argc, char **argv) ...@@ -2073,6 +2157,42 @@ main(int argc, char **argv)
if (!winsock_startup()) if (!winsock_startup())
return 1; return 1;
if (settings.webgets && !quitting) {
// Update the web list caches...
init_uifc(true, true);
char cache_path[MAX_PATH + 1];
if (get_syncterm_filename(cache_path, sizeof(cache_path), SYNCTERM_PATH_CACHE, false)) {
backslash(cache_path);
strlcat(cache_path, "syncterm-system-cache", sizeof(cache_path));
mkpath(cache_path);
size_t items;
size_t started = 0;
COUNT_LIST_ITEMS(settings.webgets, items);
struct webget_request *reqs = calloc(items, sizeof(struct webget_request));
sem_init(&download_complete_sem, 0, 0);
for (size_t i = 0; i < items; i++) {
if (init_webget_req(&reqs[i], cache_path, settings.webgets[i]->name, settings.webgets[i]->value)) {
reqs[i].cb_data = i;
_beginthread(download_thread, 0, &reqs[i]);
started++;
}
else {
reqs[i].cb_data = UINT64_C(0x8000000000000000) | i;
}
}
while (started > 0) {
if (sem_trywait_block(&download_complete_sem, 200) == 0) {
started--;
}
update_webget_progress(reqs, items, false);
}
sem_destroy(&download_complete_sem);
update_webget_progress(reqs, items, true);
}
uifcbail();
}
load_font_files(); load_font_files();
while ((!quitting) && (bbs != NULL || (bbs = show_bbslist(last_bbs, false)) != NULL)) { while ((!quitting) && (bbs != NULL || (bbs = show_bbslist(last_bbs, false)) != NULL)) {
if (default_hidepopups >= 0) if (default_hidepopups >= 0)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "bbslist.h" #include "bbslist.h"
#include "webget.h"
#if defined(_WIN32) #if defined(_WIN32)
#include <malloc.h> /* alloca() on Win32 */ #include <malloc.h> /* alloca() on Win32 */
...@@ -56,6 +57,7 @@ struct modem_settings { ...@@ -56,6 +57,7 @@ struct modem_settings {
}; };
struct syncterm_settings { struct syncterm_settings {
named_string_t **webgets;
int confirm_close; int confirm_close;
int startup_mode; int startup_mode;
int output_mode; int output_mode;
...@@ -85,7 +87,7 @@ struct syncterm_settings { ...@@ -85,7 +87,7 @@ struct syncterm_settings {
extern ini_bitdesc_t audio_output_bits[]; extern ini_bitdesc_t audio_output_bits[];
extern ini_bitdesc_t audio_output_types[]; extern ini_bitdesc_t audio_output_types[];
extern char *inpath; extern char *inpath;
extern char *list_override; extern char *list_override;
extern const char *syncterm_version; extern const char *syncterm_version;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment