/******************************************************************************
 * This file is part of a software distribution, which is furnished under the *
 * terms of a license.  Use of this software  by any means is subject to this *
 * license  and  signifies  the  acceptance of  the  licensing  terms  stated *
 * therein. Please see  the file LICENSE in the  top-level directory  of this *
 * software  distribution  for detailed copyright  disclaimers  and licensing *
 * terms.                                                                     *
 ******************************************************************************
 * Copryight (c) by Andreas S. Wetzel - All rights reserved.                  *
 ******************************************************************************/

/* $Id: vchat.h,v 1.4 2001/03/19 23:17:29 mickey Exp $ */

#ifndef __VCHAT_H__
#define	__VCHAT_H__

/*
 * Suck in config.h
 */

#include <config.h>

/*
 * Include commonly used header files
 */

#include <stdio.h>

#if HAVE_STRING_H
#  include <string.h>
#endif

#if HAVE_STRINGS_H
#  include <strings.h>
#endif

#if HAVE_CTYPE_H
#  include <ctype.h>
#endif

#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <limits.h>
#include <errno.h>
#include <netinet/in.h>

#ifndef INADDR_NONE
#  define INADDR_NONE	0xffffffff
#endif

#if HAVE_UNISTD_H
#  include <unistd.h>
#endif

#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

/*
 * Termcap/Terminfo
 */

#if HAVE_TERM_H
#  define USE_TERMINFO 1
#  define USE_TERMCAP 0
#  include <curses.h>
#  include <term.h>
#elif HAVE_TERMCAP_H
#  define USE_TERMINFO 0
#  define USE_TERMCAP 1
#  include <termcap.h>
#else
#  error "YOU BLEW IT - Your system seems to have neither terminfo nor termcap"
#endif

/*
 * Include common VChat headers
 */

#include <ascii.h>
#include <options.h>
#include <microtime.h>
#include <vproto/types.h>

/*
 * Set up some handy macros
 */

#if HAVE_BCOPY
#  define	BCOPY(a,b,c)		bcopy(a,b,c)
#elif HAVE_MEMCPY
#  define	BCOPY(a,b,c)		memcpy(b,a,c)
#else
#  error "Neither bcopy nor memcpy are available"
#endif

#if HAVE_BZERO
#  define	BZERO(a,b)		bzero(a,b)
#elif HAVE_MEMSET
#  define	BZERO(a,b)		memset(a,0,b)
#else
#  error "Neither bzero nor memset are available"
#endif

#if HAVE_BCMP
#  define	BCMP(a,b,c)		bcmp(a,b,c)
#elif HAVE_MEMCMP
#  define	BCMP(a,b,c)		memcmp(a,b,c)
#else
#  error "Neither bcmp nor memcmp are available"
#endif

#define GETPEERNAME(a,b,c)	getpeername(a, (struct sockaddr *)b, (int *)c)
#define GETSOCKNAME(a,b,c)	getsockname(a, (struct sockaddr *)b, (int *)c)
#define RECVFROM(a,b,c,d,e,f)	recvfrom(a, (void *)b, (size_t)c, d, (struct sockaddr *)e, (int *)f)
#define SENDTO(a,b,c,d,e,f)	sendto(a, (void *)b, (size_t)c, d, (struct sockaddr *)e, f)

/*
 * Define the logging priorities. If syslog(3) is present, include
 * <syslog.h> and duplicate values, otherwise define them ourselves.
 */

#ifdef HAVE_SYSLOG
  #include <syslog.h>

  #define	VLOG_EMERG	LOG_EMERG
  #define	VLOG_ALERT	LOG_ALERT
  #define	VLOG_CRIT	LOG_CRIT
  #define	VLOG_ERR	LOG_ERR
  #define	VLOG_WARNING	LOG_WARNING
  #define	VLOG_NOTICE	LOG_NOTICE
  #define	VLOG_INFO	LOG_INFO
  #define	VLOG_DEBUG	LOG_DEBUG
#else
  #define	VLOG_EMERG	0
  #define	VLOG_ALERT	1
  #define	VLOG_CRIT	2
  #define	VLOG_ERR	3
  #define	VLOG_WARNING	4
  #define	VLOG_NOTICE	5
  #define	VLOG_INFO	6
  #define	VLOG_DEBUG	7
#endif

/***********
 * Windows *
 ***********/

#define	input	0
#define	chat	1

/********************************
 * Statusbar elements and order *
 * (left to right)              *
 ********************************/

#define STAT_LOGO	0x00
#define	STAT_FLAGS	0x01
#define STAT_CLOCK	0x02
#define	STAT_SERVER	0x03
#define	STAT_ONLINE	0x04
#define	STAT_NICK	0x05
#define	STAT_CHAN	0x06
#define	STAT_VARSP	0x07
#define	STAT_TERM	0x08
#define	STAT_SIZE	0x09

/*
 * Total number of statusline items
 */

#define	STAT_MAX	0x0A

/*
 * Item flags
 */

#define	NEEDS_UPDATE	0x01

/******************************
 * Interrupt modes and levels *
 ******************************/

#define	LOCK		0xE0
#define	UNLOCK		0xE8

#define	V_IO		0x01
#define	V_TIMER		0x02
#define	V_WINCH		0x04

/***********************
 * Input editor macros *
 ***********************/

#define		CP(x,y)		(u_int)((x * 8) + y)

#define		ED_USED		(u_int)((u_long)ed->endpos - (u_long)&ed->buffer)
#define		ED_FREE		(u_int)(((u_long)&ed->buffer + EDBUFSIZE) - (u_long)ed->endpos)
#define		ED_REMAIN	(u_int)((u_long)ed->endpos - (u_long)ed->curpos)

#if 1
#define		ED_SCRPOS	(u_int)((ed->flags & ED_NO_ECHO) ? (ed->offset + 1) : (((u_long)ed->curpos - (u_long)ed->margin) + ed->offset + 1))
#else
#define		ED_SCRPOS	((ed->flags & ED_NO_ECHO) == 0) ? (((u_long)ed->curpos - (u_long)ed->margin) + ed->offset + 1) : (ed->offset + 1)
#endif

#define		ED_ENDMARGIN	(char *)((char *)ed->margin + (u_long)vtcap.cols)
#define		ED_MARGINMAX	(char *)(ed->buffer + ((EDBUFSIZE + ed->offset) - vtcap.cols))

/*****************************
 * Terminal emulation macros *
 *****************************/

#define		HAS_COLOR	(vtcap.numcolors > 0 \
				&& vtcap.set_fg_color != NULL \
				&& vtcap.set_bg_color != NULL \
				&& vtcap.reset_color != NULL)

#define		HAS_IC		(vtcap.insertchar)
#define		HAS_IM		(vtcap.insert_on && vtcap.insert_off)
#define		HAS_DC		(vtcap.deletechar)
#define		HAS_DM		(vtcap.delete_on && vtcap.delete_off)
#define		HAS_SRC		(vtcap.csave && vtcap.crestore)

/**********************
 * Control structures *
 **********************/

typedef struct
{
#	define	ED_RST_CTX	0x0001	/* Reset context on startup	*/
#	define	ED_NO_ECHO	0x0002	/* Suppress terminal echo	*/
#	define	ED_HISTORY	0x0004	/* Enable cursor up/down keys	*/
#	define	ED_SHL_DONE	0x0008	/* Shell mode done		*/
	u_short	flags;			/* Input flags			*/

	u_long	maxlen;			/* Max. number of input chars	*/
	u_long	offset;			/* Prompt offset if any.	*/
	char	*prompt;		/* Prompt pointer or NULL	*/
	char	*endpos;		/* Ending position		*/
	char	*curpos;		/* Cursor position		*/
	char	*margin;		/* Left margin of input window	*/
	char	buffer[EDBUFSIZE+1];	/* Buffer plus Nullbyte		*/

} ED;

typedef struct
{
	struct	in_addr sv_ip;		/* IP address of server		*/
	struct	in_addr my_ip;		/* My own IP address		*/

	u_int	sv_port;		/* Server portnumber		*/

	char	user[VPUSERSIZE+1];	/* Username who invoked VChat	*/
	char	home[256];		/* Homedir of user		*/
	char	nick[VPNICKSIZE+1];	/* Nickname			*/
	char	tmpnick[VPNICKSIZE+1];	/* Unacknowledged nickname      */

	char	*emulation;		/* Terminal emulation if known	*/

	u_char	bs_mode;		/* Backspace mode		*/
	u_char	sc_mode;		/* Scrolling mode 		*/
	u_char	word_wrap;		/* Word-wrap on/off		*/
	u_char	indent;			/* Indent on/off		*/
	u_char	hicolor;		/* Hicolor on/off		*/
	u_char	cursordelay;		/* Cursor dealay in seconds	*/
	u_char	videosnake;		/* Videosnake delay in minutes  */
	u_char	matchbeep;		/* Matchbeep setting		*/

	u_char	vclock_pbc_enable;	/* Enable put-back-cursor timer */
	u_char	vclock_snake_enable;	/* Enable andalusian video snake*/

	u_char	logswitch;		/* Client log 0=off 1=on	*/
	u_char	logfile[256];		/* Logfile name                 */
	FILE	*logfl;			/* FILE* of open log file	*/
	u_long	logcnt;			/* Bytes written to logfile	*/
	u_char	cmdcontext_invalid;	/* Cmd input context is invalid	*/
	u_char	cmdmode;		/* Command mode active		*/
	u_char	**history;		/* History buffer pointer	*/
	u_char	history_lines;		/* Number of history lines	*/
	u_char	history_start;		/* Start of history		*/
	u_char	history_current;	/* Current history index	*/
	u_char	history_next;		/* Next entry in history buffer */
	u_char	history_cycle;		/* Cycle history buffer		*/

} VP;

typedef struct
{
	struct	in_addr cl_ip;		/* Client IP address		*/

	u_long	my_pid;			/* Our process ID		*/
	u_char	my_host[64];		/* Our hostname			*/

	char	env_cols[32];		/* COLUMNS environment		*/
	char	env_lines[32];		/* LINES environment		*/
	char	env_term[32];		/* Terminal emulation if known	*/

	u_char	emu_ok;			/* Termtype verified?		*/
	u_char	resize_ok;		/* Resize ok ?                  */

	u_char	logswitch;		/* GATElog: 0=off 1=on 2=syslog	*/
} VD;

typedef struct
{
	u_short	x;
	u_short	y;

} SIZE;

typedef struct
{
	char	capbuf[1024];	/* Termcap entry buffer			*/
	char	tbuf[1024];	/* Decode buffer			*/

	/*
	 * Terminal capabilities
	 */

	char	*home;			/* Cursor home			*/
	char	*cls;			/* Clear screen			*/
	char	*pos;			/* Absolute cursor adressing	*/
	char	*scr_reg;		/* Set scrolling region		*/
	char	*ck_app;		/* Cursor keys application mode	*/
	char	*ck_pos;		/* Cursor keys positioning mode	*/
	char	*csave;			/* Save cursor position		*/
	char	*crestore;		/* Restore cursor position	*/
	char	*scrollf;		/* Scroll forward		*/
	char	*scrollr;		/* Scroll reverse		*/
	char	*clear2eol;		/* Clear to end-of-line		*/
	char	*clear2eod;		/* Clear to end of display	*/
	char	*metamode_on;		/* Turn on Meta mode (8bit)	*/
	char	*metamode_off;		/* Turn off Meta mode (7bit)	*/
	char	*insert_on;		/* Turn insert mode on		*/
	char	*insert_off;		/* Turn insert mode off		*/
	char	*delete_on;		/* Turn delete mode on		*/
	char	*delete_off;		/* Turn delete mode off		*/
	char	*insertchar;		/* Insert character		*/
	char	*deletechar;		/* Delete character		*/
	char	*term_init;		/* Terminal init string		*/
	char	*term_reset;		/* Terminal reset string	*/

	int	numcolors;		/* Number of colors available	*/
	char	*set_fg_color;		/* Set foreground color		*/
	char	*set_bg_color;		/* Set background color		*/
	char	*reset_color;		/* Reset colors to normal values*/

	char	*reverse;		/* Reverse video on		*/
	char	*underline;		/* Underline mode on		*/
	char	*bold;			/* Bold mode on			*/
	char	*blink;			/* Blink mode on		*/
	char	*dim;			/* Half bright mode on		*/
	char	*protected;		/* Protected mode on		*/
	char	*off;			/* Turn off all attributes	*/

	/*
	 * Key sequences used for input processing.
	 */

	char	*key_cursup;		/* Key UP sequence		*/
	char	*key_cursdown;		/* Key DOWN sequence		*/
	char	*key_cursleft;		/* Key LEFT sequence		*/
	char	*key_cursright;		/* Key RIGHT sequence		*/

	char	*key_bs;		/* Backspace key		*/
	char	*key_delete;		/* Key DELET sequence		*/
	char	*key_insert;		/* Key INSERT sequence		*/
	char	*key_cleareol;		/* Clear to end-of-line key	*/
	char	*key_cleareos;		/* Clear to end-of-screen key	*/
	char	*key_scrollf;		/* Scroll-forward key		*/
	char	*key_scrollr;		/* Scroll-reverse key		*/
	char	*key_delln;		/* Delete-line key		*/
	char	*key_cls;		/* Clear screen key		*/
	char	*key_prevpage;		/* Previous page key		*/
	char	*key_nextpage;		/* Next page key		*/

	int	cols;			/* Number of columns on screen	*/
	int	rows;			/* Number of rows on screen	*/

} VTCAP;

typedef struct
{
	time_t	clocksrc;
	time_t	pbc_timer;
	time_t	snake_timer;

} VTIMER;

typedef struct
{
	int			fd;
	struct	sockaddr_in 	saddr;
	u_char			host[64];
	VIDENT			vid;

} VCONN;

typedef struct
{
	u_char	buf[64];
	u_char	flags;
	u_char	size;

} STAT_ITEM;

typedef struct
{
	u_char	nick[VPNICKSIZE + 1];

} ULIST_ITEM;

#endif /* __VCHAT_H__ */


syntax highlighted by Code2HTML, v. 0.9.1