--- sio_hello.c 2002/11/08 10:34:24 1.4
+++ sio_hello.c 2002/11/08 11:10:41 1.5
@@ -30,7 +30,8 @@
state_t state;
char passwd[NPASS]; /* input buffer */
int npass; /* characters in input buffer */
- al_t *pre; /* saved output during protocol */
+ al_t *pre_in; /* saved during protocol */
+ al_t *pre_out; /* saved during protocol */
int isoutput; /* remember originator of protocol */
al_label_t data_label; /* al labels used by SIO */
al_label_t eof_label;
@@ -56,7 +57,9 @@
sio_label(sio, SIO_LN_DATA, &my->data_label);
sio_label(sio, SIO_LN_EOF, &my->eof_label);
- my->eof = '\0';
+ my->eof = '\0';
+ my->pre_in = NULL;
+ my->pre_out = NULL;
*u = my;
@@ -82,8 +85,6 @@
{
private_t *my = (private_t *)u;
- al_destroy(my->pre);
-
free(my);
return SIO_OK;
@@ -102,6 +103,10 @@
private_t *my = (private_t *)u;
hello_setup(sio,my);
+
+ if (al_create(&my->pre_in) != AL_OK)
+ return SIO_ERR_INT;
+
my->al_in = al;
return SIO_OK;
@@ -110,6 +115,11 @@
static
sio_rc_t hello_closer(sio_t *sio, al_t *al, void *u)
{
+ private_t *my = (private_t *)u;
+
+ al_destroy(my->pre_in);
+ my->pre_in = NULL;
+
return SIO_OK;
}
@@ -119,7 +129,10 @@
private_t *my = (private_t *)u;
hello_setup(sio,my);
- al_create(&my->pre);
+
+ if (al_create(&my->pre_out) != AL_OK)
+ return SIO_ERR_INT;
+
my->al_out = al;
return SIO_OK;
@@ -130,8 +143,8 @@
{
private_t *my = (private_t *)u;
- al_destroy(my->pre);
- my->pre = NULL;
+ al_destroy(my->pre_out);
+ my->pre_out = NULL;
return SIO_OK;
}
@@ -179,30 +192,33 @@
}
/*
- * defer initial output until protocol is done
+ * defer initial data until protocol is done
*/
static
-void hello_saveoutput(private_t *my)
+void hello_save(private_t *my)
{
- al_splice(my->pre, al_bytes(my->pre), 0, my->al_out, NULL);
+ al_splice(my->pre_in, al_bytes(my->pre_in), 0, my->al_in, NULL);
+ al_splice(my->pre_out, al_bytes(my->pre_out), 0, my->al_out, NULL);
}
/*
* restore saved output after handshake completed successfully
*/
static
-void hello_restoreoutput(private_t *my)
+void hello_restore(private_t *my)
{
- al_splice(my->al_out, 0, 0, my->pre, NULL);
+ al_splice(my->al_in, 0, 0, my->pre_in, NULL);
+ al_splice(my->al_out, 0, 0, my->pre_out, NULL);
}
/*
- * kill saved output
+ * kill saved data
*/
static
void hello_dropsaved(private_t *my)
{
- al_splice(my->pre, 0, al_bytes(my->pre), NULL, NULL);
+ al_splice(my->pre_in, 0, al_bytes(my->pre_in), NULL, NULL);
+ al_splice(my->pre_out, 0, al_bytes(my->pre_out), NULL, NULL);
}
/*
@@ -211,7 +227,7 @@
static
void hello_sendprompt(private_t *my)
{
- al_prepend_bytes(my->al_out, PROMPT, NPROMPT, my->data_label);
+ al_prepend_bytes(my->al_out, PROMPT, NPROMPT, my->data_label);
}
/************************************************************************/
@@ -246,17 +262,20 @@
* we can complete correctly after handshake
* is done
*
- * if caller starts with write, preserve data
+ * save global assembly lines
+ *
+ * if caller starts with write, stay
*
* if caller starts with read, switch to writer
*
*/
+
+ hello_save(my);
+ my->isoutput = isoutput;
+
if (isoutput) {
- my->isoutput = 1;
- hello_saveoutput(my);
GOTO(PROMPTING, SIO_LOOP);
} else {
- my->isoutput = 0;
GOTO(PROMPTING, SIO_XSTREAM);
}
break;
@@ -322,18 +341,20 @@
good = my->npass == NPASS &&
memcmp(my->passwd, PASSWD, NPASS) == 0;
if (!good) {
+ hello_dropsaved(my);
if (my->isoutput) {
- hello_dropsaved(my);
GOTO(BAD, SIO_XSTREAM);
} else {
hello_writeeof(my);
GOTO(BAD, SIO_DOWNSTREAM);
}
- } else if (my->isoutput) {
- hello_restoreoutput(my);
- GOTO(GOOD, SIO_XSTREAM);
- } else
- GOTO(GOOD, SIO_OK);
+ } else {
+ hello_restore(my);
+ if (isoutput != my->isoutput) {
+ GOTO(GOOD, SIO_XSTREAM);
+ } else
+ GOTO(GOOD, SIO_LOOP);
+ }
}
break;
|