2015-01-27 16:50:28 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2015 OpenMarket Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
from twisted.internet import defer
|
|
|
|
|
|
|
|
from ._base import BaseHandler
|
2015-01-28 12:59:38 +01:00
|
|
|
from synapse.api.errors import Codes, StoreError, SynapseError
|
2015-01-27 16:50:28 +01:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationServicesHandler(BaseHandler):
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(ApplicationServicesHandler, self).__init__(hs)
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
2015-01-27 18:15:06 +01:00
|
|
|
def register(self, app_service):
|
2015-01-27 18:34:40 +01:00
|
|
|
logger.info("Register -> %s", app_service)
|
2015-01-27 16:50:28 +01:00
|
|
|
# check the token is recognised
|
|
|
|
try:
|
2015-01-27 18:15:06 +01:00
|
|
|
stored_service = yield self.store.get_app_service(app_service.token)
|
|
|
|
if not stored_service:
|
2015-01-28 12:59:38 +01:00
|
|
|
raise StoreError(404, "Application Service Not found")
|
2015-01-27 16:50:28 +01:00
|
|
|
except StoreError:
|
|
|
|
raise SynapseError(
|
|
|
|
403, "Unrecognised application services token. "
|
2015-01-28 12:59:38 +01:00
|
|
|
"Consult the home server admin.",
|
|
|
|
errcode=Codes.FORBIDDEN
|
2015-01-27 16:50:28 +01:00
|
|
|
)
|
2015-01-27 18:15:06 +01:00
|
|
|
# TODO store this AS
|
2015-01-27 17:53:59 +01:00
|
|
|
|
|
|
|
def unregister(self, token):
|
2015-01-27 18:34:40 +01:00
|
|
|
logger.info("Unregister as_token=%s", token)
|
2015-01-27 17:53:59 +01:00
|
|
|
yield self.store.unregister_app_service(token)
|
|
|
|
|
|
|
|
def notify_interested_services(self, event):
|
|
|
|
"""Notifies (pushes) all application services interested in this event.
|
|
|
|
|
|
|
|
Pushing is done asynchronously, so this method won't block for any
|
|
|
|
prolonged length of time.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
event(Event): The event to push out to interested services.
|
|
|
|
"""
|
|
|
|
# TODO: Gather interested services
|
|
|
|
# get_services_for_event(event) <-- room IDs and user IDs
|
|
|
|
# Get a list of room aliases. Check regex.
|
|
|
|
# TODO: If unknown user: poke User Query API.
|
|
|
|
# TODO: If unknown room alias: poke Room Alias Query API.
|
|
|
|
|
|
|
|
# TODO: Fork off pushes to these services - XXX First cut, best effort
|
|
|
|
pass
|