2016-12-13 16:34:03 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "../plugin.h"
|
|
|
|
|
|
|
|
void pexit()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void handler(int cl, const char* m, const char* rqp, dictionary rq)
|
|
|
|
{
|
|
|
|
char* path = NULL;
|
|
|
|
int nimg = 19;
|
|
|
|
ws_msg_header_t* h = NULL;
|
2017-06-05 19:09:59 +02:00
|
|
|
char buff[1024];
|
2016-12-13 16:34:03 +01:00
|
|
|
if(ws_enable(rq))
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
h = ws_read_header(cl);
|
|
|
|
if(h)
|
|
|
|
{
|
2017-06-05 19:09:59 +02:00
|
|
|
if(h->mask == 0)
|
|
|
|
{
|
|
|
|
LOG("%s\n","data is not masked");
|
|
|
|
ws_close(cl, 1012);
|
|
|
|
break;
|
|
|
|
}
|
2016-12-13 16:34:03 +01:00
|
|
|
if(h->opcode == WS_CLOSE)
|
|
|
|
{
|
|
|
|
LOG("%s\n","Websocket: connection closed");
|
|
|
|
ws_close(cl, 1011);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-05 19:09:59 +02:00
|
|
|
else if(h->opcode == WS_TEXT)
|
2016-12-13 16:34:03 +01:00
|
|
|
{
|
|
|
|
int l;
|
|
|
|
if((l = ws_read_data(cl,h,sizeof(buff),buff)) > 0)
|
|
|
|
{
|
|
|
|
|
2017-06-05 19:09:59 +02:00
|
|
|
//path = __s("%s/ws/img%d.jpg",__plugin__.htdocs,buff[0]);
|
|
|
|
LOG("%s : %s\n", "send back data of", buff);
|
|
|
|
//ws_f(cl,path);
|
|
|
|
ws_t(cl,buff);
|
2016-12-13 16:34:03 +01:00
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG("%s\n","Invalid request");
|
|
|
|
ws_close(cl, 1011);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG("%s\n", "EXIT Streaming..");
|
|
|
|
}
|