class NewProfileHandler(component): Inboxes = {"inbox" : "", "control" : "Shutdown the client stream", "_response": ""} Outboxes = {"outbox" : "", "signal" : "Shutdown signal", "log" : "log", "_request": ""} def __init__(self, base_dir, atompub): super(NewProfileHandler, self).__init__() self.base_dir = base_dir self.atompub = atompub def initComponents(self): self.client = SimpleHTTPClient() self.addChildren(self.client) self.link((self, '_request'), (self.client, 'inbox')) self.link((self.client, 'outbox'), (self, '_response')) self.client.activate() def main(self): yield self.initComponents() while 1: if self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or \ isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break if self.dataReady("inbox"): feed = self.recv('inbox') for entry in feed.entries: for link in entry.links: if link.rel == 'edit-media' and link.type == 'application/xml': profile_name = urlparse(link.href)[2].rsplit('/', -1)[-1] pwd = ProfileManager.set_profile_password(self.base_dir, profile_name) profile = ProfileManager.load_profile(self.base_dir, self.atompub, profile_name) Client.register_jabber_user(self.atompub, profile_name.lower(), pwd, profile) params = {'url': link.href, 'method': 'DELETE'} self.send(params, '_request') continue if not self.anyReady(): self.pause() yield 1
def initComponents(self): sub = SubscribeTo("JID.%s" % self.session_id) self.link((sub, 'outbox'), (self, 'jid')) self.addChildren(sub) sub.activate() client = SimpleHTTPClient() self.addChildren(client) self.link((self, '_request'), (client, 'inbox')) self.link((client, 'outbox'), (self, '_response')) client.activate() return 1
def initComponents(self): sub = SubscribeTo("JID.%s" % self.session_id) self.link((sub, 'outbox'), (self, 'jid')) self.addChildren(sub) sub.activate() feedreader = FeedReaderComponent(use_etags=False) self.addChildren(feedreader) feedreader.activate() client = SimpleHTTPClient() self.addChildren(client) self.link((self, '_feedrequest'), (client, 'inbox')) self.link((client, 'outbox'), (feedreader, 'inbox')) self.link((feedreader, 'outbox'), (self, '_feedresponse')) client.activate() client = SimpleHTTPClient() self.addChildren(client) self.link((self, '_delrequest'), (client, 'inbox')) self.link((client, 'outbox'), (self, '_delresponse')) client.activate() return 1
class RegistrationHandler(component): Inboxes = {"inbox" : "headstock.api.registration.Registration", "error" : "headstock.api.registration.Registration", "control" : "Shutdown the client stream", "_response": ""} Outboxes = {"outbox" : "headstock.api.registration.Registration", "signal" : "Shutdown signal", "log" : "log", "_request": ""} def __init__(self, username, password, session_id, profile): super(RegistrationHandler, self).__init__() self.username = username self.password = password self.profile = profile self.registration_id = None self.session_id = session_id def initComponents(self): self.client = SimpleHTTPClient() self.addChildren(self.client) self.link((self, '_request'), (self.client, 'inbox')) self.link((self.client, 'outbox'), (self, '_response')) self.client.activate() def main(self): yield self.initComponents() while 1: if self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break if self.dataReady("_response"): self.recv("_response") if self.dataReady("inbox"): r = self.recv('inbox') if r.registered: self.send("'%s' is already a registered username." % r.infos[u'username'], 'log') c = Client.Sessions[r.infos[u'username']] c.shutdown() del Client.Sessions[r.infos[u'username']] elif self.registration_id == r.stanza_id: c = Client.Sessions[r.infos[u'username']] c.shutdown() del Client.Sessions[r.infos[u'username']] if '.microblogging' not in r.infos[u'username']: body = self.profile.xml() params = {'url': 'http://localhost:8080/profile/', 'method': 'POST', 'postbody': body, 'extraheaders': {'content-type': 'application/xml', 'slug': self.profile.username, 'content-length': len(body)}} self.send(params, '_request') else: if 'username' in r.infos and 'password' in r.infos: self.registration_id = generate_unique() r = Registration(type=u'set', stanza_id=self.registration_id) r.infos[u'username'] = self.username r.infos[u'password'] = self.password self.send(r, 'outbox') if self.dataReady("error"): r = self.recv('error') if r.error.code == '409': self.send("'%s' is already a registered username." % r.infos[u'username'], 'log') c = Client.Sessions[r.infos[u'username']] c.shutdown() del Client.Sessions[r.infos[u'username']] self.send(r.error, 'log') if not self.anyReady(): self.pause() yield 1