aboutsummaryrefslogtreecommitdiffstats
path: root/include/zot.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/zot.php')
-rw-r--r--include/zot.php150
1 files changed, 114 insertions, 36 deletions
diff --git a/include/zot.php b/include/zot.php
index 6c5a8c289..288493b07 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -487,20 +487,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 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 left join xchan on abook_xchan = xchan_hash 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 +505,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));
}
}
}
@@ -955,6 +957,25 @@ function zot_process_response($hub, $arr, $outq) {
logger('zot_process_response: headers: ' . print_r($arr['header'],true), LOGGER_DATA);
}
+ 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' ) ",
+ dbesc($xx['message_id']),
+ dbesc($xx['location']),
+ dbesc($xx['recipient']),
+ dbesc($xx['status']),
+ dbesc(datetime_convert($xx['date'])),
+ dbesc($xx['sender'])
+ );
+ }
+ }
+ }
+
+ 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'",
@@ -1530,6 +1551,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();
@@ -1544,16 +1566,30 @@ 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() . '>');
+
+
+// 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
// for comments travelling upstream. Wait and catch them on the way down.
@@ -1589,7 +1625,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;
}
@@ -1606,7 +1643,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.
@@ -1661,7 +1699,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;
}
@@ -1690,12 +1729,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;
@@ -1711,7 +1752,9 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
if(intval($r[0]['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?
@@ -1719,17 +1762,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,$r[0],$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.
@@ -1750,7 +1797,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);
@@ -1762,14 +1810,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();
}
}
@@ -2766,7 +2816,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
$channel = $r[0];
- $h = q("select * from hubloc where hubloc_hash = '%s'",
+ $h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($channel['channel_hash'])
);
@@ -2938,12 +2988,19 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
sync_menus($channel,$arr['menu']);
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
- if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
- $arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0);
- $arr['channel']['channel_system'] = (($arr['channel']['channel_pageflags'] & 0x1000) ? 1 : 0);
+
+ if(array_key_exists('channel_pageflags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
+ // These flags cannot be sync'd.
+ // remove the bits from the incoming flags.
+
+ if($arr['channel_pageflags'] & 0x8000)
+ $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x8000;
+ if($arr['channel_pageflags'] & 0x1000)
+ $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x1000;
+
}
- $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags');
+ $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_deleted', 'channel_system');
$clean = array();
foreach($arr['channel'] as $k => $v) {
@@ -3255,7 +3312,27 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
}
}
- $result[] = array($d['hash'],'channel sync updated',$channel['channel_name'],'');
+
+ 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']);
+
+
+ // 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');
+ $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');
+
+ $result[] = $DR->get();
+
}
return $result;
@@ -3697,4 +3774,5 @@ function zotinfo($arr) {
}
call_hooks('zot_finger',$ret);
return($ret);
+
}