├── .gitattributes ├── .gitignore ├── .travis.yml ├── amqtdd ├── build │ ├── Makefile.viper │ ├── Makefile.uclibc │ ├── Makefile │ └── build.xml └── src │ ├── Filter.c │ ├── Filter.h │ ├── Topics.h │ ├── Protocol.h │ ├── MQTTPacketOut.h │ ├── Messages.h │ ├── Persistence.h │ ├── MQTTMPProtocol.h │ ├── MQTTProtocolOut.h │ ├── MQTTSProtocolOut.h │ ├── Users.h │ ├── Clients.c │ ├── Heap.h │ ├── SocketBuffer.h │ ├── MQTTProtocolClient.h │ ├── Log.h │ ├── StackTrace.c │ ├── StackTrace.h │ ├── MQTTProtocol.h │ ├── LinkedList.h │ ├── Tree.h │ ├── MQTTSProtocol.h │ ├── SubsEngine.h │ ├── Broker.h │ ├── Makefile │ ├── Bridge.h │ ├── Socket.h │ └── Users.c ├── rsmb └── src │ ├── tools │ └── be │ │ ├── Makefile │ │ ├── view_heap.py │ │ ├── be.pl │ │ └── bememext.h │ ├── Filter.c │ ├── Filter.h │ ├── Topics.h │ ├── MQTTSClient │ ├── Python │ │ ├── MQTTSNregister.py │ │ └── MQTTSNinternal.py │ ├── MQTTSClient.c │ ├── MQTTSClientInternal.h │ ├── MQTTSClient.h │ └── MQTTSClientInternal.c │ ├── Makefile │ ├── Messages.h │ ├── MQTTSPacketSerialize.h │ ├── MQTTPacketOut.h │ ├── Persistence.h │ ├── Protocol.h │ ├── MQTTProtocolOut.h │ ├── MQTTSProtocolOut.h │ ├── Users.h │ ├── Heap.h │ ├── SocketBuffer.h │ ├── Clients.c │ ├── MQTTProtocolClient.h │ ├── Log.h │ ├── StackTrace.c │ ├── StackTrace.h │ ├── LinkedList.h │ ├── Tree.h │ ├── MQTTSProtocol.h │ ├── MQTTProtocol.h │ ├── MQTTSPacketSerialize.c │ ├── SubsEngine.h │ ├── Messages.txt │ ├── Messages.1.3.0.2 │ └── Bridge.h ├── edl-v10 ├── README.md ├── about.html └── CONTRIBUTING.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.c text 4 | *.h text 5 | 6 | *.sln text eol=crlf 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | rsmb/src/broker 2 | rsmb/src/broker_dbg 3 | rsmb/src/broker_mqtts 4 | rsmb/src/rsmb.ini 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | os: 7 | - linux 8 | - osx 9 | 10 | install: 11 | - true 12 | 13 | script: 14 | - cd rsmb/src && make 15 | -------------------------------------------------------------------------------- /amqtdd/build/Makefile.viper: -------------------------------------------------------------------------------- 1 | 2 | all: amqtdd.viper amqtdd_mqtts.viper 3 | 4 | amqtdd.viper: *.c *.h 5 | arm-linux-gcc -Wall -s -Os *.c -o amqtdd.viper 6 | 7 | amqtdd_mqtts.viper: *.c *.h 8 | arm-linux-gcc -DMQTTS -Wall -s -Os *.c -o amqtdd_mqtts.viper 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /amqtdd/build/Makefile.uclibc: -------------------------------------------------------------------------------- 1 | GCC=~/x-tools/arm-unknown-linux-uclibcgnueabi/bin/arm-unknown-linux-uclibcgnueabi-gcc 2 | 3 | 4 | all: amqtdd.arm-uclibc amqtdd_mqtts.arm-uclibc 5 | 6 | amqtdd.arm-uclibc: *.c *.h 7 | $(GCC) -Wall -s -Os *.c -o amqtdd.arm-uclibc 8 | 9 | amqtdd_mqtts.arm-uclibc: *.c *.h 10 | $(GCC) -DMQTTS -Wall -s -Os *.c -o amqtdd_mqtts.arm-ublibc 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /rsmb/src/tools/be/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ifeq ($(OS), Windows_NT) 3 | 4 | bersmb.dll: bersmb.obj 5 | link /NOLOGO /INCREMENTAL:NO /DLL bersmb.obj /OUT:$@ 6 | 7 | bersmb.obj: bersmb.cpp bememext.h 8 | cl /c /DWIN32 /D_CRT_SECURE_NO_WARNINGS /Gs /Oit /MT /nologo /W3 /WX /Tp bersmb.cpp 9 | 10 | else 11 | 12 | bersmb.so: bersmb.o 13 | g++ -Wall -shared -o $@ bersmb.o 14 | chmod a-x $@ 15 | 16 | bersmb.o: bersmb.cpp bememext.h 17 | g++ -Wall -DUNIX -DLINUX -fPIC -c $*.cpp 18 | 19 | endif 20 | 21 | -------------------------------------------------------------------------------- /rsmb/src/Filter.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "Filter.h" 18 | 19 | //Filter_ 20 | 21 | -------------------------------------------------------------------------------- /amqtdd/src/Filter.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "Filter.h" 18 | 19 | //Filter_ 20 | 21 | -------------------------------------------------------------------------------- /rsmb/src/Filter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(FILTER_H) 18 | #define FILTER_H 19 | 20 | 21 | 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /amqtdd/src/Filter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(FILTER_H) 18 | #define FILTER_H 19 | 20 | 21 | 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /amqtdd/src/Topics.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(TOPICS_H) 19 | #define TOPICS_H 20 | 21 | #define TOPIC_LEVEL_SEPARATOR "/" 22 | #define SINGLE_LEVEL_WILDCARD "+" 23 | #define MULTI_LEVEL_WILDCARD "#" 24 | 25 | int Topics_isValidName(char* aName); 26 | 27 | int Topics_hasWildcards(char* topic); 28 | 29 | int Topics_matches(char* wildTopic, char* topic); 30 | 31 | #endif /* TOPICS_H */ 32 | -------------------------------------------------------------------------------- /rsmb/src/Topics.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(TOPICS_H) 19 | #define TOPICS_H 20 | 21 | #define TOPIC_LEVEL_SEPARATOR "/" 22 | #define SINGLE_LEVEL_WILDCARD "+" 23 | #define MULTI_LEVEL_WILDCARD "#" 24 | 25 | int Topics_isValidName(char* aName); 26 | 27 | int Topics_hasWildcards(char* topic); 28 | 29 | int Topics_matches(char* wildTopic, int wildcards, char* topic); 30 | 31 | #endif /* TOPICS_H */ 32 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/Python/MQTTSNregister.py: -------------------------------------------------------------------------------- 1 | """ 2 | /******************************************************************************* 3 | * Copyright (c) 2011, 2013 IBM Corp. 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Eclipse Distribution License v1.0 which accompany this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * and the Eclipse Distribution License is available at 12 | * http://www.eclipse.org/org/documents/edl-v10.php. 13 | * 14 | * Contributors: 15 | * Ian Craggs - initial API and implementation and/or initial documentation 16 | *******************************************************************************/ 17 | """ 18 | 19 | import MQTTSNclient 20 | 21 | aclient = MQTTSNclient.Client("register", port=1885) 22 | aclient.registerCallback(MQTTSNclient.Callback()) 23 | 24 | aclient.connect() 25 | result = aclient.register("jkjkjkjkj") 26 | print "result from register 1 is", result 27 | result = aclient.register("jkjkjkjkj") 28 | print "result from register 1 is", result 29 | result = aclient.register("jkjkjkjkj2") 30 | print "result from register 2 is", result 31 | -------------------------------------------------------------------------------- /rsmb/src/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ifeq ($(OS), Windows_NT) 3 | 4 | # the /Zp4 option aligns structure elements on 4 byte boundaries to allow 5 | # the heapdump mapping to work 6 | 7 | all: broker.exe broker_mqtts.exe rsmb.ini 8 | 9 | broker.exe: *.c *.h 10 | vcvars32.bat 11 | cl -O2 -DWIN32 ws2_32.lib *.c /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /Zp4 /Febroker.exe /link /MANIFEST 12 | mt -manifest broker.exe.manifest -outputresource:broker.exe\;1 13 | 14 | 15 | broker_mqtts.exe: *.c *.h 16 | vcvars32.bat 17 | cl -O2 -DWIN32 Iphlpapi.lib ws2_32.lib *.c /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /DMQTTS /Zp4 /Febroker_mqtts.exe /link /MANIFEST 18 | mt -manifest broker_mqtts.exe.manifest -outputresource:broker_mqtts.exe\;1 19 | 20 | rsmb.ini: *.h 21 | perl tools\\be\\be.pl 22 | 23 | else 24 | 25 | ifndef CC 26 | CC = gcc 27 | endif 28 | 29 | TARGETS = broker broker_dbg broker_mqtts rsmb.ini 30 | 31 | all: $(TARGETS) 32 | 33 | broker: *.c *.h 34 | $(CC) -Wall -Os *.c -o broker 35 | 36 | broker_dbg: *.c *.h 37 | $(CC) -Wall -ggdb *.c -o broker_dbg 38 | 39 | broker_mqtts: *.c *.h 40 | $(CC) -DMQTTS -Wall -Os *.c -o broker_mqtts 41 | 42 | broker_mqtts32: *.c *.h 43 | $(CC) -m32 -DMQTTS -Wall -Os *.c -o broker_mqtts32 44 | 45 | rsmb.ini: *.h 46 | perl tools/be/be.pl 47 | 48 | clean: 49 | rm -f $(TARGETS) 50 | 51 | endif 52 | -------------------------------------------------------------------------------- /rsmb/src/Messages.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MESSAGES_H) 19 | #define MESSAGES_H 20 | 21 | /** 22 | * Number of messages in the file 23 | */ 24 | #if !defined(MQTTS) 25 | #define MESSAGE_COUNT 103 26 | #else 27 | #define MESSAGE_COUNT 107 28 | #endif 29 | 30 | /** 31 | * Largest message number 32 | */ 33 | #if !defined(MQTTS) 34 | #define MAX_MESSAGE_INDEX 153 35 | #else 36 | #define MAX_MESSAGE_INDEX 303 37 | #endif 38 | 39 | #include "Broker.h" 40 | 41 | int Messages_initialize(BrokerStates*); 42 | void Messages_terminate(); 43 | 44 | char* Messages_get(int, int); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /amqtdd/src/Protocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef PROTOCOL_H_ 18 | #define PROTOCOL_H_ 19 | 20 | void Protocol_timeslice(); 21 | void Protocol_processPublication(Publish* publish, char* originator); 22 | 23 | int Protocol_initialize(BrokerStates* bs); 24 | void Protocol_terminate(); 25 | Clients* Protocol_getclientbyaddr(char* addr); 26 | int clientPrefixCompare(void* prefix, void* clientid); 27 | int Protocol_isClientQuiescing(Clients* client); 28 | int Protocol_inProcess(Clients* client); 29 | 30 | #if !defined(NO_BRIDGE) 31 | Clients* Protocol_getoutboundclient(int sock); 32 | #endif 33 | 34 | #endif /* PROTOCOL_H_ */ 35 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSPacketSerialize.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTSPACKETSERIALIZE_H) 18 | #define MQTTSPACKETSERIALIZE_H 19 | 20 | 21 | typedef struct 22 | { 23 | int len; 24 | char* data; 25 | char* ptr; /* pointer to the next free space in the buffer */ 26 | } PacketBuffer; 27 | 28 | 29 | PacketBuffer MQTTSPacketSerialize_ack(char type, int msgId); 30 | PacketBuffer MQTTSPacketSerialize_advertise(unsigned char gateway_id, short duration); 31 | PacketBuffer MQTTSPacketSerialize_connect(int cleansession, int will, char protocolID, short keepAlive, char* clientID); 32 | PacketBuffer MQTTSSerialize_connack(int returnCode); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTPacketOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPACKETOUT_H) 19 | #define MQTTPACKETOUT_H 20 | 21 | #include "MQTTPacket.h" 22 | 23 | int MQTTPacket_send_connect(Clients* client); 24 | void* MQTTPacket_connack(unsigned char aHeader, char* data, int datalen); 25 | 26 | int MQTTPacket_send_pingreq(int socket, char* clientID); 27 | 28 | int MQTTPacket_send_subscribe(List* topics, List* qoss, int msgid, int dup, int socket, char* clientID); 29 | void* MQTTPacket_suback(unsigned char aHeader, char* data, int datalen); 30 | 31 | int MQTTPacket_send_unsubscribe(List* topics, int msgid, int dup, int socket, char* clientID); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /rsmb/src/MQTTPacketOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPACKETOUT_H) 19 | #define MQTTPACKETOUT_H 20 | 21 | #include "MQTTPacket.h" 22 | 23 | int MQTTPacket_send_connect(Clients* client); 24 | void* MQTTPacket_connack(unsigned char aHeader, char* data, int datalen); 25 | 26 | int MQTTPacket_send_pingreq(int socket, char* clientID); 27 | 28 | int MQTTPacket_send_subscribe(List* topics, List* qoss, int msgid, int dup, int socket, char* clientID); 29 | void* MQTTPacket_suback(unsigned char aHeader, char* data, int datalen); 30 | 31 | int MQTTPacket_send_unsubscribe(List* topics, int msgid, int dup, int socket, char* clientID); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /amqtdd/src/Messages.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MESSAGES_H) 19 | #define MESSAGES_H 20 | 21 | /** 22 | * Number of messages in the file 23 | */ 24 | #if defined(MQTTMP) 25 | #define MESSAGE_COUNT 114 26 | #else 27 | #if !defined(MQTTS) 28 | #define MESSAGE_COUNT 104 29 | #else 30 | #define MESSAGE_COUNT 116 31 | #endif 32 | #endif 33 | 34 | /** 35 | * Largest message number 36 | */ 37 | #if defined(MQTTMP) 38 | #define MAX_MESSAGE_INDEX 209 39 | #else 40 | #if !defined(MQTTS) 41 | #define MAX_MESSAGE_INDEX 153 42 | #else 43 | #define MAX_MESSAGE_INDEX 301 44 | #endif 45 | #endif 46 | 47 | #include "Broker.h" 48 | 49 | int Messages_initialize(BrokerStates*); 50 | void Messages_terminate(); 51 | 52 | char* Messages_get(int, int); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /amqtdd/src/Persistence.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(PERSISTENCE_H) 19 | #define PERSISTENCE_H 20 | 21 | #include "Broker.h" 22 | #include 23 | 24 | int Persistence_read_config(char* filename, BrokerStates* s, int config_set); 25 | void Persistence_free_config(BrokerStates* bs); 26 | 27 | FILE* Persistence_open_retained(char mode); 28 | int Persistence_write_retained(char* payload, int payloadlen, int qos, char* topicName); 29 | RetainedPublications* Persistence_read_retained(); 30 | 31 | FILE* Persistence_open_subscriptions(char mode); 32 | int Persistence_write_subscription(Subscriptions*); 33 | Subscriptions* Persistence_read_subscription(); 34 | void Persistence_close_file(); 35 | 36 | void Persistence_read_command(BrokerStates* bs); 37 | 38 | #endif /* PERSISTENCE_H */ 39 | -------------------------------------------------------------------------------- /rsmb/src/Persistence.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(PERSISTENCE_H) 19 | #define PERSISTENCE_H 20 | 21 | #include "Broker.h" 22 | #include 23 | 24 | int Persistence_read_config(char* filename, BrokerStates* s, int config_set); 25 | void Persistence_free_config(BrokerStates* bs); 26 | 27 | FILE* Persistence_open_retained(char mode); 28 | int Persistence_write_retained(char* payload, int payloadlen, int qos, char* topicName); 29 | RetainedPublications* Persistence_read_retained(); 30 | 31 | FILE* Persistence_open_subscriptions(char mode); 32 | int Persistence_write_subscription(Subscriptions*); 33 | Subscriptions* Persistence_read_subscription(); 34 | void Persistence_close_file(int); 35 | 36 | void Persistence_read_command(BrokerStates* bs); 37 | 38 | #endif /* PERSISTENCE_H */ 39 | -------------------------------------------------------------------------------- /edl-v10: -------------------------------------------------------------------------------- 1 | 2 | Eclipse Distribution License - v 1.0 3 | 4 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. 5 | 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 9 | 10 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | 16 | -------------------------------------------------------------------------------- /rsmb/src/Protocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef PROTOCOL_H_ 18 | #define PROTOCOL_H_ 19 | 20 | void Protocol_timeslice(); 21 | void Protocol_processPublication(Publish* publish, char* originator); 22 | int Protocol_startOrQueuePublish(Clients* pubclient, Publish* publish, int qos, int retained, int priority, Messages** m); 23 | 24 | int Protocol_initialize(BrokerStates* bs); 25 | void Protocol_terminate(); 26 | Clients* Protocol_getclientbyaddr(char* addr); 27 | int clientPrefixCompare(void* prefix, void* clientid); 28 | int Protocol_isClientQuiescing(Clients* client); 29 | int Protocol_inProcess(Clients* client); 30 | 31 | #if !defined(NO_BRIDGE) 32 | Clients* Protocol_getoutboundclient(int sock); 33 | #endif 34 | 35 | int Protocol_handlePublishes(Publish* publish, int sock, Clients* client, char* clientid); 36 | 37 | #endif /* PROTOCOL_H_ */ 38 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTMPProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Nicholas O'Leary, Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef MQTTMPPROTOCOL_H_ 18 | #define MQTTMPPROTOCOL_H_ 19 | 20 | #include "Broker.h" 21 | 22 | void MQTTMPProtocol_initialize(BrokerStates* bs); 23 | void MQTTMPProtocol_timeslice(int sock); 24 | void MQTTMPProtocol_terminate(); 25 | int MQTTMPProtocol_getNextVirtualSocket(); 26 | void MQTTMPProtocol_closeSession(Clients* client, int send_close); 27 | int MQTTMPProtocol_get_real_socket(int sock); 28 | int MQTTMPProtocol_getCurrentChannel(); 29 | Clients* MQTTMPProtocol_getClientForVirtualSocket(int virtSocket); 30 | void MQTTMPProtocol_closeSocket(int socket); 31 | int MQTTMPProtocol_closeChannel(int socket, int channel); 32 | int MQTTMPProtocol_send_connack(int aRc, int socket, int channel, char* clientID); 33 | #define MP_PACKET_MQTT 0 34 | #define MP_PACKET_CLOSE 1 35 | 36 | #endif /* MQTTMPPROTOCOL_H_ */ 37 | -------------------------------------------------------------------------------- /rsmb/src/tools/be/view_heap.py: -------------------------------------------------------------------------------- 1 | """ 2 | /******************************************************************************* 3 | * Copyright (c) 2007, 2013 IBM Corp. 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Eclipse Distribution License v1.0 which accompany this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * and the Eclipse Distribution License is available at 12 | * http://www.eclipse.org/org/documents/edl-v10.php. 13 | * 14 | * Contributors: 15 | * Ian Craggs - initial API and implementation and/or initial documentation 16 | *******************************************************************************/ 17 | 18 | Extract heap dump from a file containing some other data, e.g. an FFDC 19 | 20 | """ 21 | 22 | 23 | import sys, os 24 | 25 | start_eyecatcher = "=========== Start of heap dump ==========\n" 26 | end_eyecatcher = "\n=========== End of heap dump ==========" 27 | 28 | infile = open(sys.argv[1], "rb") 29 | contents = infile.read() 30 | infile.close() 31 | 32 | symbols = "" 33 | if contents.find("MQTTS") != -1: 34 | symbols += "-D MQTTS " 35 | if contents.find("epoll") != -1: 36 | symbols += "-D USE_POLL " 37 | 38 | outfile = open("heapdump", "wb") 39 | outfile.write(contents[contents.find(start_eyecatcher) + len(start_eyecatcher):-len(end_eyecatcher)]) 40 | outfile.close() 41 | 42 | if os.name == "posix": 43 | call = "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. be -i rsmb.ini "+symbols+" rsmb\!heapdump" 44 | else: 45 | call = "be -i rsmb.ini "+symbols+" rsmb!heapdump" 46 | 47 | os.system(call) 48 | 49 | 50 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTProtocolOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPROTOCOLOUT_H) 19 | #define MQTTPROTOCOLOUT_H 20 | 21 | #include "Broker.h" 22 | #include "LinkedList.h" 23 | #include "SubsEngine.h" 24 | #include "MQTTPacket.h" 25 | #include "Clients.h" 26 | #include "Log.h" 27 | #include "Messages.h" 28 | #include "MQTTProtocol.h" 29 | #include "MQTTProtocolClient.h" 30 | 31 | #define DEFAULT_PORT 1883 32 | 33 | void MQTTProtocol_reconnect(char* ip_address, Clients* client); 34 | Clients* MQTTProtocol_connect(char* ip_address, char* clientID, int cleansession, int try_private, int keepalive, willMessages* willMessage, char* username, char* password); 35 | int MQTTProtocol_handlePingresps(void* pack, int sock); 36 | int MQTTProtocol_subscribe(Clients* client, List* topics, List* qoss); 37 | int MQTTProtocol_handleSubacks(void* pack, int sock); 38 | int MQTTProtocol_unsubscribe(Clients* client, List* topics); 39 | int MQTTProtocol_handleUnsubacks(void* pack, int sock); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /rsmb/src/MQTTProtocolOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPROTOCOLOUT_H) 19 | #define MQTTPROTOCOLOUT_H 20 | 21 | #include "Broker.h" 22 | #include "LinkedList.h" 23 | #include "SubsEngine.h" 24 | #include "MQTTPacket.h" 25 | #include "Clients.h" 26 | #include "Log.h" 27 | #include "Messages.h" 28 | #include "MQTTProtocol.h" 29 | #include "MQTTProtocolClient.h" 30 | 31 | #define DEFAULT_PORT 1883 32 | 33 | void MQTTProtocol_reconnect(char* ip_address, Clients* client); 34 | Clients* MQTTProtocol_connect(char* ip_address, char* clientID, int cleansession, int try_private, int keepalive, willMessages* willMessage, char* username, char* password); 35 | int MQTTProtocol_handlePingresps(void* pack, int sock, Clients* client); 36 | int MQTTProtocol_subscribe(Clients* client, List* topics, List* qoss); 37 | int MQTTProtocol_handleSubacks(void* pack, int sock, Clients* client); 38 | int MQTTProtocol_unsubscribe(Clients* client, List* topics); 39 | int MQTTProtocol_handleUnsubacks(void* pack, int sock, Clients* client); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTSProtocolOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Nicholas O'Leary, Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef MQTTSPROTOCOLOUT_H_ 18 | #define MQTTSPROTOCOLOUT_H_ 19 | 20 | #include "Broker.h" 21 | #include "LinkedList.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTSPacket.h" 24 | #include "Clients.h" 25 | #include "Log.h" 26 | #include "Messages.h" 27 | #include "MQTTSProtocol.h" 28 | 29 | 30 | Clients* MQTTSProtocol_connect(char* ip_address, char* clientID, int cleansession, int try_private, int keepalive, willMessages* willMessage); 31 | 32 | 33 | int MQTTSProtocol_handleConnacks(void* pack, int sock, char* clientAddr); 34 | void MQTTSProtocol_reconnect(char* ip_address, Clients* client); 35 | int MQTTSProtocol_handleWillTopicReqs(void* pack, int sock, char* clientAddr); 36 | int MQTTSProtocol_handleWillMsgReqs(void* pack, int sock, char* clientAddr); 37 | int MQTTSProtocol_handleSubacks(void* pack, int sock, char* clientAddr); 38 | int MQTTSProtocol_startSubscription(Clients* client, char* topic, int qos); 39 | int MQTTSProtocol_startClientRegistration(Clients* client, char* topic); 40 | 41 | #endif /* MQTTSPROTOCOLOUT_H_ */ 42 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSProtocolOut.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef MQTTSPROTOCOLOUT_H_ 18 | #define MQTTSPROTOCOLOUT_H_ 19 | 20 | #include "Broker.h" 21 | #include "LinkedList.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTSPacket.h" 24 | #include "Clients.h" 25 | #include "Log.h" 26 | #include "Messages.h" 27 | #include "MQTTSProtocol.h" 28 | 29 | 30 | Clients* MQTTSProtocol_create_multicast(char* ip_address, char* clientID, int loopback); 31 | Clients* MQTTSProtocol_connect(char* ip_address, char* clientID, int cleansession, int try_private, int keepalive, willMessages* willMessage); 32 | 33 | 34 | int MQTTSProtocol_handleConnacks(void* pack, int sock, char* clientAddr, Clients* client); 35 | void MQTTSProtocol_reconnect(char* ip_address, Clients* client); 36 | int MQTTSProtocol_handleWillTopicReqs(void* pack, int sock, char* clientAddr, Clients* client); 37 | int MQTTSProtocol_handleWillMsgReqs(void* pack, int sock, char* clientAddr, Clients* client); 38 | int MQTTSProtocol_handleSubacks(void* pack, int sock, char* clientAddr, Clients* client); 39 | int MQTTSProtocol_startSubscription(Clients* client, char* topic, int qos); 40 | int MQTTSProtocol_startClientRegistration(Clients* client, char* topic); 41 | 42 | #endif /* MQTTSPROTOCOLOUT_H_ */ 43 | -------------------------------------------------------------------------------- /amqtdd/src/Users.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(USERS_H) 18 | #define USERS_H 19 | 20 | #include "LinkedList.h" 21 | 22 | #define ACL_FULL 0 23 | #define ACL_WRITE 1 24 | #define ACL_READ 2 25 | 26 | /*BE 27 | include "LinkedList" 28 | BE*/ 29 | /*BE 30 | map permission 31 | { 32 | "full" . 33 | "write" . 34 | "read" . 35 | } 36 | def RULE 37 | { 38 | n32 ptr STRING open "topic" 39 | n32 map permission "permission" 40 | } 41 | defList(RULE) 42 | BE*/ 43 | 44 | /*BE 45 | def USER 46 | { 47 | n32 ptr STRING open "username" 48 | n32 ptr STRING open "password" 49 | n32 ptr RULEList open "acl" 50 | } 51 | defList(USER) 52 | BE*/ 53 | typedef struct 54 | { 55 | char* username; /**< username */ 56 | char* password; /**< password */ 57 | List* acl; /**< Access Control List */ 58 | } User; 59 | 60 | typedef struct 61 | { 62 | char* topic; 63 | int permission; 64 | } Rule; 65 | 66 | 67 | 68 | void Users_add_user(char* username, char* pword); 69 | void Users_free_list(); 70 | int Users_authenticate(char* username, char* pword); 71 | User* Users_get_user(char* username); 72 | 73 | void Users_add_default_rule(char* topic, int permission); 74 | void Users_add_rule(User* user, char* topic, int permission); 75 | 76 | int Users_authorise(User* user, char* topic, int action); 77 | 78 | #endif /* USERS_H_ */ 79 | -------------------------------------------------------------------------------- /rsmb/src/Users.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(USERS_H) 18 | #define USERS_H 19 | 20 | #include "LinkedList.h" 21 | 22 | #define ACL_FULL 0 23 | #define ACL_WRITE 1 24 | #define ACL_READ 2 25 | 26 | /*BE 27 | include "LinkedList" 28 | BE*/ 29 | /*BE 30 | map permission 31 | { 32 | "full" . 33 | "write" . 34 | "read" . 35 | } 36 | def RULE 37 | { 38 | n32 ptr STRING open "topic" 39 | n32 map permission "permission" 40 | } 41 | defList(RULE) 42 | BE*/ 43 | 44 | /*BE 45 | def USER 46 | { 47 | n32 ptr STRING open "username" 48 | n32 ptr STRING open "password" 49 | n32 ptr RULEList open "acl" 50 | } 51 | defList(USER) 52 | BE*/ 53 | typedef struct 54 | { 55 | char* username; /**< username */ 56 | char* password; /**< password */ 57 | List* acl; /**< Access Control List */ 58 | } User; 59 | 60 | typedef struct 61 | { 62 | char* topic; 63 | int permission; 64 | } Rule; 65 | 66 | 67 | 68 | void Users_add_user(char* username, char* pword); 69 | void Users_free_list(); 70 | int Users_authenticate(char* username, char* pword); 71 | User* Users_get_user(char* username); 72 | 73 | void Users_add_default_rule(char* topic, int permission); 74 | void Users_add_rule(User* user, char* topic, int permission); 75 | 76 | int Users_authorise(User* user, char* topic, int action); 77 | 78 | #endif /* USERS_H_ */ 79 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/MQTTSClient.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTSClient.h" 18 | 19 | #include "MQTTSPacket.h" 20 | 21 | 22 | MQTTS_Header* MQTTS_getPacket(int sock, char* clientAddr, int* error) 23 | { 24 | int error; 25 | 26 | pack = MQTTSPacket_Factory(sock, &clientAddr, error); 27 | 28 | return pack; 29 | } 30 | 31 | 32 | DLLExport int MQTTSClient_create(MQTTClient* handle, char* serverURI, char* clientId, 33 | int persistence_type, void* persistence_context) 34 | { 35 | int i; 36 | newc = malloc(sizeof(Clients)); 37 | memset(newc, '\0', sizeof(Clients)); 38 | newc->outboundMsgs = ListInitialize(); 39 | newc->inboundMsgs = ListInitialize(); 40 | newc->clientID = clientID; 41 | } 42 | } 43 | 44 | 45 | DLLExport int MQTTSClient_connect(MQTTSClient handle, MQTTSClient_connectOptions* options) 46 | { 47 | MQTTClients* m = handle; 48 | int rc = SOCKET_ERROR; 49 | 50 | 51 | FUNC_ENTRY; 52 | 53 | addr = MQTTProtocol_addressPort(ip_address, &port); 54 | 55 | newc->addr = malloc(strlen(ip_address)); 56 | strcpy(newc->addr, ip_address); 57 | 58 | rc = Socket_new_type(addr, port, &(newc->socket), SOCK_DGRAM); 59 | 60 | if (rc == EINPROGRESS || rc == EWOULDBLOCK) 61 | newc->connect_state = 1; /* UDP connect called - improbable, but possible on obscure platforms */ 62 | else if (rc == 0) 63 | { 64 | newc->connect_state = 2; 65 | rc = MQTTSPacket_send_connect(newc); 66 | } 67 | 68 | /* receive connack */ 69 | MQTTS_getPacket(sock, clientAddr, &error); 70 | 71 | /* start background receiving thread, if callbacks have been set */ 72 | 73 | FUNC_EXIT; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /amqtdd/src/Clients.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /** 18 | * @file 19 | * client utility functions 20 | */ 21 | 22 | #include "Clients.h" 23 | 24 | #include 25 | #include 26 | 27 | 28 | /** 29 | * List callback function for comparing clients by clientid 30 | * @param a first integer value 31 | * @param b second integer value 32 | * @return boolean indicating whether a and b are equal 33 | */ 34 | #include "StackTrace.h" 35 | 36 | int clientIDCompare(void* a, void* b) 37 | { 38 | Clients* client = (Clients*)a; 39 | /*printf("comparing clientdIDs %s with %s\n", client->clientID, (char*)b);*/ 40 | return strcmp(client->clientID, (char*)b) == 0; 41 | } 42 | 43 | 44 | /** 45 | * List callback function for comparing clients by socket 46 | * @param a first integer value 47 | * @param b second integer value 48 | * @return boolean indicating whether a and b are equal 49 | */ 50 | int clientSocketCompare(void* a, void* b) 51 | { 52 | Clients* client = (Clients*)a; 53 | /*printf("comparing %d with %d\n", (char*)a, (char*)b);*/ 54 | return client->socket == *(int*)b; 55 | } 56 | 57 | 58 | int queuedMsgsCount(Clients* aClient) 59 | { 60 | int i, 61 | count = 0; 62 | 63 | for (i = 0; i < PRIORITY_MAX; ++i) 64 | count += aClient->queuedMsgs[i]->count; 65 | return count; 66 | } 67 | #if defined(MQTTS) || defined(MQTTMP) 68 | int clientAddrCompare(void*a, void* b) 69 | { 70 | Clients* client = (Clients*)a; 71 | /* if client->addr is NULL (which it can be, for Bridge clients for example), return false. */ 72 | return (client->addr) ? strcmp(client->addr, (char*)b) == 0 : 0; 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /amqtdd/src/Heap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(HEAP_H) 19 | #define HEAP_H 20 | 21 | #if defined(HIGH_PERFORMANCE) 22 | #define NO_HEAP_TRACKING 1 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #if !defined(NO_HEAP_TRACKING) 30 | /** 31 | * redefines malloc to use "mymalloc" so that heap allocation can be tracked 32 | * @param x the size of the item to be allocated 33 | * @return the pointer to the item allocated, or NULL 34 | */ 35 | #define malloc(x) mymalloc(__FILE__, __LINE__, x) 36 | 37 | /** 38 | * redefines realloc to use "myrealloc" so that heap allocation can be tracked 39 | * @param a the heap item to be reallocated 40 | * @param b the new size of the item 41 | * @return the new pointer to the heap item 42 | */ 43 | #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b) 44 | 45 | /** 46 | * redefines free to use "myfree" so that heap allocation can be tracked 47 | * @param x the size of the item to be freed 48 | */ 49 | #define free(x) myfree(__FILE__, __LINE__, x) 50 | 51 | #endif 52 | 53 | /** 54 | * Information about the state of the heap. 55 | */ 56 | typedef struct 57 | { 58 | int current_size; /**< current size of the heap in bytes */ 59 | int max_size; /**< max size the heap has reached in bytes */ 60 | } heap_info; 61 | 62 | 63 | void* mymalloc(char*, int, size_t size); 64 | void* myrealloc(char*, int, void* p, size_t size); 65 | void myfree(char*, int, void* p); 66 | 67 | void Heap_scan(FILE* file); 68 | int Heap_initialize(void); 69 | void Heap_terminate(void); 70 | heap_info* Heap_get_info(void); 71 | int HeapDump(FILE* file); 72 | int HeapDumpString(FILE* file, char* str); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /rsmb/src/Heap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(HEAP_H) 19 | #define HEAP_H 20 | 21 | #if defined(HIGH_PERFORMANCE) 22 | #define NO_HEAP_TRACKING 1 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #if !defined(NO_HEAP_TRACKING) 30 | /** 31 | * redefines malloc to use "mymalloc" so that heap allocation can be tracked 32 | * @param x the size of the item to be allocated 33 | * @return the pointer to the item allocated, or NULL 34 | */ 35 | #define malloc(x) mymalloc(__FILE__, __LINE__, x) 36 | 37 | /** 38 | * redefines realloc to use "myrealloc" so that heap allocation can be tracked 39 | * @param a the heap item to be reallocated 40 | * @param b the new size of the item 41 | * @return the new pointer to the heap item 42 | */ 43 | #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b) 44 | 45 | /** 46 | * redefines free to use "myfree" so that heap allocation can be tracked 47 | * @param x the size of the item to be freed 48 | */ 49 | #define free(x) myfree(__FILE__, __LINE__, x) 50 | 51 | #endif 52 | 53 | /** 54 | * Information about the state of the heap. 55 | */ 56 | typedef struct 57 | { 58 | int current_size; /**< current size of the heap in bytes */ 59 | int max_size; /**< max size the heap has reached in bytes */ 60 | } heap_info; 61 | 62 | 63 | void* mymalloc(char*, int, size_t size); 64 | void* myrealloc(char*, int, void* p, size_t size); 65 | void myfree(char*, int, void* p); 66 | 67 | void Heap_scan(FILE* file); 68 | int Heap_initialize(void); 69 | void Heap_terminate(void); 70 | heap_info* Heap_get_info(void); 71 | int HeapDump(FILE* file); 72 | int HeapDumpString(FILE* file, char* str); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/MQTTSClientInternal.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | typedef struct 19 | { 20 | int socket; /**< this client's socket */ 21 | char* addr; /**< remote address as returned by getpeer */ 22 | char* clientID; /**< MQTT id of the client */ 23 | char* username; /**< Username for outbound client connections */ 24 | char* password; /**< Password for outbound client connections */ 25 | unsigned int cleansession : 1; /**< MQTT cleansession flag */ 26 | unsigned int connected : 1; /**< is the client connected */ 27 | unsigned int good : 1; /**< if we have an error on the socket we turn this off */ 28 | unsigned int outbound : 1; /**< is this an incoming, or bridge client */ 29 | unsigned int noLocal : 1; /**< subscriptions to be noLocal? */ 30 | unsigned int ping_outstanding : 1; /**< have we sent a ping? */ 31 | unsigned int connect_state : 2; /**< state while connecting */ 32 | int msgID; /**< current outward MQTT message id */ 33 | int keepAliveInterval; /**< MQTT keep alive interval in seconds */ 34 | void* bridge_context; /**< for bridge use */ 35 | time_t lastContact; /**< time of last contact with this client */ 36 | willMessages* will; /**< will message if set (NULL if not) */ 37 | List* inboundMsgs; /**< list of inbound message state */ 38 | List* outboundMsgs; /**< list of outbound in flight messages */ 39 | List* queuedMsgs; /**< list of queued up outbound messages - not in flight */ 40 | int sleep_state; /***< MQTT-S sleep state: asleep, active, awake, lost */ 41 | List* registrations; 42 | PendingRegistration* pendingRegistration; 43 | PendingSubscription* pendingSubscription; 44 | } Clients; 45 | -------------------------------------------------------------------------------- /rsmb/src/SocketBuffer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(SOCKETBUFFER_H) 18 | #define SOCKETBUFFER_H 19 | 20 | #if defined(WIN32) 21 | /* default on Windows is 64 - increase to make Linux and Windows the same */ 22 | #define FD_SETSIZE 1024 23 | #include "winsock2.h" 24 | #else 25 | #include 26 | #endif 27 | 28 | #if defined(WIN32) 29 | typedef WSABUF iobuf; 30 | #else 31 | typedef struct iovec iobuf; 32 | #endif 33 | 34 | typedef struct 35 | { 36 | int socket; 37 | int index, headerlen; 38 | char fixed_header[5]; // header plus up to 4 length bytes 39 | int buflen, // total length of the buffer 40 | datalen; // current length of data in buf 41 | char* buf; 42 | } socket_queue; 43 | 44 | typedef struct 45 | { 46 | int socket, total, count; 47 | unsigned long bytes; 48 | iobuf iovecs[5]; 49 | } pending_writes; 50 | 51 | #define SOCKETBUFFER_COMPLETE 0 52 | #if !defined(SOCKET_ERROR) 53 | #define SOCKET_ERROR -1 54 | #endif 55 | #define SOCKETBUFFER_INTERRUPTED -2 /* must be the same value as TCPSOCKET_INTERRUPTED */ 56 | 57 | void SocketBuffer_initialize(); 58 | void SocketBuffer_terminate(); 59 | void SocketBuffer_cleanup(int socket); 60 | char* SocketBuffer_getQueuedData(int socket, int bytes, int* actual_len); 61 | int SocketBuffer_getQueuedChar(int socket, char* c); 62 | void SocketBuffer_interrupted(int socket, int actual_len); 63 | char* SocketBuffer_complete(int socket); 64 | void SocketBuffer_queueChar(int socket, char c); 65 | 66 | void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int total, int bytes); 67 | pending_writes* SocketBuffer_getWrite(int socket); 68 | int SocketBuffer_writeComplete(int socket); 69 | pending_writes* SocketBuffer_updateWrite(int socket, char* topic, char* payload); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /rsmb/src/Clients.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /** 18 | * @file 19 | * client utility functions 20 | */ 21 | 22 | #include "Clients.h" 23 | 24 | #include 25 | #include 26 | 27 | 28 | /** 29 | * List callback function for comparing clients by clientid 30 | * @param a first integer value 31 | * @param b second integer value 32 | * @return boolean indicating whether a and b are equal 33 | */ 34 | #include "StackTrace.h" 35 | 36 | int clientIDCompare(void* a, void* b, int value) 37 | { 38 | char* as = ((Clients*)a)->clientID; 39 | char* bs = (value) ? ((Clients*)b)->clientID : (char*)b; 40 | 41 | return strcmp(as, bs); 42 | } 43 | 44 | 45 | /** 46 | * List callback function for comparing clients by socket 47 | * @param a first integer value 48 | * @param b second integer value 49 | * @return boolean indicating whether a and b are equal 50 | */ 51 | int clientSocketCompare(void* a, void* b, int value) 52 | { 53 | int ai = ((Clients*)a)->socket; 54 | int bi = (value) ? ((Clients*)b)->socket : *(int*)b; 55 | 56 | return (ai > bi) ? -1 : (ai == bi) ? 0 : 1; 57 | } 58 | 59 | 60 | int queuedMsgsCount(Clients* aClient) 61 | { 62 | int i, 63 | count = 0; 64 | 65 | for (i = 0; i < PRIORITY_MAX; ++i) 66 | count += aClient->queuedMsgs[i]->count; 67 | return count; 68 | } 69 | 70 | 71 | #if defined(MQTTS) 72 | int clientAddrCompare(void* a, void* b, int value) 73 | { 74 | //Clients* client = (Clients*)a; 75 | 76 | /* if client->addr is NULL (which it can be, for Bridge clients for example), return false. */ 77 | //return (client->addr) ? strcmp(client->addr, (char*)b) == 0 : 0; 78 | 79 | char* as = ((Clients*)a)->addr; 80 | char* bs = (value) ? ((Clients*)b)->addr : (char*)b; 81 | 82 | return strcmp(as, bs); 83 | } 84 | #endif 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RSMB: Really Small Message Broker 2 | ================================= 3 | 4 | The Really Small Message Broker is a server implementation of the MQTT and MQTT-SN protocols. Any client that implements this protocol properly can use this server for sending and receiving messages. 5 | 6 | The main reason for using RSMB over the main [Mosquitto](http://mosquitto.org/) codebase is that Mosquitto doesn't currently have support for the MQTT-SN protocol. 7 | 8 | 9 | ## Project History 10 | 11 | After several IBM servers were produced during the 2000s, Really Small Message Broker (RSMB) was released onto IBM alphaWorks in 2008. It's aim was to be a minimalist MQTT server, and according to the usual alphaWorks practices, was closed source and released under an evaluation-only license. During the following two years, it gained a small but enthusiastic following. In 2010, Roger Light learned about MQTT and RSMB from an Andy Stanford-Clark presentation. He created Mosquitto to be an open source alternative to RSMB. 12 | 13 | RSMB has had MQTT-SN capabilities added but not released outside of IBM. Now we have the chance to bring Mosquitto and RSMB back together as one Eclipse project, taking advantage of the collaboration of the authors of both previous projects. 14 | 15 | You can read more about the background of RSMB on the Eclipse project page for Mosquitto: 16 | https://www.eclipse.org/proposals/technology.mosquitto/ 17 | 18 | 19 | ## Getting started 20 | 21 | RSMB has been tested on Linux, Mac OS and Windows. 22 | 23 | To compile on Linux and Mac, it should be as simple as: 24 | 25 | ``` 26 | cd rsmb/src 27 | make 28 | ``` 29 | 30 | For more detailed information, see the rsmb/doc/gettingstarted.htm document. 31 | 32 | 33 | ## Sample Configuration 34 | 35 | ``` 36 | # Uncomment this to show you packets being sent and received 37 | #trace_output protocol 38 | 39 | # Normal MQTT listener 40 | listener 1883 INADDR_ANY 41 | ipv6 true 42 | 43 | # MQTT-SN listener 44 | listener 1883 INADDR_ANY mqtts 45 | ipv6 true 46 | ``` 47 | 48 | For a more complex example, see Ian Craggs' blog post: 49 | http://modelbasedtesting.co.uk/?p=44 50 | 51 | 52 | ## Links 53 | 54 | - Source code repository: 55 | - Find existing bugs or submit a new bug: 56 | - Mailing-list: 57 | 58 | 59 | [![Travis Build Status (master)](https://travis-ci.org/eclipse/mosquitto.rsmb.svg?branch=master)](https://travis-ci.org/eclipse/mosquitto.rsmb) 60 | -------------------------------------------------------------------------------- /amqtdd/src/SocketBuffer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(SOCKETBUFFER_H) 18 | #define SOCKETBUFFER_H 19 | 20 | #if defined(WIN32) 21 | /* default on Windows is 64 - increase to make Linux and Windows the same */ 22 | #define FD_SETSIZE 1024 23 | #include "winsock2.h" 24 | #else 25 | #include 26 | #endif 27 | 28 | #if defined(WIN32) 29 | typedef WSABUF iobuf; 30 | #else 31 | typedef struct iovec iobuf; 32 | #endif 33 | 34 | typedef struct 35 | { 36 | int socket; 37 | int index, headerlen; 38 | char fixed_header[8]; // header plus up to 4 length bytes 39 | int buflen, // total length of the buffer 40 | datalen; // current length of data in buf 41 | char* buf; 42 | } socket_queue; 43 | 44 | typedef struct 45 | { 46 | int socket, total, count; 47 | unsigned long bytes; 48 | iobuf iovecs[6]; 49 | int free[6]; 50 | } pending_writes; 51 | 52 | #define SOCKETBUFFER_COMPLETE 0 53 | #if !defined(SOCKET_ERROR) 54 | #define SOCKET_ERROR -1 55 | #endif 56 | #define SOCKETBUFFER_INTERRUPTED -2 /* must be the same value as TCPSOCKET_INTERRUPTED */ 57 | 58 | void SocketBuffer_initialize(); 59 | void SocketBuffer_terminate(); 60 | void SocketBuffer_cleanup(int socket); 61 | char* SocketBuffer_getQueuedData(int socket, int bytes, int* actual_len); 62 | int SocketBuffer_getQueuedChar(int socket, char* c); 63 | void SocketBuffer_interrupted(int socket, int actual_len); 64 | char* SocketBuffer_complete(int socket); 65 | void SocketBuffer_queueChar(int socket, char c); 66 | 67 | void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int total, int bytes, int* buffree); 68 | pending_writes* SocketBuffer_getWrite(int socket); 69 | int SocketBuffer_writeComplete(int socket); 70 | pending_writes* SocketBuffer_updateWrite(int socket, char* topic, char* payload); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/MQTTSClient.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /* 18 | * Calls: 19 | * 20 | * - MQTTS_search(short radius) 21 | * can get multiple replies 22 | * no connection needed 23 | * 24 | * MQTTS_connect 25 | * gateway sends willtopicreq and willtopicmsg, so replies to these packets can be handled 26 | * internally by the client. The connect options can thus include will details as for MQTT 27 | * 28 | * - MQTTS_register(char* topicName) 29 | * 30 | * - MQTTS_publish 31 | * 1. client object, flags, topic, payload (in the case of QoS 0, 1 or 2) 32 | * 2. address, flags, topic, payload (in the case of QoS -1, or broadcasting) 33 | * 34 | * - MQTTS_subscribe 35 | * 36 | * - MQTTS_unsubscribe 37 | * 38 | * - MQTTS_willtopicupd 39 | * 40 | * - MQTTS_willmsgupd 41 | * 42 | * - MQTTS_disconnect 43 | * 44 | * - synchronous information retrieval 45 | * MQTTS_getGatewayInfo returns gateway id and address of next gateway 46 | * MQTTS_receive 47 | * MQTTS_waitForCompletion 48 | * MQTTS_isConnected 49 | * 50 | * - callbacks 51 | * typedef MQTTS_gatewayInfo 52 | * typedef int MQTTS_messageArrived 53 | * typedef void MQTTS_deliveryComplete 54 | * typedef void MQTTS_connectionLost 55 | * 56 | */ 57 | 58 | #if !defined(MQTTSCLIENT_H) 59 | #define MQTTSCLIENT_H 60 | 61 | #if defined(WIN32) 62 | #define DLLImport __declspec(dllimport) 63 | #define DLLExport __declspec(dllexport) 64 | #else 65 | #define DLLImport extern 66 | #define DLLExport 67 | #endif 68 | 69 | DLLExport int MQTTSClient_create(MQTTClient* handle, char* serverURI, char* clientId, 70 | int persistence_type, void* persistence_context); 71 | 72 | DLLExport int MQTTSClient_connect(MQTTSClient handle, MQTTSClient_connectOptions* options); 73 | -------------------------------------------------------------------------------- /about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | About 5 | 6 | 7 |

About This Content

8 | 9 |

December 9, 2013

10 |

License

11 | 12 |

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise 13 | indicated below, the Content is provided to you under the terms and conditions of the 14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL"). 15 | A copy of the EPL is available at 16 | http://www.eclipse.org/legal/epl-v10.html 17 | and a copy of the EDL is available at 18 | http://www.eclipse.org/org/documents/edl-v10.php. 19 | For purposes of the EPL, "Program" will mean the Content.

20 | 21 |

If you did not receive this Content directly from the Eclipse Foundation, the Content is 22 | being redistributed by another party ("Redistributor") and different terms and conditions may 23 | apply to your use of any object code in the Content. Check the Redistributor's license that was 24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise 25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content 26 | and such source code may be obtained at http://www.eclipse.org.

27 | 28 | 29 |

Third Party Content

30 |

The Content includes items that have been sourced from third parties as set out below. If you 31 | did not receive this Content directly from the Eclipse Foundation, the following is provided 32 | for informational purposes only, and you should look to the Redistributor's license for 33 | terms and conditions of use.

34 |

35 | Replace these sections with the relevant content, as described below. One section 36 | will be required for each third-party component contained within the plug-in

37 | bememext.h - from Andy's Binary Folding Editor (BE) version 21/11/05

38 | This header file is used to build an extension for BE which is used to display RSMB heap 39 | dumps for debugging. It is part of the BE package obtained from http://www.nyangau.org/ 40 | which is in the public domain. 41 |

42 |

43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /rsmb/src/tools/be/be.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | #/******************************************************************************* 4 | # * Copyright (c) 2008, 2013 IBM Corp. 5 | # * 6 | # * All rights reserved. This program and the accompanying materials 7 | # * are made available under the terms of the Eclipse Public License v1.0 8 | # * and Eclipse Distribution License v1.0 which accompany this distribution. 9 | # * 10 | # * The Eclipse Public License is available at 11 | # * http://www.eclipse.org/legal/epl-v10.html 12 | # * and the Eclipse Distribution License is available at 13 | # * http://www.eclipse.org/org/documents/edl-v10.php. 14 | # * 15 | # * Contributors: 16 | # * Nicholas O'Leary - initial API and implementation and/or initial documentation 17 | # *******************************************************************************/ 18 | 19 | use File::Spec; 20 | 21 | # usage: be.pl Broker.h ../rsmb.ini 22 | 23 | my $root = "."; 24 | my $output = "rsmb.ini"; 25 | my $srcDir; 26 | 27 | ARG:while($_ = shift ) 28 | { 29 | study; 30 | /^-h$/ and usage(); 31 | /-s(.*)/ and do { $root = $1 || shift ; next ARG;}; 32 | /-o(.*)/ and do { $output = $1|| shift ; next ARG;}; 33 | /[^-]|-[^so]/ and usage(); 34 | } 35 | 36 | sub usage { 37 | print " 38 | Usage: be.pl -s srcdir -o output 39 | -s srcdir : this is the directory containing Broker.h. default: '.' 40 | -o output : the file to write the be definition to. default: 'rsmb.ini' 41 | 42 | "; 43 | exit 0; 44 | } 45 | 46 | 47 | my %processedFiles = (); 48 | 49 | sub processFile { 50 | my $out = $_[0]; 51 | my $file = $_[1]; 52 | if (!exists($processedFiles{$file})) { 53 | open(IN,"<$file") or die "Failed to process '$file': $!"; 54 | my @lines = ; 55 | close(IN); 56 | print $out "// ************** $file **************\n"; 57 | my $inblock = 0; 58 | foreach $line (@lines) { 59 | $line =~ s/\r\n/\n/g; 60 | if ($inblock) { 61 | if ($line =~ /^(.*)BE\*\//) { 62 | print $out $1; 63 | $inblock = 0; 64 | } else { 65 | if ($line =~ /^include "(.*)"/) { 66 | processFile($out, File::Spec->catfile(($root),"$1.h")); 67 | } else { 68 | print $out $line; 69 | } 70 | } 71 | } else { 72 | if ($line =~ /^\/\*BE(.*)/) { 73 | print $out $1; 74 | $inblock = 1; 75 | } 76 | } 77 | } 78 | $processedFiles{$file} = 1; 79 | } 80 | } 81 | 82 | open(OUT,"> $output") or die "$output: $!"; 83 | processFile(*OUT, File::Spec->catfile(($root),'Broker.h')); 84 | close(OUT); 85 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTProtocolClient.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPROTOCOLCLIENT_H) 19 | #define MQTTPROTOCOLCLIENT_H 20 | 21 | #include "Broker.h" 22 | #include "LinkedList.h" 23 | #include "SubsEngine.h" 24 | #include "MQTTPacket.h" 25 | #include "Clients.h" 26 | #include "Log.h" 27 | #include "MQTTProtocol.h" 28 | #include "Messages.h" 29 | 30 | /** 31 | * MQTT protocol maximum message id - as defined in the spec. 32 | */ 33 | #define MAX_MSG_ID 65535 34 | 35 | /** 36 | * MQTT protocol maximum client id length - as defined in the spec. 37 | */ 38 | #define MAX_CLIENTID_LEN 23 39 | 40 | int MQTTProtocol_assignMsgId(Clients* client); 41 | int MQTTProtocol_startPublish(Clients* pubclient, Publish* publish, int qos, int retained, Messages** m); 42 | int MQTTProtocol_queuePublish(Clients* pubclient, Publish* publish, int qos, int retained, int priority, Messages** m); 43 | int MQTTProtocol_startOrQueuePublish(Clients* pubclient, Publish* publish, int qos, int retained, int priority, Messages** m); 44 | Messages* MQTTProtocol_createMessage(Publish* publish, Messages** mm, int qos, int retained); 45 | Publications* MQTTProtocol_storePublication(Publish* publish, int* len); 46 | int messageIDCompare(void* a, void* b); 47 | int MQTTProtocol_assignMsgId(Clients* client); 48 | 49 | int MQTTProtocol_handlePublishes(void* pack, int sock); 50 | int MQTTProtocol_handlePubacks(void* pack, int sock); 51 | int MQTTProtocol_handlePubrecs(void* pack, int sock); 52 | int MQTTProtocol_handlePubrels(void* pack, int sock); 53 | int MQTTProtocol_handlePubcomps(void* pack, int sock); 54 | 55 | void MQTTProtocol_keepalive(time_t); 56 | int MQTTProtocol_processQueued(Clients* client); 57 | int MQTTProtocol_retry(time_t, int); 58 | void MQTTProtocol_retries(time_t now, Clients* client); 59 | void MQTTProtocol_freeClient(Clients* client); 60 | void MQTTProtocol_removeQoS0Messages(List* msgList); 61 | void MQTTProtocol_emptyMessageList(List* msgList); 62 | void MQTTProtocol_freeMessageList(List* msgList); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /rsmb/src/MQTTProtocolClient.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(MQTTPROTOCOLCLIENT_H) 19 | #define MQTTPROTOCOLCLIENT_H 20 | 21 | #include "Broker.h" 22 | #include "LinkedList.h" 23 | #include "SubsEngine.h" 24 | #include "MQTTPacket.h" 25 | #include "Clients.h" 26 | #include "Log.h" 27 | #include "MQTTProtocol.h" 28 | #include "Messages.h" 29 | 30 | /** 31 | * MQTT protocol maximum message id - as defined in the spec. 32 | */ 33 | #define MAX_MSG_ID 65535 34 | 35 | /** 36 | * MQTT protocol maximum client id length - as defined in the spec. 37 | */ 38 | #define MAX_CLIENTID_LEN 23 39 | 40 | int MQTTProtocol_assignMsgId(Clients* client); 41 | int MQTTProtocol_startPublish(Clients* pubclient, Publish* publish, int qos, int retained, Messages** m); 42 | int MQTTProtocol_queuePublish(Clients* pubclient, Publish* publish, int qos, int retained, int priority, Messages** m); 43 | Messages* MQTTProtocol_createMessage(Publish* publish, Messages** mm, int qos, int retained); 44 | Publications* MQTTProtocol_storePublication(Publish* publish, int* len); 45 | void MQTTProtocol_removePublication(Publications* p); 46 | int messageIDCompare(void* a, void* b); 47 | int MQTTProtocol_assignMsgId(Clients* client); 48 | 49 | int MQTTProtocol_handlePublishes(void* pack, int sock, Clients* client); 50 | int MQTTProtocol_handlePubacks(void* pack, int sock, Clients* client); 51 | int MQTTProtocol_handlePubrecs(void* pack, int sock, Clients* client); 52 | int MQTTProtocol_handlePubrels(void* pack, int sock, Clients* client); 53 | int MQTTProtocol_handlePubcomps(void* pack, int sock, Clients* client); 54 | 55 | void MQTTProtocol_keepalive(time_t); 56 | int MQTTProtocol_processQueued(Clients* client); 57 | int MQTTProtocol_retry(time_t, int); 58 | void MQTTProtocol_retries(time_t now, Clients* client); 59 | void MQTTProtocol_freeClient(Clients* client); 60 | void MQTTProtocol_removeQoS0Messages(List* msgList); 61 | void MQTTProtocol_emptyMessageList(List* msgList); 62 | void MQTTProtocol_freeMessageList(List* msgList); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /rsmb/src/Log.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | #if !defined(LOG_H) 17 | #define LOG_H 18 | 19 | /*BE 20 | map LOG_LEVELS 21 | { 22 | "TRACE_MAXIMUM" 1 23 | "TRACE_MEDIUM" 2 24 | "TRACE_MINIMUM" 3 25 | "TRACE_PROTOCOL" 4 26 | 27 | "CONFIG" 5 28 | "DETAIL" 6 29 | "INFO" 7 30 | "AUDIT" 8 31 | "WARNING" 9 32 | "ERROR" 10 33 | "SEVERE" 11 34 | "FATAL" 12 35 | } 36 | BE*/ 37 | 38 | enum { 39 | TRACE_MAXIMUM = 1, 40 | TRACE_MEDIUM, 41 | TRACE_MINIMUM, 42 | TRACE_PROTOCOL, 43 | LOG_CONFIG, 44 | LOG_DETAIL, 45 | LOG_INFO, 46 | LOG_INFORMATION = LOG_INFO, 47 | LOG_AUDIT, 48 | LOG_WARNING, 49 | LOG_WARN = LOG_WARNING, 50 | LOG_ERROR, 51 | LOG_SEVERE, 52 | LOG_FATAL, 53 | } Log_levels; 54 | 55 | 56 | /*BE 57 | def trace_settings_type 58 | { 59 | n32 map LOG_LEVELS "log_level" 60 | n32 dec "max_log_entries" 61 | n32 map LOG_LEVELS "trace_level" 62 | n32 dec "max_trace_entries" 63 | n32 dec "trace_output_level" 64 | n32 dec "isservice" 65 | } 66 | BE*/ 67 | typedef struct 68 | { 69 | int log_level; /**< log level */ 70 | int max_log_entries; /**< max no of entries in the log buffer */ 71 | int trace_level; /**< trace level */ 72 | int max_trace_entries; /**< max no of entries in the trace buffer */ 73 | int trace_output_level; /**< trace level to output to destination */ 74 | int isdaemon; /**< are we running as Linux daemon, or Windows service? */ 75 | } trace_settings_type; 76 | 77 | extern trace_settings_type trace_settings; 78 | 79 | #define LOG_PROTOCOL TRACE_PROTOCOL 80 | #define TRACE_MAX TRACE_MAXIMUM 81 | #define TRACE_MIN TRACE_MINIMUM 82 | #define TRACE_MED TRACE_MEDIUM 83 | 84 | #define MSG_PREFIX "CWNAN" 85 | 86 | int Log_initialize(); 87 | void Log_terminate(); 88 | 89 | void Log_setPublish(int flag); 90 | 91 | void Log(int, int, char *, ...); 92 | void Log_stackTrace(int, int, int, const char*, int, int*); 93 | 94 | #include 95 | 96 | FILE* Log_destToFile(char* dest); 97 | int Log_dumpTrace(char *); 98 | 99 | int Log_traceOutput(char*); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /amqtdd/src/Log.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(LOG_H) 18 | #define LOG_H 19 | 20 | /*BE 21 | map LOG_LEVELS 22 | { 23 | "TRACE_MAXIMUM" 1 24 | "TRACE_MEDIUM" 2 25 | "TRACE_MINIMUM" 3 26 | "TRACE_PROTOCOL" 4 27 | 28 | "CONFIG" 5 29 | "DETAIL" 6 30 | "INFO" 7 31 | "AUDIT" 8 32 | "WARNING" 9 33 | "ERROR" 10 34 | "SEVERE" 11 35 | "FATAL" 12 36 | } 37 | BE*/ 38 | 39 | enum { 40 | TRACE_MAXIMUM = 1, 41 | TRACE_MEDIUM, 42 | TRACE_MINIMUM, 43 | TRACE_PROTOCOL, 44 | LOG_CONFIG, 45 | LOG_DETAIL, 46 | LOG_INFO, 47 | LOG_INFORMATION = LOG_INFO, 48 | LOG_AUDIT, 49 | LOG_WARNING, 50 | LOG_WARN = LOG_WARNING, 51 | LOG_ERROR, 52 | LOG_SEVERE, 53 | LOG_FATAL, 54 | } Log_levels; 55 | 56 | 57 | /*BE 58 | def trace_settings_type 59 | { 60 | n32 map LOG_LEVELS "log_level" 61 | n32 dec "max_log_entries" 62 | n32 map LOG_LEVELS "trace_level" 63 | n32 dec "max_trace_entries" 64 | n32 dec "trace_output_level" 65 | n32 dec "isservice" 66 | } 67 | BE*/ 68 | typedef struct 69 | { 70 | int log_level; /**< log level */ 71 | int max_log_entries; /**< max no of entries in the log buffer */ 72 | int trace_level; /**< trace level */ 73 | int max_trace_entries; /**< max no of entries in the trace buffer */ 74 | int trace_output_level; /**< trace level to output to destination */ 75 | int isdaemon; /**< are we running as Linux daemon, or Windows service? */ 76 | } trace_settings_type; 77 | 78 | extern trace_settings_type trace_settings; 79 | 80 | #define LOG_PROTOCOL TRACE_PROTOCOL 81 | #define TRACE_MAX TRACE_MAXIMUM 82 | #define TRACE_MIN TRACE_MINIMUM 83 | #define TRACE_MED TRACE_MEDIUM 84 | 85 | #define MSG_PREFIX "CWNAN" 86 | 87 | int Log_initialize(); 88 | void Log_terminate(); 89 | 90 | void Log_setPublish(int flag); 91 | 92 | void Log(int, int, char *, ...); 93 | void Log_stackTrace(int, int, int, const char*, int, int*); 94 | 95 | #include 96 | 97 | FILE* Log_destToFile(char* dest); 98 | int Log_dumpTrace(char *); 99 | 100 | #include "LinkedList.h" 101 | 102 | List* Log_getTraceBuffer(); 103 | List* Log_getLogBuffer(); 104 | 105 | int Log_traceOutput(char*); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /amqtdd/src/StackTrace.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "StackTrace.h" 18 | #include "Log.h" 19 | #include "LinkedList.h" 20 | 21 | #include "Clients.h" 22 | 23 | #include "Broker.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "Heap.h" 30 | 31 | /*BE 32 | def STACKENTRY 33 | { 34 | n32 ptr STRING open "name" 35 | n32 dec "line" 36 | } 37 | 38 | defList(STACKENTRY) 39 | BE*/ 40 | 41 | #define MAX_STACK_DEPTH 30 42 | #define MAX_FUNCTION_NAME_LENGTH 30 43 | 44 | typedef struct 45 | { 46 | char name[MAX_FUNCTION_NAME_LENGTH]; 47 | int line; 48 | } stackEntry; 49 | 50 | static int maxdepth = 0; 51 | static int current_depth = 0; 52 | 53 | #include "StackTrace.h" 54 | 55 | static stackEntry callstack[MAX_STACK_DEPTH]; 56 | 57 | void StackTrace_entry(const char* name, int line, int trace_level) 58 | { 59 | if (trace_level != -1) 60 | Log_stackTrace(trace_level, 29, current_depth, name, line, NULL); 61 | strncpy(callstack[current_depth].name, name, sizeof(callstack[0].name)-1); 62 | callstack[current_depth++].line = line; 63 | if (current_depth > maxdepth) 64 | maxdepth = current_depth; 65 | if (current_depth >= MAX_STACK_DEPTH) 66 | Log(LOG_FATAL, 13, "Max stack depth exceeded"); 67 | } 68 | 69 | 70 | void StackTrace_exit(const char* name, int line, void* rc, int trace_level) 71 | { 72 | if (--current_depth < 0) 73 | Log(LOG_FATAL, 13, "Minimum stack depth exceeded"); 74 | if (strncmp(callstack[current_depth].name, name, sizeof(callstack[0].name)-1) != 0) 75 | Log(LOG_FATAL, 13, "Stack mismatch. Entry:%s Exit:%s\n", callstack[current_depth].name, name); 76 | if (trace_level != -1) 77 | Log_stackTrace(trace_level, (rc == NULL) ? 30 : 31, current_depth, name, line, rc); 78 | } 79 | 80 | 81 | void StackTrace_dumpStack(char* dest) 82 | { 83 | FILE* file = Log_destToFile(dest); 84 | int i = current_depth - 1; 85 | 86 | fprintf(file, "=========== Start of stack trace ==========\n"); 87 | if (i >= 0) 88 | { 89 | fprintf(file, "%s (%d)\n", callstack[i].name, callstack[i].line); 90 | while (--i >= 0) 91 | fprintf(file, " at %s (%d)\n", callstack[i].name, callstack[i].line); 92 | } 93 | fprintf(file, "=========== End of stack trace ==========\n\n"); 94 | if (file != stdout && file != stderr && file != NULL) 95 | fclose(file); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /rsmb/src/StackTrace.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "StackTrace.h" 18 | #include "Log.h" 19 | #include "LinkedList.h" 20 | 21 | #include "Clients.h" 22 | 23 | #include "Broker.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "Heap.h" 30 | 31 | /*BE 32 | def STACKENTRY 33 | { 34 | n32 ptr STRING open "name" 35 | n32 dec "line" 36 | } 37 | 38 | defList(STACKENTRY) 39 | BE*/ 40 | 41 | #define MAX_STACK_DEPTH 30 42 | #define MAX_FUNCTION_NAME_LENGTH 30 43 | 44 | typedef struct 45 | { 46 | char name[MAX_FUNCTION_NAME_LENGTH]; 47 | int line; 48 | } stackEntry; 49 | 50 | static int maxdepth = 0; 51 | static int current_depth = 0; 52 | 53 | #include "StackTrace.h" 54 | 55 | static stackEntry callstack[MAX_STACK_DEPTH]; 56 | 57 | void StackTrace_entry(const char* name, int line, int trace_level) 58 | { 59 | if (trace_level != -1) 60 | Log_stackTrace(trace_level, 29, current_depth, name, line, NULL); 61 | strncpy(callstack[current_depth].name, name, sizeof(callstack[0].name)-1); 62 | callstack[current_depth++].line = line; 63 | if (current_depth > maxdepth) 64 | maxdepth = current_depth; 65 | if (current_depth >= MAX_STACK_DEPTH) 66 | Log(LOG_FATAL, 13, "Max stack depth exceeded"); 67 | } 68 | 69 | 70 | void StackTrace_exit(const char* name, int line, void* rc, int trace_level) 71 | { 72 | if (--current_depth < 0) 73 | Log(LOG_FATAL, 13, "Minimum stack depth exceeded"); 74 | if (strncmp(callstack[current_depth].name, name, sizeof(callstack[0].name)-1) != 0) 75 | Log(LOG_FATAL, 13, "Stack mismatch. Entry:%s Exit:%s\n", callstack[current_depth].name, name); 76 | if (trace_level != -1) 77 | Log_stackTrace(trace_level, (rc == NULL) ? 30 : 31, current_depth, name, line, rc); 78 | } 79 | 80 | 81 | void StackTrace_dumpStack(char* dest) 82 | { 83 | FILE* file = Log_destToFile(dest); 84 | int i = current_depth - 1; 85 | 86 | fprintf(file, "=========== Start of stack trace ==========\n"); 87 | if (i >= 0) 88 | { 89 | fprintf(file, "%s (%d)\n", callstack[i].name, callstack[i].line); 90 | while (--i >= 0) 91 | fprintf(file, " at %s (%d)\n", callstack[i].name, callstack[i].line); 92 | } 93 | fprintf(file, "=========== End of stack trace ==========\n\n"); 94 | if (file != stdout && file != stderr && file != NULL) 95 | fclose(file); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /amqtdd/src/StackTrace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef STACKTRACE_H_ 18 | #define STACKTRACE_H_ 19 | 20 | #if defined(NOSTACKTRACE) 21 | #define FUNC_ENTRY 22 | #define FUNC_ENTRY_NOLOG 23 | #define FUNC_ENTRY_MED 24 | #define FUNC_ENTRY_MAX 25 | #define FUNC_EXIT 26 | #define FUNC_EXIT_NOLOG 27 | #define FUNC_EXIT_MED 28 | #define FUNC_EXIT_MAX 29 | #define FUNC_EXIT_RC(x) 30 | #define FUNC_EXIT_MED_RC(x) 31 | #define FUNC_EXIT_MAX_RC(x) 32 | #else 33 | #if defined(WIN32) 34 | #define inline __inline 35 | #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM) 36 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1) 37 | #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM) 38 | #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM) 39 | #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM) 40 | #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1) 41 | #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM) 42 | #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM) 43 | #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM) 44 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM) 45 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM) 46 | #else 47 | #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM) 48 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1) 49 | #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM) 50 | #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM) 51 | #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM) 52 | #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1) 53 | #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM) 54 | #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM) 55 | #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM) 56 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM) 57 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM) 58 | #endif 59 | #endif 60 | 61 | void StackTrace_entry(const char* name, int line, int trace); 62 | void StackTrace_exit(const char* name, int line, void* return_value, int trace); 63 | 64 | void StackTrace_dumpStack(char* dest); 65 | 66 | #endif /* STACKTRACE_H_ */ 67 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTPROTOCOL_H) 18 | #define MQTTPROTOCOL_H 19 | 20 | #include "Broker.h" 21 | #include "LinkedList.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTPacket.h" 24 | #include "Clients.h" 25 | 26 | #define MAX_MSG_ID 65535 27 | #define MAX_CLIENTID_LEN 23 28 | #define INTERNAL_CLIENTID "$SYS/INTERNAL/CLIENT" 29 | 30 | /*BE 31 | map CONNACK_RETURN_CODES 32 | { 33 | "CONNACK_CONNECTION_ACCEPTED" . 34 | "CONNACK_UNACCEPTABLE_PROTOCOL_VERSION" . 35 | "CONNACK_IDENTIFIER_REJECTED" . 36 | "CONNACK_BROKER_UNAVAILABLE" . 37 | "CONNACK_BAD_USERNAME_OR_PASSWORD" . 38 | "CONNACK_NOT_AUTHORIZED" . 39 | "CONNACK_NONE_RECEIVED" 99 40 | } 41 | BE*/ 42 | 43 | enum connack_return_codes 44 | { 45 | CONNACK_CONNECTION_ACCEPTED, CONNACK_UNACCEPTABLE_PROTOCOL_VERSION, 46 | CONNACK_IDENTIFIER_REJECTED, CONNACK_BROKER_UNAVAILABLE, 47 | CONNACK_BAD_USERNAME_OR_PASSWORD, CONNACK_NOT_AUTHORIZED, CONNACK_NONE_RECEIVED=99 48 | }; 49 | 50 | typedef struct 51 | { 52 | int socket; 53 | Publications* p; 54 | } pending_write; 55 | 56 | 57 | typedef struct 58 | { 59 | List publications; 60 | List pending_writes; /* for qos 0 writes not complete */ 61 | } MQTTProtocol; 62 | 63 | int MQTTProtocol_reinitialize(); 64 | int MQTTProtocol_initialize(BrokerStates*); 65 | void MQTTProtocol_shutdown(int terminate); 66 | void MQTTProtocol_checkPendingWrites(); 67 | int MQTTProtocol_housekeeping(int more_work); 68 | void MQTTProtocol_timeslice(int sock, Clients* client); 69 | void MQTTProtocol_clean_clients(List* clients); 70 | void MQTTProtocol_terminate(); 71 | void MQTTProtocol_closeSession(Clients* client, int unclean); 72 | void MQTTProtocol_removeAllSubscriptions(char* clientID); 73 | void MQTTProtocol_sys_publish(char* topic, char* string); 74 | 75 | int MQTTProtocol_handleConnects(void* pack, int sock); 76 | int MQTTProtocol_handlePingreqs(void* pack, int sock); 77 | int MQTTProtocol_handleDisconnects(void* pack, int sock); 78 | void MQTTProtocol_processRetaineds(Clients* client, char* topic, int qos, int priority); 79 | int MQTTProtocol_handleSubscribes(void* pack, int sock); 80 | int MQTTProtocol_handleUnsubscribes(void* pack, int sock); 81 | 82 | #if defined(MQTTS) 83 | void MQTTProtocol_setWillTopic(Clients* client, char* topic, int retained, int qos); 84 | void MQTTProtocol_setWillMsg(Clients* client, char* msg); 85 | void MQTTProtocol_clearWill(Clients* client); 86 | #endif 87 | 88 | #if defined(NO_BRIDGE) 89 | #include "MQTTProtocolClient.h" 90 | #else 91 | #include "MQTTProtocolOut.h" 92 | #endif 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /rsmb/src/StackTrace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef STACKTRACE_H_ 18 | #define STACKTRACE_H_ 19 | 20 | #if defined(HIGH_PERFORMANCE) 21 | #define NOSTACKTRACE 1 22 | #endif 23 | 24 | #if defined(NOSTACKTRACE) 25 | #define FUNC_ENTRY 26 | #define FUNC_ENTRY_NOLOG 27 | #define FUNC_ENTRY_MED 28 | #define FUNC_ENTRY_MAX 29 | #define FUNC_EXIT 30 | #define FUNC_EXIT_NOLOG 31 | #define FUNC_EXIT_MED 32 | #define FUNC_EXIT_MAX 33 | #define FUNC_EXIT_RC(x) 34 | #define FUNC_EXIT_MED_RC(x) 35 | #define FUNC_EXIT_MAX_RC(x) 36 | #else 37 | #if defined(WIN32) 38 | #define inline __inline 39 | #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM) 40 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1) 41 | #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM) 42 | #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM) 43 | #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM) 44 | #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1) 45 | #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM) 46 | #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM) 47 | #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM) 48 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM) 49 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM) 50 | #else 51 | #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM) 52 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1) 53 | #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM) 54 | #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM) 55 | #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM) 56 | #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1) 57 | #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM) 58 | #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM) 59 | #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM) 60 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM) 61 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM) 62 | #endif 63 | #endif 64 | 65 | void StackTrace_entry(const char* name, int line, int trace); 66 | void StackTrace_exit(const char* name, int line, void* return_value, int trace); 67 | 68 | void StackTrace_dumpStack(char* dest); 69 | 70 | #endif /* STACKTRACE_H_ */ 71 | -------------------------------------------------------------------------------- /rsmb/src/LinkedList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(LINKEDLIST_H) 19 | #define LINKEDLIST_H 20 | 21 | /*BE 22 | defm defList(T) 23 | 24 | def T concat Item 25 | { 26 | at 4 27 | n32 ptr T concat Item suppress "next" 28 | at 0 29 | n32 ptr T concat Item suppress "prev" 30 | at 8 31 | n32 ptr T id2str(T) 32 | at 12 33 | n32 suppress "size" 34 | } 35 | 36 | def T concat List 37 | { 38 | n32 ptr T concat Item suppress "first" 39 | n32 ptr T concat Item suppress "last" 40 | n32 ptr T concat Item suppress "current" 41 | n32 dec "count" 42 | n32 suppress "size" 43 | } 44 | endm 45 | 46 | defList(INT) 47 | defList(STRING) 48 | defList(TMP) 49 | 50 | BE*/ 51 | 52 | /** 53 | * Structure to hold all data for one list element 54 | */ 55 | typedef struct ListElementStruct 56 | { 57 | struct ListElementStruct *prev, /**< pointer to previous list element */ 58 | *next; /**< pointer to next list element */ 59 | void* content; /**< pointer to element content */ 60 | int size; /**< size of content */ 61 | } ListElement; 62 | 63 | 64 | /** 65 | * Structure to hold all data for one list 66 | */ 67 | typedef struct 68 | { 69 | ListElement *first, /**< first element in the list */ 70 | *last, /**< last element in the list */ 71 | *current; /**< current element in the list, for iteration */ 72 | int count, /**< no of items */ 73 | size; /**< heap storage used */ 74 | } List; 75 | 76 | void ListZero(List*); 77 | List* ListInitialize(); 78 | 79 | void ListAppend(List* aList, void* content, int size); 80 | void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, int size); 81 | 82 | int ListRemove(List* aList, void* content); 83 | int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*)); 84 | int ListRemoveHead(List* aList); 85 | void ListRemoveHeadAddTail(List* aList, void* content, int size); 86 | void* ListPopTail(List* aList); 87 | 88 | int ListDetach(List* aList, void* content); 89 | int ListDetachItem(List* aList, void* content, int(*callback)(void*, void*)); 90 | 91 | void ListFree(List* aList); 92 | void ListEmpty(List* aList); 93 | void ListFreeNoContent(List* aList); 94 | 95 | ListElement* ListNextElement(List* aList, ListElement** pos); 96 | ListElement* ListPrevElement(List* aList, ListElement** pos); 97 | 98 | ListElement* ListFind(List* aList, void* content); 99 | ListElement* ListFindItem(List* aList, void* content, int(*callback)(void*, void*)); 100 | 101 | int intcompare(void* a, void* b); 102 | int stringcompare(void* a, void* b); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /amqtdd/src/LinkedList.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(LINKEDLIST_H) 19 | #define LINKEDLIST_H 20 | 21 | /*BE 22 | defm defList(T) 23 | 24 | def T concat Item 25 | { 26 | at 4 27 | n32 ptr T concat Item suppress "next" 28 | at 0 29 | n32 ptr T concat Item suppress "prev" 30 | at 8 31 | n32 ptr T id2str(T) 32 | at 12 33 | n32 suppress "size" 34 | } 35 | 36 | def T concat List 37 | { 38 | n32 ptr T concat Item suppress "first" 39 | n32 ptr T concat Item suppress "last" 40 | n32 ptr T concat Item suppress "current" 41 | n32 dec "count" 42 | n32 suppress "size" 43 | } 44 | endm 45 | 46 | defList(INT) 47 | defList(STRING) 48 | defList(TMP) 49 | 50 | BE*/ 51 | 52 | /** 53 | * Structure to hold all data for one list element 54 | */ 55 | typedef struct ListElementStruct 56 | { 57 | struct ListElementStruct *prev, /**< pointer to previous list element */ 58 | *next; /**< pointer to next list element */ 59 | void* content; /**< pointer to element content */ 60 | int size; /**< size of content */ 61 | } ListElement; 62 | 63 | 64 | /** 65 | * Structure to hold all data for one list 66 | */ 67 | typedef struct 68 | { 69 | ListElement *first, /**< first element in the list */ 70 | *last, /**< last element in the list */ 71 | *current; /**< current element in the list, for iteration */ 72 | int count, /**< no of items */ 73 | size; /**< heap storage used */ 74 | } List; 75 | 76 | void ListZero(List*); 77 | List* ListInitialize(); 78 | 79 | void ListAppend(List* aList, void* content, int size); 80 | void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, int size); 81 | 82 | int ListRemove(List* aList, void* content); 83 | int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*)); 84 | int ListRemoveHead(List* aList); 85 | void ListRemoveHeadAddTail(List* aList, void* content, int size); 86 | void* ListPopTail(List* aList); 87 | 88 | int ListDetach(List* aList, void* content); 89 | int ListDetachItem(List* aList, void* content, int(*callback)(void*, void*)); 90 | 91 | void ListFree(List* aList); 92 | void ListEmpty(List* aList); 93 | void ListFreeNoContent(List* aList); 94 | 95 | ListElement* ListNextElement(List* aList, ListElement** pos); 96 | ListElement* ListPrevElement(List* aList, ListElement** pos); 97 | 98 | ListElement* ListFind(List* aList, void* content); 99 | ListElement* ListFindItem(List* aList, void* content, int(*callback)(void*, void*)); 100 | 101 | int intcompare(void* a, void* b); 102 | int stringcompare(void* a, void* b); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /amqtdd/src/Tree.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(TREE_H) 19 | #define TREE_H 20 | 21 | /*BE 22 | defm defTree(T) // macro to define a tree 23 | 24 | def T concat Node 25 | { 26 | n32 ptr T concat Node "parent" 27 | n32 ptr T concat Node "left" 28 | n32 ptr T concat Node "right" 29 | n32 ptr T id2str(T) 30 | n32 suppress "size" 31 | } 32 | 33 | 34 | def T concat Tree 35 | { 36 | struct 37 | { 38 | n32 ptr T concat Node suppress "root" 39 | n32 ptr DATA suppress "compare" 40 | } 41 | struct 42 | { 43 | n32 ptr T concat Node suppress "root" 44 | n32 ptr DATA suppress "compare" 45 | } 46 | n32 dec "count" 47 | n32 dec suppress "size" 48 | } 49 | 50 | endm 51 | 52 | defTree(INT) 53 | defTree(STRING) 54 | defTree(TMP) 55 | 56 | BE*/ 57 | 58 | /** 59 | * Structure to hold all data for one list element 60 | */ 61 | typedef struct NodeStruct 62 | { 63 | struct NodeStruct *parent, /**< pointer to parent tree node, in case we need it */ 64 | *child[2]; /**< pointers to child tree nodes 0 = left, 1 = right */ 65 | void* content; /**< pointer to element content */ 66 | int size; /**< size of content */ 67 | unsigned int red : 1; 68 | } Node; 69 | 70 | 71 | /** 72 | * Structure to hold all data for one tree 73 | */ 74 | typedef struct 75 | { 76 | struct 77 | { 78 | Node *root; /**< root node pointer */ 79 | int (*compare)(void*, void*, int); /**< comparison function */ 80 | } index[2]; 81 | int indexes, /**< no of indexes into tree */ 82 | count, /**< no of items */ 83 | size; /**< heap storage used */ 84 | unsigned int heap_tracking : 1; /**< switch on heap tracking for this tree? */ 85 | unsigned int allow_duplicates : 1; /**< switch to allow duplicate entries */ 86 | } Tree; 87 | 88 | 89 | Tree* TreeInitialize(int(*compare)(void*, void*, int)); 90 | void TreeInitializeNoMalloc(Tree* aTree, int(*compare)(void*, void*, int)); 91 | void TreeAddIndex(Tree* aTree, int(*compare)(void*, void*, int)); 92 | 93 | void* TreeAdd(Tree* aTree, void* content, int size); 94 | 95 | void* TreeRemove(Tree* aTree, void* content); 96 | 97 | void* TreeRemoveKey(Tree* aTree, void* key); 98 | void* TreeRemoveKeyIndex(Tree* aTree, void* key, int index); 99 | 100 | void* TreeRemoveNodeIndex(Tree* aTree, Node* aNode, int index); 101 | 102 | void TreeFree(Tree* aTree); 103 | 104 | Node* TreeFind(Tree* aTree, void* key); 105 | Node* TreeFindIndex(Tree* aTree, void* key, int index); 106 | 107 | Node* TreeNextElement(Tree* aTree, Node* curnode); 108 | 109 | int TreeIntCompare(void* a, void* b, int); 110 | int TreePtrCompare(void* a, void* b, int); 111 | int TreeStringCompare(void* a, void* b, int); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /amqtdd/src/MQTTSProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Nicholas O'Leary, Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef MQTTSPROTOCOL_H_ 18 | #define MQTTSPROTOCOL_H_ 19 | 20 | #include "Clients.h" 21 | #include "Broker.h" 22 | 23 | #if !defined(NO_BRIDGE) 24 | #include "MQTTSProtocolOut.h" 25 | #endif 26 | 27 | 28 | int MQTTSProtocol_initialize(BrokerStates* aBrokerState); 29 | void MQTTSProtocol_timeslice(int sock); 30 | 31 | int MQTTSProtocol_handleAdvertises(void* pack, int sock, char* clientAddr); 32 | int MQTTSProtocol_handleSearchGws(void* pack, int sock, char* clientAddr); 33 | int MQTTSProtocol_handleGwInfos(void* pack, int sock, char* clientAddr); 34 | int MQTTSProtocol_handleConnects(void* pack, int sock, char* clientAddr); 35 | int MQTTSProtocol_handleWillTopics(void* pack, int sock, char* clientAddr); 36 | int MQTTSProtocol_handleWillMsgs(void* pack, int sock, char* clientAddr); 37 | int MQTTSProtocol_handleRegisters(void* pack, int sock, char* clientAddr); 38 | int MQTTSProtocol_handleRegacks(void* pack, int sock, char* clientAddr); 39 | int MQTTSProtocol_handlePublishes(void* pack, int sock, char* clientAddr); 40 | int MQTTSProtocol_handlePubacks(void* pack, int sock, char* clientAddr); 41 | int MQTTSProtocol_handlePubcomps(void* pack, int sock, char* clientAddr); 42 | int MQTTSProtocol_handlePubrecs(void* pack, int sock, char* clientAddr); 43 | int MQTTSProtocol_handlePubrels(void* pack, int sock, char* clientAddr); 44 | int MQTTSProtocol_handleSubscribes(void* pack, int sock, char* clientAddr); 45 | int MQTTSProtocol_handleUnsubscribes(void* pack, int sock, char* clientAddr); 46 | int MQTTSProtocol_handleUnsubacks(void* pack, int sock, char* clientAddr); 47 | int MQTTSProtocol_handlePingreqs(void* pack, int sock, char* clientAddr); 48 | int MQTTSProtocol_handlePingresps(void* pack, int sock, char* clientAddr); 49 | int MQTTSProtocol_handleDisconnects(void* pack, int sock, char* clientAddr); 50 | int MQTTSProtocol_handleWillTopicUpds(void* pack, int sock, char* clientAddr); 51 | int MQTTSProtocol_handleWillTopicResps(void* pack, int sock, char* clientAddr); 52 | int MQTTSProtocol_handleWillMsgUpds(void* pack, int sock, char* clientAddr); 53 | int MQTTSProtocol_handleWillMsgResps(void* pack, int sock, char* clientAddr); 54 | 55 | 56 | char* MQTTSProtocol_getRegisteredTopicName(Clients* client, int topicId); 57 | void MQTTSProtocol_freeRegistrationList(List* regList); 58 | void MQTTSProtocol_emptyRegistrationList(List* regList); 59 | int MQTTSProtocol_startPublishCommon(Clients* client, Publish* mqttPublish, int dup, int qos, int retained); 60 | int MQTTSProtocol_startRegistration(Clients* client, char* topic); 61 | Registration* MQTTSProtocol_registerTopic(Clients* client, char* topicName); 62 | int MQTTSProtocol_getRegisteredTopicId(Clients* client, char* topicName); 63 | 64 | #endif /* MQTTSPROTOCOL_H_ */ 65 | -------------------------------------------------------------------------------- /rsmb/src/Tree.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(TREE_H) 19 | #define TREE_H 20 | 21 | /*BE 22 | map TREE_BITS 23 | { 24 | "heap_tracking" 1 : . 25 | "allow_duplicates" 2 : . 26 | } 27 | 28 | defm defTree(T) // macro to define a tree 29 | 30 | def T concat Node 31 | { 32 | n32 ptr T concat Node "parent" 33 | n32 ptr T concat Node "left" 34 | n32 ptr T concat Node "right" 35 | n32 ptr T id2str(T) 36 | n32 suppress "size" 37 | n32 dec suppress "red" 38 | } 39 | 40 | def T concat TreeIndex 41 | { 42 | n32 ptr T concat Node suppress "root" 43 | n32 ptr DATA suppress "compare" 44 | } 45 | 46 | def T concat Tree 47 | { 48 | 2 T concat TreeIndex "index" 49 | n32 dec "indexes" 50 | n32 dec "count" 51 | n32 dec suppress "size" 52 | n32 map TREE_BITS "bits" 53 | } 54 | 55 | endm 56 | 57 | defTree(INT) 58 | defTree(STRING) 59 | defTree(TMP) 60 | 61 | BE*/ 62 | 63 | /** 64 | * Structure to hold all data for one list element 65 | */ 66 | typedef struct NodeStruct 67 | { 68 | struct NodeStruct *parent, /**< pointer to parent tree node, in case we need it */ 69 | *child[2]; /**< pointers to child tree nodes 0 = left, 1 = right */ 70 | void* content; /**< pointer to element content */ 71 | int size; /**< size of content */ 72 | unsigned int red : 1; 73 | } Node; 74 | 75 | 76 | /** 77 | * Structure to hold all data for one tree 78 | */ 79 | typedef struct 80 | { 81 | struct 82 | { 83 | Node *root; /**< root node pointer */ 84 | int (*compare)(void*, void*, int); /**< comparison function */ 85 | } index[2]; 86 | int indexes, /**< no of indexes into tree */ 87 | count, /**< no of items */ 88 | size; /**< heap storage used */ 89 | unsigned int heap_tracking : 1; /**< switch on heap tracking for this tree? */ 90 | unsigned int allow_duplicates : 1; /**< switch to allow duplicate entries */ 91 | } Tree; 92 | 93 | 94 | Tree* TreeInitialize(int(*compare)(void*, void*, int)); 95 | void TreeInitializeNoMalloc(Tree* aTree, int(*compare)(void*, void*, int)); 96 | void TreeAddIndex(Tree* aTree, int(*compare)(void*, void*, int)); 97 | 98 | void* TreeAdd(Tree* aTree, void* content, int size); 99 | 100 | void* TreeRemove(Tree* aTree, void* content); 101 | 102 | void* TreeRemoveKey(Tree* aTree, void* key); 103 | void* TreeRemoveKeyIndex(Tree* aTree, void* key, int index); 104 | 105 | void* TreeRemoveNodeIndex(Tree* aTree, Node* aNode, int index); 106 | 107 | void TreeFree(Tree* aTree); 108 | 109 | Node* TreeFind(Tree* aTree, void* key); 110 | Node* TreeFindIndex(Tree* aTree, void* key, int index); 111 | 112 | Node* TreeNextElement(Tree* aTree, Node* curnode); 113 | 114 | int TreeIntCompare(void* a, void* b, int); 115 | int TreePtrCompare(void* a, void* b, int); 116 | int TreeStringCompare(void* a, void* b, int); 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef MQTTSPROTOCOL_H_ 18 | #define MQTTSPROTOCOL_H_ 19 | 20 | #include "Clients.h" 21 | #include "Broker.h" 22 | 23 | #if !defined(NO_BRIDGE) 24 | #include "MQTTSProtocolOut.h" 25 | #endif 26 | 27 | 28 | int MQTTSProtocol_initialize(BrokerStates* aBrokerState); 29 | void MQTTSProtocol_terminate(); 30 | void MQTTSProtocol_housekeeping(); 31 | void MQTTSProtocol_timeslice(int sock); 32 | 33 | int MQTTSProtocol_handleAdvertises(void* pack, int sock, char* clientAddr, Clients* client); 34 | int MQTTSProtocol_handleSearchGws(void* pack, int sock, char* clientAddr, Clients* client); 35 | int MQTTSProtocol_handleGwInfos(void* pack, int sock, char* clientAddr, Clients* client); 36 | int MQTTSProtocol_handleConnects(void* pack, int sock, char* clientAddr, Clients* client); 37 | int MQTTSProtocol_handleWillTopics(void* pack, int sock, char* clientAddr, Clients* client); 38 | int MQTTSProtocol_handleWillMsgs(void* pack, int sock, char* clientAddr, Clients* client); 39 | int MQTTSProtocol_handleRegisters(void* pack, int sock, char* clientAddr, Clients* client); 40 | int MQTTSProtocol_handleRegacks(void* pack, int sock, char* clientAddr, Clients* client); 41 | int MQTTSProtocol_handlePublishes(void* pack, int sock, char* clientAddr, Clients* client); 42 | int MQTTSProtocol_handlePubacks(void* pack, int sock, char* clientAddr, Clients* client); 43 | int MQTTSProtocol_handlePubcomps(void* pack, int sock, char* clientAddr, Clients* client); 44 | int MQTTSProtocol_handlePubrecs(void* pack, int sock, char* clientAddr, Clients* client); 45 | int MQTTSProtocol_handlePubrels(void* pack, int sock, char* clientAddr, Clients* client); 46 | int MQTTSProtocol_handleSubscribes(void* pack, int sock, char* clientAddr, Clients* client); 47 | int MQTTSProtocol_handleUnsubscribes(void* pack, int sock, char* clientAddr, Clients* client); 48 | int MQTTSProtocol_handleUnsubacks(void* pack, int sock, char* clientAddr, Clients* client); 49 | int MQTTSProtocol_handlePingreqs(void* pack, int sock, char* clientAddr, Clients* client); 50 | int MQTTSProtocol_handlePingresps(void* pack, int sock, char* clientAddr, Clients* client); 51 | int MQTTSProtocol_handleDisconnects(void* pack, int sock, char* clientAddr, Clients* client); 52 | int MQTTSProtocol_handleWillTopicUpds(void* pack, int sock, char* clientAddr, Clients* client); 53 | int MQTTSProtocol_handleWillTopicResps(void* pack, int sock, char* clientAddr, Clients* client); 54 | int MQTTSProtocol_handleWillMsgUpds(void* pack, int sock, char* clientAddr, Clients* client); 55 | int MQTTSProtocol_handleWillMsgResps(void* pack, int sock, char* clientAddr, Clients* client); 56 | 57 | 58 | char* MQTTSProtocol_getRegisteredTopicName(Clients* client, int topicId); 59 | void MQTTSProtocol_freeRegistrationList(List* regList); 60 | void MQTTSProtocol_emptyRegistrationList(List* regList); 61 | int MQTTSProtocol_startPublishCommon(Clients* client, Publish* mqttPublish, int dup, int qos, int retained); 62 | int MQTTSProtocol_startRegistration(Clients* client, char* topic); 63 | Registration* MQTTSProtocol_registerTopic(Clients* client, char* topicName); 64 | int MQTTSProtocol_getRegisteredTopicId(Clients* client, char* topicName); 65 | 66 | #endif /* MQTTSPROTOCOL_H_ */ 67 | -------------------------------------------------------------------------------- /rsmb/src/MQTTProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTPROTOCOL_H) 18 | #define MQTTPROTOCOL_H 19 | 20 | #include "Broker.h" 21 | #include "LinkedList.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTPacket.h" 24 | #include "Clients.h" 25 | 26 | #define MAX_MSG_ID 65535 27 | #define MAX_CLIENTID_LEN 23 28 | #define INTERNAL_CLIENTID "$SYS/INTERNAL/CLIENT" 29 | 30 | /*BE 31 | map CONNACK_RETURN_CODES 32 | { 33 | "CONNACK_CONNECTION_ACCEPTED" . 34 | "CONNACK_UNACCEPTABLE_PROTOCOL_VERSION" . 35 | "CONNACK_IDENTIFIER_REJECTED" . 36 | "CONNACK_BROKER_UNAVAILABLE" . 37 | "CONNACK_BAD_USERNAME_OR_PASSWORD" . 38 | "CONNACK_NOT_AUTHORIZED" . 39 | "CONNACK_NONE_RECEIVED" 99 40 | } 41 | BE*/ 42 | 43 | enum connack_return_codes 44 | { 45 | CONNACK_CONNECTION_ACCEPTED, CONNACK_UNACCEPTABLE_PROTOCOL_VERSION, 46 | CONNACK_IDENTIFIER_REJECTED, CONNACK_BROKER_UNAVAILABLE, 47 | CONNACK_BAD_USERNAME_OR_PASSWORD, CONNACK_NOT_AUTHORIZED, CONNACK_NONE_RECEIVED=99 48 | }; 49 | 50 | /*BE 51 | 52 | include "Clients" 53 | 54 | def PENDING_WRITE 55 | { 56 | n32 dec "socket" 57 | n32 ptr PUBLICATIONS open "publication" 58 | n32 ptr CLIENTS open "client" 59 | } 60 | 61 | defList(PUBLICATIONS) 62 | defList(PENDING_WRITE) 63 | 64 | def MQTTPROTOCOL 65 | { 66 | PUBLICATIONSList "publications" 67 | PENDING_WRITEList "pending_writes" 68 | } 69 | 70 | BE*/ 71 | 72 | typedef struct 73 | { 74 | int socket; 75 | Publications* p; 76 | Clients* client; 77 | } pending_write; 78 | 79 | 80 | typedef struct 81 | { 82 | List publications; 83 | List pending_writes; /* for qos 0 writes not complete */ 84 | } MQTTProtocol; 85 | 86 | MQTTProtocol* MQTTProtocol_getState(); 87 | int MQTTProtocol_reinitialize(); 88 | int MQTTProtocol_initialize(BrokerStates*); 89 | void MQTTProtocol_shutdownclients(Tree* clients, int terminate); 90 | void MQTTProtocol_shutdown(int terminate); 91 | void MQTTProtocol_checkPendingWrites(); 92 | int MQTTProtocol_housekeeping(int more_work); 93 | void MQTTProtocol_timeslice(int sock, Clients* client); 94 | void MQTTProtocol_clean_clients(Tree* clients); 95 | void MQTTProtocol_terminate(); 96 | void MQTTProtocol_closeSession(Clients* client, int unclean); 97 | void MQTTProtocol_removeAllSubscriptions(char* clientID); 98 | void MQTTProtocol_sys_publish(char* topic, char* string); 99 | 100 | int MQTTProtocol_handleConnects(void* pack, int sock, Clients* client); 101 | int MQTTProtocol_handlePingreqs(void* pack, int sock, Clients* client); 102 | int MQTTProtocol_handleDisconnects(void* pack, int sock, Clients* client); 103 | void MQTTProtocol_processRetaineds(Clients* client, char* topic, int qos, int priority); 104 | int MQTTProtocol_handleSubscribes(void* pack, int sock, Clients* client); 105 | int MQTTProtocol_handleUnsubscribes(void* pack, int sock, Clients* client); 106 | 107 | #if defined(MQTTS) 108 | void MQTTProtocol_setWillTopic(Clients* client, char* topic, int retained, int qos); 109 | void MQTTProtocol_setWillMsg(Clients* client, char* msg); 110 | void MQTTProtocol_clearWill(Clients* client); 111 | #endif 112 | 113 | #if defined(NO_BRIDGE) 114 | #include "MQTTProtocolClient.h" 115 | #else 116 | #include "MQTTProtocolOut.h" 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSPacketSerialize.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 20012, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "MQTTSPacket.h" 18 | #include "Log.h" 19 | #include "StackTrace.h" 20 | #include "Heap.h" 21 | 22 | #include "MQTTSPacketSerialize.h" 23 | 24 | 25 | PacketBuffer MQTTSPacketSerialize_header(MQTTSHeader header) 26 | { 27 | PacketBuffer buf; 28 | 29 | if (header.len > 256) 30 | { 31 | header.len += 2; 32 | buf.data = malloc(header.len); 33 | buf.ptr = buf.data; 34 | *(buf.ptr)++ = 0x01; 35 | writeInt(&buf.ptr, header.len); 36 | } 37 | else 38 | { 39 | buf.data = malloc(header.len); 40 | buf.ptr = buf.data; 41 | *(buf.ptr)++ = header.len; 42 | } 43 | buf.len = header.len; 44 | *(buf.ptr)++ = header.type; 45 | return buf; 46 | } 47 | 48 | 49 | PacketBuffer MQTTSPacketSerialize_ack(char type, int msgId) 50 | { 51 | MQTTSHeader header; 52 | PacketBuffer buf; 53 | 54 | FUNC_ENTRY; 55 | if (msgId >= 0) 56 | header.len = 4; 57 | else 58 | header.len = 2; 59 | header.type = type; 60 | 61 | buf = MQTTSPacketSerialize_header(header); 62 | if (msgId >= 0) 63 | writeInt(&buf.ptr, msgId); 64 | 65 | FUNC_EXIT; 66 | return buf; 67 | } 68 | 69 | 70 | PacketBuffer MQTTSPacketSerialize_advertise(unsigned char gateway_id, short duration) 71 | { 72 | MQTTSHeader header; 73 | PacketBuffer buf; 74 | 75 | FUNC_ENTRY; 76 | header.len = 5; 77 | header.type = MQTTS_ADVERTISE; 78 | 79 | buf = MQTTSPacketSerialize_header(header); 80 | 81 | writeChar(&buf.ptr, gateway_id); 82 | writeInt(&buf.ptr, duration); 83 | 84 | FUNC_EXIT; 85 | return buf; 86 | } 87 | 88 | 89 | PacketBuffer MQTTSPacketSerialize_connect(int cleansession, int will, char protocolID, short keepAlive, char* clientID) 90 | { 91 | MQTTSHeader header; 92 | PacketBuffer buf; 93 | MQTTSFlags flags = {0}; 94 | 95 | FUNC_ENTRY; 96 | header.len = 6 + strlen(clientID); 97 | header.type = MQTTS_CONNECT; 98 | 99 | buf = MQTTSPacketSerialize_header(header); 100 | 101 | flags.cleanSession = cleansession; 102 | flags.will = will ? 1 : 0; 103 | writeChar(&buf.ptr, flags.all); 104 | writeChar(&buf.ptr, 0x01); /* protocol ID */ 105 | writeInt(&buf.ptr, keepAlive); 106 | memcpy(buf.ptr, clientID, strlen(clientID)); 107 | 108 | FUNC_EXIT; 109 | return buf; 110 | } 111 | 112 | 113 | PacketBuffer MQTTSSerialize_connack(int returnCode) 114 | { 115 | MQTTSHeader header; 116 | PacketBuffer buf; 117 | 118 | FUNC_ENTRY; 119 | header.len = 3; 120 | header.type = MQTTS_CONNACK; 121 | 122 | buf = MQTTSPacketSerialize_header(header); 123 | *(buf.ptr)++ = (char)returnCode; 124 | 125 | FUNC_EXIT; 126 | return buf; 127 | } 128 | 129 | /* 130 | PacketBuffer MQTTSSerialize_regAck(int msgId, int topicId, char returnCode) 131 | { 132 | MQTTS_RegAck packet; 133 | int rc = 0; 134 | char *buf, *ptr; 135 | int datalen = 5; 136 | 137 | FUNC_ENTRY; 138 | packet.header.len = 7; 139 | packet.header.type = MQTTS_REGACK; 140 | 141 | ptr = buf = malloc(datalen); 142 | writeInt(&ptr, topicId); 143 | writeInt(&ptr, msgId); 144 | writeChar(&ptr, returnCode); 145 | 146 | rc = MQTTSPacket_send(client->socket, client->addr, packet.header, buf, datalen); 147 | free(buf); 148 | 149 | FUNC_EXIT_RC(rc); 150 | return rc; 151 | } 152 | */ 153 | -------------------------------------------------------------------------------- /amqtdd/src/SubsEngine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(SUBSENGINE_H) 18 | #define SUBSENGINE_H 19 | 20 | #include "LinkedList.h" 21 | /*BE 22 | include "LinkedList" 23 | BE*/ 24 | 25 | /** 26 | * System topic prefix 27 | */ 28 | #define sysprefix "$SYS/" 29 | 30 | /*BE 31 | def SUBSCRIPTIONS 32 | { 33 | n32 ptr STRING open "clientName" 34 | n32 ptr STRING open "topicName" 35 | n32 dec "qos" 36 | n32 map bool "noLocal" 37 | n32 map bool "durable" 38 | n32 dec "priority" 39 | } 40 | BE*/ 41 | enum 42 | { 43 | PRIORITY_LOW, 44 | PRIORITY_NORMAL, 45 | PRIORITY_HIGH, 46 | }; 47 | #if !defined(PRIORITY_MAX) 48 | #define PRIORITY_MAX 3 49 | #endif 50 | /** 51 | * Data for each client subscription 52 | */ 53 | typedef struct 54 | { 55 | char* clientName; /**< ID of client which holds this subscription */ 56 | char* topicName; /**< the name of the topic, possible wildcarded */ 57 | int qos; /**< the Quality of Service of the subscription */ 58 | unsigned int noLocal; /**< noLocal flag (for bridge use) */ 59 | int durable; /**< so that the save process knows which ones to omit */ 60 | int priority; /**< priority of subscription */ 61 | } Subscriptions; 62 | 63 | /*BE 64 | def RETAINEDPUBLICATIONS 65 | { 66 | n32 ptr STRING open "topicName" 67 | n32 dec "qos" 68 | n32 ptr DATA open "payload" 69 | n32 dec "payloadlen" 70 | } 71 | BE*/ 72 | /** 73 | * Retained message data 74 | */ 75 | typedef struct 76 | { 77 | char* topicName; /**< topic name string, no wildcards */ 78 | int qos; /**< quality of service */ 79 | char* payload; /**< message content */ 80 | unsigned int payloadlen; /**< length of payload */ 81 | } RetainedPublications; 82 | 83 | Subscriptions* Subscriptions_initialize(char*, char*, int, int, int, int); 84 | 85 | /*BE 86 | 87 | defList(SUBSCRIPTIONS) 88 | defList(RETAINEDPUBLICATIONS) 89 | 90 | def SUBSCRIPTIONENGINES 91 | { 92 | n32 ptr SUBSCRIPTIONSList open "subs" 93 | n32 ptr RETAINEDPUBLICATIONSList open "retaineds" 94 | n32 dec "retained_changes" 95 | struct 96 | { 97 | n32 ptr SUBSCRIPTIONSList open "system_subs" 98 | n32 ptr RETAINEDPUBLICATIONSList open "system_retaineds" 99 | } 100 | } 101 | BE*/ 102 | /** 103 | * Subscription engine main state 104 | */ 105 | typedef struct 106 | { 107 | List* subs; /**< main subscription list */ 108 | List* retaineds; /**< main retained message list */ 109 | int retained_changes; /**< flag to show whether changes have been made since last save */ 110 | struct 111 | { 112 | List* subs; /**< system topics */ 113 | List* retaineds; /**< system retained messages */ 114 | } system; /**< system topic space */ 115 | } SubscriptionEngines; 116 | 117 | SubscriptionEngines* SubscriptionEngines_initialize(); 118 | void SubscriptionEngines_save(SubscriptionEngines* se); 119 | void SubscriptionEngines_terminate(SubscriptionEngines* se); 120 | 121 | int SubscriptionEngines_subscribe(SubscriptionEngines*, char*, char*, int, int, int, int); 122 | void SubscriptionEngines_unsubscribe(SubscriptionEngines*, char*, char*); 123 | int subsClientIDCompare(void* a, void* b); 124 | char* SubscriptionEngines_mostSpecific(char* topicA, char* topicB); 125 | List* SubscriptionEngines_getSubscribers(SubscriptionEngines*, char* topic, char* clientID); 126 | 127 | void SubscriptionEngines_setRetained(SubscriptionEngines* se, char* topicName, int qos, char* payload, unsigned int payloadlen); 128 | List* SubscriptionEngines_getRetained(SubscriptionEngines* se, char* topicName); 129 | void SubscriptionEngines_clearRetained(SubscriptionEngines* se, char* topicName); 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Mosquitto RSMB 2 | ============================== 3 | 4 | Thank you for your interest in this project. 5 | 6 | Project description: 7 | -------------------- 8 | 9 | The Mosquitto project has been created to provide a light weight, open-source 10 | implementation, of an MQTT broker to allow new, existing, and emerging 11 | applications for Machine-to-Machine (M2M) and Internet of Things (IoT). 12 | 13 | This is the RSMB component of the Mosquitto project, which provides MQTT-SN 14 | support as well as MQTT support. 15 | 16 | - 17 | 18 | 19 | Source 20 | ------ 21 | 22 | The Mosquitto code is stored in a git repository. 23 | 24 | - http://github.com/eclipse/mosquitto.rsmb 25 | 26 | You can contribute bugfixes and new features by sending pull requests through GitHub. 27 | 28 | 29 | ## Legal 30 | 31 | In order for your contribution to be accepted, it must comply with the Eclipse 32 | Foundation IP policy. 33 | 34 | Please read the [Eclipse Foundation policy on accepting contributions via Git](http://wiki.eclipse.org/Development_Resources/Contributing_via_Git). 35 | 36 | 1. Sign the [Eclipse CLA](http://www.eclipse.org/legal/CLA.php) 37 | 1. Register for an Eclipse Foundation User ID. You can register [here](https://dev.eclipse.org/site_login/createaccount.php). 38 | 2. Log into the [Projects Portal](https://projects.eclipse.org/), and click on the '[Eclipse CLA](https://projects.eclipse.org/user/sign/cla)' link. 39 | 2. Go to your [account settings](https://dev.eclipse.org/site_login/myaccount.php#open_tab_accountsettings) and add your GitHub username to your account. 40 | 3. Make sure that you _sign-off_ your Git commits in the following format: 41 | ``` Signed-off-by: John Smith ``` This is usually at the bottom of the commit message. You can automate this by adding the '-s' flag when you make the commits. e.g. ```git commit -s -m "Adding a cool feature"``` 42 | 4. Ensure that the email address that you make your commits with is the same one you used to sign up to the Eclipse Foundation website with. 43 | 44 | ## Contributing a change 45 | 46 | 1. [Fork the repository on GitHub](https://github.com/eclipse/mosquitto.rsmb/fork) 47 | 2. Clone the forked repository onto your computer: ``` git clone 48 | https://github.com//mosquitto.rsmb.git ``` 49 | 3. If you are adding a new feature, then create a new branch from the latest 50 | ```develop``` branch with ```git checkout -b YOUR_BRANCH_NAME 51 | origin/develop``` 52 | 4. If you are fixing a bug, then create a new branch from the latest 53 | ```fixes``` branch with ```git checkout -b YOUR_BRANCH_NAME origin/fixes``` 54 | 5. Make your changes 55 | 6. Ensure that all new and existing tests pass. 56 | 7. Commit the changes into the branch: ``` git commit -s ``` Make sure that 57 | your commit message is meaningful and describes your changes correctly. 58 | 8. If you have a lot of commits for the change, squash them into a single / few 59 | commits. 60 | 9. Push the changes in your branch to your forked repository. 61 | 10. Finally, go to 62 | [https://github.com/eclipse/mosquitto.rsmb](https://github.com/eclipse/mosquitto.rsmb) 63 | and create a pull request from your "YOUR_BRANCH_NAME" branch to the 64 | ```develop``` or ```fixes``` branch as appropriate to request review and 65 | merge of the commits in your pushed branch. 66 | 67 | 68 | What happens next depends on the content of the patch. If it is 100% authored 69 | by the contributor and is less than 1000 lines (and meets the needs of the 70 | project), then it can be pulled into the main repository. If not, more steps 71 | are required. These are detailed in the 72 | [legal process poster](http://www.eclipse.org/legal/EclipseLegalProcessPoster.pdf). 73 | 74 | 75 | 76 | Contact: 77 | -------- 78 | 79 | Contact the project developers via the project's development 80 | [mailing list](https://dev.eclipse.org/mailman/listinfo/mosquitto-dev). 81 | 82 | Search for bugs: 83 | ---------------- 84 | 85 | This project uses [Github](https://github.com/eclipse/mosquitto.rsmb/issues) 86 | to track ongoing development and issues. 87 | 88 | Create a new bug: 89 | ----------------- 90 | 91 | Be sure to search for existing bugs before you create another one. Remember 92 | that contributions are always welcome! 93 | 94 | - [Create new Mosquitto bug](https://github.com/eclipse/mosquitto.rsmb/issues) 95 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/MQTTSClientInternal.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | Clients* MQTTSProtocol_connect(char* ip_address, char* clientID, int cleansession, int try_private, int keepalive, willMessages* willMessage) 19 | { /* outgoing connection */ 20 | int rc, port; 21 | char* addr; 22 | Clients* newc = NULL; 23 | 24 | FUNC_ENTRY; 25 | newc = malloc(sizeof(Clients)); 26 | memset(newc, '\0', sizeof(Clients)); 27 | newc->outboundMsgs = ListInitialize(); 28 | newc->inboundMsgs = ListInitialize(); 29 | newc->queuedMsgs[i] = ListInitialize(); 30 | newc->clientID = clientID; 31 | 32 | newc->cleansession = cleansession; 33 | newc->outbound = newc->good = 1; 34 | newc->keepAliveInterval = keepalive; 35 | newc->registrations = ListInitialize(); 36 | newc->will = willMessage; 37 | newc->noLocal = try_private; /* try private connection first */ 38 | time(&(newc->lastContact)); 39 | newc->pendingRegistration = NULL; 40 | newc->protocol = PROTOCOL_MQTTS; 41 | 42 | addr = MQTTProtocol_addressPort(ip_address, &port); 43 | 44 | newc->addr = malloc(strlen(ip_address)); 45 | strcpy(newc->addr, ip_address); 46 | 47 | rc = Socket_new_type(addr, port, &(newc->socket), SOCK_DGRAM); 48 | 49 | if (rc == EINPROGRESS || rc == EWOULDBLOCK) 50 | newc->connect_state = 1; /* UDP connect called - improbable, but possible on obscure platforms */ 51 | else if (rc == 0) 52 | { 53 | newc->connect_state = 2; 54 | rc = MQTTSPacket_send_connect(newc); 55 | } 56 | 57 | FUNC_EXIT; 58 | return newc; 59 | } 60 | 61 | 62 | void MQTTSProtocol_receive(int sock) 63 | { 64 | int error; 65 | MQTTS_Header* pack; 66 | char* clientAddr; 67 | Clients* client = NULL; 68 | 69 | FUNC_ENTRY; 70 | pack = MQTTSPacket_Factory(sock, &clientAddr, &error); 71 | 72 | client = Protocol_getclientbyaddr(clientAddr); 73 | 74 | #if !defined(NO_BRIDGE) 75 | if (client == NULL) 76 | client = Protocol_getoutboundclient(sock); 77 | #endif 78 | 79 | if (pack == NULL) 80 | { 81 | if (error == SOCKET_ERROR || error == UDPSOCKET_INCOMPLETE) 82 | { 83 | if (client != NULL) 84 | { 85 | client->good = 0; /* make sure we don't try and send messages to ourselves */ 86 | client->connected = 0; 87 | if (error == SOCKET_ERROR) 88 | Log(LOG_WARNING, 18, NULL, client->clientID, client->socket, 89 | Socket_getpeer(client->socket)); 90 | else 91 | Log(LOG_WARNING, 19, NULL, client->clientID, client->socket, 92 | Socket_getpeer(client->socket)); 93 | MQTTProtocol_closeSession(client, 0); 94 | } 95 | else 96 | { 97 | if (error == SOCKET_ERROR) 98 | Log(LOG_WARNING, 20, NULL, sock, Socket_getpeer(sock)); 99 | else 100 | Log(LOG_WARNING, 21, NULL, sock, Socket_getpeer(sock)); 101 | /*Socket_close(sock);*/ 102 | } 103 | } 104 | } 105 | else if (handle_packets[(int)pack->header.type] == NULL) 106 | { 107 | Log(LOG_WARNING, 22, NULL, pack->header.type, handle_packets[(int)pack->header.type]); 108 | MQTTSPacket_free_packet(pack); 109 | } 110 | else if (client == NULL 111 | && 112 | ((pack->header.type == MQTTS_PUBLISH && ((MQTTS_Publish*)pack)->flags.QoS != 3) 113 | || 114 | (pack->header.type != MQTTS_PUBLISH && pack->header.type != MQTTS_CONNECT))) 115 | { 116 | Log(LOG_WARNING, 23, NULL, sock, MQTTSPacket_name(pack->header.type)); 117 | MQTTSPacket_free_packet(pack); 118 | } 119 | else 120 | { 121 | (*handle_packets[(int)pack->header.type])(pack, sock, clientAddr); 122 | /* TODO: 123 | * - error handling 124 | * - centralise calls to time( &(c->lastContact) ); (currently in each _handle* function 125 | */ 126 | } 127 | 128 | FUNC_EXIT; 129 | } 130 | -------------------------------------------------------------------------------- /rsmb/src/SubsEngine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(SUBSENGINE_H) 18 | #define SUBSENGINE_H 19 | 20 | #include "LinkedList.h" 21 | #include "Tree.h" 22 | /*BE 23 | include "LinkedList" 24 | include "Tree" 25 | BE*/ 26 | 27 | /** 28 | * System topic prefix 29 | */ 30 | #define sysprefix "$SYS/" 31 | 32 | /*BE 33 | def SUBSCRIPTIONS 34 | { 35 | n32 ptr STRING open "clientName" 36 | n32 ptr STRING open "topicName" 37 | n32 dec "qos" 38 | n32 map bool "noLocal" 39 | n32 map bool "durable" 40 | n32 dec "priority" 41 | n32 map bool "wildcards" 42 | } 43 | BE*/ 44 | enum 45 | { 46 | PRIORITY_LOW, 47 | PRIORITY_NORMAL, 48 | PRIORITY_HIGH, 49 | }; 50 | #if !defined(PRIORITY_MAX) 51 | #define PRIORITY_MAX 3 52 | #endif 53 | /** 54 | * Data for each client subscription 55 | */ 56 | typedef struct 57 | { 58 | char* clientName; /**< ID of client which holds this subscription */ 59 | char* topicName; /**< the name of the topic, possible wildcarded */ 60 | int qos; /**< the Quality of Service of the subscription */ 61 | unsigned int noLocal; /**< noLocal flag (for bridge use) */ 62 | int durable; /**< so that the save process knows which ones to omit */ 63 | int priority; /**< priority of subscription */ 64 | int wildcards; 65 | } Subscriptions; 66 | 67 | 68 | /*BE 69 | def RETAINEDPUBLICATIONS 70 | { 71 | n32 ptr STRING open "topicName" 72 | n32 dec "qos" 73 | n32 ptr DATA open "payload" 74 | n32 dec "payloadlen" 75 | } 76 | BE*/ 77 | /** 78 | * Retained message data 79 | */ 80 | typedef struct 81 | { 82 | char* topicName; /**< topic name string, no wildcards */ 83 | int qos; /**< quality of service */ 84 | char* payload; /**< message content */ 85 | unsigned int payloadlen; /**< length of payload */ 86 | } RetainedPublications; 87 | 88 | Subscriptions* Subscriptions_initialize(char*, char*, int, int, int, int); 89 | 90 | /*BE 91 | 92 | defList(SUBSCRIPTIONS) 93 | defTree(RETAINEDPUBLICATIONS) 94 | defTree(SUBSCRIPTIONSList) 95 | 96 | def SUBSCRIPTIONENGINES 97 | { 98 | n32 ptr SUBSCRIPTIONSListTree open "subs" 99 | n32 ptr SUBSCRIPTIONSList open "wsubs" 100 | n32 ptr RETAINEDPUBLICATIONSTree open "retaineds" 101 | n32 dec "retained_changes" 102 | struct 103 | { 104 | n32 ptr SUBSCRIPTIONSList open "system_subs" 105 | n32 ptr RETAINEDPUBLICATIONSTree open "system_retaineds" 106 | } 107 | } 108 | BE*/ 109 | /** 110 | * Subscription engine main state 111 | */ 112 | typedef struct 113 | { 114 | Tree* subs; /**< non-wildcard main subscriptions */ 115 | List* wsubs; /**< main subscription list - wildcard subscriptions */ 116 | Tree* retaineds; /**< main retained message list */ 117 | int retained_changes; /**< flag to show whether changes have been made since last save */ 118 | struct 119 | { 120 | List* subs; /**< system topics */ 121 | Tree* retaineds; /**< system retained messages */ 122 | } system; /**< system topic space */ 123 | } SubscriptionEngines; 124 | 125 | SubscriptionEngines* SubscriptionEngines_initialize(); 126 | void SubscriptionEngines_save(SubscriptionEngines* se); 127 | void SubscriptionEngines_terminate(SubscriptionEngines* se); 128 | 129 | int SubscriptionEngines_subscribe(SubscriptionEngines*, char*, char*, int, int, int, int); 130 | void SubscriptionEngines_unsubscribe(SubscriptionEngines*, char*, char*); 131 | char* SubscriptionEngines_mostSpecific(char* topicA, char* topicB); 132 | List* SubscriptionEngines_getSubscribers(SubscriptionEngines*, char* topic, char* clientID); 133 | 134 | void SubscriptionEngines_setRetained(SubscriptionEngines* se, char* topicName, int qos, char* payload, unsigned int payloadlen); 135 | List* SubscriptionEngines_getRetained(SubscriptionEngines* se, char* topicName); 136 | void SubscriptionEngines_clearRetained(SubscriptionEngines* se, char* topicName); 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /rsmb/src/tools/be/bememext.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * This file was obtained from http://www.nyangau.org/ 4 | * It is part of Andy's Binary Folding Editor 5 | * package, which is in the public domain. It should not be changed. 6 | * 7 | *******************************************************************************/ 8 | 9 | // 10 | // bememext.h - Interface needed by implementors of BE memory extensions 11 | // 12 | // Despite both BE and the helpers being implemented in C++, I use a C 13 | // style interface. This avoids name mangling problems. 14 | // 15 | // The bemem_init entrypoint will be called before any other entrypoint. 16 | // If bemem_init fails, then it should set err to point to some meaningful 17 | // static error string, and return FALSE. 18 | // bemem_init can be omitted if there is no initialisation required. 19 | // 20 | // For every non-0 bemem_create, BE will later call bemem_delete. 21 | // If bemem_create fails, then it should set err to point to some meaningful 22 | // static error string, and return (void *) 0. 23 | // 24 | // After all bemem_deletes, bemem_term will be called (last). 25 | // bemem_term can be omitted if there is no termination required. 26 | // 27 | // If the memory extension helper is caching data (presumably for speed), 28 | // then it should discard this cache if bemem_refresh is called. 29 | // If a memory extension helper does not cache any data, it need not 30 | // implement a bemem_refresh routine. 31 | // 32 | // A memory extension helper can optionally provide the bemem_write and 33 | // bemem_flush routines, if the data it provides access to is in some way 34 | // modifiable. bemem_write changes a byte in the data, and before the 35 | // Binary Editor shuts down, it will call bemem_flush to make any changes 36 | // made using bemem_write 'final'. If data is modified via bemem_write, 37 | // the modified data should immediately be accessible via bemem_read. 38 | // 39 | // bemem_options is an optional mechanism whereby arbitrary commands may 40 | // be passed through to the memory extension, for a specific instance. 41 | // 42 | // If 64 bit address space entrypoints are implemented, then BE will use 43 | // these, otherwise it will call the older 32 bit entrypoints. 44 | // 45 | // If a memory extension implements bemem_memacc and/or bemem_memacc_64, 46 | // then immediately after calling bemem_init, BE will call the extension to 47 | // tell it the address of functions within BE itself which access the BE whole 48 | // memory space. In this way memory extensions may be written which provide 49 | // shadow views of data elsewhere in the memory space, or data derived from 50 | // data elsewhere in the memory space. 51 | // 52 | 53 | #ifndef BEMEM_H 54 | #define BEMEM_H 55 | 56 | #ifndef Boolean_DEFINED 57 | #define Boolean_DEFINED 58 | typedef int Boolean; 59 | #define TRUE 1 60 | #define FALSE 0 61 | #endif 62 | 63 | #if defined(OS2) 64 | #define BEMEMEXPORT 65 | #define BEMEMENTRY _System 66 | #define BEMEMADDR32 unsigned 67 | #define BEMEMADDR64 unsigned_long_long 68 | #elif defined(WIN32) 69 | #define BEMEMEXPORT __declspec(dllexport) 70 | #define BEMEMENTRY __stdcall 71 | #define BEMEMADDR32 unsigned 72 | #define BEMEMADDR64 unsigned __int64 73 | #elif defined(DOS32) 74 | #define BEMEMEXPORT 75 | #define BEMEMENTRY __export _cdecl 76 | #define BEMEMADDR32 unsigned 77 | #define BEMEMADDR64 unsigned __int64 78 | #elif defined(NW) 79 | #define BEMEMEXPORT 80 | #define BEMEMENTRY 81 | #define BEMEMADDR32 unsigned 82 | #define BEMEMADDR64 unsigned __int64 83 | #else 84 | #define BEMEMEXPORT 85 | #define BEMEMENTRY 86 | #define BEMEMADDR32 unsigned 87 | #define BEMEMADDR64 unsigned long long 88 | #endif 89 | 90 | #ifdef AIX 91 | typedef void (*BEMEM_EP)(void); 92 | typedef struct { BEMEM_EP ep; const char *name; } BEMEM_EXPORT; 93 | #endif 94 | 95 | typedef Boolean (*BEMEMREAD32)(BEMEMADDR32 addr, unsigned char & b); 96 | typedef Boolean (*BEMEMWRITE32)(BEMEMADDR32 addr, unsigned char b); 97 | #ifdef BE64 98 | typedef Boolean (*BEMEMREAD64)(BEMEMADDR64 addr, unsigned char & b); 99 | typedef Boolean (*BEMEMWRITE64)(BEMEMADDR64 addr, unsigned char b); 100 | #endif 101 | 102 | extern "C" { 103 | 104 | BEMEMEXPORT Boolean BEMEMENTRY bemem_init(const char *(&err)); 105 | BEMEMEXPORT void * BEMEMENTRY bemem_create(const char *args, BEMEMADDR32 addr, const char *(&err)); 106 | BEMEMEXPORT Boolean BEMEMENTRY bemem_read(void * ptr, BEMEMADDR32 addr, unsigned char & b); 107 | BEMEMEXPORT Boolean BEMEMENTRY bemem_write(void * ptr, BEMEMADDR32 addr, unsigned char b); 108 | BEMEMEXPORT void BEMEMENTRY bemem_memacc(BEMEMREAD32 read_fn, BEMEMWRITE32 write_fn); 109 | #ifdef BE64 110 | BEMEMEXPORT void * BEMEMENTRY bemem_create_64(const char *args, BEMEMADDR64 addr, const char *(&err)); 111 | BEMEMEXPORT Boolean BEMEMENTRY bemem_read_64(void * ptr, BEMEMADDR64 addr, unsigned char & b); 112 | BEMEMEXPORT Boolean BEMEMENTRY bemem_write_64(void * ptr, BEMEMADDR64 addr, unsigned char b); 113 | BEMEMEXPORT void BEMEMENTRY bemem_memacc_64(BEMEMREAD64 read_fn, BEMEMWRITE64 write_fn); 114 | #endif 115 | BEMEMEXPORT void BEMEMENTRY bemem_refresh(void * ptr); 116 | BEMEMEXPORT Boolean BEMEMENTRY bemem_flush(void * ptr); 117 | BEMEMEXPORT Boolean BEMEMENTRY bemem_options(void * ptr, const char *options, const char *(&err)); 118 | BEMEMEXPORT void BEMEMENTRY bemem_delete(void * ptr); 119 | BEMEMEXPORT void BEMEMENTRY bemem_term(); 120 | 121 | } 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /amqtdd/src/Broker.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(BROKER_H) 18 | #define BROKER_H 19 | 20 | #include "SubsEngine.h" 21 | #include "Bridge.h" 22 | 23 | #define true 1 24 | #define false 0 25 | 26 | #define assert(x) if (!x) printf("Assertion error %s\n", # x); 27 | 28 | /*BE 29 | def INT { n32 "value" } 30 | def TMP { n32 "tmp" } 31 | def DATA { 100 n8 hex "data" } 32 | def STRING { buf 100 zterm asc "data" } 33 | map bool 34 | { 35 | "false" . 36 | "true" . 37 | } 38 | BE*/ 39 | 40 | /*BE 41 | include "Log" // include this even though it isn't included in the .h 42 | include "SubsEngine" 43 | include "Bridge" 44 | include "Users" 45 | BE*/ 46 | 47 | /*BE 48 | map BROKER_RUN_STATE { 49 | "BROKER_STOPPED" . 50 | "BROKER_RUNNING" . 51 | "BROKER_STOPPING" . 52 | } 53 | BE*/ 54 | /** 55 | * broker run states 56 | */ 57 | enum broker_run_state { BROKER_STOPPED, BROKER_RUNNING, BROKER_STOPPING }; 58 | 59 | /*BE 60 | def BROKERSTATES 61 | { 62 | n32 ptr STRING open "version" 63 | n32 ptr STRING open "build_timestamp" 64 | n32 dec "max_inflight_messages" 65 | n32 dec "max_queued_messages" 66 | n32 dec "retry_interval" 67 | n32 ptr CLIENTSList open "clients" 68 | $ifndef MQTTCLIENT 69 | n32 dec "connection_messages" 70 | n32 ptr SUBSCRIPTIONENGINES "SubscriptionEngine" 71 | n32 map BROKER_RUN_STATE "state" 72 | n32 dec "hup_signal" 73 | n32 ptr STRING open "ffdc_location" 74 | n32 ptr STRING open "persistence_location" 75 | n32 dec "persistence" 76 | n32 map bool "autosave_on_changes" 77 | n32 dec "autosave_interval" 78 | $ifdef WIN32 79 | n64 time "last_autosave" 80 | $else 81 | n32 time "last_autosave" 82 | $endif 83 | n32 ptr STRINGList open "clientid_prefixes" 84 | BRIDGES "bridge" 85 | $ifdef SINGLE_LISTENER 86 | n32 dec "port" 87 | n32 ptr STRING open "bind_address" 88 | n32 dec "max_connections" 89 | n32 map bool "ipv6" 90 | $else 91 | n32 ptr LISTENERList open "listeners" 92 | $endif 93 | n32 ptr STRING open "password_file" 94 | n32 ptr USERList open "users" 95 | n32 ptr STRING open "acl_file" 96 | n32 map bool "allow_anonymous" 97 | n32 ptr RULEList open "defaultACL" 98 | n32 dec "msgs_received" 99 | n32 dec "msgs_sent" 100 | n32 unsigned dec "bytes_received" 101 | n32 unsigned dec "bytes_sent" 102 | $ifdef WIN32 103 | n64 time "start_time" 104 | $else 105 | n32 time "start_time" 106 | $endif 107 | $endif 108 | } 109 | BE*/ 110 | /** 111 | * Global broker state. 112 | */ 113 | typedef struct 114 | { 115 | char* version; /**< broker version */ 116 | char* timestamp; /**< build timestamp */ 117 | int max_inflight_messages; /**< per client, outbound */ 118 | int max_queued_messages; /**< per client, outbound */ 119 | int retry_interval; /**< MQTT retry interval */ 120 | List* clients; /**< list of clients */ 121 | #if !defined(MQTTCLIENT) 122 | int connection_messages; /**< connection messages for bridge clients */ 123 | SubscriptionEngines* se; /**< subscription engine state */ 124 | volatile int state; /**< signal handling indicator */ 125 | volatile int hup_signal; /**< hup signal handling indicator */ 126 | char* ffdc_location; /**< ffdc output (if different from persistence) */ 127 | char* persistence_location; /**< persistence directory location */ 128 | int persistence; /**< retained message and subscription persistence */ 129 | int autosave_on_changes; /**< autosave on number of state changes? */ 130 | int autosave_interval; /**< autosave on time interval? */ 131 | time_t last_autosave; /**< time of last autosave */ 132 | List* clientid_prefixes; /**< list of authorized client prefixes */ 133 | Bridges bridge; /**< bridge state */ 134 | #if defined(SINGLE_LISTENER) 135 | int port; /**< single listener server port */ 136 | char* bind_address; /**< single listener server bind address */ 137 | int max_connections; /**< single listener max no of connections */ 138 | int ipv6; /**< use ipv6? */ 139 | #else 140 | List* listeners; /**< list of listeners */ 141 | #endif 142 | char* password_file; /**< password file location */ 143 | List* users; /**< known users & passwords */ 144 | char* acl_file; /**< acl file location */ 145 | int allow_anonymous; /**< whether anonymous users are allowed to connect */ 146 | List* defaultACL; /**< acl that applied to all users */ 147 | unsigned int msgs_received; /**< statistics: number of messages received */ 148 | unsigned int msgs_sent; /**< statistics: number of messages sent */ 149 | unsigned long int bytes_received; /**< statistics: number of bytes received */ 150 | unsigned long int bytes_sent; /**< statistics: number of bytes sent */ 151 | time_t start_time; /**< start time of the broker for uptime calculation */ 152 | #endif 153 | } BrokerStates; /**< Global broker state */ 154 | 155 | /*BE 156 | def main 157 | { 158 | BROKERSTATES "Broker States" 159 | n32 hex ptr STRINGList open "Log Buffer" 160 | n32 hex ptr STRINGList open "Trace Buffer" 161 | n32 ptr STRING open "Config file" 162 | SOCKETS "sockets" 163 | } 164 | BE*/ 165 | 166 | int Broker_stop(char* s); 167 | int Broker_dumpHeap(char* dest); 168 | char* Broker_recordFFDC(char* symptoms); 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /rsmb/src/MQTTSClient/Python/MQTTSNinternal.py: -------------------------------------------------------------------------------- 1 | """ 2 | /******************************************************************************* 3 | * Copyright (c) 2011, 2013 IBM Corp. 4 | * 5 | * All rights reserved. This program and the accompanying materials 6 | * are made available under the terms of the Eclipse Public License v1.0 7 | * and Eclipse Distribution License v1.0 which accompany this distribution. 8 | * 9 | * The Eclipse Public License is available at 10 | * http://www.eclipse.org/legal/epl-v10.html 11 | * and the Eclipse Distribution License is available at 12 | * http://www.eclipse.org/org/documents/edl-v10.php. 13 | * 14 | * Contributors: 15 | * Ian Craggs - initial API and implementation and/or initial documentation 16 | *******************************************************************************/ 17 | """ 18 | 19 | import MQTTSN, time, sys, socket, traceback 20 | 21 | debug = False 22 | 23 | class Receivers: 24 | 25 | def __init__(self, socket): 26 | print "initializing receiver" 27 | self.socket = socket 28 | self.connected = False 29 | self.observe = None 30 | self.observed = [] 31 | 32 | self.inMsgs = {} 33 | self.outMsgs = {} 34 | 35 | self.puback = MQTTSN.Pubacks() 36 | self.pubrec = MQTTSN.Pubrecs() 37 | self.pubrel = MQTTSN.Pubrels() 38 | self.pubcomp = MQTTSN.Pubcomps() 39 | 40 | def lookfor(self, msgType): 41 | self.observe = msgType 42 | 43 | def waitfor(self, msgType, msgId=None): 44 | msg = None 45 | count = 0 46 | while True: 47 | while len(self.observed) > 0: 48 | msg = self.observed.pop(0) 49 | if msg.mh.MsgType == msgType and (msgId == None or msg.MsgId == msgId): 50 | break 51 | else: 52 | msg = None 53 | if msg != None: 54 | break 55 | time.sleep(0.2) 56 | count += 1 57 | if count == 25: 58 | msg = None 59 | break 60 | self.observe = None 61 | return msg 62 | 63 | def receive(self, callback=None): 64 | packet = None 65 | try: 66 | packet, address = MQTTSN.unpackPacket(MQTTSN.getPacket(self.socket)) 67 | except: 68 | if sys.exc_info()[0] != socket.timeout: 69 | print "unexpected exception", sys.exc_info() 70 | raise sys.exc_info() 71 | if packet == None: 72 | time.sleep(0.1) 73 | return 74 | elif debug: 75 | print packet 76 | 77 | if self.observe == packet.mh.MsgType: 78 | print "observed", packet 79 | self.observed.append(packet) 80 | 81 | elif packet.mh.MsgType == MQTTSN.ADVERTISE: 82 | if hasattr(callback, "advertise"): 83 | callback.advertise(address, packet.GwId, packet.Duration) 84 | 85 | elif packet.mh.MsgType == MQTTSN.REGISTER: 86 | if callback and hasattr(callback, "register"): 87 | callback.register(packet.TopicId, packet.Topicname) 88 | 89 | elif packet.mh.MsgType == MQTTSN.PUBACK: 90 | "check if we are expecting a puback" 91 | if self.outMsgs.has_key(packet.MsgId) and \ 92 | self.outMsgs[packet.MsgId].Flags.QoS == 1: 93 | del self.outMsgs[packet.MsgId] 94 | if hasattr(callback, "published"): 95 | callback.published(packet.MsgId) 96 | else: 97 | raise Exception("No QoS 1 message with message id "+str(packet.MsgId)+" sent") 98 | 99 | elif packet.mh.MsgType == MQTTSN.PUBREC: 100 | if self.outMsgs.has_key(packet.MsgId): 101 | self.pubrel.MsgId = packet.MsgId 102 | self.socket.send(self.pubrel.pack()) 103 | else: 104 | raise Exception("PUBREC received for unknown msg id "+ \ 105 | str(packet.MsgId)) 106 | 107 | elif packet.mh.MsgType == MQTTSN.PUBREL: 108 | "release QOS 2 publication to client, & send PUBCOMP" 109 | msgid = packet.MsgId 110 | if not self.inMsgs.has_key(msgid): 111 | pass # what should we do here? 112 | else: 113 | pub = self.inMsgs[packet.MsgId] 114 | if callback == None or \ 115 | callback.messageArrived(pub.TopicName, pub.Data, 2, pub.Flags.Retain, pub.MsgId): 116 | del self.inMsgs[packet.MsgId] 117 | self.pubcomp.MsgId = packet.MsgId 118 | self.socket.send(self.pubcomp.pack()) 119 | if callback == None: 120 | return (pub.TopicName, pub.Data, 2, pub.Flags.Retain, pub.MsgId) 121 | 122 | elif packet.mh.MsgType == MQTTSN.PUBCOMP: 123 | "finished with this message id" 124 | if self.outMsgs.has_key(packet.MsgId): 125 | del self.outMsgs[packet.MsgId] 126 | if hasattr(callback, "published"): 127 | callback.published(packet.MsgId) 128 | else: 129 | raise Exception("PUBCOMP received for unknown msg id "+ \ 130 | str(packet.MsgId)) 131 | 132 | elif packet.mh.MsgType == MQTTSN.PUBLISH: 133 | "finished with this message id" 134 | if packet.Flags.QoS in [0, 3]: 135 | qos = packet.Flags.QoS 136 | topicname = packet.TopicName 137 | data = packet.Data 138 | if qos == 3: 139 | qos = -1 140 | if packet.Flags.TopicIdType == MQTTSN.TOPICID: 141 | topicname = packet.Data[:packet.TopicId] 142 | data = packet.Data[packet.TopicId:] 143 | if callback == None: 144 | return (topicname, data, qos, packet.Flags.Retain, packet.MsgId) 145 | else: 146 | callback.messageArrived(topicname, data, qos, packet.Flags.Retain, packet.MsgId) 147 | elif packet.Flags.QoS == 1: 148 | if callback == None: 149 | return (packet.topicName, packet.Data, 1, 150 | packet.Flags.Retain, packet.MsgId) 151 | else: 152 | if callback.messageArrived(packet.TopicName, packet.Data, 1, 153 | packet.Flags.Retain, packet.MsgId): 154 | self.puback.MsgId = packet.MsgId 155 | self.socket.send(self.puback.pack()) 156 | elif packet.Flags.QoS == 2: 157 | self.inMsgs[packet.MsgId] = packet 158 | self.pubrec.MsgId = packet.MsgId 159 | self.socket.send(self.pubrec.pack()) 160 | 161 | else: 162 | raise Exception("Unexpected packet"+str(packet)) 163 | return packet 164 | 165 | def __call__(self, callback): 166 | try: 167 | while True: 168 | self.receive(callback) 169 | except: 170 | if sys.exc_info()[0] != socket.error: 171 | print "unexpected exception", sys.exc_info() 172 | traceback.print_exc() 173 | -------------------------------------------------------------------------------- /amqtdd/build/Makefile: -------------------------------------------------------------------------------- 1 | ifndef AMQTDD_SRCDIR 2 | AMQTDD_SRCDIR = $(CURDIR) 3 | endif 4 | 5 | SOURCE_FILES = $(AMQTDD_SRCDIR)/*.c 6 | HEADERS = $(AMQTDD_SRCDIR)/*.h 7 | 8 | # In most cases the targets will be built for the native platform. However, to allow for cross compiling, 9 | # a target platform variable can be set to override the platform choice. If this variable is set to 10 | # a recognised string (currently just 'Arm') the appropriate values of OSTYPE and MACHINETYPE are set. 11 | ifeq ($(TARGET_PLATFORM),Arm) 12 | OSTYPE = Linux 13 | MACHINETYPE = Arm 14 | else 15 | ifeq ($(OS),Windows_NT) 16 | OSTYPE = $(OS) 17 | else 18 | OSTYPE = $(shell uname -s) 19 | MACHINETYPE = $(shell uname -m) 20 | endif 21 | endif 22 | 23 | ifeq ($(OSTYPE), Windows_NT) 24 | 25 | # the /Zp4 option aligns structure elements on 4 byte boundaries to allow 26 | # the heapdump mapping to work 27 | 28 | all: windows_ia32/amqtdd.exe amqtdd.ini be_amqtdd.dll 29 | 30 | ######################################################################################################### 31 | # The following was how the DeviceDaemon was built using cygwin GNU make and has been left here as a reference 32 | # This has been converted to use ming GNU make (which uses the native format of file names) 33 | # 34 | #windows_ia32/amqtdd.exe: $(shell cygpath -au ${SOURCE_FILES}) $(shell cygpath -au ${HEADERS}) 35 | # -mkdir windows_ia32 36 | # cl -O2 -DWIN32 ws2_32.lib $(shell cygpath -am ${SOURCE_FILES}) /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /Zp4 /Fewindows_ia32/amqtdd.exe -DMQTTMP /link /manifest 37 | # mt -manifest windows_ia32/amqtdd.exe.manifest -outputresource:windows_ia32/amqtdd.exe\;1 38 | # 39 | #amqtdd.ini: $(shell cygpath -au ${HEADERS}) 40 | # perl $(shell cygpath -am ${AMQTDD_SRCDIR})/tools/be/be.pl -s $(shell cygpath -am ${AMQTDD_SRCDIR}) -o amqtdd.ini 41 | # 42 | #be_amqtdd.dll: be_amqtdd.obj 43 | # link /NOLOGO /INCREMENTAL:NO /DLL be_amqtdd.obj /OUT:$@ 44 | # 45 | #be_amqtdd.obj: $(shell cygpath -au $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp) $(shell cygpath -au $(AMQTDD_SRCDIR)/tools/be/bememext.h) 46 | # cl /c /DWIN32 /D_CRT_SECURE_NO_WARNINGS /Gs /Oit /MT /nologo /W3 /WX /Tp $(shell cygpath -am $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp) /Febe_amqtdd.obj 47 | ######################################################################################################### 48 | 49 | windows_ia32/amqtdd.exe: ${SOURCE_FILES} ${HEADERS} 50 | -mkdir windows_ia32 51 | cl -O2 -DWIN32 ws2_32.lib ${SOURCE_FILES} /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /Zp4 /Fewindows_ia32/amqtdd.exe -DMQTTMP /link /manifest 52 | mt -manifest windows_ia32/amqtdd.exe.manifest -outputresource:windows_ia32/amqtdd.exe\;1 53 | 54 | amqtdd.ini: ${HEADERS} 55 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 56 | 57 | be_amqtdd.dll: be_amqtdd.obj 58 | link /NOLOGO /INCREMENTAL:NO /DLL be_amqtdd.obj /OUT:$@ 59 | 60 | be_amqtdd.obj: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 61 | cl /c /DWIN32 /D_CRT_SECURE_NO_WARNINGS /Gs /Oit /MT /nologo /W3 /WX /Tp $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp /Febe_amqtdd.obj 62 | 63 | endif 64 | 65 | ifeq ($(OSTYPE),Linux) 66 | 67 | ifeq ($(MACHINETYPE),x86_64) 68 | CC = gcc 69 | 70 | all: linux_ia64/amqtdd #amqtdd.ini be_amqtdd.so 71 | 72 | linux_ia64/amqtdd: ${SOURCE_FILES} ${HEADERS} 73 | -mkdir linux_ia64 74 | ${CC} -m64 -Wall -s -Os ${SOURCE_FILES} -o linux_ia64/amqtdd -DMQTTMP 75 | 76 | amqtdd.ini: ${HEADERS} 77 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 78 | 79 | be_amqtdd.so: be_amqtdd.o 80 | g++ -Wall -shared -o $@ be_amqtdd.o 81 | chmod a-x $@ 82 | 83 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 84 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 85 | 86 | else 87 | ifeq ($(MACHINETYPE),s390x) 88 | CC = gcc 89 | 90 | all: linux_s390x/amqtdd #amqtdd.ini be_amqtdd.so 91 | 92 | linux_s390x/amqtdd: ${SOURCE_FILES} ${HEADERS} 93 | -mkdir linux_s390x 94 | ${CC} -m64 -Wall -s -Os ${SOURCE_FILES} -o linux_s390x/amqtdd -DREVERSED -DMQTTMP 95 | 96 | amqtdd.ini: ${HEADERS} 97 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 98 | 99 | be_amqtdd.so: be_amqtdd.o 100 | g++ -Wall -shared -o $@ be_amqtdd.o 101 | chmod a-x $@ 102 | 103 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 104 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 105 | 106 | else 107 | ifeq ($(MACHINETYPE),Arm) 108 | 109 | CC = gcc 110 | # ARM_GLIBC_CC = arm-linux-gcc 111 | # ARM_UCLIBC_CC = ~/x-tools/arm-unknown-linux-uclibcgnueabi/bin/arm-unknown-linux-uclibcgnueabi-gcc 112 | 113 | ifndef ARM_GLIBC_CC 114 | ARM_GLIBC_CC = arm-linux-gcc 115 | endif 116 | ifndef ARM_UCLIBC_CC 117 | ARM_UCLIBC_CC = arm-unknown-linux-uclibcgnueabi-gcc 118 | endif 119 | 120 | all: linux_ARM_glibc/amqtdd linux_ARM_uclibc/amqtdd 121 | 122 | linux_ARM_glibc/amqtdd: ${SOURCE_FILES} ${HEADERS} 123 | -mkdir linux_ARM_glibc 124 | ${ARM_GLIBC_CC} -Wall -s -Os ${SOURCE_FILES} -o linux_ARM_glibc/amqtdd -DMQTTMP 125 | 126 | linux_ARM_uclibc/amqtdd: ${SOURCE_FILES} ${HEADERS} 127 | -mkdir linux_ARM_uclibc 128 | ${ARM_UCLIBC_CC} -Wall -s -Os ${SOURCE_FILES} -o linux_ARM_uclibc/amqtdd -DMQTTMP 129 | 130 | else 131 | 132 | CC = gcc 133 | 134 | all: linux_ia32/amqtdd amqtdd.ini 135 | #all: linux_ia32/amqtdd amqtdd.ini be_amqtdd.so 136 | 137 | linux_ia32/amqtdd: ${SOURCE_FILES} ${HEADERS} 138 | -mkdir linux_ia32 139 | ${CC} -m32 -Wall -s -Os ${SOURCE_FILES} -o linux_ia32/amqtdd -DMQTTMP 140 | 141 | amqtdd.ini: ${HEADERS} 142 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 143 | 144 | be_amqtdd.so: be_amqtdd.o 145 | g++ -m32 -Wall -shared -o $@ be_amqtdd.o 146 | chmod a-x $@ 147 | 148 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 149 | g++ -m32 -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 150 | 151 | endif 152 | 153 | endif 154 | 155 | endif 156 | 157 | endif 158 | 159 | 160 | ifeq ($(OSTYPE),AIX) 161 | CC = gxlc 162 | 163 | all: aix/amqtdd #amqtdd.ini be_amqtdd.so 164 | 165 | aix/amqtdd: ${SOURCE_FILES} ${HEADERS} 166 | -mkdir aix 167 | ${CC} -s -Os ${SOURCE_FILES} -o aix/amqtdd -DREVERSED -DMQTTMP -DAIX 168 | 169 | amqtdd.ini: ${HEADERS} 170 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 171 | 172 | be_amqtdd.so: be_amqtdd.o 173 | g++ -Wall -shared -o $@ be_amqtdd.o 174 | chmod a-x $@ 175 | 176 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 177 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 178 | 179 | endif 180 | -------------------------------------------------------------------------------- /amqtdd/src/Makefile: -------------------------------------------------------------------------------- 1 | ifndef AMQTDD_SRCDIR 2 | AMQTDD_SRCDIR = $(CURDIR) 3 | endif 4 | 5 | SOURCE_FILES = $(AMQTDD_SRCDIR)/*.c 6 | HEADERS = $(AMQTDD_SRCDIR)/*.h 7 | 8 | # In most cases the targets will be built for the native platform. However, to allow for cross compiling, 9 | # a target platform variable can be set to override the platform choice. If this variable is set to 10 | # a recognised string (currently just 'Arm') the appropriate values of OSTYPE and MACHINETYPE are set. 11 | ifeq ($(TARGET_PLATFORM),Arm) 12 | OSTYPE = Linux 13 | MACHINETYPE = Arm 14 | else 15 | ifeq ($(OS),Windows_NT) 16 | OSTYPE = $(OS) 17 | else 18 | OSTYPE = $(shell uname -s) 19 | MACHINETYPE = $(shell uname -m) 20 | endif 21 | endif 22 | 23 | ifeq ($(OSTYPE), Windows_NT) 24 | 25 | # the /Zp4 option aligns structure elements on 4 byte boundaries to allow 26 | # the heapdump mapping to work 27 | 28 | all: windows_ia32/amqtdd.exe amqtdd.ini be_amqtdd.dll 29 | 30 | ######################################################################################################### 31 | # The following was how the DeviceDaemon was built using cygwin GNU make and has been left here as a reference 32 | # This has been converted to use ming GNU make (which uses the native format of file names) 33 | # 34 | #windows_ia32/amqtdd.exe: $(shell cygpath -au ${SOURCE_FILES}) $(shell cygpath -au ${HEADERS}) 35 | # -mkdir windows_ia32 36 | # cl -O2 -DWIN32 ws2_32.lib $(shell cygpath -am ${SOURCE_FILES}) /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /Zp4 /Fewindows_ia32/amqtdd.exe -DMQTTMP /link /manifest 37 | # mt -manifest windows_ia32/amqtdd.exe.manifest -outputresource:windows_ia32/amqtdd.exe\;1 38 | # 39 | #amqtdd.ini: $(shell cygpath -au ${HEADERS}) 40 | # perl $(shell cygpath -am ${AMQTDD_SRCDIR})/tools/be/be.pl -s $(shell cygpath -am ${AMQTDD_SRCDIR}) -o amqtdd.ini 41 | # 42 | #be_amqtdd.dll: be_amqtdd.obj 43 | # link /NOLOGO /INCREMENTAL:NO /DLL be_amqtdd.obj /OUT:$@ 44 | # 45 | #be_amqtdd.obj: $(shell cygpath -au $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp) $(shell cygpath -au $(AMQTDD_SRCDIR)/tools/be/bememext.h) 46 | # cl /c /DWIN32 /D_CRT_SECURE_NO_WARNINGS /Gs /Oit /MT /nologo /W3 /WX /Tp $(shell cygpath -am $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp) /Febe_amqtdd.obj 47 | ######################################################################################################### 48 | 49 | windows_ia32/amqtdd.exe: ${SOURCE_FILES} ${HEADERS} 50 | -mkdir windows_ia32 51 | cl -O2 -DWIN32 ws2_32.lib ${SOURCE_FILES} /W3 /D _CRT_SECURE_NO_WARNINGS /D UNICODE /MD /Zp4 /Fewindows_ia32/amqtdd.exe -DMQTTMP /link /manifest 52 | mt -manifest windows_ia32/amqtdd.exe.manifest -outputresource:windows_ia32/amqtdd.exe\;1 53 | 54 | amqtdd.ini: ${HEADERS} 55 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 56 | 57 | be_amqtdd.dll: be_amqtdd.obj 58 | link /NOLOGO /INCREMENTAL:NO /DLL be_amqtdd.obj /OUT:$@ 59 | 60 | be_amqtdd.obj: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 61 | cl /c /DWIN32 /D_CRT_SECURE_NO_WARNINGS /Gs /Oit /MT /nologo /W3 /WX /Tp $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp /Febe_amqtdd.obj 62 | 63 | endif 64 | 65 | ifeq ($(OSTYPE),Linux) 66 | 67 | ifeq ($(MACHINETYPE),x86_64) 68 | CC = gcc 69 | 70 | all: linux_ia64/amqtdd #amqtdd.ini be_amqtdd.so 71 | 72 | linux_ia64/amqtdd: ${SOURCE_FILES} ${HEADERS} 73 | -mkdir linux_ia64 74 | ${CC} -m64 -Wall -s -Os ${SOURCE_FILES} -o linux_ia64/amqtdd -DMQTTMP 75 | 76 | amqtdd.ini: ${HEADERS} 77 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 78 | 79 | be_amqtdd.so: be_amqtdd.o 80 | g++ -Wall -shared -o $@ be_amqtdd.o 81 | chmod a-x $@ 82 | 83 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 84 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 85 | 86 | else 87 | ifeq ($(MACHINETYPE),s390x) 88 | CC = gcc 89 | 90 | all: linux_s390x/amqtdd #amqtdd.ini be_amqtdd.so 91 | 92 | linux_s390x/amqtdd: ${SOURCE_FILES} ${HEADERS} 93 | -mkdir linux_s390x 94 | ${CC} -m64 -Wall -s -Os ${SOURCE_FILES} -o linux_s390x/amqtdd -DREVERSED -DMQTTMP 95 | 96 | amqtdd.ini: ${HEADERS} 97 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 98 | 99 | be_amqtdd.so: be_amqtdd.o 100 | g++ -Wall -shared -o $@ be_amqtdd.o 101 | chmod a-x $@ 102 | 103 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 104 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 105 | 106 | else 107 | ifeq ($(MACHINETYPE),Arm) 108 | 109 | CC = gcc 110 | # ARM_GLIBC_CC = arm-linux-gcc 111 | # ARM_UCLIBC_CC = ~/x-tools/arm-unknown-linux-uclibcgnueabi/bin/arm-unknown-linux-uclibcgnueabi-gcc 112 | 113 | ifndef ARM_GLIBC_CC 114 | ARM_GLIBC_CC = arm-linux-gcc 115 | endif 116 | ifndef ARM_UCLIBC_CC 117 | ARM_UCLIBC_CC = arm-unknown-linux-uclibcgnueabi-gcc 118 | endif 119 | 120 | all: linux_ARM_glibc/amqtdd linux_ARM_uclibc/amqtdd 121 | 122 | linux_ARM_glibc/amqtdd: ${SOURCE_FILES} ${HEADERS} 123 | -mkdir linux_ARM_glibc 124 | ${ARM_GLIBC_CC} -Wall -s -Os ${SOURCE_FILES} -o linux_ARM_glibc/amqtdd -DMQTTMP 125 | 126 | linux_ARM_uclibc/amqtdd: ${SOURCE_FILES} ${HEADERS} 127 | -mkdir linux_ARM_uclibc 128 | ${ARM_UCLIBC_CC} -Wall -s -Os ${SOURCE_FILES} -o linux_ARM_uclibc/amqtdd -DMQTTMP 129 | 130 | else 131 | 132 | CC = gcc 133 | 134 | all: linux_ia32/amqtdd amqtdd.ini 135 | #all: linux_ia32/amqtdd amqtdd.ini be_amqtdd.so 136 | 137 | linux_ia32/amqtdd: ${SOURCE_FILES} ${HEADERS} 138 | -mkdir linux_ia32 139 | ${CC} -m32 -Wall -s -Os ${SOURCE_FILES} -o linux_ia32/amqtdd -DMQTTMP 140 | 141 | amqtdd.ini: ${HEADERS} 142 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 143 | 144 | be_amqtdd.so: be_amqtdd.o 145 | g++ -m32 -Wall -shared -o $@ be_amqtdd.o 146 | chmod a-x $@ 147 | 148 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 149 | g++ -m32 -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 150 | 151 | endif 152 | 153 | endif 154 | 155 | endif 156 | 157 | endif 158 | 159 | 160 | ifeq ($(OSTYPE),AIX) 161 | CC = gxlc 162 | 163 | all: aix/amqtdd #amqtdd.ini be_amqtdd.so 164 | 165 | aix/amqtdd: ${SOURCE_FILES} ${HEADERS} 166 | -mkdir aix 167 | ${CC} -s -Os ${SOURCE_FILES} -o aix/amqtdd -DREVERSED -DMQTTMP -DAIX 168 | 169 | amqtdd.ini: ${HEADERS} 170 | perl ${AMQTDD_SRCDIR}/tools/be/be.pl -s ${AMQTDD_SRCDIR} -o amqtdd.ini 171 | 172 | be_amqtdd.so: be_amqtdd.o 173 | g++ -Wall -shared -o $@ be_amqtdd.o 174 | chmod a-x $@ 175 | 176 | be_amqtdd.o: $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp $(AMQTDD_SRCDIR)/tools/be/bememext.h 177 | g++ -Wall -DUNIX -DLINUX -fPIC -c $(AMQTDD_SRCDIR)/tools/be/be_amqtdd.cpp 178 | 179 | endif 180 | -------------------------------------------------------------------------------- /rsmb/src/Messages.txt: -------------------------------------------------------------------------------- 1 | #//%W% %I% 2 | #/******************************************************************************* 3 | #* Copyright (c) 2007, 2013 IBM Corp. 4 | #* 5 | #* All rights reserved. This program and the accompanying materials 6 | #* are made available under the terms of the Eclipse Public License v1.0 7 | #* and Eclipse Distribution License v1.0 which accompany this distribution. 8 | #* 9 | #* The Eclipse Public License is available at 10 | #* http://www.eclipse.org/legal/epl-v10.html 11 | #* and the Eclipse Distribution License is available at 12 | #* http://www.eclipse.org/org/documents/edl-v10.php. 13 | #* 14 | #* Contributors: 15 | #* Ian Craggs - initial API and implementation and/or initial documentation 16 | #*******************************************************************************/ 17 | # NLS_MESSAGEFORMAT_VAR 18 | # NLS_ENCODING=UNICODE 19 | 0=Could not read configuration file %s 20 | 1=No value for keyword %s on line %d 21 | 2=Unrecognized topic direction %s 22 | 3=Setting property "%s" to %s 23 | 4=Unrecognized boolean value %s on line number %d 24 | 5=Setting property "%s" to "%s" 25 | 6=Adding value "%s" to list "%s" 26 | 7=Setting property "%s" to %d 27 | 8=Unrecognized configuration keyword %s on line number %d 28 | 9=Cannot open %s file %s for writing, %ss will not be saved 29 | 10=Cannot open %s file %s for reading, %ss will not be restored 30 | 11=Restoring %ss from file %s 31 | 12=Wildcard in publish topic %.20s from client %s not allowed 32 | 13=Internal error; FFDC written to file %s 33 | 14=MQTT protocol starting, listening on port %d 34 | 15=Cannot start listener on port %d 35 | 16=MQTT protocol stopping 36 | 17=Closing client %s 37 | 18=Socket error for client identifier %s, socket %d, peer address %s; ending connection 38 | 19=Bad packet for client identifier %s, socket %d, peer address %s; ending connection 39 | 20=Socket error on socket %d, peer address %s; ending connection 40 | 21=Badly formed packet on socket %d, peer address %s; ending connection 41 | 22=Unknown MQTT packet type %d on socket %d 42 | 23=Connect was not first packet on socket %d, peer address %s; got %s 43 | 24=%d second keepalive timeout for client %s, ending connection 44 | 25=Incorrect configuration: acl_file requires password_file to be specified 45 | 28=Trying PUBLISH again for client %s, socket %d, message identifier %d 46 | 29=Socket error for client %s, socket %d, ending connection 47 | 30=Trying PUBREL again for client %s, message identifier %d 48 | 31=Refusing connection attempt for unauthorized client identifier %s 49 | 32=Connection attempt using unsupported protocol %s version %d received 50 | 33=Connection attempt to listener %d received from client %s on address %s 51 | 34=Duplicate connection attempt received for client identifier "%s" from address %s, ending oldest connection 52 | 38=Disconnection request received from client %s 53 | 39=Invalid user entry on line number %d 54 | 40=Unrecognized user %s on line number %d 55 | 41=Invalid access control rule on line number %d 56 | 42=Uptime: %d seconds 57 | 43=Messages received: %d 58 | 44=Messages sent: %d 59 | 45=Queued message limit reached for client %s. Number of messages discarded so far: %d 60 | 46=Broker stopping 61 | 47=Broker stopped 62 | 48=First Failure Data Capture (FFDC) condition occurred, but FFDC writing turned off 63 | 49=Configuration file name is %s 64 | 50=Packet %s received from client %s for message identifier %d, but no record of that message identifier found 65 | 51=Packet %s received from client %s for message identifier %d, but message is wrong QoS, %d 66 | 52=Packet %s received from client %s for message identifier %d, but message is in wrong state 67 | 53=Version %s, %s 68 | 54=Features included: 69 | 55=Maximum heap use: %d bytes 70 | 56=Bridge connection %s not started because its client identifier %s is a duplicate 71 | 57=Connection %s is deleted 72 | 58=Error deleting connection %s 73 | 59=No bridge connection with name %s 74 | 60=Stopping bridge connection %s 75 | 61=Unable to stop connection %s 76 | 62=Connection %s is now stopped 77 | 63=Stopping connection %s on idle timeout 78 | 64=%d queued messages discarded for client %s 79 | 65=Unable to clear retained flag for system topic %s 80 | 66=Discarding retained message with invalid topic name %s 81 | 67=Error getting network format for address %s 82 | 68=Processing command file %s 83 | 71=Unexpected ping response received for client %s 84 | 75=Socket error %d (%s) in %s for socket %d 85 | 77=Cannot open socket 86 | 78=Cannot bind port %d 87 | 79=TCP listen call failed for port %d 88 | 92=%s is not a valid IP address 89 | 99=Trying bridge connection %s address %s again, without private protocol 90 | 100=Autosaving persistent data after %d changes 91 | 101=Autosaving persistent data after %d second interval 92 | 104=Saving persistence state at user request 93 | 105=Ignoring user request to save state because there are no changes 94 | 109=Failed to setsockopt SO_REUSEADDR on listening port %d 95 | 123=Trying backup bridge connection %s 96 | 124=Starting bridge connection %s 97 | 125=Error starting bridge connection 98 | 127=Starting reconnection attempt for bridge connection %s, address %s 99 | 128=TCP connect timeout for bridge connection %s 100 | 129=Can't get connection completion state from socket 101 | 130=Connect for bridge client %s, address %s, failed with TCP error code %d 102 | 132=Connection acknowledgement rc %d received for client %s 103 | 133=Bridge connection %s to %s now established 104 | 134=Closing bridge backup connection %s 105 | 135=Inbound bridge topic %s does not match any pattern for connection %s 106 | 136=Outbound bridge topic %s does not match any pattern for connection %s 107 | 139=retained message 108 | 140=subscription 109 | 141=Refusing connection attempt by client %s; maximum number of connections %d already reached for listener %d 110 | 142=Incorrect configuration: no addresses for bridge connection %s 111 | 143=Ping response not received within %d seconds for bridge connection %s; ending connection 112 | 144=Connection with name %s already exists; add failed 113 | 145=Message queue for client %s is more than %d%% full 114 | 146=Message queue for client %s is less than %d%% full 115 | 147=Error saving retained message persistence file 116 | 148=Error saving subscription persistence file 117 | 149=Client %s is not authorized to publish to topic: %s 118 | 150=Client %s is not authorized to subscribe to topic: %s 119 | 151=Cannot give read access to topic: %s 120 | 152=Unrecognized configuration value %s on line number %d 121 | 153=Invalid topic syntax in subscription %.20s from client identifier %s, peer address %s 122 | 300=MQTT-S protocol starting, listening on port %d 123 | 301=MQTT-S protocol stopping 124 | 302=Unknown interface %s for if_nametoindex 125 | 303=Adding multicast interface %s on interface %s 126 | -------------------------------------------------------------------------------- /rsmb/src/Messages.1.3.0.2: -------------------------------------------------------------------------------- 1 | #//%W% %I% 2 | #/******************************************************************************* 3 | #* Copyright (c) 2007, 2013 IBM Corp. 4 | #* 5 | #* All rights reserved. This program and the accompanying materials 6 | #* are made available under the terms of the Eclipse Public License v1.0 7 | #* and Eclipse Distribution License v1.0 which accompany this distribution. 8 | #* 9 | #* The Eclipse Public License is available at 10 | #* http://www.eclipse.org/legal/epl-v10.html 11 | #* and the Eclipse Distribution License is available at 12 | #* http://www.eclipse.org/org/documents/edl-v10.php. 13 | #* 14 | #* Contributors: 15 | #* Ian Craggs - initial API and implementation and/or initial documentation 16 | #*******************************************************************************/ 17 | # NLS_MESSAGEFORMAT_VAR 18 | # NLS_ENCODING=UNICODE 19 | 0=Could not read configuration file %s 20 | 1=No value for keyword %s on line %d 21 | 2=Unrecognized topic direction %s 22 | 3=Setting property "%s" to %s 23 | 4=Unrecognized boolean value %s on line number %d 24 | 5=Setting property "%s" to "%s" 25 | 6=Adding value "%s" to list "%s" 26 | 7=Setting property "%s" to %d 27 | 8=Unrecognized configuration keyword %s on line number %d 28 | 9=Cannot open %s file %s for writing, %ss will not be saved 29 | 10=Cannot open %s file %s for reading, %ss will not be restored 30 | 11=Restoring %ss from file %s 31 | 12=Wildcard in publish topic %.20s from client %s not allowed 32 | 13=Internal error; FFDC written to file %s 33 | 14=MQTT protocol starting, listening on port %d 34 | 15=Cannot start listener on port %d 35 | 16=MQTT protocol stopping 36 | 17=Closing client %s 37 | 18=Socket error for client identifier %s, socket %d, peer address %s; ending connection 38 | 19=Bad packet for client identifier %s, socket %d, peer address %s; ending connection 39 | 20=Socket error on socket %d, peer address %s; ending connection 40 | 21=Badly formed packet on socket %d, peer address %s; ending connection 41 | 22=Unknown MQTT packet type %d on socket %d 42 | 23=Connect was not first packet on socket %d, peer address %s; got %s 43 | 24=%d second keepalive timeout for client %s, ending connection 44 | 25=Incorrect configuration: acl_file requires password_file to be specified 45 | 28=Trying PUBLISH again for client %s, socket %d, message identifier %d 46 | 29=Socket error for client %s, socket %d, ending connection 47 | 30=Trying PUBREL again for client %s, message identifier %d 48 | 31=Refusing connection attempt for unauthorized client identifier %s 49 | 32=Connection attempt using unsupported protocol %s version %d received 50 | 33=Connection attempt to listener %d received from client %s on address %s 51 | 34=Duplicate connection attempt received for client identifier "%s" from address %s, ending oldest connection 52 | 38=Disconnection request received from client %s 53 | 39=Invalid user entry on line number %d 54 | 40=Unrecognized user %s on line number %d 55 | 41=Invalid access control rule on line number %d 56 | 42=Uptime: %d seconds 57 | 43=Messages received: %d 58 | 44=Messages sent: %d 59 | 45=Queued message limit reached for client %s. Number of messages discarded so far: %d 60 | 46=Broker stopping 61 | 47=Broker stopped 62 | 48=First Failure Data Capture (FFDC) condition occurred, but FFDC writing turned off 63 | 49=Configuration file name is %s 64 | 50=Packet %s received from client %s for message identifier %d, but no record of that message identifier found 65 | 51=Packet %s received from client %s for message identifier %d, but message is wrong QoS, %d 66 | 52=Packet %s received from client %s for message identifier %d, but message is in wrong state 67 | 53=Version %s, %s 68 | 54=Features included: 69 | 55=Maximum heap use: %d bytes 70 | 56=Bridge connection %s not started because its client identifier %s is a duplicate 71 | 57=Connection %s is deleted 72 | 58=Error deleting connection %s 73 | 59=No bridge connection with name %s 74 | 60=Stopping bridge connection %s 75 | 61=Unable to stop connection %s 76 | 62=Connection %s is now stopped 77 | 63=Stopping connection %s on idle timeout 78 | 64=%d queued messages discarded for client %s 79 | 65=Unable to clear retained flag for system topic %s 80 | 66=Discarding retained message with invalid topic name %s 81 | 67=Error getting network format for address %s 82 | 68=Processing command file %s 83 | 71=Unexpected ping response received for client %s 84 | 75=Socket error %d (%s) in %s for socket %d 85 | 77=Cannot open socket 86 | 78=Cannot bind port %d 87 | 79=TCP listen call failed for port %d 88 | 92=%s is not a valid IP address 89 | 99=Trying bridge connection %s address %s again, without private protocol 90 | 100=Autosaving persistent data after %d changes 91 | 101=Autosaving persistent data after %d second interval 92 | 104=Saving persistence state at user request 93 | 105=Ignoring user request to save state because there are no changes 94 | 109=Failed to setsockopt SO_REUSEADDR on listening port %d 95 | 123=Trying backup bridge connection %s 96 | 124=Starting bridge connection %s 97 | 125=Error starting bridge connection 98 | 127=Starting reconnection attempt for bridge connection %s, address %s 99 | 128=TCP connect timeout for bridge connection %s 100 | 129=Can't get connection completion state from socket 101 | 130=Connect for bridge client %s, address %s, failed with TCP error code %d 102 | 132=Connection acknowledgement rc %d received for client %s 103 | 133=Bridge connection %s to %s now established 104 | 134=Closing bridge backup connection %s 105 | 135=Inbound bridge topic %s does not match any pattern for connection %s 106 | 136=Outbound bridge topic %s does not match any pattern for connection %s 107 | 139=retained message 108 | 140=subscription 109 | 141=Refusing connection attempt by client %s; maximum number of connections %d already reached for listener %d 110 | 142=Incorrect configuration: no addresses for bridge connection %s 111 | 143=Ping response not received within %d seconds for bridge connection %s; ending connection 112 | 144=Connection with name %s already exists; add failed 113 | 145=Message queue for client %s is more than %d%% full 114 | 146=Message queue for client %s is less than %d%% full 115 | 147=Error saving retained message persistence file 116 | 148=Error saving subscription persistence file 117 | 149=Client %s is not authorized to publish to topic: %s 118 | 150=Client %s is not authorized to subscribe to topic: %s 119 | 151=Cannot give read access to topic: %s 120 | 152=Unrecognized configuration value %s on line number %d 121 | 153=Invalid topic syntax in subscription %.20s from client identifier %s, peer address %s 122 | 300=MQTT-S protocol starting, listening on port %d 123 | 301=MQTT-S protocol stopping 124 | 302=Unknown interface %s for if_nametoindex 125 | 303=Adding multicast interface %s on interface %s 126 | -------------------------------------------------------------------------------- /rsmb/src/Bridge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(BRIDGE_H) 19 | #define BRIDGE_H 20 | 21 | #include "Clients.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTPacket.h" 24 | 25 | /*BE 26 | include "Clients" 27 | include "SubsEngine" 28 | include "MQTTPacket" 29 | include "MQTTProtocol" 30 | BE*/ 31 | 32 | /*BE 33 | map BRIDGE_TOPIC_DIRECTION 34 | { 35 | "both" . 36 | "in" . 37 | "out" . 38 | } 39 | 40 | def BRIDGETOPICS 41 | { 42 | n32 ptr STRING open "pattern" 43 | n32 ptr STRING open "localPrefix" 44 | n32 ptr STRING open "remotePrefix" 45 | n32 map BRIDGE_TOPIC_DIRECTION "direction" 46 | $ifdef MQTTS 47 | n32 map bool "subscribed" 48 | $endif 49 | } 50 | defList(BRIDGETOPICS) 51 | BE*/ 52 | /** 53 | * Bridge topic structure 54 | */ 55 | typedef struct 56 | { 57 | char *pattern, /**< topic pattern */ 58 | *localPrefix, /**< local prefix from config */ 59 | *remotePrefix; /**< remote prefix from config */ 60 | int direction; /**< out, in or both */ 61 | int priority; 62 | #if defined(MQTTS) 63 | int subscribed; /**< has this topic been subscribed to? */ 64 | #endif 65 | } BridgeTopics; /**< Bridge topic structure */ 66 | 67 | /*BE 68 | map START_TYPES 69 | { 70 | "START_AUTOMATIC" . 71 | "START_MANUAL" . 72 | "START_LAZY" . 73 | "START_ONCE" . 74 | } 75 | map RUN_STATE 76 | { 77 | "CONNECTION_STOPPED" . 78 | "CONNECTION_RUNNING" . 79 | "CONNECTION_STOPPING" . 80 | "CONNECTION_STOPPING_THEN_DELETE" . 81 | "CONNECTION_DELETE" . 82 | "CONNECTION_SWITCHING" . 83 | } 84 | BE*/ 85 | enum start_types { START_AUTOMATIC, START_MANUAL, START_LAZY, START_ONCE }; 86 | enum run_state { CONNECTION_STOPPED, CONNECTION_RUNNING, CONNECTION_STOPPING, 87 | CONNECTION_STOPPING_THEN_DELETE, CONNECTION_DELETE, CONNECTION_SWITCHING}; 88 | 89 | 90 | /*BE 91 | def BRIDGECONNECTIONS 92 | { 93 | n32 ptr STRING open "name" 94 | n32 ptr STRINGList open "addresses" 95 | n32 ptr STRINGItem open "cur_address" 96 | n32 map bool "round_robin" 97 | n32 map bool "try_private" 98 | n32 map CONNACK_RETURN_CODES "last_connect_result" 99 | n32 map bool "notifications" 100 | n32 map START_TYPES "start_type" 101 | n32 map bool "stop_was_manual" 102 | n32 dec "cleansession" 103 | n32 dec "no_successful_connections" 104 | n32 ptr STRING open "notification_topic" 105 | n32 dec "keepalive_interval" 106 | n32 dec "inbound_filter" 107 | n32 ptr BRIDGETOPICSList open "topics" 108 | expr "topics->count" dec "number of topics" 109 | n32 ptr CLIENTS "primary" 110 | n32 ptr CLIENTS "backup" 111 | n32 dec "threshold" 112 | n32 dec "idle_timeout" 113 | n32 map RUN_STATE "state" 114 | $ifdef MQTTS 115 | n32 map PROTOCOLS "protocol" 116 | n32 map bool "completed_subscriptions" 117 | n32 dec "loopback" 118 | $endif 119 | n32 ptr STRING open "username" 120 | n32 ptr STRING open "password" 121 | n32 ptr STRING open "clientid" 122 | } 123 | defList(BRIDGECONNECTIONS) 124 | BE*/ 125 | /** 126 | * State for each bridge connection. 127 | */ 128 | typedef struct 129 | { 130 | char* name; /**< connection name */ 131 | List* addresses; /**< list of connection addresses */ 132 | ListElement* cur_address; /**< current connection address */ 133 | unsigned int round_robin; /**< round robin flag */ 134 | unsigned int try_private; /**< try private bridge connection for nanobrokers */ 135 | unsigned int last_connect_result; /**< did the last connection attempt work? */ 136 | unsigned int notifications; /**< send notifications on stop/start? */ 137 | unsigned int start_type; /**< automatic, manual, lazy, once */ 138 | unsigned int stop_was_manual; /**< manual stop means don't auto restart */ 139 | int cleansession; /**< clean session override flag */ 140 | int no_successful_connections; /**< how many successful connections have there been */ 141 | char* notification_topic; /**< what topic to issue the notifications on */ 142 | int keepalive_interval; /**< MQTT keepalive interval to use in seconds */ 143 | int inbound_filter; /**< not yet used */ 144 | List* topics; /**< of BridgeTopics */ 145 | Clients* primary; /**< primary bridge client */ 146 | Clients* backup; /**< not needed in round robin mode */ 147 | int threshold; /**< lazy bridge setting */ 148 | int idle_timeout; /**< lazy bridge setting */ 149 | volatile unsigned int state; /**< run state of the connection */ 150 | #if defined(MQTTS) 151 | int protocol; /* 0=MQTT 1=MQTTS 2=MQTTS_MULTICAST*/ 152 | unsigned int completed_subscriptions; /* have all the inbound topics been subscribed to? */ 153 | int loopback; /**< multicast loopback? */ 154 | #endif 155 | char* username; /**< username for authenticated connections */ 156 | char* password; /**< password for authenticated connections */ 157 | char* clientid; /**< allow the explicit setting of clientid */ 158 | } BridgeConnections; 159 | 160 | /*BE 161 | def BRIDGES 162 | { 163 | n32 ptr BRIDGECONNECTIONSList open "connections" 164 | } 165 | BE*/ 166 | /** 167 | * Bridge state 168 | */ 169 | typedef struct 170 | { 171 | List* connections; /**< list of connections */ 172 | } Bridges; /**< bridge state */ 173 | 174 | void Bridge_initialize(Bridges* br, SubscriptionEngines* se); 175 | void Bridge_stop(Bridges* br); 176 | BridgeConnections* Bridge_new_connection(Bridges* bridge, char* name); 177 | void Bridge_terminate(Bridges* br); 178 | void Bridge_timeslice(Bridges* bridge); 179 | void Bridge_handleConnection(Clients* client); 180 | int Bridge_handleConnacks(void* pack, int sock, Clients* client); 181 | void Bridge_handleInbound(Clients* client, Publish* publish); 182 | void Bridge_handleOutbound(Clients* client, Publish* publish); 183 | 184 | #if defined(MQTTS) 185 | BridgeConnections* Bridge_getBridgeConnection(int sock); 186 | Clients* Bridge_getClient(int sock); 187 | #endif 188 | 189 | #if !defined(NO_ADMIN_COMMANDS) 190 | int Bridge_startConnection(char* name); 191 | int Bridge_stopConnection(char* name); 192 | int Bridge_deleteConnection(char* name); 193 | #endif 194 | 195 | #endif /* BRIDGE_H */ 196 | -------------------------------------------------------------------------------- /amqtdd/build/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | source.folder not set 5 | output.folder not set 6 | release.version not set 7 | build.level not set 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /amqtdd/src/Bridge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | 18 | #if !defined(BRIDGE_H) 19 | #define BRIDGE_H 20 | 21 | #include "Clients.h" 22 | #include "SubsEngine.h" 23 | #include "MQTTPacket.h" 24 | 25 | /*BE 26 | include "Clients" 27 | include "SubsEngine" 28 | include "MQTTPacket" 29 | include "MQTTProtocol" 30 | BE*/ 31 | 32 | /*BE 33 | map BRIDGE_TOPIC_DIRECTION 34 | { 35 | "both" . 36 | "in" . 37 | "out" . 38 | } 39 | 40 | def BRIDGETOPICS 41 | { 42 | n32 ptr STRING open "pattern" 43 | n32 ptr STRING open "localPrefix" 44 | n32 ptr STRING open "remotePrefix" 45 | n32 map BRIDGE_TOPIC_DIRECTION "direction" 46 | $ifdef MQTTS 47 | n32 map bool "subscribed" 48 | $endif 49 | } 50 | defList(BRIDGETOPICS) 51 | BE*/ 52 | /** 53 | * Bridge topic structure 54 | */ 55 | typedef struct 56 | { 57 | char *pattern, /**< topic pattern */ 58 | *localPrefix, /**< local prefix from config */ 59 | *remotePrefix; /**< remote prefix from config */ 60 | int direction; /**< out, in or both */ 61 | int priority; 62 | #if defined(MQTTS) 63 | int subscribed; /**< has this topic been subscribed to? */ 64 | #endif 65 | } BridgeTopics; /**< Bridge topic structure */ 66 | 67 | /*BE 68 | map START_TYPES 69 | { 70 | "START_AUTOMATIC" . 71 | "START_MANUAL" . 72 | "START_LAZY" . 73 | "START_ONCE" . 74 | } 75 | map RUN_STATE 76 | { 77 | "CONNECTION_STOPPED" . 78 | "CONNECTION_RUNNING" . 79 | "CONNECTION_STOPPING" . 80 | "CONNECTION_STOPPING_THEN_DELETE" . 81 | "CONNECTION_DELETE" . 82 | "CONNECTION_SWITCHING" . 83 | } 84 | BE*/ 85 | enum start_types { START_AUTOMATIC, START_MANUAL, START_LAZY, START_ONCE }; 86 | enum run_state { CONNECTION_STOPPED, CONNECTION_RUNNING, CONNECTION_STOPPING, 87 | CONNECTION_STOPPING_THEN_DELETE, CONNECTION_DELETE, CONNECTION_SWITCHING}; 88 | 89 | 90 | /*BE 91 | def BRIDGECONNECTIONS 92 | { 93 | n32 ptr STRING open "name" 94 | n32 ptr STRINGList open "addresses" 95 | n32 ptr STRINGItem open "cur_address" 96 | n32 map bool "round_robin" 97 | n32 map bool "try_private" 98 | n32 map CONNACK_RETURN_CODES "last_connect_result" 99 | n32 map bool "notifications" 100 | n32 map START_TYPES "start_type" 101 | n32 map bool "stop_was_manual" 102 | n32 dec "cleansession" 103 | n32 dec "no_successful_connections" 104 | n32 ptr STRING open "notification_topic" 105 | n32 dec "keepalive_interval" 106 | n32 dec "inbound_filter" 107 | n32 ptr BRIDGETOPICSList open "topics" 108 | expr "topics->count" dec "number of topics" 109 | n32 ptr CLIENTS "primary" 110 | n32 ptr CLIENTS "backup" 111 | n32 dec "threshold" 112 | n32 dec "idle_timeout" 113 | n32 map RUN_STATE "state" 114 | $ifdef MQTTS 115 | n32 map PROTOCOLS "protocol" 116 | n32 map bool "completed_subscriptions" 117 | $endif 118 | n32 ptr STRING open "username" 119 | n32 ptr STRING open "password" 120 | n32 ptr STRING open "clientid" 121 | } 122 | defList(BRIDGECONNECTIONS) 123 | BE*/ 124 | /** 125 | * State for each bridge connection. 126 | */ 127 | typedef struct 128 | { 129 | char* name; /**< connection name */ 130 | List* addresses; /**< list of connection addresses */ 131 | ListElement* cur_address; /**< current connection address */ 132 | unsigned int round_robin; /**< round robin flag */ 133 | unsigned int try_private; /**< try private bridge connection for nanobrokers */ 134 | unsigned int last_connect_result; /**< did the last connection attempt work? */ 135 | unsigned int notifications; /**< send notifications on stop/start? */ 136 | unsigned int start_type; /**< automatic, manual, lazy, once */ 137 | unsigned int stop_was_manual; /**< manual stop means don't auto restart */ 138 | int cleansession; /**< clean session override flag */ 139 | int no_successful_connections; /**< how many successful connections have there been */ 140 | char* notification_topic; /**< what topic to issue the notifications on */ 141 | int keepalive_interval; /**< MQTT keepalive interval to use in seconds */ 142 | int inbound_filter; /**< not yet used */ 143 | List* topics; /**< of BridgeTopics */ 144 | Clients* primary; /**< primary bridge client */ 145 | Clients* backup; /**< not needed in round robin mode */ 146 | int threshold; /**< lazy bridge setting */ 147 | int idle_timeout; /**< lazy bridge setting */ 148 | volatile unsigned int state; /**< run state of the connection */ 149 | #if defined(MQTTS) 150 | int protocol; /* 0=MQTT 1=MQTTS */ 151 | unsigned int completed_subscriptions; /* have all the inbound topics been subscribed to? */ 152 | #endif 153 | char* username; /**< username for authenticated connections */ 154 | char* password; /**< password for authenticated connections */ 155 | char* clientid; /**< allow the explicit setting of clientid */ 156 | int start_reconnect_interval; /**< the starting, minimum retry interval after a failure */ 157 | int max_reconnect_interval; /**< if set, max of the range of retry intervals */ 158 | int reconnect_interval; /**< current value of retry interval (backs off on failure) */ 159 | int reconnect_count; 160 | int chosen_reconnect_interval; 161 | int connect_timeout; 162 | } BridgeConnections; 163 | 164 | /*BE 165 | def BRIDGES 166 | { 167 | n32 ptr BRIDGECONNECTIONSList open "connections" 168 | } 169 | BE*/ 170 | /** 171 | * Bridge state 172 | */ 173 | typedef struct 174 | { 175 | List* connections; /**< list of connections */ 176 | } Bridges; /**< bridge state */ 177 | 178 | void Bridge_initialize(Bridges* br, SubscriptionEngines* se); 179 | void Bridge_stop(Bridges* br); 180 | BridgeConnections* Bridge_new_connection(Bridges* bridge, char* name); 181 | void Bridge_terminate(Bridges* br); 182 | void Bridge_timeslice(Bridges* bridge); 183 | void Bridge_handleConnection(Clients* client); 184 | int Bridge_handleConnacks(void* pack, int sock); 185 | void Bridge_handleInbound(Clients* client, Publish* publish); 186 | void Bridge_handleOutbound(Clients* client, Publish* publish); 187 | 188 | #if defined(MQTTS) 189 | BridgeConnections* Bridge_getBridgeConnection(int sock); 190 | Clients* Bridge_getClient(int sock); 191 | #endif 192 | 193 | #if !defined(NO_ADMIN_COMMANDS) 194 | int Bridge_startConnection(char* name); 195 | int Bridge_stopConnection(char* name); 196 | int Bridge_deleteConnection(char* name); 197 | #endif 198 | 199 | #endif /* BRIDGE_H */ 200 | -------------------------------------------------------------------------------- /amqtdd/src/Socket.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(SOCKET_H) 18 | #define SOCKET_H 19 | 20 | #include 21 | 22 | #if defined(WIN32) 23 | /* default on Windows is 64 - increase to make Linux and Windows the same */ 24 | #define FD_SETSIZE 1024 25 | #include 26 | #include 27 | #define MAXHOSTNAMELEN 256 28 | #define EAGAIN WSAEWOULDBLOCK 29 | #define EINTR WSAEINTR 30 | #define EINVAL WSAEINVAL 31 | #define EINPROGRESS WSAEINPROGRESS 32 | #define EWOULDBLOCK WSAEWOULDBLOCK 33 | #define ENOTCONN WSAENOTCONN 34 | #define ECONNRESET WSAECONNRESET 35 | #define ioctl ioctlsocket 36 | #define socklen_t int 37 | #else 38 | #define INVALID_SOCKET SOCKET_ERROR 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #endif 51 | 52 | /** socket operation completed successfully */ 53 | #define TCPSOCKET_COMPLETE 0 54 | #if !defined(SOCKET_ERROR) 55 | /** error in socket operation */ 56 | #define SOCKET_ERROR -1 57 | #endif 58 | /** must be the same as SOCKETBUFFER_INTERRUPTED */ 59 | #define TCPSOCKET_INTERRUPTED -2 60 | /** no further work was completed in this call */ 61 | #define TCPSOCKET_NOWORK -3 62 | 63 | #define UDPSOCKET_INCOMPLETE 0 64 | 65 | #if !defined(INET6_ADDRSTRLEN) 66 | #define INET6_ADDRSTRLEN 46 /**< only needed for gcc/cygwin on windows */ 67 | #endif 68 | 69 | #if !defined(max) 70 | #define max(A,B) ( (A) > (B) ? (A):(B)) 71 | #endif 72 | 73 | #include "LinkedList.h" 74 | 75 | #if !defined(SINGLE_LISTENER) 76 | /*BE 77 | def SOCKADDR_IN 78 | { 79 | // TODO: will be different sizes on some platforms 80 | 16 n8 "sockaddr" 81 | } 82 | def SOCKADDR_IN6 83 | { 84 | // TODO: will be different sizes on some platforms 85 | 28 n8 "sockaddr6" 86 | } 87 | $ifndef SINGLE_LISTENER 88 | def CONNECTION 89 | { 90 | n32 dec "socket" 91 | } 92 | defList(CONNECTION) 93 | 94 | def LISTENER 95 | { 96 | n32 dec "socket" 97 | SOCKADDR_IN "addr" 98 | SOCKADDR_IN6 "addr6" 99 | n32 map bool "ipv6" 100 | n32 map PROTOCOLS "protocol" 101 | n32 ptr STRING open "address" 102 | n32 dec "port" 103 | n32 ptr CONNECTIONList open "connections" 104 | n32 signed dec "max_connections" 105 | n32 ptr STRING "mount_point" 106 | } 107 | defList(LISTENER) 108 | $endif 109 | BE*/ 110 | 111 | 112 | typedef struct 113 | { 114 | int socket; 115 | struct sockaddr_in addr; 116 | struct sockaddr_in6 addr6; 117 | int ipv6; 118 | int protocol; /* 0 = MQTT, 1 = MQTTS, 2 = MQTTMP */ 119 | char* address; 120 | int port; 121 | List* connections; 122 | int max_connections; 123 | char* mount_point; 124 | } Listener; 125 | #endif 126 | 127 | /*BE 128 | def NEWSOCKET 129 | { 130 | n32 dec "socket" 131 | $ifdef WIN32 132 | n64 time "opened" 133 | $else 134 | n32 time "opened" 135 | $endif 136 | n32 dec "outbound" 137 | } 138 | defList(NEWSOCKET) 139 | $endif 140 | BE*/ 141 | 142 | typedef struct 143 | { 144 | int socket; 145 | time_t opened; 146 | int outbound; 147 | } NewSockets; 148 | 149 | /*BE 150 | def FD_SET 151 | { 152 | 128 n8 "data" 153 | } 154 | 155 | def SOCKETS 156 | { 157 | $ifndef SINGLE_LISTENER 158 | n32 ptr LISTENERList open "listeners" 159 | $else 160 | n32 dec "mySocket" 161 | n32 dec "port" 162 | SOCKADDR_IN "addr" 163 | SOCKADDR_IN6 "addr6" 164 | n32 dec "ipv6" 165 | $endif 166 | FD_SET "rset" 167 | FD_SET "rset_saved" 168 | n32 dec "maxfdp1" 169 | n32 ptr INTList "clientsds" 170 | n32 ptr INTItem "cur_clientsds" 171 | n32 ptr INTList "connect_pending" 172 | n32 ptr INTList "write_pending" 173 | FD_SET "pending_wset" 174 | n32 ptr NEWSOCKETList open "newsockets" 175 | } 176 | BE*/ 177 | 178 | /** 179 | * Structure to hold all socket data for the module 180 | */ 181 | typedef struct 182 | { 183 | #if !defined(SINGLE_LISTENER) 184 | List* listeners; /**< list of listener structures */ 185 | #else 186 | int mySocket; /**< server socket */ 187 | int port; /**< server port to listen on */ 188 | struct sockaddr_in addr; 189 | struct sockaddr_in6 addr6; 190 | int ipv6; 191 | #endif 192 | fd_set rset, /**< socket read set (see select doc) */ 193 | rset_saved; /**< saved socket read set */ 194 | int maxfdp1; /**< max descriptor used +1 (again see select doc) */ 195 | List* clientsds; /**< list of client socket descriptors */ 196 | ListElement* cur_clientsds; /**< current client socket descriptor (iterator) */ 197 | List* connect_pending; /**< list of sockets for which a connect is pending */ 198 | List* write_pending; /**< list of sockets for which a write is pending */ 199 | fd_set pending_wset; /**< socket pending write set for select */ 200 | List* newSockets; /**< sockets that haven't connected yet */ 201 | } Sockets; 202 | 203 | 204 | #if !defined(SINGLE_LISTENER) 205 | int Socket_initialize(List* myListeners); 206 | int Socket_addServerSocket(Listener* listener); 207 | Listener* Socket_new_listener(); 208 | Listener* Socket_getParentListener(int sock); 209 | #else 210 | int Socket_initialize(char* anAddress, int aPort, int ipv6); 211 | #endif 212 | 213 | int Socket_error(char* aString, int sock); 214 | 215 | void Socket_outInitialize(); 216 | void Socket_outTerminate(); 217 | void Socket_terminate(); 218 | int Socket_getReadySocket(int more_work, struct timeval *tp); 219 | int Socket_getch(int socket, char* c); 220 | char *Socket_getdata(int socket, int bytes, int* actual_len); 221 | int Socket_putdatas(int socket, char* buf0, int buf0len, int count, char** buffers, int* buflens, int* bufffree); 222 | void Socket_close(int socket); 223 | int Socket_new(char* addr, int port, int* socket); 224 | #if defined(MQTTS) 225 | int Socket_new_type(char* addr, int port, int* sock, int type); 226 | #endif 227 | char* Socket_gethostname(); 228 | char* Socket_getpeer(int sock); 229 | char* Socket_getaddrname(struct sockaddr* sa, int sock); 230 | 231 | int Socket_noPendingWrites(int socket); 232 | 233 | typedef struct 234 | { 235 | int more_work_count; 236 | int not_more_work_count; 237 | int timeout_zero_count; 238 | int timeout_non_zero_count; 239 | } socket_stats; 240 | 241 | socket_stats* Socket_getStats(); 242 | 243 | Sockets* Socket_getSockets(); 244 | NewSockets* Socket_getNew(int socket); 245 | int Socket_removeNew(int socket); 246 | void Socket_cleanNew(time_t now); 247 | 248 | #endif /* SOCKET_H */ 249 | -------------------------------------------------------------------------------- /amqtdd/src/Users.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007, 2013 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs, Nicholas O'Leary - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /** 18 | * @file 19 | * User module. 20 | * Handles authentication and authorisation 21 | */ 22 | 23 | #include "LinkedList.h" 24 | #include "Broker.h" 25 | #include "SubsEngine.h" 26 | #include "Topics.h" 27 | #include "Log.h" 28 | #include "StackTrace.h" 29 | 30 | #include "Users.h" 31 | 32 | #include 33 | 34 | #include "Heap.h" 35 | 36 | BrokerStates* bstate; 37 | 38 | void Users_initialize(BrokerStates* aBrokerState) 39 | { 40 | FUNC_ENTRY; 41 | bstate = aBrokerState; 42 | bstate->defaultACL = ListInitialize(); 43 | FUNC_EXIT; 44 | } 45 | 46 | /** 47 | * Adds the specified user to the known user list. 48 | * @param username 49 | * @param pword 50 | */ 51 | void Users_add_user(char* username, char* pword) 52 | { 53 | User* u = malloc(sizeof(User)); 54 | 55 | FUNC_ENTRY; 56 | memset(u, '\0', sizeof(User)); 57 | u->username = malloc(strlen(username)+1); 58 | u->password = malloc(strlen(pword)+1); 59 | strcpy(u->username,username); 60 | strcpy(u->password,pword); 61 | u->acl = ListInitialize(); 62 | ListAppend(bstate->users,u,sizeof(u)+strlen(username)+strlen(pword)+2); 63 | FUNC_EXIT; 64 | } 65 | 66 | /** 67 | * Frees the memory used by the provided list of ACL structs 68 | */ 69 | void Users_free_acl(List* list) 70 | { 71 | ListElement* current = NULL; 72 | 73 | FUNC_ENTRY; 74 | while (ListNextElement(list, ¤t)) 75 | { 76 | Rule* rule = (Rule*)(current->content); 77 | free(rule->topic); 78 | } 79 | ListFree(list); 80 | FUNC_EXIT; 81 | } 82 | 83 | /** 84 | * Frees the memory used by the user list and all ACL lists 85 | */ 86 | void Users_free_list() 87 | { 88 | ListElement* current = NULL; 89 | 90 | FUNC_ENTRY; 91 | while (ListNextElement(bstate->users, ¤t)) 92 | { 93 | User* user = (User*)(current->content); 94 | free(user->username); 95 | free(user->password); 96 | Users_free_acl(user->acl); 97 | } 98 | ListFree(bstate->users); 99 | Users_free_acl(bstate->defaultACL); 100 | 101 | FUNC_EXIT; 102 | } 103 | 104 | int userCompare(void* a, void* b) 105 | { 106 | User* user = (User*)a; 107 | return strcmp(user->username,(char*)b) == 0; 108 | } 109 | 110 | /** 111 | * Encrypts the provided password. Currently, this is a no-op as 112 | * passwords are stored in clear-text. 113 | * @param pword the unencrypted password 114 | * @return the encrypted password 115 | */ 116 | char* Users_encrypt_password(char* pword) 117 | { 118 | // For now, handle things in clear-text 119 | return pword; 120 | } 121 | 122 | /** 123 | * Verifies the specified username/password is valid 124 | * @param username 125 | * @param pword 126 | * @return whether the user is authenticated - (true/false) 127 | */ 128 | int Users_authenticate(char* username, char* pword) 129 | { 130 | User* user = NULL; 131 | int result = false; 132 | char* encryptedPword = Users_encrypt_password(pword); 133 | 134 | FUNC_ENTRY; 135 | if ((user = Users_get_user(username)) != NULL) 136 | { 137 | if (strcmp(user->password,encryptedPword)==0) 138 | { 139 | result = true; 140 | } 141 | } 142 | FUNC_EXIT_RC(result); 143 | return result; 144 | } 145 | 146 | /** 147 | * Gets the User struct for the specified username 148 | */ 149 | User* Users_get_user(char* username) 150 | { 151 | User* user = NULL; 152 | ListElement* elem = NULL; 153 | 154 | if ((elem = ListFindItem(bstate->users, username, userCompare)) != NULL) 155 | { 156 | user = (User*)elem->content; 157 | } 158 | return user; 159 | } 160 | 161 | /** 162 | * Creates an ACL struct 163 | */ 164 | Rule* Users_create_rule(char* topic, int permission) 165 | { 166 | Rule* rule = NULL; 167 | 168 | FUNC_ENTRY; 169 | rule = malloc(sizeof(Rule)); 170 | rule->permission = permission; 171 | rule->topic = malloc(strlen(topic)+1); 172 | strcpy(rule->topic,topic); 173 | FUNC_EXIT; 174 | return rule; 175 | } 176 | 177 | /** 178 | * Adds the specified ACL information to the default ACL 179 | */ 180 | void Users_add_default_rule(char* topic, int permission) 181 | { 182 | Rule* rule = NULL; 183 | 184 | FUNC_ENTRY; 185 | rule = Users_create_rule(topic,permission); 186 | ListAppend(bstate->defaultACL, rule, sizeof(rule)+strlen(topic)+1); 187 | FUNC_EXIT; 188 | } 189 | 190 | /** 191 | * Adds the specified ACL information to the specified User's ACL 192 | */ 193 | void Users_add_rule(User* user, char* topic, int permission) 194 | { 195 | Rule* rule = NULL; 196 | 197 | FUNC_ENTRY; 198 | rule = Users_create_rule(topic,permission); 199 | ListAppend(user->acl, rule, sizeof(rule)+strlen(topic)+1); 200 | FUNC_EXIT; 201 | } 202 | 203 | int Users_subscription_matches(char* ruleTopic, char* subTopic) 204 | { 205 | int rc = false; 206 | int subIsWC = Topics_hasWildcards(subTopic); 207 | 208 | FUNC_ENTRY; 209 | if (!subIsWC) 210 | rc = Topics_matches(ruleTopic, subTopic); 211 | else 212 | { 213 | int t1 = strcspn(ruleTopic, "#"); 214 | rc = (strncmp(ruleTopic,subTopic,t1)==0); 215 | } 216 | FUNC_EXIT_RC(rc); 217 | return rc; 218 | } 219 | /** 220 | * Finds the most specific Rule in the specified list for 221 | * the provided topic. 222 | */ 223 | int Users_authorise1(List* aclList, char* topic, int action) 224 | { 225 | int rc = true; 226 | ListElement* current = NULL; 227 | 228 | FUNC_ENTRY; 229 | while (ListNextElement(aclList, ¤t)) 230 | { 231 | Rule* rule = (Rule*)(current->content); 232 | if (action == ACL_WRITE) 233 | { 234 | if (Topics_matches(rule->topic, topic)) 235 | if (rule->permission == ACL_FULL || rule->permission == action) 236 | goto exit; 237 | } 238 | else 239 | { 240 | if (Users_subscription_matches(rule->topic, topic)) 241 | if (rule->permission == ACL_FULL || rule->permission == action) 242 | goto exit; 243 | } 244 | } 245 | rc = false; 246 | exit: 247 | FUNC_EXIT_RC(rc); 248 | return rc; 249 | } 250 | 251 | /** 252 | * Checks whether the specified user is allowed to access the specified topic 253 | */ 254 | int Users_authorise(User* user, char* topic, int action) 255 | { 256 | int rc = true; 257 | 258 | FUNC_ENTRY; 259 | if (!Users_authorise1(bstate->defaultACL, topic, action)) 260 | { 261 | if (user != NULL) 262 | { 263 | rc = Users_authorise1(user->acl, topic, action); 264 | goto exit; 265 | } 266 | else 267 | { 268 | rc = false; 269 | goto exit; 270 | } 271 | } 272 | exit: 273 | FUNC_EXIT_RC(rc); 274 | return rc; 275 | } 276 | 277 | --------------------------------------------------------------------------------