terom@26: #ifndef CONFIG_H terom@26: #define CONFIG_H terom@26: terom@26: #include terom@26: #include terom@26: terom@26: #define ADDR_TEXT_LEN 128 terom@26: #define ADDR_TEXT_LEN_STR "128" terom@26: #define PORT_TEXT_LEN 32 terom@26: #define PORT_TEXT_LEN_STR "32" terom@26: #define PATH_TEXT_LEN 108 /* from sys/un.h */ terom@26: #define PATH_TEXT_LEN_STR "108" /* from sys/un.h */ terom@26: terom@26: struct config_endpoint { terom@26: // one of AF_LOCAL, AF_INET, AF_INET6 terom@26: int family; terom@26: terom@26: // buffers to store the extracted textual addres/port into terom@26: // these /should/ be long enough terom@26: union { terom@26: // PF_INET - may be a numeric IPv4 address, numeric IPv6 address, or hostname terom@26: struct { terom@26: const char *addr; terom@26: const char *port; terom@26: } inet; terom@26: terom@26: // PF_LOCAL terom@26: struct { terom@26: const char *path; terom@26: } local; terom@26: terom@26: } af; terom@26: terom@26: struct { terom@26: char addr[ADDR_TEXT_LEN]; terom@26: char port[PORT_TEXT_LEN]; terom@26: char default_port[PORT_TEXT_LEN]; terom@26: char path[PATH_TEXT_LEN]; terom@26: } _data; terom@26: }; terom@26: terom@26: void endpoint_init (struct config_endpoint *endpoint, unsigned short default_port); terom@26: int endpoint_parse (struct config_endpoint *endpoint, const char *addr_spec); terom@26: terom@26: /* terom@26: * Parse a host:port string. terom@26: * terom@26: * Valid formats: terom@26: * host terom@26: * host:port terom@26: * [host] terom@26: * [host]:port terom@26: * terom@26: * The contents of the given hostport string *will* be modified. terom@26: * terom@26: * The value of *port will be set to NULL if no port was given. terom@26: * terom@26: * Returns 0 and sets *host if succesfull, nonzero otherwise. terom@26: * terom@26: */ terom@26: int parse_hostport (char *hostport, char **host, char **port); terom@26: terom@26: #endif /* CONFIG_H */ terom@26: