A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
Diff: saslclientio.c
- Revision:
- 5:ae49385aff34
- Parent:
- 1:eab586236bfe
- Child:
- 6:641a9672db08
--- a/saslclientio.c Tue Jun 07 10:49:20 2016 -0700 +++ b/saslclientio.c Fri Jul 01 10:42:48 2016 -0700 @@ -57,7 +57,6 @@ void* on_io_open_complete_context; void* on_io_close_complete_context; void* on_io_error_context; - LOGGER_LOG logger_log; SASL_HEADER_EXCHANGE_STATE sasl_header_exchange_state; SASL_CLIENT_NEGOTIATION_STATE sasl_client_negotiation_state; size_t header_bytes_received; @@ -155,7 +154,7 @@ } else { - LOG(sasl_client_io_instance->logger_log, LOG_LINE, "-> Header (AMQP 3.1.0.0)"); + LOG(LOG_TRACE, LOG_LINE, "-> Header (AMQP 3.1.0.0)"); result = 0; } @@ -262,15 +261,15 @@ static void log_incoming_frame(SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance, AMQP_VALUE performative) { - if (sasl_client_io_instance->logger_log != NULL) + if (xlogging_get_log_function() != NULL) { AMQP_VALUE descriptor = amqpvalue_get_inplace_descriptor(performative); if (descriptor != NULL) { - LOG(sasl_client_io_instance->logger_log, 0, "<- "); - LOG(sasl_client_io_instance->logger_log, 0, (char*)get_frame_type_as_string(descriptor)); + LOG(LOG_TRACE, 0, "<- "); + LOG(LOG_TRACE, 0, (char*)get_frame_type_as_string(descriptor)); char* performative_as_string = NULL; - LOG(sasl_client_io_instance->logger_log, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative))); + LOG(LOG_TRACE, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative))); if (performative_as_string != NULL) { amqpalloc_free(performative_as_string); @@ -281,15 +280,15 @@ static void log_outgoing_frame(SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance, AMQP_VALUE performative) { - if (sasl_client_io_instance->logger_log != NULL) + if (xlogging_get_log_function() != NULL) { AMQP_VALUE descriptor = amqpvalue_get_inplace_descriptor(performative); if (descriptor != NULL) { - LOG(sasl_client_io_instance->logger_log, 0, "-> "); - LOG(sasl_client_io_instance->logger_log, 0, (char*)get_frame_type_as_string(descriptor)); + LOG(LOG_TRACE, 0, "-> "); + LOG(LOG_TRACE, 0, (char*)get_frame_type_as_string(descriptor)); char* performative_as_string = NULL; - LOG(sasl_client_io_instance->logger_log, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative))); + LOG(LOG_TRACE, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative))); if (performative_as_string != NULL) { amqpalloc_free(performative_as_string); @@ -349,7 +348,7 @@ sasl_client_io_instance->header_bytes_received++; if (sasl_client_io_instance->header_bytes_received == sizeof(sasl_header)) { - LOG(sasl_client_io_instance->logger_log, LOG_LINE, "<- Header (AMQP 3.1.0.0)"); + LOG(LOG_TRACE, LOG_LINE, "<- Header (AMQP 3.1.0.0)"); switch (sasl_client_io_instance->sasl_header_exchange_state) { @@ -808,7 +807,7 @@ } else { - LOG(sasl_client_io_instance->logger_log, LOG_LINE, "Bad SASL frame"); + LogError("Bad SASL frame"); } } } @@ -834,7 +833,7 @@ handle_error(sasl_client_io_instance); } -CONCRETE_IO_HANDLE saslclientio_create(void* io_create_parameters, LOGGER_LOG logger_log) +CONCRETE_IO_HANDLE saslclientio_create(void* io_create_parameters) { SASLCLIENTIO_CONFIG* sasl_client_io_config = io_create_parameters; SASL_CLIENT_IO_INSTANCE* result; @@ -862,7 +861,7 @@ else { /* Codes_SRS_SASLCLIENTIO_01_089: [saslclientio_create shall create a frame_codec to be used for encoding/decoding frames bycalling frame_codec_create and passing the underlying_io as argument.] */ - result->frame_codec = frame_codec_create(on_frame_codec_error, result, logger_log); + result->frame_codec = frame_codec_create(on_frame_codec_error, result); if (result->frame_codec == NULL) { /* Codes_SRS_SASLCLIENTIO_01_090: [If frame_codec_create fails, then saslclientio_create shall fail and return NULL.] */ @@ -886,7 +885,6 @@ result->on_io_open_complete = NULL; result->on_io_error = NULL; result->on_io_close_complete = NULL; - result->logger_log = logger_log; result->on_bytes_received_context = NULL; result->on_io_open_complete_context = NULL; result->on_io_close_complete_context = NULL; @@ -1028,15 +1026,6 @@ { SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance = (SASL_CLIENT_IO_INSTANCE*)sasl_client_io; - if (sasl_client_io_instance->logger_log != NULL) - { - size_t i; - for (i = 0; i < size; i++) - { - LOG(sasl_client_io_instance->logger_log, 0, " %02x", ((const unsigned char*)buffer)[i]); - } - } - /* Codes_SRS_SASLCLIENTIO_01_019: [If saslclientio_send is called while the SASL client IO state is not IO_STATE_OPEN, saslclientio_send shall fail and return a non-zero value.] */ if (sasl_client_io_instance->io_state != IO_STATE_OPEN) {