ref: 6f648fdb5b6ec6debecd45d316663438ec8f1234
parent: 09dddd479ccc39088ccbb2f5b514fa9127c74811
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Aug 5 04:51:12 EDT 2021
response may come on a different chunk stream - compare the code (if set) in the response
--- a/rtmp.c
+++ b/rtmp.c
@@ -78,6 +78,7 @@
struct Command {
void (*cb)(RTMP *r, int ok, A₀ *a[NumCb], void *aux);
+ char *code;
void *aux;
int tid;
int cs;
@@ -446,12 +447,13 @@
static void
loop(void *aux)
{
- int res, n, ok;
- A₀ *a[NumCb];
+ int res, n, ok, i;
+ A₀ *a[NumCb], *v;
u8int *s, *e;
s16int s16;
Message *m;
Command *c;
+ char *k;
RTMP *r;
r = aux;
@@ -501,16 +503,30 @@
werrstr("transaction ID is not a number");
goto err;
}
+ if(a[n]->num == 0) /* no transaction, will try matching with response */
+ break;
for(c = r->cmds.w; c != nil; c = c->next){
/* transaction id match */
if(c->tid == a[n]->num)
break;
- /* no transaction id, but the chunk stream matches */
- if(a[n]->num == 0 && c->cs == m->cs)
+ }
+ break;
+ case CbResponse:
+ if(a[CbTransID]->num != 0) /* should have matches with the transaction */
+ break;
+ if(a[n]->type != Tobj)
+ break;
+ for(i = 0; i < a[n]->obj.n; i++){
+ k = a[n]->obj.k[i];
+ v = a[n]->obj.v[i];
+ if(strcmp(k, "code") == 0 && v->type == Tstr){
+ for(c = r->cmds.w; c != nil; c = c->next){
+ if(c->code != nil && strcmp(c->code, v->str) == 0)
+ break;
+ }
break;
+ }
}
- if(c == nil)
- fprint(2, "response to non-existent transaction %d", (int)a[n]->num);
break;
}
}
@@ -525,6 +541,8 @@
r->cmds.w = c->next;
c->cb(r, ok, a, c->aux);
free(c);
+ }else if(a[CbTransID] != nil){
+ fprint(2, "response/command with no handler (transaction %d)\n", (int)a[CbTransID]->num);
}
break;
@@ -728,6 +746,7 @@
r->o.msg.cmd.cb = streampublished;
r->o.msg.cmd.aux = c;
+ r->o.msg.cmd.code = "NetStream.Publish.Start";
r->o.msg.sid = sid;
n = rtmpsend(r);