void Mapping::sort_as(const Mapping & map) { object_list_type n; std::set<Object> t_set(this->_lst.begin(), this->_lst.end()); for(object_list_type::const_iterator i = map._lst.begin(); i != map._lst.end(); ++i) { if(t_set.find(*i) != t_set.end()) { n.push_back(*i); } } std::set<Object> o_set(n.begin(), n.end()); for(object_list_type::const_iterator i = this->_lst.begin(); i != this->_lst.end(); ++i) { if(o_set.find(*i) == o_set.end()) { n.push_back(*i); } else { // key is also in "map" Object & tv = this->at(*i); const Object & ov = map.at(*i); if(tv.is<Mapping>() && ov.is<Mapping>()) { Mapping & tm = reinterpret_cast<Mapping &>(tv.get_object()); const Mapping & om = reinterpret_cast<const Mapping &>(ov.get_object()); tm.sort_as(om); } } } if(this->_lst.size() != n.size()) { std::cerr << "internal error" << std::endl; std::cerr << "this->_lst: " << this->_lst.size() << std::endl; for(object_list_type::const_iterator i = this->_lst.begin(); i != this->_lst.end(); ++i) { std::cerr << " " << i->repr() << std::endl; } std::cerr << "n: " << n.size() << std::endl; for(object_list_type::const_iterator i = n.begin(); i != n.end(); ++i) { std::cerr << " " << i->repr() << std::endl; } std::cout << this->_lst.size() << " " << n.size() << std::endl; throw InternalError(DEBUG_INFO, "key sorting was not successful"); assert(false); } this->_lst = n; }
static int modem_stat(char *cmd, slist_t *oks, slist_t *ers,int timeout, char *stat, size_t stat_len) { char buf[MAX_STRING];int rc; slist_t *cs;time_t t1=t_set(timeout); DEBUG(('M',4,"modem_stat: cmd=\"%s\" timeout=%d",cmd,timeout)); rc=modem_sendstr(cmd); if(rc!=1) { if(stat) xstrcpy(stat, "FAILURE", stat_len); DEBUG(('M',3,"modem_stat: modem_sendstr failed, rc=%d",rc)); return MC_FAIL; } if(!oks && !ers) return MC_OK; rc=OK; while(ISTO(rc) && !t_exp(t1)) { rc=tty_gets(buf, MAX_STRING-1, t_rest(t1)); if(!*buf) continue; if(rc!=OK) { if(stat) xstrcat(stat, "FAILURE", stat_len); DEBUG(('M',3,"modem_stat: tty_gets failed")); return MC_FAIL; } for(cs=oks;cs;cs=cs->next) if(!strncmp(buf, cs->str, strlen(cs->str))) { if(stat) xstrcat(stat, buf, stat_len); return MC_OK; } for(cs=ers;cs;cs=cs->next) if(!strncmp(buf, cs->str, strlen(cs->str))) { if(stat) xstrcat(stat, buf, stat_len); return MC_ERROR; } if(stat) { xstrcat(stat,buf,stat_len); xstrcat(stat,"\n",stat_len); } } if(stat) { if (ISTO(rc)) xstrcat(stat, "TIMEOUT", stat_len); else xstrcat(stat, "FAILURE", stat_len); } return MC_FAIL; }
int hangup() { slist_t *hc; int rc=MC_FAIL,to=t_set(cfgi(CFG_WAITRESET)); if(!cfgsl(CFG_MODEMHANGUP))return MC_OK; write_log("hanging up..."); while(rc!=MC_OK&&!t_exp(to)) { for(hc=cfgsl(CFG_MODEMHANGUP);hc;hc=hc->next) { rc=modem_chat(hc->str,cfgsl(CFG_MODEMOK),cfgsl(CFG_MODEMNODIAL), cfgsl(CFG_MODEMERROR),cfgsl(CFG_MODEMBUSY), cfgs(CFG_MODEMRINGING),cfgi(CFG_MAXRINGS), t_rest(to),NULL,0); } if(rc!=MC_OK)sleep(1); tty_purge(); rc=alive(); tty_purge(); } #ifdef NEED_DEBUG if(rc!=MC_OK)DEBUG(('M',3,"hangup: failed, rc=%d [%s]",rc,mcs[rc])); #endif return rc; }
int modem_chat(char *cmd, slist_t *oks, slist_t *nds, slist_t *ers, slist_t *bys, char *ringing, int maxr, int timeout, char *rest, size_t restlen) { char buf[MAX_STRING]; int rc,nrng=0; slist_t *cs; time_t t1; calling=1; DEBUG(('M',4,"modem_chat: cmd=\"%s\" timeout=%d",cmd,timeout)); rc=modem_sendstr(cmd); if(rc!=1) { if(rest) xstrcpy(rest, "FAILURE", restlen); DEBUG(('M',3,"modem_chat: modem_sendstr failed, rc=%d",rc)); return MC_FAIL; } if(!oks && !ers && !bys) return MC_OK; rc=OK; t1=t_set(timeout); while(ISTO(rc) && !t_exp(t1) && (!maxr || nrng<maxr)) { getevt(); rc=tty_gets(buf, MAX_STRING-1, t_rest(t1)); if(rc==RCDO) { if(rest)xstrcpy(rest,"HANGUP",restlen); return MC_BUSY; } if(rc!=OK) { if(rest) xstrcpy(rest, "FAILURE", restlen); DEBUG(('M',3,"modem_chat: tty_gets failed, rc=%d",rc)); return MC_FAIL; } if(!*buf)continue; for(cs=oks;cs;cs=cs->next) if(!strncmp(buf,cs->str,strlen(cs->str))) { if(rest)xstrcpy(rest,buf,restlen); return MC_OK; } for(cs=ers;cs;cs=cs->next) if(!strncmp(buf,cs->str,strlen(cs->str))) { if(rest)xstrcpy(rest,buf,restlen); return MC_ERROR; } if(ringing&&!strncmp(buf,ringing,strlen(ringing))) { if(!nrng&&strlen(ringing)==4) { if(rest)xstrcpy(rest,buf,restlen); return MC_RING; } nrng++; continue; } for(cs=nds;cs;cs=cs->next) if(!strncmp(buf,cs->str,strlen(cs->str))) { if(rest)xstrcpy(rest,buf,restlen); return MC_NODIAL; } for(cs=bys;cs;cs=cs->next) if(!strncmp(buf,cs->str,strlen(cs->str))) { if(rest)xstrcpy(rest,buf,restlen); return MC_BUSY; } } if(rest) { if(nrng && maxr && nrng>=maxr) snprintf(rest, restlen, "%d RINGINGs", nrng); else if(ISTO(rc)) xstrcpy(rest, "TIMEOUT", restlen); else xstrcpy(rest, "FAILURE", restlen); } return MC_FAIL; }
static void answer_mode(int type) { int rc, spd;char *cs; struct sockaddr_in sa; socklen_t ss=sizeof(sa); sts_t sts; if(cfgs(CFG_ROOTDIR)&&ccs[0])chdir(ccs); rnode=xcalloc(1,sizeof(ninfo_t)); is_ip=!isatty(0); xstrcpy(ip_id,"ipline",10); rnode->tty=xstrdup(is_ip?(bink?"binkp":"tcpip"):basename(ttyname(0))); rnode->options|=O_INB; if(!log_init(cfgs(CFG_LOG),rnode->tty)) { printf("can't open log %s!\n",ccs); exit(S_FAILURE); } signal(SIGINT,SIG_IGN); signal(SIGTERM,sigerr); signal(SIGSEGV,sigerr); signal(SIGFPE,sigerr); signal(SIGPIPE,SIG_IGN); IFPerl(perl_init(cfgs(CFG_PERLFILE),0)); log_callback=NULL;xsend_cb=NULL; ssock=cls_conn(CLS_LINE,cfgs(CFG_SERVER),NULL); if(ssock<0)write_log("can't connect to server: %s",strerror(errno)); else log_callback=vlogs; rc=aso_init(cfgs(CFG_ASOOUTBOUND),cfgs(CFG_BSOOUTBOUND),cfgs(CFG_QSTOUTBOUND),cfgal(CFG_ADDRESS)->addr.z); if(!rc) { write_log("No outbound defined"); stopit(S_FAILURE); } write_log("answering incoming call");vidle(); if(is_ip&&!getpeername(0,(struct sockaddr*)&sa,&ss)) { write_log("remote is %s",inet_ntoa(sa.sin_addr)); spd=TCP_SPEED; } else { cs=getenv("CONNECT");spd=cs?atoi(cs):0; xfree(connstr);connstr=xstrdup(cs); if(cs&&spd)write_log("*** CONNECT %s",cs); else { write_log("*** CONNECT Unknown"); spd=DEFAULT_SPEED; } } if((cs=getenv("CALLER_ID"))&&strcasecmp(cs,"none")&&strlen(cs)>3)write_log("caller-id: %s",cs); tty_setattr(0); tty_local(0); rc=session(0,type,NULL,spd); tty_local(1); if(!is_ip) { hangup(); stat_collect(); } tty_cooked(); if((S_OK==(rc&S_MASK))&&cfgi(CFG_HOLDONSUCCESS)) { log_done(); log_init(cfgs(CFG_MASTERLOG),NULL); aso_getstatus(&rnode->addrs->addr, &sts); sts.flags|=(Q_WAITA|Q_WAITR|Q_WAITX); sts.htime=MAX(t_set(cci*60),sts.htime); write_log("calls to %s delayed for %d min after successful incoming session", ftnaddrtoa(&rnode->addrs->addr),cci); aso_setstatus(&rnode->addrs->addr,&sts); log_done(); log_init(cfgs(CFG_LOG),rnode->tty); } title("Waiting..."); vidle();sline(""); aso_done(); stopit(rc); }