Esempio n. 1
0
def _call_and_process(handler, request, device):
	response = handler.call_upstream(request, device)
	cookie = None
	pkcs12 = None
	alias = None
	with minidom.parseString(response.body_text()) as doc:
		x_response = qxml.get_child(doc, 'response')
		x_alias = qxml.get_child(x_response, 'user_device_name')
		alias = qxml.get_text(x_alias)
		x_adp_token = qxml.get_child(x_response, 'adp_token')
		if x_adp_token:
			cookie = qxml.get_text(x_adp_token)
		else:
			x_cookie = qxml.get_child(x_response, 'store_authentication_cookie')
			cookie = qxml.get_text(x_cookie)
			x_key = qxml.get_child(x_response, 'device_private_key')
			pkcs12 = qxml.get_text(x_key)
	if pkcs12:
		try:
			pkcs12 = b64decode(bytes(pkcs12, 'ascii'))
		except:
			logging.exception("failed to decode incoming device key")
			pkcs12 = None
	devices.update(device, alias = alias, cookie = cookie, pkcs12_bytes = pkcs12)
	return response
Esempio n. 2
0
def _call_and_process(handler, request, device):
    response = handler.call_upstream(request, device)
    cookie = None
    pkcs12 = None
    alias = None
    with minidom.parseString(response.body_text()) as doc:
        x_response = qxml.get_child(doc, 'response')
        x_alias = qxml.get_child(x_response, 'user_device_name')
        alias = qxml.get_text(x_alias)
        x_adp_token = qxml.get_child(x_response, 'adp_token')
        if x_adp_token:
            cookie = qxml.get_text(x_adp_token)
        else:
            x_cookie = qxml.get_child(x_response,
                                      'store_authentication_cookie')
            cookie = qxml.get_text(x_cookie)
            x_key = qxml.get_child(x_response, 'device_private_key')
            pkcs12 = qxml.get_text(x_key)
    if pkcs12:
        try:
            pkcs12 = b64decode(bytes(pkcs12, 'ascii'))
        except:
            logging.exception("failed to decode incoming device key")
            pkcs12 = None
    devices.update(device, alias=alias, cookie=cookie, pkcs12_bytes=pkcs12)
    return response
Esempio n. 3
0
def _process_sidecar_upload(device, book_ids, book_nodes):
	# book_ids is NOT a complete list of books on device
	for asin in book_ids:
		book = calibre.book(asin)
		if book:
			book.mark_on_device(device)

	for x_book in book_nodes:
		asin = x_book.getAttribute('key')
		book = calibre.book(asin)
		if not book:
			logging.warn("sidecar upload for unknown book %s", asin)
			continue

		for kind in ('last_read', 'bookmark', 'highlight', 'note'):
			for x_item in qxml.iter_children(x_book, kind):
				timestamp = x_item.getAttribute('timestamp') or None
				begin = x_item.getAttribute('begin') or None
				end = x_item.getAttribute('end') or begin
				pos = x_item.getAttribute('pos') or None
				state = x_item.getAttribute('state') or None
				text = qxml.get_text(x_item) if kind == 'note' else None

				if kind == 'last_read':
					annotations.set_last_read(device, asin, timestamp, begin, pos, state)
				else:
					action = x_item.getAttribute('action')
					if action == 'create':
						annotations.create(device, asin, kind, timestamp, begin, end, pos, state, text)
					elif action == 'delete':
						annotations.delete(device, asin, kind, timestamp, begin, end)
					elif action == 'modify':
						annotations.modify(device, asin, kind, timestamp, begin, end, text)
					else:
						logging.error("unknown sidecar action %s: %s", action, x_item)
Esempio n. 4
0
def get_query_params(req):
	_, _, query = req.path.partition('?')
	if query:
		return query_params(query)
	q = {}
	if is_signed(req) and req.command == 'POST' and req.body and req.headers['Content-Type'] == 'text/xml':
		try:
			with minidom.parseString(req.body) as doc:
				x_request = qxml.get_child(doc, 'request')
				x_parameters = qxml.get_child(x_request, 'parameters')
				for p in qxml.list_children(x_parameters):
					q[p.nodeName] = qxml.get_text(p)
		except: pass
	return q
Esempio n. 5
0
def get_query_params(req):
    _, _, query = req.path.partition('?')
    if query:
        return query_params(query)
    q = {}
    if is_signed(req) and req.command == 'POST' and req.body and req.headers[
            'Content-Type'] == 'text/xml':
        try:
            with minidom.parseString(req.body) as doc:
                x_request = qxml.get_child(doc, 'request')
                x_parameters = qxml.get_child(x_request, 'parameters')
                for p in qxml.list_children(x_parameters):
                    q[p.nodeName] = qxml.get_text(p)
        except:
            pass
    return q