Created
February 11, 2015 23:32
-
-
Save mpenick/5318ecaaca061e85efcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| /* Stubs to make this compile */ | |
| typedef struct CassCluster_ { | |
| } CassCluster; | |
| typedef enum CassError_ { | |
| CASS_OK = 0 | |
| } CassError; | |
| /* Proposed external SASL interface for the DataStax C/C++ driver */ | |
| typedef enum CassAuthState_ { | |
| CASS_AUTH_STATE_INIT, | |
| CASS_AUTH_STATE_CHALLENGE, | |
| CASS_AUTH_STATE_SUCCESS | |
| } CassAuthState; | |
| typedef struct CassAuth_ { | |
| CassAuthState state; | |
| char* response; | |
| const size_t response_capacity; | |
| const char* challenge_or_token; | |
| const size_t challege_or_token_size; | |
| } CassAuth; | |
| /* | |
| * Callback for interfacing with SASL authentication. | |
| * | |
| * Return -1 if an error occurred otherwise return the size written into the | |
| * response buffer. If the response is bigger than 'response_capacity' then | |
| * return the required size. If the returned size is greater than | |
| * 'response_capacity' then the callback will be recalled with a response | |
| * buffer equal to previously returned size. 0 should be returned for a | |
| * call where 'state' is CASS_AUTH_STATE_SUCCESS; | |
| */ | |
| typedef ssize_t (*CassAuthCallback)(CassAuth* auth, void* data); | |
| CassError | |
| cass_cluster_set_auth_callback(CassCluster* cluster, | |
| CassAuthCallback callback, | |
| void* data); | |
| /* Example usage */ | |
| ssize_t on_auth(CassAuth* auth, void* data) { | |
| size_t required_capcity = 1024; | |
| switch (auth->state) { | |
| case CASS_AUTH_STATE_INIT: | |
| /* Check to see if reponse buffer is big enough */ | |
| if (auth->response_capacity < required_capcity) { | |
| return required_capcity; | |
| } | |
| /* Write into response buffer */ | |
| return required_capacity; | |
| case CASS_AUTH_STATE_CHALLENGE: | |
| /* Check to see if reponse buffer is big enough */ | |
| if (auth->response_capacity < required_capcity) { | |
| return required_capcity; | |
| } | |
| /* Verify challenge */ | |
| /* Write into response buffer */ | |
| return required_capacity; | |
| case CASS_AUTH_STATE_SUCCESS: | |
| /* Use token */ | |
| return 0; | |
| } | |
| } | |
| int main() { | |
| CassCluster* cluster = NULL; /* Create cluster */ | |
| void* some_sasl_object = NULL; /* Initialize SASL object */ | |
| cass_cluster_set_auth_callback(cluster, on_auth, some_sasl_object); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment