summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-12-25 22:55:21 +0100
committertomsmeding <tom.smeding@gmail.com>2016-12-25 22:56:13 +0100
commited2b3a38ec05c566c645dc2aabfd513edff8d63b (patch)
tree388cf0c5d6a425f5d7f86783e0c67e930f94c6a4 /plugins
parent70431dcb67e33bd466d03fb41e5a90ba301127a4 (diff)
Plugins
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile39
-rw-r--r--plugins/echoback/echoback.c25
2 files changed, 64 insertions, 0 deletions
diff --git a/plugins/Makefile b/plugins/Makefile
new file mode 100644
index 0000000..145500c
--- /dev/null
+++ b/plugins/Makefile
@@ -0,0 +1,39 @@
+CC = gcc
+CFLAGS = -Wall -Wextra -std=c11 -fwrapv -I..
+ifneq ($(DEBUG),)
+ CFLAGS += -g
+else
+ CFLAGS += -O2
+endif
+
+ifeq ($(shell uname),Darwin)
+ SO_EXT = dylib
+ SO_FLAGS = -dynamiclib
+else
+ SO_EXT = so
+ SO_FLAGS = -shared
+endif
+SO_FLAGS += -fPIC
+
+TARGET = $(PLUGINNAME)/$(PLUGINNAME).$(SO_EXT)
+
+
+.PHONY: all clean remake warning
+
+all: warning $(TARGET)
+
+clean:
+ rm -rf $(TARGET) $(PLUGINNAME)/*.{o,dSYM}
+
+remake: clean all
+
+warning:
+ifndef PLUGINNAME
+ $(error "PLUGINNAME not set! Please run root Makefile instead.")
+endif
+
+
+.SECONDARY:
+
+$(PLUGINNAME)/%.$(SO_EXT): $(patsubst %.c,%.o,$(wildcard $(PLUGINNAME)/*.c)) $(wildcard ../*.o ../*.h)
+ $(CC) $(SO_FLAGS) -o $@ $(filter %.o,$^)
diff --git a/plugins/echoback/echoback.c b/plugins/echoback/echoback.c
new file mode 100644
index 0000000..af94cbf
--- /dev/null
+++ b/plugins/echoback/echoback.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include "plugin.h"
+#include "util.h"
+
+
+static Handler_ret_t connection_handler(int sock,Headers *headers){
+ sendall(sock,"HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/plain; charset=UTF-8\r\n"
+ "Server: cserver\r\n"
+ "\r\n",-1);
+
+ sendallf(sock,"Method: %s\n",headers->method);
+ sendallf(sock,"URL: %s\n",headers->url);
+ sendallf(sock,"Version: %s\n",headers->version);
+ sendall(sock,"\n",1);
+ for(int i=0;i<headers->nheaders;i++){
+ sendallf(sock,"Header '%s': '%s'\n",headers->headers[i][0],headers->headers[i][1]);
+ }
+
+ return HR_HANDLED;
+}
+
+void plugin_register_yourself(register_callback_t callback){
+ callback("echoback",&connection_handler);
+}