void sendServerStatus(const char* modem, char* tag) { DIR* dirp; struct dirent* dentp; config deflt; char fifomatch[80]; int fifomatchlen; if (!(dirp = opendir("."))) { syslog(LOG_ERR, "%s: opendir: %m", SPOOLDIR); sendError("Problem accessing spool directory."); done(-1, "EXIT"); } /* * Setup a prefix for matching potential FIFO files. * We do this carefully and in a way that insures we * use only the definitions in config.h. */ if (strcmp(modem, MODEM_ANY) == 0) modem = ""; sprintf(fifomatch, "%s.%.*s", FAX_FIFO, sizeof (fifomatch) - (sizeof (FAX_FIFO)+2), modem); fifomatchlen = strlen(fifomatch); while ((dentp = readdir(dirp)) != 0) { int fifo; if (strncmp(dentp->d_name, fifomatch, fifomatchlen) != 0) continue; fifo = open(dentp->d_name, O_WRONLY|O_NDELAY); if (fifo != -1) { config configuration; char fileName[1024]; char* cp; (void) close(fifo); cp = strchr(dentp->d_name, '.') + 1; sprintf(fileName, "%s.%s", FAX_CONFIG, cp); getConfig(fileName, &configuration, &deflt); if (version > 0) { char serverStatus[1024]; char* tp; sprintf(fileName, "%s/%s", FAX_STATUSDIR, cp); getServerStatus(fileName, serverStatus); /* * Convert fifo name from canonical format back * to a pathname by replacing '_'s with '/'s. */ for (tp = cp; tp = strchr(tp, '_'); *tp = '/') ; sendClient("server", "%s:%s:%s", configuration.faxNumber, cp, serverStatus); } else sendClient("server", "%s", configuration.faxNumber); } } (void) closedir(dirp); }
static void reallyRemoveJob(const char* op, Job* job, const char* jobname) { char line[1024]; /* call it line to use isCmd() on it */ char* cp; char* tag; char* cmd; int fd; FILE* fp; fp = fopen((char*) job->qfile, "r+w"); if (fp == NULL) { syslog(LOG_ERR, "%s: cannot open %s (%m)", op, job->qfile); sendClient("openFailed", "%s", jobname); return; } fd = fileno(fp); /* * First ask server to do removal. If the job is being * processed, it will first be aborted. Otherwise, do * the cleanup here. */ cmd = (strcmp(op, "remove") == 0 ? "R" : "K"); if (notifyServer(job->modem, "%s%s", cmd, job->qfile)) { sendClient("removed", "%s", jobname); } else if (flock(fd, LOCK_EX|LOCK_NB) == 0) { while (fgets(line, sizeof (line) - 1, fp)) { if (line[0] == '#') continue; if (cp = strchr(line, '\n')) *cp = '\0'; tag = strchr(line, ':'); if (tag) *tag++ = '\0'; while (isspace(*tag)) tag++; if (isCmd("tiff") || isCmd("!tiff") || isCmd("postscript") || isCmd("!postscript")) { if (unlink(tag) < 0) { syslog(LOG_ERR, "%s: unlink %s failed (%m)", op, tag); sendClient("docUnlinkFailed", "%s", jobname); } } } if (unlink(job->qfile) < 0) { syslog(LOG_ERR, "%s: unlink %s failed (%m)", op, job->qfile); sendClient("unlinkFailed", "%s", jobname); } else { syslog(LOG_INFO, "%s %s completed", strcmp(op, "remove") == 0 ? "REMOVE" : "KILL", job->qfile); sendClient("removed", "%s", jobname); } } job->flags |= JOB_INVALID; (void) fclose(fp); /* implicit unlock */ }
static void sendClientJobLocked(Job* job, const char* jobname) { if (version > 0) sendClient("jobStatus", "%s:%s:locked:%s:%s:%s", jobname, job->sender, job->number, job->modem, job->status); else sendClient("jobLocked", "%s:%s:0:%s", jobname, job->sender, job->number); }
static int readQFile(int fd, char* qfile, int beingReceived, struct stat* sb) { int ok = 0; TIFF* tif = TIFFFdOpen(fd, qfile, "r"); if (tif) { ok = isFAXImage(tif); if (ok) { u_long pageWidth, pageLength; char* cp; char sender[80]; char date[30]; float resolution = 98; int c, i, npages; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &pageWidth); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &pageLength); if (TIFFGetField(tif, TIFFTAG_YRESOLUTION, &resolution)) { u_short resunit = RESUNIT_NONE; TIFFGetField(tif, TIFFTAG_RESOLUTIONUNIT, &resunit); if (resunit == RESUNIT_CENTIMETER) resolution *= 25.4; } else resolution = 98; if (TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &cp)) sanitize(sender, cp, sizeof (sender)); else strcpy(sender, "<unknown>"); if (TIFFGetField(tif, TIFFTAG_DATETIME, &cp)) sanitize(date, cp, sizeof (date)); else strftime(date, sizeof (date), "%Y:%m:%d %H:%M:%S", localtime(&sb->st_mtime)); npages = 0; do { npages++; } while (TIFFReadDirectory(tif)); if (version > 0) sendClient("recvJob", "%d:%lu:%lu:%3.1f:%u:%s:%s", beingReceived, pageWidth, pageLength, resolution, npages, date, sender); else sendClient("recvJob", "%d:%lu:%lu:%3.1f:%u:%u:%s", beingReceived, pageWidth, pageLength, resolution, npages, sb->st_mtime, sender); } TIFFClose(tif); } return (ok); }
static void sendClientJobStatus(Job* job, const char* jobname) { if (version > 0) { char tts[30]; if (job->tts != 0) strftime(tts, sizeof (tts), "%Y/%m/%d %H.%M.%S", localtime(&job->tts)); else strcpy(tts, "asap"); sendClient("jobStatus", "%s:%s:%s:%s:%s:%s", jobname, job->sender, tts, job->number, job->modem, job->status); } else sendClient("jobStatus", "%s:%s:%d:%s", jobname, job->sender, job->tts, job->number); }
void MainWidget::doubleClicked() { qDebug() << "doubleClicked"; TGbutton *button = (TGbutton*)sender(); if (button->curState != TGbutton::Click) return; int a,b; button->GetAB(a,b); int counter = 0; if (a-1 >= 0 && fields[a-1][b].curState == TGbutton::Flag) counter++; if (a+1 < row && fields[a+1][b].curState == TGbutton::Flag) counter++; if (b-1 >= 0 && fields[a][b-1].curState == TGbutton::Flag) counter++; if (b+1 < col && fields[a][b+1].curState == TGbutton::Flag) counter++; if (a-1 >= 0 && b-1 >= 0 && fields[a-1][b-1].curState == TGbutton::Flag) counter++; if (a+1 < row && b+1 < col && fields[a+1][b+1].curState == TGbutton::Flag) counter++; if (a-1 >= 0 && b+1 < col && fields[a-1][b+1].curState == TGbutton::Flag) counter++; if (a+1 < row && b-1 >= 0 && fields[a+1][b-1].curState == TGbutton::Flag) counter++; if (button->text().toInt() == counter) { button->curState = TGbutton::Disable; emit sendClient("DOUBLE", a, b); presses << "DOUBLE"; QPair <int,int> pair; pair.first = a; pair.second = b; pressBut << pair; clickRound(a,b); } }
void MainWidget::rightClicked() { qDebug() << "rightClicked"; TGbutton *button = (TGbutton*)sender(); int a,b; button->GetAB(a,b); emit sendClient("RIGHT", a, b); presses << "RIGHT"; QPair <int,int> pair; pair.first = a; pair.second = b; pressBut << pair; if(button->curState == TGbutton::First) { button->setIcon(QIcon(":/flag.png")); button->curState = TGbutton::Flag; emit updateMines(--mines); } else if(button->curState == TGbutton::Flag) { button->setIcon(QIcon()); button->curState = TGbutton::First; emit updateMines(++mines); } }
void neb::app::__net::sendClient(sp::shared_ptr< neb::message::OBase > message) { assert(message); /** @todo wtf */ //neb::std::wrapper wrap(message); auto buffer = sp::make_shared<gal::net::omessage>(); /** @todo boost serial warning */ //buffer->ar_ << wrapper; sendClient(buffer); }
void THIS::sendClient(std::shared_ptr<neb::fnd::net::msg::Base> m) { assert(m); /** @todo wtf */ gal::stl::wrapper<T> wrapper(std::move(m)); auto buffer = S_MSG(new gal::net::message); buffer->init_output(); /** @todo boost serial warning */ *buffer->get_oar() << wrapper; sendClient(buffer); }
// отправка данных для отображения медиапотоков записи void sendMediaStreamsDataToRecord(){ string mediaStreams = xmlGetString(config, "record"); string outDataXML = xmlStringToTag("id", "responseMediastreamsDataToRecord"); outDataXML += xmlGetTags(mediaStreams, "mediaStreamName"); outDataXML += xmlGetTags(mediaStreams, "mediaStreamId"); vector<string> arrayRecordStatus = xmlGetArrayTags(mediaStreams, "mediaStream"); string mediaStreamsRecordStatus; for(vector<string>::const_iterator it = arrayRecordStatus.begin(); it !=arrayRecordStatus.end(); ++it){ string recordStatus = recordStatusMap[xmlGetString(*it, "mediaStreamId")]; if (recordStatus == "") mediaStreamsRecordStatus += xmlStringToTag("mediaStreamRecordStatus", "stop"); else mediaStreamsRecordStatus += xmlStringToTag("mediaStreamRecordStatus", recordStatus); } outDataXML += mediaStreamsRecordStatus; sendClient(outDataXML); // отправляяем клиенту }
Server::Server(QWidget *parent) : QDialog(parent), ui(new Ui::Server) { ui->setupUi(this); QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); ui->lineEditIP->setText(ipAddressesList.at(0).toString()); ui->lineEditPort->setValidator(new QIntValidator(1, 65535, this)); tcpServer = new QTcpServer(this); QObject::connect(tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); QObject::connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(clearText())); QObject::connect(ui->pushButtonSend, SIGNAL(clicked()), this, SLOT(sendClient())); QObject::connect(ui->pushButtonQuit, SIGNAL(clicked()), this, SLOT(close())); QObject::connect(ui->pushButtonListen, SIGNAL(clicked()), this, SLOT(setListen())); }
void submitJob(const char* modem, char* otag) { u_long tts = 0; time_t t = time(0); struct tm* now = localtime(&t); sprintf(qfile, "%s/q%d", FAX_SENDDIR, seqnum = getSequenceNumber()); qfd = fopen(qfile, "w"); if (qfd == NULL) { syslog(LOG_ERR, "%s: Can not create qfile: %m", qfile); sendError("Can not create qfile \"%s\".", qfile); cleanupJob(); } flock(fileno(qfd), LOCK_EX); fprintf(qfd, "modem:%s\n", modem); for (;;) { if (!getCommandLine()) cleanupJob(); if (isCmd("end") || isCmd(".")) { setupData(seqnum); break; } if (isCmd("sendAt")) { tts = cvtTime(tag, now, "time-to-send"); } else if (isCmd("killtime")) { fprintf(qfd, "%s:%lu\n", line, cvtTime(tag, now, "kill-time")); } else if (isCmd("cover")) { coverProtocol(atoi(tag), seqnum); } else fprintf(qfd, "%s:%s\n", line, tag); /* XXX check info */ } fprintf(qfd, "tts:%lu\n", tts); fclose(qfd), qfd = NULL; if (!notifyServer(modem, "S%s", qfile)) sendError("Warning, no server appears to be running."); sendClient("job", "%d", seqnum); }
void MainWidget::check() { // qDebug() << "check"; isEmitter = false; TGbutton *button = (TGbutton*)sender(); if (button->curState != TGbutton::First) return; if (isNewGame == false) { isNewGame = true; emit newGame(); } cur++; if(cur == all) { type = true; for (int i=0; i < row; i++) { for(int j=0;j<col;j++) { if (fields[i][j].curState == TGbutton::First) { if (mat[i][j]==-1) fields[i][j].setIcon(QIcon(":/bomb.png")); else fields[i][j].click(); } else if (fields[i][j].curState == TGbutton::Flag && mat[i][j] != -1) { type = false; QPalette pal = fields[i][j].palette(); pal.setColor(QPalette::Button,QColor(249,123,126,128)); fields[i][j].setPalette(pal); } } } emit progress(100); QTimer::singleShot(1,this,SLOT(theEnd())); return; } int a,b; button->GetAB(a,b); qDebug() << "click" << a << b; if (isNotSend == false) { isEmitter = true; emit sendClient("CLICK", a, b); } presses << "CLICK"; QPair <int,int> pair; pair.first = a; pair.second = b; pressBut << pair; QColor color; if(mat[a][b] == -1) { type = false; for (int i=0; i < row; i++) { for(int j=0;j<col;j++) { if(mat[i][j] == -1 && fields[i][j].curState == TGbutton::First) fields[i][j].setIcon(QIcon(":/bomb.png")); else if ((mat[i][j] == -1 && fields[i][j].curState != TGbutton::Flag) || (mat[i][j] != -1 && fields[i][j].curState == TGbutton::Flag)) { QPalette pal = fields[i][j].palette(); pal.setColor(QPalette::Button,QColor(249,123,126,128)); fields[i][j].setPalette(pal); } } } QTimer::singleShot(100,this,SLOT(theEnd())); return; } else if(mat[a][b] == 1) color.setRgb(50,205,80,255); else if(mat[a][b] == 2) color.setRgb(220,160,40,255); else if(mat[a][b] == 0) color.setRgb(0,0,0,255); else color.setRgb(255,0,0,255); button->curState = TGbutton::Click; QFont font("Sans",10,10,false); button->setFont(font); button->setMaximumWidth(button->width()); QPalette p=button->palette(); p.setColor(QPalette::ButtonText,color); p.setColor(QPalette::Button,QColor(182,214,220,128)); button->setPalette(p); if (mat[a][b] != 0) button->setText(QString::number(mat[a][b])); else clickRound(a,b); isNotSend = false; emit progress((int)(((float)cur/(float)all)*100)); }