⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobs.c++

📁 fax相关的东西
💻 C++
📖 第 1 页 / 共 4 页
字号:
HylaFAXServer::jstatLine(Token t, const char* fmt ...){    printf("    %s: ", parmToken(t));    va_list ap;    va_start(ap, fmt);    vprintf(fmt, ap);    va_end(ap);    printf("\r\n");}/* * Implement the jparm command that returns the entire * job state as a series of parameter: value pairs. * This command is mainly intended for debugging and * may go away in the final spec (or become a site cmd). */voidHylaFAXServer::jstatCmd(const Job& job){    lreply(217, "Job state: jobid %s groupid %s",	(const char*) job.jobid, (const char*) job.groupid);    if (checkAccess(job, T_SENDTIME, A_READ)) {	if (job.tts != 0) {	    const struct tm* tm = cvtTime(job.tts);	    // XXX should this include seconds? (useful for debugging)	    jstatLine(T_SENDTIME, "%d%02d%02d%02d%02d%02d"		, tm->tm_year+1900		, tm->tm_mon+1		, tm->tm_mday		, tm->tm_hour		, tm->tm_min		, tm->tm_sec	    );	} else	    jstatLine(T_SENDTIME, "%s", "NOW");    }    if (checkAccess(job, T_LASTTIME, A_READ)) {	time_t tv = job.killtime - job.tts;	jstatLine(T_LASTTIME, "%02d%02d%02d",	    tv/(24*60*60), (tv/(60*60))%24, (tv/60)%60);    }    if (checkAccess(job, T_RETRYTIME, A_READ))	jstatLine(T_RETRYTIME, "%02d%02d", job.retrytime/60, job.retrytime%60);    if (checkAccess(job, T_STATE, A_READ))	jstatLine(T_STATE,	"%s", stateVals[job.state]);    if (checkAccess(job, T_NOTIFY, A_READ))	jstatLine(T_NOTIFY,	"%s", notifyVals[job.notify]);    if (checkAccess(job, T_PAGECHOP, A_READ))	jstatLine(T_PAGECHOP,	"%s", chopVals[job.pagechop]);    if (checkAccess(job, T_CHOPTHRESH, A_READ))	jstatLine(T_CHOPTHRESH,	"%g", job.chopthreshold);    if (checkAccess(job, T_DATAFORMAT, A_READ))	jstatLine(T_DATAFORMAT,	"%s", dataVals[job.desireddf]);    if (checkAccess(job, T_USE_ECM, A_READ))	jstatLine(T_USE_ECM,	"%s", boolString(job.desiredec));    if (checkAccess(job, T_USE_TAGLINE, A_READ))	jstatLine(T_USE_TAGLINE,"%s", boolString(job.desiredtl));    if (checkAccess(job, T_USE_XVRES, A_READ))	jstatLine(T_USE_XVRES,"%s", boolString(job.usexvres));    if (checkAccess(job, T_USE_CONTCOVER, A_READ))	jstatLine(T_USE_CONTCOVER,"%s", boolString(job.useccover));    u_int i, n;    for (i = 0, n = N(strvals); i < n; i++)	if (checkAccess(job, strvals[i].t, A_READ))	    jstatLine(strvals[i].t, "%s", (const char*) (job.*strvals[i].p));    for (i = 0, n = N(shortvals); i < n; i++)	if (checkAccess(job, shortvals[i].t, A_READ))	    jstatLine(shortvals[i].t, "%u", job.*shortvals[i].p);    /*     * NB: This assumes access to T_DOCUMENT is sufficient     *     for access to T_COVER and T_POLL also.     */    if (checkAccess(job, T_DOCUMENT, A_READ)) {	for (i = 0, n = job.items.length(); i < n; i++) {	    const FaxItem& fitem = job.items[i];	    switch (fitem.op) {	    case FaxRequest::send_fax:		jstatLine(T_DOCUMENT, "%s %s %u", docTypeNames[fitem.op],		    (const char*) fitem.item, fitem.dirnum);		break;	    case FaxRequest::send_tiff:	    case FaxRequest::send_tiff_saved:	    case FaxRequest::send_pdf:	    case FaxRequest::send_pdf_saved:	    case FaxRequest::send_postscript:	    case FaxRequest::send_postscript_saved:	    case FaxRequest::send_pcl:	    case FaxRequest::send_pcl_saved:	    case FaxRequest::send_data:	    case FaxRequest::send_data_saved:		jstatLine(		    (fitem.item.length() > 7 && fitem.item.tail(6) == ".cover" ?			T_COVER : T_DOCUMENT) 		    , "%s %s"		    , docTypeNames[fitem.op]		    , (const char*) fitem.item		);		break;	    case FaxRequest::send_page:	    case FaxRequest::send_page_saved:		jstatLine(T_DOCUMENT		    , fitem.addr == "" ? "%s \"%s\"" : "%s \"%s\" \"%s\""		    , docTypeNames[fitem.op]		    , (const char*) fitem.item		    , (const char*) fitem.addr		);		break;	    case FaxRequest::send_poll:		jstatLine(T_POLL		    , fitem.addr == "" ? "\"%s\"" : "\"%s\" \"%s\""		    , (const char*) fitem.item		    , (const char*) fitem.addr		);		break;	    }	}    }    reply(217, "End of job %s state.", (const char*) job.jobid);}/*  * Set a job state parameter value from an array of * parameter names; the value is the index into the * array.  Parameter names are case-insensitive.  * Unknown values cause an error reply.   */boolHylaFAXServer::setValue(u_short& v, const char* value, const char* what,    const char* valNames[], u_int nValNames){    for (u_int i = 0; i < nValNames; i++)	if (strcasecmp(value, valNames[i]) == 0) {	    v = i;	    return (true);	}    reply(503, "Unknown %s value %s.", what, value);    return (false);}voidHylaFAXServer::parmBotch(Token t){    reply(503, "Botch, don't know how to set %s parameter.", parmToken(t));}/* * Discard any prepared documents so that * they will be re-prepared with revised * parameters. */voidHylaFAXServer::flushPreparedDocuments(Job& job){    u_int j = 0;    while (j < job.items.length()) {	FaxItem& fitem = job.items[j];	if (fitem.op == FaxRequest::send_fax) {	    // NB: don't waste time requesting ACK	    fxStr emsg;	    sendQueuer(emsg, "U%s", (const char*) fitem.item);	    job.items.remove(j);	    continue;	}	if (fitem.isSavedOp())	    fitem.op--;				// assumes order of enum	j++;    }    job.pagehandling = "";			// force recalculation}/* * Set a job state parameter that has a string value. */boolHylaFAXServer::setJobParameter(Job& job, Token t, const fxStr& value){    if (checkParm(job, t, A_WRITE|A_MODIFY)) {	switch (t) {	case T_NOTIFY:	    return setValue(job.notify, value, parmToken(t),		notifyVals, N(notifyVals));	case T_PAGECHOP:	    if (setValue(job.pagechop, value, parmToken(t),	      chopVals, N(chopVals))) {		job.pagehandling = "";		// force recalculation		return (true);	    } else		return (false);	case T_DATAFORMAT:	    if (setValue(job.desireddf, value, parmToken(t),	      dataVals, N(dataVals))) {		flushPreparedDocuments(job);		return (true);	    } else		return (false);	}	for (u_int i = 0, n = N(strvals); i < n; i++)	    if (strvals[i].t == t) {		job.*strvals[i].p = value;		return (true);	    }	parmBotch(t);    }    return (false);}/* * Set a job state parameter that has a integer value. */boolHylaFAXServer::setJobParameter(Job& job, Token t, u_short value){    if (checkParm(job, t, A_WRITE|A_MODIFY)) {	for (u_int i = 0, n = N(shortvals); i < n; i++)	    if (shortvals[i].t == t) {		if (job.*shortvals[i].p != value) {		    // XXX constrain values per A_MODIFY		    job.*shortvals[i].p = value;	// XXX		    /*		     * Handle parameters with side effects.		     */		    switch (t) {		    case T_PAGEWIDTH:		    case T_PAGELENGTH:		    case T_VRES:		    case T_HRES:			flushPreparedDocuments(job);			break;		    case T_SCHEDPRI:			job.pri = job.usrpri;		// reload			break;		    }		}		return (true);	    }	parmBotch(t);    }    return (false);}/* * Set a job state parameter that has a time value. */boolHylaFAXServer::setJobParameter(Job& job, Token t, time_t value){    if (checkParm(job, t, A_WRITE|A_MODIFY)) {	time_t now = Sys::now();	switch (t) {	case T_SENDTIME:	    if (value != 0) {			// explicit time		/*		 * We don't complain anymore if this value is in the		 * past.  Instead, we verify that the killtime is in		 * the future, ensuring that a window of send-time		 * opportunity still exists.		 */		job.tts = value;	    } else				// ``NOW''		job.tts = now;	    return (true);	case T_LASTTIME:	    /*	     * Convert client-specified kill time (as a relative number)	     * to an absolute time.  If the time-to-send has been set,	     * then the killtime is relative to that; otherwise it's	     * made relative to ``now''.  Note that this implies the	     * order of setting SENDTIME and LASTTIME is important; if	     * a client sets LASTTIME before SENDTIME then an unexpected	     * value may be installed for LASTTIME.	     */	    job.killtime = value + (job.tts == 0 ? now : job.tts);	    if (job.killtime < now) {		reply(503, "Bad time to send; time window is entirely in the past.");		return (false);	    }	    return (true);	case T_RETRYTIME:	    job.retrytime = value;	    return (true);	}	parmBotch(t);    }    return (false);}/* * Set a job state parameter that has a boolean value. */boolHylaFAXServer::setJobParameter(Job& job, Token t, bool b){    if (checkParm(job, t, A_WRITE|A_MODIFY)) {	switch (t) {	case T_USE_ECM:	    job.desiredec = b;	    return (true);	case T_USE_TAGLINE:	    job.desiredtl = b;	    return (true);	case T_USE_XVRES:	    job.usexvres = b;	    return (true);	case T_USE_CONTCOVER:	    job.useccover = b;	    return (true);	}	parmBotch(t);    }    return (true);}/* * Set a job state parameter that has a float value. */boolHylaFAXServer::setJobParameter(Job& job, Token t, float value){    if (checkParm(job, t, A_WRITE|A_MODIFY)) {	switch (t) {	case T_CHOPTHRESH:	    if (job.chopthreshold != value) {		job.chopthreshold = value;		job.pagehandling = "";		// force recalculation	    }	    return (true);	}	parmBotch(t);    }    return (false);}/* * Initialize the default job state.  We * explicitly set string values since this * routine may be called for a JREST command * to reset job state to the default settings. */voidHylaFAXServer::initDefaultJob(void){    defJob.jobid	= "default";    defJob.owner	= the_user;    defJob.state	= FaxRequest::state_undefined;    defJob.maxdials	= FAX_REDIALS;    defJob.maxtries	= FAX_RETRIES;    defJob.pagewidth	= 0;    defJob.pagelength	= 0;    defJob.resolution	= FAX_DEFVRES;    defJob.usrpri	= FAX_DEFPRIORITY;    defJob.minbr	= BR_2400;    defJob.desiredbr	= BR_33600;    defJob.desiredst	= ST_0MS;    defJob.desiredec	= EC_ENABLE256;    defJob.desireddf	= DF_2DMMR;    defJob.desiredtl	= false;    defJob.usexvres	= false;    defJob.useccover	= true;    defJob.pagechop	= FaxRequest::chop_default;    defJob.notify	= FaxRequest::no_notice;// FAX_DEFNOTIFY    defJob.chopthreshold= 3.0;    defJob.tts		= 0;			// ``NOW''    defJob.killtime	= 3*60*60;		// FAX_TIMEOUT    defJob.retrytime	= 0;    defJob.sender	= the_user;		// XXX usually incorrect    defJob.mailaddr	= the_user | "@" | remotehost;    defJob.jobtag	= "";    defJob.number	= "";    defJob.subaddr	= "";    defJob.passwd	= "";    defJob.external	= "";    defJob.modem	= MODEM_ANY;    defJob.faxnumber	= "";    defJob.tsi		= "";    defJob.receiver	= "";    defJob.company	= "";    defJob.location	= "";    defJob.voice	= "";    defJob.fromcompany	= "";    defJob.fromlocation	= "";    defJob.fromvoice	= "";    defJob.regarding	= "";    defJob.comments	= "";    defJob.client	= remotehost;    defJob.tagline	= "";    defJob.doneop	= "default";}/* * JNEW command; create a new job and * make it the current job. */voidHylaFAXServer::newJobCmd(void){    fxStr emsg;    if (newJob(emsg) && updateJobOnDisk(*curJob, emsg)) {	fxStr file("/" | curJob->qfile);	setFileOwner(file);			// force ownership	FileCache::chmod(file, 0660);		// sync cache	curJob->lastmod = Sys::now();		// noone else should update	reply(200, "New job created: jobid: %s groupid: %s.",	    (const char*) curJob->jobid, (const char*) curJob->groupid);	blankJobs[curJob->jobid] = curJob;    } else	reply(503, "%s.", (const char*) emsg);}/* * Create a new job, inheriting state from the current * job and make the new job be the current job.  Note * that the current job must be owned by the client; * otherwise people could ``look inside'' other people's * jobs by inheriting state--this would permit them to * look at privileged information such as calling card * information in dial strings and passwords to be * transmitted with polling items. */boolHylaFAXServer::newJob(fxStr& emsg){    if (!IS(PRIVILEGED) && the_user != curJob->owner) {	emsg = "Permission denied; cannot inherit from job " | curJob->jobid;	return (false);    }    u_int id = getJobNumber(emsg);		// allocate unique job ID    if (id == (u_int) -1)	return (false);    fxStr jobid = fxStr::format("%u", id);    Job* job = new Job(FAX_SENDDIR "/" FAX_QFILEPREF | jobid);    job->jobid = jobid;    job->groupid = curJob->groupid;    if (job->groupid == "")	job->groupid = jobid;    job->owner = the_user;    job->state = FaxRequest::state_suspended;    job->maxdials = curJob->maxdials;    job->maxtries = curJob->maxtries;    job->pagewidth = curJob->pagewidth;    job->pagelength = curJob->pagelength;    job->resolution = curJob->resolution;    job->usrpri = curJob->usrpri;    job->minbr = curJob->minbr;    job->desiredbr = curJob->desiredbr;    job->desiredst = curJob->desiredst;    job->desiredec = curJob->desiredec;    job->desireddf = curJob->desireddf;    job->desiredtl = curJob->desiredtl;    job->usexvres = curJob->usexvres;    job->useccover = curJob->useccover;    job->pagechop = curJob->pagechop;    job->notify = curJob->notify;    job->chopthreshold = curJob->chopthreshold;    job->tts = curJob->tts;    job->killtime = curJob->killtime;    job->retrytime = curJob->retrytime;    job->sender = curJob->sender;    job->mailaddr = curJob->mailaddr;    job->jobtag = curJob->jobtag;		// ???    job->number = curJob->number;    job->external = curJob->external;    job->modem = curJob->modem;    job->faxnumber = curJob->faxnumber;    job->tsi = curJob->tsi;    job->receiver = curJob->receiver;    job->company = curJob->company;    job->location = curJob->location;    job->voice = curJob->voice;    job->fromcompany = curJob->fromcompany;    job->fromlocation = curJob->fromlocation;    job->fromvoice = curJob->fromvoice;    job->regarding = curJob->regarding;    job->comments = curJob->comments;    job->jobtype = curJob->jobtype;    job->tagline = curJob->tagline;    job->client = remotehost;    job->doneop = curJob->doneop;    job->queued = curJob->queued;    jobs[jobid] = job;    curJob = job;    return (true);}/* * Update the job's state on disk. */boolHylaFAXServer::updateJobOnDisk(Job& job, fxStr& emsg){    if (lockJob(job, LOCK_EX|LOCK_NB, emsg)) {	// XXX don't update in place, use temp file and rename	job.writeQFile();	unlockJob(job);	return (true);    } else	return (false);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -