#include "collectd/lcc_features.h"
+#include "collectd/network.h" /* for lcc_security_level_t */
+#include "collectd/network_parse.h" /* for lcc_network_parse_options_t */
#include "collectd/types.h"
-#include "collectd/network.h" /* for lcc_security_level_t */
#include <stdint.h>
LCC_BEGIN_DECLS
+/* lcc_network_parser_t is a callback that parses received network packets. It
+ * is expected to call lcc_network_parse_options_t.writer with each
+ * lcc_value_list_t it parses that has the required security level. */
+typedef int (*lcc_network_parser_t)(void *payload, size_t payload_size,
+ lcc_network_parse_options_t opts);
+
/* lcc_listener_t holds parameters for running a collectd server. */
typedef struct {
/* conn is a UDP socket for the server to listen on. */
* LCC_DEFAULT_PORT. */
char *service;
+ /* parser is the callback used to parse incoming network packets. Defaults to
+ * lcc_network_parse() if set to NULL. */
+ lcc_network_parser_t parser;
+
/* writer is the callback used to send incoming lcc_value_list_t to. */
lcc_value_list_writer_t writer;
/* TODO(octo): this should be a define. */
srv.buffer_size = 1452;
+ if (srv.parser == NULL)
+ srv.parser = lcc_network_parse;
+
int ret = 0;
while (42) {
char buffer[srv.buffer_size];
break;
}
- /* TODO(octo): implement parse(). */
- (void)lcc_network_parse(buffer, (size_t)len,
- (lcc_network_parse_options_t){
- .writer = srv.writer,
- .password_lookup = srv.password_lookup,
- .security_level = srv.security_level,
- });
+ (void)srv.parser(buffer, (size_t)len,
+ (lcc_network_parse_options_t){
+ .writer = srv.writer,
+ .password_lookup = srv.password_lookup,
+ .security_level = srv.security_level,
+ });
}
if (close_socket) {