int authentication_set_option(AUTHENTICATION_HANDLE authentication_handle, const char* name, void* value) { int result; // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_097: [If `authentication_handle` or `name` or `value` is NULL, authentication_set_option shall fail and return a non-zero value] if (authentication_handle == NULL || name == NULL || value == NULL) { LogError("authentication_set_option failed (one of the followin are NULL: authentication_handle=%p, name=%p, value=%p)", authentication_handle, name, value); result = __FAILURE__; } else { AUTHENTICATION_INSTANCE* instance = (AUTHENTICATION_INSTANCE*)authentication_handle; // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_098: [If name matches AUTHENTICATION_OPTION_CBS_REQUEST_TIMEOUT_SECS, `value` shall be saved on `instance->cbs_request_timeout_secs`] if (strcmp(AUTHENTICATION_OPTION_CBS_REQUEST_TIMEOUT_SECS, name) == 0) { instance->cbs_request_timeout_secs = *((size_t*)value); result = RESULT_OK; } // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_124: [If name matches AUTHENTICATION_OPTION_SAS_TOKEN_REFRESH_TIME_SECS, `value` shall be saved on `instance->sas_token_refresh_time_secs`] else if (strcmp(AUTHENTICATION_OPTION_SAS_TOKEN_REFRESH_TIME_SECS, name) == 0) { instance->sas_token_refresh_time_secs = *((size_t*)value); result = RESULT_OK; } // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_125: [If name matches AUTHENTICATION_OPTION_SAS_TOKEN_LIFETIME_SECS, `value` shall be saved on `instance->sas_token_lifetime_secs`] else if (strcmp(AUTHENTICATION_OPTION_SAS_TOKEN_LIFETIME_SECS, name) == 0) { instance->sas_token_lifetime_secs = *((size_t*)value); result = RESULT_OK; } else if (strcmp(AUTHENTICATION_OPTION_SAVED_OPTIONS, name) == 0) { // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_098: [If name matches AUTHENTICATION_OPTION_SAVED_OPTIONS, `value` shall be applied using OptionHandler_FeedOptions] if (OptionHandler_FeedOptions((OPTIONHANDLER_HANDLE)value, authentication_handle) != OPTIONHANDLER_OK) { // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_126: [If OptionHandler_FeedOptions fails, authentication_set_option shall fail and return a non-zero value] LogError("authentication_set_option failed (OptionHandler_FeedOptions failed)"); result = __FAILURE__; } else { result = RESULT_OK; } } else { // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_128: [If name does not match any supported option, authentication_set_option shall fail and return a non-zero value] LogError("authentication_set_option failed (option with name '%s' is not suppported)", name); result = __FAILURE__; } } // Codes_SRS_IOTHUBTRANSPORT_AMQP_AUTH_09_099: [If no errors occur, authentication_set_option shall return 0] return result; }
int xio_setoption(XIO_HANDLE xio, const char* optionName, const void* value) { int result; /* Codes_SRS_XIO_03_030: [If the xio argument or the optionName argument is NULL, xio_setoption shall return a non-zero value.] */ if (xio == NULL || optionName == NULL) { result = __LINE__; } else { XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; if (strcmp(CONCRETE_OPTIONS, optionName) == 0) { /*then value is a pointer to OPTIONHANDLER_HANDLE*/ if (OptionHandler_FeedOptions((OPTIONHANDLER_HANDLE)value, xio_instance->concrete_xio_handle) != OPTIONHANDLER_OK) { LogError("unable to OptionHandler_FeedOptions"); result = __LINE__; } else { result = 0; } } else /*passthrough*/ { /* Codes_SRS_XIO_003_028: [xio_setoption shall pass the optionName and value to the concrete IO implementation specified in xio_create by invoking the concrete_xio_setoption function.] */ /* Codes_SRS_XIO_03_029: [xio_setoption shall return 0 upon success.] */ /* Codes_SRS_XIO_03_031: [If the underlying concrete_xio_setoption fails, xio_setOption shall return a non-zero value.] */ result = xio_instance->io_interface_description->concrete_io_setoption(xio_instance->concrete_xio_handle, optionName, value); } } return result; }