Skip to content

Commit

Permalink
Add T[r]XXX sub-command.
Browse files Browse the repository at this point in the history
PR: 	#59
  • Loading branch information
sobomax committed Jan 23, 2023
1 parent b70f6a1 commit 76609e8
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BASE_SOURCES=main.c rtp.h rtpp_server.c rtpp_pthread.c rtpp_pthread.h \
rtpp_nofile.c rtpp_nofile.h rtpp_record_adhoc.h \
$(CMDSRCDIR)/rpcpv1_norecord.c $(CMDSRCDIR)/rpcpv1_norecord.h \
$(CMDSRCDIR)/rpcpv1_ul_subc.c $(CMDSRCDIR)/rpcpv1_ul_subc.h \
$(CMDSRCDIR)/rpcpv1_ul_subc_ttl.c $(CMDSRCDIR)/rpcpv1_ul_subc_ttl.h \
$(RTPP_AUTOSRC_SOURCES) rtpp_epoll.c
ADV_DIR=$(top_srcdir)/src/advanced
BASE_SOURCES+=$(ADV_DIR)/packet_observer.h $(ADV_DIR)/pproc_manager.c \
Expand Down
28 changes: 27 additions & 1 deletion src/commands/rpcpv1_ul_subc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020 Sippy Software, Inc., http://www.sippysoft.com
* Copyright (c) 2006-2021 Sippy Software, Inc., http://www.sippysoft.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -31,17 +31,20 @@
#include "rtpp_types.h"
#include "rtpp_cfg.h"
#include "rtpp_util.h"
#include "rtpp_mallocs.h"
#include "rtpp_modman.h"
#include "rtpp_command_args.h"
#include "commands/rpcpv1_ul.h"
#include "commands/rpcpv1_ul_subc.h"
#include "commands/rpcpv1_ul_subc_ttl.h"

int
rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp,
const struct rtpp_command_args *subc_args, struct after_success_h *asp)
{
int mod_id, inst_id;
const char *cp;
struct rtpp_subcommand_ttl ttl_arg, *tap;

switch(subc_args->v[0][0]) {
case 'M':
Expand All @@ -57,6 +60,29 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp,
return (-1);
break;

case 'T':
case 't':
if (subc_args->c != 1)
return (-1);
cp = &subc_args->v[0][1];
if (cp[0] == 'r' || cp[0] == 'R') {
ttl_arg.direction = TTL_REVERSE;
cp += 1;
} else {
ttl_arg.direction = TTL_FORWARD;
}
if (atoi_safe(cp, &ttl_arg.ttl) != ATOI_OK)
return (-1);
if (ttl_arg.ttl <= 0)
return (-1);
tap = rtpp_zmalloc(sizeof(ttl_arg));
if (tap == NULL)
return (-1);
*tap = ttl_arg;
asp->args.dyn = tap;
asp->handler = rtpp_subcommand_ttl_handler;
break;

default:
return (-1);
}
Expand Down
62 changes: 62 additions & 0 deletions src/commands/rpcpv1_ul_subc_ttl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2021 Sippy Software, Inc., http://www.sippysoft.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
*/

#include <stdint.h>
#include <stdlib.h>

#include "rtpp_types.h"
#include "rtpp_stream.h"
#include "rtpp_ttl.h"
#include "rtpp_command_sub.h"
#include "commands/rpcpv1_ul.h"
#include "commands/rpcpv1_ul_subc_ttl.h"

int
rtpp_subcommand_ttl_handler(const struct after_success_h_args *ashap,
const struct rtpp_subc_ctx *rscp)
{
const struct rtpp_subcommand_ttl *tap;
struct rtpp_stream *strmp;

tap = (struct rtpp_subcommand_ttl *)ashap->dyn;
switch (tap->direction) {
case TTL_FORWARD:
strmp = rscp->strmp_in;
break;

case TTL_REVERSE:
strmp = rscp->strmp_out;
if (strmp == NULL)
return (-1);
break;

default:
abort();
}

CALL_SMETHOD(strmp->ttl, reset_with, tap->ttl);
return (0);
}
41 changes: 41 additions & 0 deletions src/commands/rpcpv1_ul_subc_ttl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 Sippy Software, Inc., http://www.sippysoft.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
*/

struct rtpp_subc_ctx;
struct after_success_h_args;

enum rtpp_subcommand_ttl_direction {
TTL_FORWARD = 0,
TTL_REVERSE = 1
};

struct rtpp_subcommand_ttl {
int ttl;
enum rtpp_subcommand_ttl_direction direction;
};

int rtpp_subcommand_ttl_handler(const struct after_success_h_args *,
const struct rtpp_subc_ctx *);
1 change: 1 addition & 0 deletions src/commands/rpcpv1_ver.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static struct proto_cap proto_caps[] = {
{ "20150617", "Support for the wildcard %%CC_SELF%% as a disconnect notify target" },
{ "20191015", "Support for the && sub-command specifier" },
{ "20200226", "Support for the N command to stop recording" },
{ "20210524", "Support for changing session's ttl" },
{ NULL, NULL }
};

Expand Down

0 comments on commit 76609e8

Please sign in to comment.