From 952b2ef2ab256d46d616db70edc42ffe640a5e9d Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 10 Mar 2013 18:45:58 -0700 Subject: . --- include/zot.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 1cf34170e..e5b6ac56a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -503,7 +503,15 @@ function import_xchan($arr) { ); } + // what we are missing for true hub independence is for any changes in the primary hub to + // get reflected not only in the hublocs, but also to update the URLs and addr in the appropriate xchan + if($arr['locations']) { + + $xisting = q("select hubloc_id, hubloc_url from hubloc where hubloc_hash = '%s'", + dbesc($xchan_hash) + ); + foreach($arr['locations'] as $location) { if(! rsa_verify($location['url'],base64url_decode($location['url_sig']),$arr['key'])) { logger('import_xchan: Unable to verify site signature for ' . $location['url']); @@ -511,12 +519,19 @@ function import_xchan($arr) { continue; } + for($x = 0; $x < count($xisting); $x ++) { + if($xisiting[$x]['hubloc_url'] == $location['url']) { + $xisting[$x]['updated'] = true; + } + } + $r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' limit 1", dbesc($xchan_hash), dbesc($location['url']) ); if($r) { - if(($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary'])) { + if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary'])) + || ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)) && ($location['primary']))) { $r = q("update hubloc set hubloc_flags = (hubloc_flags ^ %d) where hubloc_id = %d limit 1", intval(HUBLOC_FLAGS_PRIMARY), intval($r[0]['hubloc_id']) @@ -525,6 +540,16 @@ function import_xchan($arr) { continue; } + // new hub claiming to be primary. Make it so. + + if(intval($location['primary'])) { + $r = q("update hubloc set hubloc_flags = (hubloc_flags ^ %d) where hubloc_hash = '%s' and (hubloc_flags & %d )", + intval(HUBLOC_FLAGS_PRIMARY), + dbesc($xchan_hash), + intval(HUBLOC_FLAGS_PRIMARY) + ); + } + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey) values ( '%s','%s','%s','%s', %d ,'%s','%s','%s','%s','%s')", dbesc($arr['guid']), @@ -541,6 +566,18 @@ function import_xchan($arr) { } + // get rid of any hubs we have for this channel which weren't reported. + + if($xisting) { + foreach($xisting as $x) { + if(! array_key_exists('updated',$x)) { + $r = q("delete from hubloc where hubloc_id = %d limit 1", + intval($x['hubloc_id']) + ); + } + } + } + } if(! x($ret,'message')) { -- cgit v1.2.3