Example #1
0
int send_resource_subs(char* uri, void* param)
{
	str pres_uri, *tmp_str;
	struct sip_uri parsed_pres_uri;
	int duplicate = 0;
	
	subs_info_t *s = (subs_info_t *) ((void**)param)[0];
	list_entry_t **rls_contact_list = (list_entry_t **) ((void**)param)[1];

	pres_uri.s = uri;
	pres_uri.len = strlen(uri);
	if (parse_uri(pres_uri.s, pres_uri.len, &parsed_pres_uri) < 0)
	{
		LM_ERR("bad uri: %.*s\n", pres_uri.len, pres_uri.s);
		return -1;
	}

	if (check_self(&parsed_pres_uri.host, 0, PROTO_NONE) != 1
		&& rls_disable_remote_presence != 0)
	{
		LM_WARN("Unable to subscribe to remote contact %.*s for watcher %.*s\n",
				pres_uri.len, pres_uri.s,
				s->watcher_uri->len,
				s->watcher_uri->s);
		return 1;
	}

	/* Silently drop subscribes over the limit - will print a single warning
 	   later */
	if (rls_max_backend_subs > 0 && ++counter > rls_max_backend_subs)
		return 1;

	s->pres_uri = &pres_uri;
	s->remote_target = &pres_uri;

	/* Build list of contacts... checking each contact exists only once */
	if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL)
	{
		LM_ERR("out of private memory\n");
		return -1;
	}
	if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * pres_uri.len)) == NULL)
	{
		pkg_free(tmp_str);
		LM_ERR("out of private memory\n");
		return -1;
	}
	memcpy(tmp_str->s, pres_uri.s, pres_uri.len);
	tmp_str->len = pres_uri.len;
	*rls_contact_list = list_insert(tmp_str, *rls_contact_list, &duplicate);
	if (duplicate != 0)
	{
		LM_WARN("%.*s has %.*s multiple times in the same resource list\n",
			s->watcher_uri->len, s->watcher_uri->s,
			s->pres_uri->len, s->pres_uri->s);
		return 1;
	}

	return pua_send_subscribe(s);
}
Example #2
0
int send_resource_subs(char* uri, void* param)
{
        int duplicate = 0;
	str pres_uri;
	str *tmp_str;
	subs_info_t *s = (subs_info_t *) ((void**)param)[0];
	list_entry_t **rls_contact_list = (list_entry_t **) ((void**)param)[1];

	pres_uri.s= uri;
	pres_uri.len= strlen(uri);

	s->pres_uri= &pres_uri;

        /* Build a list of uris checking each uri exists only once */
        if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL)
        {
                LM_ERR("out of private memory\n");
                return -1;
        }

        if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * pres_uri.len + 1)) == NULL)
        {
                pkg_free(tmp_str);
                LM_ERR("out of private memory\n");
                return -1;
        }

        memcpy(tmp_str->s, pres_uri.s, pres_uri.len);
        tmp_str->len = pres_uri.len;
	tmp_str->s[tmp_str->len] = '\0';
        *rls_contact_list = list_insert(tmp_str, *rls_contact_list, &duplicate);
        if (duplicate != 0)
        {
                LM_WARN("%.*s has %.*s multiple times in the same resource list\n",
                        s->watcher_uri->len, s->watcher_uri->s,
                        s->pres_uri->len, s->pres_uri->s);
                return 1;
        }

	return pua_send_subscribe(s);
}
Example #3
0
void bla_cb(ucontact_t* c, int type, void* param)
{
	subs_info_t subs;
	str uri={0, 0};
	char* at;
	LM_DBG("start\n");
	if(is_bla_aor== 0)
	{
		LM_DBG("Not a recognized BLA AOR\n");
		return ;
	}

	if(type & UL_CONTACT_INSERT)
		LM_DBG("type= UL_CONTACT_INSERT\n");
	else
	if(type & UL_CONTACT_UPDATE)
		LM_DBG("type= UL_CONTACT_UPDATE\n");
	else
	if(type & UL_CONTACT_EXPIRE)
		LM_DBG("type= UL_CONTACT_EXPIRE\n");
	else
	if(type & UL_CONTACT_DELETE)
		LM_DBG("type= UL_CONTACT_DELETE\n");

	memset(&subs, 0, sizeof(subs_info_t));
	subs.pres_uri= &c->c;

	subs.to_uri= reg_from_uri;

	uri.s = (char*)pkg_malloc(sizeof(char)*(c->aor->len+default_domain.len+6));
	if(uri.s == NULL) {
		LM_ERR( "pkg_malloc uri failed\n" );
		goto error;
	}

	memcpy(uri.s, "sip:", 4);
	uri.len = 4;

	memcpy(uri.s+ uri.len, c->aor->s, c->aor->len);
	uri.len+= c->aor->len;
	at = memchr(c->aor->s, '@', c->aor->len);
	if(!at)
	{
		if(default_domain.s == NULL)
		{
			LM_ERR("No domain found in register and default_domain module"
					" parameter not set\n");
			goto error;
		}
		LM_DBG("domain not found - added default= %.*s\n",
			default_domain.len, default_domain.s);

		uri.s[uri.len++]= '@';
		memcpy(uri.s+ uri.len, default_domain.s, default_domain.len);
		uri.len+= default_domain.len;
	}

	subs.watcher_uri= &uri;
	if(type & UL_CONTACT_DELETE || type & UL_CONTACT_EXPIRE )
		subs.expires= 0;
	else
		subs.expires= c->expires - (int)time(NULL);

	subs.source_flag= BLA_SUBSCRIBE;
	subs.event= BLA_EVENT;
	subs.contact= &server_address;

	if(bla_outbound_proxy.s && bla_outbound_proxy.len)
		subs.outbound_proxy= &bla_outbound_proxy;
	else
	if(c->received.s && c->received.len)
		subs.outbound_proxy= &c->received;

	if(type & UL_CONTACT_INSERT)
		subs.flag|= INSERT_TYPE;
	else
		subs.flag|= UPDATE_TYPE;

	if(pua_send_subscribe(&subs)< 0)
	{
		LM_ERR("while sending subscribe\n");
	}
	pkg_free(uri.s);
error:
	is_bla_aor= 0;
	return ;
}
Example #4
0
int presence_subscribe(xmlNodePtr pres_node, int expires,int  flag)
{
	subs_info_t subs;
	char* type= NULL, *uri= NULL;
 	str to_uri= {0, 0};
 	str from_uri= {0, 0};
 	char buf_from[256];

	uri= XMLNodeGetAttrContentByName(pres_node, "to"); 
	if(uri== NULL)
	{
		LM_ERR("failed to get to attribute from xml doc\n");
		return -1;
	}
	to_uri.s = xmpp_uri_xmpp2sip(uri, &to_uri.len);
	if(to_uri.s == 0)
	{
		LM_ERR("failed to get from attribute from xml doc\n");
		goto error;
	}
 	xmlFree(uri);
 
 	uri= XMLNodeGetAttrContentByName(pres_node, "from");
 	if(uri == NULL)
 	{
 		LM_ERR("failed to get from attribute from xml doc\n");
 		goto error;
 	}
 
 	ENC_SIP_URI(from_uri, buf_from, uri);
 	xmlFree(uri);
	
	memset(&subs, 0, sizeof(subs_info_t));

	subs.pres_uri= &to_uri;
	subs.watcher_uri= &from_uri;
	subs.contact= &server_address;
	if(presence_server.s)
		subs.outbound_proxy = &presence_server;
	/*
	type= XMLNodeGetAttrContentByName(pres_node, "type" );
	if(strcmp(type, "subscribe")==0 ||strcmp(type, "probe")== 0)
		subs->flag|= INSERT_TYPE;
	else	
		if(strcmp(type, "unsubscribe")== 0)
			subs->flag|= UPDATE_TYPE;
	xmlFree(type);
	type= NULL;
	*/

	subs.source_flag|= flag;
	subs.event= PRESENCE_EVENT;
	subs.expires= expires;
	
	if(presence_server.s && presence_server.len)
		subs.outbound_proxy = &presence_server;

	LM_DBG("XMPP subscription to [%.*s] , from [%.*s], expires= [%d]\n", 
			subs.pres_uri->len,  subs.pres_uri->s,
			subs.watcher_uri->len,  subs.watcher_uri->s, expires);
	if(subs.outbound_proxy)
		LM_DBG("outbound_proxy= %.*s\n", subs.outbound_proxy->len,  subs.outbound_proxy->s);

	if(pua_send_subscribe(&subs)< 0)
	{
		LM_ERR("while sending SUBSCRIBE\n");
		goto error;
	}
	return 0;

error:
	if(type)
		xmlFree(type);
	return -1;
}
Example #5
0
struct mi_root* mi_pua_subscribe(struct mi_root* cmd, void* param)
{
	int exp= 0;
	str pres_uri, watcher_uri, expires;
	struct mi_node* node= NULL;
	struct mi_root* rpl= NULL;
	struct sip_uri uri;
	subs_info_t subs;
	int sign= 1;
	str event;

	node = cmd->node.kids;
	if(node == NULL)
		return 0;

	pres_uri= node->value;
	if(pres_uri.s == NULL || pres_uri.s== 0)
	{
		return init_mi_tree(400, "Bad uri", 7);
	}
	if(parse_uri(pres_uri.s, pres_uri.len, &uri)<0 )
	{
		LM_ERR("bad uri\n");	
		return init_mi_tree(400, "Bad uri", 7);
	}

	node = node->next;
	if(node == NULL)
		return 0;

	watcher_uri= node->value;
	if(watcher_uri.s == NULL || watcher_uri.s== 0)
	{
		return init_mi_tree(400, "Bad uri", 7);
	}
	if(parse_uri(watcher_uri.s, watcher_uri.len, &uri)<0 )
	{
		LM_ERR("bad uri\n");	
		return init_mi_tree(400, "Bad uri", 7);
	}

	/* Get event */
	node = node->next;
	if(node == NULL)
		return 0;

	event= node->value;
	if(event.s== NULL || event.len== 0)
	{
		LM_ERR("empty event parameter\n");
		return init_mi_tree(400, "Empty event parameter", 21);
	}
	LM_DBG("event '%.*s'\n", event.len, event.s);

	node = node->next;
	if(node == NULL || node->next!=NULL)
	{
		LM_ERR("Too much or too many parameters\n");
		return 0;
	}

	expires= node->value;
	if(expires.s== NULL || expires.len== 0)
	{
		LM_ERR("Bad expires parameter\n");
		return init_mi_tree(400, "Bad expires", 11);
	}		
	if(expires.s[0]== '-')
	{
		sign= -1;
		expires.s++;
		expires.len--;
	}
	if( str2int(&expires, (unsigned int*) &exp)< 0)
	{
		LM_ERR("invalid expires parameter\n" );
		goto error;
	}
	
	exp= exp* sign;

	LM_DBG("expires '%d'\n", exp);
	
	memset(&subs, 0, sizeof(subs_info_t));
	
	subs.pres_uri= &pres_uri;

	subs.watcher_uri= &watcher_uri;

	subs.contact= &watcher_uri;
	
	subs.expires= exp;
	subs.source_flag |= MI_SUBSCRIBE;
	subs.event= get_event_flag(&event);
	if(subs.event< 0)
	{
		LM_ERR("unkown event\n");
		return init_mi_tree(400, "Unknown event", 13);
	}

	if(pua_send_subscribe(&subs)< 0)
	{
		LM_ERR("while sending subscribe\n");
		goto error;
	}
	
	rpl= init_mi_tree(202, "accepted", 8);
	if(rpl == NULL)
		return 0;
	
	return rpl;

error:

	return 0;

}
Example #6
0
int presence_subscribe(xmlNodePtr pres_node, int expires,int  flag)
{
	subs_info_t subs;
	char* to_uri= NULL, *from_uri= NULL;
	char* uri= NULL;
	char* type= NULL;
	str to_uri_str;
	str from_uri_str;

	uri= XMLNodeGetAttrContentByName(pres_node, "to"); 
	if(uri== NULL)
	{
		LM_ERR("while getting attribute from xml doc\n");
		return -1;
	}
	to_uri= duri_xmpp_sip(uri);
	if(to_uri== NULL)
	{
		LM_ERR("while decoding xmpp--sip uri\n");
		goto error;
	}
	xmlFree(uri);
	to_uri_str.s= to_uri;
	to_uri_str.len= strlen(to_uri);

	uri= XMLNodeGetAttrContentByName(pres_node, "from"); 
	if(uri== NULL)
	{
		LM_ERR("while getting attribute from xml doc\n");
		goto error;
	}
	from_uri= euri_xmpp_sip(uri);
	if(from_uri== NULL)
	{
		LM_ERR("while encoding xmpp-sip uri\n");
		goto error;	
	}	
	xmlFree(uri);
	from_uri_str.s= from_uri;
	from_uri_str.len= strlen(from_uri);
	
	memset(&subs, 0, sizeof(subs_info_t));

	subs.pres_uri= &to_uri_str;
	subs.watcher_uri= &from_uri_str;
	subs.contact= subs.watcher_uri;
	/*
	type= XMLNodeGetAttrContentByName(pres_node, "type" );
	if(strcmp(type, "subscribe")==0 ||strcmp(type, "probe")== 0)
		subs->flag|= INSERT_TYPE;
	else	
		if(strcmp(type, "unsubscribe")== 0)
			subs->flag|= UPDATE_TYPE;
	xmlFree(type);
	type= NULL;
	*/

	subs.source_flag|= flag;
	subs.event= PRESENCE_EVENT;
	subs.expires= expires;
	
	LM_DBG("subs:\n");
	LM_DBG("\tpres_uri= %.*s\n", subs.pres_uri->len,  subs.pres_uri->s);
	LM_DBG("\twatcher_uri= %.*s\n", subs.watcher_uri->len,  subs.watcher_uri->s);
	LM_DBG("\texpires= %d\n", subs.expires);

	if(pua_send_subscribe(&subs)< 0)
	{
		LM_ERR("while sending SUBSCRIBE\n");
		goto error;
	}
	return 0;

error:
	if(type)
		xmlFree(type);

	return -1;
}