| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import weakref, sha |
|---|
| 27 |
from xml.sax.saxutils import escape, quoteattr |
|---|
| 28 |
from RBFoundation.BindCallable import BindCallable |
|---|
| 29 |
from iqQuery import iqQueryBase |
|---|
| 30 |
|
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
#~ Definitions |
|---|
| 33 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 34 |
|
|---|
| 35 |
class iqAuthQuery(iqQueryBase): |
|---|
| 36 |
def __init__(self, JC, username, password, resource, callback=None, BidValue=1): |
|---|
| 37 |
self._AuthInProgress = 1 |
|---|
| 38 |
iqQueryBase.__init__(self, JC, callback, BidValue) |
|---|
| 39 |
|
|---|
| 40 |
self.JC().information.authorized = 0 |
|---|
| 41 |
self.JC().information.jid = self.JC().BuildJID(username, None, resource) |
|---|
| 42 |
|
|---|
| 43 |
while not self.JC()._elements: |
|---|
| 44 |
self.JC().Process() |
|---|
| 45 |
|
|---|
| 46 |
digest = sha.new(self.JC()._elements[0].id + password).hexdigest() |
|---|
| 47 |
xmlAuthInfo = '<username>%s</username><digest>%s</digest><resource>%s</resource>' % (username, digest, resource) |
|---|
| 48 |
|
|---|
| 49 |
self.SendQuery('jabber:iq:auth', type='set', xml=xmlAuthInfo) |
|---|
| 50 |
# The last match assertion says that there is a child |
|---|
| 51 |
# in the jabber:iq:auth namespace, which there won't be. |
|---|
| 52 |
# So remove that match criteria. |
|---|
| 53 |
self.Match.pop() |
|---|
| 54 |
|
|---|
| 55 |
def __nonzero__(self): |
|---|
| 56 |
if self._AuthInProgress: |
|---|
| 57 |
return 1 |
|---|
| 58 |
else: return super(iqAuthQuery, self).__nonzero__() |
|---|
| 59 |
|
|---|
| 60 |
def __call__(self, stream, iq): |
|---|
| 61 |
if iq.type == 'result': |
|---|
| 62 |
self.JC().information.authorized = 1 |
|---|
| 63 |
self._AuthInProgress = 0 |
|---|
| 64 |
if self: |
|---|
| 65 |
return super(iqAuthQuery, self).__call__(stream, iq) |
|---|