2007-05-06 13:54:52 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
** **
|
2007-07-17 17:28:09 +00:00
|
|
|
** Linux Call Router **
|
2007-05-06 13:54:52 +00:00
|
|
|
** **
|
|
|
|
**---------------------------------------------------------------------------**
|
|
|
|
** Copyright: Andreas Eversberg **
|
|
|
|
** **
|
2007-07-26 12:23:56 +00:00
|
|
|
** join functions for remote application **
|
2007-05-06 13:54:52 +00:00
|
|
|
** **
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
//#define __u8 unsigned char
|
|
|
|
//#define __u16 unsigned short
|
2008-06-14 06:34:50 +00:00
|
|
|
//#define __u32 unsigned int
|
2007-05-06 13:54:52 +00:00
|
|
|
|
2010-12-13 08:22:49 +00:00
|
|
|
extern unsigned int new_remote;
|
2007-05-06 13:54:52 +00:00
|
|
|
|
|
|
|
/*
|
2007-07-17 17:28:09 +00:00
|
|
|
* constructor for a new join
|
|
|
|
* the join will have a relation to the calling endpoint
|
2007-05-06 13:54:52 +00:00
|
|
|
*/
|
2008-06-14 06:34:50 +00:00
|
|
|
JoinRemote::JoinRemote(unsigned int serial, char *remote_name, int remote_id) : Join()
|
2007-05-06 13:54:52 +00:00
|
|
|
{
|
2007-08-12 09:16:45 +00:00
|
|
|
union parameter param;
|
2007-05-06 13:54:52 +00:00
|
|
|
|
2007-07-27 18:07:22 +00:00
|
|
|
SCPY(j_remote_name, remote_name);
|
|
|
|
j_remote_id = remote_id;
|
2007-07-26 12:23:56 +00:00
|
|
|
j_type = JOIN_TYPE_REMOTE;
|
2010-12-13 08:22:49 +00:00
|
|
|
j_remote_ref = new_remote++;
|
2007-05-06 13:54:52 +00:00
|
|
|
|
2011-10-15 07:28:11 +00:00
|
|
|
PDEBUG(DEBUG_JOIN, "Constructor(new join) ref=%d\n", j_remote_ref);
|
|
|
|
|
2007-08-11 13:57:58 +00:00
|
|
|
j_epoint_id = serial; /* this is the endpoint, if created by epoint */
|
2007-07-26 12:23:56 +00:00
|
|
|
if (j_epoint_id)
|
2011-10-15 07:28:11 +00:00
|
|
|
PDEBUG(DEBUG_JOIN, "New remote join connected to endpoint id %lu and application %s (ref=%d)\n", j_epoint_id, remote_name, j_remote_ref);
|
2007-07-26 12:23:56 +00:00
|
|
|
|
|
|
|
/* send new ref to remote socket */
|
2007-08-12 09:16:45 +00:00
|
|
|
memset(¶m, 0, sizeof(union parameter));
|
|
|
|
if (serial)
|
2010-12-13 08:22:49 +00:00
|
|
|
param.newref.direction = 1; /* new ref from lcr */
|
|
|
|
if (admin_message_from_lcr(j_remote_id, j_remote_ref, MESSAGE_NEWREF, ¶m)<0)
|
2007-07-27 18:07:22 +00:00
|
|
|
FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", j_remote_name);
|
2007-05-06 13:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-07-17 17:28:09 +00:00
|
|
|
* join descructor
|
2007-05-06 13:54:52 +00:00
|
|
|
*/
|
2007-07-26 12:23:56 +00:00
|
|
|
JoinRemote::~JoinRemote()
|
2007-05-06 13:54:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-14 06:34:50 +00:00
|
|
|
void JoinRemote::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
|
2007-07-15 10:03:09 +00:00
|
|
|
{
|
|
|
|
/* if endpoint has just been removed, but still a message in the que */
|
2007-07-26 12:23:56 +00:00
|
|
|
if (epoint_id != j_epoint_id)
|
2007-07-15 10:03:09 +00:00
|
|
|
return;
|
|
|
|
|
2011-10-15 07:28:11 +00:00
|
|
|
PDEBUG(DEBUG_JOIN, "Message %d of endpoint %d from LCR to remote (ref=%d)\n", message_type, j_epoint_id, j_remote_ref);
|
|
|
|
|
2007-07-26 12:23:56 +00:00
|
|
|
/* look for Remote's interface */
|
2010-12-13 08:22:49 +00:00
|
|
|
if (admin_message_from_lcr(j_remote_id, j_remote_ref, message_type, param)<0) {
|
2007-07-27 18:07:22 +00:00
|
|
|
PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", j_remote_name);
|
2007-07-15 10:03:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-05 20:14:21 +00:00
|
|
|
if (message_type == MESSAGE_RELEASE) {
|
2007-07-15 10:03:09 +00:00
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-11 13:57:58 +00:00
|
|
|
void JoinRemote::message_remote(int message_type, union parameter *param)
|
2007-05-06 13:54:52 +00:00
|
|
|
{
|
2008-04-25 07:06:20 +00:00
|
|
|
struct lcr_msg *message;
|
2007-07-15 10:03:09 +00:00
|
|
|
|
2011-10-15 07:28:11 +00:00
|
|
|
PDEBUG(DEBUG_JOIN, "Message %d of endpoint %d from remote to LCR (ref=%d)\n", message_type, j_epoint_id, j_remote_ref);
|
|
|
|
|
2007-07-15 10:03:09 +00:00
|
|
|
/* create relation if no relation exists */
|
2009-07-05 20:14:21 +00:00
|
|
|
if (!j_epoint_id) {
|
2007-07-15 10:03:09 +00:00
|
|
|
class Endpoint *epoint;
|
|
|
|
|
2007-08-11 13:57:58 +00:00
|
|
|
if (!(epoint = new Endpoint(0, j_serial)))
|
2007-07-15 10:03:09 +00:00
|
|
|
FATAL("No memory for Endpoint instance\n");
|
2007-08-11 13:57:58 +00:00
|
|
|
j_epoint_id = epoint->ep_serial;
|
2011-10-15 07:28:11 +00:00
|
|
|
PDEBUG(DEBUG_JOIN, "Created endpoint %d\n", j_epoint_id);
|
2012-01-16 08:14:22 +00:00
|
|
|
epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing
|
2007-07-15 10:03:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 06:27:52 +00:00
|
|
|
#ifdef WITH_MISDN
|
2007-08-11 13:57:58 +00:00
|
|
|
/* set serial on bchannel message
|
|
|
|
* also ref is given, so we send message with ref */
|
2009-07-05 20:14:21 +00:00
|
|
|
if (message_type == MESSAGE_BCHANNEL) {
|
2008-06-06 13:18:59 +00:00
|
|
|
message_bchannel_from_remote(this, param->bchannel.type, param->bchannel.handle);
|
2007-08-11 13:57:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-27 06:27:52 +00:00
|
|
|
#endif
|
2007-08-11 13:57:58 +00:00
|
|
|
|
2008-04-25 07:06:20 +00:00
|
|
|
/* cannot just forward, because param is not of container "struct lcr_msg" */
|
2007-07-26 12:23:56 +00:00
|
|
|
message = message_create(j_serial, j_epoint_id, JOIN_TO_EPOINT, message_type);
|
2007-07-15 10:03:09 +00:00
|
|
|
memcpy(&message->param, param, sizeof(message->param));
|
|
|
|
message_put(message);
|
|
|
|
|
2009-07-05 20:14:21 +00:00
|
|
|
if (message_type == MESSAGE_RELEASE) {
|
2007-07-15 10:03:09 +00:00
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
2007-05-06 13:54:52 +00:00
|
|
|
}
|
|
|
|
|
2007-07-15 10:03:09 +00:00
|
|
|
|
|
|
|
|