aboutsummaryrefslogtreecommitdiff
path: root/plugins/framing_fixedlength.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-06-20 15:23:45 +0200
committercbdev <cb@cbcdn.com>2019-06-20 15:23:45 +0200
commit7a1b8a0fefe9a2a0fae6289195e2936ec9c17000 (patch)
treed8ac7b6055ac661cbf65208995cea182cf690e9a /plugins/framing_fixedlength.c
parent3c75202f5f4e9c1c61fead33f0f08e742d143223 (diff)
downloadwebsocksy-7a1b8a0fefe9a2a0fae6289195e2936ec9c17000.tar.gz
websocksy-7a1b8a0fefe9a2a0fae6289195e2936ec9c17000.tar.bz2
websocksy-7a1b8a0fefe9a2a0fae6289195e2936ec9c17000.zip
Implement fixedlength framing
Diffstat (limited to 'plugins/framing_fixedlength.c')
-rw-r--r--plugins/framing_fixedlength.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/plugins/framing_fixedlength.c b/plugins/framing_fixedlength.c
new file mode 100644
index 0000000..1a66df4
--- /dev/null
+++ b/plugins/framing_fixedlength.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+
+#include "../websocksy.h"
+
+static int64_t framing_fixedlen(uint8_t* data, size_t length, size_t last_read, ws_operation* opcode, void** framing_data, const char* config){
+ size_t* frame_size = framing_data ? (size_t*) (*framing_data) : NULL;
+
+ if(data && !frame_size){
+ frame_size = calloc(1, sizeof(size_t));
+ if(!frame_size){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return -1;
+ }
+
+ *frame_size = strtoul(config, NULL, 0);
+ *framing_data = frame_size;
+ }
+ else if(!data && frame_size){
+ free(*framing_data);
+ *framing_data = NULL;
+ }
+
+ if(!(*frame_size)){
+ return length;
+ }
+
+ if(length >= *frame_size){
+ return *frame_size;
+ }
+
+ return 0;
+}
+
+static void __attribute__((constructor)) init(){
+ core_register_framing("fixedlength", framing_fixedlen);
+}