X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Favmfritz%2FFritzBox.java;h=bd34c806b99ecd21278960206463b1e59f765783;hb=e4126a1787b7045a53f6074e9ef15681c9f5fde4;hp=c1852e789ad78bb84da05f7e4efaad98759071e7;hpb=276d9a69fa796728169c2992921a1e4bd875f549;p=jpim.git diff --git a/src/de/j32/avmfritz/FritzBox.java b/src/de/j32/avmfritz/FritzBox.java index c1852e7..bd34c80 100644 --- a/src/de/j32/avmfritz/FritzBox.java +++ b/src/de/j32/avmfritz/FritzBox.java @@ -15,87 +15,81 @@ import de.j32.util.Util; public class FritzBox { - String url_; - String sid_; - - public FritzBox(String password, String url) - throws SAXException, IOException - { - url_ = url; - - HttpResponse response = null; - try { - response = httpGet("cgi-bin/webcm") - .addParameter("getpage", "../html/login_sid.xml") - .execute(); - LoginXML loginxml = new LoginXML(response); - response.close(); - response = null; - - if (loginxml.iswriteaccess()) { - sid_ = loginxml.sid(); - return; - } - - response = httpPost("cgi-bin/webcm") - .addParameter("getpage", "../html/login_sid.xml") - .addParameter("var:lang", "de") - .addParameter("login:command/response", - loginxml.response(password)).execute(); - loginxml = new LoginXML(response); - response.close(); - response = null; - - if (!loginxml.iswriteaccess()) - throw new RuntimeException("FritzBox login failed"); - - sid_ = loginxml.sid(); - } - finally { - Util.nothrowClose(response); - } - - } - - public InputStream exportAddressbook() - throws IOException - { - return httpPostMultipart("cgi-bin/firmwarecfg") - .addParameter("sid", sid_) - .addParameter("PhonebookId", "0") - .addParameter("PhonebookExportName", "Telefonbuch") - .addParameter("PhonebookExport", "").execute(); - } - - public OutputStream importAddressbook() - throws IOException - { - return new ByteArrayOutputStream() { - public void close() - throws IOException - { - httpPostMultipart("cgi-bin/firmwarecfg") - .addParameter("sid", sid_) - .addParameter("PhonebookId", "0") - .addParameter("PhonebookImportFile", toByteArray(), "iso-8859-1") - .execute() - .close(); - } - }; - } - - HttpRequest httpGet(String path) - { - return new HttpGETRequest(url_ + "/" + path); - } - - HttpRequest httpPost(String path) - { - return new HttpPOSTRequest(url_ + "/" + path); - } - - HttpRequest httpPostMultipart(String path) - { - return new HttpPOSTRequest(url_ + "/" + path).setMultipart(true); - } + String url_; + String sid_; + + public FritzBox(String password, String url) throws SAXException, + IOException + { + url_ = url; + + HttpResponse response = null; + try { + response = httpGet("cgi-bin/webcm").addParameter("getpage", + "../html/login_sid.xml").execute(); + LoginXML loginxml = new LoginXML(response); + response.close(); + response = null; + + if (loginxml.iswriteaccess()) { + sid_ = loginxml.sid(); + return; + } + + response = httpPost("cgi-bin/webcm") + .addParameter("getpage", "../html/login_sid.xml") + .addParameter("var:lang", "de") + .addParameter("login:command/response", + loginxml.response(password)).execute(); + loginxml = new LoginXML(response); + response.close(); + response = null; + + if (!loginxml.iswriteaccess()) throw new RuntimeException( + "FritzBox login failed"); + + sid_ = loginxml.sid(); + } + finally { + Util.nothrowClose(response); + } + + } + + public InputStream exportAddressbook() throws IOException + { + return httpPostMultipart("cgi-bin/firmwarecfg") + .addParameter("sid", sid_).addParameter("PhonebookId", "0") + .addParameter("PhonebookExportName", "Telefonbuch") + .addParameter("PhonebookExport", "").execute(); + } + + public OutputStream importAddressbook() throws IOException + { + return new ByteArrayOutputStream() { + public void close() throws IOException + { + httpPostMultipart("cgi-bin/firmwarecfg") + .addParameter("sid", sid_) + .addParameter("PhonebookId", "0") + .addParameter("PhonebookImportFile", toByteArray(), + "iso-8859-1").execute().close(); + } + }; + } + + HttpRequest httpGet(String path) + { + return new HttpGETRequest(url_ + "/" + path); + } + + HttpRequest httpPost(String path) + { + return new HttpPOSTRequest(url_ + "/" + path); + } + + HttpRequest httpPostMultipart(String path) + { + return new HttpPOSTRequest(url_ + "/" + path).setMultipart(true); + } }