From f4a4cf140268db48fa5fb49d10e7149b3fb7c4cf Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 19 Sep 2015 15:36:07 -0700 Subject: clone new connection requests --- include/zot.php | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 4b3e23eea..d01613225 100644 --- a/include/zot.php +++ b/include/zot.php @@ -488,21 +488,17 @@ function zot_refresh($them, $channel = null, $force = false) { if($y) { logger("New introduction received for {$channel['channel_name']}"); $new_perms = get_all_perms($channel['channel_id'],$x['hash']); - if($new_perms != $previous_perms) { - // Send back a permissions update if permissions have changed - $z = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 limit 1", - dbesc($x['hash']), - intval($channel['channel_id']), - intval(ABOOK_FLAG_SELF) - ); - if($z) - proc_run('php','include/notifier.php','permission_update',$z[0]['abook_id']); - } - $new_connection = q("select abook_id, abook_flags from abook where abook_channel = %d and abook_xchan = '%s' order by abook_created desc limit 1", + + // Send a clone sync packet and a permissions update if permissions have changed + $new_connection = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 order by abook_created desc limit 1", + dbesc($x['hash']), intval($channel['channel_id']), - dbesc($x['hash']) + intval(ABOOK_FLAG_SELF) ); + if($new_connection) { + if($new_perms != $previous_perms) + proc_run('php','include/notifier.php','permission_update',$new_connection[0]['abook_id']); require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_INTRO, @@ -510,12 +506,17 @@ function zot_refresh($them, $channel = null, $force = false) { 'to_xchan' => $channel['channel_hash'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'], )); - } + + if($their_perms & PERMS_R_STREAM) { + if(($channel['channel_w_stream'] & PERMS_PENDING) + || (! ($new_connection[0]['abook_flags'] & ABOOK_FLAG_PENDING)) ) + proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']); + } - if($new_connection && ($their_perms & PERMS_R_STREAM)) { - if(($channel['channel_w_stream'] & PERMS_PENDING) - || (! ($new_connection[0]['abook_flags'] & ABOOK_FLAG_PENDING)) ) - proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']); + unset($new_connection[0]['abook_id']); + unset($new_connection[0]['abook_account']); + unset($new_connection[0]['abook_channel']); + build_sync_packet($channel['channel_id'], array('abook' => $new_connection)); } } } @@ -995,7 +996,7 @@ function zot_process_response($hub, $arr, $outq) { ); } - logger('zot_process_response: ' . print_r($x,true), LOGGER_DATA); + logger('zot_process_response: ' . print_r($x,true), LOGGER_DEBUG); } /** -- cgit v1.2.3 From 5d6f59a598fdf700b90d7d14bb5c9087c0968cb9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 19 Sep 2015 22:46:59 -0700 Subject: clone new connections --- include/zot.php | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 6c5a8c289..52ae23ba5 100644 --- a/include/zot.php +++ b/include/zot.php @@ -487,20 +487,16 @@ function zot_refresh($them, $channel = null, $force = false) { if($y) { logger("New introduction received for {$channel['channel_name']}"); $new_perms = get_all_perms($channel['channel_id'],$x['hash']); - if($new_perms != $previous_perms) { - // Send back a permissions update if permissions have changed - $z = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", - dbesc($x['hash']), - intval($channel['channel_id']) - ); - if($z) - proc_run('php','include/notifier.php','permission_update',$z[0]['abook_id']); - } - $new_connection = q("select abook_id, abook_pending from abook where abook_channel = %d and abook_xchan = '%s' order by abook_created desc limit 1", - intval($channel['channel_id']), - dbesc($x['hash']) + + // Send a clone sync packet and a permissions update if permissions have changed + $new_connection = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 order by abook_created desc limit 1", + dbesc($x['hash']), + intval($channel['channel_id']) ); + if($new_connection) { + if($new_perms != $previous_perms) + proc_run('php','include/notifier.php','permission_update',$new_connection[0]['abook_id']); require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_INTRO, @@ -508,12 +504,17 @@ function zot_refresh($them, $channel = null, $force = false) { 'to_xchan' => $channel['channel_hash'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'], )); - } + + if($their_perms & PERMS_R_STREAM) { + if(($channel['channel_w_stream'] & PERMS_PENDING) + || (! intval($new_connection[0]['abook_pending'])) ) + proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']); + } - if($new_connection && ($their_perms & PERMS_R_STREAM)) { - if(($channel['channel_w_stream'] & PERMS_PENDING) - || (! intval($new_connection[0]['abook_pending'])) ) - proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']); + unset($new_connection[0]['abook_id']); + unset($new_connection[0]['abook_account']); + unset($new_connection[0]['abook_channel']); + build_sync_packet($channel['channel_id'], array('abook' => $new_connection)); } } } -- cgit v1.2.3 From 9de8df496a98019d4b4a3e7549e0d5047dd87024 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 20 Sep 2015 16:52:21 -0700 Subject: we need the xchan record also --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index d01613225..57645f631 100644 --- a/include/zot.php +++ b/include/zot.php @@ -490,7 +490,7 @@ function zot_refresh($them, $channel = null, $force = false) { $new_perms = get_all_perms($channel['channel_id'],$x['hash']); // Send a clone sync packet and a permissions update if permissions have changed - $new_connection = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 order by abook_created desc limit 1", + $new_connection = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 order by abook_created desc limit 1", dbesc($x['hash']), intval($channel['channel_id']), intval(ABOOK_FLAG_SELF) -- cgit v1.2.3 From 35f09f4f746fa53fc3c495f71e0f8379c24207fa Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 20 Sep 2015 17:45:23 -0700 Subject: remove system flags from channel import packet --- include/zot.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 57645f631..db53ccfc5 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2925,11 +2925,15 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { } if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) { - if(array_key_exists('channel_removed',$arr['channel'])) - $arr['channel_pageflags'] |= PAGE_REMOVED; - if(array_key_exists('channel_system',$arr['channel'])) - $arr['channel_pageflags'] |= PAGE_SYSTEM; - + + // These flags cannot be sync'd. + // If these bits aren't set locally, remove the bits from the incoming flags. + + if(! ($channel['channel_pageflags'] & PAGE_REMOVED)) + $arr['channel_pageflags'] = $arr['channel_pageflags'] & PAGE_REMOVED; + if(! ($channel['channel_pageflags'] & PAGE_SYSTEM)) + $arr['channel_pageflags'] = $arr['channel_pageflags'] & PAGE_SYSTEM; + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_system'); $clean = array(); -- cgit v1.2.3 From 59a56ac77fcef3348bcf82db043d526b33f5bc9f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 20 Sep 2015 17:47:41 -0700 Subject: catch the timestamp also --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index db53ccfc5..f01789216 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2934,7 +2934,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(! ($channel['channel_pageflags'] & PAGE_SYSTEM)) $arr['channel_pageflags'] = $arr['channel_pageflags'] & PAGE_SYSTEM; - $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_system'); + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_system', 'channel_deleted' ); $clean = array(); foreach($arr['channel'] as $k => $v) { -- cgit v1.2.3 From efcb4abfd0ceb8155626a9d55016a92601a4780c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 20 Sep 2015 18:08:06 -0700 Subject: improve on the last attempt --- include/zot.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index f01789216..e23bad4fe 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2929,10 +2929,10 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { // These flags cannot be sync'd. // If these bits aren't set locally, remove the bits from the incoming flags. - if(! ($channel['channel_pageflags'] & PAGE_REMOVED)) - $arr['channel_pageflags'] = $arr['channel_pageflags'] & PAGE_REMOVED; - if(! ($channel['channel_pageflags'] & PAGE_SYSTEM)) - $arr['channel_pageflags'] = $arr['channel_pageflags'] & PAGE_SYSTEM; + if((! ($channel['channel_pageflags'] & PAGE_REMOVED)) && ($arr['channel_pageflags'] & PAGE_REMOVED)) + $arr['channel_pageflags'] = $arr['channel_pageflags'] - PAGE_REMOVED; + if((! ($channel['channel_pageflags'] & PAGE_SYSTEM)) && ($arr['channel_pageflags'] & PAGE_SYSTEM)) + $arr['channel_pageflags'] = $arr['channel_pageflags'] - PAGE_SYSTEM; $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_system', 'channel_deleted' ); -- cgit v1.2.3 From a679081993945d409cf88b6442610ad5b3dbd8b5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 20 Sep 2015 20:21:54 -0700 Subject: new delivery report format --- include/zot.php | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index e23bad4fe..ddcd6b41f 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1547,6 +1547,7 @@ function allowed_public_recips($msg) { function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $request = false) { $result = array(); + require_once('include/DReport.php'); $result['site'] = z_root(); @@ -1561,16 +1562,22 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ foreach($deliveries as $d) { $local_public = $public; + + $DR = new DReport(z_root(),$sender['hash'],$d['hash'],$arr['mid']); + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($d['hash']) ); if(! $r) { - $result[] = array($d['hash'], 'recipients not found'); + $DR->update('recipient not found'); + $result[] = $DR->get(); continue; } $channel = $r[0]; + $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); + // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. @@ -1609,7 +1616,8 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ if((! perm_is_allowed($channel['channel_id'],$sender['hash'],$perm)) && (! $tag_delivery) && (! $local_public)) { logger("permission denied for delivery to channel {$channel['channel_id']} {$channel['channel_address']}"); - $result[] = array($d['hash'],'permission denied',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('permission denied'); + $result[] = $DR->get(); continue; } @@ -1626,7 +1634,8 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ intval($channel['channel_id']) ); if(! $r) { - $result[] = array($d['hash'],'comment parent not found',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('comment parent not found'); + $result[] = $DR->get(); // We don't seem to have a copy of this conversation or at least the parent // - so request a copy of the entire conversation to date. @@ -1681,7 +1690,8 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ if($last_hop && $last_hop != $sender['hash']) { logger('comment route mismatch: parent route = ' . $r[0]['route'] . ' expected = ' . $current_route, LOGGER_DEBUG); logger('comment route mismatch: parent msg = ' . $r[0]['id'],LOGGER_DEBUG); - $result[] = array($d['hash'],'comment route mismatch',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('comment route mismatch'); + $result[] = $DR->get(); continue; } @@ -1710,12 +1720,14 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $arr['uid'] = $channel['channel_id']; $item_id = delete_imported_item($sender,$arr,$channel['channel_id'],$relay); - $result[] = array($d['hash'],(($item_id) ? 'deleted' : 'delete_failed'),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update(($item_id) ? 'deleted' : 'delete_failed'); + $result[] = $DR->get(); if($relay && $item_id) { logger('process_delivery: invoking relay'); proc_run('php','include/notifier.php','relay',intval($item_id)); - $result[] = array($d['hash'],'relayed',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('relayed'); + $result[] = $DR->get(); } continue; @@ -1730,7 +1742,8 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $item_id = $r[0]['id']; if($r[0]['item_restrict'] & ITEM_DELETED) { // It was deleted locally. - $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('update ignored'); + $result[] = $DR->get(); continue; } // Maybe it has been edited? @@ -1738,17 +1751,21 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $arr['id'] = $r[0]['id']; $arr['uid'] = $channel['channel_id']; if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) { - $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('update ignored'); + $result[] = $DR->get(); } else { update_imported_item($sender,$arr,$channel['channel_id']); - $result[] = array($d['hash'],'updated',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('updated'); + $result[] = $DR->get(); if(! $relay) add_source_route($item_id,$sender['hash']); } } else { - $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('update ignored'); + $result[] = $DR->get(); + // We need this line to ensure wall-to-wall comments are relayed (by falling through to the relay bit), // and at the same time not relay any other relayable posts more than once, because to do so is very wasteful. if(! ($r[0]['item_flags'] & ITEM_ORIGIN)) @@ -1768,7 +1785,8 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $item_id = 0; if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) { - $result[] = array($d['hash'],'post ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update('post ignored'); + $result[] = $DR->get(); } else { $item_result = item_store($arr); @@ -1780,14 +1798,16 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ if(! $relay) add_source_route($item_id,$sender['hash']); } - $result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->update(($item_id) ? 'posted' : 'storage failed: ' . $item_result['message']); + $result[] = $DR->get(); } } if($relay && $item_id) { logger('process_delivery: invoking relay'); proc_run('php','include/notifier.php','relay',intval($item_id)); - $result[] = array($d['hash'],'relayed',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); + $DR->addto_update('relayed'); + $result[] = $DR->get(); } } -- cgit v1.2.3 From 146ff6f70308647b27374a1bba386c156498bd2e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 21 Sep 2015 22:30:28 -0700 Subject: more progress on delivery reports. Store the remote results from zot sites locally. --- include/zot.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 767abae38..f728d8fb9 100644 --- a/include/zot.php +++ b/include/zot.php @@ -957,6 +957,21 @@ function zot_process_response($hub, $arr, $outq) { logger('zot_process_response: headers: ' . print_r($arr['header'],true), LOGGER_DATA); } + if(array_key_exists('delivery_report',$x)) { + foreach($x['delivery_report'] as $xx) { + if(is_array($xx) && array_key_exists('message_id',$xx)) { + q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", + dbesc($xx['message_id']), + dbesc($xx['location']), + dbesc($xx['recipient']), + dbesc($xx['status']), + dbesc(datetime_convert($xx['date'])), + dbesc($xx['sender']) + ); + } + } + } + // update the timestamp for this site q("update site set site_dead = 0, site_update = '%s' where site_url = '%s'", -- cgit v1.2.3 From 0b1b11ea53ee3fd466eb338ac5ce67e62af87413 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 02:32:04 -0700 Subject: heavy lifting for delivery reports --- include/zot.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index f728d8fb9..942998b98 100644 --- a/include/zot.php +++ b/include/zot.php @@ -971,7 +971,11 @@ function zot_process_response($hub, $arr, $outq) { } } } - + + q("delete from dreport where dreport_queue = '%s' limit 1", + dbesc($outq['outq_hash']) + ); + // update the timestamp for this site q("update site set site_dead = 0, site_update = '%s' where site_url = '%s'", @@ -1575,6 +1579,12 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ continue; } + if($d['hash'] === $sender['hash']) { + $DR->update('self delivery ignored'); + $result[] = $DR->get(); + continue; + } + $channel = $r[0]; $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); -- cgit v1.2.3 From 2869ccfe39cbda4974a82c303eeeb4e38966b126 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 04:04:51 -0700 Subject: delivery reports - crude but mostly functional at least for zot deliveries --- include/zot.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 942998b98..fb55da0fa 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1579,15 +1579,16 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ continue; } + $channel = $r[0]; + $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); + + if($d['hash'] === $sender['hash']) { $DR->update('self delivery ignored'); $result[] = $DR->get(); continue; } - $channel = $r[0]; - $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); - // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. -- cgit v1.2.3 From f84151e1fe830dca59ae83de429670dfde76b7d2 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 04:24:54 -0700 Subject: fix foreach warning --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index fb55da0fa..d0f4f5680 100644 --- a/include/zot.php +++ b/include/zot.php @@ -957,7 +957,7 @@ function zot_process_response($hub, $arr, $outq) { logger('zot_process_response: headers: ' . print_r($arr['header'],true), LOGGER_DATA); } - if(array_key_exists('delivery_report',$x)) { + if(array_key_exists('delivery_report',$x) && is_array($x['delivery_report'])) { foreach($x['delivery_report'] as $xx) { if(is_array($xx) && array_key_exists('message_id',$xx)) { q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", -- cgit v1.2.3 From 1c1155513a6206b56e45045f762908767049f86e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 04:28:05 -0700 Subject: add one more test --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index d0f4f5680..adeedd42e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -957,7 +957,7 @@ function zot_process_response($hub, $arr, $outq) { logger('zot_process_response: headers: ' . print_r($arr['header'],true), LOGGER_DATA); } - if(array_key_exists('delivery_report',$x) && is_array($x['delivery_report'])) { + if(is_array($x) && array_key_exists('delivery_report',$x) && is_array($x['delivery_report'])) { foreach($x['delivery_report'] as $xx) { if(is_array($xx) && array_key_exists('message_id',$xx)) { q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", -- cgit v1.2.3 From 7dd61c05dcf169807aed91d305ea235bcaa9035e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 04:39:36 -0700 Subject: allow self delivery until we figure out why clone sync of posted items isn't doing it's thing --- include/zot.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index adeedd42e..4b4be477f 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1583,11 +1583,12 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); - if($d['hash'] === $sender['hash']) { - $DR->update('self delivery ignored'); - $result[] = $DR->get(); - continue; - } +// uncomment this once we find out what's stopping the clone sync of the item from working +// if($d['hash'] === $sender['hash']) { +// $DR->update('self delivery ignored'); +// $result[] = $DR->get(); +// continue; +// } // allow public postings to the sys channel regardless of permissions, but not -- cgit v1.2.3 From c2dcc6880302406de6e1abf90c985975e8a4f13a Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 16:19:08 -0700 Subject: backport item sync --- include/zot.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index ddcd6b41f..a41295aad 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3273,6 +3273,14 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { } } + + if(array_key_exists('item',$arr) && $arr['item']) + sync_items($channel,$arr['item']); + + if(array_key_exists('item_id',$arr) && $arr['item_id']) + sync_items($channel,$arr['item_id']); + + $result[] = array($d['hash'],'channel sync updated',$channel['channel_name'],''); } @@ -3431,3 +3439,80 @@ function zot_process_message_request($data) { return $ret; } + + + +function import_items($channel,$items) { + + if($channel && $items) { + $allow_code = false; + $r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id + where channel_id = %d limit 1", + intval($channel['channel_id']) + ); + if($r) { + if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { + $allow_code = true; + } + } + + foreach($items as $i) { + $item = get_item_elements($i,$allow_code); + if(! $item) + continue; + + $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", + dbesc($item['mid']), + intval($channel['channel_id']) + ); + if($r) { + if($item['edited'] > $r[0]['edited']) { + $item['id'] = $r[0]['id']; + $item['uid'] = $channel['channel_id']; + item_store_update($item); + continue; + } + } + else { + $item['aid'] = $channel['channel_account_id']; + $item['uid'] = $channel['channel_id']; + $item_result = item_store($item); + } + + } + } +} + + +function sync_items($channel,$items) { + import_items($channel,$items); +} + + + +function import_item_ids($channel,$itemids) { + if($channel && $itemids) { + foreach($itemids as $i) { + $r = q("select id from item where mid = '%s' and uid = %d limit 1", + dbesc($i['mid']), + intval($channel['channel_id']) + ); + if(! $r) + continue; + $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1", + dbesc($i['service']), + dbesc($i['sid']), + intval($r[0]['id']), + intval($channel['channel_id']) + ); + if(! $z) { + q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')", + intval($r[0]['id']), + intval($channel['channel_id']), + dbesc($i['sid']), + dbesc($i['service']) + ); + } + } + } +} -- cgit v1.2.3 From 642f460dcad84b8254126f316db4c0225a958958 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 16:43:36 -0700 Subject: report the channel sync --- include/zot.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index a41295aad..eb04e421c 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3281,7 +3281,17 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { sync_items($channel,$arr['item_id']); - $result[] = array($d['hash'],'channel sync updated',$channel['channel_name'],''); + // we should probably do this for all items, but usually we only send one. + + require_once('include/DReport.php'); + + if(array_key_exists('item',$arr) && is_array($arr['item'][0])) + $DR = new DReport(z_root(),$d['hash'],$d['hash'],$arr['item'][0]['message_id'],'channel sync processed'); + else + $DR = new DReport(z_root(),$d['hash'],$d['hash'],'sync packet','channel sync delivered'); + + $result[] = $DR->get(); + } return $result; -- cgit v1.2.3 From 34291d593845c1ec4c2d68dcc4662b020db33f32 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 16:50:08 -0700 Subject: add names to delivery report for sync delivery --- include/zot.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index eb04e421c..0b1aaa989 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3285,8 +3285,10 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { require_once('include/DReport.php'); - if(array_key_exists('item',$arr) && is_array($arr['item'][0])) + if(array_key_exists('item',$arr) && is_array($arr['item'][0])) { $DR = new DReport(z_root(),$d['hash'],$d['hash'],$arr['item'][0]['message_id'],'channel sync processed'); + $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); + } else $DR = new DReport(z_root(),$d['hash'],$d['hash'],'sync packet','channel sync delivered'); -- cgit v1.2.3 From 15feeb7bfe324bbe87e689ee7920a6be20cc204c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 18:40:03 -0700 Subject: inverted logic syncing deleted hublocs --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 0b1aaa989..236b55522 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2363,7 +2363,7 @@ function sync_locations($sender, $arr, $absolute = false) { foreach($xisting as $x) { if(! array_key_exists('updated',$x)) { 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", + $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d), hubloc_updated = '%s' where hubloc_id = %d", intval(HUBLOC_FLAGS_DELETED), dbesc(datetime_convert()), intval($x['hubloc_id']) -- cgit v1.2.3 From d16ac62a511ed32e7bcd50ee25148c0771b5e765 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 19:13:10 -0700 Subject: don't send sync packets to deleted hubloc locations --- include/zot.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 236b55522..aae429709 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2802,8 +2802,10 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $channel = $r[0]; - $h = q("select * from hubloc where hubloc_hash = '%s'", - dbesc($channel['channel_hash']) + $h = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", + dbesc($channel['channel_hash']), + intval(HUBLOC_FLAGS_DELETED), + intval(HUBLOC_OFFLINE) ); if(! $h) -- cgit v1.2.3 From d35c5bcb2f425bf498eae53c5ac268a96c808cb9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Sep 2015 19:16:13 -0700 Subject: merge issue --- include/zot.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 86e9da5f3..288493b07 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2816,10 +2816,8 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $channel = $r[0]; - $h = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", - dbesc($channel['channel_hash']), - intval(HUBLOC_FLAGS_DELETED), - intval(HUBLOC_OFFLINE) + $h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", + dbesc($channel['channel_hash']) ); if(! $h) -- cgit v1.2.3