listener.h 9.17 KB
Newer Older
1 2 3 4 5 6
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation, either version 2 of the License, or
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef belle_sip_listener_h
#define belle_sip_listener_h

23 24
BELLE_SIP_BEGIN_DECLS

25 26 27 28 29 30
typedef struct belle_sip_dialog_terminated_event belle_sip_dialog_terminated_event_t;
typedef struct belle_sip_io_error_event belle_sip_io_error_event_t;
typedef struct belle_sip_request_event belle_sip_request_event_t;
typedef struct belle_sip_response_event belle_sip_response_event_t;
typedef struct belle_sip_timeout_event belle_sip_timeout_event_t;
typedef struct belle_sip_transaction_terminated_event belle_sip_transaction_terminated_event_t;
31
typedef struct belle_sip_auth_event belle_sip_auth_event_t;
jehan's avatar
jehan committed
32 33
typedef struct belle_sip_certificates_chain belle_sip_certificates_chain_t;
typedef struct belle_sip_signing_key belle_sip_signing_key_t;
34

35 36 37 38 39 40 41 42

BELLE_SIP_DECLARE_INTERFACE_BEGIN(belle_sip_listener_t)
	void (*process_dialog_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_dialog_terminated_event_t *event);
	void (*process_io_error)(belle_sip_listener_t *user_ctx, const belle_sip_io_error_event_t *event);
	void (*process_request_event)(belle_sip_listener_t *user_ctx, const belle_sip_request_event_t *event);
	void (*process_response_event)(belle_sip_listener_t *user_ctx, const belle_sip_response_event_t *event);
	void (*process_timeout)(belle_sip_listener_t *user_ctx, const belle_sip_timeout_event_t *event);
	void (*process_transaction_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_transaction_terminated_event_t *event);
43
	void (*process_auth_requested)(belle_sip_listener_t *user_ctx, belle_sip_auth_event_t *event);
44 45 46
BELLE_SIP_DECLARE_INTERFACE_END

#define BELLE_SIP_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_listener_t)
47

48
/*Response event*/
49 50
BELLESIP_EXPORT belle_sip_response_t* belle_sip_response_event_get_response(const belle_sip_response_event_t* event);
BELLESIP_EXPORT belle_sip_client_transaction_t *belle_sip_response_event_get_client_transaction(const belle_sip_response_event_t* event);
Sylvain Berfini's avatar
Sylvain Berfini committed
51
BELLESIP_EXPORT belle_sip_dialog_t *belle_sip_response_event_get_dialog(const belle_sip_response_event_t* event);
52

53
/*Request event*/
54 55 56
BELLESIP_EXPORT belle_sip_request_t* belle_sip_request_event_get_request(const belle_sip_request_event_t* event);
BELLESIP_EXPORT belle_sip_server_transaction_t *belle_sip_request_event_get_server_transaction(const belle_sip_request_event_t* event);
BELLESIP_EXPORT belle_sip_dialog_t *belle_sip_request_event_get_dialog(const belle_sip_request_event_t* event);
57

58
/*Dialog terminated event*/
59
BELLESIP_EXPORT belle_sip_dialog_t* belle_sip_dialog_terminated_event_get_dialog(const belle_sip_dialog_terminated_event_t *event);
60
BELLESIP_EXPORT int belle_sip_dialog_terminated_event_is_expired(const belle_sip_dialog_terminated_event_t *event);
61

62 63 64
/**
 * Timeout Event
 */
Sylvain Berfini's avatar
Sylvain Berfini committed
65
BELLESIP_EXPORT belle_sip_client_transaction_t *belle_sip_timeout_event_get_client_transaction(const belle_sip_timeout_event_t* event);
66 67
belle_sip_server_transaction_t *belle_sip_timeout_event_get_server_transaction(const belle_sip_timeout_event_t* event);

jehan's avatar
jehan committed
68 69 70
/**
 * Transaction Termonated Event
 */
Sylvain Berfini's avatar
Sylvain Berfini committed
71 72
BELLESIP_EXPORT belle_sip_client_transaction_t *belle_sip_transaction_terminated_event_get_client_transaction(const belle_sip_transaction_terminated_event_t* event);
BELLESIP_EXPORT belle_sip_server_transaction_t *belle_sip_transaction_terminated_event_get_server_transaction(const belle_sip_transaction_terminated_event_t* event);
jehan's avatar
jehan committed
73 74


jehan's avatar
jehan committed
75 76 77 78
/**
 * auth event mode
 * */
typedef enum belle_sip_auth_mode {
Simon Morlat's avatar
Simon Morlat committed
79 80
	BELLE_SIP_AUTH_MODE_HTTP_DIGEST, /** Digest authentication has been requested by the server*/
	BELLE_SIP_AUTH_MODE_TLS /** Client certificate has been requested by the server*/
jehan's avatar
jehan committed
81 82
} belle_sip_auth_mode_t;

Sylvain Berfini's avatar
Sylvain Berfini committed
83
BELLESIP_EXPORT void belle_sip_auth_event_destroy(belle_sip_auth_event_t* event);
84
BELLESIP_EXPORT const char* belle_sip_auth_event_get_username(const belle_sip_auth_event_t* event);
jehan's avatar
jehan committed
85
BELLESIP_EXPORT void belle_sip_auth_event_set_username(belle_sip_auth_event_t* event, const char* value);
86

jehan's avatar
jehan committed
87
BELLESIP_EXPORT const char* belle_sip_auth_event_get_userid(const belle_sip_auth_event_t* event);
Sylvain Berfini's avatar
Sylvain Berfini committed
88
BELLESIP_EXPORT void belle_sip_auth_event_set_userid(belle_sip_auth_event_t* event, const char* value);
89

90
BELLESIP_EXPORT const char* belle_sip_auth_event_get_realm(const belle_sip_auth_event_t* event);
jehan's avatar
jehan committed
91
BELLESIP_EXPORT void belle_sip_auth_event_set_realm(belle_sip_auth_event_t* event, const char* value);
92

93 94 95
BELLESIP_EXPORT const char* belle_sip_auth_event_get_domain(const belle_sip_auth_event_t* event);
BELLESIP_EXPORT void belle_sip_auth_event_set_domain(belle_sip_auth_event_t* event, const char* value);

jehan's avatar
jehan committed
96
BELLESIP_EXPORT const char* belle_sip_auth_event_get_passwd(const belle_sip_auth_event_t* event);
97
BELLESIP_EXPORT void belle_sip_auth_event_set_passwd(belle_sip_auth_event_t* event, const char* value);
98

jehan's avatar
jehan committed
99
BELLESIP_EXPORT const char* belle_sip_auth_event_get_ha1(const belle_sip_auth_event_t* event);
Sylvain Berfini's avatar
Sylvain Berfini committed
100
BELLESIP_EXPORT void belle_sip_auth_event_set_ha1(belle_sip_auth_event_t* event, const char* value);
101

jehan's avatar
jehan committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
/**
 * get the authentication mode requested by the server, can be either TLS client certificates of http digest
 * @param event
 * @return  belle_sip_auth_mode_t
 * */
BELLESIP_EXPORT belle_sip_auth_mode_t belle_sip_auth_event_get_mode(const belle_sip_auth_event_t* event);


/**
 * In case of TLS auth, get value of the distinguished name sent by the server
 * @param event
 * @return DN has sent by the server
 *
 */
BELLESIP_EXPORT const char* belle_sip_auth_event_get_distinguished_name(const belle_sip_auth_event_t* event);
/**
 * get client certificate
 * @return  belle_sip_certificate_t*
 * */
BELLESIP_EXPORT belle_sip_certificates_chain_t* belle_sip_auth_event_get_client_certificates_chain(const belle_sip_auth_event_t* event);
/**
 * set client certificate to be sent in answer to the certificate request issued by the server for the DN belle_sip_auth_event_get_distinguished_name() name
 * @return  belle_sip_certificate_t*
 * */
BELLESIP_EXPORT void belle_sip_auth_event_set_client_certificates_chain(belle_sip_auth_event_t* event, belle_sip_certificates_chain_t* value);
/**
 * get client certificate private key
 * @return  belle_sip_signing_key_t*
 * */
BELLESIP_EXPORT belle_sip_signing_key_t* belle_sip_auth_event_get_signing_key(const belle_sip_auth_event_t* event);
/**
 * set the private key attached to the client certificate.
 * @param event belle_sip_auth_event_t
 * @param value belle_sip_signing_key_t signing key
 * */
BELLESIP_EXPORT void belle_sip_auth_event_set_signing_key(belle_sip_auth_event_t* event, belle_sip_signing_key_t* value);


140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/*Io error event*/
/*
 * Give access to the remote host
 * @param event object
 * @return host value the socket is pointing to
 * */
const char* belle_sip_io_error_event_get_host(const belle_sip_io_error_event_t* event);
/*
 * Give access to the used transport
 * @param event object
 * @return host value the socket is pointing to
 * */
const char* belle_sip_io_error_event_get_transport(const belle_sip_io_error_event_t* event);
/*
 * Give access to the remote port
 * @param event object
 * @return port value the socket is pointing to
 * */
unsigned int belle_sip_io_error_event_port(const belle_sip_io_error_event_t* event);

/*
 * Get access to the object involved in this error, can be either belle_sip_dialog_t or belle_sip_transaction_t or belle_sip_provider_t
 * @param event
 * @return belle_sip_object_t source, use belle_sip_object_is_instance_of to check returns type
 * */

Sylvain Berfini's avatar
Sylvain Berfini committed
166
BELLESIP_EXPORT belle_sip_object_t* belle_sip_io_error_event_get_source(const belle_sip_io_error_event_t* event);
167

168

169 170 171 172 173 174 175
struct belle_sip_listener_callbacks{
	void (*process_dialog_terminated)(void *user_ctx, const belle_sip_dialog_terminated_event_t *event);
	void (*process_io_error)(void *user_ctx, const belle_sip_io_error_event_t *event);
	void (*process_request_event)(void *user_ctx, const belle_sip_request_event_t *event);
	void (*process_response_event)(void *user_ctx, const belle_sip_response_event_t *event);
	void (*process_timeout)(void *user_ctx, const belle_sip_timeout_event_t *event);
	void (*process_transaction_terminated)(void *user_ctx, const belle_sip_transaction_terminated_event_t *event);
176
	void (*process_auth_requested)(void *user_ctx, belle_sip_auth_event_t *auth_event);
177
	void (*listener_destroyed)(void *user_ctx);
178 179 180 181 182 183 184 185
};

typedef struct belle_sip_listener_callbacks belle_sip_listener_callbacks_t;

/**
 * Creates an object implementing the belle_sip_listener_t interface.
 * This object passes the events to the callbacks, providing also the user context.
**/
186
BELLESIP_EXPORT belle_sip_listener_t *belle_sip_listener_create_from_callbacks(const belle_sip_listener_callbacks_t *callbacks, void *user_ctx);
187

188 189
BELLE_SIP_END_DECLS

190 191
#endif