# Copyright (C) 1994, Index Data I/S
# All rights reserved.
# Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.1 1995-03-10 18:22:44 quinn Exp $
+# $Id: Makefile,v 1.2 1995-03-14 10:27:57 quinn Exp $
SHELL=/bin/sh
-INCLUDE=-I../include -I. -I../asn -I../odr -I../../egate/include -I../../xtimosi/src
+INCLUDE=-I../include -I. -I../asn -I../odr -I../yazlib -I../../egate/include -I../../xtimosi/src
+LIBDIR=../../lib
+LIBINCLUDE=-L$(LIBDIR)
#CFLAGS=-Wall -pedantic -g
-#CFLAGS=-g
DEFS=$(INCLUDE)
-LIB= server.a
+LIB=$(LIBDIR)/libserver.a
+LIBS=-lserver -lasn -lodr -lcomstack options.o
PO = eventl.o
CPP=cc -E
-#CC=checkergcc
+PROG=statserv
+PROGO=statserv.o session.o
-all: $(LIB)
+all: $(LIBDIR) $(LIB) $(PROG)
+
+$(PROG): $(LIB) $(PROGO) options.o
+ $(CC) $(CFLAGS) $(LIBINCLUDE) -o $(PROG) $(PROGO) $(LIBS)
alll:
ar qc $(LIB) $(PO)
ranlib $(LIB)
+$(LIBDIR):
+ mkdir $(LIBDIR)
+
.c.o:
$(CC) -c $(DEFS) $(CFLAGS) $<
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: eventl.c,v $
- * Revision 1.1 1995-03-10 18:22:44 quinn
+ * Revision 1.2 1995-03-14 10:27:59 quinn
+ * More work on demo server.
+ *
+ * Revision 1.1 1995/03/10 18:22:44 quinn
* The rudiments of an asynchronous server.
*
*/
new->fd = fd;
new->flags = flags;
new->fun = cb;
+ new->next = iochans;
+ iochans = new;
return new;
}
-void iochan_destroy(IOCHAN i)
-{
- i->destroyed = 1;
-}
-
int event_loop()
{
do
IOCHAN p, nextp;
fd_set in, out, except;
int res, max;
+ static struct timeval nullto = {0, 0};
+ struct timeval *timeout;
FD_ZERO(&in);
FD_ZERO(&out);
FD_ZERO(&except);
+ timeout = 0; /* hang on select */
for (p = iochans; p; p = p->next)
{
+ if (p->force_event)
+ timeout = &nullto;
if (p->flags & EVENT_INPUT)
FD_SET(p->fd, &in);
if (p->flags & EVENT_OUTPUT)
if (p->fd > max)
max = p->fd;
}
- if ((res = select(max + 1, &in, &out, &except, 0)) < 0)
+ if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
{
if (errno == EINTR)
continue;
continue;
for (p = iochans; p; p = nextp)
{
+ int force_event = p->force_event;
+
+ p->force_event = 0;
nextp = p->next;
- if (FD_ISSET(p->fd, &in))
+ if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
(*p->fun)(p, EVENT_INPUT);
- if (!p->destroyed && FD_ISSET(p->fd, &in))
+ if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
+ force_event == EVENT_OUTPUT))
(*p->fun)(p, EVENT_OUTPUT);
- if (!p->destroyed && FD_ISSET(p->fd, &except))
+ if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
+ force_event == EVENT_EXCEPT))
(*p->fun)(p, EVENT_EXCEPT);
if (p->destroyed)
{
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: eventl.h,v $
- * Revision 1.1 1995-03-10 18:22:45 quinn
+ * Revision 1.2 1995-03-14 10:28:00 quinn
+ * More work on demo server.
+ *
+ * Revision 1.1 1995/03/10 18:22:45 quinn
* The rudiments of an asynchronous server.
*
*/
#define EVENT_OUTPUT 0x02
#define EVENT_EXCEPT 0x04
#define EVENT_TIMEOUT 0x08
+int force_event;
IOC_CALLBACK fun;
void *data;
int destroyed;
#define iochan_setflags(i, d) ((i)->flags = d)
#define iochan_getfun(i) ((i)->fun)
#define iochan_setfun(i, d) ((i)->fun = d)
+#define iochan_setevent(i, e) ((i)->force_event = (e))
+
+IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags);
+int event_loop();
#endif
--- /dev/null
+/*
+ * Copyright (C) 1994, Index Data I/S
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: session.h,v $
+ * Revision 1.1 1995-03-14 10:28:02 quinn
+ * More work on demo server.
+ *
+ *
+ */
+
+#ifndef SESSION_H
+#define SESSION_H
+
+#include <comstack.h>
+#include <odr.h>
+
+typedef struct association
+{
+ /* comms-related handles */
+ IOCHAN client_chan;
+ COMSTACK client_link;
+ ODR decode;
+ ODR encode;
+ char *encode_buffer;
+ int encoded_len;
+ char *input_buffer;
+ int input_buffer_len;
+ int input_apdu_len;
+ int state;
+#define ASSOC_UNINIT 0
+#define ASSOC_IDLE 1
+
+ /* session parameters */
+ int preferredMessageSize;
+ int maximumRecordSize;
+} association;
+
+association *create_association(IOCHAN channel, COMSTACK link);
+void ir_session(IOCHAN h, int event);
+
+#endif
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: statserv.c,v $
- * Revision 1.1 1995-03-10 18:22:45 quinn
+ * Revision 1.2 1995-03-14 10:28:03 quinn
+ * More work on demo server.
+ *
+ * Revision 1.1 1995/03/10 18:22:45 quinn
* The rudiments of an asynchronous server.
*
*/
#include <stdio.h>
+#include <options.h>
+#include <eventl.h>
+#include <session.h>
#include <eventl.h>
+#include <comstack.h>
+#include <tcpip.h>
+#include <xmosi.h>
static char *me = "";
void listener(IOCHAN h, int event)
{
COMSTACK line = (COMSTACK) iochan_getdata(h);
+ association *newas;
if (event == EVENT_INPUT)
{
fprintf(stderr, "cs_listen failed.\n");
exit(1);
}
- iochan_setflags(h, EVENT_OUTPUT) /* set us up for accepting */
+ iochan_setflags(h, EVENT_OUTPUT); /* set us up for accepting */
}
else if (event == EVENT_OUTPUT)
{
fprintf(stderr, "Accept failed.\n");
exit(1);
}
- if (!(new_chan = iochan_create(cs_fileno(initializer, init_fun,
- EVENT_INPUT))))
+ if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session,
+ EVENT_INPUT)))
{
fprintf(stderr, "Failed to create iochan\n");
exit(1);
}
+ if (!(newas = create_association(new_chan, new_line)))
+ {
+ fprintf(stderr, "Failed to create new assoc.\n");
+ exit(1);
+ }
+ iochan_setdata(h, newas);
iochan_setflags(h, EVENT_INPUT); /* reset for listening */
}
else
{
COMSTACK l;
CS_TYPE type;
- char mode[100], addr[100]
+ char mode[100], addr[100];
void *ap;
IOCHAN lst;
}
if (!strcmp(mode, "tcp"))
{
- if (!(ap = tcpip_strtoaddr(where)))
+ if (!(ap = tcpip_strtoaddr(addr)))
{
fprintf(stderr, "Address resolution failed for TCP.\n");
exit(1);
}
type = tcpip_type;
}
+#if 0
else if (!strcmp(mode, "osi"))
{
- if (!(ap = mosi_strtoaddr(where)))
+ if (!(ap = mosi_strtoaddr(addr)))
{
fprintf(stderr, "Address resolution failed for TCP.\n");
exit(1);
}
type = mosi_type;
}
+#endif
else
{
fprintf(stderr, "You must specify either 'osi:' or 'tcp:'.\n");
switch (ret)
{
case 0: me = arg; break;
- case 'l': add_listener(arg); l++; break;
+ case 'l': add_listener(arg); listeners++; break;
default:
fprintf(stderr, "Usage: %s [-l <listener-addr>]\n", me);
exit(1);