ref: 8fb3df30a16cc34dcb10c3c068ddca913fb71047
parent: c6821e9c478e8c1e4effdba02cfe7d56a78c3cd9
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Jul 27 10:28:45 EDT 2021
print packet contents on Invoke
--- a/amf.c
+++ b/amf.c
@@ -190,3 +190,88 @@
*i = p[0]<<16 | p[1]<<16 | p[2]<<8 | p[3];
return p+4;
}
+
+u8int *
+amffmt(Fmt *f, u8int *p, u8int *e, int one)
+{
+ union {
+ double v;
+ u64int u;
+ }x;
+ s16int s16;
+ int n;
+
+ for(; p != e;){
+ atleast(1);
+
+ switch(*p++){
+ case Anum:
+ atleast(8);
+ x.u = (uvlong)p[0]<<56 | (uvlong)p[1]<<48 | (uvlong)p[2]<<40 | (uvlong)p[3]<<32;
+ x.u |= p[4]<<24 | p[5]<<16 | p[6]<<8 | p[7];
+ fmtprint(f, "%g", x.v);
+ p += 8;
+ break;
+ case Abool:
+ atleast(1);
+ fmtprint(f, *p ? "true" : "false");
+ p++;
+ break;
+ case Astr:
+ if((p = amfi16get(p, e, &s16)) == nil)
+ return nil;
+ n = s16;
+String:
+ atleast(n);
+ /* FIXME this isn't correct - UTF-8 */
+ fmtprint(f, "%.*#q", n, (char*)p);
+ p += n;
+ break;
+ case Aobj:
+ fmtprint(f, "O{");
+ for(;;){
+ if((p = amfi16get(p, e, &s16)) == nil)
+ return nil;
+ if(s16 == 0){
+ atleast(1);
+ if(*p != Aend){
+ werrstr("object doesn't end well");
+ return nil;
+ }
+ p++;
+ fmtprint(f, "}");
+ break;
+ }
+ n = s16;
+ atleast(n);
+ fmtprint(f, "%.*s=", n, (char*)p);
+ p += n;
+ p = amffmt(f, p, e, 1);
+ fmtprint(f, " ");
+ }
+ break;
+ case Aarr:
+ fmtprint(f, "A{");
+ atleast(4);
+ p += 4;
+ break;
+ case Aend:
+ fmtprint(f, "}");
+ break;
+ case Alstr:
+ if((p = amfi32get(p, e, &n)) == nil)
+ return nil;
+ goto String;
+ default:
+ fmtprint(f, "?%d?", p[-1]);
+ break;
+ }
+
+ if(one)
+ break;
+ if(p != e)
+ fmtprint(f, " ");
+ }
+
+ return p;
+}
--- a/amf.h
+++ b/amf.h
@@ -16,3 +16,5 @@
u8int *amfi16get(u8int *p, u8int *e, s16int *i);
u8int *amfi24get(u8int *p, u8int *e, s32int *i);
u8int *amfi32get(u8int *p, u8int *e, s32int *i);
+
+u8int *amffmt(Fmt *f, u8int *p, u8int *e, int one);
--- a/rtmp.c
+++ b/rtmp.c
@@ -10,18 +10,17 @@
#define min(a,b) ((a)<(b)?(a):(b))
enum {
- Port = 1935,
+ SzLarge,
+ SzMedium,
+ SzSmall,
+ SzTiny,
+ Port = 1935,
Sigsz = 1536,
Chunk = 128,
ChanCtl = 3,
- SzLarge = 0,
- SzMedium,
- SzSmall,
- SzTiny,
-
PktChunkSz = 1,
PktBytesReadReport,
PktControl,
@@ -130,7 +129,12 @@
p = va_arg(f->args, Packet*);
- return fmtprint(f, "type=%T chan=%d ts=%ud sz=%d", p->type, p->chan, p->ts, p->sz);
+ fmtprint(f, "type=%T chan=%d ts=%ud sz=%d: ", p->type, p->chan, p->ts, p->sz);
+
+ if(p->type == PktInvoke)
+ amffmt(f, p->data, p->data+p->sz, 0);
+
+ return 0;
}
static Packet *
@@ -386,6 +390,7 @@
fmtinstall('T', pktypefmt);
fmtinstall('P', pkfmt);
+ quotefmtinstall();
r = nil;
f = -1;