1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
13 //#define __u8 unsigned char
14 //#define __u16 unsigned short
15 //#define __u32 unsigned int
18 /* notify endpoint about state change (if any) */
19 static int notify_state_change(int join_id, int epoint_id, int old_state, int new_state)
21 int notify_off = 0, notify_on = 0;
22 struct lcr_msg *message;
24 if (old_state == new_state)
28 case NOTIFY_STATE_ACTIVE:
30 case NOTIFY_STATE_HOLD:
31 notify_on = INFO_NOTIFY_REMOTE_HOLD;
33 case NOTIFY_STATE_SUSPEND:
34 notify_on = INFO_NOTIFY_USER_SUSPENDED;
36 case NOTIFY_STATE_CONFERENCE:
37 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
42 case NOTIFY_STATE_HOLD:
44 case NOTIFY_STATE_ACTIVE:
45 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
47 case NOTIFY_STATE_SUSPEND:
48 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
49 notify_on = INFO_NOTIFY_USER_SUSPENDED;
51 case NOTIFY_STATE_CONFERENCE:
52 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
53 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
58 case NOTIFY_STATE_SUSPEND:
60 case NOTIFY_STATE_ACTIVE:
61 notify_off = INFO_NOTIFY_USER_RESUMED;
63 case NOTIFY_STATE_HOLD:
64 notify_off = INFO_NOTIFY_USER_RESUMED;
65 notify_on = INFO_NOTIFY_REMOTE_HOLD;
67 case NOTIFY_STATE_CONFERENCE:
68 notify_off = INFO_NOTIFY_USER_RESUMED;
69 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
74 case NOTIFY_STATE_CONFERENCE:
76 case NOTIFY_STATE_ACTIVE:
77 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
79 case NOTIFY_STATE_HOLD:
80 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
81 notify_on = INFO_NOTIFY_REMOTE_HOLD;
83 case NOTIFY_STATE_SUSPEND:
84 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
85 notify_on = INFO_NOTIFY_USER_SUSPENDED;
91 if (join_id && notify_off) {
92 message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
93 message->param.notifyinfo.notify = notify_off;
97 if (join_id && notify_on) {
98 message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
99 message->param.notifyinfo.notify = notify_on;
100 message_put(message);
107 /* debug function for join */
108 void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
110 struct join_relation *relation;
111 struct port_list *portlist;
112 class Endpoint *epoint;
116 if (!(options.deb & DEBUG_JOIN))
119 PDEBUG(DEBUG_JOIN, "join(%d) start (called from %s)\n", joinpbx->j_serial, function);
121 relation = joinpbx->j_relation;
124 PDEBUG(DEBUG_JOIN, "join has no relations\n");
126 epoint = find_epoint_id(relation->epoint_id);
128 PDEBUG(DEBUG_JOIN, "warning: relations epoint id=%d doesn't exists!\n", relation->epoint_id);
129 relation = relation->next;
133 UPRINT(strchr(buffer,0), "*** ep%d", relation->epoint_id);
134 UPRINT(strchr(buffer,0), " ifs=");
135 portlist = epoint->ep_portlist;
137 port = find_port_id(portlist->port_id);
139 UPRINT(strchr(buffer,0), "%s,", port->p_name);
141 UPRINT(strchr(buffer,0), "<port %d doesn't exist>,", portlist->port_id);
142 portlist = portlist->next;
144 // UPRINT(strchr(buffer,0), " endpoint=%d on=%s hold=%s", epoint->ep_serial, (epoint->ep_join_id==joinpbx->j_serial)?"yes":"no", (epoint->get_hold_id()==joinpbx->j_serial)?"yes":"no");
145 UPRINT(strchr(buffer,0), " endpoint=%d on=%s", epoint->ep_serial, (epoint->ep_join_id==joinpbx->j_serial)?"yes":"no");
146 switch(relation->type) {
147 case RELATION_TYPE_CALLING:
148 UPRINT(strchr(buffer,0), " type=CALLING");
150 case RELATION_TYPE_SETUP:
151 UPRINT(strchr(buffer,0), " type=SETUP");
153 case RELATION_TYPE_CONNECT:
154 UPRINT(strchr(buffer,0), " type=CONNECT");
157 UPRINT(strchr(buffer,0), " type=unknown");
160 if (relation->channel_state)
161 UPRINT(strchr(buffer,0), " channel=CONNECT");
163 UPRINT(strchr(buffer,0), " channel=HOLD");
164 switch(relation->tx_state) {
165 case NOTIFY_STATE_ACTIVE:
166 UPRINT(strchr(buffer,0), " tx_state=ACTIVE");
168 case NOTIFY_STATE_HOLD:
169 UPRINT(strchr(buffer,0), " tx_state=HOLD");
171 case NOTIFY_STATE_SUSPEND:
172 UPRINT(strchr(buffer,0), " tx_state=SUSPEND");
174 case NOTIFY_STATE_CONFERENCE:
175 UPRINT(strchr(buffer,0), " tx_state=CONFERENCE");
178 UPRINT(strchr(buffer,0), " tx_state=unknown");
181 switch(relation->rx_state) {
182 case NOTIFY_STATE_ACTIVE:
183 UPRINT(strchr(buffer,0), " rx_state=ACTIVE");
185 case NOTIFY_STATE_HOLD:
186 UPRINT(strchr(buffer,0), " rx_state=HOLD");
188 case NOTIFY_STATE_SUSPEND:
189 UPRINT(strchr(buffer,0), " rx_state=SUSPEND");
191 case NOTIFY_STATE_CONFERENCE:
192 UPRINT(strchr(buffer,0), " rx_state=CONFERENCE");
195 UPRINT(strchr(buffer,0), " rx_state=unknown");
198 PDEBUG(DEBUG_JOIN, "%s\n", buffer);
199 relation = relation->next;
202 PDEBUG(DEBUG_JOIN, "end\n");
207 * constructor for a new join
208 * the join will have a relation to the calling endpoint
210 JoinPBX::JoinPBX(class Endpoint *epoint) : Join()
212 struct join_relation *relation;
213 // char filename[256];
216 FATAL("epoint is NULL.\n");
218 PDEBUG(DEBUG_JOIN, "creating new join and connecting it to the endpoint.\n");
220 j_type = JOIN_TYPE_PBX;
222 j_caller_id[0] = '\0';
228 j_partyline_jingle = 0;
232 /* initialize a relation only to the calling interface */
233 relation = j_relation = (struct join_relation *)MALLOC(sizeof(struct join_relation));
235 relation->type = RELATION_TYPE_CALLING;
236 relation->channel_state = 0; /* audio is assumed on a new join */
237 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
238 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
239 relation->epoint_id = epoint->ep_serial;
242 if (options.deb & DEBUG_JOIN)
243 joinpbx_debug(this, "JoinPBX::Constructor(new join)");
252 struct join_relation *relation, *rtemp;
254 relation = j_relation;
256 rtemp = relation->next;
257 FREE(relation, sizeof(struct join_relation));
264 /* bridge sets the audio flow of all bchannels assiociated to 'this' join
265 * also it changes and notifies active/hold/conference states
267 void JoinPBX::bridge(void)
269 struct join_relation *relation;
270 struct lcr_msg *message;
271 int numconnect = 0, relations = 0;
272 class Endpoint *epoint;
273 struct port_list *portlist;
275 #ifdef DEBUG_COREBRIDGE
276 int allmISDN = 0; // never set for debug purpose
278 int allmISDN = 1; // set until a non-mISDN relation is found
281 relation = j_relation;
283 /* count all relations */
286 /* check for relation's objects */
287 epoint = find_epoint_id(relation->epoint_id);
289 PERROR("software error: relation without existing endpoints.\n");
290 relation = relation->next;
293 portlist = epoint->ep_portlist;
295 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
296 //#warning testing: keep on hold until single audio stream available
297 relation->channel_state = 0;
298 relation = relation->next;
301 if (portlist->next) {
302 PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
303 //#warning testing: keep on hold until single audio stream available
304 relation->channel_state = 0;
305 relation = relation->next;
308 port = find_port_id(portlist->port_id);
310 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
311 relation = relation->next;
314 if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) {
315 PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
317 PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
320 relation = relation->next;
324 relation = relation->next;
327 PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
328 /* we notify all relations about rxdata. */
329 relation = j_relation;
331 /* count connected relations */
332 if ((relation->channel_state == 1)
333 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
334 && (relation->rx_state != NOTIFY_STATE_HOLD))
337 /* remove unconnected parties from conference, also remove remotely disconnected parties so conference will not be disturbed. */
338 if (relation->channel_state == 1
339 && relation->rx_state != NOTIFY_STATE_HOLD
340 && relation->rx_state != NOTIFY_STATE_SUSPEND
341 && relations>1 // no conf with one member
342 && allmISDN) { // no conf if any member is not mISDN
343 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
344 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
345 message->param.mISDNsignal.conf = j_serial<<16 | j_pid;
346 PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
347 message_put(message);
349 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
350 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
351 message->param.mISDNsignal.conf = 0;
352 PDEBUG(DEBUG_JOIN, "join%d EP%d +off+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
353 message_put(message);
357 * request data from endpoint/port if:
359 * - any without mISDN
360 * in this case we bridge
362 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
363 message->param.mISDNsignal.message = mISDNSIGNAL_JOINDATA;
364 message->param.mISDNsignal.joindata = (relations==2 && !allmISDN);
365 PDEBUG(DEBUG_JOIN, "join%d EP%d set joindata=%d\n", j_serial, relation->epoint_id, message->param.mISDNsignal.joindata);
366 message_put(message);
368 relation = relation->next;
371 /* two people just exchange their states */
372 if (relations==2 && !j_partyline) {
373 PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial);
374 relation = j_relation;
375 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
376 relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
378 /* one member in a join, so we put her on hold */
379 if ((relations==1 || numconnect==1)/* && !j_partyline_jingle*/) {
380 PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial);
381 relation = j_relation;
383 if ((relation->channel_state == 1)
384 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
385 && (relation->rx_state != NOTIFY_STATE_HOLD))
386 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD);
387 relation = relation->next;
390 /* if conference/partyline (or more than two members and more than one is connected), so we set conference state */
391 PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect);
392 relation = j_relation;
394 if ((relation->channel_state == 1)
395 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
396 && (relation->rx_state != NOTIFY_STATE_HOLD))
397 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_CONFERENCE);
398 relation = relation->next;
404 * bridging is only possible with two connected endpoints
406 void JoinPBX::bridge_data(unsigned int epoint_from, struct join_relation *relation_from, union parameter *param)
408 struct join_relation *relation_to;
410 /* if we are alone */
411 if (!j_relation->next)
414 /* if we are more than two */
415 if (j_relation->next->next)
418 /* skip if source endpoint has NOT audio mode CONNECT */
419 if (relation_from->channel_state != 1)
422 /* get destination relation */
423 relation_to = j_relation;
424 if (relation_to == relation_from) {
425 /* oops, we are the first, so destination is: */
426 relation_to = relation_to->next;
429 /* skip if destination endpoint has NOT audio mode CONNECT */
430 if (relation_to->channel_state != 1)
433 /* now we may send our data to the endpoint where it
434 * will be delivered to the port
436 //printf("from %d, to %d\n", relation_from->epoint_id, relation_to->epoint_id);
437 message_forward(j_serial, relation_to->epoint_id, JOIN_TO_EPOINT, param);
440 /* release join from endpoint
441 * if the join has two relations, all relations are freed and the join will be
443 * on outgoing relations, the cause is collected, if not connected
444 * returns if join has been destroyed
446 int JoinPBX::release(struct join_relation *relation, int location, int cause)
448 struct join_relation *reltemp, **relationpointer;
449 struct lcr_msg *message;
453 /* remove from bridge */
454 if (relation->channel_state != 0) {
455 relation->channel_state = 0;
456 j_updatebridge = 1; /* update bridge flag */
457 // note: if join is not released, bridge must be updated
460 /* detach given interface */
461 reltemp = j_relation;
462 relationpointer = &j_relation;
464 /* endpoint of function call */
465 if (relation == reltemp)
467 relationpointer = &reltemp->next;
468 reltemp = reltemp->next;
471 FATAL("relation not in list of our relations. this must not happen.\n");
472 //printf("releasing relation %d\n", reltemp->epoint_id);
473 *relationpointer = reltemp->next;
474 FREE(reltemp, sizeof(struct join_relation));
476 relation = reltemp = NULL; // just in case of reuse fault;
478 /* if no more relation */
480 PDEBUG(DEBUG_JOIN, "join is completely removed.\n");
481 /* there is no more endpoint related to the join */
484 // end of join object!
485 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
487 /* if join is a party line */
489 PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n");
491 /* if only one relation left */
492 if (!j_relation->next) {
493 PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause);
494 message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
495 message->param.disconnectinfo.cause = cause;
496 message->param.disconnectinfo.location = location;
497 message_put(message);
500 // end of join object!
501 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
506 if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX)
507 joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}");
510 PDEBUG(DEBUG_JOIN, "join_release(): ended.\n");
514 /* count number of relations in a join
516 int joinpbx_countrelations(unsigned int join_id)
518 struct join_relation *relation;
521 class JoinPBX *joinpbx;
523 join = find_join_id(join_id);
528 if (join->j_type == JOIN_TYPE_REMOTE)
531 if (join->j_type != JOIN_TYPE_PBX)
533 joinpbx = (class JoinPBX *)join;
536 relation = joinpbx->j_relation;
539 relation = relation->next;
545 /* check if one is calling and all other relations are setup-realations */
546 int joinpbx_onecalling_othersetup(struct join_relation *relation)
548 int calling = 0, other = 0;
551 switch(relation->type) {
552 case RELATION_TYPE_CALLING:
555 case RELATION_TYPE_SETUP:
562 relation = relation->next;
565 if (calling == 1 && other == 0)
570 void JoinPBX::remove_relation(struct join_relation *relation)
572 struct join_relation *temp, **tempp;
580 if (temp == relation)
586 PERROR("relation not in join.\n");
590 PDEBUG(DEBUG_JOIN, "removing relation.\n");
591 *tempp = relation->next;
592 FREE(temp, sizeof(struct join_relation));
597 struct join_relation *JoinPBX::add_relation(void)
599 struct join_relation *relation;
602 PERROR("there is no first relation to this join\n");
605 relation = j_relation;
606 while(relation->next)
607 relation = relation->next;
609 relation->next = (struct join_relation *)MALLOC(sizeof(struct join_relation));
611 /* the record pointer is set at the first time the data is received for the relation */
613 // if (options.deb & DEBUG_JOIN)
614 // joinpbx_debug(join, "add_relation");
615 return(relation->next);
618 /* epoint sends a message to a join
621 void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
624 struct join_relation *relation, *reltemp;
627 struct lcr_msg *message;
628 // int size, writesize, oldpointer;
629 char *number, *numbers;
632 PERROR("software error, epoint == NULL\n");
636 // if (options.deb & DEBUG_JOIN) {
637 // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
638 // joinpbx_debug(join,"Join::message_epoint");
640 if (options.deb & DEBUG_JOIN) {
641 if (message_type != MESSAGE_DATA) {
644 if (cl->j_type == JOIN_TYPE_PBX)
645 joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
652 relation = j_relation;
654 if (relation->epoint_id == epoint_id)
656 relation = relation->next;
659 PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
663 /* count relations */
664 num=joinpbx_countrelations(j_serial);
666 /* process party line */
667 if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
668 j_partyline = param->setup.partyline;
669 j_partyline_jingle = param->setup.partyline_jingle;
672 switch(message_type) {
674 PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
675 relation->type = RELATION_TYPE_CONNECT;
676 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
677 SPRINT(message->param.connectinfo.id, "%d", j_partyline);
678 message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
679 message_put(message);
680 j_updatebridge = 1; /* update bridge flag */
681 if (j_partyline_jingle)
685 case MESSAGE_AUDIOPATH:
686 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
687 if (relation->channel_state != param->audiopath) {
688 relation->channel_state = param->audiopath;
689 j_updatebridge = 1; /* update bridge flag */
690 if (options.deb & DEBUG_JOIN)
691 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
695 case MESSAGE_DISCONNECT:
696 PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
697 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
698 message->param.disconnectinfo.cause = CAUSE_NORMAL;
699 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
700 message_put(message);
703 case MESSAGE_RELEASE:
704 PDEBUG(DEBUG_JOIN, "releasing from join\n");
705 release(relation, 0, 0);
706 if (j_partyline_jingle)
711 PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n");
717 /* process messages */
718 switch(message_type) {
719 /* process audio path message */
720 case MESSAGE_AUDIOPATH:
721 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
722 if (relation->channel_state != param->audiopath) {
723 relation->channel_state = param->audiopath;
724 j_updatebridge = 1; /* update bridge flag */
725 if (options.deb & DEBUG_JOIN)
726 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
732 switch(param->notifyinfo.notify) {
733 case INFO_NOTIFY_USER_SUSPENDED:
734 case INFO_NOTIFY_USER_RESUMED:
735 case INFO_NOTIFY_REMOTE_HOLD:
736 case INFO_NOTIFY_REMOTE_RETRIEVAL:
737 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
738 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
739 new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
740 if (new_state != relation->rx_state) {
741 relation->rx_state = new_state;
743 if (options.deb & DEBUG_JOIN)
744 joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
749 /* send notification to all other endpoints */
750 reltemp = j_relation;
752 if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) {
753 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
754 memcpy(&message->param, param, sizeof(union parameter));
755 message_put(message);
757 reltemp = reltemp->next;
764 /* now send audio data to the other endpoint */
765 bridge_data(epoint_id, relation, param);
768 /* relations sends a connect */
769 case MESSAGE_CONNECT:
770 /* outgoing setup type becomes connected */
771 if (relation->type == RELATION_TYPE_SETUP)
772 relation->type = RELATION_TYPE_CONNECT;
773 /* release other relations in setup state */
775 reltemp = j_relation;
777 //printf("connect, checking relation %d\n", reltemp->epoint_id);
778 if (reltemp->type == RELATION_TYPE_SETUP) {
779 //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
780 /* send release to endpoint */
781 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
782 message->param.disconnectinfo.cause = CAUSE_NONSELECTED;
783 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
784 message_put(message);
786 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards.
787 return; // must return, because join IS destroyed
790 if (reltemp->type == RELATION_TYPE_CALLING)
791 reltemp->type = RELATION_TYPE_CONNECT;
792 reltemp = reltemp->next;
794 break; // continue with our message
796 /* release is sent by endpoint */
797 case MESSAGE_RELEASE:
798 switch(relation->type) {
799 case RELATION_TYPE_SETUP: /* by called */
800 /* collect cause and send collected cause */
801 collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
803 release(relation, j_multilocation, j_multicause);
805 release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED);
808 case RELATION_TYPE_CALLING: /* by calling */
809 /* remove us, if we don't have a called releation yet */
810 if (!j_relation->next) {
811 release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
812 return; // must return, because join IS destroyed
814 /* in a conf, we don't kill the other members */
815 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation)) {
816 release(relation, 0, 0);
819 /* remove all relations that are of called type */
821 reltemp = j_relation;
823 if (reltemp->type == RELATION_TYPE_SETUP) {
824 /* send release to endpoint */
825 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type);
826 memcpy(&message->param, param, sizeof(union parameter));
827 message_put(message);
829 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL))
830 return; // must return, because join IS destroyed
833 reltemp = reltemp->next;
835 PERROR("we are still here, this should not happen\n");
838 default: /* by connected */
839 /* send current cause */
840 release(relation, param->disconnectinfo.location, param->disconnectinfo.cause);
842 return; // must return, because join may be destroyed
845 /* check number of relations */
846 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation) && message_type != MESSAGE_CONNECT) {
847 PDEBUG(DEBUG_JOIN, "we are in a conference, so we ignore the messages, except MESSAGE_CONNECT.\n");
851 /* if join has no other relation, we process the setup message */
853 switch(message_type) {
855 if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) {
856 /* in case of keypad */
857 numbers = param->setup.dialinginfo.keypad;
859 while((number = strsep(&numbers, ","))) {
860 if (out_setup(epoint_id, message_type, param, NULL, number))
861 return; // join destroyed
863 /* after keypad finish dialing */
867 numbers = param->setup.dialinginfo.id;
868 while((number = strsep(&numbers, ","))) {
869 if (out_setup(epoint_id, message_type, param, number, NULL))
870 return; // join destroyed
874 if (out_setup(epoint_id, message_type, param, NULL, NULL))
875 return; // join destroyed
879 PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
882 /* sending message to other relation(s) */
883 relation = j_relation;
885 if (relation->epoint_id != epoint_id) {
886 PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
887 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
888 memcpy(&message->param, param, sizeof(union parameter));
889 message_put(message);
890 PDEBUG(DEBUG_JOIN, "message sent.\n");
892 relation = relation->next;
898 /* join process is called from the main loop
899 * it processes the current calling state.
900 * returns 0 if join nothing was done
902 int JoinPBX::handler(void)
904 // struct join_relation *relation;
905 // char dialing[32][32];
911 /* the bridge must be updated */
912 if (j_updatebridge) {
922 int track_notify(int oldstate, int notify)
924 int newstate = oldstate;
927 case INFO_NOTIFY_USER_RESUMED:
928 case INFO_NOTIFY_REMOTE_RETRIEVAL:
929 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
930 case INFO_NOTIFY_RESERVED_CT_1:
931 case INFO_NOTIFY_RESERVED_CT_2:
932 case INFO_NOTIFY_CALL_IS_DIVERTING:
933 newstate = NOTIFY_STATE_ACTIVE;
936 case INFO_NOTIFY_USER_SUSPENDED:
937 newstate = NOTIFY_STATE_SUSPEND;
940 case INFO_NOTIFY_REMOTE_HOLD:
941 newstate = NOTIFY_STATE_HOLD;
944 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
945 newstate = NOTIFY_STATE_CONFERENCE;
954 * setup to exactly one endpoint
955 * if it fails, the calling endpoint is released.
956 * if other outgoing endpoints already exists, they are release as well.
957 * note: if this functions fails, it will destroy its own join object!
959 int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber, char *newkeypad)
961 struct join_relation *relation;
962 struct lcr_msg *message;
963 class Endpoint *epoint;
965 PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n");
966 /* create a new relation */
967 if (!(relation=add_relation()))
968 FATAL("No memory for relation.\n");
969 relation->type = RELATION_TYPE_SETUP;
970 relation->channel_state = 0; /* audio is assumed on a new join */
971 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
972 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
973 /* create a new endpoint */
974 epoint = new Endpoint(0, j_serial);
976 FATAL("No memory for Endpoint instance\n");
977 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 1))) // outgoing
978 FATAL("No memory for Endpoint Application instance\n");
979 relation->epoint_id = epoint->ep_serial;
980 /* send setup message to new endpoint */
981 //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial));
982 //i if (options.deb & DEBUG_JOIN)
983 // joinpbx_debug(join, "Join::message_epoint");
984 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
985 memcpy(&message->param, param, sizeof(union parameter));
987 SCPY(message->param.setup.dialinginfo.id, newnumber);
989 message->param.setup.dialinginfo.id[0] = '\0';
991 SCPY(message->param.setup.dialinginfo.keypad, newkeypad);
993 message->param.setup.dialinginfo.keypad[0] = '\0';
994 PDEBUG(DEBUG_JOIN, "setup message sent to ep %d with number='%s' keypad='%s'.\n", relation->epoint_id, message->param.setup.dialinginfo.id, message->param.setup.dialinginfo.keypad);
995 message_put(message);
1000 /* send play message to all members to play join/release jingle */
1001 void JoinPBX::play_jingle(int in)
1003 struct join_relation *relation;
1004 struct lcr_msg *message;
1006 relation = j_relation;
1010 if (!relation->next)
1013 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
1014 SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
1015 message_put(message);
1016 relation = relation->next;