Initial nodelist parsing

This commit is contained in:
Andrew Pamment 2018-02-06 08:05:02 +10:00
parent 7cde3b8704
commit 29ebb8277a
20 changed files with 213 additions and 17 deletions

View File

@ -66,3 +66,7 @@ NEWSTRING: ""
LINE 148 CLEARED LINE 148 CLEARED
OLDSTRING: "Enter the number of a text file to display or Q to quit:" OLDSTRING: "Enter the number of a text file to display or Q to quit:"
NEWSTRING: "" NEWSTRING: ""
LINE 124 MODIFIED
OLDSTRING: "\r\nMailing to %d:%d/%d.%d\r\n"
NEWSTRING: "\r\nMailing to %d:%d/%d.%d (%s)\r\n"

View File

@ -10,6 +10,7 @@ Real Names = false
[network] [network]
type = fido type = fido
fido node = 637:1/999 fido node = 637:1/999
domain = happynet
[General] [General]
Read Sec Level = 10 Read Sec Level = 10

View File

@ -121,7 +121,7 @@ Change Subject? (Y/N)
Read message [1-%d] or N for New: Read message [1-%d] or N for New:
\r\nADDR: \r\nADDR:
\r\n\r\nInvalid Address\r\n \r\n\r\nInvalid Address\r\n
\r\nMailing to %d:%d/%d.%d\r\n \r\nMailing to %d:%d/%d.%d (%s)\r\n
\r\nMailing to @%d\r\n \r\nMailing to @%d\r\n
Start at message [1-%d] or N for New? Start at message [1-%d] or N for New?
\e[2J\e[1;1H\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m \e[2J\e[1;1H\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m

View File

@ -29,7 +29,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -30,7 +30,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && ./configure
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -29,7 +29,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -26,10 +26,10 @@ $(JSMN):
cd ../deps/jsmn/ && $(MAKE) cd ../deps/jsmn/ && $(MAKE)
$(CDK): $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -31,10 +31,10 @@ $(JSMN):
cd ../deps/jsmn/ && $(MAKE) cd ../deps/jsmn/ && $(MAKE)
$(CDK): $(CDK):
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a
JSMN = ../deps/jsmn/libjsmn.a JSMN = ../deps/jsmn/libjsmn.a
CDK = ../deps/cdk-5-20161210/libcdk.a CDK = ../deps/cdk-5-20161210/libcdk.a
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd

View File

@ -34,7 +34,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && ./configure
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -30,7 +30,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && ./configure
cd ../deps/cdk-5.0-20161210/ && $(MAKE) cd ../deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -70,6 +70,7 @@ struct mail_conference {
char *name; char *name;
char *path; char *path;
char *tagline; char *tagline;
char *domain;
int networked; int networked;
int nettype; int nettype;
int realnames; int realnames;
@ -366,4 +367,6 @@ extern char *www_create_link(int dir, int sub, int fid);
extern char *www_decode_hash(char *hash); extern char *www_decode_hash(char *hash);
#endif #endif
extern int menu_system(char *menufile); extern int menu_system(char *menufile);
extern char *nl_get_bbsname(struct fido_addr *addr, char *domain);
#endif #endif

View File

@ -2064,6 +2064,7 @@ void post_message(struct user_record *user) {
char buffer2[256]; char buffer2[256];
int z; int z;
int sem_fd; int sem_fd;
char *bbsname;
s_JamBase *jb; s_JamBase *jb;
s_JamMsgHeader jmh; s_JamMsgHeader jmh;
@ -2106,7 +2107,14 @@ void post_message(struct user_record *user) {
s_printf(get_string(122)); s_printf(get_string(122));
return; return;
} }
s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point); if (conf.mail_conferences[gUser->cur_mail_conf]->domain != NULL) {
bbsname = nl_get_bbsname(from_addr, conf.mail_conferences[gUser->cur_mail_conf]->domain);
} else {
bbsname = strdup("Unknown");
}
s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point, bbsname);
free(bbsname);
} }
} }
} }

View File

@ -327,6 +327,8 @@ static int mail_area_handler(void* user, const char* section, const char* name,
} }
} else if (strcasecmp(name, "fido node") == 0) { } else if (strcasecmp(name, "fido node") == 0) {
mc->fidoaddr = parse_fido_addr(value); mc->fidoaddr = parse_fido_addr(value);
} else if (strcasecmp(name, "domain") == 0) {
mc->domain = strdup(value);
} }
} else { } else {
// check if it's partially filled in // check if it's partially filled in
@ -551,6 +553,7 @@ static int handler(void* user, const char* section, const char* name,
conf->mail_conferences[conf->mail_conference_count]->tagline = NULL; conf->mail_conferences[conf->mail_conference_count]->tagline = NULL;
conf->mail_conferences[conf->mail_conference_count]->mail_area_count = 0; conf->mail_conferences[conf->mail_conference_count]->mail_area_count = 0;
conf->mail_conferences[conf->mail_conference_count]->nettype = 0; conf->mail_conferences[conf->mail_conference_count]->nettype = 0;
conf->mail_conferences[conf->mail_conference_count]->domain = NULL;
conf->mail_conference_count++; conf->mail_conference_count++;
} else if (strcasecmp(section, "file directories") == 0) { } else if (strcasecmp(section, "file directories") == 0) {
if (conf->file_directory_count == 0) { if (conf->file_directory_count == 0) {

53
src/nodelist.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <string.h>
#include <sqlite3.h>
#include "bbs.h"
extern struct bbs_config conf;
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);
return 0;
}
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;
}

124
utils/nodelistp/nodelistp.pl Executable file
View File

@ -0,0 +1,124 @@
#!/usr/bin/env perl
# Contains code by Robert James Clay's FTNDB project. Licensed under the
# same license as perl.
# https://metacpan.org/source/JAME/App-FTNDB-0.39/bin/ftndb-nodelist
use DBI;
use strict;
if ($#ARGV < 2) {
print "Usage ./nodelistp.pl nodelist database.sq3 domain\n";
exit(0);
}
my $nodelist = $ARGV[0];
my $database = $ARGV[1];
my $domain = $ARGV[2];
my $driver = "SQLite";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "";
my $password = "";
my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
or die $DBI::errstr;
my $stmt = qq(CREATE TABLE IF NOT EXISTS nodelist (
Id INTEGER PRIMARY KEY,
domain TEXT COLLATE NOCASE,
nodeno TEXT,
sysop TEXT,
location TEXT,
bbsname TEXT););
my $rv = $dbh->do($stmt);
if($rv < 0){
print $DBI::errstr;
exit(0);
}
open NODELIST, $nodelist or die print "Cannot open $nodelist";
$stmt = 'DELETE FROM nodelist WHERE domain=$1;';
my $sth = $dbh->prepare( $stmt );
$rv = $sth->execute($domain) or die $DBI::errstr;
if($rv < 0){
print $DBI::errstr;
}
my $nodelistcount = 0;
my $zone = 1;
my $net = 0;
my $node = 0;
my $region = 0;
my $location;
my $sysop;
my $name;
my $type;
my $number;
my $phone;
my $bps;
my $flags;
my $zone_number;
my $nodeno;
while (<NODELIST>) {
if ( /^;/ || /^\cZ/ ) {
# print;
next;
}
( $type, $number, $name, $location, $sysop, $phone, $bps, $flags ) =
split /,/, $_, 8 ;
# if $flags is undefined (i.e., nothing after the baud rate)
if ( !defined $flags ) {
$flags = q{ };
}
else {
$flags =~ s/\r?\n$//; # else remove EOL (removes \r\n or \n but not \r) from $flags
}
if ( $type eq 'Zone' ) { # Zone line
$zone = $number;
$net = $number;
$node = 0;
} #
elsif ( $type eq 'Region' ) { # Region line
$region = $number;
$net = $number;
$node = 0;
}
elsif ( $type eq 'Host' ) { # Host line
$net = $number;
$node = 0;
}
else {
$node = $number;
}
# If zone_number is defined, then go to the next line if the zone
# number is not the same as zone_number
if (defined $zone_number) {
if ($zone != $zone_number) {
next;
}
}
$name =~ s/\_/ /g;
$sysop =~ s/\_/ /g;
$location =~ s/\_/ /g;
$nodeno = "$zone:$net/$node";
$sth = $dbh->prepare('INSERT INTO nodelist (domain, nodeno, sysop, location, bbsname) VALUES($1, $2, $3, $4, $5)');
$sth->execute($domain, $nodeno, $sysop, $location, $name);
$nodelistcount++;
}
close NODELIST;
print "Processed $nodelistcount nodes.\n";