GCal: Better Callback management

- when callback of an old channel is received this channel is canceled automatically
This commit is contained in:
Martin Bauer
2014-06-20 08:57:04 +02:00
parent 5fc206112d
commit 5639c5fd82
2 changed files with 49 additions and 7 deletions

View File

@@ -332,3 +332,36 @@ def stopAllGCalSubscriptions( service=None ):
for dbChannel in GCalPushChannel.objects.all():
print("Stopping %s expiry at %d " % ( dbChannel.id, dbChannel.expiration ) )
GCalPushChannel.stop( service, dbChannel.toGChannel() )
def checkIfGoogleCallbackIsValid( token, channelID, resourceID, service=None ):
if service is None: service = getServiceObject()
allChannels = GCalPushChannel.objects.all()
if len(allChannels) == 0:
return False # no known subscriptions -> callback has to be from an old channel
if len(allChannels) > 1:
logger.warning( "Multiple GCal subscriptions! This is strange and probably an error. "
"All channels are closed and one new is created. ")
stopAllGCalSubscriptions( service )
checkGCalSubscription()
allChannels = GCalPushChannel.objects.all()
assert( len(allChannels) == 1 )
theChannel = allChannels[0]
if channelID != theChannel.id or resourceID != theChannel.resource_id or token != theChannel.token:
logger.warning( "Got GCal Response from an unexpected Channel"
"Got (%s,%s,%s) "
"expected (%s,%s,%s) "
"Old Channel is stopped."
% ( channelID, resourceID,token, theChannel.id, theChannel.resource_id, theChannel.token ))
channelToStop = GCalPushChannel( id = channelID, resource_id = resourceID, token = token )
GCalPushChannel.stop( service, channelToStop.toGChannel() )
return False
return True