home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / ytalk-3.0 / part01 / header.h < prev    next >
C/C++ Source or Header  |  1993-08-20  |  12KB  |  313 lines

  1. /* header.h */
  2.  
  3. /*               NOTICE
  4.  *
  5.  * Copyright (c) 1990,1992,1993 Britt Yenne.  All rights reserved.
  6.  * 
  7.  * This software is provided AS-IS.  The author gives no warranty,
  8.  * real or assumed, and takes no responsibility whatsoever for any 
  9.  * use or misuse of this software, or any damage created by its use
  10.  * or misuse.
  11.  * 
  12.  * This software may be freely copied and distributed provided that
  13.  * no part of this NOTICE is deleted or edited in any manner.
  14.  * 
  15.  */
  16.  
  17. /* Mail comments or questions to ytalk@austin.eds.com */
  18.  
  19. #include <sys/types.h>
  20. #include <sys/param.h>
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <errno.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #ifdef USE_X11
  28. # include <X11/X.h>
  29. #endif
  30.  
  31. #define VMAJOR    3    /* major version number */
  32. #define VMINOR    0    /* minor version number */
  33.  
  34. /* ---- YTalk protocols ---- */
  35.  
  36. /* These protocol numbers are a MAJOR HACK designed to get around the
  37.  * fact that old versions of ytalk didn't send any version information
  38.  * during handshaking.  Nor did they bzero() the unused portions of the
  39.  * handshaking structures.  Argh!  These two protocol numbers were very
  40.  * carefully picked... do not add any others and expect them to work.
  41.  * Instead, use the "vmajor" and "vminor" fields of the y_parm structure.
  42.  */
  43. #define YTP_OLD    20    /* YTalk versions before 3.0 */
  44. #define YTP_NEW    27    /* YTalk versions 3.0 and up */
  45.  
  46. /* ---- types ---- */
  47.  
  48. typedef void *    yaddr;        /* any 32-bit address */
  49. typedef yaddr    yterm;        /* terminal cookie */
  50. typedef u_char    ychar;        /* we use unsigned chars */
  51.  
  52. typedef struct {
  53.     u_char w_rows, w_cols;    /* window size FOR PROTOCOL YTP_OLD */
  54.     char protocol;        /* ytalk protocol -- see above */
  55.     char pad1;            /* zeroed out */
  56.     short vmajor, vminor;    /* version numbers */
  57.     u_short rows, cols;        /* his window size over there */
  58.     u_short my_rows, my_cols;    /* my window size over there */
  59.     u_long pid;            /* my process id */
  60.     char pad[44];        /* zeroed out */
  61. } y_parm;
  62.  
  63. #define MAXARG    4        /* max ESC sequence arg count */
  64.  
  65. typedef struct _yuser {
  66.     struct _yuser *next;    /* next user in group lists */
  67.     struct _yuser *unext;    /* next user in full user list */
  68.     int fd;            /* file descriptor */
  69.     int output_fd;        /* non-zero if output is going to a file */
  70.     u_long flags;        /* active FL_* flags below */
  71.     ychar edit[4];        /* edit characters */
  72.     u_short t_rows, t_cols;    /* his rows and cols on window over here */
  73.     u_short rows, cols;        /* his active region rows and cols over here */
  74.     y_parm remote;        /* remote parms */
  75.     ychar **scr;        /* screen data */
  76.     char bump;            /* set if at far right */
  77.     ychar old_rub;        /* my actual rub character */
  78.     char got_esc;        /* received an ESC */
  79.     ychar key;            /* this user's ident letter for menus */
  80.     int y, x;            /* current cursor position */
  81.     int sy, sx;            /* saved cursor position */
  82.     int sc_top, sc_bot;        /* scrolling region */
  83.     int region_set;        /* set if using a screen region */
  84.     char *full_name;        /* full name (up to 50 chars) */
  85.     char *user_name;        /* user name */
  86.     char *host_name;        /* host name */
  87.     char *tty_name;        /* tty name */
  88.     u_long host_addr;        /* host inet address */
  89.     int daemon;            /* daemon type to use */
  90.     u_long l_id, r_id;        /* local and remote talkd invite list index */
  91.     u_long d_id;        /* talk daemon process id -- see socket.c */
  92.     long last_invite;        /* timestamp of last invitation sent */
  93.     struct sockaddr_in sock;    /* communication socket */
  94.     struct sockaddr_in orig_sock; /* original socket -- another sick hack */
  95.     u_int av[MAXARG];        /* ESC sequence arguments */
  96.     u_int ac;            /* ESC sequence arg count */
  97.  
  98.     /* out-of-band data */
  99.  
  100.     int dbuf_size;        /* current buffer size */
  101.     ychar *dbuf, *dptr;        /* buffer base and current pointer */
  102.     int drain;            /* remaining bytes to drain */
  103.     void (*dfunc)();        /* function to call with drained data */
  104.     int got_oob;        /* got OOB flag */
  105.  
  106.     /* anything below this is available for the terminal interface */
  107.  
  108.     yterm term;            /* terminal cookie */
  109.     int ty, tx;            /* terminal's idea of Y,X (optional) */
  110. #ifdef USE_X11
  111.     Window win;            /* user's window */
  112. #endif
  113. } yuser;
  114.  
  115. #define FL_RAW        0x00000001L    /* raw input enabled */
  116. #define FL_SCROLL    0x00000002L    /* scrolling enabled */
  117. #define FL_WRAP        0x00000004L    /* word-wrap enabled */
  118. #define FL_IMPORT    0x00000008L    /* auto-import enabled */
  119. #define FL_INVITE    0x00000010L    /* auto-invite enabled */
  120. #define FL_RING        0x00000020L    /* auto-rering enabled */
  121. #define FL_XWIN        0x00000040L    /* X Windows enabled (startup opt) */
  122. #define FL_LOCKED    0x40000000L    /* flags locked by other end */
  123.  
  124. /* ---- defines and short-cuts ---- */
  125.  
  126. #ifdef NOFILE
  127. # define MAX_FILES    NOFILE    /* max open file descriptors */
  128. #else
  129. # define MAX_FILES    256    /* better to be too high than too low */
  130. #endif
  131. #define CLEAN_INTERVAL    16    /* seconds between calls to house_clean() */
  132. #define MAXBUF        4096    /* buffer size for I/O operations */
  133. #define MAXERR        132    /* error text buffer size */
  134. #define MAXTEXT        50    /* text entry buffer */
  135.  
  136. #define RUB    edit[0]
  137. #define KILL    edit[1]
  138. #define WORD    edit[2]
  139. #define CLR    edit[3]
  140. #define RUBDEF    0xfe
  141.  
  142. /* ---- Ytalk version 3.* out-of-band data ---- */
  143.  
  144. /* see comm.c for a description of Ytalk 3.* OOB protocol */
  145.  
  146. #define V3_OOB        0xfd    /* out-of-band marker -- see comm.c */
  147. #define V3_MAXPACK    0xfc    /* max OOB packet size -- see comm.c */
  148. #define V3_NAMELEN    16    /* max username length */
  149. #define V3_HOSTLEN    64    /* max hostname length */
  150.  
  151. typedef struct {
  152.     ychar code;            /* V3_EXPORT, V3_IMPORT, or V3_ACCEPT */
  153.     char filler[3];
  154.     u_long host_addr;        /* host address */
  155.     u_long pid;            /* process id */
  156.     char name[V3_NAMELEN];    /* user name */
  157.     char host[V3_HOSTLEN];    /* host name */
  158. } v3_pack;
  159.  
  160. #define V3_PACKLEN    sizeof(v3_pack)
  161. #define V3_EXPORT    101    /* export a user */
  162. #define V3_IMPORT    102    /* import a user */
  163. #define V3_ACCEPT    103    /* accept a connection from a user */
  164.  
  165. typedef struct {
  166.     ychar code;            /* V3_LOCKF or V3_UNLOCKF */
  167.     char filler[3];
  168.     u_long flags;        /* flags */
  169. } v3_flags;
  170.  
  171. #define V3_FLAGSLEN    sizeof(v3_flags)
  172. #define V3_LOCKF    111    /* lock my flags */
  173. #define V3_UNLOCKF    112    /* unlock my flags */
  174.  
  175. typedef struct {
  176.     ychar code;            /* V3_YOURWIN, V3_MYWIN, or V3_REGION */
  177.     char filler[3];
  178.     u_short rows, cols;        /* window size */
  179. } v3_winch;
  180.  
  181. #define V3_WINCHLEN    sizeof(v3_winch)
  182. #define V3_YOURWIN    121    /* your window size changed over here */
  183. #define V3_MYWIN    122    /* my window size changed over here */
  184. #define V3_REGION    123    /* my window region changed over here */
  185.  
  186. /* ---- Ytalk version 2.* out-of-band data ---- */
  187.  
  188. #define V2_NAMELEN    12
  189. #define V2_HOSTLEN    64
  190.  
  191. typedef struct {
  192.     ychar code;            /* one of the V2_?? codes below */
  193.     char filler;
  194.     char name[V2_NAMELEN];    /* user name */
  195.     char host[V2_HOSTLEN];    /* user host */
  196. } v2_pack;
  197.  
  198. #define V2_PACKLEN    sizeof(v2_pack)
  199. #define V2_EXPORT    130    /* export a user */
  200. #define V2_IMPORT    131    /* import a user */
  201. #define V2_ACCEPT    132    /* accept a connection from a user */
  202. #define V2_AUTO        133    /* accept auto invitation */
  203.  
  204. /* ---- exit codes ---- */
  205.  
  206. #define YTE_SUCCESS    0    /* successful completion */
  207. #define YTE_INIT    1    /* initialization error */
  208. #define YTE_NO_MEM    2    /* out of memory */
  209. #define YTE_SIGNAL    3    /* fatal signal received */
  210. #define YTE_ERROR    4    /* unrecoverable error */
  211.  
  212. /* ---- global variables ---- */
  213.  
  214. extern char *sys_errlist[];    /* system errors */
  215.  
  216. extern yuser *me;        /* just lil' ol' me */
  217. extern yuser *user_list;    /* full list of invited/connected users */
  218. extern yuser *connect_list;    /* list of connected users */
  219. extern yuser *wait_list;    /* list of invited users */
  220. extern yuser *fd_to_user[MAX_FILES];    /* convert file descriptors to users */
  221. extern yuser *key_to_user[128];    /* convert menu ident chars to users */
  222. extern char errstr[MAXERR];    /* temporary string for errors */
  223. extern u_long def_flags;    /* default FL_* flags */
  224. extern int user_winch;        /* user window/status changed flag */
  225.  
  226. extern ychar *io_ptr;        /* user input pointer */
  227. extern int    io_len;        /* user input count */
  228.  
  229. extern int running_process;    /* flag: is process running? */
  230.  
  231. /* ---- global functions ---- */
  232.  
  233. extern void    bail        ( /* int */ );            /* main.c */
  234. extern yaddr    get_mem        ( /* int */ );            /* main.c */
  235. extern char    *str_copy    ( /* string */ );        /* main.c */
  236. extern yaddr    realloc_mem    ( /* pointer, int */ );        /* main.c */
  237. extern void    show_error    ( /* str */ );            /* main.c */
  238.  
  239. extern void    init_term    ();                /* term.c */
  240. extern void    set_terminal_size  ( /* fd, rows, cols */ );    /* term.c */
  241. extern void    set_terminal_flags ( /* fd */ );        /* term.c */
  242. extern int    what_term    ();                /* term.c */
  243. extern void    end_term    ();                /* term.c */
  244. extern int    open_term    ( /* yuser, title */ );        /* term.c */
  245. extern void    close_term    ( /* yuser */ );        /* term.c */
  246. extern void    addch_term    ( /* yuser, ch */ );        /* term.c */
  247. extern void    move_term    ( /* yuser, y, x */ );        /* term.c */
  248. extern void    clreol_term    ( /* yuser */ );        /* term.c */
  249. extern void    clreos_term    ( /* yuser */ );        /* term.c */
  250. extern void    scroll_term    ( /* yuser */ );        /* term.c */
  251. extern void    rev_scroll_term    ( /* yuser */ );        /* term.c */
  252. extern void    flush_term    ( /* yuser */ );        /* term.c */
  253. extern void    rub_term    ( /* yuser */ );        /* term.c */
  254. extern int    word_term    ( /* yuser */ );        /* term.c */
  255. extern void    kill_term    ( /* yuser */ );        /* term.c */
  256. extern void    tab_term    ( /* yuser */ );        /* term.c */
  257. extern void    newline_term    ( /* yuser */ );        /* term.c */
  258. extern void    add_line_term    ( /* yuser, num */ );        /* term.c */
  259. extern void    del_line_term    ( /* yuser, num */ );        /* term.c */
  260. extern void    add_char_term    ( /* yuser, num */ );        /* term.c */
  261. extern void    del_char_term    ( /* yuser, num */ );        /* term.c */
  262. extern void    redraw_term    ( /* yuser, start_row */ );    /* term.c */
  263. extern void    resize_win    ( /* yuser, h, w */ );        /* term.c */
  264. extern void    set_win_region    ( /* yuser, h, w */ );        /* term.c */
  265. extern void    end_win_region    ( /* yuser */ );        /* term.c */
  266. extern void    set_scroll_region( /* yuser, top, bottom */ );    /* term.c */
  267. extern void    msg_term    ( /* yuser, str */ );        /* term.c */
  268. extern void    spew_term    ( /* yuser, fd, rows, cols */ ); /* term.c */
  269. extern int    center        ( /* width, n */ );        /* term.c */
  270.  
  271. extern void    init_user    ();                /* user.c */
  272. extern yuser   *new_user    ( /* name, host, tty */ );    /* user.c */
  273. extern void    free_user    ( /* yuser */ );        /* user.c */
  274. extern yuser   *find_user    ( /* name, host_addr, pid */ );    /* user.c */
  275.  
  276. extern void    init_fd        ();                /* fd.c */
  277. extern void    add_fd        ( /* fd, func */ );        /* fd.c */
  278. extern void    remove_fd    ( /* fd */ );            /* fd.c */
  279. extern int    full_read    ( /* fd, buf, len */ );        /* fd.c */
  280. extern void    main_loop    ();                /* fd.c */
  281. extern void    input_loop    ();                /* fd.c */
  282.  
  283. extern void    invite        ( /* username, announce */ );    /* comm.c */
  284. extern void    house_clean    ();                /* comm.c */
  285. extern void    send_winch    ( /* yuser */ );        /* comm.c */
  286. extern void    send_region    ();                /* comm.c */
  287. extern void    send_end_region    ();                /* comm.c */
  288. extern void    send_users    ( /* buf, len */ );        /* comm.c */
  289. extern void    show_input    ( /* user, buf, len */ );    /* comm.c */
  290. extern void    my_input    ( /* buf, len */ );        /* comm.c */
  291. extern void    lock_flags    ( /* flags */ );        /* comm.c */
  292. extern void    unlock_flags    ();                /* comm.c */
  293.  
  294. extern void    init_socket    ();                /* socket.c */
  295. extern void    close_all    ();                /* socket.c */
  296. extern int    send_dgram    ( /* user, type */ );        /* socket.c */
  297. extern int    send_auto    ( /* type */ );            /* socket.c */
  298. extern void    kill_auto    ();                /* socket.c */
  299. extern int    newsock        ( /* yuser */ );        /* socket.c */
  300. extern int    connect_to    ( /* yuser */ );        /* socket.c */
  301. extern u_long    get_host_addr    ( /* hostname */ );        /* socket.c */
  302. extern char    *host_name    ( /* addr */ );            /* socket.c */
  303. extern void    readdress_host    ( /* from, to, on */ );        /* socket.c */
  304.  
  305. extern void    read_ytalkrc    ();                /* rc.c */
  306.  
  307. extern void    execute        ( /* command */ );        /* exec.c */
  308. extern void    update_exec    ();                /* exec.c */
  309. extern void    kill_exec    ();                /* exec.c */
  310. extern void    winch_exec    ();                /* exec.c */
  311.  
  312. /* EOF */
  313.