Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void login()
- throws IOException, LoginFailureException, CorruptStreamException
- {
- out.streamStart(connection.domain, connection.resource);
- System.err.println("sent stream start");
- sendFeatures();
- System.err.println("sent features");
- sendAuth();
- System.err.println("sent auth");
- in.streamStart();
- System.err.println("read stream start");
- String challengeData = readFeaturesAndChallenge();
- System.err.println("read features and challenge");
- sendResponse(challengeData);
- System.err.println("sent response");
- readSuccess();
- }
- private void sendFeatures()
- throws IOException
- {
- out.write(new ProtocolTreeNode("stream:features", null, connection.supports_receipt_acks ? (new ProtocolTreeNode[] {
- new ProtocolTreeNode("receipt_acks", null)
- }) : null), false);
- }
- private void sendAuth()
- throws IOException
- {
- ProtocolTreeNode node = new ProtocolTreeNode("auth", new KeyValue[] {
- new KeyValue("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"), new KeyValue("mechanism", "DIGEST-MD5-1")
- });
- out.write(node);
- }
- private String readFeaturesAndChallenge()
- throws IOException, CorruptStreamException
- {
- label0:
- {
- ProtocolTreeNode root;
- boolean server_supports_receipt_acks;
- label1:
- do
- {
- for(server_supports_receipt_acks = false; (root = in.nextTree()) != null; server_supports_receipt_acks = root.getChild("receipt_acks") != null)
- if(!ProtocolTreeNode.tagEquals(root, "stream:features"))
- continue label1;
- break label0;
- } while(!ProtocolTreeNode.tagEquals(root, "challenge"));
- connection.supports_receipt_acks = connection.supports_receipt_acks && server_supports_receipt_acks;
- String data = new String(Base64.decode(root.data.getBytes()));
- return data;
- }
- throw new CorruptStreamException("fell out of loop in readFeaturesAndChallenge");
- }
- private void sendResponse(String challengeData)
- throws IOException
- {
- String response = getResponse(challengeData);
- ProtocolTreeNode node = new ProtocolTreeNode("response", new KeyValue[] {
- new KeyValue("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl")
- }, new String(Base64.encode(response.getBytes())));
- out.write(node);
- }
- private void readSuccess()
- throws CorruptStreamException, IOException, LoginFailureException
- {
- ProtocolTreeNode node = in.nextTree();
- if(ProtocolTreeNode.tagEquals(node, "failure"))
- throw new LoginFailureException(0);
- ProtocolTreeNode.require(node, "success");
- String expiration = node.getAttributeValue("expiration");
- if(expiration != null)
- try
- {
- connection.expire_date = Long.parseLong(expiration);
- }
- catch(NumberFormatException xxx)
- {
- throw new IOException("invalid expire date: " + expiration);
- }
- String kind = node.getAttributeValue("kind");
- if("paid".equals(kind))
- connection.account_kind = 1;
- else
- if("free".equals(kind))
- connection.account_kind = 0;
- else
- connection.account_kind = -1;
- String status = node.getAttributeValue("status");
- if("expired".equals(status))
- {
- LoginFailureException failex = new LoginFailureException(1);
- failex.expire_date = connection.expire_date;
- throw failex;
- }
- if("active".equals(status))
- {
- if(expiration == null)
- throw new IOException("active account with no expiration");
- } else
- {
- connection.account_kind = -1;
- }
- }
- public WhatsApp(TreeNodeReader r, TreeNodeWriter w, MessageDigest d)
- {
- super(d, r, w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement