/**
Onion HTTP server library
Copyright (C) 2010-2018 David Moreno Montero and others
This library is free software; you can redistribute it and/or
modify it under the terms of, at your choice:
a. the Apache License Version 2.0.
b. the GNU General Public License as published by the
Free Software Foundation; either version 2.0 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of both licenses, if not see
and
.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
onion *o = NULL;
int onion_run = 1;
#define MAX_ACTIVE_CLIENTS 2
enum onion_websocket_status_e {
NORMAL_CLOSURE = 1000,
GOING_AWAY = 1001,
PROTOCOL_ERROR = 1002,
UNSUPPORTED_DATA = 1003,
// RESERVED = 1004,
NO_STATUS_RECEIVED = 1005,
ABNORMAL_CLOSURE = 1006,
INVALID_FRAME_PAYLOAD_DATA = 1007,
POLICY_VIOLATION = 1008,
MESSAGE_TOO_BIG = 1009,
MISSING_EXTENSION = 1010,
INTERNAL_ERROR = 1011,
SERVICE_RESTART = 1012,
TRY_AGAIN_LATER = 1013,
BAD_GATEWAY = 1014,
TLS_HANDSHAKE = 1015,
};
// convert into char[2] e.g.: STATUS(sname, NORMAL_CLOSURE)
#define STATUS_STR(NAME, NUM) char NAME[2] \
= {((NUM>>8)&0xFF) , ((NUM)&0xFF)};
onion_websocket *ws_active[MAX_ACTIVE_CLIENTS] = { 0 };
pthread_mutex_t ws_lock[MAX_ACTIVE_CLIENTS];
void onion_end_signal(int unused) {
if( o ){
onion_run = 0;
ONION_INFO("Closing connections");
int i;
for( i=0; i