Skip to content

Commit 51437ba

Browse files
authored
Fix RTMP URL path parsing (#245)
1 parent 05a960b commit 51437ba

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

include/re_fmt.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int pl_strcasecmp(const struct pl *pl, const char *str);
4242
int pl_cmp(const struct pl *pl1, const struct pl *pl2);
4343
int pl_casecmp(const struct pl *pl1, const struct pl *pl2);
4444
const char *pl_strchr(const struct pl *pl, char c);
45+
const char *pl_strrchr(const struct pl *pl, char c);
4546

4647
/** Advance pl position/length by +/- N bytes */
4748
static inline void pl_advance(struct pl *pl, ssize_t n)

src/fmt/pl.c

+25
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,28 @@ const char *pl_strchr(const struct pl *pl, char c)
503503

504504
return NULL;
505505
}
506+
507+
508+
/**
509+
* Locate the last occurrence of character in pointer-length string
510+
*
511+
* @param pl Pointer-length string
512+
* @param c Character to locate
513+
*
514+
* @return Pointer to last char if found, otherwise NULL
515+
*/
516+
const char *pl_strrchr(const struct pl *pl, char c)
517+
{
518+
const char *p, *end;
519+
520+
if (!pl_isset(pl))
521+
return NULL;
522+
523+
end = pl->p + pl->l - 1;
524+
for (p = end; p >= pl->p; p--) {
525+
if (*p == c)
526+
return p;
527+
}
528+
529+
return NULL;
530+
}

src/rtmp/conn.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static int send_connect(struct rtmp_conn *conn)
437437
1,
438438
RTMP_AMF_TYPE_OBJECT, 8,
439439
RTMP_AMF_TYPE_STRING, "app", conn->app,
440-
RTMP_AMF_TYPE_STRING, "flashVer", "LNX 9,0,124,2",
440+
RTMP_AMF_TYPE_STRING, "flashVer", "FMLE/3.0",
441441
RTMP_AMF_TYPE_STRING, "tcUrl", conn->uri,
442442
RTMP_AMF_TYPE_BOOLEAN, "fpad", false,
443443
RTMP_AMF_TYPE_NUMBER, "capabilities", 15.0,
@@ -803,18 +803,30 @@ int rtmp_connect(struct rtmp_conn **connp, struct dnsc *dnsc, const char *uri,
803803
struct pl pl_hostport;
804804
struct pl pl_host;
805805
struct pl pl_port;
806+
struct pl pl_path;
806807
struct pl pl_app;
807808
struct pl pl_stream;
809+
const char *tok;
808810
uint16_t defport;
809811
int err;
810812

811813
if (!connp || !uri)
812814
return EINVAL;
813815

814-
if (re_regex(uri, strlen(uri), "[a-z]+://[^/]+/[^/]+/[^]+",
815-
&pl_scheme, &pl_hostport, &pl_app, &pl_stream))
816+
if (re_regex(uri, strlen(uri), "[a-z]+://[^/]+/[^]+",
817+
&pl_scheme, &pl_hostport, &pl_path))
816818
return EINVAL;
817819

820+
tok = pl_strrchr(&pl_path, '/');
821+
if (!tok)
822+
return EINVAL;
823+
824+
pl_app.p = pl_path.p;
825+
pl_app.l = tok - pl_path.p;
826+
827+
pl_stream.p = tok + 1;
828+
pl_stream.l = pl_path.p + pl_path.l - pl_stream.p;
829+
818830
if (!pl_strcasecmp(&pl_scheme, "rtmp")) {
819831
tls = NULL;
820832
defport = RTMP_PORT;

0 commit comments

Comments
 (0)