Skip to content

Commit

Permalink
Make TTL sub-command functional.
Browse files Browse the repository at this point in the history
PR:	#59
  • Loading branch information
sobomax committed May 24, 2021
1 parent 1e9fcb9 commit 66142c2
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ BASE_SOURCES=main.c rtp.h rtpp_server.c \
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_AUTOSRC_SOURCES_S)
ADV_DIR=$(top_srcdir)/src/advanced
BASE_SOURCES+=$(ADV_DIR)/packet_observer.h $(ADV_DIR)/po_manager.c \
Expand Down
4 changes: 3 additions & 1 deletion src/commands/rpcpv1_ul.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ rtpp_command_ul_opts_free(struct ul_opts *ulop)
FREE_IF_NULL(ulop->codecs);
FREE_IF_NULL(ulop->ia[0]);
FREE_IF_NULL(ulop->ia[1]);
FREE_IF_NULL(ulop->after_success.arg);
free(ulop);
}

Expand Down Expand Up @@ -659,7 +660,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
}
if (ulop->after_success.handler != NULL) {
struct rtpp_subc_ctx rsc = {.sessp = spa, .strmp = spa->rtp->stream[pidx],
.strmp_rev = spa->rtp->stream[sidx], .subc_args = &(cmd->subc_args)};
.subc_args = &(cmd->subc_args)};
rsc.strmp_rev = (sidx != -1) ? spa->rtp->stream[sidx] : NULL;
ulop->reply.subc_res = ulop->after_success.handler(ulop->after_success.arg, &rsc);
}
ul_reply_port(cmd, &ulop->reply);
Expand Down
29 changes: 18 additions & 11 deletions 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, ttl;
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 @@ -60,18 +63,22 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp,
case 'T':
case 't':
cp = &subc_args->v[0][1];
if (cp[0] == 'r' || cp[0] == 'R')
if (cp[0] == 'r' || cp[0] == 'R') {
ttl_arg.direction = TTL_REVERSE;
cp += 1;
if (atoi_safe(cp, &ttl) != ATOI_OK)
} else {
ttl_arg.direction = TTL_FORWARD;
}
if (atoi_safe(cp, &ttl_arg.ttl) != ATOI_OK)
return (-1);
if (ttl <= 0)
if (ttl_arg.ttl <= 0)
return (-1);
#if 0
if (c == 't')
ulop->requested_sttl = n;
else
ulop->requested_pttl = n;
#endif
tap = rtpp_zmalloc(sizeof(ttl_arg));
if (tap == NULL)
return (-1);
*tap = ttl_arg;
asp->arg = tap;
asp->handler = rtpp_subcommand_ttl_handler;
break;

default:
Expand Down
60 changes: 60 additions & 0 deletions src/commands/rpcpv1_ul_subc_ttl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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_subc_ttl.h"

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

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

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

default:
abort();
}

CALL_METHOD(strmp->ttl, reset_with, tap->ttl);
return (0);
}
39 changes: 39 additions & 0 deletions src/commands/rpcpv1_ul_subc_ttl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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;

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(void *, 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 66142c2

Please sign in to comment.