Search in sources :

Example 1 with GetCallerListException

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

the class FritzOS559Firmware method getCallerList.

public List getCallerList(int id, String name) throws GetCallerListException, IOException {
    if (!this.isInitialized())
        throw new GetCallerListException("Could not get phone book from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getCallerListAsStream(Integer.toString(id), name);
    } catch (IOException e) {
        throw new GetCallerListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    StringBuffer xml = new StringBuffer();
    String encoding = (is600 ? "utf-8" : "iso-8859-1");
    InputStreamReader inr = new InputStreamReader(in, encoding);
    BufferedReader bufReader = new BufferedReader(inr);
    // drop header
    String line = bufReader.readLine();
    while (bufReader.ready()) {
        line = bufReader.readLine();
        xml.append(line + " ");
    }
    bufReader.close();
    in.close();
    result.addAll(parseXML(xml, name));
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Phonebook from FritzBox succuessfully fetched. List size: " + result.size());
    return result;
}
Also used : GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 2 with GetCallerListException

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

the class FritzOS559Firmware method getCallerListAsStream.

private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
    long start = System.currentTimeMillis();
    this.m_logger.info("Starting retrieving phone book...");
    // The list should be updated now
    // Get the csv file for processing
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
    URL url;
    URLConnection urlConn;
    DataOutputStream printout;
    try {
        this.m_logger.info("Calling FritzBox URL: " + urlstr);
        url = new URL(urlstr);
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetCallerListException("Invalid URL: " + urlstr);
    }
    urlConn = url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setUseCaches(false);
    // Sending postdata to the fritz box
    urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
    printout = new DataOutputStream(urlConn.getOutputStream());
    StringBuffer sb = new StringBuffer();
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(this.m_sid + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_id + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_name + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
    printout.writeBytes(sb.toString());
    printout.flush();
    printout.close();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e2) {
        this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
    }
    try {
        // Get response data from the box
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
        Stream.copy(urlConn.getInputStream(), bos);
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        // this.m_logger.info(bos.toString());
        this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
        urlConn.getInputStream().close();
        return bin;
    } catch (IOException e1) {
        this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        throw new GetCallerListException(e1.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 3 with GetCallerListException

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

the class FritzOSFirmware method getCallerList.

public List getCallerList(int id, String name) throws GetCallerListException, IOException {
    if (!this.isInitialized())
        throw new GetCallerListException("Could not get phone book from FritzBox: FritzBox firmware not initialized.");
    InputStream in = null;
    try {
        in = this.getCallerListAsStream(Integer.toString(id), name);
    } catch (IOException e) {
        throw new GetCallerListException(e.getMessage());
    }
    if (in == null)
        return new ArrayList(0);
    List result = new ArrayList();
    StringBuffer xml = new StringBuffer();
    InputStreamReader inr = new InputStreamReader(in, "iso-8859-1");
    BufferedReader bufReader = new BufferedReader(inr);
    // drop header
    String line = bufReader.readLine();
    while (bufReader.ready()) {
        line = bufReader.readLine();
        xml.append(line + " ");
    }
    bufReader.close();
    in.close();
    result.addAll(parseXML(xml, name));
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Phonebook from FritzBox succuessfully fetched. List size: " + result.size());
    return result;
}
Also used : GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 4 with GetCallerListException

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

the class FritzOSFirmware method getCallerListAsStream.

private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
    long start = System.currentTimeMillis();
    this.m_logger.info("Starting retrieving phone book...");
    // The list should be updated now
    // Get the csv file for processing
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
    URL url;
    URLConnection urlConn;
    DataOutputStream printout;
    try {
        this.m_logger.info("Calling FritzBox URL: " + urlstr);
        url = new URL(urlstr);
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetCallerListException("Invalid URL: " + urlstr);
    }
    urlConn = url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setUseCaches(false);
    // Sending postdata to the fritz box
    urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
    printout = new DataOutputStream(urlConn.getOutputStream());
    StringBuffer sb = new StringBuffer();
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(this.m_sid + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_id + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_name + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
    printout.writeBytes(sb.toString());
    printout.flush();
    printout.close();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e2) {
        this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
    }
    try {
        // Get response data from the box
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
        Stream.copy(urlConn.getInputStream(), bos);
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        // this.m_logger.info(bos.toString());
        this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
        urlConn.getInputStream().close();
        return bin;
    } catch (IOException e1) {
        this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        throw new GetCallerListException(e1.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 5 with GetCallerListException

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

the class UnitymediaFirmware method getCallerListAsStream.

private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
    long start = System.currentTimeMillis();
    this.m_logger.info("Starting retrieving phone book...");
    // The list should be updated now
    // Get the csv file for processing
    String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
    URL url;
    URLConnection urlConn;
    DataOutputStream printout;
    try {
        this.m_logger.info("Calling FritzBox URL: " + urlstr);
        url = new URL(urlstr);
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new GetCallerListException("Invalid URL: " + urlstr);
    }
    urlConn = url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    urlConn.setUseCaches(false);
    // Sending postdata to the fritz box
    urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
    printout = new DataOutputStream(urlConn.getOutputStream());
    StringBuffer sb = new StringBuffer();
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(this.m_sid + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_id + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(pb_name + IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
    sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append(IJAMConst.CRLF);
    sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
    printout.writeBytes(sb.toString());
    printout.flush();
    printout.close();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e2) {
        this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
    }
    try {
        // Get response data from the box
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
        Stream.copy(urlConn.getInputStream(), bos);
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        // this.m_logger.info(bos.toString());
        this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
        urlConn.getInputStream().close();
        return bin;
    } catch (IOException e1) {
        this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
        throw new GetCallerListException(e1.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)10 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 List (java.util.List)6 ArrayList (java.util.ArrayList)5 BufferedReader (java.io.BufferedReader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataOutputStream (java.io.DataOutputStream)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 URLConnection (java.net.URLConnection)4 ICallerList (de.janrufmonitor.framework.ICallerList)1 IPhonebookEntry (de.janrufmonitor.fritzbox.IPhonebookEntry)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 GetAddressbooksException (de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException)1 File (java.io.File)1 SQLException (java.sql.SQLException)1