| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054 |
- <?php
- /* @(#) $Header: /sources/phpprintipp/phpprintipp/php_classes/PrintIPP.php,v 1.3 2010/09/06 22:41:41 harding Exp $
- *
- * Class PrintIPP - Send IPP requests, Get and parses IPP Responses.
- *
- * Copyright (C) 2005-2006 Thomas HARDING
- * Parts Copyright (C) 2005-2006 Manuel Lemos
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * mailto:thomas.harding@laposte.net
- * Thomas Harding, 56 rue de la bourie rouge, 45 000 ORLEANS -- FRANCE
- *
- */
-
- /*
- This class is intended to implement Internet Printing Protocol on client side.
- References needed to debug / add functionnalities:
- - RFC 2910
- - RFC 2911
- - RFC 3380
- - RFC 3382
- */
- /*
- TODO: beta tests on other servers than Cups
- */
- require_once("BasicIPP.php");
- class PrintIPP extends BasicIPP
- {
- public function __construct()
- {
- parent::__construct();
- }
- // OPERATIONS
- public function printJob()
- {
- self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
- if (!$this->_stringJob())
- {
- return FALSE;
- }
- if (is_readable($this->data))
- {
- self::_putDebug( _("Printing a FILE\n"),3);
- $this->output = $this->stringjob;
- if ($this->setup->datatype == "TEXT")
- {
- $this->output .= chr(0x16);
- }
- $post_values = array( "Content-Type" => "application/ipp",
- "Data" => $this->output,
- "File" => $this->data);
- if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
- {
- $post_values = array_merge($post_values,array("Filetype"=>"TEXT"));
- }
- }
- else
- {
- self::_putDebug( _("Printing DATA\n"),3);
- $this->output = $this->stringjob;
- $this->output .= $this->datahead;
- $this->output .= $this->data;
- $this->output .= $this->datatail;
-
- $post_values = array( "Content-Type" => "application/ipp",
- "Data" => $this->output);
- }
- if (self::_sendHttp ($post_values,$this->paths['printers']))
- {
- if(self::_parseServerOutput())
- {
- $this->_getJobId();
- $this->_getJobUri();
- $this->_parseJobAttributes();
- }
- else
- {
- $this->jobs = array_merge($this->jobs,array(''));
- $this->jobs_uri = array_merge($this->jobs_uri,array(''));
- }
- }
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog(sprintf("printing job %s: ",$this->last_job) .$this->serveroutput->status,3);
- }
- else
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- self::_errorLog(sprintf("printing job: ",$this->last_job) .$this->serveroutput->status,1);
- if ($this->with_exceptions)
- {
- throw new ippException(sprintf("job status: %s",
- $this->serveroutput->status));
- }
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- self::_errorLog("printing job : OPERATION FAILED",1);
- return false;
- }
- public function cancelJob ($job_uri)
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
- if (!$this->_stringCancel($job_uri))
- {
- return FALSE;
- }
- self::_putDebug( _("Cancelling Job $job_uri\n"),3);
- $this->output = $this->stringjob;
- $post_values = array( "Content-Type"=>"application/ipp",
- "Data"=>$this->output);
- if (self::_sendHttp ($post_values,$this->paths['jobs']))
- {
- self::_parseServerOutput();
- }
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,3);
- }
- else
- {
- self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,1);
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- self::_errorLog("cancelling job : OPERATION FAILED",3);
- return false;
- }
- public function validateJob ()
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- $this->serveroutput->response = '';
- self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
- self::_putDebug( _("Validate Job\n"),2);
- if (!isset($this->setup->charset))
- {
- self::setCharset();
- }
- if (!isset($this->setup->datatype))
- {
- self::setBinary();
- }
- if (!isset($this->setup->uri))
- {
- $this->getPrinters();
- unset($this->jobs[count($this->jobs) - 1]);
- unset($this->jobs_uri[count($this->jobs_uri) - 1]);
- unset($this->status[count($this->status) - 1]);
- if (array_key_exists(0,$this->available_printers))
- {
- self::setPrinterURI($this->available_printers[0]);
- }
- else
- {
- trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
- self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
- self::_errorLog(" Printer URI is not set, die",2);
- return FALSE;
- }
- }
- if (!isset($this->meta->copies))
- {
- self::setCopies(1);
- }
- if (!isset($this->setup->copies))
- {
- self::setCopies(1);
- }
- if (!isset($this->setup->language))
- {
- self::setLanguage('en_us');
- }
- if (!isset($this->setup->mime_media_type))
- {
- self::setMimeMediaType();
- }
- if ($this->setup->datatype != "TEXT")
- {
- unset ($this->setup->mime_media_type);
- }
- if (!isset($this->setup->jobname))
- {
- if (is_readable($this->data))
- {
- self::setJobName(basename($this->data),true);
- }
- else
- {
- self::setJobName();
- }
- }
- unset($this->setup->jobname);
- if (!isset($this->meta->username))
- {
- self::setUserName();
- }
- if (!isset($this->meta->fidelity))
- {
- $this->meta->fidelity = '';
- }
- if (!isset($this->meta->document_name))
- {
- $this->meta->document_name = '';
- }
- if (!isset($this->meta->sides))
- {
- $this->meta->sides = '';
- }
- if (!isset($this->meta->page_ranges))
- {
- $this->meta->page_ranges = '';
- }
- $jobattributes = '';
- $operationattributes = '';
- $printerattributes = '';
- self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
- self::_setOperationId();
- $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
- . chr(0x00) . chr (0x04) // Validate-Job | operation-id
- . $this->meta->operation_id // request-id
- . chr(0x01) // start operation-attributes | operation-attributes-tag
- . $this->meta->charset
- . $this->meta->language
- . $this->meta->printer_uri
- . $this->meta->username
- . $this->meta->jobname
- . $this->meta->fidelity
- . $this->meta->document_name
- . $this->meta->mime_media_type
- . $operationattributes
- . chr(0x02) // start job-attributes | job-attributes-tag
- . $this->meta->copies
- . $this->meta->sides
- . $this->meta->page_ranges
- . $jobattributes
- . chr(0x03); // end-of-attributes | end-of-attributes-tag
- self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
- $this->output = $this->stringjob;
- $post_values = array( "Content-Type"=>"application/ipp",
- "Data"=>$this->output);
- if (self::_sendHttp ($post_values,$this->paths['printers']))
- {
- if(self::_parseServerOutput())
- {
- self::_parseAttributes();
- }
- }
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog("validate job: ".$this->serveroutput->status,3);
- }
- else
- {
- self::_errorLog("validate job: ".$this->serveroutput->status,1);
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- self::_errorLog("validate job : OPERATION FAILED",3);
- return false;
- }
- public function getPrinterAttributes()
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- $jobattributes = '';
- $operationattributes = '';
- self::_buildValues($operationattributes,$jobattributes,$printerattributes);
- self::_setOperationId();
- $this->parsed = array();
- unset($this->printer_attributes);
- if (!isset($this->setup->uri))
- {
- $this->getPrinters();
- unset($this->jobs[count($this->jobs) - 1]);
- unset($this->jobs_uri[count($this->jobs_uri) - 1]);
- unset($this->status[count($this->status) - 1]);
- if (array_key_exists(0,$this->available_printers))
- {
- self::setPrinterURI($this->available_printers[0]);
- }
- else
- {
- trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
- self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
- self::_errorLog(" Printer URI is not set, die",2);
- return FALSE;
- }
- }
- if (!isset($this->setup->charset))
- {
- self::setCharset();
- }
- if (!isset($this->setup->language))
- {
- self::setLanguage('en_us');
- }
- if (!isset($this->meta->username))
- {
- self::setUserName();
- }
- $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
- . chr(0x00) . chr (0x0b) // Print-URI | operation-id
- . $this->meta->operation_id // request-id
- . chr(0x01) // start operation-attributes | operation-attributes-tag
- . $this->meta->charset
- . $this->meta->language
- . $this->meta->printer_uri
- . $this->meta->username
- . $printerattributes
- . chr(0x03); // end-of-attributes | end-of-attributes-tag
- self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
- self::_putDebug(sprintf(_("Getting printer attributes of %s\n"),$this->printer_uri),2);
- $this->output = $this->stringjob;
- $post_values = array( "Content-Type"=>"application/ipp",
- "Data"=>$this->output);
- if (self::_sendHttp ($post_values,$this->paths['root']))
- {
- if (self::_parseServerOutput())
- {
- self::_parsePrinterAttributes();
- }
- }
- $this->attributes = &$this->printer_attributes;
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
- $this->serveroutput->status),3);
- }
- else
- {
- self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
- $this->serveroutput->status),1);
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- self::_errorLog(date("Y-m-d H:i:s : ")
- .basename($_SERVER['PHP_SELF'])
- .sprintf(_("getting printer's attributes of %s : OPERATION FAILED"),
- $this->printer_uri),3);
- return false;
- }
- public function getJobs($my_jobs=true,$limit=0,$which_jobs="not-completed",$subset=false)
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- self::_setOperationId();
- $this->parsed = array();
- unset($this->printer_attributes);
- if (!isset($this->setup->uri))
- {
- $this->getPrinters();
- unset($this->jobs[count($this->jobs) - 1]);
- unset($this->jobs_uri[count($this->jobs_uri) - 1]);
- unset($this->status[count($this->status) - 1]);
- if (array_key_exists(0,$this->available_printers))
- {
- self::setPrinterURI($this->available_printers[0]);
- }
- else
- {
- trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
- self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
- self::_errorLog("getJobs: Printer URI is not set, die",2);
- return FALSE;
- }
- }
- if (!isset($this->setup->charset))
- {
- self::setCharset();
- }
- if (!isset($this->setup->language))
- {
- self::setLanguage('en_us');
- }
- if (!isset($this->meta->username))
- {
- self::setUserName();
- }
- if ($limit)
- {
- $limit = self::_integerBuild($limit);
- $this->meta->limit = chr(0x21) // integer
- . self::_giveMeStringLength('limit')
- . 'limit'
- . self::_giveMeStringLength($limit)
- . $limit;
- }
- else
- {
- $this->meta->limit = '';
- }
- if ($which_jobs == 'completed')
- {
- $this->meta->which_jobs = chr(0x44) // keyword
- . self::_giveMeStringLength('which-jobs')
- . 'which-jobs'
- . self::_giveMeStringLength($which_jobs)
- . $which_jobs;
- }
- else
- {
- $this->meta->which_jobs = "";
- }
- if ($my_jobs)
- {
- $this->meta->my_jobs = chr(0x22) // boolean
- . self::_giveMeStringLength('my-jobs')
- . 'my-jobs'
- . self::_giveMeStringLength(chr(0x01))
- . chr(0x01);
- }
- else
- {
- $this->meta->my_jobs = '';
- }
- $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
- . chr(0x00) . chr (0x0A) // Get-Jobs | operation-id
- . $this->meta->operation_id // request-id
- . chr(0x01) // start operation-attributes | operation-attributes-tag
- . $this->meta->charset
- . $this->meta->language
- . $this->meta->printer_uri
- . $this->meta->username
- . $this->meta->limit
- . $this->meta->which_jobs
- . $this->meta->my_jobs;
- if ($subset)
- {
- $this->stringjob .=
- chr(0x44) // keyword
- . self::_giveMeStringLength('requested-attributes')
- . 'requested-attributes'
- . self::_giveMeStringLength('job-uri')
- . 'job-uri'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-name')
- . 'job-name'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-state')
- . 'job-state'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-state-reason')
- . 'job-state-reason';
- }
- else
- { # cups 1.4.4 doesn't return much of anything without this
- $this->stringjob .=
- chr(0x44) // keyword
- . self::_giveMeStringLength('requested-attributes')
- . 'requested-attributes'
- . self::_giveMeStringLength('all')
- . 'all';
- }
- $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
- self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
- self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2);
- $this->output = $this->stringjob;
- $post_values = array( "Content-Type"=>"application/ipp",
- "Data"=>$this->output);
- if (self::_sendHttp ($post_values,$this->paths['jobs']))
- {
- if (self::_parseServerOutput())
- {
- self::_parseJobsAttributes();
- }
- }
- $this->attributes = &$this->jobs_attributes;
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
- .$this->serveroutput->status,3);
- }
- else
- {
- self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
- .$this->serveroutput->status,1);
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- self::_errorLog(date("Y-m-d H:i:s : ")
- .basename($_SERVER['PHP_SELF'])
- .sprintf(_("getting jobs of %s : OPERATION FAILED"),
- $this->printer_uri),3);
- return false;
- }
- public function getJobAttributes($job_uri,$subset=false,$attributes_group="all")
- {
- $this->jobs = array_merge($this->jobs,array(""));
- $this->jobs_uri = array_merge($this->jobs_uri,array(""));
- if (!$job_uri)
- {
- trigger_error(_("getJobAttributes: Job URI is not set, die."));
- return FALSE;
- }
- self::_setOperationId();
- $this->parsed = array();
- unset($this->printer_attributes);
- if (!isset($this->setup->uri))
- {
- $this->getPrinters();
- unset($this->jobs[count($this->jobs) - 1]);
- unset($this->jobs_uri[count($this->jobs_uri) - 1]);
- unset($this->status[count($this->status) - 1]);
- if (array_key_exists(0,$this->available_printers))
- {
- self::setPrinterURI($this->available_printers[0]);
- }
- else
- {
- trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
- self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
- self::_errorLog("getJobs: Printer URI is not set, die",2);
- return FALSE;
- }
- }
- if (!isset($this->setup->charset))
- {
- self::setCharset();
- }
- if (!isset($this->setup->language))
- {
- self::setLanguage('en_us');
- }
- if (!isset($this->meta->username))
- {
- self::setUserName();
- }
- $this->meta->job_uri = chr(0x45) // URI
- . self::_giveMeStringLength('job-uri')
- . 'job-uri'
- . self::_giveMeStringLength($job_uri)
- . $job_uri;
- $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
- . chr(0x00) . chr (0x09) // Get-Job-Attributes | operation-id
- . $this->meta->operation_id // request-id
- . chr(0x01) // start operation-attributes | operation-attributes-tag
- . $this->meta->charset
- . $this->meta->language
- . $this->meta->job_uri
- . $this->meta->username;
- if ($subset)
- {
- $this->stringjob .=
- chr(0x44) // keyword
- . self::_giveMeStringLength('requested-attributes')
- . 'requested-attributes'
- . self::_giveMeStringLength('job-uri')
- . 'job-uri'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-name')
- . 'job-name'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-state')
- . 'job-state'
- . chr(0x44) // keyword
- . self::_giveMeStringLength('')
- . ''
- . self::_giveMeStringLength('job-state-reason')
- . 'job-state-reason';
- }
- elseif($attributes_group)
- {
- switch($attributes_group)
- {
- case 'job-template':
- break;
- case 'job-description':
- break;
- case 'all':
- break;
- default:
- trigger_error(_('not a valid attribute group: ').$attributes_group,E_USER_NOTICE);
- $attributes_group = '';
- break;
- }
- $this->stringjob .=
- chr(0x44) // keyword
- . self::_giveMeStringLength('requested-attributes')
- . 'requested-attributes'
- . self::_giveMeStringLength($attributes_group)
- . $attributes_group;
- }
- $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
- self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
- self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2);
- $this->output = $this->stringjob;
- $post_values = array( "Content-Type"=>"application/ipp",
- "Data"=>$this->output);
- if (self::_sendHttp ($post_values,$this->paths['jobs']))
- {
- if (self::_parseServerOutput())
- {
- self::_parseJobAttributes();
- }
- }
- $this->attributes = &$this->job_attributes;
- if (isset($this->serveroutput) && isset($this->serveroutput->status))
- {
- $this->status = array_merge($this->status,array($this->serveroutput->status));
- if ($this->serveroutput->status == "successfull-ok")
- {
- self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
- .$this->serveroutput->status,3);
- }
- else
- {
- self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
- .$this->serveroutput->status,1);
- }
- return $this->serveroutput->status;
- }
- $this->status = array_merge($this->status,array("OPERATION FAILED"));
- self::_errorLog(date("Y-m-d H:i:s : ")
- .basename($_SERVER['PHP_SELF'])
- .sprintf(_("getting jobs attributes of %s : OPERATION FAILED"),
- $job_uri),3);
- return false;
- }
- public function getPrinters()
- {
- // placeholder for vendor extension operation (getAvailablePrinters for CUPS)
- $this->jobs = array_merge($this->jobs,array(''));
- $this->jobs_uri = array_merge($this->jobs_uri,array(''));
- $this->status = array_merge($this->status,array(''));
- }
- public function generateError ($error)
- {
- switch ($error)
- {
- case "request_body_malformed":
- $this->error_generation->request_body_malformed = chr(0xFF);
- break;
- default:
- true;
- break;
- }
- trigger_error(sprintf(_('Setting Error %s'),$error),E_USER_NOTICE);
- }
-
- public function resetError ($error)
- {
- unset ($this->error_generation->$error);
- trigger_error(sprintf(_('Reset Error %s'),$error),E_USER_NOTICE);
- }
- // SETUP
- protected function _setOperationId ()
- {
- $prepend = '';
- $this->operation_id += 1;
- $this->meta->operation_id = self::_integerBuild($this->operation_id);
- self::_putDebug( "operation id is: ".$this->operation_id."\n",2);
- }
-
- protected function _setJobId()
- {
- $this->meta->jobid +=1;
- $prepend = '';
- $prepend_length = 4 - strlen($this->meta->jobid);
- for ($i = 0; $i < $prepend_length ; $i++ )
- {
- $prepend .= '0';
- }
- return $prepend.$this->meta->jobid;
- }
-
- protected function _setJobUri ($job_uri)
- {
- $this->meta->job_uri = chr(0x45) // type uri
- . chr(0x00).chr(0x07) // name-length
- . "job-uri"
- //. chr(0x00).chr(strlen($job_uri))
- . self::_giveMeStringLength($job_uri)
- . $job_uri;
-
- self::_putDebug( "job-uri is: ".$job_uri."\n",2);
- }
- // RESPONSE PARSING
- protected function _parsePrinterAttributes()
- {
- //if (!preg_match('#successful#',$this->serveroutput->status))
- // return false;
- $k = -1;
- $l = 0;
- for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
- {
- for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
- {
- if (!empty($this->serveroutput->response[$i][$j]['name']))
- {
- $k++;
- $l = 0;
- $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
- $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
- $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- else
- {
- $l ++;
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- }
- }
- $this->serveroutput->response = array();
- $this->printer_attributes = new \stdClass();
- for ($i = 0 ; $i < count($this->parsed) ; $i ++)
- {
- $name = $this->parsed[$i]['name'];
- $php_name = str_replace('-','_',$name);
- $type = $this->parsed[$i]['type'];
- $range = $this->parsed[$i]['range'];
- $this->printer_attributes->$php_name = new \stdClass();
- $this->printer_attributes->$php_name->_type = $type;
- $this->printer_attributes->$php_name->_range = $range;
- for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
- {
- $value = $this->parsed[$i][$j];
- $index = '_value'.$j;
- $this->printer_attributes->$php_name->$index = $value;
- }
- }
- $this->parsed = array();
- }
- protected function _parseJobsAttributes()
- {
- //if ($this->serveroutput->status != "successfull-ok")
- // return false;
- $job = -1;
- $l = 0;
- for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
- {
- if ($this->serveroutput->response[$i]['attributes'] == "job-attributes")
- {
- $job ++;
- }
- $k = -1;
- for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
- {
- if (!empty($this->serveroutput->response[$i][$j]['name']))
- {
- $k++;
- $l = 0;
- $this->parsed[$job][$k]['range'] = $this->serveroutput->response[$i]['attributes'];
- $this->parsed[$job][$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
- $this->parsed[$job][$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
- $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- else
- {
- $l ++;
- $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- }
- }
- $this->serveroutput->response = array();
- $this->jobs_attributes = new \stdClass();
- for ($job_nbr = 0 ; $job_nbr <= $job ; $job_nbr ++)
- {
- $job_index = "job_".$job_nbr;
- $this->jobs_attributes->$job_index = new \stdClass();
- for ($i = 0 ; $i < count($this->parsed[$job_nbr]) ; $i ++)
- {
- $name = $this->parsed[$job_nbr][$i]['name'];
- $php_name = str_replace('-','_',$name);
- $type = $this->parsed[$job_nbr][$i]['type'];
- $range = $this->parsed[$job_nbr][$i]['range'];
- $this->jobs_attributes->$job_index->$php_name = new \stdClass();
- $this->jobs_attributes->$job_index->$php_name->_type = $type;
- $this->jobs_attributes->$job_index->$php_name->_range = $range;
- for ($j = 0 ; $j < (count($this->parsed[$job_nbr][$i]) - 3) ; $j ++)
- {
- # This causes incorrect parsing of integer job attributes.
- # 2010-08-16
- # bpkroth
- #$value = self::_interpretAttribute($name,$type,$this->parsed[$job_nbr][$i][$j]);
- $value = $this->parsed[$job_nbr][$i][$j];
- $index = '_value'.$j;
- $this->jobs_attributes->$job_index->$php_name->$index = $value;
- }
- }
- }
- $this->parsed = array();
- }
- protected function _readAttribute($attributes_type)
- {
- $tag = ord($this->serveroutput->body[$this->_parsing->offset]);
- $this->_parsing->offset += 1;
- $j = $this->index;
- $tag = self::_readTag($tag);
- switch ($tag)
- {
- case "begCollection": //RFC3382 (BLIND CODE)
- if ($this->end_collection)
- {
- $this->index --;
- }
- $this->end_collection = false;
- $this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
- self::_putDebug( "tag is: begCollection\n");
- self::_readAttributeName ($attributes_type,$j);
- if (!$this->serveroutput->response[$attributes_type][$j]['name'])
- { // it is a multi-valued collection
- $this->collection_depth ++;
- $this->index --;
- $this->collection_nbr[$this->collection_depth] ++;
- }
- else
- {
- $this->collection_depth ++;
- if ($this->collection_depth == 0)
- {
- $this->collection = (object) 'collection';
- }
- if (array_key_exists($this->collection_depth,$this->collection_nbr))
- {
- $this->collection_nbr[$this->collection_depth] ++;
- }
- else
- {
- $this->collection_nbr[$this->collection_depth] = 0;
- }
- unset($this->end_collection);
- }
- self::_readValue ("begCollection",$attributes_type,$j);
- break;
- case "endCollection": //RFC3382 (BLIND CODE)
- $this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
- self::_putDebug( "tag is: endCollection\n");
- self::_readAttributeName ($attributes_type,$j,0);
- self::_readValue ('name',$attributes_type,$j,0);
- $this->collection_depth --;
- $this->collection_key[$this->collection_depth] = 0;
- $this->end_collection = true;
- break;
- case "memberAttrName": // RFC3382 (BLIND CODE)
- $this->serveroutput->response[$attributes_type][$j]['type'] = "memberAttrName";
- $this->index -- ;
- self::_putDebug( "tag is: memberAttrName\n");
- self::_readCollection ($attributes_type,$j);
- break;
- default:
- $this->collection_depth = -1;
- $this->collection_key = array();
- $this->collection_nbr = array();
- $this->serveroutput->response[$attributes_type][$j]['type'] = $tag;
- self::_putDebug( "tag is: $tag\n");
- $attribute_name = self::_readAttributeName ($attributes_type,$j);
- if (!$attribute_name)
- {
- $attribute_name = $this->attribute_name;
- }
- else
- {
- $this->attribute_name = $attribute_name;
- }
- $value = self::_readValue ($tag,$attributes_type,$j);
- $this->serveroutput->response[$attributes_type][$j]['value'] =
- self::_interpretAttribute($attribute_name,$tag,$this->serveroutput->response[$attributes_type][$j]['value']);
- break;
- }
- return;
- }
- protected function _readTag($tag)
- {
- switch ($tag)
- {
- case 0x10:
- $tag = "unsupported";
- break;
- case 0x11:
- $tag = "reserved for 'default'";
- break;
- case 0x12:
- $tag = "unknown";
- break;
- case 0x13:
- $tag = "no-value";
- break;
- case 0x15: // RFC 3380
- $tag = "not-settable";
- break;
- case 0x16: // RFC 3380
- $tag = "delete-attribute";
- break;
- case 0x17: // RFC 3380
- $tag = "admin-define";
- break;
- case 0x20:
- $tag = "IETF reserved (generic integer)";
- break;
- case 0x21:
- $tag = "integer";
- break;
- case 0x22:
- $tag = "boolean";
- break;
- case 0x23:
- $tag = "enum";
- break;
- case 0x30:
- $tag = "octetString";
- break;
- case 0x31:
- $tag = "datetime";
- break;
- case 0x32:
- $tag = "resolution";
- break;
- case 0x33:
- $tag = "rangeOfInteger";
- break;
- case 0x34: //RFC3382 (BLIND CODE)
- $tag = "begCollection";
- break;
- case 0x35:
- $tag = "textWithLanguage";
- break;
- case 0x36:
- $tag = "nameWithLanguage";
- break;
- case 0x37: //RFC3382 (BLIND CODE)
- $tag = "endCollection";
- break;
- case 0x40:
- $tag = "IETF reserved text string";
- break;
- case 0x41:
- $tag = "textWithoutLanguage";
- break;
- case 0x42:
- $tag = "nameWithoutLanguage";
- break;
- case 0x43:
- $tag = "IETF reserved for future";
- break;
- case 0x44:
- $tag = "keyword";
- break;
- case 0x45:
- $tag = "uri";
- break;
- case 0x46:
- $tag = "uriScheme";
- break;
- case 0x47:
- $tag = "charset";
- break;
- case 0x48:
- $tag = "naturalLanguage";
- break;
- case 0x49:
- $tag = "mimeMediaType";
- break;
- case 0x4A: // RFC3382 (BLIND CODE)
- $tag = "memberAttrName";
- break;
- case 0x7F:
- $tag = "extended type";
- break;
- default:
- if ($tag >= 0x14 && $tag < 0x15 && $tag > 0x17 && $tag <= 0x1f)
- {
- $tag = "out-of-band";
- }
- elseif (0x24 <= $tag && $tag <= 0x2f)
- {
- $tag = "new integer type";
- }
- elseif (0x38 <= $tag && $tag <= 0x3F)
- {
- $tag = "new octet-stream type";
- }
- elseif (0x4B <= $tag && $tag <= 0x5F)
- {
- $tag = "new character string type";
- }
- elseif ((0x60 <= $tag && $tag < 0x7f) || $tag >= 0x80 )
- {
- $tag = "IETF reserved for future";
- }
- else
- {
- $tag = sprintf("UNKNOWN: 0x%x (%u)",$tag,$tag);
- }
- break;
- }
- return $tag;
- }
- protected function _readCollection($attributes_type,$j)
- {
- $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
- $this->_parsing->offset += 2;
- self::_putDebug( "Collection name_length ". $name_length ."\n");
- $name = '';
- for ($i = 0; $i < $name_length; $i++)
- {
- $name .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- if ($this->_parsing->offset > strlen($this->serveroutput->body))
- {
- return;
- }
- }
- $collection_name = $name;
- $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
- $this->_parsing->offset += 2;
- self::_putDebug( "Attribute name_length ". $name_length ."\n");
- $name = '';
- for ($i = 0; $i < $name_length; $i++)
- {
- $name .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- if ($this->_parsing->offset > strlen($this->serveroutput->body))
- {
- return;
- }
- }
- $attribute_name = $name;
- if ($attribute_name == "")
- {
- $attribute_name = $this->last_attribute_name;
- $this->collection_key[$this->collection_depth] ++;
- }
- else
- {
- $this->collection_key[$this->collection_depth] = 0;
- }
- $this->last_attribute_name = $attribute_name;
- self::_putDebug( "Attribute name ".$name."\n");
- $tag = self::_readTag(ord($this->serveroutput->body[$this->_parsing->offset]));
- $this->_parsing->offset ++;
- $type = $tag;
- $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
- $this->_parsing->offset += 2;
- self::_putDebug( "Collection2 name_length ". $name_length ."\n");
- $name = '';
- for ($i = 0; $i < $name_length; $i++)
- {
- $name .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- if ($this->_parsing->offset > strlen($this->serveroutput->body))
- {
- return;
- }
- }
- $collection_value = $name;
- $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
- self::_putDebug( "Collection value_length ".$this->serveroutput->body[ $this->_parsing->offset]
- . $this->serveroutput->body[$this->_parsing->offset + 1]
- .": "
- . $value_length
- . " ");
- $this->_parsing->offset += 2;
- $value = '';
- for ($i = 0; $i < $value_length; $i++)
- {
- if ($this->_parsing->offset >= strlen($this->serveroutput->body))
- {
- return;
- }
- $value .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- }
- $object = &$this->collection;
- for ($i = 0 ; $i <= $this->collection_depth ; $i ++)
- {
- $indice = "_indice".$this->collection_nbr[$i];
- if (!isset($object->$indice))
- {
- $object->$indice = (object) 'indice';
- }
- $object = &$object->$indice;
- }
- $value_key = "_value".$this->collection_key[$this->collection_depth];
- $col_name_key = "_collection_name".$this->collection_key[$this->collection_depth];
- $col_val_key = "_collection_value".$this->collection_key[$this->collection_depth];
- $attribute_value = self::_interpretAttribute($attribute_name,$tag,$value);
- $attribute_name = str_replace('-','_',$attribute_name);
- self::_putDebug( sprintf("Value: %s\n",$value));
- $object->$attribute_name->_type = $type;
- $object->$attribute_name->$value_key = $attribute_value;
- $object->$attribute_name->$col_name_key = $collection_name;
- $object->$attribute_name->$col_val_key = $collection_value;
- $this->serveroutput->response[$attributes_type][$j]['value'] = $this->collection;
- }
- protected function _readAttributeName ($attributes_type,$j,$write=1)
- {
- $name_length = ord($this->serveroutput->body[ $this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
- $this->_parsing->offset += 2;
- self::_putDebug( "name_length ". $name_length ."\n");
- $name = '';
- for ($i = 0; $i < $name_length; $i++)
- {
- if ($this->_parsing->offset >= strlen($this->serveroutput->body))
- {
- return;
- }
- $name .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- }
- if($write)
- {
- $this->serveroutput->response[$attributes_type][$j]['name'] = $name;
- }
- self::_putDebug( "name " . $name . "\n");
- return $name;
- }
- protected function _readValue ($type,$attributes_type,$j,$write=1)
- {
- $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256
- + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
-
- self::_putDebug( "value_length ".$this->serveroutput->body[ $this->_parsing->offset]
- . $this->serveroutput->body[$this->_parsing->offset + 1]
- .": "
- . $value_length
- . " ");
- $this->_parsing->offset += 2;
- $value = '';
- for ($i = 0; $i < $value_length; $i++)
- {
- if ($this->_parsing->offset >= strlen($this->serveroutput->body))
- {
- return;
- }
- $value .= $this->serveroutput->body[$this->_parsing->offset];
- $this->_parsing->offset += 1;
- }
- self::_putDebug( sprintf("Value: %s\n",$value));
- if ($write)
- {
- $this->serveroutput->response[$attributes_type][$j]['value'] = $value;
- }
- return $value;
- }
- protected function _parseAttributes()
- {
- $k = -1;
- $l = 0;
- for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
- {
- for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
- {
- if (!empty($this->serveroutput->response[$i][$j]['name']))
- {
- $k++;
- $l = 0;
- $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
- $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
- $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- else
- {
- $l ++;
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- }
- }
- $this->serveroutput->response = array();
- $this->attributes = new \stdClass();
- for ($i = 0 ; $i < count($this->parsed) ; $i ++)
- {
- $name = $this->parsed[$i]['name'];
- $php_name = str_replace('-','_',$name);
- $type = $this->parsed[$i]['type'];
- $range = $this->parsed[$i]['range'];
- $this->attributes->$php_name = new \stdClass();
- $this->attributes->$php_name->_type = $type;
- $this->attributes->$php_name->_range = $range;
- for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
- {
- $value = $this->parsed[$i][$j];
- $index = '_value'.$j;
- $this->attributes->$php_name->$index = $value;
- }
- }
- $this->parsed = array();
- }
- protected function _parseJobAttributes()
- {
- //if (!preg_match('#successful#',$this->serveroutput->status))
- // return false;
- $k = -1;
- $l = 0;
- for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
- {
- for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
- {
- if (!empty($this->serveroutput->response[$i][$j]['name']))
- {
- $k++;
- $l = 0;
- $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
- $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
- $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- else
- {
- $l ++;
- $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
- }
- }
- }
- $this->serveroutput->response = array();
- $this->job_attributes = new \stdClass();
- for ($i = 0 ; $i < count($this->parsed) ; $i ++)
- {
- $name = $this->parsed[$i]['name'];
- $php_name = str_replace('-','_',$name);
- $type = $this->parsed[$i]['type'];
- $range = $this->parsed[$i]['range'];
- $this->job_attributes->$php_name = new \stdClass();
- $this->job_attributes->$php_name->_type = $type;
- $this->job_attributes->$php_name->_range = $range;
- for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
- {
- $value = $this->parsed[$i][$j];
- $index = '_value'.$j;
- $this->job_attributes->$php_name->$index = $value;
- }
- }
- $this->parsed = array();
- }
- protected function _interpretAttribute($attribute_name,$type,$value)
- {
- switch ($type)
- {
- case "integer":
- $value = self::_interpretInteger($value);
- break;
- case "rangeOfInteger":
- $value = self::_interpretRangeOfInteger($value);
- break;
- case 'boolean':
- $value = ord($value);
- if ($value == 0x00)
- {
- $value = 'false';
- }
- else
- {
- $value = 'true';
- }
- break;
- case 'datetime':
- $value = self::_interpretDateTime($value);
- break;
- case 'enum':
- $value = $this->_interpretEnum($attribute_name,$value); // must be overwritten by children
- break;
- case 'resolution':
- $unit = $value[8];
- $value = self::_interpretRangeOfInteger(substr($value,0,8));
- switch($unit)
- {
- case chr(0x03):
- $unit = "dpi";
- break;
- case chr(0x04):
- $unit = "dpc";
- break;
- }
- $value = $value." ".$unit;
- break;
- default:
- break;
- }
- return $value;
- }
- protected function _interpretRangeOfInteger($value)
- {
- $value_parsed = 0;
- $integer1 = $integer2 = 0;
- $halfsize = strlen($value) / 2;
- $integer1 = self::_interpretInteger(substr($value,0,$halfsize));
- $integer2 = self::_interpretInteger(substr($value,$halfsize,$halfsize));
- $value_parsed = sprintf('%s-%s',$integer1,$integer2);
- return $value_parsed;
- }
- protected function _interpretDateTime($date)
- {
- $year = self::_interpretInteger(substr($date,0,2));
- $month = self::_interpretInteger(substr($date,2,1));
- $day = self::_interpretInteger(substr($date,3,1));
- $hour = self::_interpretInteger(substr($date,4,1));
- $minute = self::_interpretInteger(substr($date,5,1));
- $second = self::_interpretInteger(substr($date,6,1));
- $direction = substr($date,8,1);
- $hours_from_utc = self::_interpretInteger(substr($date,9,1));
- $minutes_from_utc = self::_interpretInteger(substr($date,10,1));
- $date = sprintf('%s-%s-%s %s:%s:%s %s%s:%s',$year,$month,$day,$hour,$minute,$second,$direction,$hours_from_utc,$minutes_from_utc);
- return $date;
- }
- protected function _interpretEnum($attribute_name,$value)
- {
- $value_parsed = self::_interpretInteger($value);
- switch ($attribute_name)
- {
- case 'job-state':
- switch ($value_parsed)
- {
- case 0x03:
- $value = 'pending';
- break;
- case 0x04:
- $value = 'pending-held';
- break;
- case 0x05:
- $value = 'processing';
- break;
- case 0x06:
- $value = 'processing-stopped';
- break;
- case 0x07:
- $value = 'canceled';
- break;
- case 0x08:
- $value = 'aborted';
- break;
- case 0x09:
- $value = 'completed';
- break;
- }
- if ($value_parsed > 0x09)
- {
- $value = sprintf('Unknown(IETF standards track "job-state" reserved): 0x%x',$value_parsed);
- }
- break;
- case 'print-quality':
- case 'print-quality-supported':
- case 'print-quality-default':
- switch ($value_parsed)
- {
- case 0x03:
- $value = 'draft';
- break;
- case 0x04:
- $value = 'normal';
- break;
- case 0x05:
- $value = 'high';
- break;
- }
- break;
- case 'printer-state':
- switch ($value_parsed)
- {
- case 0x03:
- $value = 'idle';
- break;
- case 0x04:
- $value = 'processing';
- break;
- case 0x05:
- $value = 'stopped';
- break;
- }
- if ($value_parsed > 0x05)
- {
- $value = sprintf('Unknown(IETF standards track "printer-state" reserved): 0x%x',$value_parsed);
- }
- break;
- case 'operations-supported':
- switch($value_parsed)
- {
- case 0x0000:
- case 0x0001:
- $value = sprintf('Unknown(reserved) : %s',ord($value));
- break;
- case 0x0002:
- $value = 'Print-Job';
- break;
- case 0x0003:
- $value = 'Print-URI';
- break;
- case 0x0004:
- $value = 'Validate-Job';
- break;
- case 0x0005:
- $value = 'Create-Job';
- break;
- case 0x0006:
- $value = 'Send-Document';
- break;
- case 0x0007:
- $value = 'Send-URI';
- break;
- case 0x0008:
- $value = 'Cancel-Job';
- break;
- case 0x0009:
- $value = 'Get-Job-Attributes';
- break;
- case 0x000A:
- $value = 'Get-Jobs';
- break;
- case 0x000B:
- $value = 'Get-Printer-Attributes';
- break;
- case 0x000C:
- $value = 'Hold-Job';
- break;
- case 0x000D:
- $value = 'Release-Job';
- break;
- case 0x000E:
- $value = 'Restart-Job';
- break;
- case 0x000F:
- $value = 'Unknown(reserved for a future operation)';
- break;
- case 0x0010:
- $value = 'Pause-Printer';
- break;
- case 0x0011:
- $value = 'Resume-Printer';
- break;
- case 0x0012:
- $value = 'Purge-Jobs';
- break;
- case 0x0013:
- $value = 'Set-Printer-Attributes'; // RFC3380
- break;
- case 0x0014:
- $value = 'Set-Job-Attributes'; // RFC3380
- break;
- case 0x0015:
- $value = 'Get-Printer-Supported-Values'; // RFC3380
- break;
- case 0x0016:
- $value = 'Create-Printer-Subscriptions';
- break;
- case 0x0017:
- $value = 'Create-Job-Subscriptions';
- break;
- case 0x0018:
- $value = 'Get-Subscription-Attributes';
- break;
- case 0x0019:
- $value = 'Get-Subscriptions';
- break;
- case 0x001A:
- $value = 'Renew-Subscription';
- break;
- case 0x001B:
- $value = 'Cancel-Subscription';
- break;
- case 0x001C:
- $value = 'Get-Notifications';
- break;
- case 0x001D:
- $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
- break;
- case 0x001E:
- $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
- break;
- case 0x001F:
- $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
- break;
- case 0x0020:
- $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
- break;
- case 0x0021:
- $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
- break;
- case 0x0022:
- $value = 'Enable-Printer';
- break;
- case 0x0023:
- $value = 'Disable-Printer';
- break;
- case 0x0024:
- $value = 'Pause-Printer-After-Current-Job';
- break;
- case 0x0025:
- $value = 'Hold-New-Jobs';
- break;
- case 0x0026:
- $value = 'Release-Held-New-Jobs';
- break;
- case 0x0027:
- $value = 'Deactivate-Printer';
- break;
- case 0x0028:
- $value = 'Activate-Printer';
- break;
- case 0x0029:
- $value = 'Restart-Printer';
- break;
- case 0x002A:
- $value = 'Shutdown-Printer';
- break;
- case 0x002B:
- $value = 'Startup-Printer';
- break;
- }
- if ($value_parsed > 0x002B && $value_parsed <= 0x3FFF)
- {
- $value = sprintf('Unknown(IETF standards track operations reserved): 0x%x',$value_parsed);
- }
- elseif ($value_parsed >= 0x4000 && $value_parsed <= 0x8FFF)
- {
- if (method_exists($this,'_getEnumVendorExtensions'))
- {
- $value = $this->_getEnumVendorExtensions($value_parsed);
- }
- else
- {
- $value = sprintf('Unknown(Vendor extension for operations): 0x%x',$value_parsed);
- }
- }
- elseif ($value_parsed > 0x8FFF)
- {
- $value = sprintf('Unknown operation (should not exists): 0x%x',$value_parsed);
- }
- break;
- case 'finishings':
- case 'finishings-default':
- case 'finishings-supported':
- switch ($value_parsed)
- {
- case 3:
- $value = 'none';
- break;
- case 4:
- $value = 'staple';
- break;
- case 5:
- $value = 'punch';
- break;
- case 6:
- $value = 'cover';
- break;
- case 7:
- $value = 'bind';
- break;
- case 8:
- $value = 'saddle-stitch';
- break;
- case 9:
- $value = 'edge-stitch';
- break;
- case 20:
- $value = 'staple-top-left';
- break;
- case 21:
- $value = 'staple-bottom-left';
- break;
- case 22:
- $value = 'staple-top-right';
- break;
- case 23:
- $value = 'staple-bottom-right';
- break;
- case 24:
- $value = 'edge-stitch-left';
- break;
- case 25:
- $value = 'edge-stitch-top';
- break;
- case 26:
- $value = 'edge-stitch-right';
- break;
- case 27:
- $value = 'edge-stitch-bottom';
- break;
- case 28:
- $value = 'staple-dual-left';
- break;
- case 29:
- $value = 'staple-dual-top';
- break;
- case 30:
- $value = 'staple-dual-right';
- break;
- case 31:
- $value = 'staple-dual-bottom';
- break;
- }
- if ($value_parsed > 31)
- {
- $value = sprintf('Unknown(IETF standards track "finishing" reserved): 0x%x',$value_parsed);
- }
- break;
- case 'orientation-requested':
- case 'orientation-requested-supported':
- case 'orientation-requested-default':
- switch ($value_parsed)
- {
- case 0x03:
- $value = 'portrait';
- break;
- case 0x04:
- $value = 'landscape';
- break;
- case 0x05:
- $value = 'reverse-landscape';
- break;
- case 0x06:
- $value = 'reverse-portrait';
- break;
- }
- if ($value_parsed > 0x06)
- {
- $value = sprintf('Unknown(IETF standards track "orientation" reserved): 0x%x',$value_parsed);
- }
- break;
- default:
- break;
- }
- return $value;
- }
- protected function _getJobId ()
- {
- if (!isset($this->serveroutput->response))
- {
- $this->jobs = array_merge($this->jobs,array('NO JOB'));
- }
- $jobfinded = false;
- for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
- {
- if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
- {
- for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
- {
- if ($this->serveroutput->response[$i][$j]['name'] == "job-id")
- {
- $this->last_job = $this->serveroutput->response[$i][$j]['value'];
- $this->jobs = array_merge($this->jobs,array($this->serveroutput->response[$i][$j]['value']));
- return;
- }
- }
- }
- }
- }
- protected function _getJobUri ()
- {
- if (!isset($this->jobs_uri))
- {
- $this->jobs_uri = array();
- }
- $jobfinded = false;
- for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
- {
- if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
- {
- for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
- {
- if ($this->serveroutput->response[$i][$j]['name'] == "job-uri")
- {
- $this->last_job = $this->serveroutput->response[$i][$j]['value'];
- $this->jobs_uri = array_merge($this->jobs_uri,array($this->last_job));
- return;
- }
- }
- }
- }
- $this->last_job = '';
- }
- protected function _parseResponse ()
- {
- $j = -1;
- $this->index = 0;
- for ($i = $this->_parsing->offset; $i < strlen($this->serveroutput->body) ; $i = $this->_parsing->offset)
- {
- $tag = ord($this->serveroutput->body[$this->_parsing->offset]);
- if ($tag > 0x0F)
- {
- self::_readAttribute($j);
- $this->index ++;
- continue;
- }
- switch ($tag)
- {
- case 0x01:
- $j += 1;
- $this->serveroutput->response[$j]['attributes'] = "operation-attributes";
- $this->index = 0;
- $this->_parsing->offset += 1;
- break;
- case 0x02:
- $j += 1;
- $this->serveroutput->response[$j]['attributes'] = "job-attributes";
- $this->index = 0;
- $this->_parsing->offset += 1;
- break;
- case 0x03:
- $j +=1;
- $this->serveroutput->response[$j]['attributes'] = "end-of-attributes";
- self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n");
- if ($this->alert_on_end_tag === 1)
- {
- echo "END tag OK<br />";
- }
- $this->response_completed[(count($this->response_completed) -1)] = "completed";
- return;
- case 0x04:
- $j += 1;
- $this->serveroutput->response[$j]['attributes'] = "printer-attributes";
- $this->index = 0;
- $this->_parsing->offset += 1;
- break;
- case 0x05:
- $j += 1;
- $this->serveroutput->response[$j]['attributes'] = "unsupported-attributes";
- $this->index = 0;
- $this->_parsing->offset += 1;
- break;
- default:
- $j += 1;
- $this->serveroutput->response[$j]['attributes'] = sprintf(_("0x%x (%u) : attributes tag Unknown (reserved for future versions of IPP"),$tag,$tag);
- $this->index = 0;
- $this->_parsing->offset += 1;
- break;
- }
- self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n\n\n");
- }
- return;
- }
- /*
- // NOTICE : HAVE TO READ AGAIN RFC 2911 TO SEE IF IT IS PART OF SERVER'S RESPONSE (CUPS DO NOT)
- protected function _getPrinterUri () {
- for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
- if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
- for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
- if ($this->serveroutput->response[$i][$j]['name'] == "printer-uri") {
- $this->printers_uri = array_merge($this->printers_uri,array($this->serveroutput->response[$i][$j]['value']));
- return;
-
- }
- $this->printers_uri = array_merge($this->printers_uri,array(''));
-
- }
- */
- // REQUEST BUILDING
- protected function _stringCancel ($job_uri)
- {
-
- if (!isset($this->setup->charset))
- {
- self::setCharset();
- }
- if (!isset($this->setup->datatype))
- {
- self::setBinary();
- }
- if (!isset($this->setup->language))
- {
- self::setLanguage('en_us');
- }
- if (!$this->requesting_user)
- {
- self::setUserName();
- }
- if (!isset($this->meta->message))
- {
- $this->meta->message = '';
- }
- self::_setOperationId();
- self::_setJobUri($job_uri);
- if (!isset($this->error_generation->request_body_malformed))
- {
- $this->error_generation->request_body_malformed = "";
- }
- $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
- . chr(0x00) . chr (0x08) // cancel-Job | operation-id
- . $this->meta->operation_id // request-id
- . $this->error_generation->request_body_malformed
- . chr(0x01) // start operation-attributes | operation-attributes-tag
- . $this->meta->charset
- . $this->meta->language
- . $this->meta->job_uri
- . $this->meta->username
- . $this->meta->message
- . chr(0x03); // end-of-attributes | end-of-attributes-tag
-
- self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
- return TRUE;
- }
- }
|