extensions introduce pre close veto

This establishes a pre-close extension check to allow an extension to
veto a close.  x-google-mux then uses this to stop ch1 going down
(subchannel 1 is the original socket connection that turns into a mux
parent) if it has active mux children; it just marks ch1 as closed in
its conn struct in that case and returns 1 from the callback to veto.

Code is also added to take care of the case ch1 is 'closed', and the
last child is subsequently closed, it actively calls close on the mux
parent then.

Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index 0a448d9..0021eb4 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -166,6 +166,35 @@
 	wsi->close_reason = reason;
 
 	/*
+	 * are his extensions okay with him closing?  Eg he might be a mux
+	 * parent and just his ch1 aspect is closing?
+	 */
+
+
+	for (n = 0; n < wsi->count_active_extensions; n++) {
+		if (!wsi->active_extensions[n]->callback)
+			continue;
+
+		m = wsi->active_extensions[n]->callback(context,
+			wsi->active_extensions[n], wsi,
+			LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE,
+				       wsi->active_extensions_user[n], NULL, 0);
+
+		/*
+		 * if somebody vetoed actually closing him at this time....
+		 * up to the extension to track the attempted close, let's
+		 * just bail
+		 */
+
+		if (m) {
+			fprintf(stderr, "extension vetoed close\n");
+			return;
+		}
+	}
+
+
+
+	/*
 	 * flush any tx pending from extensions, since we may send close packet
 	 * if there are problems with send, just nuke the connection
 	 */
@@ -2145,6 +2174,9 @@
 {
 	int n = 0;
 
+	if (wsi == NULL)
+		return NULL;
+
 	while (n < wsi->count_active_extensions) {
 		if (wsi->active_extensions[n] != ext) {
 			n++;