Beispiel #1
0
 def msg(self, vars, mc, data):
     if not mc:
         # print "warning: minor bug in pypsyc: msg() without mc"
         return
     if self.get_option("debug"):
         dump_packet(">>>", vars, mc, data)
     source = vars.get("_context") or vars.get("_source")
     if not source:
         return  # ignore empty packets?
     obj = self.find_object(source)
     if obj:
         obj.msg(vars, mc, data)
         return
     print "unhandled packet from %s" % source
     # do something about it... pop up a window, etc
     u = parseUNL(source)
     if u["resource"] and u["resource"].startswith("~"):
         # create a user object
         obj = self.create_user(source)
         obj.msg(vars, mc, data)
     elif u["resource"] and u["resource"].startswith("@"):
         # create a place object
         obj = self.create_place(source)
         obj.msg(vars, mc, data)
     else:
         print "no handler for %s object" % (source)
Beispiel #2
0
 def handle(self, vars, mc, data, protocol):
     method = getattr(self, 'recv%s'%mc, None)
     if method is not None:
         method(vars, mc, data, protocol) 
     else:
         u = parseUNL(vars['_source'])
         self.center.register_remote(protocol, u['root'])
         self.center.msg(vars, mc, data)
Beispiel #3
0
 def msg(self, vars, mc, data):
     if not mc:
         return  # ignore empty packets
     source = vars["_source"]
     # TODO: auth check 'global' or per-object
     if vars.has_key("_identification"):
         print "Identification of %s is %s" % (source, vars["_identification"])
     context = vars.get("_context")
     if context and not self.is_local_object(context):
         target = context
     else:
         target = vars["_target"]
     if self.unl2uni.has_key(source):
         """local client who is using us as a proxy"""
         self.unl2uni[source].sendmsg(vars, mc, data)
     elif target:
         obj = self.find_object(target)
         if obj:
             return obj.msg(vars, mc, data)
         # probably object has to be created
         if self.is_local_object(target):
             u = parseUNL(target)
             if u["resource"] and u["resource"].startswith("@"):
                 obj = self.create_place(target)
                 if obj:
                     return obj.msg(vars, mc, data)
                 else:
                     vars["_target"], vars["_source"] = vars["_source"], vars["_target"]
                     self.sendmsg(vars, "_error_unknown_name_place", "No such place: [_source]")
             elif u["resource"] and u["resource"].startswith("~"):
                 obj = self.create_user(target)
                 if obj:
                     return obj.msg(vars, mc, data)
                 else:
                     vars["_target"], vars["_source"] = vars["_source"], vars["_target"]
                     self.sendmsg(vars, "_error_unknown_name_user", "No such user: [_source]")
             elif u["resource"]:
                 vars["_target"] = source
                 vars["_source"] = target
                 self.sendmsg(vars, "_error_unknown_name", "No such object: [_source]")
             else:  # rootmsg
                 pass
         elif context is not None and self.remote_contexts.has_key(context):
             self.remote_contexts[context].castmsg(vars, mc, data)
         else:  # nonlocal target
             print "rejected relay %s from %s to %s" % (mc, source, target)
             return  # skip it for now
             self.sendmsg(
                 {"_target": source, "_source": self.location, "_destination": target},
                 "_error_rejected_relay",
                 "You are not allowed to send messages to [_destination]",
             )
     else:
         # no target???
         print "no target in packet???"
Beispiel #4
0
    def __init__(self, config):
        self.config = config

        self.default_uni = config.get("main", "uni")

        u = parseUNL(self.default_uni)
        self.nick = u["resource"][1:]
        self.default_connection = netLocation(self.default_uni)
        if self.config.has_section("library"):
            for option in self.config.options("library"):
                self.options[option] = self.config.getboolean("library", option)
Beispiel #5
0
 def __init__(self, center, target, myname = None):
     # TODO: dont try to resolve IP addresses ;)
     # must subclass
     if not self.factory_type: raise NotImplementedError
     try:
         self.factory = self.factory_type(center, target, myname)
     except:
         print self.factory_type
         raise
     u = parseUNL(target)
     self.host = u['host']
     d = client.lookupService('_psyc._tcp.' + self.host)
     d.addCallback(self.srvResolved)
Beispiel #6
0
 def sendmsg(self, vars, mc, data):
     target = vars["_target"]
     if self.is_local_object(target):
         self.msg(vars, mc, data)
     else:
         u = parseUNL(target)
         target = self.find_object(target) or self.find_remote(target) or self.find_remote(target)
         if not target and u["scheme"] == "psyc":
             q = self.connect(u["root"])
             q.msg(vars, mc, data)
         elif target:
             target.msg(vars, mc, data)
         else:
             raise "can not find %s" % (target)  # programming error?
Beispiel #7
0
 def check(self, vars, mc, data, protocol, peer):
     source = vars.get('_context') or vars.get('_source')
     if (source and not 
         source.startswith('psyc://%s'%(peer.host))):
         u = parseUNL(source)
         d = client.lookupAddress(u['host'])
         d.addCallback(self.resolved, peer.host, vars, mc, data, protocol)
     elif source:
         # numeric address
         self.handle(vars, mc, data, protocol)
     else:
         protocol.msg({ '_source' : self.myname }, 
                     '_error_syntax_protocol_missing_source', 
                     'Your implementation is broken')
Beispiel #8
0
 def msg_request_leave(self, vars, mc, data):
     source = vars['_source']
     # TODO again 
     origin = parseUNL(source)['root']
     v = { '_source' : source }
     if self.member(source):
         self.castmsg({ '_source' : source }, '_notice_place_leave', 
                      '[_nick] leaves')
         self.remove(source)
     else: # not a member for whatever reason
         self.sendmsg({ '_target' : source}, '_echo_place_leave',
                      'You are not even a member')
         pass
     if self.sizeof() == 0:
         # empty
         pass
Beispiel #9
0
 def msg_request_enter(self, vars, mc, data):
     source = vars['_source']
     if '_identification' in vars:
         ident = vars.get('_identification')
         print 'looking up identification %s'%(ident,)
         self.sendmsg({ '_target' : ident,
                      '_location' : source },
                      '_request_authenticate', 'Is that really you?')
         d = defer.Deferred()
         d.addCallback(self.helper, vars, mc, data)
         d.addErrback(self.helper, vars, mc, data)
         self.idcallbacks[(source, ident)] = d
         return
     # TODO: while it is not the final plan to make this via parseUNL
     #       it is acceptable for now
     origin = parseUNL(source)['root']
     v = { '_target' : source,
         '_source' : self.netname }
     if '_tag' in vars:
         v['_tag'] = vars['_tag']
     else:
         pass
     if '_nick' in vars:
         v['_nick'] = vars['_nick']
     else:
         pass
     if self.silent is True:
         v['_control'] = '_silent'
     self.sendmsg(v, '_echo_place_enter', 
                  '[_nick] enters')
     v.pop('_control', None)
     v.pop('_tag', None)
     
     v['_list_members'] = self.showMembers() + [ source ]
     self.sendmsg(v, '_status_place_members', '...')
         
     v.pop('_list_members')
     if not self.member(source): 
         v['_source'] = source
         self.castmsg(v, '_notice_place_enter', '[_nick] enters')
     self.insert(vars['_source'], origin)
Beispiel #10
0
 def create_place(self, netname):
     u = parseUNL(netname)
     res = u['resource'][1:]
     if self.feeds.has_key(res):
         return Feedplace(netname, center, self.feeds[res])
     return False