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;
232 memset(&j_updatebridge, 0, sizeof(j_updatebridge));
233 add_work(&j_updatebridge, update_bridge, this, 0);
235 /* initialize a relation only to the calling interface */
236 relation = j_relation = (struct join_relation *)MALLOC(sizeof(struct join_relation));
238 relation->type = RELATION_TYPE_CALLING;
239 relation->channel_state = 0; /* audio is assumed on a new join */
240 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
241 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
242 relation->epoint_id = epoint->ep_serial;
245 if (options.deb & DEBUG_JOIN)
246 joinpbx_debug(this, "JoinPBX::Constructor(new join)");
255 struct join_relation *relation, *rtemp;
257 relation = j_relation;
259 rtemp = relation->next;
260 FREE(relation, sizeof(struct join_relation));
265 /* remove 3PTY from other join */
268 class JoinPBX *joinpbx;
270 join = find_join_id(j_3pty);
271 if (join && join->j_type == JOIN_TYPE_PBX) {
272 joinpbx = (class JoinPBX *)join;
274 trigger_work(&joinpbx->j_updatebridge);
278 del_work(&j_updatebridge);
282 /* bridge sets the audio flow of all bchannels assiociated to 'this' join
283 * also it changes and notifies active/hold/conference states
285 int update_bridge(struct lcr_work *work, void *instance, int index)
287 class JoinPBX *joinpbx = (class JoinPBX *)instance;
294 void JoinPBX::bridge(void)
296 struct join_relation *relation;
297 struct lcr_msg *message;
298 int numconnect = 0, relations = 0;
299 class Endpoint *epoint;
300 struct port_list *portlist;
302 unsigned int bridge_id;
303 #ifdef DEBUG_COREBRIDGE
304 int allmISDN = 0; // never set for debug purpose
306 int allmISDN = 1; // set until a non-mISDN relation is found
309 /* bridge id is the serial of join
310 * if we have a 3pty with another join, we always use the lowest brigde id.
311 * this way we use common ids, so both joins share same bridge */
312 if (j_3pty && j_3pty < j_serial)
315 bridge_id = j_serial;
317 relation = j_relation;
319 /* count all relations */
322 /* check for relation's objects */
323 epoint = find_epoint_id(relation->epoint_id);
325 PERROR("software error: relation without existing endpoints.\n");
326 relation = relation->next;
329 portlist = epoint->ep_portlist;
331 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
332 //#warning testing: keep on hold until single audio stream available
333 relation->channel_state = 0;
334 relation = relation->next;
337 if (portlist->next) {
338 PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
339 //#warning testing: keep on hold until single audio stream available
340 relation->channel_state = 0;
341 relation = relation->next;
344 port = find_port_id(portlist->port_id);
346 PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
347 relation = relation->next;
350 if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) {
351 PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
353 PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
356 relation = relation->next;
360 relation = relation->next;
363 PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
364 /* we notify all relations about rxdata. */
365 relation = j_relation;
367 /* count connected relations */
368 if ((relation->channel_state == 1)
369 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
370 && (relation->rx_state != NOTIFY_STATE_HOLD))
373 /* remove unconnected parties from conference, also remove remotely disconnected parties so conference will not be disturbed. */
376 if (relation->channel_state == 1
377 && relation->rx_state != NOTIFY_STATE_HOLD
378 && relation->rx_state != NOTIFY_STATE_SUSPEND
379 && relations>1 // no conf with one member
380 && allmISDN) { // no conf if any member is not mISDN
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 = (bridge_id << 16) | j_pid;
384 PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
385 message_put(message);
387 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
388 message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
389 message->param.mISDNsignal.conf = 0;
390 PDEBUG(DEBUG_JOIN, "join%d EP%d +off+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
391 message_put(message);
395 if (relation->channel_state == 1
396 && relation->rx_state != NOTIFY_STATE_HOLD
397 && relation->rx_state != NOTIFY_STATE_SUSPEND
398 && relations>1 // no bridge with one member
399 && !allmISDN) { // no bridge if all members are mISDN
400 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_BRIDGE);
401 message->param.bridge_id = bridge_id;
402 PDEBUG(DEBUG_JOIN, "join%u EP%u requests bridge=%u\n", j_serial, relation->epoint_id, bridge_id);
403 message_put(message);
405 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_BRIDGE);
406 message->param.bridge_id = 0;
407 PDEBUG(DEBUG_JOIN, "join%u EP%u drop bridge=%u\n", j_serial, relation->epoint_id, bridge_id);
408 message_put(message);
411 relation = relation->next;
414 /* two people just exchange their states */
415 if (!j_3pty && relations==2 && !j_partyline) {
416 PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial);
417 relation = j_relation;
418 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
419 relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
421 /* one member in a join, so we put her on hold */
422 if (!j_3pty && (relations==1 || numconnect==1)/* && !j_partyline_jingle*/) {
423 PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial);
424 relation = j_relation;
426 if ((relation->channel_state == 1)
427 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
428 && (relation->rx_state != NOTIFY_STATE_HOLD))
429 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD);
430 relation = relation->next;
433 /* if conference/partyline (or more than two members and more than one is connected), so we set conference state */
434 PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect);
435 relation = j_relation;
437 if ((relation->channel_state == 1)
438 && (relation->rx_state != NOTIFY_STATE_SUSPEND)
439 && (relation->rx_state != NOTIFY_STATE_HOLD))
440 relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_CONFERENCE);
441 relation = relation->next;
446 /* release join from endpoint
447 * if the join has two relations, all relations are freed and the join will be
449 * on outgoing relations, the cause is collected, if not connected
450 * returns if join has been destroyed
452 int JoinPBX::release(struct join_relation *relation, int location, int cause)
454 struct join_relation *reltemp, **relationpointer;
455 struct lcr_msg *message;
459 /* remove from bridge */
460 if (relation->channel_state != 0) {
461 relation->channel_state = 0;
462 trigger_work(&j_updatebridge);
463 // note: if join is not released, bridge must be updated
466 /* detach given interface */
467 reltemp = j_relation;
468 relationpointer = &j_relation;
470 /* endpoint of function call */
471 if (relation == reltemp)
473 relationpointer = &reltemp->next;
474 reltemp = reltemp->next;
477 FATAL("relation not in list of our relations. this must not happen.\n");
478 //printf("releasing relation %d\n", reltemp->epoint_id);
479 *relationpointer = reltemp->next;
480 FREE(reltemp, sizeof(struct join_relation));
482 relation = reltemp = NULL; // just in case of reuse fault;
484 /* if no more relation */
486 PDEBUG(DEBUG_JOIN, "join is completely removed.\n");
487 /* there is no more endpoint related to the join */
490 // end of join object!
491 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
493 /* if join is a party line */
495 PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n");
497 /* if only one relation left */
498 if (!j_relation->next) {
499 PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause);
500 message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
501 message->param.disconnectinfo.cause = cause;
502 message->param.disconnectinfo.location = location;
503 message_put(message);
506 // end of join object!
507 PDEBUG(DEBUG_JOIN, "join completely removed!\n");
512 if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX)
513 joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}");
516 PDEBUG(DEBUG_JOIN, "join_release(): ended.\n");
520 /* count number of relations in a join
522 int joinpbx_countrelations(unsigned int join_id)
524 struct join_relation *relation;
527 class JoinPBX *joinpbx;
529 join = find_join_id(join_id);
534 if (join->j_type != JOIN_TYPE_PBX)
536 joinpbx = (class JoinPBX *)join;
539 relation = joinpbx->j_relation;
542 relation = relation->next;
548 /* check if one is calling and all other relations are setup-realations */
549 int joinpbx_onecalling_othersetup(struct join_relation *relation)
551 int calling = 0, other = 0;
554 switch(relation->type) {
555 case RELATION_TYPE_CALLING:
558 case RELATION_TYPE_SETUP:
565 relation = relation->next;
568 if (calling == 1 && other == 0)
573 void JoinPBX::remove_relation(struct join_relation *relation)
575 struct join_relation *temp, **tempp;
583 if (temp == relation)
589 PERROR("relation not in join.\n");
593 PDEBUG(DEBUG_JOIN, "removing relation.\n");
594 *tempp = relation->next;
595 FREE(temp, sizeof(struct join_relation));
600 struct join_relation *JoinPBX::add_relation(void)
602 struct join_relation *relation;
605 PERROR("there is no first relation to this join\n");
608 relation = j_relation;
609 while(relation->next)
610 relation = relation->next;
612 relation->next = (struct join_relation *)MALLOC(sizeof(struct join_relation));
614 /* the record pointer is set at the first time the data is received for the relation */
616 // if (options.deb & DEBUG_JOIN)
617 // joinpbx_debug(join, "add_relation");
618 return(relation->next);
621 /* epoint sends a message to a join
624 void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
627 struct join_relation *relation, *reltemp;
630 struct lcr_msg *message;
631 // int size, writesize, oldpointer;
632 char *number, *numbers;
635 PERROR("software error, epoint == NULL\n");
639 // if (options.deb & DEBUG_JOIN) {
640 // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
641 // joinpbx_debug(join,"Join::message_epoint");
643 if (options.deb & DEBUG_JOIN) {
647 if (cl->j_type == JOIN_TYPE_PBX)
648 joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
655 relation = j_relation;
657 if (relation->epoint_id == epoint_id)
659 relation = relation->next;
662 PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
666 /* count relations */
667 num=joinpbx_countrelations(j_serial);
669 /* process party line */
670 if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
671 j_partyline = param->setup.partyline;
672 j_partyline_jingle = param->setup.partyline_jingle;
675 switch(message_type) {
677 PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
678 relation->type = RELATION_TYPE_CONNECT;
679 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
680 SPRINT(message->param.connectinfo.id, "%d", j_partyline);
681 message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
682 message_put(message);
683 trigger_work(&j_updatebridge);
684 if (j_partyline_jingle)
688 case MESSAGE_AUDIOPATH:
689 PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
690 if (relation->channel_state != param->audiopath) {
691 relation->channel_state = param->audiopath;
692 trigger_work(&j_updatebridge);
693 if (options.deb & DEBUG_JOIN)
694 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
698 case MESSAGE_DISCONNECT:
699 PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
700 message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
701 message->param.disconnectinfo.cause = CAUSE_NORMAL;
702 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
703 message_put(message);
706 case MESSAGE_RELEASE:
707 PDEBUG(DEBUG_JOIN, "releasing from join\n");
708 release(relation, 0, 0);
709 if (j_partyline_jingle)
714 PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n");
720 /* process messages */
721 switch(message_type) {
722 /* process audio path message */
723 case MESSAGE_AUDIOPATH:
724 PDEBUG(DEBUG_JOIN, "join received channel message: audiopath=%d, current relation's channel_state=%d\n", param->audiopath, relation->channel_state);
725 if (relation->channel_state != param->audiopath) {
726 relation->channel_state = param->audiopath;
727 trigger_work(&j_updatebridge);
728 if (options.deb & DEBUG_JOIN)
729 joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
735 switch(param->notifyinfo.notify) {
736 case INFO_NOTIFY_USER_SUSPENDED:
737 case INFO_NOTIFY_USER_RESUMED:
738 case INFO_NOTIFY_REMOTE_HOLD:
739 case INFO_NOTIFY_REMOTE_RETRIEVAL:
740 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
741 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
742 new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
743 if (new_state != relation->rx_state) {
744 relation->rx_state = new_state;
745 trigger_work(&j_updatebridge);
746 if (options.deb & DEBUG_JOIN)
747 joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
752 /* send notification to all other endpoints */
753 reltemp = j_relation;
755 if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) {
756 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
757 memcpy(&message->param, param, sizeof(union parameter));
758 message_put(message);
760 reltemp = reltemp->next;
765 /* relations sends a connect */
766 case MESSAGE_CONNECT:
767 /* outgoing setup type becomes connected */
768 if (relation->type == RELATION_TYPE_SETUP)
769 relation->type = RELATION_TYPE_CONNECT;
770 /* release other relations in setup state */
772 reltemp = j_relation;
774 //printf("connect, checking relation %d\n", reltemp->epoint_id);
775 if (reltemp->type == RELATION_TYPE_SETUP) {
776 //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
777 /* send release to endpoint */
778 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
779 message->param.disconnectinfo.cause = CAUSE_NONSELECTED;
780 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
781 message_put(message);
783 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards.
784 return; // must return, because join IS destroyed
787 if (reltemp->type == RELATION_TYPE_CALLING)
788 reltemp->type = RELATION_TYPE_CONNECT;
789 reltemp = reltemp->next;
791 break; // continue with our message
793 /* release is sent by endpoint */
794 case MESSAGE_RELEASE:
795 switch(relation->type) {
796 case RELATION_TYPE_SETUP: /* by called */
797 /* collect cause and send collected cause */
798 collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
800 release(relation, j_multilocation, j_multicause);
802 release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED);
805 case RELATION_TYPE_CALLING: /* by calling */
806 /* remove us, if we don't have a called releation yet */
807 if (!j_relation->next) {
808 release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
809 return; // must return, because join IS destroyed
811 /* in a conf, we don't kill the other members */
812 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation)) {
813 release(relation, 0, 0);
816 /* remove all relations that are of called type */
818 reltemp = j_relation;
820 if (reltemp->type == RELATION_TYPE_SETUP) {
821 /* send release to endpoint */
822 message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type);
823 memcpy(&message->param, param, sizeof(union parameter));
824 message_put(message);
826 if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL))
827 return; // must return, because join IS destroyed
830 reltemp = reltemp->next;
832 PERROR("we are still here, this should not happen\n");
835 default: /* by connected */
836 /* send current cause */
837 release(relation, param->disconnectinfo.location, param->disconnectinfo.cause);
839 return; // must return, because join may be destroyed
842 /* check number of relations */
843 if (num > 2 && !joinpbx_onecalling_othersetup(j_relation) && message_type != MESSAGE_CONNECT) {
844 PDEBUG(DEBUG_JOIN, "we are in a conference, so we ignore the messages, except MESSAGE_CONNECT.\n");
848 /* if join has no other relation, we process the setup message */
850 switch(message_type) {
852 if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) {
853 /* in case of keypad */
854 numbers = param->setup.dialinginfo.keypad;
856 while((number = strsep(&numbers, ","))) {
857 if (out_setup(epoint_id, message_type, param, NULL, number))
858 return; // join destroyed
860 /* after keypad finish dialing */
864 numbers = param->setup.dialinginfo.id;
865 while((number = strsep(&numbers, ","))) {
866 if (out_setup(epoint_id, message_type, param, number, NULL))
867 return; // join destroyed
871 if (out_setup(epoint_id, message_type, param, param->setup.dialinginfo.id, param->setup.dialinginfo.keypad))
872 return; // join destroyed
876 PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
879 /* sending message to other relation(s) */
880 relation = j_relation;
882 if (relation->epoint_id != epoint_id) {
883 PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
884 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
885 memcpy(&message->param, param, sizeof(union parameter));
886 message_put(message);
887 PDEBUG(DEBUG_JOIN, "message sent.\n");
889 relation = relation->next;
895 int track_notify(int oldstate, int notify)
897 int newstate = oldstate;
900 case INFO_NOTIFY_USER_RESUMED:
901 case INFO_NOTIFY_REMOTE_RETRIEVAL:
902 case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
903 case INFO_NOTIFY_RESERVED_CT_1:
904 case INFO_NOTIFY_RESERVED_CT_2:
905 case INFO_NOTIFY_CALL_IS_DIVERTING:
906 newstate = NOTIFY_STATE_ACTIVE;
909 case INFO_NOTIFY_USER_SUSPENDED:
910 newstate = NOTIFY_STATE_SUSPEND;
913 case INFO_NOTIFY_REMOTE_HOLD:
914 newstate = NOTIFY_STATE_HOLD;
917 case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
918 newstate = NOTIFY_STATE_CONFERENCE;
927 * setup to exactly one endpoint
928 * if it fails, the calling endpoint is released.
929 * if other outgoing endpoints already exists, they are release as well.
930 * note: if this functions fails, it will destroy its own join object!
932 int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber, char *newkeypad)
934 struct join_relation *relation;
935 struct lcr_msg *message;
936 class Endpoint *epoint;
938 PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n");
939 /* create a new relation */
940 if (!(relation=add_relation()))
941 FATAL("No memory for relation.\n");
942 relation->type = RELATION_TYPE_SETUP;
943 relation->channel_state = 0; /* audio is assumed on a new join */
944 relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
945 relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */
946 /* create a new endpoint */
947 epoint = new Endpoint(0, j_serial);
949 FATAL("No memory for Endpoint instance\n");
950 epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing
951 relation->epoint_id = epoint->ep_serial;
952 /* send setup message to new endpoint */
953 //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial));
954 //i if (options.deb & DEBUG_JOIN)
955 // joinpbx_debug(join, "Join::message_epoint");
956 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
957 memcpy(&message->param, param, sizeof(union parameter));
959 SCPY(message->param.setup.dialinginfo.id, newnumber);
961 message->param.setup.dialinginfo.id[0] = '\0';
963 SCPY(message->param.setup.dialinginfo.keypad, newkeypad);
965 message->param.setup.dialinginfo.keypad[0] = '\0';
966 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);
967 message_put(message);
972 /* send play message to all members to play join/release jingle */
973 void JoinPBX::play_jingle(int in)
975 struct join_relation *relation;
976 struct lcr_msg *message;
978 relation = j_relation;
985 message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
986 SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
987 message_put(message);
988 relation = relation->next;