aboutsummaryrefslogtreecommitdiffstats
path: root/include/zot.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-03-10 18:45:58 -0700
committerfriendica <info@friendica.com>2013-03-10 18:45:58 -0700
commit952b2ef2ab256d46d616db70edc42ffe640a5e9d (patch)
tree1bd9cb83a6beae2beb5ff30b1b26d604e7ccfc06 /include/zot.php
parent0d504715c1859276e919ddc6b236f946c783714f (diff)
downloadvolse-hubzilla-952b2ef2ab256d46d616db70edc42ffe640a5e9d.tar.gz
volse-hubzilla-952b2ef2ab256d46d616db70edc42ffe640a5e9d.tar.bz2
volse-hubzilla-952b2ef2ab256d46d616db70edc42ffe640a5e9d.zip
.
Diffstat (limited to 'include/zot.php')
-rw-r--r--include/zot.php39
1 files changed, 38 insertions, 1 deletions
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')) {