static int prov_sc_get_record(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, const char* id, void** handle_ptr, HANDLE_FUNCTION_VECTOR vector, const char* path_format)
{
    int result = 0;

    if (prov_client == NULL)
    {
        LogError("Invalid Provisioning Client Handle");
        result = __FAILURE__;
    }
    else if (id == NULL)
    {
        LogError("Invalid id");
        result = __FAILURE__;
    }
    else if (handle_ptr == NULL)
    {
        LogError("Invalid handle");
        result = __FAILURE__;
    }
    else
    {
        STRING_HANDLE registration_path = create_registration_path(path_format, id);
        if (registration_path == NULL)
        {
            LogError("Failed to construct a registration path");
            result = __FAILURE__;
        }
        else
        {
            HTTP_HEADERS_HANDLE request_headers;
            if ((request_headers = construct_http_headers(prov_client, NULL, HTTP_CLIENT_REQUEST_GET)) == NULL)
            {
                LogError("Failure constructing http headers");
                result = __FAILURE__;
            }
            else
            {
                result = rest_call(prov_client, HTTP_CLIENT_REQUEST_GET, STRING_c_str(registration_path), request_headers, NULL);

                if (result == 0)
                {
                    void* handle;
                    if ((handle = vector.deserializeFromJson(prov_client->response)) == NULL)
                    {
                        LogError("Failure constructing new enrollment structure from json response");
                        result = __FAILURE__;
                    }
                    *handle_ptr = handle;
                }
                clear_response(prov_client);
            }
            HTTPHeaders_Free(request_headers);
        }
        STRING_delete(registration_path);
    }

    return result;
}
Пример #2
0
void li_gnutls_ocsp_free(liGnuTLSOCSP *ocsp) {
	if (NULL != ocsp->responses) {
		guint i;
		for (i = 0; i < ocsp->responses->len; ++i) {
			ocsp_response* response = &g_array_index(ocsp->responses, ocsp_response, i);
			clear_response(response);
		}
		g_array_free(ocsp->responses, TRUE);
	}
	memset(ocsp, 0, sizeof(*ocsp));
	g_slice_free(liGnuTLSOCSP, ocsp);
}
Пример #3
0
int httpUtil::parse_response(const char* source,uint32_t len) {
    if(!source||len==0) {
        return -1;
    }
    clear_response();
    char* pheadEnd=strstr(source,"\r\n\r\n");
    if(pheadEnd==0) {
        return -1;
    }
    uint32_t  headlen=pheadEnd+4-source;
    if(headlen==0) {
        return -1;
    }
    char* headbuff=new char[headlen+1];
    if(!headbuff) {
        return -1;
    }
    memset(headbuff,0,headlen+1);
    memcpy(headbuff,source,headlen);
    int contentLenRet=0;
    int transEncodRet=0;
    get_header_field(headbuff,_response_firstLine,"HTTP/");
    get_header_field(headbuff,_response_date,"Date: ");
    contentLenRet=get_header_field(headbuff,_response_contentLength,"Content-Length: ");
    get_header_field(headbuff,_response_contentType,"Content-Type: ");
    get_header_field(headbuff,_response_connection,"Connection: ");
    transEncodRet=get_header_field(headbuff,_response_transferEncoding,"Transfer-Encoding: ");
    dissect_response_firstLine();
    const char* pentity=pheadEnd+4;
    uint32_t entitylen=len-headlen;
    if(contentLenRet==0) {
        _response_payload.append(pentity,entitylen);
    }
    else if(transEncodRet==0) {
        dissect_response_chunked_transfer_entity(pentity,entitylen);
        uint32_t contentLen=_response_payload.length();
        ostringstream ost;
        ost<<contentLen;
        _response_contentLength=ost.str();

    }
    delete [] headbuff;
    return 0;
}
Пример #4
0
/* pass ownership of der_data */
static gboolean add_response(liServer *srv, liGnuTLSOCSP *ocsp, gnutls_datum_t* der_data) {
	ocsp_response response;
	int r;
	guint i;

	memset(&response, 0, sizeof(response));

	response.resp_data = *der_data;
	der_data->data = NULL; der_data->size = 0;

	if (GNUTLS_E_SUCCESS > (r = gnutls_ocsp_resp_init(&response.resp))) {
		ERROR(srv, "gnutls_ocsp_resp_init (%s): %s",
			gnutls_strerror_name(r), gnutls_strerror(r));
		goto error;
	}

	if (GNUTLS_E_SUCCESS > (r = gnutls_ocsp_resp_import(response.resp, &response.resp_data))) {
		ERROR(srv, "gnutls_ocsp_resp_import (%s): %s",
			gnutls_strerror_name(r), gnutls_strerror(r));
		goto error;
	}

	response.certificates = g_array_new(FALSE, TRUE, sizeof(ocsp_response_cert_entry));
	for (i = 0; ; ++i) {
		ocsp_response_cert_entry entry;

		r = get_entry(srv, &entry, response.resp, i);
		if (GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE == r) break; /* got them all */
		if (GNUTLS_E_SUCCESS > r) goto error;

		g_array_append_vals(response.certificates, &entry, 1);

		if (entry.serial.size > ocsp->max_serial_length) ocsp->max_serial_length = entry.serial.size;
		if (entry.issuer_name_hash.size > ocsp->max_hash_length) ocsp->max_hash_length = entry.issuer_name_hash.size;
	}

	g_array_append_vals(ocsp->responses, &response, 1);
	return TRUE;

error:
	clear_response(&response);
	return FALSE;
}
static int prov_sc_delete_record_by_param(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, const char* id, const char* etag, const char* path_format)
{
    int result = 0;

    if (prov_client == NULL)
    {
        LogError("Invalid Provisioning Client Handle");
        result = __FAILURE__;
    }
    else if (id == NULL)
    {
        LogError("Invalid Id");
        result = __FAILURE__;
    }
    else
    {
        STRING_HANDLE registration_path = create_registration_path(path_format, id);
        if (registration_path == NULL)
        {
            LogError("Failed to construct a registration path");
            result = __FAILURE__;
        }
        else
        {
            HTTP_HEADERS_HANDLE request_headers;
            if ((request_headers = construct_http_headers(prov_client, etag, HTTP_CLIENT_REQUEST_DELETE)) == NULL)
            {
                LogError("Failure constructing http headers");
                result = __FAILURE__;
            }
            else
            {
                result = rest_call(prov_client, HTTP_CLIENT_REQUEST_DELETE, STRING_c_str(registration_path), request_headers, NULL);
                clear_response(prov_client);
            }
            HTTPHeaders_Free(request_headers);
        }
        STRING_delete(registration_path);
    }

    return result;
}
static int prov_sc_query_records(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, PROVISIONING_QUERY_SPECIFICATION* query_spec, char** cont_token_ptr, PROVISIONING_QUERY_RESPONSE** query_res_ptr, const char* path_format)
{
    int result = 0;

    if (prov_client == NULL)
    {
        LogError("Invalid Provisioning Client Handle");
        result = __FAILURE__;
    }
    else if (query_spec == NULL || query_spec->version != PROVISIONING_QUERY_SPECIFICATION_VERSION_1)
    {
        LogError("Invalid Query details");
        result = __FAILURE__;
    }
    else if (cont_token_ptr == NULL)
    {
        LogError("Invalid Continuation Token pointer");
        result = __FAILURE__;
    }
    else if (query_res_ptr == NULL)
    {
        LogError("Invalid Query Response pointer");
        result = __FAILURE__;
    }
    else
    {
        char* content = NULL;

        //do not serialize the query specification if there is no query_string (i.e. DRS query)
        if ((query_spec->query_string != NULL) && ((content = querySpecification_serializeToJson(query_spec)) == NULL))
        {
            LogError("Failure serializing query specification");
            result = __FAILURE__;
        }
        else
        {
            STRING_HANDLE registration_path = create_registration_path(path_format, query_spec->registration_id);
            if (registration_path == NULL)
            {
                LogError("Failed to construct a registration path");
                result = __FAILURE__;
            }
            else
            {
                HTTP_HEADERS_HANDLE request_headers;
                if ((request_headers = construct_http_headers(prov_client, NULL, HTTP_CLIENT_REQUEST_POST)) == NULL)
                {
                    LogError("Failure constructing http headers");
                    result = __FAILURE__;
                }
                else if ((add_query_headers(request_headers, query_spec->page_size, *cont_token_ptr)) != 0)
                {
                    LogError("Failure adding query headers");
                    result = __FAILURE__;
                }
                else
                {
                    result = rest_call(prov_client, HTTP_CLIENT_REQUEST_POST, STRING_c_str(registration_path), request_headers, content);

                    if (result == 0)
                    {
                        const char* resp_type = NULL;
                        char* new_cont_token = NULL;
                        PROVISIONING_QUERY_TYPE type;

                        if (get_response_headers(prov_client, &new_cont_token, &resp_type) != 0)
                        {
                            LogError("Failure reading response headers");
                            result = __FAILURE__;
                        }
                        else if ((type = queryType_stringToEnum(resp_type)) == QUERY_TYPE_INVALID)
                        {
                            LogError("Failure to parse response type");
                            result = __FAILURE__;
                        }
                        else if ((*query_res_ptr = queryResponse_deserializeFromJson(prov_client->response, type)) == NULL)
                        {
                            LogError("Failure deserializing query response");
                            result = __FAILURE__;
                        }
                        free(*cont_token_ptr);
                        *cont_token_ptr = new_cont_token;
                    }
                    else
                    {
                        LogError("Rest call failed");
                    }
                    clear_response(prov_client);
                }
                HTTPHeaders_Free(request_headers);
            }
            STRING_delete(registration_path);
        }
        free(content);
    }

    return result;
}
static int prov_sc_run_bulk_operation(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, PROVISIONING_BULK_OPERATION* bulk_op, PROVISIONING_BULK_OPERATION_RESULT** bulk_res_ptr , const char* path_format)
{
    int result = 0;

    if (prov_client == NULL)
    {
        LogError("Invalid Provisioning Client Handle");
        result = __FAILURE__;
    }
    else if (bulk_op == NULL)
    {
        LogError("Invalid Bulk Op");
        result = __FAILURE__;
    }
    else if (bulk_op->version != PROVISIONING_BULK_OPERATION_VERSION_1)
    {
        LogError("Invalid Bulk Op Version #");
        result = __FAILURE__;
    }
    else if (bulk_res_ptr == NULL)
    {
        LogError("Invalid Bulk Op Result pointer");
        result = __FAILURE__;
    }
    else
    {
        char* content;
        if ((content = bulkOperation_serializeToJson(bulk_op)) == NULL)
        {
            LogError("Failure serializing bulk operation");
            result = __FAILURE__;
        }
        else
        {
            STRING_HANDLE registration_path = create_registration_path(path_format, NULL);
            if (registration_path == NULL)
            {
                LogError("Failed to construct a registration path");
                result = __FAILURE__;
            }
            else
            {
                HTTP_HEADERS_HANDLE request_headers;
                if ((request_headers = construct_http_headers(prov_client, NULL, HTTP_CLIENT_REQUEST_POST)) == NULL)
                {
                    LogError("Failure constructing http headers");
                    result = __FAILURE__;
                }
                else
                {
                    result = rest_call(prov_client, HTTP_CLIENT_REQUEST_POST, STRING_c_str(registration_path), request_headers, content);
                    
                    if (result == 0)
                    {
                        if ((*bulk_res_ptr = bulkOperationResult_deserializeFromJson(prov_client->response)) == NULL)
                        {
                            LogError("Failure deserializing bulk operation result");
                            result = __FAILURE__;
                        }
                    }
                    else
                    {
                        LogError("Rest call failed");
                    }
                    clear_response(prov_client);
                }
                HTTPHeaders_Free(request_headers);
            }
            STRING_delete(registration_path);
        }
        free(content);
    }

    return result;
}
static int prov_sc_create_or_update_record(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, void** handle_ptr, HANDLE_FUNCTION_VECTOR vector, const char* path_format)
{
    int result = 0;
    void* handle;

    if (prov_client == NULL)
    {
        LogError("Invalid Provisioning Client Handle");
        result = __FAILURE__;
    }
    else if ((handle_ptr == NULL) || ((handle = *handle_ptr) == NULL))
    {
        LogError("Invalid handle");
        result = __FAILURE__;
    }
    else
    {
        char* content;
        if ((content = vector.serializeToJson(handle)) == NULL)
        {
            LogError("Failure serializing enrollment");
            result = __FAILURE__;
        }
        else
        {
            STRING_HANDLE registration_path = NULL;
            const char* id = NULL;
            if ((id = vector.getId(handle)) == NULL)
            {
                LogError("Given model does not have a valid ID");
                result = __FAILURE__;
            }
            else if ((registration_path = create_registration_path(path_format, id)) == NULL)
            {
                LogError("Failed to construct a registration path");
                result = __FAILURE__;
            }
            else
            {
                HTTP_HEADERS_HANDLE request_headers;
                if ((request_headers = construct_http_headers(prov_client, vector.getEtag(handle), HTTP_CLIENT_REQUEST_PUT)) == NULL)
                {
                    LogError("Failure constructing headers");
                    result = __FAILURE__;
                }
                else
                {
                    result = rest_call(prov_client, HTTP_CLIENT_REQUEST_PUT, STRING_c_str(registration_path), request_headers, content);

                    if (result == 0)
                    {
                        INDIVIDUAL_ENROLLMENT_HANDLE new_handle;
                        if ((new_handle = vector.deserializeFromJson(prov_client->response)) == NULL)
                        {
                            LogError("Failure constructing new enrollment structure from json response");
                            result = __FAILURE__;
                        }

                        //Free the user submitted enrollment, and replace the pointer reference to a new enrollment from the provisioning service
                        vector.destroy(handle);
                        *handle_ptr = new_handle;
                    }
                    else
                    {
                        LogError("Rest call failed");
                    }
                    clear_response(prov_client);
                }
                HTTPHeaders_Free(request_headers);
            }
            STRING_delete(registration_path);
        }
        free(content);
    }

    return result;
}
Пример #9
0
			CurlResponse() : _header(""), _body(""){ clear_response(); };