Commit d804e0f2 authored by Zot's avatar Zot

more work on httpsig and create a dedicated queue driver for pubcrawl as it...

more work on httpsig and create a dedicated queue driver for pubcrawl as it will eventually need to sign packets and edit headers on send
parent 9da9e5c7
......@@ -69,6 +69,23 @@ class HTTPSig {
}
static function parse_sigheader($header) {
$ret = [];
$matches = [];
if(preg_match('keyId="(.*?)"/ism',$header,$matches))
$ret['keyId'] = $matches[1];
if(preg_match('algorithm="(.*?)"/ism',$header,$matches))
$ret['algorithm'] = $matches[1];
if(preg_match('headers="(.*?)"/ism',$header,$matches))
$ret['headers'] = explode(' ', $matches[1]);
if(! $ret['headers'])
$ret['headers'] = [ 'date' ];
if(preg_match('signature="(.*?)"/ism',$header,$matches))
$ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1]));
return $ret;
}
}
......
......@@ -27,7 +27,7 @@ function pubcrawl_load() {
'follow_allow' => 'pubcrawl_follow_allow',
'discover_channel_webfinger' => 'pubcrawl_discover_channel_webfinger',
'permissions_create' => 'pubcrawl_permissions_create',
'queue_deliver' => 'pubcrawl_queue_deliver'
]);
}
......@@ -335,7 +335,7 @@ function pubcrawl_permissions_create(&$b) {
'hash' => $hash,
'account_id' => $b['sender']['channel_account_id'],
'channel_id' => $b['sender']['channel_id'],
'driver' => 'post',
'driver' => 'pubcrawl',
'posturl' => $h[0]['hubloc_callback'],
'msg' => $x
]);
......@@ -344,3 +344,55 @@ function pubcrawl_permissions_create(&$b) {
$b['success'] = 1;
}
function pubcrawl_queue_deliver(&$b) {
$outq = $b['outq'];
$base = $b['base'];
$immediate = $b['immediate'];
if($outq['outq_driver'] === 'pubcrawl') {
$b['handled'] = true;
$retries = 0;
$result = z_post_url($outq['outq_posturl'],$outq['outq_msg'],$retries,[ 'headers' => [ 'Content-type: ' . 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ]] );
if($result['success'] && $result['return_code'] < 300) {
logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
if($base) {
q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
dbesc(datetime_convert()),
dbesc($base)
);
}
q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc('accepted for delivery'),
dbesc(datetime_convert()),
dbesc($outq['outq_hash'])
);
remove_queue_item($outq['outq_hash']);
// server is responding - see if anything else is going to this destination and is piled up
// and try to send some more. We're relying on the fact that do_delivery() results in an
// immediate delivery otherwise we could get into a queue loop.
if(! $immediate) {
$x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
dbesc($outq['outq_posturl'])
);
$piled_up = array();
if($x) {
foreach($x as $xx) {
$piled_up[] = $xx['outq_hash'];
}
}
if($piled_up) {
do_delivery($piled_up);
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment