"interface" : "eth1",
"ssl" : "false",
"port" : "23000",
- "binaryProtocol" : "true"
+ "binaryProtocol" : "true",
+ "useExtensions" : "true"
}
]
}
"port" : "23000",
"ssl" : "false",
"ip" : "192.168.1.40",
- "binaryProtocol" : "true"
+ "binaryProtocol" : "true",
+ "useExtensions" : "true"
}
],
"sinks": [
--- /dev/null
+websocket plugins
+
+The websocket sink and source plugins are designed to relay data between devices and
+potentially to web pages.
+
+To enable the websocket plugins, run cmake and enable the websocket_plugin option:
+
+cmake -Dwebsocket_plugin=On ..
+
+
+To use the websocket sink plugin, add the following to the "sinks" array in /etc/ambd/config:
+
+{
+ "name" : "websocket sink",
+ "path" : "/usr/lib/automotive-message-broker/websocketsink.so",
+ "interface" : "lo",
+ "useExtensions" : "true",
+ "binaryProtocol" : "false",
+ "ssl" : "false".
+ "cert" : "libwebsockets-test-server.pem",
+ "key" : "libwebsockets-test-server.key.pem"
+}
+
+To use the websocket source plugin, add the following to the "sources" array in /etc/ambd/config:
+
+{
+ "name" : "WebsocketSource",
+ "path" : "/usr/lib/automotive-message-broker/websocketsource.so",
+ "port" : "23000",
+ "ssl" : "false",
+ "ip" : "192.168.1.40",
+ "binaryProtocol" : "true",
+ "useExtensions" : "true"
+}
+
+Configuration Key Definitions:
+
+"name"
+name of plugin. This key is not used by the plugin at this moment.
+
+"path"
+path to plugin on the filesystem.
+
+"interface" (sink only)
+interface device. Usually "lo" for loopback or "eth0".
+
+default: lo
+
+"useExtensions"
+Use built in libwebsocket extensions like zlib compression of frames
+
+default: false
+
+"binaryProtocol"
+Use fast and efficient binary protocol instead of JSON.
+
+default: false
+
+"ssl"
+Use ssl secure socket
+
+default: false
+
+"cert" (sink only)
+
+path to ssl certificate
+
+"key" (sink only)
+
+path to ssl key
+
#include "common.h"
+bool doBinary = false;
+int lwsWrite(libwebsocket *lws, QByteArray d, int len)
+{
+
+ int retval = -1;
+
+ QByteArray temp = d;
+
+ int numframes = 1;
+ int framesize = 122;
+
+ if(d.length() > framesize)
+ {
+ numframes = qCeil((double)d.length() / 122.0);
+ QVariantMap multiFrameMessage;
+ multiFrameMessage["type"] = "multiframe";
+ multiFrameMessage["frames"] = numframes;
+
+ QByteArray msg;
+
+ if(doBinary)
+ msg = QJsonDocument::fromVariant(multiFrameMessage).toBinaryData();
+ else
+ {
+ msg = QJsonDocument::fromVariant(multiFrameMessage).toJson();
+ cleanJson(msg);
+ }
+
+ lwsWrite(lws, msg, msg.length());
+ }
+
+ while(numframes--)
+ {
+ int range = 0;
+ if(temp.length() > framesize)
+ range = framesize;
+ else range = temp.length();
+
+ QByteArray toWrite = temp.mid(0,range);
+ const char* strToWrite = toWrite.data();
+
+ temp = temp.mid(range);
+
+ if(doBinary)
+ {
+ retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_BINARY);
+ }
+ else
+ {
+ std::unique_ptr<char[]> buffer(new char[LWS_SEND_BUFFER_PRE_PADDING + len + LWS_SEND_BUFFER_POST_PADDING]);
+ char *buf = buffer.get() + LWS_SEND_BUFFER_PRE_PADDING;
+ memcpy(buf, strToWrite, toWrite.length());
+
+ retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_TEXT);
+ }
+ }
+ return retval;
+
+}
+
+
+void cleanJson(QByteArray &json)
+{
+ json.replace(" ", "");
+ json.replace("\n", "");
+ json.replace("\t", "");
+}
#include <QJsonDocument>
#include <memory>
-static bool doBinary = false;
+extern bool doBinary;
-static void cleanJson(QByteArray &json)
-{
- json.replace(" ", "");
- json.replace("\n", "");
- json.replace("\t", "");
-}
+void cleanJson(QByteArray &json);
// libwebsocket_write helper function
-static int lwsWrite(struct libwebsocket *lws, QByteArray d, int len)
-{
- int retval = -1;
-
- QByteArray temp = d;
-
- int numframes = 1;
- int framesize = 122;
-
- if(d.length() > framesize)
- {
- numframes = qCeil((double)d.length() / 122.0);
- QVariantMap multiFrameMessage;
- multiFrameMessage["type"] = "multiframe";
- multiFrameMessage["frames"] = numframes;
-
- QByteArray msg;
-
- if(doBinary)
- msg = QJsonDocument::fromVariant(multiFrameMessage).toBinaryData();
- else
- {
- msg = QJsonDocument::fromVariant(multiFrameMessage).toJson();
- cleanJson(msg);
- }
-
- lwsWrite(lws, msg, msg.length());
- }
-
- while(numframes--)
- {
- int range = 0;
- if(temp.length() > framesize)
- range = framesize;
- else range = temp.length();
-
- QByteArray toWrite = temp.mid(0,range);
- const char* strToWrite = toWrite.data();
-
- temp = temp.mid(range);
-
- if(doBinary)
- {
- retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_BINARY);
- }
- else
- {
- std::unique_ptr<char[]> buffer(new char[LWS_SEND_BUFFER_PRE_PADDING + len + LWS_SEND_BUFFER_POST_PADDING]);
- char *buf = buffer.get() + LWS_SEND_BUFFER_PRE_PADDING;
- memcpy(buf, strToWrite, toWrite.length());
-
- retval = libwebsocket_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_TEXT);
- }
- }
- return retval;
-}
+int lwsWrite(struct libwebsocket *lws, QByteArray d, int len);
#endif
#include <QJsonDocument>
#include <QVariantMap>
-WebSocketSink::WebSocketSink(AbstractRoutingEngine* re, libwebsocket *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty, bool dB) : AbstractSink(re,map<string, string> ())
+WebSocketSink::WebSocketSink(AbstractRoutingEngine* re, libwebsocket *wsi, string uuid, VehicleProperty::Property property, std::string ambdproperty) : AbstractSink(re,map<string, string> ())
{
- doBinary = dB;
m_amdbproperty = ambdproperty;
m_uuid = uuid;
m_wsi = wsi;
{
public:
- WebSocketSink(AbstractRoutingEngine* re,libwebsocket *wsi,string uuid,VehicleProperty::Property property,std::string ambdproperty, bool dB);
+ WebSocketSink(AbstractRoutingEngine* re,libwebsocket *wsi,string uuid,VehicleProperty::Property property,std::string ambdproperty);
~WebSocketSink();
const string uuid() ;
void propertyChanged(AbstractPropertyType *value);
std::string ssl_key_path;
int options = 0;
bool ssl = false;
+ info.extensions = nullptr;
+
//Try to load config
for (map<string,string>::iterator i=configuration.begin();i!=configuration.end();i++)
{
ssl = false;
}
}
+ if ((*i).first == "useExtensions")
+ {
+ {
+ if((*i).second == "true")
+ {
+ info.extensions = libwebsocket_get_internal_extensions();
+ }
+ else info.extensions = nullptr;
+ }
+ }
}
info.iface = interface.c_str();
info.protocols = protocollist;
- info.extensions = nullptr;
- //info.extensions = libwebsocket_get_internal_extensions();
info.gid = -1;
info.uid = -1;
info.options = options;
lwsWrite(socket, replystr, replystr.length());
- WebSocketSink *sink = new WebSocketSink(m_engine,socket,uuid,property,property, doBinary);
+ WebSocketSink *sink = new WebSocketSink(m_engine,socket,uuid,property,property);
m_sinkMap[property].push_back(sink);
}
extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
memset(&info, 0, sizeof info);
info.protocols = protocols;
info.extensions = nullptr;
- //info.extensions = libwebsocket_get_internal_extensions();
+
+ if(config.find("useExtensions") != config.end() && config["useExtensions"] == "true")
+ {
+ info.extensions = libwebsocket_get_internal_extensions();
+ }
+
info.gid = -1;
info.uid = -1;
info.port = CONTEXT_PORT_NO_LISTEN;
info.user = this;
- //std::string ssl_key_path = "/home/michael/.ssh/id_rsa";
- //info.ssl_ca_filepath = ssl_key_path.c_str();
-
+
context = libwebsocket_create_context(&info);
- //context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,protocols, libwebsocket_internal_extensions,NULL, NULL, -1, -1, 0);
setConfiguration(config);
re->setSupported(supported(), this);