]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
adding nat_map api
authorBrian West <brian@freeswitch.org>
Mon, 1 Jun 2009 18:24:54 +0000 (18:24 +0000)
committerBrian West <brian@freeswitch.org>
Mon, 1 Jun 2009 18:24:54 +0000 (18:24 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13531 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c

index 3bb399da0ea92ad1b46d4826bf26fd8030c6b961..7b51b8c231aca6eddc67c5b494a07bf88b2dfdcb 100644 (file)
@@ -44,6 +44,53 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown);
 SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown, NULL);
 
+SWITCH_STANDARD_API(nat_map_function)
+{
+       int argc;
+       char *mydata = NULL, *argv[4];
+       switch_nat_ip_proto_t proto = SWITCH_NAT_UDP;
+
+       if (!cmd) {
+               goto error;
+       }
+
+       mydata = strdup(cmd);
+       switch_assert(mydata);
+
+       argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+       if (argc < 3) {
+               goto error;
+       }
+
+       if (argv[2] && switch_stristr("tcp", argv[2])) {
+               proto = SWITCH_NAT_TCP;
+       } else if (argv[2] && switch_stristr("udp", argv[2])) {
+               proto = SWITCH_NAT_UDP;
+       }
+
+       if (argv[0] && switch_stristr("add", argv[0])) {
+               if (switch_nat_add_mapping(atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) {
+                       stream->write_function(stream, "true");
+                       goto ok;
+               }
+       } else if (argv[0] && switch_stristr("del", argv[0])) {
+               if (switch_nat_del_mapping(atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) {
+                       stream->write_function(stream, "true");
+                       goto ok;
+               }
+       }
+
+  error:
+
+       stream->write_function(stream, "false");
+
+  ok:
+
+       switch_safe_free(mydata);
+
+       return SWITCH_STATUS_SUCCESS;
+}
 
 SWITCH_STANDARD_API(time_test_function)
 {
@@ -3483,6 +3530,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "stun", "stun", stun_function, "<stun_server>[:port]");
        SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, "<mss>");
+       SWITCH_ADD_API(commands_api_interface, "nat_map", "nat_map", nat_map_function, "[add|del] <port> [tcp|udp]");
 
        /* indicate that the module should continue to be loaded */
        return SWITCH_STATUS_NOUNLOAD;