Skip to content

Commit

Permalink
Make it build without warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Hackl committed Jun 21, 2017
1 parent e6dfdab commit 994cc45
Show file tree
Hide file tree
Showing 11 changed files with 1,263 additions and 1,907 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
nohup.out
broker
broker_mqtts
cmake-build-debug/*
CMakeLists.txt
.idea/*
3 changes: 3 additions & 0 deletions rsmb/src/Broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ int main(int argc, char* argv[])
Heap_initialize();
Log_initialize();

printf("%s\n", broker_timestamp_eye);
printf("%s\n", broker_version_eye);

Log(LOG_INFO, 9999, PRODUCT_NAME);
Log(LOG_INFO, 9998, "Part of Project Mosquitto in Eclipse\n("
"http://projects.eclipse.org/projects/technology.mosquitto)");
Expand Down
1 change: 0 additions & 1 deletion rsmb/src/MQTTProtocolClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extern MQTTProtocol state; /**< MQTT Protocol state shared with the MQTTProtoco
extern BrokerStates* bstate; /**< broker state shared with the MQTTProtocol module */
extern int in_MQTTPacket_Factory; /**< flag shared with the MQTTProtocol module */

void MQTTProtocol_removePublication(Publications* p);

/**
* List callback function for comparing Message structures by message id
Expand Down
15 changes: 7 additions & 8 deletions rsmb/src/MQTTSPacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void* MQTTSPacket_Factory(int sock, char** clientAddr, struct sockaddr* from, ui
// Skip Crt(1) field
data++ ;
// Wireless Node Id
*wlnid = data ;
*wlnid = (uint8_t*) data ;
// Wireless Node Id length is packet length - 3 octet (Length(1) + MsgType(1) + Crt(1))
*wlnid_len = header.len - 3 ;
data += *wlnid_len ;
Expand Down Expand Up @@ -445,7 +445,6 @@ void* MQTTSPacket_publish(MQTTSHeader header, char* data)
{
MQTTS_Publish* pack = NULL;
char* curdata = data;
char* enddata = &data[header.len - 2];
int topicLen = 0;
int datalen = 0;

Expand Down Expand Up @@ -780,7 +779,7 @@ int MQTTSPacket_send(const Clients *client, MQTTSHeader header, char* buffer, in
{
int rc = 0;
char *data = NULL;
uint8_t *ptr = NULL;
char *ptr = NULL;
PacketBuffer buf;

FUNC_ENTRY;
Expand All @@ -805,7 +804,7 @@ int MQTTSPacket_send(const Clients *client, MQTTSHeader header, char* buffer, in

buf.data = data;
buf.len = buflen + 2;
char *colon ;
char *colon = NULL;
if ( client->wirelessNodeId != NULL )
{
buf = MQTTSPacketSerialize_forwarder_encapsulation(client , buf) ;
Expand Down Expand Up @@ -841,7 +840,7 @@ int MQTTSPacket_send_ack(Clients* client, char type)
FUNC_ENTRY;
buf = MQTTSPacketSerialize_ack(type, -1);

char *colon ;
char *colon = NULL;
if ( client->wirelessNodeId != NULL )
{
buf = MQTTSPacketSerialize_forwarder_encapsulation(client , buf) ;
Expand All @@ -867,7 +866,7 @@ int MQTTSPacket_send_ack_with_msgId(Clients* client, char type, int msgId)
FUNC_ENTRY;
buf = MQTTSPacketSerialize_ack(type, msgId);

char *colon ;
char *colon = NULL;
if ( client->wirelessNodeId != NULL )
{
buf = MQTTSPacketSerialize_forwarder_encapsulation(client , buf) ;
Expand All @@ -893,7 +892,7 @@ int MQTTSPacket_send_connack(Clients* client, int returnCode)
FUNC_ENTRY;
buf = MQTTSSerialize_connack(returnCode);

char *colon ;
char *colon = NULL;
if ( client->wirelessNodeId != NULL )
{
buf = MQTTSPacketSerialize_forwarder_encapsulation(client , buf) ;
Expand Down Expand Up @@ -1169,7 +1168,7 @@ int MQTTSPacket_send_connect(Clients* client)
FUNC_ENTRY;
buf = MQTTSPacketSerialize_connect(client->cleansession, (client->will != NULL), 1, client->keepAliveInterval, client->clientID);

char *colon ;
char *colon = NULL;
if ( client->wirelessNodeId != NULL )
{
buf = MQTTSPacketSerialize_forwarder_encapsulation(client , buf) ;
Expand Down
37 changes: 22 additions & 15 deletions rsmb/src/MQTTSProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
#define FORCE_CLIENT_RESUB 0x04
#endif

void MQTTProtocol_removePublication(Publications* p);

static time_t last_keepalive; /**< time of last keep alive processing */
typedef int (*pf)(void*, int, char* clientAddr, Clients* client);

Expand Down Expand Up @@ -194,6 +192,9 @@ void MQTTSProtocol_housekeeping()
rc = MQTTSPacket_send_advertise(listener->socket,
listener->advertise->address, listener->advertise->gateway_id,
listener->advertise->interval);
if(rc) {
Log(LOG_WARNING, 17, NULL, "Advertising Failed");
}
listener->advertise->last = now;
}
}
Expand Down Expand Up @@ -360,7 +361,9 @@ int MQTTSProtocol_handleConnects(void* pack, int sock, char* clientAddr, Clients
Node* elem = NULL;
int rc = 0;
int existingClient = 0;
int newClient = 0;
#if defined(BLUEROVER)
int newClient = 0;
#endif

FUNC_ENTRY;
Log(LOG_PROTOCOL, 39, NULL, sock, clientAddr, client ? client->clientID : "", connect->flags.cleanSession);
Expand Down Expand Up @@ -416,8 +419,10 @@ int MQTTSProtocol_handleConnects(void* pack, int sock, char* clientAddr, Clients
{
/* Brand new client connection */
int i;


#if defined(BLUEROVER)
newClient = 1;
#endif

client = malloc(sizeof(Clients));
memset(client, '\0', sizeof(Clients));
Expand Down Expand Up @@ -476,7 +481,9 @@ int MQTTSProtocol_handleConnects(void* pack, int sock, char* clientAddr, Clients
client->cleansession = connect->flags.cleanSession;
client->socket = sock;
client->addr = malloc(strlen(clientAddr)+1);
#if defined(BLUEROVER)
client->resubscription_requested = 0;
#endif
strcpy(client->addr, clientAddr);
TreeAdd(bstate->mqtts_clients, client, sizeof(Clients) + strlen(client->clientID)+1 + 3*sizeof(List));

Expand Down Expand Up @@ -1232,7 +1239,7 @@ int MQTTSProtocol_handleDisconnects(void* pack, int sock, char* clientAddr, Clie
// Otherwise keep it. It is a sleeping client
if ( disc->duration == 0 )
{
client->sleep_state == DISCONNECTED;
client->sleep_state = DISCONNECTED;
MQTTSProtocol_emptyRegistrationList(client->registrations);
MQTTProtocol_closeSession(client, 0);
}
Expand Down Expand Up @@ -1633,13 +1640,12 @@ int MQTTSProtocol_retry(time_t now, int doRetry)
return rc;
}


void MQTTSProtocol_keepalive(time_t now)
{
Node* current = NULL;

FUNC_ENTRY;

current = TreeNextElement(bstate->mqtts_clients, current);

while (current)
Expand All @@ -1651,7 +1657,7 @@ void MQTTSProtocol_keepalive(time_t now)
if (client->outbound)
{
if (client->connected && client->keepAliveInterval > 0
&& (difftime(now, client->lastContact) >= client->keepAliveInterval))
&& (difftime(now, client->lastContact) >= client->keepAliveInterval))
{
if (client->ping_outstanding)
{
Expand All @@ -1676,19 +1682,19 @@ void MQTTSProtocol_keepalive(time_t now)
else
#endif
if (client->connected && client->keepAliveInterval > 0
&& (difftime(now, client->lastContact) > 2*(client->keepAliveInterval)))
&& (difftime(now, client->lastContact) > 2*(client->keepAliveInterval)))
{ /* zero keepalive interval means never disconnect */
Log(LOG_INFO, 24, NULL, client->keepAliveInterval, client->clientID);
client->sleep_state = DISCONNECTED;
MQTTProtocol_closeSession(client, 1);
}
if ( (client->sleep_state == ASLEEP)
&& (client->sleep_duration > 0)
&& (difftime(now, client->start_sleep) > client->sleep_duration)
)

if ( (client->sleep_state == ASLEEP)
&& (client->sleep_duration > 0)
&& (difftime(now, client->start_sleep) > client->sleep_duration)
)
{
printf("client %s sleep duration timed out, now = %d, start_sleep = %d\n", client->clientID, now, client->start_sleep);
printf("client %s sleep duration timed out, now = %lu, start_sleep = %lu\n", client->clientID, now, client->start_sleep);
client->sleep_state = LOST;
Log(LOG_INFO, 24, NULL, client->sleep_duration, client->clientID);
MQTTProtocol_closeSession(client, 1);
Expand All @@ -1697,4 +1703,5 @@ void MQTTSProtocol_keepalive(time_t now)
FUNC_EXIT;
}


#endif
2 changes: 2 additions & 0 deletions rsmb/src/MQTTSProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ int MQTTSProtocol_initialize(BrokerStates* aBrokerState);
void MQTTSProtocol_terminate();
void MQTTSProtocol_housekeeping();
void MQTTSProtocol_timeslice(int sock);
void MQTTSProtocol_keepalive(time_t now);
void MQTTProtocol_removePublication(Publications* p);

int MQTTSProtocol_handleAdvertises(void* pack, int sock, char* clientAddr, Clients* client);
int MQTTSProtocol_handleSearchGws(void* pack, int sock, char* clientAddr, Clients* client);
Expand Down
10 changes: 7 additions & 3 deletions rsmb/src/MQTTSProtocolOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ Clients* MQTTSProtocol_create_multicast(char* ip_address, char* clientID, int lo

addr = MQTTProtocol_addressPort(ip_address, &port);

newc->addr = malloc(strlen(ip_address) + 1);
strcpy(newc->addr, ip_address);
newc->addr = malloc(strlen(addr) + 1);
strcpy(newc->addr, addr);

ipv6 = (newc->addr[0] == '[');

rc = Socket_new_udp(&(newc->socket), ipv6);
if(rc) {
Log(LOG_ERROR, 42, NULL, "Error creating UDP socket");
}

if (setsockopt(newc->socket, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&loopback, sizeof(loopback)) == SOCKET_ERROR)
if (setsockopt(newc->socket, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&loopback, sizeof(loopback)) == SOCKET_ERROR) {
Socket_error("set bridge IP_MULTICAST_LOOP", newc->socket);
}

if (intface)
{
Expand Down
14 changes: 7 additions & 7 deletions rsmb/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Inference rules are rules distinguished by the use of the character “%” in the dependency line.
# The “%” (rule character) is a wild card, matching zero or more characters. As an example, here
# Inference rules are rules distinguished by the use of the character �%� in the dependency line.
# The �%� (rule character) is a wild card, matching zero or more characters. As an example, here
# is an inference rule for building .obj files from .c files:
#
# %.obj : %.c
# $(CC) $(CFLAGS) c $(.SOURCE)
# $(CC) $(CFLAGS) c $(.SOURCE)
#
# This rule states that a .obj file can be built from a corresponding .c file when the .c and .obj
# files share the same root of the file name.
Expand All @@ -12,7 +12,7 @@
# specified in an alternative way:
#
# .c.obj :
# $(CC) $(CFLAGS) c $(.SOURCE)
# $(CC) $(CFLAGS) c $(.SOURCE)

SOURCES_MQTT=Bridge.c Broker.c Clients.c Filter.c Heap.c LinkedList.c Log.c Messages.c MQTTPacket.c MQTTPacketOut.c \
MQTTProtocol.c MQTTProtocolClient.c MQTTProtocolOut.c Persistence.c Protocol.c Socket.c SocketBuffer.c \
Expand Down Expand Up @@ -88,10 +88,10 @@ else
ifndef GCC
GCC = gcc
endif
CFLAGS=-Wall
CFLAGS=-Wall -Werror
INSTALL_PATH=~/rsmb

# TARGETS=broker broker_dbg broker_mqtts rsmb.ini
#TARGETS=broker broker_dbg broker_mqtts rsmb.ini
TARGETS=broker broker_mqtts

all: $(TARGETS)
Expand Down Expand Up @@ -122,7 +122,7 @@ broker_mqtts: $(OBJS)

$(OBJDIR_MQTT-SN)/%.o : %.c *.h
@mkdir -p $(@D)
$(GCC) $(CFLAGS) -Os -c -DMQTTS -DBLUEROVER $< -o $@
$(GCC) $(CFLAGS) -Os -c -DMQTTS $< -o $@

# broker_mqtts: *.c *.h
# ${GCC} -DMQTTS -Wall -s -Os *.c -o broker_mqtts
Expand Down
1 change: 1 addition & 0 deletions rsmb/src/Persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "StackTrace.h"

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stddef.h>
#include <memory.h>
Expand Down
Loading

0 comments on commit 994cc45

Please sign in to comment.