void EndpointAppPBX::action_init_efi(void) { // int language = e_ext.vbox_language; // struct route_param *rparam; struct lcr_msg *message; struct port_list *portlist = ea_endpoint->ep_portlist; /* if no caller id */ if (e_callerinfo.id[0] == '\0') { /* facility rejected */ message = message_create(ea_endpoint->ep_serial, portlist->port_id, EPOINT_TO_PORT, MESSAGE_DISCONNECT); message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message->param.disconnectinfo.cause = CAUSE_FACILITYREJECTED; message_put(message); logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); new_state(EPOINT_STATE_OUT_DISCONNECT); set_tone(portlist,"cause_22"); return; } /* connect */ new_state(EPOINT_STATE_CONNECT); /* initialize the vbox */ PDEBUG(DEBUG_EPOINT, "EPOINT(%d) initializing efi\n", ea_endpoint->ep_serial); e_efi_state = EFI_STATE_HELLO; set_tone_efi("hello"); e_efi_digit = 0; }
void message_put(donnee_t D, socket_t from) { char ack; struct sockaddr_in ident; socket_t new_from; envoyerTypeMessage(PUT, from); envoyerCle(D->cle, from); recevoirOctet(&ack, from); if (ack == 0) { #ifdef DEBUG_MESSAGE_CLIENT printf("message_put:serveur suivant\n"); #endif /* * On relance la fonction avec un nouveau serveur et une nouvelle socket */ recevoirSockAddr(&ident, from); message_disconnect(from); new_from = ___connect2server___(ident); envoyerOrigine(FROM_CLIENT, new_from); message_put(D, new_from); } else if (ack == 1) { /* * Le serveur a accepté la clé, il reçoit donc la donnée */ envoyerDonnee(D, from); #ifdef DEBUG_MESSAGE_CLIENT printf("message_put:\n"); #endif } }
sd_close() { if (msgtask) { if (sd_server) { if (sd_width != 80) sd_screen_80(); message_put(sd_server, TTYServerCloseEvent, 0, 0); } message_close(); } sd_server = 0; /* mark as closed */ return 0; }
/* * set the given vbox-tone with full path (without appending) * the tone is played and after eof, a message is received */ void EndpointAppPBX::set_tone_efi(const char *tone) { struct lcr_msg *message; if (tone == NULL) tone = ""; if (!ea_endpoint->ep_portlist) { PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial); } message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE); SCPY(message->param.tone.dir, (char *)"tones_efi"); SCPY(message->param.tone.name, tone); message_put(message); PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set tone '%s'\n", ea_endpoint->ep_serial, e_ext.number, tone); }
/* send play message to all members to play join/release jingle */ void JoinPBX::play_jingle(int in) { struct join_relation *relation; struct lcr_msg *message; relation = j_relation; if (!relation) return; if (!relation->next) return; while(relation) { message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE); SCPY(message->param.tone.name, (char *)((in)?"joined":"left")); message_put(message); relation = relation->next; } }
int main(void) { socket_link_t *link; message_queue_t *send_queue; message_queue_t *receive_queue; link_manager_t *manager; void *data; int size; int priority; printf("starting client\n"); link = new_link_client("127.0.0.1", 2210); if (link == NULL) goto error; send_queue = new_message_queue(); if (send_queue == NULL) goto error; receive_queue = new_message_queue(); if (receive_queue == NULL) goto error; manager = create_link_manager(send_queue, receive_queue, link); if (manager == NULL) goto error; if (message_get(receive_queue, &data, &size, &priority)) goto error; printf("received message:\n"); printf(" data: %s\n", (char *)data); printf(" size: %d\n", size); printf(" priority: %d\n", priority); data = strdup("world"); if (data == NULL) goto error; if (message_put(send_queue, data, 6, 200)) goto error; /* let's wait for the message to be sent (unreliable sleep, but does it for the test) */ sleep(1); printf("client ends\n"); return 0; error: printf("there was an error\n"); return 1; }
int main(void) { socket_link_t *link; message_queue_t *send_queue; message_queue_t *receive_queue; link_manager_t *manager; void *data; int size; int priority; printf("starting server\n"); link = new_link_server(2210); if (link == NULL) goto error; send_queue = new_message_queue(); if (send_queue == NULL) goto error; receive_queue = new_message_queue(); if (receive_queue == NULL) goto error; manager = create_link_manager(send_queue, receive_queue, link); if (manager == NULL) goto error; data = strdup("hello"); if (data == NULL) goto error; if (message_put(send_queue, data, 6, 100)) goto error; if (message_get(receive_queue, &data, &size, &priority)) goto error; printf("received message:\n"); printf(" data: %s\n", (char *)data); printf(" size: %d\n", size); printf(" priority: %d\n", priority); printf("server ends\n"); return 0; error: printf("there was an error\n"); return 1; }
/* * setup to exactly one endpoint * if it fails, the calling endpoint is released. * if other outgoing endpoints already exists, they are release as well. * note: if this functions fails, it will destroy its own join object! */ int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber, char *newkeypad) { struct join_relation *relation; struct lcr_msg *message; class Endpoint *epoint; PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n"); /* create a new relation */ if (!(relation=add_relation())) FATAL("No memory for relation.\n"); relation->type = RELATION_TYPE_SETUP; relation->channel_state = 0; /* audio is assumed on a new join */ relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */ relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */ /* create a new endpoint */ epoint = new Endpoint(0, j_serial); if (!epoint) FATAL("No memory for Endpoint instance\n"); epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing relation->epoint_id = epoint->ep_serial; /* send setup message to new endpoint */ //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial)); //i if (options.deb & DEBUG_JOIN) // joinpbx_debug(join, "Join::message_epoint"); message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); if (newnumber) SCPY(message->param.setup.dialinginfo.id, newnumber); else message->param.setup.dialinginfo.id[0] = '\0'; if (newkeypad) SCPY(message->param.setup.dialinginfo.keypad, newkeypad); else message->param.setup.dialinginfo.keypad[0] = '\0'; PDEBUG(DEBUG_JOIN, "setup message sent to ep %d with number='%s' keypad='%s'.\n", relation->epoint_id, message->param.setup.dialinginfo.id, message->param.setup.dialinginfo.keypad); message_put(message); return(0); }
void JoinRemote::message_remote(int message_type, union parameter *param) { struct lcr_msg *message; PDEBUG(DEBUG_JOIN, "Message %d of endpoint %d from remote to LCR (ref=%d)\n", message_type, j_epoint_id, j_remote_ref); /* create relation if no relation exists */ if (!j_epoint_id) { class Endpoint *epoint; if (!(epoint = new Endpoint(0, j_serial))) FATAL("No memory for Endpoint instance\n"); j_epoint_id = epoint->ep_serial; PDEBUG(DEBUG_JOIN, "Created endpoint %d\n", j_epoint_id); epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing } #ifdef WITH_MISDN /* set serial on bchannel message * also ref is given, so we send message with ref */ if (message_type == MESSAGE_BCHANNEL) { message_bchannel_from_remote(this, param->bchannel.type, param->bchannel.handle); return; } #endif /* cannot just forward, because param is not of container "struct lcr_msg" */ message = message_create(j_serial, j_epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(message->param)); message_put(message); if (message_type == MESSAGE_RELEASE) { delete this; return; } }
/* that thread receives messages from the link and puts them in the queue */ static void *link_manager_receiver_thread(void *_manager) { link_manager_t *manager = _manager; void *data; int size; LOG_D(MAC, "starting link manager receiver thread\n"); while (manager->run) { if (link_receive_packet(manager->socket_link, &data, &size)) goto error; /* todo: priority */ if (message_put(manager->receive_queue, data, size, 0)) goto error; } LOG_D(MAC, "link manager receiver thread quits\n"); return NULL; error: LOG_E(MAC, "%s: error\n", __FUNCTION__); return NULL; }
/* epoint sends a message to a join * */ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param) { class Join *cl; struct join_relation *relation, *reltemp; int num; int new_state; struct lcr_msg *message; // int size, writesize, oldpointer; char *number, *numbers; if (!epoint_id) { PERROR("software error, epoint == NULL\n"); return; } // if (options.deb & DEBUG_JOIN) { // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial); // joinpbx_debug(join,"Join::message_epoint"); // } if (options.deb & DEBUG_JOIN) { if (message_type) { cl = join_first; while(cl) { if (cl->j_type == JOIN_TYPE_PBX) joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}"); cl = cl->next; } } } /* check relation */ relation = j_relation; while(relation) { if (relation->epoint_id == epoint_id) break; relation = relation->next; } if (!relation) { PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id); return; } /* count relations */ num=joinpbx_countrelations(j_serial); /* process party line */ if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) { j_partyline = param->setup.partyline; j_partyline_jingle = param->setup.partyline_jingle; } if (j_partyline) { switch(message_type) { case MESSAGE_SETUP: PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n"); relation->type = RELATION_TYPE_CONNECT; message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT); SPRINT(message->param.connectinfo.id, "%d", j_partyline); message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN; message_put(message); trigger_work(&j_updatebridge); if (j_partyline_jingle) play_jingle(1); break; case MESSAGE_AUDIOPATH: PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath); if (relation->channel_state != param->audiopath) { relation->channel_state = param->audiopath; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new channel state}"); } break; /* track notify */ case MESSAGE_NOTIFY: switch(param->notifyinfo.notify) { case INFO_NOTIFY_USER_SUSPENDED: case INFO_NOTIFY_USER_RESUMED: case INFO_NOTIFY_REMOTE_HOLD: case INFO_NOTIFY_REMOTE_RETRIEVAL: case INFO_NOTIFY_CONFERENCE_ESTABLISHED: case INFO_NOTIFY_CONFERENCE_DISCONNECTED: new_state = track_notify(relation->rx_state, param->notifyinfo.notify); if (new_state != relation->rx_state) { relation->rx_state = new_state; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new rx state}"); } break; } break; case MESSAGE_DISCONNECT: PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n"); message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = CAUSE_NORMAL; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); // fall through case MESSAGE_RELEASE: PDEBUG(DEBUG_JOIN, "releasing from join\n"); release(relation, 0, 0); if (j_partyline_jingle) play_jingle(0); break; default: PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n"); } return; } /* process messages */ switch(message_type) { /* process audio path message */ case MESSAGE_AUDIOPATH: PDEBUG(DEBUG_JOIN, "join received channel message: audiopath=%d, current relation's channel_state=%d\n", param->audiopath, relation->channel_state); if (relation->channel_state != param->audiopath) { relation->channel_state = param->audiopath; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new channel state}"); } return; /* track notify */ case MESSAGE_NOTIFY: switch(param->notifyinfo.notify) { case INFO_NOTIFY_USER_SUSPENDED: case INFO_NOTIFY_USER_RESUMED: case INFO_NOTIFY_REMOTE_HOLD: case INFO_NOTIFY_REMOTE_RETRIEVAL: case INFO_NOTIFY_CONFERENCE_ESTABLISHED: case INFO_NOTIFY_CONFERENCE_DISCONNECTED: new_state = track_notify(relation->rx_state, param->notifyinfo.notify); if (new_state != relation->rx_state) { relation->rx_state = new_state; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new rx state}"); } break; default: /* send notification to all other endpoints */ reltemp = j_relation; while(reltemp) { if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) { message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); } reltemp = reltemp->next; } } return; /* relations sends a connect */ case MESSAGE_CONNECT: /* outgoing setup type becomes connected */ if (relation->type == RELATION_TYPE_SETUP) relation->type = RELATION_TYPE_CONNECT; /* release other relations in setup state */ release_again: reltemp = j_relation; while(reltemp) { //printf("connect, checking relation %d\n", reltemp->epoint_id); if (reltemp->type == RELATION_TYPE_SETUP) { //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id); /* send release to endpoint */ message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = CAUSE_NONSELECTED; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards. return; // must return, because join IS destroyed goto release_again; } if (reltemp->type == RELATION_TYPE_CALLING) reltemp->type = RELATION_TYPE_CONNECT; reltemp = reltemp->next; } break; // continue with our message /* release is sent by endpoint */ case MESSAGE_RELEASE: switch(relation->type) { case RELATION_TYPE_SETUP: /* by called */ /* collect cause and send collected cause */ collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location); if (j_multicause) release(relation, j_multilocation, j_multicause); else release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED); break; case RELATION_TYPE_CALLING: /* by calling */ /* remove us, if we don't have a called releation yet */ if (!j_relation->next) { release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL); return; // must return, because join IS destroyed } /* in a conf, we don't kill the other members */ if (num > 2 && !joinpbx_onecalling_othersetup(j_relation)) { release(relation, 0, 0); return; } /* remove all relations that are of called type */ release_again2: reltemp = j_relation; while(reltemp) { if (reltemp->type == RELATION_TYPE_SETUP) { /* send release to endpoint */ message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) return; // must return, because join IS destroyed goto release_again2; } reltemp = reltemp->next; } PERROR("we are still here, this should not happen\n"); break; default: /* by connected */ /* send current cause */ release(relation, param->disconnectinfo.location, param->disconnectinfo.cause); } return; // must return, because join may be destroyed } /* check number of relations */ if (num > 2 && !joinpbx_onecalling_othersetup(j_relation) && message_type != MESSAGE_CONNECT) { PDEBUG(DEBUG_JOIN, "we are in a conference, so we ignore the messages, except MESSAGE_CONNECT.\n"); return; } /* if join has no other relation, we process the setup message */ if (num == 1) { switch(message_type) { case MESSAGE_SETUP: if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) { /* in case of keypad */ numbers = param->setup.dialinginfo.keypad; if (numbers[0]) { while((number = strsep(&numbers, ","))) { if (out_setup(epoint_id, message_type, param, NULL, number)) return; // join destroyed } /* after keypad finish dialing */ break; } /* dialed number */ numbers = param->setup.dialinginfo.id; while((number = strsep(&numbers, ","))) { if (out_setup(epoint_id, message_type, param, number, NULL)) return; // join destroyed } break; } if (out_setup(epoint_id, message_type, param, param->setup.dialinginfo.id, param->setup.dialinginfo.keypad)) return; // join destroyed break; default: PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n"); } } else { /* sending message to other relation(s) */ relation = j_relation; while(relation) { if (relation->epoint_id != epoint_id) { PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id); message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); PDEBUG(DEBUG_JOIN, "message sent.\n"); } relation = relation->next; } } }
/* release join from endpoint * if the join has two relations, all relations are freed and the join will be * destroyed * on outgoing relations, the cause is collected, if not connected * returns if join has been destroyed */ int JoinPBX::release(struct join_relation *relation, int location, int cause) { struct join_relation *reltemp, **relationpointer; struct lcr_msg *message; class Join *join; int destroy = 0; /* remove from bridge */ if (relation->channel_state != 0) { relation->channel_state = 0; trigger_work(&j_updatebridge); // note: if join is not released, bridge must be updated } /* detach given interface */ reltemp = j_relation; relationpointer = &j_relation; while(reltemp) { /* endpoint of function call */ if (relation == reltemp) break; relationpointer = &reltemp->next; reltemp = reltemp->next; } if (!reltemp) FATAL("relation not in list of our relations. this must not happen.\n"); //printf("releasing relation %d\n", reltemp->epoint_id); *relationpointer = reltemp->next; FREE(reltemp, sizeof(struct join_relation)); cmemuse--; relation = reltemp = NULL; // just in case of reuse fault; /* if no more relation */ if (!j_relation) { PDEBUG(DEBUG_JOIN, "join is completely removed.\n"); /* there is no more endpoint related to the join */ destroy = 1; delete this; // end of join object! PDEBUG(DEBUG_JOIN, "join completely removed!\n"); } else /* if join is a party line */ if (j_partyline) { PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n"); } else /* if only one relation left */ if (!j_relation->next) { PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause); message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = cause; message->param.disconnectinfo.location = location; message_put(message); destroy = 1; delete this; // end of join object! PDEBUG(DEBUG_JOIN, "join completely removed!\n"); } join = join_first; while(join) { if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX) joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}"); join = join->next; } PDEBUG(DEBUG_JOIN, "join_release(): ended.\n"); return(destroy); }
void JoinPBX::bridge(void) { struct join_relation *relation; struct lcr_msg *message; int numconnect = 0, relations = 0; class Endpoint *epoint; struct port_list *portlist; class Port *port; unsigned int bridge_id; class Join *join_3pty; class JoinPBX *joinpbx_3pty; #ifdef DEBUG_COREBRIDGE int allmISDN = 0; // never set for debug purpose #else int allmISDN = 1; // set until a non-mISDN relation is found #endif /* bridge id is the serial of join * if we have a 3pty with another join, we always use the lowest brigde id. * this way we use common ids, so both joins share same bridge */ if (j_3pty && j_3pty < j_serial) bridge_id = j_3pty; else bridge_id = j_serial; relation = j_relation; while(relation) { /* count all relations */ relations++; /* check for relation's objects */ epoint = find_epoint_id(relation->epoint_id); if (!epoint) { PERROR("software error: relation without existing endpoints.\n"); relation = relation->next; continue; } portlist = epoint->ep_portlist; if (!portlist) { PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial); //#warning testing: keep on hold until single audio stream available relation->channel_state = 0; relation = relation->next; continue; } if (portlist->next) { PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial); //#warning testing: keep on hold until single audio stream available relation->channel_state = 0; relation = relation->next; continue; } port = find_port_id(portlist->port_id); if (!port) { PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial); relation = relation->next; continue; } if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) { PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial); if (allmISDN) { PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial); allmISDN = 0; } relation = relation->next; continue; } relation = relation->next; } /* check if 3pty members have no mISDN, so bridging via mISDN/lcr will be selected correctly */ join_3pty = find_join_id(j_3pty); if (join_3pty && join_3pty->j_type == JOIN_TYPE_PBX) { joinpbx_3pty = (class JoinPBX *)join_3pty; relation = joinpbx_3pty->j_relation; while(relation) { #if 0 no need to count, because j_3pty is taken into account below when checking relations /* count all relations */ relations++; #endif /* check for relation's objects */ epoint = find_epoint_id(relation->epoint_id); if (!epoint) { PERROR("software error: relation without existing endpoints.\n"); relation = relation->next; continue; } portlist = epoint->ep_portlist; if (!portlist) { PDEBUG(DEBUG_JOIN, "other 3pty join %d: ignoring relation without port object.\n", joinpbx_3pty->j_serial); //#warning testing: keep on hold until single audio stream available relation->channel_state = 0; relation = relation->next; continue; } if (portlist->next) { PDEBUG(DEBUG_JOIN, "other 3pty join %d: ignoring relation with ep%d due to port_list.\n", joinpbx_3pty->j_serial, epoint->ep_serial); //#warning testing: keep on hold until single audio stream available relation->channel_state = 0; relation = relation->next; continue; } port = find_port_id(portlist->port_id); if (!port) { PDEBUG(DEBUG_JOIN, "other 3pty join %d: ignoring relation without existing port object.\n", joinpbx_3pty->j_serial); relation = relation->next; continue; } if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) { PDEBUG(DEBUG_JOIN, "other 3pty join %d: ignoring relation ep%d because it's port is not mISDN.\n", joinpbx_3pty->j_serial, epoint->ep_serial); if (allmISDN) { PDEBUG(DEBUG_JOIN, "other 3pty join %d: not all endpoints are mISDN.\n", joinpbx_3pty->j_serial); allmISDN = 0; } relation = relation->next; continue; } relation = relation->next; } } PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)"); /* we notify all relations about rxdata. */ relation = j_relation; while(relation) { /* count connected relations */ if ((relation->channel_state == 1) && (relation->rx_state != NOTIFY_STATE_SUSPEND) && (relation->rx_state != NOTIFY_STATE_HOLD)) numconnect ++; /* remove unconnected parties from conference, also remove remotely disconnected parties so conference will not be disturbed. */ /* mISDN */ if (relation->channel_state == 1 && relation->rx_state != NOTIFY_STATE_HOLD && relation->rx_state != NOTIFY_STATE_SUSPEND && relations>1 // no conf with one member && allmISDN) { // no conf if any member is not mISDN message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL); message->param.mISDNsignal.message = mISDNSIGNAL_CONF; message->param.mISDNsignal.conf = (bridge_id << 16) | j_pid; PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf); message_put(message); } else { message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL); message->param.mISDNsignal.message = mISDNSIGNAL_CONF; message->param.mISDNsignal.conf = 0; PDEBUG(DEBUG_JOIN, "join%d EP%d +off+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf); message_put(message); } /* core bridge */ if (relation->channel_state == 1 && relation->rx_state != NOTIFY_STATE_HOLD && relation->rx_state != NOTIFY_STATE_SUSPEND && relations>1 // no bridge with one member && !allmISDN) { // no bridge if all members are mISDN message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_BRIDGE); message->param.bridge_id = bridge_id; PDEBUG(DEBUG_JOIN, "join%u EP%u requests bridge=%u\n", j_serial, relation->epoint_id, bridge_id); message_put(message); } else { message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_BRIDGE); message->param.bridge_id = 0; PDEBUG(DEBUG_JOIN, "join%u EP%u drop bridge=%u\n", j_serial, relation->epoint_id, bridge_id); message_put(message); } relation = relation->next; } /* two people just exchange their states */ if (!j_3pty && relations==2 && !j_partyline) { PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial); relation = j_relation; relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state); relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state); } else /* one member in a join, so we put her on hold */ if (!j_3pty && (relations==1 || numconnect==1)/* && !j_partyline_jingle*/) { PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial); relation = j_relation; while(relation) { if ((relation->channel_state == 1) && (relation->rx_state != NOTIFY_STATE_SUSPEND) && (relation->rx_state != NOTIFY_STATE_HOLD)) relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD); relation = relation->next; } } else { /* if conference/partyline (or more than two members and more than one is connected), so we set conference state */ PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect); relation = j_relation; while(relation) { if ((relation->channel_state == 1) && (relation->rx_state != NOTIFY_STATE_SUSPEND) && (relation->rx_state != NOTIFY_STATE_HOLD)) relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_CONFERENCE); relation = relation->next; } } }
/* notify endpoint about state change (if any) */ static int notify_state_change(int join_id, int epoint_id, int old_state, int new_state) { int notify_off = 0, notify_on = 0; struct lcr_msg *message; if (old_state == new_state) return(old_state); switch(old_state) { case NOTIFY_STATE_ACTIVE: switch(new_state) { case NOTIFY_STATE_HOLD: notify_on = INFO_NOTIFY_REMOTE_HOLD; break; case NOTIFY_STATE_SUSPEND: notify_on = INFO_NOTIFY_USER_SUSPENDED; break; case NOTIFY_STATE_CONFERENCE: notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED; break; } break; case NOTIFY_STATE_HOLD: switch(new_state) { case NOTIFY_STATE_ACTIVE: notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL; break; case NOTIFY_STATE_SUSPEND: notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL; notify_on = INFO_NOTIFY_USER_SUSPENDED; break; case NOTIFY_STATE_CONFERENCE: notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL; notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED; break; } break; case NOTIFY_STATE_SUSPEND: switch(new_state) { case NOTIFY_STATE_ACTIVE: notify_off = INFO_NOTIFY_USER_RESUMED; break; case NOTIFY_STATE_HOLD: notify_off = INFO_NOTIFY_USER_RESUMED; notify_on = INFO_NOTIFY_REMOTE_HOLD; break; case NOTIFY_STATE_CONFERENCE: notify_off = INFO_NOTIFY_USER_RESUMED; notify_on = INFO_NOTIFY_CONFERENCE_ESTABLISHED; break; } break; case NOTIFY_STATE_CONFERENCE: switch(new_state) { case NOTIFY_STATE_ACTIVE: notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED; break; case NOTIFY_STATE_HOLD: notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED; notify_on = INFO_NOTIFY_REMOTE_HOLD; break; case NOTIFY_STATE_SUSPEND: notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED; notify_on = INFO_NOTIFY_USER_SUSPENDED; break; } break; } if (join_id && notify_off) { message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY); message->param.notifyinfo.notify = notify_off; message_put(message); } if (join_id && notify_on) { message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY); message->param.notifyinfo.notify = notify_on; message_put(message); } return(new_state); }
/* ** zero current counts */ zero_current() { struct zone_item *z = 0; unsigned short int i = 0; char text[80], datemsg[20]; picker_item picker; picker_order_item picker_order; section_prod_log_item splog; unsigned long int now = 0L; time_t * nowptr = 0; TZone zone_num = 0; datemsg[19] = '\0'; text[79] = '\0'; memset(&splog, 0x0, sizeof(section_prod_log_item)); /* ** zero the total configured time values */ if (!zero_pa_file()) return; /* ** clear out all picker records */ begin_work(); while ( picker_next( &picker, LOCK ) == 0 ) { picker.p_zone = 0; picker.p_status = 0; picker.p_cur_order_count = 0; picker.p_cur_lines = 0; picker.p_cur_units = 0; picker.p_cur_time = 0; picker.p_cum_order_count = 0; picker.p_cum_lines = 0; picker.p_cum_units = 0; picker.p_cum_time = 0; picker_update( &picker ); commit_work(); begin_work(); } commit_work(); /* ** clear out all picker_order records */ begin_work(); while ( !picker_order_next( &picker_order, LOCK )) { if (picker_order.p_completion_time) { if (picker_order.p_order_status & PA_CURRENT) { picker_order.p_order_status ^= (PA_CURRENT); picker_order_update( &picker_order ); } } commit_work(); begin_work(); } commit_work(); sprintf(text, "dbaccess caps sql/copy_section_prod.sql %s", "1>/dev/null 2>&1"); system(text); nowptr = (time_t *)&now; strftime(datemsg, 20, "%Y-%m-%d %T", localtime(nowptr)); strcpy(splog.spl_record_date, datemsg); sprintf(text, "dbaccess caps src/h/informix/section_prod.sql %s", "1>/dev/null 2>&1"); system(text); for (i = 0; i <= coh->co_zone_cnt; i++) { z = &zone[i]; zone_num = z->zt_zone; z->zt_picker = 0; memset(z->zt_picker_name, 0, 12); z->zt_picker_name[11] = '\0'; message_put(0, ZoneOfflineRequest, &zone_num, sizeof(TZone)); } eh_post(ERR_CONFIRM, "Zero current counts"); }
main() { short rm; short ret; unsigned char t; char buf[NUM_PROMPTS][BUF_SIZE]; /* array of buffers */ short i; short n; putenv("_=printer_control"); chdir(getenv("HOME")); open_all(); while(1) /* begin massive loop */ { fix(berkeley_control); sd_screen_off(); sd_clear_screen(); /* clear screen */ sd_text(berkeley_control); sd_screen_on(); /* clear input buffers */ for(i = 0; i < NUM_PROMPTS; i++) for(n = 0; n < BUF_SIZE; n++) buf[i][n] = 0; /* main loop to get code */ while(1) { t = sd_input(&fld[0],sd_prompt(&fld[0],0),&rm,buf[0],0); if (t == EXIT) leave(); if (t == UP_CURSOR) continue; *buf[0] = tolower(*buf[0]); if (*buf[0] == 'a' || *buf[0] == 'c' || *buf[0] == 'k' || *buf[0] == 's' || *buf[0] == 'r' || *buf[0] == 'd') break; eh_post(ERR_CODE, buf[0]); } if (*buf[0] == 'c') { t = sd_input(&fld1, sd_prompt(&fld1, 0), 0, op_printer, 0); if (t == EXIT) leave(); if (t == UP_CURSOR) continue; message_put(sd_server, ChangePrinterEvent, op_printer, strlen(op_printer)); sprintf(printer, "PRINTER=%s", op_printer); putenv(printer); continue; } /* code entered. display second prompt */ if(buf[0][0] != 'd') /* not display */ { while (*buf[0] == 'k') { sd_prompt(&fld[1],0); t = sd_input(&fld[1],0,&rm,buf[1],0); if(t == EXIT) leave(); else if(t == RETURN) break; } switch(buf[0][0]) { case 'a': /* abort current print job */ sd_wait(); sd_cursor(0, 18, 27); sd_text("."); sprintf(command, "cancel %s", op_printer); system(command); sleep(2); break; case 'k': /* kill print file */ sd_wait(); sd_cursor(0, 18, 27); sd_text("."); sprintf(command, "cancel %s-%s", op_printer, buf[1]); system(command); sleep(2); break; case 's': /* stop print file */ sd_wait(); sd_cursor(0, 18, 27); sd_text("."); sprintf(command, "disable %s", op_printer); system(command); sleep(2); break; case 'r': /* restart printing */ sd_wait(); sd_cursor(0, 18, 27); sd_text("."); sprintf(command, "enable %s", op_printer); system(command); sleep(2); break; } continue; } else /* display request */ { sd_cursor(0,16,2); sd_text("Job ID Operator Size Date"); } /* * Get Printer Queue Data */ tmp_name(tname); /* get temp name */ sprintf(command, "lpstat -o %s >%s", op_printer, tname); system(command); t_fd = fopen(tname, "r"); if (t_fd == 0) continue; /* open failed */ memset(x, 0, sizeof(x)); for (max = 0; max < 25; max++) { if (!fgets(x[max], 80, t_fd)) break; n = strlen(x[max]) - 1; x[max][n] = 0; } n = 0; fclose(t_fd); unlink(tname); while(1) { sd_cursor(0, 17, 1); sd_clear_rest(); for (i = 0; i < 5 && n + i < max; i++) { sd_cursor(0, 17 + i, 2); sd_text(x[i + n]); } sd_cursor(0,23,23); sd_text("(Exit, Forward, or Backward)"); sd_prompt(&fld[2],0); t = sd_input(&fld[2],0,&rm,buf[2],0); ret = sd_more(t, code_to_caps(buf[2][0])); /* F041897 */ if (ret == 0) leave(); /* exit */ else if (ret == 1) /* forward */ { if (n + 5 < max) n += 5; } else if (ret == 2) /* backward */ { if (n > 0) n -= 5; } else if (ret == 3) break; /* quit display */ } } /* end massive while(1)loop */ }