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 void JoinPBX::remove_relation(struct join_relation *relation)
547 struct join_relation *temp, **tempp;
555 if (temp == relation)
561 PERROR("relation not in join.\n");
565 PDEBUG(DEBUG_JOIN, "removing relation.\n");
566 *tempp = relation->next;
567 FREE(temp, sizeof(struct join_relation));
572 struct join_relation *JoinPBX::add_relation(void)
574 struct join_relation *relation;
577 PERROR("there is no first relation to this join\n");
580 relation = j_relation;
581 while(relation->next)
582 relation = relation->next;
584 relation->next = (struct join_relation *)MALLOC(sizeof(struct join_relation));
586 /* the record pointer is set at the first time the data is received for the relation */
588 // if (options.deb & DEBUG_JOIN)
589 // joinpbx_debug(join, "add_relation");
590 return(relation->next);
593 /* epoint sends a message to a join
596 void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
599 struct join_relation *relation, *reltemp;
602 struct lcr_msg *message;
603 // int size, writesize, oldpointer;
604 char *number, *numbers;
607 PERROR("software error, epoint == NULL\n");
611 // if (options.deb & DEBUG_JOIN) {
612 // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
613 // joinpbx_debug(join,"Join::message_epoint");
615 if (options.deb & DEBUG_JOIN) {
616 if (message_type != MESSAGE_DATA) {
619 if (cl->j_type == JOIN_TYPE_PBX)
620 joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
627 relation = j_relation;
629 if (relation->epoint_id == epoint_id)
631 relation = relation->next;
634 PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
638 /* process party line */
639 if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
640 j_partyline = param->setup.partyline;
641 j_partyline_jingle = param->setup.partyline_jingle;
644 switch(message_type) {
646 PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
647 relation->type = RELATION_TYPE_CONNECT;
648 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
649 SPRINT(message->param.connectinfo.id, "%d", j_partyline);
650 message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
651 message_put(message);
652 j_updatebridge = 1; /* update bridge flag */
653 if (j_partyline_jingle)
657 case MESSAGE_AUDIOPATH:
658 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
659 if (relation->channel_state != param->audiopath) {
660 relation->channel_state = param->audiopath;
661 j_updatebridge = 1; /* update bridge flag */
662 if (options.deb & DEBUG_JOIN)
663 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
667 case MESSAGE_DISCONNECT:
668 PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
669 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
670 message->param.disconnectinfo.cause = CAUSE_NORMAL;
671 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
672 message_put(message);
675 case MESSAGE_RELEASE:
676 PDEBUG(DEBUG_JOIN, "releasing from join\n");
677 release(relation, 0, 0);
678 if (j_partyline_jingle)
683 PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n");
689 /* process messages */
690 switch(message_type) {
691 /* process audio path message */
692 case MESSAGE_AUDIOPATH:
693 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
694 if (relation->channel_state != param->audiopath) {
695 relation->channel_state = param->audiopath;
696 j_updatebridge = 1; /* update bridge flag */
697 if (options.deb & DEBUG_JOIN)
698 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
704 switch(param->notifyinfo.notify) {
705 case INFO_NOTIFY_USER_SUSPENDED:
706 case INFO_NOTIFY_USER_RESUMED:
707 case INFO_NOTIFY_REMOTE_HOLD:
708 case INFO_NOTIFY_REMOTE_RETRIEVAL:
709 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
710 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
711 new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
712 if (new_state != relation->rx_state) {
713 relation->rx_state = new_state;
715 if (options.deb & DEBUG_JOIN)
716 joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
721 /* send notification to all other endpoints */
722 reltemp = j_relation;
724 if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) {
725 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
726 memcpy(&message->param, param, sizeof(union parameter));
727 message_put(message);
729 reltemp = reltemp->next;
736 /* now send audio data to the other endpoint */
737 bridge_data(epoint_id, relation, param);
740 /* relations sends a connect */
741 case MESSAGE_CONNECT:
742 /* outgoing setup type becomes connected */
743 if (relation->type == RELATION_TYPE_SETUP)
744 relation->type = RELATION_TYPE_CONNECT;
745 /* release other relations in setup state */
747 reltemp = j_relation;
749 //printf("connect, checking relation %d\n", reltemp->epoint_id);
750 if (reltemp->type == RELATION_TYPE_SETUP) {
751 //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
752 /* send release to endpoint */
753 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
754 message->param.disconnectinfo.cause = CAUSE_NONSELECTED;
755 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
756 message_put(message);
758 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards.
759 return; // must return, because join IS destroyed
762 if (reltemp->type == RELATION_TYPE_CALLING)
763 reltemp->type = RELATION_TYPE_CONNECT;
764 reltemp = reltemp->next;
766 break; // continue with our message
768 /* release is sent by endpoint */
769 case MESSAGE_RELEASE:
770 switch(relation->type) {
771 case RELATION_TYPE_SETUP: /* by called */
772 /* collect cause and send collected cause */
773 collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
775 release(relation, j_multilocation, j_multicause);
777 release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED);
780 case RELATION_TYPE_CALLING: /* by calling */
781 /* remove us, if we don't have a called releation yet */
782 if (!j_relation->next) {
783 release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
784 return; // must return, because join IS destroyed
786 /* remove all relations that are in called */
788 reltemp = j_relation;
790 if (reltemp->type == RELATION_TYPE_SETUP) {
791 /* send release to endpoint */
792 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type);
793 memcpy(&message->param, param, sizeof(union parameter));
794 message_put(message);
796 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL))
797 return; // must return, because join IS destroyed
800 reltemp = reltemp->next;
802 PERROR("we are still here, this should not happen\n");
805 default: /* by connected */
806 /* send current cause */
807 release(relation, param->disconnectinfo.location, param->disconnectinfo.cause);
809 return; // must return, because join may be destroyed
812 /* count relations */
813 num=joinpbx_countrelations(j_serial);
815 /* check number of relations */
817 PDEBUG(DEBUG_JOIN, "join has more than two relations so there is no need to send a message.\n");
821 /* find interfaces not related to calling epoint */
822 relation = j_relation;
824 if (relation->epoint_id != epoint_id)
826 relation = relation->next;
829 switch(message_type) {
831 if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) {
832 numbers = param->setup.dialinginfo.id;
833 while((number = strsep(&numbers, ","))) {
834 if (out_setup(epoint_id, message_type, param, number))
835 return; // join destroyed
839 if (out_setup(epoint_id, message_type, param, NULL))
840 return; // join destroyed
844 PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
847 PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
848 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
849 memcpy(&message->param, param, sizeof(union parameter));
850 message_put(message);
851 PDEBUG(DEBUG_JOIN, "message sent.\n");
856 /* join process is called from the main loop
857 * it processes the current calling state.
858 * returns 0 if join nothing was done
860 int JoinPBX::handler(void)
862 // struct join_relation *relation;
863 // char dialing[32][32];
869 /* the bridge must be updated */
870 if (j_updatebridge) {
880 int track_notify(int oldstate, int notify)
882 int newstate = oldstate;
885 case INFO_NOTIFY_USER_RESUMED:
886 case INFO_NOTIFY_REMOTE_RETRIEVAL:
887 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
888 case INFO_NOTIFY_RESERVED_CT_1:
889 case INFO_NOTIFY_RESERVED_CT_2:
890 case INFO_NOTIFY_CALL_IS_DIVERTING:
891 newstate = NOTIFY_STATE_ACTIVE;
894 case INFO_NOTIFY_USER_SUSPENDED:
895 newstate = NOTIFY_STATE_SUSPEND;
898 case INFO_NOTIFY_REMOTE_HOLD:
899 newstate = NOTIFY_STATE_HOLD;
902 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
903 newstate = NOTIFY_STATE_CONFERENCE;
912 * setup to exactly one endpoint
913 * if it fails, the calling endpoint is released.
914 * if other outgoing endpoints already exists, they are release as well.
915 * note: if this functions fails, it will destroy its own join object!
917 int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber)
919 struct join_relation *relation;
920 struct lcr_msg *message;
921 class Endpoint *epoint;
923 PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n");
924 /* create a new relation */
925 if (!(relation=add_relation()))
926 FATAL("No memory for relation.\n");
927 relation->type = RELATION_TYPE_SETUP;
928 relation->channel_state = 0; /* audio is assumed on a new join */
929 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
930 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
931 /* create a new endpoint */
932 epoint = new Endpoint(0, j_serial);
934 FATAL("No memory for Endpoint instance\n");
935 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 1))) // outgoing
936 FATAL("No memory for Endpoint Application instance\n");
937 relation->epoint_id = epoint->ep_serial;
938 /* send setup message to new endpoint */
939 //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial));
940 //i if (options.deb & DEBUG_JOIN)
941 // joinpbx_debug(join, "Join::message_epoint");
942 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
943 memcpy(&message->param, param, sizeof(union parameter));
945 SCPY(message->param.setup.dialinginfo.id, newnumber);
946 PDEBUG(DEBUG_JOIN, "setup message sent to ep %d with number='%s'.\n", relation->epoint_id, message->param.setup.dialinginfo.id);
947 message_put(message);
952 /* send play message to all members to play join/release jingle */
953 void JoinPBX::play_jingle(int in)
955 struct join_relation *relation;
956 struct lcr_msg *message;
958 relation = j_relation;
965 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
966 SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
967 message_put(message);
968 relation = relation->next;