Revision 98b047dd src/CloudSupport/libs3_delegate_helper.c

View differences:

src/CloudSupport/libs3_delegate_helper.c
36 36
  void* (*cloud_helper_init)(struct nodeID *local, const char *config);
37 37
  int (*get_from_cloud)(void *context, const char *key, uint8_t *header_ptr,
38 38
                        int header_size, int free_header);
39
  int (*get_from_cloud_default)(void *context, const char *key,
40
                                uint8_t *header_ptr, int header_size, int free_header,
41
                                uint8_t *defval_ptr, int defval_size, int free_defval);
39 42
  int (*put_on_cloud)(void *context, const char *key, uint8_t *buffer_ptr,
40 43
                      int buffer_size, int free_buffer);
41 44
  struct nodeID* (*get_cloud_node)(void *context, uint8_t variant);
......
121 124
  int data_length;
122 125
  int free_data;
123 126

  
127
  uint8_t *default_value;
128
  int default_value_length;
129
  int free_default_value;
130

  
124 131
  struct libs3_cloud_context *ctx;
125 132
};
126 133
typedef struct libs3_request libs3_request_t;
......
163 170

  
164 171
  free(req->key);
165 172
  if (req->free_data > 0) free(req->data);
173
  if (req->free_default_value > 0)
174
    free(req->default_value);
166 175

  
167 176
  free(req);
168 177
}
......
432 441
    rsp->data_length = cbk_ctx->bytes + req->data_length;
433 442
    rsp->read_bytes = 0;
434 443
    rsp->last_timestamp = cbk_ctx->last_timestamp;
444
  } else {
445
    /* Since there was no value for the specified key. If the caller specified a
446
       default value, use that */
447
    if (req->default_value) {
448
      rsp->data = malloc(req->data_length + req->default_value_length);
449
      if (!rsp->data) return 1;
450
      rsp->current_byte = rsp->data;
451
      if (req->data_length > 0)
452
        memcpy(rsp->data, req->data, req->data_length);
453

  
454
      memcpy(rsp->data, req->default_value, req->default_value_length);
455

  
456
      rsp->status = S3StatusOK;
457
    }
435 458
  }
436 459

  
437
  status = (cbk_ctx->status == S3StatusOK) ? 0 : -1;
438 460
  free(cbk_ctx);
461
  status = (rsp->status == S3StatusOK) ? 0 : -1;
462

  
439 463

  
440 464
  return status;
441 465
}
......
536 560
  return ctx;
537 561
}
538 562

  
539
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
540
                   int header_size, int free_header)
563
int get_from_cloud_default(void *context, const char *key, uint8_t *header_ptr,
564
                           int header_size, int free_header, uint8_t *defval_ptr,
565
                           int defval_size, int free_defval)
541 566
{
542 567
  struct libs3_cloud_context *ctx;
543 568
  libs3_request_t *request;
......
552 577
  request->data = header_ptr;
553 578
  request->data_length = header_size;
554 579
  request->free_data = free_header;
580
  request->default_value = defval_ptr;
581
  request->default_value_length = defval_size;
582
  request->free_default_value = free_defval;
555 583
  request->ctx = ctx;
556 584

  
557 585
  req_handler_add_request(ctx->req_handler,
......
562 590
  return 0;
563 591
}
564 592

  
593
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
594
                   int header_size, int free_header)
595
{
596
  return get_from_cloud_default(context, key, header_ptr, header_size,
597
                                free_header, NULL, 0, 0);
598
}
599

  
565 600
int put_on_cloud(void *context, const char *key, uint8_t *buffer_ptr,
566 601
                 int buffer_size, int free_buffer)
567 602
{
......
578 613
  request->data = buffer_ptr;
579 614
  request->data_length = buffer_size;
580 615
  request->free_data = free_buffer;
616
  request->default_value = NULL;
617
  request->default_value_length = 0;
618
  request->free_default_value = 0;
581 619
  request->ctx = ctx;
582 620

  
583 621
  if (ctx->blocking_put_request) {
......
676 714
struct delegate_iface delegate_impl = {
677 715
  .cloud_helper_init = &cloud_helper_init,
678 716
  .get_from_cloud = &get_from_cloud,
717
  .get_from_cloud_default = &get_from_cloud_default,
679 718
  .put_on_cloud = &put_on_cloud,
680 719
  .get_cloud_node = &get_cloud_node,
681 720
  .timestamp_cloud = &timestamp_cloud,

Also available in: Unified diff