2018-02-05 22:05:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include "bbs.h"
|
|
|
|
|
|
|
|
extern struct bbs_config conf;
|
2018-02-06 01:41:55 +00:00
|
|
|
extern struct user_record *gUser;
|
2018-02-05 22:05:02 +00:00
|
|
|
|
|
|
|
char *nl_get_bbsname(struct fido_addr *addr, char *domain) {
|
|
|
|
sqlite3 *db;
|
|
|
|
sqlite3_stmt *res;
|
|
|
|
int rc;
|
|
|
|
char buffer[PATH_MAX];
|
|
|
|
char *ret;
|
|
|
|
char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?";
|
|
|
|
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
|
|
|
|
|
|
|
|
rc = sqlite3_open(buffer, &db);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
|
|
|
return strdup("Unknown");
|
|
|
|
}
|
|
|
|
sqlite3_busy_timeout(db, 5000);
|
|
|
|
|
|
|
|
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
sqlite3_close(db);
|
2018-02-06 01:41:55 +00:00
|
|
|
return strdup("Unknown");
|
2018-02-05 22:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (addr->point == 0) {
|
|
|
|
snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node);
|
|
|
|
} else {
|
|
|
|
// no support for point addresses yet.
|
|
|
|
return strdup("Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_bind_text(res, 1, buffer, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 2, domain, -1, 0);
|
|
|
|
|
|
|
|
if (sqlite3_step(res) != SQLITE_ROW) {
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return strdup("Unknown");
|
|
|
|
}
|
|
|
|
ret = strdup(sqlite3_column_text(res, 0));
|
|
|
|
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return ret;
|
2018-02-06 01:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nl_temp {
|
|
|
|
char *address;
|
|
|
|
char *location;
|
|
|
|
char *sysop;
|
|
|
|
char *bbsname;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nl_browser() {
|
|
|
|
int entry_count = 0;
|
|
|
|
struct nl_temp **entries;
|
|
|
|
sqlite3 *db;
|
|
|
|
sqlite3_stmt *res;
|
|
|
|
int rc;
|
|
|
|
char buffer[PATH_MAX];
|
|
|
|
char *ret;
|
|
|
|
char *sql_buf = "SELECT nodeno,location,sysop,bbsname FROM nodelist WHERE domain=?";
|
|
|
|
int i;
|
|
|
|
int redraw = 1;
|
|
|
|
int start = 0;
|
|
|
|
int selected = 0;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
// load nodelist
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path);
|
|
|
|
|
|
|
|
rc = sqlite3_open(buffer, &db);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sqlite3_busy_timeout(db, 5000);
|
|
|
|
|
|
|
|
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
sqlite3_close(db);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0);
|
|
|
|
|
|
|
|
while (sqlite3_step(res) == SQLITE_ROW) {
|
|
|
|
if (entry_count == 0) {
|
|
|
|
entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *));
|
|
|
|
} else {
|
|
|
|
entries = (struct nl_temp **)realloc(entries, sizeof(struct nl_temp *) * (entry_count + 1));
|
|
|
|
}
|
|
|
|
entries[entry_count] = (struct nl_temp *)malloc(sizeof(struct nl_temp));
|
|
|
|
|
|
|
|
entries[entry_count]->address = strdup(sqlite3_column_text(res, 0));
|
|
|
|
entries[entry_count]->location = strdup(sqlite3_column_text(res, 1));
|
|
|
|
entries[entry_count]->sysop = strdup(sqlite3_column_text(res, 2));
|
|
|
|
entries[entry_count]->bbsname = strdup(sqlite3_column_text(res, 3));
|
|
|
|
entry_count++;
|
|
|
|
}
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (redraw) {
|
|
|
|
s_printf("\e[2J\e[1;1H");
|
|
|
|
s_printf(get_string(145));
|
|
|
|
s_printf(get_string(146));
|
|
|
|
for (i=start;i<start+22 && i < entry_count;i++) {
|
|
|
|
if (i == selected) {
|
|
|
|
s_printf(get_string(147), i - start + 2, i, entries[i]->address, entries[i]->bbsname);
|
|
|
|
} else {
|
2018-02-06 01:51:08 +00:00
|
|
|
s_printf(get_string(261), i - start + 2, i, entries[i]->address, entries[i]->bbsname);
|
2018-02-06 01:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
|
|
|
redraw = 0;
|
|
|
|
}
|
|
|
|
c = s_getchar();
|
|
|
|
if (tolower(c) == 'q') {
|
|
|
|
break;
|
|
|
|
} else if (c == 27) {
|
|
|
|
c = s_getchar();
|
|
|
|
if (c == 91) {
|
|
|
|
c = s_getchar();
|
|
|
|
if (c == 66) {
|
|
|
|
// down
|
|
|
|
if (selected + 1 >= start + 22) {
|
|
|
|
start += 22;
|
|
|
|
if (start >= entry_count) {
|
|
|
|
start = entry_count - 22;
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
selected++;
|
|
|
|
if (selected >= entry_count) {
|
|
|
|
selected = entry_count - 1;
|
|
|
|
} else {
|
|
|
|
if (!redraw) {
|
2018-02-06 01:51:08 +00:00
|
|
|
s_printf(get_string(261), selected - start + 1, selected - 1, entries[selected - 1]->address, entries[selected - 1]->bbsname);
|
2018-02-06 01:41:55 +00:00
|
|
|
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
|
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == 65) {
|
|
|
|
// up
|
|
|
|
if (selected - 1 < start) {
|
|
|
|
start -= 22;
|
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
selected--;
|
|
|
|
if (selected < 0) {
|
|
|
|
selected = 0;
|
|
|
|
} else {
|
|
|
|
if (!redraw) {
|
|
|
|
s_printf(get_string(147), selected - start + 2, selected, entries[selected]->address, entries[selected]->bbsname);
|
2018-02-06 01:51:08 +00:00
|
|
|
s_printf(get_string(261), selected - start + 3, selected + 1, entries[selected + 1]->address, entries[selected + 1]->bbsname);
|
2018-02-06 01:41:55 +00:00
|
|
|
s_printf("\e[%d;5H", selected - start + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == 75) {
|
|
|
|
// END KEY
|
|
|
|
selected = entry_count - 1;
|
|
|
|
start = entry_count - 22;
|
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 72) {
|
|
|
|
// HOME KEY
|
|
|
|
selected = 0;
|
|
|
|
start = 0;
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 86 || c == '5') {
|
|
|
|
if (c == '5') {
|
|
|
|
s_getchar();
|
|
|
|
}
|
|
|
|
// PAGE UP
|
|
|
|
selected = selected - 22;
|
|
|
|
if (selected < 0) {
|
|
|
|
selected = 0;
|
|
|
|
}
|
|
|
|
start = selected;
|
|
|
|
redraw = 1;
|
|
|
|
} else if (c == 85 || c == '6') {
|
|
|
|
if (c == '6') {
|
|
|
|
s_getchar();
|
|
|
|
}
|
|
|
|
// PAGE DOWN
|
|
|
|
selected = selected + 22;
|
|
|
|
if (selected >= entry_count) {
|
|
|
|
selected = entry_count -1;
|
|
|
|
}
|
|
|
|
start = selected;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == 13) {
|
|
|
|
s_printf("\e[2J\e[1;1H");
|
|
|
|
s_printf(get_string(262), entries[selected]->address);
|
|
|
|
s_printf(get_string(263));
|
|
|
|
s_printf(get_string(264), entries[selected]->bbsname);
|
|
|
|
s_printf(get_string(265), entries[selected]->sysop);
|
|
|
|
s_printf(get_string(266), entries[selected]->location);
|
|
|
|
s_printf(get_string(267));
|
|
|
|
s_printf(get_string(185));
|
|
|
|
s_getc();
|
|
|
|
s_printf("\r\n");
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0;i<entry_count;i++) {
|
|
|
|
free(entries[i]->address);
|
|
|
|
free(entries[i]->bbsname);
|
|
|
|
free(entries[i]->sysop);
|
|
|
|
free(entries[i]->location);
|
|
|
|
free(entries[i]);
|
|
|
|
}
|
|
|
|
free(entries);
|
2018-02-05 22:05:02 +00:00
|
|
|
}
|