DS3 C SDK  4.1.0
Provides access to the Spectra S3 API with C
ds3_utils.c
Go to the documentation of this file.
1 /*
2  * ******************************************************************************
3  * Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
4  * Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5  * this file except in compliance with the License. A copy of the License is located at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * or in the "license" file accompanying this file.
10  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  * ****************************************************************************
14  */
15 
16 
17 #include <glib.h>
18 
19 #include "ds3.h"
20 #include "ds3_utils.h"
21 
22 ds3_error* ds3_create_error(ds3_error_code code, const char * message) {
23  ds3_error* error = g_new0(ds3_error, 1);
24  error->code = code;
25  error->message = ds3_str_init(message);
26  error->error = NULL;
27  return error;
28 }
29 
30 size_t ds3_load_buffer(void* buffer, size_t size, size_t nmemb, void* user_data) {
31  size_t realsize = size * nmemb;
32  GByteArray* blob = (GByteArray*) user_data;
33 
34  g_byte_array_append(blob, (const guint8 *) buffer, realsize);
35  return realsize;
36 }
37 
38 void ds3_log_message(const ds3_log* log, ds3_log_lvl lvl, const char* message, ...) {
39  if (log == NULL) {
40  return;
41  }
42 
43  if (log->log_callback == NULL) {
44  fprintf(stderr, "ERROR: ds3_c_sdk - User supplied log_callback is null, failed to log message.\n");
45  return;
46  }
47 
48  if (lvl <= log->log_lvl) {
49  va_list args;
50  char * log_message;
51 
52  va_start(args, message);
53  log_message = g_strdup_vprintf(message, args);
54  va_end(args);
55 
56  log->log_callback(log_message, log->user_data);
57 
58  g_free(log_message);
59  }
60 }
61 
ds3_log_lvl
Definition: ds3.h:84
Definition: ds3.h:92
ds3_error_code code
Definition: ds3.h:2128
void ds3_log_message(const ds3_log *log, ds3_log_lvl lvl, const char *message,...)
Definition: ds3_utils.c:38
ds3_error * ds3_create_error(ds3_error_code code, const char *message)
Definition: ds3_utils.c:22
size_t ds3_load_buffer(void *buffer, size_t size, size_t nmemb, void *user_data)
Definition: ds3_utils.c:30
The public definitions for the Spectra S3 C SDK.
ds3_error_code
Definition: ds3.h:103
ds3_error_response * error
Definition: ds3.h:2130
void(* log_callback)(const char *log_message, void *user_data)
Definition: ds3.h:93
ds3_str * message
Definition: ds3.h:2129
ds3_str * ds3_str_init(const char *string)
Definition: ds3_string.c:20
void * user_data
Definition: ds3.h:94