# HG changeset patch # User normaldotcom # Date 2010-06-07 18:58:39 # Node ID 8b315b2b5d849e86d459058a3c8ca1c7cd574839 # Parent 6af19560cd72181f3c6b472e0d6b4753ed1765f1 Reorganized and commented code that binki needs to focus on diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -42,57 +42,6 @@ #include #define DEBUG 0 -/** - Sends the server a single request (see protocol.h) -*/ -int sendSignal(struct remoteio *rem, char signal) -{ - size_t written; - size_t towrite; - char *ssignal; - - _distren_asprintf(&ssignal, "%c", signal); - towrite = strlen(ssignal); - while( towrite - && !remoteio_write(rem, ssignal, towrite, &written)) - { - fprintf(stderr, "Sending request...\n"); - towrite -= written; - } - if(written) - return 0; - - /** - if remoteio_write returned 1, the connection - is probably dead or there was a real error - */ - return 1; -} - -/** - Sends the server an extended signal (request + data) -*/ -int sendExtSignal(struct remoteio *rem, char signal, char *data){ - size_t written; - size_t towrite; - char *ssignal; - _distren_asprintf(&ssignal, "%c%s", signal, data); // Just append the data FIXME: We should do this differently - towrite = strlen(ssignal); - while( towrite - && !remoteio_write(rem, ssignal, towrite, &written)) - { - fprintf(stderr, "Sending request...\n"); - towrite -= written; - } - if(written) - return 0; - - /** - if remoteio_write returned 1, the connection - is probably dead or there was a real error - */ - return 1; -} @@ -254,14 +203,6 @@ CURLcode curlpost(char *filename, char * return res; } - -/** Logs the user into the server after ensuring that keys exist */ -int login_user(char *username) -{ - // @TODO: Put some telnet-style auth code here unless this is obselete - return 1; // success -} - /** Replaces wordtoreplace with replacewith in conffile (relative to SYSCONFDIR) */ int conf_replace(char *conffile, char *wordtoreplace, char *replacewith){ int maxlinelen = 120; @@ -438,70 +379,6 @@ int uploadOutput(char *pathtoOutput, cha } } -/** - Extracts archive to the specified directory, creating this directory - if necessary (but this directory will not be recursively created). - @param outdir output directory - @param pathtoTar filename of the archive to extract - */ -int unpackJob(char *outdir, char *pathtoTar) -{ - int ret; - - struct archive *a; - struct archive_entry *ae; - int astatus; - - /* ignore return because directory may exist already */ - mkdir(outdir, 0700); - ret = chdir(outdir); - if(ret == -1) - { - perror("chdir"); - return 1; - } - - a = archive_read_new(); - ae = archive_entry_new(); - - archive_read_support_compression_all(a); - archive_read_support_format_raw(a); - astatus = archive_read_open_filename(a, pathtoTar, 8192); - if (astatus != ARCHIVE_OK) - { - fprintf(stderr, "error opening archive\n"); - return 1; - } - - for(astatus = ARCHIVE_OK; - astatus == ARCHIVE_OK - || astatus == ARCHIVE_WARN; - ) - { - astatus = archive_read_next_header2(a, ae); - if(astatus == ARCHIVE_WARN) - fprintf(stderr, "Encountered nonfatal read error somehow\n"); - - if(astatus == ARCHIVE_OK - || astatus == ARCHIVE_WARN) - astatus = archive_read_extract(a, ae, - ARCHIVE_EXTRACT_NO_OVERWRITE - | ARCHIVE_EXTRACT_SECURE_SYMLINKS - | ARCHIVE_EXTRACT_SECURE_NODOTDOT); - } - archive_entry_free(ae); - archive_read_finish(a); - - if(astatus != ARCHIVE_EOF) - { - fprintf(stderr, "Error reading archive\n"); - return 1; - } - - return 0; -} - - void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile, char **urltoJobfile, char **urltoOutput,char **pathtoOutput, char **pathtoRenderOutput, char **pathtoOutdir) { // Variable Preparation @@ -871,17 +748,159 @@ free(realOutput); return ret; } + + +/** *********************************************************************************************************/ +/** Why hello ohnobinki! Normaldotcom has graciously prepared this portion of code for you to work on! Yay! */ +/** *********************************************************************************************************/ + + +/** + Extracts archive to the specified directory, creating this directory + if necessary (but this directory will not be recursively created). + @param outdir output directory + @param pathtoTar filename of the archive to extract + + ohnobinki: please make me work :-\ + */ +int unpackJob(char *outdir, char *pathtoTar) +{ + int ret; + + struct archive *a; + struct archive_entry *ae; + int astatus; + + /* ignore return because directory may exist already */ + mkdir(outdir, 0700); + ret = chdir(outdir); + if(ret == -1) + { + perror("chdir"); + return 1; + } + + a = archive_read_new(); + ae = archive_entry_new(); + + archive_read_support_compression_all(a); + archive_read_support_format_raw(a); + astatus = archive_read_open_filename(a, pathtoTar, 8192); + if (astatus != ARCHIVE_OK) + { + fprintf(stderr, "error opening archive\n"); + return 1; + } + + for(astatus = ARCHIVE_OK; + astatus == ARCHIVE_OK + || astatus == ARCHIVE_WARN; + ) + { + astatus = archive_read_next_header2(a, ae); + if(astatus == ARCHIVE_WARN) + fprintf(stderr, "Encountered nonfatal read error somehow\n"); + + if(astatus == ARCHIVE_OK + || astatus == ARCHIVE_WARN) + astatus = archive_read_extract(a, ae, + ARCHIVE_EXTRACT_NO_OVERWRITE + | ARCHIVE_EXTRACT_SECURE_SYMLINKS + | ARCHIVE_EXTRACT_SECURE_NODOTDOT); + } + archive_entry_free(ae); + archive_read_finish(a); + + if(astatus != ARCHIVE_EOF) + { + fprintf(stderr, "Error reading archive\n"); + return 1; + } + + return 0; +} + + +/** Logs the user into the server after ensuring that keys exist + ohnobinki: I assume you could use this for remoteio, or just kill it +*/ +int login_user(char *username) +{ + // @TODO: Put some telnet-style auth code here unless this is obselete + return 1; // success +} + +/** + Sends the server a single request (see protocol.h) + ohnobinki: This should hopefully work, maybe ;D +*/ +int sendSignal(struct remoteio *rem, char signal) +{ + size_t written; + size_t towrite; + char *ssignal; + + _distren_asprintf(&ssignal, "%c", signal); + towrite = strlen(ssignal); + while( towrite + && !remoteio_write(rem, ssignal, towrite, &written)) + { + fprintf(stderr, "Sending request...\n"); + towrite -= written; + } + if(written) + return 0; + + /** + if remoteio_write returned 1, the connection + is probably dead or there was a real error + */ + return 1; +} + +/** + Sends the server an extended signal (request + data) + ohnobinki: I have no clue how you really want to handle this. Please clarify/edit +*/ +int sendExtSignal(struct remoteio *rem, char signal, char *data){ + size_t written; + size_t towrite; + char *ssignal; + _distren_asprintf(&ssignal, "%c%s", signal, data); // Just append the data FIXME: We should do this differently + towrite = strlen(ssignal); + while( towrite + && !remoteio_write(rem, ssignal, towrite, &written)) + { + fprintf(stderr, "Sending request...\n"); + towrite -= written; + } + if(written) + return 0; + + /** + if remoteio_write returned 1, the connection + is probably dead or there was a real error + */ + return 1; +} + + /* Port of web functions for standard code Currently, most functions are stubs due to lack - of socket reading code */ + of socket reading code + ohnobinki: I can take care of a fair amount of this, but the remotio reading and writing is where you should really lay down some code. +*/ + +/** marks frame finished on server */ void finishframe(struct remoteio *rem, int jobnum, int framenum){ char* data; _distren_asprintf(&data, "%d%d", jobnum, framenum); sendExtSignal(rem, DISTREN_REQUEST_DONEFRAME, data); } +/** resets frame to unassigned on server */ void resetframe(struct remoteio *rem, int jobnum, int framenum){ fprintf(stderr,"Resetting frame %d in job %d on server... ",framenum,jobnum); char* data; @@ -890,6 +909,7 @@ void resetframe(struct remoteio *rem, in } +/** marks frame assigned on server */ void startframe(struct remoteio *rem, int jobnum, int framenum){ if(DEBUG) fprintf(stderr,"Marking frame %d started on server... ",framenum); @@ -899,6 +919,7 @@ void startframe(struct remoteio *rem, in } +/** retrieves job from server */ int getwork(struct remoteio *rem, int *jobnum, int *framenum){ char* data; _distren_asprintf(&data, "%d%d", jobnum, framenum); @@ -906,6 +927,7 @@ int getwork(struct remoteio *rem, int *j return 0; } +/** sets render power of slave on server */ void setrenderpower(struct remoteio *rem, int renderpower){ fprintf(stderr,"Setting render power on server... "); char* data; @@ -913,12 +935,13 @@ void setrenderpower(struct remoteio *rem sendExtSignal(rem,DISTREN_REQUEST_SETRENDERPOWER, data); } - +/** retrieves render power of slave from server */ int getrenderpower(struct remoteio *rem){ sendSignal(rem, DISTREN_REQUEST_GETRENDERPOWER); return 0; } +/** compares slave software version with server software version */ int checkslaveversion(struct remoteio *rem){ sendSignal(rem, DISTREN_REQUEST_GETVERSION); char* serverVersionFromRemotio = "9000";