X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fcollectd%2Fserver.h;h=e50df17df77b75137c3e7a842b4fd22ccee2044a;hb=6b0e22a545bb3e4be1684a9fd6d2b48259ba9a7f;hp=d103d7f3a0f7e8fce0d75e569e5819ebba681593;hpb=c3eb1f9dd670b0d112820ed2894e6d5ecb09c286;p=collectd.git diff --git a/src/libcollectdclient/collectd/server.h b/src/libcollectdclient/collectd/server.h index d103d7f3..e50df17d 100644 --- a/src/libcollectdclient/collectd/server.h +++ b/src/libcollectdclient/collectd/server.h @@ -28,24 +28,29 @@ #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 -LCC_BEGIN_DECLS +#ifndef LCC_NETWORK_BUFFER_SIZE +#define LCC_NETWORK_BUFFER_SIZE 1452 +#endif -/* lcc_value_list_writer_t is a write callback to which value lists are - * dispatched. */ -typedef int (*lcc_value_list_writer_t)(lcc_value_list_t const *); +LCC_BEGIN_DECLS -/* lcc_password_lookup_t is a callback for looking up the password for a given - * user. Must return NULL if the user is not known. */ -typedef char const *(*lcc_password_lookup_t)(char const *); +/* 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. */ + /* conn is a UDP socket for the server to listen on. If set to <0 node and + * service will be used to open a new UDP socket. If >=0, it is the caller's + * job to clean up the socket. */ int conn; /* node is the local address to listen on if conn is <0. Defaults to "::" (any @@ -56,21 +61,20 @@ typedef struct { * LCC_DEFAULT_PORT. */ char *service; - /* writer is the callback used to send incoming lcc_value_list_t to. */ - lcc_value_list_writer_t writer; - - /* buffer_size determines the maximum packet size to accept. */ - uint16_t buffer_size; + /* parser is the callback used to parse incoming network packets. Defaults to + * lcc_network_parse() if set to NULL. */ + lcc_network_parser_t parser; - /* password_lookup is used to look up the password for a given username. */ - lcc_password_lookup_t password_lookup; + /* parse_options contains options for parser and is passed on verbatimely. */ + lcc_network_parse_options_t parse_options; - /* security_level is the minimal required security level. */ - lcc_security_level_t security_level; + /* buffer_size determines the maximum packet size to accept. Defaults to + * LCC_NETWORK_BUFFER_SIZE if set to zero. */ + uint16_t buffer_size; /* interface is the name of the interface to use when subscribing to a * multicast group. Has no effect when using unicast. */ - char *interface; + char *iface; } lcc_listener_t; /* lcc_listen_and_write listens on the provided UDP socket (or opens one using @@ -79,24 +83,6 @@ typedef struct { * failure and does not return otherwise. */ int lcc_listen_and_write(lcc_listener_t srv); -typedef struct { - /* writer is the callback used to send incoming lcc_value_list_t to. */ - lcc_value_list_writer_t writer; - - /* password_lookup is used to look up the password for a given username. */ - lcc_password_lookup_t password_lookup; - - /* security_level is the minimal required security level. */ - lcc_security_level_t security_level; -} lcc_network_parse_options_t; - -/* lcc_network_parse parses data received from the network and calls "w" with - * the parsed lcc_value_list_ts. */ -/* TODO(octo): the Go code returns a []api.ValueList. Should we return a - * value_list_t** here? */ -int lcc_network_parse(void *buffer, size_t buffer_size, - lcc_network_parse_options_t opts); - LCC_END_DECLS #endif /* LIBCOLLECTD_SERVER_H */