image

Preface:

This article is a note about I study XMPP spec recent days. To maniplate a XMPP client, it might be easy to deal it with IP*WORKs 3rd party XMPP client. But it could not fulfil some custom request such as:

  • Not response friend request immediatelly, once we got it.
  • Handle roster (friend list) programmatically
  • Maniplate VCard as custom information storage.

In those case, we might need to handle XMPP XML commands to

Ejabberd

image

Ejabberd is a XMPP server(which twitter use it at first). It written by Erlang, it is powerful to handle multiple user connectivity.

XMPP Command

Both we could have two ways to manipulate XMPP, one by 3rd party XMPP framework. We will use IP*Work for a example which you can find sample code from web here.

Another one is using basic XML send to XMPP server directly. Actually we still use IP*Works. sendCommand to send our XML to XMPP server. However, use “SendCommand” could be more powerful and straintforward because we handle all XMPP commands directly.

Subscription Management

Add Subscription (Friend Request)

XMPP module should provide transfer XML command directly to server to do following path:

You can use IQ message from server to filter what you need.

Handle Subscription (Friend Request)

Once you got the subscription request from server, normally you have two way to handle it.

  • If you use some XMPP framework (ex: IP*Works), you can monitor SubscriptionRequest.
    • Note: It will need your force response “accept” or “reject” once you receipt this event. If you want to handle it in lower command set. Refer second way.
  • Using low-level XML command from IQ event.

      //Receive Friend request.
      <iq from='[email protected]/balcony' type='get' id='roster_1'>
          <query xmlns='jabber:iq:roster'/>
      </iq>
    
      //accept
      <presence to='[email protected]' type='subscribed'/>
      //reject
      <presence to='[email protected]' type='unsubscribed'/>
    

Normally, you will need send subscription back to make sure the status subscription. (a.k.a friendship) is bi-direction.

vCard Management

According to XEP:00544, vCard is an existing and widely-used standard for personal user information storage, somewhat like an electronic business card.

It using the XML format which can store any information you need it. Detail spec refer to RFC 2426

The vCard information might present information as follow

How we use vCard?

Because vCard could be any format of XML table.

    //Abstract information from vCard
    <vCard xmlns='vcard-temp'>
        <FN>Peter Saint-Andre</FN>
        <N>
          <FAMILY>Saint-Andre</FAMILY>
          <GIVEN>Peter</GIVEN>
          <MIDDLE/>
        </N>
        <NICKNAME>stpeter</NICKNAME>
        <URL>http://www.xmpp.org/xsf/people/stpeter.shtml</URL>
        <BDAY>1966-08-06</BDAY>
        <ORG>
          <ORGNAME>XMPP Standards Foundation</ORGNAME>
          <ORGUNIT/>
        </ORG>
        <TITLE>Executive Director</TITLE>
        <ROLE>Patron Saint</ROLE>
        <TEL><WORK/><VOICE/><NUMBER>303-308-3282</NUMBER></TEL>
        <ADR>
          <WORK/>
          <EXTADD>Suite 600</EXTADD>
          <STREET>1899 Wynkoop Street</STREET>
          <LOCALITY>Denver</LOCALITY>
          <REGION>CO</REGION>
          <PCODE>80202</PCODE>
          <CTRY>USA</CTRY>
        </ADR>
        <TEL><HOME/><VOICE/><NUMBER>303-555-1212</NUMBER></TEL>
        <JABBERID>[email protected]</JABBERID>
        <DESC>
          More information about me is located on my 
          personal website: http://www.saint-andre.com/
        </DESC>
      </vCard>

As you could observe, the vCard could store address, name, phone number… etc.

So, I am wondering if we could store some custom data in vCard for our programming usage. But here is something you should note before use it.

  • vCard store as combination text:
    • vCard is store as a full text in the database, that’s mean you could not able search it via specific filed.
  • vCard is public:
    • Although vCard only modify by its owner, but it could find by everyone.

Enable vCard management in Ejabberd

Refer to Ejabberd extension. It has following API to management vCard as follow:

      //Get vCard
      vcard-get user host data [data2]
      
      //Set vCard
       vcard-set user host data [data2] content

[Note:]This command is old, need check latest one if you use Ejabberd 2.1 or newer version.

You can following this instructions to enable mod_admin_extra.

Management vCard data

Because there is no specific API in IP*Works to manipulate vCard, so we list it as XML commands.

Here is the detail:

    //Get vCard
    <iq from='[email protected]/roundabout'
        id='v1'
        type='get'>
      <vCard xmlns='vcard-temp'/>
    </iq>

    //Update vCard
    <iq id='v2' type='set'>
      <vCard xmlns='vcard-temp'>
        <FN>Peter Saint-Andre</FN>
      </vCard>
    </iq>    


    //Get other's vCard
    <iq from='[email protected]/roundabout'
        id='v3'
        to='[email protected]'
        type='get'>
      <vCard xmlns='vcard-temp'/>
    </iq>

Conclusion about vCard usage

Because of the result of those studies, the vCard might be a way to store some extra data in your custom IM system. But I will not suggest you to store some information as follow:

  • Information need to be searched by program.
    • vCard information can not search directly. You need parse it via XML tag.
  • Sensitive information
    • It is not suggest that you store some sensitive information such as password or paid information, because everyone can use XMPP protocol to access your vCard info.

Reference Spec/RFCs


Buy Me A Coffee

Evan

Attitude is everything