config.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 21:30:32 +0300
changeset 41 540737bf6bac
parent 26 6d615203d963
permissions -rw-r--r--
sending requests, and partial support for receiving -- incomplete, not tested
#ifndef CONFIG_H
#define CONFIG_H

#include <sys/socket.h>
#include <sys/un.h>

#define ADDR_TEXT_LEN 128    
#define ADDR_TEXT_LEN_STR "128"
#define PORT_TEXT_LEN 32
#define PORT_TEXT_LEN_STR "32"
#define PATH_TEXT_LEN 108   /* from sys/un.h */
#define PATH_TEXT_LEN_STR "108" /* from sys/un.h */

struct config_endpoint {
    // one of AF_LOCAL, AF_INET, AF_INET6
    int family;

    // buffers to store the extracted textual addres/port into
    // these /should/ be long enough
    union {
        // PF_INET - may be a numeric IPv4 address, numeric IPv6 address, or hostname
        struct {
            const char *addr;
            const char *port;
        } inet;
        
        // PF_LOCAL
        struct {
            const char *path;
        } local;

    } af;

    struct {
        char addr[ADDR_TEXT_LEN];
        char port[PORT_TEXT_LEN];
        char default_port[PORT_TEXT_LEN];
        char path[PATH_TEXT_LEN];
    } _data;
};

void endpoint_init (struct config_endpoint *endpoint, unsigned short default_port);
int endpoint_parse (struct config_endpoint *endpoint, const char *addr_spec);

/*
 * Parse a host:port string.
 *
 * Valid formats:
 *  host
 *  host:port
 *  [host]
 *  [host]:port
 *
 * The contents of the given hostport string *will* be modified.
 *
 * The value of *port will be set to NULL if no port was given.
 *
 * Returns 0 and sets *host if succesfull, nonzero otherwise.
 *
 */
int parse_hostport (char *hostport, char **host, char **port);

#endif /* CONFIG_H */