Exemple #1
0
void sipomatic_iterate(Sipomatic *obj)
{
	MSList *elem;
	MSList *to_be_destroyed=NULL;
	Call *call;
	double elapsed;
	eXosip_event_t *ev;

	while((ev=eXosip_event_wait(0,0))!=NULL){
		sipomatic_process_event(obj,ev);
	}
	elem=obj->calls;
	while(elem!=NULL){
		call=(Call*)elem->data;
		elapsed=time(NULL)-call->time;
		switch(call->state){
			case CALL_STATE_INIT:
				if (elapsed>obj->acceptance_time){
					call_accept(call);
				}
			break;
			case CALL_STATE_RUNNING:
				if (elapsed>obj->max_call_time || call->eof){
					call_release(call);
					to_be_destroyed=ms_list_append(to_be_destroyed,call);
				}
			break;
		}
		elem=ms_list_next(elem);
	}
	for(;to_be_destroyed!=NULL; to_be_destroyed=ms_list_next(to_be_destroyed)){
		call_destroy((Call*)to_be_destroyed->data);
	}
}
Exemple #2
0
/* Handle incoming calls */
static void sipsess_conn_handler(const struct sip_msg *msg, void *arg)
{
	const struct sip_hdr *hdr;
	struct ua *ua;
	struct call *call = NULL;
	char to_uri[256];
	int err;

	(void)arg;

	ua = uag_find(&msg->uri.user);
	if (!ua) {
		warning("ua: %r: UA not found: %r\n",
			&msg->from.auri, &msg->uri.user);
		(void)sip_treply(NULL, uag_sip(), msg, 404, "Not Found");
		return;
	}

	/* handle multiple calls */
	if (list_count(&ua->calls) + 1 > MAX_CALLS) {
		info("ua: rejected call from %r (maximum %d calls)\n",
		     &msg->from.auri, MAX_CALLS);
		(void)sip_treply(NULL, uag.sip, msg, 486, "Busy Here");
		return;
	}

	/* Handle Require: header, check for any required extensions */
	hdr = sip_msg_hdr_apply(msg, true, SIP_HDR_REQUIRE,
				require_handler, ua);
	if (hdr) {
		info("ua: call from %r rejected with 420"
			     " -- option-tag '%r' not supported\n",
			     &msg->from.auri, &hdr->val);

		(void)sip_treplyf(NULL, NULL, uag.sip, msg, false,
				  420, "Bad Extension",
				  "Unsupported: %r\r\n"
				  "Content-Length: 0\r\n\r\n",
				  &hdr->val);
		return;
	}

	(void)pl_strcpy(&msg->to.auri, to_uri, sizeof(to_uri));

	err = ua_call_alloc(&call, ua, VIDMODE_ON, msg, NULL, to_uri);
	if (err) {
		warning("ua: call_alloc: %m\n", err);
		goto error;
	}

	err = call_accept(call, uag.sock, msg);
	if (err)
		goto error;

	return;

 error:
	mem_deref(call);
	(void)sip_treply(NULL, uag.sip, msg, 500, "Call Error");
}