ソースを参照

First version

tags/v0.9.3
Michael Brown 19年前
コミット
e4131ebb84
2個のファイルの変更58行の追加0行の削除
  1. 25
    0
      src/core/proto.c
  2. 33
    0
      src/include/proto.h

+ 25
- 0
src/core/proto.c ファイルの表示

@@ -0,0 +1,25 @@
1
+#include "stddef.h"
2
+#include "string.h"
3
+#include "proto.h"
4
+
5
+static struct protocol protocols[0] __protocol_start;
6
+static struct protocol default_protocols[0] __default_protocol_start;
7
+static struct protocol protocols_end[0] __protocol_end;
8
+
9
+/*
10
+ * Identify protocol given a name.  name may be NULL, in which case
11
+ * the first default protocol (if any) will be used.
12
+ *
13
+ */
14
+struct protocol * identify_protocol ( const char *name ) {
15
+	struct protocol *proto = default_protocols;
16
+
17
+	if ( name ) {
18
+		for ( proto = protocols ; proto < protocols_end ; proto++ ) {
19
+			if ( strcmp ( name, proto->name ) == 0 )
20
+				break;
21
+		}
22
+	}
23
+
24
+	return proto < protocols_end ? proto : NULL;
25
+}

+ 33
- 0
src/include/proto.h ファイルの表示

@@ -0,0 +1,33 @@
1
+#ifndef PROTO_H
2
+#define PROTO_H
3
+
4
+#include "tables.h"
5
+
6
+struct protocol {
7
+	char *name;
8
+	int ( * load ) ( const char *name,
9
+			 int ( * process ) ( unsigned char *data,
10
+					     unsigned int blocknum,
11
+					     unsigned int len,
12
+					     int eof ) );
13
+};
14
+
15
+/*
16
+ * Protocols that should be used if no explicit protocol is specified
17
+ * (i.e. tftp) should use __default_protocol; all other protocols
18
+ * should use __protocol.
19
+ *
20
+ */
21
+#define __protocol_start		__table_start(protocol)
22
+#define __protocol			__table(protocol,01)
23
+#define __default_protocol_start	__table(protocol,02)
24
+#define __default_protocol		__table(protocol,03)
25
+#define __protocol_end			__table_end(protocol)
26
+
27
+/*
28
+ * Functions in proto.c
29
+ *
30
+ */
31
+extern struct protocol * identify_protocol ( const char *name );
32
+
33
+#endif /* PROTO_H */

読み込み中…
キャンセル
保存