コード例 #1
0
ファイル: priserver.c プロジェクト: DastanIqbal/FreeSWITCH
static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) 
{
	printf( "number is: %s\n", event->ring.callednum);
	if(strlen(event->ring.callednum) > 3) {
		printf( "final number is: %s\n", event->ring.callednum);
		pri_answer(spri->pri, event->ring.call, 0, 1);
	}
	return 0;
}
コード例 #2
0
ファイル: priserver.c プロジェクト: DastanIqbal/FreeSWITCH
static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event) 
{
	printf("-- Ring on channel %d (from %s to %s), answering...\n", event->ring.channel, event->ring.callingnum, event->ring.callednum);
	pri_answer(spri->pri, event->ring.call, event->ring.channel, 1);
	memcpy(&pidmap[event->ring.channel-1].call, event->ring.call, sizeof(q931_call));
	pidmap[event->ring.channel-1].pri=spri->pri;
	pidmap[event->ring.channel-1].call = *event->ring.call;
	launch_channel(spri, event->ring.channel);
	return 0;
}
コード例 #3
0
static void event1(struct pri *pri, pri_event *e)
{
	/* Network */
	int x;
	static q931_call *calls[TEST_CALLS];
	char name[256], num[256], dest[256];
	switch(e->gen.e) {
	case PRI_EVENT_DCHAN_UP:
		printf("Network is up.  Sending blast of calls!\n");
		for (x=0;x<TEST_CALLS;x++) {
			sprintf(name, "Caller %d", x + 1);
			sprintf(num, "25642860%02d", x+1);
			sprintf(dest, "60%02d", x + 1);
			if (!(calls[x] = pri_new_call(pri))) {
				perror("pri_new_call");
				continue;
			}
#if 0
			{
				struct pri_sr *sr;
				sr = pri_sr_new();
				pri_sr_set_channel(sr, x+1, 0, 0);
				pri_sr_set_bearer(sr, 0, PRI_LAYER_1_ULAW);
				pri_sr_set_called(sr, dest, PRI_NATIONAL_ISDN, 1);
				pri_sr_set_caller(sr, num, name, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
				pri_sr_set_redirecting(sr, num, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
				if (pri_setup(pri, calls[x], sr))
					perror("pri_setup");
				pri_sr_free(sr);
			}
#else
			if (pri_call(pri, calls[x], PRI_TRANS_CAP_DIGITAL, x + 1, 1, 1, num, 
				PRI_NATIONAL_ISDN, name, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
				dest, PRI_NATIONAL_ISDN, PRI_LAYER_1_ULAW)) {
					perror("pri_call");
			}
#endif
		}
		printf("Setup %d calls!\n", TEST_CALLS);
		break;
	case PRI_EVENT_RINGING:
		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
		q931_facility(pri, e->ringing.call);
		pri_answer(pri, e->ringing.call, e->ringing.channel, 0);
		break;
	case PRI_EVENT_HANGUP_REQ:
		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
		pri_hangup(pri, e->hangup.call, e->hangup.cause);
		break;
	default:
		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
	}
}
コード例 #4
0
ファイル: pritest.c プロジェクト: Distrotech/libpri
static void start_channel(struct pri *pri, pri_event *e)
{
	int channo = e->ring.channel;
	int		flag = 1;
	pri_event_ring	*ring = &e->ring;

	if(channo == -1) {
		channo = e->ring.channel = get_free_channel(MAX_CHAN);

		if(channo == DCHANNEL_TIMESLOT)
			channo = e->ring.channel = get_free_channel(MAX_CHAN);
		  
		
		fprintf(stdout, "Any channel selected: %d\n", channo);

		if(!channo) {
		  pri_release(pri, ring->call, PRI_CAUSE_REQUESTED_CHAN_UNAVAIL);
		  fprintf(stdout, "Abort call due to no avl B channels\n");
		  return;
		}

		flag = 0;
	}
	/* Make sure it's a valid number */
	if ((channo >= MAX_CHAN) || (channo < 0)) { 
		fprintf(stderr, "--!! Channel %d is out of range\n", channo);
		return;
	}

	/* Make sure nothing is there */
	if (chans[channo].pid) {
		fprintf(stderr, "--!! Channel %d still has a call on it, ending it...\n", channo);
		hangup_channel(channo);
		/* Wait for it to die */
		while(chans[channo].pid)
			usleep(100);
	}

	/* Record call number */
	chans[channo].call = e->ring.call;

	/* Answer the line */
	if(flag) {
		pri_answer(pri, chans[channo].call, channo, 1);
	} else {
		pri_need_more_info(pri, chans[channo].call, channo, 1);
	}

	/* Launch a process to handle it */
	launch_channel(channo);

}
コード例 #5
0
ファイル: pritest.c プロジェクト: Distrotech/libpri
static void handle_pri_event(struct pri *pri, pri_event *e)
{
	switch(e->e) {
	case PRI_EVENT_DCHAN_UP:
		printf("-- D-Channel is now up!  :-)\n");
		break;
	case PRI_EVENT_DCHAN_DOWN:
		printf("-- D-Channel is now down! :-(\n");
		break;
	case PRI_EVENT_RESTART:
		printf("-- Restarting channel %d\n", e->restart.channel);
		hangup_channel(e->restart.channel);
		break;
	case PRI_EVENT_CONFIG_ERR:
		printf("-- Configuration error detected: %s\n", e->err.err);
		break;
	case PRI_EVENT_RING:
		printf("-- Ring on channel %d (from %s to %s), answering...\n", e->ring.channel, e->ring.callingnum, e->ring.callednum);
		start_channel(pri, e);
		break;
	case PRI_EVENT_HANGUP:
		printf("-- Hanging up channel %d\n", e->hangup.channel);
		hangup_channel(e->hangup.channel);
		break;
	case PRI_EVENT_RINGING:
	case PRI_EVENT_ANSWER:
		fprintf(stderr, "--!! What?  We shouldn't be making any calls...\n");
		break;
	case PRI_EVENT_HANGUP_ACK:
		/* Ignore */
		break;
	case PRI_EVENT_INFO_RECEIVED:
		fprintf(stdout, "number is: %s\n", e->ring.callednum);
		if(!number_incommplete(e->ring.callednum)) {
			fprintf(stdout, "final number is: %s\n", e->ring.callednum);
			pri_answer(pri, e->ring.call, 0, 1);
		}
		
		break;
	default:
		fprintf(stderr, "--!! Unknown PRI event %d\n", e->e);
	}
}