function CoalIntakeHandler()
{
    global $l;
    $l = new llog();
    $l->a("Started CoalIntakeHandler<br>");
    global $generalAuthKey;
    if (authorized($generalAuthKey)) {
        global $coalVersion;
        $coalVersion = 5;
        global $coalCompressionType;
        $coalCompressionType = 'bz2';
        $insertion = insertCoal();
        //echo 'INSERTION: '. print_r($insertion,true);
        $id = $insertion['id'];
        $status = $insertion['status'];
        if (check($status, true)) {
            if (isset($_REQUEST['outputwebloc'])) {
                $filename = base64_decode($insertion['filename']);
                $smallified = "[InternetShortcut]\nURL=http://futuramerlin.com/d/r/active.php?coalId=" . $id . "&authorizationKey=" . urlencode($generalAuthKey) . "&handler=1&coalVerbose=1&handlerNeeded=CoalRetrieve\nIconIndex=0";
                start_file_download($filename, strlen($smallified));
                echo $smallified;
            } else {
                if (check($status, true)) {
                    if (isset($_REQUEST['coalVerbose'])) {
                        echo 'Added coal: ';
                    }
                    $csum = Csum_import($insertion['csum']);
                    //echo 'CSUM: '.print_r($csum,true);
                    echo $id . '|' . $csum->len . '|' . $csum->md5 . '|' . $csum->sha . '|' . $csum->s512;
                    if (isset($_REQUEST['coalVerbose'])) {
                        echo '; used ' . memory_get_peak_usage() . ' bytes of memory at peak; currently using ' . memory_get_usage() . ' bytes of memory.<br><h1>Log output:</h1><br><small>';
                        $l->e();
                    }
                }
            }
        }
    }
}
function store($data, $csumb)
{
    $csum = new Csum($data);
    if (!$csum->matches($csumb)) {
        return null;
    }
    $status = 0;
    //Why I'm not doing this type of deduplication: It could lead to inaccurate metadata about the coal.
    //Ya know, screw that. Coal *shouldn't support* file uploads — that should be handled by higher level software. I'm putting this back in for now, and just remember that the Coal file-level metadata is only an ugly, non-archival-quality, incomplete hack for while Ember doesn't exist yet to take care of that.
    $db = new FractureDB('futuqiur_ember');
    $potentialDuplicates = $db->getColumnsUH('strings', 'id', 'md5', $csum->md5);
    foreach ($potentialDuplicates as $potential) {
        //echo 'duplicate testing';
        $potentialRecord = retrieveCoal($potential['id']);
        if (!is_null($potentialRecord)) {
            $potentialData = $potentialRecord['data'];
            $potentialCsum = Csum_import($potentialRecord['csum']);
            if ($potentialData === $data && matches($csum, $potentialCsum)) {
                $duplicateId = $potential['id'];
                return array('id' => $duplicateId, 'csum' => $potentialRecord['csum'], 'status' => $status);
            }
        }
    }
    $db->close();
    //echo 'gotten here';
    $filename = 'coal_temp/' . uniqid() . '.cstf';
    file_put_contents($filename, $data);
    return insertCoal($filename, $csum);
}