From 79ba3b3c478aef78b7a4005ae3deb7f1484e1a1e Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Fri, 15 Apr 2005 21:36:44 +0000 Subject: [PATCH] Added basic irc ideas --- configure | 14 +++++ configure.in | 8 +-- lib/mbselib.h | 26 +++++++++ mbtask/Makefile | 11 ++-- mbtask/mbtask.c | 24 ++++++-- mbtask/ping.c | 3 - mbtask/taskchat.c | 7 ++- mbtask/taskirc.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++ mbtask/taskirc.h | 11 ++++ 9 files changed, 223 insertions(+), 17 deletions(-) create mode 100644 mbtask/taskirc.c create mode 100644 mbtask/taskirc.h diff --git a/configure b/configure index 4c303383..2657ae50 100755 --- a/configure +++ b/configure @@ -841,6 +841,7 @@ if test -n "$ac_init_help"; then Optional Features: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-experiment Compile experimental code --enable-debugging Compile for debugging --enable-optimize Enable CPU optimize --enable-newsgate Compile with newsgate @@ -2989,6 +2990,19 @@ esac +# Check whether --enable-experiment or --disable-experiment was given. +if test "${enable_experiment+set}" = set; then + enableval="$enable_experiment" + experiment=$enableval +else + experiment=no +fi; +if test "$experiment" = "yes"; then + cat >>confdefs.h <<\_ACEOF +#define USE_EXPERIMENT 1 +_ACEOF + +fi # Check whether --enable-debugging or --disable-debugging was given. if test "${enable_debugging+set}" = set; then diff --git a/configure.in b/configure.in index 93f51d79..3dc1e819 100644 --- a/configure.in +++ b/configure.in @@ -67,10 +67,10 @@ AC_C_BIGENDIAN dnl dnl Additional commandline switches dnl -dnl AC_ARG_ENABLE(experiment, [ --enable-experiment Compile experimental code], [ experiment=$enableval ], [ experiment=no ]) -dnl if test "$experiment" = "yes"; then -dnl AC_DEFINE(USE_EXPERIMENT) -dnl fi +AC_ARG_ENABLE(experiment, [ --enable-experiment Compile experimental code], [ experiment=$enableval ], [ experiment=no ]) +if test "$experiment" = "yes"; then + AC_DEFINE(USE_EXPERIMENT) +fi AC_ARG_ENABLE(debugging, [ --enable-debugging Compile for debugging], [ debugging=$enableval ], [ debugging=no ]) if test "$debugging" = "yes"; then diff --git a/lib/mbselib.h b/lib/mbselib.h index 7db8e1b0..b2978c62 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -2029,6 +2029,27 @@ struct _route { +/* + * IRC servers to connect to. + */ +#ifdef USE_EXPERIMENT +struct _ircsrvhdr { + long hdrsize; /* Size of header */ + long recsize; /* Size of record */ +}; + + +struct _ircsrv { + char server[64]; /* Peer server name */ + char passwd[16]; /* Password */ + unsigned Active : 1; /* Is server active */ + unsigned Deleted : 1; /* Must server be deleted */ + unsigned Compress : 1; /* Use compresssion */ +}; +#endif + + + /* * From clcomm.c */ @@ -2642,5 +2663,10 @@ struct _scanmgr scanmgr; struct _routehdr routehdr; /* Routing file */ struct _route route; +#ifdef USE_EXPERIMENT +struct _ircsrvhdr ircsrvhdr; /* IRC servers */ +struct _ircsrv ircsrv; +#endif + #endif diff --git a/mbtask/Makefile b/mbtask/Makefile index 42a2d96b..dfbfa8b0 100644 --- a/mbtask/Makefile +++ b/mbtask/Makefile @@ -4,13 +4,13 @@ include ../Makefile.global -SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c \ +SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c taskirc.c \ mbtask.c outstat.c signame.c taskdisk.c taskregs.c taskutil.c \ ports.c calllist.c ping.c taskchat.c crc.c HDRS = callstat.h mbtask.h outstat.h signame.h taskdisk.h taskregs.h taskutil.h \ - scanout.h taskcomm.h taskinfo.h taskstat.h \ + scanout.h taskcomm.h taskinfo.h taskstat.h taskirc.h \ ports.h calllist.h ping.h taskchat.h -OBJS = callstat.o scanout.o taskcomm.o taskinfo.o taskstat.o \ +OBJS = callstat.o scanout.o taskcomm.o taskinfo.o taskstat.o taskirc.o \ mbtask.o outstat.o signame.o taskdisk.o taskregs.o taskutil.o \ ports.o calllist.o ping.o taskchat.o crc.o SLIBS = ../lib/libnodelist.a @@ -73,7 +73,8 @@ scanout.o: ../config.h ../lib/mbselib.h taskutil.h scanout.h taskcomm.o: ../config.h ../lib/mbselib.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskchat.h taskcomm.h taskinfo.o: ../config.h ../lib/mbselib.h taskinfo.h taskstat.o: ../config.h ../lib/mbselib.h taskstat.h callstat.h outstat.h taskutil.h -mbtask.o: ../config.h ../lib/mbselib.h ../paths.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h taskdisk.h callstat.h outstat.h ../lib/nodelist.h ports.h calllist.h ping.h taskchat.h mbtask.h +taskirc.o: ../config.h ../lib/mbselib.h taskirc.h +mbtask.o: ../config.h ../lib/mbselib.h ../paths.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h taskdisk.h taskirc.h callstat.h outstat.h ../lib/nodelist.h ports.h calllist.h ping.h taskchat.h mbtask.h outstat.o: ../config.h ../lib/mbselib.h taskutil.h taskstat.h scanout.h ../lib/nodelist.h callstat.h ports.h outstat.h signame.o: ../config.h signame.h taskdisk.o: ../config.h ../lib/mbselib.h taskdisk.h taskutil.h @@ -82,6 +83,6 @@ taskutil.o: ../config.h ../lib/mbselib.h signame.h scanout.h taskutil.h ports.o: ../config.h ../lib/mbselib.h taskutil.h ../lib/nodelist.h ports.h calllist.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h callstat.h outstat.h mbtask.h calllist.h ping.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h ping.h -taskchat.o: ../config.h ../lib/mbselib.h taskutil.h taskregs.h taskchat.h +taskchat.o: ../config.h ../lib/mbselib.h taskutil.h taskregs.h taskchat.h taskirc.h crc.o: ../config.h ../lib/mbselib.h # End of generated dependencies diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index 7285204e..60cf3c05 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -37,6 +37,7 @@ #include "taskregs.h" #include "taskcomm.h" #include "taskdisk.h" +#include "taskirc.h" #include "callstat.h" #include "outstat.h" #include "../lib/nodelist.h" @@ -47,8 +48,6 @@ #include "mbtask.h" -#define NUM_THREADS 4 /* Max. nr of threads */ - /* * Global variables @@ -116,7 +115,9 @@ extern int cmd_run; /* Cmd running */ extern int ping_run; /* Ping running */ int sched_run = FALSE; /* Scheduler running */ extern int disk_run; /* Disk watch running */ - +#ifdef USE_EXPERIMENT +extern int irc_run; /* IRC thread running */ +#endif /* @@ -126,7 +127,9 @@ pthread_t pt_ping; pthread_t pt_command; pthread_t pt_disk; pthread_t pt_scheduler; -// pthread_t p_thread[NUM_THREADS]; /* thread's structure */ +#ifdef USE_EXPERIMENT +pthread_t pt_irc; +#endif @@ -742,10 +745,18 @@ void die(int onsig) * build to stop within a second. */ now = time(NULL) + 2; +#ifdef USE_EXPERIMENT + while ((cmd_run || ping_run || sched_run || disk_run || irc_run) && (time(NULL) < now)) { +#else while ((cmd_run || ping_run || sched_run || disk_run) && (time(NULL) < now)) { +#endif sleep(1); } +#ifdef USE_EXPERIMENT + if (cmd_run || ping_run || sched_run || disk_run || irc_run) +#else if (cmd_run || ping_run || sched_run || disk_run) +#endif Syslog('+', "Not all threads stopped! Forced shutdown"); else Syslog('+', "All threads stopped"); @@ -1036,6 +1047,11 @@ void start_scheduler(void) } else if ((rc = pthread_create(&pt_scheduler, NULL, (void (*))scheduler, NULL))) { WriteError("$pthread_create scheduler rc=%d", rc); die(SIGTERM); +#ifdef USE_EXPERIMENT + } else if ((rc = pthread_create(&pt_irc, NULL, (void (*))irc_thread, NULL))) { + WriteError("$pthread_create irc rc=%d", rc); + die(SIGTERM); +#endif } else { Syslog('+', "All threads installed"); } diff --git a/mbtask/ping.c b/mbtask/ping.c index 305bd20f..539766ad 100644 --- a/mbtask/ping.c +++ b/mbtask/ping.c @@ -347,9 +347,6 @@ printf("Start ping thread\n"); while (! T_Shutdown) { -#ifdef USE_EXPERMIMENT - Syslog('p', "ping_thread loop start"); -#endif /* * Select new address to ping */ diff --git a/mbtask/taskchat.c b/mbtask/taskchat.c index 9870d18e..c5941b1b 100644 --- a/mbtask/taskchat.c +++ b/mbtask/taskchat.c @@ -33,6 +33,8 @@ #include "taskutil.h" #include "taskregs.h" #include "taskchat.h" +#include "taskirc.h" + #define MAXCHANNELS 10 /* Maximum chat channels */ #define MAXMESSAGES 100 /* Maximum ringbuffer for messages */ @@ -123,7 +125,6 @@ int part(pid_t, char*); - void chat_dump(void) { int i, first; @@ -371,6 +372,10 @@ void chat_msg(int channel, char *nick, char *msg) system_msg(chat_users[i].pid, buf); } } + +#ifdef USE_EXPERIMENT + send_all(buf); +#endif } diff --git a/mbtask/taskirc.c b/mbtask/taskirc.c new file mode 100644 index 00000000..a1cd6a4a --- /dev/null +++ b/mbtask/taskirc.c @@ -0,0 +1,136 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: mbtask - Internet Realy Chat (sort of) + * + ***************************************************************************** + * Copyright (C) 1997-2005 + * + * Michiel Broek FIDO: 2:280/2802 + * Beekmansbos 10 + * 1971 BV IJmuiden + * the Netherlands + * + * This file is part of MBSE BBS. + * + * This BBS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * MBSE BBS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MBSE BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + *****************************************************************************/ + +#include "../config.h" +#include "../lib/mbselib.h" +#include "taskirc.h" + + + +#ifdef USE_EXPERIMENT + +int irc_run = FALSE; /* Thread running */ +extern int T_Shutdown; /* Program shutdown */ + + + +/* + * Send a UDP message to one other server. + */ +void send_server(char *name, char *msg) +{ + int a1, a2, a3, a4; + int s; /* Socket */ + struct hostent *he; /* Host info */ + struct servent *se; /* Service information */ + struct sockaddr_in server; /* Destination address */ + char *errmsg; + + /* + * Get IP address for the hostname + */ + if (sscanf(name,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) == 4) + server.sin_addr.s_addr = inet_addr(name); + else if ((he = gethostbyname(name))) + memcpy(&server.sin_addr,he->h_addr,he->h_length); + else { + switch (h_errno) { + case HOST_NOT_FOUND: errmsg = (char *)"Authoritative: Host not found"; break; + case TRY_AGAIN: errmsg = (char *)"Non-Authoritive: Host not found"; break; + case NO_RECOVERY: errmsg = (char *)"Non recoverable errors"; break; + default: errmsg = (char *)"Unknown error"; break; + } + Syslog('+', "No IP address for %s: %s", name, errmsg); + return; + } + + se = getservbyname("fido", "udp"); + if (se == NULL) { + Syslog('n', "Service fido udp not in /etc/services"); + return; + } + + server.sin_family = AF_INET; + server.sin_port = se->s_port; + + Syslog('r', "Send to %s, port %d\n", inet_ntoa(server.sin_addr), ntohs(server.sin_port)); + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) { + Syslog('r', "$Can't create socket"); + return; + } + + if (bind(s, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) == -1) { + Syslog('r', "$Can't bind socket"); + return; + } + + if (sendto(s, msg, strlen(msg), 0, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) == -1) { + Syslog('r', "$Can't send message"); + return; + } +} + + + +/* + * Send a message to all servers + */ +void send_all(char *msg) +{ + send_server((char *)"router.mbse.ym", msg); + send_server((char *)"hppa.mbse.ym", msg); +} + + + +/* + * IRC thread + */ +void *irc_thread(void *dummy) +{ + Syslog('+', "Starting IRC thread"); + irc_run = TRUE; + + while (! T_Shutdown) { + sleep(1); + } + + irc_run = FALSE; + Syslog('+', "IRC thread stopped"); + pthread_exit(NULL); +} + + + +#endif + + diff --git a/mbtask/taskirc.h b/mbtask/taskirc.h new file mode 100644 index 00000000..c2b65b3b --- /dev/null +++ b/mbtask/taskirc.h @@ -0,0 +1,11 @@ +#ifndef _TASKIRC_H +#define _TASKIRC_H + +/* $Id$ */ + +#ifdef USE_EXPERIMENT +void send_all(char *); +void *irc_thread(void *); +#endif + +#endif