Esempio n. 1
0
 def do_databases(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     revision, delta = self.get_revision(query)
     if len(path) == 1:
         reply = []
         db = []
         items = self.server.backend.get_items()
         count = len([i for i in items.values() if i["valid"]])
         name = self.server.name
         playlists = self.server.backend.get_playlists()
         npl = 1 + len([p for p in playlists.values() if p["valid"]])
         db.append(
             (
                 "mlit",
                 [
                     ("miid", 1),  # Item ID
                     ("mper", 1),  # Persistent ID
                     ("minm", name),  # Name
                     ("mimc", count),  # Total count
                     # Playlist is always non-zero because of
                     # default playlist.
                     ("mctc", npl),  # Playlist count
                 ],
             )
         )
         update = 1 if delta else 0
         reply.append(
             (
                 "avdb",
                 [
                     ("mstt", DAAP_OK),  # OK
                     ("muty", update),  # Update type
                     ("mtco", 1),  # Specified total count
                     ("mrco", 1),  # Returned count
                     ("mlcl", db),  # db listing
                 ],
             )
         )
         return (DAAP_OK, reply, [])
     else:
         # XXX might want to consider using regexp to do some complex
         # matching here.
         if path[2] == "containers":
             return self.do_database_containers(path, query)
         elif path[2] == "browse":
             return self.do_database_browse(path, query)
         elif path[2] == "items":
             return self.do_database_items(path, query)
         elif path[2] == "groups":
             return self.do_database_groups(path, query)
         else:
             return (DAAP_FORBIDDEN, [], [])
Esempio n. 2
0
 def do_update(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     # UGH.  We should be updating this ... this is not supported at the 
     # moment.
     xxx_revision = 2
     reply = []
     reply.append(('mupd', [('mstt', DAAP_OK), ('musr', xxx_revision)]))
     return (DAAP_OK, reply, [])
Esempio n. 3
0
 def do_update(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     old_revision, old_delta = self.get_revision(query)
     # if not old_revision:
     #    return (DAAP_BADREQUEST, [], [])
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     revision = self.server.backend.get_revision(session, old_revision, self.request)
     reply = []
     reply.append(("mupd", [("mstt", DAAP_OK), ("musr", revision)]))
     return (DAAP_OK, reply, [])
Esempio n. 4
0
 def get_session(self):
     path, query = split_url_path(self.path)
     session = 0
     if not query or not 'session-id' in query.keys():
         pass
     else:
         try:
             session = int(query['session-id'])
             if not self.server.renew_session(session):
                 session = 0
         except ValueError:
             pass
     return session
Esempio n. 5
0
 def get_session(self):
     path, query = split_url_path(self.path)
     session = 0
     if not query or not 'session-id' in query.keys():
         pass
     else:
         try:
             session = int(query['session-id'])
             if not self.server.renew_session(session):
                 session = 0
         except ValueError:
             pass
     return session
Esempio n. 6
0
 def do_update(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     old_revision, old_delta = self.get_revision(query)
     #if not old_revision:
     #    return (DAAP_BADREQUEST, [], [])
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     revision = self.server.backend.get_revision(session, old_revision,
                                                 self.request)
     reply = []
     reply.append(('mupd', [('mstt', DAAP_OK), ('musr', revision)]))
     return (DAAP_OK, reply, [])
Esempio n. 7
0
 def do_databases(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     revision, delta = self.get_revision(query)
     if len(path) == 1:
         reply = []
         db = []
         items = self.server.backend.get_items()
         count = len([i for i in items.values() if i['valid']])
         name = self.server.name
         playlists = self.server.backend.get_playlists()
         npl = 1 + len([p for p in playlists.values() if p['valid']])
         db.append((
             'mlit',
             [
                 ('miid', 1),  # Item ID
                 ('mper', 1),  # Persistent ID
                 ('minm', name),  # Name
                 ('mimc', count),  # Total count
                 # Playlist is always non-zero because of
                 # default playlist.
                 ('mctc', npl)  # Playlist count
             ]))
         update = 1 if delta else 0
         reply.append((
             'avdb',
             [
                 ('mstt', DAAP_OK),  # OK
                 ('muty', update),  # Update type
                 ('mtco', 1),  # Specified total count
                 ('mrco', 1),  # Returned count
                 ('mlcl', db)  # db listing
             ]))
         return (DAAP_OK, reply, [])
     else:
         # XXX might want to consider using regexp to do some complex
         # matching here.
         if path[2] == 'containers':
             return self.do_database_containers(path, query)
         elif path[2] == 'browse':
             return self.do_database_browse(path, query)
         elif path[2] == 'items':
             return self.do_database_items(path, query)
         elif path[2] == 'groups':
             return self.do_database_groups(path, query)
         else:
             return (DAAP_FORBIDDEN, [], [])
Esempio n. 8
0
 def do_databases(self):
     path, query = split_url_path(self.path)
     session = self.get_session()
     if not session:
         return (DAAP_FORBIDDEN, [], [])
     revision, delta = self.get_revision(query)
     if len(path) == 1:
         reply = []
         db = []
         items = self.server.backend.get_items()
         count = len([i for i in items.values() if i['valid']])
         name = self.server.name
         playlists = self.server.backend.get_playlists()
         npl = 1 + len([p for p in playlists.values() if p['valid']])
         db.append((
             'mlit',
             [
                 ('miid', 1),  # Item ID
                 ('mper', 1),  # Persistent ID
                 ('minm', name),  # Name
                 ('mimc', count),  # Total count
                 # Playlist is always non-zero because of
                 # default playlist.
                 ('mctc', npl)  # Playlist count
             ]))
         update = 1 if delta else 0
         reply.append((
             'avdb',
             [
                 ('mstt', DAAP_OK),  # OK
                 ('muty', update),  # Update type
                 ('mtco', 1),  # Specified total count
                 ('mrco', 1),  # Returned count
                 ('mlcl', db)  # db listing
             ]))
         return (DAAP_OK, reply, [])
     else:
         # XXX might want to consider using regexp to do some complex
         # matching here.
         if path[2] == 'containers':
             return self.do_database_containers(path, query)
         elif path[2] == 'browse':
             return self.do_database_browse(path, query)
         elif path[2] == 'items':
             return self.do_database_items(path, query)
         elif path[2] == 'groups':
             return self.do_database_groups(path, query)
         else:
             return (DAAP_FORBIDDEN, [], [])