001/** 002 * 003 * Copyright © 2017 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.httpfileupload; 018 019import org.jivesoftware.smack.util.Objects; 020 021import org.jxmpp.jid.DomainBareJid; 022 023public class UploadService { 024 025 public enum Version { 026 /** 027 * Upload service as specified in XEP-0363 v0.2 or lower. 028 * 029 * @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.2.5.html">XEP-0363 v0.2.5</a> 030 */ 031 v0_2, 032 033 /** 034 * Upload service as specified in XEP-0363 v0.3 or higher. 035 * 036 * @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.4.0.html">XEP-0363 v0.4.0</a> 037 */ 038 v0_3, 039 } 040 041 private final DomainBareJid address; 042 private final Version version; 043 private final Long maxFileSize; 044 045 UploadService(DomainBareJid address, Version version) { 046 this(address, version, null); 047 } 048 049 UploadService(DomainBareJid address, Version version, Long maxFileSize) { 050 this.address = Objects.requireNonNull(address); 051 this.version = version; 052 this.maxFileSize = maxFileSize; 053 } 054 055 public DomainBareJid getAddress() { 056 return address; 057 } 058 059 public Version getVersion() { 060 return version; 061 } 062 063 public boolean hasMaxFileSizeLimit() { 064 return maxFileSize != null; 065 } 066 067 public Long getMaxFileSize() { 068 return maxFileSize; 069 } 070 071 public boolean acceptsFileOfSize(long size) { 072 if (!hasMaxFileSizeLimit()) { 073 return true; 074 } 075 076 return size <= maxFileSize; 077 } 078}