use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class OfflineMessageManager method getMessageCount.
/**
* Returns the number of offline messages for the user of the connection.
*
* @return the number of offline messages for the user of the connection.
* @throws XMPPErrorException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = serviceDiscoveryManager.discoverInfo(null, NAMESPACE);
DataForm dataForm = DataForm.from(info, NAMESPACE);
if (dataForm == null) {
return 0;
}
String numberOfMessagesString = dataForm.getField("number_of_messages").getFirstValue();
return Integer.parseInt(numberOfMessagesString);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.
the class CustomDataProvider method parse.
@Override
public DataForm parse(XmlPullParser parser, int initialDepth) throws Exception {
DataForm.Type dataFormType = DataForm.Type.fromString(parser.getAttributeValue("", "type"));
DataForm dataForm = new DataForm(dataFormType);
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String name = parser.getName();
String namespace = parser.getNamespace();
switch(name) {
case "instructions":
dataForm.addInstruction(parser.nextText());
break;
case "title":
dataForm.setTitle(parser.nextText());
break;
case "field":
dataForm.addField(parseField(parser));
break;
case "item":
dataForm.addItem(parseItem(parser));
break;
case "reported":
dataForm.setReportedData(parseReported(parser));
break;
// See XEP-133 Example 32 for a corner case where the data form contains this extension.
case RosterPacket.ELEMENT:
if (namespace.equals(RosterPacket.NAMESPACE)) {
dataForm.addExtensionElement(RosterPacketProvider.INSTANCE.parse(parser));
}
break;
// See XEP-141 Data Forms Layout
case DataLayout.ELEMENT:
if (namespace.equals(DataLayout.NAMESPACE)) {
dataForm.addExtensionElement(DataLayoutProvider.parse(parser));
}
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return dataForm;
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.
the class SSNManager method onFormReceived.
private void onFormReceived(AccountJid account, Jid from, String session, Feature feature) {
OtrMode otrMode = getOtrMode(account, session);
boolean cancel = false;
Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions();
DisclosureValue disclosureValue = DisclosureValue.never;
if (disclosureValues == null)
disclosureValue = null;
else if (!disclosureValues.contains(disclosureValue))
cancel = true;
Collection<SecurityValue> securityValues = feature.getSecurityOptions();
SecurityValue securityValue;
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem != null && accountItem.getConnectionSettings().getTlsMode() == TLSMode.required) {
securityValue = SecurityValue.c2s;
} else {
securityValue = SecurityValue.none;
}
if (securityValues == null)
securityValue = null;
else if (!securityValues.contains(securityValue))
cancel = true;
Collection<LoggingValue> loggingValues = feature.getLoggingOptions();
LoggingValue loggingValue;
if (loggingValues == null)
loggingValue = null;
else {
loggingValue = otrMode.selectLoggingValue(loggingValues);
if (loggingValue == null)
cancel = true;
}
if (cancel) {
DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
if (feature.getAcceptValue() != null) {
Feature.addAcceptField(dataForm, false);
sessionStates.remove(account.toString(), session);
} else {
Feature.addRenegotiateField(dataForm, false);
}
sendFeature(account, from, session, new Feature(dataForm));
return;
}
DataForm dataForm = Feature.createDataForm(DataForm.Type.submit);
if (feature.getAcceptValue() != null)
Feature.addAcceptField(dataForm, true);
else
Feature.addRenegotiateField(dataForm, true);
if (disclosureValue != null)
Feature.addDisclosureField(dataForm, null, disclosureValue);
if (securityValue != null)
Feature.addSecurityField(dataForm, null, securityValue);
if (loggingValue != null) {
Feature.addLoggingField(dataForm, null, loggingValue);
}
sessionStates.put(account.toString(), session, SessionState.active);
sendFeature(account, from, session, new Feature(dataForm));
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.
the class SSNManager method onTerminateReceived.
private void onTerminateReceived(AccountJid account, Jid from, String session) {
if (sessionStates.get(account.toString(), session) == null) {
return;
}
sessionStates.remove(account.toString(), session);
DataForm dataForm = Feature.createDataForm(DataForm.Type.result);
Feature.addTerminateField(dataForm);
sendFeature(account, from, session, new Feature(dataForm));
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.
the class Feature method createDataForm.
public static DataForm createDataForm(DataForm.Type type) {
DataForm dataForm = new DataForm(type);
FormField typeField = new FormField(FORM_TYPE_FIELD);
typeField.addValue(FORM_TYPE_VALUE);
typeField.setType(FormField.Type.hidden);
dataForm.addField(typeField);
return dataForm;
}
Aggregations