pmd: autobahn fixes
[platform/upstream/libwebsockets.git] / lib / extension.c
index 990f586..ac28204 100644 (file)
@@ -6,7 +6,6 @@ LWS_VISIBLE void
 lws_context_init_extensions(struct lws_context_creation_info *info,
                            struct lws_context *context)
 {
-       context->extensions = info->extensions;
        lwsl_info(" LWS_MAX_EXTENSIONS_ACTIVE: %u\n", LWS_MAX_EXTENSIONS_ACTIVE);
 }
 
@@ -28,6 +27,8 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
                     pending_close_quote = 0;
        struct lws_ext_option_arg oa;
 
+       oa.option_name = NULL;
+
        while (opts[count_options].name)
                count_options++;
        while (len) {
@@ -61,7 +62,7 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
                                                        oa.option_index = n;
                                                        lwsl_ext("hit %d\n", oa.option_index);
                                                        leap = LEAPS_SEEK_VAL;
-                                                       if (len ==1)
+                                                       if (len == 1)
                                                                goto set_arg;
                                                        break;
                                                }
@@ -171,6 +172,9 @@ int lws_ext_cb_active(struct lws *wsi, int reason, void *arg, int len)
                                 wsi->active_extensions[n]->name, reason);
                        return -1;
                }
+               /* valgrind... */
+               if (reason == LWS_EXT_CB_DESTROY)
+                       wsi->act_ext_user[n] = NULL;
                if (m > handled)
                        handled = m;
        }
@@ -182,11 +186,16 @@ int lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi,
                        int reason, void *arg, int len)
 {
        int n = 0, m, handled = 0;
-       const struct lws_extension *ext = context->extensions;
+       const struct lws_extension *ext;
+
+       if (!wsi || !wsi->vhost)
+               return 0;
+
+       ext = wsi->vhost->extensions;
 
        while (ext && ext->callback && !handled) {
                m = ext->callback(context, ext, wsi, reason,
-                                 (void *)(long)n, arg, len);
+                                 (void *)(lws_intptr_t)n, arg, len);
                if (m < 0) {
                        lwsl_ext("Ext '%s' failed to handle callback %d!\n",
                                 wsi->active_extensions[n]->name, reason);
@@ -308,3 +317,28 @@ lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r
 
        return handled;
 }
+
+int
+lws_set_extension_option(struct lws *wsi, const char *ext_name,
+                        const char *opt_name, const char *opt_val)
+{
+       struct lws_ext_option_arg oa;
+       int idx = 0;
+
+       /* first identify if the ext is active on this wsi */
+       while (idx < wsi->count_act_ext &&
+              strcmp(wsi->active_extensions[idx]->name, ext_name))
+               idx++;
+
+       if (idx == wsi->count_act_ext)
+               return -1; /* request ext not active on this wsi */
+
+       oa.option_name = opt_name;
+       oa.option_index = 0;
+       oa.start = opt_val;
+       oa.len = 0;
+
+       return wsi->active_extensions[idx]->callback(
+                       wsi->context, wsi->active_extensions[idx], wsi,
+                       LWS_EXT_CB_NAMED_OPTION_SET, wsi->act_ext_user[idx], &oa, 0);
+}