Skip to content

Commit

Permalink
add get_tag()
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed Apr 17, 2023
1 parent 46a3149 commit 38a1ec8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
40 changes: 39 additions & 1 deletion status.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ uint32_t send_poll(int fd,int ssrc){


// Extract SSRC; 0 means not present (reserved value)
int get_ssrc(uint8_t const *buffer,int length){
uint32_t get_ssrc(uint8_t const *buffer,int length){
uint8_t const *cp = buffer;

while(cp - buffer < length){
Expand Down Expand Up @@ -360,6 +360,44 @@ int get_ssrc(uint8_t const *buffer,int length){
}
cp += optlen;
}
done:;
return 0;
}
// Extract command tag
uint32_t get_tag(uint8_t const *buffer,int length){
uint8_t const *cp = buffer;

while(cp - buffer < length){
enum status_type const type = *cp++; // increment cp to length field

if(type == EOL)
break; // end of list, no length

unsigned int optlen = *cp++;
if(optlen & 0x80){
// length is >= 128 bytes; fetch actual length from next N bytes, where N is low 7 bits of optlen
int length_of_length = optlen & 0x7f;
optlen = 0;
while(length_of_length > 0){
optlen <<= 8;
optlen |= *cp++;
length_of_length--;
}
}
if(cp - buffer + optlen >= length)
break; // invalid length; we can't continue to scan

switch(type){
case EOL: // Shouldn't get here
goto done;
case COMMAND_TAG:
return decode_int(cp,optlen);
break;
default:
break; // Ignore on this pass
}
cp += optlen;
}
done:;
return 0; // broadcast
}
Expand Down
3 changes: 2 additions & 1 deletion status.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ float decode_float(uint8_t const *,int);
double decode_double(uint8_t const *,int);
struct sockaddr *decode_socket(void *sock,uint8_t const *,int);
char *decode_string(uint8_t const *,int,char *,int);
int get_ssrc(uint8_t const *buffer,int length);
uint32_t get_ssrc(uint8_t const *buffer,int length);
uint32_t get_tag(uint8_t const *buffer,int length);

void dump_metadata(uint8_t const *,int);

Expand Down

0 comments on commit 38a1ec8

Please sign in to comment.