All pastes #33546 Raw Edit

Miscellany

public text v1 · immutable
#33546 ·published 2005-12-13 18:14 UTC
rendered paste body
bool read_node = false;

read:
read_node = reader.Read();
no_read:
if( !read_node )
{
	// at end of available reading material, it seems.
	throw new Xmpp.ProtocolException("No stream:stream element found!");
}
else if( reader.NodeType == XmlNodeType.None )
{
	throw new Xmpp.Exception("WTF");
}
else if( reader.NodeType == XmlNodeType.XmlDeclaration )
{
	// Read another node off the top of the stack.
	goto read;
}
else if(	reader.NodeType == XmlNodeType.Element 
	&&	reader.Name == "stream:stream" )
{
	if(log.IsDebugEnabled) log.Debug("Found stream:stream opening element...");
		
	/*
		Only thing I care about in stream-opening element is xmpp version...
		If this call returns false, throw an exception because the version 
		attribute is missing.
	*/
	if( !reader.MoveToAttribute("version") )
	{
		throw new Xmpp.ProtocolException(
			"Server failed to specify Xmpp version!");
	}
	else if( log.IsDebugEnabled )
	{
		log.Debug("Found \"version\" attribute for stream:stream element");
	}
	
	// Don't call Read(), MoveToAttribute() already read a new node.
	goto no_read;
}
else if(	reader.NodeType == XmlNodeType.Attribute
	&&	reader.Name == "version" )
{
	if( reader.Value != "1.0" )
	{
		throw new Xmpp.ProtocolException(
			String.Format("Bad version \"{0}\"!", reader.Value)); 
	}
	
	// Go to next stage.
	goto end;
}

end:

/* this is used to parse the first TWO (!!) elements of  following:
0000   00 00 03 04 00 00 00 00 00 00 00 00 00 00 08 00  ................
0010   45 00 02 74 68 ac 40 00 40 06 d1 d5 7f 00 00 01  E..th.@.@.......
0020   7f 00 00 01 d7 b6 87 9d 64 63 22 81 63 88 e2 c5  ........dc".c...
0030   80 18 20 00 00 69 00 00 01 01 08 0a dc 50 4a 34  .. ..i.......PJ4
0040   dc 50 4a 33 3c 3f 78 6d 6c 20 76 65 72 73 69 6f  .PJ3<?xml versio
0050   6e 3d 27 31 2e 30 27 20 65 6e 63 6f 64 69 6e 67  n='1.0' encoding
0060   3d 27 55 54 46 2d 38 27 3f 3e 3c 73 74 72 65 61  ='UTF-8'?><strea
0070   6d 3a 73 74 72 65 61 6d 20 78 6d 6c 6e 73 3a 73  m:stream xmlns:s
0080   74 72 65 61 6d 3d 22 68 74 74 70 3a 2f 2f 65 74  tream="http://et
0090   68 65 72 78 2e 6a 61 62 62 65 72 2e 6f 72 67 2f  herx.jabber.org/
00a0   73 74 72 65 61 6d 73 22 20 78 6d 6c 6e 73 3d 22  streams" xmlns="
00b0   6a 61 62 62 65 72 3a 63 6c 69 65 6e 74 22 20 66  jabber:client" f
00c0   72 6f 6d 3d 22 6c 6f 63 61 6c 68 6f 73 74 22 20  rom="localhost" 
00d0   69 64 3d 22 63 61 34 39 61 62 36 61 22 20 78 6d  id="ca49ab6a" xm
00e0   6c 3a 6c 61 6e 67 3d 22 65 6e 22 20 76 65 72 73  l:lang="en" vers
00f0   69 6f 6e 3d 22 31 2e 30 22 3e 3c 73 74 72 65 61  ion="1.0"><strea
0100   6d 3a 66 65 61 74 75 72 65 73 3e 3c 73 74 61 72  m:features><star
0110   74 74 6c 73 20 78 6d 6c 6e 73 3d 22 75 72 6e 3a  ttls xmlns="urn:
0120   69 65 74 66 3a 70 61 72 61 6d 73 3a 78 6d 6c 3a  ietf:params:xml:
0130   6e 73 3a 78 6d 70 70 2d 74 6c 73 22 3e 3c 2f 73  ns:xmpp-tls"></s
0140   74 61 72 74 74 6c 73 3e 3c 6d 65 63 68 61 6e 69  tarttls><mechani
0150   73 6d 73 20 78 6d 6c 6e 73 3d 22 75 72 6e 3a 69  sms xmlns="urn:i
0160   65 74 66 3a 70 61 72 61 6d 73 3a 78 6d 6c 3a 6e  etf:params:xml:n
0170   73 3a 78 6d 70 70 2d 73 61 73 6c 22 3e 3c 6d 65  s:xmpp-sasl"><me
0180   63 68 61 6e 69 73 6d 3e 43 52 41 4d 2d 4d 44 35  chanism>CRAM-MD5
0190   3c 2f 6d 65 63 68 61 6e 69 73 6d 3e 3c 6d 65 63  </mechanism><mec
01a0   68 61 6e 69 73 6d 3e 44 49 47 45 53 54 2d 4d 44  hanism>DIGEST-MD
01b0   35 3c 2f 6d 65 63 68 61 6e 69 73 6d 3e 3c 6d 65  5</mechanism><me
01c0   63 68 61 6e 69 73 6d 3e 50 4c 41 49 4e 3c 2f 6d  chanism>PLAIN</m
01d0   65 63 68 61 6e 69 73 6d 3e 3c 6d 65 63 68 61 6e  echanism><mechan
01e0   69 73 6d 3e 41 4e 4f 4e 59 4d 4f 55 53 3c 2f 6d  ism>ANONYMOUS</m
01f0   65 63 68 61 6e 69 73 6d 3e 3c 2f 6d 65 63 68 61  echanism></mecha
0200   6e 69 73 6d 73 3e 3c 61 75 74 68 20 78 6d 6c 6e  nisms><auth xmln
0210   73 3d 22 68 74 74 70 3a 2f 2f 6a 61 62 62 65 72  s="http://jabber
0220   2e 6f 72 67 2f 66 65 61 74 75 72 65 73 2f 69 71  .org/features/iq
0230   2d 61 75 74 68 22 2f 3e 3c 72 65 67 69 73 74 65  -auth"/><registe
0240   72 20 78 6d 6c 6e 73 3d 22 68 74 74 70 3a 2f 2f  r xmlns="http://
0250   6a 61 62 62 65 72 2e 6f 72 67 2f 66 65 61 74 75  jabber.org/featu
0260   72 65 73 2f 69 71 2d 72 65 67 69 73 74 65 72 22  res/iq-register"
0270   2f 3e 3c 2f 73 74 72 65 61 6d 3a 66 65 61 74 75  /></stream:featu
0280   72 65 73 3e                                      res>
*/