Revision b9e7dd7b src/CloudSupport/libs3_delegate_helper.c

View differences:

src/CloudSupport/libs3_delegate_helper.c
36 36
 ***********************************************************************/
37 37
struct delegate_iface {
38 38
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
39
  int (*get_from_cloud)(void *context, char *key, uint8_t *header_ptr,
40
                        int header_size);
41
  int (*put_on_cloud)(void *context, char *key, uint8_t *buffer_ptr,
42
                      int buffer_size);
39
  int (*get_from_cloud)(void *context, const char *key, uint8_t *header_ptr,
40
                        int header_size, int free_header);
41
  int (*put_on_cloud)(void *context, const char *key, uint8_t *buffer_ptr,
42
                      int buffer_size, int free_buffer);
43 43
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
44 44
  time_t (*timestamp_cloud)(void *context);
45 45
  int (*is_cloud_node)(void *context, struct nodeID* node);
......
60 60
     For PUT this is the pointer to the actual data */
61 61
  uint8_t *data;
62 62
  int data_length;
63
  int free_data;
63 64
} libs3_request_t;
64 65

  
65 66
typedef struct libs3_get_response {
......
169 170
  S3Status status;
170 171
};
171 172

  
173
static void free_request(libs3_request_t *req)
174
{
175
  if (!req) return;
176

  
177
  free(req->key);
178
  if (req->free_data > 0) free(req->data);
179

  
180
  free(req);
181
}
172 182

  
173 183
static void add_request(struct libs3_cloud_context *ctx, libs3_request_t *req)
174 184
{
......
539 549
                "libs3_delegate_helper: failed to perform operation\n");
540 550
      }
541 551

  
542
      /* TODO: to free or not to free? */
543
      if (req->data) free(req->data);
544
      free(req);
552
      free_request(req);
545 553
    }
546 554
  } while(req != NULL);
547 555

  
......
749 757
  return ctx;
750 758
}
751 759

  
752
int get_from_cloud(void *context, char *key, uint8_t *header_ptr,
753
                   int header_size)
760
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
761
                   int header_size, int free_header)
754 762
{
755 763
  struct libs3_cloud_context *ctx;
756 764
  libs3_request_t *request;
......
764 772
  request->key = strdup(key);
765 773
  request->data = header_ptr;
766 774
  request->data_length = header_size;
775
  request->free_data = free_header;
767 776

  
768 777
  add_request(ctx, request);
769 778

  
770 779
  return 0;
771 780
}
772 781

  
773
  int put_on_cloud(void *context, char *key, uint8_t *buffer_ptr,
774
                      int buffer_size)
782
  int put_on_cloud(void *context, const char *key, uint8_t *buffer_ptr,
783
                   int buffer_size, int free_buffer)
775 784
  {
776 785
  struct libs3_cloud_context *ctx;
777 786
  libs3_request_t *request;
......
785 794
  request->key = strdup(key);
786 795
  request->data = buffer_ptr;
787 796
  request->data_length = buffer_size;
797
  request->free_data = free_buffer;
788 798

  
789
  if (ctx->blocking_put_request)
790
    return request_handler_process_put_request(ctx, request);
799
  if (ctx->blocking_put_request) {
800
    int res;
801
    res = request_handler_process_put_request(ctx, request);
802
    free_request(request);
803
    return res;
804
  }
791 805
  else
792 806
    add_request(ctx, request);
793 807

  

Also available in: Unified diff