@@ -364,7 +364,7 @@ static char* _net_compute_signature(const ds3_log* log, const ds3_creds* creds,
364364 gsize bufSize = 256 ;
365365 guint8 buffer [256 ];
366366 unsigned char * signature_str = _generate_signature_str (verb , resource_name , date , content_type , md5 , amz_headers );
367- unsigned char * escaped_str = g_strescape (signature_str , NULL );
367+ char * escaped_str = g_strescape (( char * ) signature_str , NULL );
368368
369369 LOG (log , DEBUG , "signature string: %s" , escaped_str );
370370 g_free (escaped_str );
@@ -471,12 +471,13 @@ static int ds3_curl_logger(CURL *handle, curl_infotype type, char* data, size_t
471471}
472472
473473static ds3_error * _net_process_request (const ds3_client * client , const ds3_request * _request , void * read_user_struct , size_t (* read_handler_func )(void * , size_t , size_t , void * ), void * write_user_struct , size_t (* write_handler_func )(void * , size_t , size_t , void * ), GHashTable * * return_headers ) {
474- _init_curl ();
475-
476474 struct _ds3_request * request = (struct _ds3_request * ) _request ;
477- CURL * handle = curl_easy_init () ;
475+ CURL * handle ;
478476 CURLcode res ;
479477
478+ _init_curl ();
479+ handle = curl_easy_init ();
480+
480481 if (handle ) {
481482 char * url ;
482483
@@ -581,7 +582,6 @@ static ds3_error* _net_process_request(const ds3_client* client, const ds3_reque
581582
582583 headers = curl_slist_append (headers , auth_header );
583584 headers = curl_slist_append (headers , date_header );
584-
585585 headers = _append_headers (headers , request -> headers );
586586
587587 curl_easy_setopt (handle , CURLOPT_HTTPHEADER , headers );
@@ -614,9 +614,14 @@ static ds3_error* _net_process_request(const ds3_client* client, const ds3_reque
614614 error -> error = g_new0 (ds3_error_response , 1 );
615615 error -> error -> status_code = response_data .status_code ;
616616 error -> error -> status_message = ds3_str_init (response_data .status_message -> value );
617- error -> error -> error_body = ds3_str_init_with_size ((char * )response_data .body -> data , response_data .body -> len );
618-
619- g_byte_array_free (response_data .body , TRUE);
617+ if (response_data .body != NULL ) {
618+ error -> error -> error_body = ds3_str_init_with_size ((char * )response_data .body -> data , response_data .body -> len );
619+ g_byte_array_free (response_data .body , TRUE);
620+ }
621+ else {
622+ LOG (client -> log , ERROR , "The response body for the error is empty" );
623+ error -> error -> error_body = NULL ;
624+ }
620625 g_hash_table_destroy (response_headers );
621626 ds3_str_free (response_data .status_message );
622627 return error ;
@@ -971,7 +976,7 @@ static ds3_bool xml_get_bool_from_attribute(const ds3_log* log, xmlDocPtr doc, s
971976 return result ;
972977}
973978
974- static void _parse_buckets (xmlDocPtr doc , xmlNodePtr buckets_node , ds3_get_service_response * response ) {
979+ static void _parse_buckets (const ds3_log * log , xmlDocPtr doc , xmlNodePtr buckets_node , ds3_get_service_response * response ) {
975980 xmlNodePtr data_ptr ;
976981 xmlNodePtr curr ;
977982 GArray * array = g_array_new (FALSE, TRUE, sizeof (ds3_bucket ));
@@ -988,7 +993,7 @@ static void _parse_buckets(xmlDocPtr doc, xmlNodePtr buckets_node, ds3_get_servi
988993 bucket .name = xml_get_string (doc , data_ptr );
989994 }
990995 else {
991- fprintf ( stderr , "Unknown element: (%s)\n" , data_ptr -> name );
996+ LOG ( log , ERROR , "Unknown element: (%s)\n" , data_ptr -> name );
992997 }
993998 }
994999 g_array_append_val (array , bucket );
@@ -1064,15 +1069,15 @@ ds3_error* ds3_get_service(const ds3_client* client, const ds3_request* request,
10641069 for (child_node = root -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
10651070 if (element_equal (child_node , "Buckets" ) == true) {
10661071 //process buckets here
1067- _parse_buckets (doc , child_node , response );
1072+ _parse_buckets (client -> log , doc , child_node , response );
10681073 }
10691074 else if (element_equal (child_node , "Owner" ) == true) {
10701075 //process owner here
10711076 ds3_owner * owner = _parse_owner (doc , child_node );
10721077 response -> owner = owner ;
10731078 }
10741079 else {
1075- fprintf ( stderr , "Unknown xml element: (%s)\b" , child_node -> name );
1080+ LOG ( client -> log , ERROR , "Unknown xml element: (%s)\b" , child_node -> name );
10761081 }
10771082 }
10781083
@@ -1133,21 +1138,21 @@ static ds3_object _parse_object(xmlDocPtr doc, xmlNodePtr contents_node) {
11331138 return object ;
11341139}
11351140
1136- static ds3_str * _parse_common_prefixes (xmlDocPtr doc , xmlNodePtr contents_node ) {
1141+ static ds3_str * _parse_common_prefixes (const ds3_log * log , xmlDocPtr doc , xmlNodePtr contents_node ) {
11371142 xmlNodePtr child_node ;
11381143 ds3_str * prefix = NULL ;
11391144
11401145 for (child_node = contents_node -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
11411146 if (element_equal (child_node , "Prefix" ) == true) {
11421147 if (prefix ) {
1143- fprintf ( stderr , "More than one Prefix found in CommonPrefixes\n" );
1148+ LOG ( log , WARN , "More than one Prefix found in CommonPrefixes\n" );
11441149 }
11451150 else {
11461151 prefix = xml_get_string (doc , child_node );
11471152 }
11481153 }
11491154 else {
1150- fprintf ( stderr , "Unknown xml element: %s\n" , child_node -> name );
1155+ LOG ( log , ERROR , "Unknown xml element: %s\n" , child_node -> name );
11511156 }
11521157 }
11531158
@@ -1264,11 +1269,11 @@ ds3_error* ds3_get_bucket(const ds3_client* client, const ds3_request* request,
12641269 xmlFree (text );
12651270 }
12661271 else if (element_equal (child_node , "CommonPrefixes" ) == true) {
1267- ds3_str * prefix = _parse_common_prefixes (doc , child_node );
1272+ ds3_str * prefix = _parse_common_prefixes (client -> log , doc , child_node );
12681273 g_array_append_val (common_prefix_array , prefix );
12691274 }
12701275 else {
1271- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1276+ LOG ( client -> log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
12721277 }
12731278 }
12741279
@@ -1331,12 +1336,12 @@ static ds3_bulk_object _parse_bulk_object(const ds3_log* log, xmlDocPtr doc, xml
13311336 response .offset = xml_get_uint64_from_attribute (doc , attribute );
13321337 }
13331338 else {
1334- fprintf ( stderr , "Unknown attribute: (%s)\n" , attribute -> name );
1339+ LOG ( log , ERROR , "Unknown attribute: (%s)\n" , attribute -> name );
13351340 }
13361341 }
13371342
13381343 for (child_node = object_node -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
1339- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1344+ LOG ( log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
13401345 }
13411346
13421347 return response ;
@@ -1371,7 +1376,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13711376 response -> chunk_number = xml_get_uint64_from_attribute (doc , attribute );
13721377 }
13731378 else {
1374- fprintf ( stderr , "Unknown attribute: (%s)\n" , attribute -> name );
1379+ LOG ( log , ERROR , "Unknown attribute: (%s)\n" , attribute -> name );
13751380 }
13761381
13771382 }
@@ -1382,7 +1387,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13821387 g_array_append_val (object_array , object );
13831388 }
13841389 else {
1385- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1390+ LOG ( log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
13861391 }
13871392 }
13881393
@@ -1392,7 +1397,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13921397 return response ;
13931398}
13941399
1395- static ds3_job_priority _match_priority (const xmlChar * priority_str ) {
1400+ static ds3_job_priority _match_priority (const ds3_log * log , const xmlChar * priority_str ) {
13961401 if (xmlStrcmp (priority_str , (const xmlChar * ) "CRITICAL" ) == 0 ) {
13971402 return CRITICAL ;
13981403 }
@@ -1415,51 +1420,51 @@ static ds3_job_priority _match_priority(const xmlChar* priority_str) {
14151420 return MINIMIZED_DUE_TO_TOO_MANY_RETRIES ;
14161421 }
14171422 else {
1418- fprintf ( stderr , "ERROR: Unknown priority type of '%s'. Returning LOW to be safe.\n" , priority_str );
1423+ LOG ( log , ERROR , "ERROR: Unknown priority type of '%s'. Returning LOW to be safe.\n" , priority_str );
14191424 return LOW ;
14201425 }
14211426}
14221427
1423- static ds3_job_request_type _match_request_type (const xmlChar * request_type ) {
1428+ static ds3_job_request_type _match_request_type (const ds3_log * log , const xmlChar * request_type ) {
14241429 if (xmlStrcmp (request_type , (const xmlChar * ) "PUT" ) == 0 ) {
14251430 return PUT ;
14261431 }
14271432 else if (xmlStrcmp (request_type , (const xmlChar * ) "GET" ) == 0 ) {
14281433 return GET ;
14291434 }
14301435 else {
1431- fprintf ( stderr , "ERROR: Unknown request type of '%s'. Returning GET for safety.\n" , request_type );
1436+ LOG ( log , ERROR , "ERROR: Unknown request type of '%s'. Returning GET for safety.\n" , request_type );
14321437 return GET ;
14331438 }
14341439}
14351440
1436- static ds3_write_optimization _match_write_optimization (const xmlChar * text ) {
1441+ static ds3_write_optimization _match_write_optimization (const ds3_log * log , const xmlChar * text ) {
14371442 if (xmlStrcmp (text , (const xmlChar * ) "CAPACITY" ) == 0 ) {
14381443 return CAPACITY ;
14391444 }
14401445 else if (xmlStrcmp (text , (const xmlChar * ) "PERFORMANCE" ) == 0 ) {
14411446 return PERFORMANCE ;
14421447 }
14431448 else {
1444- fprintf ( stderr , "ERROR: Unknown write optimization of '%s'. Returning CAPACITY for safety.\n" , text );
1449+ LOG ( log , ERROR , "ERROR: Unknown write optimization of '%s'. Returning CAPACITY for safety.\n" , text );
14451450 return CAPACITY ;
14461451 }
14471452}
14481453
1449- static ds3_chunk_ordering _match_chunk_order (const xmlChar * text ) {
1454+ static ds3_chunk_ordering _match_chunk_order (const ds3_log * log , const xmlChar * text ) {
14501455 if (xmlStrcmp (text , (const xmlChar * ) "IN_ORDER" ) == 0 ) {
14511456 return IN_ORDER ;
14521457 }
14531458 else if (xmlStrcmp (text , (const xmlChar * ) "NONE" ) == 0 ) {
14541459 return NONE ;
14551460 }
14561461 else {
1457- fprintf ( stderr , "ERROR: Unknown chunk processing order guaruntee value of '%s'. Returning IN_ORDER for safety.\n" , text );
1462+ LOG ( log , ERROR , "ERROR: Unknown chunk processing order guaruntee value of '%s'. Returning IN_ORDER for safety.\n" , text );
14581463 return NONE ;
14591464 }
14601465}
14611466
1462- static ds3_job_status _match_job_status (const xmlChar * text ) {
1467+ static ds3_job_status _match_job_status (const ds3_log * log , const xmlChar * text ) {
14631468 if (xmlStrcmp (text , (const xmlChar * ) "IN_PROGRESS" ) == 0 ) {
14641469 return IN_PROGRESS ;
14651470 }
@@ -1470,7 +1475,7 @@ static ds3_job_status _match_job_status(const xmlChar* text) {
14701475 return CANCELED ;
14711476 }
14721477 else {
1473- fprintf ( stderr , "ERROR: Unknown job status value of '%s'. Returning IN_PROGRESS for safety.\n" , text );
1478+ LOG ( log , ERROR , "ERROR: Unknown job status value of '%s'. Returning IN_PROGRESS for safety.\n" , text );
14741479 return IN_PROGRESS ;
14751480 }
14761481}
@@ -1551,39 +1556,39 @@ static ds3_error* _parse_master_object_list(const ds3_log* log, xmlDocPtr doc, d
15511556 if (text == NULL ) {
15521557 continue ;
15531558 }
1554- response -> priority = _match_priority (text );
1559+ response -> priority = _match_priority (log , text );
15551560 xmlFree (text );
15561561 }
15571562 else if (attribute_equal (attribute , "RequestType" ) == true) {
15581563 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15591564 if (text == NULL ) {
15601565 continue ;
15611566 }
1562- response -> request_type = _match_request_type (text );
1567+ response -> request_type = _match_request_type (log , text );
15631568 xmlFree (text );
15641569 }
15651570 else if (attribute_equal (attribute , "WriteOptimization" ) == true) {
15661571 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15671572 if (text == NULL ) {
15681573 continue ;
15691574 }
1570- response -> write_optimization = _match_write_optimization (text );
1575+ response -> write_optimization = _match_write_optimization (log , text );
15711576 xmlFree (text );
15721577 }
15731578 else if (attribute_equal (attribute , "ChunkClientProcessingOrderGuarantee" ) == true) {
15741579 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15751580 if (text == NULL ) {
15761581 continue ;
15771582 }
1578- response -> chunk_order = _match_chunk_order (text );
1583+ response -> chunk_order = _match_chunk_order (log , text );
15791584 xmlFree (text );
15801585 }
15811586 else if (attribute_equal (attribute , "Status" ) == true) {
15821587 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15831588 if (text == NULL ) {
15841589 continue ;
15851590 }
1586- response -> status = _match_job_status (text );
1591+ response -> status = _match_job_status (log , text );
15871592 xmlFree (text );
15881593 }
15891594 else {
@@ -2080,7 +2085,6 @@ void ds3_free_service_response(ds3_get_service_response* response){
20802085void ds3_free_bulk_response (ds3_bulk_response * response ) {
20812086 int i ;
20822087 if (response == NULL ) {
2083- fprintf (stderr , "Bulk response was NULL\n" );
20842088 return ;
20852089 }
20862090
@@ -2116,7 +2120,6 @@ void ds3_free_bulk_response(ds3_bulk_response* response) {
21162120
21172121void ds3_free_owner (ds3_owner * owner ) {
21182122 if (owner == NULL ) {
2119- fprintf (stderr , "Owner was NULL\n" );
21202123 return ;
21212124 }
21222125 if (owner -> name != NULL ) {
0 commit comments