Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Patch for sending Gateway Info Messages

I have implemented the handling of search GW Messages and sending GWInfo Messages.

Attached the patch

Ian , Please review...

Regards,
Md.Jamal

-------------------------------------------------------------------------------------------------------------------------------
[ C-DAC is on facebook. Kindly follow us on the following url:  https://www.facebook.com/CDACINDIA ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
-------------------------------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------------------------------------
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
-------------------------------------------------------------------------------------------------------------------------------

Only in org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src: broker
Only in org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src: broker.cfg
Only in org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src: broker_dbg
Only in org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src: broker_mqtts
Only in org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src: FFDC.CWNAN.20141028.150212.813.dmp
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/Messages.c org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Messages.c
--- org.eclipse.mosquitto.rsmb/rsmb/src/Messages.c	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Messages.c	2014-10-28 14:58:27.856063044 +0530
@@ -77,7 +77,7 @@
     "%d %s %s -> MQTT-S SEARCHGW", /* 32 */
     "%d %s %s <- MQTT-S SEARCHGW", /* 33 */
     "%d %s %s -> MQTT-S GWINFO", /* 34 */
-    "%d %s %s <- MQTT-S GWINFO", /* 35 */
+    "%d %s %s %d <- MQTT-S GWINFO", /* 35 */
     "reserved", /* 36 */
     "reserved", /* 37 */
     "%d %s %s -> MQTT-S CONNECT cleansession: %d (%d)", /* 38 */
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacket.c org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacket.c
--- org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacket.c	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacket.c	2014-10-28 14:59:43.344063271 +0530
@@ -807,6 +807,23 @@
 	return rc;
 }
 
+int MQTTSPacket_send_gwInfo(int sock,char *clientAddress,char *gwAddress,unsigned char gwId)
+{
+	PacketBuffer buf;
+	int rc = 0;
+
+	FUNC_ENTRY;
+	buf = MQTTSPacketSerialize_gwInfo(gwId, gwAddress);
+	
+	rc = MQTTSPacket_sendPacketBuffer(sock, clientAddress, buf);
+	
+	free(buf.data);
+
+	Log(LOG_PROTOCOL, 35, NULL, socket, clientAddress, gwAddress, gwId, rc);
+	FUNC_EXIT_RC(rc);
+	return rc;
+
+}
 
 int MQTTSPacket_send_connack(Clients* client, int returnCode)
 {
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacket.h org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacket.h
--- org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacket.h	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacket.h	2014-10-28 14:59:05.092063162 +0530
@@ -281,6 +281,7 @@
 
 int MQTTSPacket_send(int socket, char* addr, MQTTSHeader header, char* buffer, int buflen);
 int MQTTSPacket_send_publish(Clients* client, MQTTS_Publish* pub);
+int MQTTSPacket_send_gwInfo(int sock,char *clientAddress,char *gwAddress,unsigned char gwId);
 int MQTTSPacket_send_connack(Clients* client, int returnCode);
 int MQTTSPacket_send_willTopicReq(Clients* client);
 int MQTTSPacket_send_willMsgReq(Clients* client);
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacketSerialize.c org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacketSerialize.c
--- org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacketSerialize.c	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacketSerialize.c	2014-10-28 14:58:08.548062991 +0530
@@ -85,6 +85,23 @@
 	return buf;
 }
 
+PacketBuffer MQTTSPacketSerialize_gwInfo(unsigned char gateway_id,char *address)
+{
+	MQTTSHeader header;
+	PacketBuffer buf;
+	
+	FUNC_ENTRY;
+	header.len = 3+strlen(address);
+	header.type = MQTTS_GWINFO;
+
+	buf = MQTTSPacketSerialize_header(header);
+
+	writeChar(&buf.ptr, gateway_id);
+	memcpy(buf.ptr,address,strlen(address));
+	FUNC_EXIT;
+	return buf;
+}
+
 
 PacketBuffer MQTTSPacketSerialize_connect(int cleansession, int will, char protocolID, short keepAlive, char* clientID)
 {
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacketSerialize.h org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacketSerialize.h
--- org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSPacketSerialize.h	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSPacketSerialize.h	2014-10-28 14:57:36.740062923 +0530
@@ -28,6 +28,7 @@
 
 PacketBuffer MQTTSPacketSerialize_ack(char type, int msgId);
 PacketBuffer MQTTSPacketSerialize_advertise(unsigned char gateway_id, short duration);
+PacketBuffer MQTTSPacketSerialize_gwInfo(unsigned char gateway_id, char *address);
 PacketBuffer MQTTSPacketSerialize_connect(int cleansession, int will, char protocolID, short keepAlive, char* clientID);
 PacketBuffer MQTTSSerialize_connack(int returnCode);
 
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSProtocol.c org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSProtocol.c
--- org.eclipse.mosquitto.rsmb/rsmb/src/MQTTSProtocol.c	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/MQTTSProtocol.c	2014-10-28 15:01:43.032063628 +0530
@@ -296,7 +296,19 @@
 
 int MQTTSProtocol_handleSearchGws(void* pack, int sock, char* clientAddr, Clients* client)
 {
-	return 0;
+	ListElement* current = NULL;
+	int rc = 0;
+	FUNC_ENTRY;
+	while (ListNextElement(bstate->listeners, &current))
+	{
+		Listener *listener = (Listener*)current->content;
+		if (listener->gatewayinfo)
+		{
+			rc = MQTTSPacket_send_gwInfo(sock,clientAddr,listener->gatewayinfo->address,listener->gatewayinfo->gateway_id); 
+		}
+	}	
+	FUNC_EXIT_RC(rc);
+	return rc;
 }
 
 
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/Persistence.c org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Persistence.c
--- org.eclipse.mosquitto.rsmb/rsmb/src/Persistence.c	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Persistence.c	2014-10-28 14:56:03.008062617 +0530
@@ -167,6 +167,7 @@
 #if defined(MQTTS)
 	{ "multicast_groups", 3, offsetof(Listener, multicast_groups) },
 	{ "advertise", 1, offsetof(Listener, advertise) },
+	{ "gateway", 1, offsetof(Listener , gatewayinfo) },
 	{ "loopback", PROPERTY_INT, offsetof(Listener, loopback) },
 #endif
 	{ "connection", 1, offsetof(BridgeConnections, name) },
@@ -582,6 +583,21 @@
 								  adv->gateway_id = atoi(val);
 							}
 							((Listener*)s)->advertise = adv;
+						}else if (strcmp(pword, "gateway") == 0)
+						{
+							/* gateway address gateway_id*/
+							gatewayinfo_parms *gw = malloc(sizeof(gatewayinfo_parms));
+							memset(gw,'\0',sizeof(gatewayinfo_parms));
+							gw->address = malloc(strlen(val) + 1);
+							strcpy(gw->address,val);
+							if ((val = strtok_r(NULL, delims, &curpos)))
+							{
+								gw->gateway_id = atoi(val);							}
+							if(true)
+							printf("Gateway Address:%s,gateway id:%d\n",gw->address,gw->gateway_id);					
+							((Listener *)s)->gatewayinfo = gw;
+
+
 						}
 						else
 #endif
diff -rauB org.eclipse.mosquitto.rsmb/rsmb/src/Socket.h org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Socket.h
--- org.eclipse.mosquitto.rsmb/rsmb/src/Socket.h	2014-10-28 15:03:10.216063885 +0530
+++ org.eclipse.mosquitto.rsmb_with_gwinfo/rsmb/src/Socket.h	2014-10-28 14:54:33.948062352 +0530
@@ -91,6 +91,12 @@
 
 typedef struct
 {
+	char *address;
+	unsigned char gateway_id;
+} gatewayinfo_parms;
+
+typedef struct
+{
 	char* address;
 	unsigned char gateway_id;
 	int interval;
@@ -155,6 +161,7 @@
 #if defined(MQTTS)
 	List* multicast_groups;
 	advertise_parms* advertise;
+	gatewayinfo_parms *gatewayinfo;
 	int loopback;
 #endif
 #if defined(USE_POLL)

Back to the top