Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration


File:  [GForge:cvsroot/nutss] / libnutss / examples / nutssd.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 11:42:45 2007 UTC (10 years, 5 months ago) by saikat
Branches: saikat
CVS tags: version_0_1_0, initial
Initial upload


/**
 * $Id: nutssd.c,v 1.1.1.1 2007/04/24 11:42:45 saikat Exp $
 * Copyright (C) 2007  Saikat Guha <saikat@cs.cornell.edu>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <semaphore.h>
#include <string.h>
#include <errno.h>

#define _GNU_SOURCE
#include <getopt.h>

#include "nutss.h"

sem_t sem;

void usage(char *argv0);

void
usage(char *argv0)
{
    printf("Usage:\n"
        "\t%s [OPTIONS] [SERVICES] user@domain\n"
        "\n"
        "Services:\n"
        "  --stuntd,-s\t\tEnable STUNT server\n"
        "  --turnd,-t\t\tEnable TURN server\n"
        "  --swaplinksd,-w\tEnable Swaplinks server\n"
        "\n"
        "Options:\n"
        "  --registrar,-r server:port\tUse sip registrar at server\n"
        "  --password,-p pass\t\tUse password for registering with proxy\n",
        "nutssd");
    exit(1);
}

int
main(int argc, char **argv)
{
    int c;
    int idx = 0;
    char *tmp;
    static int one = 1;
    static struct option opts[] = {
        {"stuntd", 0, 0, 's'},
        {"turnd", 0, 0, 't'},
        {"swaplinksd", 0, 0, 'w'},
        {"registrar", 1, 0, 'r'},
        {"password", 1, 0, 'p'},
        {"help", 1, 0, 'h'},
        {0, 0, 0, 0}
    };

    nutss_config_set(NUTSS_CONFIG_OPT_BIND, &one, sizeof(one));
    while (1) {
        c = getopt_long(argc, argv, "hp:r:stw", opts, &idx);

        if (c == -1)
            break;

        switch (c) {
            case 's':
                nutss_config_set(NUTSS_CONFIG_OPT_STUNTD, &one,
                    sizeof(one));
                break;
            case 't':
                nutss_config_set(NUTSS_CONFIG_OPT_TURND, &one, sizeof(one));
                break;
            case 'w':
                nutss_config_set(NUTSS_CONFIG_OPT_SWAPLINKSD, &one,
                    sizeof(one));
                break;
            case 'r':
                nutss_config_set(NUTSS_CONFIG_SIGPROXY, optarg,
                    strlen(optarg) + 1);
                break;
            case 'p':
                nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, optarg,
                    strlen(optarg) + 1);
                break;
            case 'h':
            default:
                usage(argv[0]);
        }
    }

    if (optind >= argc)
        usage(argv[0]);

    tmp = strchr(argv[optind], '@');
    if (!tmp)
        usage(argv[0]);
    tmp[0] = '\0';
    tmp++;
    nutss_config_set(NUTSS_CONFIG_USERNAME, argv[optind],
        strlen(argv[optind]) + 1);
    nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, argv[optind],
        strlen(argv[optind]) + 1);
    nutss_config_set(NUTSS_CONFIG_DOMAINNAME, tmp, strlen(tmp) + 1);
    optind++;

    sem_init(&sem, 0, 0);
    nutss_init();
    while (sem_wait(&sem) == -1 && errno == EINTR);

    return 1;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment