First version
authorMichael Brown <mcb30@etherboot.org>
Fri, 29 Apr 2005 13:17:25 +0000 (13:17 +0000)
committerMichael Brown <mcb30@etherboot.org>
Fri, 29 Apr 2005 13:17:25 +0000 (13:17 +0000)
src/core/proto.c [new file with mode: 0644]
src/include/proto.h [new file with mode: 0644]

diff --git a/src/core/proto.c b/src/core/proto.c
new file mode 100644 (file)
index 0000000..6695697
--- /dev/null
@@ -0,0 +1,25 @@
+#include "stddef.h"
+#include "string.h"
+#include "proto.h"
+
+static struct protocol protocols[0] __protocol_start;
+static struct protocol default_protocols[0] __default_protocol_start;
+static struct protocol protocols_end[0] __protocol_end;
+
+/*
+ * Identify protocol given a name.  name may be NULL, in which case
+ * the first default protocol (if any) will be used.
+ *
+ */
+struct protocol * identify_protocol ( const char *name ) {
+       struct protocol *proto = default_protocols;
+
+       if ( name ) {
+               for ( proto = protocols ; proto < protocols_end ; proto++ ) {
+                       if ( strcmp ( name, proto->name ) == 0 )
+                               break;
+               }
+       }
+
+       return proto < protocols_end ? proto : NULL;
+}
diff --git a/src/include/proto.h b/src/include/proto.h
new file mode 100644 (file)
index 0000000..5ca56ce
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef PROTO_H
+#define PROTO_H
+
+#include "tables.h"
+
+struct protocol {
+       char *name;
+       int ( * load ) ( const char *name,
+                        int ( * process ) ( unsigned char *data,
+                                            unsigned int blocknum,
+                                            unsigned int len,
+                                            int eof ) );
+};
+
+/*
+ * Protocols that should be used if no explicit protocol is specified
+ * (i.e. tftp) should use __default_protocol; all other protocols
+ * should use __protocol.
+ *
+ */
+#define __protocol_start               __table_start(protocol)
+#define __protocol                     __table(protocol,01)
+#define __default_protocol_start       __table(protocol,02)
+#define __default_protocol             __table(protocol,03)
+#define __protocol_end                 __table_end(protocol)
+
+/*
+ * Functions in proto.c
+ *
+ */
+extern struct protocol * identify_protocol ( const char *name );
+
+#endif /* PROTO_H */