1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** Socket link server **
10 \*****************************************************************************/
13 #include <sys/socket.h>
18 char socket_name[128];
20 struct sockaddr_un sock_address;
22 struct admin_list *admin_first = NULL;
25 * initialize admin socket
31 /* open and bind socket */
32 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
33 PERROR("Failed to create admin socket. (errno=%d)\n", errno);
37 memset(&sock_address, 0, sizeof(sock_address));
38 SPRINT(socket_name, SOCKET_NAME, options.lock);
39 sock_address.sun_family = AF_UNIX;
40 UCPY(sock_address.sun_path, socket_name);
42 if (bind(sock, (struct sockaddr *)(&sock_address), SUN_LEN(&sock_address)) < 0) {
47 PERROR("Failed to bind admin socket to \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
50 if (listen(sock, 5) < 0) {
55 PERROR("Failed to listen to socket \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
58 if (ioctl(sock, FIONBIO, (unsigned char *)(&on)) < 0) {
63 PERROR("Failed to set socket \"%s\" into non-blocking mode. (errno=%d)\n", sock_address.sun_path, errno);
66 if (chmod(socket_name, options.socketrights) < 0) {
67 PERROR("Failed to change socket rights to %d. (errno=%d)\n", options.socketrights, errno);
69 if (chown(socket_name, options.socketuser, options.socketgroup) < 0) {
70 PERROR("Failed to change socket user/group to %d/%d. (errno=%d)\n", options.socketuser, options.socketgroup, errno);
79 * also releases all remote joins
81 void free_connection(struct admin_list *admin)
83 struct admin_queue *response;
85 union parameter param;
86 class Join *join, *joinnext;
87 struct mISDNport *mISDNport;
90 /* free remote joins */
91 if (admin->remote_name[0]) {
99 "REMOTE APP release");
100 add_trace("app", "name", "%s", admin->remote_name);
102 /* release all exported channels */
103 mISDNport = mISDNport_first;
106 ii = mISDNport->b_num;
108 if (mISDNport->b_remote_id[i] == admin->sock) {
109 mISDNport->b_state[i] = B_STATE_IDLE;
110 mISDNport->b_timer[i] = 0;
111 mISDNport->b_remote_id[i] = 0;
112 mISDNport->b_remote_ref[i] = 0;
116 mISDNport = mISDNport->next;
121 joinnext = join->next;
122 if (join->j_type==JOIN_TYPE_REMOTE) if (((class JoinRemote *)join)->j_remote_id == admin->sock) {
123 memset(¶m, 0, sizeof(param));
124 param.disconnectinfo.cause = CAUSE_OUTOFORDER;
125 param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
126 ((class JoinRemote *)join)->message_remote(MESSAGE_RELEASE, ¶m);
127 /* join is now destroyed, so we go to next join */
133 if (admin->sock >= 0) {
137 // printf("new\n", response);
138 response = admin->response;
141 // printf("%x\n", response);
142 temp = response->next;
145 response = (struct admin_queue *)temp;
147 // printf("new2\n", response);
149 // printf("new3\n", response);
155 * cleanup admin socket
157 void admin_cleanup(void)
159 struct admin_list *admin, *next;;
165 free_connection(admin);
179 * do interface reload
181 int admin_interface(struct admin_queue **responsep)
183 struct admin_queue *response; /* response pointer */
184 const char *err_txt = "";
187 if (read_interfaces()) {
189 free_interfaces(interface_first);
190 interface_first = interface_newlist;
191 interface_newlist = NULL;
193 err_txt = interface_error;
196 /* create state response */
197 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
201 response->am[0].message = ADMIN_RESPONSE_CMD_INTERFACE;
203 response->am[0].u.x.error = err;
205 SCPY(response->am[0].u.x.message, err_txt);
206 /* attach to response chain */
207 *responsep = response;
208 responsep = &response->next;
217 int admin_route(struct admin_queue **responsep)
219 struct route_ruleset *ruleset_new;
220 struct admin_queue *response; /* response pointer */
221 char err_txt[256] = "";
226 class EndpointAppPBX *apppbx;
230 apppbx = apppbx_first;
233 apppbx = apppbx->next;
236 SPRINT(err_txt, "Cannot reload routing, because %d endpoints active\n", n);
241 if (!(ruleset_new = ruleset_parse())) {
242 SPRINT(err_txt, ruleset_error);
246 ruleset_free(ruleset_first);
247 ruleset_first = ruleset_new;
248 ruleset_main = getrulesetbyname("main");
250 SPRINT(err_txt, "Ruleset reloaded, but rule 'main' not found.\n");
253 apppbx = apppbx_first;
255 if (apppbx->e_action) {
256 switch(apppbx->e_action->index) {
257 case ACTION_INTERNAL:
258 apppbx->e_action = &action_internal;
260 case ACTION_EXTERNAL:
261 apppbx->e_action = &action_external;
264 apppbx->e_action = &action_remote;
266 case ACTION_VBOX_RECORD:
267 apppbx->e_action = &action_vbox;
269 case ACTION_PARTYLINE:
270 apppbx->e_action = &action_partyline;
275 } else if (apppbx->e_state != EPOINT_STATE_CONNECT) {
277 apppbx->e_callback = 0;
278 apppbx->e_action = NULL;
279 apppbx->release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
282 numberrize_callerinfo(apppbx->e_callerinfo.id, apppbx->e_callerinfo.ntype, options.national, options.international),
283 apppbx->e_dialinginfo.id,
286 apppbx->ea_endpoint->ep_serial,
287 "KICK (reload routing)");
291 apppbx->e_action_timeout = 0;
292 apppbx->e_rule = NULL;
293 apppbx->e_ruleset = NULL;
295 apppbx = apppbx->next;
299 /* create state response */
300 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
304 response->am[0].message = ADMIN_RESPONSE_CMD_ROUTE;
306 response->am[0].u.x.error = err;
308 SCPY(response->am[0].u.x.message, err_txt);
309 /* attach to response chain */
310 *responsep = response;
311 responsep = &response->next;
320 int admin_dial(struct admin_queue **responsep, char *message)
322 struct extension ext; /* temporary extension's settings */
323 struct admin_queue *response; /* response pointer */
324 char *p; /* pointer to dialing digits */
326 /* create state response */
327 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
331 response->am[0].message = ADMIN_RESPONSE_CMD_DIAL;
333 /* process request */
334 if (!(p = strchr(message,':'))) {
335 response->am[0].u.x.error = -EINVAL;
336 SPRINT(response->am[0].u.x.message, "no seperator ':' in message to seperate number from extension");
341 /* modify extension */
342 if (!read_extension(&ext, message)) {
343 response->am[0].u.x.error = -EINVAL;
344 SPRINT(response->am[0].u.x.message, "extension doesn't exist");
348 write_extension(&ext, message);
351 /* attach to response chain */
352 *responsep = response;
353 responsep = &response->next;
361 int admin_trace(struct admin_list *admin, struct admin_trace_req *trace)
363 memcpy(&admin->trace, trace, sizeof(struct admin_trace_req));
371 * 0 = make port available
372 * 1 = make port administratively blocked
374 * the result is returned:
375 * 0 = port is now available
376 * 1 = port is now blocked
377 * 2 = port cannot be loaded or has been unloaded
378 * -1 = port doesn't exist
380 int admin_block(struct admin_queue **responsep, int portnum, int block)
382 struct admin_queue *response; /* response pointer */
383 struct interface *interface;
384 struct interface_port *ifport;
386 /* create block response */
387 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
391 response->am[0].message = ADMIN_RESPONSE_CMD_BLOCK;
392 response->am[0].u.x.portnum = portnum;
394 /* search for port */
396 interface = interface_first;
398 ifport = interface->ifport;
400 if (ifport->portnum == portnum)
402 ifport = ifport->next;
406 interface = interface->next;
408 /* not found, we return -1 */
410 response->am[0].u.x.block = -1;
411 response->am[0].u.x.error = 1;
412 SPRINT(response->am[0].u.x.message, "Port %d does not exist.", portnum);
417 if (!ifport->mISDNport) {
418 /* not loaded anyway */
420 response->am[0].u.x.block = 2;
424 /* try loading interface */
425 ifport->block = block;
428 /* port cannot load */
429 if (ifport->block >= 2) {
430 response->am[0].u.x.block = 2;
431 response->am[0].u.x.error = 1;
432 SPRINT(response->am[0].u.x.message, "Port %d will not load.", portnum);
437 response->am[0].u.x.block = ifport->block;
441 /* if we shall unload interface */
443 mISDNport_close(ifport->mISDNport);
444 ifport->mISDNport = 0;
449 /* port new blocking state */
450 ifport->block = response->am[0].u.x.block = block;
453 /* attach to response chain */
454 *responsep = response;
455 responsep = &response->next;
463 int admin_release(struct admin_queue **responsep, char *message)
466 struct admin_queue *response; /* response pointer */
467 class EndpointAppPBX *apppbx;
469 /* create state response */
470 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
474 response->am[0].message = ADMIN_RESPONSE_CMD_RELEASE;
477 apppbx = apppbx_first;
479 if (apppbx->ea_endpoint->ep_serial == id)
481 apppbx = apppbx->next;
484 response->am[0].u.x.error = -EINVAL;
485 SPRINT(response->am[0].u.x.message, "Given endpoint %d doesn't exist.", id);
489 apppbx->e_callback = 0;
490 apppbx->release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
493 /* attach to response chain */
494 *responsep = response;
495 responsep = &response->next;
503 int admin_call(struct admin_list *admin, struct admin_message *msg)
505 class Endpoint *epoint;
506 class EndpointAppPBX *apppbx;
508 if (!(epoint = new Endpoint(0, 0)))
509 FATAL("No memory for Endpoint instance\n");
510 if (!(epoint->ep_app = apppbx = new DEFAULT_ENDPOINT_APP(epoint, 1))) // outgoing
511 FATAL("No memory for Endpoint Application instance\n");
512 apppbx->e_adminid = admin->sockserial;
513 admin->epointid = epoint->ep_serial;
514 SCPY(apppbx->e_callerinfo.id, nationalize_callerinfo(msg->u.call.callerid, &apppbx->e_callerinfo.ntype, options.national, options.international));
515 if (msg->u.call.present)
516 apppbx->e_callerinfo.present = INFO_PRESENT_ALLOWED;
518 apppbx->e_callerinfo.present = INFO_PRESENT_RESTRICTED;
519 apppbx->e_callerinfo.screen = INFO_SCREEN_NETWORK;
521 //printf("hh=%d\n", apppbx->e_capainfo.hlc);
523 apppbx->e_capainfo.bearer_capa = msg->u.call.bc_capa;
524 apppbx->e_capainfo.bearer_mode = msg->u.call.bc_mode;
525 apppbx->e_capainfo.bearer_info1 = msg->u.call.bc_info1;
526 apppbx->e_capainfo.hlc = msg->u.call.hlc;
527 apppbx->e_capainfo.exthlc = msg->u.call.exthlc;
528 SCPY(apppbx->e_dialinginfo.id, msg->u.call.dialing);
529 SCPY(apppbx->e_dialinginfo.interfaces, msg->u.call.interface);
530 apppbx->e_dialinginfo.sending_complete = 1;
532 apppbx->new_state(PORT_STATE_OUT_SETUP);
539 * this function is called for response whenever a call state changes.
541 void admin_call_response(int adminid, int message, const char *connected, int cause, int location, int notify)
543 struct admin_list *admin;
544 struct admin_queue *response, **responsep; /* response pointer */
546 /* searching for admin id
547 * maybe there is no admin instance, because the calling port was not
548 * initiated by admin_call */
551 if (adminid == admin->sockserial)
558 /* seek to end of response list */
559 response = admin->response;
560 responsep = &admin->response;
562 responsep = &response->next;
563 response = response->next;
566 /* create state response */
567 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
571 response->am[0].message = message;
572 // printf("MESSAGE: %d\n", message);
574 SCPY(response->am[0].u.call.callerid, connected);
575 response->am[0].u.call.cause = cause;
576 response->am[0].u.call.location = location;
577 response->am[0].u.call.notify = notify;
579 /* attach to response chain */
580 *responsep = response;
581 responsep = &response->next;
586 * send data to the remote socket join instance
588 int admin_message_to_join(struct admin_msg *msg, struct admin_list *admin)
591 struct admin_list *temp;
594 if (msg->type == MESSAGE_HELLO) {
595 if (admin->remote_name[0]) {
596 PERROR("Remote application repeats hello message.\n");
599 /* look for second application */
602 if (!strcmp(temp->remote_name, msg->param.hello.application))
607 PERROR("Remote application connects twice??? (ignoring)\n");
610 /* set remote socket instance */
611 SCPY(admin->remote_name, msg->param.hello.application);
619 "REMOTE APP registers");
620 add_trace("app", "name", "%s", admin->remote_name);
625 /* check we have no application name */
626 if (!admin->remote_name[0]) {
627 PERROR("Remote application did not send us a hello message.\n");
632 if (msg->type == MESSAGE_NEWREF) {
633 /* create new join instance */
634 join = new JoinRemote(0, admin->remote_name, admin->sock); // must have no serial, because no endpoint is connected
636 FATAL("No memory for remote join instance\n");
643 * no ref given for *_ack */
644 if (msg->type == MESSAGE_BCHANNEL)
645 if (msg->param.bchannel.type == BCHANNEL_ASSIGN_ACK
646 || msg->param.bchannel.type == BCHANNEL_REMOVE_ACK
647 || msg->param.bchannel.type == BCHANNEL_RELEASE) {
648 /* no ref, but address */
649 message_bchannel_from_remote(NULL, msg->param.bchannel.type, msg->param.bchannel.handle);
655 PERROR("Remote application did not send us a valid ref with a message.\n");
659 /* find join instance */
662 if (join->j_serial == msg->ref)
667 PDEBUG(DEBUG_LOG, "No join found with serial %d. (May have been already released.)\n", msg->ref);
671 /* check application */
672 if (join->j_type != JOIN_TYPE_REMOTE) {
673 PERROR("Ref %d does not belong to a remote join instance.\n", msg->ref);
676 if (admin->sock != ((class JoinRemote *)join)->j_remote_id) {
677 PERROR("Ref %d belongs to remote application %s, but not to sending application %s.\n", msg->ref, ((class JoinRemote *)join)->j_remote_name, admin->remote_name);
682 ((class JoinRemote *)join)->message_remote(msg->type, &msg->param);
689 * this function is called for every message to remote socket
691 int admin_message_from_join(int remote_id, unsigned int ref, int message_type, union parameter *param)
693 struct admin_list *admin;
694 struct admin_queue **responsep; /* response pointer */
696 /* searching for admin id
697 * maybe there is no given remote application
701 if (admin->remote_name[0] && admin->sock==remote_id)
705 /* no given remote application connected */
709 /* seek to end of response list */
710 responsep = &admin->response;
712 responsep = &(*responsep)->next;
715 /* create state response */
716 *responsep = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
718 (*responsep)->num = 1;
721 (*responsep)->am[0].message = ADMIN_MESSAGE;
722 (*responsep)->am[0].u.msg.type = message_type;
723 (*responsep)->am[0].u.msg.ref = ref;
724 memcpy(&(*responsep)->am[0].u.msg.param, param, sizeof(union parameter));
733 int admin_state(struct admin_queue **responsep)
737 class EndpointAppPBX *apppbx;
740 struct interface *interface;
741 struct interface_port *ifport;
742 struct mISDNport *mISDNport;
746 struct admin_queue *response;
747 struct admin_list *admin;
749 /* create state response */
750 response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
754 response->am[0].message = ADMIN_RESPONSE_STATE;
756 SCPY(response->am[0].u.s.version_string, VERSION_STRING);
758 memcpy(&response->am[0].u.s.tm, now_tm, sizeof(struct tm));
760 SCPY(response->am[0].u.s.logfile, options.log);
761 /* interface count */
763 interface = interface_first;
765 ifport = interface->ifport;
768 ifport = ifport->next;
770 interface = interface->next;
772 response->am[0].u.s.interfaces = i;
773 /* remote connection count */
777 if (admin->remote_name[0])
781 response->am[0].u.s.remotes = i;
789 response->am[0].u.s.joins = i;
791 apppbx = apppbx_first;
795 apppbx = apppbx->next;
797 response->am[0].u.s.epoints = i;
805 response->am[0].u.s.ports = i;
806 /* attach to response chain */
807 *responsep = response;
808 responsep = &response->next;
810 /* create response for all instances */
811 num = (response->am[0].u.s.interfaces)
812 + (response->am[0].u.s.remotes)
813 + (response->am[0].u.s.joins)
814 + (response->am[0].u.s.epoints)
815 + (response->am[0].u.s.ports);
818 response = (struct admin_queue *)MALLOC(sizeof(admin_queue)+(num*sizeof(admin_message)));
821 *responsep = response;
822 responsep = &response->next;
823 interface = interface_first;
826 ifport = interface->ifport;
829 response->am[num].message = ADMIN_RESPONSE_S_INTERFACE;
831 SCPY(response->am[num].u.i.interface_name, interface->name);
833 response->am[num].u.i.portnum = ifport->portnum;
835 SCPY(response->am[num].u.i.portname, ifport->portname);
837 response->am[num].u.i.extension = interface->extension;
839 response->am[num].u.i.block = ifport->block;
840 if (ifport->mISDNport) {
841 mISDNport = ifport->mISDNport;
844 response->am[num].u.i.ptp = mISDNport->ptp;
846 response->am[num].u.i.l1hold = mISDNport->l1hold;
848 response->am[num].u.i.l2hold = mISDNport->l2hold;
850 response->am[num].u.i.ntmode = mISDNport->ntmode;
852 response->am[num].u.i.pri = mISDNport->pri;
854 response->am[num].u.i.use = mISDNport->use;
856 response->am[num].u.i.l1link = mISDNport->l1link;
858 response->am[num].u.i.l2link = mISDNport->l2link;
859 memcpy(response->am[num].u.i.l2mask, mISDNport->l2mask, 16);
861 response->am[num].u.i.los = mISDNport->los;
863 response->am[num].u.i.ais = mISDNport->ais;
865 response->am[num].u.i.rdi = mISDNport->rdi;
867 response->am[num].u.i.slip_tx = mISDNport->slip_tx;
868 response->am[num].u.i.slip_rx = mISDNport->slip_rx;
870 response->am[num].u.i.channels = mISDNport->b_num;
874 while(i < mISDNport->b_num) {
875 response->am[num].u.i.busy[i] = mISDNport->b_state[i];
876 if (mISDNport->b_port[i])
877 response->am[num].u.i.port[i] = mISDNport->b_port[i]->p_serial;
878 response->am[num].u.i.mode[i] = mISDNport->b_mode[i];
884 ifport = ifport->next;
886 interface = interface->next;
889 /* create response for all remotes */
892 if (admin->remote_name[0]) {
894 response->am[num].message = ADMIN_RESPONSE_S_REMOTE;
896 SCPY(response->am[num].u.r.name, admin->remote_name);
903 /* create response for all joins */
907 response->am[num].message = ADMIN_RESPONSE_S_JOIN;
909 response->am[num].u.j.serial = join->j_serial;
911 if (join->j_type == JOIN_TYPE_PBX)
912 response->am[num].u.j.partyline = ((class JoinPBX *)join)->j_partyline;
913 /* remote application */
914 if (join->j_type == JOIN_TYPE_REMOTE)
915 SCPY(response->am[num].u.j.remote, ((class JoinRemote *)join)->j_remote_name);
921 /* create response for all endpoint */
922 apppbx = apppbx_first;
925 response->am[num].message = ADMIN_RESPONSE_S_EPOINT;
927 response->am[num].u.e.serial = apppbx->ea_endpoint->ep_serial;
929 response->am[num].u.e.join = apppbx->ea_endpoint->ep_join_id;
930 /* rx notification */
931 response->am[num].u.e.rx_state = apppbx->e_rx_state;
932 /* tx notification */
933 response->am[num].u.e.tx_state = apppbx->e_tx_state;
935 switch(apppbx->e_state) {
936 case EPOINT_STATE_IN_SETUP:
937 response->am[num].u.e.state = ADMIN_STATE_IN_SETUP;
939 case EPOINT_STATE_OUT_SETUP:
940 response->am[num].u.e.state = ADMIN_STATE_OUT_SETUP;
942 case EPOINT_STATE_IN_OVERLAP:
943 response->am[num].u.e.state = ADMIN_STATE_IN_OVERLAP;
945 case EPOINT_STATE_OUT_OVERLAP:
946 response->am[num].u.e.state = ADMIN_STATE_OUT_OVERLAP;
948 case EPOINT_STATE_IN_PROCEEDING:
949 response->am[num].u.e.state = ADMIN_STATE_IN_PROCEEDING;
951 case EPOINT_STATE_OUT_PROCEEDING:
952 response->am[num].u.e.state = ADMIN_STATE_OUT_PROCEEDING;
954 case EPOINT_STATE_IN_ALERTING:
955 response->am[num].u.e.state = ADMIN_STATE_IN_ALERTING;
957 case EPOINT_STATE_OUT_ALERTING:
958 response->am[num].u.e.state = ADMIN_STATE_OUT_ALERTING;
960 case EPOINT_STATE_CONNECT:
961 response->am[num].u.e.state = ADMIN_STATE_CONNECT;
963 case EPOINT_STATE_IN_DISCONNECT:
964 response->am[num].u.e.state = ADMIN_STATE_IN_DISCONNECT;
966 case EPOINT_STATE_OUT_DISCONNECT:
967 response->am[num].u.e.state = ADMIN_STATE_OUT_DISCONNECT;
970 response->am[num].u.e.state = ADMIN_STATE_IDLE;
973 SCPY(response->am[num].u.e.terminal, apppbx->e_ext.number);
975 SCPY(response->am[num].u.e.callerid, apppbx->e_callerinfo.id);
977 SCPY(response->am[num].u.e.dialing, apppbx->e_dialinginfo.id);
979 if (apppbx->e_action)
980 SCPY(response->am[num].u.e.action, action_defs[apppbx->e_action->index].name);
981 // if (apppbx->e_action)
982 // printf("action=%s\n",action_defs[apppbx->e_action->index].name);
984 response->am[num].u.e.park = apppbx->ea_endpoint->ep_park;
985 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))
986 memcpy(response->am[num].u.e.park_callid, apppbx->ea_endpoint->ep_park_callid, apppbx->ea_endpoint->ep_park_len);
987 response->am[num].u.e.park_len = apppbx->ea_endpoint->ep_park_len;
989 if (apppbx->e_crypt == CRYPT_ON)
990 response->am[num].u.e.crypt = 1;
992 apppbx = apppbx->next;
996 /* create response for all ports */
1000 response->am[num].message = ADMIN_RESPONSE_S_PORT;
1002 response->am[num].u.p.serial = port->p_serial;
1004 SCPY(response->am[num].u.p.name, port->p_name);
1006 response->am[num].u.p.epoint = ACTIVE_EPOINT(port->p_epointlist);
1008 switch(port->p_state) {
1009 case PORT_STATE_IN_SETUP:
1010 response->am[num].u.p.state = ADMIN_STATE_IN_SETUP;
1012 case PORT_STATE_OUT_SETUP:
1013 response->am[num].u.p.state = ADMIN_STATE_OUT_SETUP;
1015 case PORT_STATE_IN_OVERLAP:
1016 response->am[num].u.p.state = ADMIN_STATE_IN_OVERLAP;
1018 case PORT_STATE_OUT_OVERLAP:
1019 response->am[num].u.p.state = ADMIN_STATE_OUT_OVERLAP;
1021 case PORT_STATE_IN_PROCEEDING:
1022 response->am[num].u.p.state = ADMIN_STATE_IN_PROCEEDING;
1024 case PORT_STATE_OUT_PROCEEDING:
1025 response->am[num].u.p.state = ADMIN_STATE_OUT_PROCEEDING;
1027 case PORT_STATE_IN_ALERTING:
1028 response->am[num].u.p.state = ADMIN_STATE_IN_ALERTING;
1030 case PORT_STATE_OUT_ALERTING:
1031 response->am[num].u.p.state = ADMIN_STATE_OUT_ALERTING;
1033 case PORT_STATE_CONNECT:
1034 response->am[num].u.p.state = ADMIN_STATE_CONNECT;
1036 case PORT_STATE_IN_DISCONNECT:
1037 response->am[num].u.p.state = ADMIN_STATE_IN_DISCONNECT;
1039 case PORT_STATE_OUT_DISCONNECT:
1040 response->am[num].u.p.state = ADMIN_STATE_OUT_DISCONNECT;
1042 case PORT_STATE_RELEASE:
1043 response->am[num].u.p.state = ADMIN_STATE_RELEASE;
1046 response->am[num].u.p.state = ADMIN_STATE_IDLE;
1049 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1) {
1050 response->am[num].u.p.isdn = 1;
1051 pdss1 = (class Pdss1 *)port;
1052 response->am[num].u.p.isdn_chan = pdss1->p_m_b_channel;
1053 response->am[num].u.p.isdn_hold = pdss1->p_m_hold;
1054 response->am[num].u.p.isdn_ces = pdss1->p_m_d_ces;
1063 int sockserial = 1; // must start with 1, because 0 is used if no serial is set
1065 * handle admin socket (non blocking)
1067 int admin_handle(void)
1069 struct admin_list *admin, **adminp;
1071 struct admin_message msg;
1074 socklen_t sock_len = sizeof(sock_address);
1075 unsigned int on = 1;
1076 int work = 0; /* if work was done */
1077 struct Endpoint *epoint;
1082 /* check for new incoming connections */
1083 if ((new_sock = accept(sock, (struct sockaddr *)&sock_address, &sock_len)) >= 0) {
1085 /* insert new socket */
1086 admin = (struct admin_list *)MALLOC(sizeof(struct admin_list));
1087 if (ioctl(new_sock, FIONBIO, (unsigned char *)(&on)) >= 0) {
1089 // PERROR("DEBUG incoming socket %d, serial=%d\n", new_sock, sockserial);
1092 admin->sockserial = sockserial++;
1093 admin->next = admin_first;
1094 admin_first = admin;
1095 admin->sock = new_sock;
1098 FREE(admin, sizeof(struct admin_list));
1101 if (errno != EWOULDBLOCK) {
1102 PERROR("Failed to accept connection from socket \"%s\". (errno=%d) Closing socket.\n", sock_address.sun_path, errno);
1108 /* loop all current socket connections */
1109 admin = admin_first;
1110 adminp = &admin_first;
1113 len = read(admin->sock, &msg, sizeof(msg));
1115 if (errno != EWOULDBLOCK) {
1118 PDEBUG(DEBUG_LOG, "Broken pipe on socket %d. (errno=%d).\n", admin->sock, errno);
1119 *adminp = admin->next;
1120 free_connection(admin);
1128 //PERROR("DEBUG socket %d got data. serial=%d\n", admin->sock, admin->sockserial);
1132 /*release endpoint if exists */
1133 if (admin->epointid) {
1134 epoint = find_epoint_id(admin->epointid);
1136 ((class DEFAULT_ENDPOINT_APP *)epoint->ep_app)->
1137 release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
1142 //PERROR("DEBUG socket %d closed by remote.\n", admin->sock);
1143 *adminp = admin->next;
1144 free_connection(admin);
1146 //PERROR("DEBUG (admin_first=%x)\n", admin_first);
1149 if (len != sizeof(msg)) {
1150 PERROR("Short/long read on socket %d. (len=%d != size=%d).\n", admin->sock, len, sizeof(msg));
1151 *adminp = admin->next;
1152 free_connection(admin);
1156 /* process socket command */
1157 if (admin->response && msg.message != ADMIN_MESSAGE) {
1158 PERROR("Data from socket %d while sending response.\n", admin->sock);
1159 *adminp = admin->next;
1160 free_connection(admin);
1164 switch (msg.message) {
1165 case ADMIN_REQUEST_CMD_INTERFACE:
1166 if (admin_interface(&admin->response) < 0) {
1167 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1168 goto response_error;
1172 case ADMIN_REQUEST_CMD_ROUTE:
1173 if (admin_route(&admin->response) < 0) {
1174 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1175 goto response_error;
1179 case ADMIN_REQUEST_CMD_DIAL:
1180 if (admin_dial(&admin->response, msg.u.x.message) < 0) {
1181 PERROR("Failed to create dial response for socket %d.\n", admin->sock);
1182 goto response_error;
1186 case ADMIN_REQUEST_CMD_RELEASE:
1187 if (admin_release(&admin->response, msg.u.x.message) < 0) {
1188 PERROR("Failed to create release response for socket %d.\n", admin->sock);
1189 goto response_error;
1193 case ADMIN_REQUEST_STATE:
1194 if (admin_state(&admin->response) < 0) {
1195 PERROR("Failed to create state response for socket %d.\n", admin->sock);
1196 goto response_error;
1200 case ADMIN_TRACE_REQUEST:
1201 if (admin_trace(admin, &msg.u.trace_req) < 0) {
1202 PERROR("Failed to create trace response for socket %d.\n", admin->sock);
1203 goto response_error;
1207 case ADMIN_REQUEST_CMD_BLOCK:
1208 if (admin_block(&admin->response, msg.u.x.portnum, msg.u.x.block) < 0) {
1209 PERROR("Failed to create block response for socket %d.\n", admin->sock);
1210 goto response_error;
1215 if (admin_message_to_join(&msg.u.msg, admin) < 0) {
1216 PERROR("Failed to deliver message for socket %d.\n", admin->sock);
1217 goto response_error;
1222 struct admin_queue *response;
1224 response = admin->response;
1226 printf("%c", '0'+response->am[0].message);
1227 response=response->next;
1234 case ADMIN_CALL_SETUP:
1235 if (admin_call(admin, &msg) < 0) {
1236 PERROR("Failed to create call for socket %d.\n", admin->sock);
1238 *adminp = admin->next;
1239 free_connection(admin);
1246 PERROR("Invalid message %d from socket %d.\n", msg.message, admin->sock);
1247 *adminp = admin->next;
1248 free_connection(admin);
1254 if (admin->response) {
1256 //PERROR("DEBUG socket %d sending data.\n", admin->sock);
1257 len = write(admin->sock, ((unsigned char *)(admin->response->am))+admin->response->offset, sizeof(struct admin_message)*(admin->response->num)-admin->response->offset);
1259 if (errno != EWOULDBLOCK) {
1268 if (len < (int)(sizeof(struct admin_message)*(admin->response->num) - admin->response->offset)) {
1269 admin->response->offset+=len;
1272 temp = admin->response;
1273 admin->response = admin->response->next;
1278 /* done with socket instance */
1280 adminp = &admin->next;
1281 admin = admin->next;