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 long
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)
29 case NOTIFY_STATE_ACTIVE:
32 case NOTIFY_STATE_HOLD:
33 notify_on = INFO_NOTIFY_REMOTE_HOLD;
35 case NOTIFY_STATE_SUSPEND:
36 notify_on = INFO_NOTIFY_USER_SUSPENDED;
38 case NOTIFY_STATE_CONFERENCE:
39 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
44 case NOTIFY_STATE_HOLD:
47 case NOTIFY_STATE_ACTIVE:
48 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
50 case NOTIFY_STATE_SUSPEND:
51 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
52 notify_on = INFO_NOTIFY_USER_SUSPENDED;
54 case NOTIFY_STATE_CONFERENCE:
55 notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
56 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
61 case NOTIFY_STATE_SUSPEND:
64 case NOTIFY_STATE_ACTIVE:
65 notify_off = INFO_NOTIFY_USER_RESUMED;
67 case NOTIFY_STATE_HOLD:
68 notify_off = INFO_NOTIFY_USER_RESUMED;
69 notify_on = INFO_NOTIFY_REMOTE_HOLD;
71 case NOTIFY_STATE_CONFERENCE:
72 notify_off = INFO_NOTIFY_USER_RESUMED;
73 notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED;
78 case NOTIFY_STATE_CONFERENCE:
81 case NOTIFY_STATE_ACTIVE:
82 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
84 case NOTIFY_STATE_HOLD:
85 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
86 notify_on = INFO_NOTIFY_REMOTE_HOLD;
88 case NOTIFY_STATE_SUSPEND:
89 notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
90 notify_on = INFO_NOTIFY_USER_SUSPENDED;
96 if (join_id && notify_off)
98 message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
99 message->param.notifyinfo.notify = notify_off;
100 message_put(message);
103 if (join_id && notify_on)
105 message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
106 message->param.notifyinfo.notify = notify_on;
107 message_put(message);
114 /* debug function for join */
115 void joinpbx_debug(class JoinPBX *joinpbx, char *function)
117 struct join_relation *relation;
118 struct port_list *portlist;
119 class Endpoint *epoint;
123 if (!(options.deb & DEBUG_JOIN))
126 PDEBUG(DEBUG_JOIN, "join(%d) start (called from %s)\n", joinpbx->j_serial, function);
128 relation = joinpbx->j_relation;
131 PDEBUG(DEBUG_JOIN, "join has no relations\n");
134 epoint = find_epoint_id(relation->epoint_id);
137 PDEBUG(DEBUG_JOIN, "warning: relations epoint id=%ld doesn't exists!\n", relation->epoint_id);
138 relation = relation->next;
142 UPRINT(strchr(buffer,0), "*** ep%ld", relation->epoint_id);
143 UPRINT(strchr(buffer,0), " ifs=");
144 portlist = epoint->ep_portlist;
147 port = find_port_id(portlist->port_id);
149 UPRINT(strchr(buffer,0), "%s,", port->p_name);
151 UPRINT(strchr(buffer,0), "<port %ld doesn't exist>,", portlist->port_id);
152 portlist = portlist->next;
154 // 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");
155 UPRINT(strchr(buffer,0), " endpoint=%d on=%s", epoint->ep_serial, (epoint->ep_join_id==joinpbx->j_serial)?"yes":"no");
156 switch(relation->type)
158 case RELATION_TYPE_CALLING:
159 UPRINT(strchr(buffer,0), " type=CALLING");
161 case RELATION_TYPE_SETUP:
162 UPRINT(strchr(buffer,0), " type=SETUP");
164 case RELATION_TYPE_CONNECT:
165 UPRINT(strchr(buffer,0), " type=CONNECT");
168 UPRINT(strchr(buffer,0), " type=unknown");
171 switch(relation->channel_state)
173 case CHANNEL_STATE_CONNECT:
174 UPRINT(strchr(buffer,0), " channel=CONNECT");
176 case CHANNEL_STATE_HOLD:
177 UPRINT(strchr(buffer,0), " channel=HOLD");
180 UPRINT(strchr(buffer,0), " channel=unknown");
183 switch(relation->tx_state)
185 case NOTIFY_STATE_ACTIVE:
186 UPRINT(strchr(buffer,0), " tx_state=ACTIVE");
188 case NOTIFY_STATE_HOLD:
189 UPRINT(strchr(buffer,0), " tx_state=HOLD");
191 case NOTIFY_STATE_SUSPEND:
192 UPRINT(strchr(buffer,0), " tx_state=SUSPEND");
194 case NOTIFY_STATE_CONFERENCE:
195 UPRINT(strchr(buffer,0), " tx_state=CONFERENCE");
198 UPRINT(strchr(buffer,0), " tx_state=unknown");
201 switch(relation->rx_state)
203 case NOTIFY_STATE_ACTIVE:
204 UPRINT(strchr(buffer,0), " rx_state=ACTIVE");
206 case NOTIFY_STATE_HOLD:
207 UPRINT(strchr(buffer,0), " rx_state=HOLD");
209 case NOTIFY_STATE_SUSPEND:
210 UPRINT(strchr(buffer,0), " rx_state=SUSPEND");
212 case NOTIFY_STATE_CONFERENCE:
213 UPRINT(strchr(buffer,0), " rx_state=CONFERENCE");
216 UPRINT(strchr(buffer,0), " rx_state=unknown");
219 PDEBUG(DEBUG_JOIN, "%s\n", buffer);
220 relation = relation->next;
223 PDEBUG(DEBUG_JOIN, "end\n");
228 * constructor for a new join
229 * the join will have a relation to the calling endpoint
231 JoinPBX::JoinPBX(class Endpoint *epoint) : Join()
233 struct join_relation *relation;
234 // char filename[256];
237 FATAL("epoint is NULL.\n");
239 PDEBUG(DEBUG_JOIN, "creating new join and connecting it to the endpoint.\n");
241 j_type = JOIN_TYPE_PBX;
243 j_caller_id[0] = '\0';
249 j_partyline_jingle = 0;
253 /* initialize a relation only to the calling interface */
254 relation = j_relation = (struct join_relation *)MALLOC(sizeof(struct join_relation));
256 relation->type = RELATION_TYPE_CALLING;
257 relation->channel_state = CHANNEL_STATE_HOLD; /* audio is assumed on a new join */
258 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
259 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
260 relation->epoint_id = epoint->ep_serial;
263 if (options.deb & DEBUG_JOIN)
264 joinpbx_debug(this, "JoinPBX::Constructor(new join)");
273 struct join_relation *relation, *rtemp;
275 relation = j_relation;
278 rtemp = relation->next;
279 FREE(relation, sizeof(struct join_relation));
286 /* bridge sets the audio flow of all bchannels assiociated to 'this' join
287 * also it changes and notifies active/hold/conference states
289 void JoinPBX::bridge(void)
291 struct join_relation *relation;
292 struct lcr_msg *message;
293 int numconnect = 0, relations = 0;
294 class Endpoint *epoint;
295 struct port_list *portlist;
297 #ifdef DEBUG_COREBRIDGE
298 int allmISDN = 0; // never set for debug purpose
300 int allmISDN = 1; // set until a non-mISDN relation is found
303 relation = j_relation;
306 /* count all relations */
309 /* check for relation's objects */
310 epoint = find_epoint_id(relation->epoint_id);
313 PERROR("software error: relation without existing endpoints.\n");
314 relation = relation->next;
317 portlist = epoint->ep_portlist;
320 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
321 //#warning testing: keep on hold until single audio stream available
322 relation->channel_state = CHANNEL_STATE_HOLD;
323 relation = relation->next;
328 PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
329 //#warning testing: keep on hold until single audio stream available
330 relation->channel_state = CHANNEL_STATE_HOLD;
331 relation = relation->next;
334 port = find_port_id(portlist->port_id);
337 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
338 relation = relation->next;
341 if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN)
343 PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
346 PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
349 relation = relation->next;
353 relation = relation->next;
356 PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
357 /* we notify all relations about rxdata. */
358 relation = j_relation;
361 /* count connected relations */
362 if ((relation->channel_state == CHANNEL_STATE_CONNECT)
363 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
364 && (relation->rx_state != NOTIFY_STATE_HOLD))
367 /* remove unconnected parties from conference, also remove remotely disconnected parties so conference will not be disturbed. */
368 if (relation->channel_state == CHANNEL_STATE_CONNECT
369 && relation->rx_state != NOTIFY_STATE_HOLD
370 && relation->rx_state != NOTIFY_STATE_SUSPEND
371 && relations>1 // no conf with one member
372 && allmISDN) // no conf if any member is not mISDN
374 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
375 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
376 message->param.mISDNsignal.conf = j_serial<<16 | j_pid;
377 PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
378 message_put(message);
381 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
382 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
383 message->param.mISDNsignal.conf = 0;
384 PDEBUG(DEBUG_JOIN, "join%d EP%d +off+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
385 message_put(message);
389 * request data from endpoint/port if:
391 * - any without mISDN
392 * in this case we bridge
394 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
395 message->param.mISDNsignal.message = mISDNSIGNAL_JOINDATA;
396 message->param.mISDNsignal.joindata = (relations==2 && !allmISDN);
397 PDEBUG(DEBUG_JOIN, "join%d EP%d set joindata=%d\n", j_serial, relation->epoint_id, message->param.mISDNsignal.joindata);
398 message_put(message);
400 relation = relation->next;
403 /* two people just exchange their states */
404 if (relations==2 && !j_partyline)
406 PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial);
407 relation = j_relation;
408 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
409 relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
411 /* one member in a join, so we put her on hold */
412 if ((relations==1 || numconnect==1)/* && !j_partyline_jingle*/)
414 PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial);
415 relation = j_relation;
418 if ((relation->channel_state == CHANNEL_STATE_CONNECT)
419 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
420 && (relation->rx_state != NOTIFY_STATE_HOLD))
421 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD);
422 relation = relation->next;
425 /* if conference/partyline (or more than two members and more than one is connected), so we set conference state */
427 PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect);
428 relation = j_relation;
431 if ((relation->channel_state == CHANNEL_STATE_CONNECT)
432 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
433 && (relation->rx_state != NOTIFY_STATE_HOLD))
434 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_CONFERENCE);
435 relation = relation->next;
441 * bridging is only possible with two connected endpoints
443 void JoinPBX::bridge_data(unsigned long epoint_from, struct join_relation *relation_from, union parameter *param)
445 struct join_relation *relation_to;
447 /* if we are alone */
448 if (!j_relation->next)
451 /* if we are more than two */
452 if (j_relation->next->next)
455 /* skip if source endpoint has NOT audio mode CONNECT */
456 if (relation_from->channel_state != CHANNEL_STATE_CONNECT)
459 /* get destination relation */
460 relation_to = j_relation;
461 if (relation_to == relation_from)
463 /* oops, we are the first, so destination is: */
464 relation_to = relation_to->next;
467 /* skip if destination endpoint has NOT audio mode CONNECT */
468 if (relation_to->channel_state != CHANNEL_STATE_CONNECT)
471 /* now we may send our data to the endpoint where it
472 * will be delivered to the port
474 //printf("from %d, to %d\n", relation_from->epoint_id, relation_to->epoint_id);
475 message_forward(j_serial, relation_to->epoint_id, JOIN_TO_EPOINT, param);
478 /* release join from endpoint
479 * if the join has two relations, all relations are freed and the join will be
481 * on outgoing relations, the cause is collected, if not connected
482 * returns if join has been destroyed
484 int JoinPBX::release(struct join_relation *relation, int location, int cause)
486 struct join_relation *reltemp, **relationpointer;
487 struct lcr_msg *message;
491 /* remove from bridge */
492 if (relation->channel_state != CHANNEL_STATE_HOLD)
494 relation->channel_state = CHANNEL_STATE_HOLD;
495 j_updatebridge = 1; /* update bridge flag */
496 // note: if join is not released, bridge must be updated
499 /* detach given interface */
500 reltemp = j_relation;
501 relationpointer = &j_relation;
504 /* endpoint of function call */
505 if (relation == reltemp)
507 relationpointer = &reltemp->next;
508 reltemp = reltemp->next;
511 FATAL("relation not in list of our relations. this must not happen.\n");
512 //printf("releasing relation %d\n", reltemp->epoint_id);
513 *relationpointer = reltemp->next;
514 FREE(reltemp, sizeof(struct join_relation));
516 relation = reltemp = NULL; // just in case of reuse fault;
518 /* if no more relation */
521 PDEBUG(DEBUG_JOIN, "join is completely removed.\n");
522 /* there is no more endpoint related to the join */
525 // end of join object!
526 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
528 /* if join is a party line */
531 PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n");
533 /* if only one relation left */
534 if (!j_relation->next)
536 PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause);
537 message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
538 message->param.disconnectinfo.cause = cause;
539 message->param.disconnectinfo.location = location;
540 message_put(message);
543 // end of join object!
544 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
550 if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX)
551 joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}");
554 PDEBUG(DEBUG_JOIN, "join_release(): ended.\n");
558 /* count number of relations in a join
560 int joinpbx_countrelations(unsigned long join_id)
562 struct join_relation *relation;
565 class JoinPBX *joinpbx;
567 join = find_join_id(join_id);
572 if (join->j_type != JOIN_TYPE_REMOTE)
575 if (join->j_type != JOIN_TYPE_PBX)
577 joinpbx = (class JoinPBX *)join;
580 relation = joinpbx->j_relation;
584 relation = relation->next;
590 void JoinPBX::remove_relation(struct join_relation *relation)
592 struct join_relation *temp, **tempp;
601 if (temp == relation)
608 PERROR("relation not in join.\n");
612 PDEBUG(DEBUG_JOIN, "removing relation.\n");
613 *tempp = relation->next;
614 FREE(temp, sizeof(struct join_relation));
619 struct join_relation *JoinPBX::add_relation(void)
621 struct join_relation *relation;
625 PERROR("there is no first relation to this join\n");
628 relation = j_relation;
629 while(relation->next)
630 relation = relation->next;
632 relation->next = (struct join_relation *)MALLOC(sizeof(struct join_relation));
634 /* the record pointer is set at the first time the data is received for the relation */
636 // if (options.deb & DEBUG_JOIN)
637 // joinpbx_debug(join, "add_relation");
638 return(relation->next);
641 /* epoint sends a message to a join
644 void JoinPBX::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
647 struct join_relation *relation, *reltemp;
650 struct lcr_msg *message;
651 // int size, writesize, oldpointer;
652 char *number, *numbers;
656 PERROR("software error, epoint == NULL\n");
660 // if (options.deb & DEBUG_JOIN)
662 // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
663 // joinpbx_debug(join,"Join::message_epoint");
665 if (options.deb & DEBUG_JOIN)
667 if (message_type != MESSAGE_DATA)
672 if (cl->j_type == JOIN_TYPE_PBX)
673 joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
680 relation = j_relation;
683 if (relation->epoint_id == epoint_id)
685 relation = relation->next;
689 PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
693 /* process party line */
694 if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline)
696 j_partyline = param->setup.partyline;
697 j_partyline_jingle = param->setup.partyline_jingle;
704 PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
705 relation->type = RELATION_TYPE_CONNECT;
706 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
707 SPRINT(message->param.connectinfo.id, "%d", j_partyline);
708 message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
709 message_put(message);
710 j_updatebridge = 1; /* update bridge flag */
711 if (j_partyline_jingle)
715 case MESSAGE_AUDIOPATH:
716 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
717 if (relation->channel_state != param->audiopath)
719 relation->channel_state = param->audiopath;
720 j_updatebridge = 1; /* update bridge flag */
721 if (options.deb & DEBUG_JOIN)
722 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
726 case MESSAGE_DISCONNECT:
727 PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
728 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
729 message->param.disconnectinfo.cause = CAUSE_NORMAL;
730 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
731 message_put(message);
734 case MESSAGE_RELEASE:
735 PDEBUG(DEBUG_JOIN, "releasing from join\n");
736 release(relation, 0, 0);
737 if (j_partyline_jingle)
742 PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n");
748 /* process messages */
751 /* process audio path message */
752 case MESSAGE_AUDIOPATH:
753 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
754 if (relation->channel_state != param->audiopath)
756 relation->channel_state = param->audiopath;
757 j_updatebridge = 1; /* update bridge flag */
758 if (options.deb & DEBUG_JOIN)
759 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
765 switch(param->notifyinfo.notify)
767 case INFO_NOTIFY_USER_SUSPENDED:
768 case INFO_NOTIFY_USER_RESUMED:
769 case INFO_NOTIFY_REMOTE_HOLD:
770 case INFO_NOTIFY_REMOTE_RETRIEVAL:
771 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
772 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
773 new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
774 if (new_state != relation->rx_state)
776 relation->rx_state = new_state;
778 if (options.deb & DEBUG_JOIN)
779 joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
784 /* send notification to all other endpoints */
785 reltemp = j_relation;
788 if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id)
790 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
791 memcpy(&message->param, param, sizeof(union parameter));
792 message_put(message);
794 reltemp = reltemp->next;
801 /* now send audio data to the other endpoint */
802 bridge_data(epoint_id, relation, param);
805 /* relations sends a connect */
806 case MESSAGE_CONNECT:
807 /* outgoing setup type becomes connected */
808 if (relation->type == RELATION_TYPE_SETUP)
809 relation->type = RELATION_TYPE_CONNECT;
810 /* release other relations in setup state */
812 reltemp = j_relation;
815 //printf("connect, checking relation %d\n", reltemp->epoint_id);
816 if (reltemp->type == RELATION_TYPE_SETUP)
818 //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
819 /* send release to endpoint */
820 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
821 message->param.disconnectinfo.cause = CAUSE_NONSELECTED;
822 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
823 message_put(message);
825 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards.
826 return; // must return, because join IS destroyed
829 if (reltemp->type == RELATION_TYPE_CALLING)
830 reltemp->type = RELATION_TYPE_CONNECT;
831 reltemp = reltemp->next;
833 break; // continue with our message
835 /* release is sent by endpoint */
836 case MESSAGE_RELEASE:
837 switch(relation->type)
839 case RELATION_TYPE_SETUP: /* by called */
840 /* collect cause and send collected cause */
841 collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
843 release(relation, j_multilocation, j_multicause);
845 release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED);
848 case RELATION_TYPE_CALLING: /* by calling */
849 /* remove us, if we don't have a called releation yet */
850 if (!j_relation->next)
852 release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
853 return; // must return, because join IS destroyed
855 /* remove all relations that are in called */
857 reltemp = j_relation;
860 if (reltemp->type == RELATION_TYPE_SETUP)
862 /* send release to endpoint */
863 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type);
864 memcpy(&message->param, param, sizeof(union parameter));
865 message_put(message);
867 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL))
868 return; // must return, because join IS destroyed
871 reltemp = reltemp->next;
873 PERROR("we are still here, this should not happen\n");
876 default: /* by connected */
877 /* send current cause */
878 release(relation, param->disconnectinfo.location, param->disconnectinfo.cause);
880 return; // must return, because join may be destroyed
883 /* count relations */
884 num=joinpbx_countrelations(j_serial);
886 /* check number of relations */
889 PDEBUG(DEBUG_JOIN, "join has more than two relations so there is no need to send a message.\n");
893 /* find interfaces not related to calling epoint */
894 relation = j_relation;
897 if (relation->epoint_id != epoint_id)
899 relation = relation->next;
906 if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION)
908 numbers = param->setup.dialinginfo.id;
909 while((number = strsep(&numbers, ",")))
911 if (out_setup(epoint_id, message_type, param, number))
912 return; // join destroyed
916 if (out_setup(epoint_id, message_type, param, NULL))
917 return; // join destroyed
921 PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
925 PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
926 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
927 memcpy(&message->param, param, sizeof(union parameter));
928 message_put(message);
929 PDEBUG(DEBUG_JOIN, "message sent.\n");
934 /* join process is called from the main loop
935 * it processes the current calling state.
936 * returns 0 if join nothing was done
938 int JoinPBX::handler(void)
940 // struct join_relation *relation;
941 // char dialing[32][32];
947 /* the bridge must be updated */
959 int track_notify(int oldstate, int notify)
961 int newstate = oldstate;
965 case INFO_NOTIFY_USER_RESUMED:
966 case INFO_NOTIFY_REMOTE_RETRIEVAL:
967 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
968 case INFO_NOTIFY_RESERVED_CT_1:
969 case INFO_NOTIFY_RESERVED_CT_2:
970 case INFO_NOTIFY_CALL_IS_DIVERTING:
971 newstate = NOTIFY_STATE_ACTIVE;
974 case INFO_NOTIFY_USER_SUSPENDED:
975 newstate = NOTIFY_STATE_SUSPEND;
978 case INFO_NOTIFY_REMOTE_HOLD:
979 newstate = NOTIFY_STATE_HOLD;
982 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
983 newstate = NOTIFY_STATE_CONFERENCE;
992 * setup to exactly one endpoint
993 * if it fails, the calling endpoint is released.
994 * if other outgoing endpoints already exists, they are release as well.
995 * note: if this functions fails, it will destroy its own join object!
997 int JoinPBX::out_setup(unsigned long epoint_id, int message_type, union parameter *param, char *newnumber)
999 struct join_relation *relation;
1000 struct lcr_msg *message;
1001 class Endpoint *epoint;
1003 PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n");
1004 /* create a new relation */
1005 if (!(relation=add_relation()))
1006 FATAL("No memory for relation.\n");
1007 relation->type = RELATION_TYPE_SETUP;
1008 relation->channel_state = CHANNEL_STATE_HOLD; /* audio is assumed on a new join */
1009 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
1010 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
1011 /* create a new endpoint */
1012 epoint = new Endpoint(0, j_serial);
1014 FATAL("No memory for Endpoint instance\n");
1015 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 1))) // outgoing
1016 FATAL("No memory for Endpoint Application instance\n");
1017 relation->epoint_id = epoint->ep_serial;
1018 /* send setup message to new endpoint */
1019 //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial));
1020 //i if (options.deb & DEBUG_JOIN)
1021 // joinpbx_debug(join, "Join::message_epoint");
1022 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
1023 memcpy(&message->param, param, sizeof(union parameter));
1025 SCPY(message->param.setup.dialinginfo.id, newnumber);
1026 PDEBUG(DEBUG_JOIN, "setup message sent to ep %d with number='%s'.\n", relation->epoint_id, message->param.setup.dialinginfo.id);
1027 message_put(message);
1032 /* send play message to all members to play join/release jingle */
1033 void JoinPBX::play_jingle(int in)
1035 struct join_relation *relation;
1036 struct lcr_msg *message;
1038 relation = j_relation;
1042 if (!relation->next)
1046 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
1047 SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
1048 message_put(message);
1049 relation = relation->next;