diff --git a/src/common/execio.c b/src/common/execio.c --- a/src/common/execio.c +++ b/src/common/execio.c @@ -28,6 +28,7 @@ #include #include #include +#include #include int execio_open(struct execio **rem, const char *progname, char *const argv[]) @@ -75,7 +76,6 @@ int execio_open(struct execio **rem, con /* setup execio struct */ (*rem) = malloc(sizeof(struct execio)); - fprintf(stderr, "Allocated rem at %d\n", rem); if(!(*rem)) { /* we should tell the child we're dead - use wait and close our end of the pipes! */ diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -109,6 +109,7 @@ int main(int argc, char *argv[]) CLIENTSTATUS_IDLE = 2 } clientstatus; + clientstatus = CLIENTSTATUS_UNINITIALIZED; // xmlinit(); for(counter = 0; counter < argc; counter ++) @@ -161,26 +162,31 @@ int main(int argc, char *argv[]) /* Make the following code more event-driven */ frame_watchdog(&general_info.head); - struct frameset *frame; + struct frameset frame; struct distrenjob *job; + distrenjob_new(&job); + + memset(&frame, '\0', sizeof(frame)); /* If the client is idle, must be modified for climbing through linked list of clients (client->clientnum) */ if(clientstatus == CLIENTSTATUS_IDLE) { - int returnnum = find_jobframe(general_info.conn, slaveKey, &job->jobnum, &frame->num); // Finds a frame to render @FIXME: Slavenum :D + int returnnum = find_jobframe(general_info.conn, slaveKey, &job->jobnum, &frame.num); // Finds a frame to render @FIXME: Slavenum :D if(returnnum) { fprintf(stderr,"No frames are available to render at this time. Idling...\n"); sleep(10); } else - remotio_send_to_client(frame->num, job->jobnum); // Pseudo-sends data to client + remotio_send_to_client(frame.num, job->jobnum); // Pseudo-sends data to client } /* If the client states that they finished the frame */ - if(clientsays == DISTREN_REQUEST_DONEFRAME){ - clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle - finish_frame(general_info.conn, 0, job->jobnum, frame->num); // @TODO: Make sure this actually works. - } + if(clientsays == DISTREN_REQUEST_DONEFRAME) + { + clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle + finish_frame(general_info.conn, 0, job->jobnum, frame.num); // @TODO: Make sure this actually works. + } + distrenjob_free(&job); } distrend_unlisten(general_info.config->listens, clients); diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -139,22 +139,24 @@ size_t curl_writetodisk(void *ptr, size_ } /** Helper function for cURL's progress display */ -int curl_progress( char *Bar,double t,double d,double ultotal,double ulnow) +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){ +CURLcode curlget(char *url, char *out){ fprintf(stderr,"Preparing to download %s\n",url); double *Bar; // Stores cURL progress display info CURL *curl; CURLcode res; FILE *outfile; + res = CURLE_FAILED_INIT; curl = curl_easy_init(); - if(curl) { + if(curl) + { outfile = fopen(out, "w"); // Open where we're writing to if(outfile == NULL) return 2; // Output dir doesn't exist @@ -162,19 +164,19 @@ int curlget(char *url, char *out){ 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_PROGRESSFUNCTION, (curl_progress_callback)&curl_progress); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar); res = curl_easy_perform(curl); curl_easy_cleanup(curl); + fclose(outfile); } fprintf(stderr,"\n"); // Clears out he progressbar's carriage return - fclose(outfile); return res; // 0 is OK, 1 is 404 or other error } /** Posts a file to a url with cUrl */ -int curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey){ - fprintf(stderr,"Uploading to %s\n", url); +CURLcode curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey) +{ char *targetname = "uploadedfile"; // Name of the target in the php file on the server (Don't change me unless you have different PHP code) CURL *curl; CURLcode res; @@ -186,6 +188,9 @@ int curlpost(char *filename, char *url, char *sjobnum; char *sframenum; char *sslavekey; + + fprintf(stderr,"Uploading to %s\n", url); + _distren_asprintf(&sjobnum,"%d",jobnum); _distren_asprintf(&sframenum,"%d",framenum); _distren_asprintf(&sslavekey,"%d",slavekey); @@ -226,9 +231,11 @@ int curlpost(char *filename, char *url, CURLFORM_COPYCONTENTS, "send", CURLFORM_END); + res = CURLE_FAILED_INIT; curl = curl_easy_init(); headerlist = curl_slist_append(headerlist, buf); - if(curl) { + if(curl) + { /* Setting the URL to get the post, and the contents of the post */ curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); @@ -241,7 +248,7 @@ int curlpost(char *filename, char *url, free(sjobnum); free(sframenum); free(sslavekey); - } + } return res; } @@ -634,9 +641,9 @@ struct _web_memorystruct { size_t size; }; -static void *_web_myrealloc(void *ptr, size_t size); +void *_web_myrealloc(void *ptr, size_t size); -static void *_web_myrealloc(void *ptr, size_t size) +void *_web_myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ @@ -646,7 +653,7 @@ static void *_web_myrealloc(void *ptr, s return malloc(size); } -static size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data) +size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; struct _web_memorystruct *mem = (struct _web_memorystruct *)data; diff --git a/src/server/slavefuncs.h b/src/server/slavefuncs.h --- a/src/server/slavefuncs.h +++ b/src/server/slavefuncs.h @@ -24,6 +24,7 @@ #include "common/remoteio.h" +#include #include #include @@ -35,8 +36,8 @@ xmlNodePtr xml_quickxpath(xmlXPathContex int software_updatecheck(); int delete_jobdata(int jobnum, char *datadir); size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream); -int curlget(char *url, char *out); -int curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey); +CURLcode curlget(char *url, char *out); +CURLcode curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey); int ssh_keygen(); int register_user(char *username, char *email); int login_user(char *username); @@ -55,8 +56,8 @@ void slaveTest(); /* Simple slave */ struct _web_memorystruct; -static void *_web_myrealloc(void *ptr, size_t size); -static size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data); +void *_web_myrealloc(void *ptr, size_t size); +size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data); struct _web_memorystruct _web_getrequest(char *url); void _web_finishframe(int slavekey, char *slavepass, int jobnum, int framenum); void _web_startframe(int slavekey, char *slavepass, int jobnum, int framenum);