static int create_connection(PROV_TRANSPORT_MQTT_INFO* mqtt_info)
{
    int result;
    MQTT_CLIENT_OPTIONS options = { 0 };
    char* username_info;

    if ((username_info = construct_username(mqtt_info)) == NULL)
    {
        LogError("Failure creating username info");
        result = __FAILURE__;
    }
    else if (construct_transport(mqtt_info))
    {
        LogError("Failure constructing transport");
        free(username_info);
        result = __FAILURE__;
    }
    else
    {
        (void)mqtt_client_set_trace(mqtt_info->mqtt_client, mqtt_info->log_trace, false);

        options.username = username_info;
        options.clientId = mqtt_info->registration_id;
        options.useCleanSession = 1;
        options.log_trace = mqtt_info->log_trace;
        options.qualityOfServiceValue = DELIVER_AT_LEAST_ONCE;
        if (mqtt_client_connect(mqtt_info->mqtt_client, mqtt_info->transport_io, &options) != 0)
        {
            xio_destroy(mqtt_info->transport_io);
            mqtt_info->transport_io = NULL;
            LogError("Failure connecting to mqtt server");
            result = __FAILURE__;
        }
        else
        {
            result = 0;
        }
        free(username_info);
    }
    return result;
}
/* setting up/initalizing the connection details */
static int set_connection_details(sspi_auth_ctx* ctx)
{
	SECURITY_STATUS ss;

	if (ctx->scr->username == NULL) {
		ctx->scr->username = get_username_from_context(ctx->r->connection->pool, sspiModuleInfo.functable, 
			&ctx->scr->server_context);
	}

	if (ctx->scr->username == NULL)
		return HTTP_INTERNAL_SERVER_ERROR;
	else
		construct_username(ctx);

	if (ctx->r->user == NULL) {
		ctx->r->user = ctx->scr->username;
		ctx->r->ap_auth_type = ctx->scr->package;
	}

	if (ctx->scr->usertoken == NULL) {
		if ((ss = sspiModuleInfo.functable->ImpersonateSecurityContext(&ctx->scr->server_context)) != SEC_E_OK) {
			return HTTP_INTERNAL_SERVER_ERROR;
		}

		if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY_SOURCE | TOKEN_READ, TRUE, &ctx->scr->usertoken)) {
			sspiModuleInfo.functable->RevertSecurityContext(&ctx->scr->server_context);
			return HTTP_INTERNAL_SERVER_ERROR;
		}

		if ((ss = sspiModuleInfo.functable->RevertSecurityContext(&ctx->scr->server_context)) != SEC_E_OK) {
			return HTTP_INTERNAL_SERVER_ERROR;
		}
	}

	return OK;
}