Skip to content

Commit

Permalink
Merge pull request #163 from smartdevicelink/release/5.1.0
Browse files Browse the repository at this point in the history
Release/5.1.0
  • Loading branch information
jacobkeeler authored Apr 17, 2019
2 parents c69fa29 + 0155505 commit 6e52740
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 45 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
path = modules/json4lua
url = https://github.com/CustomSDL/json4lua
branch = master
[submodule "modules/luamq"]
path = modules/luamq
url = https://github.com/dboltovskyi/luamq
branch = master
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SOURCES= src/lua_interpreter.cc \
src/qdatetime.cc \
src/timers.cc

all: interp modules/libxml.so modules/libmq.so modules/libluaopenssl.so
all: interp modules/libxml.so modules/libluaopenssl.so

interp: $(PROJECT).mk $(SOURCES)
make -f $<
Expand All @@ -23,11 +23,6 @@ interp: $(PROJECT).mk $(SOURCES)
modules/libxml.so: src/lua_xml.cc
$(CXX) $(CXXFLAGS) -shared -std=c++11 $< -o modules/libxml.so -g -I/usr/include/libxml2 -llua5.2 -lxml2 -fPIC

modules/libmq.so:
cd ./modules/luamq/; make
cp -f ./modules/luamq/src/mq.so ./modules/libmq.so
rm -f ./modules/luamq/src/mq.so ./modules/luamq/src/lua-mq.o

modules/libluaopenssl.so: src/lua_openssl.cc
$(CXX) $(CXXFLAGS) -shared -std=c++11 $< -o modules/libluaopenssl.so -g -I/usr/include/openssl -llua5.2 -lssl -lcrypto -fPIC

Expand Down
10 changes: 5 additions & 5 deletions modules/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ config.application1 =
syncMsgVersion =
{
majorVersion = 5,
minorVersion = 0
minorVersion = 1
},
appName = "Test Application",
isMediaApplication = true,
Expand Down Expand Up @@ -115,7 +115,7 @@ config.application2 =
syncMsgVersion =
{
majorVersion = 5,
minorVersion = 0
minorVersion = 1
},
appName = "Test Application2",
isMediaApplication = true,
Expand Down Expand Up @@ -143,7 +143,7 @@ config.application3 =
syncMsgVersion =
{
majorVersion = 5,
minorVersion = 0
minorVersion = 1
},
appName = "Test Application3",
isMediaApplication = true,
Expand Down Expand Up @@ -171,7 +171,7 @@ config.application4 =
syncMsgVersion =
{
majorVersion = 5,
minorVersion = 0
minorVersion = 1
},
appName = "Test Application4",
isMediaApplication = true,
Expand Down Expand Up @@ -199,7 +199,7 @@ config.application5 =
syncMsgVersion =
{
majorVersion = 5,
minorVersion = 0
minorVersion = 1
},
appName = "Test Application5",
isMediaApplication = true,
Expand Down
7 changes: 6 additions & 1 deletion modules/connecttest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ function Test:initHMI()
"BasicCommunication.PlayTone",
"BasicCommunication.OnSDLClose",
"SDL.OnSDLConsentNeeded",
"BasicCommunication.OnResumeAudioSource"
"BasicCommunication.OnResumeAudioSource",
"BasicCommunication.OnSystemCapabilityUpdated"
})
registerComponent("UI",
{
Expand All @@ -208,6 +209,10 @@ function Test:initHMI()
"Navigation.OnAudioDataStreaming",
"Navigation.OnVideoDataStreaming"
})
registerComponent("AppService",
{
"AppService.OnAppServiceData"
})
end)
self.hmiConnection:Connect()
end
Expand Down
1 change: 0 additions & 1 deletion modules/luamq
Submodule luamq deleted from 667058
12 changes: 4 additions & 8 deletions modules/message_dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ function MD.FileStream(filename, version, sessionId, service, encryption, bandwi

local frameSize = (constants.FRAME_SIZE["P" .. res.version]
- constants.PROTOCOL_HEADER_SIZE)

res.chunksize = (frameSize < bandwidth) and frameSize or (bandwidth - 1)
local chunkSize = (frameSize < bandwidth) and frameSize or (bandwidth)
local numberOfChunksPerSecond = 2
res.chunksize = math.floor(chunkSize / numberOfChunksPerSecond + 0.5) -- allow to send 2 chunks per 1 second
res.protocol_handler = ph.ProtocolHandler()
res.messageId = 1
res.rfd, errmsg = io.open(filename, "r")
Expand All @@ -123,13 +124,8 @@ end
-- @treturn number timeout Timeout for next message
function fstream_mt.__index:GetMessage()
local timespan = timestamp() - self.ts
if timespan > 5000 then
self.ts = self.ts + timespan - 1000
self.bytesSent = self.bytesSent / (timespan / 1000)
timespan = 1000
end
if (self.bytesSent + self.chunksize) / (timespan / 1000) > self.bandwidth then
return nil, 200
return nil, 250 -- timeout for next message
end
local res = nil
if self.keep then
Expand Down
51 changes: 51 additions & 0 deletions modules/mobile_session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ function mt.__index:ExpectPacket(frameMessage, binaryDataCompareFunc)
return self.mobile_session_impl:ExpectFrame(frameMessage, binaryDataCompareFunc)
end

--- Expectation of request
-- @tparam number funcName Expected request name
-- @tparam table ... Expectation parameters
-- @treturn Expectation Expectation for request
function mt.__index:ExpectRequest(funcName, ...)
return self.mobile_session_impl:ExpectRequest(funcName, ...)
end

--- Expectation of response with specific correlation_id
-- @tparam number cor_id Correlation identifier of specific rpc event
-- @tparam table ... Expectation parameters
Expand All @@ -55,6 +63,14 @@ function mt.__index:ExpectNotification(funcName, ...)
return self.mobile_session_impl:ExpectNotification(funcName, ...)
end

--- Expectation of encrypted request with specific funcName
-- @tparam number funcName Expected request name
-- @tparam table ... Expectation parameters
-- @treturn Expectation Expectation for response
function mt.__index:ExpectEncryptedRequest(funcName, ...)
return self.mobile_session_impl:ExpectEncryptedRequest(funcName, ...)
end

--- Expectation of encrypted response with specific correlation_id
-- @tparam number cor_id Correlation identifier of specific rpc event
-- @tparam table ... Expectation parameters
Expand Down Expand Up @@ -101,6 +117,23 @@ function mt.__index:SendRPC(func, arguments, fileName)
return self.mobile_session_impl:SendRPC(func, arguments, fileName)
end

--- Send RPC response
-- @tparam string func RPC name
-- @tparam string cor_id Correlation identifier
-- @tparam table arguments Arguments for RPC function
-- @tparam string fileName Path to file with binary data
function mt.__index:SendResponse(func, cor_id, arguments, fileName)
return self.mobile_session_impl:SendResponse(func, cor_id, arguments, fileName)
end

--- Send notification
-- @tparam string func RPC name
-- @tparam table arguments Arguments for RPC function
-- @tparam string fileName Path to file with binary data
function mt.__index:SendNotification(func, arguments, fileName)
return self.mobile_session_impl:SendNotification(func, arguments, fileName)
end

--- Send encrypted RPC
-- @tparam string func RPC name
-- @tparam table arguments Arguments for RPC function
Expand All @@ -109,6 +142,24 @@ function mt.__index:SendEncryptedRPC(func, arguments, fileName)
return self.mobile_session_impl:SendEncryptedRPC(func, arguments, fileName)
end

--- Send encrypted RPC response
-- @tparam string func RPC name
-- @tparam string cor_id Correlation identifier
-- @tparam table arguments Arguments for RPC function
-- @tparam string fileName Path to file with binary data
function mt.__index:SendEncryptedResponse(func, cor_id, arguments, fileName)
return self.mobile_session_impl:SendEncryptedResponse(func, cor_id, arguments, fileName)
end

--- Send encrypted notification
-- @tparam string func RPC name
-- @tparam table arguments Arguments for RPC function
-- @tparam string fileName Path to file with binary data
function mt.__index:SendEncryptedNotification(func, arguments, fileName)
return self.mobile_session_impl:SendEncryptedNotification(func, arguments, fileName)
end


---Start specific service
-- For service == 7 should be used StartRPC() instead of this function
-- @tparam number service Service type
Expand Down
64 changes: 64 additions & 0 deletions modules/mobile_session_impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function mt.__index:ExpectAny()
return self.mobile_expectations:ExpectAny()
end

--- Expectation of request
-- @tparam table ... Expectation parameters
-- @treturn Expectation Expectation for request
function mt.__index:ExpectRequest(funcName, ...)
return self.rpc_services:ExpectRequest(funcName, ...)
end

--- Expectation of response with specific correlation_id
-- @tparam number cor_id Correlation identifier of specific rpc event
-- @tparam table ... Expectation parameters
Expand All @@ -64,6 +71,19 @@ function mt.__index:ExpectNotification(funcName, ...)
return self.rpc_services:ExpectNotification(funcName, ...)
end

--- Expectation of encrypted request with specific funcName
-- @tparam number funcName Expected request name
-- @tparam table ... Expectation parameters
-- @treturn Expectation Expectation for response
function mt.__index:ExpectEncryptedRequest(funcName, ...)
if not (self.isSecuredSession and self.security:checkSecureService(constants.SERVICE_TYPE.RPC)) then
print("Error: Can not create expectation for encrypted response. "
.. "Secure service was not established. Session: " .. self.sessionId.get())
end

return self.rpc_services:ExpectEncryptedRequest(funcName, ...)
end

--- Expectation of encrypted response with specific correlation_id
-- @tparam number cor_id Correlation identifier of specific rpc event
-- @tparam table ... Expectation parameters
Expand Down Expand Up @@ -126,6 +146,23 @@ function mt.__index:SendRPC(func, arguments, fileName)
return self.rpc_services:SendRPC(func, arguments, fileName, securityConstants.ENCRYPTION.OFF)
end

--- Send RPC response
-- @tparam string func RPC name
-- @tparam string cor_id Correlation identifier
-- @tparam table arguments Arguments for RPC response
-- @tparam string fileName Path to file with binary data
function mt.__index:SendResponse(func, cor_id, arguments, fileName)
return self.rpc_services:SendResponse(func, cor_id, arguments, fileName, securityConstants.ENCRYPTION.OFF)
end

--- Send notification
-- @tparam string func notification name
-- @tparam table arguments Arguments for RPC notification
-- @tparam string fileName Path to file with binary data
function mt.__index:SendNotification(func, arguments, fileName)
return self.rpc_services:SendNotification(func, arguments, fileName, securityConstants.ENCRYPTION.OFF)
end

--- Send encrypted RPC
-- @tparam string func RPC name
-- @tparam table arguments Arguments for RPC function
Expand All @@ -139,6 +176,33 @@ function mt.__index:SendEncryptedRPC(func, arguments, fileName)
return -1
end

--- Send encrypted RPC response
-- @tparam string func RPC name
-- @tparam string cor_id Correlation identifier
-- @tparam table arguments Arguments for RPC response
-- @tparam string fileName Path to file with binary data
function mt.__index:SendEncryptedResponse(func, cor_id, arguments, fileName)
if self.isSecuredSession and self.security:checkSecureService(constants.SERVICE_TYPE.RPC) then
return self.rpc_services:SendResponse(func, cor_id, arguments, fileName, securityConstants.ENCRYPTION.ON)
end
print("Error: Can not send encrypted response. "
.. "Secure service was not established. Session: " .. self.sessionId.get())
return -1
end

--- Send encrypted RPC
-- @tparam string func RPC name
-- @tparam table arguments Arguments for RPC function
-- @tparam string fileName Path to file with binary data
function mt.__index:SendEncryptedNotification(func, arguments, fileName)
if self.isSecuredSession and self.security:checkSecureService(constants.SERVICE_TYPE.RPC) then
return self.rpc_services:SendNotification(func, arguments, fileName, securityConstants.ENCRYPTION.ON)
end
print("Error: Can not send encrypted request. "
.. "Secure service was not established. Session: " .. self.sessionId.get())
return -1
end

--- Start specific service
-- For service == 7 should be used StartRPC() instead of this function
-- @tparam number service Service type
Expand Down
14 changes: 12 additions & 2 deletions modules/protocol_handler/protocol_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ local function int32ToBytes(val)
return res
end

--- Convert unsigned 32 bit integer value to signed 32 bit integer value
-- @tparam value unsigned 32 bit integer value
-- @treturn signed 32 bit integer value
local function uint32ToInt32(val)
if val >= 2 ^ 31 then
return val - 2 ^ 32
end
return val
end

--- Build int32 value from its byte representation
-- @tparam string val Byte representation of int32
-- @tparam number offset Offset
Expand All @@ -65,7 +75,7 @@ local function rpcPayload(msg)
bit32.rshift(bit32.band(msg.rpcFunctionId, 0xff0000), 16),
bit32.rshift(bit32.band(msg.rpcFunctionId, 0xff00), 8),
bit32.band(msg.rpcFunctionId, 0xff)) ..
int32ToBytes(msg.rpcCorrelationId) ..
int32ToBytes(uint32ToInt32(msg.rpcCorrelationId)) ..
int32ToBytes(#msg.payload) ..
msg.payload .. msg.binaryData

Expand Down Expand Up @@ -172,7 +182,7 @@ local function parseBinaryHeader(message, validateJson)
message.rpcType = rpcType
message.rpcFunctionId = rpcFunctionId
message.rpcJsonSize = rpcJsonSize
message.rpcCorrelationId = bytesToInt32(message.binaryData, 5)
message.rpcCorrelationId = uint32ToInt32(bytesToInt32(message.binaryData, 5))
if message.rpcJsonSize > 0 then
if not validateJson then
message.payload = json.decode(string.sub(message.binaryData, BINARY_HEADER_SIZE + 1, BINARY_HEADER_SIZE + message.rpcJsonSize))
Expand Down
Loading

0 comments on commit 6e52740

Please sign in to comment.