@@ -357,13 +357,17 @@ static char* _generate_date_string(void) {
357357 return date_string ;
358358}
359359
360- static char * _net_compute_signature (const ds3_creds * creds , http_verb verb , char * resource_name ,
360+ static char * _net_compute_signature (const ds3_log * log , const ds3_creds * creds , http_verb verb , char * resource_name ,
361361 char * date , char * content_type , char * md5 , char * amz_headers ) {
362362 GHmac * hmac ;
363363 gchar * signature ;
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+ char * escaped_str = g_strescape ((char * ) signature_str , NULL );
368+
369+ LOG (log , DEBUG , "signature string: %s" , escaped_str );
370+ g_free (escaped_str );
367371
368372 hmac = g_hmac_new (G_CHECKSUM_SHA1 , (unsigned char * ) creds -> secret_key -> value , creds -> secret_key -> size );
369373 g_hmac_update (hmac , signature_str , -1 );
@@ -467,12 +471,13 @@ static int ds3_curl_logger(CURL *handle, curl_infotype type, char* data, size_t
467471}
468472
469473static 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 ) {
470- _init_curl ();
471-
472474 struct _ds3_request * request = (struct _ds3_request * ) _request ;
473- CURL * handle = curl_easy_init () ;
475+ CURL * handle ;
474476 CURLcode res ;
475477
478+ _init_curl ();
479+ handle = curl_easy_init ();
480+
476481 if (handle ) {
477482 char * url ;
478483
@@ -571,13 +576,12 @@ static ds3_error* _net_process_request(const ds3_client* client, const ds3_reque
571576
572577 date = _generate_date_string ();
573578 date_header = g_strconcat ("Date: " , date , NULL );
574- signature = _net_compute_signature (client -> creds , request -> verb , request -> path -> value , date , "" , "" , "" );
579+ signature = _net_compute_signature (client -> log , client -> creds , request -> verb , request -> path -> value , date , "" , "" , "" );
575580 headers = NULL ;
576581 auth_header = g_strconcat ("Authorization: AWS " , client -> creds -> access_id -> value , ":" , signature , NULL );
577582
578583 headers = curl_slist_append (headers , auth_header );
579584 headers = curl_slist_append (headers , date_header );
580-
581585 headers = _append_headers (headers , request -> headers );
582586
583587 curl_easy_setopt (handle , CURLOPT_HTTPHEADER , headers );
@@ -610,9 +614,14 @@ static ds3_error* _net_process_request(const ds3_client* client, const ds3_reque
610614 error -> error = g_new0 (ds3_error_response , 1 );
611615 error -> error -> status_code = response_data .status_code ;
612616 error -> error -> status_message = ds3_str_init (response_data .status_message -> value );
613- error -> error -> error_body = ds3_str_init_with_size ((char * )response_data .body -> data , response_data .body -> len );
614-
615- 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+ }
616625 g_hash_table_destroy (response_headers );
617626 ds3_str_free (response_data .status_message );
618627 return error ;
@@ -967,7 +976,7 @@ static ds3_bool xml_get_bool_from_attribute(const ds3_log* log, xmlDocPtr doc, s
967976 return result ;
968977}
969978
970- 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 ) {
971980 xmlNodePtr data_ptr ;
972981 xmlNodePtr curr ;
973982 GArray * array = g_array_new (FALSE, TRUE, sizeof (ds3_bucket ));
@@ -984,7 +993,7 @@ static void _parse_buckets(xmlDocPtr doc, xmlNodePtr buckets_node, ds3_get_servi
984993 bucket .name = xml_get_string (doc , data_ptr );
985994 }
986995 else {
987- fprintf ( stderr , "Unknown element: (%s)\n" , data_ptr -> name );
996+ LOG ( log , ERROR , "Unknown element: (%s)\n" , data_ptr -> name );
988997 }
989998 }
990999 g_array_append_val (array , bucket );
@@ -1060,15 +1069,15 @@ ds3_error* ds3_get_service(const ds3_client* client, const ds3_request* request,
10601069 for (child_node = root -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
10611070 if (element_equal (child_node , "Buckets" ) == true) {
10621071 //process buckets here
1063- _parse_buckets (doc , child_node , response );
1072+ _parse_buckets (client -> log , doc , child_node , response );
10641073 }
10651074 else if (element_equal (child_node , "Owner" ) == true) {
10661075 //process owner here
10671076 ds3_owner * owner = _parse_owner (doc , child_node );
10681077 response -> owner = owner ;
10691078 }
10701079 else {
1071- fprintf ( stderr , "Unknown xml element: (%s)\b" , child_node -> name );
1080+ LOG ( client -> log , ERROR , "Unknown xml element: (%s)\b" , child_node -> name );
10721081 }
10731082 }
10741083
@@ -1129,21 +1138,21 @@ static ds3_object _parse_object(xmlDocPtr doc, xmlNodePtr contents_node) {
11291138 return object ;
11301139}
11311140
1132- 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 ) {
11331142 xmlNodePtr child_node ;
11341143 ds3_str * prefix = NULL ;
11351144
11361145 for (child_node = contents_node -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
11371146 if (element_equal (child_node , "Prefix" ) == true) {
11381147 if (prefix ) {
1139- fprintf ( stderr , "More than one Prefix found in CommonPrefixes\n" );
1148+ LOG ( log , WARN , "More than one Prefix found in CommonPrefixes\n" );
11401149 }
11411150 else {
11421151 prefix = xml_get_string (doc , child_node );
11431152 }
11441153 }
11451154 else {
1146- fprintf ( stderr , "Unknown xml element: %s\n" , child_node -> name );
1155+ LOG ( log , ERROR , "Unknown xml element: %s\n" , child_node -> name );
11471156 }
11481157 }
11491158
@@ -1260,11 +1269,11 @@ ds3_error* ds3_get_bucket(const ds3_client* client, const ds3_request* request,
12601269 xmlFree (text );
12611270 }
12621271 else if (element_equal (child_node , "CommonPrefixes" ) == true) {
1263- ds3_str * prefix = _parse_common_prefixes (doc , child_node );
1272+ ds3_str * prefix = _parse_common_prefixes (client -> log , doc , child_node );
12641273 g_array_append_val (common_prefix_array , prefix );
12651274 }
12661275 else {
1267- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1276+ LOG ( client -> log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
12681277 }
12691278 }
12701279
@@ -1327,12 +1336,12 @@ static ds3_bulk_object _parse_bulk_object(const ds3_log* log, xmlDocPtr doc, xml
13271336 response .offset = xml_get_uint64_from_attribute (doc , attribute );
13281337 }
13291338 else {
1330- fprintf ( stderr , "Unknown attribute: (%s)\n" , attribute -> name );
1339+ LOG ( log , ERROR , "Unknown attribute: (%s)\n" , attribute -> name );
13311340 }
13321341 }
13331342
13341343 for (child_node = object_node -> xmlChildrenNode ; child_node != NULL ; child_node = child_node -> next ) {
1335- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1344+ LOG ( log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
13361345 }
13371346
13381347 return response ;
@@ -1367,7 +1376,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13671376 response -> chunk_number = xml_get_uint64_from_attribute (doc , attribute );
13681377 }
13691378 else {
1370- fprintf ( stderr , "Unknown attribute: (%s)\n" , attribute -> name );
1379+ LOG ( log , ERROR , "Unknown attribute: (%s)\n" , attribute -> name );
13711380 }
13721381
13731382 }
@@ -1378,7 +1387,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13781387 g_array_append_val (object_array , object );
13791388 }
13801389 else {
1381- fprintf ( stderr , "Unknown element: (%s)\n" , child_node -> name );
1390+ LOG ( log , ERROR , "Unknown element: (%s)\n" , child_node -> name );
13821391 }
13831392 }
13841393
@@ -1388,7 +1397,7 @@ static ds3_bulk_object_list* _parse_bulk_objects(const ds3_log* log, xmlDocPtr d
13881397 return response ;
13891398}
13901399
1391- 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 ) {
13921401 if (xmlStrcmp (priority_str , (const xmlChar * ) "CRITICAL" ) == 0 ) {
13931402 return CRITICAL ;
13941403 }
@@ -1411,51 +1420,51 @@ static ds3_job_priority _match_priority(const xmlChar* priority_str) {
14111420 return MINIMIZED_DUE_TO_TOO_MANY_RETRIES ;
14121421 }
14131422 else {
1414- 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 );
14151424 return LOW ;
14161425 }
14171426}
14181427
1419- 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 ) {
14201429 if (xmlStrcmp (request_type , (const xmlChar * ) "PUT" ) == 0 ) {
14211430 return PUT ;
14221431 }
14231432 else if (xmlStrcmp (request_type , (const xmlChar * ) "GET" ) == 0 ) {
14241433 return GET ;
14251434 }
14261435 else {
1427- 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 );
14281437 return GET ;
14291438 }
14301439}
14311440
1432- 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 ) {
14331442 if (xmlStrcmp (text , (const xmlChar * ) "CAPACITY" ) == 0 ) {
14341443 return CAPACITY ;
14351444 }
14361445 else if (xmlStrcmp (text , (const xmlChar * ) "PERFORMANCE" ) == 0 ) {
14371446 return PERFORMANCE ;
14381447 }
14391448 else {
1440- 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 );
14411450 return CAPACITY ;
14421451 }
14431452}
14441453
1445- 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 ) {
14461455 if (xmlStrcmp (text , (const xmlChar * ) "IN_ORDER" ) == 0 ) {
14471456 return IN_ORDER ;
14481457 }
14491458 else if (xmlStrcmp (text , (const xmlChar * ) "NONE" ) == 0 ) {
14501459 return NONE ;
14511460 }
14521461 else {
1453- 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 );
14541463 return NONE ;
14551464 }
14561465}
14571466
1458- 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 ) {
14591468 if (xmlStrcmp (text , (const xmlChar * ) "IN_PROGRESS" ) == 0 ) {
14601469 return IN_PROGRESS ;
14611470 }
@@ -1466,7 +1475,7 @@ static ds3_job_status _match_job_status(const xmlChar* text) {
14661475 return CANCELED ;
14671476 }
14681477 else {
1469- 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 );
14701479 return IN_PROGRESS ;
14711480 }
14721481}
@@ -1547,39 +1556,39 @@ static ds3_error* _parse_master_object_list(const ds3_log* log, xmlDocPtr doc, d
15471556 if (text == NULL ) {
15481557 continue ;
15491558 }
1550- response -> priority = _match_priority (text );
1559+ response -> priority = _match_priority (log , text );
15511560 xmlFree (text );
15521561 }
15531562 else if (attribute_equal (attribute , "RequestType" ) == true) {
15541563 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15551564 if (text == NULL ) {
15561565 continue ;
15571566 }
1558- response -> request_type = _match_request_type (text );
1567+ response -> request_type = _match_request_type (log , text );
15591568 xmlFree (text );
15601569 }
15611570 else if (attribute_equal (attribute , "WriteOptimization" ) == true) {
15621571 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15631572 if (text == NULL ) {
15641573 continue ;
15651574 }
1566- response -> write_optimization = _match_write_optimization (text );
1575+ response -> write_optimization = _match_write_optimization (log , text );
15671576 xmlFree (text );
15681577 }
15691578 else if (attribute_equal (attribute , "ChunkClientProcessingOrderGuarantee" ) == true) {
15701579 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15711580 if (text == NULL ) {
15721581 continue ;
15731582 }
1574- response -> chunk_order = _match_chunk_order (text );
1583+ response -> chunk_order = _match_chunk_order (log , text );
15751584 xmlFree (text );
15761585 }
15771586 else if (attribute_equal (attribute , "Status" ) == true) {
15781587 text = xmlNodeListGetString (doc , attribute -> children , 1 );
15791588 if (text == NULL ) {
15801589 continue ;
15811590 }
1582- response -> status = _match_job_status (text );
1591+ response -> status = _match_job_status (log , text );
15831592 xmlFree (text );
15841593 }
15851594 else {
@@ -2076,7 +2085,6 @@ void ds3_free_service_response(ds3_get_service_response* response){
20762085void ds3_free_bulk_response (ds3_bulk_response * response ) {
20772086 int i ;
20782087 if (response == NULL ) {
2079- fprintf (stderr , "Bulk response was NULL\n" );
20802088 return ;
20812089 }
20822090
@@ -2112,7 +2120,6 @@ void ds3_free_bulk_response(ds3_bulk_response* response) {
21122120
21132121void ds3_free_owner (ds3_owner * owner ) {
21142122 if (owner == NULL ) {
2115- fprintf (stderr , "Owner was NULL\n" );
21162123 return ;
21172124 }
21182125 if (owner -> name != NULL ) {
0 commit comments