static void service_network() { struct iax_event *e = 0; int callNo; struct iaxc_registration *reg; while ( (e = iax_get_event(0)) ) { #ifdef WIN32 iaxc_millisleep(0); //fd: #endif // first, see if this is an event for one of our calls. callNo = iaxc_find_call_by_session(e->session); if ( e->etype == IAX_EVENT_NULL ) { // Should we do something here? // Right now we do nothing, just go with the flow // and let the event be deallocated. } else if ( callNo >= 0 ) { iaxc_handle_network_event(e, callNo); } else if ( (reg = iaxc_find_registration_by_session(e->session)) != NULL ) { iaxc_handle_regreply(e,reg); } else if ( e->etype == IAX_EVENT_REGACK || e->etype == IAX_EVENT_REGREJ ) { iaxci_usermsg(IAXC_ERROR, "Unexpected registration reply"); } else if ( e->etype == IAX_EVENT_REGREQ ) { iaxci_usermsg(IAXC_ERROR, "Registration requested by someone, but we don't understand!"); } else if ( e->etype == IAX_EVENT_CONNECT ) { iaxc_handle_connect(e); } else if ( e->etype == IAX_EVENT_TIMEOUT ) { iaxci_usermsg(IAXC_STATUS, "Timeout for a non-existant session. Dropping", e->etype); } else { iaxci_usermsg(IAXC_STATUS, "Event (type %d) for a non-existant session. Dropping", e->etype); } iax_event_free(e); } }
bool IAXVoIPLink::getEvent() { mutexIAX_.enter(); iax_event *event; while ((event = iax_get_event(0)) != NULL) { // If we received an 'ACK', libiax2 tells apps to ignore them. if (event->etype == IAX_EVENT_NULL) { iax_event_free(event); continue; } IAXCall *call = iaxFindCallBySession(event->session); if (call) { iaxHandleCallEvent(event, call); } else if (event->session && event->session == regSession_) { iaxHandleRegReply(event); // This is a registration session, deal with it } else // We've got an event before it's associated with any call iaxHandlePrecallEvent(event); iax_event_free(event); } mutexIAX_.leave(); if (nextRefreshStamp_ && nextRefreshStamp_ < time(NULL)) sendRegister(dynamic_cast<IAXAccount *>(Manager::instance().getAccount(accountID_))); sendAudioFromMic(); // thread wait 3 millisecond ost::Thread::sleep(3); return handlingEvents_; }
void do_iax_event(FILE *f) { int sessions = 0; struct iax_event *e = 0; struct peer *peer; while ( (e = iax_get_event(0))) { peer = find_peer(e->session); if(peer) { handle_event(f, e, peer); } else if (e->session == registry) { fprintf(stderr, "Registration complete: %s (%d)\n", (e->event.regreply.status == IAX_REG_SUCCESS) ? "Success" : "Failed", e->event.regreply.status); registry = NULL; } else { if(e->etype != IAX_EVENT_CONNECT) { fprintf(stderr, "Huh? This is an event for a non-existant session?\n"); continue; } sessions++; if(sessions >= MAX_SESSIONS) { fprintf(f, "Missed a call... too many sessions open.\n"); } if(e->event.connect.callerid && e->event.connect.dnid) fprintf(f, "Call from '%s' for '%s'", e->event.connect.callerid, e->event.connect.dnid); else if(e->event.connect.dnid) { fprintf(f, "Call from '%s'", e->event.connect.dnid); } else if(e->event.connect.callerid) { fprintf(f, "Call from '%s'", e->event.connect.callerid); } else printf("Call from"); fprintf(f, " (%s)\n", inet_ntoa(iax_get_peer_addr(e->session).sin_addr)); if(most_recent_answer) { fprintf(f, "Incoming call ignored, there's already a call waiting for answer... \ please accept or reject first\n"); iax_reject(e->session, "Too many calls, we're busy!"); } else { if ( !(peer = malloc(sizeof(struct peer)))) { fprintf(f, "Warning: Unable to allocate memory!\n"); return; } peer->time = time(0); peer->session = e->session; if (peer->gsmin) free(peer->gsmin); peer->gsmin = 0; if (peer->gsmout) free(peer->gsmout); peer->gsmout = 0; peer->next = peers; peers = peer; iax_accept(peer->session); iax_ring_announce(peer->session); most_recent_answer = peer; ringing = 1; gentone(TONE_RINGER, 0); fprintf(f, "Incoming call!\n"); } issue_prompt(f); } iax_event_free(e); }