pass ext pointer in ext callback
authorAndy Green <andy@warmcat.com>
Tue, 22 Mar 2011 09:04:01 +0000 (09:04 +0000)
committerAndy Green <andy@warmcat.com>
Tue, 22 Mar 2011 09:04:01 +0000 (09:04 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/extension-deflate-stream.c
lib/extension-deflate-stream.h
lib/handshake.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/parsers.c
lib/private-libwebsockets.h
libwebsockets-api-doc.html

index 7ea7c04..9b7b192 100644 (file)
@@ -7,7 +7,9 @@
 
 
 int lws_extension_callback_deflate_stream(
-       struct libwebsocket_context *context, struct libwebsocket *wsi,
+               struct libwebsocket_context *context,
+               struct libwebsocket_extension *ext,
+               struct libwebsocket *wsi,
                        enum libwebsocket_extension_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
index ff43b47..a8187bc 100644 (file)
@@ -11,7 +11,8 @@ struct lws_ext_deflate_stream_conn {
 };
 
 extern int lws_extension_callback_deflate_stream(
-       struct libwebsocket_context *context,
-                       struct libwebsocket *wsi,
-                       enum libwebsocket_extension_callback_reasons reason,
+               struct libwebsocket_context *context,
+               struct libwebsocket_extension *ext,
+               struct libwebsocket *wsi,
+               enum libwebsocket_extension_callback_reasons reason,
                                              void *user, void *in, size_t len);
index e89bd01..bac5f7f 100644 (file)
@@ -435,7 +435,8 @@ handshake_0405(struct libwebsocket *wsi)
                                /* allow him to construct his context */
 
                                ext->callback(wsi->protocol->owning_server,
-                                               wsi, LWS_EXT_CALLBACK_CONSTRUCT,
+                                               ext, wsi,
+                                               LWS_EXT_CALLBACK_CONSTRUCT,
                                                wsi->active_extensions_user[
                                        wsi->count_active_extensions], NULL, 0);
 
index 717f6c0..6a0ef37 100644 (file)
@@ -182,7 +182,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
 
                for (n = 0; n < wsi->count_active_extensions; n++) {
                        m = wsi->active_extensions[n]->callback(
-                               wsi->protocol->owning_server, wsi,
+                                       wsi->protocol->owning_server,
+                                       wsi->active_extensions[n], wsi,
                                        LWS_EXT_CALLBACK_FLUSH_PENDING_TX,
                                   wsi->active_extensions_user[n], &eff_buf, 0);
                        if (m < 0) {
@@ -285,9 +286,10 @@ just_kill_connection:
                if (!wsi->active_extensions[n]->callback)
                        continue;
 
-               wsi->active_extensions[n]->callback(context, wsi,
-                       LWS_EXT_CALLBACK_DESTROY,
-                       wsi->active_extensions_user[n], NULL, 0);
+               wsi->active_extensions[n]->callback(context,
+                       wsi->active_extensions[n], wsi,
+                               LWS_EXT_CALLBACK_DESTROY,
+                                      wsi->active_extensions_user[n], NULL, 0);
 
                free(wsi->active_extensions_user[n]);
        }
@@ -539,7 +541,8 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
 
                for (n = 0; n < wsi->count_active_extensions; n++) {
                        m = wsi->active_extensions[n]->callback(
-                               wsi->protocol->owning_server, wsi,
+                               wsi->protocol->owning_server,
+                               wsi->active_extensions[n], wsi,
                                        LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
                                   wsi->active_extensions_user[n], &eff_buf, 0);
                        if (m < 0) {
@@ -1586,9 +1589,11 @@ select_protocol:
                                /* allow him to construct his context */
 
                                ext->callback(wsi->protocol->owning_server,
-                                       wsi, LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
+                                       ext, wsi,
+                                          LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
                                                wsi->active_extensions_user[
-                                       wsi->count_active_extensions], NULL, 0);
+                                                wsi->count_active_extensions],
+                                                                      NULL, 0);
 
                                wsi->count_active_extensions++;
 
@@ -1764,9 +1769,11 @@ bail2:
                        more = 0;
 
                        for (n = 0; n < wsi->count_active_extensions; n++) {
-                               m = wsi->active_extensions[n]->callback(context, wsi,
+                               m = wsi->active_extensions[n]->callback(context,
+                                       wsi->active_extensions[n], wsi,
                                        LWS_EXT_CALLBACK_PACKET_RX_PREPARSE,
-                                    wsi->active_extensions_user[n], &eff_buf, 0);
+                                       wsi->active_extensions_user[n],
+                                                                  &eff_buf, 0);
                                if (m < 0) {
                                        fprintf(stderr, "Extension reports fatal error\n");
                                        libwebsocket_close_and_free_session(context, wsi,
index bb3444f..c247c3a 100644 (file)
@@ -192,6 +192,7 @@ enum lws_close_status {
 
 struct libwebsocket;
 struct libwebsocket_context;
+struct libwebsocket_extension;
 
 /* document the generic callback (it's a fake prototype under this) */
 /**
@@ -394,6 +395,7 @@ extern int callback(struct libwebsocket_context * context,
 /**
  * extension_callback() - Hooks to allow extensions to operate
  * @context:   Websockets context
+ * @ext:       This extension
  * @wsi:       Opaque websocket instance pointer
  * @reason:    The reason for the call
  * @user:      Pointer to per-session user data allocated by library
@@ -450,6 +452,7 @@ extern int callback(struct libwebsocket_context * context,
  */
 
 extern int extension_callback(struct libwebsocket_context * context,
+                       struct libwebsocket_extension *ext,
                        struct libwebsocket *wsi,
                         enum libwebsocket_callback_reasons reason, void *user,
                                                          void *in, size_t len);
@@ -515,6 +518,7 @@ struct libwebsocket_protocols {
 struct libwebsocket_extension {
        const char *name;
        int (*callback)(struct libwebsocket_context *context,
+                       struct libwebsocket_extension *ext,
                        struct libwebsocket *wsi,
                        enum libwebsocket_extension_callback_reasons reason,
                                              void *user, void *in, size_t len);
index 5b7a3bd..7e1e900 100644 (file)
@@ -1379,7 +1379,8 @@ send_raw:
 
                for (n = 0; n < wsi->count_active_extensions; n++) {
                        m = wsi->active_extensions[n]->callback(
-                               wsi->protocol->owning_server, wsi,
+                                       wsi->protocol->owning_server,
+                                       wsi->active_extensions[n], wsi,
                                        LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
                                   wsi->active_extensions_user[n], &eff_buf, 0);
                        if (m < 0) {
index 2a11c11..edaeaa9 100644 (file)
@@ -228,7 +228,7 @@ enum pending_timeout {
 
 struct libwebsocket {
        const struct libwebsocket_protocols *protocol;
-       const struct libwebsocket_extension *
+       struct libwebsocket_extension *
                                   active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
        void * active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
        int count_active_extensions;
index 80e8504..bc0ce48 100644 (file)
@@ -728,6 +728,7 @@ internal polling loop, you can just ignore it.
 <i>int</i>
 <b>extension_callback</b>
 (<i>struct libwebsocket_context *</i> <b>context</b>,
+<i>struct libwebsocket_extension *</i> <b>ext</b>,
 <i>struct libwebsocket *</i> <b>wsi</b>,
 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
 <i>void *</i> <b>user</b>,
@@ -737,6 +738,8 @@ internal polling loop, you can just ignore it.
 <dl>
 <dt><b>context</b>
 <dd>Websockets context
+<dt><b>ext</b>
+<dd>This extension
 <dt><b>wsi</b>
 <dd>Opaque websocket instance pointer
 <dt><b>reason</b>
@@ -858,7 +861,7 @@ allows as many protocols as you like to be handled by one server.
 <h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
 <b>struct libwebsocket_extension</b> {<br>
 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
-&nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_extension_callback_reasons reason,void *user, void *in, size_t len)</i>;<br>
+&nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context *context,struct libwebsocket_extension *ext,struct libwebsocket *wsi,enum libwebsocket_extension_callback_reasons reason,void *user, void *in, size_t len)</i>;<br>
 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
 };<br>
 <h3>Members</h3>