add methods to check max file size for http upload
This commit is contained in:
parent
e074104004
commit
74c496fe3e
|
@ -52,8 +52,12 @@ public class Account extends AbstractEntity {
|
||||||
public static final int OPTION_USECOMPRESSION = 3;
|
public static final int OPTION_USECOMPRESSION = 3;
|
||||||
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
|
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
|
||||||
|
|
||||||
|
public boolean httpUploadAvailable(long filesize) {
|
||||||
|
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean httpUploadAvailable() {
|
public boolean httpUploadAvailable() {
|
||||||
return xmppConnection != null && xmppConnection.getFeatures().httpUpload();
|
return httpUploadAvailable(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayName(String displayName) {
|
public void setDisplayName(String displayName) {
|
||||||
|
|
|
@ -190,6 +190,19 @@ public class ServiceDiscoveryResult {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExtendedDiscoInformation(String formType, String name) {
|
||||||
|
for(Data form : this.forms) {
|
||||||
|
if (formType.equals(form.getFormType())) {
|
||||||
|
for(Field field: form.getFields()) {
|
||||||
|
if (name.equals(field.getFieldName())) {
|
||||||
|
return field.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected byte[] mkCapHash() {
|
protected byte[] mkCapHash() {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
|
|
||||||
|
|
|
@ -847,8 +847,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
||||||
private void sendFileMessage(final Message message, final boolean delay) {
|
private void sendFileMessage(final Message message, final boolean delay) {
|
||||||
Log.d(Config.LOGTAG, "send file message");
|
Log.d(Config.LOGTAG, "send file message");
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
final XmppConnection connection = account.getXmppConnection();
|
if (account.httpUploadAvailable()) {
|
||||||
if (connection != null && connection.getFeatures().httpUpload()) {
|
|
||||||
mHttpConnectionManager.createNewUploadConnection(message, delay);
|
mHttpConnectionManager.createNewUploadConnection(message, delay);
|
||||||
} else {
|
} else {
|
||||||
mJingleConnectionManager.createNewConnection(message);
|
mJingleConnectionManager.createNewConnection(message);
|
||||||
|
|
|
@ -688,7 +688,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
||||||
} else {
|
} else {
|
||||||
this.mServerInfoPep.setText(R.string.server_info_unavailable);
|
this.mServerInfoPep.setText(R.string.server_info_unavailable);
|
||||||
}
|
}
|
||||||
if (features.httpUpload()) {
|
if (features.httpUpload(0)) {
|
||||||
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
|
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
|
||||||
} else {
|
} else {
|
||||||
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
|
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
|
||||||
|
|
|
@ -1346,12 +1346,12 @@ public class XmppConnection implements Runnable {
|
||||||
this.streamId = null;
|
this.streamId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) {
|
||||||
synchronized (this.disco) {
|
synchronized (this.disco) {
|
||||||
final List<Jid> items = new ArrayList<>();
|
final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>();
|
||||||
for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) {
|
for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) {
|
||||||
if (cursor.getValue().getFeatures().contains(feature)) {
|
if (cursor.getValue().getFeatures().contains(feature)) {
|
||||||
items.add(cursor.getKey());
|
items.add(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
|
@ -1359,9 +1359,9 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid findDiscoItemByFeature(final String feature) {
|
public Jid findDiscoItemByFeature(final String feature) {
|
||||||
final List<Jid> items = findDiscoItemsByFeature(feature);
|
final List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(feature);
|
||||||
if (items.size() >= 1) {
|
if (items.size() >= 1) {
|
||||||
return items.get(0);
|
return items.get(0).getKey();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1505,7 +1505,6 @@ public class XmppConnection implements Runnable {
|
||||||
|
|
||||||
public boolean pep() {
|
public boolean pep() {
|
||||||
synchronized (XmppConnection.this.disco) {
|
synchronized (XmppConnection.this.disco) {
|
||||||
final Pair<String, String> needle = new Pair<>("pubsub", "pep");
|
|
||||||
ServiceDiscoveryResult info = disco.get(account.getServer());
|
ServiceDiscoveryResult info = disco.get(account.getServer());
|
||||||
if (info != null && info.hasIdentity("pubsub", "pep")) {
|
if (info != null && info.hasIdentity("pubsub", "pep")) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1534,8 +1533,22 @@ public class XmppConnection implements Runnable {
|
||||||
this.blockListRequested = value;
|
this.blockListRequested = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean httpUpload() {
|
public boolean httpUpload(long filesize) {
|
||||||
return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0;
|
if (Config.DISABLE_HTTP_UPLOAD) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD);
|
||||||
|
if (items.size() > 0) {
|
||||||
|
try {
|
||||||
|
long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size"));
|
||||||
|
return maxsize <= filesize;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return filesize <= 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue