summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am24
-rwxr-xr-xautogen.sh7
-rw-r--r--configure.ac22
-rw-r--r--falgproto/falgproto-0.1.pc.in10
-rw-r--r--falgproto/falgproto.c77
-rw-r--r--falgproto/falgproto.h48
6 files changed, 188 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..754c312
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,24 @@
+# vim: set sw=8 ts=8 sts=8 noet:
+
+NULL =
+
+lib_LTLIBRARIES = falgproto/libfalgproto-0.1.la
+
+EXTRA_DIST = \
+ autogen.sh \
+ $(NULL)
+
+falgproto_libfalgproto_0_1_la_SOURCES = \
+ falgproto/falgproto.h \
+ falgproto/falgproto.c \
+ $(NULL)
+
+falgprotoincludedir = $(includedir)/falgproto-0.1
+falgprotoinclude_HEADERS = \
+ falgproto/falgproto.h \
+ $(NULL)
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = \
+ falgproto/falgproto-0.1.pc \
+ $(NULL)
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..849ffcf
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+( cd "$srcdir" && autoreconf -fiv && rm -rf autom4te.cache )
+"$srcdir/configure" "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..ae3f5d1
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,22 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+# vim: set sw=4 ts=4 sts=4 et:
+
+AC_INIT([fastalg-protocol], [0.1], [BUG-REPORT-ADDRESS])
+AC_CONFIG_SRCDIR([falgproto/falgproto.c])
+AC_CONFIG_HEADERS([config.h])
+
+AM_INIT_AUTOMAKE([foreign subdir-objects])
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CC_STDC
+LT_INIT
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_CHECK_HEADER_STDBOOL
+AC_TYPE_SIZE_T
+
+AC_CONFIG_FILES([Makefile falgproto/falgproto-0.1.pc])
+AC_OUTPUT
diff --git a/falgproto/falgproto-0.1.pc.in b/falgproto/falgproto-0.1.pc.in
new file mode 100644
index 0000000..693c519
--- /dev/null
+++ b/falgproto/falgproto-0.1.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol library for FastALG
+Description: Application layer protocol parser for FastALG
+Version: @VERSION@
+Libs: -lfalgproto-0.1
+Cflags: -I${includedir}/falgproto-0.1
diff --git a/falgproto/falgproto.c b/falgproto/falgproto.c
new file mode 100644
index 0000000..b6f6c38
--- /dev/null
+++ b/falgproto/falgproto.c
@@ -0,0 +1,77 @@
+/* vim: set sw=4 ts=4 sts=4 et: */
+
+#include "falgproto.h"
+
+#include <stddef.h>
+#include <strings.h>
+
+
+struct proto_info {
+ FalgprotoType protocol;
+ FalgprotoTransport transport;
+ char* name;
+ char* description;
+ FalgprotoParamGetter param_getter;
+ FalgprotoPrinter printer;
+};
+
+static struct proto_info info[] = {
+ { FALGPROTO_TYPE_HTTP, FALGPROTO_TRANSPORT_TCP, "http",
+ "HTTP",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_HTTPS, FALGPROTO_TRANSPORT_TCP, "https",
+ "HTTPS",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_DNS, FALGPROTO_TRANSPORT_UDP, "dns",
+ "DNS",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_FTP, FALGPROTO_TRANSPORT_TCP, "ftp",
+ "FTP",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_SSH, FALGPROTO_TRANSPORT_TCP, "ssh",
+ "SSH",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_LDAP, FALGPROTO_TRANSPORT_TCP, "ldap",
+ "LDAP",
+ NULL,
+ NULL },
+ { FALGPROTO_TYPE_MAX, 0, NULL, NULL, NULL, NULL }
+};
+
+unsigned falgproto_get_count (void) {
+ return FALGPROTO_TYPE_MAX;
+}
+
+int falgproto_get_protocol (const char *name) {
+ for (size_t i = 0; info[i].name != NULL; i++) {
+ if (strcasecmp (name, info[i].name) == 0) {
+ return info[i].protocol;
+ }
+ }
+ return -1;
+}
+
+const char* falgproto_get_name (FalgprotoType protocol) {
+ return info[protocol].name;
+}
+
+const char* falgproto_get_description (FalgprotoType protocol) {
+ return info[protocol].description;
+}
+
+FalgprotoTransport falgproto_get_transport (FalgprotoType protocol) {
+ return info[protocol].transport;
+}
+
+FalgprotoParamGetter falgproto_get_param_getter (FalgprotoType protocol) {
+ return info[protocol].param_getter;
+}
+
+FalgprotoPrinter falgproto_get_printer (FalgprotoType protocol) {
+ return info[protocol].printer;
+}
diff --git a/falgproto/falgproto.h b/falgproto/falgproto.h
new file mode 100644
index 0000000..0f66fe8
--- /dev/null
+++ b/falgproto/falgproto.h
@@ -0,0 +1,48 @@
+/* vim: set sw=4 ts=4 sts=4 et: */
+#ifndef FALGPROTO_H
+#define FALGPROTO_H
+
+#include <stdbool.h>
+#include <stdio.h>
+
+typedef enum falgproto_type {
+ FALGPROTO_TYPE_HTTP,
+ FALGPROTO_TYPE_HTTPS,
+ FALGPROTO_TYPE_DNS,
+ FALGPROTO_TYPE_FTP,
+ FALGPROTO_TYPE_SSH,
+ FALGPROTO_TYPE_LDAP,
+ FALGPROTO_TYPE_MAX
+} FalgprotoType;
+
+typedef enum falgproto_transport {
+ FALGPROTO_TRANSPORT_TCP,
+ FALGPROTO_TRANSPORT_UDP
+} FalgprotoTransport;
+
+typedef struct falgproto_param {
+ char* param;
+ size_t len;
+ bool dup;
+ int result;
+} FalgprotoParam;
+
+#define FALGPROTO_PARAM_RESULT_ERROR -1
+#define FALGPROTO_PARAM_RESULT_OK 0
+#define FALGPROTO_PARAM_RESULT_NOT_FOUND 1
+#define FALGPROTO_PARAM_RESULT_INCOMPLETE 2
+
+typedef FalgprotoParam (*FalgprotoParamGetter) (const char *pkt);
+typedef void (*FalgprotoPrinter) (const char *pkt, FILE *fp);
+
+
+unsigned falgproto_get_count (void);
+int falgproto_get_protocol (const char *name);
+const char* falgproto_get_name (FalgprotoType protocol);
+const char* falgproto_get_description (FalgprotoType protocol);
+FalgprotoTransport falgproto_get_transport (FalgprotoType protocol);
+FalgprotoParamGetter falgproto_get_param_getter (FalgprotoType protocol);
+FalgprotoPrinter falgproto_get_printer (FalgprotoType protocol);
+
+
+#endif /* FALGPROTO_H */