Managing the roster

Apart from connecting to the XMPP network, we need a way to manage our roster, or who our friends are. In this chapter, we will use the simplest, but not safest, approach, by accepting all presence subscription requests:

private void AttachFeatures() 
{ 
this.xmppClient.OnPresenceSubscribe += (Sender, e) => 
{ 
Log.Informational("Accepting friendship request.", 
this.xmppClient.BareJID, e.From); 
e.Accept(); 
}; 
 
this.xmppClient.OnPresenceUnsubscribe += (Sender, e) => 
{ 
Log.Informational("Friendship removed.", 
this.xmppClient.BareJID, e.From); 
e.Accept(); 
}; 
 
this.xmppClient.OnPresenceSubscribed += (Sender, e) => 
Log.Informational("Friendship request accepted.", 
this.xmppClient.BareJID, e.From); 
this.xmppClient.OnPresenceUnsubscribed += (Sender, e) => 
Log.Informational("Friendship removal accepted.", 
this.xmppClient.BareJID, e.From); 

We also take the opportunity to log events of interest:

this.xmppClient.OnError += (Sender, ex) => Log.Error(ex); 
this.xmppClient.OnPasswordChanged += (Sender, e) => 
Log.Informational("Password changed.", 
this.xmppClient.BareJID); 
} 
Note that anyone with an active subscription to your device's presence will be able to request sensor data from it, and be able to request control actions to be performed on it. In a later chapter, we will discuss how to secure this.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset