Skip to content

Commit

Permalink
Minor cleanups (Azure#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
antkmsft authored Feb 12, 2020
1 parent d108343 commit 778fd89
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 81 deletions.
44 changes: 23 additions & 21 deletions sdk/core/core/inc/az_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <az_result.h>
#include <az_span.h>

#include <stdbool.h>
#include <stdint.h>

#include <_az_cfg_prefix.h>
Expand Down Expand Up @@ -170,7 +171,7 @@ az_http_request_append_header(az_http_request * p_request, az_span key, az_span
* - `index` is out of range.
*/
AZ_NODISCARD az_result
az_http_request_get_header(az_http_request * p_request, int32_t index, az_pair * out_result);
az_http_request_get_header(az_http_request const * p_request, int32_t index, az_pair * out_result);

typedef enum {
AZ_HTTP_RESPONSE_KIND_STATUS_LINE = 0,
Expand All @@ -189,14 +190,15 @@ typedef struct {
} parser;
} _internal;
} az_http_response;

///////////////////////////////////////////////

typedef enum {
// 1xx (information) Status Codes:
AZ_HTTP_STATUS_CODE_CONTINUE = 100,
AZ_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS = 101,
AZ_HTTP_STATUS_CODE_PROCESSING = 102,
AZ_HTTP_STATUS_CODE_EARLYPROCESSING = 103,
AZ_HTTP_STATUS_CODE_EARLY_HINTS = 103,

// 2xx (successful) Status Codes:
AZ_HTTP_STATUS_CODE_OK = 200,
Expand Down Expand Up @@ -234,28 +236,24 @@ typedef enum {
AZ_HTTP_STATUS_CODE_GONE = 410,
AZ_HTTP_STATUS_CODE_LENGTH_REQUIRED = 411,
AZ_HTTP_STATUS_CODE_PRECONDITION_FAILED = 412,
AZ_HTTP_STATUS_CODE_REQUEST_ENTITY_TOO_LARGE = 413,
AZ_HTTP_STATUS_CODE_REQUEST_URI_TOO_LONG = 414,
AZ_HTTP_STATUS_CODE_PAYLOAD_TOO_LARGE = 413,
AZ_HTTP_STATUS_CODE_URI_TOO_LONG = 414,
AZ_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
AZ_HTTP_STATUS_CODE_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
AZ_HTTP_STATUS_CODE_RANGE_NOT_SATISFIABLE = 416,
AZ_HTTP_STATUS_CODE_EXPECTATION_FAILED = 417,
AZ_HTTP_STATUS_CODE_IM_A_TEAPOT = 418,
AZ_HTTP_STATUS_CODE_ENHANCE_YOUR_CALM = 420,
AZ_HTTP_STATUS_CODE_MISDIRECTED_REQUEST = 421,
AZ_HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY = 422,
AZ_HTTP_STATUS_CODE_LOCKED = 423,
AZ_HTTP_STATUS_CODE_FAILED_DEPENDENCY = 424,
AZ_HTTP_STATUS_CODE_TOO_EARLY = 425,
AZ_HTTP_STATUS_CODE_UPGRADE_REQUIRED = 426,
AZ_HTTP_STATUS_CODEPRECONDITION_REQUIRED_ = 428,
AZ_HTTP_STATUS_CODE_PRECONDITION_REQUIRED = 428,
AZ_HTTP_STATUS_CODE_TOO_MANY_REQUESTS = 429,
AZ_HTTP_STATUS_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
AZ_HTTP_STATUS_CODE_NO_RESPONSE = 444,
AZ_HTTP_STATUS_CODE_RETRY_WITH = 449,
AZ_HTTP_STATUS_CODE_BLOCKED_BY_wINDOWS_PARENTAL_cONTROLS = 450,
AZ_HTTP_STATUS_CODE_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
AZ_HTTP_STATUS_CODE_CLIENT_CLOSED_REQUEST = 499,

// 5xx (SERVER error) Status Codes:
AZ_HTTP_STATUS_CODE_INTERLAN_SERVER_ERROR = 500,
// 5xx (server error) Status Codes:
AZ_HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500,
AZ_HTTP_STATUS_CODE_NOT_IMPLEMENTED = 501,
AZ_HTTP_STATUS_CODE_BAD_GATEWAY = 502,
AZ_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE = 503,
Expand All @@ -264,11 +262,8 @@ typedef enum {
AZ_HTTP_STATUS_CODE_VARIANT_ALSO_NEGOTIATES = 506,
AZ_HTTP_STATUS_CODE_INSUFFICIENT_STORAGE = 507,
AZ_HTTP_STATUS_CODE_LOOP_DETECTED = 508,
AZ_HTTP_STATUS_CODE_BANDWIDTH_LIMIT_EXCEEDED = 509,
AZ_HTTP_STATUS_CODE_NOT_EXTENDED = 510,
AZ_HTTP_STATUS_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511,
AZ_HTTP_STATUS_CODE_NETWORK_READ_TIMEOUT_ERROR = 598,
AZ_HTTP_STATUS_CODE_NETWORK_CONNECT_TIMEOUT_ERROR = 599,
} az_http_status_code;

/**
Expand All @@ -285,10 +280,16 @@ typedef struct {

AZ_NODISCARD AZ_INLINE az_result
az_http_response_init(az_http_response * self, az_span http_response) {
*self = (az_http_response){ ._internal
= { .http_response = http_response,
.parser = { .remaining = az_span_null(),
.next_kind = AZ_HTTP_RESPONSE_KIND_STATUS_LINE } } };
*self = (az_http_response){
._internal = {
.http_response = http_response,
.parser = {
.remaining = az_span_null(),
.next_kind = AZ_HTTP_RESPONSE_KIND_STATUS_LINE,
},
},
};

return AZ_OK;
}

Expand Down Expand Up @@ -334,6 +335,7 @@ AZ_NODISCARD AZ_INLINE az_result az_http_response_reset(az_http_response * self)
az_span_ptr(self->_internal.http_response),
0,
az_span_capacity(self->_internal.http_response));

return AZ_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions sdk/core/core/inc/az_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <az_span.h>

#include <stdbool.h>
#include <stdint.h>

#include <_az_cfg_prefix.h>

Expand Down Expand Up @@ -110,8 +111,8 @@ AZ_NODISCARD AZ_INLINE az_result az_json_builder_init(az_json_builder * self, az
return AZ_OK;
}

AZ_NODISCARD AZ_INLINE az_span az_json_builder_span_get(az_json_builder self) {
return self._internal.json;
AZ_NODISCARD AZ_INLINE az_span az_json_builder_span_get(az_json_builder const * self) {
return self->_internal.json;
}

AZ_NODISCARD az_result az_json_builder_append_token(az_json_builder * self, az_json_token token);
Expand Down
1 change: 0 additions & 1 deletion sdk/core/core/inc/az_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <az_result.h>
#include <az_span.h>

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Expand Down
7 changes: 4 additions & 3 deletions sdk/core/core/inc/az_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
#include <_az_cfg_prefix.h>

// TODO - move this into the PAL layer
az_result _az_pal_os_get(az_span * os) {
AZ_INLINE AZ_NODISCARD az_result _az_pal_os_get(az_span * out_os) {

*os = AZ_SPAN_FROM_STR("Unknown OS");
*out_os = AZ_SPAN_FROM_STR("Unknown OS");
// Add specific implementations for each PAL implementation
//
// os = AZ_STR("Unix 1.0.0.0");
// os = AZ_STR("Windows_NT")

return AZ_OK;
}

#include <_az_cfg_suffix.h>

#endif
#endif
1 change: 0 additions & 1 deletion sdk/core/core/inc/az_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include <_az_cfg_prefix.h>

Expand Down
46 changes: 18 additions & 28 deletions sdk/core/core/inc/az_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <az_result.h>

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

Expand Down Expand Up @@ -55,7 +54,7 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; }
// A size of the string literal.
// Details: to make sure that `S` is a `string literal`, we are appending `""`
// to `S`.
#define AZ_STRING_LITERAL_LEN(S) (sizeof(S "") - 1)
#define _az_STRING_LITERAL_LEN(S) (sizeof(S "") - 1)

/**
* Creates a az_span literal which can be used to initialize a constant. For example
Expand All @@ -64,11 +63,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; }
*/
#define AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL) \
{ \
._internal \
= {.ptr = (uint8_t *)STRING_LITERAL, \
.length = AZ_STRING_LITERAL_LEN(STRING_LITERAL), \
.capacity = AZ_STRING_LITERAL_LEN(STRING_LITERAL), \
} \
._internal = { \
.ptr = (uint8_t *)STRING_LITERAL, \
.length = _az_STRING_LITERAL_LEN(STRING_LITERAL), \
.capacity = _az_STRING_LITERAL_LEN(STRING_LITERAL), \
}, \
}

/**
Expand All @@ -84,7 +83,7 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; }
*
*/
AZ_NODISCARD AZ_INLINE az_span az_span_init(uint8_t * ptr, int32_t length, int32_t capacity) {
return (az_span){ ._internal = { .ptr = ptr, .length = length, .capacity = capacity } };
return (az_span){ ._internal = { .ptr = ptr, .length = length, .capacity = capacity, }, };
}

/**
Expand All @@ -104,10 +103,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_from_str(char * str) {
*/
#define AZ_SPAN_LITERAL_FROM_BUFFER(BYTE_BUFFER) \
{ \
._internal \
= {.ptr = BYTE_BUFFER, \
.length = 0, \
.capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])) } \
._internal = { \
.ptr = BYTE_BUFFER, \
.length = 0, \
.capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \
}, \
}

#define AZ_SPAN_FROM_BUFFER(BYTE_BUFFER) (az_span) AZ_SPAN_LITERAL_FROM_BUFFER(BYTE_BUFFER)
Expand All @@ -120,10 +120,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_from_str(char * str) {
*/
#define AZ_SPAN_LITERAL_FROM_INITIALIZED_BUFFER(BYTE_BUFFER) \
{ \
._internal \
= {.ptr = BYTE_BUFFER, \
.length = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \
.capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])) } \
._internal = { \
.ptr = BYTE_BUFFER, \
.length = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \
.capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \
}, \
}

#define AZ_SPAN_FROM_INITIALIZED_BUFFER(BYTE_BUFFER) \
Expand Down Expand Up @@ -178,7 +179,6 @@ AZ_NODISCARD az_result az_span_copy(az_span dst, az_span src, az_span * out);

AZ_NODISCARD az_result az_span_copy_url_encode(az_span dst, az_span src, az_span * out);

// TODO: this will become az_span_append once we remove actions ....
/**
* @brief append az_span if there is enough capacity for it
*
Expand All @@ -188,18 +188,8 @@ AZ_NODISCARD az_result az_span_copy_url_encode(az_span dst, az_span src, az_span
*/
AZ_NODISCARD az_result az_span_append(az_span self, az_span span, az_span * out);

// TODO: remove this signature/function once actions are GONE
/**
* @brief append az_span if there is enough capacity for it
*
* @param self src span where to append
* @param span content to be appended
* @return AZ_NODISCARD az_span_append_
*/
// AZ_NODISCARD az_result az_span_append_(az_span * self, az_span span);

/**
* @brief converts @b src span to zero-terminated srt. Content is copied to @b buffer and then \0 is
* @brief converts @b src span to zero-terminated str. Content is copied to @b buffer and then \0 is
* addeed at the end. Then out_result will be created out of buffer
*
* @param s buffer where to write str
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core/internal/az_contract_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#ifndef _az_CONTRACT_INTERNAL_H
#define _az_CONTRACT_INTERNAL_H

#include <az_result.h>
#include <az_span.h>

#include <stdbool.h>
#include <stddef.h>

#include <_az_cfg_prefix.h>
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/core/internal/az_log_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <az_log.h>
#include <az_span.h>

#include <stdbool.h>

#include <_az_cfg_prefix.h>

void az_log_write(az_log_classification classification, az_span message);
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core/src/az_http_request_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ az_http_request_append_header(az_http_request * p_hrb, az_span key, az_span valu
}

AZ_NODISCARD az_result
az_http_request_get_header(az_http_request * p_hrb, int32_t index, az_pair * out_result) {
az_http_request_get_header(az_http_request const * p_hrb, int32_t index, az_pair * out_result) {
AZ_CONTRACT_ARG_NOT_NULL(p_hrb);
AZ_CONTRACT_ARG_NOT_NULL(out_result);

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core/src/az_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void az_span_swap(az_span a, az_span b) {
}

/**
* @brief converts @b src span to zero-terminated srt. Content is copied to @b buffer and then \0 is
* @brief converts @b src span to zero-terminated str. Content is copied to @b buffer and then \0 is
* addeed at the end. Then out_result will be created out of buffer
*
* @param buffer
Expand Down
1 change: 1 addition & 0 deletions sdk/core/core/test/az_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT

#include <assert.h>
#include <stdio.h>

extern int exit_code;

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core/test/test_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static inline void _reset_log_invocation_status() {
}

static void _log_listener(az_log_classification classification, az_span message) {
// fprintf(stderr, "%.*s\n", (unsigned int)message.size, message.begin);
// fprintf(stderr, "%.*s\n", (unsigned int)az_span_length(message), az_span_ptr(message));
switch (classification) {
case AZ_LOG_HTTP_REQUEST:
_log_invoked_for_http_request = true;
Expand Down
4 changes: 1 addition & 3 deletions sdk/keyvault/keyvault/inc/az_keyvault.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
#ifndef _az_KEYVAULT_H
#define _az_KEYVAULT_H

#include <az_contract_internal.h>
#include <az_credentials.h>
#include <az_http.h>
#include <az_http_pipeline_internal.h>
#include <az_optional_types.h>
#include <az_result.h>
#include <az_span.h>

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include <_az_cfg_prefix.h>
Expand Down Expand Up @@ -62,6 +59,7 @@ AZ_NODISCARD az_result az_keyvault_keys_client_init(
az_keyvault_keys_client_options * options);

typedef az_span json_web_key_type;

AZ_NODISCARD AZ_INLINE json_web_key_type az_keyvault_web_key_type_ec() {
return AZ_SPAN_FROM_STR("EC");
}
Expand Down
1 change: 1 addition & 0 deletions sdk/keyvault/keyvault/src/az_keyvault_client.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT

#include <az_contract_internal.h>
#include <az_credentials_internal.h>
#include <az_http_pipeline_internal.h>
#include <az_json.h>
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault/test/client_key_poc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <az_json.h>
#include <az_keyvault.h>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <_az_cfg.h>
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/blobs/inc/az_storage_blobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#ifndef _az_STORAGE_BLOBS_H
#define _az_STORAGE_BLOBS_H

#include <az_contract_internal.h>
#include <az_credentials.h>
#include <az_http.h>
#include <az_http_pipeline_internal.h>
#include <az_result.h>
#include <az_span.h>

#include <stdint.h>

#include <_az_cfg_prefix.h>

static az_span const AZ_STORAGE_API_VERSION = AZ_SPAN_LITERAL_FROM_STR("2019-02-02");
Expand Down
Loading

0 comments on commit 778fd89

Please sign in to comment.