Beispiel #1
0
 def testSubscribe(self):
     "testing iq/pubsub/subscribe stanzas"
     iq = self.Iq()
     iq['pubsub']['subscribe']['options']
     iq['pubsub']['subscribe']['node'] = 'cheese'
     iq['pubsub']['subscribe']['jid'] = '[email protected]/sleekxmpp'
     iq['pubsub']['subscribe']['options']['node'] = 'cheese'
     iq['pubsub']['subscribe']['options'][
         'jid'] = '[email protected]/sleekxmpp'
     form = xep_0004.Form()
     form.addField('pubsub#title',
                   ftype='text-single',
                   value='this thing is awesome')
     iq['pubsub']['subscribe']['options']['options'] = form
     self.check(iq,
                """
     <iq id="0">
       <pubsub xmlns="http://jabber.org/protocol/pubsub">
         <subscribe node="cheese" jid="[email protected]/sleekxmpp">
           <options node="cheese" jid="[email protected]/sleekxmpp">
             <x xmlns="jabber:x:data" type="submit">
               <field var="pubsub#title">
                 <value>this thing is awesome</value>
               </field>
             </x>
           </options>
         </subscribe>
       </pubsub>
     </iq>""",
                use_values=False)
    def _discover_nodes(self):
        """ Discover all nodes user can access """
        subscriptions = self._get_subscribed_nodes()
        self._nodes = {}

        affiliations = self['xep_0060'].get_affiliations(self._pubsub)
        affiliations = affiliations['pubsub']['affiliations']
        if 'substanzas' not in affiliations.values:
            # No nodes available
            return
        for affiliation in affiliations.values['substanzas']:
            affiliation, node = affiliation['affiliation'], affiliation['node']
            if affiliation == 'owner' and node.startswith('GTG_'):
                # Check node config
                config = self['xep_0060'].get_node_config(self._pubsub, node)
                values = config['pubsub_owner']['configure']['form']['values']

                form = xep_0004.Form()
                form.add_field(
                    var='FORM_TYPE',
                    type='hidden',
                    value='http://jabber.org/protocol/pubsub#node_config')

                if int(values['pubsub#max_items']) < self.MAX_ITEMS:
                    Log.info("Max items is set only to %s" %
                             values['pubsub#max_items'])
                    form.add_field(var='pubsub#max_items',
                                   value=str(self.MAX_ITEMS))

                if values['pubsub#access_model'] != 'whitelist':
                    form.add_field(var='pubsub#access_model',
                                   value='whitelist')

                if not values['pubsub#notify_delete']:
                    form.add_field(var='pubsub#notify_delete', value='1')

                if not values['pubsub#notify_config']:
                    form.add_field(var='pubsub#notify_config', value='1')

                m = re.match('Project (@\w+)', values['pubsub#title'])
                if not m:
                    Log.warning("Malformed node name '%s'" %
                                values['pubsub#title'])
                    continue

                project_name = m.group(1)
                self._nodes[node] = project_name
                Log.info("Discovered project '%s'" % project_name)

                if len(form.field) > 1:
                    form['type'] = 'submit'
                    self['xep_0060'].set_node_config(self._pubsub, node, form)

                if node not in subscriptions:
                    self['xep_0060'].subscribe(self._pubsub, node)

                # Find teammates for cache
                self._teams[node] = self._get_teammates(node)
Beispiel #3
0
    def testPublish(self):
        "Testing iq/pubsub/publish stanzas"
        iq = self.Iq()
        iq['pubsub']['publish']['node'] = 'thingers'
        payload = ET.fromstring("""
          <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
             <child1 />
             <child2 normandy='cheese' foo='bar' />
           </thinger>""")
        payload2 = ET.fromstring("""
          <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
            <child12 />
            <child22 normandy='cheese2' foo='bar2' />
           </thinger2>""")
        item = pubsub.Item()
        item['id'] = 'asdf'
        item['payload'] = payload
        item2 = pubsub.Item()
        item2['id'] = 'asdf2'
        item2['payload'] = payload2
        iq['pubsub']['publish'].append(item)
        iq['pubsub']['publish'].append(item2)
        form = xep_0004.Form()
        form.addField('pubsub#description',
                      ftype='text-single',
                      value='this thing is awesome')
        iq['pubsub']['publish_options'] = form

        self.check(
            iq, """
          <iq id="0">
            <pubsub xmlns="http://jabber.org/protocol/pubsub">
              <publish node="thingers">
                <item id="asdf">
                  <thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
                    <child1 />
                    <child2 foo="bar" normandy="cheese" />
                  </thinger>
                </item>
                <item id="asdf2">
                  <thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
                    <child12 />
                    <child22 foo="bar2" normandy="cheese2" />
                  </thinger2>
                </item>
              </publish>
              <publish-options>
                <x xmlns="jabber:x:data" type="submit">
                  <field var="pubsub#description">
                    <value>this thing is awesome</value>
                  </field>
                </x>
              </publish-options>
            </pubsub>
          </iq>""")
    def _create_node(self, tag):
        """ Create a new node for tag """
        name = 'GTG_%s' % uuid.uuid4()
        form = xep_0004.Form()
        form.add_field(var='pubsub#max_items', value=str(self.MAX_ITEMS))
        form.add_field(var='pubsub#access_model', value='whitelist')
        form.add_field(var='pubsub#notify_delete', value='1')
        form.add_field(var='pubsub#notify_config', value='1')
        title = "Project %s" % tag
        form.add_field(var='pubsub#title', value=title)

        Log.info("Creating node '%s' for tag %s" % (name, tag))
        self['xep_0060'].create_node(self._pubsub, name, config=form)
        self['xep_0060'].subscribe(self._pubsub, name)
        self._nodes[name] = tag
        return name
 def get_options(self):
     config = self.xml.find('{jabber:x:data}x')
     form = xep_0004.Form(xml=config)
     return form
Beispiel #6
0
 def get_publish_options(self):
     config = self.xml.find('{jabber:x:data}x')
     if config is None:
         return None
     form = xep_0004.Form(xml=config)
     return form