source: azure_iot_hub/trunk/azure_iohub/c-utility/inc/azure_c_shared_utility/uws_client.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: 7.3 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#ifndef UWS_CLIENT_H
5#define UWS_CLIENT_H
6
7#include "xio.h"
8#include "azure_c_shared_utility/umock_c_prod.h"
9#include "azure_c_shared_utility/optionhandler.h"
10
11#ifdef __cplusplus
12#include <cstddef>
13#include <cstdint>
14extern "C" {
15#else
16#include <stdbool.h>
17#include <stddef.h>
18#include <stdint.h>
19#endif
20
21typedef struct UWS_CLIENT_INSTANCE_TAG* UWS_CLIENT_HANDLE;
22
23#define WS_SEND_FRAME_RESULT_VALUES \
24 WS_SEND_FRAME_OK, \
25 WS_SEND_FRAME_ERROR, \
26 WS_SEND_FRAME_CANCELLED
27
28MU_DEFINE_ENUM(WS_SEND_FRAME_RESULT, WS_SEND_FRAME_RESULT_VALUES);
29
30#define WS_OPEN_RESULT_VALUES \
31 WS_OPEN_OK, \
32 WS_OPEN_ERROR_UNDERLYING_IO_OPEN_FAILED, \
33 WS_OPEN_ERROR_UNDERLYING_IO_OPEN_CANCELLED, \
34 WS_OPEN_ERROR_NOT_ENOUGH_MEMORY, \
35 WS_OPEN_ERROR_CANNOT_CONSTRUCT_UPGRADE_REQUEST, \
36 WS_OPEN_ERROR_CANNOT_SEND_UPGRADE_REQUEST, \
37 WS_OPEN_ERROR_MULTIPLE_UNDERLYING_IO_OPEN_EVENTS, \
38 WS_OPEN_ERROR_CONSTRUCTING_UPGRADE_REQUEST, \
39 WS_OPEN_ERROR_INVALID_BYTES_RECEIVED_ARGUMENTS, \
40 WS_OPEN_ERROR_BYTES_RECEIVED_BEFORE_UNDERLYING_OPEN, \
41 WS_OPEN_CANCELLED, \
42 WS_OPEN_ERROR_UNDERLYING_IO_ERROR, \
43 WS_OPEN_ERROR_BAD_UPGRADE_RESPONSE, \
44 WS_OPEN_ERROR_BAD_RESPONSE_STATUS, \
45 WS_OPEN_ERROR_BASE64_ENCODE_FAILED
46
47MU_DEFINE_ENUM(WS_OPEN_RESULT, WS_OPEN_RESULT_VALUES);
48
49#define WS_ERROR_VALUES \
50 WS_ERROR_NOT_ENOUGH_MEMORY, \
51 WS_ERROR_BAD_FRAME_RECEIVED, \
52 WS_ERROR_CANNOT_REMOVE_SENT_ITEM_FROM_LIST, \
53 WS_ERROR_UNDERLYING_IO_ERROR, \
54 WS_ERROR_CANNOT_CLOSE_UNDERLYING_IO
55
56MU_DEFINE_ENUM(WS_ERROR, WS_ERROR_VALUES);
57
58#define WS_FRAME_TYPE_UNKNOWN 0x00
59#define WS_FRAME_TYPE_TEXT 0x01
60#define WS_FRAME_TYPE_BINARY 0x02
61
62/* Codes_SRS_UWS_CLIENT_01_324: [ 1000 indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled. ]*/
63/* Codes_SRS_UWS_CLIENT_01_325: [ 1001 indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page. ]*/
64/* Codes_SRS_UWS_CLIENT_01_326: [ 1002 indicates that an endpoint is terminating the connection due to a protocol error. ]*/
65/* Codes_SRS_UWS_CLIENT_01_327: [ 1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message). ]*/
66/* Codes_SRS_UWS_CLIENT_01_328: [ Reserved. The specific meaning might be defined in the future. ]*/
67/* Codes_SRS_UWS_CLIENT_01_329: [ 1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. ]*/
68/* Codes_SRS_UWS_CLIENT_01_330: [ 1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. ]*/
69/* Codes_SRS_UWS_CLIENT_01_331: [ 1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message). ]*/
70/* Codes_SRS_UWS_CLIENT_01_332: [ 1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy. ]*/
71/* Codes_SRS_UWS_CLIENT_01_333: [ 1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process. ]*/
72/* Codes_SRS_UWS_CLIENT_01_334: [ 1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. ]*/
73/* Codes_SRS_UWS_CLIENT_01_336: [ 1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request. ]*/
74/* Codes_SRS_UWS_CLIENT_01_337: [ 1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. ]*/
75/* */
76#define CLOSE_NORMAL 1000
77#define CLOSE_GOING_AWAY 1001
78#define CLOSE_PROTOCOL_ERROR 1002
79#define CLOSE_CANNOT_ACCEPT_DATA_TYPE 1003
80#define CLOSE_UNDEFINED_1004 1004
81#define CLOSE_RESERVED_1005 1005
82#define CLOSE_RESERVED_1006 1006
83#define CLOSE_INCONSISTENT_DATA_IN_MESSAGE 1007
84#define CLOSE_POLICY_VIOLATION 1008
85#define CLOSE_MESSAGE_TOO_BIG 1009
86#define CLOSE_UNSUPPORTED_EXTENSION_LIST 1010
87#define CLOSE_UNEXPECTED_CONDITION 1011
88#define CLOSE_RESERVED_1015 1015
89
90typedef void(*ON_WS_FRAME_RECEIVED)(void* context, unsigned char frame_type, const unsigned char* buffer, size_t size);
91typedef void(*ON_WS_SEND_FRAME_COMPLETE)(void* context, WS_SEND_FRAME_RESULT ws_send_frame_result);
92typedef void(*ON_WS_OPEN_COMPLETE)(void* context, WS_OPEN_RESULT ws_open_result);
93typedef void(*ON_WS_CLOSE_COMPLETE)(void* context);
94typedef void(*ON_WS_PEER_CLOSED)(void* context, uint16_t* close_code, const unsigned char* extra_data, size_t extra_data_length);
95typedef void(*ON_WS_ERROR)(void* context, WS_ERROR error_code);
96
97typedef struct WS_PROTOCOL_TAG
98{
99 const char* protocol;
100} WS_PROTOCOL;
101
102MOCKABLE_FUNCTION(, UWS_CLIENT_HANDLE, uws_client_create, const char*, hostname, unsigned int, port, const char*, resource_name, bool, use_ssl, const WS_PROTOCOL*, protocols, size_t, protocol_count);
103MOCKABLE_FUNCTION(, UWS_CLIENT_HANDLE, uws_client_create_with_io, const IO_INTERFACE_DESCRIPTION*, io_interface, void*, io_create_parameters, const char*, hostname, unsigned int, port, const char*, resource_name, const WS_PROTOCOL*, protocols, size_t, protocol_count)
104MOCKABLE_FUNCTION(, void, uws_client_destroy, UWS_CLIENT_HANDLE, uws_client);
105MOCKABLE_FUNCTION(, int, uws_client_open_async, UWS_CLIENT_HANDLE, uws_client, ON_WS_OPEN_COMPLETE, on_ws_open_complete, void*, on_ws_open_complete_context, ON_WS_FRAME_RECEIVED, on_ws_frame_received, void*, on_ws_frame_received_context, ON_WS_PEER_CLOSED, on_ws_peer_closed, void*, on_ws_peer_closed_context, ON_WS_ERROR, on_ws_error, void*, on_ws_error_context);
106MOCKABLE_FUNCTION(, int, uws_client_close_async, UWS_CLIENT_HANDLE, uws_client, ON_WS_CLOSE_COMPLETE, on_ws_close_complete, void*, on_ws_close_complete_context);
107MOCKABLE_FUNCTION(, int, uws_client_close_handshake_async, UWS_CLIENT_HANDLE, uws_client, uint16_t, close_code, const char*, close_reason, ON_WS_CLOSE_COMPLETE, on_ws_close_complete, void*, on_ws_close_complete_context);
108MOCKABLE_FUNCTION(, int, uws_client_send_frame_async, UWS_CLIENT_HANDLE, uws_client, unsigned char, frame_type, const unsigned char*, buffer, size_t, size, bool, is_final, ON_WS_SEND_FRAME_COMPLETE, on_ws_send_frame_complete, void*, callback_context);
109MOCKABLE_FUNCTION(, void, uws_client_dowork, UWS_CLIENT_HANDLE, uws_client);
110MOCKABLE_FUNCTION(, int, uws_client_set_request_header, UWS_CLIENT_HANDLE, uws_client, const char*, name, const char*, value);
111MOCKABLE_FUNCTION(, int, uws_client_set_option, UWS_CLIENT_HANDLE, uws_client, const char*, option_name, const void*, value);
112MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, uws_client_retrieve_options, UWS_CLIENT_HANDLE, uws_client);
113
114#ifdef __cplusplus
115}
116#endif /* __cplusplus */
117
118#endif /* UWS_CLIENT_H */
Note: See TracBrowser for help on using the repository browser.