Esempio n. 1
0
 function findParent(Node $node, $type = null)
 {
     if ($node->getType() == $type) {
         return $node;
     } else {
         findParent($node->getParent(), $type);
     }
 }
Esempio n. 2
0
 function &findParent(&$root, $search_id)
 {
     foreach ($root['children'] as &$page) {
         if ($page['id'] == $search_id) {
             return $page;
         }
         if (sizeof($page['children']) > 0) {
             $parent =& findParent($page, $search_id);
             if ($parent) {
                 return $parent;
             }
         }
     }
     return false;
 }
Esempio n. 3
0
    // It exists - stop there.
    error('commodity/exists');
}
// Does the future issuer exist?
$exists = $dz->get_row('select ID from `Root.Entities` where Endpoint="' . $issuer . '"');
if (!$exists) {
    // Didn't find the entity that wants to issue it.
    error('entity/notfound');
}
// Update issuer with the (local) ID:
$issuerID = $exists['ID'];
// $verifiedEntity must match the parent commodity.
// Find the parent commodity and then check to see if its issuer signed the request.
// For example, if we're requesting 'currency.usd', then the issuer of 'currency'
// must have been the one signing this request.
$parentIssuer = findParent($tag);
if (!$parentIssuer) {
    // No suitable parent commodity was not found.
    error('commodity/notfound');
}
// Was that parent issuer the same one who signed this request?
if ($verifiedEntity != $parentIssuer['ID']) {
    // Nope! Only the parent can sign the request.
    error('entity/notparent');
}
// Create the commodity now:
$dz->query('insert into `Root.Commodities` (`Tag`,`Description_en`,`Name_en`,`Divisor`,`Issuer`,`Policy`) values ("' . $tag . '","' . $description_en . '","' . $name_en . '",' . $divisor . ',' . $issuerID . ',' . $policy . ')');
changed('com', array('tag' => $tag, 'description' => array('en' => $description_en), 'name' => array('en' => $name_en), 'divisor' => $divisor, 'issuer' => $issuer, 'policy' => $policy));
// Is this already forwarded? If so, stop there.
if ($forwardedFromRoot != 0) {
    // Some other root forwarded the request here. Just quit:
Esempio n. 4
0
<?php

// Full commodity information. This API is specific to particular issuers.
// Get the commodity:
$tag = safe('tag', VALID_DOMAIN, $_GET);
// Is this tag something we issue?
$parent = findParent($tag);
if ($parent['ID'] != $thisEntity['ID']) {
    // I'm not the issuer of that!
    error('entity/notissuer');
}
// Get the row, if it exists:
$row = $dz->get_row('select * from `Issuer.Commodities` where `Tag`="' . $tag . '"');
$content = null;
if ($row) {
    // Extra content is potentially available.
    $content = $row['Content'];
}
if (!$content) {
    // No extra content available.
    $content = 'null';
}
// Instead of 'content', you may instead respond with 'api' and a URL, like so:
// {"tag":"land.earth.wwks.57834","api":"https://land.gov.uk/api/warwickshire/57834"}
echo '{"tag":"' . $tag . '","content":' . $content . '}';
Esempio n. 5
0
<?php

// Creates a sub-commodity. Used by the commodity/create UI.
// Note that the UI could request the issuer directly, but CORS (in web browsers) may cause problems.
// Receives JSON:
postedTo();
// Quick verify of the request; we're just forwarding it on to the issuer.
if (!$verifiedEntity) {
    // Requires an entity.
    error('entity/required');
}
// Get the tag they want to register:
$tag = safe('tag', VALID_DOMAIN);
// Get the parent issuer for that tag:
$targetIssuer = findParent($tag);
if (!$targetIssuer) {
    // Not found.
    error('entity/notfound');
}
// Get the issuers endpoint:
$row = $dz->get_row('select Endpoint from `Root.Entities` where ID=' . $targetIssuer['ID']);
if (!$row) {
    // server error; the server has an out-of-date entity/coms table:
    serverError();
}
// Send it to the issuer now:
$payload = file_get_contents('php://input');
$error;
// Post it off:
$response = post('https://' . $row['Endpoint'] . '/v1/commodity/request', $payload, $error);
if ($error) {