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");
205 int update_bridge(struct lcr_work *work, void *instance, int index);
208 * constructor for a new join
209 * the join will have a relation to the calling endpoint
211 JoinPBX::JoinPBX(class Endpoint *epoint) : Join()
213 struct join_relation *relation;
214 // char filename[256];
217 FATAL("epoint is NULL.\n");
219 PDEBUG(DEBUG_JOIN, "creating new join and connecting it to the endpoint.\n");
221 j_type = JOIN_TYPE_PBX;
223 j_caller_id[0] = '\0';
228 j_partyline_jingle = 0;
231 memset(&j_updatebridge, 0, sizeof(j_updatebridge));
232 add_work(&j_updatebridge, update_bridge, this, 0);
234 /* initialize a relation only to the calling interface */
235 relation = j_relation = (struct join_relation *)MALLOC(sizeof(struct join_relation));
237 relation->type = RELATION_TYPE_CALLING;
238 relation->channel_state = 0; /* audio is assumed on a new join */
239 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
240 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
241 relation->epoint_id = epoint->ep_serial;
244 if (options.deb & DEBUG_JOIN)
245 joinpbx_debug(this, "JoinPBX::Constructor(new join)");
254 struct join_relation *relation, *rtemp;
256 relation = j_relation;
258 rtemp = relation->next;
259 FREE(relation, sizeof(struct join_relation));
264 del_work(&j_updatebridge);
268 /* bridge sets the audio flow of all bchannels assiociated to 'this' join
269 * also it changes and notifies active/hold/conference states
271 int update_bridge(struct lcr_work *work, void *instance, int index)
273 class JoinPBX *joinpbx = (class JoinPBX *)instance;
280 void JoinPBX::bridge(void)
282 struct join_relation *relation;
283 struct lcr_msg *message;
284 int numconnect = 0, relations = 0;
285 class Endpoint *epoint;
286 struct port_list *portlist;
288 #ifdef DEBUG_COREBRIDGE
289 int allmISDN = 0; // never set for debug purpose
291 int allmISDN = 1; // set until a non-mISDN relation is found
294 relation = j_relation;
296 /* count all relations */
299 /* check for relation's objects */
300 epoint = find_epoint_id(relation->epoint_id);
302 PERROR("software error: relation without existing endpoints.\n");
303 relation = relation->next;
306 portlist = epoint->ep_portlist;
308 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
309 //#warning testing: keep on hold until single audio stream available
310 relation->channel_state = 0;
311 relation = relation->next;
314 if (portlist->next) {
315 PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
316 //#warning testing: keep on hold until single audio stream available
317 relation->channel_state = 0;
318 relation = relation->next;
321 port = find_port_id(portlist->port_id);
323 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
324 relation = relation->next;
327 if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) {
328 PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
330 PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
333 relation = relation->next;
337 relation = relation->next;
340 PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
341 /* we notify all relations about rxdata. */
342 relation = j_relation;
344 /* count connected relations */
345 if ((relation->channel_state == 1)
346 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
347 && (relation->rx_state != NOTIFY_STATE_HOLD))
350 /* remove unconnected parties from conference, also remove remotely disconnected parties so conference will not be disturbed. */
351 if (relation->channel_state == 1
352 && relation->rx_state != NOTIFY_STATE_HOLD
353 && relation->rx_state != NOTIFY_STATE_SUSPEND
354 && relations>1 // no conf with one member
355 && allmISDN) { // no conf if any member is not mISDN
356 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
357 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
358 message->param.mISDNsignal.conf = j_serial<<16 | j_pid;
359 PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
360 message_put(message);
362 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
363 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
364 message->param.mISDNsignal.conf = 0;
365 PDEBUG(DEBUG_JOIN, "join%d EP%d +off+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
366 message_put(message);
370 * Bridge between port instances if:
371 * - one or all are not mISDN
373 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_BRIDGE);
374 message->param.bridge_id = j_serial;
375 PDEBUG(DEBUG_JOIN, "join%u EP%u requests bridge=%u\n", j_serial, relation->epoint_id, message->param.bridge_id);
376 message_put(message);
378 relation = relation->next;
381 /* two people just exchange their states */
382 if (relations==2 && !j_partyline) {
383 PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial);
384 relation = j_relation;
385 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
386 relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
388 /* one member in a join, so we put her on hold */
389 if ((relations==1 || numconnect==1)/* && !j_partyline_jingle*/) {
390 PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial);
391 relation = j_relation;
393 if ((relation->channel_state == 1)
394 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
395 && (relation->rx_state != NOTIFY_STATE_HOLD))
396 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD);
397 relation = relation->next;
400 /* if conference/partyline (or more than two members and more than one is connected), so we set conference state */
401 PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect);
402 relation = j_relation;
404 if ((relation->channel_state == 1)
405 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
406 && (relation->rx_state != NOTIFY_STATE_HOLD))
407 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_CONFERENCE);
408 relation = relation->next;
413 /* release join from endpoint
414 * if the join has two relations, all relations are freed and the join will be
416 * on outgoing relations, the cause is collected, if not connected
417 * returns if join has been destroyed
419 int JoinPBX::release(struct join_relation *relation, int location, int cause)
421 struct join_relation *reltemp, **relationpointer;
422 struct lcr_msg *message;
426 /* remove from bridge */
427 if (relation->channel_state != 0) {
428 relation->channel_state = 0;
429 trigger_work(&j_updatebridge);
430 // note: if join is not released, bridge must be updated
433 /* detach given interface */
434 reltemp = j_relation;
435 relationpointer = &j_relation;
437 /* endpoint of function call */
438 if (relation == reltemp)
440 relationpointer = &reltemp->next;
441 reltemp = reltemp->next;
444 FATAL("relation not in list of our relations. this must not happen.\n");
445 //printf("releasing relation %d\n", reltemp->epoint_id);
446 *relationpointer = reltemp->next;
447 FREE(reltemp, sizeof(struct join_relation));
449 relation = reltemp = NULL; // just in case of reuse fault;
451 /* if no more relation */
453 PDEBUG(DEBUG_JOIN, "join is completely removed.\n");
454 /* there is no more endpoint related to the join */
457 // end of join object!
458 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
460 /* if join is a party line */
462 PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n");
464 /* if only one relation left */
465 if (!j_relation->next) {
466 PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause);
467 message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
468 message->param.disconnectinfo.cause = cause;
469 message->param.disconnectinfo.location = location;
470 message_put(message);
473 // end of join object!
474 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
479 if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX)
480 joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}");
483 PDEBUG(DEBUG_JOIN, "join_release(): ended.\n");
487 /* count number of relations in a join
489 int joinpbx_countrelations(unsigned int join_id)
491 struct join_relation *relation;
494 class JoinPBX *joinpbx;
496 join = find_join_id(join_id);
501 if (join->j_type == JOIN_TYPE_REMOTE)
504 if (join->j_type != JOIN_TYPE_PBX)
506 joinpbx = (class JoinPBX *)join;
509 relation = joinpbx->j_relation;
512 relation = relation->next;
518 /* check if one is calling and all other relations are setup-realations */
519 int joinpbx_onecalling_othersetup(struct join_relation *relation)
521 int calling = 0, other = 0;
524 switch(relation->type) {
525 case RELATION_TYPE_CALLING:
528 case RELATION_TYPE_SETUP:
535 relation = relation->next;
538 if (calling == 1 && other == 0)
543 void JoinPBX::remove_relation(struct join_relation *relation)
545 struct join_relation *temp, **tempp;
553 if (temp == relation)
559 PERROR("relation not in join.\n");
563 PDEBUG(DEBUG_JOIN, "removing relation.\n");
564 *tempp = relation->next;
565 FREE(temp, sizeof(struct join_relation));
570 struct join_relation *JoinPBX::add_relation(void)
572 struct join_relation *relation;
575 PERROR("there is no first relation to this join\n");
578 relation = j_relation;
579 while(relation->next)
580 relation = relation->next;
582 relation->next = (struct join_relation *)MALLOC(sizeof(struct join_relation));
584 /* the record pointer is set at the first time the data is received for the relation */
586 // if (options.deb & DEBUG_JOIN)
587 // joinpbx_debug(join, "add_relation");
588 return(relation->next);
591 /* epoint sends a message to a join
594 void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
597 struct join_relation *relation, *reltemp;
600 struct lcr_msg *message;
601 // int size, writesize, oldpointer;
602 char *number, *numbers;
605 PERROR("software error, epoint == NULL\n");
609 // if (options.deb & DEBUG_JOIN) {
610 // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
611 // joinpbx_debug(join,"Join::message_epoint");
613 if (options.deb & DEBUG_JOIN) {
617 if (cl->j_type == JOIN_TYPE_PBX)
618 joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
625 relation = j_relation;
627 if (relation->epoint_id == epoint_id)
629 relation = relation->next;
632 PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
636 /* count relations */
637 num=joinpbx_countrelations(j_serial);
639 /* process party line */
640 if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
641 j_partyline = param->setup.partyline;
642 j_partyline_jingle = param->setup.partyline_jingle;
645 switch(message_type) {
647 PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
648 relation->type = RELATION_TYPE_CONNECT;
649 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
650 SPRINT(message->param.connectinfo.id, "%d", j_partyline);
651 message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
652 message_put(message);
653 trigger_work(&j_updatebridge);
654 if (j_partyline_jingle)
658 case MESSAGE_AUDIOPATH:
659 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
660 if (relation->channel_state != param->audiopath) {
661 relation->channel_state = param->audiopath;
662 trigger_work(&j_updatebridge);
663 if (options.deb & DEBUG_JOIN)
664 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
668 case MESSAGE_DISCONNECT:
669 PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
670 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
671 message->param.disconnectinfo.cause = CAUSE_NORMAL;
672 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
673 message_put(message);
676 case MESSAGE_RELEASE:
677 PDEBUG(DEBUG_JOIN, "releasing from join\n");
678 release(relation, 0, 0);
679 if (j_partyline_jingle)
684 PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n");
690 /* process messages */
691 switch(message_type) {
692 /* process audio path message */
693 case MESSAGE_AUDIOPATH:
694 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
695 if (relation->channel_state != param->audiopath) {
696 relation->channel_state = param->audiopath;
697 trigger_work(&j_updatebridge);
698 if (options.deb & DEBUG_JOIN)
699 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
705 switch(param->notifyinfo.notify) {
706 case INFO_NOTIFY_USER_SUSPENDED:
707 case INFO_NOTIFY_USER_RESUMED:
708 case INFO_NOTIFY_REMOTE_HOLD:
709 case INFO_NOTIFY_REMOTE_RETRIEVAL:
710 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
711 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
712 new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
713 if (new_state != relation->rx_state) {
714 relation->rx_state = new_state;
715 trigger_work(&j_updatebridge);
716 if (options.deb & DEBUG_JOIN)
717 joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
722 /* send notification to all other endpoints */
723 reltemp = j_relation;
725 if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) {
726 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
727 memcpy(&message->param, param, sizeof(union parameter));
728 message_put(message);
730 reltemp = reltemp->next;
735 /* relations sends a connect */
736 case MESSAGE_CONNECT:
737 /* outgoing setup type becomes connected */
738 if (relation->type == RELATION_TYPE_SETUP)
739 relation->type = RELATION_TYPE_CONNECT;
740 /* release other relations in setup state */
742 reltemp = j_relation;
744 //printf("connect, checking relation %d\n", reltemp->epoint_id);
745 if (reltemp->type == RELATION_TYPE_SETUP) {
746 //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
747 /* send release to endpoint */
748 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
749 message->param.disconnectinfo.cause = CAUSE_NONSELECTED;
750 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
751 message_put(message);
753 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards.
754 return; // must return, because join IS destroyed
757 if (reltemp->type == RELATION_TYPE_CALLING)
758 reltemp->type = RELATION_TYPE_CONNECT;
759 reltemp = reltemp->next;
761 break; // continue with our message
763 /* release is sent by endpoint */
764 case MESSAGE_RELEASE:
765 switch(relation->type) {
766 case RELATION_TYPE_SETUP: /* by called */
767 /* collect cause and send collected cause */
768 collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
770 release(relation, j_multilocation, j_multicause);
772 release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED);
775 case RELATION_TYPE_CALLING: /* by calling */
776 /* remove us, if we don't have a called releation yet */
777 if (!j_relation->next) {
778 release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
779 return; // must return, because join IS destroyed
781 /* in a conf, we don't kill the other members */
782 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation)) {
783 release(relation, 0, 0);
786 /* remove all relations that are of called type */
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 /* check number of relations */
813 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation) && message_type != MESSAGE_CONNECT) {
814 PDEBUG(DEBUG_JOIN, "we are in a conference, so we ignore the messages, except MESSAGE_CONNECT.\n");
818 /* if join has no other relation, we process the setup message */
820 switch(message_type) {
822 if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) {
823 /* in case of keypad */
824 numbers = param->setup.dialinginfo.keypad;
826 while((number = strsep(&numbers, ","))) {
827 if (out_setup(epoint_id, message_type, param, NULL, number))
828 return; // join destroyed
830 /* after keypad finish dialing */
834 numbers = param->setup.dialinginfo.id;
835 while((number = strsep(&numbers, ","))) {
836 if (out_setup(epoint_id, message_type, param, number, NULL))
837 return; // join destroyed
841 if (out_setup(epoint_id, message_type, param, param->setup.dialinginfo.id, param->setup.dialinginfo.keypad))
842 return; // join destroyed
846 PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
849 /* sending message to other relation(s) */
850 relation = j_relation;
852 if (relation->epoint_id != epoint_id) {
853 PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
854 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
855 memcpy(&message->param, param, sizeof(union parameter));
856 message_put(message);
857 PDEBUG(DEBUG_JOIN, "message sent.\n");
859 relation = relation->next;
865 int track_notify(int oldstate, int notify)
867 int newstate = oldstate;
870 case INFO_NOTIFY_USER_RESUMED:
871 case INFO_NOTIFY_REMOTE_RETRIEVAL:
872 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
873 case INFO_NOTIFY_RESERVED_CT_1:
874 case INFO_NOTIFY_RESERVED_CT_2:
875 case INFO_NOTIFY_CALL_IS_DIVERTING:
876 newstate = NOTIFY_STATE_ACTIVE;
879 case INFO_NOTIFY_USER_SUSPENDED:
880 newstate = NOTIFY_STATE_SUSPEND;
883 case INFO_NOTIFY_REMOTE_HOLD:
884 newstate = NOTIFY_STATE_HOLD;
887 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
888 newstate = NOTIFY_STATE_CONFERENCE;
897 * setup to exactly one endpoint
898 * if it fails, the calling endpoint is released.
899 * if other outgoing endpoints already exists, they are release as well.
900 * note: if this functions fails, it will destroy its own join object!
902 int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber, char *newkeypad)
904 struct join_relation *relation;
905 struct lcr_msg *message;
906 class Endpoint *epoint;
908 PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n");
909 /* create a new relation */
910 if (!(relation=add_relation()))
911 FATAL("No memory for relation.\n");
912 relation->type = RELATION_TYPE_SETUP;
913 relation->channel_state = 0; /* audio is assumed on a new join */
914 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
915 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
916 /* create a new endpoint */
917 epoint = new Endpoint(0, j_serial);
919 FATAL("No memory for Endpoint instance\n");
920 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 1))) // outgoing
921 FATAL("No memory for Endpoint Application instance\n");
922 relation->epoint_id = epoint->ep_serial;
923 /* send setup message to new endpoint */
924 //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial));
925 //i if (options.deb & DEBUG_JOIN)
926 // joinpbx_debug(join, "Join::message_epoint");
927 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
928 memcpy(&message->param, param, sizeof(union parameter));
930 SCPY(message->param.setup.dialinginfo.id, newnumber);
932 message->param.setup.dialinginfo.id[0] = '\0';
934 SCPY(message->param.setup.dialinginfo.keypad, newkeypad);
936 message->param.setup.dialinginfo.keypad[0] = '\0';
937 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);
938 message_put(message);
943 /* send play message to all members to play join/release jingle */
944 void JoinPBX::play_jingle(int in)
946 struct join_relation *relation;
947 struct lcr_msg *message;
949 relation = j_relation;
956 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
957 SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
958 message_put(message);
959 relation = relation->next;