From ee3eee425c92b37fba5a7035d8e9ec0b0b563d0b Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 Jan 2015 16:13:18 -0800 Subject: that should take care of the bitfields in hubloc --- include/Contact.php | 10 ++++---- include/fixd.php | 33 --------------------------- include/hubloc.php | 2 +- include/identity.php | 4 ++-- include/network.php | 5 ++-- include/notifier.php | 2 +- include/onedirsync.php | 2 +- include/text.php | 6 ++--- include/zot.php | 62 ++++++++++++++++++++++---------------------------- mod/import.php | 12 ++++------ mod/locs.php | 13 ++++------- 11 files changed, 51 insertions(+), 100 deletions(-) delete mode 100644 include/fixd.php diff --git a/include/Contact.php b/include/Contact.php index 4a016e32f..c872dc913 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -22,9 +22,8 @@ function rconnect_url($channel_id,$xchan) { if(($r) && ($r[0]['xchan_follow'])) return $r[0]['xchan_follow']; - $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d )>0 limit 1", - dbesc($xchan), - intval(HUBLOC_FLAGS_PRIMARY) + $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 limit 1", + dbesc($xchan) ); if($r) @@ -389,8 +388,7 @@ function mark_orphan_hubsxchans() { // } - $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0", - ); + $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0"); if($r) { foreach($r as $rr) { @@ -398,7 +396,7 @@ function mark_orphan_hubsxchans() { // see if any other hublocs are still alive for this channel $x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0", - dbesc($rr['hubloc_hash']), + dbesc($rr['hubloc_hash']) ); if($x) { diff --git a/include/fixd.php b/include/fixd.php deleted file mode 100644 index bce5eb348..000000000 --- a/include/fixd.php +++ /dev/null @@ -1,33 +0,0 @@ -get_hostname()), - intval(($primary) ? HUBLOC_FLAGS_PRIMARY : 0), + intval($primary), dbesc(z_root()), dbesc(base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey']))), dbesc(get_app()->get_hostname()), diff --git a/include/network.php b/include/network.php index 170b77d7d..8082d0217 100644 --- a/include/network.php +++ b/include/network.php @@ -1113,7 +1113,7 @@ function discover_by_webbie($webbie) { if(! $r) { - $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_flags ) values ('%s','%s','%s','%s','%s','%s','%s','%s', %d)", + $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_primary ) values ('%s','%s','%s','%s','%s','%s','%s','%s', 1)", dbesc($guid), dbesc($addr), dbesc($addr), @@ -1121,8 +1121,7 @@ function discover_by_webbie($webbie) { dbesc(trim($diaspora_base,'/')), dbesc($hostname), dbesc($notify), - dbescdate(datetime_convert()), - intval(HUBLOC_FLAGS_PRIMARY) + dbescdate(datetime_convert()) ); } $photos = import_profile_photo($vcard['photo'],$addr); diff --git a/include/notifier.php b/include/notifier.php index 0bdc71261..29646fb38 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -493,7 +493,7 @@ function notifier_run($argv, $argc){ // aren't the owner or author. - $r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select * from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") order by hubloc_connected desc limit 1"); } else { diff --git a/include/onedirsync.php b/include/onedirsync.php index c94a1410f..e611492af 100644 --- a/include/onedirsync.php +++ b/include/onedirsync.php @@ -55,7 +55,7 @@ function onedirsync_run($argv, $argc){ $h = q("select * from hubloc where hubloc_addr = '%s' limit 1", dbesc($r[0]['ud_addr']) ); - if(($h) && (intval($h[0]['hubloc_error']))) + if(($h) && (intval($h[0]['hubloc_error']))) { $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), diff --git a/include/text.php b/include/text.php index b6e4abf24..fcd7b422c 100644 --- a/include/text.php +++ b/include/text.php @@ -1890,13 +1890,13 @@ function xchan_query(&$items,$abook = true,$effective_uid = 0) { if(count($arr)) { if($abook) { $chans = q("select * from xchan left join hubloc on hubloc_hash = xchan_hash left join abook on abook_xchan = xchan_hash and abook_channel = %d - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0", + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1", intval($item['uid']) ); } else { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0"); + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1"); } $xchans = q("select * from xchan where xchan_hash in (" . implode(',',$arr) . ") and xchan_network in ('rss','unknown')"); if(! $chans) @@ -1924,7 +1924,7 @@ function xchan_mail_query(&$item) { if(count($arr)) { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0"); + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1"); } if($chans) { $item['from'] = find_xchan_in_array($item['from_xchan'],$chans); diff --git a/include/zot.php b/include/zot.php index ac5127f1c..debd2c8a8 100644 --- a/include/zot.php +++ b/include/zot.php @@ -201,9 +201,8 @@ function zot_finger($webbie,$channel,$autofallback = true) { $r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where xchan_addr = '%s' and (hubloc_flags & %d) > 0 limit 1", - dbesc($xchan_addr), - intval(HUBLOC_FLAGS_PRIMARY) + where xchan_addr = '%s' and hubloc_primary = 1 limit 1", + dbesc($xchan_addr) ); if($r) { @@ -300,9 +299,8 @@ function zot_refresh($them,$channel = null, $force = false) { if($them['hubloc_url']) $url = $them['hubloc_url']; else { - $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d ) > 0 limit 1", - dbesc($them['xchan_hash']), - intval(HUBLOC_FLAGS_PRIMARY) + $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 limit 1", + dbesc($them['xchan_hash']) ); if($r) $url = $r[0]['hubloc_url']; @@ -1887,9 +1885,8 @@ function sync_locations($sender,$arr,$absolute = false) { q("update hubloc set hubloc_error = 0 where hubloc_id = %d", intval($r[0]['hubloc_id']) ); - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { - q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_ORPHANCHECK), + if(intval($r[0]['hubloc_orphancheck'])) { + q("update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d", intval($r[0]['hubloc_id']) ); } @@ -1911,15 +1908,15 @@ function sync_locations($sender,$arr,$absolute = false) { } } - if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary'])) - || ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)) && ($location['primary']))) { - $m = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", - intval(HUBLOC_FLAGS_PRIMARY), + if((intval($r[0]['hubloc_primary']) && (! $location['primary'])) + || ((! intval($r[0]['hubloc_primary'])) && ($location['primary']))) { + $m = q("update hubloc set hubloc_primary = %d, hubloc_updated = '%s' where hubloc_id = %d", + intval($location['primary']), dbesc(datetime_convert()), intval($r[0]['hubloc_id']) ); // make sure hubloc_change_primary() has current data - $r[0]['hubloc_flags'] = $r[0]['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY; + $r[0]['hubloc_primary'] = intval($location['primary']); hubloc_change_primary($r[0]); $what .= 'primary_hub '; $changed = true; @@ -1949,22 +1946,20 @@ function sync_locations($sender,$arr,$absolute = false) { // New hub claiming to be primary. Make it so by removing any existing primaries. if(intval($location['primary'])) { - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_hash = '%s' and (hubloc_flags & %d )>0", - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1", dbesc(datetime_convert()), - dbesc($sender['hash']), - intval(HUBLOC_FLAGS_PRIMARY) + dbesc($sender['hash']) ); } logger('sync_locations: new hub: ' . $location['url']); - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) values ( '%s','%s','%s','%s', '%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", dbesc($sender['guid']), dbesc($sender['guid_sig']), dbesc($sender['hash']), dbesc($location['address']), dbesc('zot'), - intval((intval($location['primary'])) ? HUBLOC_FLAGS_PRIMARY : 0), + intval($location['primary']), dbesc($location['url']), dbesc($location['url_sig']), dbesc($location['host']), @@ -2017,18 +2012,16 @@ function zot_encode_locations($channel) { $x = zot_get_hublocs($channel['channel_hash']); if($x && count($x)) { foreach($x as $hub) { - if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) { - $ret[] = array( - 'host' => $hub['hubloc_host'], - 'address' => $hub['hubloc_addr'], - 'primary' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false), - 'url' => $hub['hubloc_url'], - 'url_sig' => $hub['hubloc_url_sig'], - 'callback' => $hub['hubloc_callback'], - 'sitekey' => $hub['hubloc_sitekey'], - 'deleted' => (intval($hub['hubloc_deleted']) ? true : false) - ); - } + $ret[] = array( + 'host' => $hub['hubloc_host'], + 'address' => $hub['hubloc_addr'], + 'primary' => (intval($hub['hubloc_primary']) ? true : false), + 'url' => $hub['hubloc_url'], + 'url_sig' => $hub['hubloc_url_sig'], + 'callback' => $hub['hubloc_callback'], + 'sitekey' => $hub['hubloc_sitekey'], + 'deleted' => (intval($hub['hubloc_deleted']) ? true : false) + ); } } return $ret; @@ -2843,10 +2836,9 @@ function get_rpost_path($observer) { function import_author_zot($x) { $hash = make_xchan_hash($x['guid'],$x['guid_sig']); - $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and (hubloc_flags & %d)>0 limit 1", + $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), - dbesc($x['guid_sig']), - intval(HUBLOC_FLAGS_PRIMARY) + dbesc($x['guid_sig']) ); if($r) { diff --git a/mod/import.php b/mod/import.php index c9a4edb67..bd95311df 100644 --- a/mod/import.php +++ b/mod/import.php @@ -200,8 +200,8 @@ function import_post(&$a) { 'url' => $hubloc['hubloc_url'], 'url_sig' => $hubloc['hubloc_url_sig'] ); - if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && ($hubloc['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && ($seize)) - $hubloc['hubloc_flags'] = ($hubloc['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY); + if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) + $hubloc['hubloc_primary'] = 0; if(! zot_gethub($arr)) { unset($hubloc['hubloc_id']); @@ -220,7 +220,7 @@ function import_post(&$a) { // create new hubloc for the new channel at this site - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey ) values ( '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s' )", dbesc($channel['channel_guid']), @@ -228,7 +228,7 @@ function import_post(&$a) { dbesc($channel['channel_hash']), dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), dbesc('zot'), - intval(($seize) ? HUBLOC_FLAGS_PRIMARY : 0), + intval(($seize) ? 1 : 0), dbesc(z_root()), dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), dbesc(get_app()->get_hostname()), @@ -239,9 +239,7 @@ function import_post(&$a) { // reset the original primary hubloc if it is being seized if($seize) - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' and hubloc_url != '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ", dbesc($channel['channel_hash']), dbesc(z_root()) ); diff --git a/mod/locs.php b/mod/locs.php index 352112e3a..deb784100 100644 --- a/mod/locs.php +++ b/mod/locs.php @@ -19,13 +19,10 @@ function locs_post(&$a) { notice( t('Location not found.') . EOL); return; } - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' ", dbesc($channel['channel_hash']) ); - $r = q("update hubloc set hubloc_flags = (hubloc_flags & %d) where hubloc_id = %d and hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 1 where hubloc_id = %d and hubloc_hash = '%s'", intval($hubloc_id), dbesc($channel['channel_hash']) ); @@ -37,7 +34,7 @@ function locs_post(&$a) { if($_REQUEST['drop']) { $hubloc_id = intval($_REQUEST['drop']); if($hubloc_id) { - $r = q("select hubloc_id, hubloc_flags from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", + $r = q("select * from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", intval($hubloc_id), dbesc(z_root()), dbesc($channel['channel_hash']) @@ -46,7 +43,7 @@ function locs_post(&$a) { notice( t('Location not found.') . EOL); return; } - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) { + if(intval($r[0]['hubloc_primary'])) { notice( t('Primary location cannot be removed.') . EOL); return; } @@ -83,7 +80,7 @@ function locs_content(&$a) { for($x = 0; $x < count($r); $x ++) { - $r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false); + $r[$x]['primary'] = (intval($r[$x]['hubloc_primary']) ? true : false); $r[$x]['deleted'] = (intval($r[$x]['hubloc_deleted']) ? true : false); } -- cgit v1.2.3