From ffac0b09c2029685cc10ae40f6195832d3f75f82 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Sat, 24 Jun 2023 13:19:11 +0100 Subject: [PATCH 1/2] update hash for incoming transactions to include via branch --- libsofia-sip-ua/nta/nta.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libsofia-sip-ua/nta/nta.c b/libsofia-sip-ua/nta/nta.c index cdd229b1..fc66f178 100644 --- a/libsofia-sip-ua/nta/nta.c +++ b/libsofia-sip-ua/nta/nta.c @@ -685,6 +685,7 @@ static void leg_recv(nta_leg_t *, msg_t *, sip_t *, tport_t *); static void leg_free(nta_agent_t *sa, nta_leg_t *leg); #define NTA_HASH(i, cs) ((i)->i_hash + 26839U * (uint32_t)(cs)) +#define NTA_HASH_WITH_VIA(i, cs, v) ((i)->i_hash + 26839U * (uint32_t)(cs) + (v ? 39581U * msg_hash_string(v) : 0)) HTABLE_PROTOS_WITH(incoming_htable, iht, nta_incoming_t, size_t, hash_value_t); static nta_incoming_t *incoming_create(nta_agent_t *agent, @@ -5695,7 +5696,8 @@ nta_incoming_t *incoming_create(nta_agent_t *agent, irq->irq_tport = tport_ref(tport); } - irq->irq_hash = NTA_HASH(irq->irq_call_id, irq->irq_cseq->cs_seq); + /* DCH: added via branch to hash calculation so when receiving forked invites we can track each as a server txn */ + irq->irq_hash = NTA_HASH_WITH_VIA(irq->irq_call_id, irq->irq_cseq->cs_seq, irq->irq_via->v_branch); incoming_insert(agent, queue, irq); } @@ -6255,7 +6257,8 @@ static nta_incoming_t *incoming_find(nta_agent_t const *agent, assert(cseq); - hash = NTA_HASH(i, cseq->cs_seq); + /* DCH: changed to include not only call-id and cseq but via branch to find server txn */ + hash = NTA_HASH_WITH_VIA(i, cseq->cs_seq, v->v_branch); if (v->v_branch && su_casenmatch(v->v_branch, "z9hG4bK", 7)) magic_branch = v->v_branch + 7; @@ -8275,6 +8278,10 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent, /* Now we are committed in sending the transaction */ orq->orq_request = msg; agent->sa_stats->as_client_tr++; + + /* DCH: this is a client txn, currently I have not made changes to include via branch here + * we may want to do so in the future. + */ orq->orq_hash = NTA_HASH(sip->sip_call_id, sip->sip_cseq->cs_seq); if (orq->orq_user_tport) @@ -9503,6 +9510,7 @@ nta_outgoing_t *outgoing_find(nta_agent_t const *sa, if (cseq == NULL) return NULL; + /* DCH: I have not made changes to include via branch in client txns yet */ hash = NTA_HASH(i, cseq->cs_seq); method = cseq->cs_method; @@ -11441,8 +11449,11 @@ nta_reliable_t *reliable_find(nta_agent_t const *agent, incoming_htable_t const *iht = agent->sa_incoming; nta_incoming_t *irq, **ii; sip_call_id_t const *i = sip->sip_call_id; + sip_via_t const *v = sip->sip_via; sip_rack_t const *rack = sip->sip_rack; - hash_value_t hash = NTA_HASH(i, rack->ra_cseq); + + /* DCH: changed incoming hash (server txns) to include via branch */ + hash_value_t hash = NTA_HASH_WITH_VIA(i, rack->ra_cseq, v->v_branch); /* XXX - add own hash table for 100rel */ From 3d75ced990d818411f0b1ae571fa15dc77b7a738 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Sat, 24 Jun 2023 23:05:18 +0100 Subject: [PATCH 2/2] fix warnings --- libsofia-sip-ua/http/http_header.c | 20 ++++----- libsofia-sip-ua/http/http_parser.c | 4 +- libsofia-sip-ua/msg/msg_date.c | 9 ++-- libsofia-sip-ua/msg/msg_parser.c | 2 +- libsofia-sip-ua/nua/nua_client.c | 5 ++- libsofia-sip-ua/nua/nua_stack.c | 8 ++-- libsofia-sip-ua/nua/nua_stack.h | 6 +-- libsofia-sip-ua/sdp/sdp.c | 6 ++- libsofia-sip-ua/sip/sip_pref_util.c | 4 -- libsofia-sip-ua/stun/stun.c | 41 +++++++++++------ libsofia-sip-ua/stun/stun_internal.h | 3 +- libsofia-sip-ua/su/sofia-sip/heap.h | 4 +- libsofia-sip-ua/su/sofia-sip/htable.h | 4 +- libsofia-sip-ua/su/su_alloc.c | 2 +- libsofia-sip-ua/su/su_localinfo.c | 2 +- libsofia-sip-ua/su/su_socket_port.c | 12 +++-- libsofia-sip-ua/tport/tport_tls.c | 23 ++++++++++ libsofia-sip-ua/tport/ws.c | 64 ++++++++++++++++++++++++++- 18 files changed, 160 insertions(+), 59 deletions(-) diff --git a/libsofia-sip-ua/http/http_header.c b/libsofia-sip-ua/http/http_header.c index 4ae01598..1f362799 100644 --- a/libsofia-sip-ua/http/http_header.c +++ b/libsofia-sip-ua/http/http_header.c @@ -66,18 +66,15 @@ int http_request_complete(msg_t *msg) http_payload_t const *pl; su_home_t *home = msg_home(msg); - if (!http) - return -1; - if (!http->http_request) - return -1; - if (!http->http_host) - return -1; + if (!http) return -1; + if (!http->http_request) return -1; + if (!http->http_host) return -1; - for (pl = http->http_payload; pl; pl = pl->pl_next) - len += pl->pl_len; + for (pl = http->http_payload; pl; pl = pl->pl_next) { + len += pl->pl_len; + } - if (len > UINT32_MAX) - return -1; + if (len > UINT32_MAX) return -1; if (!http->http_content_length) { http->http_content_length = http_content_length_create(home, (uint32_t)len); @@ -89,8 +86,9 @@ int http_request_complete(msg_t *msg) } } - if (!http->http_separator) + if (!http->http_separator) { http->http_separator = http_separator_create(home); + } return 0; } diff --git a/libsofia-sip-ua/http/http_parser.c b/libsofia-sip-ua/http/http_parser.c index 09dd4d21..0733570d 100644 --- a/libsofia-sip-ua/http/http_parser.c +++ b/libsofia-sip-ua/http/http_parser.c @@ -463,8 +463,8 @@ http_method_t http_method_d(char **ss, char const **nname) case 'H': if (MATCH(s, "HEAD")) code = http_method_head; break; case 'O': if (MATCH(s, "OPTIONS")) code = http_method_options; break; case 'P': if (MATCH(s, "POST")) code = http_method_post; - else - if (MATCH(s, "PUT")) code = http_method_put; break; + else if (MATCH(s, "PUT")) code = http_method_put; + break; case 'T': if (MATCH(s, "TRACE")) code = http_method_trace; break; } diff --git a/libsofia-sip-ua/msg/msg_date.c b/libsofia-sip-ua/msg/msg_date.c index 5a8f354f..d96f6ffe 100644 --- a/libsofia-sip-ua/msg/msg_date.c +++ b/libsofia-sip-ua/msg/msg_date.c @@ -143,7 +143,8 @@ int time_d(char const **ss, return -1; *sec = 10 * s[0] + s[1] - 11 * '0'; s += 2; if (*s) { - if (!IS_LWS(*s)) return -1; skip_lws(&s); + if (!IS_LWS(*s)) return -1; + skip_lws(&s); } *ss = s; return 0; @@ -247,8 +248,10 @@ issize_t msg_date_d(char const **ss, msg_time_t *date) else { /* actime-date = wkday SP month SP ( 2DIGIT | ( SP 1DIGIT )) SP time SP 4DIGIT */ - mon = month_d(s); skip_token(&s); - if (mon < 0 || !IS_LWS(*s)) return -1; s++; + mon = month_d(s); + skip_token(&s); + if (mon < 0 || !IS_LWS(*s)) return -1; + s++; while (IS_LWS(*s)) s++; if (!is_digit(*s)) return -1; day = *s++ - '0'; if (is_digit(*s)) day = 10 * day + *s++ - '0'; diff --git a/libsofia-sip-ua/msg/msg_parser.c b/libsofia-sip-ua/msg/msg_parser.c index bc85eaf8..8b2e11c1 100644 --- a/libsofia-sip-ua/msg/msg_parser.c +++ b/libsofia-sip-ua/msg/msg_parser.c @@ -2017,7 +2017,7 @@ msg_header_t **serialize_one(msg_t *msg, msg_header_t *h, msg_header_t **prev) for (last = h; last->sh_succ; last = last->sh_succ) { /* Ensure that chain is connected */ assert(last->sh_next == last->sh_succ); - assert(last->sh_succ->sh_prev = &last->sh_succ); + assert(last->sh_succ->sh_prev == &last->sh_succ); } prev = &last->sh_succ; } diff --git a/libsofia-sip-ua/nua/nua_client.c b/libsofia-sip-ua/nua/nua_client.c index 8efaa31d..b8a99a52 100644 --- a/libsofia-sip-ua/nua/nua_client.c +++ b/libsofia-sip-ua/nua/nua_client.c @@ -1591,9 +1591,10 @@ int nua_client_treport(nua_client_request_t *cr, int nua_client_next_request(nua_client_request_t *cr, int invite) { for (; cr; cr = cr->cr_next) { - if (cr->cr_method == sip_method_cancel) + if (cr->cr_method == sip_method_cancel) { continue; - break; + } + break; } if (cr && !nua_client_request_in_progress(cr)) { diff --git a/libsofia-sip-ua/nua/nua_stack.c b/libsofia-sip-ua/nua/nua_stack.c index 7364d4b2..3d6ee200 100644 --- a/libsofia-sip-ua/nua/nua_stack.c +++ b/libsofia-sip-ua/nua/nua_stack.c @@ -690,23 +690,23 @@ nua_event_data_t const *nua_event_data(nua_saved_event_t const saved[1]) * * @sa #nua_event_e, nua_event_save(), nua_event_data(), nua_saved_event_request(). */ -void nua_destroy_event(nua_saved_event_t saved[1]) +void nua_destroy_event(nua_saved_event_t *saved) { if (saved && saved[0]) su_msg_destroy(saved); } /** @internal Move signal. */ -void nua_move_signal(nua_saved_signal_t a[1], nua_saved_signal_t b[1]) +void nua_move_signal(nua_saved_signal_t *a, nua_saved_signal_t *b) { su_msg_save(a, b); } -void nua_destroy_signal(nua_saved_signal_t saved[1]) +void nua_destroy_signal(nua_saved_signal_t *saved) { if (saved) su_msg_destroy(saved); } -nua_signal_data_t const *nua_signal_data(nua_saved_signal_t const saved[1]) +nua_signal_data_t const *nua_signal_data(nua_saved_signal_t const *saved) { return nua_event_data(saved); } diff --git a/libsofia-sip-ua/nua/nua_stack.h b/libsofia-sip-ua/nua/nua_stack.h index ba2d69a5..4aebcc16 100644 --- a/libsofia-sip-ua/nua/nua_stack.h +++ b/libsofia-sip-ua/nua/nua_stack.h @@ -308,9 +308,9 @@ typedef int nua_stack_signal_handler(nua_t *, nua_event_t, tagi_t const *); -void nua_move_signal(nua_saved_signal_t a[1], nua_saved_signal_t b[1]); -nua_signal_data_t const *nua_signal_data(nua_saved_signal_t const saved[1]); -void nua_destroy_signal(nua_saved_signal_t saved[1]); +void nua_move_signal(nua_saved_signal_t *a, nua_saved_signal_t *b); +nua_signal_data_t const *nua_signal_data(nua_saved_signal_t const *saved); +void nua_destroy_signal(nua_saved_signal_t *saved); nua_stack_signal_handler nua_stack_set_params, nua_stack_get_params, diff --git a/libsofia-sip-ua/sdp/sdp.c b/libsofia-sip-ua/sdp/sdp.c index 9b46dd09..79170c68 100644 --- a/libsofia-sip-ua/sdp/sdp.c +++ b/libsofia-sip-ua/sdp/sdp.c @@ -1858,7 +1858,8 @@ int sdp_rtpmap_match(sdp_rtpmap_t const *a, sdp_rtpmap_t const *b) if (aparam == bparam) return 1; - if (!aparam) aparam = "1"; if (!bparam) bparam = "1"; + if (!aparam) aparam = "1"; + if (!bparam) bparam = "1"; if (!su_casematch(aparam, bparam)) return 0; @@ -1895,7 +1896,8 @@ sdp_rtpmap_t *sdp_rtpmap_find_matching(sdp_rtpmap_t const *list, break; } - if (!lparam) lparam = "1"; if (!rparam) rparam = "1"; + if (!lparam) lparam = "1"; + if (!rparam) rparam = "1"; if (!su_casematch(lparam, rparam)) continue; diff --git a/libsofia-sip-ua/sip/sip_pref_util.c b/libsofia-sip-ua/sip/sip_pref_util.c index 9da9187a..3116c9f4 100644 --- a/libsofia-sip-ua/sip/sip_pref_util.c +++ b/libsofia-sip-ua/sip/sip_pref_util.c @@ -323,9 +323,6 @@ int sip_is_callerpref(char const *param) if (param[0] == '+') param++, xor = 1; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstring-plus-int" - switch (param[0]) { case 'a': case 'A': base = MATCH("audio") || MATCH("automata") || MATCH("application") || @@ -365,7 +362,6 @@ int sip_is_callerpref(char const *param) base = 0; break; } -#pragma GCC diagnostic pop #undef MATCH diff --git a/libsofia-sip-ua/stun/stun.c b/libsofia-sip-ua/stun/stun.c index 089c0c09..aa98af65 100644 --- a/libsofia-sip-ua/stun/stun.c +++ b/libsofia-sip-ua/stun/stun.c @@ -573,17 +573,20 @@ int stun_obtain_shared_secret(stun_handle_t *sh, s = su_socket(family = AF_INET, SOCK_STREAM, 0); if (s == INVALID_SOCKET) { - return STUN_ERROR(errno, socket); + STUN_ERROR(errno, socket); + return -1; } /* asynchronous connect() */ if (su_setblocking(s, 0) < 0) { - return STUN_ERROR(errno, su_setblocking); + STUN_ERROR(errno, su_setblocking); + return -1; } if (setsockopt(s, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1) { - return STUN_ERROR(errno, setsockopt); + STUN_ERROR(errno, setsockopt); + return -1; } /* Do an asynchronous connect(). Three error codes are ok, @@ -592,7 +595,8 @@ int stun_obtain_shared_secret(stun_handle_t *sh, ai->ai_addrlen) == SOCKET_ERROR) { err = su_errno(); if (err != EINPROGRESS && err != EAGAIN && err != EWOULDBLOCK) { - return STUN_ERROR(err, connect); + STUN_ERROR(err, connect); + return -1; } } @@ -604,15 +608,18 @@ int stun_obtain_shared_secret(stun_handle_t *sh, /* req = stun_request_create(sd); */ events = SU_WAIT_CONNECT | SU_WAIT_ERR; - if (su_wait_create(wait, s, events) == -1) - return STUN_ERROR(errno, su_wait_create); + if (su_wait_create(wait, s, events) == -1) { + STUN_ERROR(errno, su_wait_create); + return -1; + } /* su_root_eventmask(sh->sh_root, sh->sh_root_index, s, events); */ if ((sd->sd_index = su_root_register(sh->sh_root, wait, stun_tls_callback, (su_wakeup_arg_t *) sd, 0)) == -1) { su_wait_destroy(wait); - return STUN_ERROR(errno, su_root_register); + STUN_ERROR(errno, su_root_register); + return -1; } ta_start(ta, tag, value); @@ -789,7 +796,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket) /* set socket asynchronous */ if (su_setblocking(s, 0) < 0) { - return STUN_ERROR(errno, su_setblocking); + STUN_ERROR(errno, su_setblocking); + return -1; } /* xxx -- check if socket is already assigned to this root */ @@ -815,7 +823,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket) } if (getsockname(s, &su->su_sa, &sulen) == -1) { - return STUN_ERROR(errno, getsockname); + STUN_ERROR(errno, getsockname); + return -1; } } @@ -828,7 +837,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket) events = SU_WAIT_IN | SU_WAIT_ERR; if (su_wait_create(wait, s, events) == -1) { - return STUN_ERROR(su_errno(), su_wait_create); + STUN_ERROR(su_errno(), su_wait_create); + return -1; } /* Register receiving function with events specified above */ @@ -836,7 +846,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket) wait, stun_bind_callback, (su_wakeup_arg_t *) sd, 0)) < 0) { su_wait_destroy(wait); - return STUN_ERROR(errno, su_root_register); + STUN_ERROR(errno, su_root_register); + return -1; } SU_DEBUG_7(("%s: socket registered.\n", __func__)); @@ -877,13 +888,15 @@ static int get_localinfo(int family, su_sockaddr_t *su, socklen_t *return_len) su_freelocalinfo(res); if (!li) { /* Not found */ - return STUN_ERROR(error, su_getlocalinfo); + STUN_ERROR(error, su_getlocalinfo); + return -1; } return 0; } else { - return STUN_ERROR(error, su_getlocalinfo); + STUN_ERROR(error, su_getlocalinfo); + return -1; } } #endif @@ -1355,7 +1368,7 @@ int stun_tls_callback(su_root_magic_t *m, su_wait_t *w, su_wakeup_arg_t *arg) /* openssl initiation */ SSLeay_add_ssl_algorithms(); SSL_load_error_strings(); - ctx = SSL_CTX_new(TLSv1_client_method()); + ctx = SSL_CTX_new(TLS_client_method()); self->sh_ctx = ctx; if (ctx == NULL) { diff --git a/libsofia-sip-ua/stun/stun_internal.h b/libsofia-sip-ua/stun/stun_internal.h index 00ef89b5..66d5d153 100644 --- a/libsofia-sip-ua/stun/stun_internal.h +++ b/libsofia-sip-ua/stun/stun_internal.h @@ -87,8 +87,7 @@ extern char const STUN_DEBUG[]; /* dummy declaration for Doxygen */ #endif #define STUN_ERROR(err, what) \ - SU_DEBUG_5(("%s: %s: %s\n", __func__, #what, su_strerror(err))), \ - -1 \ + SU_DEBUG_5(("%s: %s: %s\n", __func__, #what, su_strerror(err))) int stun_is_requested(tag_type_t tag, tag_value_t value, ...); diff --git a/libsofia-sip-ua/su/sofia-sip/heap.h b/libsofia-sip-ua/su/sofia-sip/heap.h index 2b51f90c..e3b45f48 100644 --- a/libsofia-sip-ua/su/sofia-sip/heap.h +++ b/libsofia-sip-ua/su/sofia-sip/heap.h @@ -160,7 +160,7 @@ scope type prefix##get(heaptype, size_t) * bytes in the heap. */ #define HEAP_BODIES(scope, heaptype, prefix, type, less, set, alloc, null) \ -scope int prefix##resize(void *realloc_arg, heaptype h[1], size_t new_size) \ +scope int prefix##resize(void *realloc_arg, heaptype *h, size_t new_size) \ { \ struct prefix##priv { size_t _size, _used; type _heap[2]; }; \ struct prefix##priv *_priv; \ @@ -198,7 +198,7 @@ scope int prefix##resize(void *realloc_arg, heaptype h[1], size_t new_size) \ } \ \ /** Free heap. */ \ -scope int prefix##free(void *realloc_arg, heaptype h[1]) \ +scope int prefix##free(void *realloc_arg, heaptype* h) \ { \ (void)realloc_arg; \ *(void **)h = alloc(realloc_arg, *(void **)h, 0); \ diff --git a/libsofia-sip-ua/su/sofia-sip/htable.h b/libsofia-sip-ua/su/sofia-sip/htable.h index cc7e61bb..cdfcdbd0 100644 --- a/libsofia-sip-ua/su/sofia-sip/htable.h +++ b/libsofia-sip-ua/su/sofia-sip/htable.h @@ -100,7 +100,7 @@ typedef unsigned long hash_value_t; HTABLE_PROTOS_WITH(prefix, pr, entry_t, unsigned, hash_value_t) #define HTABLE_PROTOS_WITH(prefix, pr, entry_t, size_t, hash_value_t) \ -HTABLE_SCOPE int prefix##_resize(su_home_t *, prefix##_t pr[1], size_t); \ +HTABLE_SCOPE int prefix##_resize(su_home_t *, prefix##_t *pr, size_t); \ HTABLE_SCOPE int prefix##_is_full(prefix##_t const *); \ HTABLE_SCOPE entry_t **prefix##_hash(prefix##_t const *, hash_value_t hv); \ HTABLE_SCOPE entry_t **prefix##_next(prefix##_t const *, entry_t * const *ee); \ @@ -127,7 +127,7 @@ HTABLE_SCOPE int prefix##_remove(prefix##_t *, entry_t const *e) /** Reallocate new hash table */ \ HTABLE_SCOPE \ int prefix##_resize(su_home_t *home, \ - prefix##_t pr[], \ + prefix##_t *pr, \ size_t new_size) \ { \ entry_t **new_hash; \ diff --git a/libsofia-sip-ua/su/su_alloc.c b/libsofia-sip-ua/su/su_alloc.c index 0eab46ed..1ea712a0 100644 --- a/libsofia-sip-ua/su/su_alloc.c +++ b/libsofia-sip-ua/su/su_alloc.c @@ -1987,7 +1987,7 @@ void su_home_stats_free(su_block_t *sub, void *p, void *preload, hs->hs_blocks.hsb_rbytes -= rsize; } -void su_home_stat_add(su_home_stat_t total[1], su_home_stat_t const hs[1]) +void su_home_stat_add(su_home_stat_t *total, su_home_stat_t const *hs) { total->hs_clones += hs->hs_clones; total->hs_rehash += hs->hs_rehash; diff --git a/libsofia-sip-ua/su/su_localinfo.c b/libsofia-sip-ua/su/su_localinfo.c index 47e951f1..e2b7aea8 100644 --- a/libsofia-sip-ua/su/su_localinfo.c +++ b/libsofia-sip-ua/su/su_localinfo.c @@ -1164,7 +1164,7 @@ int localinfo6(su_localinfo_t const *hints, su_localinfo_t **rresult) #include static -int bsd_localinfo(su_localinfo_t const hints[1], +int bsd_localinfo(su_localinfo_t const *hints, su_localinfo_t **return_result) { struct ifaddrs *ifa, *results; diff --git a/libsofia-sip-ua/su/su_socket_port.c b/libsofia-sip-ua/su/su_socket_port.c index 90a05411..75f616c6 100644 --- a/libsofia-sip-ua/su/su_socket_port.c +++ b/libsofia-sip-ua/su/su_socket_port.c @@ -169,11 +169,15 @@ void su_socket_port_deinit(su_port_t *self) su_port_deregister(self, self->sup_mbox_index); self->sup_mbox_index = 0; - if (self->sup_mbox[0] && self->sup_mbox[0] != INVALID_SOCKET) - su_close(self->sup_mbox[0]); self->sup_mbox[0] = INVALID_SOCKET; + if (self->sup_mbox[0] && self->sup_mbox[0] != INVALID_SOCKET) { + su_close(self->sup_mbox[0]); + self->sup_mbox[0] = INVALID_SOCKET; + } #if HAVE_SOCKETPAIR - if (self->sup_mbox[1] && self->sup_mbox[1] != INVALID_SOCKET) - su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET; + if (self->sup_mbox[1] && self->sup_mbox[1] != INVALID_SOCKET) { + su_close(self->sup_mbox[1]); + self->sup_mbox[1] = INVALID_SOCKET; + } #endif su_pthread_port_deinit(self); diff --git a/libsofia-sip-ua/tport/tport_tls.c b/libsofia-sip-ua/tport/tport_tls.c index 3c10c8e2..a197bd61 100644 --- a/libsofia-sip-ua/tport/tport_tls.c +++ b/libsofia-sip-ua/tport/tport_tls.c @@ -137,6 +137,7 @@ enum { tls_buffer_size = 16384 }; * Log the TLS error specified by the error code @a e and all the errors in * the queue. The error code @a e implies no error, and it is not logged. */ +/* void tls_log_errors(unsigned level, char const *s, unsigned long e) { if (e == 0) @@ -158,6 +159,28 @@ void tls_log_errors(unsigned level, char const *s, unsigned long e) } } } +*/ +void tls_log_errors(unsigned level, char const *s, unsigned long e) +{ + char err_buf[256]; + + if (e == 0) + e = ERR_get_error(); + + if (!tport_log->log_init) + su_log_init(tport_log); + + if (s == NULL) s = "tls"; + + for (; e != 0; e = ERR_get_error()) { + if (level <= tport_log->log_level) { + ERR_error_string_n(e, err_buf, sizeof(err_buf)); + + su_llog(tport_log, level, "%s: %08lx:%s\n", + s, e, err_buf); + } + } +} /* * This callback hands back the password to be used during decryption. diff --git a/libsofia-sip-ua/tport/ws.c b/libsofia-sip-ua/tport/ws.c index 2512d645..c4fe87c9 100644 --- a/libsofia-sip-ua/tport/ws.c +++ b/libsofia-sip-ua/tport/ws.c @@ -1,6 +1,9 @@ #include #include "ws.h" #include +#include +#include +#include #ifndef _MSC_VER #include @@ -238,6 +241,41 @@ static void sha1_digest(char *digest, unsigned char *in) } #else +static void sha1_digest(unsigned char *digest, char *in) +{ + EVP_MD_CTX *mdctx; + unsigned int digest_len; + + if((mdctx = EVP_MD_CTX_new()) == NULL) { + // handle error, e.g. print an error message and return or exit + printf("Failed to create new OpenSSL digest context\n"); + return; + } + + if(EVP_DigestInit_ex(mdctx, EVP_sha1(), NULL) != 1) { + // handle error + printf("Failed to initialize OpenSSL digest\n"); + EVP_MD_CTX_free(mdctx); + return; + } + + if(EVP_DigestUpdate(mdctx, in, strlen(in)) != 1) { + // handle error + printf("Failed to update OpenSSL digest\n"); + EVP_MD_CTX_free(mdctx); + return; + } + + if(EVP_DigestFinal_ex(mdctx, digest, &digest_len) != 1) { + // handle error + printf("Failed to finalize OpenSSL digest\n"); + EVP_MD_CTX_free(mdctx); + return; + } + + EVP_MD_CTX_free(mdctx); +} +/* static void sha1_digest(unsigned char *digest, char *in) { SHA_CTX sha; @@ -247,7 +285,7 @@ static void sha1_digest(unsigned char *digest, char *in) SHA1_Final(digest, &sha); } - +*/ #endif int ws_handshake(wsh_t *wsh) @@ -428,6 +466,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block) * Log the WSS error specified by the error code @a e and all the errors in * the queue. The error code @a e implies no error, and it is not logged. */ +/* void wss_log_errors(unsigned level, char const *s, unsigned long e) { if (e == 0) @@ -449,6 +488,29 @@ void wss_log_errors(unsigned level, char const *s, unsigned long e) } } } +*/ +void wss_log_errors(unsigned level, char const *s, unsigned long e) +{ + char err_buf[256]; + + if (e == 0) + e = ERR_get_error(); + + if (!tport_log->log_init) + su_log_init(tport_log); + + if (s == NULL) s = "tls"; + + for (; e != 0; e = ERR_get_error()) { + if (level <= tport_log->log_level) { + ERR_error_string_n(e, err_buf, sizeof(err_buf)); + + su_llog(tport_log, level, "%s: %08lx:%s\n", + s, e, err_buf); + } + } +} + int wss_error(wsh_t *wsh, int ssl_err, char const *who) {