Skip to content

Commit 66142c2

Browse files
committed
Make TTL sub-command functional.
PR: #59
1 parent 1e9fcb9 commit 66142c2

File tree

6 files changed

+122
-12
lines changed

6 files changed

+122
-12
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ BASE_SOURCES=main.c rtp.h rtpp_server.c \
6363
rtpp_nofile.c rtpp_nofile.h rtpp_record_adhoc.h \
6464
$(CMDSRCDIR)/rpcpv1_norecord.c $(CMDSRCDIR)/rpcpv1_norecord.h \
6565
$(CMDSRCDIR)/rpcpv1_ul_subc.c $(CMDSRCDIR)/rpcpv1_ul_subc.h \
66+
$(CMDSRCDIR)/rpcpv1_ul_subc_ttl.c $(CMDSRCDIR)/rpcpv1_ul_subc_ttl.h \
6667
$(RTPP_AUTOSRC_SOURCES) $(RTPP_AUTOSRC_SOURCES_S)
6768
ADV_DIR=$(top_srcdir)/src/advanced
6869
BASE_SOURCES+=$(ADV_DIR)/packet_observer.h $(ADV_DIR)/po_manager.c \

src/commands/rpcpv1_ul.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ rtpp_command_ul_opts_free(struct ul_opts *ulop)
151151
FREE_IF_NULL(ulop->codecs);
152152
FREE_IF_NULL(ulop->ia[0]);
153153
FREE_IF_NULL(ulop->ia[1]);
154+
FREE_IF_NULL(ulop->after_success.arg);
154155
free(ulop);
155156
}
156157

@@ -659,7 +660,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
659660
}
660661
if (ulop->after_success.handler != NULL) {
661662
struct rtpp_subc_ctx rsc = {.sessp = spa, .strmp = spa->rtp->stream[pidx],
662-
.strmp_rev = spa->rtp->stream[sidx], .subc_args = &(cmd->subc_args)};
663+
.subc_args = &(cmd->subc_args)};
664+
rsc.strmp_rev = (sidx != -1) ? spa->rtp->stream[sidx] : NULL;
663665
ulop->reply.subc_res = ulop->after_success.handler(ulop->after_success.arg, &rsc);
664666
}
665667
ul_reply_port(cmd, &ulop->reply);

src/commands/rpcpv1_ul_subc.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020 Sippy Software, Inc., http://www.sippysoft.com
2+
* Copyright (c) 2006-2021 Sippy Software, Inc., http://www.sippysoft.com
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -31,17 +31,20 @@
3131
#include "rtpp_types.h"
3232
#include "rtpp_cfg.h"
3333
#include "rtpp_util.h"
34+
#include "rtpp_mallocs.h"
3435
#include "rtpp_modman.h"
3536
#include "rtpp_command_args.h"
3637
#include "commands/rpcpv1_ul.h"
3738
#include "commands/rpcpv1_ul_subc.h"
39+
#include "commands/rpcpv1_ul_subc_ttl.h"
3840

3941
int
4042
rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp,
4143
const struct rtpp_command_args *subc_args, struct after_success_h *asp)
4244
{
43-
int mod_id, inst_id, ttl;
45+
int mod_id, inst_id;
4446
const char *cp;
47+
struct rtpp_subcommand_ttl ttl_arg, *tap;
4548

4649
switch(subc_args->v[0][0]) {
4750
case 'M':
@@ -60,18 +63,22 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp,
6063
case 'T':
6164
case 't':
6265
cp = &subc_args->v[0][1];
63-
if (cp[0] == 'r' || cp[0] == 'R')
66+
if (cp[0] == 'r' || cp[0] == 'R') {
67+
ttl_arg.direction = TTL_REVERSE;
6468
cp += 1;
65-
if (atoi_safe(cp, &ttl) != ATOI_OK)
69+
} else {
70+
ttl_arg.direction = TTL_FORWARD;
71+
}
72+
if (atoi_safe(cp, &ttl_arg.ttl) != ATOI_OK)
6673
return (-1);
67-
if (ttl <= 0)
74+
if (ttl_arg.ttl <= 0)
6875
return (-1);
69-
#if 0
70-
if (c == 't')
71-
ulop->requested_sttl = n;
72-
else
73-
ulop->requested_pttl = n;
74-
#endif
76+
tap = rtpp_zmalloc(sizeof(ttl_arg));
77+
if (tap == NULL)
78+
return (-1);
79+
*tap = ttl_arg;
80+
asp->arg = tap;
81+
asp->handler = rtpp_subcommand_ttl_handler;
7582
break;
7683

7784
default:

src/commands/rpcpv1_ul_subc_ttl.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2021 Sippy Software, Inc., http://www.sippysoft.com
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23+
* SUCH DAMAGE.
24+
*
25+
*/
26+
27+
#include <stdint.h>
28+
#include <stdlib.h>
29+
30+
#include "rtpp_types.h"
31+
#include "rtpp_stream.h"
32+
#include "rtpp_ttl.h"
33+
#include "rtpp_command_sub.h"
34+
#include "commands/rpcpv1_ul_subc_ttl.h"
35+
36+
int
37+
rtpp_subcommand_ttl_handler(void *ap, const struct rtpp_subc_ctx *rscp)
38+
{
39+
const struct rtpp_subcommand_ttl *tap;
40+
struct rtpp_stream *strmp;
41+
42+
tap = (struct rtpp_subcommand_ttl *)ap;
43+
switch (tap->direction) {
44+
case TTL_FORWARD:
45+
strmp = rscp->strmp;
46+
break;
47+
48+
case TTL_REVERSE:
49+
strmp = rscp->strmp_rev;
50+
if (strmp == NULL)
51+
return (-1);
52+
break;
53+
54+
default:
55+
abort();
56+
}
57+
58+
CALL_METHOD(strmp->ttl, reset_with, tap->ttl);
59+
return (0);
60+
}

src/commands/rpcpv1_ul_subc_ttl.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021 Sippy Software, Inc., http://www.sippysoft.com
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23+
* SUCH DAMAGE.
24+
*
25+
*/
26+
27+
struct rtpp_subc_ctx;
28+
29+
enum rtpp_subcommand_ttl_direction {
30+
TTL_FORWARD = 0,
31+
TTL_REVERSE = 1
32+
};
33+
34+
struct rtpp_subcommand_ttl {
35+
int ttl;
36+
enum rtpp_subcommand_ttl_direction direction;
37+
};
38+
39+
int rtpp_subcommand_ttl_handler(void *, const struct rtpp_subc_ctx *);

src/commands/rpcpv1_ver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static struct proto_cap proto_caps[] = {
6262
{ "20150617", "Support for the wildcard %%CC_SELF%% as a disconnect notify target" },
6363
{ "20191015", "Support for the && sub-command specifier" },
6464
{ "20200226", "Support for the N command to stop recording" },
65+
{ "20210524", "Support for changing session's ttl" },
6566
{ NULL, NULL }
6667
};
6768

0 commit comments

Comments
 (0)