22// Util.h
33// ofxLibwebsockets
44//
5+ // This class is primarily the static callbacks needed by libwebsockets
6+ //
57// Created by Brett Renfer on 4/11/12.
68// Copyright (c) 2012 Robotconscience. All rights reserved.
79//
@@ -33,7 +35,7 @@ namespace ofxLibwebsockets {
3335
3436 Reactor* reactor = NULL ;
3537 Protocol* protocol;
36-
38+
3739 for (int i=0 ; i<(int )reactors.size (); i++){
3840 if (reactors[i]->getContext () == context){
3941 reactor = reactors[i];
@@ -47,7 +49,7 @@ namespace ofxLibwebsockets {
4749 }
4850 }
4951
50- ofLog ( OF_LOG_VERBOSE, getCallbackReason (reason) );
52+ ofLog ( OF_LOG_VERBOSE, " [ofxLibwebsockets] " + getCallbackReason (reason) );
5153
5254 if (reason == LWS_CALLBACK_CLIENT_ESTABLISHED ){
5355 libwebsocket_callback_on_writable (context, ws);
@@ -56,26 +58,38 @@ namespace ofxLibwebsockets {
5658
5759 switch (reason)
5860 {
61+ // cases we may use in the future
5962 case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY:
6063 case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:
61- case LWS_CALLBACK_PROTOCOL_INIT:
64+ case LWS_CALLBACK_PROTOCOL_INIT: // this may be useful, says we're OK to allocate protocol data
6265 case LWS_CALLBACK_WSI_CREATE:
66+
67+ case LWS_CALLBACK_HTTP_BODY_COMPLETION:
68+ case LWS_CALLBACK_HTTP_FILE_COMPLETION:
69+ case LWS_CALLBACK_HTTP_WRITEABLE:
70+
71+ case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
6372 return 0 ;
6473
74+ // check if we allow this connection (default is always yes)
75+ case LWS_CALLBACK_FILTER_HTTP_CONNECTION:
6576 case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
6677 if (protocol != NULL ){
6778 return reactor->_allow (ws, protocol, (int )(long )user)? 0 : 1 ;
6879 } else {
6980 return 0 ;
7081 }
82+
83+ // need to serve up an HTTP file
7184 case LWS_CALLBACK_HTTP:
7285 if ( reactor != NULL ){
7386 return reactor->_http (ws, (char *)data);
7487 } else {
7588 return 0 ;
7689 }
7790
78- // we're not really worried about this at the moment
91+ // we're not really worried about these at the moment
92+ case LWS_CALLBACK_CLOSED_HTTP:
7993 case LWS_CALLBACK_ADD_POLL_FD:
8094 case LWS_CALLBACK_DEL_POLL_FD:
8195 case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
@@ -86,6 +100,13 @@ namespace ofxLibwebsockets {
86100 case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
87101 return 1 ;
88102
103+ // catch-all for most important events:
104+ // LWS_CALLBACK_CLIENT_CONNECTION_ERROR
105+ // LWS_CALLBACK_CLIENT_ESTABLISHED
106+ // LWS_CALLBACK_RECEIVE
107+ // LWS_CALLBACK_CLIENT_RECEIVE
108+ // LWS_CALLBACK_CLIENT_RECEIVE_PONG
109+ // LWS_CALLBACK_CLIENT_WRITEABLE
89110 default :
90111 if ( reactor != NULL ){
91112 // conn = *(Connection**)user;
@@ -129,8 +150,9 @@ namespace ofxLibwebsockets {
129150 }
130151 }
131152
132- ofLog ( OF_LOG_VERBOSE, getCallbackReason (reason) );
153+ ofLog ( OF_LOG_VERBOSE, " [ofxLibwebsockets] " + getCallbackReason (reason) );
133154
155+ // server completed handshake, need to ask for next "writable" callback
134156 if (reason == LWS_CALLBACK_ESTABLISHED){
135157 libwebsocket_callback_on_writable (context, ws);
136158
0 commit comments