From f624f84022651c6c5f8f5448e0cba7e9574cdc4e Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 11 May 2010 13:12:40 +0200 Subject: [PATCH] add support for the draft --- pyweb/mumble/mmobjects.py | 33 ++++++++++++++++++++++++++++++--- pyweb/mumble/models.py | 30 +++++++++++++++++++----------- pyweb/mumble/urls.py | 21 ++++++++++++--------- pyweb/mumble/views.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 23 deletions(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index ed0a5bf..41b1aed 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -154,10 +154,24 @@ class mmChannel( object ): def asDict( self ): chandata = self.channel_obj.__dict__.copy() - chandata['players'] = [ pl.asDict() for pl in self.players ] - chandata['subchans'] = [ sc.asDict() for sc in self.subchans ] + chandata['users'] = [ pl.asDict() for pl in self.players ] + chandata['channels'] = [ sc.asDict() for sc in self.subchans ] + chandata['x-connecturl'] = self.connecturl return chandata + def asXml( self, parentnode ): + from xml.etree.cElementTree import SubElement + me = SubElement( parentnode, "channel" ) + for key in self.channel_obj.__dict__: + me.set( key, unicode( getattr( self.channel_obj, key ) ) ) + + me.set( "x-connecturl", self.connecturl ) + + for sc in self.subchans: + sc.asXml(me) + for pl in self.players: + pl.asXml(me) + def asMvXml( self, parentnode ): """ Return an XML tree for this channel suitable for MumbleViewer-ng. """ from xml.etree.cElementTree import SubElement @@ -264,13 +278,26 @@ class mmPlayer( object ): def asDict( self ): pldata = self.player_obj.__dict__.copy() + pldata["x-addrstring"] = self.ipaddress if self.mumbleuser: if self.mumbleuser.hasTexture(): - pldata['texture'] = self.mumbleuser.textureUrl + pldata['x-texture'] = self.mumbleuser.textureUrl return pldata + def asXml( self, parentnode ): + from xml.etree.cElementTree import SubElement + me = SubElement( parentnode, "user" ) + for key in self.player_obj.__dict__: + me.set( key, unicode( getattr( self.player_obj, key ) ) ) + + me.set("x-addrstring", self.ipaddress ) + + if self.mumbleuser: + if self.mumbleuser.hasTexture(): + me.set( 'x-texture', self.mumbleuser.textureUrl ) + def asMvXml( self, parentnode ): """ Return an XML node for this player suitable for MumbleViewer-ng. """ from xml.etree.cElementTree import SubElement diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 9e963ef..d611638 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -16,19 +16,19 @@ """ import socket, Ice, re -from sys import stderr +from sys import stderr from urllib import urlopen -from StringIO import StringIO -from PIL import Image +from StringIO import StringIO +from PIL import Image -from django.utils.translation import ugettext_noop, ugettext_lazy as _ +from django.utils.translation import ugettext_noop, ugettext_lazy as _ from django.contrib.auth.models import User -from django.db import models -from django.db.models import signals -from django.conf import settings +from django.db import models +from django.db.models import signals +from django.conf import settings -from mumble.mmobjects import mmChannel, mmPlayer -from mumble.mctl import MumbleCtlBase +from mumble.mmobjects import mmChannel, mmPlayer +from mumble.mctl import MumbleCtlBase def get_ipv46_host_by_name( hostname ): @@ -36,7 +36,7 @@ def get_ipv46_host_by_name( hostname ): if applicable. Returns: { AF_INET: inet4address, AF_INET6: inet6address }. For addresses that don't exist, the corresponding field will be None. """ - addrinfo = socket.getaddrinfo( hostname, settings.MUMBLE_DEFAULT_PORT ) + addrinfo = socket.getaddrinfo( hostname, settings.MUMBLE_DEFAULT_PORT, 0, socket.SOCK_DGRAM ) ret = {} for (family, socktype, proto, canonname, sockaddr) in addrinfo: if family not in ret: @@ -551,9 +551,17 @@ class Mumble( models.Model ): def asDict( self ): return { 'name': self.name, 'id': self.id, - 'root': self.rootchan.asDict() + 'root': self.rootchan.asDict(), + 'x-connecturl': self.connecturl } + def asXml( self ): + from xml.etree.cElementTree import Element + root = Element( "server", id=unicode(self.id), name=self.name ) + root.set( 'x-connecturl', self.connecturl ) + self.rootchan.asXml(root) + return root + def asMvXml( self ): """ Return an XML tree for this server suitable for MumbleViewer-ng. """ from xml.etree.cElementTree import Element diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index 713d51e..cd40e07 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -19,18 +19,21 @@ from django.conf.urls.defaults import patterns urlpatterns = patterns( 'mumble.views', - ( r'djangousers', 'djangousers' ), - ( r'(?P\d+)/users', 'users' ), + ( r'djangousers', 'djangousers' ), + ( r'(?P\d+)/users', 'users' ), - ( r'(?P\d+)/(?P\d+)/texture.png', 'showTexture' ), + ( r'(?P\d+)/(?P\d+)/texture.png', 'showTexture' ), - ( r'murmur/tree/(?P\d+)', 'mmng_tree' ), - ( r'mumbleviewer/(?P\d+).xml', 'mumbleviewer_tree_xml' ), - ( r'mumbleviewer/(?P\d+).json', 'mumbleviewer_tree_json'), + ( r'murmur/tree/(?P\d+)', 'mmng_tree' ), + ( r'mumbleviewer/(?P\d+).xml', 'mumbleviewer_tree_xml' ), + ( r'mumbleviewer/(?P\d+).json', 'mumbleviewer_tree_json'), - ( r'mobile/(?P\d+)', 'mobile_show' ), - ( r'mobile/?$', 'mobile_mumbles' ), + ( r'mobile/(?P\d+)', 'mobile_show' ), + ( r'mobile/?$', 'mobile_mumbles' ), + + ( r'(?P\d+).json', 'cvp_json' ), + ( r'(?P\d+).xml', 'cvp_xml' ), ( r'(?P\d+)', 'show' ), - ( r'$', 'mumbles' ), + ( r'$', 'mumbles' ), ) diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index e24048a..3ac0fbf 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -378,6 +378,36 @@ def mmng_tree( request, server ): ) +def cvp_json( request, server ): + """ JSON reference implementation for the Channel Viewer Protocol. + + See + """ + srv = get_object_or_404( Mumble, id=int(server) ) + + if "jsonp_callback" in request.GET: + prefix = request.GET["jsonp_callback"] + else: + prefix = "" + + return HttpResponse( + prefix + "(" + simplejson.dumps( srv.asDict() ) + ")", + mimetype='text/javascript' + ) + +def cvp_xml( request, server ): + """ XML reference implementation for the Channel Viewer Protocol. + + See + """ + from xml.etree.cElementTree import tostring as xml_to_string + srv = get_object_or_404( Mumble, id=int(server) ) + return HttpResponse( + xml_to_string( srv.asXml(), encoding='utf-8' ), + mimetype='text/xml' + ) + + def mumbleviewer_tree_xml( request, server ): """ Get the XML tree from the server and serialize it to the client. """ from xml.etree.cElementTree import tostring as xml_to_string