webXMPP

Check-in [6e2093a529]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support more subtleties of XMPP presence; "type" field basically means you're offline. Seem to be tracking Jane/Amri along with the n910's XMPP stack behavior.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:6e2093a529779eaa5d3d0078ba9023dba445a964490b0deee82ea42cd6c442b9
User & Date: ajv-899-334-8894@vsta.org 2018-03-13 03:59:48
Context
2018-03-13
04:00
Some debug support tooling for presence data structures check-in: 5bf9f900bf user: ajv-899-334-8894@vsta.org tags: master, trunk
03:59
Support more subtleties of XMPP presence; "type" field basically means you're offline. Seem to be tracking Jane/Amri along with the n910's XMPP stack behavior. check-in: 6e2093a529 user: ajv-899-334-8894@vsta.org tags: master, trunk
02:29
Blacklist in its own file, update from it on demand. check-in: 93ec53def7 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to acct_xmpp.py.

     1      1   #
     2      2   # user.py
     3      3   #	User state
     4      4   #
     5         -import sys, os, xmpp, time
            5  +import sys, os, xmpp, time, cPickle
     6      6   from chore.utils import toascii
     7      7   
     8      8   # Build an account name from a JID node
     9      9   def aname(jid):
    10     10       u = toascii(jid.node)
    11     11       d = toascii(jid.domain)
    12     12       return "%s@%s" % (u, d)
................................................................................
    53     53       #  and exit()
    54     54       def stop(self, tid):
    55     55   	self.stopping = True
    56     56   
    57     57       # Update to presence status of somebody
    58     58       def presence(self, conn, presence):
    59     59   	user = self.user
           60  +
           61  +	# Debug, log so we can break out all the stupid XMPP cases
           62  +	if True:
           63  +	    f = open("/tmp/xmpp_presence.log", "a")
           64  +	    cPickle.dump(presence, f)
           65  +	    f.write("\n\n")
           66  +	    f.close()
    60     67   
    61     68   	# Decode who sent to us
    62     69   	# Note it can be somebody we haven't heard about; presence
    63     70   	#  can arrive before our roster request is fulfilled.
    64     71   	# XMPP is a beast.
    65     72   	n = presence.attrs.get("from")
    66     73   	if not n:
................................................................................
    67     74   	    return
    68     75   	sender = n.node
    69     76   	senddom = n.domain
    70     77   	if (not sender) or (not senddom):
    71     78   	    return
    72     79   	who = sender + "@" + senddom
    73     80   
           81  +	# If they have a type, it's most likely "unavailable"
           82  +	#  and indicates somebody on our configured roster who
           83  +	#  is not online
           84  +	attrs = presence.attrs
           85  +	if "type" in attrs:
           86  +	    if attrs["type"] != "unavailable":
           87  +		sys.stderr.write("Status type not 'unavailable': %s\n" %
           88  +		    (attrs["type"],))
           89  +	    newstat = "offline"
           90  +	    if user.status.get(who, "NEW") != newstat:
           91  +		sys.stderr.write("%s offline\n" % (who,))
           92  +		user.status[who] = newstat
           93  +		user.rgen += 1
           94  +	    return
           95  +
           96  +	# Without that, they should be online
           97  +
    74     98   	# Decode status (i.e., "show") update
    75     99   	sys.stderr.write("presence: %s\n" % (who,))
    76         -	anystat = bool(presence.kids)
    77    100   	for kid in presence.kids:
    78    101   
    79    102   	    # Decode initial part of data
    80    103   	    d0 = None
    81    104   	    if len(kid.data) > 0:
    82    105   		d0 = toascii(kid.data[0])
    83    106   		if not isinstance(d0, str):
    84    107   		    d0 = None
    85    108   
    86    109   	    # Away status
    87    110   	    kn = toascii(kid.name)
    88    111   	    sys.stderr.write("%s %s\n" % (kn, d0))
    89         -	    if kn == "priority":
    90         -		# If they're actually online, this'll show
    91         -		anystat = True
    92    112   	    if kn == "show":
    93    113   		if d0 is None:
    94    114   		    continue
    95    115   		if user.status.get(who, "NEW") != d0:
    96    116   		    sys.stderr.write(" updated %d\n" % (user.rgen,))
    97    117   		    user.status[who] = d0
    98    118   		    user.rgen += 1
    99    119   		break
   100    120   
   101    121   	    # TBD, "status" is a descriptive string
   102    122   
   103    123   	# If "show" didn't break the loop, they're available
   104    124   	else:
   105         -	    if anystat:
   106         -		newstat = "xa"
   107         -	    else:
   108         -		newstat = "offline"
          125  +	    newstat = "available"
   109    126   	    if newstat != user.status.get(who, "NEW"):
   110    127   		sys.stderr.write("no show, updating to assume %s %d\n" %
   111    128   		    (newstat, user.rgen))
   112    129   		user.rgen += 1
   113    130   		user.status[who] = newstat
   114    131   
   115    132       # Update our presence