summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--action.cpp4
-rw-r--r--admin_client.c2
-rw-r--r--admin_server.c43
-rw-r--r--admin_server.h6
-rw-r--r--joinremote.cpp15
-rw-r--r--joinremote.h5
-rw-r--r--route.c2
7 files changed, 42 insertions, 35 deletions
diff --git a/action.cpp b/action.cpp
index d0dbf8d..8056435 100644
--- a/action.cpp
+++ b/action.cpp
@@ -90,7 +90,7 @@ void EndpointAppPBX::_action_init_call(char *remote)
admin = admin_first;
while(admin)
{
- if (admin->remote[0] && !strcmp(admin->remote, remote))
+ if (admin->remote_name[0] && !strcmp(admin->remote_name, remote))
break;
admin = admin->next;
}
@@ -105,7 +105,7 @@ void EndpointAppPBX::_action_init_call(char *remote)
set_tone(portlist,"cause_22");
return;
}
- join = new JoinRemote(ea_endpoint->ep_serial, remote);
+ join = new JoinRemote(ea_endpoint->ep_serial, remote, admin->sock);
}
else
join = new JoinPBX(ea_endpoint);
diff --git a/admin_client.c b/admin_client.c
index 02624a0..6bf964c 100644
--- a/admin_client.c
+++ b/admin_client.c
@@ -966,7 +966,7 @@ char *admin_state(int sock, char *argv[])
while(l!=ll)
{
move(line++>1?line-1:1, 0);
- if (strlen(logline[l % LOGLINES]) > hoffset)
+ if ((int)strlen(logline[l % LOGLINES]) > hoffset)
SCPY(buffer, logline[l % LOGLINES] + hoffset);
else
buffer[0] = '\0';
diff --git a/admin_server.c b/admin_server.c
index 6292e12..f1275a6 100644
--- a/admin_server.c
+++ b/admin_server.c
@@ -96,13 +96,13 @@ void free_connection(struct admin_list *admin)
class Join *join, *joinnext;
/* free remote joins */
- if (admin->remote[0])
+ if (admin->remote_name[0])
{
join = join_first;
while(join)
{
joinnext = join->next;
- if (join->j_type==JOIN_TYPE_REMOTE && !strcmp(((class JoinRemote *)join)->j_remote, admin->remote))
+ if (join->j_type==JOIN_TYPE_REMOTE) if (((class JoinRemote *)join)->j_remote_id == admin->sock)
{
memset(&param, 0, sizeof(param));
param.disconnectinfo.cause = CAUSE_OUTOFORDER;
@@ -593,7 +593,7 @@ void admin_call_response(int adminid, int message, char *connected, int cause, i
/*
* send data to the remote socket join instance
*/
-int admin_message_to_join(struct admin_msg *msg, char *remote)
+int admin_message_to_join(struct admin_msg *msg, char *remote_name, int sock_id)
{
class Join *join;
struct admin_list *admin;
@@ -601,7 +601,7 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
/* hello message */
if (msg->type == MESSAGE_HELLO)
{
- if (remote[0])
+ if (remote_name[0])
{
PERROR("Remote application repeats hello message.\n");
return(-1);
@@ -610,7 +610,7 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
admin = admin_first;
while(admin)
{
- if (!strcmp(admin->remote, msg->param.hello.application))
+ if (!strcmp(admin->remote_name, msg->param.hello.application))
break;
admin = admin->next;
}
@@ -619,13 +619,13 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
PERROR("Remote application connects twice??? (ignoring)\n");
return(-1);
}
- /* set asterisk socket instance */
- SCPY(remote, msg->param.hello.application);
+ /* set remote socket instance */
+ SCPY(remote_name, msg->param.hello.application);
return(0);
}
- /* check we already have no application name */
- if (!remote[0])
+ /* check we have no application name */
+ if (remote_name[0])
{
PERROR("Remote application did not send us a hello message.\n");
return(-1);
@@ -635,7 +635,7 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
if (msg->type == MESSAGE_NEWREF)
{
/* create new join instance */
- join = new JoinRemote(0, remote); // must have no serial, because no endpoint is connected
+ join = new JoinRemote(0, remote_name, sock_id); // must have no serial, because no endpoint is connected
if (!join)
FATAL("No memory for remote join instance\n");
return(0);
@@ -656,6 +656,11 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
break;
join = join->next;
}
+ if (!join)
+ {
+ PERROR("No join found with serial %d.\n", msg->ref);
+ return(-1);
+ }
/* check application */
if (join->j_type != JOIN_TYPE_REMOTE)
@@ -663,9 +668,9 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
PERROR("Ref %d does not belong to a remote join instance.\n", msg->ref);
return(-1);
}
- if (!!strcmp(remote, ((class JoinRemote *)join)->j_remote))
+ if (sock_id != ((class JoinRemote *)join)->j_remote_id)
{
- PERROR("Ref %d belongs to remote application %s, but not to sending application %s.\n", msg->ref, ((class JoinRemote *)join)->j_remote, remote);
+ PERROR("Ref %d belongs to remote application %s, but not to sending application %s.\n", msg->ref, ((class JoinRemote *)join)->j_remote_name, remote_name);
return(-1);
}
@@ -679,7 +684,7 @@ int admin_message_to_join(struct admin_msg *msg, char *remote)
/*
* this function is called for every message to remote socket
*/
-int admin_message_from_join(char *remote, unsigned long ref, int message_type, union parameter *param)
+int admin_message_from_join(int remote_id, unsigned long ref, int message_type, union parameter *param)
{
struct admin_list *admin;
struct admin_queue *response, **responsep; /* response pointer */
@@ -690,7 +695,7 @@ int admin_message_from_join(char *remote, unsigned long ref, int message_type, u
admin = admin_first;
while(admin)
{
- if (admin->remote[0] && !strcmp(admin->remote, remote))
+ if (admin->remote_name[0] && admin->sock==remote_id)
break;
admin = admin->next;
}
@@ -775,7 +780,7 @@ int admin_state(struct admin_queue **responsep)
admin = admin_first;
while(admin)
{
- if (admin->remote[0])
+ if (admin->remote_name[0])
i++;
admin = admin->next;
}
@@ -877,12 +882,12 @@ int admin_state(struct admin_queue **responsep)
admin = admin_first;
while(admin)
{
- if (admin->remote[0])
+ if (admin->remote_name[0])
{
/* message */
response->am[num].message = ADMIN_RESPONSE_S_REMOTE;
/* name */
- SCPY(response->am[num].u.r.name, admin->remote);
+ SCPY(response->am[num].u.r.name, admin->remote_name);
/* */
num++;
}
@@ -902,7 +907,7 @@ int admin_state(struct admin_queue **responsep)
response->am[num].u.j.partyline = ((class JoinPBX *)join)->j_partyline;
/* remote application */
if (join->j_type == JOIN_TYPE_REMOTE)
- SCPY(response->am[num].u.j.remote, ((class JoinRemote *)join)->j_remote);
+ SCPY(response->am[num].u.j.remote, ((class JoinRemote *)join)->j_remote_name);
/* */
join = join->next;
num++;
@@ -1225,7 +1230,7 @@ int admin_handle(void)
break;
case ADMIN_MESSAGE:
- if (admin_message_to_join(&msg.u.msg, admin->remote) < 0)
+ if (admin_message_to_join(&msg.u.msg, admin->remote_name, admin->sock) < 0)
{
PERROR("Failed to deliver message for socket %d.\n", admin->sock);
goto response_error;
diff --git a/admin_server.h b/admin_server.h
index 2351298..9d1c8a2 100644
--- a/admin_server.h
+++ b/admin_server.h
@@ -22,7 +22,7 @@ struct admin_list {
struct admin_list *next;
int sock;
int sockserial;
- char remote[32]; /* socket is connected remote application */
+ char remote_name[32]; /* socket is connected remote application */
struct admin_trace_req trace; /* stores trace, if detail != 0 */
unsigned long epointid;
struct admin_queue *response;
@@ -33,8 +33,8 @@ int admin_init(void);
void admin_cleanup(void);
int admin_handle(void);
void admin_call_response(int adminid, int message, char *connected, int cause, int location, int notify);
-int admin_message_to_join(struct admin_message *msg);
-int admin_message_from_join(char *remote, unsigned long ref, int message_type, union parameter *param);
+int admin_message_to_join(struct admin_message *msg, int remote_id);
+int admin_message_from_join(int remote_id, unsigned long ref, int message_type, union parameter *param);
diff --git a/joinremote.cpp b/joinremote.cpp
index 4b5e458..3b7291c 100644
--- a/joinremote.cpp
+++ b/joinremote.cpp
@@ -28,22 +28,23 @@
* constructor for a new join
* the join will have a relation to the calling endpoint
*/
-JoinRemote::JoinRemote(unsigned long serial, char *remote) : Join()
+JoinRemote::JoinRemote(unsigned long serial, char *remote_name, int remote_id) : Join()
{
PDEBUG(DEBUG_JOIN, "Constructor(new join)");
union parameter *param;
- SCPY(j_remote, remote);
+ SCPY(j_remote_name, remote_name);
+ j_remote_id = remote_id;
j_type = JOIN_TYPE_REMOTE;
j_epoint_id = serial;
if (j_epoint_id)
- PDEBUG(DEBUG_JOIN, "New remote join connected to endpoint id %lu and application %s\n", j_epoint_id, remote);
+ PDEBUG(DEBUG_JOIN, "New remote join connected to endpoint id %lu and application %s\n", j_epoint_id, remote_name);
/* send new ref to remote socket */
memset(&param, 0, sizeof(param));
- if (admin_message_from_join(j_remote, j_serial, MESSAGE_NEWREF, param)<0)
- FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", j_remote);
+ if (admin_message_from_join(j_remote_id, j_serial, MESSAGE_NEWREF, param)<0)
+ FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", j_remote_name);
}
@@ -73,9 +74,9 @@ void JoinRemote::message_epoint(unsigned long epoint_id, int message_type, union
return;
/* look for Remote's interface */
- if (admin_message_from_join(j_remote, j_serial, message_type, param)<0)
+ if (admin_message_from_join(j_remote_id, j_serial, message_type, param)<0)
{
- PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", j_remote);
+ PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", j_remote_name);
return;
}
diff --git a/joinremote.h b/joinremote.h
index d9e7e2b..ac86467 100644
--- a/joinremote.h
+++ b/joinremote.h
@@ -12,13 +12,14 @@
class JoinRemote : public Join
{
public:
- JoinRemote(unsigned long serial, char *remote);
+ JoinRemote(unsigned long serial, char *remote_name, int remote_id);
~JoinRemote();
void message_epoint(unsigned long epoint_id, int message, union parameter *param);
void message_remote(unsigned long ref, int message_type, union parameter *param);
int handler(void);
- char j_remote[32];
+ int j_remote_id;
+ char j_remote_name[32];
unsigned long j_epoint_id;
};
diff --git a/route.c b/route.c
index 3381251..e8bf896 100644
--- a/route.c
+++ b/route.c
@@ -2216,7 +2216,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
admin = admin_first;
while(admin)
{
- if (admin->remote[0] && !strcmp(cond->string_value, admin->remote))
+ if (admin->remote_name[0] && !strcmp(cond->string_value, admin->remote_name))
break;
admin = admin->next;
}