libomsocc: Add function to check if interface is attached

This commit is contained in:
Andreas Eversberg 2021-04-02 16:22:45 +02:00
parent 2d1b5fb437
commit 046834ac97
2 changed files with 23 additions and 13 deletions

View File

@ -172,6 +172,27 @@ static int split_address(const char *address, const char **host_p, uint16_t *por
return 0;
}
osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface)
{
osmo_cc_call_t *att;
for (att = ep->call_list; att; att = att->next) {
if (att->state != OSMO_CC_STATE_ATTACH_IN)
continue;
/* no interface given, just use the attached peer */
if (!interface[0])
break;
/* no interface name given on attached peer, ignore it */
if (!att->attached_name || !att->attached_name[0])
continue;
/* interface given, use the attached peer with the same interface name */
if (!strcmp(interface, att->attached_name))
break;
}
return att;
}
/* helper to forward message to upper layer */
static void forward_to_ul(osmo_cc_call_t *call, osmo_cc_msg_t *msg)
{
@ -233,19 +254,7 @@ reject:
if (rc < 0)
interface[0] = '\0';
/* check for incoming attachment */
for (att = call->ep->call_list; att; att = att->next) {
if (att->state != OSMO_CC_STATE_ATTACH_IN)
continue;
/* no interface given, just use the attached peer */
if (!interface[0])
break;
/* no interface name given on attached peer, ignore it */
if (!att->attached_name || !att->attached_name[0])
continue;
/* interface given, use the attached peer with the same interface name */
if (!strcmp(interface, att->attached_name))
break;
}
att = osmo_cc_get_attached_interface(call->ep, interface);
if (!att && !interface[0]) {
PDEBUG(DCC, DEBUG_ERROR, "No remote peer attached, rejecting call.\n");
goto reject;

View File

@ -112,6 +112,7 @@ int osmo_cc_new(osmo_cc_endpoint_t *ep, const char *version, const char *name, u
void osmo_cc_delete(struct osmo_cc_endpoint *ep);
int osmo_cc_handle(void);
osmo_cc_call_t *osmo_cc_call_by_callref(osmo_cc_endpoint_t *ep, uint32_t callref);
osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface);
void osmo_cc_ll_msg(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg);
void osmo_cc_ul_msg(void *priv, uint32_t callref, osmo_cc_msg_t *msg);
osmo_cc_call_t *osmo_cc_call_new(osmo_cc_endpoint_t *ep);