Esempio n. 1
0
void sca_publish(b2b_sca_record_t *record, str *extra_hdr)
{
	str_lst_t *new_watcher;
	publ_info_t publ;

	/* TESTING */
	//return;

	memset(&publ, 0, sizeof(publ_info_t));

	publ.id = callinfo_id;
	publ.body = NULL;

	publ.expires = record->expires;

	publ.flag|= UPDATE_TYPE;
	publ.source_flag|= CALLINFO_PUBLISH;
	publ.event|= CALLINFO_EVENT;

	publ.content_type.s = NULL;
	publ.content_type.len = 0;

	publ.etag = NULL;

	publ.extra_headers= extra_hdr;

	publ.outbound_proxy = presence_server;
	publ.cb_param = NULL;

	new_watcher = record->watchers;
	while (new_watcher) {
		publ.pres_uri = &new_watcher->watcher;
		if(pua_api.send_publish(&publ)< 0) {
			LM_ERR("sending publish failed\n");
		}
		new_watcher = new_watcher->next;
	}

	return;
}
Esempio n. 2
0
void reginfo_event_process()
{
    	publ_info_t publ;
	subs_info_t subs;
	reginfo_event_t *ev;
	for (;;) {
		LM_DBG("POPPING REGINFO EVENT\n");
	        ev = pop_reginfo_event();
	        LM_DBG("PROCESSING REGINFO EVENT with event [%d]\n", ev->event);

	        switch (ev->event) {
	        case REG_EVENT_PUBLISH:
	        	LM_DBG("Sending out-of-band publish with pres_uri [%.*s] publ_id [%.*s] publ_content_type [%.*s] extra_headers [%.*s]"
				"expires [%d] event [%d]\n",
				ev->pres_uri.len, ev->pres_uri.s, ev->publ_id.len, ev->publ_id.s, ev->publ_content_type.len, ev->publ_content_type.s,
				ev->extra_headers.len, ev->extra_headers.s, ev->expires, ev->reg_info_event);
			LM_DBG("publ_body [%.*s] \n",
				ev->publ_body.len, ev->publ_body.s);
			
			memset(&publ, 0, sizeof(publ_info_t));
			publ.pres_uri = &ev->pres_uri;
			publ.body = &ev->publ_body;
			publ.id = ev->publ_id;
			publ.content_type = ev->publ_content_type;
			publ.expires = ev->expires;

			/* make UPDATE_TYPE, as if this "publish dialog" is not found
			 by pua it will fallback to INSERT_TYPE anyway */
			publ.flag |= ev->flag;
			publ.source_flag |= ev->sourge_flag;
			publ.event |= ev->reg_info_event;
			publ.extra_headers = &ev->extra_headers;

			if (pua.send_publish(&publ) < 0) {
				LM_ERR("Error while sending publish\n");
			}
	        	break;
	        case REG_EVENT_SUBSCRIBE:
	        	memset(&subs, 0, sizeof(subs_info_t));

			subs.remote_target = &ev->subs_remote_target;
			subs.pres_uri= &ev->pres_uri;
			subs.watcher_uri= &ev->subs_watcher_uri;
			subs.expires = ev->expires;

			subs.source_flag= ev->sourge_flag;
			subs.event= ev->reg_info_event;
			subs.contact= &ev->subs_contact;
			subs.extra_headers = &ev->extra_headers;

			if(ev->subs_outbound_proxy.s) {
			    subs.outbound_proxy= &ev->subs_outbound_proxy;
			}

			subs.flag|= ev->flag;
			
			
			LM_DBG("Sending out-of-band subscribe with remote_target [%.*s] pres_uri [%.*s] subs_watcher_uri [%.*s] subs_contact [%.*s] extra_headers [%.*s] "
				"expires [%d] event [%d] flag [%d] source_flag [%d]\n",
				subs.remote_target->len, subs.remote_target->s, subs.pres_uri->len, subs.pres_uri->s, subs.watcher_uri->len, subs.watcher_uri->s,
				subs.contact->len, subs.contact->s, subs.extra_headers->len, subs.extra_headers->s, subs.expires, subs.event, subs.flag, subs.source_flag);
			if(subs.outbound_proxy) {
			    LM_DBG("subs_outbound_proxy [%.*s]\n",
				subs.outbound_proxy->len, subs.outbound_proxy->s);
			}
			

			if(pua.send_subscribe(&subs)< 0) {
				LM_ERR("while sending subscribe\n");
			}
			
	        	break;
	        default:
	        	LM_ERR("Unknown REG event.....ignoring\n");
	        	break;
	        }
	        free_reginfo_event(ev);
	}
}
Esempio n. 3
0
static void pua_rpc_publish(rpc_t* rpc, void* c)
{
	str pres_uri, expires, event, content_type, id, etag,
		outbound_proxy, extra_headers, body;
	rpc_delayed_ctx_t* dctx;
	int exp, sign, ret, err_ret, sip_error;
	char err_buf[MAX_REASON_LEN];
	struct sip_uri uri;
	publ_info_t publ;

	body.s = 0;
	body.len = 0;
	dctx = 0;

	LM_DBG("rpc publishing ...\n");

	if ((rpc->capabilities == 0) ||
	    !(rpc->capabilities(c) & RPC_DELAYED_REPLY)) {
		rpc->fault(c, 600, "Reply wait/async mode not supported"
			   " by this rpc transport");
		return;
	}

	ret = rpc->scan(c, "SSSSSSSS*S", &pres_uri, &expires, &event,
			&content_type, &id, &etag, &outbound_proxy,
			&extra_headers, &body);
	if (ret < 8) {
		rpc->fault(c, 400, "Too few or wrong type of parameters (%d)",
			   ret);
		return;
	}

	if (parse_uri(pres_uri.s, pres_uri.len, &uri) <0) {
		LM_ERR("bad resentity uri\n");
		rpc->fault(c, 400, "Invalid presentity uri '%s'", pres_uri.s);
		return;
	}
	LM_DBG("presentity uri '%.*s'\n", pres_uri.len, pres_uri.s);

	if (expires.s[0]== '-') {
		sign= -1;
		expires.s++;
		expires.len--;
	} else {
		sign = 1;
	}
	if (str2int(&expires, (unsigned int*)&exp) < 0) {
		LM_ERR("invalid expires parameter\n" );
		rpc->fault(c, 400, "Invalid expires value '%s'", expires.s);
		return;
	}
	exp = exp * sign;
	LM_DBG("expires '%d'\n", exp);

	LM_DBG("event '%.*s'\n", event.len, event.s);

	LM_DBG("content type '%.*s'\n", content_type.len, content_type.s);

	LM_DBG("id '%.*s'\n", id.len, id.s);

	LM_DBG("ETag '%.*s'\n", etag.len, etag.s);

	LM_DBG("outbound_proxy '%.*s'\n", outbound_proxy.len, outbound_proxy.s);

	LM_DBG("extra headers '%.*s'\n", extra_headers.len, extra_headers.s);

	if (body.len > 0) LM_DBG("body '%.*s'\n", body.len, body.s);

	if ((body.s == 0) &&
	    (content_type.len != 1 || content_type.s[0] != '.')) {
		LM_ERR("body is missing, but content type is not .\n");
		rpc->fault(c, 400, "Body is missing");
		return;
	}

	memset(&publ, 0, sizeof(publ_info_t));

	publ.pres_uri= &pres_uri;

	publ.expires= exp;

	publ.event= get_event_flag(&event);
	if (publ.event < 0) {
		LM_ERR("unknown event '%.*s'\n", event.len, event.s);
		rpc->fault(c, 400, "Unknown event");
		return;
	}

	if (content_type.len != 1) {
		publ.content_type= content_type;
	}

	if (!((id.len == 1) && (id.s[0]== '.'))) {
		publ.id= id;
	}

	if (!((etag.len== 1) && (etag.s[0]== '.'))) {
		publ.etag= &etag;
	}

	if (!((outbound_proxy.len == 1) && (outbound_proxy.s[0] == '.'))) {
		publ.outbound_proxy = &outbound_proxy;
	}

	if (!((extra_headers.len == 1) && (extra_headers.s[0] == '.'))) {
		publ.extra_headers = &extra_headers;
	}

	if (body.s != 0) {
		publ.body= &body;
	}

	dctx = rpc->delayed_ctx_new(c);
	if (dctx == 0) {
		LM_ERR("internal error: failed to create context\n");
		rpc->fault(c, 500, "Internal error: failed to create context");
		return;
	}
	publ.cb_param = dctx;
	publ.source_flag = MI_ASYN_PUBLISH;

	ret = pua_rpc_api.send_publish(&publ);
	LM_DBG("pua send_publish returned %d\n", ret);

	if (dctx->reply_ctx != 0) {
		/* callback was not executed or its execution failed */
		rpc = &dctx->rpc;
		c = dctx->reply_ctx;
	} else {
		return;
	}

	if (ret < 0) {
		LM_ERR("pua send_publish failed\n");
		err_ret = err2reason_phrase(ret, &sip_error, err_buf,
					    sizeof(err_buf), "RPC/PUBLISH") ;
		if (err_ret > 0 ) {
			rpc->fault(c, sip_error, "%s", err_buf);
		} else {
			rpc->fault(c, 500, "RPC/PUBLISH error");
		}
		rpc->delayed_ctx_close(dctx);
	}

	if (ret == 418) {
		rpc->fault(c, 500, "Wrong ETag");
		rpc->delayed_ctx_close(dctx);
	}


	return;
}
Esempio n. 4
0
int send_partial_publish(ppublic_t *impu, struct pcontact *c, int type)
{
	publ_info_t publ;
	str content_type;
	int id_buf_len;
	char id_buf[512];
	str p_asserted_identity_header;

	content_type.s = "application/reginfo+xml";
	content_type.len = 23;
	
	int len = strlen(P_ASSERTED_IDENTITY_HDR_PREFIX) + pcscf_uri.len + 1 + CRLF_LEN;
	p_asserted_identity_header.s = (char *)pkg_malloc( len );
	if ( p_asserted_identity_header.s == NULL ) {
	    LM_ERR( "insert_asserted_identity: pkg_malloc %d bytes failed", len );
	    goto error;
	}
	
	memcpy(p_asserted_identity_header.s, P_ASSERTED_IDENTITY_HDR_PREFIX, strlen(P_ASSERTED_IDENTITY_HDR_PREFIX));
	p_asserted_identity_header.len = strlen(P_ASSERTED_IDENTITY_HDR_PREFIX);
	memcpy(p_asserted_identity_header.s + p_asserted_identity_header.len, pcscf_uri.s, pcscf_uri.len);
	p_asserted_identity_header.len += pcscf_uri.len;
	*(p_asserted_identity_header.s + p_asserted_identity_header.len) = '>';
	p_asserted_identity_header.len ++;
	memcpy( p_asserted_identity_header.s + p_asserted_identity_header.len, CRLF, CRLF_LEN );
	p_asserted_identity_header.len += CRLF_LEN;
	
	LM_DBG("p_asserted_identity_header: [%.*s]", p_asserted_identity_header.len, p_asserted_identity_header.s);
	
	LM_DBG("Sending publish\n");
	str *body = build_reginfo_partial(impu, c, type);

	if (body == NULL || body->s == NULL) {
		LM_ERR("Error on creating XML-Body for publish\n");
		goto error;
	}
	LM_DBG("XML-Body:\n%.*s\n", body->len, body->s);

	memset(&publ, 0, sizeof(publ_info_t));
	publ.pres_uri = &impu->public_identity;
	publ.body = body;
	id_buf_len = snprintf(id_buf, sizeof(id_buf), "IMSPCSCF_PUBLISH.%.*s", c->aor.len, c->aor.s);
	publ.id.s = id_buf;
	publ.id.len = id_buf_len;
	publ.content_type = content_type;
	publ.expires = 3600;

	/* make UPDATE_TYPE, as if this "publish dialog" is not found
	 by pua it will fallback to INSERT_TYPE anyway */
	publ.flag |= UPDATE_TYPE;
	publ.source_flag |= REGINFO_PUBLISH;
	publ.event |= REGINFO_EVENT;
	publ.extra_headers = &p_asserted_identity_header;

	if (pua.send_publish(&publ) < 0) {
		LM_ERR("Error while sending publish\n");
	}
	if (p_asserted_identity_header.s) {
		pkg_free(p_asserted_identity_header.s);
	}
	
	return 1;

error:
	
	if (p_asserted_identity_header.s) {
		pkg_free(p_asserted_identity_header.s);
	}
	if (body) {
		if (body->s)
			xmlFree(body->s);
		pkg_free(body);
	}
	return -1;
}