From f5b50d6c0e974bd0b407b3032c0895f29855d29d Mon Sep 17 00:00:00 2001 From: james Date: Wed, 13 Feb 2008 18:05:06 +0000 Subject: [PATCH] *** empty log message *** --- apps/Makefile.am | 9 +- apps/client.c | 17 +++ apps/client.h | 23 ++++ apps/clients.c | 61 ++++++++++ apps/clients.h | 43 +++++++ apps/sympathyd.c | 42 ++++--- configure.in | 28 ++++- src/Makefile.am | 11 +- src/project.h | 6 +- src/prototypes.h | 203 +++++++++++++++++---------------- src/sympathy.h.head.in | 34 ++++++ src/symsocket.c | 249 +++++++++++++++++++++++++++++++++++++++++ src/symsocket.h | 36 ++++++ src/terminal.c | 12 +- test/test.c | 6 + version-files | 2 +- 16 files changed, 649 insertions(+), 133 deletions(-) create mode 100644 apps/client.c create mode 100644 apps/client.h create mode 100644 apps/clients.c create mode 100644 apps/clients.h create mode 100644 src/symsocket.c create mode 100644 src/symsocket.h diff --git a/apps/Makefile.am b/apps/Makefile.am index f2b82b4..6b4d868 100644 --- a/apps/Makefile.am +++ b/apps/Makefile.am @@ -7,6 +7,9 @@ # $Id$ # # $Log$ +# Revision 1.3 2008/02/13 18:05:06 james +# *** empty log message *** +# # Revision 1.2 2008/02/06 11:30:45 james # *** empty log message *** # @@ -20,10 +23,12 @@ INCLUDES = -I$(srcdir)/../src noinst_PROGRAMS = sympathyd sympathy -sympathy_SOURCES = sympathy.c +noinst_HEADERS=clients.h client.h + +sympathy_SOURCES = sympathy.c client.c sympathy_LDADD = ../src/libsympathy.la -lutil -sympathyd_SOURCES = sympathyd.c +sympathyd_SOURCES = sympathyd.c clients.c client.c sympathyd_LDADD = ../src/libsympathy.la -lutil AM_CFLAGS=-g diff --git a/apps/client.c b/apps/client.c new file mode 100644 index 0000000..e1b650e --- /dev/null +++ b/apps/client.c @@ -0,0 +1,17 @@ +/* + * client.c: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +static char rcsid[] = "$Id$"; + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + diff --git a/apps/client.h b/apps/client.h new file mode 100644 index 0000000..52293d1 --- /dev/null +++ b/apps/client.h @@ -0,0 +1,23 @@ +/* + * client.h: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + +#ifndef __CLIENT_H__ +#define __CLIENT_H__ + +#endif /* __CLIENT_H__ */ diff --git a/apps/clients.c b/apps/clients.c new file mode 100644 index 0000000..234c0ed --- /dev/null +++ b/apps/clients.c @@ -0,0 +1,61 @@ +/* + * clients.c: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +static char rcsid[] = "$Id$"; + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + +#include +#include "clients.h" + + +void clients_output (Clients *c, void *_buf, int len) +{ + +} + +Clients *clients_new(void) +{ + + + +return NULL; +} + +void clients_pre_select (Clients *c, fd_set *rfds, fd_set *wfds) +{ + + +} + +void clients_post_select(Clients *c,Context *ctx, fd_set *rfds, fd_set *wfds) +{ + + +} + +Client * clients_new_client(Clients *c,Socket *s,Context *ctx) +{ + +ipc_msg_send_debug(s,"fishsoup"); +socket_free(s); + +return NULL; +} + +void clients_shutdown(Clients *c) +{ + + + +} diff --git a/apps/clients.h b/apps/clients.h new file mode 100644 index 0000000..78ecdc3 --- /dev/null +++ b/apps/clients.h @@ -0,0 +1,43 @@ +/* + * clients.h: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + +#ifndef __CLIENTS_H__ +#define __CLIENTS_H__ + +typedef struct Client_struct { + struct Client_struct *next; + + Socket *s; + int dead; +} Client; + +typedef struct { + Client *head; + int n; +} Clients; + + +extern Clients *clients_new(void); +extern void clients_pre_select (Clients *, fd_set *, fd_set *); +extern void clients_post_select(Clients *,Context *, fd_set *, fd_set *); +extern Client *clients_new_client(Clients *,Socket *,Context *); +extern void clients_shutdown(Clients *); +extern void clients_output (Clients *, void *, int); + +#endif /* __CLIENTS_H__ */ diff --git a/apps/sympathyd.c b/apps/sympathyd.c index 820f4d9..2e45ed1 100644 --- a/apps/sympathyd.c +++ b/apps/sympathyd.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/02/13 18:05:06 james + * *** empty log message *** + * * Revision 1.4 2008/02/13 17:21:55 james * *** empty log message *** * @@ -24,16 +27,18 @@ static char rcsid[] = "$Id$"; * */ -#include "sympathy.h" +#include -#include -void main (int argc,char *argv[]) +#include "client.h" +#include "clients.h" + +int main (int argc,char *argv[]) { - fd_set rfd, wfd; + fd_set rfds, wfds; ANSI a = { 0 }; Context c; Socket *s, *cs; - Client **clients; + Clients *clients; s = socket_listen ("socket"); @@ -55,34 +60,35 @@ void main (int argc,char *argv[]) struct timeval tv = { 0, 100000 }; - FD_ZERO (&rfd); - FD_ZERO (&wfd); + FD_ZERO (&rfds); + FD_ZERO (&wfds); - tty_pre_select (c.t, &rfd); - tty_pre_select (a.terminal, &rfd); + tty_pre_select (c.t, &rfds,&wfds); + tty_pre_select (a.terminal, &rfds,&wfds); - socket_pre_select (s, &rfd, &wfd); + socket_pre_select (s, &rfds, &wfds); - client_pre_select (clients); + clients_pre_select (clients,&rfds,&wfds); - select (FD_SETSIZE, &rfd, NULL, NULL, &tv); + select (FD_SETSIZE, &rfds, NULL, NULL, &tv); - cs = socket_post_select (s, &rfd, &wfd); + cs = socket_post_select (s, &rfds, &wfds); if (cs) { /*New client connexion */ - clients_new (clients, cs, c); + clients_new_client (clients, cs, &c); } - clients_post_select (clients, c, &rfds, &wfds); - if (FD_ISSET (c->t->rfd, &rfds)) + clients_post_select (clients, &c, &rfds, &wfds); + + if (FD_ISSET (c.t->rfd, &rfds)) { char buf[1024]; int red; - red = c->t->recv (c->t, buf, sizeof (buf)); + red = c.t->recv (c.t, buf, sizeof (buf)); if (red < 0) break; @@ -90,7 +96,7 @@ void main (int argc,char *argv[]) if (red) { clients_output (clients, buf, red); - vt102_parse (c, buf, red); + vt102_parse (&c, buf, red); } } diff --git a/configure.in b/configure.in index 91c7516..1db47fe 100644 --- a/configure.in +++ b/configure.in @@ -8,6 +8,9 @@ dnl dnl $Id$ dnl dnl $Log$ +dnl Revision 1.2 2008/02/13 18:05:06 james +dnl *** empty log message *** +dnl dnl Revision 1.1 2008/02/03 16:20:23 james dnl *** empty log message *** dnl @@ -96,17 +99,36 @@ G2_HAVE_UNISTD_H=0 if test "$ac_cv_header_unistd_h" = "yes"; then G2_HAVE_UNISTD_H=1 fi +G2_HAVE_MALLOC_H=0 +if test "$ac_cv_header_malloc_h" = "yes"; then + G2_HAVE_MALLOC_H=1 +fi +G2_HAVE_STDINT_H=0 +if test "$ac_cv_header_stdint_h" = "yes"; then + G2_HAVE_STDINT_H=1 +fi +G2_TIME_WITH_SYS_TIME=0 +if test "$ac_cv_header_time_h" = "yes"; then + G2_TIME_WITH_SYS_TIME=1 +fi +G2_TM_IN_SYS_TIME=0 +if test "$ac_cv_struct_tm" = "sys/time.h"; then + G2_TM_IN_SYS_TIME=1 +fi + AC_SUBST(G2_TM_H) AC_SUBST(G2_HAVE_STDINT_H) AC_SUBST(G2_HAVE_SYS_INT_TYPES_H) AC_SUBST(G2_HAVE_UNISTD_H) - - +AC_SUBST(G2_HAVE_MALLOC_H) +AC_SUBST(G2_HAVE_STDINT_H) +AC_SUBST(G2_TIME_WITH_SYS_TIME) +AC_SUBST(G2_TM_IN_SYS_TIME) AC_OUTPUT([Makefile src/Makefile - src/sympathy.h + src/sympathy.h.head test/Makefile apps/Makefile libsympathy-config.src],[chmod +x libsympathy-config.src]) diff --git a/src/Makefile.am b/src/Makefile.am index efbeda7..63a00b4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ # $Id$ # # $Log$ +# Revision 1.10 2008/02/13 18:05:06 james +# *** empty log message *** +# # Revision 1.9 2008/02/13 16:57:29 james # *** empty log message *** # @@ -41,12 +44,12 @@ INCLUDES= -PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h context.h prototypes.h +PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h context.h symsocket.h prototypes.h HDRS=project.h SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c \ - history.c ring.c ptty.c terminal.c util.c log.c ipc.c slide.c + history.c ring.c ptty.c terminal.c util.c log.c ipc.c slide.c symsocket.c CPROTO=cproto @@ -67,7 +70,7 @@ lib_LTLIBRARIES=libsympathy.la include_HEADERS=sympathy.h -AM_CFLAGS=-g +AM_CFLAGS=-g -Werror libsympathy_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ @@ -83,7 +86,7 @@ VDEF=${shell echo `cat ${VFD}/version-major`.`cat ${VFD}/version-minor`.`cat ${V protos: echo > prototypes.h - ${CPROTO} -v ${INCLUDES} ${SRCS} > prototypes.tmp + ${CPROTO} -e -v ${INCLUDES} ${SRCS} > prototypes.tmp mv -f prototypes.tmp prototypes.h tidy: ${SRCS} ${HDRS} diff --git a/src/project.h b/src/project.h index c30ff77..1f46906 100644 --- a/src/project.h +++ b/src/project.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.9 2008/02/13 18:05:06 james + * *** empty log message *** + * * Revision 1.8 2008/02/13 16:57:29 james * *** empty log message *** * @@ -81,10 +84,9 @@ #include #endif -#include -#include #include #include + #include #include #include diff --git a/src/prototypes.h b/src/prototypes.h index df2d7d5..ee95d30 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,115 +1,120 @@ /* ansi.c */ -int terminal_winches; -void ansi_move(ANSI *a, CRT_Pos p); -void ansi_showhide_cursor(ANSI *a, int hide); -void ansi_force_attr_normal(ANSI *a); -void ansi_set_color(ANSI *a, int color); -void ansi_set_attr(ANSI *a, int attr); -void ansi_render(ANSI *a, CRT_CA ca); -void ansi_cls(ANSI *a); -void ansi_draw_line(ANSI *a, CRT_CA *cap, int y); -void ansi_resize_check(ANSI *a); -void ansi_history(ANSI *a, History *h); -void ansi_draw(ANSI *a, CRT *c); -void ansi_reset(ANSI *a, CRT *c); -void ansi_terminal_reset(ANSI *a); -void ansi_flush_escape(ANSI *a, Context *c); -void ansi_parse_deckey(ANSI *a, Context *c); -void ansi_parse_ansikey(ANSI *a, Context *c); -void ansi_parse_escape(ANSI *a, Context *c); -void ansi_check_escape(ANSI *a, Context *c); -void ansi_parse_char(ANSI *a, Context *c, int ch); -void ansi_parse(ANSI *a, Context *c, char *buf, int len); -int ansi_dispatch(ANSI *a, Context *c); -void ansi_update(ANSI *a, Context *c); +extern void ansi_move(ANSI *a, CRT_Pos p); +extern void ansi_showhide_cursor(ANSI *a, int hide); +extern void ansi_force_attr_normal(ANSI *a); +extern void ansi_set_color(ANSI *a, int color); +extern void ansi_set_attr(ANSI *a, int attr); +extern void ansi_render(ANSI *a, CRT_CA ca); +extern void ansi_cls(ANSI *a); +extern void ansi_draw_line(ANSI *a, CRT_CA *cap, int y); +extern void ansi_resize_check(ANSI *a); +extern void ansi_history(ANSI *a, History *h); +extern void ansi_draw(ANSI *a, CRT *c); +extern void ansi_reset(ANSI *a, CRT *c); +extern void ansi_terminal_reset(ANSI *a); +extern void ansi_flush_escape(ANSI *a, Context *c); +extern void ansi_parse_deckey(ANSI *a, Context *c); +extern void ansi_parse_ansikey(ANSI *a, Context *c); +extern void ansi_parse_escape(ANSI *a, Context *c); +extern void ansi_check_escape(ANSI *a, Context *c); +extern void ansi_parse_char(ANSI *a, Context *c, int ch); +extern void ansi_parse(ANSI *a, Context *c, char *buf, int len); +extern int ansi_dispatch(ANSI *a, Context *c); +extern void ansi_update(ANSI *a, Context *c); /* crt.c */ -void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea); -void crt_cls(CRT *c); -void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea); -void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea); -void crt_reset(CRT *c); -void crt_insert(CRT *c, CRT_CA ca); +extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea); +extern void crt_cls(CRT *c); +extern void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea); +extern void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea); +extern void crt_reset(CRT *c); +extern void crt_insert(CRT *c, CRT_CA ca); /* html.c */ -void html_entity(FILE *f, int c); -void html_render(FILE *f, CRT_CA c); -void html_draw(FILE *f, CRT *c); +extern void html_entity(FILE *f, int c); +extern void html_render(FILE *f, CRT_CA c); +extern void html_draw(FILE *f, CRT *c); /* libsympathy.c */ /* render.c */ /* version.c */ /* vt102.c */ -void vt102_log_line(Context *c, int line); -void vt102_history(Context *c, CRT_Pos t, CRT_Pos b); -void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br); -void vt102_cursor_normalize(VT102 *v); -void vt102_cursor_carriage_return(VT102 *v); -void vt102_cursor_advance_line(Context *c); -void vt102_cursor_advance(Context *c); -void vt102_do_pending_wrap(Context *c); -void vt102_cursor_retard(VT102 *v); -void vt102_reset_tabs(VT102 *v); -void vt102_cursor_advance_tab(VT102 *v); -int vt102_cursor_home(VT102 *v); -int vt102_cursor_absolute(VT102 *v, int x, int y); -int vt102_cursor_relative(VT102 *v, int x, int y); -void vt102_delete_from_line(VT102 *v, CRT_Pos p); -void vt102_insert_into_line(VT102 *v, CRT_Pos p); -void vt102_change_mode(VT102 *v, int private, char *ns, int set); -void vt102_parse_mode_string(VT102 *v, char *buf, int len); -void vt102_change_attr(VT102 *v, char *na); -void vt102_parse_attr_string(VT102 *v, char *buf, int len); -void vt102_save_state(VT102 *v); -void vt102_restore_state(VT102 *v); -void vt102_scs(Context *c, int g, int s); -void vt102_parse_esc(Context *c, int ch); -void vt102_parse_csi(Context *c, char *buf, int len); -void vt102_status_line(VT102 *v, char *str); -void vt102_parse_char(Context *c, int ch); -int vt102_parse(Context *c, char *buf, int len); -void vt102_parser_reset(VT102_parser *p); -void vt102_send(Context *c, uint8_t key); -void vt102_reset(VT102 *v); -int vt102_dispatch(Context *c); -int vt102_dispatch_one(Context *c); -VT102 *vt102_new(void); -void vt102_free(VT102 *v); +extern void vt102_log_line(Context *c, int line); +extern void vt102_history(Context *c, CRT_Pos t, CRT_Pos b); +extern void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br); +extern void vt102_cursor_normalize(VT102 *v); +extern void vt102_cursor_carriage_return(VT102 *v); +extern void vt102_cursor_advance_line(Context *c); +extern void vt102_cursor_advance(Context *c); +extern void vt102_do_pending_wrap(Context *c); +extern void vt102_cursor_retard(VT102 *v); +extern void vt102_reset_tabs(VT102 *v); +extern void vt102_cursor_advance_tab(VT102 *v); +extern int vt102_cursor_home(VT102 *v); +extern int vt102_cursor_absolute(VT102 *v, int x, int y); +extern int vt102_cursor_relative(VT102 *v, int x, int y); +extern void vt102_delete_from_line(VT102 *v, CRT_Pos p); +extern void vt102_insert_into_line(VT102 *v, CRT_Pos p); +extern void vt102_change_mode(VT102 *v, int private, char *ns, int set); +extern void vt102_parse_mode_string(VT102 *v, char *buf, int len); +extern void vt102_change_attr(VT102 *v, char *na); +extern void vt102_parse_attr_string(VT102 *v, char *buf, int len); +extern void vt102_save_state(VT102 *v); +extern void vt102_restore_state(VT102 *v); +extern void vt102_scs(Context *c, int g, int s); +extern void vt102_parse_esc(Context *c, int ch); +extern void vt102_parse_csi(Context *c, char *buf, int len); +extern void vt102_status_line(VT102 *v, char *str); +extern void vt102_parse_char(Context *c, int ch); +extern int vt102_parse(Context *c, char *buf, int len); +extern void vt102_parser_reset(VT102_parser *p); +extern void vt102_send(Context *c, uint8_t key); +extern void vt102_reset(VT102 *v); +extern int vt102_dispatch(Context *c); +extern int vt102_dispatch_one(Context *c); +extern VT102 *vt102_new(void); +extern void vt102_free(VT102 *v); /* tty.c */ -void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds); +extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds); /* history.c */ -History *history_new(int n); -void history_free(History *h); -void history_add(History *h, CRT_CA *c); +extern History *history_new(int n); +extern void history_free(History *h); +extern void history_add(History *h, CRT_CA *c); /* ring.c */ -int ring_read(Ring *r, void *b, int n); -int ring_write(Ring *r, void *b, int n); -int ring_space(Ring *r); -int ring_bytes(Ring *r); -Ring *ring_new(int n); +extern int ring_read(Ring *r, void *b, int n); +extern int ring_write(Ring *r, void *b, int n); +extern int ring_space(Ring *r); +extern int ring_bytes(Ring *r); +extern Ring *ring_new(int n); /* ptty.c */ -TTY *ptty_open(char *path, char *argv[]); +extern TTY *ptty_open(char *path, char *argv[]); /* terminal.c */ -void terminal_atexit(void); -void terminal_getsize(TTY *_t); -void terminal_dispatch(void); -void terminal_register_handlers(void); -TTY *terminal_open(int rfd, int wfd); +extern int terminal_winches; +extern void terminal_atexit(void); +extern void terminal_getsize(TTY *_t); +extern void terminal_dispatch(void); +extern void terminal_register_handlers(void); +extern TTY *terminal_open(int rfd, int wfd); /* util.c */ -int wrap_read(int fd, void *buf, int len); -int wrap_write(int fd, void *buf, int len); -void set_nonblocking(int fd); -void set_blocking(int fd); -void raw_termios(struct termios *termios); -void default_termios(struct termios *termios); +extern int wrap_read(int fd, void *buf, int len); +extern int wrap_write(int fd, void *buf, int len); +extern void set_nonblocking(int fd); +extern void set_blocking(int fd); +extern void raw_termios(struct termios *termios); +extern void default_termios(struct termios *termios); /* log.c */ -Log *file_log_new(char *fn); +extern Log *file_log_new(char *fn); /* ipc.c */ -Socket *socket_listen(char *path); -Socket *socket_accept(Socket *l); -Socket *socket_connect(char *path); -Socket *socket_postselect(Socket *s, fd_set *rfds, fd_set *wfds); -void socket_preselect(Socket *s, fd_set *rfds, fd_set *wfds); +extern IPC_Msg *ipc_check_for_message_in_slide(Slide *s); /* slide.c */ -void slide_free(Slide *s); -void slide_consume(Slide *s, int n); -void slide_added(Slide *s, int n); -Slide *slide_new(int n); -void slide_expand(Slide *s, int n); +extern void slide_free(Slide *s); +extern void slide_consume(Slide *s, int n); +extern void slide_added(Slide *s, int n); +extern Slide *slide_new(int n); +extern void slide_expand(Slide *s, int n); +/* symsocket.c */ +extern void socket_free(Socket *s); +extern Socket *socket_listen(char *path); +extern Socket *socket_accept(Socket *l); +extern Socket *socket_connect(char *path); +extern Socket *socket_post_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern void socket_consume_msg(Socket *s); +extern void socket_pre_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern IPC_Msg *ipc_check_for_message_in_slide(Slide *s); diff --git a/src/sympathy.h.head.in b/src/sympathy.h.head.in index a703ce2..d2edcdf 100644 --- a/src/sympathy.h.head.in +++ b/src/sympathy.h.head.in @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/02/13 18:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/13 16:57:29 james * *** empty log message *** * @@ -33,6 +36,7 @@ extern "C" { #endif #include +#include /*the integer constants here are set by configure*/ @@ -52,4 +56,34 @@ extern "C" { /*get struct tm defined*/ #include <@G2_TM_H@> +#if @G2_TM_IN_SYS_TIME@ +#include +#if @G2_TIME_WITH_SYS_TIME@ +#include +#endif +#else +#if @G2_TIME_WITH_SYS_TIME@ +#include +#endif +#include +#endif + + +#if @G2_HAVE_MALLOC_H@ +#include +#endif + +#if @G2_HAVE_UNISTD_H@ +#include +#endif + +#if @G2_HAVE_STDINT_H@ +#include +#elif @HAVE_SYS_INT_TYPES_H@ +#include +#endif + +#include +#include + diff --git a/src/symsocket.c b/src/symsocket.c new file mode 100644 index 0000000..fde1b2d --- /dev/null +++ b/src/symsocket.c @@ -0,0 +1,249 @@ +/* + * symsocket.c: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +static char rcsid[] = "$Id$"; + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + +#include "project.h" +#include +#include + +#define BUF_SIZE 16384 +#define MAX_TXN 4096 + + +void socket_free(Socket *s) +{ +if (!s) return; +if (s->read_buf) slide_free(s->read_buf); +if (s->write_buf) slide_free(s->write_buf); +close(s->fd); +} + + +Socket * +socket_listen (char *path) +{ + int fd; + struct sockaddr_un *sun; + Socket *ret; + int n; + + + unlink (path); + + fd = socket (PF_UNIX, SOCK_STREAM, 0); + + if (fd < 0) + return NULL; + + n = strlen (path) + sizeof (struct sockaddr_un); + sun = (struct sockaddr_un *) malloc (n); + memset (sun, 0, n); + + sun->sun_family = AF_UNIX; + strcpy (sun->sun_path, path); + + if (bind (fd, (struct sockaddr *) sun, SUN_LEN (sun)) < 0) + { + free (sun); + close (fd); + return NULL; + } + + free (sun); + + if (listen (fd, 5) < 0) + { + close (fd); + return NULL; + } + + set_nonblocking (fd); + + ret = (Socket *) malloc (sizeof (Socket)); + memset (ret, 0, sizeof (Socket)); + ret->read_buf = NULL; + ret->write_buf = NULL; + + ret->fd = fd; + + + return ret; +} + +Socket * +socket_accept (Socket * l) +{ + Socket *ret; + int len; + int fd; + struct sockaddr_un sun; + + len = sizeof (struct sockaddr_un); + + fd = accept (l->fd, (struct sockaddr *) &sun, &len); + + if (fd < 0) + return NULL; + + + ret = (Socket *) malloc (sizeof (Socket)); + memset (ret, 0, sizeof (Socket)); + + set_nonblocking (fd); + + ret->fd = fd; + ret->read_buf = slide_new (BUF_SIZE); + ret->write_buf = slide_new (BUF_SIZE); + ret->msg = 0; + + return ret; +} + + +/*Blocking for now*/ +Socket * +socket_connect (char *path) +{ + int n; + int fd; + struct sockaddr_un *sun; + Socket *ret; + + unlink (path); + + fd = socket (PF_UNIX, SOCK_STREAM, 0); + + if (fd < 0) + return NULL; + + n = strlen (path) + sizeof (struct sockaddr_un); + sun = (struct sockaddr_un *) malloc (n); + memset (sun, 0, n); + + sun->sun_family = AF_UNIX; + strcpy (sun->sun_path, path); + + if (connect (fd, (struct sockaddr *) sun, SUN_LEN (sun))) + { + free (sun); + close (fd); + return NULL; + } + + free (sun); + + set_nonblocking (fd); + + ret = (Socket *) malloc (sizeof (Socket)); + memset (ret, 0, sizeof (Socket)); + + ret->fd = fd; + ret->read_buf = slide_new (BUF_SIZE); + ret->write_buf = slide_new (BUF_SIZE); + ret->msg = 0; + + return ret; +} + +Socket * +socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds) +{ + char buf[1024]; + int n; + + if (SOCKET_IS_LISTENER (s)) + { + if (!FD_ISSET (s->fd, rfds)) + return NULL; + + return socket_accept (s); + } + + + if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds)) + { + n = + (SLIDE_BYTES (s->write_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf); + n = write (s->fd, SLIDE_RPTR (s->write_buf), n); + if (n > 0) + slide_consume (s->write_buf, n); + } + + if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds)) + { + n = + (SLIDE_SPACE (s->read_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf); + n = read (s->fd, SLIDE_RPTR (s->read_buf), n); + + if (n > 0) + slide_added (s->read_buf, n); + } + + if (SLIDE_BYTES (s->read_buf) >= sizeof (IPC_Msg)) + { + s->msg = ipc_check_for_message_in_slide(s->read_buf); + } else { + s->msg=NULL; + } + + + return NULL; + +} + +void socket_consume_msg(Socket *s) +{ +int n; + +if (!s->msg) return; + +n=s->msg->size; + +slide_consume(s->read_buf,n); + + if (SLIDE_BYTES (s->read_buf) >= sizeof (IPC_Msg)) + { + s->msg = ipc_check_for_message_in_slide(s->read_buf); + } else { + s->msg=NULL; + } + +} + +void +socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds) +{ + char buf[1024]; + int n; + + /*Server socket */ + if (SOCKET_IS_LISTENER (s)) + { + FD_SET (s->fd, rfds); + return; + } + + if (!SLIDE_EMPTY (s->write_buf)) + FD_SET (s->fd, wfds); + + if (!SLIDE_FULL (s->read_buf)) + FD_SET (s->fd, rfds); + +} + + diff --git a/src/symsocket.h b/src/symsocket.h new file mode 100644 index 0000000..3996816 --- /dev/null +++ b/src/symsocket.h @@ -0,0 +1,36 @@ +/* + * symsocket.h: + * + * Copyright (c) 2008 James McKenzie , + * All rights reserved. + * + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2008/02/13 18:05:06 james + * *** empty log message *** + * + */ + +#ifndef __SYMSOCKET_H__ +#define __SYMSOCKET_H__ + +typedef struct +{ + int fd; + + Slide *read_buf; + Slide *write_buf; + + IPC_Msg *msg; + +} Socket; + +#define SOCKET_IS_LISTENER(s) (!((s)->read_buf)) + +#endif /* __SYMSOCKET_H__ */ diff --git a/src/terminal.c b/src/terminal.c index 7bbc761..03ac5d4 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/02/13 18:05:06 james + * *** empty log message *** + * * Revision 1.4 2008/02/13 16:57:29 james * *** empty log message *** * @@ -82,10 +85,11 @@ terminal_close (TTY * _t) set_nonblocking (t->wfd); - t->xmit (t, "\033[r", 3); - t->xmit (t, "\033[0m", 4); + t->xmit (_t, "\033[r", 3); + t->xmit (_t, "\033[0m", 4); i = sprintf (buf, "\033[%d;%dH", CRT_ROWS + 1, 1); - t->xmit (t, buf, i); + t->xmit (_t, buf, i); + t->xmit (_t, "\033[J", 3); set_blocking (t->rfd); set_blocking (t->wfd); @@ -149,7 +153,7 @@ terminal_dispatch (void) terminal_winches = 0; for (t = terminal_list; t; t = t->next) - terminal_getsize (t); + terminal_getsize ((TTY *)t); } diff --git a/test/test.c b/test/test.c index d92ca26..f9b2016 100644 --- a/test/test.c +++ b/test/test.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/13 18:05:06 james + * *** empty log message *** + * * Revision 1.2 2008/02/04 11:30:57 james * *** empty log message *** * @@ -22,6 +25,9 @@ static char rcsid[] = "$Id$"; int main(int argc,char *argv[]) { + +ring_test(); +return 0; testy(); return 0; diff --git a/version-files b/version-files index 8d378d5..c014e19 100644 --- a/version-files +++ b/version-files @@ -1,4 +1,4 @@ -src/sympathy.h.in +src/sympathy.h.head.in src/libsympathy.c src/version.c src/project.h -- 2.30.2