From 998f05896130fb3cfbfdd03a145164d2067cd042 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 5 Mar 2007 00:58:24 +0000 Subject: Implemented new STUN server framework git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1040 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjstun-srv-test/main.c | 132 ++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 pjlib-util/src/pjstun-srv-test/main.c (limited to 'pjlib-util/src/pjstun-srv-test/main.c') diff --git a/pjlib-util/src/pjstun-srv-test/main.c b/pjlib-util/src/pjstun-srv-test/main.c new file mode 100644 index 00000000..6bc3382d --- /dev/null +++ b/pjlib-util/src/pjstun-srv-test/main.c @@ -0,0 +1,132 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2005 Benny Prijono + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "server.h" + +struct options +{ + char *realm; + char *user_name; + char *password; + char *nonce; + pj_bool_t use_fingerprint; +} o; + +static void usage(void) +{ + puts("Usage: pjstun_srv_test [OPTIONS]"); + puts(""); + puts("where OPTIONS:"); + puts(" --realm, -r Set realm of the credential"); + puts(" --username, -u Set username of the credential"); + puts(" --password, -p Set password of the credential"); + puts(" --nonce, -N Set NONCE"); + puts(" --fingerprint, -F Use fingerprint for outgoing requests"); + puts(" --help, -h"); +} + + +static void server_main(void) +{ + int quit = 0; + + while (!quit) { + char line[10]; + + printf("Menu:\n" + " q Quit\n" + "Choice:"); + + fgets(line, sizeof(line), stdin); + if (line[0] == 'q') + quit = 1; + } +} + +int main(int argc, char *argv[]) +{ + struct pj_getopt_option long_options[] = { + { "realm", 1, 0, 'r'}, + { "username", 1, 0, 'u'}, + { "password", 1, 0, 'p'}, + { "nonce", 1, 0, 'N'}, + { "fingerprint",0, 0, 'F'}, + { "help", 0, 0, 'h'} + }; + int c, opt_id; + pj_caching_pool cp; + pj_stun_server *srv; + pj_stun_usage *bu; + pj_status_t status; + + while((c=pj_getopt_long(argc,argv, "r:u:p:hF", long_options, &opt_id))!=-1) { + switch (c) { + case 'r': + o.realm = pj_optarg; + break; + case 'u': + o.user_name = pj_optarg; + break; + case 'p': + o.password = pj_optarg; + break; + case 'N': + o.nonce = pj_optarg; + break; + case 'h': + usage(); + return 0; + case 'F': + o.use_fingerprint = PJ_TRUE; + break; + default: + printf("Argument \"%s\" is not valid. Use -h to see help", + argv[pj_optind]); + return 1; + } + } + + if (pj_optind != argc) { + puts("Error: invalid arguments"); + return 1; + } + + pj_init(); + pjlib_util_init(); + pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); + + status = pj_stun_server_create(&cp.factory, 1, &srv); + if (status != PJ_SUCCESS) { + pj_stun_perror(THIS_FILE, "Unable to create server", status); + return 1; + } + + status = pj_stun_bind_usage_create(srv, NULL, 3478, &bu); + if (status != PJ_SUCCESS) { + pj_stun_perror(THIS_FILE, "Unable to create bind usage", status); + return 1; + } + + server_main(); + + pj_stun_usage_destroy(bu); + pj_stun_server_destroy(srv); + pj_pool_factory_dump(&cp.factory, PJ_TRUE); + pj_shutdown(); + return 0; +} -- cgit v1.2.3