diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -90,6 +90,9 @@ struct general_info unsigned long total_priority_pieces; user_mgr_t user_mgr; + + /* my servertype, see protocol.h */ + uint8_t servertype; }; @@ -307,6 +310,8 @@ int distrend_handle_version(struct gener return 1; } + client->servertype = version.servertype; + return 0; } @@ -394,7 +399,8 @@ static distren_request_file_post_context */ void distrend_client_file_post_free(struct distrend_client_file_post *client_file_post) { - fclose(client_file_post->fd); + if(client_file_post->fd) + fclose(client_file_post->fd); free(client_file_post->filename); unlink(client_file_post->file_save_path); free(client_file_post->file_save_path); @@ -414,11 +420,6 @@ int distrend_handle_file_post_start(stru int ret; - /** - * @todo access check! - */ - fprintf(stderr, __FILE__ ":%d:distrend_handle_file_post_start(): You need to check if a client is actually allowed to upload files somehow!\n", __LINE__); - /* * other servers should be excluded from this check, but we don't * store the servertype in client yet. @@ -581,6 +582,8 @@ int distrend_handle_file_post_finish(str * Here it is... manage a file being submitted for rendering... or * for whatever purpose it was uploaded for somehow... */ + fclose(client_file_post->fd); + client_file_post->fd = NULL; distrend_handle_successful_upload(client, client_file_post); list_remove_element(client->file_post_list, client_file_post); @@ -599,6 +602,8 @@ int distrend_handle_successful_upload(st fprintf(stderr, __FILE__ ":%d: STUB: I don't know what to do with %s[%s] :-/\n", __LINE__, client_file_post->filename, client_file_post->file_save_path); + unpackJob("/home/ohnobinki/var/distren/tmp", client_file_post->file_save_path); + return 0; } diff --git a/src/server/listen.h b/src/server/listen.h --- a/src/server/listen.h +++ b/src/server/listen.h @@ -129,6 +129,11 @@ struct distrend_client enum distrend_client_state state; /** + * \see protocol.h for DISTREN_SERVERTYPE_ constants. + */ + uint8_t servertype; + + /** The absolute time at which this client's entry in the client list will be expired, closed, and marked as dead so that it may be cleaned up. This is used to implement ping timeouts (if state == DISTREND_CLIENT_GOOD) and diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -811,30 +811,38 @@ int unpackJob(char *outdir, char *pathto 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) + if(!a + || !ae) { - fprintf(stderr, "Error opening archive!\n"); + if(a) + archive_read_finish(a); + if(ae) + archive_entry_free(ae); return 1; } - for(astatus = ARCHIVE_OK; - astatus == ARCHIVE_OK - || astatus == ARCHIVE_WARN; - ) + fprintf(stderr, "Trying to unpack %s into %s\n", pathtoTar, outdir); + + archive_read_support_compression_all(a); + archive_read_support_format_all(a); + astatus = archive_read_open_filename(a, pathtoTar, 1); + if (astatus != ARCHIVE_OK) { - astatus = archive_read_next_header2(a, ae); - if(astatus == ARCHIVE_WARN) - fprintf(stderr, "Encountered nonfatal read error somehow!\n"); + fprintf(stderr, "Error opening archive!\n"); + archive_read_finish(a); + archive_entry_free(ae); + return 1; + } - 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); + while((astatus = archive_read_next_header2(a, ae)) == ARCHIVE_OK) + { + astatus = archive_read_extract(a, ae, + ARCHIVE_EXTRACT_NO_OVERWRITE + | ARCHIVE_EXTRACT_SECURE_SYMLINKS + | ARCHIVE_EXTRACT_SECURE_NODOTDOT); + if(astatus != ARCHIVE_OK) + fprintf(stderr, "Encountered error or warning when attempting to extract file: %s\n", + archive_entry_pathname(ae)); } archive_entry_free(ae); archive_read_finish(a);