test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / simline / server.h
blob4cc4b945741fdee7fc5201b00f7d442cf82be85b
1 #ifndef __ISDS_SERVER_H
2 #define __ISDS_SERVER_H
4 #include <sys/types.h> /* For pid_t */
5 #include "server_types.h"
6 #include "services.h"
8 struct http_connection; /* Declare opaque not to export http.h */
9 struct http_request; /* Declare opaque not to export http.h */
10 extern char *server_error;
12 /* Save error message if not yet set. The message will be duplicated.
13 * @message is printf(3) formatting string. */
14 void set_server_error(const char *message, ...);
17 /* Creates listening TCP socket on localhost.
18 * Returns the socket descriptor or -1. */
19 int listen_on_socket(void);
22 /* Format socket address as printable string.
23 * @return allocated string or NULL in case of error. */
24 char *socket2address(int socket);
27 struct tls_authentication {
28 const char *authority_certificate; /* PEM CA certificate file name */
29 const char *server_certificate; /* PEM server certificate file name */
30 const char *server_key; /* PEM server private key file name */
31 const char *client_name; /* Client distinguished name.
32 NULL if you do not want to
33 authenticate a client using X.509 */
37 struct arguments_basic_authentication {
38 const char *username; /* Sets required user name server has to require.
39 Set NULL to disable HTTP authentication. */
40 const char *password; /* sets required password server has to require */
41 _Bool isds_deviations; /* is flag to set conformance level. If false,
42 server is compliant to standards (HTTP, SOAP)
43 if not conflicts with ISDS specification.
44 Otherwise server mimics real ISDS implementation
45 as much as possible. */
46 const struct service_configuration *services; /* Array of enabled
47 services. Last name must
48 be SERVICE_END. */
51 /* Do the server protocol.
52 * @connection is HTTP connection
53 * @server_arguments is pointer to structure arguments_basic_authentication
54 * @request is parsed HTTP client request
55 * @return 0 to accept new client, return -1 in case of fatal error. */
56 int server_basic_authentication(const struct http_connection *connection,
57 const void *server_arguments, const struct http_request *request);
59 /* Do the server protocol.
60 * @connection is HTTP connection
61 * @server_arguments is pointer to structure arguments_basic_authentication
62 * @request is parsed HTTP client request
63 * @return 0 to accept new client, return -1 in case of fatal error. */
64 int server_certificate_with_password_authentication(
65 const struct http_connection *connection,
66 const void *server_arguments, const struct http_request *request);
68 struct arguments_otp_authentication {
69 enum auth_otp_method method; /* Selects OTP method to enable */
70 const char *username; /* Sets required user name server has to require.
71 Set NULL to disable HTTP authentication. */
72 const char *password; /* Sets password server has to require */
73 const char *otp; /* Sets OTP code server has to requiere */
74 _Bool isds_deviations; /* Is flag to set conformance level. If false,
75 server is compliant to standards (HTTP, SOAP)
76 if not conflicts with ISDS specification.
77 Otherwise server mimics real ISDS implementation
78 as much as possible. */
79 const struct service_configuration *services; /* Array of enabled
80 services. Last name must
81 be SERVICE_END. */
84 /* Do the server protocol with OTP authentication.
85 * @connection is HTTP connection
86 * @server_arguments is pointer to structure arguments_otp_authentication. It
87 * selects OTP method to enable.
88 * @request is parsed HTTP client requrest
89 * @return 0 to accept new client, return -1 in case of fatal error. */
90 int server_otp_authentication(const struct http_connection *connection,
91 const void *server_arguments, const struct http_request *request);
93 /* Implementation of server that is out of order.
94 * It always sends back SOAP Fault with HTTP error 503.
95 * @connection is HTTP connection
96 * @server_arguments is ununsed pointer
97 * @request is parsed HTTP client request
98 * @return 0 to accept new client, return -1 in case of fatal error. */
99 int server_out_of_order(const struct http_connection *connection,
100 const void *server_arguments, const struct http_request *request);
103 /* Start sever in separate process.
104 * @server_process is PID of forked server
105 * @server_address is automatically allocated TCP address of listening server
106 * @server_implementation points to kind of server to implement. Valid values
107 * are addresses of server_basic_authentication(),
108 * server_otp_authentication(), or server_out_of_order().
109 * @server_arguments is pointer to argument pass to @server_implementation. It
110 * usually contains:
111 * @username sets required user name server has to require. Set NULL to
112 * disable HTTP authentication.
113 * @password sets required password server has to require
114 * socket.
115 * @isds_deviations is flag to set conformance level. If false, server is
116 * compliant to standards (HTTP, SOAP) if not conflicts with ISDS
117 * specification. Otherwise server mimics real ISDS implementation as much
118 * as possible.
119 * @tls sets TLS layer. Pass NULL for plain HTTP.
120 * @return -1 in case of error. */
121 int start_server(pid_t *server_process, char **server_address,
122 int (*server_implementation)(const struct http_connection *,
123 const void *, const struct http_request *),
124 const void *server_arguments, const struct tls_authentication *tls);
127 /* Kill the server process.
128 * Return 0. Return -1 if server could not been stopped. Return 1 if server
129 * crashed. */
130 int stop_server(pid_t server_process);
132 #endif