keygen/src/iam.c
/**
 * iam_send_ep_auth() - sends an endpoint request to XIAM
 * @auth: The endpoint authorization parameters to send (see xiam.NEW_ENDPOINT_AUTH)
 * @token: The session token provided by XCR
 * @ep_resp: A continer to populate with the reponse data
 *
 * @ep_resp must be freed with ep_auth_resp_destroy
 *
 * Return: 1 on success, 0 on failure
 */
sends an endpoint request to XIAM
@auth: The endpoint authorization parameters to send
@token: The session token provided by XCR
@ep_resp: A continer to populate with the reponse data



1 on success, 0 on failure
sends an endpoint request to XIAM @auth : The endpoint authorization parameters to send @token : The session token provided by XCR @ep_resp : A continer to populate with the reponse data 1 on success 0 on failure
int iam_send_ep_auth(struct iam_create_endpoint_request *auth, char *token, struct iam_endpoint *ep_resp)
{
    struct enftun_req api_req = {0};
    char *send_post = NULL;
    char *response = NULL;
    int ret = 1;
    ret = enftun_curl_init(&api_req);
    if (!ret) {
        ret = 0;
        fprintf(stderr, "%s CURL init failed.\n", __func__);
        goto cleanup;
    }
    enftun_req_set_auth(&api_req, token);
    send_post = ep_auth_marshal(auth);
    if (!send_post) {
        ret = 0;
        fprintf(stderr, "%s Could not marshal request.\n", __func__);
        goto cleanup;
    }
    response = enftun_curl_send(&api_req, XIAM_FUNC_EP_AUTH, send_post);
    if (response) {
        ret = ep_auth_resp_unmarshal(response, ep_resp);
        if (!ret) {
            struct iam_error emsg = {0};
            iam_error_unmarshall(response, &emsg);
            if(emsg.error == 500)
                fprintf(stderr, "A server error occured. Please check input parameters.\n");
            else if(emsg.error == 403)
                fprintf(stderr, "An authorization error occured. Please check input parameters.\n");
            else
                fprintf(stderr, "An unknown error occured (%d, %d, %s)\n", emsg.error, emsg.http_error, emsg.reason);
            iam_error_free(&emsg);
            ret = 0;
        }
    } else {
        ret = 0;
        fprintf(stderr, "%s No response received\n", __func__);
    }
cleanup:
    free(response);
    free(send_post);
    enftun_curl_destroy(&api_req);
    return ret;
}
int iam_send_ep_auth ( struct iam_create_endpoint_request * auth , char * token , struct iam_endpoint * ep_resp ) { struct enftun_req api_req = { 0 } ; char * send_post = NULL ; char * response = NULL ; int ret = 1 ; ret = enftun_curl_init ( & api_req ) ; if ( ! ret ) { ret = 0 ; fprintf ( stderr , " \n " , __func__ ) ; goto cleanup ; } enftun_req_set_auth ( & api_req , token ) ; send_post = ep_auth_marshal ( auth ) ; if ( ! send_post ) { ret = 0 ; fprintf ( stderr , " \n " , __func__ ) ; goto cleanup ; } response = enftun_curl_send ( & api_req , XIAM_FUNC_EP_AUTH , send_post ) ; if ( response ) { ret = ep_auth_resp_unmarshal ( response , ep_resp ) ; if ( ! ret ) { struct iam_error emsg = { 0 } ; iam_error_unmarshall ( response , & emsg ) ; if ( emsg . error == 500 ) fprintf ( stderr , " \n " ) ; else if ( emsg . error == 403 ) fprintf ( stderr , " \n " ) ; else fprintf ( stderr , " \n " , emsg . error , emsg . http_error , emsg . reason ) ; iam_error_free ( & emsg ) ; ret = 0 ; } } else { ret = 0 ; fprintf ( stderr , " \n " , __func__ ) ; } cleanup : free ( response ) ; free ( send_post ) ; enftun_curl_destroy ( & api_req ) ; return ret ; }
iam_send_ep_auth() - sends an endpoint request to XIAM
 @auth: The endpoint authorization parameters to send (see xiam.NEW_ENDPOINT_AUTH)
 @token: The session token provided by XCR
 @ep_resp: A continer to populate with the reponse data
iam_send_ep_auth () - sends an endpoint request to XIAM @auth : The endpoint authorization parameters to send ( see xiam . NEW_ENDPOINT_AUTH ) @token : The session token provided by XCR @ep_resp : A continer to populate with the reponse data
/* Prepare the request */ /* Turn the request into JSON */ /* Actually send the request */ /* try to figure out the error */