add http upload manager

This commit is contained in:
Daniel Gultsch 2023-02-21 18:23:35 +01:00
parent d136928322
commit d7ab5e1a4b
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
11 changed files with 112 additions and 15 deletions

View file

@ -0,0 +1,31 @@
package im.conversations.android.tls;
import android.content.Context;
import im.conversations.android.database.model.Account;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
public class TrustManager implements X509TrustManager {
private final Context context;
private final Account account;
public TrustManager(final Context context, final Account account) {
this.context = context;
this.account = account;
}
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType)
throws CertificateException {}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType)
throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}

View file

@ -3,15 +3,12 @@ package im.conversations.android.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import im.conversations.android.R;
import im.conversations.android.databinding.ActivityMainBinding;
import im.conversations.android.service.ForegroundService;
import im.conversations.android.ui.Activities;
import im.conversations.android.ui.model.MainViewModel;
import im.conversations.android.ui.model.SetupViewModel;
public class MainActivity extends BaseActivity {
@ -24,9 +21,13 @@ public class MainActivity extends BaseActivity {
final ViewModelProvider viewModelProvider =
new ViewModelProvider(this, getDefaultViewModelProviderFactory());
final var mainViewModel = viewModelProvider.get(MainViewModel.class);
mainViewModel.hasNoAccounts().observe(this, hasNoAccounts -> {
mainViewModel
.hasNoAccounts()
.observe(
this,
hasNoAccounts -> {
if (Boolean.TRUE.equals(hasNoAccounts)) {
startActivity(new Intent(this,SetupActivity.class));
startActivity(new Intent(this, SetupActivity.class));
finish();
}
});

View file

@ -1,12 +1,10 @@
package im.conversations.android.ui.model;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Transformations;
import im.conversations.android.repository.AccountRepository;
public class MainViewModel extends AndroidViewModel {

View file

@ -12,6 +12,8 @@ import im.conversations.android.xmpp.manager.BookmarkManager;
import im.conversations.android.xmpp.manager.CarbonsManager;
import im.conversations.android.xmpp.manager.ChatStateManager;
import im.conversations.android.xmpp.manager.DiscoManager;
import im.conversations.android.xmpp.manager.HttpUploadManager;
import im.conversations.android.xmpp.manager.JingleConnectionManager;
import im.conversations.android.xmpp.manager.NickManager;
import im.conversations.android.xmpp.manager.PepManager;
import im.conversations.android.xmpp.manager.PresenceManager;
@ -36,6 +38,10 @@ public final class Managers {
.put(CarbonsManager.class, new CarbonsManager(context, connection))
.put(ChatStateManager.class, new ChatStateManager(context, connection))
.put(DiscoManager.class, new DiscoManager(context, connection))
.put(HttpUploadManager.class, new HttpUploadManager(context, connection))
.put(
JingleConnectionManager.class,
new JingleConnectionManager(context, connection))
.put(NickManager.class, new NickManager(context, connection))
.put(PepManager.class, new PepManager(context, connection))
.put(PresenceManager.class, new PresenceManager(context, connection))

View file

@ -1793,13 +1793,14 @@ public class XmppConnection implements Runnable {
this.sendPacket(response);
}
public void sendErrorFor(final Iq request, final Condition condition) {
public void sendErrorFor(final Iq request, final Error.Type type, final Condition condition) {
final var from = request.getFrom();
final var id = request.getId();
final var response = new Iq(Iq.Type.ERROR);
response.setTo(from);
response.setId(id);
final Error error = response.addExtension(new Error());
error.setType(type);
error.setCondition(condition);
this.sendPacket(response);
}

View file

@ -24,6 +24,7 @@ import im.conversations.android.xmpp.model.disco.info.InfoQuery;
import im.conversations.android.xmpp.model.disco.items.Item;
import im.conversations.android.xmpp.model.disco.items.ItemsQuery;
import im.conversations.android.xmpp.model.error.Condition;
import im.conversations.android.xmpp.model.error.Error;
import im.conversations.android.xmpp.model.stanza.Iq;
import im.conversations.android.xmpp.model.version.Version;
import java.util.Arrays;
@ -303,7 +304,7 @@ public class DiscoManager extends AbstractManager {
serviceDescription = cachedServiceDescription;
} else {
LOGGER.warn("No disco info was cached for node {}", nodeRequest);
connection.sendErrorFor(request, new Condition.ItemNotFound());
connection.sendErrorFor(request, Error.Type.CANCEL, new Condition.ItemNotFound());
return;
}
}
@ -314,7 +315,7 @@ public class DiscoManager extends AbstractManager {
public void handleVersion(final Iq request) {
if (isPrivacyModeEnabled()) {
connection.sendErrorFor(request, new Condition.ServiceUnavailable());
connection.sendErrorFor(request, Error.Type.CANCEL, new Condition.ServiceUnavailable());
} else {
final var version = new Version();
version.setSoftwareName(BuildConfig.APP_NAME);

View file

@ -0,0 +1,11 @@
package im.conversations.android.xmpp.manager;
import android.content.Context;
import im.conversations.android.xmpp.XmppConnection;
public class HttpUploadManager extends AbstractManager {
public HttpUploadManager(Context context, XmppConnection connection) {
super(context, connection);
}
}

View file

@ -0,0 +1,16 @@
package im.conversations.android.xmpp.manager;
import android.content.Context;
import im.conversations.android.xmpp.XmppConnection;
import im.conversations.android.xmpp.model.stanza.Iq;
public class JingleConnectionManager extends AbstractManager {
public JingleConnectionManager(Context context, XmppConnection connection) {
super(context, connection);
}
public void handleJingle(Iq packet) {
}
}

View file

@ -3,6 +3,7 @@ package im.conversations.android.xmpp.model.error;
import im.conversations.android.annotation.XmlElement;
import im.conversations.android.xml.Namespace;
import im.conversations.android.xmpp.model.Extension;
import java.util.Locale;
@XmlElement(namespace = Namespace.JABBER_CLIENT)
public class Error extends Extension {
@ -22,4 +23,15 @@ public class Error extends Extension {
public Text getText() {
return this.getExtension(Text.class);
}
public void setType(final Type type) {
this.setAttribute("type", type.toString().toLowerCase(Locale.ROOT));
}
public enum Type {
MODIFY,
CANCEL,
AUTH,
WAIT
}
}

View file

@ -0,0 +1,13 @@
package im.conversations.android.xmpp.model.jingle;
import im.conversations.android.annotation.XmlElement;
import im.conversations.android.xmpp.model.Extension;
@XmlElement
public class Jingle extends Extension {
public Jingle() {
super(Jingle.class);
}
}

View file

@ -5,11 +5,14 @@ import com.google.common.base.Preconditions;
import im.conversations.android.xmpp.XmppConnection;
import im.conversations.android.xmpp.manager.BlockingManager;
import im.conversations.android.xmpp.manager.DiscoManager;
import im.conversations.android.xmpp.manager.JingleConnectionManager;
import im.conversations.android.xmpp.manager.RosterManager;
import im.conversations.android.xmpp.model.blocking.Block;
import im.conversations.android.xmpp.model.blocking.Unblock;
import im.conversations.android.xmpp.model.disco.info.InfoQuery;
import im.conversations.android.xmpp.model.error.Condition;
import im.conversations.android.xmpp.model.error.Error;
import im.conversations.android.xmpp.model.jingle.Jingle;
import im.conversations.android.xmpp.model.ping.Ping;
import im.conversations.android.xmpp.model.roster.Query;
import im.conversations.android.xmpp.model.stanza.Iq;
@ -68,9 +71,13 @@ public class IqProcessor extends XmppConnection.Delegate implements Consumer<Iq>
return;
}
if (type == Iq.Type.SET && packet.hasExtension(Jingle.class)) {
getManager(JingleConnectionManager.class).handleJingle(packet);
}
final var extensionIds = packet.getExtensionIds();
LOGGER.info("Received from {} type {}", packet.getFrom(), type);
LOGGER.info("Could not handle {}. Sending feature-not-implemented", extensionIds);
connection.sendErrorFor(packet, new Condition.FeatureNotImplemented());
connection.sendErrorFor(packet, Error.Type.CANCEL, new Condition.FeatureNotImplemented());
}
}