Ejemplo n.º 1
0
    int
sca_aor_create_from_info( str *aor, uri_type type, str *user, str *domain,
	str *port )
{
    str		scheme = STR_NULL;
    int		len = 0;

    assert( aor != NULL );

    uri_type_to_str( type, &scheme );

    /* +1 for ':', +1 for '@' */
    len = scheme.len + 1 + user->len + 1 + domain->len;
    if ( !SCA_STR_EMPTY( port )) {
	/* +1 for ':' */
	len += 1 + port->len;
    }

    aor->s = (char *)pkg_malloc( len );
    if ( aor->s == NULL ) {
	LM_ERR( "sca_aor_create_from_info: pkg_malloc %d bytes failed", len );
	return( -1 );
    }

    len = 0;
    SCA_STR_COPY( aor, &scheme );
    len += scheme.len;

    *(aor->s + len) = ':';
    aor->len++;
    len++;

    SCA_STR_APPEND( aor, user );
    len += user->len;

    *(aor->s + len) = '@';
    aor->len++;
    len++;

    SCA_STR_APPEND( aor, domain );
    len += domain->len;

    if ( !SCA_STR_EMPTY( port )) {
	*(aor->s + len) = ':';
	len += 1;

	SCA_STR_APPEND( aor, port );
	len += port->len;
    }

    return( aor->len );
}
Ejemplo n.º 2
0
/*
 * send a call-info NOTIFY to all subscribers to a given SCA AoR.
 */
int sca_notify_call_info_subscribers(sca_mod *scam, str *subscription_aor)
{
	sca_hash_slot *slot;
	sca_hash_entry *e;
	sca_subscription *sub;
	str headers = STR_NULL;
	str hash_key = STR_NULL;
	char hdrbuf[SCA_HEADERS_MAX_LEN];
	char keybuf[512];
	char *event_name;
	int slot_idx;
	int rc = -1;

	assert(scam->subscriptions != NULL);
	assert(!SCA_STR_EMPTY(subscription_aor));

	LM_DBG("Notifying ALL subscribers of AOR %.*s due to a SUBSCRIBTION request\n",
			STR_FMT(subscription_aor));

	event_name = sca_event_name_from_type(SCA_EVENT_TYPE_CALL_INFO);
	if (subscription_aor->len + strlen(event_name) >= sizeof(keybuf)) {
		LM_ERR("Hash key %.*s + %s is too long\n",
				STR_FMT(subscription_aor), event_name);
		return (-1);
	}
	hash_key.s = keybuf;
	SCA_STR_COPY(&hash_key, subscription_aor);
	SCA_STR_APPEND_CSTR(&hash_key, event_name);

	slot_idx = sca_hash_table_index_for_key(scam->subscriptions, &hash_key);
	slot = sca_hash_table_slot_for_index(scam->subscriptions, slot_idx);

	sca_hash_table_lock_index(scam->subscriptions, slot_idx);

	for (e = slot->entries; e != NULL; e = e->next) {
		sub = (sca_subscription *) e->value;
		if (!SCA_STR_EQ(subscription_aor, &sub->target_aor)) {
			continue;
		}

		if (headers.len == 0) {
			headers.s = hdrbuf;

			if (sca_notify_build_headers_from_info(&headers, sizeof(hdrbuf),
					scam, sub, SCA_CALL_INFO_APPEARANCE_INDEX_ANY) < 0) {
				LM_ERR("Failed to build NOTIFY headers\n");
				goto done;
			}
		}

		// XXX would like this to be wrapped in one location
		sub->dialog.notify_cseq += 1;

		if (sca_notify_subscriber_internal(scam, sub, &headers) < 0) {
			goto done;
		}
	}
	rc = 1;

	done:
	sca_hash_table_unlock_index(scam->subscriptions, slot_idx);

	return (rc);
}