"Fossies" - the Fresh Open Source Software Archive 
Member "npadmin-0.14/printmib.C" (22 Nov 2002, 47386 Bytes) of package /linux/misc/old/npadmin-0.14.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* Copyright (c) 2000 Ben Woodard
2 * All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public Licence
6 * as published by the Free Software Foundation; either version 2
7 * of the Licence, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRENTY; without even the implied warrenty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public Licence in the COPYING file for more
13 * details.
14 *
15 * You should have received a copy of the GNU Library General
16 * Public License along with the GNU C Library; see the file
17 * COPYING.LIB. If not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <stdio.h>
24 #include <limits.h>
25 #include <time.h>
26
27 #include "printmib.h"
28 #include "npaconsts.h"
29 #include "npastructs.h"
30 #include "npaoids.h"
31 #include "argflags.h"
32 #include "npahelpers.h"
33
34 #define MAXSTR 512
35
36 extern char *progname;
37
38 static MarkerTable BMTID;
39 static MediaPathInfo BMPID;
40 static InputTrayInfo BITID;
41 static CoverTable BCTID;
42 static LangInfo BLTID;
43 static ProtocolTable BPTID;
44 static MarkerSuppliesTable BMSTID;
45 static AlertTable BATID;
46
47 static const char OTHERSTR[]="other";
48 static const char UNKNOWNSTR[]="unknown";
49 static const char TENTHOUSANDTHSOFINCHES[]="tenThousandthsOfInches";
50 static const char MICROMETERS[]="micrometers";
51 static const char IMPRESSIONS[]="impressions";
52 static const char SHEETS[]="sheets";
53 static const char HOURS[]="hours";
54
55 static const char *MARKTECH[]={
56 NULL,OTHERSTR,UNKNOWNSTR,"electrophotographicLED",
57 "electrophotographicLaser","electrophotographicOther",
58 "impactMovingHeadDotMatrix9pin","impactMovingHeadDotMatrix24pin",
59 "impactMovingHeadDotMatrixOther","impactMovingHeadFullyFormed",
60 "impactBand","impactOther","inkjetAqueous","inkjetSolid",
61 "inkjetOther","pen","thermalTransfer","thermalSensitive",
62 "thermalDiffusion", "thermalOther","electroerosion",
63 "electrostatic","photographicMicrofiche",
64 "photographicImagesetter","photographicOther","ionDeposition",
65 "eBeam","typesetter"};
66
67 static const char *MARKERCOUNTERUNIT[]={
68 NULL,NULL,NULL,TENTHOUSANDTHSOFINCHES,MICROMETERS,"characters","lines",
69 IMPRESSIONS,SHEETS,"dotRow",NULL,HOURS,NULL,NULL,NULL,NULL,"feet",
70 "meters"};
71
72 static const char *MEDIAUNIT[]={
73 NULL,NULL,NULL,TENTHOUSANDTHSOFINCHES,MICROMETERS};
74
75 /* xxx check input tray & marker processing code before you
76 change this. */
77 static const char *MEDIASPEEDUNIT[]={
78 NULL,NULL,NULL,"tenThousandthsOfInchesPerHour",
79 "micrometersPerHour","charactersPerHour","linesPerHour",
80 "impressionsPerHour","sheetsPerHour","dotRowPerHour",NULL,
81 NULL,NULL,NULL,NULL,NULL,"feetPerHour","metersPerHour"};
82
83 static const char *MEDIATYPE[]={
84 NULL,OTHERSTR,UNKNOWNSTR,"longEdgeBindingDuplex",
85 "shortEdgeBindingDuplex","simplex"};
86 static const char *INPUTTYPE[]={
87 NULL,OTHERSTR,UNKNOWNSTR,"sheetFeedAutoRemovableTray",
88 "sheetFeedAutoNonRemovableTray","sheetFeedManual",
89 "continuousRoll","continuousFanFold"};
90 static const char *CAPACITYUNIT[]={
91 NULL,NULL,NULL,TENTHOUSANDTHSOFINCHES,MICROMETERS,NULL,NULL,NULL,SHEETS,NULL,
92 NULL,NULL,NULL,NULL,NULL,NULL,"feet","meters"};
93 static const char *LANGUAGES[]={
94 NULL,OTHERSTR,NULL,"PCL","HPGL","PJL","PS","IDPS","PPDS","EscapeP",
95 "Epson","DDIF","Interpress","ISO6429","LineData","MODCA","REGIS",
96 "SCS","SPDL","TEK401","PDS","IGP","CodeV","DSCDSE","WPS","LN03",
97 "CCITT","QUIC","CPAP","DecPPL","SimpleText","NPAP","DOC","imPress",
98 "Pinwriter","NPDL","NEC201PL","Automatic","Pages","LIPS","TIFF",
99 "Diagnostic","PSPrinter","CaPSL","EXCL","LCDS","XES","PCLXL"};
100 static const char *ORIENTATIONS[]={
101 NULL,OTHERSTR,NULL,"portrait","landscape"};
102 static const char *COVERSTATUS[]={
103 NULL,OTHERSTR,NULL,"doorOpen","doorClosed","interlockOpen",
104 "interlockClosed"};
105 static const char *CHANNELTYPE[]={
106 NULL,OTHERSTR,NULL,"SerialPort","ParallelPort","IEEE1284Port",
107 "SCSIPort","AppleTalkPAP","LPDServer","NetwareRPrinter",
108 "NetwarePServer","Port9100(depricated)","AppSocket","FTP","TFTP",
109 "DLCLLCPort","IBM3270","IBM5250","Fax","IEEE1394","Transport1",
110 "CPAP",NULL,NULL,NULL,NULL,"PCPrint","ServerMessageBlock","PSM",NULL,
111 NULL,"SystemObjectManager","DECLAT","NPAP","USB","IRDA",
112 "PrintXChange","PortTCP","BidirPortTCP","UNPP","AppleTalkADSP",
113 "PortSPX","PortHTTP","NDPS"};
114 static const char *CHANNELSTATE[]={
115 NULL,OTHERSTR,NULL,"printDataAccepted","noDataAccepted"};
116 static const char *MARKERSUPPLIESCLASS[]={
117 NULL,OTHERSTR,NULL,"supplyThatIsConsumed","receptacleThatIsFilled"};
118 static const char *MARKERSUPPLIESTYPE[]={
119 NULL,OTHERSTR,UNKNOWNSTR,"toner","wasteToner","ink","inkCartridge",
120 "inkRibbon","wasteInk","opc","developer","fuserOil","solidWax",
121 "ribbonWax","wasteWax","fuser","coronaWire","fuserOilWick",
122 "cleanerUnit","fuserCleaningPad","transferUnit","tonerCartridge",
123 "fuserOiler"};
124 static const char *MARKERSUPPLIESSUPPLYUNIT[]={
125 NULL,NULL,NULL,TENTHOUSANDTHSOFINCHES,MICROMETERS,NULL,NULL,IMPRESSIONS,
126 SHEETS,NULL,HOURS,NULL,"thousandthsOfOunces","tenthsOfGrams",
127 "hundrethsOfFluidOunces","tenthsOfMilliliters","feet","meters"};
128 static const char *PRTALERTSEVERITYLEVEL[]={
129 NULL,OTHERSTR,NULL,"critical","warning","warningBinaryChangeEvent"};
130 static const char *PRTALERTTRAININGLEVEL[]={
131 NULL,OTHERSTR,UNKNOWNSTR,"untrained","trained","fieldService",
132 "management"};
133 static const char *PRTALERTGROUP[]={
134 NULL,OTHERSTR,NULL,"hostResourcesMIBStorageTable",
135 "hostResourcesMIBDeviceTable","generalPrinter","cover",
136 "localization","input","output","marker","markerSupplies",
137 "markerColorant","mediaPath","channel","interpreter",
138 "consoleDisplayBuffer","consoleLights"};
139
140 // All the values <100 indexes 0-38
141 static const char *ALERTCODES[]={
142 NULL,"other","unknown","coverOpen","coverClosed","interlockOpen",
143 "interlockClosed","configurationChange","jammed",
144 "subunitMissing","subunitLifeAlmostOver","subunitLifeOver",
145 "subunitAlmostEmpty","subunitEmpty","subunitAlmostFull",
146 "subunitFull","subunitNearLimit","subunitAtLimit",
147 "subunitOpened","subunitClosed","subunitTurnedOn",
148 "subunitTurnedOff","subunitOffline","subunitPowerSaver",
149 "subunitWarmingUp","subunitAdded","subunitRemoved",
150 "subunitResourceAdded","subunitResourceRemoved",
151 "subunitRecoverableFailure","subunitUnrecoverableFailure",
152 "subunitRecoverableStorageError",
153 "subunitUnrecoverableStorageError","subunitMotorFailure",
154 "subunitMemoryExhausted","subunitUnderTemperature",
155 "subunitOverTemperature","subunitTimingFailure",
156 "subunitThermistorFailure",
157
158 // all the values in the 500's indexes 39-45
159 "doorOpen","doorClosed","powerUp","powerDown","printerNMSReset",
160 "printerManualReset","printerReadyToPrint",
161
162 // all the values in the 800's indexes 46-58
163 "inputMediaTrayMissing","inputMediaSizeChange",
164 "inputMediaWeightChange","inputMediaTypeChange",
165 "inputMediaColorChange","inputMediaFormPartsChange",
166 "inputMediaSupplyLow","inputMediaSupplyEmpty",
167 "inputMediaChangeRequest","inputManualInputRequest",
168 "inputTrayPositionFailure","inputTrayElevationFailure",
169 "inputCannotFeedSizeSelected",
170
171 // all the values in the 900's indexes 59-62
172 "outputMediaTrayMissing","outputMediaTrayAlmostFull",
173 "outputMediaTrayFull","outputMailboxSelectFailure",
174
175 // all the values in the 1000's indexes 63-67
176 "markerFuserUnderTemperature","markerFuserOverTemperature",
177 "markerFuserTimingFailure","markerFuserThermistorFailure",
178 "markerAdjustingPrintQuality",
179
180 // all the values in the 1100's indexes 68-82
181 "markerTonerEmpty","markerInkEmpty","markerPrintRibbonEmpty",
182 "markerTonerAlmostEmpty","markerInkAlmostEmpty",
183 "markerPrintRibbonAlmostEmpty",
184 "markerWasteTonerReceptacleAlmostFull",
185 "markerWasteInkReceptacleAlmostFull",
186 "markerWasteTonerReceptacleFull",
187 "markerWasteInkReceptacleFull",
188 "markerOpcLifeAlmostOver","markerOpcLifeOver",
189 "markerDeveloperAlmostEmpty","markerDeveloperEmpty",
190 "markerTonerCartridgeMissing",
191
192 // all the values in the 1300's indexes 83-85
193 "mediaPathMediaTrayMissing","mediaPathMediaTrayAlmostFull",
194 "mediaPathMediaTrayFull",
195
196 // all the values in the 1500's indexes 86-93
197 "interpreterMemoryIncrease","interpreterMemoryDecrease",
198 "interpreterCartridgeAdded","interpreterCartridgeDeleted",
199 "interpreterResourceAdded","interpreterResourceDeleted",
200 "interpreterResourceUnavailable",
201 "interpreterComplexPageEncountered",
202
203 // all the values in the 1800's indexes 94
204 "alertRemovalOfBinaryChangeEntry"};
205
206 static char SYSUPTIME[]=_SYSUPTIME_;
207 static char PRTMEDIAPATHMAXSPEEDPRINTUNIT_BASE[]=_PRTMEDIAPATHMAXSPEEDPRINTUNIT_BASE_;
208 static char PRTMEDIAPATHMEDIASIZEUNIT_BASE[]=_PRTMEDIAPATHMEDIASIZEUNIT_BASE_;
209 static char PRTMEDIAPATHMAXMEDIAFEEDDIR_BASE[]=_PRTMEDIAPATHMAXMEDIAFEEDDIR_BASE_;
210 static char PRTMEDIAPATHMAXMEDIAXFEEDDIR_BASE[]=_PRTMEDIAPATHMAXMEDIAXFEEDDIR_BASE_;
211 static char PRTMEDIAPATHMINMEDIAFEEDDIR_BASE[]=_PRTMEDIAPATHMINMEDIAFEEDDIR_BASE_;
212 static char PRTMEDIAPATHMINMEDIAXFEEDDIR_BASE[]=_PRTMEDIAPATHMINMEDIAXFEEDDIR_BASE_;
213 static char PRTMEDIAPATHTYPE_BASE[]=_PRTMEDIAPATHTYPE_BASE_;
214 static char PRTMEDIAPATHDESCRIPTION_BASE[]=_PRTMEDIAPATHDESCRIPTION_BASE_;
215 static char PRTMEDIAPATHSTATUS_BASE[]=_PRTMEDIAPATHSTATUS_BASE_;
216 static char PRTCONSOLEDISPLAYBUFFERTEXT_BASE[]=_PRTCONSOLEDISPLAYBUFFERTEXT_BASE_;
217 static char PRTINPUTTYPE_BASE[]=_PRTINPUTTYPE_BASE_;
218 static char PRTINPUTDIMUNIT_BASE[]=_PRTINPUTDIMUNIT_BASE_;
219 static char PRTINPUTMEDIADIMFEEDDIRCHOSEN_BASE[]=_PRTINPUTMEDIADIMFEEDDIRCHOSEN_BASE_;
220 static char PRTINPUTMEDIADIMXFEEDDIRCHOSEN_BASE[]=_PRTINPUTMEDIADIMXFEEDDIRCHOSEN_BASE_;
221 static char PRTINPUTCAPACITYUNIT_BASE[]=_PRTINPUTCAPACITYUNIT_BASE_;
222 static char PRTINPUTMAXCAPACITY_BASE[]=_PRTINPUTMAXCAPACITY_BASE_;
223 static char PRTINPUTCURRENTLEVEL_BASE[]=_PRTINPUTCURRENTLEVEL_BASE_;
224 static char PRTINPUTINPUTSTATUS_BASE[]=_PRTINPUTINPUTSTATUS_BASE_;
225 static char PRTINPUTMEDIANAME_BASE[]=_PRTINPUTMEDIANAME_BASE_;
226 static char PRTINPUTNAME_BASE[]=_PRTINPUTNAME_BASE_;
227 static char PRTINPUTINPUTDESCRIPTION_BASE[]=_PRTINPUTINPUTDESCRIPTION_BASE_;
228 static char PRTINTERPRETERLANGFAMILY_BASE[]=_PRTINTERPRETERLANGFAMILY_BASE_;
229 static char PRTINTERPRETERLANGLEVEL_BASE[]=_PRTINTERPRETERLANGLEVEL_BASE_;
230 static char PRTINTERPRETERLANGVERSION_BASE[]=_PRTINTERPRETERLANGVERSION_BASE_;
231 static char PRTINTERPRETERDESCRIPTION_BASE[]=_PRTINTERPRETERDESCRIPTION_BASE_;
232 static char PRTINTERPRETERVERSION_BASE[]=_PRTINTERPRETERVERSION_BASE_;
233 static char PRTINTERPRETERDEFAULTORIENTATION_BASE[]=_PRTINTERPRETERDEFAULTORIENTATION_BASE_;
234 static char PRTINTERPRETERFEEDADDRESSABILITY_BASE[]=_PRTINTERPRETERFEEDADDRESSABILITY_BASE_;
235 static char PRTINTERPRETERXFEEDADDRESSABILITY_BASE[]=_PRTINTERPRETERXFEEDADDRESSABILITY_BASE_;
236 static char PRTINTERPRETERTWOWAY_BASE[]=_PRTINTERPRETERTWOWAY_BASE_;
237 static char PRTCOVERDESCRIPTION_BASE[]=_PRTCOVERDESCRIPTION_BASE_;
238 static char PRTCOVERSTATUS_BASE[]=_PRTCOVERSTATUS_BASE_;
239 static char PRTCHANNELTYPE_BASE[]=_PRTCHANNELTYPE_BASE_;
240 static char PRTCHANNELPROTOCOLVERSION_BASE[]=_PRTCHANNELPROTOCOLVERSION_BASE_;
241 static char PRTCHANNELCURRENTJOBCNTLLANGINDEX_BASE[]=_PRTCHANNELCURRENTJOBCNTLLANGINDEX_BASE_;
242 static char PRTCHANNELDEFAULTPAGEDESCLANGINDEX_BASE[]=_PRTCHANNELDEFAULTPAGEDESCLANGINDEX_BASE_;
243 static char PRTCHANNELSTATE_BASE[]=_PRTCHANNELSTATE_BASE_;
244 static char PRTCHANNELSTATUS_BASE[]=_PRTCHANNELSTATUS_BASE_;
245 static char PRTMARKERMARKTECH_BASE[]=_PRTMARKERMARKTECH_BASE_;
246 static char PRTMARKERCOUNTERUNITS_BASE[]=_PRTMARKERCOUNTERUNITS_BASE_;
247 static char PRTMARKERLIFECOUNT_BASE[]=_PRTMARKERLIFECOUNT_BASE_;
248 static char PRTMARKERPROCESSCOLORANTS_BASE[]=_PRTMARKERPROCESSCOLORANTS_BASE_;
249 static char PRTMARKERADDRESSABILITYUNIT_BASE[]=_PRTMARKERADDRESSABILITYUNIT_BASE_;
250 static char PRTMARKERADDRESSABILITYFEEDDIR_BASE[]=_PRTMARKERADDRESSABILITYFEEDDIR_BASE_;
251 static char PRTMARKERADDRESSABILITYXFEEDDIR_BASE[]=_PRTMARKERADDRESSABILITYXFEEDDIR_BASE_;
252 static char PRTMARKERNORTHMARGIN_BASE[]=_PRTMARKERNORTHMARGIN_BASE_;
253 static char PRTMARKERSOUTHMARGIN_BASE[]=_PRTMARKERSOUTHMARGIN_BASE_;
254 static char PRTMARKERWESTMARGIN_BASE[]=_PRTMARKERWESTMARGIN_BASE_;
255 static char PRTMARKEREASTMARGIN_BASE[]=_PRTMARKEREASTMARGIN_BASE_;
256 static char PRTMARKERSTATUS_BASE[]=_PRTMARKERSTATUS_BASE_;
257 // static char PRTMARKERSUPPLIESCOLORANTINDEX_BASE[]=_PRTMARKERSUPPLIESCOLORANTINDEX_BASE_;
258 static char PRTMARKERSUPPLIESCLASS_BASE[]=_PRTMARKERSUPPLIESCLASS_BASE_;
259 static char PRTMARKERSUPPLIESTYPE_BASE[]=_PRTMARKERSUPPLIESTYPE_BASE_;
260 static char PRTMARKERSUPPLIESDESCRIPTION_BASE[]=_PRTMARKERSUPPLIESDESCRIPTION_BASE_;
261 static char PRTMARKERSUPPLIESSUPPLYUNIT_BASE[]=_PRTMARKERSUPPLIESSUPPLYUNIT_BASE_;
262 static char PRTMARKERSUPPLIESMAXCAPACITY_BASE[]=_PRTMARKERSUPPLIESMAXCAPACITY_BASE_;
263 static char PRTMARKERSUPPLIESLEVEL_BASE[]=_PRTMARKERSUPPLIESLEVEL_BASE_;
264 static char PRTALERTSEVERITYLEVEL_BASE[]=_PRTALERTSEVERITYLEVEL_BASE_;
265 static char PTRALERTTRAININGLEVEL_BASE[]=_PTRALERTTRAININGLEVEL_BASE_;
266 static char PRTALERTGROUP_BASE[]=_PRTALERTGROUP_BASE_;
267 static char PRTALERTGROUPINDEX_BASE[]=_PRTALERTGROUPINDEX_BASE_;
268 static char PRTALERTLOCATION_BASE[]=_PRTALERTLOCATION_BASE_;
269 static char PRTALERTCODE_BASE[]=_PRTALERTCODE_BASE_;
270 static char PRTALERTDESCRIPTION_BASE[]=_PRTALERTDESCRIPTION_BASE_;
271 static char PRTALERTTIME_BASE[]=_PRTALERTTIME_BASE_;
272 static char PRTGENERALRESET[]=_PRTGENERALRESET_;
273 static char PRTMEDIAPATHMAXSPEED_BASE[]=_PRTMEDIAPATHMAXSPEED_BASE_;
274 static char PRTGENERALSERIALNUMBER[]=_PRTGENERALSERIALNUMBER_;
275
276 const char *AlertTable::decode_code(){
277 /* the code is a sparse enumeration and instead of making a
278 totally huge vector I made a more complicated function. */
279 switch(code/100){
280 case 0:
281 assert(code>=1 && code<=38);
282 return ALERTCODES[code];
283 case 5:
284 assert(code>=501 && code<=507);
285 return ALERTCODES[code-500+38];
286 case 8:
287 assert(code>=801 && code<=813);
288 return ALERTCODES[code-800+45];
289 case 9:
290 assert(code>=901 && code<=904);
291 return ALERTCODES[code-900+58];
292 case 10:
293 assert(code>=1001 && code<1005);
294 return ALERTCODES[code-1000+62];
295 case 11:
296 assert(code>=1101 && code<1115);
297 return ALERTCODES[code-1100+67];
298 case 13:
299 assert(code>=1301 && code<1303);
300 return ALERTCODES[code-1300+82];
301 case 15:
302 assert(code>=1501 && code<1509);
303 return ALERTCODES[code-1500+85];
304 case 18:
305 assert(code==1801);
306 return ALERTCODES[code-1800+93];
307 default:
308 assert(0); //bad value
309 }
310 }
311
312 void do_printmib_get(SNMP_session &session, unsigned long *argflags){
313 char buf[MAXSTR];
314 /* ----- General section of the printmib ---------------------------*/
315 if(CK_SERIALNUM_FLAG){
316 SNMP_structFiller getreq(session);
317 GeneralPrintmib gpm;
318
319 getreq.append(PRTGENERALSERIALNUMBER,STRING_TAG,
320 (char*)&gpm.serial-(char*)&gpm);
321 char retry=0;
322 do{
323 try{
324 getreq.get(&gpm);
325 retry=0;
326 }catch(SNMP_error_unrecoverable &error){
327 handle_unrecoverable(progname, session.Hostname(),error);
328 }
329 }while(retry);
330 snprintf(buf,MAXSTR,"serialnum=\"%s\";",gpm.serial);
331 session.printstr(argflags,NEEDNL_ENTRY,buf);
332 }
333 /* ----- marker table -----------------------------------------------*/
334 if(CK_MARKER_FLAGS){
335 MarkerTable *markerinfo;
336 unsigned int len;
337 SNMP_table markerinforeq(session,sizeof(struct MarkerTable));
338 if(CK_MARKER_FLAG || CK_PAGECOUNT_FLAG){
339 markerinforeq.append(PRTMARKERLIFECOUNT_BASE,COUNTER_TAG,
340 (char*)&BMTID.lifecount-(char*)&BMTID);
341 markerinforeq.append(PRTMARKERCOUNTERUNITS_BASE,INT_TAG,
342 (char*)&BMTID.counterunits-(char*)&BMTID);
343 }
344 if(CK_MARKER_FLAG || CK_COLORS_FLAG)
345 markerinforeq.append(PRTMARKERPROCESSCOLORANTS_BASE,INT_TAG,
346 (char*)&BMTID.processcolorants-(char*)&BMTID);
347 if(CK_MARKER_FLAG || CK_RESOLUTION_FLAG || CK_MINMARGIN_FLAG)
348 markerinforeq.append(PRTMARKERADDRESSABILITYUNIT_BASE,INT_TAG,
349 (char*)&BMTID.addrunits-(char*)&BMTID);
350 if(CK_MARKER_FLAG || CK_RESOLUTION_FLAG){
351 markerinforeq.append(PRTMARKERADDRESSABILITYFEEDDIR_BASE,INT_TAG,
352 (char*)&BMTID.addrfeeddir-(char*)&BMTID);
353 markerinforeq.append(PRTMARKERADDRESSABILITYXFEEDDIR_BASE,INT_TAG,
354 (char*)&BMTID.addrxfeeddir-(char*)&BMTID);
355 }
356 if(CK_MARKER_FLAG || CK_MINMARGIN_FLAG){
357 markerinforeq.append(PRTMARKERNORTHMARGIN_BASE,INT_TAG,
358 (char*)&BMTID.northmargin-(char*)&BMTID);
359 markerinforeq.append(PRTMARKERSOUTHMARGIN_BASE,INT_TAG,
360 (char*)&BMTID.southmargin-(char*)&BMTID);
361 markerinforeq.append(PRTMARKEREASTMARGIN_BASE,INT_TAG,
362 (char*)&BMTID.eastmargin-(char*)&BMTID);
363 markerinforeq.append(PRTMARKERWESTMARGIN_BASE,INT_TAG,
364 (char*)&BMTID.westmargin-(char*)&BMTID);
365 }
366 if(CK_MARKER_FLAG){
367 markerinforeq.append(PRTMARKERMARKTECH_BASE,INT_TAG,
368 (char*)&BMTID.marktech-(char*)&BMTID);
369 markerinforeq.append(PRTMARKERSTATUS_BASE,INT_TAG,
370 (char*)&BMTID.status-(char*)&BMTID);
371 }
372 try{
373 assert(markerinfo=(MarkerTable*)markerinforeq.get(len));
374 } catch (SNMP_error_unrecoverable &error){
375 handle_unrecoverable(progname, session.Hostname(),error);
376 }
377 for(unsigned int i=0;i<len;i++){
378 //check marktech
379 if(CK_MARKER_FLAG)
380 assert(markerinfo[i].marktech>0 && markerinfo[i].marktech<=27 &&
381 MARKTECH[markerinfo[i].marktech]!=NULL);
382
383 //check couterunits
384 if(CK_MARKER_FLAG || CK_PAGECOUNT_FLAG)
385 assert(markerinfo[i].counterunits>0 && markerinfo[i].counterunits<=17
386 && MARKERCOUNTERUNIT[markerinfo[i].counterunits]!=NULL);
387 //check addrunits
388 if(CK_MARKER_FLAG || CK_RESOLUTION_FLAG || CK_MINMARGIN_FLAG)
389 assert(markerinfo[i].addrunits>0 && markerinfo[i].addrunits<=4 &&
390 MEDIAUNIT[markerinfo[i].addrunits]);
391 if(CK_MARKER_FLAG){
392 snprintf(buf,MAXSTR,"markerTechnology=\"%s\";counterUnits=\"%s\";"
393 "lifeCount=\"%ld\";processColorants=\"%ld\";"
394 "addressabilityUnit=\"%s\";addressabilityFeedDir=\"%ld\";"
395 "addressabilityXFeedDir=\"%ld\";northMargin=\"%ld\";"
396 "southMargin=\"%ld\";eastMargin=\"%ld\";westMargin=\"%ld\";"
397 "status=\"%s\";\n",MARKTECH[markerinfo[i].marktech],
398 MARKERCOUNTERUNIT[markerinfo[i].counterunits],
399 markerinfo[i].lifecount,markerinfo[i].processcolorants,
400 MEDIAUNIT[markerinfo[i].addrunits],markerinfo[i].addrfeeddir,
401 markerinfo[i].addrxfeeddir,markerinfo[i].northmargin,
402 markerinfo[i].southmargin,markerinfo[i].eastmargin,
403 markerinfo[i].westmargin,decode_status(markerinfo[i].status));
404 session.printstr(argflags,NEEDNL_LINE,buf);
405 }
406 if(CK_PAGECOUNT_FLAG){
407 snprintf(buf,MAXSTR,"counterUnits=\"%s\";pagecount=\"%ld\";\n",
408 MARKERCOUNTERUNIT[markerinfo[i].counterunits],
409 markerinfo[i].lifecount);
410 session.printstr(argflags,NEEDNL_ENTRY,buf);
411 }
412 if(CK_COLORS_FLAG){
413 snprintf(buf,MAXSTR,"processColorants=\"%ld\";\n",
414 markerinfo[i].processcolorants);
415 session.printstr(argflags,NEEDNL_ENTRY,buf);
416 }
417 if(CK_RESOLUTION_FLAG){
418 snprintf(buf,MAXSTR,"addressabilityUnit=\"%s\";"
419 "addressabilityFeedDir=\"%ld\";"
420 "addressabilityXFeedDir=\"%ld\";",
421 MEDIAUNIT[markerinfo[i].addrunits],markerinfo[i].addrfeeddir,
422 markerinfo[i].addrxfeeddir);
423 session.printstr(argflags,NEEDNL_ENTRY,buf);
424 }
425 if(CK_MINMARGIN_FLAG){
426 if(CK_RESOLUTION_FLAG){
427 snprintf(buf,MAXSTR,"northMargin=\"%ld\";southMargin=\"%ld\";"
428 "eastMargin=\"%ld\";westMargin=\"%ld\";",
429 markerinfo[i].northmargin,markerinfo[i].southmargin,
430 markerinfo[i].eastmargin,markerinfo[i].westmargin);
431 }else{
432 snprintf(buf,MAXSTR,"addressabilityUnit=\"%s\";northMargin=\"%ld\";"
433 "southMargin=\"%ld\";eastMargin=\"%ld\";westMargin=\"%ld\";"
434 ,MEDIAUNIT[markerinfo[i].addrunits],
435 markerinfo[i].northmargin,markerinfo[i].southmargin,
436 markerinfo[i].eastmargin,markerinfo[i].westmargin);
437 }
438 session.printstr(argflags,NEEDNL_ENTRY,buf);
439 }
440 }
441 } // end of processing marker table
442
443 /* ----- media path table ------------------------------------*/
444 if(CK_MEDIAPATH_FLAGS){
445 MediaPathInfo *mpi;
446 unsigned int len;
447 SNMP_table mediapathreq(session,sizeof(MediaPathInfo));
448 mediapathreq.append(PRTMEDIAPATHMAXSPEEDPRINTUNIT_BASE,INT_TAG,
449 (char*)&BMPID.maxSpeedPrintUnit-(char*)&BMPID);
450 mediapathreq.append(PRTMEDIAPATHMEDIASIZEUNIT_BASE,INT_TAG,
451 (char*)&BMPID.mediaSizeUnit-(char*)&BMPID);
452 mediapathreq.append(PRTMEDIAPATHMAXSPEED_BASE,INT_TAG,
453 (char*)&BMPID.maxSpeed-(char*)&BMPID);
454 mediapathreq.append(PRTMEDIAPATHMAXMEDIAFEEDDIR_BASE,INT_TAG,
455 (char*)&BMPID.maxMediaFeedDir-(char*)&BMPID);
456 mediapathreq.append(PRTMEDIAPATHMAXMEDIAXFEEDDIR_BASE,INT_TAG,
457 (char*)&BMPID.maxMediaXFeedDir-(char*)&BMPID);
458 mediapathreq.append(PRTMEDIAPATHMINMEDIAFEEDDIR_BASE,INT_TAG,
459 (char*)&BMPID.minMediaFeedDir-(char*)&BMPID);
460 mediapathreq.append(PRTMEDIAPATHMINMEDIAXFEEDDIR_BASE,INT_TAG,
461 (char*)&BMPID.minMediaXFeedDir-(char*)&BMPID);
462 mediapathreq.append(PRTMEDIAPATHTYPE_BASE,INT_TAG,
463 (char*)&BMPID.type-(char*)&BMPID);
464 mediapathreq.append(PRTMEDIAPATHSTATUS_BASE,INT_TAG,
465 (char*)&BMPID.status-(char*)&BMPID);
466 mediapathreq.append(PRTMEDIAPATHDESCRIPTION_BASE,STRING_TAG,
467 (char*)&BMPID.description-(char*)&BMPID);
468 try{
469 mpi=(MediaPathInfo*)mediapathreq.get(len);
470 assert(mpi);
471 } catch (SNMP_error_unrecoverable &error){
472 handle_unrecoverable(progname, session.Hostname(),error);
473 }
474
475 long maxSpeed=0;
476 unsigned int maxSpeedIndex=0;
477 long maxMediaFeedDir=0;
478 long maxMediaXFeedDir=0;
479 unsigned int maxMediaIndex=0;
480 long minMediaFeedDir=LONG_MAX;
481 long minMediaXFeedDir=LONG_MAX;
482 unsigned int minMediaIndex=0;
483 char duplex=0;
484 for(unsigned int i=0;i<len;i++){
485 /* this computes the maximum and the minumum paper size by area rather
486 than having one dimension be more important than the other. This
487 should not cause a problem in most modern printers.
488
489 It also assumes that the printer is doesn't have different units
490 for different media paths.
491
492 If either of these assumptions are found to be in error on any
493 printer please let me know. */
494
495 // check for undocumented units
496 assert(mpi[i].mediaSizeUnit>=0 && mpi[i].mediaSizeUnit<=4 &&
497 MEDIAUNIT[mpi[i].mediaSizeUnit]!=NULL);
498 // check for undocumented speeds
499 assert(mpi[i].maxSpeedPrintUnit>=0 && mpi[i].maxSpeedPrintUnit<=17 &&
500 MEDIASPEEDUNIT[mpi[i].maxSpeedPrintUnit]!=NULL);
501 // check for undocumented media path types;
502 assert(mpi[i].type<=5 && MEDIATYPE[mpi[i].type]!=NULL);
503
504 if((float)mpi[i].maxMediaFeedDir*(float)mpi[i].maxMediaXFeedDir>
505 (float)maxMediaFeedDir*(float)maxMediaXFeedDir){
506 maxMediaFeedDir=mpi[i].maxMediaFeedDir;
507 maxMediaXFeedDir=mpi[i].maxMediaXFeedDir;
508 maxMediaIndex=i;
509 }
510 if((float)mpi[i].minMediaFeedDir*(float)mpi[i].minMediaXFeedDir<
511 (float)minMediaFeedDir*(float)minMediaXFeedDir){
512 minMediaFeedDir=mpi[i].minMediaFeedDir;
513 minMediaXFeedDir=mpi[i].minMediaXFeedDir;
514 minMediaIndex=i;
515 }
516 if(mpi[i].maxSpeed>maxSpeed){
517 maxSpeed=mpi[i].maxSpeed;
518 maxSpeedIndex=i;
519 }
520 if(mpi[i].type==3 || mpi[i].type==4)
521 duplex=1;
522 if(CK_MEDIAPATH_FLAG){
523 char *tmp;
524 snprintf(buf,MAXSTR,"maxSpeedPrintUnit=\"%s\";mediaSizeUnit=\"%s\";"
525 "maxSpeed=\"%ld\";maxMediaFeedDir=\"%ld\";"
526 "maxMediaXFeedDir=\"%ld\";minMediaFeedDir=\"%ld\";"
527 "minMediaXFeedDir=\"%ld\";type=\"%s\";description=\"%s\";"
528 "status=\"%s\";\n",
529 MEDIASPEEDUNIT[mpi[i].maxSpeedPrintUnit],
530 MEDIAUNIT[mpi[i].mediaSizeUnit],mpi[i].maxSpeed,
531 mpi[i].maxMediaFeedDir,mpi[i].maxMediaXFeedDir,
532 mpi[i].minMediaFeedDir,mpi[i].minMediaXFeedDir,
533 MEDIATYPE[mpi[i].type],mpi[i].description,
534 tmp=decode_status(mpi[i].status));
535 session.printstr(argflags,NEEDNL_LINE,buf);
536 delete tmp;
537 }
538 }
539 /* the for loop above will have gathered the information from the all the
540 media path table entries and now we just have to print them. */
541 if(CK_DUPLEX_FLAG){
542 snprintf(buf,MAXSTR,"duplex=\"%c\";",duplex==1?'Y':'N');
543 session.printstr(argflags,NEEDNL_ENTRY,buf);
544 }
545 if(CK_MAXPAPERSIZE_FLAG){
546 snprintf(buf,MAXSTR,"maxMediaUnit=\"%s\";maxMediaFeedDir=\"%ld\";"
547 "maxMediaXFeedDir=\"%ld\";",
548 MEDIAUNIT[mpi[maxMediaIndex].mediaSizeUnit],
549 maxMediaFeedDir,maxMediaXFeedDir);
550 session.printstr(argflags,NEEDNL_ENTRY,buf);
551 }
552 if(CK_MINPAPERSIZE_FLAG){
553 snprintf(buf,MAXSTR,"minMediaUnit=\"%s\";minMediaFeedDir=\"%ld\";"
554 "minMediaXFeedDir=\"%ld\";",
555 MEDIAUNIT[mpi[minMediaIndex].mediaSizeUnit],
556 minMediaFeedDir,minMediaXFeedDir);
557 session.printstr(argflags,NEEDNL_ENTRY,buf);
558 }
559 if(CK_ENGINESPEED_FLAG){
560 snprintf(buf,MAXSTR,"maxSpeedUnit=\"%s\";maxSpeed=\"%ld\";",
561 MEDIASPEEDUNIT[mpi[maxSpeedIndex].maxSpeedPrintUnit],maxSpeed);
562 session.printstr(argflags,NEEDNL_ENTRY,buf);
563 }
564 } // ends the section processing the media path table
565
566 /* ----- display table -------------------------------------------------*/
567 if(CK_DISPLAY_FLAG){
568 char **dispbuf;
569 unsigned int len;
570 SNMP_table dispbufreq(session,sizeof(char*));
571 dispbufreq.append(PRTCONSOLEDISPLAYBUFFERTEXT_BASE,STRING_TAG,0);
572 try{
573 dispbuf=(char**)dispbufreq.get(len);
574 assert(dispbuf);
575 } catch (SNMP_error_unrecoverable &error){
576 handle_unrecoverable(progname, session.Hostname(),error);
577 }
578
579 for(unsigned int i=0;i<len;i++){
580 snprintf(buf,MAXSTR,"displayBufferText=\"%s\";\n",dispbuf[i]);
581 session.printstr(argflags,NEEDNL_ENTRY,buf);
582 }
583 } // ends the section processint the display path
584
585 /* ----- input tray table ----------------------------------------------*/
586 if(CK_INPUTTRAY_FLAGS){
587 struct InputTrayInfo *trayinfo;
588 unsigned int len;
589 SNMP_table trayinforeq(session,sizeof(struct InputTrayInfo));
590 trayinforeq.append(PRTINPUTTYPE_BASE,INT_TAG,
591 (char*)&BITID.type-(char*)&BITID);
592 trayinforeq.append(PRTINPUTDIMUNIT_BASE,INT_TAG,
593 (char*)&BITID.dimUnit-(char*)&BITID);
594 trayinforeq.append(PRTINPUTMEDIADIMFEEDDIRCHOSEN_BASE,INT_TAG,
595 (char*)&BITID.dimFeedDir-(char*)&BITID);
596 trayinforeq.append(PRTINPUTMEDIADIMXFEEDDIRCHOSEN_BASE,INT_TAG,
597 (char*)&BITID.dimXFeedDir-(char*)&BITID);
598 trayinforeq.append(PRTINPUTCAPACITYUNIT_BASE,INT_TAG,
599 (char*)&BITID.capUnit-(char*)&BITID);
600 trayinforeq.append(PRTINPUTMAXCAPACITY_BASE,INT_TAG,
601 (char*)&BITID.maxCap-(char*)&BITID);
602 trayinforeq.append(PRTINPUTCURRENTLEVEL_BASE,INT_TAG,
603 (char*)&BITID.curLev-(char*)&BITID);
604 trayinforeq.append(PRTINPUTINPUTSTATUS_BASE,INT_TAG,
605 (char*)&BITID.status-(char*)&BITID);
606 trayinforeq.append(PRTINPUTMEDIANAME_BASE,STRING_TAG,
607 (char*)&BITID.mediaName-(char*)&BITID);
608 trayinforeq.append(PRTINPUTNAME_BASE,STRING_TAG,
609 (char*)&BITID.name-(char*)&BITID);
610 trayinforeq.append(PRTINPUTINPUTDESCRIPTION_BASE,STRING_TAG,
611 (char*)&BITID.desc-(char*)&BITID);
612 try{
613 trayinfo=(InputTrayInfo*)trayinforeq.get(len);
614 assert(trayinfo);
615 } catch (SNMP_error_unrecoverable &error){
616 handle_unrecoverable(progname, session.Hostname(),error);
617 }
618
619 int letter=0;
620 int legal=0;
621 int tabloid=0;
622 int executive=0;
623 int a3=0;
624 int a4=0;
625 int b4=0;
626 int b5=0;
627 for(unsigned int i=0;i<len;i++){
628 InputTrayInfo &ti=trayinfo[i];
629 // check for undocumented input tray types.
630 assert(ti.type>=0 && ti.type<=7 &&
631 INPUTTYPE[ti.type]!=NULL);
632 // check for undocumented dimunits.
633 assert(ti.dimUnit>=0 && ti.dimUnit<=4 &&
634 MEDIAUNIT[ti.dimUnit]!=NULL);
635 // check for undocumented capacity types.
636 assert(ti.capUnit>=0 && ti.capUnit<=17 &&
637 CAPACITYUNIT[ti.capUnit]!=NULL);
638
639 if(CK_PAPERSIZE_FLAGS){
640 long shortedge,longedge;
641 if(ti.dimFeedDir<ti.dimXFeedDir){
642 shortedge=ti.dimFeedDir;
643 longedge=ti.dimXFeedDir;
644 } else {
645 shortedge=ti.dimXFeedDir;
646 longedge=ti.dimFeedDir;
647 }
648 if(ti.curLev>=0){
649 if(ti.dimUnit==3){ // ten thousands of an inch
650 if(shortedge==LETTER_SHORT_IN && longedge==LETTER_LONG_IN)
651 letter+=ti.curLev;
652 if(shortedge==LEGAL_SHORT_IN && longedge==LEGAL_LONG_IN)
653 legal+=ti.curLev;
654 if(shortedge==TABLOID_SHORT_IN && longedge==TABLOID_LONG_IN)
655 tabloid+=ti.curLev;
656 if(shortedge==EXECUTIVE_SHORT_IN && longedge==EXECUTIVE_LONG_IN)
657 executive+=ti.curLev;
658 if(shortedge==A4_SHORT_IN && longedge==A4_LONG_IN)
659 a4+=ti.curLev;
660 if(shortedge==A3_SHORT_IN && longedge==A3_LONG_IN)
661 a4+=ti.curLev;
662 if(shortedge==B5_SHORT_IN && longedge==B5_LONG_IN)
663 a4+=ti.curLev;
664 if(shortedge==B4_SHORT_IN && longedge==B4_LONG_IN)
665 a4+=ti.curLev;
666 } else { /* micrometers
667 there are currently only two dimunits if this changes
668 then we will need to change this code */
669 if(shortedge==LETTER_SHORT_M && longedge==LETTER_LONG_M)
670 letter+=ti.curLev;
671 if(shortedge==LEGAL_SHORT_M && longedge==LEGAL_LONG_M)
672 legal+=ti.curLev;
673 if(shortedge==TABLOID_SHORT_M && longedge==TABLOID_LONG_M)
674 tabloid+=ti.curLev;
675 if(shortedge==EXECUTIVE_SHORT_M && longedge==EXECUTIVE_LONG_M)
676 executive+=ti.curLev;
677 if(shortedge==A4_SHORT_M && longedge==A4_LONG_M)
678 a4+=ti.curLev;
679 if(shortedge==A3_SHORT_M && longedge==A3_LONG_M)
680 a4+=ti.curLev;
681 if(shortedge==B5_SHORT_M && longedge==B5_LONG_M)
682 a4+=ti.curLev;
683 if(shortedge==B4_SHORT_M && longedge==B4_LONG_M)
684 a4+=ti.curLev;
685 }
686 } else {
687 fprintf(stderr,"Warning: Can't sense paper level.\n");
688 }
689 } // ends section counting pages of a size
690 if(CK_INPUTTRAY_FLAG){
691 char *tmp=decode_status(ti.status);
692 snprintf(buf,MAXSTR,"type=\"%s\";dimUnit=\"%s\";dimFeedDir=\"%ld\";"
693 "dimXFeedDir=\"%ld\";capUnit=\"%s\";maxCap=\"%ld\";"
694 "curLevel=\"%ld\";mediaName=\"%s\";name=\"%s\";"
695 "description=\"%s\";status=\"%s\";\n",
696 INPUTTYPE[ti.type],MEDIAUNIT[ti.dimUnit],ti.dimFeedDir,
697 ti.dimXFeedDir,CAPACITYUNIT[ti.capUnit],ti.maxCap,
698 ti.curLev,ti.mediaName,ti.name,ti.desc,
699 tmp);
700 session.printstr(argflags,NEEDNL_LINE,buf);
701 delete tmp;
702 }
703 } // ends iterating through each one of the trays
704 if(CK_LEGAL_FLAG){
705 snprintf(buf,MAXSTR,"legal=\"%d\";",legal);
706 session.printstr(argflags,NEEDNL_ENTRY,buf);
707 }
708 if(CK_TABLOID_FLAG){
709 snprintf(buf,MAXSTR,"tabloid=\"%d\";",tabloid);
710 session.printstr(argflags,NEEDNL_ENTRY,buf);
711 }
712 if(CK_A4_FLAG){
713 snprintf(buf,MAXSTR,"a4=\"%d\";",a4);
714 session.printstr(argflags,NEEDNL_ENTRY,buf);
715 }
716 if(CK_B4_FLAG){
717 snprintf(buf,MAXSTR,"b4=\"%d\";",b4);
718 session.printstr(argflags,NEEDNL_ENTRY,buf);
719 }
720 if(CK_B5_FLAG){
721 snprintf(buf,MAXSTR,"b5=\"%d\";",b5);
722 session.printstr(argflags,NEEDNL_ENTRY,buf);
723 }
724 if(CK_LETTER_FLAG){
725 snprintf(buf,MAXSTR,"letter=\"%d\";",letter);
726 session.printstr(argflags,NEEDNL_ENTRY,buf);
727 }
728 if(CK_A3_FLAG){
729 snprintf(buf,MAXSTR,"a3=\"%d\";",a3);
730 session.printstr(argflags,NEEDNL_ENTRY,buf);
731 }
732 if(CK_EXECUTIVE_FLAG){
733 snprintf(buf,MAXSTR,"executive=\"%d\";",executive);
734 session.printstr(argflags,NEEDNL_ENTRY,buf);
735 }
736 } // ends the section processing input tray table
737
738 /* ----- covers table ------------------------------------------------- */
739 if(CK_COVER_FLAG){
740 struct CoverTable *coverinfo;
741 unsigned int len;
742
743 SNMP_table coverinforeq(session,sizeof(struct CoverTable));
744 coverinforeq.append(PRTCOVERDESCRIPTION_BASE,STRING_TAG,
745 (char*)&BCTID.desc-(char*)&BCTID);
746 coverinforeq.append(PRTCOVERSTATUS_BASE,INT_TAG,
747 (char*)&BCTID.status-(char*)&BCTID);
748 try{
749 coverinfo=(CoverTable*)coverinforeq.get(len);
750 assert(coverinfo);
751 } catch (SNMP_error_unrecoverable &error){
752 handle_unrecoverable(progname, session.Hostname(),error);
753 }
754
755 for(unsigned int i=0;i<len;i++){
756 //make sure we didn't get something weird for a cover status
757 assert(coverinfo[i].status>0 && coverinfo[i].status<=6 &&
758 COVERSTATUS[coverinfo[i].status]!=NULL);
759 snprintf(buf,MAXSTR,"description=\"%s\";status=\"%s\";\n",
760 coverinfo[i].desc,COVERSTATUS[coverinfo[i].status]);
761 session.printstr(argflags,NEEDNL_LINE,buf);
762 }
763 } // ends the section processing the cover table
764
765 /* ----- Languages table ----------------------------------------------- */
766 /* these two variables are put outside of the loop so that they do not go
767 out of scope when the language table is finished being printed out that
768 way they can be used when processing the protocol table */
769 struct LangInfo *langinfo;
770 unsigned int langlen;
771
772 if(CK_PROTOCOL_FLAGS || CK_LANGUAGES_FLAGS){
773 SNMP_table langinforeq(session,sizeof(struct LangInfo));
774
775 langinforeq.append(PRTINTERPRETERLANGFAMILY_BASE,INT_TAG,
776 (char*)&BLTID.family-(char*)&BLTID);
777 if(CK_LANGUAGES_FLAG){
778 langinforeq.append(PRTINTERPRETERLANGLEVEL_BASE,STRING_TAG,
779 (char*)&BLTID.langLevel-(char*)&BLTID);
780 langinforeq.append(PRTINTERPRETERLANGVERSION_BASE,STRING_TAG,
781 (char*)&BLTID.langVersion-(char*)&BLTID);
782 langinforeq.append(PRTINTERPRETERDESCRIPTION_BASE,STRING_TAG,
783 (char*)&BLTID.description-(char*)&BLTID);
784 langinforeq.append(PRTINTERPRETERVERSION_BASE,STRING_TAG,
785 (char*)&BLTID.version-(char*)&BLTID);
786 langinforeq.append(PRTINTERPRETERDEFAULTORIENTATION_BASE,INT_TAG,
787 (char*)&BLTID.orientation-(char*)&BLTID);
788 langinforeq.append(PRTINTERPRETERFEEDADDRESSABILITY_BASE,INT_TAG,
789 (char*)&BLTID.feedAddressability-(char*)&BLTID);
790 langinforeq.append(PRTINTERPRETERXFEEDADDRESSABILITY_BASE,INT_TAG,
791 (char*)&BLTID.xFeedAddressability-(char*)&BLTID);
792 langinforeq.append(PRTINTERPRETERTWOWAY_BASE,INT_TAG,
793 (char*)&BLTID.twoWay-(char*)&BLTID);
794 }
795 try{
796 langinfo=(LangInfo*)langinforeq.get(langlen);
797 assert(langinfo);
798 } catch (SNMP_error_unrecoverable &error){
799 handle_unrecoverable(progname, session.Hostname(),error);
800 }
801
802 char flags=0;
803 for(unsigned int i=0; i<langlen;i++){
804 switch(langinfo[i].family){
805 case 3:
806 flags|=PCL_C_FLAG;
807 break;
808 case 4:
809 flags|=HPGL_C_FLAG;
810 break;
811 case 5:
812 flags|=PJL_C_FLAG;
813 break;
814 case 6:
815 flags|=PS_C_FLAG;
816 break;
817 case 42:
818 flags|=PSPRINTER_C_FLAG;
819 break;
820 case 37:
821 flags|=AUTOLANG_C_FLAG;
822 break;
823 } // pretty much ignore the rest.
824
825 // toss out any unknown printer language families
826 assert(langinfo[i].family>0 && langinfo[i].family<=47 &&
827 LANGUAGES[langinfo[i].family]!=NULL);
828
829 if(CK_LANGUAGES_FLAG){
830 // toss out any unknown orientations
831 assert(langinfo[i].orientation>0 && langinfo[i].orientation<=4 &&
832 ORIENTATIONS[langinfo[i].orientation]!=NULL);
833 // toss out undefined communication info
834 assert(langinfo[i].twoWay==3 || langinfo[i].twoWay==4);
835
836 snprintf(buf,MAXSTR,"langFamily=\"%s\";langLevel=\"%s\";"
837 "langVersion=\"%s\";description=\"%s\";version=\"%s\";"
838 "orientation=\"%s\";feedAddressability=\"%ld\";"
839 "xFeedAddressability=\"%ld\";twoWay=\"%c\";\n",
840 LANGUAGES[langinfo[i].family],langinfo[i].langLevel,
841 langinfo[i].langVersion,langinfo[i].description,
842 langinfo[i].version,ORIENTATIONS[langinfo[i].orientation],
843 langinfo[i].feedAddressability,
844 langinfo[i].xFeedAddressability,
845 langinfo[i].twoWay==3?'Y':'N');
846 session.printstr(argflags,NEEDNL_LINE,buf);
847 }
848 }
849 if(CK_POSTSCRIPT_FLAG){
850 snprintf(buf,MAXSTR,"postscript=\"%c\";",flags&PS_C_FLAG?'Y':'N');
851 session.printstr(argflags,NEEDNL_ENTRY,buf);
852 }
853 if(CK_PCL_FLAG){
854 snprintf(buf,MAXSTR,"pcl=\"%c\";",flags&PCL_C_FLAG?'Y':'N');
855 session.printstr(argflags,NEEDNL_ENTRY,buf);
856 }
857 if(CK_PJL_FLAG){
858 snprintf(buf,MAXSTR,"pjl=\"%c\";",flags&PJL_C_FLAG?'Y':'N');
859 session.printstr(argflags,NEEDNL_ENTRY,buf);
860 }
861 if(CK_HPGL_FLAG){
862 snprintf(buf,MAXSTR,"hpgl=\"%c\";",flags&HPGL_C_FLAG?'Y':'N');
863 session.printstr(argflags,NEEDNL_ENTRY,buf);
864 }
865 if(CK_PSPRINTER_FLAG){
866 snprintf(buf,MAXSTR,"psprinter=\"%c\";",flags&PSPRINTER_C_FLAG?'Y':'N');
867 session.printstr(argflags,NEEDNL_ENTRY,buf);
868 }
869 if(CK_AUTOLANG_FLAG){
870 snprintf(buf,MAXSTR,"autolang=\"%c\";",flags&AUTOLANG_C_FLAG?'Y':'N');
871 session.printstr(argflags,NEEDNL_ENTRY,buf);
872 }
873 } // ends the section proccessing the languages table
874
875 /* ----- channel table ----------------------------------------------- */
876 if(CK_PROTOCOL_FLAGS){
877 struct ProtocolTable *protoinfo;
878 unsigned int len;
879
880 SNMP_table protoinforeq(session,sizeof(struct ProtocolTable));
881 protoinforeq.append(PRTCHANNELTYPE_BASE,INT_TAG,
882 (char*)&BPTID.type-(char*)&BPTID);
883 if(CK_PROTOCOL_FLAG){
884 protoinforeq.append(PRTCHANNELPROTOCOLVERSION_BASE,STRING_TAG,
885 (char*)&BPTID.version-(char*)&BPTID);
886 protoinforeq.append(PRTCHANNELCURRENTJOBCNTLLANGINDEX_BASE,INT_TAG,
887 (char*)&BPTID.curjclidx-(char*)&BPTID);
888 protoinforeq.append(PRTCHANNELDEFAULTPAGEDESCLANGINDEX_BASE,INT_TAG,
889 (char*)&BPTID.defpdlidx-(char*)&BPTID);
890 protoinforeq.append(PRTCHANNELSTATE_BASE,INT_TAG,
891 (char*)&BPTID.state-(char*)&BPTID);
892 protoinforeq.append(PRTCHANNELSTATUS_BASE,INT_TAG,
893 (char*)&BPTID.status-(char*)&BPTID);
894 }
895 try{
896 protoinfo=(ProtocolTable*)protoinforeq.get(len);
897 assert(protoinfo);
898 } catch (SNMP_error_unrecoverable &error){
899 handle_unrecoverable(progname, session.Hostname(),error);
900 }
901
902 char flags=0;
903 for(unsigned int i=0;i<len;i++){
904 switch(protoinfo[i].type){
905 case 7:
906 flags|=APPLETALK_C_FLAG;
907 break;
908 case 8:
909 flags|=LPD_C_FLAG;
910 break;
911 case 10:
912 flags|=NETWARE_C_FLAG;
913 break;
914 case 11: // old depricated port 9100
915 case 38: // new bidirectional tcp port
916 case 12: // appsocket on tek's
917 flags|=PORT9100_C_FLAG;
918 break;
919 }
920 //kick out bad types.
921 assert(protoinfo[i].type>0 && protoinfo[i].type<=43 &&
922 CHANNELTYPE[protoinfo[i].type]!=NULL);
923 if(CK_PROTOCOL_FLAG){
924 //kick out bad states
925 assert(protoinfo[i].state>0 && protoinfo[i].state<=4 &&
926 CHANNELSTATE[protoinfo[i].state]!=NULL);
927 //make sure the jcl index is valid we have already made
928 //sure that the type is valid above
929 assert(protoinfo[i].curjclidx>0 &&
930 static_cast<unsigned>(protoinfo[i].curjclidx)<=langlen);
931 //make sure the pdl index is valid
932 assert(protoinfo[i].defpdlidx>0 &&
933 static_cast<unsigned>(protoinfo[i].defpdlidx)<=langlen);
934
935 snprintf(buf,MAXSTR,"type=\"%s\";version=\"%s\";"
936 "currentJobControlLang=\"%s\";defaultPageDescLang=\"%s\";"
937 "state=\"%s\";status=\"%s\";\n",
938 CHANNELTYPE[protoinfo[i].type],protoinfo[i].version,
939 LANGUAGES[langinfo[protoinfo[i].curjclidx-1].family],
940 LANGUAGES[langinfo[protoinfo[i].defpdlidx-1].family],
941 CHANNELSTATE[protoinfo[i].state],
942 decode_status(protoinfo[i].status));
943 session.printstr(argflags,NEEDNL_LINE,buf);
944 }
945 }
946
947 if(CK_APPLETALK_FLAG){
948 snprintf(buf,MAXSTR,"appletalk=\"%c\";",flags&APPLETALK_C_FLAG?'Y':'N');
949 session.printstr(argflags,NEEDNL_ENTRY,buf);
950 }
951 if(CK_LPD_FLAG){
952 snprintf(buf,MAXSTR,"lpd=\"%c\";",flags&LPD_C_FLAG?'Y':'N');
953 session.printstr(argflags,NEEDNL_ENTRY,buf);
954 }
955 if(CK_NETWARE_FLAG){
956 snprintf(buf,MAXSTR,"netware=\"%c\";",flags&NETWARE_C_FLAG?'Y':'N');
957 session.printstr(argflags,NEEDNL_ENTRY,buf);
958 }
959 if(CK_PORT9100_FLAG){
960 snprintf(buf,MAXSTR,"port9100=\"%c\";",flags&PORT9100_C_FLAG?'Y':'N');
961 session.printstr(argflags,NEEDNL_ENTRY,buf);
962 }
963
964 } // ends the section processing the channel table
965 /* ----- Marker Supplies table ------------------------------ */
966 if(CK_SUPPLIES_FLAG){
967 struct MarkerSuppliesTable *msupplyinfo;
968 unsigned int len;
969
970 SNMP_table msuppreq(session,sizeof(MarkerSuppliesTable));
971 // msupreq.append(PRTMARKERSUPPLIESCOLORANTINDEX_BASE,INT_TAG,
972 // (char*)&BMSTID.colorantidx-(char*)&BMSTID);
973 msuppreq.append(PRTMARKERSUPPLIESCLASS_BASE,INT_TAG,
974 (char*)&BMSTID.msclass-(char*)&BMSTID);
975 msuppreq.append(PRTMARKERSUPPLIESTYPE_BASE,INT_TAG,
976 (char*)&BMSTID.type-(char*)&BMSTID);
977 msuppreq.append(PRTMARKERSUPPLIESDESCRIPTION_BASE,STRING_TAG,
978 (char*)&BMSTID.desc-(char*)&BMSTID);
979 msuppreq.append(PRTMARKERSUPPLIESSUPPLYUNIT_BASE,INT_TAG,
980 (char*)&BMSTID.supplyunit-(char*)&BMSTID);
981 msuppreq.append(PRTMARKERSUPPLIESMAXCAPACITY_BASE,INT_TAG,
982 (char*)&BMSTID.maxcap-(char*)&BMSTID);
983 msuppreq.append(PRTMARKERSUPPLIESLEVEL_BASE,INT_TAG,
984 (char*)&BMSTID.level-(char*)&BMSTID);
985 try{
986 msupplyinfo=(MarkerSuppliesTable*)msuppreq.get(len);
987 assert(msupplyinfo);
988 } catch (SNMP_error_unrecoverable &error){
989 handle_unrecoverable(progname, session.Hostname(),error);
990 }
991
992 for(unsigned int i=0;i<len;i++){
993 //really should make sure colorant is actually used
994 assert(msupplyinfo[i].msclass>0 && msupplyinfo[i].msclass<=4 &&
995 MARKERSUPPLIESCLASS[msupplyinfo[i].msclass]!=NULL);
996 if(!(msupplyinfo[i].type>0 && msupplyinfo[i].type<=22 &&
997 MARKERSUPPLIESTYPE[msupplyinfo[i].type]!=NULL)){
998 // Seems apropriate to print out type number as type
999 fprintf(stderr,"Warning: markerSupplyType=%ld out of bounds.\n",
1000 msupplyinfo[i].type);
1001 snprintf(buf,MAXSTR,"type=\"%ld\";",msupplyinfo[i].type);
1002 session.printstr(argflags,NEEDNL_ENTRY,buf);
1003 }else{
1004 snprintf(buf,MAXSTR,"type=\"%s\";",
1005 MARKERSUPPLIESTYPE[msupplyinfo[i].type]);
1006 session.printstr(argflags,NEEDNL_ENTRY,buf);
1007 }
1008 if(!(msupplyinfo[i].supplyunit>0 && msupplyinfo[i].supplyunit<=17 &&
1009 MARKERSUPPLIESSUPPLYUNIT[msupplyinfo[i].supplyunit]))
1010 // Skipping the unit seems like the best thing to do here
1011 fprintf(stderr,"Warning: markerSupplyUnit=%ld out of bounds.\n",
1012 msupplyinfo[i].supplyunit);
1013 else{
1014 snprintf(buf,MAXSTR,"supplyunit=\"%s\";",
1015 MARKERSUPPLIESSUPPLYUNIT[msupplyinfo[i].supplyunit]);
1016 session.printstr(argflags,NEEDNL_ENTRY,buf);
1017 }
1018 snprintf(buf,MAXSTR,"class=\"%s\";desc=\"%s\";maxcap=\"%ld\";"
1019 "level=\"%ld\";\n",
1020 MARKERSUPPLIESCLASS[msupplyinfo[i].msclass],msupplyinfo[i].desc,
1021 msupplyinfo[i].maxcap,msupplyinfo[i].level);
1022 session.printstr(argflags,NEEDNL_LINE,buf);
1023
1024 }
1025 } // end processing supplies table
1026
1027 /* ----- Alerts table --------------------------------------- */
1028 if(CK_ALERTS_FLAG){
1029 struct AlertTable *alertinfo;
1030 unsigned int len;
1031
1032 SNMP_table alertreq(session,sizeof(AlertTable));
1033 alertreq.append(PRTALERTSEVERITYLEVEL_BASE,INT_TAG,
1034 (char*)&BATID.severityLevel-(char*)&BATID);
1035 alertreq.append(PTRALERTTRAININGLEVEL_BASE,INT_TAG,
1036 (char*)&BATID.trainingLevel-(char*)&BATID);
1037 alertreq.append(PRTALERTGROUP_BASE,INT_TAG,
1038 (char*)&BATID.group-(char*)&BATID);
1039 alertreq.append(PRTALERTGROUPINDEX_BASE,INT_TAG,
1040 (char*)&BATID.groupIndex-(char*)&BATID);
1041 alertreq.append(PRTALERTLOCATION_BASE,INT_TAG,
1042 (char*)&BATID.location-(char*)&BATID);
1043 alertreq.append(PRTALERTCODE_BASE,INT_TAG,
1044 (char*)&BATID.code-(char*)&BATID);
1045 alertreq.append(PRTALERTDESCRIPTION_BASE,STRING_TAG,
1046 (char*)&BATID.desc-(char*)&BATID);
1047 alertreq.append(PRTALERTTIME_BASE,TIME_TICK_TAG,
1048 (char*)&BATID.time-(char*)&BATID);
1049 try{
1050 alertinfo=(AlertTable*)alertreq.get(len);
1051 assert(alertinfo);
1052 }catch(SNMP_error_unrecoverable &error){
1053 handle_unrecoverable(progname, session.Hostname(),error);
1054 }catch(SNMP_error_oid &error){
1055 /* This is a workaround for broken HP firmware. Instead of
1056 returning timeticks like they are supposed to do. They
1057 return a time in the form of a string. */
1058 fprintf(stderr,"Trying a work around for broken HP firmware.\n");
1059 SNMP_table alertreq2(session,sizeof(AlertTable));
1060 alertreq2.append(PRTALERTSEVERITYLEVEL_BASE,INT_TAG,
1061 (char*)&BATID.severityLevel-(char*)&BATID);
1062 alertreq2.append(PTRALERTTRAININGLEVEL_BASE,INT_TAG,
1063 (char*)&BATID.trainingLevel-(char*)&BATID);
1064 alertreq2.append(PRTALERTGROUP_BASE,INT_TAG,
1065 (char*)&BATID.group-(char*)&BATID);
1066 alertreq2.append(PRTALERTGROUPINDEX_BASE,INT_TAG,
1067 (char*)&BATID.groupIndex-(char*)&BATID);
1068 alertreq2.append(PRTALERTLOCATION_BASE,INT_TAG,
1069 (char*)&BATID.location-(char*)&BATID);
1070 alertreq2.append(PRTALERTCODE_BASE,INT_TAG,
1071 (char*)&BATID.code-(char*)&BATID);
1072 alertreq2.append(PRTALERTDESCRIPTION_BASE,STRING_TAG,
1073 (char*)&BATID.desc-(char*)&BATID);
1074 alertreq2.append(PRTALERTTIME_BASE,INT_TAG,
1075 (char*)&BATID.time-(char*)&BATID);
1076 try{
1077 alertinfo=(AlertTable*)alertreq2.get(len);
1078 assert(alertinfo);
1079 }catch(SNMP_error_unrecoverable &err){
1080 handle_unrecoverable(progname, session.Hostname(),err);
1081 }catch(SNMP_error_oid &err){
1082 assert(0); // never should happen.
1083 }
1084 }
1085
1086 unsigned long printertime;
1087 SNMP_structFiller timereq(session);
1088 timereq.append(SYSUPTIME,TIME_TICK_TAG,0);
1089 try{
1090 timereq.get(&printertime);
1091 }catch(SNMP_error_unrecoverable &error){
1092 handle_unrecoverable(progname, session.Hostname(),error);
1093 }
1094 unsigned long systemtime=time(NULL);
1095
1096 for(unsigned int i=0;i<len;i++){
1097 int bufpos;
1098 if(alertinfo[i].severityLevel>0 && alertinfo[i].severityLevel<=5 &&
1099 alertinfo[i].severityLevel!=2 &&
1100 PRTALERTSEVERITYLEVEL[alertinfo[i].severityLevel]!=NULL){
1101 bufpos=snprintf(buf,MAXSTR,"severityLevel=\"%s\";",
1102 PRTALERTSEVERITYLEVEL[alertinfo[i].severityLevel]);
1103 }else{
1104 fprintf(stderr,"Warning: invalid severity level. Buggy firmware?\n");
1105 bufpos=snprintf(buf,MAXSTR,"severityLevel=\"%ld\";",
1106 alertinfo[i].severityLevel);
1107 }
1108 assert(alertinfo[i].trainingLevel>0 && alertinfo[i].trainingLevel<=6 &&
1109 PRTALERTTRAININGLEVEL[alertinfo[i].trainingLevel]!=NULL);
1110 assert(alertinfo[i].group>0 && alertinfo[i].group<=17 &&
1111 PRTALERTGROUP[alertinfo[i].group]!=NULL);
1112 /* although the code is an enumeration -- it has a decode
1113 function which will catch any cases where it fails to
1114 reference anything valid in the vector. */
1115 snprintf(buf+bufpos,MAXSTR-bufpos,"trainingLevel=\"%s\";"
1116 "group=\"%s\";groupIndex=\"%ld\";location=\"%ld\";code=\"%s\";"
1117 "description=\"%s\";time=\"%lu\";\n",
1118 PRTALERTTRAININGLEVEL[alertinfo[i].trainingLevel],
1119 PRTALERTGROUP[alertinfo[i].group],
1120 alertinfo[i].groupIndex,alertinfo[i].location,
1121 alertinfo[i].decode_code(),alertinfo[i].desc,
1122 (printertime-alertinfo[i].time)/100+systemtime);
1123 session.printstr(argflags,NEEDNL_LINE,buf);
1124 }
1125 } // end processing alert table
1126 }
1127
1128 void do_printmib_set(SNMP_session &session, unsigned long *argflags){
1129 OidSeq hpprivsets;
1130 if(CK_REBOOT_FLAG)
1131 hpprivsets.append(PRTGENERALRESET,INT_TAG,4);
1132 session.set(&hpprivsets);
1133 }