Search in sources :

Example 1 with GetBlockedListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException in project janrufmonitor by tbrandt77.

the class AbstractFritzBoxFirmware method getBlockedList.

public List getBlockedList() throws IOException, GetBlockedListException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getBlockedListAsStream();
    } catch (IOException e) {
        throw new GetBlockedListException(e.getMessage());
    } catch (DoBlockException e) {
        throw new GetBlockedListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    StringBuffer parseBuffer = new StringBuffer();
    InputStreamReader inr = new InputStreamReader(in);
    BufferedReader bufReader = new BufferedReader(inr);
    // drop header
    String line = bufReader.readLine();
    // fasten the processing
    bufReader.skip(4096);
    while (bufReader.ready()) {
        line = bufReader.readLine();
        parseBuffer.append(line);
        parseBuffer.append(IJAMConst.CRLF);
    }
    bufReader.close();
    in.close();
    Pattern p = Pattern.compile(PATTERN_DETECT_BLOCKED_LIST, Pattern.UNICODE_CASE);
    Matcher m = p.matcher(parseBuffer);
    while (m.find() && m.groupCount() == 1) {
        result.add(m.group(1).trim());
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Blocked list from FritzBox successfully fetched. List size: " + result.size());
    return result;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) DoBlockException(de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)

Example 2 with GetBlockedListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException in project janrufmonitor by tbrandt77.

the class FritzOS559Firmware method getBlockedList.

public List getBlockedList() throws GetBlockedListException, IOException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/sperre.lua?sid=" + this.m_sid;
    try {
        data.append(this.executeURL(urlstr, null, true).trim());
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.WARNING, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetBlockedListException("Could not get blocked list from FritzBox: " + e.getMessage());
    }
    List blockedNumbers = new ArrayList();
    String[] s = data.toString().split("CallerID");
    Pattern p = Pattern.compile(PATTERN_DETECT_BLOCKED_NUMBER, Pattern.UNICODE_CASE);
    for (int i = 0, j = s.length; i < j; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            if (m.group(1).trim().length() > 3)
                blockedNumbers.add(m.group(1).trim());
        }
    }
    return blockedNumbers;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 3 with GetBlockedListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException in project janrufmonitor by tbrandt77.

the class FritzOSFirmware method getBlockedList.

public List getBlockedList() throws GetBlockedListException, IOException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/sperre.lua?sid=" + this.m_sid;
    try {
        data.append(this.executeURL(urlstr, null, true).trim());
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.WARNING, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetBlockedListException("Could not get blocked list from FritzBox: " + e.getMessage());
    }
    List blockedNumbers = new ArrayList();
    String[] s = data.toString().split("CallerID");
    Pattern p = Pattern.compile(PATTERN_DETECT_BLOCKED_NUMBER, Pattern.UNICODE_CASE);
    for (int i = 0, j = s.length; i < j; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            if (m.group(1).trim().length() > 3)
                blockedNumbers.add(m.group(1).trim());
        }
    }
    return blockedNumbers;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 4 with GetBlockedListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException in project janrufmonitor by tbrandt77.

the class UnitymediaFirmware method getBlockedList.

public List getBlockedList() throws GetBlockedListException, IOException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/sperre.lua?sid=" + this.m_sid;
    try {
        data.append(this.executeURL(urlstr, null, true).trim());
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.WARNING, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetBlockedListException("Could not get blocked list from FritzBox: " + e.getMessage());
    }
    List blockedNumbers = new ArrayList();
    String[] s = data.toString().split("CallerID");
    Pattern p = Pattern.compile(PATTERN_DETECT_BLOCKED_NUMBER, Pattern.UNICODE_CASE);
    for (int i = 0, j = s.length; i < j; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            if (m.group(1).trim().length() > 3)
                blockedNumbers.add(m.group(1).trim());
        }
    }
    return blockedNumbers;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 5 with GetBlockedListException

use of de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException in project janrufmonitor by tbrandt77.

the class TR064FritzBoxFirmware method getBlockedList.

public List getBlockedList() throws GetBlockedListException, IOException {
    if (!this.isInitialized())
        throw new GetBlockedListException("Could not get blocked list from FritzBox: FritzBox firmware not initialized.");
    StringBuffer data = new StringBuffer();
    String u = "http://" + this.m_server + ":" + this.m_port + "/fon_num/sperre.lua?sid=" + FritzBoxTR064Manager.getInstance().getSID(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"));
    try {
        data.append(doHttpCall(u, "GET", null, new String[][] {}));
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.WARNING, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetBlockedListException("Could not get blocked list from FritzBox: " + e.getMessage());
    }
    List blockedNumbers = new ArrayList();
    String[] s = data.toString().split("CallerID");
    Pattern p = Pattern.compile("] = \"([\\d]*)\",", Pattern.UNICODE_CASE);
    for (int i = 0, j = s.length; i < j; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            if (m.group(1).trim().length() > 3)
                blockedNumbers.add(m.group(1).trim());
        }
    }
    return blockedNumbers;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) GetBlockedListException(de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

GetBlockedListException (de.janrufmonitor.fritzbox.firmware.exception.GetBlockedListException)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 DoBlockException (de.janrufmonitor.fritzbox.firmware.exception.DoBlockException)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1