package me.xephore.virustotal2bind.packets;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import me.xephore.virustotal2bind.Configuration;
import me.xephore.virustotal2bind.enums.PacketType;

public class DomainPacket implements Packet {

	private String domain;

	@Override
	public String getName() {
		return "Domain-packet";
	}

	@Override
	public PacketType getType() {
		return PacketType.DOMAIN;
	}

	@Override
	public String[] getParams() {
		return new String[]{domain, Configuration.getConfiguration().getApiKey()};
	}

	public void setDomainNameParam(String name) {
		if(isUrl(name)) {
			this.domain = name;
		} else {
			throw new IllegalArgumentException("the domain name has to be a valid url!");	
		}
	}

	@Override
	public boolean isPacketComplete() {
		if(domain != null && Configuration.getConfiguration().getApiKey() != null) {
			return true;
		}
		return false;
	}

	public static boolean isUrl(String data) {
		Pattern p = Pattern.compile("^[A-Za-z0-9\\.]*\\.(co|biz|com|jobs|mobi|travel|net|org|pro|tel|info|xxx|name|ac|ag|am|asia|at|be|bz|cc|cn|cx|de|eu|fm|gs|hn|ht|im|in|io|it|jp|ki|la|lc|me|mn|mx|nf|nl|sb|sc|se|sh|tl|tv|tw|uk|us|vc|ws|ru|in)");
		Matcher match = p.matcher(data);
		return match.matches();
	}

}

@@ -1020,16 +1020,22 @@
 mpile(%22%5E
+((?!-)
 %5BA-Za-z0
@@ -1040,203 +1040,41 @@
 z0-9
-%5C%5C.%5D*%5C%5C.(co%7Cbiz%7Ccom%7Cjobs%7Cmobi%7Ctravel%7Cnet%7Corg%7Cpro%7Ctel%7Cinfo%7Cxxx%7Cname%7Cac%7Cag%7Cam%7Casia%7Cat%7Cbe%7Cbz%7Ccc%7Ccn%7Ccx%7Cde%7Ceu%7Cfm%7Cgs%7Chn%7Cht%7Cim%7Cin%7Cio%7Cit%7Cjp%7Cki%7Cla%7Clc%7Cme%7Cmn%7Cmx%7Cnf%7Cnl%7Csb%7Csc%7Cse%7Csh%7Ctl%7Ctv%7Ctw%7Cuk%7Cus%7Cvc%7Cws%7Cru%7Cin)
+-%5D%7B1,63%7D(?%3C!-)%5C%5C.)+%5BA-Za-z%5D%7B2,6%7D$
 %22);%0D

make domain regex not domain depended