diff -urN clussed-19981227/CHANGELOG clussed-19981228/CHANGELOG --- clussed-19981227/CHANGELOG Sun Dec 27 13:20:40 1998 +++ clussed-19981228/CHANGELOG Mon Dec 28 03:36:40 1998 @@ -62,4 +62,13 @@ Fixed send_us() and made some of the cluster.c stubs call it to send cluster events to users. Look ma, variable substitution! +Mon Dec 28 03:36:09 EET 1998 + + Implemented the message ID database in f_mid.c. + Added user commands: dx announce say shout + Made DX spot and PC time formats handling work. + Made announcements work. + The PC ^ token parser now ignores the trailing ~ (actually ignores + a ~ in the beginning of any field). For clx & dxnet compatibility. + diff -urN clussed-19981227/Makefile clussed-19981228/Makefile --- clussed-19981227/Makefile Sun Dec 27 03:25:24 1998 +++ clussed-19981228/Makefile Sun Dec 27 21:08:37 1998 @@ -63,7 +63,7 @@ cmd_cluster.o cmd_sys.o cmd_net.o cmd_usercfg.o \ network.o net_link.o net_user.o net_ping.o net_rdb.o net_pc.o \ linker.o ui.o \ - cfile.o f_dx.o f_ann.o f_wwv.o f_luser.o f_nuser.o f_last.o mid.o \ + cfile.o f_dx.o f_ann.o f_wwv.o f_luser.o f_nuser.o f_last.o f_mid.o \ CLUSSED_LIBS = -lm -lz -lgdbm CLUSSED_SLIBS = lib/libax25.a @@ -100,7 +100,8 @@ luser.o: luser.h luser.c config.h log.h hmalloc.h version.h csock.h \ net_user.h f_luser.h timer.h ctime.h cluster.o: cluster.h cluster.c command.h help.h cmd_sys.h cmd_cluster.h \ - cmd_net.h cmd_usercfg.h network.h net_ping.h luser.h + cmd_net.h cmd_usercfg.h network.h net_ping.h luser.h ctime.h \ + config.h command.o: command.h command.c csock.h cfgfile.h cmd_sys.o: cmd_sys.h cmd_sys.c csock.h version.h hmalloc.h cmd_cluster.o: cmd_cluster.h cmd_cluster.c csock.h hmalloc.h network.h \ @@ -109,12 +110,12 @@ cmd_usercfg.o: cmd_usercfg.h cmd_usercfg.c csock.h luser.h cfgfile.h f_luser.h help.o: help.h help.c csock.h cluster.h network.o: network.h network.c net_ping.h net_link.h net_pc.h net_user.h \ - net_rdb.h mid.h ctime.h config.h ctypes.h luser.h log.h \ + net_rdb.h f_mid.h ctime.h config.h ctypes.h luser.h log.h \ crc.h hmalloc.h linker.h version.h cluster.h ui.h \ f_last.h f_nuser.h f_dx.h f_ann.h f_wwv.h timer.h net_link.o: net_link.h net_link.c network.h net_pc.h net_pc.o: net_pc.h net_pc.c network.h net_user.h log.h cfgfile.h \ - hmalloc.h timer.h ctime.h net_ping.h + hmalloc.h timer.h ctime.h cstring.h net_ping.h net_user.o: net_user.h net_user.c network.h hmalloc.h log.h cluster.h \ net_link.h f_nuser.h timer.h net_ping.o: net_ping.h net_ping.c csock.h network.h luser.h cstring.h \ @@ -122,13 +123,13 @@ net_rdb.o: net_rdb.h net_rdb.c linker.o: linker.h linker.c hmalloc.h csock.h log.h cfgfile.h ui.o: ui.h ui.c -cfile.o: cfile.h cfile.c f_luser.h f_nuser.h +cfile.o: cfile.h cfile.c f_luser.h f_nuser.h f_mid.h f_dx.o: f_dx.h f_dx.c f_ann.o: f_ann.h f_ann.c f_wwv.o: f_wwv.h f_wwv.c f_luser.o: f_luser.h f_luser.c hmalloc.h log.h db.h config.h cstring.h -f_nuser.o: f_nuser.h f_nuser.c hmalloc.h ctypes.h log.h +f_nuser.o: f_nuser.h f_nuser.c hmalloc.h log.h db.h ctypes.h f_last.o: f_last.h f_last.c -mid.o: mid.h mid.c +f_mid.o: f_mid.h f_mid.c hmalloc.h log.h db.h config.h timer.h Binary files clussed-19981227/base/data/mid.db and clussed-19981228/base/data/mid.db differ Binary files clussed-19981227/base/data/nuser.db and clussed-19981228/base/data/nuser.db differ Binary files clussed-19981227/base2/data/mid.db and clussed-19981228/base2/data/mid.db differ Binary files clussed-19981227/base2/data/nuser.db and clussed-19981228/base2/data/nuser.db differ diff -urN clussed-19981227/base2/etc/links.conf clussed-19981228/base2/etc/links.conf --- clussed-19981227/base2/etc/links.conf Thu Dec 24 20:31:11 1998 +++ clussed-19981228/base2/etc/links.conf Sun Dec 27 21:26:06 1998 @@ -3,8 +3,8 @@ protocol pc script scripts/oh7lzb-1.con -#link oh2lzb-1 -#protocol pc -#mode incoming +link oh1lzb-1 +protocol pc +mode incoming diff -urN clussed-19981227/base2/scripts/oh1rbi.con clussed-19981228/base2/scripts/oh1rbi.con --- clussed-19981227/base2/scripts/oh1rbi.con Sun Dec 20 18:08:29 1998 +++ clussed-19981228/base2/scripts/oh1rbi.con Thu Jan 1 02:00:00 1970 @@ -1,21 +0,0 @@ - -# -# Connection script for Clusse 0.40 -# - -telnet localhost 3694 -# ax25 lo0 oh7lzb-2 -# netrom nrclu oh7lzb-2 - -#s "c lo0 oh7lzb-2" -#r "connected" "disc" "fail" "err" - -r "login:" -s "oh7lzb-1" - -r "Welcome" -s "i" - -r "LinuxNode" -s "b" - diff -urN clussed-19981227/base2/scripts/oh7lzb-1.con clussed-19981228/base2/scripts/oh7lzb-1.con --- clussed-19981227/base2/scripts/oh7lzb-1.con Sun Dec 27 02:55:07 1998 +++ clussed-19981228/base2/scripts/oh7lzb-1.con Sun Dec 27 21:25:31 1998 @@ -3,20 +3,5 @@ # Connection script for Clusse 0.40 # -#compressed -#telnet localhost 3694 ax25 lo0 oh7lzb-1 -#netrom nrcl oh7lzb-2 - -#s "c lo0 oh7lzb-1" -#r "connected" "disc" "fail" "err" - -#r "login:" -#s "oh7lzb-1" - -#r "Welcome" -#s "i" - -#r "LinuxNode" -#s "b" Binary files clussed-19981227/base3/data/luser.db and clussed-19981228/base3/data/luser.db differ Binary files clussed-19981227/base3/data/mid.db and clussed-19981228/base3/data/mid.db differ Binary files clussed-19981227/base3/data/nuser.db and clussed-19981228/base3/data/nuser.db differ diff -urN clussed-19981227/base3/etc/clussed.conf clussed-19981228/base3/etc/clussed.conf --- clussed-19981227/base3/etc/clussed.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981228/base3/etc/clussed.conf Sun Dec 27 21:24:14 1998 @@ -0,0 +1,27 @@ + +# +# Visible hostname +# +HostName funk.oh7lzb.ampr.org + +# +# Cluster callsign +# +Callsign oh1lzb-1 + +# +# Sysop's callsign and name +# +SysopCall oh7lzb +SysopName Hessu + +# +# The QTH of the node (arbitrary string) +# +QTH Koivukylä, Vantaa + +# +# Date string field order: dmy, mdy, ymd or ydm +# +#DateFormat dmy + diff -urN clussed-19981227/base3/etc/interface.conf clussed-19981228/base3/etc/interface.conf --- clussed-19981227/base3/etc/interface.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981228/base3/etc/interface.conf Sun Dec 27 21:26:46 1998 @@ -0,0 +1,36 @@ + +# +# TcpListen: Make clussed listen for connections on a TCP port +# +# TcpListen portname port (listen on all addresses) +# TcpListen portname host:port (listen on one address only) +# TcpListen portname ipaddr:port (without the help of DNS) +# +# The 'portname' is an arbitrary name string which Clusse will use +# in the user interface and logs for this interface. +# +# Feel free to use multiple TcpListen directives. +# + +TcpListen tcp 3693 + +# +# Ax25Listen: Make clussed listen for AX.25 connections +# +# Ax25Listen port:callsign (single callsign on a single port) +# Ax25Listen callsign (the same callsign on all ports) +# + +Ax25Listen oh1lzb-1 +Ax25Listen oh1lzb-7 compress +#Ax25Listen bpq:oh7lzb-2 + +# +# NetromListen: Make clussed listen for NET/ROM connections +# +# NetromListen port (port being defined in nrports) +# + +#NetromListen nrcl2 + + diff -urN clussed-19981227/base3/etc/links.conf clussed-19981228/base3/etc/links.conf --- clussed-19981227/base3/etc/links.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981228/base3/etc/links.conf Sun Dec 27 21:24:58 1998 @@ -0,0 +1,5 @@ + +link oh2lzb-1 +protocol pc +script scripts/oh2lzb-1.con + diff -urN clussed-19981227/base3/scripts/oh2lzb-1.con clussed-19981228/base3/scripts/oh2lzb-1.con --- clussed-19981227/base3/scripts/oh2lzb-1.con Thu Jan 1 02:00:00 1970 +++ clussed-19981228/base3/scripts/oh2lzb-1.con Sun Dec 27 21:23:59 1998 @@ -0,0 +1,7 @@ + +# +# Connection script for Clusse 0.40 +# + +ax25 lo0 oh2lzb-1 + diff -urN clussed-19981227/cfile.c clussed-19981228/cfile.c --- clussed-19981227/cfile.c Sat Dec 26 18:21:20 1998 +++ clussed-19981228/cfile.c Sun Dec 27 17:23:24 1998 @@ -9,16 +9,19 @@ #include "cfile.h" #include "f_luser.h" #include "f_nuser.h" +#include "f_mid.h" void files_init(void) { open_luserf(); open_nuserf(); + open_midf(); } void files_close(void) { close_luserf(); close_nuserf(); + close_midf(); } diff -urN clussed-19981227/cluster.c clussed-19981228/cluster.c --- clussed-19981227/cluster.c Sun Dec 27 04:29:55 1998 +++ clussed-19981228/cluster.c Sun Dec 27 21:18:28 1998 @@ -6,6 +6,8 @@ * command list, prompt, cluster event message sending */ +#include + #include "cluster.h" #include "command.h" #include "help.h" @@ -16,20 +18,26 @@ #include "network.h" #include "net_ping.h" #include "luser.h" +#include "ctime.h" +#include "config.h" /* * Cluster commands */ struct cmd cluster_cmds[] = { + { "announce", cmd_announce }, { "bye", cmd_bye }, { "commands", cmd_commands }, + { "dx", cmd_dx }, { "help", cmd_help }, { "links", cmd_links }, { "messages", cmd_messages }, { "memory", cmd_memory }, { "nodes", cmd_nodes }, { "name", cmd_name }, + { "say", cmd_say }, + { "shout", cmd_shout }, { "sockets", cmd_sockets }, { "talk", cmd_talk }, { "treply", cmd_treply }, @@ -101,15 +109,26 @@ (u->away_str) ? u->away_str : ""); } -void user_dx(struct dx_t *dx) +void user_dx(struct dx_t *d) { + char s[sizeof(call_t)+2]; + + sprintf(s, "%s:", d->fromcall); + send_us(M_DX, "DX de %-10.10s%9.9s %-13.13s%sZ %s", + s, freq2str(d->freq), d->call, timestr_s(d->time), d->info); } -void user_announce(struct ann_t *ann) +void user_announce(struct ann_t *a) { + if (!strcmp(a->tonodec, "*")) + send_us(M_ANN, "%s shouts$t: %s", a->fromcall, a->message); + else if (!strcmp(a->tonodec, (char *)clucall)) + send_us(M_ANN, "%s says$t: %s", a->fromcall, a->message); + else + send_us(M_ANN, "%s shouts @%s: %s", a->fromcall, a->tonodec, a->message); } -void user_wwv(struct wwv_t *wwv) +void user_wwv(struct wwv_t *w) { } diff -urN clussed-19981227/cluster.h clussed-19981228/cluster.h --- clussed-19981227/cluster.h Sun Dec 20 18:08:27 1998 +++ clussed-19981228/cluster.h Sun Dec 27 21:07:39 1998 @@ -18,9 +18,9 @@ extern void user_userdel(struct nuser_t *u); extern void user_userhere(struct nuser_t *u); extern void user_useraway(struct nuser_t *u); -extern void user_dx(struct dx_t *dx); -extern void user_announce(struct ann_t *ann); -extern void user_wwv(struct wwv_t *wwv); +extern void user_dx(struct dx_t *d); +extern void user_announce(struct ann_t *a); +extern void user_wwv(struct wwv_t *w); #endif diff -urN clussed-19981227/cmd_cluster.c clussed-19981228/cmd_cluster.c --- clussed-19981227/cmd_cluster.c Sat Dec 26 03:45:41 1998 +++ clussed-19981228/cmd_cluster.c Sun Dec 27 21:19:36 1998 @@ -15,6 +15,7 @@ #include "cstring.h" #include "config.h" #include "cfgfile.h" +#include "timer.h" int cmd_bye(struct csock_t *s, int argc, char **argv) { @@ -64,7 +65,7 @@ } } - if (valid_call((call_t *)to)) { + if (!valid_call((call_t *)to)) { csprintf(s, "%s is not a valid callsign.\n", to); return 0; } @@ -100,3 +101,167 @@ return construct_talk(s, s->lu->last_talk_from, 1, argc, argv); } + +/* + * DX + */ + +int cmd_dx(struct csock_t *s, int argc, char **argv) +{ + struct dx_t *d; + unsigned long fr = 0; + int call_arg = 2; + int i; + + if (argc >= 3) { + if (!((fr = str2freq(argv[1])))) { + fr = str2freq(argv[2]); + call_arg = 1; + } + } + + if (!fr || argc < 3 || strlen(argv[call_arg]) < 3) { + csputs(s, "Usage: Dx []\n"); + return 0; + } + + hstrupr(argv[call_arg]); + d = hmalloc(sizeof(struct dx_t)); + + d->time = now - now % 60; /* need to align on minute boundary, otherwice + we get our own spots back on merge, + the MID checking looses seconds on + the PC link */ + + d->freq = fr; + hstrncpy(d->call, argv[call_arg], sizeof(d->call)); + hstrncpy(d->fromcall, s->lu->f->call, sizeof(call_t)); + hstrncpy(d->fromnodec, (char *)clucall, sizeof(call_t)); + d->via = NULL; + d->hops = 0; + if (argc > 3) + hstrncpy(d->info, argstr(3, argc, argv), sizeof(d->info)); + else + *d->info = '\0'; + + i = net_dx(d); + + switch (i) { + case -1: + csputs(s, "Duplicate check: Already have this spot.\n"); + break; + case -2: + csputs(s, "Bad frequency.\n"); + break; + case -3: + csputs(s, "Bad source node or user callsign.\n"); + break; + default: + } + + return 0; +} + +/* + * Announce + */ + +int cmd_announce(struct csock_t *s, int argc, char **argv) +{ + struct ann_t *a; + + if (argc < 3) { + csputs(s, "Usage: Announce Local|Full| \n"); + return 0; + } + + a = hmalloc(sizeof(struct ann_t)); + hstrncpy(a->tonodec, argv[1], sizeof(call_t)); + hstrupr(a->tonodec); + if (!strcmp(a->tonodec, "F") || !strcmp(a->tonodec, "FULL")) + strcpy(a->tonodec, "*"); + else if (!strcmp(a->tonodec, "L") || !strcmp(a->tonodec, "LOCAL")) + strcpy(a->tonodec, (char *)clucall); + else if (!get_node(&a->tonodec)) { + csprintf(s, "Node %s not found.\n", a->tonodec); + hfree(a); + return 0; + } + + hstrncpy(a->message, argstr(2, argc, argv), sizeof(a->message)); + hstrncpy(a->fromcall, s->lu->f->call, sizeof(call_t)); + hstrncpy(a->fromnodec, (char *)clucall, sizeof(call_t)); + + a->wx = 0; + a->sysop = 0; + a->time = now; + a->hops = 0; + a->via = NULL; + + net_announce(a); + + return 0; +} + +/* + * Say + */ + +int cmd_say(struct csock_t *s, int argc, char **argv) +{ + struct ann_t *a; + + if (argc < 2) { + csputs(s, "Usage: Say \n"); + return 0; + } + + a = hmalloc(sizeof(struct ann_t)); + hstrncpy(a->tonodec, (char *)clucall, sizeof(call_t)); + + hstrncpy(a->message, argstr(1, argc, argv), sizeof(a->message)); + hstrncpy(a->fromcall, s->lu->f->call, sizeof(call_t)); + hstrncpy(a->fromnodec, (char *)clucall, sizeof(call_t)); + + a->wx = 0; + a->sysop = 0; + a->time = now; + a->hops = 0; + a->via = NULL; + + net_announce(a); + + return 0; +} + +/* + * Shout + */ + +int cmd_shout(struct csock_t *s, int argc, char **argv) +{ + struct ann_t *a; + + if (argc < 2) { + csputs(s, "Usage: SHout \n"); + return 0; + } + + a = hmalloc(sizeof(struct ann_t)); + hstrncpy(a->tonodec, "*", sizeof(call_t)); + + hstrncpy(a->message, argstr(1, argc, argv), sizeof(a->message)); + hstrncpy(a->fromcall, s->lu->f->call, sizeof(call_t)); + hstrncpy(a->fromnodec, (char *)clucall, sizeof(call_t)); + + a->wx = 0; + a->sysop = 0; + a->time = now; + a->hops = 0; + a->via = NULL; + + net_announce(a); + + return 0; +} + diff -urN clussed-19981227/cmd_cluster.h clussed-19981228/cmd_cluster.h --- clussed-19981227/cmd_cluster.h Sun Dec 20 18:08:27 1998 +++ clussed-19981228/cmd_cluster.h Sun Dec 27 21:18:09 1998 @@ -7,5 +7,9 @@ extern int cmd_bye(struct csock_t *s, int argc, char **argv); extern int cmd_talk(struct csock_t *s, int argc, char **argv); extern int cmd_treply(struct csock_t *s, int argc, char **argv); +extern int cmd_dx(struct csock_t *s, int argc, char **argv); +extern int cmd_announce(struct csock_t *s, int argc, char **argv); +extern int cmd_say(struct csock_t *s, int argc, char **argv); +extern int cmd_shout(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981227/cmd_net.c clussed-19981228/cmd_net.c --- clussed-19981227/cmd_net.c Sat Dec 26 18:41:35 1998 +++ clussed-19981228/cmd_net.c Sun Dec 27 22:35:46 1998 @@ -34,13 +34,18 @@ int cmd_nodes(struct csock_t *s, int argc, char **argv) { struct node_t *n1 = nodes, *n2 = nodes, *n2s; - int i; + int i, l; - for (i = 0; i < node_count/2; i++) + /* dang. this part looks ugly. but works */ + /* bottle of beer for the one who cleans this up */ + l = node_count/2; + if ((node_count % 2 != 0) && (node_count > 1)) + l++; + if (node_count == 1) + n2 = NULL; + for (i = 1; (i <= l) && (n2); i++) n2 = n2->next; /* Halfway up the list */ - if (i == 0) - n2 = n2->next; - + n2s = n2; csprintf(s, "Nodes: %d (max %d), %d of %d links\n", @@ -132,9 +137,6 @@ return 0; } - - - /* * User listing diff -urN clussed-19981227/config.c clussed-19981228/config.c --- clussed-19981227/config.c Thu Dec 24 20:37:26 1998 +++ clussed-19981228/config.c Sun Dec 27 17:27:32 1998 @@ -69,6 +69,7 @@ char *data_d = NULL; char *luser_f = NULL; char *nuser_f = NULL; +char *mid_f = NULL; call_t *clucall = NULL; char *hostname = NULL; @@ -131,6 +132,8 @@ luser_f = hstrdup(s); snprintf(s, PATHLEN, "%s%s", data_d, NUSER_F_N); nuser_f = hstrdup(s); + snprintf(s, PATHLEN, "%s%s", data_d, MID_F_N); + mid_f = hstrdup(s); } /* diff -urN clussed-19981227/config.h clussed-19981228/config.h --- clussed-19981227/config.h Thu Dec 24 16:51:44 1998 +++ clussed-19981228/config.h Sun Dec 27 17:27:01 1998 @@ -12,6 +12,7 @@ extern char *links_f; extern char *luser_f; extern char *nuser_f; +extern char *mid_f; #define ETC_D_N "etc/" #define CONFIG_F_N "clussed.conf" @@ -20,6 +21,7 @@ #define DATA_D_N "data/" #define LUSER_F_N "luser.db" #define NUSER_F_N "nuser.db" +#define MID_F_N "mid.db" extern call_t *clucall; extern char *hostname; diff -urN clussed-19981227/cstring.c clussed-19981228/cstring.c --- clussed-19981227/cstring.c Mon Dec 21 20:52:42 1998 +++ clussed-19981228/cstring.c Sun Dec 27 19:05:03 1998 @@ -80,10 +80,10 @@ char *p[1]; if (s == NULL) - return -1; + return 0; while (*s && *s != '-') { if (!isalnum(*s)) - return -1; + return 0; if (isdigit(*s)) nums++; len++; @@ -91,15 +91,15 @@ } if (*s == '-') { if (!isdigit(*++s)) - return -1; + return 0; ssid = strtol(s, p, 10); if (**p) - return -1; + return 0; } if (len < 4 || len > 6 || !nums || nums > 2 || ssid < 0 || ssid > 15) - return -1; + return 0; - return 0; + return 1; } /* @@ -356,7 +356,7 @@ char *freq2str(long i) { static char s[30]; - snprintf(s, 30, "%.1f", i / 10); + snprintf(s, 30, "%.1f", (double)i / (double)10); s[29] = '\0'; return s; } diff -urN clussed-19981227/ctime.c clussed-19981228/ctime.c --- clussed-19981227/ctime.c Sat Dec 26 03:37:34 1998 +++ clussed-19981228/ctime.c Sun Dec 27 20:17:19 1998 @@ -7,6 +7,8 @@ #include #include +#include +#include #include "ctime.h" @@ -16,13 +18,13 @@ time_t start_time; -char days[7][10] = { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" +char *days[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", NULL }; -char months[12][4] = { +char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec" + "Oct", "Nov", "Dec", NULL }; /* Days in a month */ @@ -61,7 +63,7 @@ char *secs2str_l(long i) { - static char s[40]; + static char s[10]; int sec, min, hou; int day; @@ -92,7 +94,7 @@ char *secs2str_s(long i) { int sec, min, hou, day; - static char s[10]; + static char s[4]; day = (long) (i / 86400.0); if (day > 0) { @@ -151,7 +153,7 @@ char *mins2str_s(long i) { int min, hou, day; - static char s[10]; + static char s[5]; day = (long) (i / 1440.0); if (day > 0) { @@ -176,7 +178,7 @@ char *datestr(time_t t) { - static char s[15]; + static char s[9]; struct tm *tm; tm = gmtime(&t); @@ -209,7 +211,7 @@ char *datestr_s(time_t t) { - static char s[10]; + static char s[6]; struct tm *tm; tm = gmtime(&t); @@ -234,7 +236,7 @@ char *datestr_s_pad(time_t t) { - static char s[10]; + static char s[6]; struct tm *tm; tm = gmtime(&t); @@ -259,7 +261,7 @@ char *timestr_l(time_t t) { - static char s[15]; + static char s[9]; struct tm *tm; tm = gmtime(&t); @@ -276,7 +278,7 @@ char *timestr_p(time_t t) { - static char s[15]; + static char s[6]; struct tm *tm; tm = gmtime(&t); @@ -292,7 +294,7 @@ char *timestr(time_t t) { - static char s[15]; + static char s[6]; struct tm *tm; tm = gmtime(&t); @@ -309,7 +311,7 @@ char *timestr_s(time_t t) { - static char s[15]; + static char s[5]; struct tm *tm; tm = gmtime(&t); @@ -325,24 +327,88 @@ extern time_t pcstr2t(char *pcdate, char *pctime) { - return 0; + char *p, *p2; + struct tm t; + int i; + + t.tm_sec = 0; + t.tm_min = 0; + t.tm_hour = 0; + + t.tm_mday = 0; + t.tm_mon = 0; + t.tm_year = 0; + + t.tm_isdst = 0; + + /* mday */ + p = pcdate; + if (!((p2 = strchr(p, '-')))) + return 0; + *p2 = '\0'; + t.tm_mday = atoi(p); + + /* mon */ + p = p2 + 1; + if (!((p2 = strchr(p, '-')))) + return 0; + *p2 = '\0'; + for (i = 0; (*months[i]); i++) + if (!strcasecmp(months[i], p)) + break; + if (!*months[i]) + return 0; + t.tm_mon = i; + + /* year */ + p = p2 + 1; + if (!*p) + return 0; + t.tm_year = atoi(p) - 1900; + if (t.tm_year < 0) + return 0; + + /* min */ + if (strlen(pctime) != 5) + return 0; + if (!((p = strchr(pctime, 'Z')))) + return 0; + *p = '\0'; + p = pctime + 2; + t.tm_min = atoi(p); + + /* hour */ + *p = '\0'; + t.tm_hour = atoi(pctime); + + return mktime(&t); } /* - * time_t to PC date + * time_t to PC date "d-Mon-year" */ extern char *pcdatestr(time_t t) { - return NULL; + static char s[12]; + struct tm *tm; + + tm = gmtime(&t); + sprintf(s, "%d-%s-%d", tm->tm_mday, months[tm->tm_mon], tm->tm_year+1900); + return s; } /* - * time_t to PC time + * time_t to PC time "hhmmZ" */ extern char *pctimestr(time_t t) { - return NULL; + static char s[6]; + struct tm *tm; + + tm = gmtime(&t); + sprintf(s, "%2.2d%2.2dZ", tm->tm_hour, tm->tm_min); + return s; } diff -urN clussed-19981227/db.c clussed-19981228/db.c --- clussed-19981227/db.c Thu Dec 24 15:57:46 1998 +++ clussed-19981228/db.c Sun Dec 27 17:47:05 1998 @@ -5,6 +5,9 @@ * an attempt to make a little bit of separation between the clusse * code and gdbm, so that it would be a little bit easier to replace * gdbm with something else, some day, when need arises. SQL, anyone? 8-) + * + * At the moment the db_ functions are practically a one-to-one mapping + * to the equal gdbm_ functions, which are documented in gdbm(3). */ #include @@ -47,9 +50,9 @@ hfree(dbp); } -int db_store(struct db_t *dbp, datum key, datum content) +int db_store(struct db_t *dbp, datum key, datum content, int flag) { - return gdbm_store(dbp->f, key, content, GDBM_REPLACE); + return gdbm_store(dbp->f, key, content, flag); } datum db_fetch(struct db_t *dbp, datum key) diff -urN clussed-19981227/db.h clussed-19981228/db.h --- clussed-19981227/db.h Sun Dec 20 18:08:27 1998 +++ clussed-19981228/db.h Sun Dec 27 17:36:55 1998 @@ -4,6 +4,9 @@ #include +#define DB_INSERT GDBM_INSERT +#define DB_REPLACE GDBM_REPLACE + struct db_t { GDBM_FILE f; char *name; @@ -11,7 +14,7 @@ extern struct db_t *db_open(char *name); extern void db_close(struct db_t *dbp); -extern int db_store(struct db_t *dbp, datum key, datum content); +extern int db_store(struct db_t *dbp, datum key, datum content, int flag); extern datum db_fetch(struct db_t *dbp, datum key); extern int db_exists(struct db_t *dbp, datum key); extern int db_delete(struct db_t *dbp, datum key); diff -urN clussed-19981227/f_luser.c clussed-19981228/f_luser.c --- clussed-19981227/f_luser.c Thu Dec 24 16:12:06 1998 +++ clussed-19981228/f_luser.c Sun Dec 27 17:40:57 1998 @@ -56,7 +56,7 @@ content.dptr = (void *)fp; content.dsize = sizeof(struct luserf_t); - db_store(luser_db, key, content); + db_store(luser_db, key, content, DB_REPLACE); } /* diff -urN clussed-19981227/f_mid.c clussed-19981228/f_mid.c --- clussed-19981227/f_mid.c Thu Jan 1 02:00:00 1970 +++ clussed-19981228/f_mid.c Mon Dec 28 03:33:41 1998 @@ -0,0 +1,52 @@ + +#include "f_mid.h" +#include "log.h" +#include "db.h" +#include "config.h" +#include "hmalloc.h" +#include "timer.h" + +struct db_t *mid_db = NULL; + +/* + * Insert a new mid in database. If it exists already, return 0, + * if it doesn't, return 1. + */ + +int new_mid(mid_t *mid) +{ + datum key, content; + + key.dptr = (void *)mid; + key.dsize = sizeof(mid_t); + + content.dptr = (void *)&now; + content.dsize = sizeof(time_t); + + return !(db_store(mid_db, key, content, DB_INSERT)); +} + +/* + * Open mid file + */ + +int open_midf(void) +{ + mid_db = db_open(mid_f); + if (!mid_db) { + log(L_CRIT, "open_midf(): db_open() failed for %s, abandon ship.", mid_f); + exit(1); + } + return 0; +} + +/* + * Close mid file + */ + +int close_midf(void) +{ + db_close(mid_db); + return 0; +} + diff -urN clussed-19981227/f_mid.h clussed-19981228/f_mid.h --- clussed-19981227/f_mid.h Thu Jan 1 02:00:00 1970 +++ clussed-19981228/f_mid.h Sun Dec 27 17:51:35 1998 @@ -0,0 +1,18 @@ + +#ifndef F_MID_H +#define F_MID_H + +#define MID_LEN 15 + +#define MIDT_DX (char)1 +#define MIDT_WWV (char)2 +#define MIDT_ANN (char)3 +#define MIDT_TALK (char)4 + +typedef char mid_t[MID_LEN]; + +extern int new_mid(mid_t *mid); +extern int open_midf(void); +extern int close_midf(void); + +#endif diff -urN clussed-19981227/f_nuser.c clussed-19981228/f_nuser.c --- clussed-19981227/f_nuser.c Thu Dec 24 16:13:02 1998 +++ clussed-19981228/f_nuser.c Sun Dec 27 17:42:40 1998 @@ -56,7 +56,7 @@ content.dptr = (void *)fp; content.dsize = sizeof(struct nuserf_t); - db_store(nuser_db, key, content); + db_store(nuser_db, key, content, DB_REPLACE); } /* diff -urN clussed-19981227/login.c clussed-19981228/login.c --- clussed-19981227/login.c Sun Dec 20 18:08:27 1998 +++ clussed-19981228/login.c Sun Dec 27 18:52:04 1998 @@ -98,7 +98,7 @@ hstrupr(p); - if (valid_call((call_t *)p) == -1) { + if (!valid_call((call_t *)p)) { csprintf(s, "Invalid callsign.\n"); return login_failed(s); } diff -urN clussed-19981227/mid.c clussed-19981228/mid.c --- clussed-19981227/mid.c Sun Dec 20 18:08:27 1998 +++ clussed-19981228/mid.c Thu Jan 1 02:00:00 1970 @@ -1,8 +0,0 @@ - -#include "mid.h" - -int new_mid(mid_t *mid) -{ - return 1; -} - diff -urN clussed-19981227/mid.h clussed-19981228/mid.h --- clussed-19981227/mid.h Sun Dec 20 18:08:27 1998 +++ clussed-19981228/mid.h Thu Jan 1 02:00:00 1970 @@ -1,14 +0,0 @@ - -#ifndef MID_H -#define MID_H - -#define MID_LEN 15 - -#define MIDT_DX 1 -#define MIDT_WWV 2 - -typedef char mid_t[MID_LEN]; - -extern int new_mid(mid_t *mid); - -#endif diff -urN clussed-19981227/net_pc.c clussed-19981228/net_pc.c --- clussed-19981227/net_pc.c Sat Dec 26 19:51:45 1998 +++ clussed-19981228/net_pc.c Mon Dec 28 03:12:04 1998 @@ -19,6 +19,7 @@ #include "hmalloc.h" #include "timer.h" #include "ctime.h" +#include "cstring.h" int pc_10(struct link_t *l, int argc, char **argv); int pc_11(struct link_t *l, int argc, char **argv); @@ -169,34 +170,40 @@ { struct node_t *p; char s[PCMAXLEN]; - int i; - int chosen; + int i = 0; + int chosen = -1; clear_nlocks(); - pc_send(l, "PC19^0^%s^0^%d^H99^\n", l->mycall, pc_version); + strcpy(s, "PC19"); + for (p = n; (p); p = p->next) + if (p == localnode) { + add_node_str(s + strlen(s), p); + i++; + chosen = 0; + } + while (1) { - strcpy(s, "PC19"); - i = 0; - chosen = 0; p = n; while (p) { - if ((chosen && p->via != l && p->hops_ok && p->hops == chosen && !p->locked) - || (!chosen && p->via != l && p->hops_ok && !p->locked && p->hops < 99 && p->hops > 0)) { - if (!chosen) + if ((chosen != -1 && p->via != l && p->hops_ok && p->hops == chosen && !p->locked) + || (chosen == -1 && p->via != l && p->hops_ok && !p->locked && p->hops < 99 && p->hops > 0)) { + if (chosen == -1) chosen = p->hops; add_node_str(s + strlen(s), p); i++; } if (strlen(s) > PCMAXLEN - 30 || (!p->next && (i))) { - sprintf(s + strlen(s), "^%s\n", hops2pcstr(chosen)); + sprintf(s + strlen(s), "^%s^\n", hops2pcstr(chosen)); pc_send(l, "%s", s); i = 0; strcpy(s, "PC19"); } p = p->next; } - if (!chosen) + if (chosen == -1) return; + chosen = -1; + i = 0; } } @@ -299,24 +306,40 @@ if (dx->hops <= 98) pc_sendall(dx->via, "PC11^%s^%s^%s^%s^%s^%s^%s^%s^~\n", freq2str(dx->freq), dx->call, pcdatestr(dx->time), - pctimestr(dx->time), dx->info, dx->fromcall, dx->fromnodec, hops2pcstr(dx->hops)); + pctimestr(dx->time), + (*dx->info) ? dx->info : " ", + dx->fromcall, dx->fromnodec, hops2pcstr(dx->hops)); } void pc_announce(struct ann_t *ann) { + struct node_t *n; int c = '\0'; + + if (ann->hops > 98) + return; + + if ((n = get_node((call_t *)ann->tonodec)) == localnode) + return; + if (strlen(ann->message) > 190) { c = ann->message[189]; ann->message[189] = '\0'; } - if (ann->hops <= 98) + if (n) + pc_send(n->via, "PC12^%s^%s^%s^%s^%s^%s^%s^~\n", + ann->fromcall, ann->tonodec, + (*ann->message) ? ann->message : " ", + (ann->sysop) ? "*" : " ", ann->fromnodec, + (ann->wx) ? "1" : "0", hops2pcstr(ann->hops)); + else if (*ann->tonodec == '*') pc_sendall(ann->via, "PC12^%s^%s^%s^%s^%s^%s^%s^~\n", ann->fromcall, ann->tonodec, (*ann->message) ? ann->message : " ", (ann->sysop) ? "*" : " ", ann->fromnodec, (ann->wx) ? "1" : "0", hops2pcstr(ann->hops)); - + if (c) ann->message[189] = c; } @@ -357,15 +380,16 @@ { int ct = 0; - while (ct < 255) - { - if (*cmd == 0) + while (ct < 255) { + if (!*cmd) break; argv[ct++] = cmd; while (*cmd && *cmd != '^') cmd++; if (*cmd) *cmd++ = 0; + if (*cmd && *cmd == '~') + *cmd++ = 0; } argv[ct] = NULL; return ct; @@ -475,13 +499,13 @@ struct talk_t t; struct nuser_t *nu; - if (argc != 8) - return invalid_argc(l, 8, argc, argv); + if (argc != 7) + return invalid_argc(l, 7, argc, argv); - strncpy(t.fromcall, argv[1], sizeof(call_t)); - strncpy(t.tocall, argv[2], sizeof(call_t)); - strncpy(t.message, argv[3], sizeof(t.message)); - strncpy(t.fromnodec, argv[6], sizeof(call_t)); + hstrncpy(t.fromcall, argv[1], sizeof(call_t)); + hstrncpy(t.tocall, argv[2], sizeof(call_t)); + hstrncpy(t.message, argv[3], sizeof(t.message)); + hstrncpy(t.fromnodec, argv[6], sizeof(call_t)); t.via = l; t.time = now; @@ -490,7 +514,7 @@ else { t.tonode = get_node(&t.tocall); if (*argv[5] != ' ') - strncpy(t.tocall, argv[5], sizeof(call_t)); + hstrncpy(t.tocall, argv[5], sizeof(call_t)); } if (!t.tonode) @@ -511,11 +535,11 @@ d = hmalloc(sizeof(struct dx_t)); d->freq = str2freq(argv[1]); - strncpy(d->call, argv[2], sizeof(d->call)); + hstrncpy(d->call, argv[2], sizeof(d->call)); d->time = pcstr2t(argv[3], argv[4]); - strncpy(d->info, argv[5], sizeof(d->info)); - strncpy(d->fromcall, argv[6], sizeof(call_t)); - strncpy(d->fromnodec, argv[7], sizeof(call_t)); + hstrncpy(d->info, argv[5], sizeof(d->info)); + hstrncpy(d->fromcall, argv[6], sizeof(call_t)); + hstrncpy(d->fromnodec, argv[7], sizeof(call_t)); d->hops = pchops2int(argv[8]); d->via = l; @@ -528,16 +552,16 @@ { struct ann_t *a; - if (argc != 9) - return invalid_argc(l, 9, argc, argv); + if (argc != 8) + return invalid_argc(l, 8, argc, argv); a = hmalloc(sizeof(struct ann_t)); - strncpy(a->fromcall, argv[1], sizeof(call_t)); - strncpy(a->tonodec, argv[2], sizeof(call_t)); - strncpy(a->message, argv[3], sizeof(a->message)); + hstrncpy(a->fromcall, argv[1], sizeof(call_t)); + hstrncpy(a->tonodec, argv[2], sizeof(call_t)); + hstrncpy(a->message, argv[3], sizeof(a->message)); a->sysop = (*argv[4] == '*'); - strncpy(a->fromnodec, argv[5], sizeof(call_t)); + hstrncpy(a->fromnodec, argv[5], sizeof(call_t)); a->wx = (*argv[6] == '1'); a->hops = pchops2int(argv[7]); a->time = now; @@ -575,7 +599,7 @@ nu->prevp = prevp; prevp = &nu->next; nu->next = NULL; - strncpy(nu->call, argv[i], sizeof(nu->call)); + hstrncpy(nu->call, argv[i], sizeof(nu->call)); nu->here = (*hr == '1'); nu->since = now; nu->name[0] = '\0'; @@ -611,8 +635,8 @@ /* Request link init */ int pc_18(struct link_t *l, int argc, char **argv) { - if (argc != 4) - return invalid_argc(l, 4, argc, argv); + if (argc != 3) + return invalid_argc(l, 3, argc, argv); log(L_LINK, "PC: %s: requests link initialisation, sending tables", l->name); l->version = atoi(argv[2]); @@ -642,13 +666,13 @@ n->prevp = prevp; prevp = &n->next; n->next = NULL; - strncpy(n->call, argv[i+1], sizeof(n->call)); + hstrncpy(n->call, argv[i+1], sizeof(n->call)); n->here = (*argv[i] == '1'); n->version = atoi(argv[i+3]); n->via = l; n->since = now; n->hops = hops; - n->hops_ok = 0; + n->hops_ok = 1; n->users_ok = 1; n->users_known = 0; n->users = 0; @@ -710,8 +734,8 @@ struct wwv_t *w; struct tm *tm; - if (argc != 11) - return invalid_argc(l, 11, argc, argv); + if (argc != 10) + return invalid_argc(l, 10, argc, argv); w = hmalloc(sizeof(struct wwv_t)); @@ -721,9 +745,9 @@ w->sfi = atoi(argv[3]); w->a = atoi(argv[4]); w->k = atoi(argv[5]); - strncpy(w->forecast, argv[6], sizeof(w->forecast)); - strncpy(w->fromcall, argv[7], sizeof(call_t)); - strncpy(w->fromnodec, argv[8], sizeof(call_t)); + hstrncpy(w->forecast, argv[6], sizeof(w->forecast)); + hstrncpy(w->fromcall, argv[7], sizeof(call_t)); + hstrncpy(w->fromnodec, argv[8], sizeof(call_t)); w->via = l; w->hops = pchops2int(argv[9]); @@ -737,8 +761,8 @@ { char *p, *p2; - if (argc != 3) - return invalid_argc(l, 3, argc, argv); + if (argc != 2) + return invalid_argc(l, 2, argc, argv); p2 = p = argv[1]; while (p) { diff -urN clussed-19981227/net_user.c clussed-19981228/net_user.c --- clussed-19981227/net_user.c Fri Dec 25 22:14:48 1998 +++ clussed-19981228/net_user.c Sun Dec 27 18:52:24 1998 @@ -234,7 +234,7 @@ while (p) { next = p->next; - if (get_nuserh(&p->call, p->node) || (valid_call(&p->call) == -1)) { + if (get_nuserh(&p->call, p->node) || (!valid_call(&p->call))) { if (p->next) p->next->prevp = p->prevp; *p->prevp = p->next; diff -urN clussed-19981227/network.c clussed-19981228/network.c --- clussed-19981227/network.c Sun Dec 27 03:11:27 1998 +++ clussed-19981228/network.c Mon Dec 28 03:37:49 1998 @@ -23,7 +23,7 @@ #include "ctime.h" #include "timer.h" #include "log.h" -#include "mid.h" +#include "f_mid.h" #include "crc.h" #include "linker.h" #include "version.h" @@ -527,7 +527,7 @@ * Process a talk message */ -void net_talk(struct talk_t *t) +int net_talk(struct talk_t *t) { struct luser_t *p; struct nuser_t *u; @@ -540,43 +540,45 @@ if (t->tonode != localnode) { /* Route the message */ link_talk(t); - return; + return 0; } if (!strcmp(t->tocall, (char *)clucall)) { /* Is this a message to the local node itself */ talk_tonode(t); - return; + return 0; } if ((p = get_luser(&t->tocall))) { /* The user is logged on */ if ((!p->f || ((p->f->messages & M_TALK) == M_TALK)) && !p->locked) { /* Does he accept talk messages */ talk_touser(p, t); - return; + return 0; } if (p->locked) sprintf(nt.message, "User %s is not able to talk right now.", t->tocall); else sprintf(nt.message, "User %s has disabled talk messages.", t->tocall); talk_back(0, t, &nt); - return; + return 0; } if (!strcmp(t->tocall, (char *)&clucall) && !strcmp(t->fromcall, (char *)&clucall)) /* Catch a local loop (would cause a stack overflow) */ - return; + return -1; u = get_nuser(&t->tocall); if ((u) && (u->node->via != t->via)) { /* Never route back, might loop */ /* Forward the message to another cluster node (should check for loops!) */ t->tonode = u->node; link_talk(t); - return; + return 0; } if (get_node(&t->fromcall) == NULL) { /* User is not on the node table */ sprintf(nt.message, "User or node %s is not known here.", t->tocall); talk_back(0, t, &nt); } + + return 0; } @@ -586,59 +588,77 @@ * DX */ -void net_dx(struct dx_t *dx) +int net_dx(struct dx_t *d) { mid_t mid; unsigned short w; + int i = 0; /* Dupe checking */ memset(&mid, 0, MID_LEN); - mid[0] = (char)MIDT_DX; + mid[0] = MIDT_DX; w = CRC16_SEED; - ccrc16l(dx->call, strlen(dx->call), &w); + ccrc16l(d->call, strlen(d->call), &w); memmove(&mid[1], &w, sizeof(w)); - memmove(&mid[3], &dx->time, sizeof(dx->time)); - memmove(&mid[3 + sizeof(dx->time)], &dx->freq, sizeof(dx->freq)); + memmove(&mid[3], &d->time, sizeof(d->time)); + memmove(&mid[3 + sizeof(d->time)], &d->freq, sizeof(d->freq)); - if (dx->freq > 0 && valid_call(&dx->fromcall) && - valid_call(&dx->fromnodec) && new_mid(&mid)) { - indexes.dx++; - if (indexes.dx >= 10000) /* Wraparound */ - indexes.dx = 1; - dx->num = indexes.dx; - - log(L_DX, "DX de %s: %s %s \"%s\"", - dx->fromcall, freq2str(dx->freq), dx->call, - dx->info); - - ui_dx(dx); /* Broadcast */ - user_dx(dx); /* Notify the local users */ - if (!listened) /* Route */ - link_dx(dx); + if (d->freq <= 0) { + i = -2; + goto trouble; + } - write_dx(dx); /* Write to file */ - set_homenode(NULL, &dx->fromcall, &dx->fromnodec, 2); - free(dx); + if (!valid_call(&d->fromcall) + || !valid_call(&d->fromnodec)) { + i = -3; + goto trouble; + } + + if (!new_mid(&mid)) { + i = -1; + goto trouble; } + + indexes.dx++; + if (indexes.dx >= 10000) /* Wraparound */ + indexes.dx = 1; + d->num = indexes.dx; + + log(L_DX, "DX de %s: %s %s %sZ %s", + d->fromcall, freq2str(d->freq), d->call, + timestr_s(d->time), d->info); + + ui_dx(d); /* Broadcast */ + user_dx(d); /* Notify the local users */ + if (!listened) /* Route */ + link_dx(d); + + write_dx(d); /* Write to file */ + set_homenode(NULL, &d->fromcall, &d->fromnodec, 2); + +trouble: + free(d); + return i; } -/* ====================================================================== */ - -void net_announce(struct ann_t *ann) +/* + * Announcement + */ + +int net_announce(struct ann_t *ann) { - if (valid_call(&ann->fromcall) && valid_call(&ann->fromnodec)) { indexes.ann++; if (indexes.ann >= 10000) indexes.ann = 1; ann->num = indexes.ann; - log(L_ANN, "%s shouts @%s: %s", ann->fromcall, ann->tonodec, + log(L_ANN, "Ann: %s shouts @%s: %s", ann->fromcall, ann->tonodec, ann->message); - if (!strcmp(ann->tonodec, "*") || !strcmp(ann->tonodec, (char *)&clucall)) { + if (!strcmp(ann->tonodec, "*") || !strcmp(ann->tonodec, (char *)clucall)) { user_announce(ann); /* Notify local users */ if (!(ann->wx || ann->sysop)) { ui_ann(ann); /* Broadcast */ @@ -649,19 +669,23 @@ link_announce(ann); set_homenode(NULL, &ann->fromcall, &ann->fromnodec, 2); } + free(ann); + return 0; } -/* ====================================================================== */ - -void net_wwv(struct wwv_t *wwv) +/* + * WWV + */ + +int net_wwv(struct wwv_t *wwv) { mid_t mid; struct tm *tm; /* Dupe checking */ memset(&mid, 0, MID_LEN); - mid[0] = (char)MIDT_WWV; + mid[0] = MIDT_WWV; tm = gmtime(&wwv->time); @@ -672,9 +696,9 @@ if (!new_mid(&mid)) { free(wwv); - return; + return -1; } - + indexes.wwv++; if (indexes.wwv >= 10000) indexes.wwv = 1; @@ -691,6 +715,7 @@ set_homenode(NULL, &wwv->fromcall, &wwv->fromnodec, 2); free(wwv); + return 0; } diff -urN clussed-19981227/network.h clussed-19981228/network.h --- clussed-19981227/network.h Sat Dec 26 15:17:05 1998 +++ clussed-19981228/network.h Sun Dec 27 19:14:43 1998 @@ -219,10 +219,10 @@ extern void link_logout(struct csock_t *sock); /* Cluster events */ -extern void net_dx(struct dx_t *dx); /* DX */ -extern void net_announce(struct ann_t *ann); /* Announce */ -extern void net_talk(struct talk_t *talk); /* Talk */ -extern void net_wwv(struct wwv_t *wwv); /* WWV */ +extern int net_dx(struct dx_t *dx); /* DX */ +extern int net_announce(struct ann_t *ann); /* Announce */ +extern int net_talk(struct talk_t *talk); /* Talk */ +extern int net_wwv(struct wwv_t *wwv); /* WWV */ /* Node list handling */ extern void net_nodeadd(struct node_t *n); /* Add cluster node */