Changeset - 0fa8dda72d6a
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 15 years ago 2010-08-09 23:20:05
ohnobinki@ohnopublishing.net
Working job unpacking.
3 files changed with 37 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -87,12 +87,15 @@ struct general_info
 
  int hibernate;
 
  time_t timestamp;
 
  unsigned long total_render_power;
 
  unsigned long total_priority_pieces;
 

	
 
  user_mgr_t user_mgr;
 

	
 
  /* my servertype, see protocol.h */
 
  uint8_t servertype;
 
};
 

	
 

	
 
/* *********************************************
 
   Function Prototypes
 
   ********************************************* */
 
@@ -304,12 +307,14 @@ int distrend_handle_version(struct gener
 
	}
 
      else
 
	distrend_send_disconnect(client, "Invalid PACKAGE_VERSION :-|.");
 
      return 1;
 
    }
 

	
 
  client->servertype = version.servertype;
 

	
 
  return 0;
 
}
 

	
 
/**
 
 * Handle a DISTREN_REQUEST_PASS request.
 
 */
 
@@ -391,12 +396,13 @@ static distren_request_file_post_context
 
 * Whenever calling this functino, you almost _always_ have to call
 
 * list_remove_element(client->file_post_list, client_file_post);
 
 * first.
 
 */
 
void distrend_client_file_post_free(struct distrend_client_file_post *client_file_post)
 
{
 
  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);
 

	
 
  free(client_file_post);
 
@@ -411,17 +417,12 @@ int distrend_handle_file_post_start(stru
 
  char *filename;
 

	
 
  char *str_tmp;
 

	
 
  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.
 
   */
 
  if(list_size(client->file_post_list) > 1)
 
    {
 
@@ -578,12 +579,14 @@ int distrend_handle_file_post_finish(str
 
    return 1;
 

	
 
  /*
 
   * 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);
 
  distrend_client_file_post_free(client_file_post);
 

	
 
  return 0;
 
@@ -596,12 +599,14 @@ int distrend_handle_file_post_finish(str
 
 */
 
int distrend_handle_successful_upload(struct distrend_client *client, struct distrend_client_file_post *client_file_post)
 
{
 
  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;
 
}
 

	
 
/**
 
   Performs command stored in a client's request. @TODO: Fill stub
 
*/
src/server/listen.h
Show inline comments
 
@@ -126,12 +126,17 @@ struct distrend_client_file_post
 
 */
 
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 
 
     disconnect message grace time (if state == DISTREND_CLIENT_BAD).
 
   */
 
  time_t cleanup_time;
src/server/slavefuncs.c
Show inline comments
 
@@ -808,36 +808,44 @@ int unpackJob(char *outdir, char *pathto
 
      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)
 
  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)
 
  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);
 

	
 
  if(astatus != ARCHIVE_EOF)
 
    {
0 comments (0 inline, 0 general)