There's no need to keep a "FILE *" for the file being printed to in a
[obnox/wireshark/wip.git] / packet-ipp.c
1 /* packet-ipp.c
2  * Routines for IPP packet disassembly
3  *
4  * Guy Harris <guy@alum.mit.edu>
5  *
6  * $Id: packet-ipp.c,v 1.34 2003/01/28 22:02:26 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <string.h>
32 #include <ctype.h>
33
34 #include <glib.h>
35 #include <epan/packet.h>
36 #include <epan/strutil.h>
37 #include "packet-http.h"
38
39 static int proto_ipp = -1;
40
41 static gint ett_ipp = -1;
42 static gint ett_ipp_as = -1;
43 static gint ett_ipp_attr = -1;
44
45 static dissector_handle_t data_handle;
46
47 #define PRINT_JOB               0x0002
48 #define PRINT_URI               0x0003
49 #define VALIDATE_JOB            0x0004
50 #define CREATE_JOB              0x0005
51 #define SEND_DOCUMENT           0x0006
52 #define SEND_URI                0x0007
53 #define CANCEL_JOB              0x0008
54 #define GET_JOB_ATTRIBUTES      0x0009
55 #define GET_JOBS                0x000A
56 #define GET_PRINTER_ATTRIBUTES  0x000B
57
58 static const value_string operation_vals[] = {
59     { PRINT_JOB,              "Print-Job" },
60     { PRINT_URI,              "Print-URI" },
61     { VALIDATE_JOB,           "Validate-Job" },
62     { CREATE_JOB,             "Create-Job" },
63     { SEND_DOCUMENT,          "Send-Document" },
64     { SEND_URI,               "Send-URI" },
65     { CANCEL_JOB,             "Cancel-Job" },
66     { GET_JOB_ATTRIBUTES,     "Get-Job-Attributes" },
67     { GET_JOBS,               "Get-Jobs" },
68     { GET_PRINTER_ATTRIBUTES, "Get-Printer-Attributes" },
69     { 0,                      NULL }
70 };
71
72 #define STATUS_SUCCESSFUL       0x0000
73 #define STATUS_INFORMATIONAL    0x0100
74 #define STATUS_REDIRECTION      0x0200
75 #define STATUS_CLIENT_ERROR     0x0400
76 #define STATUS_SERVER_ERROR     0x0500
77
78 #define STATUS_TYPE_MASK        0xFF00
79
80 #define SUCCESSFUL_OK                           0x0000
81 #define SUCCESSFUL_OK_IGN_OR_SUB_ATTR           0x0001
82 #define SUCCESSFUL_OK_CONFLICTING_ATTR          0x0002
83
84 #define CLIENT_ERROR_BAD_REQUEST                0x0400
85 #define CLIENT_ERROR_FORBIDDEN                  0x0401
86 #define CLIENT_ERROR_NOT_AUTHENTICATED          0x0402
87 #define CLIENT_ERROR_NOT_AUTHORIZED             0x0403
88 #define CLIENT_ERROR_NOT_POSSIBLE               0x0404
89 #define CLIENT_ERROR_TIMEOUT                    0x0405
90 #define CLIENT_ERROR_NOT_FOUND                  0x0406
91 #define CLIENT_ERROR_GONE                       0x0407
92 #define CLIENT_ERROR_REQ_ENTITY_TOO_LRG         0x0408
93 #define CLIENT_ERROR_REQ_VALUE_TOO_LONG         0x0409
94 #define CLIENT_ERROR_DOC_FMT_NOT_SUPP           0x040A
95 #define CLIENT_ERROR_ATTR_OR_VAL_NOT_SUPP       0x040B
96 #define CLIENT_ERROR_URI_SCHEME_NOT_SUPP        0x040C
97 #define CLIENT_ERROR_CHARSET_NOT_SUPP           0x040D
98 #define CLIENT_ERROR_CONFLICTING_ATTRS          0x040E
99
100 #define SERVER_ERROR_INTERNAL_ERROR             0x0500
101 #define SERVER_ERROR_OPERATION_NOT_SUPP         0x0501
102 #define SERVER_ERROR_SERVICE_UNAVAIL            0x0502
103 #define SERVER_ERROR_VERSION_NOT_SUPP           0x0503
104 #define SERVER_ERROR_DEVICE_ERROR               0x0504
105 #define SERVER_ERROR_TEMPORARY_ERROR            0x0505
106 #define SERVER_ERROR_NOT_ACCEPTING_JOBS         0x0506
107 #define SERVER_ERROR_BUSY                       0x0507
108 #define SERVER_ERROR_JOB_CANCELED               0x0508
109
110 static const value_string status_vals[] = {
111     { SUCCESSFUL_OK,                     "Successful-OK" },
112     { SUCCESSFUL_OK_IGN_OR_SUB_ATTR,     "Successful-OK-Ignored-Or-Substituted-Attributes" },
113     { SUCCESSFUL_OK_CONFLICTING_ATTR,    "Successful-OK-Conflicting-Attributes" },
114     { CLIENT_ERROR_BAD_REQUEST,          "Client-Error-Bad-Request" },
115     { CLIENT_ERROR_FORBIDDEN,            "Client-Error-Forbidden" },
116     { CLIENT_ERROR_NOT_AUTHENTICATED,    "Client-Error-Not-Authenticated" },
117     { CLIENT_ERROR_NOT_AUTHORIZED,       "Client-Error-Not-Authorized" },
118     { CLIENT_ERROR_NOT_POSSIBLE,         "Client-Error-Not-Possible" },
119     { CLIENT_ERROR_TIMEOUT,              "Client-Error-Timeout" },
120     { CLIENT_ERROR_NOT_FOUND,            "Client-Error-Not-Found" },
121     { CLIENT_ERROR_GONE,                 "Client-Error-Gone" },
122     { CLIENT_ERROR_REQ_ENTITY_TOO_LRG,   "Client-Error-Request-Entity-Too-Large" },
123     { CLIENT_ERROR_REQ_VALUE_TOO_LONG,   "Client-Error-Request-Value-Too-Long" },
124     { CLIENT_ERROR_DOC_FMT_NOT_SUPP,     "Client-Error-Document-Format-Not-Supported" },
125     { CLIENT_ERROR_ATTR_OR_VAL_NOT_SUPP, "Client-Error-Attributes-Or-Values-Not-Supported" },
126     { CLIENT_ERROR_URI_SCHEME_NOT_SUPP,  "Client-Error-URI-Scheme-Not-Supported" },
127     { CLIENT_ERROR_CHARSET_NOT_SUPP,     "Client-Error-Charset-Not-Supported" },
128     { CLIENT_ERROR_CONFLICTING_ATTRS,    "Client-Error-Conflicting-Attributes" },
129     { SERVER_ERROR_INTERNAL_ERROR,       "Server-Error-Internal-Error" },
130     { SERVER_ERROR_OPERATION_NOT_SUPP,   "Server-Error-Operation-Not-Supported" },
131     { SERVER_ERROR_SERVICE_UNAVAIL,      "Server-Error-Service-Unavailable" },
132     { SERVER_ERROR_VERSION_NOT_SUPP,     "Server-Error-Version-Not-Supported" },
133     { SERVER_ERROR_DEVICE_ERROR,         "Server-Error-Device-Error" },
134     { SERVER_ERROR_TEMPORARY_ERROR,      "Server-Error-Temporary-Error" },
135     { SERVER_ERROR_NOT_ACCEPTING_JOBS,   "Server-Error-Not-Accepting-Jobs" },
136     { SERVER_ERROR_BUSY,                 "Server-Error-Busy" },
137     { SERVER_ERROR_JOB_CANCELED,         "Server-Error-Job-Canceled" },
138     { 0,                                 NULL }
139 };
140
141 static int parse_attributes(tvbuff_t *tvb, int offset, proto_tree *tree);
142 static proto_tree *add_integer_tree(proto_tree *tree, tvbuff_t *tvb,
143     int offset, int name_length, int value_length, guint8 tag);
144 static void add_integer_value(gchar *tag_desc, proto_tree *tree,
145     tvbuff_t *tvb, int offset, int name_length, int value_length, guint8 tag);
146 static proto_tree *add_octetstring_tree(proto_tree *tree, tvbuff_t *tvb,
147     int offset, int name_length, int value_length);
148 static void add_octetstring_value(gchar *tag_desc, proto_tree *tree,
149     tvbuff_t *tvb, int offset, int name_length, int value_length);
150 static proto_tree *add_charstring_tree(proto_tree *tree, tvbuff_t *tvb,
151     int offset, int name_length, int value_length);
152 static void add_charstring_value(gchar *tag_desc, proto_tree *tree,
153     tvbuff_t *tvb, int offset, int name_length, int value_length);
154 static int add_value_head(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
155     int offset, int name_length, int value_length);
156
157 static void
158 dissect_ipp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
159 {
160         proto_tree *ipp_tree;
161         proto_item *ti;
162         int offset = 0;
163         gboolean is_request = (pinfo->destport == 631);
164         guint16 status_code;
165         gchar *status_fmt;
166
167         if (check_col(pinfo->cinfo, COL_PROTOCOL))
168                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPP");
169         if (check_col(pinfo->cinfo, COL_INFO)) {
170                 if (is_request)
171                         col_set_str(pinfo->cinfo, COL_INFO, "IPP request");
172                 else
173                         col_set_str(pinfo->cinfo, COL_INFO, "IPP response");
174         }
175
176         if (tree) {
177                 ti = proto_tree_add_item(tree, proto_ipp, tvb, offset, -1,
178                     FALSE);
179                 ipp_tree = proto_item_add_subtree(ti, ett_ipp);
180
181                 proto_tree_add_text(ipp_tree, tvb, offset, 2, "Version: %u.%u",
182                     tvb_get_guint8(tvb, offset),
183                     tvb_get_guint8(tvb, offset + 1));
184                 offset += 2;
185
186                 if (is_request) {
187                         proto_tree_add_text(ipp_tree, tvb, offset, 2, "Operation-id: %s",
188                             val_to_str(tvb_get_ntohs(tvb, offset), operation_vals,
189                                 "Unknown (0x%04x)"));
190                 } else {
191                         status_code = tvb_get_ntohs(tvb, offset);
192                         switch (status_code & STATUS_TYPE_MASK) {
193
194                         case STATUS_SUCCESSFUL:
195                                 status_fmt = "Successful (0x%04x)";
196                                 break;
197
198                         case STATUS_INFORMATIONAL:
199                                 status_fmt = "Informational (0x%04x)";
200                                 break;
201
202                         case STATUS_REDIRECTION:
203                                 status_fmt = "Redirection (0x%04x)";
204                                 break;
205
206                         case STATUS_CLIENT_ERROR:
207                                 status_fmt = "Client error (0x%04x)";
208                                 break;
209
210                         case STATUS_SERVER_ERROR:
211                                 status_fmt = "Server error (0x%04x)";
212                                 break;
213
214                         default:
215                                 status_fmt = "Unknown (0x%04x)";
216                                 break;
217                         }
218                         proto_tree_add_text(ipp_tree, tvb, offset, 2, "Status-code: %s",
219                             val_to_str(status_code, status_vals, status_fmt));
220                 }
221                 offset += 2;
222
223                 proto_tree_add_text(ipp_tree, tvb, offset, 4, "Request ID: %u",
224                     tvb_get_ntohl(tvb, offset));
225                 offset += 4;
226
227                 offset = parse_attributes(tvb, offset, ipp_tree);
228
229                 if (tvb_offset_exists(tvb, offset)) {
230                         call_dissector(data_handle,
231                             tvb_new_subset(tvb, offset, -1, -1), pinfo,
232                             ipp_tree);
233                 }
234         }
235 }
236
237 #define TAG_TYPE(tag)           ((tag) & 0xF0)
238 #define TAG_TYPE_DELIMITER      0x00
239 #define TAG_TYPE_INTEGER        0x20
240 #define TAG_TYPE_OCTETSTRING    0x30
241 #define TAG_TYPE_CHARSTRING     0x40
242
243 #define TAG_END_OF_ATTRIBUTES   0x03
244
245 #define TAG_INTEGER             0x21
246 #define TAG_BOOLEAN             0x22
247 #define TAG_ENUM                0x23
248
249 #define TAG_OCTETSTRING         0x30
250 #define TAG_DATETIME            0x31
251 #define TAG_RESOLUTION          0x32
252 #define TAG_RANGEOFINTEGER      0x33
253 #define TAG_TEXTWITHLANGUAGE    0x35
254 #define TAG_NAMEWITHLANGUAGE    0x36
255
256 #define TAG_TEXTWITHOUTLANGUAGE 0x41
257 #define TAG_NAMEWITHOUTLANGUAGE 0x42
258 #define TAG_KEYWORD             0x44
259 #define TAG_URI                 0x45
260 #define TAG_URISCHEME           0x46
261 #define TAG_CHARSET             0x47
262 #define TAG_NATURALLANGUAGE     0x48
263 #define TAG_MIMEMEDIATYPE       0x49
264
265 static const value_string tag_vals[] = {
266         /* Delimiter tags */
267         { 0x01,                    "Operation attributes" },
268         { 0x02,                    "Job attributes" },
269         { TAG_END_OF_ATTRIBUTES,   "End of attributes" },
270         { 0x04,                    "Printer attributes" },
271         { 0x05,                    "Unsupported attributes" },
272
273         /* Value tags */
274         { 0x10,                    "Unsupported" },
275         { 0x12,                    "Unknown" },
276         { 0x13,                    "No value" },
277         { TAG_INTEGER,             "Integer" },
278         { TAG_BOOLEAN,             "Boolean" },
279         { TAG_ENUM,                "Enum" },
280         { TAG_OCTETSTRING,         "Octet string" },
281         { TAG_DATETIME,            "Date/Time" },
282         { TAG_RESOLUTION,          "Resolution" },
283         { TAG_RANGEOFINTEGER,      "Range of integer" },
284         { TAG_TEXTWITHLANGUAGE,    "Text with language" },
285         { TAG_NAMEWITHLANGUAGE,    "Name with language" },
286         { TAG_TEXTWITHOUTLANGUAGE, "Text without language" },
287         { TAG_NAMEWITHOUTLANGUAGE, "Name without language" },
288         { TAG_KEYWORD,             "Keyword" },
289         { TAG_URI,                 "URI" },
290         { TAG_URISCHEME,           "URI scheme" },
291         { TAG_CHARSET,             "Character set" },
292         { TAG_NATURALLANGUAGE,     "Natural language" },
293         { TAG_MIMEMEDIATYPE,       "MIME media type" },
294         { 0,                       NULL }
295 };
296
297 static int
298 parse_attributes(tvbuff_t *tvb, int offset, proto_tree *tree)
299 {
300         guint8 tag;
301         gchar *tag_desc;
302         int name_length, value_length;
303         proto_tree *as_tree = tree;
304         proto_item *tas = NULL;
305         int start_offset = offset;
306         proto_tree *attr_tree = tree;
307
308         while (tvb_offset_exists(tvb, offset)) {
309                 tag = tvb_get_guint8(tvb, offset);
310                 tag_desc = val_to_str(tag, tag_vals, "Reserved (0x%02x)");
311                 if (TAG_TYPE(tag) == TAG_TYPE_DELIMITER) {
312                         /*
313                          * If we had an attribute sequence we were
314                          * working on, we're done with it; set its
315                          * length to the length of all the stuff
316                          * we've done so far.
317                          */
318                         if (tas != NULL)
319                                 proto_item_set_len(tas, offset - start_offset);
320
321                         /*
322                          * This tag starts a new attribute sequence;
323                          * create a new tree under this tag when we see
324                          * a non-delimiter tag, under which to put
325                          * those attributes.
326                          */
327                         as_tree = NULL;
328                         attr_tree = tree;
329
330                         /*
331                          * Remember the offset at which this attribute
332                          * sequence started, so we can use it to compute
333                          * its length when it's finished.
334                          */
335                         start_offset = offset;
336
337                         /*
338                          * Now create a new item for this tag.
339                          */
340                         tas = proto_tree_add_text(tree, tvb, offset, 1,
341                             "%s", tag_desc);
342                         offset++;
343                         if (tag == TAG_END_OF_ATTRIBUTES) {
344                                 /*
345                                  * No more attributes.
346                                  */
347                                 break;
348                         }
349                 } else {
350                         /*
351                          * Value tag - get the name length.
352                          */
353                         name_length = tvb_get_ntohs(tvb, offset + 1);
354
355                         /*
356                          * OK, get the value length.
357                          */
358                         value_length = tvb_get_ntohs(tvb, offset + 1 + 2 + name_length);
359
360                         /*
361                          * OK, does the value run past the end of the
362                          * frame?
363                          */
364                         if (as_tree == NULL) {
365                                 /*
366                                  * OK, there's an attribute to hang
367                                  * under a delimiter tag, but we don't
368                                  * have a tree for that tag yet; create
369                                  * a tree.
370                                  */
371                                 as_tree = proto_item_add_subtree(tas,
372                                     ett_ipp_as);
373                                 attr_tree = as_tree;
374                         }
375
376                         switch (TAG_TYPE(tag)) {
377
378                         case TAG_TYPE_INTEGER:
379                                 if (name_length != 0) {
380                                         /*
381                                          * This is an attribute, not
382                                          * an additional value, so
383                                          * start a tree for it.
384                                          */
385                                         attr_tree = add_integer_tree(as_tree,
386                                             tvb, offset, name_length,
387                                             value_length, tag);
388                                 }
389                                 add_integer_value(tag_desc, attr_tree, tvb,
390                                     offset, name_length, value_length, tag);
391                                 break;
392
393                         case TAG_TYPE_OCTETSTRING:
394                                 if (name_length != 0) {
395                                         /*
396                                          * This is an attribute, not
397                                          * an additional value, so
398                                          * start a tree for it.
399                                          */
400                                         attr_tree = add_octetstring_tree(as_tree,
401                                             tvb, offset, name_length,
402                                             value_length);
403                                 }
404                                 add_octetstring_value(tag_desc, attr_tree, tvb,
405                                     offset, name_length, value_length);
406                                 break;
407
408                         case TAG_TYPE_CHARSTRING:
409                                 if (name_length != 0) {
410                                         /*
411                                          * This is an attribute, not
412                                          * an additional value, so
413                                          * start a tree for it.
414                                          */
415                                         attr_tree = add_charstring_tree(as_tree,
416                                             tvb, offset, name_length,
417                                             value_length);
418                                 }
419                                 add_charstring_value(tag_desc, attr_tree, tvb,
420                                     offset, name_length, value_length);
421                                 break;
422                         }
423                         offset += 1 + 2 + name_length + 2 + value_length;
424                 }
425         }
426
427         return offset;
428 }
429
430 static const value_string bool_vals[] = {
431         { 0x00, "false" },
432         { 0x01, "true" },
433         { 0,    NULL }
434 };
435
436 static proto_tree *
437 add_integer_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
438     int name_length, int value_length, guint8 tag)
439 {
440         proto_item *ti;
441         guint8 bool_val;
442
443         switch (tag) {
444
445         case TAG_BOOLEAN:
446                 if (value_length != 1) {
447                         ti = proto_tree_add_text(tree, tvb, offset,
448                             1 + 2 + name_length + 2 + value_length,
449                             "%.*s: Invalid boolean (length is %u, should be 1)",
450                             name_length,
451                             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
452                             value_length);
453                 } else {
454                         bool_val = tvb_get_guint8(tvb,
455                             offset + 1 + 2 + name_length + 2);
456                         ti = proto_tree_add_text(tree, tvb, offset,
457                             1 + 2 + name_length + 2 + value_length,
458                             "%.*s: %s",
459                             name_length,
460                             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
461                             val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
462                 }
463                 break;
464
465         case TAG_INTEGER:
466         case TAG_ENUM:
467                 if (value_length != 4) {
468                         ti = proto_tree_add_text(tree, tvb, offset,
469                             1 + 2 + name_length + 2 + value_length,
470                             "%.*s: Invalid integer (length is %u, should be 4)",
471                             name_length,
472                             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
473                             value_length);
474                 } else {
475                         ti = proto_tree_add_text(tree, tvb, offset,
476                             1 + 2 + name_length + 2 + value_length,
477                             "%.*s: %u",
478                             name_length,
479                             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
480                             tvb_get_ntohl(tvb, offset + 1 + 2 + name_length + 2));
481                 }
482                 break;
483
484         default:
485                 ti = proto_tree_add_text(tree, tvb, offset,
486                     1 + 2 + name_length + 2 + value_length,
487                     "%.*s: Unknown integer type 0x%02x",
488                     name_length,
489                     tvb_get_ptr(tvb, offset + 1 + 2, name_length),
490                     tag);
491                 break;
492         }
493         return proto_item_add_subtree(ti, ett_ipp_attr);
494 }
495
496 static void
497 add_integer_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
498     int offset, int name_length, int value_length, guint8 tag)
499 {
500         guint8 bool_val;
501
502         offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
503             value_length);
504
505         switch (tag) {
506
507         case TAG_BOOLEAN:
508                 if (value_length == 1) {
509                         bool_val = tvb_get_guint8(tvb, offset);
510                         proto_tree_add_text(tree, tvb, offset, value_length,
511                             "Value: %s",
512                             val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
513                 }
514                 break;
515
516         case TAG_INTEGER:
517         case TAG_ENUM:
518                 if (value_length == 4) {
519                         proto_tree_add_text(tree, tvb, offset, value_length,
520                             "Value: %u", tvb_get_ntohl(tvb, offset));
521                 }
522                 break;
523         }
524 }
525
526 static proto_tree *
527 add_octetstring_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
528     int name_length, int value_length)
529 {
530         proto_item *ti;
531
532         ti = proto_tree_add_text(tree, tvb, offset,
533             1 + 2 + name_length + 2 + value_length,
534             "%.*s: %s",
535             name_length,
536             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
537             tvb_bytes_to_str(tvb, offset + 1 + 2 + name_length + 2, value_length));
538         return proto_item_add_subtree(ti, ett_ipp_attr);
539 }
540
541 static void
542 add_octetstring_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
543     int offset, int name_length, int value_length)
544 {
545         offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
546             value_length);
547         proto_tree_add_text(tree, tvb, offset, value_length,
548             "Value: %s", tvb_bytes_to_str(tvb, offset, value_length));
549 }
550
551 static proto_tree *
552 add_charstring_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
553     int name_length, int value_length)
554 {
555         proto_item *ti;
556
557         ti = proto_tree_add_text(tree, tvb, offset,
558             1 + 2 + name_length + 2 + value_length,
559             "%.*s: %.*s",
560             name_length,
561             tvb_get_ptr(tvb, offset + 1 + 2, name_length),
562             value_length,
563             tvb_get_ptr(tvb, offset + 1 + 2 + name_length + 2, value_length));
564         return proto_item_add_subtree(ti, ett_ipp_attr);
565 }
566
567 static void
568 add_charstring_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
569     int offset, int name_length, int value_length)
570 {
571         offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
572             value_length);
573         proto_tree_add_text(tree, tvb, offset, value_length,
574             "Value: %.*s", value_length, tvb_get_ptr(tvb, offset, value_length));
575 }
576
577 static int
578 add_value_head(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb, int offset,
579     int name_length, int value_length)
580 {
581         proto_tree_add_text(tree, tvb, offset, 1, "Tag: %s", tag_desc);
582         offset += 1;
583         proto_tree_add_text(tree, tvb, offset, 2, "Name length: %u",
584             name_length);
585         offset += 2;
586         if (name_length != 0) {
587                 proto_tree_add_text(tree, tvb, offset, name_length,
588                     "Name: %.*s", name_length,
589                     tvb_get_ptr(tvb, offset, name_length));
590         }
591         offset += name_length;
592         proto_tree_add_text(tree, tvb, offset, 2, "Value length: %u",
593             value_length);
594         offset += 2;
595         return offset;
596 }
597
598 void
599 proto_register_ipp(void)
600 {
601 /*        static hf_register_info hf[] = {
602                 { &variable,
603                 { "Name",           "ipp.abbreviation", TYPE, VALS_POINTER }},
604         };*/
605         static gint *ett[] = {
606                 &ett_ipp,
607                 &ett_ipp_as,
608                 &ett_ipp_attr,
609         };
610
611         proto_ipp = proto_register_protocol("Internet Printing Protocol",
612             "IPP", "ipp");
613  /*       proto_register_field_array(proto_ipp, hf, array_length(hf));*/
614         proto_register_subtree_array(ett, array_length(ett));
615 }
616
617 void
618 proto_reg_handoff_ipp(void)
619 {
620         dissector_handle_t ipp_handle;
621
622         /*
623          * Register ourselves as running atop HTTP and using port 631.
624          */
625         ipp_handle = create_dissector_handle(dissect_ipp, proto_ipp);
626         http_dissector_add(631, ipp_handle);
627         data_handle = find_dissector("data");
628 }