config.h
author Tero Marttila <terom@fixme.fi>
Fri, 29 Aug 2008 23:31:17 +0300
changeset 48 1c67f512779b
parent 26 6d615203d963
permissions -rw-r--r--
fix doc tpyos, rename some enums, fix printf format len for non-zero terminated strings (hg status), pass args to memcache_cmd_format_header via memcache_req_*, handle zero-length STORE requests, memcache_req is_buf_ours + free, other function name typos (keymemcache_req_key), fix req state behaviour re *_DATA_* for STORE requests and FETCH/END, better memcache_server connpool events/management, modular memcache_test with a working benchmark. This is a long commit message.
#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 */