From f967610679ae80e79dfe29c20c0ab3fa7f5c6e97 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 9 Sep 2012 13:17:15 +0200 Subject: [PATCH 1/3] Set default save template to one without subfolders. Helps with readers that don't support them, such as K4A --- src/calibre/devices/smart_device_app/driver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index b1cd1e635b..1dcf74450d 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -84,6 +84,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): PREFIX = '' BACKLOADING_ERROR_MESSAGE = None + SAVE_TEMPLATE = '{title} - {authors} ({id})' + # Some network protocol constants BASE_PACKET_LEN = 4096 PROTOCOL_VERSION = 1 From 1f7965b96d8aeca1e4e06e5b4431b165231a3264 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 10 Sep 2012 09:41:26 +0200 Subject: [PATCH 2/3] Make bonjour for the content server advertize an IP address set in tweaks. --- src/calibre/gui2/actions/device.py | 9 +++++++-- src/calibre/library/server/base.py | 9 ++++++--- src/calibre/utils/mdns.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index 6e215661c8..3ec7738362 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -11,6 +11,7 @@ from PyQt4.Qt import QToolButton, QMenu, pyqtSignal, QIcon, QTimer from calibre.gui2.actions import InterfaceAction from calibre.utils.smtp import config as email_config +from calibre.utils.config import tweaks from calibre.constants import iswindows, isosx from calibre.customize.ui import is_disabled from calibre.devices.bambook.driver import BAMBOOK @@ -84,10 +85,14 @@ class ShareConnMenu(QMenu): # {{{ action=self.toggle_server_action, group=gr) def server_state_changed(self, running): - from calibre.utils.mdns import get_external_ip + from calibre.utils.mdns import get_external_ip, verify_ipV4_address text = _('Start Content Server') if running: - text = _('Stop Content Server') + ' [%s]'%get_external_ip() + listen_on = verify_ipV4_address(tweaks['server_listen_on']) + if listen_on: + text = _('Stop Content Server') + ' [%s]'%listen_on + else: + text = _('Stop Content Server') + ' [%s]'%get_external_ip() self.toggle_server_action.setText(text) def hide_smartdevice_menus(self): diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index 3554268c3b..884d273ea9 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os +import os, socket import logging from logging.handlers import RotatingFileHandler @@ -17,7 +17,7 @@ from calibre.utils.date import fromtimestamp from calibre.library.server import listen_on, log_access_file, log_error_file from calibre.library.server.utils import expose, AuthController from calibre.utils.mdns import publish as publish_zeroconf, \ - unpublish as unpublish_zeroconf, get_external_ip + unpublish as unpublish_zeroconf, get_external_ip, verify_ipV4_address from calibre.library.server.content import ContentServer from calibre.library.server.mobile import MobileServer from calibre.library.server.xml import XMLServer @@ -78,6 +78,7 @@ class BonJour(SimplePlugin): # {{{ SimplePlugin.__init__(self, engine) self.port = port self.prefix = prefix + self.ip_address = '0.0.0.0' @property def mdns_services(self): @@ -90,9 +91,10 @@ class BonJour(SimplePlugin): # {{{ def start(self): + zeroconf_ip_address = verify_ipV4_address(self.ip_address) try: for s in self.mdns_services: - publish_zeroconf(*s) + publish_zeroconf(*s, use_ip_address=zeroconf_ip_address) except: import traceback cherrypy.log.error('Failed to start BonJour:') @@ -140,6 +142,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache, if not opts.url_prefix: opts.url_prefix = '' + cherrypy.engine.bonjour.ip_address = listen_on cherrypy.engine.bonjour.port = opts.port cherrypy.engine.bonjour.prefix = opts.url_prefix diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py index abbd6c2247..706516e32c 100644 --- a/src/calibre/utils/mdns.py +++ b/src/calibre/utils/mdns.py @@ -39,6 +39,19 @@ def _get_external_ip(): #print 'ipaddr: %s' % ipaddr return ipaddr +def verify_ipV4_address(ip_address): + result = None + if ip_address != '0.0.0.0' and ip_address != '::': + # do some more sanity checks on the address + try: + socket.inet_aton(ip_address) + if len(ip_address.split('.')) == 4: + result = ip_address + except socket.error: + # Not legal ip address + pass + return result + _ext_ip = None def get_external_ip(): global _ext_ip From 26648346008800313196eea9cc4806216f6ad14f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 10 Sep 2012 14:00:51 +0200 Subject: [PATCH 3/3] Fix mdns to pass through the desired IP address. --- src/calibre/utils/mdns.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py index 706516e32c..48027791ab 100644 --- a/src/calibre/utils/mdns.py +++ b/src/calibre/utils/mdns.py @@ -106,7 +106,8 @@ def publish(desc, type, port, properties=None, add_hostname=True, use_ip_address into the TXT record. ''' server = start_server() - service = create_service(desc, type, port, properties, add_hostname) + service = create_service(desc, type, port, properties, add_hostname, + use_ip_address) server.registerService(service) def unpublish(desc, type, port, properties=None, add_hostname=True):