/usr/share/pyaimt/src/services/VCardFactory.py is in pyaimt 0.8.0.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | # Copyright 2004-2006 Daniel Henninger <jadestorm@nc.rr.com>
# Licensed for distribution under the GPL version 2, check COPYING for details
import utils
from twisted.words.xish.domish import Element
from twisted.words.protocols.jabber.jid import internJID
import legacy
import config
import lang
from debug import LogEvent, INFO, WARN, ERROR
import globals
class VCardFactory:
def __init__(self, pytrans):
self.pytrans = pytrans
self.pytrans.disco.addFeature(globals.VCARD, self.incomingIq, "USER")
self.pytrans.disco.addFeature(globals.VCARD, self.incomingIq, config.jid)
self.pytrans.adhoc.addCommand("updatemyvcard", self.getMyVCard, "command_UpdateMyVCard")
def incomingIq(self, el):
itype = el.getAttribute("type")
fro = el.getAttribute("from")
froj = internJID(fro)
to = el.getAttribute("to")
ID = el.getAttribute("id")
filter = None
if itype != "get" and itype != "error":
self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="cancel", condition="feature-not-implemented")
return
LogEvent(INFO, msg="Sending vCard")
for child in el.elements():
if child.name == "vCard" and child.uri == globals.VCARD:
for child2 in child.elements():
if child2.name == "filter" and child2.uri == globals.VCARDFILTER:
filter = child2
break
break
toGateway = not (to.find('@') > 0)
if not toGateway:
if not self.pytrans.sessions.has_key(froj.userhost()):
self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
return
s = self.pytrans.sessions[froj.userhost()]
if not s.ready:
self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
return
c = s.contactList.findContact(to)
if not c:
iq = Element((None, "iq"))
iq.attributes["to"] = fro
iq.attributes["from"] = to
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
vCard = iq.addElement("vCard")
vCard.attributes["xmlns"] = globals.VCARD
self.pytrans.legacycon.getvCardNotInList(vCard, to).addCallback(self.gotvCardResponse, iq, filter)
return
# Lets leave this up to the legacy pieces
#self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="cancel", condition="recipient-unavailable")
iq = Element((None, "iq"))
iq.attributes["to"] = fro
iq.attributes["from"] = to
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
vCard = iq.addElement("vCard")
vCard.attributes["xmlns"] = globals.VCARD
if toGateway:
FN = vCard.addElement("FN")
FN.addContent(legacy.name)
DESC = vCard.addElement("DESC")
DESC.addContent(legacy.name)
URL = vCard.addElement("URL")
URL.addContent(legacy.url)
if not config.disableAvatars and not config.disableVCardAvatars:
from legacy import defaultAvatar
PHOTO = defaultAvatar.makePhotoElement()
vCard.addChild(PHOTO)
self.pytrans.send(iq)
else:
c.fillvCard(vCard, to).addCallback(self.gotvCardResponse, iq, filter)
def gotvCardResponse(self, vcard, iq, filter):
LogEvent(INFO)
if filter:
for child in filter.elements():
for vchild in vcard.elements():
if vchild.name.lower() == child.name.lower():
vcard.children.remove(vchild)
self.pytrans.send(iq)
def getMyVCard(self, el):
to = el.getAttribute("from")
fro = el.getAttribute("from")
froj = internJID(fro)
ID = el.getAttribute("id")
ulang = utils.getLang(el)
if not self.pytrans.sessions.has_key(froj.userhost()):
self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
return
s = self.pytrans.sessions[froj.userhost()]
if not s.ready:
self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
return
s.doVCardUpdate()
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
x = command.addElement("x")
x.attributes["xmlns"] = globals.XDATA
x.attributes["type"] = "result"
title = x.addElement("title")
title.addContent(lang.get("command_UpdateMyVCard", ulang))
field = x.addElement("field")
field.attributes["type"] = "fixed"
field.addElement("value").addContent(lang.get("command_Done", ulang))
self.pytrans.send(iq)
|