/* Various length constants */
-#define UGLISTLEN 100 /* you get a ungoto list of this size */
#define ROOMNAMELEN 128 /* The size of a roomname string */
-#define NONCE_SIZE 128 /* Added by <bc> to allow for APOP auth
- * it is BIG becuase there is a hostname
- * in the nonce, as per the APOP RFC.
- */
#define USERNAME_SIZE 64 /* The size of a username string */
#define MAX_EDITORS 5 /* # of external editors supported */
#define NEWREGISTER 0 /* new user to register */
#define REREGISTER 1 /* existing user reregistering */
-#define READ_HEADER 2
-#define READ_MSGBODY 3
-
-/* commands we can send to the stty_ctdl() routine */
-#define SB_NO_INTR 0 /* set to Citadel client mode, i/q disabled */
-#define SB_YES_INTR 1 /* set to Citadel client mode, i/q enabled */
-#define SB_SAVE 2 /* save settings */
-#define SB_RESTORE 3 /* restore settings */
-#define SB_LAST 4 /* redo the last command sent */
-
-#define NEXT_KEY 15
-#define STOP_KEY 3
-
-/* citadel.rc stuff */
-#define RC_NO 0 /* always no */
-#define RC_YES 1 /* always yes */
-#define RC_DEFAULT 2 /* setting depends on user config */
-
-/* keepalives */
-enum {
- KA_NO, /* no keepalives */
- KA_YES, /* full keepalives */
- KA_HALF /* half keepalives */
-};
-
-/* for <;G>oto and <;S>kip commands */
-#define GF_GOTO 0 /* <;G>oto floor mode */
-#define GF_SKIP 1 /* <;S>kip floor mode */
-#define GF_ZAP 2 /* <;Z>ap floor mode */
-
/* number of items which may be handled by the CONF command */
#define NUM_CONFIGS 70
-/*
- * MIME types used in Citadel for configuration stuff
- */
-#define SPOOLMIME "application/x-citadel-delivery-list"
-#define INTERNETCFG "application/x-citadel-internet-config"
-#define IGNETCFG "application/x-citadel-ignet-config"
-#define IGNETMAP "application/x-citadel-ignet-map"
-#define FILTERLIST "application/x-citadel-filter-list"
-#define SIEVECONFIG "application/x-citadel-sieve-config"
-#define XMPPMORTUARY "application/x-citadel-xmpp-mortuary"
-
#define TRACE syslog(LOG_DEBUG, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
#ifndef LONG_MAX
+++ /dev/null
-#
-# This file allows full customization of the user interface.
-#
-# The standard client looks for this file in:
-# 1. $HOME/.citadelrc
-# 2. <compiled CTDLDIR>/citadel.rc
-# 3. /etc/citadel.rc
-# 4. <current directory>/citadel.rc
-
-# Set ENCRYPT to yes to force SSL/TLS encryption when connecting to a
-# Citadel server, even if the server is on the same machine as the
-# client. Set it to no to disable SSL/TLS encryption. The default is to
-# enable encryption for remote systems and to disable encryption for
-# systems on the same machine as the client.
-encrypt=default
-
-# Set EDITOR to the name of an external editor to be used for entering
-# messages. If you want the external editor to be used by default, be sure
-# to reflect this in the command set below.
-#
-# editor=vi
-
-# If you define PRINTCMD, it will be a pipe through which messages are
-# printed when the user hits the <P>rint key after a message.
-#
-#printcmd=lpr
-
-# If you define EXPCMD, it will be a pipe through which any incoming
-# instant messages will be printed.
-#expcmd=xmessage -title "Instant message" -center -buttons OK -file -
-
-# ANSI_COLOR should be set to on/off/auto/user to control the use of
-# color on the screen. If it is set to "auto" then an autodetect will be
-# attempted. If it is set to "user" then it's a user-configurable option.
-#
-ansi_color=user
-
-# USE_BACKGROUND controls Citadel's use of the background. If it is turned
-# off, then Citadel will set the background to black. When it is turned on,
-# the background will be unchanged. This is most useful with "transparent"
-# terminals. Color must be on (see above) or this option has no effect.
-#
-use_background=off
-
-# STATUS_LINE will keep an informative status line on the top of the screen,
-# but it doesn't work on all terminals (Mac OS is particularly bad at this).
-status_line=off
-
-# PROMPT_CONTROL should be set to on/off/user to control whether the <N>ext
-# and <S>top keys are active when displaying the paginator prompt. If it
-# is set to "user" then it's a user-configurable option.
-#
-prompt_control=user
-
-# If DISPLAY_MESSAGE_NUMBERS is set to 1, then messages will be displayed
-# with their message numbers in the header. This is ugly but some
-# people seem to like it anyway...
-#
-display_message_numbers=0
-
-# The FORCE_MAIL_PROMPTS directive causes mail rooms to always display a
-# prompt after each message, even if the user has prompts turned off.
-#
-force_mail_prompts=1
-
-# USE_FLOORS determines whether the user sees floors, or a flat room space.
-# Set it to YES to always use floors, NO to never use floors, or DEFAULT
-# to use the setting in the user's configuration (which is normally the case).
-#
-use_floors=DEFAULT
-
-# BEEP should be set to 1 if you wish the terminal to beep when an express
-# message (page) comes in, otherwise set it to 0.
-#
-beep=1
-
-# ALLOW_ATTACHMENTS should be set to 1 if you wish the user to be able to
-# attach files to messages and/or save attachments to disk while reading
-# messages. (DANGER: do NOT enable this for "safe" public clients!)
-#
-allow_attachments=0
-
-# IDLE_THRESHOLD is the amount of time a user does nothing before being
-# listed as "idle" on the who list. The default is 900 seconds (15 minutes).
-#
-idle_threshold=900
-
-# If you set REMEMBER_PASSWORDS to 1, the Citadel client will offer to
-# remember your user name and password for every Citadel server you access,
-# automatically logging in with them on subsequent visits.
-# (DANGER: do NOT enable this for "safe" public clients!)
-#
-remember_passwords=0
-
-# Optionally, you can force the same username and password everywhere. This
-# obviously isn't as robust as the password manager.
-#
-#username=My User Name
-#password=mypassword
-
-# If URLCMD is defined, users can hit 'U' after reading a message which
-# contains embedded URL's, and the command will be executed. Usually this
-# will be used to remote-control a web browser. (Do not enable this command
-# for 'safe' public clients.)
-#
-# This one ought to work on any Linux that has the "Portland" API's installed.
-# If properly configured, xdg-open will open the URL in the user's preferred
-# web browser.
-#urlcmd=xdg-open "%s"
-#
-# This one works really well on a Macintosh -- it opens URL's in whatever
-# browser you have configured as the system default.
-#urlcmd=open "%s"
-
-# If OPENCMD is defined, users can hit 'O' after reading a message which
-# contains attachments, to open the attachments using that command. This
-# allows attachments to be opened directly from the Citadel client without
-# having to first save them in a file. The "allow_attachments" option (see
-# above) must be enabled in order for this to work.
-#
-# xdg-open works on most newer Linux systems
-opencmd=xdg-open "%s"
-#
-# This probably will work on a Macintosh
-#opencmd=open "%s"
-
-# If GOTMAILCMD is defined, the specified command will be executed. This
-# might be nice for playing sounds or providing any other type of notification.
-#
-#gotmailcmd=play gotmail.wav
-
-# If IMAGECMD is defined, users can hit 'I' to view images attached to a
-# message. (Do not enable this command for public clients.)
-#
-# Possible image viewers follow
-
-# xdg-open - on Linux systems with the Portland API's installed, this ought
-# to open the image in the user's preferred viewer.
-#imagecmd=xdg-open "%s"
-#
-# Preview on Mac OS X
-#imagecmd=/Applications/Preview.app/Contents/MacOS/Preview "%s"
-
-
-# COMMAND SET CONFIGURATION
-#
-# All lines starting with "cmd=" are considered to be commands. This allows
-# mapping of keytstrokes to various functions of the client.
-#
-# Format of each line:
-# cmd_num,access,keystrokes
-#
-# Keep a copy of the original version of this file around as a reference
-# for the command numbers. They are not documented anywhere else.
-#
-# Access is: 0 (all users), 1 (aides or room aides), 2 (aides only).
-# Please be aware that it is futile to attempt to gain unauthorized access to
-# the administrative functions of the system by changing all the access levels
-# to 0. If you do this, you'll simply be able to enter a lot of commands that
-# will fail at the server ... so don't bother trying. :-)
-#
-# The actual key to be pressed should be prefaced with an & (ampersand)
-# character. Ampersands are interesting and useful characters and you should
-# use them as much as possible. Commands requiring more than one keystroke
-# should be entered as multiple fields.
-#
-# If the last keystroke string ends with a : (colon), then the command
-# will finish by allowing the user to enter a string.
-#
-# In keystroke names, the string ^r will be replaced by the name of the
-# current room. The string ^c will be replaced by a comma.
-#
-# Commands may contain no more than five keystrokes.
-#
-# Note that the following characters are illegal in commands:
-# , (comma) : (colon) ^ (caret) & (ampersand)
-#
-#
-cmd=1,0,&? (Help)
-cmd=1,0,&Help
-cmd=3,0,&Chat
-#
-# If you want to use an external editor by default, set <E>nter message
-# to command #46 (external editor) instead of #4 (built-in editor).
-cmd=4,0,&Enter message
-#
-cmd=5,0,&Goto
-cmd=6,0,&Skip ^r
-cmd=7,0,&Zap (forget) room
-cmd=8,0,&Known rooms
-cmd=9,0,&Last five msgs
-cmd=10,0,read &Forward
-cmd=11,0,read &Reverse
-cmd=12,0,read &Old
-cmd=13,0,read &New
-cmd=14,0,read &Directory
-cmd=15,0,&Terminate
-cmd=16,0,&Ungoto
-cmd=95,0,&.,&Ungoto:
-cmd=17,0,&Who is online
-cmd=47,0,&Abandon ^r^c goto...
-#cmd=90,0,&Abandon ^r^c goto:
-cmd=50,0,toggle e&Xpert mode
-cmd=49,0,read &Info file
-cmd=18,2,&! <shell>
-cmd=19,0,&.,list &Zapped rooms
-cmd=52,0,&.,&Skip ^r^c goto:
-cmd=56,0,&Page a user
-cmd=58,0,&Mail
-cmd=84,0,&Quiet mode
-#
-# We implement both <.G>oto and <J>ump commands which do the same thing, in
-# order to please a wider audience of users. Remove one if you want to.
-#
-cmd=20,0,&Jump:
-cmd=20,0,&.,&Goto:
-#
-cmd=21,0,&.,&Help:
-cmd=22,1,&.,&Aide,&Kill this room
-cmd=23,1,&.,&Aide,&Edit this room
-cmd=24,0,&.,&Aide,&Who knows room
-cmd=25,2,&.,&Aide,&User,&Edit
-cmd=96,2,&.,&Aide,&User,&Delete
-cmd=26,2,&.,&Aide,&Validate new users
-cmd=48,1,&.,&Aide,enter &Info file
-cmd=27,0,&.,&Aide,&Room,&Invite user
-cmd=28,0,&.,&Aide,&Room,&Kick out user
-cmd=51,1,&.,&Aide,&File,&Delete
-cmd=54,1,&.,&Aide,&File,&Move
-cmd=70,2,&.,&Aide,&Message edit:
-cmd=78,1,&.,&Aide,&Post
-cmd=80,2,&.,&Aide,&System configuration,&General
-cmd=82,2,&.,&Aide,&System configuration,&Internet
-cmd=88,2,&.,&Aide,&System configuration,&Network
-cmd=92,2,&.,&Aide,&System configuration,network &Filter list
-cmd=85,2,&.,&Aide,&Terminate server,&Now
-cmd=86,2,&.,&Aide,&Terminate server,&Scheduled
-cmd=87,1,&.,&Aide,mailing &List recipients
-cmd=94,1,&.,&Aide,mailing list &Digest recipients
-cmd=89,1,&.,&Aide,&Network room sharing
-
-cmd=29,0,&.,&Terminate,and &Quit
-cmd=30,0,&.,&Terminate,and &Stay online
-
-# The 'read user listing' command accepts two different formats. The one with
-# the trailing colon allows the user to enter a few characters to search for
-# users with a partial match.
-#
-#cmd=32,0,&.,&Read,&User listing
-cmd=32,0,&.,&Read,&User listing:
-
-cmd=33,0,&.,&Read,&Textfile formatted
-#
-# Command 55 allows the user to save a downloaded file directly to the
-# computer running the client software. It is appropriate for a copy of
-# this client running on the user's own computer. It is NOT appropriate for
-# public copies of the client that people will be dialing into.
-#
-#cmd=55,0,&.,&Read,&File
-#
-# Commands 34, 43, and 45 are appropriate for public copies of the client for
-# dialup use. They transfer downloaded files to a temporary file and then
-# send them along to a dialup user using the popular protocols.
-#
-# cmd=34,0,&.,&Read,file using &Xmodem
-# cmd=43,0,&.,&Read,file using &Ymodem
-# cmd=45,0,&.,&Read,file using &Zmodem
-cmd=31,0,&.,&Read,&File unformatted
-#
-cmd=13,0,&.,&Read,&New messages
-cmd=12,0,&.,&Read,&Old msgs reverse
-cmd=71,0,&.,read &Last:
-cmd=9,0,&.,&Read,&Last five msgs
-cmd=14,0,&.,&Read,&Directory
-cmd=49,0,&.,&Read,&Info file
-cmd=114,0,&.,&Read,&Configuration
-cmd=115,0,&.,&Read,&System info
-cmd=35,0,&.,&Enter,&Password
-cmd=36,0,&.,&Enter,&ASCII message
-cmd=37,0,&.,&Enter,&Configuration
-cmd=38,0,&.,&Enter,a new &Room
-cmd=39,0,&.,&Enter,&Textfile
-cmd=77,0,&.,&Enter,&Username
-# cmd=40,0,&.,&Enter,file using &Xmodem
-# cmd=42,0,&.,&Enter,file using &Ymodem
-# cmd=44,0,&.,&Enter,file using &Zmodem
-#
-# Command 57 is the local-file-upload command for users with their own
-# copy of the clientware. Commands 72-74 are for image uploads.
-#
-#cmd=57,0,&.,&Enter,&File
-#cmd=72,0,&.,&Enter,&Image,user &Picture
-#cmd=73,0,&.,&Enter,&Image,&Room banner
-#cmd=74,0,&.,&Enter,&Image,&Floor label
-#
-cmd=41,0,&.,&Enter,re&Gistration
-cmd=4,0,&.,&Enter,&Message
-cmd=127,0,&.,&Enter,remote POP&3 accounts
-cmd=128,0,&.,&Enter,&XML/RSS feed retrieval
-
-# If you have an external editor defined, it will appear on command 46.
-cmd=46,0,&.,&Enter,message with &Editor
-
-# If you have multiple editors defined, they will appear on
-# commands 46, 101, 102, 103... up to MAX_EDITORS (5 by default)
-#cmd=101,0,&.,&Enter,message with &VI
-#cmd=102,0,&.,&Enter,message with &Nano
-
-cmd=59,0,&;,&Configure floor mode
-cmd=60,0,&;,&Goto floor:
-cmd=60,0,&.,&Enter,&Floor:
-cmd=61,0,&;,&Skip to floor:
-cmd=62,0,&;,&Zap (forget) floor
-cmd=63,2,&;,&Aide,&Create floor
-cmd=64,2,&;,&Aide,&Edit this floor
-cmd=65,2,&;,&Aide,&Kill this floor
-cmd=68,0,&;,&Known rooms
-cmd=66,0,&.,&Enter,&Bio
-cmd=67,0,&.,&Read,&Bio
-
-cmd=79,0,&.,&Wholist,&Long
-cmd=75,0,&.,&Wholist,&Roomname
-cmd=76,0,&.,&Wholist,&Hostname
-cmd=91,0,&.,&Wholist,&Active
-cmd=93,0,&.,&Wholist,&Stealth mode
-
-cmd=110,0,&+Next room
-cmd=111,0,&-Previous room
-cmd=112,0,&>Next floor
-cmd=113,0,&<Previous floor
-cmd=116,0,&.,skip to &+Next room
-cmd=117,0,&.,skip to &-Previous room
-cmd=118,0,&.,skip to &>Next floor
-cmd=119,0,&.,skip to &<Previous floor
-
-cmd=120,0,&.,&Known,&Anonymous rooms
-cmd=121,0,&.,&Known,&Directory rooms
-cmd=68,0,&.,&Known,&Floors
-cmd=49,0,&.,&Known,room &Info
-cmd=122,0,&.,&Known,&Match rooms:
-cmd=123,0,&.,&Known,preferred &Only rooms
-cmd=124,0,&.,&Known,&Private rooms
-cmd=125,0,&.,&Known,&Read only rooms
-cmd=126,0,&.,&Known,&Shared rooms
-cmd=19,0,&.,&Known,&Zapped rooms
-
-#
-# Command 69 allows the user to enter a server command directly. It is
-# primarily for testing and not intended for general use. Usually there
-# is no need to enable it.
-cmd=69,0,&@Server command:
-#
-# end of command set configuration
-#
+++ /dev/null
-extern char fullname[USERNAME_SIZE];
-extern unsigned room_flags;
-extern char room_name[ROOMNAMELEN];
-extern struct CtdlServInfo serv_info;
-extern char axlevel;
-extern char is_room_aide;
-extern unsigned userflags;
-extern char sigcaught;
-extern char editor_paths[MAX_EDITORS][SIZ];
-extern char printcmd[SIZ];
-extern char imagecmd[SIZ];
-extern char have_xterm;
-extern char rc_username[USERNAME_SIZE];
-extern char rc_password[32];
-extern char rc_floor_mode;
-extern time_t rc_idle_threshold;
-#ifdef HAVE_OPENSSL
-extern char rc_encrypt; /* from the citadel.rc file */
-extern char arg_encrypt; /* from the command line */
-#endif
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-extern char rc_screen;
-extern char arg_screen;
-#endif
-extern char rc_alt_semantics;
-extern char instant_msgs;
-void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code);
-#define logoff(ipc, code) ctdl_logoff(__FILE__, __LINE__, (ipc), (code))
-void formout(CtdlIPC *ipc, char *name);
-void sighandler(int which_sig);
-extern int secure;
-void remove_march(char *roomname, int floornum);
AC_CHECK_LIB(intl, libintl_bindtextdomain, [LDFLAGS="$LDFLAGS -lintl"])
-
-
-AC_ARG_ENABLE(threaded-client, [ --disable-threaded-client
- disable multithreaded client])
-
AC_ARG_ENABLE(pie, [ --enable-pie build position-independent executables])
AC_ARG_WITH(pam, [ --with-pam use PAM if present (see PAM.txt before you try this)])
test -d /usr/local/BerkeleyDB.4.5 && db_dir=/usr/local/BerkeleyDB.4.5
fi
-dnl By default, we only build the client (citadel and whobbs) unless we can
-dnl figure out how to build with POSIX threads.
-TARGETS=client
-
AC_CANONICAL_HOST
PTHREAD_DEFS=-D_REENTRANT
AC_MSG_CHECKING([how to compile with POSIX threads])
#endif],
ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
if test "$ac_cv_func_pthread_create" = yes; then
- test "$DATABASE" && TARGETS="client server utils"
- if test "x$enable_threaded_client" != xno; then
- AC_DEFINE(THREADED_CLIENT, [], [define this if you want to enable the multithreaded client])
- fi
+ test "$DATABASE" && TARGETS="server utils"
fi
AC_REPLACE_FUNCS(snprintf getutline)
fi
mkdir -p $abs_builddir/utils
mkdir -p $abs_builddir/utillib
- mkdir -p $abs_builddir/textclient
fi
if test -n "$srcdir"; then
+++ /dev/null
-etc/citadel/citadel.rc
-usr/bin/citadel
+++ /dev/null
-#!/bin/sh
-# postinst script for citadel-client
-
-set -e
-
-case "$1" in
- configure)
- if test -f /etc/citadel/citadel.rc; then
- chown citadel:citadel /etc/citadel/citadel.rc
- fi
- ;;
-
- abort-upgrade|abort-remove|abort-deconfigure)
- ;;
-
- *)
- echo "postinst called with unknown argument \`$1'" >&2
- exit 1
- ;;
-esac
-
-#DEBHELPER#
-
-exit 0
/* some of the frequently used files */
extern char file_citadel_control[PATH_MAX];
-extern char file_citadel_rc[PATH_MAX];
extern char file_citadel_config[PATH_MAX];
extern char file_citadel_urlshorteners[PATH_MAX];
extern char file_lmtp_socket[PATH_MAX];
+++ /dev/null
-
-#define UDS "_UDS_"
-#ifdef __CYGWIN__
-#define DEFAULT_HOST "localhost"
-#else
-#define DEFAULT_HOST UDS
-#endif
-#define DEFAULT_PORT "504"
-
-#include "sysdep.h"
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#ifdef HAVE_OPENSSL
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-#endif
-
-#include "server.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Quick and dirty hack; we don't want to use malloc() in C++ */
-#ifdef __cplusplus
-#define ialloc(t) new t()
-#define ifree(o) delete o
-#else
-#define ialloc(t) malloc(sizeof(t))
-#define ifree(o) free(o);
-#endif
-
-struct CtdlServInfo {
- int pid;
- char nodename[32];
- char humannode[64];
- char fqdn[64];
- char software[64];
- int rev_level;
- char site_location[64];
- char sysadm[64];
- char moreprompt[256];
- int ok_floors;
- int paging_level;
- int supports_qnop;
- int supports_ldap;
- int newuser_disabled;
- char default_cal_zone[256];
- double load_avg;
- double worker_avg;
- int thread_count;
- int has_sieve;
- int fulltext_enabled;
- char svn_revision[256];
- int guest_logins;
-};
-
-/*
- * This class is responsible for the server connection
- */
-typedef struct _CtdlIPC {
- struct CtdlServInfo ServInfo; /* The server info for this connection */
-
-#if defined(HAVE_OPENSSL)
- SSL *ssl; /* NULL if not encrypted, non-NULL otherwise */
-#endif
-
-#if defined(HAVE_PTHREAD_H)
- pthread_mutex_t mutex; /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
-#endif
-
- int sock; /* Socket for connection to server, or -1 if not connected */
- int isLocal; /* 1 if server is local, 0 otherwise or if not connected */
- int downloading; /* 1 if a download is open on the server, 0 otherwise */
- int uploading; /* 1 if an upload is open on the server, 0 otherwise */
- time_t last_command_sent; /* Time the last command was sent to the server */
-
- char *Buf; /* Our buffer for linebuffered read. */
- size_t BufSize;
- size_t BufUsed;
- char *BufPtr;
-
- void (*network_status_cb)(int state); /* Callback for update on whether the IPC is locked */
- char ip_hostname[256]; /* host name of server to which we are connected (if network) */
- char ip_address[64]; /* IP address of server to which we are connected (if network) */
-
-} CtdlIPC;
-
-/* C constructor */
-CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
-/* C destructor */
-void CtdlIPC_delete(CtdlIPC* ipc);
-/* Convenience destructor; also nulls out caller's pointer */
-void CtdlIPC_delete_ptr(CtdlIPC** pipc);
-/* Read a line from server, discarding newline, for chat, will go away */
-void CtdlIPC_chat_recv(CtdlIPC* ipc, char *buf);
-/* Write a line to server, adding newline, for chat, will go away */
-void CtdlIPC_chat_send(CtdlIPC* ipc, const char *buf);
-
-struct ctdlipcroom {
- char RRname[ROOMNAMELEN]; /* Name of room */
- long RRunread; /* Number of unread messages */
- long RRtotal; /* Total number of messages in room */
- char RRinfoupdated; /* Nonzero if info was updated */
- unsigned RRflags; /* Various flags (see LKRN) */
- unsigned RRflags2; /* Various flags (see LKRN) */
- long RRhighest; /* Highest message number in room */
- long RRlastread; /* Highest message user has read */
- char RRismailbox; /* Is this room a mailbox room? */
- char RRaide; /* User can do aide commands in room */
- long RRnewmail; /* Number of new mail messages */
- char RRfloor; /* Which floor this room is on */
- char RRcurrentview; /* The user's current view for this room */
- char RRdefaultview; /* The default view for this room */
-};
-
-
-struct parts {
- struct parts *next;
- char number[16]; /* part number */
- char name[PATH_MAX]; /* Name */
- char filename[PATH_MAX]; /* Suggested filename */
- char mimetype[SIZ]; /* MIME type */
- char disposition[SIZ]; /* Content disposition */
- unsigned long length; /* Content length */
-};
-
-
-struct ctdlipcmessage {
- char msgid[SIZ]; /* Original message ID */
- char path[SIZ]; /* Return path to sender */
- char zaps[SIZ]; /* Message ID that this supersedes */
- char subject[SIZ]; /* Message subject */
- char email[SIZ]; /* Email address of sender */
- char author[SIZ]; /* Sender of message */
- char recipient[SIZ]; /* Recipient of message */
- char room[SIZ]; /* Originating room */
- char node[SIZ]; /* Short nodename of origin system */
- char hnod[SIZ]; /* Humannode of origin system */
- struct parts *attachments; /* Available attachments */
- char *text; /* Message text */
- int type; /* Message type */
- time_t time; /* Time message was posted */
- char nhdr; /* Suppress message header? */
- char anonymous; /* An anonymous message */
- char mime_chosen[SIZ]; /* Chosen MIME part to output */
- char content_type[SIZ]; /* How would you like that? */
- char references[SIZ]; /* Thread references */
-};
-
-
-struct ctdlipcfile {
- char remote_name[PATH_MAX]; /* Filename on server */
- char local_name[PATH_MAX]; /* Filename on client */
- char description[80]; /* Description on server */
- FILE *local_fd; /* Open file on client */
- size_t size; /* Size of file in octets */
- unsigned int upload:1; /* uploading? 0 if downloading */
- unsigned int complete:1; /* Transfer has finished? */
-};
-
-
-struct ctdlipcmisc {
- long newmail; /* Number of new Mail messages */
- char needregis; /* Nonzero if user needs to register */
- char needvalid; /* Nonzero if users need validation */
-};
-
-enum RoomList {
- SubscribedRooms,
- SubscribedRoomsWithNewMessages,
- SubscribedRoomsWithNoNewMessages,
- UnsubscribedRooms,
- AllAccessibleRooms,
- AllPublicRooms
-};
-#define AllFloors -1
-enum MessageList {
- AllMessages,
- OldMessages,
- NewMessages,
- LastMessages,
- FirstMessages,
- MessagesGreaterThan,
- MessagesLessThan
-};
-enum MessageDirection {
- ReadReverse = -1,
- ReadForward = 1
-};
-
-/* Shared Diffie-Hellman parameters */
-#define DH_P "F6E33BD70D475906ABCFB368DA2D1E5611D57DFDAC6A10CD78F406D6952519C74E21FFDCC5A780B9359722AACC8036E4CD24D5F5165EAC9EF226DBD9BBCF678F8DDEE86386F1BC20E291A9854A513A2CA326B411DC92E38F2ED2FEB6A3B792F13DB6550371FDBAC5ECA373BE5050CA4905431CA86088737D52B36C8D13CE9CB4EEF4C910285035E8329DD07551A80B87775676DD1067395CCEE9040C9B8BF998C528B3772B4C590A2CF18C5E58929BFCB538A62638B7437A9C68572D15287E97692B0B1EC5444D9DAB6EB062D20B79CA005EC5035065567AFD1FEF9B251D74747C6065D8C8B6B0862D1EE03F3A244C429EADE0CCC5C3A4196F5CBF5AA01A9026EFB20AA90E462BD64620278F271905EB604F38E6CFAE412EAA6C468E3B58170909BC18662FE2053224F30BE4FDB93BF9FBF969D91A5427A0665AC7BD1C43701B991094C92F7A935063055617142164F02973EB4ED86DD74D2BBAB3CD3B28F7BBD8D9F925B0FE92F7F7D0568D783F9ECE7AF96FB5AF274B586924B64639733A73ACA8F2BD1E970DF51ADDD983F7F6361A2B0DC4F086DE26D8656EC8813DE4B74D6D57BC1E690AC2FF1682B7E16938565A41D1DC64C75ADB81DA4582613FC68C0FDD327D35E2CDF20D009465303773EF3870FBDB0985EE7002A95D7912BBCC78187C29DB046763B7FABFF44EABE820F8ED0D7230AA0AF24F428F82448345BC099B"
-#define DH_G "2"
-#define DH_L 4096
-#define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH" /* see ciphers(1) */
-
-int CtdlIPCNoop(CtdlIPC *ipc);
-int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret);
-int CtdlIPCQuit(CtdlIPC *ipc);
-int CtdlIPCLogout(CtdlIPC *ipc);
-int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret);
-int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret);
-int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret);
-int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice,
- char *cret);
-int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret);
-int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor,
- struct march **listing, char *cret);
-int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret);
-int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret);
-int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
- struct ctdlipcroom **rret, char *cret);
-int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
- const char *mtemplate, unsigned long **mret, char *cret);
-int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
- struct ctdlipcmessage **mret, char *cret);
-int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret);
-/* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */
-int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret);
-int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret);
-int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret);
-int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret);
-int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret,
- char *cret);
-int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret);
-int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret);
-int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required,
- struct ctdlipcmessage *mr,
- char *cret);
-int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
-int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
-int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
- const char *destroom, char *cret);
-int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
-int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
- int type, const char *password, int floor, char *cret);
-int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
-int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
- char *cret);
-int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
-int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
- char *cret);
-int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
- char *cret);
-int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
- char *cret);
-int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
-int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
-int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
-int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
-int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom,
- char *cret);
-int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename,
- const char *destnode, char *cret);
-int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
-int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
- size_t resume,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
- void **buf,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
- const char *path,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
- const char *save_as,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
-int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name,
- char *cret);
-int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
-int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
- char *cret);
-int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
- int revision, const char *software_name, const char *hostname,
- char *cret);
-int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username,
- const char *text, char *cret);
-int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
-int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
-int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing,
- char *cret);
-int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
-int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
-int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
-int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
-int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
- char *cret);
-int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret);
-int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret);
-int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret);
-time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
-int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
- struct ctdluser **uret, char *cret);
-int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
-int CtdlIPCRenameUser(CtdlIPC *ipc, char *oldname, char *newname, char *cret);
-int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, GPEXWhichPolicy which,
- struct ExpirePolicy **policy, char *cret);
-int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
- struct ExpirePolicy *policy, char *cret);
-int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
-int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
- char **listing, char *cret);
-int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
- const char *listing, char *cret);
-int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
-int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
-int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
-int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
-int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
-int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
-int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
-int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
-
-/* ************************************************************************** */
-/* Stuff below this line is not for public consumption */
-/* ************************************************************************** */
-
-char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
-int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
-size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset,
- size_t bytes, char *cret);
-int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
-int CtdlIPCWriteUpload(CtdlIPC *ipc, FILE *uploadFP,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
-int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
- size_t resume,
- void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
- char *cret);
-int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
- const char *to_send, size_t bytes_to_send, char **to_receive,
- size_t *bytes_to_receive, char *proto_response);
-
-/* Internals */
-int starttls(CtdlIPC *ipc);
-void setCryptoStatusHook(void (*hook)(char *s));
-void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
-/* This is all Ford's doing. FIXME: figure out what it's doing */
-extern int (*error_printf)(char *s, ...);
-void setIPCDeathHook(void (*hook)(void));
-void setIPCErrorPrintf(int (*func)(char *s, ...));
-void connection_died(CtdlIPC* ipc, int using_ssl);
-int CtdlIPC_getsockfd(CtdlIPC* ipc);
-char CtdlIPC_get(CtdlIPC* ipc);
-
-
-
-static INLINE void CtdlIPC_lock(CtdlIPC *ipc)
-{
- if (ipc->network_status_cb) ipc->network_status_cb(1);
-#ifdef THREADED_CLIENT
- pthread_mutex_lock(&(ipc->mutex));
-#endif
-}
-
-
-static INLINE void CtdlIPC_unlock(CtdlIPC *ipc)
-{
-#ifdef THREADED_CLIENT
- pthread_mutex_unlock(&(ipc->mutex));
-#endif
- if (ipc->network_status_cb) ipc->network_status_cb(0);
-}
-
-#ifdef __cplusplus
-}
-#endif
+++ /dev/null
-/*
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-/*
- * Colors for color() command
- */
-#define DIM_BLACK 0
-#define DIM_RED 1
-#define DIM_GREEN 2
-#define DIM_YELLOW 3
-#define DIM_BLUE 4
-#define DIM_MAGENTA 5
-#define DIM_CYAN 6
-#define DIM_WHITE 7
-#define BRIGHT_BLACK 8
-#define BRIGHT_RED 9
-#define BRIGHT_GREEN 10
-#define BRIGHT_YELLOW 11
-#define BRIGHT_BLUE 12
-#define BRIGHT_MAGENTA 13
-#define BRIGHT_CYAN 14
-#define BRIGHT_WHITE 15
-#define COLOR_PUSH 16 /* Save current color */
-#define COLOR_POP 17 /* Restore saved color */
-#define ORIGINAL_PAIR -1 /* Default terminal colors */
-
-/*
- * declarations
- */
-void load_command_set(void);
-void stty_ctdl(int cmd);
-void newprompt(char *prompt, char *str, int len);
-void strprompt(char *prompt, char *str, int len);
-int boolprompt(char *prompt, int prev_val);
-int intprompt(char *prompt, int ival, int imin, int imax);
-int fmout(int width, FILE *fpin, char *text, FILE *fpout, int subst);
-int getcmd(CtdlIPC *ipc, char *argbuf);
-void display_help(CtdlIPC *ipc, char *name);
-void color(int colornum);
-void cls(int colornum);
-void send_ansi_detect(void);
-void look_for_ansi(void);
-int inkey(void);
-void set_keepalives(int s);
-extern int enable_color;
-int yesno(void);
-int yesno_d(int d);
-void keyopt(char *);
-char keymenu(char *menuprompt, char *menustring);
-void async_ka_start(void);
-void async_ka_end(void);
-int checkpagin(int lp, unsigned int pagin, unsigned int height);
-char was_a_key_pressed(void);
-
-#ifdef __GNUC__
-void pprintf(const char *format, ...) __attribute__((__format__(__printf__,1,2)));
-#else
-void pprintf(const char *format, ...);
-#endif
-
-
-
-extern char rc_url_cmd[SIZ];
-extern char rc_open_cmd[SIZ];
-extern char rc_gotmail_cmd[SIZ];
-extern int lines_printed;
-extern int rc_remember_passwords;
*/
#define CHATLOG "/dev/null"
-/*
- * S_KEEPALIVE is a watchdog timer. It is used to send "keep
- * alive" messages to the server to prevent the server from assuming the
- * client is dead and terminating the session. 30 seconds is the recommended
- * value; I can't think of any good reason to change it.
- */
-#define S_KEEPALIVE 30
-
/*
* Logging level to use if none is specified on the command line.
* Note that this will suppress messages before they even get to syslog().
+++ /dev/null
-/*
- * Main source module for the client program.
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "citadel_ipc.h"
-#include "axdefs.h"
-#include "routines.h"
-#include "routines2.h"
-#include "tuiconfig.h"
-#include "rooms.h"
-#include "messages.h"
-#include "commands.h"
-#include "client_chat.h"
-#include "client_passwords.h"
-#include "citadel_decls.h"
-#include "sysdep.h"
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-#include "screen.h"
-#include "citadel_dirs.h"
-
-#include "ecrash.h"
-#include "md5.h"
-
-#define IFEXPERT if (userflags&US_EXPERT)
-#define IFNEXPERT if ((userflags&US_EXPERT)==0)
-#define IFAIDE if (axlevel>=AxAideU)
-#define IFNAIDE if (axlevel<AxAideU)
-
-int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2);
-march *marchptr = NULL;
-extern char *moreprompt;
-
-/* globals associated with the client program */
-char temp[PATH_MAX]; /* Name of general-purpose temp file */
-char temp2[PATH_MAX]; /* Name of general-purpose temp file */
-char tempdir[PATH_MAX]; /* Name of general-purpose temp directory */
-char printcmd[SIZ]; /* print command */
-int editor_pid = (-1);
-char fullname[USERNAME_SIZE];
-unsigned room_flags;
-unsigned room_flags2;
-int entmsg_ok = 0;
-char room_name[ROOMNAMELEN];
-char *uglist[UGLISTLEN]; /* size of the ungoto list */
-long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
-int uglistsize = 0;
-char is_mail = 0; /* nonzero when we're in a mail room */
-char axlevel = AxDeleted; /* access level */
-char is_room_aide = 0; /* boolean flag, 1 if room aide */
-int timescalled;
-int posted;
-unsigned userflags;
-long usernum = 0L; /* user number */
-time_t lastcall = 0L; /* Date/time of previous login */
-char newnow;
-long highest_msg_read; /* used for <A>bandon room cmd */
-long maxmsgnum; /* used for <G>oto */
-char sigcaught = 0;
-char rc_username[USERNAME_SIZE];
-char rc_password[32];
-char hostbuf[SIZ];
-char portbuf[SIZ];
-char rc_floor_mode;
-char floor_mode;
-char curr_floor = 0; /* number of current floor */
-char floorlist[128][SIZ]; /* names of floors */
-int termn8 = 0; /* Set to nonzero to cause a logoff */
-int secure; /* Set to nonzero when wire is encrypted */
-
-extern char instant_msgs; /* instant messages waiting! */
-extern int rc_ansi_color; /* ansi color value from citadel.rc */
-extern int next_lazy_cmd;
-
-CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
-int enable_syslog = 0;
-
-
-/*
- * here is our 'clean up gracefully and exit' routine
- */
-void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code)
-{
- int lp;
-
- if (editor_pid > 0) { /* kill the editor if it's running */
- kill(editor_pid, SIGHUP);
- }
-
- /* Free the ungoto list */
- for (lp = 0; lp < uglistsize; lp++) {
- free(uglist[lp]);
- }
-
-/* Shut down the server connection ... but not if the logoff code is 3,
- * because that means we're exiting because we already lost the server.
- */
- if (code != 3) {
- CtdlIPCQuit(ipc);
- }
-
-/*
- * now clean up various things
- */
- unlink(temp);
- unlink(temp2);
- nukedir(tempdir);
-
- /* Violently kill off any child processes if Citadel is
- * the login shell.
- */
- if (getppid() == 1) {
- kill(0 - getpgrp(), SIGTERM);
- sleep(1);
- kill(0 - getpgrp(), SIGKILL);
- }
- color(ORIGINAL_PAIR); /* Restore the old color settings */
- stty_ctdl(SB_RESTORE); /* return the old terminal settings */
- /*
- * uncomment the following if you need to know why Citadel exited
- printf("*** Exit code %d at %s:%d\n", code, file, line);
- sleep(2);
- */
- exit(code); /* exit with the proper exit code */
-}
-
-
-
-/*
- * signal catching function for hangups...
- */
-void dropcarr(int signum)
-{
- logoff(NULL, 3); /* No IPC when server's already gone! */
-}
-
-
-
-/*
- * catch SIGCONT to reset terminal modes when were are put back into the
- * foreground.
- */
-void catch_sigcont(int signum)
-{
- stty_ctdl(SB_LAST);
- signal(SIGCONT, catch_sigcont);
-}
-
-
-/* general purpose routines */
-
-/* display a file */
-void formout(CtdlIPC *ipc, char *name)
-{
- int r; /* IPC return code */
- char buf[SIZ];
- char *text = NULL;
-
- r = CtdlIPCSystemMessage(ipc, name, &text, buf);
- if (r / 100 != 1) {
- scr_printf("%s\n", buf);
- return;
- }
- if (text) {
- fmout(screenwidth, NULL, text, NULL, 1);
- free(text);
- }
-}
-
-
-void userlist(CtdlIPC *ipc, char *patn)
-{
- char buf[SIZ];
- char fl[SIZ];
- struct tm tmbuf;
- time_t lc;
- int r; /* IPC response code */
- char *listing = NULL;
-
- r = CtdlIPCUserListing(ipc, patn, &listing, buf);
- if (r / 100 != 1) {
- scr_printf("%s\n", buf);
- return;
- }
-
- scr_printf(" User Name Num L Last Visit Logins Messages\n");
- scr_printf("------------------------- ----- - ---------- ------ --------\n");
- if (listing != NULL) while (!IsEmptyStr(listing)) {
- extract_token(buf, listing, 0, '\n', sizeof buf);
- remove_token(listing, 0, '\n');
-
- if (sigcaught == 0) {
- extract_token(fl, buf, 0, '|', sizeof fl);
- if (pattern(fl, patn) >= 0) {
- scr_printf("%-25s ", fl);
- scr_printf("%5ld %d ", extract_long(buf, 2),
- extract_int(buf, 1));
- lc = extract_long(buf, 3);
- localtime_r(&lc, &tmbuf);
- scr_printf("%02d/%02d/%04d ",
- (tmbuf.tm_mon + 1),
- tmbuf.tm_mday,
- (tmbuf.tm_year + 1900));
- scr_printf("%6ld %8ld\n", extract_long(buf, 4), extract_long(buf, 5));
- }
-
- }
- }
- free(listing);
- scr_printf("\n");
-}
-
-
-/*
- * grab assorted info about the user...
- */
-void load_user_info(char *params)
-{
- extract_token(fullname, params, 0, '|', sizeof fullname);
- axlevel = extract_int(params, 1);
- timescalled = extract_int(params, 2);
- posted = extract_int(params, 3);
- userflags = extract_int(params, 4);
- usernum = extract_long(params, 5);
- lastcall = extract_long(params, 6);
-}
-
-
-/*
- * Remove a room from the march list. 'floornum' is ignored unless
- * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
- * floor will be removed from the march list.
- */
-void remove_march(char *roomname, int floornum)
-{
- struct march *mptr, *mptr2;
-
- if (marchptr == NULL)
- return;
-
- if ((!strcasecmp(marchptr->march_name, roomname))
- || ((!strcasecmp(roomname, "_FLOOR_")) && (marchptr->march_floor == floornum))) {
- mptr = marchptr->next;
- free(marchptr);
- marchptr = mptr;
- return;
- }
- mptr2 = marchptr;
- for (mptr = marchptr; mptr != NULL; mptr = mptr->next) {
-
- if ((!strcasecmp(mptr->march_name, roomname))
- || ((!strcasecmp(roomname, "_FLOOR_"))
- && (mptr->march_floor == floornum))) {
-
- mptr2->next = mptr->next;
- free(mptr);
- mptr = mptr2;
- } else {
- mptr2 = mptr;
- }
- }
-}
-
-
-/*
- * Locate the room on the march list which we most want to go to. Each room
- * is measured given a "weight" of preference based on various factors.
- */
-char *pop_march(int desired_floor, struct march *_march)
-{
- static char TheRoom[ROOMNAMELEN];
- int TheWeight = 0;
- int weight;
- struct march *mptr = NULL;
-
- strcpy(TheRoom, "_BASEROOM_");
- if (_march == NULL)
- return (TheRoom);
-
- for (mptr = _march; mptr != NULL; mptr = mptr->next) {
- weight = 0;
- if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
- weight = weight + 10000;
- if (mptr->march_floor == desired_floor)
- weight = weight + 5000;
-
- weight = weight + ((128 - (mptr->march_floor)) * 128);
- weight = weight + (128 - (mptr->march_order));
-
- if (weight > TheWeight) {
- TheWeight = weight;
- strcpy(TheRoom, mptr->march_name);
- }
- }
- return (TheRoom);
-}
-
-
-/*
- * jump directly to a room
- */
-void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
-{
- char aaa[SIZ], bbb[SIZ];
- static long ls = 0L;
- int newmailcount = 0;
- int partial_match, best_match;
- char from_floor;
- int ugpos = uglistsize;
- int r; /* IPC result code */
- struct ctdlipcroom *room = NULL;
- int rv = 0;
-
- /* store ungoto information */
- if (fromungoto == 0) {
- /* sloppy slide them all down, hey it's the client, who cares. :-) */
- if (uglistsize >= (UGLISTLEN-1)) {
- int lp;
- free (uglist[0]);
- for (lp = 0; lp < (UGLISTLEN-1); lp++) {
- uglist[lp] = uglist[lp+1];
- uglistlsn[lp] = uglistlsn[lp+1];
- }
- ugpos--;
- } else {
- uglistsize++;
- }
-
- uglist[ugpos] = malloc(strlen(room_name)+1);
- strcpy(uglist[ugpos], room_name);
- uglistlsn[ugpos] = ls;
- }
-
- /* first try an exact match */
- r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
- if (r / 10 == 54) {
- newprompt("Enter room password: ", bbb, 9);
- r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
- if (r / 10 == 54) {
- scr_printf("Wrong password.\n");
- return;
- }
- }
-
- /*
- * If a match is not found, try a partial match.
- * Partial matches anywhere in the string carry a weight of 1,
- * left-aligned matches carry a weight of 2. Pick the room that
- * has the highest-weighted match. Do not match on forgotten
- * rooms.
- */
- if (r / 100 != 2) {
- struct march *march = NULL;
-
- best_match = 0;
- strcpy(bbb, "");
-
- r = CtdlIPCKnownRooms(ipc, SubscribedRooms, AllFloors, &march, aaa);
- if (r / 100 == 1) {
- /* Run the roomlist; free the data as we go */
- struct march *mp = march; /* Current */
-
- while (mp) {
- partial_match = 0;
- if (pattern(mp->march_name, towhere) >= 0) {
- partial_match = 1;
- }
- if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
- partial_match = 2;
- }
- if (partial_match > best_match) {
- strcpy(bbb, mp->march_name);
- best_match = partial_match;
- }
- /* Both pointers are NULL at end of list */
- march = mp->next;
- free(mp);
- mp = march;
- }
- }
-
- if (IsEmptyStr(bbb)) {
- scr_printf("No room '%s'.\n", towhere);
- return;
- }
- r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
- }
- if (r / 100 != 1 && r / 100 != 2) {
- scr_printf("%s\n", aaa);
- return;
- }
- safestrncpy(room_name, room->RRname, ROOMNAMELEN);
- room_flags = room->RRflags;
- room_flags2 = room->RRflags2;
- from_floor = curr_floor;
- curr_floor = room->RRfloor;
-
- /* Determine, based on the room's default view, whether an <E>nter message
- * command will be valid here.
- */
- switch(room->RRdefaultview) {
- case VIEW_BBS:
- case VIEW_MAILBOX:
- case VIEW_BLOG:
- entmsg_ok = 1;
- break;
- default:
- entmsg_ok = 0;
- break;
- }
-
- remove_march(room_name, 0);
- if (!strcasecmp(towhere, "_BASEROOM_"))
- remove_march(towhere, 0);
- if (!room->RRunread)
- next_lazy_cmd = 5; /* Don't read new if no new msgs */
- if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
- if (floorlist[(int) curr_floor][0] == 0)
- load_floorlist(ipc);
- scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
- }
- if (display_name == 1) {
- color(BRIGHT_WHITE);
- scr_printf("%s ", room_name);
- color(DIM_WHITE);
- scr_printf("- ");
- }
- if (display_name != 2) {
- color(BRIGHT_YELLOW);
- scr_printf("%d ", room->RRunread);
- color(DIM_WHITE);
- scr_printf("new of ");
- color(BRIGHT_YELLOW);
- scr_printf("%d ", room->RRtotal);
- color(DIM_WHITE);
- scr_printf("messages.\n");
- }
- highest_msg_read = room->RRlastread;
- maxmsgnum = room->RRhighest;
- is_mail = room->RRismailbox;
- is_room_aide = room->RRaide;
- ls = room->RRlastread;
-
- /* read info file if necessary */
- if (room->RRinfoupdated > 0)
- readinfo(ipc);
-
- /* check for newly arrived mail if we can */
- newmailcount = room->RRnewmail;
- if (newmailcount > 0) {
- color(BRIGHT_RED);
- if (newmailcount == 1) {
- scr_printf("*** A new mail message has arrived.\n");
- }
- else {
- scr_printf("*** %d new mail messages have arrived.\n",
- newmailcount);
- }
- color(DIM_WHITE);
- if (!IsEmptyStr(rc_gotmail_cmd)) {
- rv = system(rc_gotmail_cmd);
- if (rv)
- scr_printf("*** failed to check for mail calling %s Reason %d.\n",
- rc_gotmail_cmd, rv);
- }
- }
- free(room);
-
- if (screenwidth>5) snprintf(&status_line[1], screenwidth-1, "%s | %s | %s | %s | %d new mail |",
- (secure ? "Encrypted" : "Unencrypted"),
- ipc->ServInfo.humannode,
- ipc->ServInfo.site_location,
- room_name,
- newmailcount
- );
-}
-
-/* Goto next room having unread messages.
- * We want to skip over rooms that the user has already been to, and take the
- * user back to the lobby when done. The room we end up in is placed in
- * newroom - which is set to 0 (the lobby) initially.
- */
-void gotonext(CtdlIPC *ipc)
-{
- char buf[SIZ];
- struct march *mptr, *mptr2;
- char next_room[ROOMNAMELEN];
-
- /* Check to see if the march-mode list is already allocated.
- * If it is, pop the first room off the list and go there.
- */
- if (marchptr == NULL) {
- CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
- AllFloors, &marchptr, buf);
-
-/* add _BASEROOM_ to the end of the march list, so the user will end up
- * in the system base room (usually the Lobby>) at the end of the loop
- */
- mptr = (struct march *) malloc(sizeof(struct march));
- mptr->next = NULL;
- mptr->march_order = 0;
- mptr->march_floor = 0;
- strcpy(mptr->march_name, "_BASEROOM_");
- if (marchptr == NULL) {
- marchptr = mptr;
- } else {
- mptr2 = marchptr;
- while (mptr2->next != NULL)
- mptr2 = mptr2->next;
- mptr2->next = mptr;
- }
-/*
- * ...and remove the room we're currently in, so a <G>oto doesn't make us
- * walk around in circles
- */
- remove_march(room_name, 0);
- }
- if (marchptr != NULL) {
- strcpy(next_room, pop_march(curr_floor, marchptr));
- } else {
- strcpy(next_room, "_BASEROOM_");
- }
- remove_march(next_room, 0);
- dotgoto(ipc, next_room, 1, 0);
-}
-
-/*
- * forget all rooms on a given floor
- */
-void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
-{
- char buf[SIZ];
- struct march *flist = NULL;
- struct march *fptr = NULL;
- struct ctdlipcroom *room = NULL;
- int r; /* IPC response code */
-
- scr_printf("Forgetting all rooms on %s...\n", &floorlist[ffloor][0]);
- remove_march("_FLOOR_", ffloor);
- r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
- if (r / 100 != 1) {
- scr_printf("Error %d: %s\n", r, buf);
- return;
- }
- while (flist) {
- r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
- if (r / 100 == 2) {
- r = CtdlIPCForgetRoom(ipc, buf);
- if (r / 100 != 2) {
- scr_printf("Error %d: %s\n", r, buf);
- }
-
- }
- fptr = flist;
- flist = flist->next;
- free(fptr);
- }
- if (room) free(room);
-}
-
-
-/*
- * routine called by gotofloor() to move to a new room on a new floor
- */
-void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
-{
- int floor_being_left;
-
- floor_being_left = curr_floor;
-
- if (mode == GF_GOTO) { /* <;G>oto mode */
- updatels(ipc);
- dotgoto(ipc, towhere, 1, 0);
- }
- else if (mode == GF_SKIP) { /* <;S>kip mode */
- dotgoto(ipc, towhere, 1, 0);
- remove_march("_FLOOR_", floor_being_left);
- }
- else if (mode == GF_ZAP) { /* <;Z>ap mode */
- dotgoto(ipc, towhere, 1, 0);
- remove_march("_FLOOR_", floor_being_left);
- forget_all_rooms_on(ipc, floor_being_left);
- }
-}
-
-
-/*
- * go to a new floor
- */
-void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
-{
- int a, tofloor;
- int r; /* IPC response code */
- struct march *mptr;
- char buf[SIZ], targ[SIZ];
-
- if (floorlist[0][0] == 0)
- load_floorlist(ipc);
- tofloor = (-1);
- for (a = 0; a < 128; ++a)
- if (!strcasecmp(&floorlist[a][0], towhere))
- tofloor = a;
-
- if (tofloor < 0) {
- for (a = 0; a < 128; ++a) {
- if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
- tofloor = a;
- }
- }
- }
- if (tofloor < 0) {
- for (a = 0; a < 128; ++a)
- if (pattern(towhere, &floorlist[a][0]) > 0)
- tofloor = a;
- }
- if (tofloor < 0) {
- scr_printf("No floor '%s'.\n", towhere);
- return;
- }
- for (mptr = marchptr; mptr != NULL; mptr = mptr->next) {
- if ((mptr->march_floor) == tofloor) {
- gf_toroom(ipc, mptr->march_name, mode);
- return;
- }
- }
-
- /* Find first known room on the floor */
-
- strcpy(targ, "");
- mptr = NULL;
- r = CtdlIPCKnownRooms(ipc, SubscribedRooms, tofloor, &mptr, buf);
- if (r / 100 == 1) {
- struct march *tmp = mptr;
-
- /*. . . according to room order */
- if (mptr)
- strcpy(targ, pop_march(tofloor, mptr));
- while (mptr) {
- tmp = mptr->next;
- free(mptr);
- mptr = tmp;
- }
- }
- if (!IsEmptyStr(targ)) {
- gf_toroom(ipc, targ, mode);
- return;
- }
-
- /* No known rooms on the floor; unzap the first one then */
-
- strcpy(targ, "");
- mptr = NULL;
- r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
- if (r / 100 == 1) {
- struct march *tmp = mptr;
-
- /*. . . according to room order */
- if (mptr)
- strcpy(targ, pop_march(tofloor, mptr));
- while (mptr) {
- tmp = mptr->next;
- free(mptr);
- mptr = tmp;
- }
- }
- if (!IsEmptyStr(targ)) {
- gf_toroom(ipc, targ, mode);
- } else {
- scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
- }
-}
-
-/*
- * Indexing mechanism for a room list, called by gotoroomstep()
- */
-void room_tree_list_query(struct ctdlroomlisting *rp, char *findrmname, int findrmslot, char *rmname, int *rmslot, int *rmtotal)
-{
- char roomname[ROOMNAMELEN];
- static int cur_rmslot = 0;
-
- if (rp == NULL) {
- cur_rmslot = 0;
- return;
- }
-
- if (rp->lnext != NULL) {
- room_tree_list_query(rp->lnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
- }
-
- if (sigcaught == 0) {
- strcpy(roomname, rp->rlname);
-
- if (rmname != NULL) {
- if (cur_rmslot == findrmslot) {
- strcpy(rmname, roomname);
- }
- }
- if (rmslot != NULL) {
- if (!strcmp(roomname, findrmname)) {
- *rmslot = cur_rmslot;
- }
- }
- cur_rmslot++;
- }
-
- if (rp->rnext != NULL) {
- room_tree_list_query(rp->rnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
- }
-
- if ((rmname == NULL) && (rmslot == NULL))
- free(rp);
-
- if (rmtotal != NULL) {
- *rmtotal = cur_rmslot;
- }
-}
-
-/*
- * step through rooms on current floor
- */
-void gotoroomstep(CtdlIPC *ipc, int direction, int mode)
-{
- struct march *listing = NULL;
- struct march *mptr;
- int r; /* IPC response code */
- char buf[SIZ];
- struct ctdlroomlisting *rl = NULL;
- struct ctdlroomlisting *rp;
- struct ctdlroomlisting *rs;
- int list_it;
- char rmname[ROOMNAMELEN];
- int rmslot = 0;
- int rmtotal;
-
- /* Ask the server for a room list */
- r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
- if (r / 100 != 1) {
- listing = NULL;
- }
-
- load_floorlist(ipc);
-
- for (mptr = listing; mptr != NULL; mptr = mptr->next) {
- list_it = 1;
-
- if ( floor_mode
- && (mptr->march_floor != curr_floor))
- list_it = 0;
-
- if (list_it) {
- rp = malloc(sizeof(struct ctdlroomlisting));
- strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
- rp->rlflags = mptr->march_flags;
- rp->rlfloor = mptr->march_floor;
- rp->rlorder = mptr->march_order;
- rp->lnext = NULL;
- rp->rnext = NULL;
-
- rs = rl;
- if (rl == NULL) {
- rl = rp;
- } else {
- while (rp != NULL) {
- if (rordercmp(rp, rs) < 0) {
- if (rs->lnext == NULL) {
- rs->lnext = rp;
- rp = NULL;
- } else {
- rs = rs->lnext;
- }
- } else {
- if (rs->rnext == NULL) {
- rs->rnext = rp;
- rp = NULL;
- } else {
- rs = rs->rnext;
- }
- }
- }
- }
- }
- }
-
- /* Find position of current room */
- room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
- room_tree_list_query(rl, room_name, 0, NULL, &rmslot, &rmtotal);
-
- if (direction == 0) { /* Previous room */
- /* If we're at the first room, wrap to the last room */
- if (rmslot == 0) {
- rmslot = rmtotal - 1;
- } else {
- rmslot--;
- }
- } else { /* Next room */
- /* If we're at the last room, wrap to the first room */
- if (rmslot == rmtotal - 1) {
- rmslot = 0;
- } else {
- rmslot++;
- }
- }
-
- /* Get name of next/previous room */
- room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
- room_tree_list_query(rl, NULL, rmslot, rmname, NULL, NULL);
-
- /* Free the tree */
- room_tree_list_query(rl, NULL, 0, NULL, NULL, NULL);
-
- if (mode == 0) { /* not skipping */
- updatels(ipc);
- }
-
- /* Free the room list */
- while (listing) {
- mptr = listing->next;
- free(listing);
- listing = mptr;
- };
-
- dotgoto(ipc, rmname, 1, 0);
-}
-
-
-/*
- * step through floors on system
- */
-void gotofloorstep(CtdlIPC *ipc, int direction, int mode)
-{
- int tofloor;
-
- if (floorlist[0][0] == 0)
- load_floorlist(ipc);
-
- empty_keep_going:
-
- if (direction == 0) { /* Previous floor */
- if (curr_floor) tofloor = curr_floor - 1;
- else tofloor = 127;
-
- while (!floorlist[tofloor][0]) tofloor--;
- } else { /* Next floor */
- if (curr_floor < 127) tofloor = curr_floor + 1;
- else tofloor = 0;
-
- while (!floorlist[tofloor][0] && tofloor < 127) tofloor++;
- if (!floorlist[tofloor][0]) tofloor = 0;
- }
- /* ;g works when not in floor mode so . . . */
- if (!floor_mode) {
- scr_printf("(%s)\n", floorlist[tofloor] );
- }
-
- gotofloor(ipc, floorlist[tofloor], mode);
- if (curr_floor != tofloor) { /* gotofloor failed */
- curr_floor = tofloor;
- goto empty_keep_going;
- }
-}
-
-/*
- * Display user 'preferences'.
- */
-extern int rc_prompt_control;
-void read_config(CtdlIPC *ipc)
-{
- char buf[SIZ];
- char *resp = NULL;
- int r; /* IPC response code */
- char _fullname[USERNAME_SIZE];
- long _usernum;
- int _axlevel, _timescalled, _posted;
- time_t _lastcall;
- struct ctdluser *user = NULL;
-
- /* get misc user info */
- r = CtdlIPCGetBio(ipc, fullname, &resp, buf);
- if (r / 100 != 1) {
- scr_printf("%s\n", buf);
- return;
- }
- extract_token(_fullname, buf, 1, '|', sizeof fullname);
- _usernum = extract_long(buf, 2);
- _axlevel = extract_int(buf, 3);
- _lastcall = extract_long(buf, 4);
- _timescalled = extract_int(buf, 5);
- _posted = extract_int(buf, 6);
- free(resp);
- resp = NULL;
-
- /* get preferences */
- r = CtdlIPCGetConfig(ipc, &user, buf);
- if (r / 100 != 2) {
- scr_printf("%s\n", buf);
- free(user);
- return;
- }
-
- /* show misc user info */
- scr_printf("%s\nAccess level: %d (%s)\n"
- "User #%ld / %d Calls / %d Posts",
- _fullname, _axlevel, axdefs[(int) _axlevel],
- _usernum, _timescalled, _posted);
- if (_lastcall > 0L) {
- scr_printf(" / Curr login: %s",
- asctime(localtime(&_lastcall)));
- }
- scr_printf("\n");
-
- /* show preferences */
- scr_printf("Are you an experienced Citadel user: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXPERT) ? "Yes" : "No"); color(DIM_WHITE);
- scr_printf("Print last old message on New message request: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_LASTOLD)? "Yes" : "No"); color(DIM_WHITE);
- scr_printf("Prompt after each message: "); color(BRIGHT_CYAN); scr_printf("%s\n", (!(user->flags & US_NOPROMPT))? "Yes" : "No"); color(DIM_WHITE);
- if ((user->flags & US_NOPROMPT) == 0) {
- scr_printf("Use 'disappearing' prompts: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_DISAPPEAR)? "Yes" : "No"); color(DIM_WHITE);
- }
- scr_printf("Pause after each screenful of text: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PAGINATOR)? "Yes" : "No"); color(DIM_WHITE);
- if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR)) {
- scr_printf("<N>ext and <S>top work at paginator prompt: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PROMPTCTL)? "Yes" : "No"); color(DIM_WHITE);
- }
- if (rc_floor_mode == RC_DEFAULT) {
- scr_printf("View rooms by floor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_FLOORS)? "Yes" : "No"); color(DIM_WHITE);
- }
- if (rc_ansi_color == 3) {
- scr_printf("Enable color support: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_COLOR)? "Yes" : "No"); color(DIM_WHITE);
- }
- scr_printf("Be unlisted in userlog: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_UNLISTED)? "Yes" : "No"); color(DIM_WHITE);
- if (!IsEmptyStr(editor_path)) {
- scr_printf("Always enter messages with the full-screen editor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXTEDIT)? "Yes" : "No"); color(DIM_WHITE);
- }
- free(user);
-}
-
-/*
- * Display system statistics.
- */
-void system_info(CtdlIPC *ipc)
-{
- char buf[SIZ];
- char *resp = NULL;
- size_t bytes;
- int mrtg_users, mrtg_active_users;
- char mrtg_server_uptime[40];
- long mrtg_himessage;
-
- /* get #users, #active & server uptime */
- CtdlIPCGenericCommand(ipc, "MRTG|users", NULL, 0, &resp, &bytes, buf);
- mrtg_users = extract_int(resp, 0);
- remove_token(resp, 0, '\n');
- mrtg_active_users = extract_int(resp, 0);
- remove_token(resp, 0, '\n');
- extract_token(mrtg_server_uptime, resp, 0, '\n', sizeof mrtg_server_uptime);
- free(resp);
- resp = NULL;
-
- /* get high message# */
- CtdlIPCGenericCommand(ipc, "MRTG|messages", NULL, 0, &resp, &bytes, buf);
- mrtg_himessage = extract_long(resp, 0);
- free(resp);
- resp = NULL;
-
- /* refresh server info just in case */
- CtdlIPCServerInfo(ipc, buf);
-
- scr_printf("You are connected to %s (%s) @%s\n", ipc->ServInfo.nodename, ipc->ServInfo.humannode, ipc->ServInfo.fqdn);
- scr_printf("running %s with text client v%.2f,\n", ipc->ServInfo.software, (float)REV_LEVEL/100);
- scr_printf("server build %s,\n", ipc->ServInfo.svn_revision, (float)REV_LEVEL/100);
- scr_printf("and located in %s.\n", ipc->ServInfo.site_location);
- scr_printf("Connected users %d / Active users %d / Highest message #%ld\n", mrtg_users, mrtg_active_users, mrtg_himessage);
- scr_printf("Server uptime: %s\n", mrtg_server_uptime);
- scr_printf("Your system administrator is %s.\n", ipc->ServInfo.sysadm);
- scr_printf("Copyright (C)1987-2009 by the Citadel development team\n");
-}
-
-/*
- * forget all rooms on current floor
- */
-void forget_this_floor(CtdlIPC *ipc)
-{
- if (curr_floor == 0) {
- scr_printf("Can't forget this floor.\n");
- return;
- }
- if (floorlist[0][0] == 0) {
- load_floorlist(ipc);
- }
- scr_printf("Are you sure you want to forget all rooms on %s? ",
- &floorlist[(int) curr_floor][0]);
- if (yesno() == 0) {
- return;
- }
-
- gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
-}
-
-
-/*
- * set floor mode depending on client, server, and user settings
- */
-void set_floor_mode(CtdlIPC* ipc)
-{
- if (ipc->ServInfo.ok_floors == 0) {
- floor_mode = 0; /* Don't use floors if the server */
- }
- /* doesn't support them! */
- else {
- if (rc_floor_mode == RC_NO) { /* never use floors */
- floor_mode = 0;
- }
- if (rc_floor_mode == RC_YES) { /* always use floors */
- floor_mode = 1;
- }
- if (rc_floor_mode == RC_DEFAULT) { /* user choice */
- floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
- }
- }
-}
-
-/*
- * Set or change the user's password
- */
-int set_password(CtdlIPC *ipc)
-{
- char pass1[20];
- char pass2[20];
- char buf[SIZ];
-
- if (!IsEmptyStr(rc_password)) {
- strcpy(pass1, rc_password);
- strcpy(pass2, rc_password);
- } else {
- IFNEXPERT formout(ipc, "changepw");
- newprompt("Enter a new password: ", pass1, -19);
- newprompt("Enter it again to confirm: ", pass2, -19);
- }
- strproc(pass1);
- strproc(pass2);
- if (!strcasecmp(pass1, pass2)) {
- CtdlIPCChangePassword(ipc, pass1, buf);
- scr_printf("%s\n", buf);
- offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
- return (0);
- } else {
- scr_printf("*** They don't match... try again.\n");
- return (1);
- }
-}
-
-
-
-/*
- * get info about the server we've connected to
- */
-void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
-{
- char buf[SIZ];
-
- CtdlIPCServerInfo(ipc, buf);
- moreprompt = ipc->ServInfo.moreprompt;
-
- /* be nice and identify ourself to the server */
- CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
- (ipc->isLocal ? "local" : CITADEL),
- (supplied_hostname) ? supplied_hostname :
- /* Look up the , in the bible if you're confused */
- (locate_host(ipc, buf), buf), buf);
-
- /* Indicate to the server that we prefer to decode Base64 and
- * quoted-printable on the client side.
- */
- if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "dont_decode") / 100 ) != 2) {
- scr_printf("ERROR: Extremely old server; MSG4 framework not supported.\n");
- logoff(ipc, 0);
- }
-
- /*
- * Tell the server what our preferred content formats are.
- *
- * Originally we preferred HTML over plain text because we can format
- * it to the reader's screen width, but since our HTML-to-text parser
- * isn't really all that great, it's probably better to just go with
- * the plain text when we have it available.
- */
- if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/plain|text/html") / 100 ) != 2) {
- scr_printf("ERROR: Extremely old server; MSG4 framework not supported.\n");
- logoff(ipc, 0);
- }
-}
-
-
-
-/*
- * Session username compare function for SortOnlineUsers()
- */
-int rwho_username_cmp(const void *rec1, const void *rec2) {
- char *u1, *u2;
-
- u1 = strchr(rec1, '|');
- u2 = strchr(rec2, '|');
-
- return strcasecmp( (u1?++u1:"") , (u2?++u2:"") );
-}
-
-
-/*
- * Idle time compare function for SortOnlineUsers()
- */
-int idlecmp(const void *rec1, const void *rec2) {
- time_t i1, i2;
-
- i1 = extract_long(rec1, 5);
- i2 = extract_long(rec2, 5);
-
- if (i1 < i2) return(1);
- if (i1 > i2) return(-1);
- return(0);
-}
-
-
-/*
- * Sort the list of online users by idle time.
- * This function frees the supplied buffer, and returns a new one
- * to the caller. The caller is responsible for freeing the returned buffer.
- *
- * If 'condense' is nonzero, multiple sessions for the same user will be
- * combined into one for brevity.
- */
-char *SortOnlineUsers(char *listing, int condense) {
- int rows;
- char *sortbuf;
- char *retbuf;
- char buf[SIZ];
- int i;
-
- rows = num_tokens(listing, '\n');
- sortbuf = malloc(rows * SIZ);
- if (sortbuf == NULL) return(listing);
- retbuf = malloc(rows * SIZ);
- if (retbuf == NULL) {
- free(sortbuf);
- return(listing);
- }
-
- /* Copy the list into a fixed-record-size array for sorting */
- for (i=0; i<rows; ++i) {
- memset(buf, 0, SIZ);
- extract_token(buf, listing, i, '\n', sizeof buf);
- memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ);
- }
-
- /* Sort by idle time */
- qsort(sortbuf, rows, SIZ, idlecmp);
-
- /* Combine multiple sessions for the same user */
- if (condense) {
- qsort(sortbuf, rows, SIZ, rwho_username_cmp);
- if (rows > 1) for (i=1; i<rows; ++i) if (i>0) {
- char u1[USERNAME_SIZE];
- char u2[USERNAME_SIZE];
- extract_token(u1, &sortbuf[(i-1)*SIZ], 1, '|', sizeof u1);
- extract_token(u2, &sortbuf[i*SIZ], 1, '|', sizeof u2);
- if (!strcasecmp(u1, u2)) {
- memcpy(&sortbuf[i*SIZ], &sortbuf[(i+1)*SIZ], (rows-i-1)*SIZ);
- --rows;
- --i;
- }
- }
-
- qsort(sortbuf, rows, SIZ, idlecmp); /* idle sort again */
- }
-
- /* Copy back to a \n delimited list */
- strcpy(retbuf, "");
- for (i=0; i<rows; ++i) {
- if (!IsEmptyStr(&sortbuf[i*SIZ])) {
- strcat(retbuf, &sortbuf[i*SIZ]);
- if (i<(rows-1)) strcat(retbuf, "\n");
- }
- }
- free(listing);
- free(sortbuf);
- return(retbuf);
-}
-
-
-
-/*
- * Display list of users currently logged on to the server
- */
-void who_is_online(CtdlIPC *ipc, int longlist)
-{
- char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
- char flags[SIZ];
- char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
- char clientsoft[SIZ];
- time_t timenow = 0;
- time_t idletime, idlehours, idlemins, idlesecs;
- int last_session = (-1);
- int skipidle = 0;
- char *listing = NULL;
- int r; /* IPC response code */
-
- if (longlist == 2) {
- longlist = 0;
- skipidle = 1;
- }
-
- if (!longlist) {
- color(BRIGHT_WHITE);
- scr_printf(" User Name Room ");
- if (screenwidth >= 80) scr_printf(" Idle From host");
- scr_printf("\n");
- color(DIM_WHITE);
- scr_printf(" ------------------------- --------------------");
- if (screenwidth >= 80) scr_printf(" ---- ------------------------");
- scr_printf("\n");
- }
- r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
- listing = SortOnlineUsers(listing, (!longlist));
- if (r / 100 == 1) {
- while (!IsEmptyStr(listing)) {
- int isidle = 0;
-
- /* Get another line */
- extract_token(buf, listing, 0, '\n', sizeof buf);
- remove_token(listing, 0, '\n');
-
- extract_token(username, buf, 1, '|', sizeof username);
- extract_token(roomname, buf, 2, '|', sizeof roomname);
- extract_token(fromhost, buf, 3, '|', sizeof fromhost);
- extract_token(clientsoft, buf, 4, '|', sizeof clientsoft);
- extract_token(flags, buf, 7, '|', sizeof flags);
-
- idletime = timenow - extract_long(buf, 5);
- idlehours = idletime / 3600;
- idlemins = (idletime - (idlehours * 3600)) / 60;
- idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
-
- if (idletime > rc_idle_threshold) {
- if (skipidle) {
- isidle = 1;
- }
- }
-
- if (longlist) {
- extract_token(actual_user, buf, 8, '|', sizeof actual_user);
- extract_token(actual_room, buf, 9, '|', sizeof actual_room);
- extract_token(actual_host, buf, 10, '|', sizeof actual_host);
-
- scr_printf(" Flags: %s\n", flags);
- scr_printf("Session: %d\n", extract_int(buf, 0));
- scr_printf(" Name: %s\n", username);
- scr_printf("In room: %s\n", roomname);
- scr_printf(" Host: %s\n", fromhost);
- scr_printf(" Client: %s\n", clientsoft);
- scr_printf(" Idle: %ld:%02ld:%02ld\n",
- (long) idlehours,
- (long) idlemins,
- (long) idlesecs);
-
- if ( (!IsEmptyStr(actual_user)&&
- !IsEmptyStr(actual_room)&&
- !IsEmptyStr(actual_host))) {
- scr_printf("(really ");
- if (!IsEmptyStr(actual_user)) scr_printf("<%s> ", actual_user);
- if (!IsEmptyStr(actual_room)) scr_printf("in <%s> ", actual_room);
- if (!IsEmptyStr(actual_host)) scr_printf("from <%s> ", actual_host);
- scr_printf(")\n");
- }
- scr_printf("\n");
-
- } else {
- if (isidle == 0) {
- if (extract_int(buf, 0) == last_session) {
- scr_printf(" ");
- }
- else {
- color(BRIGHT_MAGENTA);
- scr_printf("%-3s", flags);
- }
- last_session = extract_int(buf, 0);
- color(BRIGHT_CYAN);
- scr_printf("%-25s ", username);
- color(BRIGHT_MAGENTA);
- roomname[20] = 0;
- scr_printf("%-20s", roomname);
-
- if (screenwidth >= 80) {
- scr_printf(" ");
- if (idletime > rc_idle_threshold) {
- /* over 1000d, must be gone fishing */
- if (idlehours > 23999) {
- scr_printf("fish");
- /* over 10 days */
- } else if (idlehours > 239) {
- scr_printf("%3ldd", idlehours / 24);
- /* over 10 hours */
- } else if (idlehours > 9) {
- scr_printf("%1ldd%02ld",
- idlehours / 24,
- idlehours % 24);
- /* less than 10 hours */
- }
- else {
- scr_printf("%1ld:%02ld", idlehours, idlemins);
- }
- }
- else {
- scr_printf(" ");
- }
- scr_printf(" ");
- color(BRIGHT_CYAN);
- fromhost[24] = '\0';
- scr_printf("%-24s", fromhost);
- }
- scr_printf("\n");
- color(DIM_WHITE);
- }
- }
- }
- }
- free(listing);
-}
-
-void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
-{
- char bbb[128];
- snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
- newprompt(bbb, buf, maxlen);
-}
-
-
-
-int shift(int argc, char **argv, int start, int count) {
- int i;
-
- for (i=start; i<(argc-count); ++i) {
- argv[i] = argv[i+count];
- }
- argc = argc - count;
- return argc;
-}
-
-static void statusHook(char *s) {
- scr_printf(s);
-}
-
-/*
- * main
- */
-int main(int argc, char **argv)
-{
- int a, b, mcmd;
- char aaa[100], bbb[100];/* general purpose variables */
- char argbuf[64]; /* command line buf */
- char nonce[NONCE_SIZE];
- char *telnet_client_host = NULL;
- char *sptr, *sptr2; /* USed to extract the nonce */
- char hexstring[MD5_HEXSTRING_SIZE];
- char password[SIZ];
- struct ctdlipcmisc chek;
- struct ctdluser *myself = NULL;
- CtdlIPC* ipc; /* Our server connection */
- int r; /* IPC result code */
- int rv = 0; /* fetch but ignore syscall return value to suppress warnings */
-
- int relh=0;
- int home=0;
- char relhome[PATH_MAX]="";
- char ctdldir[PATH_MAX]=CTDLDIR;
- int lp;
-#ifdef HAVE_BACKTRACE
- eCrashParameters params;
-// eCrashSymbolTable symbol_table;
-#endif
- calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
-
-#ifdef HAVE_BACKTRACE
- bzero(¶ms, sizeof(params));
- params.filename = file_pid_paniclog;
-// panic_fd=open(file_pid_paniclog, O_APPEND|O_CREAT|O_DIRECT);
- params.filep = fopen(file_pid_paniclog, "a+");
- params.debugLevel = ECRASH_DEBUG_VERBOSE;
- params.dumpAllThreads = TRUE;
- params.useBacktraceSymbols = 1;
-/// BuildSymbolTable(&symbol_table);
-// params.symbolTable = &symbol_table;
- params.signals[0]=SIGSEGV;
- params.signals[1]=SIGILL;
- params.signals[2]=SIGBUS;
- params.signals[3]=SIGABRT;
-
- eCrash_Init(¶ms);
-#endif
- setIPCErrorPrintf(scr_printf);
- setCryptoStatusHook(statusHook);
-
- /* Permissions sanity check - don't run citadel setuid/setgid */
- if (getuid() != geteuid()) {
- scr_printf("Please do not run citadel setuid!\n");
- logoff(NULL, 3);
- } else if (getgid() != getegid()) {
- scr_printf("Please do not run citadel setgid!\n");
- logoff(NULL, 3);
- }
-
- stty_ctdl(SB_SAVE); /* Store the old terminal parameters */
- load_command_set(); /* parse the citadel.rc file */
- stty_ctdl(SB_NO_INTR); /* Install the new ones */
- /* signal(SIGHUP, dropcarr);FIXME */ /* Cleanup gracefully if carrier is dropped */
- signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */
- signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
- signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
-#ifdef SIGWINCH
- signal(SIGWINCH, scr_winch); /* Window resize signal */
-#endif
-
-#ifdef HAVE_OPENSSL
- arg_encrypt = RC_DEFAULT;
-#endif
-
- /*
- * Handle command line options as if we were called like /bin/login
- * (i.e. from in.telnetd)
- */
- for (a=0; a<argc; ++a) {
- if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
- telnet_client_host = argv[a+1];
- argc = shift(argc, argv, a, 2);
- }
- if (!strcmp(argv[a], "-x")) {
-#ifdef HAVE_OPENSSL
- arg_encrypt = RC_NO;
-#endif
- argc = shift(argc, argv, a, 1);
- }
- if (!strcmp(argv[a], "-X")) {
-#ifdef HAVE_OPENSSL
- arg_encrypt = RC_YES;
- argc = shift(argc, argv, a, 1);
-#else
- fprintf(stderr, "Not compiled with encryption support");
- return 1;
-#endif
- }
- if (!strcmp(argv[a], "-p")) {
- struct stat st;
-
- if (chdir(CTDLDIR) < 0) {
- perror("can't change to " CTDLDIR);
- logoff(NULL, 3);
- }
-
- /*
- * Drop privileges if necessary. We stat
- * citadel.config to get the uid/gid since it's
- * guaranteed to have the uid/gid we want.
- */
- if (!getuid() || !getgid()) {
- if (stat(file_citadel_config, &st) < 0) {
- perror("couldn't stat citadel.config");
- logoff(NULL, 3);
- }
- if (!getgid() && (setgid(st.st_gid) < 0)) {
- perror("couldn't change gid");
- logoff(NULL, 3);
- }
- if (!getuid() && (setuid(st.st_uid) < 0)) {
- perror("couldn't change uid");
- logoff(NULL, 3);
- }
- /*
- scr_printf("Privileges changed to uid %d gid %d\n",
- getuid(), getgid());
- */
- }
- argc = shift(argc, argv, a, 1);
- }
- }
-
-
- screen_new();
- /* Get screen dimensions. First we go to a default of 80x24.
- * Then attempt to read the actual screen size from the terminal.
- */
- check_screen_dims();
-
-
-#ifdef __CYGWIN__
- newprompt("Connect to (return for local server): ", hostbuf, 64);
-#endif
-
- scr_printf("Attaching to server...\n");
- ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
- if (!ipc) {
- error_printf("Can't connect: %s\n", strerror(errno));
- logoff(NULL, 3);
- }
-
- CtdlIPC_SetNetworkStatusCallback(ipc, scr_wait_indicator);
-
- if (!(ipc->isLocal)) {
- scr_printf("Connected to %s [%s].\n", ipc->ip_hostname, ipc->ip_address);
- }
-
- ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
-
- CtdlIPC_chat_recv(ipc, aaa);
- if (aaa[0] != '2') {
- scr_printf("%s\n", &aaa[4]);
- logoff(ipc, atoi(aaa));
- }
-
- /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
- * is zeroized.
- */
-
- if ((sptr = strchr(aaa, '<')) == NULL)
- {
- nonce[0] = '\0';
- }
- else
- {
- if ((sptr2 = strchr(sptr, '>')) == NULL)
- {
- nonce[0] = '\0';
- }
- else
- {
- sptr2++;
- *sptr2 = '\0';
- strncpy(nonce, sptr, (size_t)NONCE_SIZE);
- }
- }
-
-#ifdef HAVE_OPENSSL
- /* Evaluate encryption preferences */
- if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
- if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
- secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
- if (!secure)
- error_printf("Can't encrypt: %s\n", aaa);
- }
- }
-#endif
-
- get_serv_info(ipc, telnet_client_host);
- scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
- ipc->ServInfo.site_location);
-
- scr_printf(" pause next stop\n");
- scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
- formout(ipc, "hello"); /* print the opening greeting */
- scr_printf("\n");
-
- GSTA: /* See if we have a username and password on disk */
- if (rc_remember_passwords) {
- get_stored_password(hostbuf, portbuf, fullname, password);
- if (!IsEmptyStr(fullname)) {
- r = CtdlIPCTryLogin(ipc, fullname, aaa);
- if (r / 100 == 3) {
- if (*nonce) {
- r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
- } else {
- r = CtdlIPCTryPassword(ipc, password, aaa);
- }
- }
-
- if (r / 100 == 2) {
- load_user_info(aaa);
- goto PWOK;
- } else {
- set_stored_password(hostbuf, portbuf, "", "");
- }
- }
- }
-
- termn8 = 0;
- newnow = 0;
- do {
- if (!IsEmptyStr(rc_username)) {
- strcpy(fullname, rc_username);
- } else {
- newprompt("Enter your name: ", fullname, 29);
- }
- strproc(fullname);
- if (!strcasecmp(fullname, "new")) { /* just in case */
- scr_printf("Please enter the name you wish to log in with.\n");
- }
- } while (
- (!strcasecmp(fullname, "bbs"))
- || (!strcasecmp(fullname, "new"))
- || (IsEmptyStr(fullname)));
-
- if (!strcasecmp(fullname, "off")) {
- mcmd = 29;
- goto TERMN8;
- }
-
- /* FIXME this is a stupid way to do guest mode but it's a reasonable test harness FIXME */
- if ( (ipc->ServInfo.guest_logins) && (!strcasecmp(fullname, "guest")) ) {
- goto PWOK;
- }
-
- /* sign on to the server */
- r = CtdlIPCTryLogin(ipc, fullname, aaa);
- if (r / 100 != 3)
- goto NEWUSR;
-
- /* password authentication */
- if (!IsEmptyStr(rc_password)) {
- strcpy(password, rc_password);
- } else {
- newprompt("\rPlease enter your password: ", password, -(SIZ-1));
- }
-
- if (*nonce) {
- r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
- if (r / 100 != 2) {
- strproc(password);
- r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
- }
- } else {
- r = CtdlIPCTryPassword(ipc, password, aaa);
- if (r / 100 != 2) {
- strproc(password);
- r = CtdlIPCTryPassword(ipc, password, aaa);
- }
- }
-
- if (r / 100 == 2) {
- load_user_info(aaa);
- offer_to_remember_password(ipc, hostbuf, portbuf,
- fullname, password);
- goto PWOK;
- }
- scr_printf("<< wrong password >>\n");
- if (!IsEmptyStr(rc_password))
- logoff(ipc, 2);
- goto GSTA;
-
-NEWUSR: if (IsEmptyStr(rc_password)) {
- scr_printf("'%s' not found.\n", fullname);
- scr_printf("Type 'off' if you would like to exit.\n");
- if (ipc->ServInfo.newuser_disabled == 1) {
- goto GSTA;
- }
- scr_printf("Do you want to create a new user account called '%s'? ",
- fullname);
- if (yesno() == 0) {
- goto GSTA;
- }
- }
-
- r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
- if (r / 100 != 2) {
- scr_printf("%s\n", aaa);
- goto GSTA;
- }
- load_user_info(aaa);
-
- while (set_password(ipc) != 0);
- newnow = 1;
-
- enter_config(ipc, 1);
-
- PWOK:
- /* Switch color support on or off if we're in user mode */
- if (rc_ansi_color == 3) {
- if (userflags & US_COLOR)
- enable_color = 1;
- else
- enable_color = 0;
- }
-
- color(BRIGHT_WHITE);
- scr_printf("\n%s\nAccess level: %d (%s)\n"
- "User #%ld / Login #%d",
- fullname, axlevel, axdefs[(int) axlevel],
- usernum, timescalled);
- if (lastcall > 0L) {
- scr_printf(" / Last login: %s",
- asctime(localtime(&lastcall)));
- }
- scr_printf("\n");
-
- r = CtdlIPCMiscCheck(ipc, &chek, aaa);
- if (r / 100 == 2) {
- b = chek.newmail;
- if (b > 0) {
- color(BRIGHT_RED);
- if (b == 1)
- scr_printf("*** You have a new private message in Mail>\n");
- if (b > 1)
- scr_printf("*** You have %d new private messages in Mail>\n", b);
- color(DIM_WHITE);
- if (!IsEmptyStr(rc_gotmail_cmd)) {
- rv = system(rc_gotmail_cmd);
- if (rv)
- scr_printf("*** failed to check for mail calling %s Reason %d.\n",
- rc_gotmail_cmd, rv);
-
- }
- }
- if ((axlevel >= AxAideU) && (chek.needvalid > 0)) {
- scr_printf("*** Users need validation\n");
- }
- if (chek.needregis > 0) {
- scr_printf("*** Please register.\n");
- formout(ipc, "register");
- entregis(ipc);
- }
- }
- /* Make up some temporary filenames for use in various parts of the
- * program. Don't mess with these once they've been set, because we
- * will be unlinking them later on in the program and we don't
- * want to delete something that we didn't create. */
- CtdlMakeTempFileName(temp, sizeof temp);
- CtdlMakeTempFileName(temp2, sizeof temp2);
- CtdlMakeTempFileName(tempdir, sizeof tempdir);
-
- r = CtdlIPCGetConfig(ipc, &myself, aaa);
- set_floor_mode(ipc);
-
- /* Enter the lobby */
- dotgoto(ipc, "_BASEROOM_", 1, 0);
-
- /* Main loop for the system... user is logged in. */
- free(uglist[0]);
- uglistsize = 0;
-
- if (newnow == 1)
- readmsgs(ipc, LastMessages, ReadForward, 5);
- else
- readmsgs(ipc, NewMessages, ReadForward, 0);
-
- /* MAIN COMMAND LOOP */
- do {
- mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
-
-#ifdef TIOCGWINSZ
- check_screen_dims(); /* get screen size */
-#endif
-
- if (termn8 == 0)
- switch (mcmd) {
- case 1:
- formout(ipc, "help");
- break;
- case 4:
- entmsg(ipc, 0, ((userflags & US_EXTEDIT) ? 2 : 0), 0);
- break;
- case 36:
- entmsg(ipc, 0, 1, 0);
- break;
- case 46:
- entmsg(ipc, 0, 2, 0);
- break;
- case 78:
- entmsg(ipc, 0, ((userflags & US_EXTEDIT) ? 2 : 0), 1);
- break;
- case 5: /* <G>oto */
- updatels(ipc);
- gotonext(ipc);
- break;
- case 47: /* <A>bandon */
- gotonext(ipc);
- break;
- case 90: /* <.A>bandon */
- dotgoto(ipc, argbuf, 0, 0);
- break;
- case 58: /* <M>ail */
- updatelsa(ipc);
- dotgoto(ipc, "_MAIL_", 1, 0);
- break;
- case 20:
- if (!IsEmptyStr(argbuf)) {
- updatels(ipc);
- dotgoto(ipc, argbuf, 0, 0);
- }
- break;
- case 52:
- if (!IsEmptyStr(argbuf)) {
- dotgoto(ipc, argbuf, 0, 0);
- }
- break;
- case 95: /* what exactly is the numbering scheme supposed to be anyway? --Ford, there isn't one. -IO */
- dotungoto(ipc, argbuf);
- break;
- case 10:
- readmsgs(ipc, AllMessages, ReadForward, 0);
- break;
- case 9:
- readmsgs(ipc, LastMessages, ReadForward, 5);
- break;
- case 13:
- readmsgs(ipc, NewMessages, ReadForward, 0);
- break;
- case 11:
- readmsgs(ipc, AllMessages, ReadReverse, 0);
- break;
- case 12:
- readmsgs(ipc, OldMessages, ReadReverse, 0);
- break;
- case 71:
- readmsgs(ipc, LastMessages, ReadForward,
- atoi(argbuf));
- break;
- case 7:
- forget(ipc);
- break;
- case 18:
- subshell();
- break;
- case 38:
- updatels(ipc);
- entroom(ipc);
- break;
- case 22:
- killroom(ipc);
- break;
- case 32:
- userlist(ipc, argbuf);
- break;
- case 27:
- invite(ipc);
- break;
- case 28:
- kickout(ipc);
- break;
- case 23:
- editthisroom(ipc);
- break;
- case 14:
- roomdir(ipc);
- break;
- case 33:
- download(ipc, 0);
- break;
- case 34:
- download(ipc, 1);
- break;
- case 31:
- download(ipc, 2);
- break;
- case 43:
- download(ipc, 3);
- break;
- case 45:
- download(ipc, 4);
- break;
- case 55:
- download(ipc, 5);
- break;
- case 39:
- upload(ipc, 0);
- break;
- case 40:
- upload(ipc, 1);
- break;
- case 42:
- upload(ipc, 2);
- break;
- case 44:
- upload(ipc, 3);
- break;
- case 57:
- cli_upload(ipc);
- break;
- case 16:
- ungoto(ipc);
- break;
- case 24:
- whoknows(ipc);
- break;
- case 26:
- validate(ipc);
- break;
- case 29:
- case 30:
- updatels(ipc);
- termn8 = 1;
- break;
- case 48:
- enterinfo(ipc);
- break;
- case 49:
- readinfo(ipc);
- break;
- case 72:
- cli_image_upload(ipc, "_userpic_");
- break;
- case 73:
- cli_image_upload(ipc, "_roompic_");
- break;
-
- case 74:
- snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
- cli_image_upload(ipc, aaa);
- break;
-
- case 75:
- enternew(ipc, "roomname", aaa, 20);
- r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
- if (r / 100 != 2)
- scr_printf("\n%s\n", bbb);
- break;
- case 76:
- enternew(ipc, "hostname", aaa, 25);
- r = CtdlIPCChangeHostname(ipc, aaa, bbb);
- if (r / 100 != 2)
- scr_printf("\n%s\n", bbb);
- break;
- case 77:
- enternew(ipc, "username", aaa, 32);
- r = CtdlIPCChangeUsername(ipc, aaa, bbb);
- if (r / 100 != 2)
- scr_printf("\n%s\n", bbb);
- break;
-
- case 35:
- set_password(ipc);
- break;
-
- case 21:
- if (argbuf[0] == 0)
- strcpy(aaa, "?");
- display_help(ipc, argbuf);
- break;
-
- case 41:
- formout(ipc, "register");
- entregis(ipc);
- break;
-
- case 15:
- scr_printf("Are you sure (y/n)? ");
- if (yesno() == 1) {
- updatels(ipc);
- a = 0;
- termn8 = 1;
- }
- break;
-
- case 85:
- scr_printf("All users will be disconnected! "
- "Really terminate the server? ");
- if (yesno() == 1) {
- updatels(ipc);
- r = CtdlIPCTerminateServerNow(ipc, aaa);
- scr_printf("%s\n", aaa);
- if (r / 100 == 2) {
- a = 0;
- termn8 = 1;
- }
- }
- break;
-
- case 86:
- scr_printf("Do you really want to schedule a "
- "server shutdown? ");
- if (yesno() == 1) {
- r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
- if (r / 100 == 2) {
- if (atoi(aaa)) {
- scr_printf(
- "The Citadel server will terminate when all users are logged off.\n"
- );
- } else {
- scr_printf(
- "The Citadel server will not terminate.\n"
- );
- }
- }
- }
- break;
-
- case 87:
- network_config_management(ipc, "listrecp",
- "Message-by-message mailing list recipients");
- break;
-
- case 94:
- network_config_management(ipc, "digestrecp",
- "Digest mailing list recipients");
- break;
-
- case 89:
- network_config_management(ipc, "ignet_push_share",
- "Nodes with which we share this room");
- break;
-
- case 88:
- do_ignet_configuration(ipc);
- break;
-
- case 92:
- do_filterlist_configuration(ipc);
- break;
-
- case 6:
- gotonext(ipc);
- break;
-
- case 3:
- chatmode(ipc);
- break;
-
- case 17:
- who_is_online(ipc, 0);
- break;
-
- case 79:
- who_is_online(ipc, 1);
- break;
-
- case 91:
- who_is_online(ipc, 2);
- break;
-
- case 80:
- do_system_configuration(ipc);
- break;
-
- case 82:
- do_internet_configuration(ipc);
- break;
-
- case 84:
- quiet_mode(ipc);
- break;
-
- case 93:
- stealth_mode(ipc);
- break;
-
- case 50:
- enter_config(ipc, 2);
- break;
-
- case 37:
- enter_config(ipc, 0);
- set_floor_mode(ipc);
- break;
-
- case 59:
- enter_config(ipc, 3);
- set_floor_mode(ipc);
- break;
-
- case 60:
- gotofloor(ipc, argbuf, GF_GOTO);
- break;
-
- case 61:
- gotofloor(ipc, argbuf, GF_SKIP);
- break;
-
- case 62:
- forget_this_floor(ipc);
- break;
-
- case 63:
- create_floor(ipc);
- break;
-
- case 64:
- edit_floor(ipc);
- break;
-
- case 65:
- kill_floor(ipc);
- break;
-
- case 66:
- enter_bio(ipc);
- break;
-
- case 67:
- read_bio(ipc);
- break;
-
- case 25:
- edituser(ipc, 25);
- break;
-
- case 96:
- edituser(ipc, 96);
- break;
-
- case 8:
- knrooms(ipc, floor_mode);
- scr_printf("\n");
- break;
-
- case 68:
- knrooms(ipc, 2);
- scr_printf("\n");
- break;
-
- case 69:
- misc_server_cmd(ipc, argbuf);
- break;
-
- case 70:
- edit_system_message(ipc, argbuf);
- break;
-
- case 19:
- listzrooms(ipc);
- scr_printf("\n");
- break;
-
- case 51:
- deletefile(ipc);
- break;
-
- case 54:
- movefile(ipc);
- break;
-
- case 56:
- page_user(ipc);
- break;
-
- case 110: /* <+> Next room */
- gotoroomstep(ipc, 1, 0);
- break;
-
- case 111: /* <-> Previous room */
- gotoroomstep(ipc, 0, 0);
- break;
-
- case 112: /* <>> Next floor */
- gotofloorstep(ipc, 1, GF_GOTO);
- break;
-
- case 113: /* <<> Previous floor */
- gotofloorstep(ipc, 0, GF_GOTO);
- break;
-
- case 116: /* <.> skip to <+> Next room */
- gotoroomstep(ipc, 1, 1);
- break;
-
- case 117: /* <.> skip to <-> Previous room */
- gotoroomstep(ipc, 0, 1);
- break;
-
- case 118: /* <.> skip to <>> Next floor */
- gotofloorstep(ipc, 1, GF_SKIP);
- break;
-
- case 119: /* <.> skip to <<> Previous floor */
- gotofloorstep(ipc, 0, GF_SKIP);
- break;
-
- case 114:
- read_config(ipc);
- break;
-
- case 115:
- system_info(ipc);
- break;
-
- case 120: /* .KAnonymous */
- dotknown(ipc, 0, NULL);
- break;
-
- case 121: /* .KDirectory */
- dotknown(ipc, 1, NULL);
- break;
-
- case 122: /* .KMatch */
- dotknown(ipc, 2, argbuf);
- break;
-
- case 123: /* .KpreferredOnly */
- dotknown(ipc, 3, NULL);
- break;
-
- case 124: /* .KPrivate */
- dotknown(ipc, 4, NULL);
- break;
-
- case 125: /* .KRead only */
- dotknown(ipc, 5, NULL);
- break;
-
- case 126: /* .KShared */
- dotknown(ipc, 6, NULL);
- break;
-
- case 127: /* Configure POP3 aggregation */
- do_pop3client_configuration(ipc);
- break;
-
- case 128: /* Configure XML/RSS feed retrieval */
- do_rssclient_configuration(ipc);
- break;
-
- default:
- break;
- } /* end switch */
- } while (termn8 == 0);
-
-TERMN8: scr_printf("%s logged out.", fullname);
- termn8 = 0;
- color(ORIGINAL_PAIR);
- scr_printf("\n");
- while (marchptr != NULL) {
- remove_march(marchptr->march_name, 0);
- }
- if (mcmd == 30) {
- scr_printf("\n\nType 'off' to disconnect, or next user...\n");
- }
- CtdlIPCLogout(ipc);
- if ((mcmd == 29) || (mcmd == 15)) {
- stty_ctdl(SB_RESTORE);
- formout(ipc, "goodbye");
- logoff(ipc, 0);
- }
- /* Free the ungoto list */
- for (lp = 0; lp < uglistsize; lp++) {
- free(uglist[lp]);
- }
- uglistsize = 0;
- goto GSTA;
-
-} /* end main() */
-
+++ /dev/null
-/*
- * front end for multiuser chat
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
-#include <sys/types.h>
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#include <stdarg.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "citadel_ipc.h"
-#include "client_chat.h"
-#include "commands.h"
-#include "routines.h"
-#include "citadel_decls.h"
-#include "rooms.h"
-#include "messages.h"
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-#include "screen.h"
-
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
-extern char temp[];
-char last_paged[SIZ] = "";
-
-void chatmode(CtdlIPC *ipc)
-{
- char wbuf[SIZ];
- char buf[SIZ];
- char response[SIZ];
- char c_user[SIZ];
- char c_text[SIZ];
- char last_user[SIZ];
- int send_complete_line;
- char ch;
- int a, pos;
- int seq = 0;
-
- fd_set rfds;
- struct timeval tv;
- int retval;
-
- CtdlIPC_chat_send(ipc, "RCHT enter");
- CtdlIPC_chat_recv(ipc, buf);
- if (buf[0] != '2') {
- scr_printf("%s\n", &buf[4]);
- return;
- }
- scr_printf("Entering chat mode (type /quit to exit)\n");
-
- strcpy(buf, "");
- strcpy(wbuf, "");
- strcpy(last_user, "");
- color(BRIGHT_YELLOW);
- scr_printf("\n");
- scr_printf("> ");
- send_complete_line = 0;
-
- while (1) {
- scr_flush();
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 1;
- tv.tv_usec = 0;
- retval = select(1, &rfds, NULL, NULL, &tv);
-
- if (retval < 0) {
- color(BRIGHT_WHITE);
- scr_printf("Server gone Exiting chat mode\n");
- scr_flush();
- return;
- }
-
- /* If there's data from the keyboard... */
- if (FD_ISSET(0, &rfds)) {
- ch = scr_getc(SCR_BLOCK);
- if ((ch == 10) || (ch == 13)) {
- send_complete_line = 1;
- } else if ((ch == 8) || (ch == 127)) {
- if (!IsEmptyStr(wbuf)) {
- wbuf[strlen(wbuf) - 1] = 0;
- scr_printf("%c %c", 8, 8);
- }
- } else {
- scr_putc(ch);
- wbuf[strlen(wbuf) + 1] = 0;
- wbuf[strlen(wbuf)] = ch;
- }
- }
-
- /* if the user hit return, send the line */
- if (send_complete_line) {
-
- if (!strcasecmp(wbuf, "/quit")) {
- CtdlIPC_chat_send(ipc, "RCHT exit");
- CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
- color(BRIGHT_WHITE);
- scr_printf("\rExiting chat mode\n");
- scr_flush();
- return;
- }
-
- CtdlIPC_chat_send(ipc, "RCHT send");
- CtdlIPC_chat_recv(ipc, response);
- if (response[0] == '4') {
- CtdlIPC_chat_send(ipc, wbuf);
- CtdlIPC_chat_send(ipc, "000");
- }
- strcpy(wbuf, "");
- send_complete_line = 0;
- }
-
- /* if it's time to word wrap, send a partial line */
- if (strlen(wbuf) >= (77 - strlen(fullname))) {
- pos = 0;
- for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
- if (wbuf[a] == 32)
- pos = a;
- }
- if (pos == 0) {
- CtdlIPC_chat_send(ipc, "RCHT send");
- CtdlIPC_chat_recv(ipc, response);
- if (response[0] == '4') {
- CtdlIPC_chat_send(ipc, wbuf);
- CtdlIPC_chat_send(ipc, "000");
- }
- strcpy(wbuf, "");
- send_complete_line = 0;
- } else {
- wbuf[pos] = 0;
- CtdlIPC_chat_send(ipc, "RCHT send");
- CtdlIPC_chat_recv(ipc, response);
- if (response[0] == '4') {
- CtdlIPC_chat_send(ipc, wbuf);
- CtdlIPC_chat_send(ipc, "000");
- }
- strcpy(wbuf, &wbuf[pos + 1]);
- }
- }
-
- /* poll for incoming chat messages */
- snprintf(buf, sizeof buf, "RCHT poll|%d", seq);
- CtdlIPC_chat_send(ipc, buf);
- CtdlIPC_chat_recv(ipc, response);
-
- if (response[0] == '1') {
- seq = extract_int(&response[4], 0);
- extract_token(c_user, &response[4], 2, '|', sizeof c_user);
- while (CtdlIPC_chat_recv(ipc, c_text), strcmp(c_text, "000")) {
- scr_printf("\r%79s\r", "");
- if (!strcmp(c_user, fullname)) {
- color(BRIGHT_YELLOW);
- } else if (!strcmp(c_user, ":")) {
- color(BRIGHT_RED);
- } else {
- color(BRIGHT_GREEN);
- }
- if (strcmp(c_user, last_user)) {
- snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
- } else {
- size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
- memset(buf, ' ', i);
- safestrncpy(&buf[i], c_text, sizeof buf - i);
- }
- while (strlen(buf) < 79) {
- strcat(buf, " ");
- }
- if (strcmp(c_user, last_user)) {
- scr_printf("\r%79s\n", "");
- strcpy(last_user, c_user);
- }
- scr_printf("\r%s\n", buf);
- scr_flush();
- }
- }
- color(BRIGHT_YELLOW);
- scr_printf("\r> %s", wbuf);
- scr_flush();
- strcpy(buf, "");
- }
-}
-
-
-/*
- * send an instant message
- */
-void page_user(CtdlIPC *ipc)
-{
- char buf[SIZ], touser[SIZ], msg[SIZ];
- FILE *pagefp;
-
- strcpy(touser, last_paged);
- strprompt("Page who", touser, 30);
-
- /* old server -- use inline paging */
- if (ipc->ServInfo.paging_level == 0) {
- newprompt("Message: ", msg, 69);
- snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
- CtdlIPC_chat_send(ipc, buf);
- CtdlIPC_chat_recv(ipc, buf);
- if (!strncmp(buf, "200", 3)) {
- strcpy(last_paged, touser);
- }
- scr_printf("%s\n", &buf[4]);
- return;
- }
- /* new server -- use extended paging */
- else if (ipc->ServInfo.paging_level >= 1) {
- snprintf(buf, sizeof buf, "SEXP %s||", touser);
- CtdlIPC_chat_send(ipc, buf);
- CtdlIPC_chat_recv(ipc, buf);
- if (buf[0] != '2') {
- scr_printf("%s\n", &buf[4]);
- return;
- }
- if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL, 0) != 0) {
- scr_printf("No message sent.\n");
- return;
- }
- pagefp = fopen(temp, "r");
- unlink(temp);
- snprintf(buf, sizeof buf, "SEXP %s|-", touser);
- CtdlIPC_chat_send(ipc, buf);
- CtdlIPC_chat_recv(ipc, buf);
- if (buf[0] == '4') {
- strcpy(last_paged, touser);
- while (fgets(buf, sizeof buf, pagefp) != NULL) {
- buf[strlen(buf) - 1] = 0;
- CtdlIPC_chat_send(ipc, buf);
- }
- fclose(pagefp);
- CtdlIPC_chat_send(ipc, "000");
- scr_printf("Message sent.\n");
- } else {
- scr_printf("%s\n", &buf[4]);
- }
- }
-}
-
-
-void quiet_mode(CtdlIPC *ipc)
-{
- static int quiet = 0;
- char cret[SIZ];
- int r;
-
- r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
- if (r / 100 == 2) {
- quiet = !quiet;
- scr_printf("Quiet mode %sabled (%sother users may page you)\n",
- (quiet) ? "en" : "dis",
- (quiet) ? "no " : "");
- } else {
- scr_printf("Unable to change quiet mode: %s\n", cret);
- }
-}
-
-
-void stealth_mode(CtdlIPC *ipc)
-{
- static int stealth = 0;
- char cret[SIZ];
- int r;
-
- r = CtdlIPCStealthMode(ipc, !stealth, cret);
- if (r / 100 == 2) {
- stealth = !stealth;
- scr_printf("Stealth mode %sabled (you are %s)\n",
- (stealth) ? "en" : "dis",
- (stealth) ? "invisible" : "listed as online");
- } else {
- scr_printf("Unable to change stealth mode: %s\n", cret);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-void chatmode(CtdlIPC *ipc);
-void page_user(CtdlIPC *ipc);
-void quiet_mode(CtdlIPC *ipc);
-void stealth_mode(CtdlIPC *ipc);
-
-extern char last_paged[];
+++ /dev/null
-/*
- * Functions which allow the client to remember usernames and passwords for
- * various sites.
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <stdio.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "citadel_ipc.h"
-#include "commands.h"
-#include "client_passwords.h"
-
-#define PWFILENAME "%s/.citadel.passwords"
-
-void determine_pwfilename(char *pwfile, size_t n) {
- struct passwd *p;
-
- p = getpwuid(getuid());
- if (p == NULL) strcpy(pwfile, "");
- snprintf(pwfile, n, PWFILENAME, p->pw_dir);
-}
-
-
-/*
- * Check the password file for a host/port match; if found, stuff the user
- * name and password into the user/pass buffers
- */
-void get_stored_password(
- char *host,
- char *port,
- char *username,
- char *password) {
-
- char pwfile[PATH_MAX];
- FILE *fp;
- char buf[SIZ];
- char buf64[SIZ];
- char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
-
- strcpy(username, "");
- strcpy(password, "");
-
- determine_pwfilename(pwfile, sizeof pwfile);
- if (IsEmptyStr(pwfile)) return;
-
- fp = fopen(pwfile, "r");
- if (fp == NULL) return;
- while (fgets(buf64, sizeof buf64, fp) != NULL) {
- CtdlDecodeBase64(buf, buf64, sizeof(buf64));
- extract_token(hostbuf, buf, 0, '|', sizeof hostbuf);
- extract_token(portbuf, buf, 1, '|', sizeof portbuf);
- extract_token(ubuf, buf, 2, '|', sizeof ubuf);
- extract_token(pbuf, buf, 3, '|', sizeof pbuf);
-
- if (!strcasecmp(hostbuf, host)) {
- if (!strcasecmp(portbuf, port)) {
- strcpy(username, ubuf);
- strcpy(password, pbuf);
- }
- }
- }
- fclose(fp);
-}
-
-
-/*
- * Set (or clear) stored passwords.
- */
-void set_stored_password(
- char *host,
- char *port,
- char *username,
- char *password) {
-
- char pwfile[PATH_MAX];
- FILE *fp, *oldfp;
- char buf[SIZ];
- char buf64[SIZ];
- char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
-
- determine_pwfilename(pwfile, sizeof pwfile);
- if (IsEmptyStr(pwfile)) return;
-
- oldfp = fopen(pwfile, "r");
- if (oldfp == NULL) oldfp = fopen("/dev/null", "r");
- unlink(pwfile);
- fp = fopen(pwfile, "w");
- if (fp == NULL) fp = fopen("/dev/null", "w");
- while (fgets(buf64, sizeof buf64, oldfp) != NULL) {
- CtdlDecodeBase64(buf, buf64, sizeof(buf64));
- extract_token(hostbuf, buf, 0, '|', sizeof hostbuf);
- extract_token(portbuf, buf, 1, '|', sizeof portbuf);
- extract_token(ubuf, buf, 2, '|', sizeof ubuf);
- extract_token(pbuf, buf, 3, '|', sizeof pbuf);
-
- if ( (strcasecmp(hostbuf, host))
- || (strcasecmp(portbuf, port)) ) {
- snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
- hostbuf, portbuf, ubuf, pbuf);
- CtdlEncodeBase64(buf64, buf, strlen(buf), 0);
- fprintf(fp, "%s\n", buf64);
- }
- }
- if (!IsEmptyStr(username)) {
- snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
- host, port, username, password);
- CtdlEncodeBase64(buf64, buf, strlen(buf), 0);
- fprintf(fp, "%s\n", buf64);
- }
- fclose(oldfp);
- fclose(fp);
- chmod(pwfile, 0600);
-}
-
-
-/*
- * Set the password if the user wants to, clear it otherwise
- */
-void offer_to_remember_password(CtdlIPC *ipc,
- char *host,
- char *port,
- char *username,
- char *password) {
-
- if (rc_remember_passwords) {
- if (boolprompt("Remember username/password for this site", 0)) {
- set_stored_password(host, port, username, password);
- }
- else {
- set_stored_password(host, port, "", "");
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-
-void determine_pwfilename(char *pwfile, size_t n);
-void get_stored_password(
- char *host,
- char *port,
- char *username,
- char *password);
-void set_stored_password(
- char *host,
- char *port,
- char *username,
- char *password);
-void offer_to_remember_password(CtdlIPC *ipc,
- char *host,
- char *port,
- char *username,
- char *password);
+++ /dev/null
-/*
- * This file contains functions which implement parts of the
- * text-mode user interface.
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#else
-#include <sgtty.h>
-#endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
-#ifdef THREADED_CLIENT
-#include <pthread.h>
-#endif
-
-#include <signal.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "citadel_ipc.h"
-#include "commands.h"
-#include "messages.h"
-#include "citadel_decls.h"
-#include "routines.h"
-#include "routines2.h"
-#include "rooms.h"
-#include "client_chat.h"
-#include "citadel_dirs.h"
-#include "tuiconfig.h"
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-#include "screen.h"
-#include "ecrash.h"
-
-struct citcmd {
- struct citcmd *next;
- int c_cmdnum;
- int c_axlevel;
- char c_keys[5][64];
-};
-
-#define IFNEXPERT if ((userflags&US_EXPERT)==0)
-
-
-int rc_exp_beep;
-char rc_exp_cmd[1024];
-int rc_allow_attachments;
-int rc_display_message_numbers;
-int rc_force_mail_prompts;
-int rc_remember_passwords;
-int rc_ansi_color;
-int rc_color_use_bg;
-int rc_prompt_control = 0;
-time_t rc_idle_threshold = (time_t)900;
-char rc_url_cmd[SIZ];
-char rc_open_cmd[SIZ];
-char rc_gotmail_cmd[SIZ];
-
-int next_lazy_cmd = 5;
-
-extern int screenwidth, screenheight;
-extern int termn8;
-extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
-
-struct citcmd *cmdlist = NULL;
-
-
-/* these variables are local to this module */
-char keepalives_enabled = KA_YES; /* send NOOPs to server when idle */
-int ok_to_interrupt = 0; /* print instant msgs asynchronously */
-time_t AnsiDetect; /* when did we send the detect code? */
-int enable_color = 0; /* nonzero for ANSI color */
-
-
-
-
-/*
- * If an interesting key has been pressed, return its value, otherwise 0
- */
-char was_a_key_pressed(void) {
- fd_set rfds;
- struct timeval tv;
- int the_character;
- int retval;
-
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- retval = select(1, &rfds, NULL, NULL, &tv);
-
- /* Careful! Disable keepalives during keyboard polling; we're probably
- * in the middle of a data transfer from the server, in which case
- * sending a NOOP would throw the client protocol out of sync.
- */
- if ((retval > 0) && FD_ISSET(0, &rfds)) {
- set_keepalives(KA_NO);
- the_character = inkey();
- set_keepalives(KA_YES);
- }
- else {
- the_character = 0;
- }
- return(the_character);
-}
-
-
-
-
-
-/*
- * print_instant() - print instant messages if there are any
- */
-void print_instant(void)
-{
- char buf[1024];
- FILE *outpipe;
- time_t timestamp;
- struct tm stamp;
- int flags = 0;
- char sender[64];
- char node[64];
- char *listing = NULL;
- int r; /* IPC result code */
-
- if (instant_msgs == 0)
- return;
-
- if (rc_exp_beep) {
- ctdl_beep();
- }
- if (IsEmptyStr(rc_exp_cmd)) {
- color(BRIGHT_RED);
- scr_printf("\r---");
- }
-
- while (instant_msgs != 0) {
- r = CtdlIPCGetInstantMessage(ipc_for_signal_handlers, &listing, buf);
- if (r / 100 != 1)
- return;
-
- instant_msgs = extract_int(buf, 0);
- timestamp = extract_long(buf, 1);
- flags = extract_int(buf, 2);
- extract_token(sender, buf, 3, '|', sizeof sender);
- extract_token(node, buf, 4, '|', sizeof node);
- strcpy(last_paged, sender);
-
- localtime_r(×tamp, &stamp);
-
- /* If the page is a Logoff Request, honor it. */
- if (flags & 2) {
- termn8 = 1;
- return;
- }
-
- if (!IsEmptyStr(rc_exp_cmd)) {
- outpipe = popen(rc_exp_cmd, "w");
- if (outpipe != NULL) {
- /* Header derived from flags */
- if (flags & 2)
- fprintf(outpipe,
- "Please log off now, as requested ");
- else if (flags & 1)
- fprintf(outpipe, "Broadcast message ");
- else if (flags & 4)
- fprintf(outpipe, "Chat request ");
- else
- fprintf(outpipe, "Message ");
- /* Timestamp. Can this be improved? */
- if (stamp.tm_hour == 0 || stamp.tm_hour == 12)
- fprintf(outpipe, "at 12:%02d%cm",
- stamp.tm_min,
- stamp.tm_hour ? 'p' : 'a');
- else if (stamp.tm_hour > 12) /* pm */
- fprintf(outpipe, "at %d:%02dpm",
- stamp.tm_hour - 12,
- stamp.tm_min);
- else /* am */
- fprintf(outpipe, "at %d:%02dam",
- stamp.tm_hour, stamp.tm_min);
- fprintf(outpipe, " from %s", sender);
- if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32))
- fprintf(outpipe, " @%s", node);
- fprintf(outpipe, ":\n%s\n", listing);
- pclose(outpipe);
- if (instant_msgs == 0)
- return;
- continue;
- }
- }
- /* fall back to built-in instant message display */
- scr_printf("\n");
-
- /* Header derived from flags */
- if (flags & 2)
- scr_printf("Please log off now, as requested ");
- else if (flags & 1)
- scr_printf("Broadcast message ");
- else if (flags & 4)
- scr_printf("Chat request ");
- else
- scr_printf("Message ");
-
- /* Timestamp. Can this be improved? */
- if (stamp.tm_hour == 0 || stamp.tm_hour == 12)/* 12am/12pm */
- scr_printf("at 12:%02d%cm", stamp.tm_min,
- stamp.tm_hour ? 'p' : 'a');
- else if (stamp.tm_hour > 12) /* pm */
- scr_printf("at %d:%02dpm",
- stamp.tm_hour - 12, stamp.tm_min);
- else /* am */
- scr_printf("at %d:%02dam", stamp.tm_hour, stamp.tm_min);
-
- /* Sender */
- scr_printf(" from %s", sender);
-
- /* Remote node, if any */
- if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32))
- scr_printf(" @%s", node);
-
- scr_printf(":\n");
- fmout(screenwidth, NULL, listing, NULL, 0);
- free(listing);
-
- }
- scr_printf("\n---\n");
- color(BRIGHT_WHITE);
-
-
-}
-
-
-void set_keepalives(int s)
-{
- keepalives_enabled = (char) s;
-}
-
-/*
- * This loop handles the "keepalive" messages sent to the server when idling.
- */
-
-static time_t idlet = 0;
-static void really_do_keepalive(void) {
-
- time(&idlet);
-
- /* This may sometimes get called before we are actually connected
- * to the server. Don't do anything if we aren't connected. -IO
- */
- if (!ipc_for_signal_handlers)
- return;
-
- /* If full keepalives are enabled, send a NOOP to the server and
- * wait for a response.
- */
- if (keepalives_enabled == KA_YES) {
- CtdlIPCNoop(ipc_for_signal_handlers);
- if (instant_msgs > 0) {
- if (ok_to_interrupt == 1) {
- scr_printf("\r%64s\r", "");
- print_instant();
- scr_printf("%s%c ", room_name,
- room_prompt(room_flags));
- scr_flush();
- }
- }
- }
-
- /* If half keepalives are enabled, send a QNOP to the server (if the
- * server supports it) and then do nothing.
- */
- if ( (keepalives_enabled == KA_HALF)
- && (ipc_for_signal_handlers->ServInfo.supports_qnop > 0) ) {
- CtdlIPC_chat_send(ipc_for_signal_handlers, "QNOP");
- }
-}
-
-/* threaded nonblocking keepalive stuff starts here. I'm going for a simple
- encapsulated interface; in theory there should be no need to touch these
- globals outside of the async_ka_* functions. */
-
-#ifdef THREADED_CLIENT
-static pthread_t ka_thr_handle;
-static int ka_thr_active = 0;
-static int async_ka_enabled = 0;
-
-static void *ka_thread(void *arg)
-{
-#ifdef HAVE_BACKTRACE
- char threadName[256];
-
- // Set up our name
- sprintf(threadName, "ka_Thread n");
-
- // Register for tracing
- eCrash_RegisterThread(threadName, 0);
-#endif
- really_do_keepalive();
- pthread_detach(ka_thr_handle);
- ka_thr_active = 0;
-
-#ifdef HAVE_BACKTRACE
- eCrash_UnregisterThread();
-#endif
- return NULL;
-}
-
-/* start up a thread to handle a keepalive in the background */
-static void async_ka_exec(void)
-{
- if (!ka_thr_active) {
- ka_thr_active = 1;
- if (pthread_create(&ka_thr_handle, NULL, ka_thread, NULL)) {
- perror("pthread_create");
- exit(1);
- }
- }
-}
-#endif /* THREADED_CLIENT */
-
-/* I changed this from static to not because I need to call it from
- screen.c, either that or make something in screen.c not static.
- Fix it how you like. Why all the staticness? stu */
-
-void do_keepalive(void)
-{
- time_t now;
-
- time(&now);
- if ((now - idlet) < ((long) S_KEEPALIVE))
- return;
-
- /* Do a space-backspace to keep telnet sessions from idling out */
- scr_printf(" %c", 8);
- scr_flush();
-
-#ifdef THREADED_CLIENT
- if (async_ka_enabled)
- async_ka_exec();
- else
-#endif
- really_do_keepalive();
-}
-
-
-/* Now the actual async-keepalve API that we expose to higher levels:
- async_ka_start() and async_ka_end(). These do nothing when we don't have
- threading enabled, so we avoid sprinkling ifdef's throughout the code. */
-
-/* wait for a background keepalive to complete. this must be done before
- attempting any further server requests! */
-void async_ka_end(void)
-{
-#ifdef THREADED_CLIENT
- if (ka_thr_active)
- pthread_join(ka_thr_handle, NULL);
-
- async_ka_enabled--;
-#endif
-}
-
-/* tell do_keepalive() that keepalives are asynchronous. */
-void async_ka_start(void)
-{
-#ifdef THREADED_CLIENT
- async_ka_enabled++;
-#endif
-}
-
-
-int inkey(void)
-{ /* get a character from the keyboard, with */
- int a; /* the watchdog timer in effect if necessary */
- fd_set rfds;
- struct timeval tv;
- time_t start_time;
-
- scr_flush();
- time(&start_time);
-
- do {
- /* This loop waits for keyboard input. If the keepalive
- * timer expires, it sends a keepalive to the server if
- * necessary and then waits again.
- */
- do {
- do_keepalive();
-
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = S_KEEPALIVE;
- tv.tv_usec = 0;
-
- select(1, &rfds, NULL, NULL, &tv);
- } while (!FD_ISSET(0, &rfds));
-
- /* At this point, there's input, so fetch it.
- * (There's a hole in the bucket...)
- */
- a = scr_getc(SCR_BLOCK);
- if (a == 127) {
- a = 8;
- }
- if (a == 13) {
- a = 10;
- }
- } while (a == 0);
- return (a);
-}
-
-
-int yesno(void)
-{ /* Returns 1 for yes, 0 for no */
- int a;
- while (1) {
- a = inkey();
- a = tolower(a);
- if (a == 'y') {
- scr_printf("Yes\n");
- return (1);
- }
- if (a == 'n') {
- scr_printf("No\n");
- return (0);
- }
- }
-}
-
-/* Returns 1 for yes, 0 for no, arg is default value */
-int yesno_d(int d)
-{
- int a;
- while (1) {
- a = inkey();
- a = tolower(a);
- if (a == 10)
- a = (d ? 'y' : 'n');
- if (a == 'y') {
- scr_printf("Yes\n");
- return (1);
- }
- if (a == 'n') {
- scr_printf("No\n");
- return (0);
- }
- }
-}
-
-
-
-
-/*
- * Function to read a line of text from the terminal.
- *
- * string Pointer to string buffer
- * lim Maximum length
- * noshow Echo asterisks instead of keystrokes?
- * bs Allow backspacing out of the prompt? (returns -1 if this happens)
- *
- * returns: string length
- */
-int ctdl_getline(char *string, int lim, int noshow, int bs)
-{
- int pos = strlen(string);
- int ch;
-
- async_ka_start();
- if (noshow && !IsEmptyStr(string)) {
- int num_stars = strlen(string);
- while (num_stars--) {
- scr_putc('*');
- }
- }
- else {
- scr_printf("%s", string);
- }
-
- while(1) {
- ch = inkey();
-
- if ((ch == 8) && (pos > 0)) { /* backspace */
- --pos;
- scr_putc(8); scr_putc(32); scr_putc(8);
- }
-
- else if ((ch == 8) && (pos == 0) && (bs)) { /* backspace out of the prompt */
- async_ka_end();
- return(-1);
- }
-
- else if ((ch == 23) && (pos > 0)) { /* Ctrl-W deletes a word */
- while ((pos > 0) && !isspace(string[pos])) {
- --pos;
- scr_putc(8); scr_putc(32); scr_putc(8);
- }
- while ((pos > 0) && !isspace(string[pos-1])) {
- --pos;
- scr_putc(8); scr_putc(32); scr_putc(8);
- }
- }
-
- else if (ch == 10) { /* return */
- string[pos] = 0;
- scr_printf("\n");
- async_ka_end();
- return(pos);
- }
-
- else if (isprint(ch)) { /* payload characters */
- scr_putc((noshow ? '*' : ch));
- string[pos] = ch;
- ++pos;
- }
- }
-}
-
-
-/*
- * newprompt() prompt for a string, print the existing value, and
- * allow the user to press return to keep it...
- * If len is negative, pass the "noshow" flag to ctdl_getline()
- */
-void strprompt(char *prompt, char *str, int len)
-{
- print_instant();
- color(DIM_WHITE);
- scr_printf("%s", prompt);
- color(DIM_WHITE);
- scr_printf(": ");
- color(BRIGHT_CYAN);
- ctdl_getline(str, abs(len), (len<0), 0);
- color(DIM_WHITE);
-}
-
-/*
- * boolprompt() - prompt for a yes/no, print the existing value and
- * allow the user to press return to keep it...
- */
-int boolprompt(char *prompt, int prev_val)
-{
- int r;
-
- color(DIM_WHITE);
- scr_printf("%s ", prompt);
- color(DIM_MAGENTA);
- scr_printf("[");
- color(BRIGHT_MAGENTA);
- scr_printf("%s", (prev_val ? "Yes" : "No"));
- color(DIM_MAGENTA);
- scr_printf("]: ");
- color(BRIGHT_CYAN);
- r = (yesno_d(prev_val));
- color(DIM_WHITE);
- return r;
-}
-
-/*
- * intprompt() - like strprompt(), except for an integer
- * (note that it RETURNS the new value!)
- */
-int intprompt(char *prompt, int ival, int imin, int imax)
-{
- char buf[16];
- int i;
- int p;
-
- do {
- i = ival;
- snprintf(buf, sizeof buf, "%d", i);
- strprompt(prompt, buf, 15);
- i = atoi(buf);
- for (p=0; !IsEmptyStr(&buf[p]); ++p) {
- if ( (!isdigit(buf[p]))
- && ( (buf[p]!='-') || (p!=0) ) )
- i = imin - 1;
- }
- if (i < imin)
- scr_printf("*** Must be no less than %d.\n", imin);
- if (i > imax)
- scr_printf("*** Must be no more than %d.\n", imax);
- } while ((i < imin) || (i > imax));
- return (i);
-}
-
-/*
- * newprompt() prompt for a string with no existing value
- * (clears out string buffer first)
- * If len is negative, pass the "noshow" flag to ctdl_getline()
- */
-void newprompt(char *prompt, char *str, int len)
-{
- str[0] = 0;
- color(BRIGHT_MAGENTA);
- scr_printf("%s", prompt);
- color(DIM_MAGENTA);
- ctdl_getline(str, abs(len), (len<0), 0);
- color(DIM_WHITE);
-}
-
-
-int lkey(void)
-{ /* returns a lower case value */
- int a;
- a = inkey();
- if (isupper(a))
- a = tolower(a);
- return (a);
-}
-
-/*
- * parse the citadel.rc file
- */
-void load_command_set(void)
-{
- FILE *ccfile;
- char buf[1024];
- struct citcmd *cptr;
- struct citcmd *lastcmd = NULL;
- int a, d;
- int b = 0;
-
- /* first, set up some defaults for non-required variables */
-
- strcpy(editor_path, "");
- strcpy(printcmd, "");
- strcpy(imagecmd, "");
- strcpy(rc_username, "");
- strcpy(rc_password, "");
- rc_floor_mode = 0;
- rc_exp_beep = 1;
- rc_allow_attachments = 0;
- rc_remember_passwords = 0;
- strcpy(rc_exp_cmd, "");
- rc_display_message_numbers = 0;
- rc_force_mail_prompts = 0;
- rc_ansi_color = 0;
- rc_color_use_bg = 0;
- strcpy(rc_url_cmd, "");
- strcpy(rc_open_cmd, "");
- strcpy(rc_gotmail_cmd, "");
-#ifdef HAVE_OPENSSL
- rc_encrypt = RC_DEFAULT;
-#endif
-
- /* now try to open the citadel.rc file */
-
- ccfile = NULL;
- if (getenv("HOME") != NULL) {
- snprintf(buf, sizeof buf, "%s/.citadelrc", getenv("HOME"));
- ccfile = fopen(buf, "r");
- }
- if (ccfile == NULL) {
- ccfile = fopen(file_citadel_rc, "r");
- }
- if (ccfile == NULL) {
- ccfile = fopen("/etc/citadel.rc", "r");
- }
- if (ccfile == NULL) {
- ccfile = fopen("./citadel.rc", "r");
- }
- if (ccfile == NULL) {
- perror("commands: cannot open citadel.rc");
- logoff(NULL, 3);
- }
- while (fgets(buf, sizeof buf, ccfile) != NULL) {
- while ((!IsEmptyStr(buf)) ? (isspace(buf[strlen(buf) - 1])) : 0)
- buf[strlen(buf) - 1] = 0;
-
- if (!strncasecmp(buf, "encrypt=", 8)) {
- if (!strcasecmp(&buf[8], "yes")) {
-#ifdef HAVE_OPENSSL
- rc_encrypt = RC_YES;
-#else
- fprintf(stderr, "citadel.rc requires encryption support but citadel is not compiled with OpenSSL");
- logoff(NULL, 3);
-#endif
- }
-#ifdef HAVE_OPENSSL
- else if (!strcasecmp(&buf[8], "no")) {
- rc_encrypt = RC_NO;
- }
- else if (!strcasecmp(&buf[8], "default")) {
- rc_encrypt = RC_DEFAULT;
- }
-#endif
- }
-
- if (!strncasecmp(buf, "editor=", 7)) {
- strcpy(editor_path, &buf[7]);
- }
-
- if (!strncasecmp(buf, "printcmd=", 9))
- strcpy(printcmd, &buf[9]);
-
- if (!strncasecmp(buf, "imagecmd=", 9))
- strcpy(imagecmd, &buf[9]);
-
- if (!strncasecmp(buf, "expcmd=", 7))
- strcpy(rc_exp_cmd, &buf[7]);
-
- if (!strncasecmp(buf, "use_floors=", 11)) {
- if (!strcasecmp(&buf[11], "yes"))
- rc_floor_mode = RC_YES;
- if (!strcasecmp(&buf[11], "no"))
- rc_floor_mode = RC_NO;
- if (!strcasecmp(&buf[11], "default"))
- rc_floor_mode = RC_DEFAULT;
- }
- if (!strncasecmp(buf, "beep=", 5)) {
- rc_exp_beep = atoi(&buf[5]);
- }
- if (!strncasecmp(buf, "allow_attachments=", 18)) {
- rc_allow_attachments = atoi(&buf[18]);
- }
- if (!strncasecmp(buf, "idle_threshold=", 15)) {
- rc_idle_threshold = atol(&buf[15]);
- }
- if (!strncasecmp(buf, "remember_passwords=", 19)) {
- rc_remember_passwords = atoi(&buf[19]);
- }
- if (!strncasecmp(buf, "display_message_numbers=", 24)) {
- rc_display_message_numbers = atoi(&buf[24]);
- }
- if (!strncasecmp(buf, "force_mail_prompts=", 19)) {
- rc_force_mail_prompts = atoi(&buf[19]);
- }
- if (!strncasecmp(buf, "ansi_color=", 11)) {
- if (!strncasecmp(&buf[11], "on", 2))
- rc_ansi_color = 1;
- if (!strncasecmp(&buf[11], "auto", 4))
- rc_ansi_color = 2; /* autodetect */
- if (!strncasecmp(&buf[11], "user", 4))
- rc_ansi_color = 3; /* user config */
- }
- if (!strncasecmp(buf, "status_line=", 12)) {
- if (!strncasecmp(&buf[12], "on", 2))
- enable_status_line = 1;
- }
- if (!strncasecmp(buf, "use_background=", 15)) {
- if (!strncasecmp(&buf[15], "on", 2))
- rc_color_use_bg = 9;
- }
- if (!strncasecmp(buf, "prompt_control=", 15)) {
- if (!strncasecmp(&buf[15], "on", 2))
- rc_prompt_control = 1;
- if (!strncasecmp(&buf[15], "user", 4))
- rc_prompt_control = 3; /* user config */
- }
- if (!strncasecmp(buf, "username=", 9))
- strcpy(rc_username, &buf[9]);
-
- if (!strncasecmp(buf, "password=", 9))
- strcpy(rc_password, &buf[9]);
-
- if (!strncasecmp(buf, "urlcmd=", 7))
- strcpy(rc_url_cmd, &buf[7]);
-
- if (!strncasecmp(buf, "opencmd=", 7))
- strcpy(rc_open_cmd, &buf[8]);
-
- if (!strncasecmp(buf, "gotmailcmd=", 11))
- strcpy(rc_gotmail_cmd, &buf[11]);
-
- if (!strncasecmp(buf, "cmd=", 4)) {
- strcpy(buf, &buf[4]);
-
- cptr = (struct citcmd *) malloc(sizeof(struct citcmd));
-
- cptr->c_cmdnum = atoi(buf);
- for (d = strlen(buf); d >= 0; --d)
- if (buf[d] == ',')
- b = d;
- strcpy(buf, &buf[b + 1]);
-
- cptr->c_axlevel = atoi(buf);
- for (d = strlen(buf); d >= 0; --d)
- if (buf[d] == ',')
- b = d;
- strcpy(buf, &buf[b + 1]);
-
- for (a = 0; a < 5; ++a)
- cptr->c_keys[a][0] = 0;
-
- a = 0;
- b = 0;
- buf[strlen(buf) + 1] = 0;
- while (!IsEmptyStr(buf)) {
- b = strlen(buf);
- for (d = strlen(buf); d >= 0; --d)
- if (buf[d] == ',')
- b = d;
- strncpy(cptr->c_keys[a], buf, b);
- cptr->c_keys[a][b] = 0;
- if (buf[b] == ',')
- strcpy(buf, &buf[b + 1]);
- else
- strcpy(buf, "");
- ++a;
- }
-
- cptr->next = NULL;
- if (cmdlist == NULL)
- cmdlist = cptr;
- else
- lastcmd->next = cptr;
- lastcmd = cptr;
- }
- }
- fclose(ccfile);
-}
-
-
-
-/*
- * return the key associated with a command
- */
-char keycmd(char *cmdstr)
-{
- int a;
-
- for (a = 0; !IsEmptyStr(&cmdstr[a]); ++a)
- if (cmdstr[a] == '&')
- return (tolower(cmdstr[a + 1]));
- return (0);
-}
-
-
-/*
- * Output the string from a key command without the ampersand
- * "mode" should be set to 0 for normal or 1 for <C>ommand key highlighting
- */
-char *cmd_expand(char *strbuf, int mode)
-{
- int a;
- static char exp[64];
- char buf[1024];
-
- strcpy(exp, strbuf);
-
- for (a = 0; exp[a]; ++a) {
- if (strbuf[a] == '&') {
-
- /* dont echo these non mnemonic command keys */
- int noecho = strbuf[a+1] == '<' || strbuf[a+1] == '>' || strbuf[a+1] == '+' || strbuf[a+1] == '-';
-
- if (mode == 0) {
- strcpy(&exp[a], &exp[a + 1 + noecho]);
- }
- if (mode == 1) {
- exp[a] = '<';
- strcpy(buf, &exp[a + 2]);
- exp[a + 2] = '>';
- exp[a + 3] = 0;
- strcat(exp, buf);
- }
- }
- if (!strncmp(&exp[a], "^r", 2)) {
- strcpy(buf, exp);
- strcpy(&exp[a], room_name);
- strcat(exp, &buf[a + 2]);
- }
- if (!strncmp(&exp[a], "^c", 2)) {
- exp[a] = ',';
- strcpy(&exp[a + 1], &exp[a + 2]);
- }
- }
-
- return (exp);
-}
-
-
-
-/*
- * Comparison function to determine if entered commands match a
- * command loaded from the config file.
- */
-int cmdmatch(char *cmdbuf, struct citcmd *cptr, int ncomp)
-{
- int a;
- int cmdax;
-
- cmdax = 0;
- if (is_room_aide)
- cmdax = 1;
- if (axlevel >= 6)
- cmdax = 2;
-
- for (a = 0; a < ncomp; ++a) {
- if ((tolower(cmdbuf[a]) != keycmd(cptr->c_keys[a]))
- || (cptr->c_axlevel > cmdax))
- return (0);
- }
- return (1);
-}
-
-
-/*
- * This function returns 1 if a given command requires a string input
- */
-int requires_string(struct citcmd *cptr, int ncomp)
-{
- int a;
- char buf[64];
-
- strcpy(buf, cptr->c_keys[ncomp - 1]);
- for (a = 0; !IsEmptyStr(&buf[a]); ++a) {
- if (buf[a] == ':')
- return (1);
- }
- return (0);
-}
-
-
-/*
- * Input a command at the main prompt.
- * This function returns an integer command number. If the command prompts
- * for a string then it is placed in the supplied buffer.
- */
-int getcmd(CtdlIPC *ipc, char *argbuf)
-{
- char cmdbuf[5];
- int cmdspaces[5];
- int cmdpos;
- int ch;
- int a;
- int got;
- int this_lazy_cmd;
- struct citcmd *cptr;
-
- /*
- * Starting a new command now, so set sigcaught to 0. This variable
- * is set to nonzero (usually NEXT_KEY or STOP_KEY) if a command has
- * been interrupted by a keypress.
- */
- sigcaught = 0;
-
- /* Switch color support on or off if we're in user mode */
- if (rc_ansi_color == 3) {
- if (userflags & US_COLOR)
- enable_color = 1;
- else
- enable_color = 0;
- }
- /* if we're running in idiot mode, display a cute little menu */
- IFNEXPERT formout(ipc, "mainmenu");
-
- print_instant();
- strcpy(argbuf, "");
- cmdpos = 0;
- for (a = 0; a < 5; ++a)
- cmdbuf[a] = 0;
- /* now the room prompt... */
- ok_to_interrupt = 1;
- color(BRIGHT_WHITE);
- scr_printf("\n%s", room_name);
- color(DIM_WHITE);
- scr_printf("%c ", room_prompt(room_flags));
-
- while (1) {
- ch = inkey();
- ok_to_interrupt = 0;
-
- /* Handle the backspace key, but only if there's something
- * to backspace over...
- */
- if ((ch == 8) && (cmdpos > 0)) {
- back(cmdspaces[cmdpos - 1] + 1);
- cmdbuf[cmdpos] = 0;
- --cmdpos;
- }
- /* Spacebar invokes "lazy traversal" commands */
- if ((ch == 32) && (cmdpos == 0)) {
- this_lazy_cmd = next_lazy_cmd;
- if (this_lazy_cmd == 13)
- next_lazy_cmd = 5;
- if (this_lazy_cmd == 5)
- next_lazy_cmd = 13;
- for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
- if (cptr->c_cmdnum == this_lazy_cmd) {
- for (a = 0; a < 5; ++a)
- if (cptr->c_keys[a][0] != 0)
- scr_printf("%s ", cmd_expand(
- cptr->c_keys[a], 0));
- scr_printf("\n");
- return (this_lazy_cmd);
- }
- }
- scr_printf("\n");
- return (this_lazy_cmd);
- }
- /* Otherwise, process the command */
- cmdbuf[cmdpos] = tolower(ch);
-
- for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
- if (cmdmatch(cmdbuf, cptr, cmdpos + 1)) {
-
- scr_printf("%s", cmd_expand(cptr->c_keys[cmdpos], 0));
- cmdspaces[cmdpos] = strlen(
- cmd_expand(cptr->c_keys[cmdpos], 0));
- if (cmdpos < 4)
- if ((cptr->c_keys[cmdpos + 1]) != 0)
- scr_putc(' ');
- ++cmdpos;
- }
- }
-
- for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
- if (cmdmatch(cmdbuf, cptr, 5)) {
- /* We've found our command. */
- if (requires_string(cptr, cmdpos)) {
- argbuf[0] = 0;
- ctdl_getline(argbuf, 64, 0, 0);
- } else {
- scr_printf("\n");
- }
-
- /* If this command is one that changes rooms,
- * then the next lazy-command (space bar)
- * should be "read new" instead of "goto"
- */
- if ((cptr->c_cmdnum == 5)
- || (cptr->c_cmdnum == 6)
- || (cptr->c_cmdnum == 47)
- || (cptr->c_cmdnum == 52)
- || (cptr->c_cmdnum == 16)
- || (cptr->c_cmdnum == 20))
- next_lazy_cmd = 13;
-
- /* If this command is "read new"
- * then the next lazy-command (space bar)
- * should be "goto"
- */
- if (cptr->c_cmdnum == 13)
- next_lazy_cmd = 5;
-
- return (cptr->c_cmdnum);
-
- }
- }
-
- if (ch == '?') {
- scr_printf("\rOne of ... \n");
- for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
- if (cmdmatch(cmdbuf, cptr, cmdpos)) {
- for (a = 0; a < 5; ++a) {
- keyopt(cmd_expand(cptr->c_keys[a], 1));
- scr_printf(" ");
- }
- scr_printf("\n");
- }
- }
- sigcaught = 0;
-
- scr_printf("\n%s%c ", room_name, room_prompt(room_flags));
- got = 0;
- for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
- if ((got == 0) && (cmdmatch(cmdbuf, cptr, cmdpos))) {
- for (a = 0; a < cmdpos; ++a) {
- scr_printf("%s ",
- cmd_expand(cptr->c_keys[a], 0));
- }
- got = 1;
- }
- }
- }
- }
-
-}
-
-
-
-
-
-/*
- * set tty modes. commands are:
- *
- * 01- set to Citadel mode
- * 2 - save current settings for later restoral
- * 3 - restore saved settings
- */
-#ifdef HAVE_TERMIOS_H
-void stty_ctdl(int cmd)
-{ /* SysV version of stty_ctdl() */
- struct termios live;
- static struct termios saved_settings;
- static int last_cmd = 0;
-
- if (cmd == SB_LAST)
- cmd = last_cmd;
- else
- last_cmd = cmd;
-
- if ((cmd == 0) || (cmd == 1)) {
- tcgetattr(0, &live);
- live.c_iflag = ISTRIP | IXON | IXANY;
- live.c_oflag = OPOST | ONLCR;
- live.c_lflag = ISIG | NOFLSH;
-
- live.c_cc[VINTR] = 0;
- live.c_cc[VQUIT] = 0;
-
-#ifdef hpux
- live.c_cc[VMIN] = 0;
- live.c_cc[VTIME] = 0;
-#endif
-
- /* do we even need this stuff anymore? */
- /* live.c_line=0; */
- live.c_cc[VERASE] = 8;
- live.c_cc[VKILL] = 24;
- live.c_cc[VEOF] = 1;
- live.c_cc[VEOL] = 255;
- live.c_cc[VEOL2] = 0;
- live.c_cc[VSTART] = 0;
- tcsetattr(0, TCSADRAIN, &live);
- }
- if (cmd == 2) {
- tcgetattr(0, &saved_settings);
- }
- if (cmd == 3) {
- tcsetattr(0, TCSADRAIN, &saved_settings);
- }
-
-}
-#else
-void stty_ctdl(int cmd)
-{ /* BSD version of stty_ctdl() */
- struct sgttyb live;
- static struct sgttyb saved_settings;
- static int last_cmd = 0;
-
- if (cmd == SB_LAST)
- cmd = last_cmd;
- else
- last_cmd = cmd;
-
- if ((cmd == 0) || (cmd == 1)) {
- gtty(0, &live);
- live.sg_flags |= CBREAK;
- live.sg_flags |= CRMOD;
- live.sg_flags |= NL1;
- live.sg_flags &= ~ECHO;
- if (cmd == 1)
- live.sg_flags |= NOFLSH;
- stty(0, &live);
- }
- if (cmd == 2) {
- gtty(0, &saved_settings);
- }
- if (cmd == 3) {
- stty(0, &saved_settings);
- }
-}
-#endif
-
-
-/*
- * display_help() - help file viewer
- */
-void display_help(CtdlIPC *ipc, char *name)
-{
- formout(ipc, name);
-}
-
-
-/*
- * fmout() - Citadel text formatter and paginator
- */
-int fmout(
- int width, /* screen width to use */
- FILE *fpin, /* file to read from, or NULL to format given text */
- char *text, /* text to be formatted (when fpin is NULL */
- FILE *fpout, /* file to write to, or NULL to write to screen */
- int subst) /* nonzero if we should use hypertext mode */
-{
- char *buffer = NULL; /* The current message */
- char *word = NULL; /* What we are about to actually print */
- char *e; /* Pointer to position in text */
- char old = 0; /* The previous character */
- int column = 0; /* Current column */
- size_t i; /* Generic counter */
-
- /* Space for a single word, which can be at most screenwidth */
- word = (char *)calloc(1, width);
- if (!word) {
- scr_printf("Can't alloc memory to print message: %s!\n",
- strerror(errno));
- logoff(NULL, 3);
- }
-
- /* Read the entire message body into memory */
- if (fpin) {
- buffer = load_message_from_file(fpin);
- if (!buffer) {
- scr_printf("Can't print message: %s!\n",
- strerror(errno));
- logoff(NULL, 3);
- }
- } else {
- buffer = text;
- }
- e = buffer;
-
- /* Run the message body */
- while (*e) {
- /* Catch characters that shouldn't be there at all */
- if (*e == '\r') {
- e++;
- continue;
- }
- /* First, are we looking at a newline? */
- if (*e == '\n') {
- e++;
- if (*e == ' ') { /* Paragraph */
- if (fpout) {
- fprintf(fpout, "\n");
- } else {
- scr_printf("\n");
- }
- column = 0;
- } else if (old != ' ') {/* Don't print two spaces */
- if (fpout) {
- fprintf(fpout, " ");
- } else {
- scr_printf(" ");
- }
- column++;
- }
- old = '\n';
- continue;
- }
-
- /* Are we looking at a nonprintable?
- * (This section is now commented out because we could be displaying
- * a character set like UTF-8 or ISO-8859-1.)
- if ( (*e < 32) || (*e > 126) ) {
- e++;
- continue;
- } */
-
- /* Or are we looking at a space? */
- if (*e == ' ') {
- e++;
- if (column >= width - 1) {
- /* Are we in the rightmost column? */
- if (fpout) {
- fprintf(fpout, "\n");
- } else {
- scr_printf("\n");
- }
- column = 0;
- } else if (!(column == 0 && old == ' ')) {
- /* Eat only the first space on a line */
- if (fpout) {
- fprintf(fpout, " ");
- } else {
- scr_printf(" ");
- }
- column++;
- }
- /* ONLY eat the FIRST space on a line */
- old = ' ';
- continue;
- }
- old = *e;
-
- /* Read a word, slightly messy */
- i = 0;
- while (e[i]) {
- if (!isprint(e[i]) && !isspace(e[i]))
- e[i] = ' ';
- if (isspace(e[i]))
- break;
- i++;
- }
-
- /* We should never see these, but... slightly messy */
- if (e[i] == '\t' || e[i] == '\f' || e[i] == '\v')
- e[i] = ' ';
-
- /* Break up really long words */
- /* TODO: auto-hyphenation someday? */
- if (i >= width)
- i = width - 1;
- strncpy(word, e, i);
- word[i] = 0;
-
- /* Decide where to print the word */
- if (column + i >= width) {
- /* Wrap to the next line */
- if (fpout) {
- fprintf(fpout, "\n");
- } else {
- scr_printf("\n");
- }
- column = 0;
- }
-
- /* Print the word */
- if (fpout) {
- fprintf(fpout, "%s", word);
- } else {
- scr_printf("%s", word);
- }
- column += i;
- e += i; /* Start over with the whitepsace! */
- }
-
- free(word);
- if (fpin) /* We allocated this, remember? */
- free(buffer);
-
- /* Is this necessary? It makes the output kind of spacey. */
- if (fpout) {
- fprintf(fpout, "\n");
- } else {
- scr_printf("\n");
- }
-
- return sigcaught;
-}
-
-
-/*
- * support ANSI color if defined
- */
-void color(int colornum)
-{
- static int hold_color;
- static int current_color;
-
- if (colornum == COLOR_PUSH) {
- hold_color = current_color;
- return;
- }
-
- if (colornum == COLOR_POP) {
- color(hold_color);
- return;
- }
-
- current_color = colornum;
- if (enable_color) {
- /* When switching to dim white, actually output an 'original
- * pair' sequence -- this looks better on black-on-white
- * terminals. - Changed to ORIGINAL_PAIR as this actually
- * wound up looking horrible on black-on-white terminals, not
- * to mention transparent terminals.
- */
- if (colornum == ORIGINAL_PAIR)
- printf("\033[0;39;49m");
- else
- printf("\033[%d;3%d;4%dm",
- (colornum & 8) ? 1 : 0,
- (colornum & 7),
- rc_color_use_bg);
-
- }
-}
-
-void cls(int colornum)
-{
- if (enable_color) {
- printf("\033[4%dm\033[2J\033[H\033[0m",
- colornum ? colornum : rc_color_use_bg);
- }
-}
-
-
-/*
- * Detect whether ANSI color is available (answerback)
- */
-void send_ansi_detect(void)
-{
- if (rc_ansi_color == 2) {
- printf("\033[c");
- scr_flush();
- time(&AnsiDetect);
- }
-}
-
-void look_for_ansi(void)
-{
- fd_set rfds;
- struct timeval tv;
- char abuf[512];
- time_t now;
- int a, rv;
-
- if (rc_ansi_color == 0) {
- enable_color = 0;
- } else if (rc_ansi_color == 1) {
- enable_color = 1;
- } else if (rc_ansi_color == 2) {
-
- /* otherwise, do the auto-detect */
-
- strcpy(abuf, "");
-
- time(&now);
- if ((now - AnsiDetect) < 2)
- sleep(1);
-
- do {
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 1;
-
- select(1, &rfds, NULL, NULL, &tv);
- if (FD_ISSET(0, &rfds)) {
- abuf[strlen(abuf) + 1] = 0;
- rv = read(0, &abuf[strlen(abuf)], 1);
- if (rv < 0) {
- scr_printf("failed to read after select: %s",
- strerror(errno));
- break;
- }
- }
- } while (FD_ISSET(0, &rfds));
-
- for (a = 0; !IsEmptyStr(&abuf[a]); ++a) {
- if ((abuf[a] == 27) && (abuf[a + 1] == '[')
- && (abuf[a + 2] == '?')) {
- enable_color = 1;
- }
- }
- }
-}
-
-
-/*
- * Display key options (highlight hotkeys inside angle brackets)
- */
-void keyopt(char *buf) {
- int i;
-
- color(DIM_WHITE);
- for (i=0; !IsEmptyStr(&buf[i]); ++i) {
- if (buf[i]=='<') {
- scr_printf("%c", buf[i]);
- color(BRIGHT_MAGENTA);
- } else {
- if (buf[i]=='>'&& buf[i+1] != '>') {
- color(DIM_WHITE);
- }
- scr_printf("%c", buf[i]);
- }
- }
- color(DIM_WHITE);
-}
-
-
-
-/*
- * Present a key-menu line choice type of thing
- */
-char keymenu(char *menuprompt, char *menustring) {
- int i, c, a;
- int choices;
- int do_prompt = 0;
- char buf[1024];
- int ch;
- int display_prompt = 1;
-
- choices = num_tokens(menustring, '|');
-
- if (menuprompt != NULL) do_prompt = 1;
- if ((menuprompt != NULL) && (IsEmptyStr(menuprompt))) do_prompt = 0;
-
- while (1) {
- if (display_prompt) {
- if (do_prompt) {
- scr_printf("%s ", menuprompt);
- }
- else {
- for (i=0; i<choices; ++i) {
- extract_token(buf, menustring, i, '|', sizeof buf);
- keyopt(buf);
- scr_printf(" ");
- }
- }
- scr_printf("-> ");
- display_prompt = 0;
- }
- ch = lkey();
-
- if ( (do_prompt) && (ch=='?') ) {
- scr_printf("\rOne of... ");
- scr_printf(" \n");
- for (i=0; i<choices; ++i) {
- extract_token(buf, menustring, i, '|', sizeof buf);
- scr_printf(" ");
- keyopt(buf);
- scr_printf("\n");
- }
- scr_printf("\n");
- display_prompt = 1;
- }
-
- for (i=0; i<choices; ++i) {
- extract_token(buf, menustring, i, '|', sizeof buf);
- for (c=1; !IsEmptyStr(&buf[c]); ++c) {
- if ( (ch == tolower(buf[c]))
- && (buf[c-1]=='<')
- && (buf[c+1]=='>') ) {
- for (a=0; !IsEmptyStr(&buf[a]); ++a) {
- if ( (a!=(c-1)) && (a!=(c+1))) {
- scr_putc(buf[a]);
- }
- }
- scr_printf("\n");
- return ch;
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * Text client functions for reading and writing of messages
- *
- * Copyright (c) 1987-2012 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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.
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-#include <limits.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-
-#include <stdarg.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "citadel_ipc.h"
-#include "citadel_decls.h"
-#include "messages.h"
-#include "commands.h"
-#include "tuiconfig.h"
-#include "rooms.h"
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-#include "screen.h"
-
-#define MAXWORDBUF SIZ
-#define NO_REPLY_TO "nobody ... xxxxxx"
-
-char reply_to[SIZ];
-char reply_subject[SIZ];
-char reply_references[SIZ];
-char reply_inreplyto[SIZ];
-
-struct cittext {
- struct cittext *next;
- char text[MAXWORDBUF];
-};
-
-void stty_ctdl(int cmd);
-int haschar(const char *st, int ch);
-int file_checksum(char *filename);
-void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
-
-unsigned long *msg_arr = NULL;
-int msg_arr_size = 0;
-int num_msgs;
-extern char room_name[];
-extern char tempdir[];
-extern unsigned room_flags;
-extern unsigned room_flags2;
-extern int entmsg_ok;
-extern long highest_msg_read;
-extern char temp[];
-extern char temp2[];
-extern int screenwidth;
-extern int screenheight;
-extern long maxmsgnum;
-extern char is_mail;
-extern char is_aide;
-extern char is_room_aide;
-extern char fullname[];
-extern char axlevel;
-extern unsigned userflags;
-extern char sigcaught;
-extern char printcmd[];
-extern int rc_allow_attachments;
-extern int rc_display_message_numbers;
-extern int rc_force_mail_prompts;
-extern int editor_pid;
-extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
-int num_urls = 0;
-char urls[MAXURLS][SIZ];
-char imagecmd[SIZ];
-int has_images = 0; /* Current msg has images */
-struct parts *last_message_parts = NULL; /* Parts from last msg */
-
-
-
-void ka_sigcatch(int signum)
-{
- alarm(S_KEEPALIVE);
- signal(SIGALRM, ka_sigcatch);
- CtdlIPCNoop(ipc_for_signal_handlers);
-}
-
-
-/*
- * server keep-alive version of wait() (needed for external editor)
- */
-pid_t ka_wait(int *kstatus)
-{
- pid_t p;
-
- alarm(S_KEEPALIVE);
- signal(SIGALRM, ka_sigcatch);
- do {
- errno = 0;
- p = wait(kstatus);
- } while (errno == EINTR);
- signal(SIGALRM, SIG_IGN);
- alarm(0);
- return (p);
-}
-
-
-/*
- * version of system() that uses ka_wait()
- */
-int ka_system(char *shc)
-{
- pid_t childpid;
- pid_t waitpid;
- int retcode;
-
- childpid = fork();
- if (childpid < 0) {
- color(BRIGHT_RED);
- perror("Cannot fork");
- color(DIM_WHITE);
- return ((pid_t) childpid);
- }
-
- if (childpid == 0) {
- execlp("/bin/sh", "sh", "-c", shc, NULL);
- exit(127);
- }
-
- if (childpid > 0) {
- do {
- waitpid = ka_wait(&retcode);
- } while (waitpid != childpid);
- return (retcode);
- }
-
- return (-1);
-}
-
-
-
-/*
- * add a newline to the buffer...
- */
-void add_newline(struct cittext *textlist)
-{
- struct cittext *ptr;
-
- ptr = textlist;
- while (ptr->next != NULL)
- ptr = ptr->next;
-
- while (ptr->text[strlen(ptr->text) - 1] == 32)
- ptr->text[strlen(ptr->text) - 1] = 0;
- /* strcat(ptr->text,"\n"); */
-
- ptr->next = (struct cittext *)
- malloc(sizeof(struct cittext));
- ptr = ptr->next;
- ptr->next = NULL;
- strcpy(ptr->text, "");
-}
-
-
-/*
- * add a word to the buffer...
- */
-void add_word(struct cittext *textlist, char *wordbuf)
-{
- struct cittext *ptr;
-
- ptr = textlist;
- while (ptr->next != NULL)
- ptr = ptr->next;
-
- if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
- ptr->next = (struct cittext *)
- malloc(sizeof(struct cittext));
- ptr = ptr->next;
- ptr->next = NULL;
- strcpy(ptr->text, "");
- }
-
- strcat(ptr->text, wordbuf);
- strcat(ptr->text, " ");
-}
-
-
-/*
- * begin editing of an opened file pointed to by fp
- */
-void citedit(FILE *fp)
-{
- int a, prev, finished, b, last_space;
- int appending = 0;
- struct cittext *textlist = NULL;
- struct cittext *ptr;
- char wordbuf[MAXWORDBUF];
- int rv = 0;
-
- /* first, load the text into the buffer */
- fseek(fp, 0L, 0);
- textlist = (struct cittext *) malloc(sizeof(struct cittext));
- textlist->next = NULL;
- strcpy(textlist->text, "");
-
- strcpy(wordbuf, "");
- prev = (-1);
- while (a = getc(fp), a >= 0) {
- appending = 1;
- if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
- add_word(textlist, wordbuf);
- strcpy(wordbuf, "");
- if ((prev == 13) || (prev == 10)) {
- add_word(textlist, "\n");
- add_newline(textlist);
- add_word(textlist, "");
- }
- } else {
- wordbuf[strlen(wordbuf) + 1] = 0;
- wordbuf[strlen(wordbuf)] = a;
- }
- if (strlen(wordbuf) + 3 > screenwidth) {
- add_word(textlist, wordbuf);
- strcpy(wordbuf, "");
- }
- prev = a;
- }
-
- /* get text */
- finished = 0;
- prev = (appending ? 13 : (-1));
- strcpy(wordbuf, "");
- async_ka_start();
- do {
- a = inkey();
- if (a == 10)
- a = 13;
- if (a == 9)
- a = 32;
- if (a == 127)
- a = 8;
-
- if ((a != 32) && (prev == 13)) {
- add_word(textlist, "\n");
- scr_printf(" ");
- }
-
- if ((a == 32) && (prev == 13)) {
- add_word(textlist, "\n");
- add_newline(textlist);
- }
-
- if (a == 8) {
- if (!IsEmptyStr(wordbuf)) {
- wordbuf[strlen(wordbuf) - 1] = 0;
- scr_putc(8);
- scr_putc(32);
- scr_putc(8);
- }
- } else if (a == 23) {
- do {
- wordbuf[strlen(wordbuf) - 1] = 0;
- scr_putc(8);
- scr_putc(32);
- scr_putc(8);
- } while (!IsEmptyStr(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
- } else if (a == 13) {
- scr_printf("\n");
- if (IsEmptyStr(wordbuf))
- finished = 1;
- else {
- for (b = 0; b < strlen(wordbuf); ++b)
- if (wordbuf[b] == 32) {
- wordbuf[b] = 0;
- add_word(textlist,
- wordbuf);
- strcpy(wordbuf,
- &wordbuf[b + 1]);
- b = 0;
- }
- add_word(textlist, wordbuf);
- strcpy(wordbuf, "");
- }
- } else {
- scr_putc(a);
- wordbuf[strlen(wordbuf) + 1] = 0;
- wordbuf[strlen(wordbuf)] = a;
- }
- if ((strlen(wordbuf) + 3) > screenwidth) {
- last_space = (-1);
- for (b = 0; b < strlen(wordbuf); ++b)
- if (wordbuf[b] == 32)
- last_space = b;
- if (last_space >= 0) {
- for (b = 0; b < strlen(wordbuf); ++b)
- if (wordbuf[b] == 32) {
- wordbuf[b] = 0;
- add_word(textlist,
- wordbuf);
- strcpy(wordbuf,
- &wordbuf[b + 1]);
- b = 0;
- }
- for (b = 0; b < strlen(wordbuf); ++b) {
- scr_putc(8);
- scr_putc(32);
- scr_putc(8);
- }
- scr_printf("\n%s", wordbuf);
- } else {
- add_word(textlist, wordbuf);
- strcpy(wordbuf, "");
- scr_printf("\n");
- }
- }
- prev = a;
- } while (finished == 0);
- async_ka_end();
-
- /* write the buffer back to disk */
- fseek(fp, 0L, 0);
- for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
- fprintf(fp, "%s", ptr->text);
- }
- putc(10, fp);
- fflush(fp);
- rv = ftruncate(fileno(fp), ftell(fp));
- if (rv < 0)
- scr_printf("failed to set message buffer: %s\n", strerror(errno));
-
-
- /* and deallocate the memory we used */
- while (textlist != NULL) {
- ptr = textlist->next;
- free(textlist);
- textlist = ptr;
- }
-}
-
-
-/*
- * Free the struct parts
- */
-void free_parts(struct parts *p)
-{
- struct parts *a_part = p;
-
- while (a_part) {
- struct parts *q;
-
- q = a_part;
- a_part = a_part->next;
- free(q);
- }
-}
-
-
-/*
- * This is a mini RFC2047 decoder.
- * It only handles strings encoded from UTF-8 as Quoted-printable.
- */
-void mini_2047_decode(char *s) {
- if (!s) return;
-
- char *qstart = strstr(s, "=?UTF-8?Q?");
- if (!qstart) return;
-
- char *qend = strstr(s, "?=");
- if (!qend) return;
-
- if (qend <= qstart) return;
-
- strcpy(qstart, &qstart[10]);
- qend -= 10;
-
- char *p = qstart;
- while (p < qend) {
-
- if (p[0] == '=') {
-
- char ch[3];
- ch[0] = p[1];
- ch[1] = p[2];
- ch[2] = p[3];
- int c;
- sscanf(ch, "%02x", &c);
- p[0] = c;
- strcpy(&p[1], &p[3]);
- qend -= 2;
- }
-
- if (p[0] == '_') {
- p[0] = ' ';
- }
-
- ++p;
- }
-
- strcpy(qend, &qend[2]);
-}
-
-/*
- * Read a message from the server
- */
-int read_message(CtdlIPC *ipc,
- long num, /* message number */
- int pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
- FILE *dest) /* Destination file, NULL for screen */
-{
- char buf[SIZ];
- char now[SIZ];
- int format_type = 0;
- int fr = 0;
- int nhdr = 0;
- struct ctdlipcmessage *message = NULL;
- int r; /* IPC response code */
- char *converted_text = NULL;
- char *lineptr;
- char *nextline;
- char *searchptr;
- int i;
- char ch;
- int linelen;
- int final_line_is_blank = 0;
-
- has_images = 0;
-
- sigcaught = 0;
- stty_ctdl(1);
-
- strcpy(reply_to, NO_REPLY_TO);
- strcpy(reply_subject, "");
- strcpy(reply_references, "");
- strcpy(reply_inreplyto, "");
-
- r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0), 4, &message, buf);
- if (r / 100 != 1) {
- scr_printf("*** msg #%ld: %d %s\n", num, r, buf);
- stty_ctdl(0);
- free(message->text);
- free_parts(message->attachments);
- free(message);
- return (0);
- }
-
- if (dest) {
- fprintf(dest, "\n ");
- } else {
- scr_printf("\n");
- if (pagin != 2)
- scr_printf(" ");
- }
- if (pagin == 1 && !dest) {
- color(BRIGHT_CYAN);
- }
-
- /* View headers only */
- if (pagin == 2) {
- scr_printf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
- message->nhdr ? "yes" : "no",
- message->author, message->type,
- message->msgid);
- if (!IsEmptyStr(message->subject)) {
- scr_printf("subj=%s\n", message->subject);
- }
- if (!IsEmptyStr(message->email)) {
- scr_printf("rfca=%s\n", message->email);
- }
- scr_printf("hnod=%s\nroom=%s\nnode=%s\ntime=%s",
- message->hnod, message->room,
- message->node,
- asctime(localtime(&message->time)));
- if (!IsEmptyStr(message->recipient)) {
- scr_printf("rcpt=%s\n", message->recipient);
- }
- if (message->attachments) {
- struct parts *ptr;
-
- for (ptr = message->attachments; ptr; ptr = ptr->next) {
- scr_printf("part=%s|%s|%s|%s|%s|%ld\n",
- ptr->name, ptr->filename, ptr->number,
- ptr->disposition, ptr->mimetype,
- ptr->length
- );
- }
- }
- scr_printf("\n");
- stty_ctdl(0);
- free(message->text);
- free_parts(message->attachments);
- free(message);
- return (0);
- }
-
- if (rc_display_message_numbers) {
- if (dest) {
- fprintf(dest, "[#%s] ", message->msgid);
- } else {
- color(DIM_WHITE);
- scr_printf("[");
- color(BRIGHT_WHITE);
- scr_printf("#%s", message->msgid);
- color(DIM_WHITE);
- scr_printf("] ");
- }
- }
- if (nhdr == 1 && !is_room_aide) {
- if (dest) {
- fprintf(dest, " ****");
- } else {
- scr_printf(" ****");
- }
- } else {
- fmt_date(now, sizeof now, message->time, 0);
- if (dest) {
- fprintf(dest, "%s from %s ", now, message->author);
- if (!IsEmptyStr(message->email)) {
- fprintf(dest, "<%s> ", message->email);
- }
- } else {
- color(BRIGHT_CYAN);
- scr_printf("%s ", now);
- color(DIM_WHITE);
- scr_printf("from ");
- color(BRIGHT_CYAN);
- scr_printf("%s ", message->author);
- if (!IsEmptyStr(message->email)) {
- color(DIM_WHITE);
- scr_printf("<");
- color(BRIGHT_BLUE);
- scr_printf("%s", message->email);
- color(DIM_WHITE);
- scr_printf("> ");
- }
- }
- if (!IsEmptyStr(message->node)) {
- if ((room_flags & QR_NETWORK)
- || ((strcasecmp(message->node, ipc->ServInfo.nodename)
- && (strcasecmp(message->node, ipc->ServInfo.fqdn))))) {
- if (IsEmptyStr(message->email)) {
- if (dest) {
- fprintf(dest, "@%s ", message->node);
- } else {
- color(DIM_WHITE);
- scr_printf("@");
- color(BRIGHT_YELLOW);
- scr_printf("%s ", message->node);
- }
- }
- }
- }
- if (strcasecmp(message->hnod, ipc->ServInfo.humannode)
- && (!IsEmptyStr(message->hnod)) && (IsEmptyStr(message->email))) {
- if (dest) {
- fprintf(dest, "(%s) ", message->hnod);
- } else {
- color(DIM_WHITE);
- scr_printf("(");
- color(BRIGHT_WHITE);
- scr_printf("%s", message->hnod);
- color(DIM_WHITE);
- scr_printf(") ");
- }
- }
- if (strcasecmp(message->room, room_name) && (IsEmptyStr(message->email))) {
- if (dest) {
- fprintf(dest, "in %s> ", message->room);
- } else {
- color(DIM_WHITE);
- scr_printf("in ");
- color(BRIGHT_MAGENTA);
- scr_printf("%s> ", message->room);
- }
- }
- if (!IsEmptyStr(message->recipient)) {
- if (dest) {
- fprintf(dest, "to %s ", message->recipient);
- } else {
- color(DIM_WHITE);
- scr_printf("to ");
- color(BRIGHT_CYAN);
- scr_printf("%s ", message->recipient);
- }
- }
- }
-
- if (dest) {
- fprintf(dest, "\n");
- } else {
- scr_printf("\n");
- }
-
- /* Set the reply-to address to an Internet e-mail address if possible
- */
- if ((message->email != NULL) && (!IsEmptyStr(message->email))) {
- if (!IsEmptyStr(message->author)) {
- snprintf(reply_to, sizeof reply_to, "%s <%s>", message->author, message->email);
- }
- else {
- safestrncpy(reply_to, message->email, sizeof reply_to);
- }
- }
-
- /* But if we can't do that, set it to a Citadel address.
- */
- if (!strcmp(reply_to, NO_REPLY_TO)) {
- snprintf(reply_to, sizeof(reply_to), "%s @ %s",
- message->author, message->node);
- }
-
- if (message->msgid != NULL) {
- safestrncpy(reply_inreplyto, message->msgid, sizeof reply_inreplyto);
- }
-
- if (message->references != NULL) if (!IsEmptyStr(message->references)) {
- safestrncpy(reply_references, message->references, sizeof reply_references);
- }
-
- if (message->subject != NULL) {
- safestrncpy(reply_subject, message->subject, sizeof reply_subject);
- if (!IsEmptyStr(message->subject)) {
- if (dest) {
- fprintf(dest, "Subject: %s\n", message->subject);
- } else {
- color(DIM_WHITE);
- scr_printf("Subject: ");
- color(BRIGHT_CYAN);
- mini_2047_decode(message->subject);
- scr_printf("%s\n", message->subject);
- }
- }
- }
-
- if (pagin == 1 && !dest) {
- color(BRIGHT_WHITE);
- }
-
- /******* end of header output, start of message text output *******/
-
- /*
- * Convert HTML to plain text, formatting for the actual width
- * of the client screen.
- */
- if (!strcasecmp(message->content_type, "text/html")) {
- converted_text = html_to_ascii(message->text, 0, screenwidth, 0);
- if (converted_text != NULL) {
- free(message->text);
- message->text = converted_text;
- format_type = 1;
- }
- }
-
- /* Text/plain is a different type */
- if (!strcasecmp(message->content_type, "text/plain")) {
- format_type = 1;
- }
-
- /* Extract URL's */
- num_urls = 0; /* Start with a clean slate */
- searchptr = message->text;
- while ( (searchptr != NULL) && (num_urls < MAXURLS) ) {
- searchptr = strstr(searchptr, "http://");
- if (searchptr != NULL) {
- safestrncpy(urls[num_urls], searchptr, sizeof(urls[num_urls]));
- for (i = 0; i < strlen(urls[num_urls]); i++) {
- ch = urls[num_urls][i];
- if (ch == '>' || ch == '\"' || ch == ')' ||
- ch == ' ' || ch == '\n') {
- urls[num_urls][i] = 0;
- break;
- }
- }
- num_urls++;
- ++searchptr;
- }
- }
-
- /*
- * Here we go
- */
- if (format_type == 0) {
- fr = fmout(screenwidth, NULL, message->text, dest, 1);
- } else {
- /* renderer for text/plain */
-
- lineptr = message->text;
-
- do {
- nextline = strchr(lineptr, '\n');
- if (nextline != NULL) {
- *nextline = 0;
- ++nextline;
- if (*nextline == 0) nextline = NULL;
- }
-
- if (sigcaught == 0) {
- linelen = strlen(lineptr);
- if (linelen && (lineptr[linelen-1] == '\r')) {
- lineptr[--linelen] = 0;
- }
- if (dest) {
- fprintf(dest, "%s\n", lineptr);
- } else {
- scr_printf("%s\n", lineptr);
- }
- }
- if (lineptr[0] == 0) final_line_is_blank = 1;
- else final_line_is_blank = 0;
- lineptr = nextline;
- } while (nextline);
- fr = sigcaught;
- }
- if (!final_line_is_blank) {
- if (dest) {
- fprintf(dest, "\n");
- }
- else {
- scr_printf("\n");
- fr = sigcaught;
- }
- }
-
- /* Enumerate any attachments */
- if ( (pagin == 1) && (message->attachments) ) {
- struct parts *ptr;
-
- for (ptr = message->attachments; ptr; ptr = ptr->next) {
- if ( (!strcasecmp(ptr->disposition, "attachment"))
- || (!strcasecmp(ptr->disposition, "inline"))
- || (!strcasecmp(ptr->disposition, ""))
- ) {
- if ( (strcasecmp(ptr->number, message->mime_chosen))
- && (!IsEmptyStr(ptr->mimetype))
- ) {
- color(DIM_WHITE);
- scr_printf("Part ");
- color(BRIGHT_MAGENTA);
- scr_printf("%s", ptr->number);
- color(DIM_WHITE);
- scr_printf(": ");
- color(BRIGHT_CYAN);
- scr_printf("%s", ptr->filename);
- color(DIM_WHITE);
- scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
- if (!strncmp(ptr->mimetype, "image/", 6)) {
- has_images++;
- }
- }
- }
- }
- }
-
- /* Save the attachments info for later */
- last_message_parts = message->attachments;
-
- /* Now we're done */
- free(message->text);
- free(message);
-
- if (pagin == 1 && !dest)
- color(DIM_WHITE);
- stty_ctdl(0);
- return (fr);
-}
-
-/*
- * replace string function for the built-in editor
- */
-void replace_string(char *filename, long int startpos)
-{
- char buf[512];
- char srch_str[128];
- char rplc_str[128];
- FILE *fp;
- int a;
- long rpos, wpos;
- char *ptr;
- int substitutions = 0;
- long msglen = 0L;
- int rv;
-
- newprompt("Enter test to be replaced: ", srch_str, (sizeof(srch_str)-1) );
- if (IsEmptyStr(srch_str)) {
- return;
- }
-
- newprompt("Enter text to replace it with: ", rplc_str, (sizeof(rplc_str)-1) );
-
- fp = fopen(filename, "r+");
- if (fp == NULL) {
- return;
- }
-
- wpos = startpos;
- fseek(fp, startpos, 0);
- strcpy(buf, "");
- while (a = getc(fp), a > 0) {
- ++msglen;
- buf[strlen(buf) + 1] = 0;
- buf[strlen(buf)] = a;
- if (strlen(buf) >= strlen(srch_str)) {
- ptr = (&buf[strlen(buf) - strlen(srch_str)]);
- if (!strncmp(ptr, srch_str, strlen(srch_str))) {
- strcpy(ptr, rplc_str);
- ++substitutions;
- }
- }
- if (strlen(buf) > 384) {
- rpos = ftell(fp);
- fseek(fp, wpos, 0);
- rv = fwrite((char *) buf, 128, 1, fp);
- if (rv < 0) {
- scr_printf("failed to replace string: %s\n", strerror(errno));
- break; /*whoopsi! */
- }
- strcpy(buf, &buf[128]);
- wpos = ftell(fp);
- fseek(fp, rpos, 0);
- }
- }
- fseek(fp, wpos, 0);
- if (!IsEmptyStr(buf)) {
- rv = fwrite((char *) buf, strlen(buf), 1, fp);
- }
- wpos = ftell(fp);
- fclose(fp);
- rv = truncate(filename, wpos);
- scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
-}
-
-/*
- * Function to begin composing a new message
- */
-int client_make_message(CtdlIPC *ipc,
- char *filename, /* temporary file name */
- char *recipient, /* NULL if it's not mail */
- int is_anonymous,
- int format_type,
- int mode,
- char *subject, /* buffer to store subject line */
- int subject_required
-) {
- FILE *fp;
- int a, b, e_ex_code;
- long beg;
- char datestr[SIZ];
- char header[SIZ];
- int cksum = 0;
-
- if ( (mode == 2) && (IsEmptyStr(editor_path)) ) {
- scr_printf("*** No editor available; using built-in editor.\n");
- mode = 0;
- }
-
- fmt_date(datestr, sizeof datestr, time(NULL), 0);
- header[0] = 0;
-
- if (room_flags & QR_ANONONLY && !recipient) {
- snprintf(header, sizeof header, " ****");
- }
- else {
- snprintf(header, sizeof header,
- " %s from %s",
- datestr,
- (is_anonymous ? "[anonymous]" : fullname)
- );
- if (!IsEmptyStr(recipient)) {
- size_t tmp = strlen(header);
- snprintf(&header[tmp], sizeof header - tmp,
- " to %s", recipient);
- }
- }
- scr_printf("%s\n", header);
- if (subject != NULL) if (!IsEmptyStr(subject)) {
- scr_printf("Subject: %s\n", subject);
- }
-
- if ( (subject_required) && (IsEmptyStr(subject)) ) {
- newprompt("Subject: ", subject, 70);
- }
-
- if (mode == 1) {
- scr_printf("(Press ctrl-d when finished)\n");
- }
-
- if (mode == 0) {
- fp = fopen(filename, "r");
- if (fp != NULL) {
- fmout(screenwidth, fp, NULL, NULL, 0);
- beg = ftell(fp);
- if (beg < 0)
- scr_printf("failed to get stream position %s\n",
- strerror(errno));
- fclose(fp);
- } else {
- fp = fopen(filename, "w");
- if (fp == NULL) {
- scr_printf("*** Error opening temp file!\n %s: %s\n",
- filename, strerror(errno)
- );
- return(1);
- }
- fclose(fp);
- }
- }
-
-ME1: switch (mode) {
-
- case 0:
- fp = fopen(filename, "r+");
- if (fp == NULL) {
- scr_printf("*** Error opening temp file!\n %s: %s\n",
- filename, strerror(errno)
- );
- return(1);
- }
- citedit(fp);
- fclose(fp);
- goto MECR;
-
- case 1:
- fp = fopen(filename, "a");
- if (fp == NULL) {
- scr_printf("*** Error opening temp file!\n"
- " %s: %s\n",
- filename, strerror(errno));
- return(1);
- }
- do {
- a = inkey();
- if (a == 255)
- a = 32;
- if (a == 13)
- a = 10;
- if (a != 4) {
- putc(a, fp);
- scr_putc(a);
- }
- if (a == 10)
- scr_putc(10);
- } while (a != 4);
- fclose(fp);
- break;
-
- case 2:
- default: /* allow 2+ modes */
- e_ex_code = 1; /* start with a failed exit code */
- stty_ctdl(SB_RESTORE);
- editor_pid = fork();
- cksum = file_checksum(filename);
- if (editor_pid == 0) {
- char tmp[SIZ];
-
- chmod(filename, 0600);
- snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", header);
- putenv(tmp);
- execlp(editor_path, editor_path, filename, NULL);
- exit(1);
- }
- if (editor_pid > 0)
- do {
- e_ex_code = 0;
- b = ka_wait(&e_ex_code);
- } while ((b != editor_pid) && (b >= 0));
- editor_pid = (-1);
- stty_ctdl(0);
- break;
- }
-
-MECR: if (mode >= 2) {
- if (file_checksum(filename) == cksum) {
- scr_printf("*** Aborted message.\n");
- e_ex_code = 1;
- }
- if (e_ex_code == 0) {
- goto MEFIN;
- }
- goto MEABT2;
- }
-
- b = keymenu("Entry command (? for options)",
- "<A>bort|"
- "<C>ontinue|"
- "<S>ave message|"
- "<P>rint formatted|"
- "add s<U>bject|"
- "<R>eplace string|"
- "<H>old message"
- );
-
- if (b == 'a') goto MEABT;
- if (b == 'c') goto ME1;
- if (b == 's') goto MEFIN;
- if (b == 'p') {
- scr_printf(" %s from %s", datestr, fullname);
- if (!IsEmptyStr(recipient)) {
- scr_printf(" to %s", recipient);
- }
- scr_printf("\n");
- if (subject != NULL) if (!IsEmptyStr(subject)) {
- scr_printf("Subject: %s\n", subject);
- }
- fp = fopen(filename, "r");
- if (fp != NULL) {
- fmout(screenwidth, fp, NULL, NULL, 0);
- beg = ftell(fp);
- if (beg < 0)
- scr_printf("failed to get stream position %s\n",
- strerror(errno));
- fclose(fp);
- }
- goto MECR;
- }
- if (b == 'r') {
- replace_string(filename, 0L);
- goto MECR;
- }
- if (b == 'h') {
- return (2);
- }
- if (b == 'u') {
- if (subject != NULL) {
- newprompt("Subject: ", subject, 70);
- }
- goto MECR;
- }
-
-MEFIN: return (0);
-
-MEABT: scr_printf("Are you sure? ");
- if (yesno() == 0) {
- goto ME1;
- }
-MEABT2: unlink(filename);
- return (2);
-}
-
-
-/*
- * Make sure there's room in msg_arr[] for at least one more.
- */
-void check_msg_arr_size(void) {
- if ((num_msgs + 1) > msg_arr_size) {
- msg_arr_size += 512;
- msg_arr = realloc(msg_arr,
- ((sizeof(long)) * msg_arr_size) );
- }
-}
-
-
-/*
- * break_big_lines() - break up lines that are >1024 characters
- * otherwise the server will truncate
- */
-void break_big_lines(char *msg) {
- char *ptr;
- char *break_here;
-
- if (msg == NULL) {
- return;
- }
-
- ptr = msg;
- while (strlen(ptr) > 1000) {
- break_here = strchr(&ptr[900], ' ');
- if ((break_here == NULL) || (break_here > &ptr[999])) {
- break_here = &ptr[999];
- }
- *break_here = '\n';
- ptr = break_here++;
- }
-}
-
-
-/*
- * entmsg() - edit and create a message
- * returns 0 if message was saved
- */
-int entmsg(CtdlIPC *ipc,
- int is_reply, /* nonzero if this was a <R>eply command */
- int c, /* mode */
- int masquerade /* prompt for a non-default display name? */
-) {
- char buf[SIZ];
- int a, b;
- int need_recp = 0;
- int mode;
- long highmsg = 0L;
- FILE *fp;
- char subject[SIZ];
- struct ctdlipcmessage message;
- unsigned long *msgarr = NULL;
- int r; /* IPC response code */
- int subject_required = 0;
-
- if (!entmsg_ok) {
- scr_printf("You may not enter messages in this type of room.\n");
- return(1);
- }
-
- if (c > 0) {
- mode = 1;
- }
- else {
- mode = 0;
- }
-
- strcpy(subject, "");
-
- /*
- * First, check to see if we have permission to enter a message in
- * this room. The server will return an error code if we can't.
- */
- strcpy(message.recipient, "");
- strcpy(message.author, "");
- strcpy(message.subject, "");
- strcpy(message.references, "");
- message.text = ""; /* point to "", changes later */
- message.anonymous = 0;
- message.type = mode;
-
- if (masquerade) {
- newprompt("Display name for this message: ", message.author, 40);
- }
-
- if (is_reply) {
-
- if (!IsEmptyStr(reply_subject)) {
- if (!strncasecmp(reply_subject,
- "Re: ", 3)) {
- strcpy(message.subject, reply_subject);
- }
- else {
- snprintf(message.subject,
- sizeof message.subject,
- "Re: %s",
- reply_subject);
- }
- }
-
- /* Trim down excessively long lists of thread references. We eliminate the
- * second one in the list so that the thread root remains intact.
- */
- int rrtok = num_tokens(reply_references, '|');
- int rrlen = strlen(reply_references);
- if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
- remove_token(reply_references, 1, '|');
- }
-
- snprintf(message.references, sizeof message.references, "%s%s%s",
- reply_references,
- (IsEmptyStr(reply_references) ? "" : "|"),
- reply_inreplyto
- );
- }
-
- r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
-
- if (r / 100 != 2 && r / 10 != 57) {
- scr_printf("%s\n", buf);
- return (1);
- }
-
- /* Error code 570 is special. It means that we CAN enter a message
- * in this room, but a recipient needs to be specified.
- */
- need_recp = 0;
- if (r / 10 == 57) {
- need_recp = 1;
- }
-
- /* If the user is a dumbass, tell them how to type. */
- if ((userflags & US_EXPERT) == 0) {
- formout(ipc, "entermsg");
- }
-
- /* Handle the selection of a recipient, if necessary. */
- strcpy(buf, "");
- if (need_recp == 1) {
- if (axlevel >= AxProbU) {
- if (is_reply) {
- strcpy(buf, reply_to);
- } else {
- newprompt("Enter recipient: ", buf, SIZ-100);
- if (IsEmptyStr(buf)) {
- return (1);
- }
- }
- } else
- strcpy(buf, "sysop");
- }
- strcpy(message.recipient, buf);
-
- if (room_flags & QR_ANONOPT) {
- scr_printf("Anonymous (Y/N)? ");
- if (yesno() == 1)
- message.anonymous = 1;
- }
-
- /* If it's mail, we've got to check the validity of the recipient... */
- if (!IsEmptyStr(message.recipient)) {
- r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
- if (r / 100 != 2) {
- scr_printf("%s\n", buf);
- return (1);
- }
- }
-
- /* Learn the number of the newest message in in the room, so we can
- * tell upon saving whether someone else has posted too.
- */
- num_msgs = 0;
- r = CtdlIPCGetMessages(ipc, LastMessages, 1, NULL, &msgarr, buf);
- if (r / 100 != 1) {
- scr_printf("%s\n", buf);
- } else {
- for (num_msgs = 0; msgarr[num_msgs]; num_msgs++)
- ;
- }
-
- /* Now compose the message... */
- if (client_make_message(ipc, temp, message.recipient,
- message.anonymous, 0, c, message.subject, subject_required) != 0) {
- if (msgarr) free(msgarr);
- return (2);
- }
-
- /* Reopen the temp file that was created, so we can send it */
- fp = fopen(temp, "r");
-
- if (!fp || !(message.text = load_message_from_file(fp))) {
- scr_printf("*** Internal error while trying to save message!\n"
- "%s: %s\n",
- temp, strerror(errno));
- unlink(temp);
- return(errno);
- }
-
- if (fp) fclose(fp);
-
- /* Break lines that are >1024 characters, otherwise the server
- * will truncate them.
- */
- break_big_lines(message.text);
-
- /* Transmit message to the server */
- r = CtdlIPCPostMessage(ipc, 1, NULL, &message, buf);
- if (r / 100 != 4) {
- scr_printf("%s\n", buf);
- return (1);
- }
-
- /* Yes, unlink it now, so it doesn't stick around if we crash */
- unlink(temp);
-
- if (num_msgs >= 1) highmsg = msgarr[num_msgs - 1];
-
- if (msgarr) free(msgarr);
- msgarr = NULL;
- r = CtdlIPCGetMessages(ipc, NewMessages, 0, NULL, &msgarr, buf);
- if (r / 100 != 1) {
- scr_printf("%s\n", buf);
- } else {
- for (num_msgs = 0; msgarr[num_msgs]; num_msgs++)
- ;
- }
-
- /* get new highest message number in room to set lrp for goto... */
- maxmsgnum = msgarr[num_msgs - 1];
-
- /* now see if anyone else has posted in here */
- b = (-1);
- for (a = 0; a < num_msgs; ++a) {
- if (msgarr[a] > highmsg) {
- ++b;
- }
- }
- if (msgarr) free(msgarr);
- msgarr = NULL;
-
- /* In the Mail> room, this algorithm always counts one message
- * higher than in public rooms, so we decrement it by one.
- */
- if (need_recp) {
- --b;
- }
-
- if (b == 1) {
- scr_printf("*** 1 additional message has been entered "
- "in this room by another user.\n");
- }
- else if (b > 1) {
- scr_printf("*** %d additional messages have been entered "
- "in this room by other users.\n", b);
- }
- free(message.text);
-
- return(0);
-}
-
-/*
- * Do editing on a quoted file
- */
-void process_quote(void)
-{
- FILE *qfile, *tfile;
- char buf[128];
- int line, qstart, qend;
-
- /* Unlink the second temp file as soon as it's opened, so it'll get
- * deleted even if the program dies
- */
- qfile = fopen(temp2, "r");
- unlink(temp2);
-
- /* Display the quotable text with line numbers added */
- line = 0;
- if (fgets(buf, 128, qfile) == NULL) {
- /* we're skipping a line here */
- }
- while (fgets(buf, 128, qfile) != NULL) {
- scr_printf("%3d %s", ++line, buf);
- }
-
- qstart = intprompt("Begin quoting at", 1, 1, line);
- qend = intprompt(" End quoting at", line, qstart, line);
-
- rewind(qfile);
- line = 0;
- if (fgets(buf, 128, qfile) == NULL) {
- /* we're skipping a line here */
- }
- tfile = fopen(temp, "w");
- while (fgets(buf, 128, qfile) != NULL) {
- if ((++line >= qstart) && (line <= qend))
- fprintf(tfile, " >%s", buf);
- }
- fprintf(tfile, " \n");
- fclose(qfile);
- fclose(tfile);
- chmod(temp, 0666);
-}
-
-
-
-/*
- * List the URL's which were embedded in the previous message
- */
-void list_urls(CtdlIPC *ipc)
-{
- int i;
- char cmd[SIZ];
- int rv;
-
- if (num_urls == 0) {
- scr_printf("There were no URL's in the previous message.\n\n");
- return;
- }
-
- for (i = 0; i < num_urls; ++i) {
- scr_printf("%3d %s\n", i + 1, urls[i]);
- }
-
- if ((i = num_urls) != 1)
- i = intprompt("Display which one", 1, 1, num_urls);
-
- snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
- rv = system(cmd);
- if (rv != 0)
- scr_printf("failed to '%s' by %d\n", cmd, rv);
- scr_printf("\n");
-}
-
-
-/*
- * Run image viewer in background
- */
-int do_image_view(const char *filename)
-{
- char cmd[SIZ];
- pid_t childpid;
-
- snprintf(cmd, sizeof cmd, imagecmd, filename);
- childpid = fork();
- if (childpid < 0) {
- unlink(filename);
- return childpid;
- }
-
- if (childpid == 0) {
- int retcode;
- pid_t grandchildpid;
-
- grandchildpid = fork();
- if (grandchildpid < 0) {
- return grandchildpid;
- }
-
- if (grandchildpid == 0) {
- int nullfd;
- int outfd = -1;
- int errfd = -1;
-
- nullfd = open("/dev/null", O_WRONLY);
- if (nullfd > -1) {
- dup2(1, outfd);
- dup2(2, errfd);
- dup2(nullfd, 1);
- dup2(nullfd, 2);
- }
- retcode = system(cmd);
- if (nullfd > -1) {
- dup2(outfd, 1);
- dup2(errfd, 2);
- close(nullfd);
- }
- unlink(filename);
- exit(retcode);
- }
-
- if (grandchildpid > 0) {
- exit(0);
- }
- }
-
- if (childpid > 0) {
- int retcode;
-
- waitpid(childpid, &retcode, 0);
- return retcode;
- }
-
- return -1;
-}
-
-
-/*
- * View an image attached to a message
- */
-void image_view(CtdlIPC *ipc, unsigned long msg)
-{
- struct parts *ptr = last_message_parts;
- char part[SIZ];
- int found = 0;
-
- /* Run through available parts */
- for (ptr = last_message_parts; ptr; ptr = ptr->next) {
- if ((!strcasecmp(ptr->disposition, "attachment")
- || !strcasecmp(ptr->disposition, "inline"))
- && !strncmp(ptr->mimetype, "image/", 6)) {
- found++;
- if (found == 1) {
- strcpy(part, ptr->number);
- }
- }
- }
-
- while (found > 0) {
- if (found > 1)
- strprompt("View which part (0 when done)", part, SIZ-1);
- found = -found;
- for (ptr = last_message_parts; ptr; ptr = ptr->next) {
- if ((!strcasecmp(ptr->disposition, "attachment")
- || !strcasecmp(ptr->disposition, "inline"))
- && !strncmp(ptr->mimetype, "image/", 6)
- && !strcasecmp(ptr->number, part)) {
- char tmp[PATH_MAX];
- char buf[SIZ];
- void *file = NULL; /* The downloaded file */
- int r;
-
- /* view image */
- found = -found;
- r = CtdlIPCAttachmentDownload(ipc, msg, ptr->number, &file, progress, buf);
- if (r / 100 != 2) {
- scr_printf("%s\n", buf);
- } else {
- size_t len;
-
- len = (size_t)extract_long(buf, 0);
- progress(ipc, len, len);
- scr_flush();
- CtdlMakeTempFileName(tmp, sizeof tmp);
- strcat(tmp, ptr->filename);
- save_buffer(file, len, tmp);
- free(file);
- do_image_view(tmp);
- }
- break;
- }
- }
- if (found == 1)
- break;
- }
-}
-
-
-/*
- * Read the messages in the current room
- */
-void readmsgs(CtdlIPC *ipc,
- enum MessageList c, /* see listing in citadel_ipc.h */
- enum MessageDirection rdir, /* 1=Forward (-1)=Reverse */
- int q /* Number of msgs to read (if c==3) */
-) {
- int a, e, f, g, start;
- int savedpos;
- int hold_sw = 0;
- char arcflag = 0;
- char quotflag = 0;
- int hold_color = 0;
- char prtfile[PATH_MAX];
- char pagin;
- char cmd[SIZ];
- char targ[ROOMNAMELEN];
- char filename[PATH_MAX];
- char save_to[PATH_MAX];
- void *attachment = NULL; /* Downloaded attachment */
- FILE *dest = NULL; /* Alternate destination other than screen */
- int r; /* IPC response code */
- static int att_seq = 0; /* Attachment download sequence number */
- int rv = 0; /* silence the stupid warn_unused_result warnings */
-
- CtdlMakeTempFileName(prtfile, sizeof prtfile);
-
- if (msg_arr) {
- free(msg_arr);
- msg_arr = NULL;
- }
- r = CtdlIPCGetMessages(ipc, c, q, NULL, &msg_arr, cmd);
- if (r / 100 != 1) {
- scr_printf("%s\n", cmd);
- } else {
- for (num_msgs = 0; msg_arr[num_msgs]; num_msgs++)
- ;
- }
-
- if (num