source: azure_iot_hub/trunk/azure_iohub/c-utility/inc/azure_c_shared_utility/httpheaders.h@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 6.4 KB
Line 
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4/** @file httpheaders.h
5* @brief This is a utility module that handles HTTP message-headers.
6*
7* @details An application would use ::HTTPHeaders_Alloc to create a new set of HTTP headers.
8* After getting the handle, the application would build in several headers by
9* consecutive calls to ::HTTPHeaders_AddHeaderNameValuePair. When the headers are
10* constructed, the application can retrieve the stored data by calling one of the
11* following functions:
12* - ::HTTPHeaders_FindHeaderValue - when the name of the header is known and it
13* wants to know the value of that header
14* - ::HTTPHeaders_GetHeaderCount - when the application needs to know the count
15* of all the headers
16* - ::HTTPHeaders_GetHeader - when the application needs to retrieve the
17* <code>name + ": " + value</code> string based on an index.
18*/
19
20#ifndef HTTPHEADERS_H
21#define HTTPHEADERS_H
22
23#include "azure_c_shared_utility/macro_utils.h"
24#include "azure_c_shared_utility/umock_c_prod.h"
25
26#ifdef __cplusplus
27#include <cstddef>
28extern "C" {
29#else
30#include <stddef.h>
31#endif
32
33/*Codes_SRS_HTTP_HEADERS_99_001:[ HttpHeaders shall have the following interface]*/
34
35#define HTTP_HEADERS_RESULT_VALUES \
36HTTP_HEADERS_OK, \
37HTTP_HEADERS_INVALID_ARG, \
38HTTP_HEADERS_ALLOC_FAILED, \
39HTTP_HEADERS_INSUFFICIENT_BUFFER, \
40HTTP_HEADERS_ERROR \
41
42/** @brief Enumeration specifying the status of calls to various APIs in this module.
43*/
44MU_DEFINE_ENUM(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES);
45typedef struct HTTP_HEADERS_HANDLE_DATA_TAG* HTTP_HEADERS_HANDLE;
46
47/**
48 * @brief Produces a @c HTTP_HANDLE that can later be used in subsequent calls to the module.
49 *
50 * This function returns @c NULL in case an error occurs. After successful execution
51 * ::HTTPHeaders_GetHeaderCount will report @c 0 existing headers.
52 *
53 * @return A HTTP_HEADERS_HANDLE representing the newly created collection of HTTP headers.
54 */
55MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Alloc);
56
57/**
58 * @brief De-allocates the data structures allocated by previous API calls to the same handle.
59 *
60 * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
61 */
62MOCKABLE_FUNCTION(, void, HTTPHeaders_Free, HTTP_HEADERS_HANDLE, httpHeadersHandle);
63
64/**
65 * @brief Adds a header record from the @p name and @p value parameters.
66 *
67 * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
68 * @param name The name of the HTTP header to add. It is invalid for
69 * the name to include the ':' character or character codes
70 * outside the range 33-126.
71 * @param value The value to be assigned to the header.
72 *
73 * The function stores the @c name:value pair in such a way that when later
74 * retrieved by a call to ::HTTPHeaders_GetHeader it will return a string
75 * that is @c strcmp equal to @c name+": "+value. If the name already exists
76 * in the collection of headers, the function concatenates the new value
77 * after the existing value, separated by a comma and a space as in:
78 * <code>old-value+", "+new-value</code>.
79 *
80 * @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from
81 * the ::HTTPAPIEX_RESULT enum.
82 */
83MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_AddHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value);
84
85/**
86 * @brief This API performs exactly the same as ::HTTPHeaders_AddHeaderNameValuePair
87 * except that if the header name already exists then the already existing value
88 * will be replaced as opposed to being concatenated to.
89 *
90 * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
91 * @param name The name of the HTTP header to add/replace. It is invalid for
92 * the name to include the ':' character or character codes
93 * outside the range 33-126.
94 * @param value The value to be assigned to the header.
95 *
96 * @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from
97 * the ::HTTPAPIEX_RESULT enum.
98 */
99MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_ReplaceHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value);
100
101/**
102 * @brief Retrieves the value for a previously stored name.
103 *
104 * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
105 * @param name The name of the HTTP header to find.
106 *
107 * @return The return value points to a string that shall be @c strcmp equal
108 * to the original stored string.
109 */
110MOCKABLE_FUNCTION(, const char*, HTTPHeaders_FindHeaderValue, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name);
111
112/**
113 * @brief This API retrieves the number of stored headers.
114 *
115 * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
116 * @param headersCount If non-null, the API writes the number of
117 * into the memory pointed at by this parameter.
118 *
119 * @return Returns @c HTTP_HEADERS_OK when execution is successful or
120 * @c HTTP_HEADERS_ERROR when an error occurs.
121 */
122MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeaderCount, HTTP_HEADERS_HANDLE, httpHeadersHandle, size_t*, headersCount);
123
124/**
125 * @brief This API retrieves the string name+": "+value for the header
126 * element at the given @p index.
127 *
128 * @param handle A valid @c HTTP_HEADERS_HANDLE value.
129 * @param index Zero-based index of the item in the
130 * headers collection.
131 * @param destination If non-null, the header value is written into a
132 * new string a pointer to which is written into this
133 * parameters. It is the caller's responsibility to free
134 * this memory.
135 *
136 * @return Returns @c HTTP_HEADERS_OK when execution is successful or
137 * @c HTTP_HEADERS_ERROR when an error occurs.
138 */
139MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeader, HTTP_HEADERS_HANDLE, handle, size_t, index, char**, destination);
140
141/**
142 * @brief This API produces a clone of the @p handle parameter.
143 *
144 * @param handle A valid @c HTTP_HEADERS_HANDLE value.
145 *
146 * If @p handle is not @c NULL this function clones the content
147 * of the handle to a new handle and returns it.
148 *
149 * @return A @c HTTP_HEADERS_HANDLE containing a cloned copy of the
150 * contents of @p handle.
151 */
152MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Clone, HTTP_HEADERS_HANDLE, handle);
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* HTTPHEADERS_H */
Note: See TracBrowser for help on using the repository browser.