diff options
Diffstat (limited to 'include/zot.php')
-rw-r--r-- | include/zot.php | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/include/zot.php b/include/zot.php index f6732037a..b7ffe14e4 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1844,8 +1844,10 @@ function sync_locations($sender,$arr,$absolute = false) { if($absolute && $xisting) { foreach($xisting as $x) { if(! array_key_exists('updated',$x)) { - logger('sync_locations: removing unreferenced hub location ' . $x['hubloc_url']); - $r = q("delete from hubloc where hubloc_id = %d limit 1", + logger('sync_locations: deleting unreferenced hub location ' . $x['hubloc_url']); + $r = q("update hubloc set hubloc_flags = (hubloc_flags ^ %d), hubloc_updated = '%s' where hubloc_id = %d limit 1", + intval(HUBLOC_FLAGS_DELETED), + dbesc(datetime_convert()), intval($x['hubloc_id']) ); $what .= 'removed_hub'; @@ -2336,7 +2338,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { function process_channel_sync_delivery($sender,$arr,$deliveries) { // FIXME - this will sync red structures (channel, pconfig and abook). Eventually we need to make this application agnostic. -// TODO: missing group membership changes + $result = array(); @@ -2352,6 +2354,10 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { $channel = $r[0]; + $max_friends = service_class_fetch($channel['channel_id'],'total_channels'); + $max_feeds = account_service_class_fetch($channel['channel_account_id'],'total_feeds'); + + if($channel['channel_hash'] != $sender['hash']) { logger('process_channel_sync_delivery: possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_hash']); $result[] = array($d['hash'],'channel mismatch',$channel['channel_name'],''); @@ -2385,6 +2391,19 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { if(array_key_exists('abook',$arr) && is_array($arr['abook']) && count($arr['abook'])) { + $total_friends = 0; + $total_feeds = 0; + + $r = q("select abook_id, abook_flags from abook where abook_channel = %d", + intval($channel['channel_id']) + ); + if($r) { + // don't count yourself + $total_friends = ((count($r) > 0) ? $count($r) - 1 : 0); + foreach($r as $rr) + if($rr['abook_flags'] & ABOOK_FLAG_FEED) + $total_feeds ++; + } $disallowed = array('abook_id','abook_account','abook_channel'); @@ -2395,14 +2414,18 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { logger('process_channel_sync_delivery: removing abook entry for ' . $abook['abook_xchan']); require_once('include/Contact.php'); - $r = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d and not ( abook_flags & %d ) limit 1", + $r = q("select abook_id, abook_flags from abook where abook_xchan = '%s' and abook_channel = %d and not ( abook_flags & %d ) limit 1", dbesc($abook['abook_xchan']), intval($channel['channel_id']), intval(ABOOK_FLAG_SELF) ); - if($r) + if($r) { contact_remove($channel['channel_id'],$r[0]['abook_id']); - + if($total_friends) + $total_friends --; + if($r[0]['abook_flags'] & ABOOK_FLAG_FEED) + $total_feeds --; + } continue; } @@ -2449,10 +2472,21 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { // make sure we have an abook entry for this xchan on this system if(! $r) { + if($max_friends !== false && $total_friends > $max_friends) { + logger('process_channel_sync_delivery: total_channels service class limit exceeded'); + continue; + } + if($max_feeds !== false && ($clean['abook_flags'] & ABOOK_FLAG_FEED) && $total_feeds > $max_feeds) { + logger('process_channel_sync_delivery: total_feeds service class limit exceeded'); + continue; + } q("insert into abook ( abook_xchan, abook_channel ) values ('%s', %d ) ", dbesc($clean['abook_xchan']), intval($channel['channel_id']) ); + $total_friends ++; + if($clean['abook_flags'] & ABOOK_FLAG_FEED) + $total_feeds ++; } if(count($clean)) { |