[Libwebsockets] need help - lwsws && external plugin

Andy Green andy at warmcat.com
Thu Jan 19 03:07:10 CET 2017



On 01/19/2017 09:44 AM, Joel Winarske wrote:
>
> Hi folks,
>
>
> I'm unclear on how to setup an external plugin.  I have my lwsws 
> config setup as:
>
>
>     "mounts": [{
>       "mountpoint": "/",
>       "origin": "file:///var/www/paper.local",
>       "default": "index.html"
>       }, {
>        "mountpoint": "/prop",
>        "origin": "callback://property-api"
>     }]
>
>
> The server startup:
> lwsws[16680]:   Plugins:
> lwsws[16680]:   Scanning 
> /usr/local/share/libwebsockets-test-server/plugins/
> lwsws[16680]:    libprotocol_example_standalone.so
> lwsws[16680]:  Compiled with OpenSSL support
> lwsws[16680]:  mem: per-conn:          768 bytes + protocol rx buf
> lwsws[16680]:  canonical_hostname = paper
> lwsws[16680]:  Using foreign event loop...
> lwsws[16680]: ----file:///var/www/paper.local
> lwsws[16680]: ----callback://property-api
> lwsws[16680]: Creating Vhost 'paper.local' port 41795, 1 protocols, 
> IPv6 off
> lwsws[16680]:    mounting file:///var/www/paper.local to /
> lwsws[16680]:    mounting callback://property-api to /prop
>
>
> When I send client request:
> curl -k 
> "http://paper.local:41795/prop/get?format=json&key=xyz&dataID=Y0NoMPgXlXDR3tXIL7dODR"
>
> I get:
> lwsws[16680]: Unable to find plugin 'property-api'
> lwsws[16680]: 172.16.19.75 - - [18/Jan/2017:17:23:30 -0800] "GET 
> /prop/get http/1.1" 0 0 Mozilla/5.0 (X11; Linux x86_64) 
> AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/55.0.2883.87 
> Chrome/55.0.2883.87 Safari/537.36
>
> In my plugin the protocols struct is set as:
> static const struct lws_protocols protocols[] = {
> {
> "property-api",
> callback_property,
> sizeof(struct per_session_data__dumb_increment),
> 10, /* rx buf size must be >= permessage-deflate rx size */
> },
> };
>
> My goal is to handle this portion of the 
> request "get?format=json&key=xyz&dataID=Y0NoMPgXlXDR3tXIL7dODR".
>
> What am I missing?
>
You did everything right... just one thing: protocols are not 
automatically enabled for operation on a vhost.

You have to explicitly list them in the vhost config as being allowed.

      "ws-protocols": [{
        "dumb-increment-protocol": {
          "status": "ok"
        },
       ...

It's for the case you have many vhosts, but some protocols must not be 
accessible except on suitably secured vhosts (eg, SSL set up). Otherwise 
all vhosts would respond to requests to talk using any ws protocol on 
the server.

-Andy

>
>
> Thanks!
> Joel
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20170119/f693e36e/attachment-0002.html>


More information about the Libwebsockets mailing list