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

CVS | Administration

Annotation of libnutss/examples/nutssd.c, revision 1.1

1.1     ! saikat      1: /**
        !             2:  * $Id: nutssd.c,v 1.3 2007/04/12 05:08:25 saikat Exp $
        !             3:  * Copyright (C) 2007  Saikat Guha <saikat@cs.cornell.edu>
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or
        !             6:  * modify it under the terms of the GNU General Public License
        !             7:  * as published by the Free Software Foundation; either version 2
        !             8:  * of the License, or (at your option) any later version.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful,
        !            11:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            13:  * GNU General Public License for more details.
        !            14:  *
        !            15:  * You should have received a copy of the GNU General Public License
        !            16:  * along with this program; if not, write to the Free Software
        !            17:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
        !            18:  **/
        !            19:
        !            20: #include <stdio.h>
        !            21: #include <stdlib.h>
        !            22: #include <string.h>
        !            23: //#include <unistd.h>
        !            24: #include <semaphore.h>
        !            25: #include <string.h>
        !            26: #include <errno.h>
        !            27:
        !            28: #define _GNU_SOURCE
        !            29: #include <getopt.h>
        !            30:
        !            31: #include "nutss.h"
        !            32:
        !            33: sem_t sem;
        !            34:
        !            35: void usage(char *argv0);
        !            36:
        !            37: void
        !            38: usage(char *argv0)
        !            39: {
        !            40:     printf("Usage:\n"
        !            41:         "\t%s [OPTIONS] [SERVICES] user@domain\n"
        !            42:         "\n"
        !            43:         "Services:\n"
        !            44:         "  --stuntd,-s\t\tEnable STUNT server\n"
        !            45:         "  --turnd,-t\t\tEnable TURN server\n"
        !            46:         "  --swaplinksd,-w\tEnable Swaplinks server\n"
        !            47:         "\n"
        !            48:         "Options:\n"
        !            49:         "  --registrar,-r server:port\tUse sip registrar at server\n"
        !            50:         "  --password,-p pass\t\tUse password for registering with proxy\n",
        !            51:         "nutssd");
        !            52:     exit(1);
        !            53: }
        !            54:
        !            55: int
        !            56: main(int argc, char **argv)
        !            57: {
        !            58:     int c;
        !            59:     int idx = 0;
        !            60:     char *tmp;
        !            61:     static int one = 1;
        !            62:     static struct option opts[] = {
        !            63:         {"stuntd", 0, 0, 's'},
        !            64:         {"turnd", 0, 0, 't'},
        !            65:         {"swaplinksd", 0, 0, 'w'},
        !            66:         {"registrar", 1, 0, 'r'},
        !            67:         {"password", 1, 0, 'p'},
        !            68:         {"help", 1, 0, 'h'},
        !            69:         {0, 0, 0, 0}
        !            70:     };
        !            71:
        !            72:     nutss_config_set(NUTSS_CONFIG_OPT_BIND, &one, sizeof(one));
        !            73:     while (1) {
        !            74:         c = getopt_long(argc, argv, "hp:r:stw", opts, &idx);
        !            75:
        !            76:         if (c == -1)
        !            77:             break;
        !            78:
        !            79:         switch (c) {
        !            80:             case 's':
        !            81:                 nutss_config_set(NUTSS_CONFIG_OPT_STUNTD, &one,
        !            82:                     sizeof(one));
        !            83:                 break;
        !            84:             case 't':
        !            85:                 nutss_config_set(NUTSS_CONFIG_OPT_TURND, &one, sizeof(one));
        !            86:                 break;
        !            87:             case 'w':
        !            88:                 nutss_config_set(NUTSS_CONFIG_OPT_SWAPLINKSD, &one,
        !            89:                     sizeof(one));
        !            90:                 break;
        !            91:             case 'r':
        !            92:                 nutss_config_set(NUTSS_CONFIG_SIGPROXY, optarg,
        !            93:                     strlen(optarg) + 1);
        !            94:                 break;
        !            95:             case 'p':
        !            96:                 nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, optarg,
        !            97:                     strlen(optarg) + 1);
        !            98:                 break;
        !            99:             case 'h':
        !           100:             default:
        !           101:                 usage(argv[0]);
        !           102:         }
        !           103:     }
        !           104:
        !           105:     if (optind >= argc)
        !           106:         usage(argv[0]);
        !           107:
        !           108:     tmp = strchr(argv[optind], '@');
        !           109:     if (!tmp)
        !           110:         usage(argv[0]);
        !           111:     tmp[0] = '\0';
        !           112:     tmp++;
        !           113:     nutss_config_set(NUTSS_CONFIG_USERNAME, argv[optind],
        !           114:         strlen(argv[optind]) + 1);
        !           115:     nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, argv[optind],
        !           116:         strlen(argv[optind]) + 1);
        !           117:     nutss_config_set(NUTSS_CONFIG_DOMAINNAME, tmp, strlen(tmp) + 1);
        !           118:     optind++;
        !           119:
        !           120:     sem_init(&sem, 0, 0);
        !           121:     nutss_init();
        !           122:     while (sem_wait(&sem) == -1 && errno == EINTR);
        !           123:
        !           124:     return 1;
        !           125: }

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