1 /* 2 linphone 3 Copyright (C) 2012 Belledonne Communications, Grenoble, France 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation; either version 2 8 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef SAL_IMPL_H_ 21 #define SAL_IMPL_H_ 22 23 #include "sal/sal.h" 24 #include "belle-sip/belle-sip.h" 25 #include "belle-sip/belle-sdp.h" 26 27 struct Sal{ 28 MSFactory *factory; 29 SalCallbacks callbacks; 30 MSList *pending_auths;/*MSList of SalOp */ 31 belle_sip_stack_t* stack; 32 belle_sip_provider_t *prov; 33 belle_sip_header_user_agent_t* user_agent; 34 belle_sip_listener_t *listener; 35 void *tunnel_client; 36 void *up; /*user pointer*/ 37 int session_expires; 38 unsigned int keep_alive; 39 char *root_ca; 40 char *root_ca_data; 41 char *uuid; 42 int refresher_retry_after; /*retry after value for refresher*/ 43 MSList *supported_tags;/*list of char * */ 44 belle_sip_header_t *supported; 45 bool_t one_matching_codec; 46 bool_t use_tcp_tls_keep_alive; 47 bool_t nat_helper_enabled; 48 bool_t tls_verify; 49 bool_t tls_verify_cn; 50 bool_t use_dates; 51 bool_t auto_contacts; 52 bool_t enable_test_features; 53 bool_t no_initial_route; 54 bool_t enable_sip_update; /*true by default*/ 55 SalOpSDPHandling default_sdp_handling; 56 bool_t pending_trans_checking; /*testing purpose*/ 57 void *ssl_config; 58 bctbx_list_t *supported_content_types; /* list of char* */ 59 }; 60 61 typedef enum SalOpState { 62 SalOpStateEarly=0 63 ,SalOpStateActive 64 ,SalOpStateTerminating /*this state is used to wait until a proceeding state, so we can send the cancel*/ 65 ,SalOpStateTerminated 66 }SalOpState; 67 68 const char* sal_op_state_to_string(SalOpState value); 69 70 typedef enum SalOpDir { 71 SalOpDirIncoming=0 72 ,SalOpDirOutgoing 73 }SalOpDir; 74 typedef enum SalOpType { 75 SalOpUnknown, 76 SalOpRegister, 77 SalOpCall, 78 SalOpMessage, 79 SalOpPresence, 80 SalOpPublish, 81 SalOpSubscribe 82 }SalOpType; 83 84 const char* sal_op_type_to_string(SalOpType type); 85 86 struct SalOp{ 87 SalOpBase base; 88 const belle_sip_listener_callbacks_t *callbacks; 89 SalErrorInfo error_info; 90 SalErrorInfo reason_error_info; 91 belle_sip_client_transaction_t *pending_auth_transaction; 92 belle_sip_server_transaction_t* pending_server_trans; 93 belle_sip_server_transaction_t* pending_update_server_trans; 94 belle_sip_client_transaction_t* pending_client_trans; 95 SalAuthInfo* auth_info; 96 belle_sip_dialog_t* dialog; 97 belle_sip_header_replaces_t *replaces; 98 belle_sip_header_referred_by_t *referred_by; 99 SalMediaDescription *result; 100 belle_sdp_session_description_t *sdp_answer; 101 SalOpState state; 102 SalOpDir dir; 103 belle_sip_refresher_t* refresher; 104 int ref; 105 SalOpType type; 106 SalPrivacyMask privacy; 107 belle_sip_header_event_t *event; /*used by SalOpSubscribe kinds*/ 108 SalOpSDPHandling sdp_handling; 109 int auth_requests; /*number of auth requested for this op*/ 110 bool_t cnx_ip_to_0000_if_sendonly_enabled; 111 bool_t auto_answer_asked; 112 bool_t sdp_offering; 113 bool_t call_released; 114 bool_t manual_refresher; 115 bool_t has_auth_pending; 116 bool_t supports_session_timers; 117 bool_t op_released; 118 }; 119 120 121 belle_sdp_session_description_t * media_description_to_sdp(const SalMediaDescription *sal); 122 int sdp_to_media_description(belle_sdp_session_description_t *sdp, SalMediaDescription *desc); 123 belle_sip_request_t* sal_op_build_request(SalOp *op,const char* method); 124 125 126 void sal_op_call_fill_cbs(SalOp*op); 127 void set_or_update_dialog(SalOp* op, belle_sip_dialog_t* dialog); 128 129 /*return reffed op*/ 130 SalOp* sal_op_ref(SalOp* op); 131 /*return null, destroy op if ref count =0*/ 132 void* sal_op_unref(SalOp* op); 133 void sal_op_release_impl(SalOp *op); 134 135 void sal_op_set_replaces(SalOp* op,belle_sip_header_replaces_t* replaces); 136 void sal_op_set_remote_ua(SalOp*op,belle_sip_message_t* message); 137 int sal_op_send_request(SalOp* op, belle_sip_request_t* request); 138 int sal_op_send_request_with_expires(SalOp* op, belle_sip_request_t* request,int expires); 139 void sal_op_resend_request(SalOp* op, belle_sip_request_t* request); 140 int sal_op_send_and_create_refresher(SalOp* op,belle_sip_request_t* req, int expires,belle_sip_refresher_listener_t listener ); 141 belle_sip_response_t *sal_op_create_response_from_request(SalOp *op, belle_sip_request_t *req, int code); 142 143 /* 144 * return true if both from and to uri are sips 145 * */ 146 bool_t sal_op_is_secure(const SalOp* op); 147 148 void sal_process_authentication(SalOp *op); 149 belle_sip_header_contact_t* sal_op_create_contact(SalOp *op) ; 150 151 bool_t _sal_compute_sal_errors(belle_sip_response_t* response, SalReason* sal_reason, char* reason, size_t reason_size); 152 SalReason _sal_reason_from_sip_code(int code); 153 void sal_op_set_reason_error_info(SalOp *op, belle_sip_message_t *msg); 154 void sal_op_set_error_info_from_response(SalOp *op, belle_sip_response_t *response); 155 /*presence*/ 156 void sal_op_presence_fill_cbs(SalOp*op); 157 /*messaging*/ 158 void sal_op_message_fill_cbs(SalOp*op); 159 void sal_process_incoming_message(SalOp *op,const belle_sip_request_event_t *event); 160 void sal_op_subscribe_fill_cbs(SalOp*op); 161 162 /*call transfer*/ 163 void sal_op_process_refer(SalOp *op, const belle_sip_request_event_t *event, belle_sip_server_transaction_t *tr); 164 void sal_op_call_process_notify(SalOp *op, const belle_sip_request_event_t *event, belle_sip_server_transaction_t *tr); 165 /*create SalAuthInfo by copying username and realm from suth event*/ 166 SalAuthInfo* sal_auth_info_create(belle_sip_auth_event_t* event) ; 167 void sal_add_pending_auth(Sal *sal, SalOp *op); 168 void sal_remove_pending_auth(Sal *sal, SalOp *op); 169 void sal_add_presence_info(SalOp *op, belle_sip_message_t *notify, SalPresenceModel *presence); 170 171 belle_sip_response_t *sal_create_response_from_request(Sal *sal, belle_sip_request_t *req, int code); 172 173 void sal_op_assign_recv_headers(SalOp *op, belle_sip_message_t *incoming); 174 175 SalBodyHandler * sal_op_get_body_handler(SalOp *op, belle_sip_message_t *msg); 176 177 int sal_reason_to_sip_code(SalReason r); 178 179 void _sal_op_add_custom_headers(SalOp *op, belle_sip_message_t *msg); 180 181 SalSubscribeStatus belle_sip_message_get_subscription_state(const belle_sip_message_t *msg); 182 183 184 #endif /* SAL_IMPL_H_ */ 185