diff options
Diffstat (limited to 'falgproto')
-rw-r--r-- | falgproto/falgproto-0.1.pc.in | 10 | ||||
-rw-r--r-- | falgproto/falgproto.c | 77 | ||||
-rw-r--r-- | falgproto/falgproto.h | 48 |
3 files changed, 135 insertions, 0 deletions
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 */ |