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