From: Andy Green Date: Tue, 22 Mar 2011 09:04:01 +0000 (+0000) Subject: pass ext pointer in ext callback X-Git-Tag: 1.2~110 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46c2ea0d6fe1ff408470e7c2da0e8bb5a631d0a4;p=profile%2Fivi%2Flibwebsockets.git pass ext pointer in ext callback Signed-off-by: Andy Green --- diff --git a/lib/extension-deflate-stream.c b/lib/extension-deflate-stream.c index 7ea7c04..9b7b192 100644 --- a/lib/extension-deflate-stream.c +++ b/lib/extension-deflate-stream.c @@ -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) { diff --git a/lib/extension-deflate-stream.h b/lib/extension-deflate-stream.h index ff43b47..a8187bc 100644 --- a/lib/extension-deflate-stream.h +++ b/lib/extension-deflate-stream.h @@ -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); diff --git a/lib/handshake.c b/lib/handshake.c index e89bd01..bac5f7f 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -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); diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 717f6c0..6a0ef37 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -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, diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index bb3444f..c247c3a 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -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); diff --git a/lib/parsers.c b/lib/parsers.c index 5b7a3bd..7e1e900 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -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) { diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 2a11c11..edaeaa9 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -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; diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index 80e8504..bc0ce48 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -728,6 +728,7 @@ internal polling loop, you can just ignore it. int extension_callback (struct libwebsocket_context * context, +struct libwebsocket_extension * ext, struct libwebsocket * wsi, enum libwebsocket_callback_reasons reason, void * user, @@ -737,6 +738,8 @@ internal polling loop, you can just ignore it.
context
Websockets context +
ext +
This extension
wsi
Opaque websocket instance pointer
reason @@ -858,7 +861,7 @@ allows as many protocols as you like to be handled by one server.

struct libwebsocket_extension - An extension we know how to cope with

struct libwebsocket_extension {
    const char * name;
-    int (*callback) (struct libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_extension_callback_reasons reason,void *user, void *in, size_t len);
+    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);
    size_t per_session_data_size;
};

Members