Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WhatsApp protocol support in Xabber #248

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
71102c0
Starting to add WhatsApp protocol stuff.
davidgfnet Aug 15, 2013
5b52c61
Adding whatsapp protocol internals. Translated from libpurple impleme…
davidgfnet Aug 15, 2013
cf5e0fe
Putting aside some files for some time. Seems to build ok and the Wha…
davidgfnet Aug 16, 2013
a759375
More WA protocol classes.
davidgfnet Aug 16, 2013
c58e5d0
Fixing some bugs and adding more functions for WhatsApp protocol func…
davidgfnet Aug 17, 2013
037bd31
Adding WA connection class wrapper.
davidgfnet Aug 17, 2013
288f9f3
Adding message serialization and socket read/write stuff.
davidgfnet Aug 17, 2013
16ef9e1
Fixed many bugs and added integration in the system.
davidgfnet Aug 21, 2013
b4a2ea9
Fixed many bugs. Now we are able to communicate with the servers and …
davidgfnet Aug 21, 2013
ad1aa7c
Fixed many bugs with auth. Now auth works!
davidgfnet Aug 22, 2013
518e6b9
Bit of cleanup.
davidgfnet Aug 22, 2013
db86318
Connect & login working!
davidgfnet Aug 22, 2013
2785d07
Message sending works.
davidgfnet Aug 22, 2013
5749171
Fixed many java related bugs.
davidgfnet Aug 23, 2013
28fdc14
Chat working more or less.
davidgfnet Aug 23, 2013
4cc20d6
Add makefile to remember build commands
davidgfnet Aug 23, 2013
9cd5e65
Added rather simple support for image chats.
davidgfnet Aug 24, 2013
f57034e
Adding permanent contacts using a SQLite table.
davidgfnet Aug 24, 2013
0c8304f
Fixed small issue with contact addition startup :)
davidgfnet Aug 24, 2013
b406df2
Added avatar support.
davidgfnet Aug 25, 2013
e3a3d70
Disabling debug output
davidgfnet Aug 25, 2013
6bdd1e7
Support for timestamp in incoming messages.
davidgfnet Aug 27, 2013
e41b76a
Adding presence sending.
davidgfnet Aug 27, 2013
c57f39f
Adding feature: sending status message along with status.
davidgfnet Aug 27, 2013
015a730
Fix small NullPointerException bug due to presence setting when disco…
davidgfnet Aug 31, 2013
4b7f81c
Adding support for group chats.
davidgfnet Sep 1, 2013
44cf312
Adding "RESOURCE" as nickname for WA accounts.
davidgfnet Sep 1, 2013
fbdb370
Correct small bug which prevented build.
davidgfnet Sep 2, 2013
8c1b0bc
Cleanup of dead code
davidgfnet Sep 15, 2013
2f4f857
More cleanup
davidgfnet Sep 15, 2013
48f113b
Add last seen at the VCard notes field.
davidgfnet Sep 15, 2013
604c9ec
Start adding HTTPS interface for user statuses
davidgfnet Sep 15, 2013
9be0f3c
Update WA protocol to V1.4.
davidgfnet Feb 1, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ gen/*
*.orig
.pydevproject
.settings
*~
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

all:
android update project --path . --target android-10 --name Xabber
ant release

2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
@@ -10,4 +10,4 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-9
target=android-10
10 changes: 9 additions & 1 deletion res/values/account_editor.xml
Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_hints_gtalk">username for gmail.com or Google Apps domain</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_hints_wapp">Telephone number (with prefix)</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_hints_livejournal">username for livejournal.com</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_hints_qip">username for qip.ru</string>
@@ -39,6 +41,8 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_gtalk">If you don\'t have Google account you may create one at http://mail.google.com\nAlso you can use your_user_name@your_google_domain</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_wapp">You need an already existing WhatsApp account. TODO: Add references on how to create/get password</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_livejournal">If you don\'t have Livejournal account you may create one at http://livejournal.com</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add.png -->
<string name="account_type_helps_qip">If you don\'t have QIP account you may create one at http://qip.ru</string>
@@ -53,6 +57,8 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_gtalk">Google Talk</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_wapp">WhatsApp</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_livejournal">LiveJournal</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_type.png -->
<string name="account_type_names_qip">QIP</string>
@@ -101,6 +107,8 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_gtalk.png -->
<string name="account_protocol_gtalk_title">Google Talk</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_wlm.png -->
<string name="account_protocol_wapp_title">WhatsApp</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_wlm.png -->
<string name="account_protocol_wlm_title">WLM</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_editor_01.png -->
<string name="account_protocol_xmpp_title">XMPP</string>
@@ -159,4 +167,4 @@
<string name="confirm_cancellation">Are you sure you want to discard all the changes?</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/account_add_error.png -->
<string name="INCORRECT_USER_NAME">Incorrect user name. Check help text below for details.</string>
</resources>
</resources>
15 changes: 15 additions & 0 deletions res/values/connections.xml
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
<string name="account_protocol_xmpp">xmpp</string>
<string name="account_protocol_gtalk">gtalk</string>
<string name="account_protocol_wlm">wlm</string>
<string name="account_protocol_wapp">wapp</string>

<!--
<array name="account_type_name">
@@ -73,6 +74,19 @@
<item>True</item>
<item>messenger.live.com</item>
</array>

<array name="account_type_wapp">
<item>@string/account_protocol_wapp</item>
<item>@string/account_type_names_wapp</item>
<item>@string/account_type_hints_wapp</item>
<item>@string/account_type_helps_wapp</item>
<item>@drawable/ic_type_wlm</item>
<item>True</item>
<item>c3.whatsapp.net</item>
<item>443</item>
<item>False</item>
<item>c3.whatsapp.net</item>
</array>

<array name="account_type_facebook">
<item>@string/account_protocol_xmpp</item>
@@ -157,6 +171,7 @@
<item>@array/account_type_xmpp</item>
<item>@array/account_type_gtalk</item>
<item>@array/account_type_wlm</item>
<item>@array/account_type_wapp</item>
<item>@array/account_type_facebook</item>
<item>@array/account_type_vkontakte</item>
<item>@array/account_type_qip</item>
57 changes: 57 additions & 0 deletions res/xml/account_editor_wapp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved.

This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.

Xabber is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/account_enabled"
android:summary="@string/account_enabled_summary"
android:key="@string/account_enabled_key"
/>
<CheckBoxPreference
android:title="@string/account_syncable"
android:summary="@string/account_syncable_summary"
android:key="@string/account_syncable_key"
/>
<EditTextPreference
android:key="@string/account_username_key"
android:title="@string/account_user_name"
android:dialogTitle="@string/account_user_name"
android:singleLine="true"
/>
<CheckBoxPreference
android:title="@string/account_store_password"
android:summary="@string/account_store_password_summary"
android:key="@string/account_store_password_key"
/>
<EditTextPreference
android:key="@string/account_password_key"
android:title="@string/account_password"
android:dialogTitle="@string/account_password"
android:password="true"
android:singleLine="true"
/>
<EditTextPreference
android:key="@string/account_resource_key"
android:title="@string/account_resource"
android:dialogTitle="@string/account_resource"
android:singleLine="true"
/>
<ListPreference
android:title="@string/account_archive_mode"
android:key="@string/account_archive_mode_key"
android:entries="@array/account_archive_mode_entries"
android:entryValues="@array/account_archive_mode_entryvalues"
/>
</PreferenceScreen>
9 changes: 9 additions & 0 deletions src/com/xabber/android/data/account/AccountProtocol.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,11 @@ public enum AccountProtocol {
* GTalk.
*/
gtalk,

/**
* WhatsApp.
*/
wapp,

/**
* Windows Live Messenger.
@@ -54,6 +59,8 @@ public int getNameResource() {
return R.string.account_type_names_xmpp;
else if (this == gtalk)
return R.string.account_type_names_gtalk;
else if (this == wapp)
return R.string.account_type_names_wapp;
else if (this == wlm)
return R.string.account_type_names_wlm;
else
@@ -68,6 +75,8 @@ public int getShortResource() {
return R.string.account_protocol_xmpp_title;
else if (this == gtalk)
return R.string.account_protocol_gtalk_title;
else if (this == wapp)
return R.string.account_protocol_wapp_title;
else if (this == wlm)
return R.string.account_protocol_wlm_title;
else
8 changes: 4 additions & 4 deletions src/com/xabber/android/data/connection/ConnectionItem.java
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
*/
package com.xabber.android.data.connection;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;

import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
@@ -99,7 +99,7 @@ public String getRealJid() {
ConnectionThread connectionThread = getConnectionThread();
if (connectionThread == null)
return null;
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
Connection xmppConnection = connectionThread.getXMPPConnection();
if (xmppConnection == null)
return null;
String user = xmppConnection.getUser();
@@ -188,7 +188,7 @@ protected void disconnect(final ConnectionThread connectionThread) {
Thread thread = new Thread("Disconnection thread for " + this) {
@Override
public void run() {
XMPPConnection xmppConnection = connectionThread
Connection xmppConnection = connectionThread
.getXMPPConnection();
if (xmppConnection != null)
try {
@@ -261,7 +261,7 @@ protected void onAuthorized(ConnectionThread connectionThread) {
* @return <code>true</code> if connection thread was managed.
*/
private boolean onDisconnect(ConnectionThread connectionThread) {
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
Connection xmppConnection = connectionThread.getXMPPConnection();
boolean acceptable = isManaged(connectionThread);
if (xmppConnection == null)
LogManager.i(this, "onClose " + acceptable);
4 changes: 2 additions & 2 deletions src/com/xabber/android/data/connection/ConnectionManager.java
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
@@ -181,7 +181,7 @@ public void sendPacket(String account, Packet packet)
|| !connectionThread.getConnectionItem().getState()
.isConnected())
throw new NetworkException(R.string.NOT_CONNECTED);
XMPPConnection xmppConnection = connectionThread.getXMPPConnection();
Connection xmppConnection = connectionThread.getXMPPConnection();
try {
xmppConnection.sendPacket(packet);
} catch (IllegalStateException e) {
18 changes: 14 additions & 4 deletions src/com/xabber/android/data/connection/ConnectionThread.java
Original file line number Diff line number Diff line change
@@ -22,9 +22,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jivesoftware.smack.WAConnection;

import javax.net.ssl.SSLException;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
@@ -67,7 +70,7 @@ public class ConnectionThread implements
/**
* SMACK connection.
*/
private XMPPConnection xmppConnection;
private Connection xmppConnection;

/**
* Thread holder for this connection.
@@ -144,7 +147,7 @@ public Thread newThread(Runnable runnable) {
started = false;
}

public XMPPConnection getXMPPConnection() {
public Connection getXMPPConnection() {
return xmppConnection;
}

@@ -318,7 +321,13 @@ private void onReady(final InetAddress address, final int port) {
connectionConfiguration.setSecurityMode(tlsMode.getSecurityMode());
connectionConfiguration.setCompressionEnabled(compression);

xmppConnection = new XMPPConnection(connectionConfiguration);
// Create different underlying classes depending on the protocol
AccountProtocol proto = connectionItem.getConnectionSettings().getProtocol();
if (proto == AccountProtocol.wapp) {
xmppConnection = new WAConnection(this, connectionConfiguration);
}else{
xmppConnection = new XMPPConnection(connectionConfiguration);
}
xmppConnection.addPacketListener(this, ACCEPT_ALL);
xmppConnection.forceAddConnectionListener(this);
connectionItem.onSRVResolved(this);
@@ -416,7 +425,8 @@ public void run() {
*/
private void connect(final String password) {
try {
xmppConnection.connect();
ConnectionSettings connectionSettings = connectionItem.getConnectionSettings();
xmppConnection.connect(connectionSettings.getUserName(), password, connectionSettings.getResource());
} catch (XMPPException e) {
checkForCertificateError(e);
if (!checkForSeeOtherHost(e)) {
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
@@ -112,7 +112,7 @@ public void onSettingsChanged() {
.getConnectionThread();
if (connectionThread == null)
continue;
XMPPConnection xmppConnection = connectionThread
Connection xmppConnection = connectionThread
.getXMPPConnection();
if (xmppConnection == null)
continue;
10 changes: 6 additions & 4 deletions src/com/xabber/android/data/extension/muc/MUCManager.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import java.util.Collections;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
@@ -129,7 +130,7 @@ private void onLoaded(Collection<RoomChat> roomChats,
* @param room
* @return <code>null</code> if does not exists.
*/
private RoomChat getRoomChat(String account, String room) {
public RoomChat getRoomChat(String account, String room) {
AbstractChat chat = MessageManager.getInstance().getChat(account, room);
if (chat != null && chat instanceof RoomChat)
return (RoomChat) chat;
@@ -219,19 +220,20 @@ public void run() {
* @param password
*/
public void createRoom(String account, String room, String nickname,
String password, boolean join) {
String password, boolean join, String subject) {
removeInvite(getInvite(account, room));
AbstractChat chat = MessageManager.getInstance().getChat(account, room);
RoomChat roomChat;
if (chat == null || !(chat instanceof RoomChat)) {
if (chat != null)
MessageManager.getInstance().removeChat(chat);
roomChat = new RoomChat(account, room, nickname, password);
roomChat = new RoomChat(account, room, nickname, password, subject);
MessageManager.getInstance().addChat(roomChat);
} else {
roomChat = (RoomChat) chat;
roomChat.setNickname(nickname);
roomChat.setPassword(password);
roomChat.setSubject(subject);
}
requestToWriteRoom(account, room, nickname, password, join);
if (join)
@@ -279,7 +281,7 @@ public boolean inUse(final String account, final String room) {
*/
public void joinRoom(final String account, final String room,
boolean requested) {
final XMPPConnection xmppConnection;
final Connection xmppConnection;
final RoomChat roomChat;
final String nickname;
final String password;
18 changes: 17 additions & 1 deletion src/com/xabber/android/data/extension/muc/RoomChat.java
Original file line number Diff line number Diff line change
@@ -82,6 +82,18 @@ public class RoomChat extends AbstractChat {
* Invited user for the sent packet ID.
*/
private final Map<String, String> invites;

RoomChat(String account, String user, String nickname, String password, String subject) {
super(account, user);
this.nickname = nickname;
this.password = password;
requested = false;
state = RoomState.unavailable;
this.subject = subject;
multiUserChat = null;
occupants = new HashMap<String, Occupant>();
invites = new HashMap<String, String>();
}

RoomChat(String account, String user, String nickname, String password) {
super(account, user);
@@ -156,6 +168,10 @@ String getSubject() {
return subject;
}

void setSubject(String s) {
this.subject = s;
}

MultiUserChat getMultiUserChat() {
return multiUserChat;
}
@@ -486,4 +502,4 @@ protected void onDisconnect() {
setState(RoomState.waiting);
}

}
}
Loading