[Olsr-cvs] olsrd-current/src plugin_util.h, NONE, 1.1 plugin_util.c, NONE, 1.1

Bernd Petrovitsch (spam-protected)
Sun Jul 15 19:46:49 CEST 2007


Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29125/src

Added Files:
	plugin_util.h plugin_util.c 
Log Message:
* added common utility functions for plugins

--- NEW FILE: plugin_util.c ---
/*
 * The olsr.org Optimized Link-State Routing daemon(olsrd)
 * Copyright (c) 2007, Bernd Petrovitsch <(spam-protected)>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * * Redistributions of source code must retain the above copyright 
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright 
 *   notice, this list of conditions and the following disclaimer in 
 *   the documentation and/or other materials provided with the 
 *   distribution.
 * * Neither the name of olsr.org, olsrd nor the names of its 
 *   contributors may be used to endorse or promote products derived 
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Visit http://www.olsr.org for more information.
 *
 * If you find this software useful feel free to make a donation
 * to the project. For more information see the website or contact
 * the copyright holders.
 *
 * $Id: plugin_util.c,v 1.1 2007/07/15 17:46:46 bernd67 Exp $
 */

#include "plugin_util.h"
#include "olsr.h"
#include "defs.h"

int set_plugin_port(const char *value, void *data)
{
    char *endptr;
    const unsigned int port = strtoul(value, &endptr, 0);
    if (*endptr != '\0' || endptr == value) {
        OLSR_PRINTF(0, "Illegal port number \"%s\"", value);
        return 1;
    }
    if (port > 65535) {
        OLSR_PRINTF(0, "Port number %u out of range", port);
        return 1;
    }
    if (data != NULL) {
        unsigned int *v = data;
        *v = port;
        OLSR_PRINTF(1, "%s port number %u\n", "Got", port);
    } else {
        OLSR_PRINTF(0, "%s port number %u\n", "Ignored", port);
    }
    return 0;
}

int set_plugin_ipaddress(const char *value, void *data)
{
    char buf[INET6_ADDRSTRLEN];
    union olsr_ip_addr ip_addr;
    if (inet_pton(olsr_cnf->ip_version, value, &ip_addr) <= 0) {
        OLSR_PRINTF(0, "Illegal IP address \"%s\"", value);
        return 1;
    }
    inet_ntop(olsr_cnf->ip_version, &ip_addr, buf, sizeof(buf));
    if (data != NULL) {
        union olsr_ip_addr *v = data;
        *v = ip_addr;
        OLSR_PRINTF(1, "%s IP address %s\n", "Got", buf);
    } else {
        OLSR_PRINTF(0, "%s IP address %s\n", "Ignored", buf);
    }
    return 0;
}


int set_boolean(const char *value, void *data)
{
    int *v = data;
    if (strcasecmp (value, "yes") == 0) {
        *v = 1;
    } else if (strcasecmp (value, "no") == 0) {
        *v = 0;
    } else {
        return 1;
    }
    return 0;
}

/*
 * Local Variables:
 * mode: c
 * style: linux
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */

--- NEW FILE: plugin_util.h ---
/*
 * Copyright (c) 2007, Bernd Petrovitsch <(spam-protected)>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * * Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 * * Neither the name of the UniK olsr daemon nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* $Id: plugin_util.h,v 1.1 2007/07/15 17:46:46 bernd67 Exp $ */

/*
 * Example plugin for olsrd.org OLSR daemon
 * Only the bare minimum
 */

#ifndef _OLSRD_PLUGIN_UTIL
#define _OLSRD_PLUGIN_UTIL

/* Common/utility functions for plugins */
int set_plugin_port(const char *value, void *data);
int set_plugin_ipaddress(const char *value, void *data);
int set_boolean(const char *value, void *data);


#endif

/*
 * Local Variables:
 * mode: c
 * style: linux
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */





More information about the Olsr-cvs mailing list