Compare commits
3 Commits
cca8f02870
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0716abc81 | ||
|
|
8b0fbfdcf7 | ||
|
|
75c0ac1997 |
7
Makefile
Normal file
7
Makefile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
libeebie.so:
|
||||||
|
$(CC) -shared -g -O2 -o libeebie.so eebie/reader.c eebie/writer.c
|
||||||
|
|
||||||
|
install:
|
||||||
|
install -d /usr/local/include/eebie
|
||||||
|
install eebie/*.h /usr/local/include/eebie
|
||||||
|
install libeebie.so /usr/local/lib
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include"reader.h"
|
#include"reader.h"
|
||||||
|
|
||||||
|
#define is_max(u) ((u) == 0xFFFFFFFFFFFFFFFFUL)
|
||||||
|
|
||||||
void ebml_reader_init(EBMLReader *this) {
|
void ebml_reader_init(EBMLReader *this) {
|
||||||
memset(this, 0, sizeof(*this));
|
memset(this, 0, sizeof(*this));
|
||||||
this->state = EBMLRS_WAITING_FOR_ELEMENT_ID;
|
this->state = EBMLRS_WAITING_FOR_ELEMENT_ID;
|
||||||
@@ -89,6 +91,10 @@ static int get_varint(const uint8_t *data, size_t length, uint64_t *result) {
|
|||||||
|
|
||||||
if(ret >= 0) {
|
if(ret >= 0) {
|
||||||
*result &= ~VARINT_MASKS[ret];
|
*result &= ~VARINT_MASKS[ret];
|
||||||
|
|
||||||
|
if(*result == (1UL << (ret * 7)) - 1) {
|
||||||
|
*result = 0xFFFFFFFFFFFFFFFFUL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -137,7 +143,7 @@ int ebml_reader_feed(EBMLReader *this, const uint8_t *data, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->idStack[this->currentDepth] = this->inside.id;
|
this->idStack[this->currentDepth] = this->inside.id;
|
||||||
this->stack[this->currentDepth] = elLength + status;
|
this->stack[this->currentDepth] = is_max(elLength) ? elLength : elLength + status;
|
||||||
|
|
||||||
this->currentDepth++;
|
this->currentDepth++;
|
||||||
|
|
||||||
@@ -156,8 +162,10 @@ int ebml_reader_feed(EBMLReader *this, const uint8_t *data, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < this->currentDepth; i++) {
|
for(int i = 0; i < this->currentDepth; i++) {
|
||||||
|
if(!is_max(this->stack[i])) {
|
||||||
this->stack[i] -= eaten;
|
this->stack[i] -= eaten;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while(this->currentDepth > 0 && this->stack[this->currentDepth - 1] == 0) {
|
while(this->currentDepth > 0 && this->stack[this->currentDepth - 1] == 0) {
|
||||||
|
|
||||||
@@ -173,3 +181,12 @@ int ebml_reader_feed(EBMLReader *this, const uint8_t *data, size_t length) {
|
|||||||
|
|
||||||
return eaten;
|
return eaten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ebml_reader_leave(EBMLReader *this, uint64_t id) {
|
||||||
|
for(int i = 0; i < this->currentDepth; i++) {
|
||||||
|
if(this->idStack[i] == id) {
|
||||||
|
this->currentDepth = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ typedef struct EBMLReader {
|
|||||||
void ebml_reader_init(EBMLReader*);
|
void ebml_reader_init(EBMLReader*);
|
||||||
int ebml_reader_feed(EBMLReader*, const uint8_t *data, size_t length);
|
int ebml_reader_feed(EBMLReader*, const uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
// Because Eebie is schemaless, it must be told when we have left an
|
||||||
|
// indefinite element, otherwise the stack may grow indefinitely and
|
||||||
|
// even overflow. The user may call this from eventEnterElement.
|
||||||
|
void ebml_reader_leave(EBMLReader*, uint64_t id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ static int bit_length(uint64_t i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t encode_int(uint64_t i) {
|
static uint64_t encode_int(uint64_t i) {
|
||||||
return i | VARINT_MASKS[(bit_length(i) + 6) / 7];
|
// bit_length(i + 1) over bit_length(i) because 0xFF... lengths are interpreted as indefinite
|
||||||
|
return i | VARINT_MASKS[(bit_length(i + 1) + 6) / 7];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void advance(EBMLWriter *this, uint64_t amount) {
|
static void advance(EBMLWriter *this, uint64_t amount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user