Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Protocol Mechanics

As we have talked about before, within the context of XML messaging, Jabber's open XML protocol contains only three top-level XML elements:

<message/> (carrier for 'ordinary' conversational elements) 
<presence/> (carrier for presences and availability messages)
<iq/> (carrier for informational and query messages) 

With these elements, a client can create messages that accomplish all the design goals of an instant messaging system and more.

NOTE

As you'll see in later chapters, the Jabber server uses other XML elements for system management, but these three are the ones clients use most.

You can think of these message types as the basic structure of the carrier of concepts between users, applications, and between Jabber message switches. They are the equivalent of spoken language rules whereby words or other elements of sentence structure are combined to form grammatical sentences.

You may not have realized it (because we haven't discussed it yet) but all these asynchronously generated and arriving XML stanzas with presence, conversation, and queries don't simply appear at the switch completely out of context, as it were.

As shown in Figure 3.1, from a client standpoint, a session with the Jabber switch occurs in the context of an XML stream. This stream may be viewed as similar to a telephone conversation where a "hello" and "goodbye" are the signals for the beginning and end of a conversation. Everything in between is the body of a conversation; whether it's about the impending snow storm or a stock transfer is immaterial from the standpoint of the switch. It just wants well-formed "sentences" in the stream. The tagging of each individual message will aid the switch in routing your conversation.

Figure 3.1Figure 3.1 A conversational stream between a single client and the switch.

Of course the jabberd is handling many simultaneous streams from potentially many clients at the same time. As depicted in Figure 3.2, some of your messages are destined for other clients, and the switch has to be able to route those on your behalf.

Figure 3.2Figure 3.2 Serving multiple clients.

The switch can also, on its own initiative, send messages as a proxy for you. For example, as Figure 3.2 suggests, when you go offline, a presence message gets sent to other clients, some of whom are on your roster and who want to alert their users that you are no longer available. Thus, within the possible conversations between a client and a server, some messages are relevant to setting up and maintaining a relationship with the server, and some are concerned with maintaining the conversational context between clients, but all must be expressed in the syntax covered in this chapter and all are contained within an XML stream that begins with a <stream> tag and officially ends when the server gets the matching </stream> tag. This all makes some sense when you remember that XML documents can have only a single root tag. Thus everything sent to or via the server must be contained within the confines of an outermost tag—the <stream> </stream> pair.

To prove that this is so and that we are not just spewing nonsense, write a little shell script that does the equivalent of a "Hello world" programming example.

In an editor buffer, type this in:

<stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>

If your development Jabber server is somewhere other than localhost, then replace that bit with the correct information.

Also, type this in on the next line:

</stream:stream>

Next, start a shell to run a Telnet session as shown in Figure 3.3.

Figure 3.3Figure 3.3 Telnet "Hello World" example.

Make certain that you turn on local echo as shown in Figure 3.3 so that you can catch the output returned by the jabberd message switch.

Next, cut the first line from your editor buffer and paste it into the Telnet window, as shown in Figure 3.4.

NOTE

We didn't recommend typing in the initial XML because we can't type that many characters without an error; if you've a steady hand, however, you could have done so. Also note that there is a time limit imposed by the server for receiving data and logging in. If you fail to meet that time limit, it boots you off. That's another reason not to hand type it.

Figure 3.4Figure 3.4 Completing "Hello World."

As shown, the server should return back the string:

<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' id='3E453A18' xmlns='jabber:client' from='localhost'>

To which you reply (either by typing or pasting),

</stream:stream>

Essentially, this is the equivalent of ringing the phone, waiting for an answer, then ringing off.

The answer you got from the server contained an id field with some hex digits in it. Notice the importance and varying uses of the id as you go through the following examples.

To expand the "Hello World" example, let's exercise one of the three acceptable message types. This time after opening a session with the <stream> tag shown earlier, let's ask the server what it takes to register a new user by pasting in the following "sentence," which is an <iq> XML stanza whose type is a 'get'—we're asking for information.

<iq id='AnythingYouWantHere' type='get'>
 <query xmlns='jabber:iq:register'/>
</iq>

The server returns an <iq> message with the same ID you used to make the query, whose type is 'result':

<iq id=' AnythingYouWantHere ' type='result'>
<query xmlns='jabber:iq:register'>
 <password/>
 <instructions>
   Choose a username and password to register with this server.
   </instructions>
   <name/>
   <email/>
   <username/>
</query>
</iq>

This is a sentence in Jabber-ese explaining that if you're going to create a client in these here parts, you're going to have to supply a name and password, a nickname (username), and an email address. Now you can paste back the following into your Telnet window:

<iq id='WhateverYouWantHere' type='set'>
 <query xmlns='jabber:iq:register'>
 <username>Praline</username>
 <password>Cleese</password>
 <name>Mr_Praline</name>
 <email>Mr_Praline@python.com</email>
 </query>
</iq> 

The Jabber server responds back to you using the same ID, and tells you that you are good to go as a new user:

<iq id='WhateverYouWantHere' type='result'/>

If you were writing a client in a programming language instead of shoving some XML in front of the server's face with Telnet, you could probably imagine that your register user method would jam the outgoing request into a dictionary structure keyed by id, put yourself into an idle loop, and then whenever the server got around to responding, you would parse the XML out of the continuously arriving stream, match up the response and see whether you were successful or not. You can imagine once again that if this were code, the iq 'result' should be interpreted by your client as 'success'. On the other hand, if you tried a second time to register, the server would slap your virtual wrist by responding as follows:

</iq><iq id='WhateverYouWantHere' type='error'>
 <query xmlns='jabber:iq:register'>
  <username>Praline</username>
  <password>Cleese</password>
  <name> Mr_Praline</name>
  <email> Mr_Praline@python.com </email>
 </query>
 <error code='409'>Username Not Available</error>
</iq> 

This is what you would fervently hope (if you were Mr. Praline) that the Jabber server would do.

Now assume you've now logged in successfully as Mr. Praline by opening a Telnet stream, pasting in the opening <stream> tag , and pasting in a login request:

<iq id='WhateverYouWantHere' type='set'>
 <query xmlns='jabber:iq:auth'>
 <username>Praline</username>
 <password>Cleese</password>
 <resource>telnet</resource>
 </query>
</iq>

You got back the hoped for

<iq id='WhateverYouWantHere' type='result'/>

from jabberd. Now say you have some buddies on your roster, which you could have created via a set of <iq>-based messages. We're not going to show that here, as we want to keep things simple for the sake of illustration. Let's inject a <presence/> into the stream and see the effects; simply paste in or type:

<presence/>

This forces the server to take a peak at your stored profile (in this case praline.xml) and shove a roster back at you:

<presence from='jane@localhost/Home' to='Praline@localhost'>
 <status>available</status>
 <priority>0</priority>
 <x xmlns='jabber:x:delay' from='jane@localhost/Home' stamp='20030208T20:47:44'/>
 <x xmlns='jabber:x:delay' from='jane@localhost/Home' stamp='20030208T20:47:44'/>
</presence>
<presence from='dana@localhost/Home' to='Praline@localhost'>
 <status>available</status>
 <priority>0</priority>
 <x xmlns='jabber:x:delay' from='dana@localhost/Home' stamp='20030208T20:15:29'/>
 <x xmlns='jabber:x:delay' from='dana@localhost/Home' stamp='20030208T20:15:30'/>
</presence>

Finally, let's say you wanted to re-enact the infamous Monty Python "Dead Parrot" sketch online. Here, you would use the final type of xml stanza type, <message/>. Once again, given that you have opened a Telnet to your jabberd on port 5222, have gotten the server's attention with a starting <stream> tag, and are logged in with an <iq> tag shown earlier, you can send a message:

<message from='Praline@localhost' to='dana@localhost' type='chat'> 
 <body>
 I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.
 </body> 
</message> 

Assuming dana is using one of the several real clients and not just typing in XML stanzas as you have been doing, a chat window pops up on dana's client (see Figure 3.5), and away you go with the dialogue.

Figure 3.5Figure 3.5 Using the "message" XML stanza.

What you actually see in the more primitive Telnet window looks like this, however, with a message ID and thread ID generated by dana's client (so that it could track subsequent messages on the same topic—at least as the concept of "topics" is understood by the communicants). Note too that the apostrophes are escaped as you would expect to see in a proper XML stream: A client and the server must deal with proper XML construction.

<message id='jcl_52' to='Praline@localhost' type='chat' from='dana@localhost/Home'>
 <thread>fd6d59abf7970b853d09580693569290739a80ae</thread>
 <body>
 Oh yes, the, uh, the Norwegian Blue...What&apos;s,uh...What&apos;s wrong with it?
 </body>
 <x xmlns='jabber:x:event'>
 <composing/>
 </x>
</message>

If you wanted to respond, you might type into the Telnet stream:

<message id='' from='Praline@localhost' to='dana@localhost' type='chat'> 
 <body>
 I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!
 </body> 
</message> 

More about the id attribute and the <thread/> tag later.

After a bit more of this, you would end the conversation with the server by typing in the closing </stream:stream> tag. If you were actually typing in the example, you might have noticed that as soon as you typed in the final > character, the Telnet session closed immediately. The Jabber server reads every character sent to it and uses an event-driven XML parser. As soon as the "hang up" event is fully detected—poof, your session is gone.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020