|
1 |
| -ipp |
2 |
| -=== |
| 1 | +# Internet Printing Protocol (IPP) for nodejs |
| 2 | +--- |
3 | 3 |
|
4 |
| -Internet Printing Protocol (IPP) for nodejs |
| 4 | +This is a very indepth protocol that spans many RFCs- some of which are dead while others were herded into IPP/v2.x. It |
| 5 | +will take a while to build this lib and definately needs community help. |
| 6 | + |
| 7 | +I have a pretty good starting point here. I created reference files |
| 8 | +(<del>`attributes`</del>, `enums`, `keywords`, `operations`, `status-codes`, `versions` and `tags`) and tried to include as many |
| 9 | +links in the comments to the ref docs as I could. |
| 10 | + |
| 11 | +IPP uses a confusing/complicated/custom binary serialization IMHO that dates back to the lates '90s. After 15 years of |
| 12 | +building this protocol- I the technologies available today could simplified things 10X (again IMO). But it is what is |
| 13 | +deployed on millions of printers now- so we'll work with it. |
| 14 | + |
| 15 | +### Install |
| 16 | +```bash |
| 17 | +$ npm install ipp |
| 18 | +``` |
| 19 | + |
| 20 | + |
| 21 | +## ipp.parse(buffer) |
| 22 | + |
| 23 | +My first goal was to create a parser... |
| 24 | + |
| 25 | +```javascript |
| 26 | +var ipp = require('ipp'); |
| 27 | +var data = new Buffer( |
| 28 | + '0200' + //version 2.0 |
| 29 | + '000B' + //Get-Printer-Attributes |
| 30 | + '00000001'+ //reqid |
| 31 | + '01' + //operation-attributes-tag |
| 32 | + //blah blah the required bloat of this protocol |
| 33 | + '470012617474726962757465732d6368617273657400057574662d3848001b617474726962757465732d6e61747572616c2d6c616e67756167650002656e' + |
| 34 | + '03' //end-of-attributes-tag |
| 35 | + ,'hex'); |
| 36 | + |
| 37 | + |
| 38 | +var result = ipp.parse(data); |
| 39 | +console.log(JSON.stringify(result,null,2)); |
| 40 | +// ta-da! |
| 41 | +//{ |
| 42 | +// "version": "2.0", |
| 43 | +// "operation": 11, |
| 44 | +// "id": 1, |
| 45 | +// "operation-attributes-tag": { |
| 46 | +// "attributes-charset": "utf-8", |
| 47 | +// "attributes-natural-language": "en" |
| 48 | +// } |
| 49 | +//} |
| 50 | +``` |
| 51 | + |
| 52 | +## ipp.request(url, data, callback) |
| 53 | + |
| 54 | +This is a work-in-progress but it is working enough for ya'll to reference. |
| 55 | + |
| 56 | +```javascript |
| 57 | +var ipp = require('ipp'); |
| 58 | +var id = 0x0123;//made up reqid |
| 59 | +var op = ipp.operations['Get-Printer-Attributes']; |
| 60 | + |
| 61 | +//This is a experimental module. |
| 62 | +//Expect it to be changed. |
| 63 | +//Don't expect it to do what you want. |
| 64 | +var data = require('./lib/message')("your-printer", op, id); |
| 65 | + |
| 66 | +ipp.request("ipp://your-printer/", data, function(err, res){ |
| 67 | + if(err){ |
| 68 | + return console.log(err); |
| 69 | + } |
| 70 | + console.log(JSON.stringify(res,null,2)); |
| 71 | +}) |
| 72 | +// ta-da!.. hopefully you'll see a ton of stuff from your printer |
| 73 | +``` |
| 74 | + |
| 75 | +## License |
| 76 | + |
| 77 | +MIT |
0 commit comments