1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
15 #include <sys/types.h>
16 //#include <sys/stat.h>
21 #include <sys/ioctl.h>
22 //#include <sys/file.h>
24 //#include <sys/mman.h>
25 //#include <sys/resource.h>
26 #include <sys/socket.h>
32 char *socket_name = SOCKET_NAME;
34 struct sockaddr_un sock_address;
36 struct admin_list *admin_list = NULL;
39 * initialize admin socket
45 /* open and bind socket */
46 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
48 PERROR("Failed to create admin socket. (errno=%d)\n", errno);
52 memset(&sock_address, 0, sizeof(sock_address));
53 sock_address.sun_family = AF_UNIX;
54 UCPY(sock_address.sun_path, socket_name);
56 if (bind(sock, (struct sockaddr *)(&sock_address), SUN_LEN(&sock_address)) < 0)
62 PERROR("Failed to bind admin socket to \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
65 if (listen(sock, 5) < 0)
71 PERROR("Failed to listen to socket \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
74 if (ioctl(sock, FIONBIO, (unsigned char *)(&on)) < 0)
80 PERROR("Failed to set socket \"%s\" into non-blocking mode. (errno=%d)\n", sock_address.sun_path, errno);
90 void free_connection(struct admin_list *admin)
92 struct admin_queue *response;
100 // printf("new\n", response);
101 response = admin->response;
105 // printf("%x\n", response);
106 temp = response->next;
109 response = (struct admin_queue *)temp;
111 // printf("new2\n", response);
113 // printf("new3\n", response);
119 * cleanup admin socket
121 void admin_cleanup(void)
123 struct admin_list *admin, *next;;
130 free_connection(admin);
143 * do interface reload
145 int admin_interface(struct admin_queue **responsep)
147 struct admin_queue *response; /* response pointer */
151 if (read_interfaces())
154 free_interfaces(interface_first);
155 interface_first = interface_newlist;
156 interface_newlist = NULL;
159 err_txt = interface_error;
162 /* create state response */
163 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
167 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
170 response->am[0].message = ADMIN_RESPONSE_CMD_INTERFACE;
172 response->am[0].u.x.error = err;
174 SCPY(response->am[0].u.x.message, err_txt);
175 /* attach to response chain */
176 *responsep = response;
177 responsep = &response->next;
186 int admin_route(struct admin_queue **responsep)
188 struct route_ruleset *ruleset_new;
189 struct admin_queue *response; /* response pointer */
190 char err_txt[256] = "";
195 class EndpointAppPBX *apppbx;
199 apppbx = apppbx_first;
203 apppbx = apppbx->next;
207 SPRINT(err_txt, "Cannot reload routing, because %d endpoints active\n", n);
212 if (!(ruleset_new = ruleset_parse()))
214 SPRINT(err_txt, ruleset_error);
218 ruleset_free(ruleset_first);
219 ruleset_first = ruleset_new;
220 ruleset_main = getrulesetbyname("main");
223 SPRINT(err_txt, "Ruleset reloaded, but rule 'main' not found.\n");
226 apppbx = apppbx_first;
229 if (apppbx->e_action)
231 switch(apppbx->e_action->index)
233 case ACTION_INTERNAL:
234 apppbx->e_action = &action_internal;
236 case ACTION_EXTERNAL:
237 apppbx->e_action = &action_external;
240 apppbx->e_action = &action_chan;
242 case ACTION_VBOX_RECORD:
243 apppbx->e_action = &action_vbox;
245 case ACTION_PARTYLINE:
246 apppbx->e_action = &action_partyline;
251 } else if (apppbx->e_state != EPOINT_STATE_CONNECT)
254 apppbx->e_callback = 0;
255 apppbx->e_action = NULL;
256 apppbx->release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
259 numberrize_callerinfo(apppbx->e_callerinfo.id, apppbx->e_callerinfo.ntype),
260 apppbx->e_dialinginfo.id,
263 apppbx->ea_endpoint->ep_serial,
264 "KICK (reload routing)");
268 apppbx->e_action_timeout = NULL;
269 apppbx->e_rule = NULL;
270 apppbx->e_ruleset = NULL;
272 apppbx = apppbx->next;
276 /* create state response */
277 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
281 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
284 response->am[0].message = ADMIN_RESPONSE_CMD_ROUTE;
286 response->am[0].u.x.error = err;
288 SCPY(response->am[0].u.x.message, err_txt);
289 /* attach to response chain */
290 *responsep = response;
291 responsep = &response->next;
300 int admin_dial(struct admin_queue **responsep, char *message)
302 struct extension ext; /* temporary extension's settings */
303 struct admin_queue *response; /* response pointer */
304 char *p; /* pointer to dialing digits */
306 /* create state response */
307 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
311 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
314 response->am[0].message = ADMIN_RESPONSE_CMD_DIAL;
316 /* process request */
317 if (!(p = strchr(message,':')))
319 response->am[0].u.x.error = -EINVAL;
320 SPRINT(response->am[0].u.x.message, "no seperator ':' in message to seperate number from extension");
325 /* modify extension */
326 if (!read_extension(&ext, message))
328 response->am[0].u.x.error = -EINVAL;
329 SPRINT(response->am[0].u.x.message, "extension doesn't exist");
333 write_extension(&ext, message);
336 /* attach to response chain */
337 *responsep = response;
338 responsep = &response->next;
346 int admin_trace(struct admin_list *admin, struct admin_trace_req *trace)
348 memcpy(&admin->trace, trace, sizeof(struct admin_trace_req));
356 * 0 = make port available
357 * 1 = make port administratively blocked
359 * the result is returned:
360 * 0 = port is now available
361 * 1 = port is now blocked
362 * 2 = port cannot be loaded or has been unloaded
363 * -1 = port doesn't exist
365 int admin_block(struct admin_queue **responsep, int portnum, int block)
367 struct admin_queue *response; /* response pointer */
368 struct interface *interface;
369 struct interface_port *ifport;
371 /* create block response */
372 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
376 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
379 response->am[0].message = ADMIN_RESPONSE_CMD_BLOCK;
380 response->am[0].u.x.portnum = portnum;
382 /* search for port */
383 interface = interface_first;
386 ifport = interface->ifport;
389 if (ifport->portnum == portnum)
391 ifport = ifport->next;
395 interface = interface->next;
397 /* not found, we return -1 */
400 response->am[0].u.x.block = -1;
401 response->am[0].u.x.error = 1;
402 SPRINT(response->am[0].u.x.message, "Port %d does not exist.", portnum);
407 if (!ifport->mISDNport)
409 /* not loaded anyway */
412 response->am[0].u.x.block = 2;
416 /* try loading interface */
417 ifport->block = block;
420 /* port cannot load */
421 if (ifport->block >= 2)
423 response->am[0].u.x.block = 2;
424 response->am[0].u.x.error = 1;
425 SPRINT(response->am[0].u.x.message, "Port %d will not load.", portnum);
430 response->am[0].u.x.block = ifport->block;
434 /* if we shall unload interface */
437 mISDNport_close(ifport->mISDNport);
438 ifport->mISDNport = 0;
443 /* port new blocking state */
444 ifport->block = response->am[0].u.x.block = block;
447 /* attach to response chain */
448 *responsep = response;
449 responsep = &response->next;
457 int admin_release(struct admin_queue **responsep, char *message)
460 struct admin_queue *response; /* response pointer */
461 class EndpointAppPBX *apppbx;
463 /* create state response */
464 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
468 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
471 response->am[0].message = ADMIN_RESPONSE_CMD_RELEASE;
474 apppbx = apppbx_first;
477 if (apppbx->ea_endpoint->ep_serial == id)
479 apppbx = apppbx->next;
483 response->am[0].u.x.error = -EINVAL;
484 SPRINT(response->am[0].u.x.message, "Given endpoint %d doesn't exist.", id);
488 apppbx->e_callback = 0;
489 apppbx->release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
492 /* attach to response chain */
493 *responsep = response;
494 responsep = &response->next;
502 int admin_call(struct admin_list *admin, struct admin_message *msg)
504 class Endpoint *epoint;
505 class EndpointAppPBX *apppbx;
507 if (!(epoint = new Endpoint(0,0)))
510 if (!(epoint->ep_app = apppbx = new DEFAULT_ENDPOINT_APP(epoint)))
512 PERROR("no memory for application\n");
515 apppbx->e_adminid = admin->sockserial;
516 admin->epointid = epoint->ep_serial;
517 SCPY(apppbx->e_callerinfo.id, nationalize_callerinfo(msg->u.call.callerid, &apppbx->e_callerinfo.ntype));
518 if (msg->u.call.present)
519 apppbx->e_callerinfo.present = INFO_PRESENT_ALLOWED;
521 apppbx->e_callerinfo.present = INFO_PRESENT_RESTRICTED;
522 apppbx->e_callerinfo.screen = INFO_SCREEN_NETWORK;
524 //printf("hh=%d\n", apppbx->e_capainfo.hlc);
526 apppbx->e_capainfo.bearer_capa = msg->u.call.bc_capa;
527 apppbx->e_capainfo.bearer_mode = msg->u.call.bc_mode;
528 apppbx->e_capainfo.bearer_info1 = msg->u.call.bc_info1;
529 apppbx->e_capainfo.hlc = msg->u.call.hlc;
530 apppbx->e_capainfo.exthlc = msg->u.call.exthlc;
531 SCPY(apppbx->e_dialinginfo.id, msg->u.call.dialing);
532 SCPY(apppbx->e_dialinginfo.interfaces, msg->u.call.interface);
533 apppbx->e_dialinginfo.sending_complete = 1;
535 apppbx->new_state(PORT_STATE_OUT_SETUP);
542 * this function is called for response whenever a call state changes.
544 void admin_call_response(int adminid, int message, char *connected, int cause, int location, int notify)
546 struct admin_list *admin;
547 struct admin_queue *response, **responsep; /* response pointer */
549 /* searching for admin id
550 * maybe there is no admin instance, because the calling port was not
551 * initiated by admin_call */
555 if (adminid == admin->sockserial)
562 /* seek to end of response list */
563 response = admin->response;
564 responsep = &admin->response;
567 responsep = &response->next;
568 response = response->next;
571 /* create state response */
572 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
576 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
579 response->am[0].message = message;
580 // printf("MESSAGE: %d\n", message);
582 SCPY(response->am[0].u.call.callerid, connected);
583 response->am[0].u.call.cause = cause;
584 response->am[0].u.call.location = location;
585 response->am[0].u.call.notify = notify;
587 /* attach to response chain */
588 *responsep = response;
589 responsep = &response->next;
596 int admin_state(struct admin_queue **responsep)
600 class EndpointAppPBX *apppbx;
603 struct interface *interface;
604 struct interface_port *ifport;
605 struct mISDNport *mISDNport;
609 struct admin_queue *response;
611 /* create state response */
612 response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
616 memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
619 response->am[0].message = ADMIN_RESPONSE_STATE;
621 SCPY(response->am[0].u.s.version_string, VERSION_STRING);
623 memcpy(&response->am[0].u.s.tm, now_tm, sizeof(struct tm));
625 SCPY(response->am[0].u.s.logfile, options.log);
626 /* interface count */
628 interface = interface_first;
631 ifport = interface->ifport;
635 ifport = ifport->next;
637 interface = interface->next;
639 response->am[0].u.s.interfaces = i;
648 response->am[0].u.s.calls = i;
650 apppbx = apppbx_first;
655 apppbx = apppbx->next;
657 response->am[0].u.s.epoints = i;
666 response->am[0].u.s.ports = i;
667 /* attach to response chain */
668 *responsep = response;
669 responsep = &response->next;
671 /* create response for all interfaces */
672 num = (response->am[0].u.s.interfaces)+(response->am[0].u.s.calls)+(response->am[0].u.s.epoints)+(response->am[0].u.s.ports);
675 response = (struct admin_queue *)malloc(sizeof(admin_queue)+(num*sizeof(admin_message)));
679 memset(response, 0, sizeof(admin_queue)+(num*sizeof(admin_message)));
681 *responsep = response;
682 responsep = &response->next;
683 interface = interface_first;
687 ifport = interface->ifport;
691 response->am[num].message = ADMIN_RESPONSE_S_INTERFACE;
693 SCPY(response->am[num].u.i.interface_name, interface->name);
695 response->am[num].u.i.portnum = ifport->portnum;
697 response->am[num].u.i.extension = interface->extension;
699 response->am[num].u.i.block = ifport->block;
700 if (ifport->mISDNport)
702 mISDNport = ifport->mISDNport;
705 response->am[num].u.i.ptp = mISDNport->ptp;
707 response->am[num].u.i.ntmode = mISDNport->ntmode;
709 response->am[num].u.i.pri = mISDNport->pri;
711 response->am[num].u.i.use = mISDNport->use;
713 response->am[num].u.i.l1link = mISDNport->l1link;
715 response->am[num].u.i.l2link = mISDNport->l2link;
717 response->am[num].u.i.channels = mISDNport->b_num;
721 while(i < mISDNport->b_num)
723 response->am[num].u.i.busy[i] = mISDNport->b_state[i];
724 if (mISDNport->b_port[i])
725 response->am[num].u.i.port[i] = mISDNport->b_port[i]->p_serial;
731 ifport = ifport->next;
733 interface = interface->next;
736 /* create response for all calls */
741 response->am[num].message = ADMIN_RESPONSE_S_CALL;
743 response->am[num].u.c.serial = call->c_serial;
745 if (call->c_type == CALL_TYPE_PBX)
746 response->am[num].u.c.partyline = ((class CallPBX *)call)->c_partyline;
752 /* create response for all endpoint */
753 apppbx = apppbx_first;
757 response->am[num].message = ADMIN_RESPONSE_S_EPOINT;
759 response->am[num].u.e.serial = apppbx->ea_endpoint->ep_serial;
761 response->am[num].u.e.call = apppbx->ea_endpoint->ep_call_id;
762 /* rx notification */
763 response->am[num].u.e.rx_state = apppbx->e_rx_state;
764 /* tx notification */
765 response->am[num].u.e.tx_state = apppbx->e_tx_state;
767 switch(apppbx->e_state)
769 case EPOINT_STATE_IN_SETUP:
770 response->am[num].u.e.state = ADMIN_STATE_IN_SETUP;
772 case EPOINT_STATE_OUT_SETUP:
773 response->am[num].u.e.state = ADMIN_STATE_OUT_SETUP;
775 case EPOINT_STATE_IN_OVERLAP:
776 response->am[num].u.e.state = ADMIN_STATE_IN_OVERLAP;
778 case EPOINT_STATE_OUT_OVERLAP:
779 response->am[num].u.e.state = ADMIN_STATE_OUT_OVERLAP;
781 case EPOINT_STATE_IN_PROCEEDING:
782 response->am[num].u.e.state = ADMIN_STATE_IN_PROCEEDING;
784 case EPOINT_STATE_OUT_PROCEEDING:
785 response->am[num].u.e.state = ADMIN_STATE_OUT_PROCEEDING;
787 case EPOINT_STATE_IN_ALERTING:
788 response->am[num].u.e.state = ADMIN_STATE_IN_ALERTING;
790 case EPOINT_STATE_OUT_ALERTING:
791 response->am[num].u.e.state = ADMIN_STATE_OUT_ALERTING;
793 case EPOINT_STATE_CONNECT:
794 response->am[num].u.e.state = ADMIN_STATE_CONNECT;
796 case EPOINT_STATE_IN_DISCONNECT:
797 response->am[num].u.e.state = ADMIN_STATE_IN_DISCONNECT;
799 case EPOINT_STATE_OUT_DISCONNECT:
800 response->am[num].u.e.state = ADMIN_STATE_OUT_DISCONNECT;
803 response->am[num].u.e.state = ADMIN_STATE_IDLE;
806 SCPY(response->am[num].u.e.terminal, apppbx->e_ext.number);
808 SCPY(response->am[num].u.e.callerid, apppbx->e_callerinfo.id);
810 SCPY(response->am[num].u.e.dialing, apppbx->e_dialinginfo.id);
812 if (apppbx->e_action)
813 SCPY(response->am[num].u.e.action, action_defs[apppbx->e_action->index].name);
814 // if (apppbx->e_action)
815 // printf("action=%s\n",action_defs[apppbx->e_action->index].name);
817 response->am[num].u.e.park = apppbx->ea_endpoint->ep_park;
818 if (apppbx->ea_endpoint->ep_park && apppbx->ea_endpoint->ep_park_len && apppbx->ea_endpoint->ep_park_len<=(int)sizeof(response->am[num].u.e.park_callid))
819 memcpy(response->am[num].u.e.park_callid, apppbx->ea_endpoint->ep_park_callid, apppbx->ea_endpoint->ep_park_len);
820 response->am[num].u.e.park_len = apppbx->ea_endpoint->ep_park_len;
822 if (apppbx->e_crypt == CRYPT_ON)
823 response->am[num].u.e.crypt = 1;
825 apppbx = apppbx->next;
829 /* create response for all ports */
834 response->am[num].message = ADMIN_RESPONSE_S_PORT;
836 response->am[num].u.p.serial = port->p_serial;
838 SCPY(response->am[num].u.p.name, port->p_name);
840 response->am[num].u.p.epoint = ACTIVE_EPOINT(port->p_epointlist);
842 switch(port->p_state)
844 case PORT_STATE_IN_SETUP:
845 response->am[num].u.p.state = ADMIN_STATE_IN_SETUP;
847 case PORT_STATE_OUT_SETUP:
848 response->am[num].u.p.state = ADMIN_STATE_OUT_SETUP;
850 case PORT_STATE_IN_OVERLAP:
851 response->am[num].u.p.state = ADMIN_STATE_IN_OVERLAP;
853 case PORT_STATE_OUT_OVERLAP:
854 response->am[num].u.p.state = ADMIN_STATE_OUT_OVERLAP;
856 case PORT_STATE_IN_PROCEEDING:
857 response->am[num].u.p.state = ADMIN_STATE_IN_PROCEEDING;
859 case PORT_STATE_OUT_PROCEEDING:
860 response->am[num].u.p.state = ADMIN_STATE_OUT_PROCEEDING;
862 case PORT_STATE_IN_ALERTING:
863 response->am[num].u.p.state = ADMIN_STATE_IN_ALERTING;
865 case PORT_STATE_OUT_ALERTING:
866 response->am[num].u.p.state = ADMIN_STATE_OUT_ALERTING;
868 case PORT_STATE_CONNECT:
869 response->am[num].u.p.state = ADMIN_STATE_CONNECT;
871 case PORT_STATE_IN_DISCONNECT:
872 response->am[num].u.p.state = ADMIN_STATE_IN_DISCONNECT;
874 case PORT_STATE_OUT_DISCONNECT:
875 response->am[num].u.p.state = ADMIN_STATE_OUT_DISCONNECT;
878 response->am[num].u.p.state = ADMIN_STATE_IDLE;
881 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
883 response->am[num].u.p.isdn = 1;
884 pdss1 = (class Pdss1 *)port;
885 response->am[num].u.p.isdn_chan = pdss1->p_m_b_channel;
886 response->am[num].u.p.isdn_hold = pdss1->p_m_hold;
887 response->am[num].u.p.isdn_ces = pdss1->p_m_d_ces;
896 int sockserial = 1; // must start with 1, because 0 is used if no serial is set
898 * handle admin socket (non blocking)
900 int admin_handle(void)
902 struct admin_list *admin, **adminp;
904 struct admin_message msg;
907 socklen_t sock_len = sizeof(sock_address);
908 unsigned long on = 1;
909 int work = 0; /* if work was done */
910 struct Endpoint *epoint;
915 /* check for new incomming connections */
916 if ((new_sock = accept(sock, (struct sockaddr *)&sock_address, &sock_len)) >= 0)
919 /* insert new socket */
920 admin = (struct admin_list *)malloc(sizeof(struct admin_list));
923 if (ioctl(new_sock, FIONBIO, (unsigned char *)(&on)) >= 0)
926 // PERROR("DEBUG incomming socket %d, serial=%d\n", new_sock, sockserial);
929 memset(admin, 0, sizeof(struct admin_list));
930 admin->sockserial = sockserial++;
931 admin->next = admin_list;
933 admin->sock = new_sock;
942 if (errno != EWOULDBLOCK)
944 PERROR("Failed to accept connection from socket \"%s\". (errno=%d) Closing socket.\n", sock_address.sun_path, errno);
950 /* loop all current socket connections */
952 adminp = &admin_list;
956 len = read(admin->sock, &msg, sizeof(msg));
959 if (errno != EWOULDBLOCK)
963 printf("Broken pipe on socket %d. (errno=%d).\n", admin->sock, errno);
964 PDEBUG(DEBUG_LOG, "Broken pipe on socket %d. (errno=%d).\n", admin->sock, errno);
965 *adminp = admin->next;
966 free_connection(admin);
974 //PERROR("DEBUG socket %d got data. serial=%d\n", admin->sock, admin->sockserial);
979 /*release endpoint if exists */
982 epoint = find_epoint_id(admin->epointid);
985 ((class DEFAULT_ENDPOINT_APP *)epoint->ep_app)->
986 release(RELEASE_ALL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, 0, 0);
991 //PERROR("DEBUG socket %d closed by remote.\n", admin->sock);
992 *adminp = admin->next;
993 free_connection(admin);
995 //PERROR("DEBUG (admin_list=%x)\n", admin_list);
998 if (len != sizeof(msg))
1000 PERROR("Short/long read on socket %d. (len=%d != size=%d).\n", admin->sock, len, sizeof(msg));
1001 *adminp = admin->next;
1002 free_connection(admin);
1006 /* process socket command */
1007 if (admin->response)
1009 PERROR("Data from socket %d while sending response.\n", admin->sock);
1010 *adminp = admin->next;
1011 free_connection(admin);
1015 switch (msg.message)
1017 case ADMIN_REQUEST_CMD_INTERFACE:
1018 if (admin_interface(&admin->response) < 0)
1020 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1021 goto response_error;
1025 case ADMIN_REQUEST_CMD_ROUTE:
1026 if (admin_route(&admin->response) < 0)
1028 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1029 goto response_error;
1033 case ADMIN_REQUEST_CMD_DIAL:
1034 if (admin_dial(&admin->response, msg.u.x.message) < 0)
1036 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1037 goto response_error;
1041 case ADMIN_REQUEST_CMD_RELEASE:
1042 if (admin_release(&admin->response, msg.u.x.message) < 0)
1044 PERROR("Failed to create release response for socket %d.\n", admin->sock);
1045 goto response_error;
1049 case ADMIN_REQUEST_STATE:
1050 if (admin_state(&admin->response) < 0)
1052 PERROR("Failed to create state response for socket %d.\n", admin->sock);
1053 goto response_error;
1057 case ADMIN_TRACE_REQUEST:
1058 if (admin_trace(admin, &msg.u.trace_req) < 0)
1060 PERROR("Failed to create trace response for socket %d.\n", admin->sock);
1061 goto response_error;
1065 case ADMIN_REQUEST_CMD_BLOCK:
1066 if (admin_block(&admin->response, msg.u.x.portnum, msg.u.x.block) < 0)
1068 PERROR("Failed to create block response for socket %d.\n", admin->sock);
1069 goto response_error;
1073 #warning interface tbd
1076 if (admin_message(&admin->response) < 0)
1078 PERROR("Failed to create message response for socket %d.\n", admin->sock);
1079 goto response_error;
1085 struct admin_queue *response;
1087 response = admin->response;
1090 printf("%c", '0'+response->am[0].message);
1091 response=response->next;
1098 case ADMIN_CALL_SETUP:
1099 if (admin_call(admin, &msg) < 0)
1101 PERROR("Failed to create call for socket %d.\n", admin->sock);
1103 *adminp = admin->next;
1104 free_connection(admin);
1111 PERROR("Invalid message %d from socket %d.\n", msg.message, admin->sock);
1112 *adminp = admin->next;
1113 free_connection(admin);
1119 if (admin->response)
1122 //PERROR("DEBUG socket %d sending data.\n", admin->sock);
1123 len = write(admin->sock, ((unsigned char *)(admin->response->am))+admin->response->offset, sizeof(struct admin_message)*(admin->response->num)-admin->response->offset);
1126 if (errno != EWOULDBLOCK)
1136 if (len < (int)(sizeof(struct admin_message)*(admin->response->num)-admin->response->offset))
1138 admin->response->offset+=len;
1142 temp = admin->response;
1143 admin->response = admin->response->next;
1148 /* done with socket instance */
1150 adminp = &admin->next;
1151 admin = admin->next;