+ * send data to the asterisk join instance
+ */
+int admin_message_to_join(struct admin_msg *msg)
+{
+ class Call *call;
+ struct admin_list *admin;
+
+ /* dummy callref means: asterisk is here */
+ if (msg->type == MESSAGE_HELLO)
+ {
+ /* look for second asterisk */
+ admin = admin_list;
+ while(admin)
+ {
+ if (admin->asterisk)
+ break;
+ admin = admin->next;
+ }
+ if (admin)
+ {
+ PERROR("Asterisk connects twice??? (ignoring)\n");
+ return(-1);
+ }
+ /* set asterisk socket instance */
+ admin->asterisk = 1;
+ }
+
+ /* find call instance */
+ call = call_first;
+ while(call)
+ {
+ if (call->c_serial == msg->ref)
+ break;
+ call = call->next;
+ }
+
+ /* create call instance if not existing */
+ if (!call)
+ {
+ if (msg->ref < 2000000000)
+ {
+ PERROR("Asterisk sends us unknown ref %d below 2000000000.\n", msg->ref);
+ return(-1);
+ }
+
+ /* create new call instance */
+ call = new CallAsterisk(0); // must have no serial, because no endpoint is connected
+ if (!call)
+ FATAL("No memory for Asterisk Call instance\n");
+ }
+
+ /* send message */
+ if (call->c_type != CALL_TYPE_ASTERISK)
+ FATAL("Call instance %d must be of type Call Asterisk\n", call->c_serial);
+ ((class CallAsterisk *)call)->message_asterisk(msg->ref, msg->type, &msg->param);
+
+ return(0);
+}
+
+
+/*
+ * this function is called for every message to asterisk
+ */
+int admin_message_from_join(unsigned long ref, int message_type, union parameter *param)
+{
+ struct admin_list *admin;
+ struct admin_queue *response, **responsep; /* response pointer */
+
+ /* searching for admin id
+ * maybe there is no asterisk instance
+ */
+ admin = admin_list;
+ while(admin)
+ {
+ if (admin->asterisk)
+ break;
+ admin = admin->next;
+ }
+ /* no asterisk connected */
+ if (!admin)
+ return(-1);
+
+ /* seek to end of response list */
+ response = admin->response;
+ responsep = &admin->response;
+ while(response)
+ {
+ responsep = &response->next;
+ response = response->next;
+ }
+
+ /* create state response */
+ response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
+ memuse++;
+ response->num = 1;
+
+ /* message */
+ response->am[0].u.msg.type = message_type;
+ response->am[0].u.msg.ref = ref;
+ memcpy(&response->am[0].u.msg.param, param, sizeof(union parameter));
+
+ /* attach to response chain */
+ *responsep = response;
+ responsep = &response->next;
+
+ return(0);
+}
+
+
+/*