'The internal method to process service discovery requests'

def _DiscoHandler(self, conn, request, typ):

    if (typ == 'items'):
        list = []
        items = []
        jid = str(request.getTo())
        if self._handlers.has_key(jid):
            for each in self._handlers[jid].keys():
                items.append((jid, each))
        else:
            for each in self._handlers[''].keys():
                items.append(('', each))
        if (items != []):
            for each in items:
                i = self._handlers[each[0]][each[1]]['disco'](conn, request, 'list')
                if (i != None):
                    list.append(Node(tag='item', attrs={'jid': i[0], 'node': i[1], 'name': i[2]}))
            iq = request.buildReply('result')
            if request.getQuerynode():
                iq.setQuerynode(request.getQuerynode())
            iq.setQueryPayload(list)
            conn.send(iq)
        else:
            conn.send(Error(request, ERR_ITEM_NOT_FOUND))
        raise NodeProcessed
    elif (typ == 'info'):
        return {'ids': [{'category': 'automation', 'type': 'command-list'}], 'features': []}
