Changeset - 89e9a3a9940c
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-10-10 19:43:19

Moved updating code to BlendNet
1 file changed with 0 insertions and 50 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -19,146 +19,96 @@
 

	
 
 /*
 
  * Registration on server. Needs attention. Prevent account spamming.
 
  * distrenslave -c username email@example.com
 
 */
 

	
 
#include "protocol.h"
 
#include "asprintf.h"
 
#include "slavefuncs.h"
 
#include "distrenjob.h"
 
#include "execio.h"
 

	
 
#include <curl/curl.h>
 
#include <curl/types.h>
 
#include <curl/easy.h>
 

	
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <stdlib.h>
 
#include <sys/stat.h>
 
#include <fcntl.h>
 

	
 

	
 

	
 
/**
 
 utility function for XPath-ish stuff:
 
 */
 
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path)
 
{
 
  xmlNodePtr toreturn;
 

	
 
  xmlXPathObjectPtr xmlxpathobjptr;
 
  xmlxpathobjptr = xmlXPathEval(path, xpathctxt);
 
  if(!xmlxpathobjptr
 
     || !xmlxpathobjptr->nodesetval->nodeNr)
 
    {
 
      fprintf(stderr, "XPath resolution failed for ``%s'' in ``%s'' (``%s'')\n", path, xpathctxt->doc->name, xpathctxt->doc->URL);
 
      return (xmlNodePtr)NULL;
 
    }
 

	
 
  toreturn = *(xmlxpathobjptr->nodesetval->nodeTab);
 

	
 
  xmlXPathFreeObject(xmlxpathobjptr);
 

	
 
  return toreturn;
 
}
 

	
 
/** Ensures that rendering engines on the computer are up-to-date */
 
int software_updatecheck(char *datadir){
 
  char *pathtoserverVersion;
 
  _distren_asprintf(&pathtoserverVersion, "%s/serverEngineVersion.info",datadir);
 

	
 
  char *engineDownloadPath;
 
  _distren_asprintf(&engineDownloadPath, "%s/engines/blender.tgz",datadir);
 

	
 
  char *pathtolocalVersion;
 
  _distren_asprintf(&pathtolocalVersion, "%s/envines/blender/version.info",datadir);
 

	
 
  curlget("http://protofusion.org/distren/srv/version.info",  pathtoserverVersion);
 
  struct stat buffer;
 
  char serverVersion[5]; // Version numbers are nice and short
 
  char localVersion[5]; // Version numbers are nice and short
 

	
 

	
 
  // Read server version
 
  {
 
    FILE * serverVersionFile;
 
    serverVersionFile = fopen(pathtoserverVersion, "r");
 
    fscanf(serverVersionFile, "%s",serverVersion);
 
    fclose(serverVersionFile);
 
  }
 

	
 
  // Read local version
 
  {
 
    FILE * localVersionFile;
 
    localVersionFile = fopen(pathtolocalVersion, "r");
 
    fscanf(localVersionFile, "%s",localVersion);
 
    fclose(localVersionFile);
 
  }
 

	
 

	
 
  // If a rendering engine was never downloaded
 
  if( stat(SYSCONFDIR "/engines/blender", &buffer) == -1){
 
    fprintf(stderr,"You don't have the blender engine. Preparing to download...");
 
    curlget("http://protofusion.org/distren/srv/blender-lin32-dist.tgz", engineDownloadPath); // Add calls for operating system info
 
    // untar(SYSCONFDIR "/engines/blender.tgz");
 
  }
 

	
 
  // If a rendering engine is out-of-date
 
  else if( serverVersion != localVersion){
 
    fprintf(stderr,"You don't have the latest blender engine. Preparing to download...");
 
    curlget("http://protofusion.org/distren/srv/blender-lin32-dist.tgz", engineDownloadPath); // Add calls for operating system info
 
    // untar(SYSCONFDIR "/engines/blender.tgz");
 
  }
 

	
 
  return 0;
 
}
 

	
 
/** Stub for deleting job data from the disk. @TODO: unstubify me! */
 
int delete_jobdata(int jobnum, char *datadir)
 
{
 
  char *jobpath;
 
  _distren_asprintf(&jobpath, "%s/%d", datadir, jobnum);
 
  rmdir(jobpath);
 
  fprintf(stderr, "I just failed to remove all of your job data because I can only delete empty directories! Haha!\nPlease contact the dev team :D\n\tWe'd be overjoyed to know that someone was willing to try to use this in this devel/design/planning stage ;-)\n");
 
  return 0;
 
}
 

	
 
/** Stub stub stubbiness ugh @TODO: Kill me. */
 
void tell_the_server(int stuff){
 
}
 

	
 
/** Function referenced by curlget() to write data to disk. */
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream)
 
 {
 
    return fwrite(ptr, size, nmemb, stream);
 
  }
 

	
 
/** Helper function for cURL's progress display */
 
int curl_progress( char *Bar,double t,double d,double ultotal,double ulnow)
 
{
 
fprintf(stderr,"Downloading: %f%% complete\r",d/t*100);
 
return 0;
 
}
 

	
 
/** Retrieves a URL with cURL and saves it to disk */
 
int curlget(char *url, char *out){
 
  fprintf(stderr,"Preparing to download %s",url);
 
  double *Bar; // Stores cURL progress display info
 
  CURL *curl;
 
  CURLcode res;
 
  FILE *outfile;
 

	
 
  curl = curl_easy_init();
 
  if(curl) {
 
	outfile = fopen(out, "w"); // Open where we're writing to
 

	
 
  curl_easy_setopt(curl, CURLOPT_URL, url);
 
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
 
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat.
 
  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
 
  res = curl_easy_perform(curl);
 
  curl_easy_cleanup(curl);
0 comments (0 inline, 0 general)