Changeset 2240

Show
Ignore:
Timestamp:
07/03/07 02:16:47 (1 year ago)
Author:
abaumann
Message:

Remove the phone's (partial) serial number from the generated UIDs.
This was a potential privacy issue, and was redundant anyway, because
OpenSync? should always tell us if a change is new (CHANGE_TYPE_ADDED)
or one we've seen before (MODIFIED).

Also, use an anchor on the serial number instead to detect if the phone
is changed and force a slow-sync.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/moto-sync/motosync.py

    r2232 r2240  
    21102110        return ret 
    21112111 
    2112     def delete_entry(self, uid): 
    2113         """Delete an event with the given UID 
     2112    def delete_entry(self, objtype, uid): 
     2113        """Delete an event with the given objtype and UID 
    21142114 
    21152115        Returns True on success, False otherwise. 
    21162116        """ 
    2117         objtype, positions = self.__uid_to_pos(uid
     2117        positions = self.__uid_to_pos(uid, objtype
    21182118        for pos in positions: 
    21192119            if objtype == 'event': 
     
    21442144            context.report_osyncwarning(err) 
    21452145            # we have an entry that can't be stored on the phone 
    2146             # if its modified and we've seen it before, delete it 
     2146            # if its modified, we've seen it before, so delete it 
    21472147            # otherwise just ignore it 
    2148             if (change.changetype == opensync.CHANGE_TYPE_MODIFIED and self.uid_seen(change.uid))
     2148            if change.changetype == opensync.CHANGE_TYPE_MODIFIED
    21492149                change.changetype = opensync.CHANGE_TYPE_DELETED 
    21502150                change.data = None 
    2151                 return self.delete_entry(change.uid) 
     2151                return self.delete_entry(objtype, change.uid) 
    21522152            else: 
    21532153                return False 
     
    21572157            entry.set_pos(positions) 
    21582158        else: 
    2159             _, positions = self.__uid_to_pos(change.uid
     2159            positions = self.__uid_to_pos(change.uid, objtype
    21602160            # check if the number of positions required has changed 
    21612161            pos_diff = entry.num_pos() - len(positions) 
     
    21792179        return True 
    21802180 
    2181     def uid_seen(self, uid): 
    2182         """Returns true iff the given UID is one of ours.""" 
    2183         try: 
    2184             self.__uid_to_pos(uid) 
    2185             return True 
    2186         except (AssertionError, ValueError, TypeError): 
    2187             return False 
    2188  
    21892181    def __init_categories(self): 
    21902182        """Initialise a hash and reverse hash of category IDs.""" 
     
    22102202        return m.hexdigest() 
    22112203 
    2212     def __generate_uid(self, entry): 
    2213         """Generate a "hopefully unique" UID for an entry. 
    2214  
    2215         Uses the last 8 digit's of the phone's IMEI to do so. 
     2204    @staticmethod 
     2205    def __generate_uid(entry): 
     2206        """Generate a UID for an entry, that encodes the objtype and the position.""" 
     2207        return ("moto-%s-%s" % (entry.get_objtype(), entry.generate_uid())) 
     2208 
     2209    @staticmethod 
     2210    def __uid_to_pos(uid, objtype): 
     2211        """Reverse of the generate_uid function above. 
     2212 
     2213        Also checks that the objtype matches. 
    22162214        """ 
    2217         return ("moto-%s-%s@%s" % (entry.get_objtype(), entry.generate_uid(), self.serial[-8:])) 
    2218  
    2219     def __uid_to_pos(self, uid): 
    2220         """Reverse the generate_uid function above. 
    2221  
    2222         Also checks that it is one of ours. 
    2223         """ 
    2224         moto, objtype, lastpart = uid.split('-', 2) 
    2225         assert(moto == "moto" and objtype in SUPPORTED_OBJTYPES, 'Invalid UID: %s' % uid) 
    2226         lastpos = lastpart.rindex('@') 
    2227         assert(lastpart[lastpos + 1:] == self.serial[-8:], 'Entry not created on this phone') 
     2215        try: 
     2216            moto, uid_objtype, lastpart = uid.split('-', 2) 
     2217            assert(moto == "moto") 
     2218        except (ValueError, AssertionError): 
     2219            raise opensync.Error("Invalid UID: " + uid) 
     2220 
     2221        if uid_objtype != objtype: 
     2222            raise opensync.Error("UID %s doesn't match objtype %s", uid, objtype) 
    22282223 
    22292224        if objtype == "event": 
    2230             positions = PhoneEventSimple.unpack_uid(lastpart[:lastpos]
     2225            return PhoneEventSimple.unpack_uid(lastpart
    22312226        elif objtype == "contact": 
    2232             positions = PhoneContact.unpack_uid(lastpart[:lastpos]) 
    2233         return objtype, positions 
     2227            return PhoneContact.unpack_uid(lastpart) 
     2228        else: 
     2229            raise opensync.Error("Unsupported objtype: " + uid) 
    22342230 
    22352231 
     
    22482244        """Connect to the phone.""" 
    22492245        self.access.connect() 
     2246        anchorpath = os.path.join(info.configdir, 'anchor.db') 
     2247        if not opensync.anchor_compare(anchorpath, 'serial', self.access.serial): 
     2248            self.sink.slowsync = True 
    22502249 
    22512250    def get_changes(self, info, ctx): 
     
    22712270            raise opensync.Error('unsupported objtype %s' % change.objtype, opensync.ERROR_NOT_SUPPORTED) 
    22722271        if change.changetype == opensync.CHANGE_TYPE_DELETED: 
    2273             success = (self.access.uid_seen(change.uid) and self.access.delete_entry(change.uid)
     2272            success = self.access.delete_entry(change.objtype, change.uid
    22742273        elif change.changetype == opensync.CHANGE_TYPE_MODIFIED: 
    22752274            old_uid = change.uid 
     
    22832282        if success: 
    22842283            self.hashtable.update_hash(change.changetype, change.uid, change.hash) 
     2284 
     2285    def sync_done(self, info, ctx): 
     2286        """Called when a sync completes successfully.""" 
     2287        anchorpath = os.path.join(info.configdir, 'anchor.db') 
     2288        opensync.anchor_update(anchorpath, 'serial', self.access.serial) 
    22852289 
    22862290    def disconnect(self, info, ctx):