Iray SDK API nvidia_logo_transpbg.gif Up
http.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_HTTP_H
8#define MI_NEURAYLIB_HTTP_H
9
10#include <cstdarg>
11#include <cstdio>
12
14#include <mi/neuraylib/idata.h>
15
16namespace mi {
17
18namespace http { class IConnection; class IWeb_socket; }
19namespace neuraylib { class IBuffer; }
20
61namespace http {
62
80{
81public:
83 virtual const char* get_request_line() const = 0;
84
86 virtual const char* get_command() const = 0;
87
89 virtual const char* get_protocol() const = 0;
90
94 virtual void set_url( const char* url) = 0;
95
97 virtual const char* get_url() const = 0;
98
103 virtual void set_header( const char* key, const char* value) = 0;
104
108 virtual void remove_header( const char* key) = 0;
109
114 virtual const char* get_header( const char* key) const = 0;
115
127 virtual bool get_header(
128 Size index, const char** key_pointer, const char** value_pointer) const = 0;
129
137 virtual void set_argument( const char* key, const char* value) = 0;
138
145 virtual void add_argument( const char* key, const char* value) = 0;
146
152 virtual void remove_argument(const char* key) = 0;
153
162 virtual const char* get_argument( const char* key) const = 0;
163
175 virtual bool get_argument(
176 Size index, const char** key_pointer, const char** value_pointer) const = 0;
177
181 virtual const char* get_body() const = 0;
182};
183
197{
198public:
203 virtual void set_result_code( Sint32 code, const char* message) = 0;
204
206 virtual Sint32 get_result_code() const = 0;
207
212 virtual void set_header( const char* key, const char* value) = 0;
213
217 virtual void remove_header( const char* key) = 0;
218
223 virtual const char* get_header( const char* key) const = 0;
224
236 virtual bool get_header(
237 Size index, const char** key_pointer, const char** value_pointer) const = 0;
238
240 virtual bool was_sent() const = 0;
241};
242
249class IData_handler : public
250 mi::base::Interface_declare<0x723054d8,0xdfa7,0x4475,0xbc,0xb4,0x44,0x23,0x25,0xea,0x52,0x50>
251{
252public:
260 virtual neuraylib::IBuffer* handle( IConnection* connection, neuraylib::IBuffer* buffer) = 0;
261};
262
277{
278public:
280 virtual const char* get_peer_address() = 0;
281
283 virtual const char* get_local_address() = 0;
284
293 virtual bool print( const char* string) = 0;
294
304 bool printf( const char* string, ...)
305#ifdef MI_COMPILER_GCC
306 __attribute__((format(printf, 2, 3)))
307#endif
308 {
309 va_list args;
310 va_start( args, string);
311 char buffer[16384];
312#ifdef MI_COMPILER_MSC
313 vsnprintf_s( &buffer[0], sizeof( buffer), sizeof( buffer)-1, string, args);
314#else
315 vsnprintf( &buffer[0], sizeof( buffer), string, args);
316#endif
317 bool result = this->print( &buffer[0]);
318 va_end( args);
319 return result;
320 }
321
331 virtual bool enqueue( neuraylib::IBuffer* buffer) = 0;
332
336 virtual Sint32 flush() = 0;
337
341 virtual bool check_error() = 0;
342
344 virtual IRequest* get_request() = 0;
345
347 virtual IResponse* get_response() = 0;
348
355 virtual void add_data_handler( IData_handler* handler) = 0;
356
365 virtual void set_data_attachment( const char* key, IData* value) = 0;
366
375 virtual IData* get_data_attachment( const char* key) = 0;
376
392 template<class T>
393 T* get_data_attachment( const char* key)
394 {
395 IData* ptr = get_data_attachment( key);
396 if( !ptr)
397 return 0;
398 T* ptr_T = static_cast<T*>( ptr->get_interface( typename T::IID()));
399 ptr->release();
400 return ptr_T;
401 }
409 virtual void set_attachment( const char* key, const char* value) = 0;
410
418 virtual const char* get_attachment( const char* key) = 0;
419
425 virtual void remove_attachment( const char* key) = 0;
426
438 virtual Sint32 read_data( Size size, char* buffer) = 0;
439
442 virtual bool is_secure_connection() = 0;
443};
444
452 mi::base::Interface_declare<0x70ad6206,0x38f0,0x4f2a,0xb7,0x5d,0x8f,0x90,0x64,0x3e,0xd0,0x06>
453{
454public:
458 virtual void handle( IWeb_socket* web_socket) = 0;
459};
460
467 mi::base::Interface_declare<0xbe989e2c,0xf1e6,0x492a,0xb6,0x42,0x1f,0xd7,0x30,0x1f,0xa2,0x9f>
468{
469public:
475 virtual void handle( IWeb_socket* web_socket, neuraylib::IBuffer* buffer,
476 bool binary_frame) = 0;
477};
478
492class IWeb_socket : public
493 mi::base::Interface_declare<0x52fd1beb,0x4c6f,0x4456,0x86,0x9c,0xfd,0xf4,0x12,0x52,0x0a,0xae>
494{
495public:
499 virtual const char* get_peer_address() const = 0;
500
504 virtual const char* get_local_address() const = 0;
505
509 virtual const char* get_url_path() const = 0;
510
512 enum State
513 {
527 WS_STATE_FORCE_32_BIT = 0xffffffffU
528 };
529
533 virtual State get_state() const = 0;
534
547 virtual void set_state_handler( IWeb_socket_state_handler* handler) = 0;
548
558 virtual void set_data_handler( IWeb_socket_data_handler* handler) = 0;
559
573 virtual Difference write( neuraylib::IBuffer* buffer, bool binary_frame = false) = 0;
574
582 virtual bool print( const char* string, bool binary_frame = false) = 0;
583
590 bool printf( const char* string, ...)
591#ifdef MI_COMPILER_GCC
592 __attribute__((format(printf, 2, 3)))
593#endif
594 {
595 va_list args;
596 va_start( args, string);
597 char buffer[16384];
598#ifdef MI_COMPILER_MSC
599 vsnprintf_s( &buffer[0], sizeof( buffer), sizeof( buffer)-1, string, args);
600#else
601 vsnprintf( &buffer[0], sizeof( buffer), string, args);
602#endif
603 bool result = this->print( &buffer[0]);
604 va_end( args);
605 return result;
606 }
607
609 virtual void close() = 0;
610
613
617 virtual void set_max_payload(Uint64 bytes) = 0;
618
622 virtual Uint64 get_max_payload() = 0;
623};
624
625mi_static_assert( sizeof( IWeb_socket::State) == sizeof( Uint32));
626
636 mi::base::Interface_declare<0xb784d27c,0x3b80,0x432e,0x89,0xa0,0x13,0xe7,0x33,0x04,0x82,0x5c>
637{
638public:
647 virtual bool handle( IWeb_socket* web_socket) = 0;
648};
649
658class IRequest_handler : public
659 mi::base::Interface_declare<0x8747d0dd,0x1e27,0x4413,0xa0,0xd4,0x07,0x60,0x8f,0xed,0xfc,0xf9>
660{
661public:
672 virtual bool handle( IConnection* connection) = 0;
673};
674
688 mi::base::Interface_declare<0xa7fe482e,0x65f8,0x4a4c,0x87,0x21,0xff,0x19,0x21,0x36,0xda,0xe0>
689{
690public:
701 virtual bool handle( IConnection* connection) = 0;
702};
703
712class IResponse_handler : public
713 mi::base::Interface_declare<0xa9386278,0x6938,0x45a7,0xa2,0x3b,0xbb,0x35,0xf7,0xe9,0x28,0x20>
714{
715public:
719 virtual void handle( IConnection* connection) = 0;
720};
721
723class IServer : public
724 mi::base::Interface_declare<0x9923b273,0x082f,0x403a,0x83,0x57,0xcd,0x23,0x9b,0xcf,0x68,0x4c>
725{
726public:
743 virtual Sint32 start( const char* listen_address) = 0;
744
771 const char* listen_address, const char* cert_file,
772 const char* private_key_file, const char* password) = 0;
773
780 virtual void shutdown() = 0;
781
786 virtual Sint32 set_default_mime_type( const char* mime_type) = 0;
787
796 virtual void add_mime_type( const char* extension, const char* mime_type) = 0;
797
802 virtual const char* lookup_mime_type( const char* extension) = 0;
803
807 virtual void install( IRequest_handler* handler) = 0;
808
812 virtual void remove( IRequest_handler* handler) = 0;
813
817 virtual void install( IWeb_socket_handler* handler) = 0;
818
822 virtual void remove( IWeb_socket_handler* handler) = 0;
823
827 virtual void install( ICGIRequest_handler* handler) = 0;
828
832 virtual void remove( ICGIRequest_handler* handler) = 0;
833
837 virtual void install( IResponse_handler* handler) = 0;
838
842 virtual void remove( IResponse_handler* handler) = 0;
843
850 virtual void set_identification( const char* id_string) = 0;
851
853 virtual const char* get_listen_address() = 0;
854
856 virtual const char* get_ssl_listen_address() = 0;
857
862
867
873 virtual void set_keep_alive_timeout( Uint32 nr_of_seconds) = 0;
874
876 virtual Uint32 get_keep_alive_timeout() const = 0;
877
883 virtual void set_send_buffer_size( Uint32 send_buffer_size) = 0;
884
886 virtual Uint32 get_send_buffer_size() const = 0;
887
891 virtual void set_http_post_body_limit( Uint32 http_post_body_limit) = 0;
892
894 virtual Uint32 get_http_post_body_limit() const = 0;
895
904 // try again.
908 virtual void set_concurrent_connection_limit( Uint32 limit ) = 0;
909
912};
913
920class IFactory : public
921 mi::base::Interface_declare<0xddded154,0x4be8,0x42b6,0x81,0x68,0x21,0x16,0xc7,0xbd,0x63,0x40>
922{
923public:
925 virtual IServer* create_server() = 0;
926
942 const char* root_url, const char* root_path, bool is_recursive = true) = 0;
943
952 const char* source_url, const char* target_url) = 0;
953
963 virtual IResponse_handler* create_log_handler( const char* path) = 0;
964
978
993 virtual IWeb_socket* create_client_web_socket( const char* web_socket_address,
994 Float32 connect_timeout) = 0;
995};
996 // end group mi_neuray_http
998
999} // namespace http
1000
1001} // namespace mi
1002
1003#endif // MI_NEURAYLIB_HTTP_H
This interface is the base interface of all types.
Definition: idata.h:297
Mixin class template for deriving new interface declarations.
Definition: interface_declare.h:43
CGI request handlers are responsible for handling HTTP requests.
Definition: http.h:689
virtual bool handle(IConnection *connection)=0
Handles a request coming in on a connection.
The connection class represents a connection from a client to the server.
Definition: http.h:277
virtual IResponse * get_response()=0
Returns the response associated with the connection.
virtual void set_attachment(const char *key, const char *value)=0
Attaches a string attachment to the connection.
virtual bool print(const char *string)=0
Prints a string to the connection.
virtual void add_data_handler(IData_handler *handler)=0
Adds a data handler to the connection.
virtual IRequest * get_request()=0
Returns the request of the connection.
virtual const char * get_local_address()=0
Returns the address of the local side of the connection.
virtual bool enqueue(neuraylib::IBuffer *buffer)=0
Enqueues a buffer to be sent on the connection.
bool printf(const char *string,...) __attribute__((format(printf
Prints a string to the connection.
virtual Sint32 flush()=0
Waits until all enqueued data has been written.
T * get_data_attachment(const char *key)
Returns an attachment from the connection.
Definition: http.h:393
virtual const char * get_attachment(const char *key)=0
Returns a string attachment from the connection.
virtual bool check_error()=0
Indicates whether an error occurred on the connection.
virtual void set_data_attachment(const char *key, IData *value)=0
Attaches an attachment to the connection.
virtual bool is_secure_connection()=0
Query whether this is a secure (i.e.
virtual void remove_attachment(const char *key)=0
Removes an attachment from the connection.
virtual Sint32 read_data(Size size, char *buffer)=0
Reads incoming CGI data into a supplied buffer.
virtual IData * get_data_attachment(const char *key)=0
Returns an attachment from the connection.
virtual const char * get_peer_address()=0
Returns the address of the peer of the connection.
A data handler may be added to a connection.
Definition: http.h:251
virtual neuraylib::IBuffer * handle(IConnection *connection, neuraylib::IBuffer *buffer)=0
Handles data.
The factory can be used to instantiate the built-in HTTP classes.
Definition: http.h:922
virtual IRequest_handler * create_file_handler(const char *root_url, const char *root_path, bool is_recursive=true)=0
Creates a new file handler for the server.
virtual IResponse_handler * create_log_handler(const char *path)=0
Creates a new log handler.
virtual IResponse_handler * create_chunked_encoding_handler()=0
Creates a new chunked encoding handler.
virtual IServer * create_server()=0
Creates a new HTTP server.
virtual IRequest_handler * create_redirect_handler(const char *source_url, const char *target_url)=0
Creates a new redirect handler which will redirect requests to a certain URL to a new URL.
virtual IWeb_socket * create_client_web_socket(const char *web_socket_address, Float32 connect_timeout)=0
Creates a client-side WebSocket connection that will attempt to establish a connection to the specifi...
Request handlers are responsible for handling HTTP requests.
Definition: http.h:660
virtual bool handle(IConnection *connection)=0
Handles a request coming in on a connection.
This interface holds all the parameters of a request.
Definition: http.h:80
virtual const char * get_url() const =0
Returns the URL of the request.
virtual const char * get_body() const =0
Returns the body string.
virtual void add_argument(const char *key, const char *value)=0
Adds an argument to the request.
virtual const char * get_protocol() const =0
Returns the protocol of the request.
virtual const char * get_header(const char *key) const =0
Returns a header from the request.
virtual const char * get_command() const =0
Returns the command of the request.
virtual void remove_header(const char *key)=0
Removes a header from the request.
virtual void set_header(const char *key, const char *value)=0
Changes an existing header of the request or adds a new header to the request.
virtual bool get_header(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the header with the given index.
virtual void set_argument(const char *key, const char *value)=0
Changes an argument of the request or adds an argument to the request.
virtual const char * get_request_line() const =0
Returns the request line of the request.
virtual const char * get_argument(const char *key) const =0
Returns an argument from the request.
virtual bool get_argument(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the argument with the given index.
virtual void remove_argument(const char *key)=0
Removes an argument from the request.
virtual void set_url(const char *url)=0
Sets the URL of the request.
Response handlers can be used to modify responses generated by request handlers.
Definition: http.h:714
virtual void handle(IConnection *connection)=0
Handles a response on a connection.
This interface holds all the parameters of a response.
Definition: http.h:197
virtual void set_header(const char *key, const char *value)=0
Changes a header of the response or adds a header to the response.
virtual bool was_sent() const =0
Indicates whether the response was already sent.
virtual Sint32 get_result_code() const =0
Returns the result code of the response.
virtual const char * get_header(const char *key) const =0
Returns a header from the response.
virtual void remove_header(const char *key)=0
Removes a header from the response.
virtual bool get_header(Size index, const char **key_pointer, const char **value_pointer) const =0
Returns the header with the given index.
virtual void set_result_code(Sint32 code, const char *message)=0
Sets the result code of the response.
The server builds a framework for the handlers.
Definition: http.h:725
virtual void remove(ICGIRequest_handler *handler)=0
Removes a previously installed CGI request handler from the server.
virtual const char * get_listen_address()=0
Returns the listen address of the server.
virtual Uint32 get_concurrent_connection_limit()=0
Returns the current concurrent connection limit.
virtual const char * get_ssl_listen_address()=0
Returns the SSL listen address of the server.
virtual Sint32 start_ssl(const char *listen_address, const char *cert_file, const char *private_key_file, const char *password)=0
Starts the server in SSL mode listening on the given address.
virtual void shutdown()=0
Shuts down a server that has been previously started.
virtual void install(IResponse_handler *handler)=0
Adds a new response handler to the server.
virtual void remove(IRequest_handler *handler)=0
Removes a previously installed request handler from the server.
virtual void remove(IResponse_handler *handler)=0
Removes a previously installed response handler from the server.
virtual void remove(IWeb_socket_handler *handler)=0
Removes a previously installed WebSocket request handler from the server.
virtual void install(IWeb_socket_handler *handler)=0
Adds a new WebSocket request handler to the server.
virtual Uint32 get_http_post_body_limit() const =0
Returns the size limit for the body of HTTP POST requests.
virtual Sint32 set_default_mime_type(const char *mime_type)=0
Sets the default MIME type to be used when no MIME type was found.
virtual void install(IRequest_handler *handler)=0
Adds a new request handler to the server.
virtual Uint32 get_keep_alive_timeout() const =0
Returns the idle timeout for keep-alive connections.
virtual Sint32 start(const char *listen_address)=0
Starts the server listening on the given address.
virtual void add_mime_type(const char *extension, const char *mime_type)=0
Adds a new MIME type to the server.
virtual Size get_nr_of_connections()=0
Returns the number of existing HTTP connections in this server.
virtual void set_send_buffer_size(Uint32 send_buffer_size)=0
Sets the send buffer size of the socket.
virtual Size get_nr_of_active_connections()=0
Returns the number of HTTP connections in this server which actually handle requests.
virtual void install(ICGIRequest_handler *handler)=0
Adds a new CGI request handler to the server.
virtual void set_concurrent_connection_limit(Uint32 limit)=0
Sets the maximum number of concurrent connections this server will accept.
virtual void set_keep_alive_timeout(Uint32 nr_of_seconds)=0
Sets the idle timeout for keep-alive connections.
virtual void set_http_post_body_limit(Uint32 http_post_body_limit)=0
Sets the size limit for the body of HTTP POST requests.
virtual Uint32 get_send_buffer_size() const =0
Returns the send buffer size of the socket.
virtual void set_identification(const char *id_string)=0
Sets the identification string of the server.
virtual const char * lookup_mime_type(const char *extension)=0
Returns the MIME type registered for a certain extension.
A WebSocket data handler that can be installed to a WebSocket connection to handle data arriving at t...
Definition: http.h:468
virtual void handle(IWeb_socket *web_socket, neuraylib::IBuffer *buffer, bool binary_frame)=0
The handle() function is called when new data is received.
WebSocket handlers are responsible for handling WebSocket requests.
Definition: http.h:637
virtual bool handle(IWeb_socket *web_socket)=0
Handles an incoming WebSocket request.
A WebSocket state handler that can be installed to a WebSocket connection to handle events of the Web...
Definition: http.h:453
virtual void handle(IWeb_socket *web_socket)=0
The handle() function is called when the WebSocket changes its state.
The WebSocket connection class represents a connection that is built on top of an HTTP connection.
Definition: http.h:494
virtual void set_max_payload(Uint64 bytes)=0
Set the maximum payload that web socket messages can have.
virtual bool print(const char *string, bool binary_frame=false)=0
Prints a string to the connection.
virtual void set_state_handler(IWeb_socket_state_handler *handler)=0
Sets a state handler to the WebSocket connection.
virtual State get_state() const =0
Returns the state of the connection.
virtual void close()=0
Closes the connection.
virtual Difference write(neuraylib::IBuffer *buffer, bool binary_frame=false)=0
Writes data from a buffer to the connection.
virtual IConnection * get_http_connection()=0
Returns the HTTP connection associated with this WebSocket connection.
virtual void set_data_handler(IWeb_socket_data_handler *handler)=0
Sets a data handler to the WebSocket connection.
State
This class represents different states that a WebSocket can be in.
Definition: http.h:513
@ WS_STATE_CLOSED
The closing handshake has been completed or the or the underlying TCP connection has been closed.
Definition: http.h:524
@ WS_STATE_ERROR
An error has occurred.
Definition: http.h:526
@ WS_STATE_CLOSING
The closing handshake has been started.
Definition: http.h:521
@ WS_STATE_CONNECTED
A connection has been established.
Definition: http.h:519
@ WS_STATE_INIT
The initial state.
Definition: http.h:515
@ WS_STATE_CONNECTING
The client has sent a request and awaits a response.
Definition: http.h:517
virtual const char * get_peer_address() const =0
Returns the peer's address of the connection.
virtual Uint64 get_max_payload()=0
Get the maximum payload.
bool printf(const char *string,...) __attribute__((format(printf
Prints a string to the connection.
virtual const char * get_url_path() const =0
Returns the URL path that the WebSocket request is sent to.
virtual const char * get_local_address() const =0
Returns the local address of the connection.
Abstract interface for a simple buffer with binary data.
Definition: ibuffer.h:25
#define mi_static_assert(expr)
Compile time assertion that raises a compilation error if the constant expression expr evaluates to f...
Definition: assert.h:65
virtual const IInterface * get_interface(const Uuid &interface_id) const =0
Acquires a const interface from another.
virtual Uint32 release() const =0
Decrements the reference count.
unsigned long long Uint64
64-bit unsigned integer.
Definition: types.h:62
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
float Float32
32-bit float.
Definition: types.h:51
signed int Sint32
32-bit signed integer.
Definition: types.h:46
Types.
Mixin class template for deriving new interface declarations.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: neuraylib.h:179