$algfound = false; $hashval = ""; $ni_err = false; $ni_errno = 0; if (getAlg($urival, $algfound, $hstr, $hashval) === false) { $ni_err = true; $ni_errno = 490; $ni_errstr = "Bummer: {$ni_errno} I don't have {$urival} \nBad algorithm, no good alg found."; retErr($ni_errno, $ni_errstr); exit(1); } if (!$algfound) { $ni_err = true; $ni_errno = 491; $ni_errstr = "Bummer: {$ni_errno} I don't have {$urival} \nBad algorithm, no good alg found."; retErr($ni_errno, $ni_errstr); exit(1); } // TODO: see if we have that file elsewhere (netinffs) // Check if we have NDO metadata $jfilename = checkMeta($hstr, $hashval); if ($jfilename) { // we have meta data! // $filename = $GLOBALS["cfg_wkd"] . "/" . $hstr . "/" . $hashval ; $filename = getNDOfname($hstr, $hashval); if (file_exists($filename)) { sendMIMEWithFile($jfilename, $filename, $msgidval); } else { sendMIMEJSONOnly($jfilename, $msgidval); } exit(0);
function storeMeta($hstr, $hashval, $urival, $loc1, $loc2, $extrameta) { // make locators a good JSON array $locstr = ""; if ($loc1 == "" && $loc2 == "") { $locstr = "[] "; } else { if ($loc1 == "") { $locstr = "[ \"{$loc2}\" ] "; } else { if ($loc2 == "") { $locstr = "[ \"{$loc1}\" ] "; } else { $locstr = "[ \"{$loc1}\" , \"{$loc2}\" ] "; } } } $timestamp = date(DATE_ATOM); if ($extrameta != "") { $jsonev = "{ \"ts\" : \"{$timestamp}\", \"loc\" : {$locstr}, \"metadata\" : {$extrameta} }"; } else { $jsonev = "{ \"ts\" : \"{$timestamp}\", \"loc\" : {$locstr} }"; } $metadir = getMetaDir(); $jfilename = "{$metadir}/{$hstr};{$hashval}"; // print "time: $timestamp\nEV: $jsonev\nFile: $jfilename\n"; if (file_exists($jfilename)) { $fh = fopen($jfilename, "a"); if (!$fh) { $ni_err = true; $ni_errno = 493; $ni_errstr = "Bummer: {$ni_errno} I don't have {$urival} \nBad algorithm, no good alg found."; retErr($ni_errno, $ni_errstr); } fwrite($fh, ",\n"); fwrite($fh, $jsonev); fwrite($fh, "\n"); fclose($fh); } else { $jsonhead = "{ \"NetInf\" : \"v0.1a Stephen\"\n,\"ni\" : \"{$urival}\",\n\"details\" : [\n"; $fh = fopen($jfilename, "w"); if (!$fh) { $ni_err = true; $ni_errno = 493; $ni_errstr = "Bummer: {$ni_errno} I don't have {$urival} \nBad algorithm, no good alg found."; retErr($ni_errno, $ni_errstr); } fwrite($fh, $jsonhead); fwrite($fh, "\n"); fwrite($fh, $jsonev); fwrite($fh, "\n"); fclose($fh); } }